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

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

Comments

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

Otherwise system will hang since nfs is not disconnected

and remove the judgement of initscript DISTRO_FEATURE when install init
script connman, because inherit systemd will remove init script

Signed-off-by: Roy Li <rongqing.li@windriver.com>
---
 meta/recipes-connectivity/connman/connman.inc      |   12 ++++--
 .../connman/connman/connman-nfs                    |   42 ++++++++++++++++++++
 .../connman/connman/connman-nfs.service            |   14 +++++++
 meta/recipes-connectivity/connman/connman_1.17.bb  |    2 +
 4 files changed, 66 insertions(+), 4 deletions(-)
 create mode 100644 meta/recipes-connectivity/connman/connman/connman-nfs
 create mode 100644 meta/recipes-connectivity/connman/connman/connman-nfs.service
Koen Kooi - Oct. 15, 2013, 10:10 a.m.
Op 15 okt. 2013, om 10:12 heeft rongqing.li@windriver.com het volgende geschreven:

> From: Roy Li <rongqing.li@windriver.com>
> 
> Otherwise system will hang since nfs is not disconnected
> 
> and remove the judgement of initscript DISTRO_FEATURE when install init
> script connman, because inherit systemd will remove init script

> Signed-off-by: Roy Li <rongqing.li@windriver.com>
> ---

[..]

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

Those hardcoded paths aren't going to work. And isn't:

ConditionKernelCommandLine!=root=/dev/nfs 

A lot cleaner to use in systemd?
rongqing.li@windriver.com - Oct. 16, 2013, 12:46 a.m.
On 10/15/2013 06:10 PM, Koen Kooi wrote:
>
> Op 15 okt. 2013, om 10:12 heeft rongqing.li@windriver.com het volgende geschreven:
>
>> From: Roy Li <rongqing.li@windriver.com>
>>
>> Otherwise system will hang since nfs is not disconnected
>>
>> and remove the judgement of initscript DISTRO_FEATURE when install init
>> script connman, because inherit systemd will remove init script
>
>> Signed-off-by: Roy Li <rongqing.li@windriver.com>
>> ---
>
> [..]
>
>> diff --git a/meta/recipes-connectivity/connman/connman/connman-nfs.service b/meta/recipes-connectivity/connman/connman/connman-nfs.service
>> new file mode 100644
>> index 0000000..9f9b690
>> --- /dev/null
>> +++ b/meta/recipes-connectivity/connman/connman/connman-nfs.service
>> @@ -0,0 +1,14 @@
>> +[Unit]
>> +Description=Connection service
>> +After=syslog.target
>> +
>> +[Service]
>> +Type=dbus
>> +BusName=net.connman
>> +Restart=on-failure
>> +ExecStartPre=-/usr/lib64/connman/wired-setup
>> +ExecStart=/usr/bin/connman-nfs
>
> Those hardcoded paths aren't going to work. And isn't:
>

Thanks, I will fix it.

> ConditionKernelCommandLine!=root=/dev/nfs
>

What is your meaning?

-Roy


> A lot cleaner to use in systemd?
>
Koen Kooi - Oct. 16, 2013, 8:54 a.m.
Op 16 okt. 2013, om 02:46 heeft Rongqing Li <rongqing.li@windriver.com> het volgende geschreven:

