Skip to content

Commit 76410d7

Browse files
committed
Add retry when bring up the network interface
During SW reset, the network interface could still be busy. This commit adds a robust retry when the returning code is EBUSY. Signed-off-by: Liming Sun <lsun@mellanox.com>
1 parent 9337c40 commit 76410d7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/rshim.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3187,10 +3187,9 @@ int rshim_register(rshim_backend_t *bd)
31873187
sizeof(init_console_termios));
31883188

31893189
bd->index = index;
3190-
if (rshim_dev_names[index] != bd->dev_name) {
3190+
if (rshim_dev_names[index])
31913191
free(rshim_dev_names[index]);
3192-
rshim_dev_names[index] = bd->dev_name;
3193-
}
3192+
rshim_dev_names[index] = strdup(bd->dev_name);
31943193
rshim_devs[index] = bd;
31953194

31963195
for (i = 0; i < 2; i++) {

src/rshim_net.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int rshim_if_open(char *ifname, int index)
5151
{
5252
char cmd[128];
5353
struct ifreq ifr;
54-
int s, fd, rc;
54+
int s, fd, rc, retry;
5555

5656
rc = system("modprobe tun");
5757
if (rc == -1)
@@ -67,8 +67,14 @@ static int rshim_if_open(char *ifname, int index)
6767
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
6868
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
6969

70-
if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) {
71-
RSHIM_ERR("ioctl failed: %m\n");
70+
retry = 16;
71+
do {
72+
rc = ioctl(fd, TUNSETIFF, (void *) &ifr);
73+
if (rc == -1 && retry)
74+
sleep(1);
75+
} while (rc == -1 && errno == EBUSY && retry--);
76+
if (rc < 0) {
77+
RSHIM_ERR("ioctl failed: %m, errno=%d\n", errno);
7278
close(fd);
7379
return -1;
7480
}

0 commit comments

Comments
 (0)