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

Commit 823a7a2

Browse files
authored
Merge pull request #302 from bergwolf/scsi-ready
retry blockdev mount
2 parents ec39c70 + 1b1924b commit 823a7a2

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
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: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,22 @@ int hyper_find_sd(char *addr, char **dev)
102102
struct dirent **list;
103103
struct dirent *dir;
104104
char path[512];
105-
int i, num;
105+
int i, num, retry = 5;
106106

107107
sprintf(path, "/sys/class/scsi_disk/0:0:%s/device/block/", addr);
108108
fprintf(stdout, "orig dev %s, scan path %s\n", *dev, path);
109109

110-
num = scandir(path, &list, NULL, NULL);
111-
if (num < 0) {
112-
perror("scan path failed");
113-
return -1;
110+
for (i = 0;; i++) {
111+
num = scandir(path, &list, NULL, NULL);
112+
if (num < 0) {
113+
if (errno != ENOENT || i >= retry) {
114+
perror("scan path failed");
115+
return -1;
116+
}
117+
usleep(20000);
118+
continue;
119+
}
120+
break;
114121
}
115122

116123
for (i = 0; i < num; i++) {
@@ -913,3 +920,21 @@ int hyper_eventfd_send(int fd, int64_t type)
913920

914921
return 0;
915922
}
923+
924+
/* block device might not be present when we call mount. Sleep a bit in such case */
925+
int hyper_mount_blockdev(const char *dev, const char *root, const char *fstype, const char *options)
926+
{
927+
int i, retry = 5;
928+
929+
for (i = 0; i < retry; i++) {
930+
if (mount(dev, root, fstype, 0, options) < 0) {
931+
if (errno != ENOENT)
932+
return -1;
933+
usleep(20000);
934+
continue;
935+
}
936+
return 0;
937+
}
938+
939+
return -1;
940+
}

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)