Blame 0010-nbd-add-systemd-generator-and-use-nbd-export-names-i.patch

Harald Hoyer 7ba020
From b070c1d360e86db69a8049b2f040b8223bc484c9 Mon Sep 17 00:00:00 2001
Harald Hoyer 7ba020
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 7ba020
Date: Mon, 14 Dec 2015 13:10:33 +0100
Harald Hoyer 7ba020
Subject: [PATCH] nbd: add systemd generator and use nbd export names instead
Harald Hoyer 7ba020
 of port numbers
Harald Hoyer 7ba020
Harald Hoyer 7ba020
Add a systemd generator for root=nbd:.. so that systemd has a correct
Harald Hoyer 7ba020
sysroot.mount unit.
Harald Hoyer 7ba020
Harald Hoyer 7ba020
Use export names instead of port numbers, because port number based
Harald Hoyer 7ba020
exports are deprecated and were removed.
Harald Hoyer 7ba020
---
Harald Hoyer 7ba020
 dracut.cmdline.7.asc             | 14 +++++++++++---
Harald Hoyer 7ba020
 modules.d/95nbd/module-setup.sh  |  3 +++
Harald Hoyer 7ba020
 modules.d/95nbd/nbdroot.sh       | 11 +++++------
Harald Hoyer 7ba020
 modules.d/95nbd/parse-nbdroot.sh | 10 ++++++++--
Harald Hoyer 7ba020
 test/TEST-40-NBD/dhcpd.conf      | 10 +++++-----
Harald Hoyer 7ba020
 test/TEST-40-NBD/server-init.sh  |  3 +--
Harald Hoyer 7ba020
 test/TEST-40-NBD/test.sh         | 41 ++++++++++++++++++++++++----------------
Harald Hoyer 7ba020
 7 files changed, 58 insertions(+), 34 deletions(-)
Harald Hoyer 7ba020
Harald Hoyer 7ba020
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
Harald Hoyer 7ba020
index c34b45b..e160e3b 100644
Harald Hoyer 7ba020
--- a/dracut.cmdline.7.asc
Harald Hoyer 7ba020
+++ b/dracut.cmdline.7.asc
Harald Hoyer 7ba020
@@ -755,13 +755,21 @@ NOTE: letters in the MAC-address must be lowercase!
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 NBD
Harald Hoyer 7ba020
 ~~~
Harald Hoyer 7ba020
-**root=**??? **netroot=**nbd:__<server>__:__<port>__[:__<fstype>__[:__<mountopts>__[:__<nbdopts>__]]]::
Harald Hoyer 7ba020
-    mount nbd share from <server>
Harald Hoyer 7ba020
+**root=**??? **netroot=**nbd:__<server>__:__<port/exportname>__[:__<fstype>__[:__<mountopts>__[:__<nbdopts>__]]]::
Harald Hoyer 7ba020
+    mount nbd share from <server>.
Harald Hoyer 7ba020
++
Harald Hoyer 7ba020
+NOTE:
Harald Hoyer 7ba020
+    If "exportname" instead of "port" is given the standard port is used.
Harald Hoyer 7ba020
+    Newer versions of nbd are only supported with "exportname".
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
-**root=dhcp** with **dhcp** **root-path=**nbd:__<server>__:__<port>__[:__<fstype>__[:__<mountopts>__[:__<nbdopts>__]]]::
Harald Hoyer 7ba020
+**root=dhcp** with **dhcp** **root-path=**nbd:__<server>__:__<port/exportname>__[:__<fstype>__[:__<mountopts>__[:__<nbdopts>__]]]::
Harald Hoyer 7ba020
     root=dhcp alone directs initrd to look at the DHCP root-path where NBD
Harald Hoyer 7ba020
     options can be specified. This syntax is only usable in cases where you are
Harald Hoyer 7ba020
     directly mounting the volume as the rootfs.
Harald Hoyer 7ba020
++
Harald Hoyer 7ba020
+NOTE:
Harald Hoyer 7ba020
+    If "exportname" instead of "port" is given the standard port is used.
Harald Hoyer 7ba020
+    Newer versions of nbd are only supported with "exportname".
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 DASD
Harald Hoyer 7ba020
 ~~~~
