From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UovEB-0000SP-9Q for qemu-devel@nongnu.org; Tue, 18 Jun 2013 08:41:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UovEA-00041R-4H for qemu-devel@nongnu.org; Tue, 18 Jun 2013 08:41:39 -0400 Received: from mail-wg0-x236.google.com ([2a00:1450:400c:c00::236]:54408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UovE9-00041D-Tj for qemu-devel@nongnu.org; Tue, 18 Jun 2013 08:41:38 -0400 Received: by mail-wg0-f54.google.com with SMTP id n11so3369995wgh.33 for ; Tue, 18 Jun 2013 05:41:36 -0700 (PDT) Date: Tue, 18 Jun 2013 14:41:33 +0200 From: Stefan Hajnoczi Message-ID: <20130618124133.GJ7649@stefanha-thinkpad.redhat.com> References: <1371114186-8854-1-git-send-email-qemulist@gmail.com> <1371114186-8854-4-git-send-email-qemulist@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1371114186-8854-4-git-send-email-qemulist@gmail.com> Subject: Re: [Qemu-devel] [PATCH v2 3/6] net: make netclient re-entrant with refcnt List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Ping Fan Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , mdroth On Thu, Jun 13, 2013 at 05:03:03PM +0800, Liu Ping Fan wrote: > From: Liu Ping Fan > > With refcnt, NetClientState's user can run agaist deleter. Please split this into two patches: 1. net_clients lock 2. NetClientState refcount > > Signed-off-by: Liu Ping Fan > --- > hw/core/qdev-properties-system.c | 14 ++++++++++++ > include/net/net.h | 3 +++ > net/hub.c | 3 +++ > net/net.c | 47 +++++++++++++++++++++++++++++++++++++--- > net/slirp.c | 3 ++- > 5 files changed, 66 insertions(+), 4 deletions(-) > > diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c > index 0eada32..41cc7e6 100644 > --- a/hw/core/qdev-properties-system.c > +++ b/hw/core/qdev-properties-system.c > @@ -302,6 +302,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque, > return; > } > > + /* inc ref, released when unset property */ > hubport = net_hub_port_find(id); > if (!hubport) { > error_set(errp, QERR_INVALID_PARAMETER_VALUE, > @@ -311,11 +312,24 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque, > *ptr = hubport; > } > > +static void release_vlan(Object *obj, const char *name, void *opaque) > +{ > + DeviceState *dev = DEVICE(obj); > + Property *prop = opaque; > + NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop); > + NetClientState **ptr = &peers_ptr->ncs[0]; > + > + if (*ptr) { > + netclient_unref(*ptr); > + } > +} > + > PropertyInfo qdev_prop_vlan = { > .name = "vlan", > .print = print_vlan, > .get = get_vlan, > .set = set_vlan, > + .release = release_vlan, > }; > > int qdev_prop_set_drive(DeviceState *dev, const char *name, What about the netdev property? I don't see any refcount code there. > @@ -1109,6 +1146,7 @@ void net_cleanup(void) > qemu_del_net_client(nc); > } > } > + qemu_mutex_destroy(&net_clients_lock); Why is it okay to iterate over net_clients here without the lock?