Patchwork connman: ignore the networking device which nfs for rootfs is working on

login
register
mail settings
Submitter rongqing.li@windriver.com
Date Oct. 17, 2013, 8:12 a.m.
Message ID <1381997565-10172-1-git-send-email-rongqing.li@windriver.com>
Download mbox | patch
Permalink /patch/60061/
State New
Headers show

Comments

rongqing.li@windriver.com - Oct. 17, 2013, 8:12 a.m.
From: Roy Li <rongqing.li@windriver.com>

Create connmand-nfs.service, which will run a script to ignore the
networking device when root is nfs.
Connmand-nfs.service will be run only when root is not nfs

Signed-off-by: Roy Li <rongqing.li@windriver.com>
---
 meta/recipes-connectivity/connman/connman.inc      |   17 +++++---
 .../connman/connman/connmand-nfs                   |   42 ++++++++++++++++++++
 .../connman/connman/nfs-connman.service            |   15 +++++++
 meta/recipes-connectivity/connman/connman_1.17.bb  |    2 +
 4 files changed, 70 insertions(+), 6 deletions(-)
 create mode 100644 meta/recipes-connectivity/connman/connman/connmand-nfs
 create mode 100644 meta/recipes-connectivity/connman/connman/nfs-connman.service
rongqing.li@windriver.com - Oct. 17, 2013, 8:24 a.m.
Drop it, the commit header is wrong

