First of all, the upstream open-iscsi client/initiator systemd service does not call iscsiadm
such that it waits until all login requests are successful before it exits (Ref.: [1] [2]).
So you can indeed try to "minimize" the chance that you bump into the race condition (but not really eliminate the race itself) by overriding the ExecStart=
command with a service snippet (see systemctl edit
) so that it does not call iscsiadm
with -W
.
The thing is, even when iscsiadm
does wait until all logins have been completed, AFAICT it does not mean that it will (or even can) wait until the generic SCSI disk driver has done probing all the drives that was just populated / virtualized in the system. (It's like the time you fully plugged a USB drive in isn't really the time the kernel has done probing it.)
So the "real" way to make sure that all the devices of a multi-device BTRFS volume are there and ready such that the volume can be mounted, is to check whether the btrfs filesystem driver has done scanning / registering them.
One way is to have a script like this and a service that is pulled by (or, perhaps even better, pulls) the corresponding mount unit and runs the script:
#!/bin/sh
while true; do
if [ -L /dev/disk/by-uuid/"$1" ] &&
btrfs device ready /dev/disk/by-uuid/"$1"; then
break
fi
done
($1
should be set to a UUID in small letters. You may even write a systemd service template and passed the service argument of each enabled instance as the script argument, although you probably need to check out the escaping rules for hyphens.)
Certainly you will need to make sure the ready-script service is ordered before the mount unit. Also make sure you use the correct Type=
. (I think oneshot
should be correct / fine.)
Also, you may want to confirm that your system creates symlinks under /dev/disk/by-uuid/
first.
If you want to pulls the mount unit with the ready-script service, I suppose you can in turn pull it with the iscsi service.
P.S. btrfs device ready
will not return 1
if a device of a multi-device volume was scanned but is now gone (unplugged or whatever) until you run btrfs device scan -u
. I think it's worth mentioning because the behavior could make you thought that the ready
subcommand is broken / useless (like I did) when you want to test it out first on a was-once-ready volume.