Skip to contentSkip to conversation

allow ifup bring up network mannually even without netroot

PATCH Superseded Dave Young 2 participants 3 messages Dec 29, 2011 2 messages not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Dave Young

author
#0 lore raw

PATCH 1/1 allow ifup bring up network mannually even without netroot

sometimes we need bring up network even without netroot

Here implement this by adding one param to ifup script, user can use:
/sbin/ifup $netif -m; to bring up eth0, note currently ifup will see anything in param $2 as same.

ifup eth0 -m will create /tmp/net.eth0.mannual stamp file, later dhclient-script can check this and pass $2 to netroot, then netroot script will bring eth0 up

---
 modules.d/40network/dhclient-script |    7 ++
 modules.d/40network/ifup            |   17 +++++--
 modules.d/40network/netroot         |   85 +++++++++++++++++++-----------------
 3 files changed, 67 insertions(+), 42 deletions(-)
modules.d/40network/dhclient-script +6 -1
Index: dracut/modules.d/40network/dhclient-script
===================================================================
@@ -74,7 +74,12 @@ case $reason in
             echo "$line"
         done >/tmp/dhclient.$netif.dhcpopts
         echo online > /sys/class/net/$netif/uevent
-        initqueue --onetime --name netroot-$netif netroot $netif
+        if [ -e /tmp/net.$netif.mannual ]; then
+            /sbin/netroot $netif -m
+            rm -f /tmp/net.$netif.mannual
+        else
+            initqueue --onetime --name netroot-$netif netroot $netif
+        fi
         ;;
     *) echo "dhcp: $reason";;
 esac
modules.d/40network/ifup +14 -3
Index: dracut/modules.d/40network/ifup
===================================================================
@@ -5,6 +5,8 @@
 # We don't need to check for ip= errors here, that is handled by the
 # cmdline parser script
 #
+# without $2 means this is for real netroot case
+# or it is for mannually bring up network ie. for kdump scp vmcore
 PATH=/usr/sbin:/usr/bin:/sbin:/bin
 
 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
@@ -50,7 +52,11 @@ do_ipv6auto() {
 
 
     echo online > /sys/class/net/$netif/uevent
-    initqueue --onetime --name netroot-$netif netroot $netif
+    if [ -z "$2" ]; then
+        initqueue --onetime --name netroot-$netif netroot $netif
+    else
+        /sbin/netroot $netif -m
+    fi
 }
 
 # Handle static ip configuration
@@ -77,7 +83,11 @@ do_static() {
     fi >> /tmp/net.$netif.resolv.conf
 
     echo online > /sys/class/net/$netif/uevent
-    initqueue --onetime --name netroot-$netif netroot $netif
+    if [ -z "$2" ]; then
+        initqueue --onetime --name netroot-$netif netroot $netif
+    else
+        /sbin/netroot $netif -m
+    fi
 }
 
 export PS4="ifup.$1.$$ + "
@@ -117,7 +127,8 @@ fi
 [ -f "/tmp/net.$netif.up" ] && exit 0
 [ -f "/tmp/root.info" ] || exit 0
 . /tmp/root.info
-[ -z "$netroot" ] && exit 0
+[ -z "$netroot" ] && [ -z $2 ] && exit 0
+[ -n "$2" ] && >/tmp/net.$netif.mannual
 
 # loopback is always handled the same way
 if [ "$netif" = "lo" ] ; then
modules.d/40network/netroot +47 -38

107 lines not on this page · raw message

A message that is not in the archive (sent off-list or not yet received): 20111229031342.GA6829-4/[email protected]

#2 lore raw
Quoted 9 lines · Dave Young

sometimes we need bring up network even without netroot

Here implement this by adding one param to ifup script, user can use:
/sbin/ifup $netif -m; to bring up eth0, note currently ifup will see anything in param $2 as same.

ifup eth0 -m will create /tmp/net.eth0.mannual stamp file, later dhclient-script can check this and pass $2 to netroot, then netroot script will bring eth0 up

'Manual' is misspelled throughout the patch, and your commit message is a bit broken -- you say '/sbin/ifup $netif -m' will bring up eth0. You put the command line that actually would in the next paragraph.

What's the use case? I'm sure there probably is one, but it's better to be specific in the commit message when giving an example. I'm assuming this is for your kdump work?

modules.d/40network/dhclient-script case $reason in · line 82

Quoted 13 lines
modules.d/40network/dhclient-script +6 -1
@@ -74,7 +74,12 @@ case $reason in
             echo "$line"
         done >/tmp/dhclient.$netif.dhcpopts
         echo online > /sys/class/net/$netif/uevent
-        initqueue --onetime --name netroot-$netif netroot $netif
+        if [ -e /tmp/net.$netif.mannual ]; then
+            /sbin/netroot $netif -m
+            rm -f /tmp/net.$netif.mannual
+        else
+            initqueue --onetime --name netroot-$netif netroot $netif
+        fi

And if we want to use kdump with NFS root?

I think it would be cleaner to add either conditionally add netroot to the initqueue only when there is actually a netroot used, or make /sbin/netroot not care... it currently exits with a nonzero value if /tmp/root.info isn't there, or $netroot is empty. I assume that causes problems elsewhere -- I haven't kept up with dracut for a while -- but perhaps not and it is safe to just always call it.

