From patchwork Tue Jan 29 13:51:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 216556 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BD6B72C0097 for ; Wed, 30 Jan 2013 01:42:24 +1100 (EST) Received: from localhost ([::1]:58326 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0Bla-0002ps-W0 for incoming@patchwork.ozlabs.org; Tue, 29 Jan 2013 09:02:26 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0Bkk-0000qI-6k for qemu-devel@nongnu.org; Tue, 29 Jan 2013 09:01:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U0Bkf-0007Ht-64 for qemu-devel@nongnu.org; Tue, 29 Jan 2013 09:01:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41341) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0Bke-0007Hl-Tr for qemu-devel@nongnu.org; Tue, 29 Jan 2013 09:01:29 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0TE1Jri015779 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 29 Jan 2013 09:01:20 -0500 Received: from amd-6168-8-1.englab.nay.redhat.com (amd-6168-8-1.englab.nay.redhat.com [10.66.104.52]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0TE06tn025703; Tue, 29 Jan 2013 09:01:16 -0500 From: Jason Wang To: mst@redhat.com, qemu-devel@nongnu.org, aliguori@us.ibm.com, shajnocz@redhat.com Date: Tue, 29 Jan 2013 21:51:18 +0800 Message-Id: <1359467492-31704-7-git-send-email-jasowang@redhat.com> In-Reply-To: <1359467492-31704-1-git-send-email-jasowang@redhat.com> References: <1359467492-31704-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: krkumar2@in.ibm.com, kvm@vger.kernel.org, mprivozn@redhat.com, Jason Wang , rusty@rustcorp.com.au, gaowanlong@cn.fujitsu.com, jwhan@filewood.snu.ac.kr, shiyer@redhat.com Subject: [Qemu-devel] [PATCH V3 06/20] net: introduce NetClientState destructor X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org To allow allocating an array of NetClientState and free it once, this patch introduces destructor of NetClientState. Which could do type specific free, which could be used by multiqueue to free the array once. Signed-off-by: Jason Wang --- include/net/net.h | 2 ++ net/net.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 995df5c..22adc99 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -35,6 +35,7 @@ typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int); typedef void (NetCleanup) (NetClientState *); typedef void (LinkStatusChanged)(NetClientState *); +typedef void (NetClientDestructor)(NetClientState *); typedef struct NetClientInfo { NetClientOptionsKind type; @@ -58,6 +59,7 @@ struct NetClientState { char *name; char info_str[256]; unsigned receive_disabled : 1; + NetClientDestructor *destructor; }; typedef struct NICState { diff --git a/net/net.c b/net/net.c index 4e84d54..6368896 100644 --- a/net/net.c +++ b/net/net.c @@ -182,11 +182,17 @@ static char *assign_name(NetClientState *nc1, const char *model) return g_strdup(buf); } +static void qemu_net_client_destructor(NetClientState *nc) +{ + g_free(nc); +} + static void qemu_net_client_setup(NetClientState *nc, NetClientInfo *info, NetClientState *peer, const char *model, - const char *name) + const char *name, + NetClientDestructor *destructor) { nc->info = info; nc->model = g_strdup(model); @@ -204,7 +210,7 @@ static void qemu_net_client_setup(NetClientState *nc, QTAILQ_INSERT_TAIL(&net_clients, nc, next); nc->send_queue = qemu_new_net_queue(nc); - + nc->destructor = destructor; } NetClientState *qemu_new_net_client(NetClientInfo *info, @@ -217,7 +223,8 @@ NetClientState *qemu_new_net_client(NetClientInfo *info, assert(info->size >= sizeof(NetClientState)); nc = g_malloc0(info->size); - qemu_net_client_setup(nc, info, peer, model, name); + qemu_net_client_setup(nc, info, peer, model, name, + qemu_net_client_destructor); return nc; } @@ -279,7 +286,9 @@ static void qemu_free_net_client(NetClientState *nc) } g_free(nc->name); g_free(nc->model); - g_free(nc); + if (nc->destructor) { + nc->destructor(nc); + } } void qemu_del_net_client(NetClientState *nc)