]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
nbd: give paritions some time to show up
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 22 May 2014 20:50:08 +0000 (15:50 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Sun, 25 May 2014 14:43:53 +0000 (10:43 -0400)
If you attach a file to /dev/nbd0, it may take some time for /dev/nbd0p1
to show up.  Allow up to 5 seconds in that case, then bail.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/bdev.c

index 20c4b55d5cb60c463dc20d2315369c102c8aed28..c0051e63e89561ceab9e49642221285d6921d9a3 100644 (file)
@@ -2631,6 +2631,19 @@ static int nbd_get_partition(const char *src)
        return *p - '0';
 }
 
+static bool wait_for_partition(const char *path)
+{
+       int count = 0;
+       while (count < 5) {
+               if (file_exists(path))
+                       return true;
+               sleep(1);
+               count++;
+       }
+       ERROR("Device %s did not show up after 5 seconds", path);
+       return false;
+}
+
 static int nbd_mount(struct bdev *bdev)
 {
        int ret = -1, partition;
@@ -2654,6 +2667,12 @@ static int nbd_mount(struct bdev *bdev)
                ERROR("Error setting up nbd device path");
                return ret;
        }
+
+       /* It might take awhile for the partition files to show up */
+       if (partition) {
+               if (!wait_for_partition(path))
+                       return -2;
+       }
        ret = mount_unknown_fs(path, bdev->dest, bdev->mntopts);
        if (ret < 0)
                ERROR("Error mounting %s", bdev->src);