Quoted 4 lines

modules.d/40network/ifup do_ipv6auto() { · line 60

Quoted 10 lines
modules.d/40network/ifup +5 -1
@@ -50,7 +52,11 @@ do_ipv6auto() {
 
 
     echo online > /sys/class/net/$netif/uevent
-    initqueue --onetime --name netroot-$netif netroot $netif
+    if [ -z "$2" ]; then
+        initqueue --onetime --name netroot-$netif netroot $netif
+    else
+        /sbin/netroot $netif -m
+    fi
 }

Same comment here, with the added bonus that "$2" will reference the function's arguments, not the scripts, so you'll always do the initqueue call.

Why are you wanting to run netroot immediately if you aren't using a network root?

If it's just to copy the configuration over when you have a kdump, is it going to hurt things to not copy in that case? Do the network scripts in the real root care? They have to handle the case when you don't have a kdump anyway -- assuming you don't bring up the network in dracut unless you have a dump push.

If they really do care, then perhaps consider splitting out the copying of the config to a separate step that can be shared, rather than making things uglier than they already are. It'd probably be a good cleanup on it's own merits.

Dave

A message that is not in the archive (sent off-list or not yet received): 1325149504.19896.13.camel-1q1vX8mYZiGLUyTwlgNVppKKF0rrzTr+@public.gmane.org

author
#4 lore raw
Quoted 7 lines · David Dillow
Quoted 6 lines · Dave Young

sometimes we need bring up network even without netroot

Here implement this by adding one param to ifup script, user can use:
/sbin/ifup $netif -m; to bring up eth0, note currently ifup will see anything in param $2 as same.

Quoted 7 lines
Quoted 3 lines

ifup eth0 -m will create /tmp/net.eth0.mannual stamp file, later dhclient-script can check this and pass $2 to netroot, then netroot script will bring eth0 up

'Manual' is misspelled throughout the patch, and your commit message is a bit broken -- you say '/sbin/ifup $netif -m' will bring up eth0. You put the command line that actually would in the next paragraph.

Thanks for comments.
Will check and fix the spelling.
For broken commit message you means 's/$netif/eth0' ? will fix

Quoted 4 lines

What's the use case? I'm sure there probably is one, but it's better to be specific in the commit message when giving an example. I'm assuming this is for your kdump work?

Yes, kdump will need scp vmcore to remote machine which need net up without netroot
Also will add to v2 patch description

Quoted 17 lines
Quoted 5 lines

modules.d/40network/dhclient-script case $reason in · line 82

Quoted 10 lines
modules.d/40network/dhclient-script +6 -1
@@ -74,7 +74,12 @@ case $reason in
             echo "$line"
         done >/tmp/dhclient.$netif.dhcpopts
         echo online > /sys/class/net/$netif/uevent
-        initqueue --onetime --name netroot-$netif netroot $netif
+        if [ -e /tmp/net.$netif.mannual ]; then
+            /sbin/netroot $netif -m
+            rm -f /tmp/net.$netif.mannual
+        else
+            initqueue --onetime --name netroot-$netif netroot $netif
+        fi

And if we want to use kdump with NFS root?

If nfsroot is already mounted as sysroot, ifup eth0 -m will return as nop; If ifup eth0 -m run firstly then the shared codes will pass-through and still will run netroot specific code.

Quoted 7 lines

I think it would be cleaner to add either conditionally add netroot to the initqueue only when there is actually a netroot used, or make /sbin/netroot not care... it currently exits with a nonzero value if /tmp/root.info isn't there, or $netroot is empty. I assume that causes problems elsewhere -- I haven't kept up with dracut for a while -- but perhaps not and it is safe to just always call it.

I'm not sure I fully understand your option. can you elaborate more detail?

Quoted 7 lines
Quoted 7 lines
modules.d/40network/ifup +0 -0
@@ -50,7 +52,11 @@ do_ipv6auto() {
 
 
Quoted 12 lines

modules.d/40network/ifup do_ipv6auto() { · line 60

Quoted 8 lines
modules.d/40network/ifup +5 -1
     echo online > /sys/class/net/$netif/uevent
-    initqueue --onetime --name netroot-$netif netroot $netif
+    if [ -z "$2" ]; then
+        initqueue --onetime --name netroot-$netif netroot $netif
+    else
+        /sbin/netroot $netif -m
+    fi
 }

Same comment here, with the added bonus that "$2" will reference the function's arguments, not the scripts, so you'll always do the initqueue call.

Good catch, will fix

Quoted 3 lines

Why are you wanting to run netroot immediately if you aren't using a network root?

I want it behave like a manual operation.

Quoted 6 lines

If it's just to copy the configuration over when you have a kdump, is it going to hurt things to not copy in that case? Do the network scripts in the real root care? They have to handle the case when you don't have a kdump anyway -- assuming you don't bring up the network in dracut unless you have a dump push.

we need to scp to nics other than nfs root nic also.

Quoted 7 lines

If they really do care, then perhaps consider splitting out the copying of the config to a separate step that can be shared, rather than making things uglier than they already are. It'd probably be a good cleanup on it's own merits.

I firstly tried to split the code and isolate some code out, but finally find it become more complex become current dracut is fully oriented to rootfs mounting...

Quoted 5 lines

Dave

Signature · 2 lines
Thanks
Dave