From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3knl-0000X6-I2 for qemu-devel@nongnu.org; Tue, 01 Dec 2015 08:17:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a3knk-0008Qf-HU for qemu-devel@nongnu.org; Tue, 01 Dec 2015 08:17:01 -0500 Date: Tue, 1 Dec 2015 14:16:49 +0100 From: Kevin Wolf Message-ID: <20151201131649.GE6527@noname.str.redhat.com> References: <1447108773-6836-1-git-send-email-mreitz@redhat.com> <1447108773-6836-15-git-send-email-mreitz@redhat.com> <20151130153621.GF4494@noname.str.redhat.com> <565C85EB.7030504@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="LQksG6bCIzRHxTLp" Content-Disposition: inline In-Reply-To: <565C85EB.7030504@redhat.com> Subject: Re: [Qemu-devel] [PATCH v7 14/24] nbd: Switch from close to eject notifier List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Alberto Garcia , qemu-block@nongnu.org, John Snow , qemu-devel@nongnu.org, Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Am 30.11.2015 um 18:22 hat Max Reitz geschrieben: > On 30.11.2015 16:36, Kevin Wolf wrote: > > Am 09.11.2015 um 23:39 hat Max Reitz geschrieben: > >> The NBD code uses the BDS close notifier to determine when a medium is > >> ejected. However, now it should use the BB's BDS removal notifier for > >> that instead of the BDS's close notifier. > >> > >> Signed-off-by: Max Reitz > >> --- > >> blockdev-nbd.c | 37 +------------------------------------ > >> nbd.c | 13 +++++++++++++ > >> 2 files changed, 14 insertions(+), 36 deletions(-) > >> > >> diff --git a/blockdev-nbd.c b/blockdev-nbd.c > >> index bcdd18b..b28a55b 100644 > >> --- a/blockdev-nbd.c > >> +++ b/blockdev-nbd.c > >> @@ -46,37 +46,11 @@ void qmp_nbd_server_start(SocketAddress *addr, Err= or **errp) > >> } > >> } > >> =20 > >> -/* > >> - * Hook into the BlockBackend notifiers to close the export when the > >> - * backend is closed. > >> - */ > >> -typedef struct NBDCloseNotifier { > >> - Notifier n; > >> - NBDExport *exp; > >> - QTAILQ_ENTRY(NBDCloseNotifier) next; > >> -} NBDCloseNotifier; > >> - > >> -static QTAILQ_HEAD(, NBDCloseNotifier) close_notifiers =3D > >> - QTAILQ_HEAD_INITIALIZER(close_notifiers); > >> - > >> -static void nbd_close_notifier(Notifier *n, void *data) > >> -{ > >> - NBDCloseNotifier *cn =3D DO_UPCAST(NBDCloseNotifier, n, n); > >> - > >> - notifier_remove(&cn->n); > >> - QTAILQ_REMOVE(&close_notifiers, cn, next); > >> - > >> - nbd_export_close(cn->exp); > >> - nbd_export_put(cn->exp); > >=20 > > Here you remove a close/put pair, but in the new code you only add the > > close call. Why is this correct? >=20 > Thanks for putting so much unfounded faith in me. :-) >=20 > After having put quite some time into looking into it, first I have to > say that it's a very good question. >=20 > First off, it's wrong. This is because I thought every export would have > a refcount of one. Turns out this is wrong, they have a refcount of two: > It is created with a refcount of one, and then it gains another by > giving it a name and entering it into the export list. >=20 > I did know about the second but I completely forgot about the former. > And indeed I do think it is wrong. qmp_nbd_server_add() does not keep > the reference to the export, once the function returns, it is gone. > Therefore, it should call nbd_export_put() before returning. >=20 > So in my opinion the current code is wrong and I didn't fix it enough. > *cough* >=20 > So, with the nbd_export_put() added to qmp_nbd_server_add(), every > export will have a refcount of 1 + |clients|. The eject notifier will > call nbd_close_notifier(), which first disconnects the clients, thus > reducing the refcount by |clients|, and then sets the name to NULL, thus > dropping the final refcount and destroying the export. >=20 > In the old code, we needed another nbd_export_put() because of the > superfluous reference from nbd_export_new(), which doesn't actually > exist for blockdev-nbd (it does for qemu-nbd, though). Okay, that makes sense to me. So first a patch that moves the existing nbd_export_put() call from nbd_close_notifier() to qmp_nbd_server_add() and then this one on top? Kevin --LQksG6bCIzRHxTLp Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJWXZ3BAAoJEH8JsnLIjy/WvW4QAIqQoy0+rkhuu+6OetjPpeTL 6rDBMF/G2DYBscGGw3viliEFYleecl+oiJW6v0gpBuaXX9rVqj2n/26IyPyxkf4b yS9LRSJ001wuipyDmoxZFP1OwJrqdI5YOc9Wq42G8sU+UBWe3q7BcJdZv6NH15qg D8TulTGMi/vJEHamNsFYoEtZmDKgtxokngP0kZk4ghR2TkgXAXadFRRQHGDlsHGN dedii4y/vMXg6/iV+/ZdrFhHgoTXSRUPCRfS5L9gp3SiOExkYnbQ+IuzruX87aqT cF2ki75p867EAWN3eSF2yiA6lxT37GSt9Y8qmTmtju/6OmzpNrrhrQ7PCQe/QbWu 9K8HNEk/BEylne49Q9sxv+ExqU/CsDM0uamEzT55DT0KBHeCLMl198ohTSCWF1Mv +uAU0DxvE0+o8a8akgzz+0Iwm2kydBE8QWqux9LdkcS8PGuNSlopVdvDg+9H5RU9 wrQcDCB1OTqIy5QI7uCljQNehHnFcJdQeu/Dzr7J5Vz8oItLx5MfYBVXl4m/rsAL ynczSY2bK1d1OHMSgdhIL0BwE+84sZL2jGn3EMz14TZgyuxs2Et//7yJaI6GfpjM H5hTDLIwAWCHiqc0M3J2VqnQa7kv5GgZHvbQMbC1xD9T0fsPyKlZgTth75rlhteJ f2tVze/fFXmYRVBpoAFt =S7jy -----END PGP SIGNATURE----- --LQksG6bCIzRHxTLp--