SG_STPG(8)
β¨ NAME β¨
okay bestie, the manual name is sg_stpg, and it's how you send a SCSI SET TARGET PORT GROUPS command π
Basically it tells a device which target port groups should be in which asymmetric access state. Very powerful, very iconic π₯
πΈ SYNOPSIS πΈ
sg_stpg [--active] [--help] [--hex] [--offline] [--optimized] [--raw]
[--standby] [--state=S,S...] [--tp=P,P...] [--unavailable] [--verbose]
[--version] DEVICE
π DESCRIPTION π
So the big idea: sg_stpg sends a SCSI SET TARGET PORT GROUPS command to DEVICE. It has two different modes, and which one you get depends on whether you pass the --tp= option π¦
Mode one: --tp= is given. The command parameter block gets built with one descriptor for each element in the list you hand to --tp=. The asymmetric access state for each one comes from the --state= list. If you don't give --state=, it comes from one of the explicit state options instead (like --unavailable), and that gets reused over and over as needed β¨
Mode two: --tp= is not given. This one is more of a whole sequence π First it sends an INQUIRY to grab the device identification VPD page, so it can find the (primary) target port group tied to DEVICE. Then it sends a REPORT TARGET PORT GROUPS command to check the current state and whether a transition to the state you asked for is supported. If it is, then the SET TARGET PORT GROUPS command goes out. Main character energy, literally π
If you want the nerdy background, target port group access is described in SPC-4, which you can find at www.t10.org. Check sections 5.8 and 5.16 (in rev 36e dated 2012/8/24). The SET TARGET PORT GROUPS command itself is covered in section 6.45 of that same document π€
π OPTIONS π
Quick heads up: arguments to long options are mandatory for short options as well, so if a long option needs a value, the short one does too π«Ά The options are listed in alphabetical order by their long option name, so you can find things easily β¨
-a,--activeβ sets the active/non-optimized state π€οΈ-h,--helpβ prints the usage message and then exits π-H,--hexβ prints the response to the REPORT TARGET PORT GROUPS command in hex, then exits π’-O,-l,--offlineβ sets the offline state. This is the right state to put a target port in before you remove the device π¦ Heads up: a relative target port identifier goes with this state (not the target port group identifier that every other state takes) π¨-o,--optimizedβ sets the active/optimized state. If you don't give any other state options and no--tp=option, active/optimized is the default, so you get it for free π-r,--rawβ writes the response to the REPORT TARGET PORT GROUPS command in binary to stdout, then exits π€-s,--standbyβ sets the standby state. A port group in standby accepts the commands listed for "unavailable" plus LOG SELECT/SENSE, MODE SELECT/SENSE, RECEIVE DIAGNOSTIC RESULTS, SEND DIAGNOSTIC, and PERSISTENT RESERVE IN/OUT π§-S,--state=S,S...β a comma separated list (one element or more) of states. You can use a number or an abbreviation. A number is decimal unless it starts with0xor ends withh, in which case it's hex π’ Only the values0,1,2,3or14are accepted. The abbreviations arean,ao,o,soru, which mean active/non-optimized(1), active/optimized(0), offline(14), standby(2) or unavailable(3), respectively π¦-t,--tp=P,P...β a comma separated list (one element or more). Each element is either a target port group identifier (when the matching state is something other than "offline") or a relative target port identifier (when the matching state is "offline"). Each element is decimal unless it starts with0xor ends withh, which means hex π-u,--unavailableβ sets the unavailable state. A port group in this state only accepts INQUIRY, REPORT LUNS, REPORT/SET TARGET PORT GROUPS, REQUEST SENSE and READ/WRITE BUFFER commands π-v,--verboseβ turns up the verbosity (aka debug output) π-V,--versionβ prints the version string, then exits π·οΈ
π NOTES π
Okay, so the SET TARGET PORT GROUPS command should be supported whenever the TPGS value in a standard INQUIRY response is 2 or 3. You can check that with the sg_inq utility π
Notice that the offline state is a "secondary target port asymmetric access state". It takes a relative target port identifier, which means it acts on a single target port π₯Ί Every other state is a "primary target port asymmetric access state", and each one takes a target port group identifier, so it acts on one or more target ports πΈ
Also, when --tp= is given, you should pass the same number of elements to --state=. If you give more than one element to --tp= and not an equal number to --state=, then as long as you only specified one state, that state gets repeated π bestie, that's a whole glow-up for your command line π
π¦ EXIT STATUS π¦
If everything goes well, sg_stpg exits with 0. If not, check the sg3_utils(8) man page for the rest of the exit codes π
π§ AUTHORS π§
Written by Douglas Gilbert π
π REPORTING BUGS π
Found a bug? Report it to <dgilbert at interlog dot com> π¬
π COPYRIGHT π
Copyright Β© 2007-2014 Hannes Reinecke, Christophe Varoqui and D Gilbert. This software is distributed under a BSD-2-Clause license. There is NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE π
π SEE ALSO π
sg_inq, sg_rtpg (sg3_utils) π«Ά
That's a wrap, bestie! π This was sg_stpg from sg3_utils-1.38, dated January 2014, and it's iconic. Now go slay your SCSI commands π β¨π
π¦ where this page comes from
- alpine 3.24: sg3_utils-doc 1.48-r0 Β· BSD-2-Clause AND GPL-2.0-or-later
- arch rolling: sg3_utils 1.49-1 Β· GPL-2.0-or-later AND BSD-2-Clause
- centos-stream 10: sg3_utils 1.48-11.el10 Β· GPL-2.0-or-later AND BSD-2-Clause
- debian trixie: sg3-utils 1.48-3~deb13u1
- fedora 43: sg3_utils 1.48-10.fc43 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 43: sg3_utils 1.48-6.fc43 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 44: sg3_utils 1.48-10.fc44 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 44: sg3_utils 1.48-8.fc44 Β· GPL-2.0-or-later AND BSD-2-Clause
- nixos 26.05: sg3_utils 1.48
- nixpkgs unstable: sg3_utils 1.49
- ubuntu questing: sg3-utils 1.48-2ubuntu1
- ubuntu resolute: sg3-utils 1.48-3ubuntu3
- ubuntu resolute: sg3-utils 1.48-3ubuntu3.2
- ubuntu stonking: sg3-utils 1.48-3ubuntu5
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms