[ovs-dev] [kernel-reload 2/8] ovs-vswitchd: Complete daemonization only after initial configuration.

Ben Pfaff blp at nicira.com
Wed Feb 2 22:31:16 UTC 2011


Otherwise when we add support for saving and restoring configuration
of internal devices around kernel module unload and reload, there's
no easy way for the "restore" code to tell when all the interfaces
should be set up and ready for configuration.
---
 lib/daemon.c               |    8 ++++++--
 lib/daemon.man             |    2 +-
 ovsdb/ovsdb-server.1.in    |    3 +++
 vswitchd/bridge.c          |    5 +++++
 vswitchd/ovs-vswitchd.8.in |    4 ++++
 vswitchd/ovs-vswitchd.c    |    4 +---
 6 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/lib/daemon.c b/lib/daemon.c
index c0f1682..3f668b9 100644
--- a/lib/daemon.c
+++ b/lib/daemon.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -475,11 +475,14 @@ daemonize_start(void)
 }
 
 /* If daemonization is configured, then this function notifies the parent
- * process that the child process has completed startup successfully. */
+ * process that the child process has completed startup successfully.
+ *
+ * Calling this function more than once has no additional effect. */
 void
 daemonize_complete(void)
 {
     fork_notify_startup(daemonize_fd);
+    daemonize_fd = -1;
 
     if (detach) {
         setsid();
@@ -487,6 +490,7 @@ daemonize_complete(void)
             ignore(chdir("/"));
         }
         close_standard_fds();
+        detach = false;
     }
 }
 
diff --git a/lib/daemon.man b/lib/daemon.man
index d9f25e1..7b07cb8 100644
--- a/lib/daemon.man
+++ b/lib/daemon.man
@@ -20,7 +20,7 @@ When \fB\-\-pidfile\fR is not specified, this option has no effect.
 .TP
 \fB\-\-detach\fR
 Causes \fB\*(PN\fR to detach itself from the foreground session and
-run as a background process.
+run as a background process. \*(DD
 .
 .TP
 \fB\-\-monitor\fR
diff --git a/ovsdb/ovsdb-server.1.in b/ovsdb/ovsdb-server.1.in
index a89f091..6100c4d 100644
--- a/ovsdb/ovsdb-server.1.in
+++ b/ovsdb/ovsdb-server.1.in
@@ -81,6 +81,9 @@ This option can be useful where a database server is needed only to
 run a single command, e.g.:
 .B "ovsdb\-server \-\-remote=punix:socket \-\-run='ovsdb\-client dump unix:socket Open_vSwitch'"
 .SS "Daemon Options"
+.ds DD \
+\fBovsdb\-server\fR detaches only after it starts listening on all \
+configured remotes.
 .so lib/daemon.man
 .SS "Logging Options"
 .so lib/vlog.man
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index fab6194..43e10fc 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -35,6 +35,7 @@
 #include "cfm.h"
 #include "classifier.h"
 #include "coverage.h"
+#include "daemon.h"
 #include "dirs.h"
 #include "dpif.h"
 #include "dynamic-string.h"
@@ -891,6 +892,10 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg)
     }
 
     free(managers);
+
+    /* ovs-vswitchd has completed initialization, so allow the process that
+     * forked us to exit successfully. */
+    daemonize_complete();
 }
 
 static const char *
diff --git a/vswitchd/ovs-vswitchd.8.in b/vswitchd/ovs-vswitchd.8.in
index 5c52526..163ad20 100644
--- a/vswitchd/ovs-vswitchd.8.in
+++ b/vswitchd/ovs-vswitchd.8.in
@@ -102,6 +102,10 @@ to be loaded.
 .IP
 On non-Linux hosts, this option is accepted but has no effect.
 .
+.ds DD \
+\fBovs\-vswitchd\fR detaches only after it has connected to the \
+database, retrieved the initial configuration, and set up that \
+configuration.
 .so lib/daemon.man
 .SS "Public Key Infrastructure Options"
 .so lib/ssl.man
diff --git a/vswitchd/ovs-vswitchd.c b/vswitchd/ovs-vswitchd.c
index 4ebc8f2..2181e82 100644
--- a/vswitchd/ovs-vswitchd.c
+++ b/vswitchd/ovs-vswitchd.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2009, 2010 Nicira Networks
+/* Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -84,8 +84,6 @@ main(int argc, char *argv[])
     }
     unixctl_command_register("exit", ovs_vswitchd_exit, &exiting);
 
-    daemonize_complete();
-
     bridge_init(remote);
     exiting = false;
     while (!exiting) {
-- 
1.7.1





More information about the dev mailing list