> 
> 
> On 10/15/2013 06:10 PM, Koen Kooi wrote:
>> 
>> Op 15 okt. 2013, om 10:12 heeft rongqing.li@windriver.com het volgende geschreven:
>> 
>>> From: Roy Li <rongqing.li@windriver.com>
>>> 
>>> Otherwise system will hang since nfs is not disconnected
>>> 
>>> and remove the judgement of initscript DISTRO_FEATURE when install init
>>> script connman, because inherit systemd will remove init script
>> 
>>> Signed-off-by: Roy Li <rongqing.li@windriver.com>
>>> ---
>> 
>> [..]
>> 
>>> diff --git a/meta/recipes-connectivity/connman/connman/connman-nfs.service b/meta/recipes-connectivity/connman/connman/connman-nfs.service
>>> new file mode 100644
>>> index 0000000..9f9b690
>>> --- /dev/null
>>> +++ b/meta/recipes-connectivity/connman/connman/connman-nfs.service
>>> @@ -0,0 +1,14 @@
>>> +[Unit]
>>> +Description=Connection service
>>> +After=syslog.target
>>> +
>>> +[Service]
>>> +Type=dbus
>>> +BusName=net.connman
>>> +Restart=on-failure
>>> +ExecStartPre=-/usr/lib64/connman/wired-setup
>>> +ExecStart=/usr/bin/connman-nfs
>> 
>> Those hardcoded paths aren't going to work. And isn't:
>> 
> 
> Thanks, I will fix it.
> 
>> ConditionKernelCommandLine!=root=/dev/nfs
>> 
> 
> What is your meaning?

That's you are creating a huge script that does something built into systemd.

> 
> -Roy
> 
> 
>> A lot cleaner to use in systemd?
>> 
> 
> -- 
> Best Reagrds,
> Roy | RongQing Li
rongqing.li@windriver.com - Oct. 16, 2013, 9:10 a.m.
On 10/16/2013 04:54 PM, Koen Kooi wrote:
>>> ConditionKernelCommandLine!=root=/dev/nfs
>>> >>
>> >
>> >What is your meaning?
> That's you are creating a huge script that does something built into systemd.
>


Yes, I can not find a way to avoid to that,

Do you have any advice?


-Roy
Koen Kooi - Oct. 16, 2013, 9:13 a.m.
Op 16 okt. 2013, om 11:10 heeft Rongqing Li <rongqing.li@windriver.com> het volgende geschreven:

> 
> 
> On 10/16/2013 04:54 PM, Koen Kooi wrote:
>>>> ConditionKernelCommandLine!=root=/dev/nfs
>>>> >>
>>> >
>>> >What is your meaning?
>> That's you are creating a huge script that does something built into systemd.
>> 
> 
> 
> Yes, I can not find a way to avoid to that,
> 
> Do you have any advice?

Yes, as I said a few mails earlier: ConditionKernelCommandLine!=root=/dev/nfs
Enrico Scholz - Oct. 16, 2013, 10:08 a.m.
Rongqing Li <rongqing.li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
writes:

>>>> ConditionKernelCommandLine!=root=/dev/nfs
>>>> >>
>>> >
>>> >What is your meaning?
>> That's you are creating a huge script that does something built into systemd.
>>
>
>
> Yes, I can not find a way to avoid to that,
>
> Do you have any advice?

I would split the cmdline generation into a dedicated one-shot service;
e.g. modify the original connman.service to have something like

  [Service]
  EnvironmentFile = -/run/connmand.env
  ExecStart=/usr/sbin/connmand -n ${CONNMAND_OPTS}


The '/run/connmand.env' is created by a service with

  [Unit]
  Before = connman.service
  ConditionKernelCommandLine!=root=/dev/nfs
  
  [Service]
  Type = oneshot
  ExecStart = /usr/sbin/create-run-connmand.env

  [Install]
  WantedBy = connman.service



Enrico
rongqing.li@windriver.com - Oct. 17, 2013, 3:29 a.m.
On 10/16/2013 06:08 PM, Enrico Scholz wrote:
> Rongqing Li <rongqing.li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
> writes:
>
>>>>> ConditionKernelCommandLine!=root=/dev/nfs
>>>>>>>
>>>>>
>>>>> What is your meaning?
>>> That's you are creating a huge script that does something built into systemd.
>>>
>>
>>
>> Yes, I can not find a way to avoid to that,
>>
>> Do you have any advice?
>
> I would split the cmdline generation into a dedicated one-shot service;
> e.g. modify the original connman.service to have something like
>
>    [Service]
>    EnvironmentFile = -/run/connmand.env
>    ExecStart=/usr/sbin/connmand -n ${CONNMAND_OPTS}
>
>
> The '/run/connmand.env' is created by a service with
>
>    [Unit]
>    Before = connman.service
>    ConditionKernelCommandLine!=root=/dev/nfs
>
>    [Service]
>    Type = oneshot
>    ExecStart = /usr/sbin/create-run-connmand.env
>
>    [Install]
>    WantedBy = connman.service
>
>
>


