Commit 4a77b25e2af0ccfa637c963f64a01468edcf94ac

Authored by Mark McLoughlin
Committed by Anthony Liguori
1 parent 1f7babf6

net: return TAPState from net_tap_init()

net_tap_fd_init() already returns TAPState, so this is a sensible
cleanup in its own right.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing 1 changed file with 16 additions and 11 deletions
... ... @@ -1429,9 +1429,9 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
1429 1429 return -1;
1430 1430 }
1431 1431  
1432   -static int net_tap_init(VLANState *vlan, const char *model,
1433   - const char *name, const char *ifname1,
1434   - const char *setup_script, const char *down_script)
  1432 +static TAPState *net_tap_init(VLANState *vlan, const char *model,
  1433 + const char *name, const char *ifname1,
  1434 + const char *setup_script, const char *down_script)
1435 1435 {
1436 1436 TAPState *s;
1437 1437 int fd;
... ... @@ -1443,13 +1443,13 @@ static int net_tap_init(VLANState *vlan, const char *model,
1443 1443 ifname[0] = '\0';
1444 1444 TFR(fd = tap_open(ifname, sizeof(ifname)));
1445 1445 if (fd < 0)
1446   - return -1;
  1446 + return NULL;
1447 1447  
1448 1448 if (!setup_script || !strcmp(setup_script, "no"))
1449 1449 setup_script = "";
1450   - if (setup_script[0] != '\0') {
1451   - if (launch_script(setup_script, ifname, fd))
1452   - return -1;
  1450 + if (setup_script[0] != '\0' &&
  1451 + launch_script(setup_script, ifname, fd)) {
  1452 + return NULL;
1453 1453 }
1454 1454 s = net_tap_fd_init(vlan, model, name, fd);
1455 1455 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
... ... @@ -1459,7 +1459,7 @@ static int net_tap_init(VLANState *vlan, const char *model,
1459 1459 snprintf(s->down_script, sizeof(s->down_script), "%s", down_script);
1460 1460 snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname);
1461 1461 }
1462   - return 0;
  1462 + return s;
1463 1463 }
1464 1464  
1465 1465 #endif /* !_WIN32 */
... ... @@ -2294,6 +2294,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
2294 2294 if (!strcmp(device, "tap")) {
2295 2295 char ifname[64], chkbuf[64];
2296 2296 char setup_script[1024], down_script[1024];
  2297 + TAPState *s;
2297 2298 int fd;
2298 2299 vlan->nb_host_devs++;
2299 2300 if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
... ... @@ -2304,8 +2305,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
2304 2305 }
2305 2306 fd = strtol(buf, NULL, 0);
2306 2307 fcntl(fd, F_SETFL, O_NONBLOCK);
2307   - net_tap_fd_init(vlan, device, name, fd);
2308   - ret = 0;
  2308 + s = net_tap_fd_init(vlan, device, name, fd);
2309 2309 } else {
2310 2310 static const char * const tap_params[] = {
2311 2311 "vlan", "name", "ifname", "script", "downscript", NULL
... ... @@ -2324,7 +2324,12 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
2324 2324 if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {
2325 2325 pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);
2326 2326 }
2327   - ret = net_tap_init(vlan, device, name, ifname, setup_script, down_script);
  2327 + s = net_tap_init(vlan, device, name, ifname, setup_script, down_script);
  2328 + }
  2329 + if (s != NULL) {
  2330 + ret = 0;
  2331 + } else {
  2332 + ret = -1;
2328 2333 }
2329 2334 } else
2330 2335 #endif
... ...