|
|
9ae3a8 |
From d83c96945764748dff98dbe37169ae7c65a3dac5 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Date: Fri, 17 Jan 2014 03:07:52 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 09/34] block: use BDS ref for block jobs
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1389928083-8921-8-git-send-email-famz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 56769
|
|
|
9ae3a8 |
O-Subject: [RHEL-7 qemu-kvm PATCH 07/18] block: use BDS ref for block jobs
|
|
|
9ae3a8 |
Bugzilla: 1041301
|
|
|
9ae3a8 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Block jobs used drive_get_ref(drive_get_by_blockdev(bs)) to avoid BDS
|
|
|
9ae3a8 |
being deleted. Now we have BDS reference count, and block jobs don't
|
|
|
9ae3a8 |
care about dinfo, so replace them to get cleaner code. It is also the
|
|
|
9ae3a8 |
safe way when BDS has no drive info.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit fa510ebffa1fd509323e2e0888e369e23adbb508)
|
|
|
9ae3a8 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts:
|
|
|
9ae3a8 |
blockdev.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflict because drive-backup is not backported, and downstream has
|
|
|
9ae3a8 |
6270aec (block: optionally disable live block jobs).
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
blockdev.c | 44 +++++++++++++++-----------------------------
|
|
|
9ae3a8 |
blockjob.c | 1 +
|
|
|
9ae3a8 |
2 files changed, 16 insertions(+), 29 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
blockdev.c | 44 +++++++++++++++-----------------------------
|
|
|
9ae3a8 |
blockjob.c | 1 +
|
|
|
9ae3a8 |
2 files changed, 16 insertions(+), 29 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/blockdev.c b/blockdev.c
|
|
|
9ae3a8 |
index 564262a..d795af2 100644
|
|
|
9ae3a8 |
--- a/blockdev.c
|
|
|
9ae3a8 |
+++ b/blockdev.c
|
|
|
9ae3a8 |
@@ -243,34 +243,34 @@ void drive_get_ref(DriveInfo *dinfo)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
typedef struct {
|
|
|
9ae3a8 |
QEMUBH *bh;
|
|
|
9ae3a8 |
- DriveInfo *dinfo;
|
|
|
9ae3a8 |
-} DrivePutRefBH;
|
|
|
9ae3a8 |
+ BlockDriverState *bs;
|
|
|
9ae3a8 |
+} BDRVPutRefBH;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* right now, this is only used from block_job_cb() */
|
|
|
9ae3a8 |
#ifdef CONFIG_LIVE_BLOCK_OPS
|
|
|
9ae3a8 |
-static void drive_put_ref_bh(void *opaque)
|
|
|
9ae3a8 |
+static void bdrv_put_ref_bh(void *opaque)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- DrivePutRefBH *s = opaque;
|
|
|
9ae3a8 |
+ BDRVPutRefBH *s = opaque;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- drive_put_ref(s->dinfo);
|
|
|
9ae3a8 |
+ bdrv_unref(s->bs);
|
|
|
9ae3a8 |
qemu_bh_delete(s->bh);
|
|
|
9ae3a8 |
g_free(s);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/*
|
|
|
9ae3a8 |
- * Release a drive reference in a BH
|
|
|
9ae3a8 |
+ * Release a BDS reference in a BH
|
|
|
9ae3a8 |
*
|
|
|
9ae3a8 |
- * It is not possible to use drive_put_ref() from a callback function when the
|
|
|
9ae3a8 |
- * callers still need the drive. In such cases we schedule a BH to release the
|
|
|
9ae3a8 |
- * reference.
|
|
|
9ae3a8 |
+ * It is not safe to use bdrv_unref() from a callback function when the callers
|
|
|
9ae3a8 |
+ * still need the BlockDriverState. In such cases we schedule a BH to release
|
|
|
9ae3a8 |
+ * the reference.
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
-static void drive_put_ref_bh_schedule(DriveInfo *dinfo)
|
|
|
9ae3a8 |
+static void bdrv_put_ref_bh_schedule(BlockDriverState *bs)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- DrivePutRefBH *s;
|
|
|
9ae3a8 |
+ BDRVPutRefBH *s;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- s = g_new(DrivePutRefBH, 1);
|
|
|
9ae3a8 |
- s->bh = qemu_bh_new(drive_put_ref_bh, s);
|
|
|
9ae3a8 |
- s->dinfo = dinfo;
|
|
|
9ae3a8 |
+ s = g_new(BDRVPutRefBH, 1);
|
|
|
9ae3a8 |
+ s->bh = qemu_bh_new(bdrv_put_ref_bh, s);
|
|
|
9ae3a8 |
+ s->bs = bs;
|
|
|
9ae3a8 |
qemu_bh_schedule(s->bh);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
@@ -1423,7 +1423,7 @@ static void block_job_cb(void *opaque, int ret)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
qobject_decref(obj);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- drive_put_ref_bh_schedule(drive_get_by_blockdev(bs));
|
|
|
9ae3a8 |
+ bdrv_put_ref_bh_schedule(bs);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
void qmp_block_stream(const char *device, bool has_base,
|
|
|
9ae3a8 |
@@ -1460,11 +1460,6 @@ void qmp_block_stream(const char *device, bool has_base,
|
|
|
9ae3a8 |
return;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* Grab a reference so hotplug does not delete the BlockDriverState from
|
|
|
9ae3a8 |
- * underneath us.
|
|
|
9ae3a8 |
- */
|
|
|
9ae3a8 |
- drive_get_ref(drive_get_by_blockdev(bs));
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
trace_qmp_block_stream(bs, bs->job);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1521,10 +1516,6 @@ void qmp_block_commit(const char *device,
|
|
|
9ae3a8 |
error_propagate(errp, local_err);
|
|
|
9ae3a8 |
return;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- /* Grab a reference so hotplug does not delete the BlockDriverState from
|
|
|
9ae3a8 |
- * underneath us.
|
|
|
9ae3a8 |
- */
|
|
|
9ae3a8 |
- drive_get_ref(drive_get_by_blockdev(bs));
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#define DEFAULT_MIRROR_BUF_SIZE (10 << 20)
|
|
|
9ae3a8 |
@@ -1658,11 +1649,6 @@ void qmp_drive_mirror(const char *device, const char *target,
|
|
|
9ae3a8 |
error_propagate(errp, local_err);
|
|
|
9ae3a8 |
return;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* Grab a reference so hotplug does not delete the BlockDriverState from
|
|
|
9ae3a8 |
- * underneath us.
|
|
|
9ae3a8 |
- */
|
|
|
9ae3a8 |
- drive_get_ref(drive_get_by_blockdev(bs));
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/blockjob.c b/blockjob.c
|
|
|
9ae3a8 |
index c0a22d9..6d8c3a2 100644
|
|
|
9ae3a8 |
--- a/blockjob.c
|
|
|
9ae3a8 |
+++ b/blockjob.c
|
|
|
9ae3a8 |
@@ -45,6 +45,7 @@ void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs,
|
|
|
9ae3a8 |
error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
|
|
|
9ae3a8 |
return NULL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
+ bdrv_ref(bs);
|
|
|
9ae3a8 |
bdrv_set_in_use(bs, 1);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
job = g_malloc0(job_type->instance_size);
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|