From patchwork Thu Oct 8 18:58:24 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 35513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D1195B70B3 for ; Fri, 9 Oct 2009 06:22:10 +1100 (EST) Received: from localhost ([127.0.0.1]:35621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvyYy-0003GN-2w for incoming@patchwork.ozlabs.org; Thu, 08 Oct 2009 15:22:08 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvyET-0006OW-34 for qemu-devel@nongnu.org; Thu, 08 Oct 2009 15:00:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvyEL-0006JF-Oy for qemu-devel@nongnu.org; Thu, 08 Oct 2009 15:00:54 -0400 Received: from [199.232.76.173] (port=52364 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvyEK-0006Hx-Ns for qemu-devel@nongnu.org; Thu, 08 Oct 2009 15:00:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53193) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvyEG-00074p-Iz for qemu-devel@nongnu.org; Thu, 08 Oct 2009 15:00:45 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n98J0hbJ030918 for ; Thu, 8 Oct 2009 15:00:44 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n98J0DTd028608; Thu, 8 Oct 2009 15:00:39 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id 5779650D22; Thu, 8 Oct 2009 19:58:33 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Thu, 8 Oct 2009 19:58:24 +0100 Message-Id: <1255028312-28180-9-git-send-email-markmc@redhat.com> In-Reply-To: <1255028312-28180-1-git-send-email-markmc@redhat.com> References: <1255028312-28180-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 08/16] net: allow clients not associated with a vlan X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Allow net clients to be created which are not connected to any vlan. This is needed by Gerd in order to allow adding -device nic, where the absence of a vlan parameter will not imply vlan=0. Also needed to allow adding a -netdevice option which doesn't connect the backend to a vlan. Signed-off-by: Mark McLoughlin --- net.c | 30 +++++++++++++++++++++++------- 1 files changed, 23 insertions(+), 7 deletions(-) diff --git a/net.c b/net.c index 35547a5..6cd63aa 100644 --- a/net.c +++ b/net.c @@ -324,15 +324,19 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan, vc->cleanup = cleanup; vc->opaque = opaque; - vc->vlan = vlan; - QTAILQ_INSERT_TAIL(&vc->vlan->clients, vc, next); + if (vlan) { + vc->vlan = vlan; + QTAILQ_INSERT_TAIL(&vc->vlan->clients, vc, next); + } return vc; } void qemu_del_vlan_client(VLANClientState *vc) { - QTAILQ_REMOVE(&vc->vlan->clients, vc, next); + if (vc->vlan) { + QTAILQ_REMOVE(&vc->vlan->clients, vc, next); + } if (vc->cleanup) { vc->cleanup(vc); @@ -387,6 +391,10 @@ int qemu_can_send_packet(VLANClientState *sender) VLANState *vlan = sender->vlan; VLANClientState *vc; + if (!sender->vlan) { + return 1; + } + QTAILQ_FOREACH(vc, &vlan->clients, next) { if (vc == sender) { continue; @@ -434,6 +442,9 @@ void qemu_purge_queued_packets(VLANClientState *vc) { VLANPacket *packet, *next; + if (!vc->vlan) + return; + QTAILQ_FOREACH_SAFE(packet, &vc->vlan->send_queue, entry, next) { if (packet->sender == vc) { QTAILQ_REMOVE(&vc->vlan->send_queue, packet, entry); @@ -444,6 +455,9 @@ void qemu_purge_queued_packets(VLANClientState *vc) void qemu_flush_queued_packets(VLANClientState *vc) { + if (!vc->vlan) + return; + while (!QTAILQ_EMPTY(&vc->vlan->send_queue)) { VLANPacket *packet; int ret; @@ -485,12 +499,12 @@ ssize_t qemu_send_packet_async(VLANClientState *sender, { int ret; - if (sender->link_down) { + if (sender->link_down || !sender->vlan) { return size; } #ifdef DEBUG_NET - printf("vlan %d send:\n", sender->vlan->id); + printf("qemu_send_packet_async:\n"); hex_dump(stdout, buf, size); #endif @@ -610,7 +624,7 @@ ssize_t qemu_sendv_packet_async(VLANClientState *sender, { int ret; - if (sender->link_down) { + if (sender->link_down || !sender->vlan) { return calc_iov_length(iov, iovcnt); } @@ -3020,7 +3034,9 @@ int net_client_init(Monitor *mon, QemuOpts *opts) void net_client_uninit(NICInfo *nd) { - nd->vlan->nb_guest_devs--; + if (nd->vlan) { + nd->vlan->nb_guest_devs--; + } nb_nics--; qemu_free(nd->model);