From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMPG1-000114-CA for qemu-devel@nongnu.org; Fri, 13 Feb 2015 18:02:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YMPFy-0004bj-3w for qemu-devel@nongnu.org; Fri, 13 Feb 2015 18:02:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38984) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMPFx-0004bX-Tb for qemu-devel@nongnu.org; Fri, 13 Feb 2015 18:02:42 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1DN2e8R022325 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 13 Feb 2015 18:02:40 -0500 Message-ID: <54DE828F.7040604@redhat.com> Date: Fri, 13 Feb 2015 18:02:39 -0500 From: Max Reitz MIME-Version: 1.0 References: <1423507124-29809-1-git-send-email-mreitz@redhat.com> <1423507124-29809-8-git-send-email-mreitz@redhat.com> In-Reply-To: <1423507124-29809-8-git-send-email-mreitz@redhat.com> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 07/22] block: Add bdrv_close_all() handlers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi On 2015-02-09 at 13:38, Max Reitz wrote: > Every time a reference to a BlockBackend is taken, a notifier for > bdrv_close_all() has to be deposited so the reference holder can > relinquish its reference when bdrv_close_all() is called. That notifier > should be revoked on a bdrv_unref() call. > > Add a Notifier * parameter to all the functions changing the reference > count of a BlockBackend: blk_new(), blk_new_with_bs(), blk_new_open(), > blk_ref() and blk_unref(). > > By dropping the manual reference handling in hw/block/xen_disk.c, the > blk_unref() in hw/ide/piix.c can be dropped as well. > > Signed-off-by: Max Reitz > --- > block/block-backend.c | 69 ++++++++++++++++++++++++++++++++++++------ > blockdev.c | 62 ++++++++++++++++++++++++++++++++++--- > device-hotplug.c | 2 +- > hw/block/xen_disk.c | 16 +++++++--- > hw/ide/piix.c | 1 - > include/sysemu/block-backend.h | 13 +++++--- > include/sysemu/blockdev.h | 3 ++ > nbd.c | 26 ++++++++++++++-- > qemu-img.c | 39 ++++++++++++------------ > qemu-io.c | 6 ++-- > qemu-nbd.c | 6 ++-- > 11 files changed, 189 insertions(+), 54 deletions(-) [snip] > diff --git a/qemu-nbd.c b/qemu-nbd.c > index ac1e5d6..5e6e4b4 100644 > --- a/qemu-nbd.c > +++ b/qemu-nbd.c > @@ -694,7 +694,8 @@ int main(int argc, char **argv) > } > > srcpath = argv[optind]; > - blk = blk_new_open("hda", srcpath, NULL, options, flags, &local_err); > + /* the reference will be passed on nbd_export_new() */ > + blk = blk_new_open("hda", srcpath, NULL, options, flags, NULL, &local_err); > if (!blk) { > errx(EXIT_FAILURE, "Failed to blk_new_open '%s': %s", argv[optind], > error_get_pretty(local_err)); > @@ -728,7 +729,9 @@ int main(int argc, char **argv) > } > } > > + /* nbd_export_new() takes the reference to blk */ > exp = nbd_export_new(blk, dev_offset, fd_size, nbdflags, nbd_export_closed); > + blk_unref(blk, NULL); > > if (sockpath) { > fd = unix_socket_incoming(sockpath); > @@ -773,7 +776,6 @@ int main(int argc, char **argv) > } > } while (state != TERMINATED); > > - blk_unref(blk); > if (sockpath) { > unlink(sockpath); > } Because qemu-nbd does not install a handler for relinquishing its reference, it has to make sure it drops that reference before a bdrv_close_all() occurs. Therefore, err() and errx() calls after blk_new_open() (except for the if (!blk) path) and before blk_unref(blk, NULL) need to be preceded by a blk_unref(blk, NULL). I'll fix it in v3. Max