Harald Hoyer 7ba020
diff --git a/modules.d/95nbd/module-setup.sh b/modules.d/95nbd/module-setup.sh
Harald Hoyer 7ba020
index 3cb6f49..22f6a3b 100755
Harald Hoyer 7ba020
--- a/modules.d/95nbd/module-setup.sh
Harald Hoyer 7ba020
+++ b/modules.d/95nbd/module-setup.sh
Harald Hoyer 7ba020
@@ -34,6 +34,9 @@ install() {
Harald Hoyer 7ba020
     inst nbd-client
Harald Hoyer 7ba020
     inst_hook cmdline 90 "$moddir/parse-nbdroot.sh"
Harald Hoyer 7ba020
     inst_script "$moddir/nbdroot.sh" "/sbin/nbdroot"
Harald Hoyer 7ba020
+    if dracut_module_included "systemd-initrd"; then
Harald Hoyer 7ba020
+        inst_script "$moddir/nbd-generator.sh" $systemdutildir/system-generators/dracut-nbd-generator
Harald Hoyer 7ba020
+    fi
Harald Hoyer 7ba020
     dracut_need_initqueue
Harald Hoyer 7ba020
 }
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
diff --git a/modules.d/95nbd/nbdroot.sh b/modules.d/95nbd/nbdroot.sh
Harald Hoyer 7ba020
index dd2bb55..7057f23 100755
Harald Hoyer 7ba020
--- a/modules.d/95nbd/nbdroot.sh
Harald Hoyer 7ba020
+++ b/modules.d/95nbd/nbdroot.sh
Harald Hoyer 7ba020
@@ -28,11 +28,6 @@ nbdfstype=${nroot%%:*}; nroot=${nroot#*:}
Harald Hoyer 7ba020
 nbdflags=${nroot%%:*}
Harald Hoyer 7ba020
 nbdopts=${nroot#*:}
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
-# If nbdport not an integer, then assume name based import
Harald Hoyer 7ba020
-if [ ! -z $(echo "$nbdport" | sed 's/[0-9]//g') ]; then
Harald Hoyer 7ba020
-    nbdport="-N $nbdport"
Harald Hoyer 7ba020
-fi
Harald Hoyer 7ba020
-
Harald Hoyer 7ba020
 if [ "$nbdopts" = "$nbdflags" ]; then
Harald Hoyer 7ba020
     unset nbdopts
Harald Hoyer 7ba020
 fi
Harald Hoyer 7ba020
@@ -113,7 +108,11 @@ if strstr "$(nbd-client --help 2>&1)" "systemd-mark"; then
Harald Hoyer 7ba020
     preopts="--systemd-mark $preopts"
Harald Hoyer 7ba020
 fi
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
-nbd-client $preopts "$nbdserver" $nbdport /dev/nbd0 $opts || exit 1
Harald Hoyer 7ba020
+if [ "$nbdport" -gt 0 ] 2>/dev/null; then
Harald Hoyer 7ba020
+    nbd-client "$nbdserver" $nbdport /dev/nbd0 $preopts $opts || exit 1
Harald Hoyer 7ba020
+else
Harald Hoyer 7ba020
+    nbd-client -name "$nbdport" "$nbdserver" /dev/nbd0 $preopts $opts || exit 1
Harald Hoyer 7ba020
+fi
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 # NBD doesn't emit uevents when it gets connected, so kick it
Harald Hoyer 7ba020
 echo change > /sys/block/nbd0/uevent
Harald Hoyer 7ba020
diff --git a/modules.d/95nbd/parse-nbdroot.sh b/modules.d/95nbd/parse-nbdroot.sh
Harald Hoyer 7ba020
index 746fb14..902e9a9 100755
Harald Hoyer 7ba020
--- a/modules.d/95nbd/parse-nbdroot.sh
Harald Hoyer 7ba020
+++ b/modules.d/95nbd/parse-nbdroot.sh
Harald Hoyer 7ba020
@@ -1,8 +1,8 @@
Harald Hoyer 7ba020
 #!/bin/sh
Harald Hoyer 7ba020
 #
Harald Hoyer 7ba020
 # Preferred format:
Harald Hoyer 7ba020
-#       root=nbd:srv:port[:fstype[:rootflags[:nbdopts]]]
Harald Hoyer 7ba020
-#       [root=*] netroot=nbd:srv:port[:fstype[:rootflags[:nbdopts]]]
Harald Hoyer 7ba020
+#       root=nbd:srv:port/exportname[:fstype[:rootflags[:nbdopts]]]
Harald Hoyer 7ba020
+#       [root=*] netroot=nbd:srv:port/exportname[:fstype[:rootflags[:nbdopts]]]
Harald Hoyer 7ba020
 #
Harald Hoyer 7ba020
 # nbdopts is a comma separated list of options to give to nbd-client
Harald Hoyer 7ba020
 #
Harald Hoyer 7ba020
@@ -45,6 +45,12 @@ fi
Harald Hoyer 7ba020
 # If it's not nbd we don't continue
Harald Hoyer 7ba020
 [ "${netroot%%:*}" = "nbd" ] || return
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+if [ -n "${DRACUT_SYSTEMD}" ] && [ "$root" = "dhcp" ]; then
Harald Hoyer 7ba020
+    echo "root=$netroot" > /etc/cmdline.d/root.conf
Harald Hoyer 7ba020
+    systemctl --no-block daemon-reload
Harald Hoyer 7ba020
+fi
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
 # Check required arguments
Harald Hoyer 7ba020
 netroot_to_var $netroot
Harald Hoyer 7ba020
 [ -z "$server" ] && die "Argument server for nbdroot is missing"
Harald Hoyer 7ba020
diff --git a/test/TEST-40-NBD/dhcpd.conf b/test/TEST-40-NBD/dhcpd.conf
Harald Hoyer 7ba020
index 942bc6a..08461f9 100644
Harald Hoyer 7ba020
--- a/test/TEST-40-NBD/dhcpd.conf
Harald Hoyer 7ba020
+++ b/test/TEST-40-NBD/dhcpd.conf
Harald Hoyer 7ba020
@@ -20,7 +20,7 @@ subnet 192.168.50.0 netmask 255.255.255.0 {
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 	group {
Harald Hoyer 7ba020
 		host nbd-2 {
Harald Hoyer 7ba020
-			option root-path "nbd:192.168.50.1:2000";
Harald Hoyer 7ba020
+			option root-path "nbd:192.168.50.1:raw";
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 			hardware ethernet 52:54:00:12:34:01;
Harald Hoyer 7ba020
 			fixed-address 192.168.50.101;
Harald Hoyer 7ba020
@@ -29,7 +29,7 @@ subnet 192.168.50.0 netmask 255.255.255.0 {
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 	group {
Harald Hoyer 7ba020
 		host nbd-3 {
Harald Hoyer 7ba020
-			option root-path "nbd:192.168.50.1:2000:ext2";
Harald Hoyer 7ba020
+			option root-path "nbd:192.168.50.1:raw:ext2";
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 			hardware ethernet 52:54:00:12:34:02;
Harald Hoyer 7ba020
 			fixed-address 192.168.50.101;
Harald Hoyer 7ba020
@@ -38,7 +38,7 @@ subnet 192.168.50.0 netmask 255.255.255.0 {
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 	group {
Harald Hoyer 7ba020
 		host nbd-4 {
Harald Hoyer 7ba020
-			option root-path "nbd:192.168.50.1:2000::errors=panic";
Harald Hoyer 7ba020
+			option root-path "nbd:192.168.50.1:raw::errors=panic";
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 			hardware ethernet 52:54:00:12:34:03;
Harald Hoyer 7ba020
 			fixed-address 192.168.50.101;
Harald Hoyer 7ba020
@@ -47,7 +47,7 @@ subnet 192.168.50.0 netmask 255.255.255.0 {
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 	group {
Harald Hoyer 7ba020
 		host nbd-5 {
Harald Hoyer 7ba020
-			option root-path "nbd:192.168.50.1:2000:ext2:errors=panic";
Harald Hoyer 7ba020
+			option root-path "nbd:192.168.50.1:raw:ext2:errors=panic";
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 			hardware ethernet 52:54:00:12:34:04;
Harald Hoyer 7ba020
 			fixed-address 192.168.50.101;
Harald Hoyer 7ba020
@@ -57,7 +57,7 @@ subnet 192.168.50.0 netmask 255.255.255.0 {
Harald Hoyer 7ba020
 	group {
Harald Hoyer 7ba020
 		host nbd-6 {
Harald Hoyer 7ba020
 			# Use the encrypted image
Harald Hoyer 7ba020
-			option root-path "nbd:192.168.50.1:2001:ext2:errors=panic";
Harald Hoyer 7ba020
+			option root-path "nbd:192.168.50.1:encrypted:ext2:errors=panic";
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 			hardware ethernet 52:54:00:12:34:05;
Harald Hoyer 7ba020
 			fixed-address 192.168.50.101;
Harald Hoyer 7ba020
diff --git a/test/TEST-40-NBD/server-init.sh b/test/TEST-40-NBD/server-init.sh
Harald Hoyer 7ba020
index 73c64d6..0039753 100755
Harald Hoyer 7ba020
--- a/test/TEST-40-NBD/server-init.sh
Harald Hoyer 7ba020
+++ b/test/TEST-40-NBD/server-init.sh
Harald Hoyer 7ba020
@@ -13,8 +13,7 @@ ip link set dev eth0 name ens3
Harald Hoyer 7ba020
 ip addr add 192.168.50.1/24 dev ens3
Harald Hoyer 7ba020
 ip link set ens3 up
Harald Hoyer 7ba020
 modprobe af_packet
Harald Hoyer 7ba020
-nbd-server 2000 /dev/sdb -C /dev/null
Harald Hoyer 7ba020
-nbd-server 2001 /dev/sdc -C /dev/null
Harald Hoyer 7ba020
+nbd-server
Harald Hoyer 7ba020
 >/var/lib/dhcpd/dhcpd.leases
Harald Hoyer 7ba020
 chmod 777 /var/lib/dhcpd/dhcpd.leases
Harald Hoyer 7ba020
 dhcpd -d -cf /etc/dhcpd.conf -lf /var/lib/dhcpd/dhcpd.leases &
Harald Hoyer 7ba020
diff --git a/test/TEST-40-NBD/test.sh b/test/TEST-40-NBD/test.sh
Harald Hoyer 7ba020
index 39966ac..28ba6aa 100755
Harald Hoyer 7ba020
--- a/test/TEST-40-NBD/test.sh
Harald Hoyer 7ba020
+++ b/test/TEST-40-NBD/test.sh
Harald Hoyer 7ba020
@@ -5,8 +5,8 @@ TEST_DESCRIPTION="root filesystem on NBD"
Harald Hoyer 7ba020
 KVERSION=${KVERSION-$(uname -r)}
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 # Uncomment this to debug failures
Harald Hoyer 7ba020
-#DEBUGFAIL="rd.shell rd.break"
Harald Hoyer 7ba020
-#SERIAL="udp:127.0.0.1:9999"
Harald Hoyer 7ba020
+#DEBUGFAIL="rd.shell rd.break rd.debug"
Harald Hoyer 7ba020
+SERIAL="tcp:127.0.0.1:9999"
Harald Hoyer 7ba020
 SERIAL="null"
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
 run_server() {
Harald Hoyer 7ba020
@@ -104,36 +104,36 @@ test_run() {
Harald Hoyer 7ba020
 client_run() {
Harald Hoyer 7ba020
     # The default is ext3,errors=continue so use that to determine
Harald Hoyer 7ba020
     # if our options were parsed and used
Harald Hoyer 7ba020
+    client_test "NBD root=nbd:IP:port" 52:54:00:12:34:00 \
Harald Hoyer 7ba020
+        "root=nbd:192.168.50.1:raw rd.luks=0" || return 1
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
     client_test "NBD root=nbd:IP:port::fsopts" 52:54:00:12:34:00 \
Harald Hoyer 7ba020
-        "root=nbd:192.168.50.1:2000::errors=panic rd.luks=0" \
Harald Hoyer 7ba020
+        "root=nbd:192.168.50.1:raw::errors=panic rd.luks=0" \
Harald Hoyer 7ba020
         ext3 errors=panic || return 1
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
-    client_test "NBD root=nbd:IP:port" 52:54:00:12:34:00 \
Harald Hoyer 7ba020
-        "root=nbd:192.168.50.1:2000 rd.luks=0" || return 1
Harald Hoyer 7ba020
-
Harald Hoyer 7ba020
     client_test "NBD root=nbd:IP:port:fstype" 52:54:00:12:34:00 \
Harald Hoyer 7ba020
-        "root=nbd:192.168.50.1:2000:ext2 rd.luks=0" ext2 || return 1
Harald Hoyer 7ba020
+        "root=nbd:192.168.50.1:raw:ext2 rd.luks=0" ext2 || return 1
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
     client_test "NBD root=nbd:IP:port:fstype:fsopts" 52:54:00:12:34:00 \
Harald Hoyer 7ba020
-        "root=nbd:192.168.50.1:2000:ext2:errors=panic rd.luks=0" \
Harald Hoyer 7ba020
+        "root=nbd:192.168.50.1:raw:ext2:errors=panic rd.luks=0" \
Harald Hoyer 7ba020
         ext2 errors=panic || return 1
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
     client_test "NBD Bridge root=nbd:IP:port:fstype:fsopts" 52:54:00:12:34:00 \
Harald Hoyer 7ba020
-        "root=nbd:192.168.50.1:2000:ext2:errors=panic bridge rd.luks=0" \
Harald Hoyer 7ba020
+        "root=nbd:192.168.50.1:raw:ext2:errors=panic bridge rd.luks=0" \
Harald Hoyer 7ba020
         ext2 errors=panic || return 1
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
      # There doesn't seem to be a good way to validate the NBD options, so
Harald Hoyer 7ba020
      # just check that we don't screw up the other options
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
     client_test "NBD root=nbd:IP:port:::NBD opts" 52:54:00:12:34:00 \
Harald Hoyer 7ba020
-        "root=nbd:192.168.50.1:2000:::bs=2048 rd.luks=0" || return 1
Harald Hoyer 7ba020
+        "root=nbd:192.168.50.1:raw:::bs=2048 rd.luks=0" || return 1
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
     client_test "NBD root=nbd:IP:port:fstype::NBD opts" 52:54:00:12:34:00 \
Harald Hoyer 7ba020
-        "root=nbd:192.168.50.1:2000:ext2::bs=2048 rd.luks=0" ext2 || return 1
Harald Hoyer 7ba020
+        "root=nbd:192.168.50.1:raw:ext2::bs=2048 rd.luks=0" ext2 || return 1
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
     client_test "NBD root=nbd:IP:port:fstype:fsopts:NBD opts" \
Harald Hoyer 7ba020
         52:54:00:12:34:00 \
Harald Hoyer 7ba020
-        "root=nbd:192.168.50.1:2000:ext2:errors=panic:bs=2048 rd.luks=0" \
Harald Hoyer 7ba020
+        "root=nbd:192.168.50.1:raw:ext2:errors=panic:bs=2048 rd.luks=0" \
Harald Hoyer 7ba020
         ext2 errors=panic || return 1
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
     # DHCP root-path parsing
Harald Hoyer 7ba020
@@ -156,7 +156,7 @@ client_run() {
Harald Hoyer 7ba020
     # netroot handling
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
     client_test "NBD netroot=nbd:IP:port" 52:54:00:12:34:00 \
Harald Hoyer 7ba020
-        "netroot=nbd:192.168.50.1:2000 rd.luks=0" || return 1
Harald Hoyer 7ba020
+        "netroot=nbd:192.168.50.1:raw rd.luks=0" || return 1
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
     client_test "NBD netroot=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
Harald Hoyer 7ba020
         52:54:00:12:34:04 "netroot=dhcp rd.luks=0" ext2 errors=panic || return 1
Harald Hoyer 7ba020
@@ -167,7 +167,7 @@ client_run() {
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
     client_test "NBD root=LABEL=dracut netroot=nbd:IP:port" \
Harald Hoyer 7ba020
         52:54:00:12:34:00 \
Harald Hoyer 7ba020
-        "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut netroot=nbd:192.168.50.1:2001" || return 1
Harald Hoyer 7ba020
+        "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut netroot=nbd:192.168.50.1:encrypted" || return 1
Harald Hoyer 7ba020
 
Harald Hoyer 7ba020
     # XXX This should be ext2,errors=panic but that doesn't currently
Harald Hoyer 7ba020
     # XXX work when you have a real root= line in addition to netroot=
Harald Hoyer 7ba020
@@ -308,11 +308,20 @@ make_server_root() {
Harald Hoyer 7ba020
         mkdir -p "$initdir"
Harald Hoyer 7ba020
         (
Harald Hoyer 7ba020
             cd "$initdir";
Harald Hoyer 7ba020
-            mkdir -p dev sys proc etc var/run var/lib/dhcpd tmp
Harald Hoyer 7ba020
+            mkdir -p dev sys proc etc var/run var/lib/dhcpd tmp etc/nbd-server
Harald Hoyer 7ba020
         )
Harald Hoyer 7ba020
+        cat > "$initdir/etc/nbd-server/config" <
Harald Hoyer 7ba020
+[generic]
Harald Hoyer 7ba020
+[raw]
Harald Hoyer 7ba020
+exportname = /dev/sdb
Harald Hoyer 7ba020
+port = 2000
Harald Hoyer 7ba020
+[encrypted]
Harald Hoyer 7ba020
+exportname = /dev/sdc
Harald Hoyer 7ba020
+port = 2001
Harald Hoyer 7ba020
+EOF
Harald Hoyer 7ba020
         inst_multiple sh ls shutdown poweroff stty cat ps ln ip \
Harald Hoyer 7ba020
             dmesg mkdir cp ping grep \
Harald Hoyer 7ba020
-            sleep nbd-server chmod
Harald Hoyer 7ba020
+            sleep nbd-server chmod modprobe vi
Harald Hoyer 7ba020
         for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
Harald Hoyer 7ba020
             [ -f ${_terminfodir}/l/linux ] && break
Harald Hoyer 7ba020
         done