ovs-xapi-sync: Use unixctl to trigger cache flushes.
authorEthan Jackson <ethan@nicira.com>
Tue, 6 Mar 2012 19:12:19 +0000 (11:12 -0800)
committerEthan Jackson <ethan@nicira.com>
Fri, 9 Mar 2012 21:37:38 +0000 (13:37 -0800)
Typically Open vSwitch communicates with running processes using
unixctl.  This patch converts ovs-xapi-sync to the strategy for
consistency.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
xenserver/etc_init.d_openvswitch
xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync

index 29f2cf6051c41d7d3e446066db7b83ef5242af93..aa65657ec5b6e8e146966b65b307478394e80e21 100755 (executable)
@@ -120,10 +120,9 @@ case $1 in
         ;;
     reload|force-reload)
         # The main OVS daemons keep up-to-date, but ovs-xapi-sync needs help.
-        pidfile=/var/run/openvswitch/ovs-xapi-sync.pid
-        if test -e "$pidfile"; then
-            pid=`cat "$pidfile"`
-            action "Configuring Open vSwitch external IDs" kill -HUP $pid
+        if daemon_is_running ovs-xapi-sync; then
+            action "Configuring Open vSwitch external IDs" \
+                ovs-appctl -t ovs-xapi-sync flush-cache
         fi
         ;;
     status)
index 8f5885a9878f085a8038f93d8dbddf04b1a4c32f..eea319a8197c30e93a540831a8bd65d9eb131d4a 100755 (executable)
@@ -24,7 +24,6 @@
 
 import argparse
 import os
-import signal
 import sys
 import time
 
@@ -39,7 +38,7 @@ import ovs.unixctl
 
 vlog = ovs.vlog.Vlog("ovs-xapi-sync")
 session = None
-force_run = False
+flush_cache = False
 exiting = False
 
 
@@ -49,6 +48,12 @@ def unixctl_exit(conn, unused_argv, unused_aux):
     conn.reply(None)
 
 
+def unixctl_flush_cache(conn, unused_argv, unused_aux):
+    global flush_cache
+    flush_cache = True
+    conn.reply(None)
+
+
 # Set up a session to interact with XAPI.
 #
 # On system start-up, OVS comes up before XAPI, so we can't log into the
@@ -226,14 +231,8 @@ def prune_schema(schema):
     schema.tables = new_tables
 
 
-def handler(signum, _):
-    global force_run
-    if (signum == signal.SIGHUP):
-        force_run = True
-
-
 def main():
-    global force_run
+    global flush_cache
 
     parser = argparse.ArgumentParser()
     parser.add_argument("database", metavar="DATABASE",
@@ -257,6 +256,8 @@ def main():
     ovs.daemon.daemonize()
 
     ovs.unixctl.command_register("exit", "", 0, 0, unixctl_exit, None)
+    ovs.unixctl.command_register("flush-cache", "", 0, 0, unixctl_flush_cache,
+                                 None)
     error, unixctl_server = ovs.unixctl.UnixctlServer.create(None)
     if error:
         ovs.util.ovs_fatal(error, "could not create unixctl server", vlog)
@@ -267,8 +268,6 @@ def main():
     while not os.path.exists(cookie_file):
         time.sleep(1)
 
-    signal.signal(signal.SIGHUP, handler)
-
     bridges = {}                # Map from bridge name to nicira-bridge-id
     iface_ids = {}              # Map from xs-vif-uuid to iface-id
     vm_ids = {}                 # Map from xs-vm-uuid to vm-id
@@ -279,19 +278,19 @@ def main():
             break;
 
         idl.run()
-        if not force_run and seqno == idl.change_seqno:
+        if not flush_cache and seqno == idl.change_seqno:
             poller = ovs.poller.Poller()
             unixctl_server.wait(poller)
             idl.wait(poller)
             poller.block()
             continue
 
-        if force_run:
-            vlog.info("Forced to re-run as the result of a SIGHUP")
+        if flush_cache:
+            vlog.info("Flushing cache as the result of unixctl.")
             bridges = {}
             iface_ids = {}
             vm_ids = {}
-            force_run = False
+            flush_cache = False
         seqno = idl.change_seqno
 
         txn = ovs.db.idl.Transaction(idl)