From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH v6 02/16] block: check bdrv_in_use() before blockdev operations
Date: Wed, 18 Jan 2012 14:40:41 +0000 [thread overview]
Message-ID: <1326897655-2799-3-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1326897655-2799-1-git-send-email-stefanha@linux.vnet.ibm.com>
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 <stefanha@linux.vnet.ibm.com>
---
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 c832782..6d78b36 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 int eject_device(Monitor *mon, BlockDriverState *bs, int force)
{
+ if (bdrv_in_use(bs)) {
+ qerror_report(QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
+ return -1;
+ }
if (!bdrv_dev_has_removable_media(bs)) {
qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
return -1;
--
1.7.8.3
next prev parent reply other threads:[~2012-01-18 14:41 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-18 14:40 [Qemu-devel] [PATCH v6 00/16] block: generic image streaming Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 01/16] coroutine: add co_sleep_ns() coroutine sleep function Stefan Hajnoczi
2012-01-18 14:40 ` Stefan Hajnoczi [this message]
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 03/16] block: make copy-on-read a per-request flag Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 04/16] block: add BlockJob interface for long-running operations Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 05/16] block: add image streaming block job Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 06/16] block: rate-limit streaming operations Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 07/16] qmp: add block_stream command Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 08/16] qmp: add block_job_set_speed command Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 09/16] qmp: add block_job_cancel command Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 10/16] qmp: add query-block-jobs Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 11/16] blockdev: make image streaming safe across hotplug Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 12/16] block: add bdrv_find_backing_image Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 13/16] add QERR_BASE_NOT_FOUND Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 14/16] block: add support for partial streaming Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 15/16] docs: describe live block operations Stefan Hajnoczi
2012-01-18 14:40 ` [Qemu-devel] [PATCH v6 16/16] test: add image streaming test cases Stefan Hajnoczi
2012-01-19 14:53 ` [Qemu-devel] [PATCH v6 00/16] block: generic image streaming Kevin Wolf
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=1326897655-2799-3-git-send-email-stefanha@linux.vnet.ibm.com \
--to=stefanha@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--cc=mtosatti@redhat.com \
--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).