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

Commit 1b1924b

Browse files
committed
wait device in hyper find sd
The device sysfs might not be present right after device hotplug. Signed-off-by: Peng Tao <bergwolf@gmail.com>
1 parent 8972e61 commit 1b1924b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/util.c

Lines changed: 12 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++) {

0 commit comments

Comments
 (0)