From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UouyL-0005QK-CN for qemu-devel@nongnu.org; Tue, 18 Jun 2013 08:25:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UouyG-0007Fb-97 for qemu-devel@nongnu.org; Tue, 18 Jun 2013 08:25:17 -0400 Received: from mail-wg0-x231.google.com ([2a00:1450:400c:c00::231]:53837) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UouyG-0007FQ-3L for qemu-devel@nongnu.org; Tue, 18 Jun 2013 08:25:12 -0400 Received: by mail-wg0-f49.google.com with SMTP id a12so3330117wgh.4 for ; Tue, 18 Jun 2013 05:25:11 -0700 (PDT) Date: Tue, 18 Jun 2013 14:25:07 +0200 From: Stefan Hajnoczi Message-ID: <20130618122507.GI7649@stefanha-thinkpad.redhat.com> References: <1371114186-8854-1-git-send-email-qemulist@gmail.com> <1371114186-8854-3-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-3-git-send-email-qemulist@gmail.com> Subject: Re: [Qemu-devel] [PATCH v2 2/6] net: introduce lock to protect NetClientState's peer's access 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:02PM +0800, Liu Ping Fan wrote: > @@ -67,6 +67,10 @@ struct NetClientState { > NetClientInfo *info; > int link_down; > QTAILQ_ENTRY(NetClientState) next; > + /* protect the race access of peer only between reader and writer. > + * to resolve the writer's race condition, resort on biglock. > + */ Indentation > @@ -301,6 +303,38 @@ static void qemu_free_net_client(NetClientState *nc) > } > } > > +/* elimate the reference and sync with exit of rx/tx action. s/elimate/Eliminate/ > + * And flush out peer's queue. > + */ > +static void qemu_net_client_detach_flush(NetClientState *nc) > +{ > + NetClientState *peer; > + > + /* reader of self's peer field , fixme? the deleters are not concurrent, > + * so this pair lock can save. > + */ Indentation, also please resolve the fixme. > @@ -394,6 +433,28 @@ int qemu_can_send_packet(NetClientState *sender) > return 1; > } > > +int qemu_can_send_packet(NetClientState *sender) > +{ > + int ret = 1; > + > + qemu_mutex_lock(&sender->peer_lock); > + if (!sender->peer) { > + goto unlock; > + } > + > + if (sender->peer->receive_disabled) { > + ret = 0; > + goto unlock; > + } else if (sender->peer->info->can_receive && > + !sender->peer->info->can_receive(sender->peer)) { > + ret = 0; > + goto unlock; > + } Just call qemu_can_send_packet_nolock() instead of duplicating code?