]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
lxc: wait for nbd device to be up to get its PIDs
authorCédric Bosdonnat <cbosdonnat@suse.com>
Wed, 15 Jul 2015 08:13:21 +0000 (10:13 +0200)
committerCédric Bosdonnat <cbosdonnat@suse.com>
Wed, 15 Jul 2015 08:16:15 +0000 (10:16 +0200)
The nbd device pid file doesn't appear immediately after starting
qemu-nbd: adding a small loop to wait for it before getting it's
processes PIDs.

src/lxc/lxc_controller.c

index c73bb4f58092a3b2f508f5756319292832e7c72f..110a55662be053e549415c5763a078073b3d4457 100644 (file)
@@ -537,12 +537,27 @@ static int virLXCControllerAppendNBDPids(virLXCControllerPtr ctrl,
     size_t npids = 0;
     size_t i;
     int ret = -1;
+    size_t loops = 0;
     pid_t pid;
 
     if (!STRPREFIX(dev, "/dev/") ||
         virAsprintf(&pidpath, "/sys/devices/virtual/block/%s/pid", dev + 5) < 0)
         goto cleanup;
 
+    /* Wait for the pid file to appear */
+    while (!virFileExists(pidpath)) {
+        /* wait for 100ms before checking again, but don't do it for ever */
+        if (errno == ENOENT && loops < 10) {
+            usleep(100 * 1000);
+            loops++;
+        } else {
+            virReportSystemError(errno,
+                                 _("Cannot check NBD device %s pid"),
+                                 dev + 5);
+            goto cleanup;
+        }
+    }
+
     if (virPidFileReadPath(pidpath, &pid) < 0)
         goto cleanup;