Skip to contentSkip to conversation

tap: delete tap(net client) if net_init_tap_one failed

PATCH In review linzhecheng 2 participants 2 messages Mar 6, 2018 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tap: delete tap(net client) if net_init_tap_one failed

If net_init_tap_one failed but net_tap_fd_init succeeded, we should delete the TAPState *s without vhostforce and has_vhostforce flag.

net/tap.c +8 -1
index 2b3a36f9b5..1cb8eaf31f 100644
@@ -651,7 +651,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
     tap_set_sndbuf(s->fd, tap, &err);
     if (err) {
         error_propagate(errp, err);
-        return;
+        goto fail;
     }
 
     if (tap->has_fd || tap->has_fds) {
@@ -688,6 +688,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
             if (vhostfd == -1) {
                 if (tap->has_vhostforce && tap->vhostforce) {
                     error_propagate(errp, err);
+                    goto fail;
                 } else {
                     warn_report_err(err);
                 }
@@ -699,6 +700,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
                 if (tap->has_vhostforce && tap->vhostforce) {
                     error_setg_errno(errp, errno,
                                      "tap: open vhost char device failed");
+                    goto fail;
                 } else {
                     warn_report("tap: open vhost char device failed: %s",
                                 strerror(errno));
@@ -713,6 +715,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
         if (!s->vhost_net) {
             if (tap->has_vhostforce && tap->vhostforce) {
                 error_setg(errp, VHOST_NET_INIT_FAILED);
+                goto fail;
             } else {
                 warn_report(VHOST_NET_INIT_FAILED);
             }
@@ -720,7 +723,11 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
         }
     } else if (vhostfdname) {
         error_setg(errp, "vhostfd(s)= is not valid without vhost");
+        goto fail;
     }
+    return;
+fail:
+    qemu_del_net_client(&s->nc);
 }
 
 static int get_fds(char *str, char *fds[], int max)
Signature · 1 line
2.12.2.windows.2
#1 lore raw
Quoted 4 lines · linzhecheng

If net_init_tap_one failed but net_tap_fd_init succeeded, we should delete the TAPState *s without vhostforce and has_vhostforce flag.

Applied and queued for stable.

Thanks

Quoted 50 lines
net/tap.c +8 -1
index 2b3a36f9b5..1cb8eaf31f 100644
@@ -651,7 +651,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
      tap_set_sndbuf(s->fd, tap, &err);
      if (err) {
          error_propagate(errp, err);
-        return;
+        goto fail;
      }
 
      if (tap->has_fd || tap->has_fds) {
@@ -688,6 +688,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
              if (vhostfd == -1) {
                  if (tap->has_vhostforce && tap->vhostforce) {
                      error_propagate(errp, err);
+                    goto fail;
                  } else {
                      warn_report_err(err);
                  }
@@ -699,6 +700,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
                  if (tap->has_vhostforce && tap->vhostforce) {
                      error_setg_errno(errp, errno,
                                       "tap: open vhost char device failed");
+                    goto fail;
                  } else {
                      warn_report("tap: open vhost char device failed: %s",
                                  strerror(errno));
@@ -713,6 +715,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
          if (!s->vhost_net) {
              if (tap->has_vhostforce && tap->vhostforce) {
                  error_setg(errp, VHOST_NET_INIT_FAILED);
+                goto fail;
              } else {
                  warn_report(VHOST_NET_INIT_FAILED);
              }
@@ -720,7 +723,11 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
          }
      } else if (vhostfdname) {
          error_setg(errp, "vhostfd(s)= is not valid without vhost");
+        goto fail;
      }
+    return;
+fail:
+    qemu_del_net_client(&s->nc);
  }
 
  static int get_fds(char *str, char *fds[], int max)