From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
qemu-block@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH 2/2] block: remove legacy_dinfo at blk_detach_dev time
Date: Fri, 8 Jan 2016 18:37:45 +0100 [thread overview]
Message-ID: <1452274665-23061-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1452274665-23061-1-git-send-email-pbonzini@redhat.com>
Currently, blockdev_del_drive does a blk_unref (and before it
blockdev_auto_del did the same) that will cause blk_delete to be called
and the DriveInfo to be freed. But really, we want to free the drive info
as soon as the device is detached, even if there are other references
for whatever reason, so that the QemuOpts are freed as well and the id
can be reused.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
block/block-backend.c | 14 ++++++++++----
blockdev.c | 7 ++++---
include/sysemu/blockdev.h | 1 +
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/block/block-backend.c b/block/block-backend.c
index 9889e81..a1db52b 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -62,8 +62,6 @@ static const AIOCBInfo block_backend_aiocb_info = {
.aiocb_size = sizeof(BlockBackendAIOCB),
};
-static void drive_info_del(DriveInfo *dinfo);
-
/* All the BlockBackends (except for hidden ones) */
static QTAILQ_HEAD(, BlockBackend) blk_backends =
QTAILQ_HEAD_INITIALIZER(blk_backends);
@@ -160,6 +158,7 @@ static void blk_delete(BlockBackend *blk)
{
assert(!blk->refcnt);
assert(!blk->dev);
+ assert(!blk->legacy_dinfo);
if (blk->bs) {
assert(blk->bs->blk == blk);
blk->bs->blk = NULL;
@@ -175,19 +174,26 @@ static void blk_delete(BlockBackend *blk)
QTAILQ_REMOVE(&blk_backends, blk, link);
}
g_free(blk->name);
- drive_info_del(blk->legacy_dinfo);
block_acct_cleanup(&blk->stats);
g_free(blk);
}
-static void drive_info_del(DriveInfo *dinfo)
+void blk_release_legacy_dinfo(BlockBackend *blk)
{
+ DriveInfo *dinfo = blk->legacy_dinfo;
+
if (!dinfo) {
return;
}
qemu_opts_del(dinfo->opts);
g_free(dinfo->serial);
g_free(dinfo);
+ blk->legacy_dinfo = NULL;
+
+ /* We are not interested anymore in retrieving the BlockBackend
+ * via blk_by_legacy_dinfo, so let it die.
+ */
+ blk_unref(blk);
}
int blk_get_refcnt(BlockBackend *blk)
diff --git a/blockdev.c b/blockdev.c
index a8309fb..d75be63 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -116,10 +116,10 @@ void override_max_devs(BlockInterfaceType type, int max_devs)
*/
void blockdev_del_drive(BlockBackend *blk)
{
- DriveInfo *dinfo = blk_legacy_dinfo(blk);
BlockDriverState *bs = blk_bs(blk);
AioContext *aio_context;
+ blk_ref(blk);
if (bs) {
aio_context = bdrv_get_aio_context(bs);
aio_context_acquire(aio_context);
@@ -131,9 +131,10 @@ void blockdev_del_drive(BlockBackend *blk)
aio_context_release(aio_context);
}
- if (dinfo) {
- blk_unref(blk);
+ if (blk_legacy_dinfo(blk)) {
+ blk_release_legacy_dinfo(blk);
}
+ blk_unref(blk);
}
/**
diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h
index ae7ad67..5722b9f 100644
--- a/include/sysemu/blockdev.h
+++ b/include/sysemu/blockdev.h
@@ -44,6 +44,7 @@ struct DriveInfo {
DriveInfo *blk_legacy_dinfo(BlockBackend *blk);
DriveInfo *blk_set_legacy_dinfo(BlockBackend *blk, DriveInfo *dinfo);
BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo);
+void blk_release_legacy_dinfo(BlockBackend *blk);
void override_max_devs(BlockInterfaceType type, int max_devs);
--
2.5.0
next prev parent reply other threads:[~2016-01-08 17:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-08 17:37 [Qemu-devel] [RFC PATCH 0/2] Early release of -drive QemuOpts Paolo Bonzini
2016-01-08 17:37 ` [Qemu-devel] [PATCH 1/2] block: detach devices from DriveInfo at unrealize time Paolo Bonzini
2016-01-08 17:37 ` Paolo Bonzini [this message]
2016-01-22 14:01 ` [Qemu-devel] [RFC PATCH 0/2] Early release of -drive QemuOpts Paolo Bonzini
2016-01-22 22:38 ` Max Reitz
2016-02-04 23:01 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1452274665-23061-3-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).