On 10/17/2013 04:12 PM, rongqing.li@windriver.com wrote:
> From: Roy Li <rongqing.li@windriver.com>
>
> Create connmand-nfs.service, which will run a script to ignore the
> networking device when root is nfs.
> Connmand-nfs.service will be run only when root is not nfs
>
> Signed-off-by: Roy Li <rongqing.li@windriver.com>
> ---
>   meta/recipes-connectivity/connman/connman.inc      |   17 +++++---
>   .../connman/connman/connmand-nfs                   |   42 ++++++++++++++++++++
>   .../connman/connman/nfs-connman.service            |   15 +++++++
>   meta/recipes-connectivity/connman/connman_1.17.bb  |    2 +
>   4 files changed, 70 insertions(+), 6 deletions(-)
>   create mode 100644 meta/recipes-connectivity/connman/connman/connmand-nfs
>   create mode 100644 meta/recipes-connectivity/connman/connman/nfs-connman.service
>
> diff --git a/meta/recipes-connectivity/connman/connman.inc b/meta/recipes-connectivity/connman/connman.inc
> index 37ce3ec..ebfef35 100644
> --- a/meta/recipes-connectivity/connman/connman.inc
> +++ b/meta/recipes-connectivity/connman/connman.inc
> @@ -64,7 +64,7 @@ python __anonymous () {
>       d.setVar('SYSTEMD_PACKAGES', systemd_packages)
>   }
>
> -SYSTEMD_SERVICE_${PN} = "connman.service"
> +SYSTEMD_SERVICE_${PN} = "connman.service nfs-connman.service"
>   SYSTEMD_SERVICE_${PN}-vpn = "connman-vpn.service"
>   SYSTEMD_WIRED_SETUP = "ExecStartPre=-${libdir}/connman/wired-setup"
>
> @@ -84,10 +84,15 @@ do_compile_append() {
>   }
>
>   do_install_append() {
> -	if ${@base_contains('DISTRO_FEATURES','sysvinit','true','false',d)}; then
> -		install -d ${D}${sysconfdir}/init.d
> -		install -m 0755 ${WORKDIR}/connman ${D}${sysconfdir}/init.d/connman
> -		sed -i s%@LIBDIR@%${libdir}% ${D}${sysconfdir}/init.d/connman
> +	install -d ${D}${sysconfdir}/init.d
> +	install -m 0755 ${WORKDIR}/connman ${D}${sysconfdir}/init.d/connman
> +	sed -i s%@LIBDIR@%${libdir}% ${D}${sysconfdir}/init.d/connman
> +
> +	if ${@base_contains('DISTRO_FEATURES','systemd','true','false',d)}; then
> +		install -m 0755 ${WORKDIR}/connmand-nfs ${D}${sbindir}/
> +		install -m 0644 ${WORKDIR}/nfs-connman.service  ${D}/${systemd_unitdir}/system/
> +		sed -i "3 i ConditionKernelCommandLine=!root=/dev/nfs" \
> +		${D}${systemd_unitdir}/system/connman.service
>   	fi
>
>   	install -d ${D}${bindir}
> @@ -165,7 +170,7 @@ FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*.so.* \
>               ${libdir}/connman/plugins \
>               ${sysconfdir} ${sharedstatedir} ${localstatedir} \
>               ${base_bindir}/* ${base_sbindir}/* ${base_libdir}/*.so* ${datadir}/${PN} \
> -            ${datadir}/dbus-1/system-services/*"
> +            ${datadir}/dbus-1/system-services/* ${systemd_unitdir}/system/nfs-connman.service"
>
>   FILES_${PN}-dbg += "${libdir}/connman/*/.debug"
>
> diff --git a/meta/recipes-connectivity/connman/connman/connmand-nfs b/meta/recipes-connectivity/connman/connman/connmand-nfs
> new file mode 100644
> index 0000000..1058787
> --- /dev/null
> +++ b/meta/recipes-connectivity/connman/connman/connmand-nfs
> @@ -0,0 +1,42 @@
> +#!/bin/sh
> +
> +nfsroot=0
> +
> +exec 9<&0 < /proc/mounts
> +while read dev mtpt fstype rest; do
> +	if test $mtpt = "/" ; then
> +		case $fstype in
> +		    nfs | nfs4)
> +			nfsroot=1
> +			break
> +			;;
> +		    *)
> +			;;
> +		esac
> +	fi
> +done
> +
> +EXTRA_PARAM=""
> +if test $nfsroot -eq 1 ; then
> +    NET_DEVS=`cat /proc/net/dev | sed -ne 's/^\([a-zA-Z0-9 ]*\):.*$/\1/p'`
> +    NET_ADDR=`cat /proc/cmdline | sed -ne 's/^.*ip=\([^ :]*\).*$/\1/p'`
> +
> +    if [ ! -z "$NET_ADDR" ]; then
> +	if [ "$NET_ADDR" = dhcp ]; then
> +	    ethn=`ifconfig | grep "^eth" | sed -e "s/\(eth[0-9]\)\(.*\)/\1/"`
> +	    if [ ! -z "$ethn" ]; then
> +		EXTRA_PARAM="-I $ethn"
> +	    fi
> +	else
> +	    for i in $NET_DEVS; do
> +		ADDR=`ifconfig $i | sed 's/addr://g' | sed -ne 's/^.*inet \([0-9.]*\) .*$/\1/p'`
> +		if [ "$NET_ADDR" = "$ADDR" ]; then
> +		    EXTRA_PARAM="-I $i"
> +		    break
> +		fi
> +	    done
> +	fi
> +    fi
> +fi
> +
> +/usr/sbin/connmand -n $EXTRA_PARAM
> diff --git a/meta/recipes-connectivity/connman/connman/nfs-connman.service b/meta/recipes-connectivity/connman/connman/nfs-connman.service
> new file mode 100644
> index 0000000..1cb82b8
> --- /dev/null
> +++ b/meta/recipes-connectivity/connman/connman/nfs-connman.service
> @@ -0,0 +1,15 @@
> +[Unit]
> +Description=Connection service when root is /dev/nfs
> +ConditionKernelCommandLine=root=/dev/nfs
> +After=syslog.target
> +
> +[Service]
> +Type=dbus
> +BusName=net.connman
> +Restart=on-failure
> +ExecStartPre=-/usr/lib64/connman/wired-setup
> +ExecStart=/bin/sh /usr/sbin/connmand-nfs
> +StandardOutput=null
> +
> +[Install]
> +WantedBy=multi-user.target
> diff --git a/meta/recipes-connectivity/connman/connman_1.17.bb b/meta/recipes-connectivity/connman/connman_1.17.bb
> index 461157f..9e8112c 100644
> --- a/meta/recipes-connectivity/connman/connman_1.17.bb
> +++ b/meta/recipes-connectivity/connman/connman_1.17.bb
> @@ -4,6 +4,8 @@ SRC_URI  = "${KERNELORG_MIRROR}/linux/network/${BPN}/${BP}.tar.xz \
>               file://0001-plugin.h-Change-visibility-to-default-for-debug-symb.patch \
>               file://add_xuser_dbus_permission.patch \
>               file://connman \
> +            file://connmand-nfs \
> +            file://nfs-connman.service \
>               "
>
>   SRC_URI[md5sum] = "dd4a13f789de1b69fcddf0cf613f2d5b"
>
Koen Kooi - Oct. 17, 2013, 10:14 a.m.
Op 17 okt. 2013, om 10:12 heeft rongqing.li@windriver.com het volgende geschreven:

