From patchwork Tue Mar 6 05:11:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: linzhecheng X-Patchwork-Id: 881921 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zwQ1q1hT2z9sb5 for ; Tue, 6 Mar 2018 16:14:38 +1100 (AEDT) Received: from localhost ([::1]:53532 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et4vs-0004J2-JS for incoming@patchwork.ozlabs.org; Tue, 06 Mar 2018 00:14:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et4vW-0004Il-EX for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:14:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1et4vT-0008Ul-Ae for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:14:14 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2609 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1et4vS-0008TW-VL for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:14:11 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 3C7C02A949C65; Tue, 6 Mar 2018 13:13:53 +0800 (CST) Received: from localhost (10.177.131.80) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.361.1; Tue, 6 Mar 2018 13:13:49 +0800 From: linzhecheng To: Date: Tue, 6 Mar 2018 13:11:25 +0800 Message-ID: <20180306051125.32812-1-linzhecheng@huawei.com> X-Mailer: git-send-email 2.12.2.windows.2 MIME-Version: 1.0 X-Originating-IP: [10.177.131.80] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 45.249.212.190 Subject: [Qemu-devel] [PATCH] tap: delete tap(net client) if net_init_tap_one failed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linzhecheng , jasowang@redhat.com, wangxinxin.wang@huawei.com, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" If net_init_tap_one failed but net_tap_fd_init succeeded, we should delete the TAPState *s without vhostforce and has_vhostforce flag. Signed-off-by: linzhecheng diff --git a/net/tap.c b/net/tap.c index 2b3a36f9b5..1cb8eaf31f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -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)