]> code.ossystems Code Review - openembedded-core.git/commitdiff
nfsroot: allow nfsroot to survive netbase init
authorQing He <qing.he@intel.com>
Tue, 18 May 2010 16:24:25 +0000 (00:24 +0800)
committerRichard Purdie <rpurdie@linux.intel.com>
Mon, 9 Aug 2010 15:54:08 +0000 (16:54 +0100)
The patch adds a script in /etc/network/if-pre-up.d,
the script returns 1 (effectly skip the ifup on the iface) iff:
  1. there is a "* / (nfs|nfs4) *" entry in the /proc/mounts
  2. the addr field in that entry is routed using $IFACE

Signed-off-by: Qing He <qing.he@intel.com>
meta/packages/netbase/netbase/nfsroot [new file with mode: 0644]
meta/packages/netbase/netbase_4.41.bb

diff --git a/meta/packages/netbase/netbase/nfsroot b/meta/packages/netbase/netbase/nfsroot
new file mode 100644 (file)
index 0000000..fc384a8
--- /dev/null
@@ -0,0 +1,39 @@
+#! /bin/sh
+
+# In case the interface is used as nfsroot, avoid ifup, otherwise
+# nfsroot may lose response
+
+nfsroot=0
+
+if test "x$IFACE" = xlo ; then
+       exit 0
+fi
+
+exec 9<&0 < /proc/mounts
+while read dev mtpt fstype rest; do
+    if test $mtpt = "/" ; then
+        case $fstype in
+            nfs | nfs4)
+                nfsroot=1
+                nfs_addr=`echo $rest | sed -e 's/^.*addr=\([0-9.]*\).*$/\1/'`
+                break
+                ;;
+            *)
+                ;;
+        esac
+    fi
+done
+exec 0<&9 9<&-
+
+test $nfsroot -eq 0 && exit 0
+
+if test -x /sbin/ip ; then
+    nfs_iface=`ip route get $nfs_addr | grep dev | sed -e 's/^.*dev \([-a-z0-9.]*\).*$/\1/'`
+fi
+
+if test "x$IFACE" = "x$nfs_iface" ; then
+    echo "ifup skipped for nfsroot interface $nfs_iface"
+    exit 1
+fi
+
+exit 0
index a3e2e87424c00ea6996b9448e7eeefc3cef4da33..88b524ffd2f8ae0cd36886fde3329d7ecb079578 100644 (file)
@@ -17,7 +17,8 @@ INITSCRIPT_PARAMS_slugos = "start 42 S 0 6 ."
 SRC_URI = "${DEBIAN_MIRROR}/main/n/netbase/netbase_${PV}.tar.gz \
            file://init \
            file://hosts \
-           file://interfaces"
+           file://interfaces \
+           file://nfsroot"
 
 do_install () {
        install -d ${D}${sysconfdir}/init.d \
@@ -33,6 +34,7 @@ do_install () {
        install -m 0644 etc-protocols ${D}${sysconfdir}/protocols
        install -m 0644 etc-services ${D}${sysconfdir}/services
        install -m 0644 ${WORKDIR}/interfaces ${D}${sysconfdir}/network/interfaces
+       install -m 0755 ${WORKDIR}/nfsroot ${D}${sysconfdir}/network/if-pre-up.d
 
        # Disable network manager on machines that commonly do NFS booting
        case "${MACHINE}" in