> From: Roy Li <rongqing.li@windriver.com>
> 
> Create connmand-nfs.service, which will run a script to ignore the
> networking device when root is nfs.
> Connmand-nfs.service will be run only when root is not nfs

You when it *is* on nfs, since the it tests for root=/dev/nfs being present

> diff --git a/meta/recipes-connectivity/connman/connman/nfs-connman.service b/meta/recipes-connectivity/connman/connman/nfs-connman.service
> new file mode 100644
> index 0000000..1cb82b8
> --- /dev/null
> +++ b/meta/recipes-connectivity/connman/connman/nfs-connman.service
> @@ -0,0 +1,15 @@
> +[Unit]
> +Description=Connection service when root is /dev/nfs
> +ConditionKernelCommandLine=root=/dev/nfs
> +After=syslog.target
> +
> +[Service]
> +Type=dbus
> +BusName=net.connman
> +Restart=on-failure
> +ExecStartPre=-/usr/lib64/connman/wired-setup
> +ExecStart=/bin/sh /usr/sbin/connmand-nfs

And as I said before, these hardcoded paths are not going to work.

Patch

diff --git a/meta/recipes-connectivity/connman/connman.inc b/meta/recipes-connectivity/connman/connman.inc
index 37ce3ec..ebfef35 100644
--- a/meta/recipes-connectivity/connman/connman.inc
+++ b/meta/recipes-connectivity/connman/connman.inc
@@ -64,7 +64,7 @@  python __anonymous () {
     d.setVar('SYSTEMD_PACKAGES', systemd_packages)
 }
 
-SYSTEMD_SERVICE_${PN} = "connman.service"
+SYSTEMD_SERVICE_${PN} = "connman.service nfs-connman.service"
 SYSTEMD_SERVICE_${PN}-vpn = "connman-vpn.service"
 SYSTEMD_WIRED_SETUP = "ExecStartPre=-${libdir}/connman/wired-setup"
 
