Skip to content

Commit a256b6e

Browse files
committed
ovs-xapi-sync: Use unixctl to trigger cache flushes.
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>
1 parent 8084c01 commit a256b6e

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

xenserver/etc_init.d_openvswitch

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ case $1 in
120120
;;
121121
reload|force-reload)
122122
# The main OVS daemons keep up-to-date, but ovs-xapi-sync needs help.
123-
pidfile=/var/run/openvswitch/ovs-xapi-sync.pid
124-
if test -e "$pidfile"; then
125-
pid=`cat "$pidfile"`
126-
action "Configuring Open vSwitch external IDs" kill -HUP $pid
123+
if daemon_is_running ovs-xapi-sync; then
124+
action "Configuring Open vSwitch external IDs" \
125+
ovs-appctl -t ovs-xapi-sync flush-cache
127126
fi
128127
;;
129128
status)

xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import argparse
2626
import os
27-
import signal
2827
import sys
2928
import time
3029

@@ -39,7 +38,7 @@ import ovs.unixctl
3938

4039
vlog = ovs.vlog.Vlog("ovs-xapi-sync")
4140
session = None
42-
force_run = False
41+
flush_cache = False
4342
exiting = False
4443

4544

@@ -49,6 +48,12 @@ def unixctl_exit(conn, unused_argv, unused_aux):
4948
conn.reply(None)
5049

5150

51+
def unixctl_flush_cache(conn, unused_argv, unused_aux):
52+
global flush_cache
53+
flush_cache = True
54+
conn.reply(None)
55+
56+
5257
# Set up a session to interact with XAPI.
5358
#
5459
# On system start-up, OVS comes up before XAPI, so we can't log into the
@@ -226,14 +231,8 @@ def prune_schema(schema):
226231
schema.tables = new_tables
227232

228233

229-
def handler(signum, _):
230-
global force_run
231-
if (signum == signal.SIGHUP):
232-
force_run = True
233-
234-
235234
def main():
236-
global force_run
235+
global flush_cache
237236

238237
parser = argparse.ArgumentParser()
239238
parser.add_argument("database", metavar="DATABASE",
@@ -257,6 +256,8 @@ def main():
257256
ovs.daemon.daemonize()
258257

259258
ovs.unixctl.command_register("exit", "", 0, 0, unixctl_exit, None)
259+
ovs.unixctl.command_register("flush-cache", "", 0, 0, unixctl_flush_cache,
260+
None)
260261
error, unixctl_server = ovs.unixctl.UnixctlServer.create(None)
261262
if error:
262263
ovs.util.ovs_fatal(error, "could not create unixctl server", vlog)
@@ -267,8 +268,6 @@ def main():
267268
while not os.path.exists(cookie_file):
268269
time.sleep(1)
269270

270-
signal.signal(signal.SIGHUP, handler)
271-
272271
bridges = {} # Map from bridge name to nicira-bridge-id
273272
iface_ids = {} # Map from xs-vif-uuid to iface-id
274273
vm_ids = {} # Map from xs-vm-uuid to vm-id
@@ -279,19 +278,19 @@ def main():
279278
break;
280279

281280
idl.run()
282-
if not force_run and seqno == idl.change_seqno:
281+
if not flush_cache and seqno == idl.change_seqno:
283282
poller = ovs.poller.Poller()
284283
unixctl_server.wait(poller)
285284
idl.wait(poller)
286285
poller.block()
287286
continue
288287

289-
if force_run:
290-
vlog.info("Forced to re-run as the result of a SIGHUP")
288+
if flush_cache:
289+
vlog.info("Flushing cache as the result of unixctl.")
291290
bridges = {}
292291
iface_ids = {}
293292
vm_ids = {}
294-
force_run = False
293+
flush_cache = False
295294
seqno = idl.change_seqno
296295

297296
txn = ovs.db.idl.Transaction(idl)

0 commit comments

Comments
 (0)