[ovs-dev] [PATCH 3/3] xenserver: Gracefully refresh network UUIDs on pool join or leave.

Ben Pfaff blp at nicira.com
Wed Apr 21 11:37:36 PDT 2010


The vswitch database is supposed to maintain an up-to-date UUID for the
system's networks in the Bridge table as external-ids:network-uuids.  On
XenServer systems, /opt/xensource/libexec/interface-reconfigure updates
these fields as bridges are brought up and down.  Most of the time, that is
sufficient.  However, this is one exception: when a XenServer host enters
or leaves a pool, interface-reconfigure is not invoked, and neither is any
other script.  So this commit adds monitoring of the XenServer's pool
membership status and refreshes the network UUIDs (by invoking the
refresh-network-uuids script) if it changes.

This functionality should have no effect on non-XenServer systems, since
they will have neither /etc/xensource/pool.conf nor refresh-network-uuids.

Bug #2097.
---
 vswitchd/ovs-vswitchd.c |    3 +
 vswitchd/xenserver.c    |   95 +++++++++++++++++++++++++++++++++++++++++++++-
 vswitchd/xenserver.h    |    4 +-
 3 files changed, 98 insertions(+), 4 deletions(-)

diff --git a/vswitchd/ovs-vswitchd.c b/vswitchd/ovs-vswitchd.c
index c1acfc4..0450efb 100644
--- a/vswitchd/ovs-vswitchd.c
+++ b/vswitchd/ovs-vswitchd.c
@@ -46,6 +46,7 @@
 #include "util.h"
 #include "vconn.h"
 #include "vswitchd/vswitch-idl.h"
+#include "xenserver.h"
 
 #include "vlog.h"
 #define THIS_MODULE VLM_vswitchd
@@ -119,6 +120,7 @@ main(int argc, char *argv[])
         unixctl_server_run(unixctl);
         dp_run();
         netdev_run();
+        xenserver_run();
 
         signal_wait(sighup);
         if (inited) {
@@ -128,6 +130,7 @@ main(int argc, char *argv[])
         unixctl_server_wait(unixctl);
         dp_wait();
         netdev_wait();
+        xenserver_wait();
         poll_block();
     }
 
diff --git a/vswitchd/xenserver.c b/vswitchd/xenserver.c
index 03c4955..32e5a49 100644
--- a/vswitchd/xenserver.c
+++ b/vswitchd/xenserver.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,13 +15,16 @@
 
 #include <config.h>
 #include "xenserver.h"
-#include <ctype.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <time.h>
 #include <unistd.h>
-#include "dynamic-string.h"
+#include "dirs.h"
+#include "poll-loop.h"
 #include "process.h"
+#include "socket-util.h"
 
 #include "vlog.h"
 #define THIS_MODULE VLM_xenserver
@@ -76,4 +79,90 @@ xenserver_get_host_uuid(void)
     }
     return host_uuid;
 }
+
+/* Network UUID refreshing.
+ *
+ * The vswitch database is supposed to maintain an up-to-date UUID for the
+ * system's networks in the Bridge table as external-ids:network-uuids.  On
+ * XenServer systems, /opt/xensource/libexec/interface-reconfigure updates
+ * these fields as bridges are brought up and down.  Most of the time, that is
+ * sufficient.  However, this is one exception: when a XenServer host enters or
+ * leaves a pool, interface-reconfigure is not invoked, and neither is any
+ * other script.  So we need to monitor the XenServer's pool membership status
+ * and refresh the network UUIDs (by invoking the refresh-network-uuids script)
+ * if it changes.
+ *
+ * This functionality should be harmless on non-XenServer systems, since they
+ * will have neither /etc/xensource/pool.conf nor refresh-network-uuids.
+ */
+
+/* Timestamp of /etc/xensource/pool.conf, or zeros if it does not exist. */
+static struct timespec pool_conf_mtime;
+
+/* The executing instance of refresh-network-uuids, or NULL if none. */
+static struct process *refresh_script;
+
+void
+xenserver_run(void)
+{
+    struct timespec new_mtime;
+
+    /* If a script is running, don't do anything until it finishes. */
+    if (refresh_script) {
+        char *s;
+
+        if (!process_exited(refresh_script)) {
+            return;
+        }
+
+        s = process_status_msg(process_status(refresh_script));
+        VLOG_INFO("refresh-network-uuids exited, %s", s);
+        free(s);
+
+        process_destroy(refresh_script);
+        refresh_script = NULL;
+    }
+
+    /* Otherwise, check for a change in timestamp.
+     *
+     * (We will always detect a change in timestamp when we start up.  That's
+     * good, since it means that the refresh-network-uuids script gets
+     * thoroughly tested and we can't miss pool changes that happen when
+     * ovs-vswitchd isn't running.)  */
+    get_mtime("/etc/xensource/pool.conf", &new_mtime);
+    if (new_mtime.tv_sec != pool_conf_mtime.tv_sec ||
+        new_mtime.tv_nsec != pool_conf_mtime.tv_nsec) {
+        struct stat s;
+        char *argv[2];
+
+        argv[0] = xasprintf("%s/scripts/refresh-network-uuids",
+                            ovs_pkgdatadir);
+        argv[1] = NULL;
+
+        if (!stat(argv[0], &s)) {
+            int error = process_start(argv, NULL, 0, NULL, 0, &refresh_script);
+            if (error) {
+                VLOG_ERR("failed to refresh network UUIDs: %s could "
+                         "not be started (%s)", argv[0], strerror(error));
+            } else {
+                VLOG_INFO("refreshing network UUIDs: started %s", argv[0]);
+            }
+        } else {
+            VLOG_ERR("failed to refresh network UUIDs: could not stat %s (%s)",
+                     argv[0], strerror(errno));
+        }
 
+        pool_conf_mtime = new_mtime;
+        free(argv[0]);
+    }
+}
+
+void
+xenserver_wait(void)
+{
+    if (refresh_script) {
+        process_wait(refresh_script);
+    } else if (pool_conf_mtime.tv_sec) {
+        poll_timer_wait(1000);
+    }
+}
diff --git a/vswitchd/xenserver.h b/vswitchd/xenserver.h
index ad9ed8c..034ee3a 100644
--- a/vswitchd/xenserver.h
+++ b/vswitchd/xenserver.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,5 +17,7 @@
 #define VSWITCHD_XENSERVER_H 1
 
 const char *xenserver_get_host_uuid(void);
+void xenserver_run(void);
+void xenserver_wait(void);
 
 #endif /* xenserver.h */
-- 
1.6.6.1





More information about the dev mailing list