@@ -84,10 +84,15 @@  do_compile_append() {
 }
 
 do_install_append() {
-	if ${@base_contains('DISTRO_FEATURES','sysvinit','true','false',d)}; then
-		install -d ${D}${sysconfdir}/init.d
-		install -m 0755 ${WORKDIR}/connman ${D}${sysconfdir}/init.d/connman
-		sed -i s%@LIBDIR@%${libdir}% ${D}${sysconfdir}/init.d/connman
+	install -d ${D}${sysconfdir}/init.d
+	install -m 0755 ${WORKDIR}/connman ${D}${sysconfdir}/init.d/connman
+	sed -i s%@LIBDIR@%${libdir}% ${D}${sysconfdir}/init.d/connman
+
+	if ${@base_contains('DISTRO_FEATURES','systemd','true','false',d)}; then
+		install -m 0755 ${WORKDIR}/connmand-nfs ${D}${sbindir}/
+		install -m 0644 ${WORKDIR}/nfs-connman.service  ${D}/${systemd_unitdir}/system/
+		sed -i "3 i ConditionKernelCommandLine=!root=/dev/nfs" \
+		${D}${systemd_unitdir}/system/connman.service 
 	fi
 
 	install -d ${D}${bindir}
@@ -165,7 +170,7 @@  FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*.so.* \
             ${libdir}/connman/plugins \
             ${sysconfdir} ${sharedstatedir} ${localstatedir} \
             ${base_bindir}/* ${base_sbindir}/* ${base_libdir}/*.so* ${datadir}/${PN} \
-            ${datadir}/dbus-1/system-services/*"
+            ${datadir}/dbus-1/system-services/* ${systemd_unitdir}/system/nfs-connman.service"
 
 FILES_${PN}-dbg += "${libdir}/connman/*/.debug"
 
diff --git a/meta/recipes-connectivity/connman/connman/connmand-nfs b/meta/recipes-connectivity/connman/connman/connmand-nfs
new file mode 100644
index 0000000..1058787
--- /dev/null
+++ b/meta/recipes-connectivity/connman/connman/connmand-nfs
@@ -0,0 +1,42 @@ 
+#!/bin/sh
+
+nfsroot=0
+
+exec 9<&0 < /proc/mounts
+while read dev mtpt fstype rest; do
+	if test $mtpt = "/" ; then
+		case $fstype in
+		    nfs | nfs4)
+			nfsroot=1
+			break
+			;;
+		    *)
+			;;
+		esac
+	fi
+done
+
+EXTRA_PARAM=""
+if test $nfsroot -eq 1 ; then
+    NET_DEVS=`cat /proc/net/dev | sed -ne 's/^\([a-zA-Z0-9 ]*\):.*$/\1/p'`
+    NET_ADDR=`cat /proc/cmdline | sed -ne 's/^.*ip=\([^ :]*\).*$/\1/p'`
+
+    if [ ! -z "$NET_ADDR" ]; then
+	if [ "$NET_ADDR" = dhcp ]; then
+	    ethn=`ifconfig | grep "^eth" | sed -e "s/\(eth[0-9]\)\(.*\)/\1/"`
+	    if [ ! -z "$ethn" ]; then
+		EXTRA_PARAM="-I $ethn"
+	    fi
+	else
+	    for i in $NET_DEVS; do
+		ADDR=`ifconfig $i | sed 's/addr://g' | sed -ne 's/^.*inet \([0-9.]*\) .*$/\1/p'`
+		if [ "$NET_ADDR" = "$ADDR" ]; then
+		    EXTRA_PARAM="-I $i"
+		    break
+		fi
+	    done
+	fi
+    fi
+fi
+
+/usr/sbin/connmand -n $EXTRA_PARAM
diff --git a/meta/recipes-connectivity/connman/connman/nfs-connman.service b/meta/recipes-connectivity/connman/connman/nfs-connman.service
new file mode 100644
index 0000000..1cb82b8
--- /dev/null
+++ b/meta/recipes-connectivity/connman/connman/nfs-connman.service
@@ -0,0 +1,15 @@ 
+[Unit]
+Description=Connection service when root is /dev/nfs
+ConditionKernelCommandLine=root=/dev/nfs
+After=syslog.target
+
+[Service]
+Type=dbus
+BusName=net.connman
+Restart=on-failure
+ExecStartPre=-/usr/lib64/connman/wired-setup
+ExecStart=/bin/sh /usr/sbin/connmand-nfs
+StandardOutput=null
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta/recipes-connectivity/connman/connman_1.17.bb b/meta/recipes-connectivity/connman/connman_1.17.bb
index 461157f..9e8112c 100644
--- a/meta/recipes-connectivity/connman/connman_1.17.bb
+++ b/meta/recipes-connectivity/connman/connman_1.17.bb
@@ -4,6 +4,8 @@  SRC_URI  = "${KERNELORG_MIRROR}/linux/network/${BPN}/${BP}.tar.xz \
             file://0001-plugin.h-Change-visibility-to-default-for-debug-symb.patch \
             file://add_xuser_dbus_permission.patch \
             file://connman \
+            file://connmand-nfs \
+            file://nfs-connman.service \
             "
 
 SRC_URI[md5sum] = "dd4a13f789de1b69fcddf0cf613f2d5b"