libxl: add libxl__spawn_confirm_offspring_startup
authorOlaf Hering <olaf@aepfle.de>
Thu, 27 Oct 2011 09:23:29 +0000 (11:23 +0200)
committerOlaf Hering <olaf@aepfle.de>
Thu, 27 Oct 2011 09:23:29 +0000 (11:23 +0200)
libxl__spawn_confirm_offspring_startup() is a generic version of
libxl__confirm_device_model_startup().

Use libxl__spawn_confirm_offspring_startup for device model.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
tools/libxl/libxl_dm.c
tools/libxl/libxl_exec.c
tools/libxl/libxl_internal.h

index c0118dc245366d31c680e6f5d367d3c3a70b9fbe..bf38877de10bc62f1711a31bbefcb4bf38b824e9 100644 (file)
@@ -890,25 +890,16 @@ out:
     return rc;
 }
 
-static int detach_device_model(libxl__gc *gc,
-                               libxl__spawner_starting *starting)
-{
-    int rc;
-    rc = libxl__spawn_detach(gc, starting->for_spawn);
-    if (starting->for_spawn)
-        free(starting->for_spawn);
-    free(starting);
-    return rc;
-}
 
 int libxl__confirm_device_model_startup(libxl__gc *gc,
                                        libxl__spawner_starting *starting)
 {
-    int detach;
-    int problem = libxl__wait_for_device_model(gc, starting->domid, "running",
-                                               starting->for_spawn, NULL, NULL);
-    detach = detach_device_model(gc, starting);
-    return problem ? problem : detach;
+    char *path;
+    int domid = starting->domid;
+    path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
+    return libxl__spawn_confirm_offspring_startup(gc,
+                                     LIBXL_DEVICE_MODEL_START_TIMEOUT,
+                                     "Device Model", path, "running", starting);
 }
 
 int libxl__destroy_device_model(libxl__gc *gc, uint32_t domid)
index 6113f9ed0e9f619bdda25751ccfb9779b45c4cf7..95151c07b15f0a155503471be07b125edd8e0f04 100644 (file)
@@ -262,6 +262,30 @@ err:
     return -1;
 }
 
+static int detach_offspring(libxl__gc *gc,
+                               libxl__spawner_starting *starting)
+{
+    int rc;
+    rc = libxl__spawn_detach(gc, starting->for_spawn);
+    if (starting->for_spawn)
+        free(starting->for_spawn);
+    free(starting);
+    return rc;
+}
+
+int libxl__spawn_confirm_offspring_startup(libxl__gc *gc,
+                                       uint32_t timeout, char *what,
+                                       char *path, char *state,
+                                       libxl__spawner_starting *starting)
+{
+    int detach;
+    int problem = libxl__wait_for_offspring(gc, starting->domid, timeout, what,
+                                               path, state,
+                                               starting->for_spawn, NULL, NULL);
+    detach = detach_offspring(gc, starting);
+    return problem ? problem : detach;
+}
+
 static int libxl__set_fd_flag(libxl__gc *gc, int fd, int flag)
 {
     int flags;
index b2dca1c91fb444828896224329f34175df818813..7a561d999f3b9462602595bbf95bd0e7767e7e2e 100644 (file)
@@ -331,6 +331,12 @@ _hidden int libxl__wait_for_offspring(libxl__gc *gc,
                                                        const char *state,
                                                        void *userdata),
                                  void *check_callback_userdata);
+
+_hidden int libxl__spawn_confirm_offspring_startup(libxl__gc *gc,
+                                       uint32_t timeout, char *what,
+                                       char *path, char *state,
+                                       libxl__spawner_starting *starting);
+
   /* Logs errors.  A copy of "what" is taken.  Return values:
    *  < 0   error, for_spawn need not be detached
    *   +1   caller is the parent, must call detach on *for_spawn eventually