[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/22] block: check bdrv_in_use() before blockdev op
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 04/22] block: check bdrv_in_use() before blockdev operations |
Date: |
Thu, 26 Jan 2012 17:37:58 +0100 |
From: Stefan Hajnoczi <address@hidden>
Long-running block operations like block migration and image streaming
must have continual access to their block device. It is not safe to
perform operations like hotplug, eject, change, resize, commit, or
external snapshot while a long-running operation is in progress.
This patch adds the missing bdrv_in_use() checks so that block migration
and image streaming never have the rug pulled out from underneath them.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 4 ++++
blockdev.c | 16 +++++++++++++++-
2 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/block.c b/block.c
index 3f072f6..43f6484 100644
--- a/block.c
+++ b/block.c
@@ -1020,6 +1020,10 @@ int bdrv_commit(BlockDriverState *bs)
return -EACCES;
}
+ if (bdrv_in_use(bs) || bdrv_in_use(bs->backing_hd)) {
+ return -EBUSY;
+ }
+
backing_drv = bs->backing_hd->drv;
ro = bs->backing_hd->read_only;
strncpy(filename, bs->backing_hd->filename, sizeof(filename));
diff --git a/blockdev.c b/blockdev.c
index 1f83c88..0499ee6 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -592,12 +592,18 @@ void do_commit(Monitor *mon, const QDict *qdict)
if (!strcmp(device, "all")) {
bdrv_commit_all();
} else {
+ int ret;
+
bs = bdrv_find(device);
if (!bs) {
qerror_report(QERR_DEVICE_NOT_FOUND, device);
return;
}
- bdrv_commit(bs);
+ ret = bdrv_commit(bs);
+ if (ret == -EBUSY) {
+ qerror_report(QERR_DEVICE_IN_USE, device);
+ return;
+ }
}
}
@@ -616,6 +622,10 @@ void qmp_blockdev_snapshot_sync(const char *device, const
char *snapshot_file,
error_set(errp, QERR_DEVICE_NOT_FOUND, device);
return;
}
+ if (bdrv_in_use(bs)) {
+ error_set(errp, QERR_DEVICE_IN_USE, device);
+ return;
+ }
pstrcpy(old_filename, sizeof(old_filename), bs->filename);
@@ -667,6 +677,10 @@ void qmp_blockdev_snapshot_sync(const char *device, const
char *snapshot_file,
static void eject_device(BlockDriverState *bs, int force, Error **errp)
{
+ if (bdrv_in_use(bs)) {
+ error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
+ return;
+ }
if (!bdrv_dev_has_removable_media(bs)) {
error_set(errp, QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
return;
--
1.7.6.5
- [Qemu-devel] [PULL 00/22] Block patches, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 01/22] rbd: wire up snapshot removal and rollback functionality, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 04/22] block: check bdrv_in_use() before blockdev operations,
Kevin Wolf <=
- [Qemu-devel] [PATCH 03/22] coroutine: add co_sleep_ns() coroutine sleep function, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 05/22] block: make copy-on-read a per-request flag, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 10/22] qmp: add block_job_set_speed command, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 09/22] qmp: add block_stream command, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 02/22] block: replace unchecked strdup/malloc/calloc with glib, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 08/22] block: rate-limit streaming operations, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 06/22] block: add BlockJob interface for long-running operations, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 12/22] qmp: add query-block-jobs, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 07/22] block: add image streaming block job, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 15/22] add QERR_BASE_NOT_FOUND, Kevin Wolf, 2012/01/26