network: add support for netroot=...
This adds support for a command line option netroot=, which is currently equivalent to root=. This will allow us to break out handling in NBD and iSCSI to support constructs such as "root=LABEL=/ netroot=dhcp" to make use of our block device handling with network attached devices. iSCSI has not been changed in this patch as I don't currently have a way to test it.master
parent
a29f15a5b6
commit
aec48753c2
|
|
@ -1,12 +1,18 @@
|
||||||
# We should go last, and default the root if needed
|
# We should go last, and default the root if needed
|
||||||
|
|
||||||
if [ -z "$root" ]; then
|
if [ -z "$root" -a -z "$netroot" ]; then
|
||||||
root=dhcp
|
netroot=dhcp
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$root" = "dhcp" -a -z "$netroot" ]; then
|
if [ "$root" = "dhcp" -a -z "$netroot" ]; then
|
||||||
rootok=1
|
rootok=1
|
||||||
netroot=dhcp
|
netroot=dhcp
|
||||||
|
unset root
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Cleanup any coversions from root->netroot if they are the same
|
||||||
|
if [ "$netroot" = "$root" ]; then
|
||||||
|
unset root
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${netroot+set}" = "set" ]; then
|
if [ "${netroot+set}" = "set" ]; then
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ fi
|
||||||
# Run the handler; don't store the root, it may change from device to device
|
# Run the handler; don't store the root, it may change from device to device
|
||||||
# XXX other variables to export?
|
# XXX other variables to export?
|
||||||
export NEWROOT
|
export NEWROOT
|
||||||
if $handler $netif $root; then
|
if $handler $netif $netroot; then
|
||||||
# Network rootfs mount successful
|
# Network rootfs mount successful
|
||||||
[ -f /tmp/dhclient.$netif.lease ] && cp /tmp/dhclient.$netif.lease /tmp/net.$netif.lease
|
[ -f /tmp/dhclient.$netif.lease ] && cp /tmp/dhclient.$netif.lease /tmp/net.$netif.lease
|
||||||
[ -f /tmp/dhclient.$netif.dhcpopts ] && cp /tmp/dhclient.$netif.dhcpopts /tmp/net.$netif.dhcpopts
|
[ -f /tmp/dhclient.$netif.dhcpopts ] && cp /tmp/dhclient.$netif.dhcpopts /tmp/net.$netif.dhcpopts
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
if [ "$root" = "dhcp" ]; then
|
if [ "$netroot" = "dhcp" ]; then
|
||||||
if [ -n "$new_root_path" -a -z "${new_root_path%%nbd:*}" ]; then
|
if [ -n "$new_root_path" -a -z "${new_root_path%%nbd:*}" ]; then
|
||||||
root="$new_root_path"
|
netroot="$new_root_path"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${root%nbd:*}" ]; then
|
if [ -z "${netroot%nbd:*}" ]; then
|
||||||
handler=/sbin/nbdroot
|
handler=/sbin/nbdroot
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,13 @@ case "$root" in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ "${root%%:*}" = "nbd" ]; then
|
if [ -z "$netroot" -a -n "$root" -a -z "${root%%nbd:*}" ]; then
|
||||||
|
netroot="$root"
|
||||||
|
unset root
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${netroot%%:*}" = "nbd" ]; then
|
||||||
# XXX validate options here?
|
# XXX validate options here?
|
||||||
# XXX generate udev rules?
|
# XXX generate udev rules?
|
||||||
rootok=1
|
rootok=1
|
||||||
netroot=nbd
|
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -3,47 +3,47 @@
|
||||||
# that the number of colons match what we expect, and our glob didn't
|
# that the number of colons match what we expect, and our glob didn't
|
||||||
# inadvertently match a different handler's.
|
# inadvertently match a different handler's.
|
||||||
#
|
#
|
||||||
if [ "$root" = "dhcp" -o "$root" = "nfs" -o "$root" = "nfs4" ]; then
|
if [ "$netroot" = "dhcp" -o "$netroot" = "nfs" -o "$netroot" = "nfs4" ]; then
|
||||||
nfsver=nfs
|
nfsver=nfs
|
||||||
if [ "$root" = "nfs4" ]; then
|
if [ "$netroot" = "nfs4" ]; then
|
||||||
nfsver=nfs4
|
nfsver=nfs4
|
||||||
fi
|
fi
|
||||||
case "$new_root_path" in
|
case "$new_root_path" in
|
||||||
nfs:*|nfs4:*) root="$new_root_path" ;;
|
nfs:*|nfs4:*) netroot="$new_root_path" ;;
|
||||||
*:/*:*)
|
*:/*:*)
|
||||||
if check_occurances "$new_root_path" ':' 2; then
|
if check_occurances "$new_root_path" ':' 2; then
|
||||||
root="$nfsver:$new_root_path"
|
netroot="$nfsver:$new_root_path"
|
||||||
fi ;;
|
fi ;;
|
||||||
*:/*,*)
|
*:/*,*)
|
||||||
if check_occurances "$new_root_path" ':' 1; then
|
if check_occurances "$new_root_path" ':' 1; then
|
||||||
root="$nfsver:$new_root_path"
|
netroot="$nfsver:$new_root_path"
|
||||||
fi ;;
|
fi ;;
|
||||||
*:/*)
|
*:/*)
|
||||||
if check_occurances "$new_root_path" ':' 1; then
|
if check_occurances "$new_root_path" ':' 1; then
|
||||||
root="$nfsver:$new_root_path:"
|
netroot="$nfsver:$new_root_path:"
|
||||||
fi ;;
|
fi ;;
|
||||||
/*:*)
|
/*:*)
|
||||||
if check_occurances "$new_root_path" ':' 1; then
|
if check_occurances "$new_root_path" ':' 1; then
|
||||||
root="$nfsver::$new_root_path"
|
netroot="$nfsver::$new_root_path"
|
||||||
fi ;;
|
fi ;;
|
||||||
/*,*)
|
/*,*)
|
||||||
if check_occurances "$new_root_path" ':' 0; then
|
if check_occurances "$new_root_path" ':' 0; then
|
||||||
root="$nfsver::$new_root_path"
|
netroot="$nfsver::$new_root_path"
|
||||||
fi ;;
|
fi ;;
|
||||||
/*)
|
/*)
|
||||||
if check_occurances "$new_root_path" ':' 0; then
|
if check_occurances "$new_root_path" ':' 0; then
|
||||||
root="$nfsver::$new_root_path:"
|
netroot="$nfsver::$new_root_path:"
|
||||||
fi ;;
|
fi ;;
|
||||||
'') root="$nfsver:::" ;;
|
'') netroot="$nfsver:::" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${root%%nfs:*}" -o -z "${root%%nfs4:*}" ]; then
|
if [ -z "${netroot%%nfs:*}" -o -z "${netroot%%nfs4:*}" ]; then
|
||||||
# Fill in missing information from DHCP
|
# Fill in missing information from DHCP
|
||||||
nfsver=${root%%:*}; root=${root#*:}
|
nfsver=${netroot%%:*}; netroot=${netroot#*:}
|
||||||
nfsserver=${root%%:*}; root=${root#*:}
|
nfsserver=${netroot%%:*}; netroot=${netroot#*:}
|
||||||
nfspath=${root%%:*}
|
nfspath=${netroot%%:*}
|
||||||
nfsflags=${root#*:}
|
nfsflags=${netroot#*:}
|
||||||
|
|
||||||
# XXX where does dhclient stash the next-server option? Do we care?
|
# XXX where does dhclient stash the next-server option? Do we care?
|
||||||
if [ -z "$nfsserver" -o "$nfsserver" = "$nfspath" ]; then
|
if [ -z "$nfsserver" -o "$nfsserver" = "$nfspath" ]; then
|
||||||
|
|
@ -51,9 +51,9 @@ if [ -z "${root%%nfs:*}" -o -z "${root%%nfs4:*}" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Handle alternate syntax of path,options
|
# Handle alternate syntax of path,options
|
||||||
if [ "$nfsflags" = "$nfspath" -a "${root#*,}" != "$root" ]; then
|
if [ "$nfsflags" = "$nfspath" -a "${netroot#*,}" != "$netroot" ]; then
|
||||||
nfspath=${root%%,*}
|
nfspath=${netroot%%,*}
|
||||||
nfsflags=${root#*,}
|
nfsflags=${netroot#*,}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Catch the case when no additional flags are set
|
# Catch the case when no additional flags are set
|
||||||
|
|
@ -62,6 +62,6 @@ if [ -z "${root%%nfs:*}" -o -z "${root%%nfs4:*}" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# XXX validate we have all the required info?
|
# XXX validate we have all the required info?
|
||||||
root="$nfsver:$nfsserver:$nfspath:$nfsflags"
|
netroot="$nfsver:$nfsserver:$nfspath:$nfsflags"
|
||||||
handler=/sbin/nfsroot
|
handler=/sbin/nfsroot
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#
|
#
|
||||||
# Preferred format:
|
# Preferred format:
|
||||||
# root=nfs[4]:[server:]path[:options]
|
# root=nfs[4]:[server:]path[:options]
|
||||||
|
# netroot=nfs[4]:[server:]path[:options]
|
||||||
#
|
#
|
||||||
# If server is unspecified it will be pulled from one of the following
|
# If server is unspecified it will be pulled from one of the following
|
||||||
# sources, in order:
|
# sources, in order:
|
||||||
|
|
@ -38,9 +39,17 @@ case "$root" in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$root" in
|
if [ -z "$netroot" -a -n "$root" -a -z "${root%%nfs*}" ]; then
|
||||||
|
netroot="$root"
|
||||||
|
unset root
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$netroot" in
|
||||||
nfs|nfs4|nfs:*|nfs4:*)
|
nfs|nfs4|nfs:*|nfs4:*)
|
||||||
rootok=1
|
rootok=1
|
||||||
netroot=nfs
|
if [ -n "$root" -a "$netroot" != "$root" ]; then
|
||||||
|
echo "WARNING: root= and netroot= do not match, ignoring root="
|
||||||
|
fi
|
||||||
|
unset root
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ if [ -z "$rootok" -a -n "${root%%error:*}" ]; then
|
||||||
root="error: No handler for root=${root}"
|
root="error: No handler for root=${root}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${root%%error:*}" ]; then
|
if [ -n "$root" -a -z "${root%%error:*}" ]; then
|
||||||
case "${root%%:*}" in
|
case "${root%%:*}" in
|
||||||
'') echo "FATAL: no root= option specified, and no network support" ;;
|
'') echo "FATAL: no root= option specified, and no network support" ;;
|
||||||
error) echo "FATAL: ${root#error:}" ;;
|
error) echo "FATAL: ${root#error:}" ;;
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,10 @@ test_nfsv3() {
|
||||||
# MAC numbering scheme:
|
# MAC numbering scheme:
|
||||||
# NFSv3: last octect starts at 0x00 and works up
|
# NFSv3: last octect starts at 0x00 and works up
|
||||||
# NFSv4: last octect starts at 0x80 and works up
|
# NFSv4: last octect starts at 0x80 and works up
|
||||||
|
|
||||||
|
client_test "NFSv3 netroot=dhcp DHCP path only" 52:54:00:12:34:00 \
|
||||||
|
"netroot=dhcp" 192.168.50.1 -wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv3 root=dhcp DHCP path only" 52:54:00:12:34:00 \
|
client_test "NFSv3 root=dhcp DHCP path only" 52:54:00:12:34:00 \
|
||||||
"root=dhcp" 192.168.50.1 -wsize=4096 || return 1
|
"root=dhcp" 192.168.50.1 -wsize=4096 || return 1
|
||||||
|
|
||||||
|
|
@ -110,6 +113,9 @@ test_nfsv3() {
|
||||||
client_test "NFSv3 root=/dev/nfs DHCP path only" 52:54:00:12:34:00 \
|
client_test "NFSv3 root=/dev/nfs DHCP path only" 52:54:00:12:34:00 \
|
||||||
"root=/dev/nfs" 192.168.50.1 -wsize=4096 || return 1
|
"root=/dev/nfs" 192.168.50.1 -wsize=4096 || return 1
|
||||||
|
|
||||||
|
client_test "NFSv3 netroot=dhcp DHCP IP:path" 52:54:00:12:34:01 \
|
||||||
|
"netroot=dhcp" 192.168.50.2 -wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv3 root=dhcp DHCP IP:path" 52:54:00:12:34:01 \
|
client_test "NFSv3 root=dhcp DHCP IP:path" 52:54:00:12:34:01 \
|
||||||
"root=dhcp" 192.168.50.2 -wsize=4096 || return 1
|
"root=dhcp" 192.168.50.2 -wsize=4096 || return 1
|
||||||
|
|
||||||
|
|
@ -122,9 +128,16 @@ test_nfsv3() {
|
||||||
client_test "NFSv3 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:02 \
|
client_test "NFSv3 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:02 \
|
||||||
"root=dhcp" 192.168.50.3 -wsize=4096 || return 1
|
"root=dhcp" 192.168.50.3 -wsize=4096 || return 1
|
||||||
|
|
||||||
|
client_test "NFSv3 netroot=dhcp DHCP proto:IP:path:options" \
|
||||||
|
52:54:00:12:34:03 "netroot=dhcp" 192.168.50.3 wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv3 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:03 \
|
client_test "NFSv3 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:03 \
|
||||||
"root=dhcp" 192.168.50.3 wsize=4096 || return 1
|
"root=dhcp" 192.168.50.3 wsize=4096 || return 1
|
||||||
|
|
||||||
|
client_test "NFSv3 netroot=nfs:..." 52:54:00:12:34:04 \
|
||||||
|
"netroot=nfs:192.168.50.1:/nfs/client" 192.168.50.1 \
|
||||||
|
-wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv3 root=nfs:..." 52:54:00:12:34:04 \
|
client_test "NFSv3 root=nfs:..." 52:54:00:12:34:04 \
|
||||||
"root=nfs:192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 || return 1
|
"root=nfs:192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 || return 1
|
||||||
|
|
||||||
|
|
@ -168,24 +181,40 @@ test_nfsv4() {
|
||||||
# server, so put these later in the list to avoid a pause when doing
|
# server, so put these later in the list to avoid a pause when doing
|
||||||
# switch_root
|
# switch_root
|
||||||
|
|
||||||
|
client_test "NFSv4 netroot=nfs4 DHCP path only" 52:54:00:12:34:80 \
|
||||||
|
"netroot=nfs4" 192.168.50.1 -wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv4 root=nfs4 DHCP path only" 52:54:00:12:34:80 \
|
client_test "NFSv4 root=nfs4 DHCP path only" 52:54:00:12:34:80 \
|
||||||
"root=nfs4" 192.168.50.1 -wsize=4096 || return 1
|
"root=nfs4" 192.168.50.1 -wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv4 root=/dev/nfs4 DHCP path only" 52:54:00:12:34:80 \
|
client_test "NFSv4 root=/dev/nfs4 DHCP path only" 52:54:00:12:34:80 \
|
||||||
"root=/dev/nfs4" 192.168.50.1 -wsize=4096 || return 1
|
"root=/dev/nfs4" 192.168.50.1 -wsize=4096 || return 1
|
||||||
|
|
||||||
|
client_test "NFSv4 netroot=nfs4 DHCP IP:path" 52:54:00:12:34:81 \
|
||||||
|
"netroot=nfs4" 192.168.50.2 -wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv4 root=nfs4 DHCP IP:path" 52:54:00:12:34:81 \
|
client_test "NFSv4 root=nfs4 DHCP IP:path" 52:54:00:12:34:81 \
|
||||||
"root=nfs4" 192.168.50.2 -wsize=4096 || return 1
|
"root=nfs4" 192.168.50.2 -wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv4 root=/dev/nfs4 DHCP IP:path" 52:54:00:12:34:81 \
|
client_test "NFSv4 root=/dev/nfs4 DHCP IP:path" 52:54:00:12:34:81 \
|
||||||
"root=/dev/nfs4" 192.168.50.2 -wsize=4096 || return 1
|
"root=/dev/nfs4" 192.168.50.2 -wsize=4096 || return 1
|
||||||
|
|
||||||
|
client_test "NFSv4 netroot=dhcp DHCP proto:IP:path" 52:54:00:12:34:82 \
|
||||||
|
"netroot=dhcp" 192.168.50.3 -wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv4 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:82 \
|
client_test "NFSv4 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:82 \
|
||||||
"root=dhcp" 192.168.50.3 -wsize=4096 || return 1
|
"root=dhcp" 192.168.50.3 -wsize=4096 || return 1
|
||||||
|
|
||||||
|
client_test "NFSv4 netroot=dhcp DHCP proto:IP:path:options" \
|
||||||
|
52:54:00:12:34:83 "netroot=dhcp" 192.168.50.3 wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv4 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:83 \
|
client_test "NFSv4 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:83 \
|
||||||
"root=dhcp" 192.168.50.3 wsize=4096 || return 1
|
"root=dhcp" 192.168.50.3 wsize=4096 || return 1
|
||||||
|
|
||||||
|
client_test "NFSv4 netroot=nfs4:..." 52:54:00:12:34:84 \
|
||||||
|
"netroot=nfs4:192.168.50.1:/client" 192.168.50.1 \
|
||||||
|
-wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv4 root=nfs4:..." 52:54:00:12:34:84 \
|
client_test "NFSv4 root=nfs4:..." 52:54:00:12:34:84 \
|
||||||
"root=nfs4:192.168.50.1:/client" 192.168.50.1 \
|
"root=nfs4:192.168.50.1:/client" 192.168.50.1 \
|
||||||
-wsize=4096 || return 1
|
-wsize=4096 || return 1
|
||||||
|
|
@ -201,8 +230,12 @@ test_nfsv4() {
|
||||||
52:54:00:12:34:84 "root=nfs4 nfsroot=/client,wsize=4096" \
|
52:54:00:12:34:84 "root=nfs4 nfsroot=/client,wsize=4096" \
|
||||||
192.168.50.1 wsize=4096 || return 1
|
192.168.50.1 wsize=4096 || return 1
|
||||||
|
|
||||||
# This one only works with NFSv4 in the test suite -- NFSv3 needs
|
# These two only work with NFSv4 in the test suite -- NFSv3 needs
|
||||||
# a /nfs prefix due to our server configuration
|
# a /nfs prefix due to our server configuration
|
||||||
|
|
||||||
|
client_test "NFSv4 netroot=nfs4" 52:54:00:12:34:84 \
|
||||||
|
"netroot=nfs4" 192.168.50.1 -wsize=4096 || return 1
|
||||||
|
|
||||||
client_test "NFSv4 root=nfs4" 52:54:00:12:34:84 \
|
client_test "NFSv4 root=nfs4" 52:54:00:12:34:84 \
|
||||||
"root=nfs4" 192.168.50.1 -wsize=4096 || return 1
|
"root=nfs4" 192.168.50.1 -wsize=4096 || return 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,14 @@ test_run() {
|
||||||
|
|
||||||
client_test "NBD root=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
|
client_test "NBD root=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
|
||||||
52:54:00:12:34:04 "root=dhcp" ext2 errors=panic || return 1
|
52:54:00:12:34:04 "root=dhcp" ext2 errors=panic || return 1
|
||||||
|
|
||||||
|
# netroot handling
|
||||||
|
|
||||||
|
client_test "NBD netroot=nbd:IP:port" 52:54:00:12:34:00 \
|
||||||
|
"netroot=nbd:192.168.50.1:2000" || return 1
|
||||||
|
|
||||||
|
client_test "NBD netroot=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
|
||||||
|
52:54:00:12:34:04 "netroot=dhcp" ext2 errors=panic || return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
make_client_root() {
|
make_client_root() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue