-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New service that waits on zvol links to be created
The zfs-volume-wait.service scans existing zvols and waits for their links under /dev to be created. Any service that depends on zvol links to be there should add a dependency on zfs-volumes.target. By default, this target is not enabled. Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Reviewed-by: Antonio Russo <antonio.e.russo@gmail.com> Reviewed-by: Richard Laager <rlaager@wiktel.com> Reviewed-by: loli10K <ezomori.nozomu@gmail.com> Reviewed-by: John Gallagher <john.gallagher@delphix.com> Reviewed-by: George Wilson <gwilson@delphix.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Pavel Zakharov <pzakharov@delphix.com> Closes #8975
- Loading branch information
1 parent
beb21db
commit 3852847
Showing
11 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist_bin_SCRIPTS = zvol_wait |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/sh | ||
|
||
count_zvols() { | ||
if [ -z "$zvols" ]; then | ||
echo 0 | ||
else | ||
echo "$zvols" | wc -l | ||
fi | ||
} | ||
|
||
filter_out_zvols_with_links() { | ||
while read -r zvol; do | ||
if [ ! -L "/dev/zvol/$zvol" ]; then | ||
echo "$zvol" | ||
fi | ||
done | ||
} | ||
|
||
filter_out_deleted_zvols() { | ||
while read -r zvol; do | ||
if zfs list "$zvol" >/dev/null 2>&1; then | ||
echo "$zvol" | ||
fi | ||
done | ||
} | ||
|
||
list_zvols() { | ||
zfs list -t volume -H -o name,volmode | while read -r zvol_line; do | ||
name=$(echo "$zvol_line" | awk '{print $1}') | ||
volmode=$(echo "$zvol_line" | awk '{print $2}') | ||
# /dev links are not created for zvols with volmode = "none". | ||
[ "$volmode" = "none" ] || echo "$name" | ||
done | ||
} | ||
|
||
zvols=$(list_zvols) | ||
zvols_count=$(count_zvols) | ||
if [ "$zvols_count" -eq 0 ]; then | ||
echo "No zvols found, nothing to do." | ||
exit 0 | ||
fi | ||
|
||
echo "Testing $zvols_count zvol links" | ||
|
||
outer_loop=0 | ||
while [ "$outer_loop" -lt 20 ]; do | ||
outer_loop=$((outer_loop + 1)) | ||
|
||
old_zvols_count=$(count_zvols) | ||
|
||
inner_loop=0 | ||
while [ "$inner_loop" -lt 30 ]; do | ||
inner_loop=$((inner_loop + 1)) | ||
|
||
zvols="$(echo "$zvols" | filter_out_zvols_with_links)" | ||
|
||
zvols_count=$(count_zvols) | ||
if [ "$zvols_count" -eq 0 ]; then | ||
echo "All zvol links are now present." | ||
exit 0 | ||
fi | ||
sleep 1 | ||
done | ||
|
||
echo "Still waiting on $zvols_count zvol links ..." | ||
# | ||
# Although zvols should normally not be deleted at boot time, | ||
# if that is the case then their links will be missing and | ||
# we would stall. | ||
# | ||
if [ "$old_zvols_count" -eq "$zvols_count" ]; then | ||
echo "No progress since last loop." | ||
echo "Checking if any zvols were deleted." | ||
|
||
zvols=$(echo "$zvols" | filter_out_deleted_zvols) | ||
zvols_count=$(count_zvols) | ||
|
||
if [ "$old_zvols_count" -ne "$zvols_count" ]; then | ||
echo "$((old_zvols_count - zvols_count)) zvol(s) deleted." | ||
fi | ||
|
||
if [ "$zvols_count" -ne 0 ]; then | ||
echo "Remaining zvols:" | ||
echo "$zvols" | ||
else | ||
echo "All zvol links are now present." | ||
exit 0 | ||
fi | ||
fi | ||
done | ||
|
||
echo "Timed out waiting on zvol links" | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Wait for ZFS Volume (zvol) links in /dev | ||
DefaultDependencies=no | ||
After=systemd-udev-settle.service | ||
After=zfs-import.target | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
ExecStart=@bindir@/zvol_wait | ||
|
||
[Install] | ||
WantedBy=zfs-volumes.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[Unit] | ||
Description=ZFS volumes are ready | ||
After=zfs-volume-wait.service | ||
Requires=zfs-volume-wait.service | ||
|
||
[Install] | ||
WantedBy=zfs.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.Dd July 5, 2019 | ||
.Dt ZVOL_WAIT 1 SMM | ||
.Os Linux | ||
.Sh NAME | ||
.Nm zvol_wait | ||
.Nd Wait for ZFS volume links in | ||
.Em /dev | ||
to be created. | ||
.Sh SYNOPSIS | ||
.Nm | ||
.Sh DESCRIPTION | ||
When a ZFS pool is imported, ZFS will register each ZFS volume | ||
(zvol) as a disk device with the system. As the disks are registered, | ||
.Xr \fBudev 7\fR | ||
will asynchronously create symlinks under | ||
.Em /dev/zvol | ||
using the zvol's name. | ||
.Nm | ||
will wait for all those symlinks to be created before returning. | ||
.Sh SEE ALSO | ||
.Xr \fBudev 7\fR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters