From nobody Wed May 1 03:23:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1493371475454959.5153208221678; Fri, 28 Apr 2017 02:24:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7FD09F75C; Fri, 28 Apr 2017 09:24:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A457B8B761; Fri, 28 Apr 2017 09:24:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5C98C4ED27; Fri, 28 Apr 2017 09:24:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3S9OL9p023815 for ; Fri, 28 Apr 2017 05:24:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 695544DA4A; Fri, 28 Apr 2017 09:24:21 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 60BC184990 for ; Fri, 28 Apr 2017 09:24:18 +0000 (UTC) Received: from out1.zte.com.cn (out1.zte.com.cn [202.103.147.172]) by mx1.redhat.com (Postfix) with ESMTP id 6CD33C04B31B for ; Fri, 28 Apr 2017 09:24:16 +0000 (UTC) Received: from unknown (HELO mse01.zte.com.cn) (10.30.3.20) by localhost with (AES256-SHA encrypted) SMTP; 28 Apr 2017 09:14:27 -0000 Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v3S9Na9N094133 for ; Fri, 28 Apr 2017 17:23:36 +0800 (GMT-8) (envelope-from lu.zhipeng@zte.com.cn) Received: from ceshi.localdomain ([10.74.120.130]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017042817234175-98187 ; Fri, 28 Apr 2017 17:23:41 +0800 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D7FD09F75C Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=zte.com.cn Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D7FD09F75C DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6CD33C04B31B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=zte.com.cn Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=lu.zhipeng@zte.com.cn DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6CD33C04B31B X-scanvirus: By SEG_CYREN AntiVirus Engine X-scanresult: CLEAN X-MAILFROM: X-RCPTTO: X-FROMIP: 10.30.3.20 X-SEG-Scaned: 1 X-Received: unknown,10.30.3.20,20170428171427 From: ZhiPeng Lu To: libvir-list@redhat.com Date: Fri, 28 Apr 2017 17:23:19 +0800 Message-Id: <1493371399-25799-1-git-send-email-lu.zhipeng@zte.com.cn> X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-04-28 17:23:41, Serialize by Router on notes_smtp/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-04-28 17:23:35, Serialize complete at 2017-04-28 17:23:35 X-MAIL: mse01.zte.com.cn v3S9Na9N094133 X-HQIP: 127.0.0.1 X-Greylist: Delayed for 72:06:16 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 28 Apr 2017 09:24:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 28 Apr 2017 09:24:17 +0000 (UTC) for IP:'202.103.147.172' DOMAIN:'out1.zte.com.cn' HELO:'out1.zte.com.cn' FROM:'lu.zhipeng@zte.com.cn' RCPT:'' X-RedHat-Spam-Score: 0.378 (BAYES_50, DCC_REPUT_00_12, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RP_MATCHES_RCVD, SPF_PASS) 202.103.147.172 out1.zte.com.cn 202.103.147.172 out1.zte.com.cn X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: ZhiPeng Lu Subject: [libvirt] [PATCH] qemu: change the name of tap device for a tap and bridge network X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 28 Apr 2017 09:24:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Creating tap device and adding the device to bridge are not atomic operatio= n. Similarly deleting tap device and removing it from bridge are not atomic op= eration. The Problem occurs when two vms start and shutdown. When one vm with the nic named "vnet0" stopping, it deleted tap device but not removing port from br= idge. At this time, another vm created the tap device named "vnet0" and added por= t to the same bridge. Then, the first vm deleted the tap device from the same bridge. Finally, the tap device of the second vm don't attached to the bridge. So, we can add domid to vm's nic name. For example, the vm's domid is 1 and= vnet0 is renamed to vnet1.0. Signed-off-by: ZhiPeng Lu --- src/qemu/qemu_interface.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index d0850c0..17d40a7 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -512,6 +512,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def, bool template_ifname =3D false; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); const char *tunpath =3D "/dev/net/tun"; + char *domIdPlusIndex =3D NULL; =20 if (net->backend.tap) { tunpath =3D net->backend.tap; @@ -531,8 +532,13 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def, STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) || strchr(net->ifname, '%')) { VIR_FREE(net->ifname); - if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_PREFIX "%d") < 0) + if (virAsprintf(&domIdPlusIndex, "%s%d.%s", + VIR_NET_GENERATED_PREFIX, def->id, "%d") < 0) { + goto cleanup; + } + if (VIR_STRDUP(net->ifname, domIdPlusIndex) < 0) { goto cleanup; + } /* avoid exposing vnet%d in getXMLDesc or error outputs */ template_ifname =3D true; } @@ -594,6 +600,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def, ret =3D 0; =20 cleanup: + VIR_FREE(domIdPlusIndex); if (ret < 0) { size_t i; for (i =3D 0; i < *tapfdSize && tapfd[i] >=3D 0; i++) --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list