Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 8972e61

Browse files
committed
retry blockdev mount
block devices are hotplugged to guest vm. It needs sometime for the guest kernel to initialize. If we proceed too soon to mount, mount can fail with ENOENT. Retry a bit in such case. Signed-off-by: Peng Tao <bergwolf@gmail.com>
1 parent ec39c70 commit 8972e61

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/container.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static int container_setup_volume(struct hyper_container *container)
134134
if (!strcmp(vol->fstype, "xfs"))
135135
options = "nouuid";
136136

137-
if (mount(dev, path, vol->fstype, 0, options) < 0) {
137+
if (hyper_mount_blockdev(dev, path, vol->fstype, options) < 0) {
138138
perror("mount volume device failed");
139139
return -1;
140140
}
@@ -588,7 +588,7 @@ static int hyper_setup_container_rootfs(void *data)
588588
if (!strncmp(container->fstype, "xfs", strlen("xfs")))
589589
options = "nouuid";
590590

591-
if (mount(dev, root, container->fstype, 0, options) < 0) {
591+
if (hyper_mount_blockdev(dev, root, container->fstype, options) < 0) {
592592
perror("mount device failed");
593593
goto fail;
594594
}

src/util.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,3 +913,21 @@ int hyper_eventfd_send(int fd, int64_t type)
913913

914914
return 0;
915915
}
916+
917+
/* block device might not be present when we call mount. Sleep a bit in such case */
918+
int hyper_mount_blockdev(const char *dev, const char *root, const char *fstype, const char *options)
919+
{
920+
int i, retry = 5;
921+
922+
for (i = 0; i < retry; i++) {
923+
if (mount(dev, root, fstype, 0, options) < 0) {
924+
if (errno != ENOENT)
925+
return -1;
926+
usleep(20000);
927+
continue;
928+
}
929+
return 0;
930+
}
931+
932+
return -1;
933+
}

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ ssize_t nonblock_read(int fd, void *buf, size_t count);
5050
int hyper_mount_nfs(char *server, char *mountpoint);
5151
int64_t hyper_eventfd_recv(int fd);
5252
int hyper_eventfd_send(int fd, int64_t type);
53+
int hyper_mount_blockdev(const char *dev, const char *root, const char *fstype, const char *options);
5354
#endif

0 commit comments

Comments
 (0)