Received: from eggs.gnu.org ([208.118.235.92]:45820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYCvm-0007BJ-9K for qemu-devel@nongnu.org; Fri, 03 May 2013 06:09:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYCvj-0002Hl-HJ for qemu-devel@nongnu.org; Fri, 03 May 2013 06:09:34 -0400 Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]:36011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYCvj-0002HX-BF for qemu-devel@nongnu.org; Fri, 03 May 2013 06:09:31 -0400 Received: by mail-wi0-f175.google.com with SMTP id h11so431674wiv.14 for ; Fri, 03 May 2013 03:09:30 -0700 (PDT) Date: Fri, 3 May 2013 12:09:27 +0200 From: Stefan Hajnoczi Message-ID: <20130503100927.GE24864@stefanha-thinkpad.redhat.com> References: <1367549122-2948-1-git-send-email-qemulist@gmail.com> <1367549122-2948-7-git-send-email-qemulist@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1367549122-2948-7-git-send-email-qemulist@gmail.com> Subject: Re: [Qemu-devel] [PATCH v2 6/6] virtio-blk: release reference to RAM's memoryRegion List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Ping Fan Cc: Peter Maydell , Anthony Liguori , Jan Kiszka , qemu-devel@nongnu.org, Vasilis Liaskovitis , Stefan Hajnoczi , Paolo Bonzini On Fri, May 03, 2013 at 10:45:22AM +0800, Liu Ping Fan wrote: > From: Liu Ping Fan > > virtio-blk will unref RAM's memoryRegion when the io-req has been > done. So we can avoid to call bdrv_drain_all() when RAM hot unplug. > > Signed-off-by: Liu Ping Fan > --- > hw/block/dataplane/virtio-blk.c | 51 +++++++++++++++++++++++++++++--------- > 1 files changed, 39 insertions(+), 12 deletions(-) > > diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c > index 3bb57d1..047e1df 100644 > --- a/hw/block/dataplane/virtio-blk.c > +++ b/hw/block/dataplane/virtio-blk.c > @@ -35,6 +35,8 @@ enum { > > typedef struct { > struct iocb iocb; /* Linux AIO control block */ > + MemoryRegion *mrs[VRING_MAX]; > + int mrs_cnt; > QEMUIOVector *inhdr; /* iovecs for virtio_blk_inhdr */ > unsigned int head; /* vring descriptor index */ > struct iovec *bounce_iov; /* used if guest buffers are unaligned */ > @@ -121,6 +123,10 @@ static void complete_request(struct iocb *iocb, ssize_t ret, void *opaque) > * transferred plus the status bytes. > */ > vring_push(&s->vring, req->head, len + sizeof(hdr)); > + while (--req->mrs_cnt >= 0) { > + memory_region_unref(req->mrs[req->mrs_cnt]); > + } The vring has the property that every virtqueue element popped will be pushed back. Therefore it might be nicer to hide the MemoryRegion unref inside vring_push(). The user wouldn't have to know about MemoryRegion - that's especially nice since there are other devices besides virtio-blk (like virtio-net) that would need to be modified if we use the current approach. Stefan