I test your method, but failed to start connmand,
it always report "hand over timeout", I think
it is caused by which the script run slow.


But I will follow your method, create two service.
the connman.service is run only when
ConditionKernelCommandLine!=root=/dev/nfs

other connman-nfs.service, which will start the
script to compute the ignored interface, is run
when ConditionKernelCommandLine=root=/dev/nfs


-Roy




> Enrico
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core
>
>
Enrico Scholz - Oct. 17, 2013, 10:34 a.m.
Rongqing Li <rongqing.li@windriver.com> writes:

>>> Do you have any advice?
>>
>> I would split the cmdline generation into a dedicated one-shot service;
>> e.g. modify the original connman.service to have something like
> ...
> I test your method, but failed to start connmand,
> it always report "hand over timeout", I think
> it is caused by which the script run slow.

strange; I just tested it with

--- connman.service ---
[Unit]
Description=Connection service
After=syslog.target
Wants = connman-env.service

[Service]
Type=dbus
BusName=net.connman
EnvironmentFile = -/run/connmand.env
ExecStart=/usr/sbin/connmand -n $CONNMAND_OPTS

[Install]
WantedBy=multi-user.target

--- connman-env.service ---
[Unit]
Before = connman.service
ConditionKernelCommandLine = root=/dev/nfs

[Service]
Type = oneshot
ExecStart = /bin/sh -c 'echo CONNMAND_OPTS=\\"--noipconfig=eth0\\" > /run/connmand.env'

[Install]
WantedBy = connman.service


which works fine. Of course, this is just a quick hack and needs some changes
(replacement of inline shell script, perhaps setting RemainAfterExit, using
'systemctl enable' instead of 'Wants = connman-env.service')




Enrico

Patch

diff --git a/meta/recipes-connectivity/connman/connman.inc b/meta/recipes-connectivity/connman/connman.inc
index 37ce3ec..51c2bfb 100644
--- a/meta/recipes-connectivity/connman/connman.inc
+++ b/meta/recipes-connectivity/connman/connman.inc
@@ -84,10 +84,14 @@  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 -d ${D}${bindir}/
+		install -m 0755 ${WORKDIR}/connman-nfs ${D}${bindir}/
+		install -T -m 0644 ${WORKDIR}/connman-nfs.service ${D}/lib/systemd/system/connman.service
 	fi
 
 	install -d ${D}${bindir}
diff --git a/meta/recipes-connectivity/connman/connman/connman-nfs b/meta/recipes-connectivity/connman/connman/connman-nfs
new file mode 100644
index 0000000..1058787
--- /dev/null
+++ b/meta/recipes-connectivity/connman/connman/connman-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/connman-nfs.service b/meta/recipes-connectivity/connman/connman/connman-nfs.service
new file mode 100644
index 0000000..9f9b690
--- /dev/null
+++ b/meta/recipes-connectivity/connman/connman/connman-nfs.service
@@ -0,0 +1,14 @@ 
+[Unit]
+Description=Connection service
+After=syslog.target
+
+[Service]
+Type=dbus
+BusName=net.connman
+Restart=on-failure
+ExecStartPre=-/usr/lib64/connman/wired-setup
+ExecStart=/usr/bin/connman-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..f3a4849 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://connman-nfs \
+            file://connman-nfs.service \
             "
 
 SRC_URI[md5sum] = "dd4a13f789de1b69fcddf0cf613f2d5b"