]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
NFS root: add support for default root path and %s substitution
authorDavid Dillow <dave@thedillows.org>
Sun, 7 Jun 2009 21:17:48 +0000 (17:17 -0400)
committerDavid Dillow <dave@thedillows.org>
Sun, 7 Jun 2009 21:17:48 +0000 (17:17 -0400)
This implements a default path of /tftpboot/%s if no path is provided,
and adds host name substitution for %s, with a fall back to the IP address,
as provided by the kernel's nfsroot handling.

The test suite is updated to test this functionality.

modules.d/95nfs/nfs-netroot.sh
modules.d/95nfs/nfsroot
test/TEST-20-NFS/exports
test/TEST-20-NFS/server-init
test/TEST-20-NFS/test.sh

index 8d552e9e6d653e956fc9370058b88c87eb09dc5c..365d3940c74219007f7b260a0d5ca8c0f76003c5 100755 (executable)
@@ -34,6 +34,7 @@ if [ "$root" = "dhcp" -o "$root" = "nfs" -o "$root" = "nfs4" ]; then
        if check_occurances "$new_root_path" ':' 0; then
            root="$nfsver::$new_root_path:"
        fi ;;
+    '') root="$nfsver:::" ;;
     esac
 fi
 
index da002c53dc9f5760fa3b1f9ea02099102cadf884..cd3bc7cdd6e18857fb5e273225d773cccf3b5fda 100755 (executable)
@@ -21,6 +21,20 @@ nfsserver=${root%%:*}; root=${root#*:}
 nfspath=${root%%:*}
 flags=${root#*:}
 
+[ -z "$nfspath" ] && nfspath=/tftpboot/%s
+
+# Kernel replaces first %s with host name, and falls back to the ip address
+# if it isn't set. Only the first %s is substituted.
+#
+if [ "${nfspath#*%s}" != "$nfspath" ]; then
+    ip=$(ip -o -f inet addr show $netif)
+    ip=${ip%%/*}
+    ip=${ip##* }
+    read node < /proc/sys/kernel/hostname
+    [ "$node" = "(none)" ] && node=$ip
+    nfspath=${nfspath%%%s*}$node${nfspath#*%s}
+fi
+
 # look through the flags and see if any are overridden by the command line
 # Append a , so we know we terminate
 flags=${flags},
index 27018771fbc7c316afbe47d1d6a3d47dd019ab3b..95619e7122328009961c257232e9ebab2d6bc116 100644 (file)
@@ -1,2 +1,5 @@
 /nfs           192.168.50.0/24(ro,fsid=0,insecure,no_subtree_check,no_root_squash)
 /nfs/client    192.168.50.0/24(ro,insecure,no_subtree_check,no_root_squash)
+/nfs/nfs3-5    192.168.50.0/24(ro,insecure,no_subtree_check,no_root_squash,nohide)
+/nfs/ip/192.168.50.101 192.168.50.0/24(ro,insecure,no_subtree_check,no_root_squash,nohide)
+/nfs/tftpboot/nfs4-5   192.168.50.0/24(ro,insecure,no_subtree_check,no_root_squash,nohide)
index 67af8fa9dc3b5aa1f8a60e2a6141ed4a82a9b716..ed7e43ecc9fde9e13f709a436cb857edb3042bd5 100755 (executable)
@@ -10,6 +10,9 @@ ip addr add 192.168.50.1/24 dev eth0
 ip addr add 192.168.50.2/24 dev eth0
 ip addr add 192.168.50.3/24 dev eth0
 ip link set eth0 up
+mount --bind /nfs/client /nfs/nfs3-5
+mount --bind /nfs/client /nfs/ip/192.168.50.101
+mount --bind /nfs/client /nfs/tftpboot/nfs4-5
 modprobe sunrpc
 mount -t rpc_pipefs sunrpc /var/lib/nfs/rpc_pipefs
 rpcbind
index 4a997c46b2f8308147d01e85f4791f1d961addc7..658336669c41d0781596ae77a36f1dc7eea49980 100755 (executable)
@@ -137,6 +137,15 @@ test_nfsv3() {
     client_test "NFSv3 root=nfs nfsroot=/nfs/client" 52:54:00:12:34:04 \
        "root=nfs nfsroot=/nfs/client" 192.168.50.1 -wsize=4096 || return 1
 
+    client_test "NFSv3 root=nfs nfsroot=/nfs/%s" 52:54:00:12:34:04 \
+       "root=nfs nfsroot=/nfs/%s" 192.168.50.1 -wsize=4096 || return 1
+
+    client_test "NFSv3 root=nfs nfsroot=/nfs/ip/%s no host name (use IP)" \
+       52:54:00:12:34:7f \
+       "root=nfs nfsroot=/nfs/ip/%s \
+               ip=192.168.50.101:192.168.50.1::255.255.255.0::eth0:static" \
+       192.168.50.1 -wsize=4096 || return 1
+
     client_test "NFSv3 root=nfs nfsroot=/nfs/client,wsize=4096" \
        52:54:00:12:34:04 "root=nfs nfsroot=/nfs/client,wsize=4096" \
        192.168.50.1 wsize=4096 || return 1
@@ -185,6 +194,11 @@ test_nfsv4() {
        52:54:00:12:34:84 "root=nfs4 nfsroot=/client,wsize=4096" \
        192.168.50.1 wsize=4096 || return 1
 
+    # This one only works with NFSv4 in the test suite -- NFSv3 needs
+    # a /nfs prefix due to our server configuration
+    client_test "NFSv4 root=nfs4" 52:54:00:12:34:84 \
+       "root=nfs4" 192.168.50.1 -wsize=4096 || return 1
+
     client_test "NFSv4 root=nfs4 DHCP path,options" \
        52:54:00:12:34:85 "root=nfs4" 192.168.50.1 wsize=4096 || return 1
 
@@ -267,6 +281,10 @@ test_setup() {
        ldconfig -n -r "$initdir" /lib* /usr/lib*
     )
 
+    mkdir -p mnt/nfs/nfs3-5
+    mkdir -p mnt/nfs/ip/192.168.50.101
+    mkdir -p mnt/nfs/tftpboot/nfs4-5
+
     sudo umount mnt
     rm -fr mnt