qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, jcody@redhat.com,
	stefanha@redhat.com, pbonzini@redhat.com,
	xiawenc@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v6 8/8] block: use BDS ref for block jobs
Date: Fri, 23 Aug 2013 09:14:51 +0800	[thread overview]
Message-ID: <1377220491-19954-9-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1377220491-19954-1-git-send-email-famz@redhat.com>

Block jobs used drive_get_ref(drive_get_by_blockdev(bs)) to avoid BDS
being deleted. Now we have BDS reference count, and block jobs don't
care about dinfo, so replace them to get cleaner code. It is also the
safe way when BDS has no drive info.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 blockdev.c | 49 +++++++++++++++----------------------------------
 blockjob.c |  1 +
 2 files changed, 16 insertions(+), 34 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 5b86c9d..d8ea1d0 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -235,32 +235,32 @@ void drive_get_ref(DriveInfo *dinfo)
 
 typedef struct {
     QEMUBH *bh;
-    DriveInfo *dinfo;
-} DrivePutRefBH;
+    BlockDriverState *bs;
+} BDRVPutRefBH;
 
-static void drive_put_ref_bh(void *opaque)
+static void bdrv_put_ref_bh(void *opaque)
 {
-    DrivePutRefBH *s = opaque;
+    BDRVPutRefBH *s = opaque;
 
-    drive_put_ref(s->dinfo);
+    bdrv_unref(s->bs);
     qemu_bh_delete(s->bh);
     g_free(s);
 }
 
 /*
- * Release a drive reference in a BH
+ * Release a BDS reference in a BH
  *
- * It is not possible to use drive_put_ref() from a callback function when the
- * callers still need the drive.  In such cases we schedule a BH to release the
- * reference.
+ * It is not safe to use bdrv_unref() from a callback function when the callers
+ * still need the BlockDriverState.  In such cases we schedule a BH to release
+ * the reference.
  */
-static void drive_put_ref_bh_schedule(DriveInfo *dinfo)
+static void bdrv_put_ref_bh_schedule(BlockDriverState *bs)
 {
-    DrivePutRefBH *s;
+    BDRVPutRefBH *s;
 
-    s = g_new(DrivePutRefBH, 1);
-    s->bh = qemu_bh_new(drive_put_ref_bh, s);
-    s->dinfo = dinfo;
+    s = g_new(BDRVPutRefBH, 1);
+    s->bh = qemu_bh_new(bdrv_put_ref_bh, s);
+    s->bs = bs;
     qemu_bh_schedule(s->bh);
 }
 
@@ -1395,7 +1395,7 @@ static void block_job_cb(void *opaque, int ret)
     }
     qobject_decref(obj);
 
-    drive_put_ref_bh_schedule(drive_get_by_blockdev(bs));
+    bdrv_put_ref_bh_schedule(bs);
 }
 
 void qmp_block_stream(const char *device, bool has_base,
@@ -1432,11 +1432,6 @@ void qmp_block_stream(const char *device, bool has_base,
         return;
     }
 
-    /* Grab a reference so hotplug does not delete the BlockDriverState from
-     * underneath us.
-     */
-    drive_get_ref(drive_get_by_blockdev(bs));
-
     trace_qmp_block_stream(bs, bs->job);
 }
 
@@ -1493,10 +1488,6 @@ void qmp_block_commit(const char *device,
         error_propagate(errp, local_err);
         return;
     }
-    /* Grab a reference so hotplug does not delete the BlockDriverState from
-     * underneath us.
-     */
-    drive_get_ref(drive_get_by_blockdev(bs));
 }
 
 void qmp_drive_backup(const char *device, const char *target,
@@ -1609,11 +1600,6 @@ void qmp_drive_backup(const char *device, const char *target,
         error_propagate(errp, local_err);
         return;
     }
-
-    /* Grab a reference so hotplug does not delete the BlockDriverState from
-     * underneath us.
-     */
-    drive_get_ref(drive_get_by_blockdev(bs));
 }
 
 #define DEFAULT_MIRROR_BUF_SIZE   (10 << 20)
@@ -1750,11 +1736,6 @@ void qmp_drive_mirror(const char *device, const char *target,
         error_propagate(errp, local_err);
         return;
     }
-
-    /* Grab a reference so hotplug does not delete the BlockDriverState from
-     * underneath us.
-     */
-    drive_get_ref(drive_get_by_blockdev(bs));
 }
 
 static BlockJob *find_block_job(const char *device)
diff --git a/blockjob.c b/blockjob.c
index ca80df1..9fe9869 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -45,6 +45,7 @@ void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs,
         error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
         return NULL;
     }
+    bdrv_ref(bs);
     bdrv_set_in_use(bs, 1);
 
     job = g_malloc0(job_type->instance_size);
-- 
1.8.3.1

  parent reply	other threads:[~2013-08-23  1:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-23  1:14 [Qemu-devel] [PATCH v6 0/8] Implement reference count for BlockDriverState Fam Zheng
2013-08-23  1:14 ` [Qemu-devel] [PATCH v6 1/8] vvfat: use bdrv_new() to allocate BlockDriverState Fam Zheng
2013-08-23  1:14 ` [Qemu-devel] [PATCH v6 2/8] iscsi: use bdrv_new() instead of stack structure Fam Zheng
2013-08-23  1:14 ` [Qemu-devel] [PATCH v6 3/8] block: implement reference count for BlockDriverState Fam Zheng
2013-08-23 16:12   ` Jeff Cody
2013-08-26  1:15     ` Fam Zheng
2013-08-23  1:14 ` [Qemu-devel] [PATCH v6 4/8] block: make bdrv_delete() static Fam Zheng
2013-08-23  1:14 ` [Qemu-devel] [PATCH v6 5/8] migration: omit drive ref as we have bdrv_ref now Fam Zheng
2013-08-23  1:14 ` [Qemu-devel] [PATCH v6 6/8] xen_disk: simplify blk_disconnect with refcnt Fam Zheng
2013-08-23  1:14 ` [Qemu-devel] [PATCH v6 7/8] nbd: use BlockDriverState refcnt Fam Zheng
2013-08-23  1:14 ` Fam Zheng [this message]
2013-09-04 13:52 ` [Qemu-devel] [PATCH v6 0/8] Implement reference count for BlockDriverState Stefan Hajnoczi

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=1377220491-19954-9-git-send-email-famz@redhat.com \
    --to=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=xiawenc@linux.vnet.ibm.com \
    /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).