__starget_for_each_device(9)
π __starget_for_each_device β the "walk every device on a target, no locks taken" helper
okay so real talk, this one lives in the Kernel API Manual and it's the unlocked sibling of the locked loop you probably want. bestie, read the NOTE before you commit, i'm begging π«Ά
β¨ NAME β¨
__starget_for_each_device β a helper to walk all devices of a target, and it is (UNLOCKED) π
Like. It doesn't lock anything for you. That's the whole personality. π
πΈ SYNOPSIS πΈ
void __starget_for_each_device (struct scsi_target *starget , void *data
, void (*fn)(struct scsi_device *, void *) );
the way that signature is literally just target, blob of data, callback, and then vibes π¦
π ARGUMENTS π
stargetβ the target whose devices we want to iterate over. this is the main character of the loop πdataβ a parameter for callbackfn. it just gets passed straight through, no questions asked πfnβ the callback function that is invoked for each device. it's giving you supply the behaviour, i supply the iteration β¨
π DESCRIPTION π
so what it does: this traverses over each device of starget, calling your fn on every single one. slay. π
but here's the iconic part β it does not take a reference on the scsi_device. not one. so the whole loop must be protected by shost->host_lock. yes, the entire loop. no cap. π₯
β οΈ no reference taken + unlocked traversal means you own the locking. if you don't hold shost->host_lock around the entire loop, that's on you, and the kernel will not be sending you a cute little warning first π
π NOTE π
the only reason why drivers would want to use this is because they need to access the device list in irq context. like, that's the one legit use case, periodt. π«
otherwise, bestie, you really want to use starget_for_each_device instead. fr fr. the locked one. the safe one. the one that doesn't make you hold host_lock manually while stress-crying into your dmesg π
π§ SEE ALSO π§
kernel file ./drivers/scsi/scsi.c and friends β go read these next, iykyk:
scsi_finish_command(9)scsi_change_queue_depth(9)scsi_track_queue_full(9)scsi_vpd_inquiry(9)scsi_get_vpd_page(9)scsi_get_vpd_buf(9)scsi_attach_vpd(9)scsi_report_opcode(9)scsi_cdl_check(9)scsi_cdl_enable(9)scsi_device_get(9)scsi_device_put(9)starget_for_each_device(9)__scsi_device_lookup_by_target(9)scsi_device_lookup_by_target(9)__scsi_device_lookup(9)scsi_device_lookup(9)
and that's the page, bestie π«Ά it ships from ./drivers/scsi, dated October 2026, still called __starget_for_each_device(9) β go forth, hold that host_lock, and stay iconic πβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms