SG_STPG(8)

πŸ“¦
version 1.49 Β· 3 versions
, in alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ 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 with 0x or ends with h, in which case it's hex πŸ”’ Only the values 0, 1, 2, 3 or 14 are accepted. The abbreviations are an, ao, o, s or u, 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 with 0x or ends with h, 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 Β© 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