[lxc-devel] [PATCH 2/2] nbd: give paritions some time to show up

Stéphane Graber stgraber at ubuntu.com
Sun May 25 14:43:16 UTC 2014


On Thu, May 22, 2014 at 03:50:08PM -0500, Serge Hallyn wrote:
> 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 at ubuntu.com>

Acked-by: Stéphane Graber <stgraber at ubuntu.com>

> ---
>  src/lxc/bdev.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
> index 20c4b55..c0051e6 100644
> --- a/src/lxc/bdev.c
> +++ b/src/lxc/bdev.c
> @@ -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);
> -- 
> 2.0.0.rc0
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140525/f25cc39e/attachment.sig>


More information about the lxc-devel mailing list