mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eduardo Otubo <otubo@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: devel@linuxdriverproject.org, sthemmin@microsoft.com,
	haiyangz@microsoft.com, kys@microsoft.com, vkuznets@redhat.com,
	mgamal@redhat.com, cavery@redhat.com
Subject: [PATCHv2] tools: hv: hv_set_ifconfig.sh double check before setting ip
Date: Fri,  8 Dec 2017 11:20:56 +0100	[thread overview]
Message-ID: <20171208102056.4725-1-otubo@redhat.com> (raw)

This patch fixes the behavior of the hv_set_ifconfig script when setting
the interface ip. Sometimes the interface has already been configured by
network daemon, in this case hv_set_ifconfig causes "RTNETLINK: file
exists error"; in order to avoid this error this patch makes sure double
checks the interface before trying anything.

Signed-off-by: Eduardo Otubo <otubo@redhat.com>
---
v2: wrap the interface configuration inside a safe wAY to avoid
interaction with network script.
 tools/hv/hv_set_ifconfig.sh | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/tools/hv/hv_set_ifconfig.sh b/tools/hv/hv_set_ifconfig.sh
index 7ed9f85ef908..b6429703cc98 100755
--- a/tools/hv/hv_set_ifconfig.sh
+++ b/tools/hv/hv_set_ifconfig.sh
@@ -61,5 +61,46 @@ cp $1 /etc/sysconfig/network-scripts/
 
 interface=$(echo $1 | awk -F - '{ print $2 }')
 
-/sbin/ifdown $interface 2>/dev/null
-/sbin/ifup $interface 2>/dev/null
+current_ip=$(ip addr show $interface|sed -En 's/.*inet (addr:)?(([0-9*\.){3}[0-9]*).*/\2/p');
+config_file_ip=$(grep IPADDR /etc/sysconfig/network-scripts/ifcfg-$interface|cut -d"=" -f2);
+
+current_ipv6=$(ip addr show $interface|sed -E 's/^*.inet6\ (.*)\ scope\ global/\1/');
+config_file_ipv6=$(grep IPV6ADDR /etc/sysconfig/network-scripts/ifcfg-eth-$interface|cut -d"=" -f2);
+config_file_ipv6_netmask=$(grep IPV6NETMASK /etc/sysconfig/network-scripts/ifcfg-eth-$interface|cut -d"=" -f2);
+config_file_ipv6=${config_file_ipv6}/${config_file_ipv6_netmask};
+
+configure_interface(){
+    # only set the IP if the network service has not done yet
+    if [[ ${current_ip} != *${config_file_ip}* || ${current_ipv6} != ${config_file_ipv6} ]]; then
+        /sbin/ifdown $interface 2>/dev/null
+        /sbin/ifup $interface 2>/dev/null
+    fi
+}
+
+error_exit(){
+    message=$1
+    logger "KVP daemon: $message"
+    exit 1;
+}
+
+if [ -e /var/run/subsys/network ]; then
+    # network script is already up
+    # it is safe to configure the interface
+    configure_interface;
+else
+    i=0;
+    while [ ! -e /var/run/subsys/network ]; do
+        # network script might be still starting.
+        # let's wait for 3 minutes
+        sleep 1m;
+        ((i++));
+
+        # if network service doens't come up in 3 minutes
+        # perhaps there's no network service at all
+        [[ $i == 3 ]] && break;
+    done
+
+    # at this point it doesn't matter if network service is up or down
+    # we're safe either way
+    configure_interface;
+fi
-- 
2.13.6

             reply	other threads:[~2017-12-08 10:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-08 10:20 Eduardo Otubo [this message]
2017-12-08 11:33 ` Olaf Hering
2017-12-08 13:43   ` Eduardo Otubo
2017-12-08 19:04   ` KY Srinivasan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171208102056.4725-1-otubo@redhat.com \
    --to=otubo@redhat.com \
    --cc=cavery@redhat.com \
    --cc=devel@linuxdriverproject.org \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgamal@redhat.com \
    --cc=sthemmin@microsoft.com \
    --cc=vkuznets@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®