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

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