Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933305AbZLOSua (ORCPT ); Tue, 15 Dec 2009 13:50:30 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1760838AbZLOSu3 (ORCPT ); Tue, 15 Dec 2009 13:50:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:2402 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760133AbZLOSu1 (ORCPT ); Tue, 15 Dec 2009 13:50:27 -0500 Date: Tue, 15 Dec 2009 20:47:40 +0200 From: "Michael S. Tsirkin" To: Shirley Ma Cc: Rusty Russell , Avi Kivity , netdev@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Anthony Liguori Subject: Re: [RFC PATCH] Subject: virtio: Add unused buffers detach from vring Message-ID: <20091215184740.GD25724@redhat.com> References: <200911231123.18898.rusty@rustcorp.com.au> <20091208122134.GA17286@redhat.com> <1260534506.30371.6.camel@localhost.localdomain> <1260535613.30371.24.camel@localhost.localdomain> <20091213114320.GC7074@redhat.com> <1260828518.8716.105.camel@localhost.localdomain> <20091215113327.GC13110@redhat.com> <1260894320.4387.64.camel@localhost.localdomain> <20091215163901.GA24015@redhat.com> <1260902573.4387.76.camel@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1260902573.4387.76.camel@localhost.localdomain> User-Agent: Mutt/1.5.19 (2009-01-05) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3102 Lines: 103 On Tue, Dec 15, 2009 at 10:42:53AM -0800, Shirley Ma wrote: > I submit one split patch for review to make sure that's the right format. > I copied Rusty's comment for the commit message, and change destroy > to detach since we destroy the buffers in caller. This patch is built > against Dave's net-next tree. Almost :) text not intended for git commit logs like the above should go after ---, this way git am knows to skip it. > There's currently no way for a virtio driver to ask for unused > buffers, so it has to keep a list itself to reclaim them at shutdown. > This is redundant, since virtio_ring stores that information. So > add a new hook to do this: virtio_net will be the first user. > > Signed-off-by: Shirley Ma > --- > drivers/virtio/virtio_ring.c | 24 ++++++++++++++++++++++++ > include/linux/virtio.h | 1 + > 2 files changed, 25 insertions(+), 0 deletions(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index fbd2ecd..f847bc3 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -334,6 +334,29 @@ static bool vring_enable_cb(struct virtqueue *_vq) > return true; > } > > +/* This function is used to return vring unused buffers to caller for free */ > +static void *vring_detach_bufs(struct virtqueue *_vq) > +{ > + struct vring_virtqueue *vq = to_vvq(_vq); > + unsigned int i; > + > + START_USE(vq); > + > + for (i = 0; i < vq->vring.num; ++i) { This is a single statement loop, so you do not need {} around it. Or even better: for (i = 0; i < vq->vring.num; ++i) { if (!vq->data[i]) continue; ... } which has less nesting. > + if (vq->data[i]) { > + /* detach_buf clears data, so grab it now. */ You wrote that comment, but did you read it :) > + detach_buf(vq, i); > + END_USE(vq); > + return vq->data[i]; In fact, this will return NULL always, won't it? > + } > + } > + /* That should have freed everything. */ > + BUG_ON(vq->num_free != vq->vring.num); > + > + END_USE(vq); > + return NULL; > +} > + > irqreturn_t vring_interrupt(int irq, void *_vq) > { > struct vring_virtqueue *vq = to_vvq(_vq); > @@ -360,6 +383,7 @@ static struct virtqueue_ops vring_vq_ops = { > .kick = vring_kick, > .disable_cb = vring_disable_cb, > .enable_cb = vring_enable_cb, > + .detach_bufs = vring_detach_bufs, > }; > > struct virtqueue *vring_new_virtqueue(unsigned int num, > diff --git a/include/linux/virtio.h b/include/linux/virtio.h > index 057a2e0..d7da456 100644 > --- a/include/linux/virtio.h > +++ b/include/linux/virtio.h > @@ -71,6 +71,7 @@ struct virtqueue_ops { > > void (*disable_cb)(struct virtqueue *vq); > bool (*enable_cb)(struct virtqueue *vq); > + void *(*detach_bufs)(struct virtqueue *vq); > }; Please add documentation in virtio.h Thanks! > > /** > > Thanks > Shirley -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/