[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/20] block: handle -EBUSY in bdrv_commit_all()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 04/20] block: handle -EBUSY in bdrv_commit_all() |
Date: |
Mon, 12 Mar 2012 16:19:35 +0100 |
From: Stefan Hajnoczi <address@hidden>
Monitor operations that manipulate image files must not execute while a
background job (like image streaming) is in progress. This prevents
corruptions from happening when two pieces of code are manipulating the
image file without knowledge of each other.
The monitor "commit" command raises QERR_DEVICE_IN_USE when
bdrv_commit() returns -EBUSY but "commit all" has no error handling.
This is easy to fix, although note that we do not deliver a detailed
error about which device was busy in the "commit all" case.
Suggested-by: Kevin Wolf <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 8 ++++++--
block.h | 2 +-
blockdev.c | 9 ++++++---
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index 52ffe14..b88ee90 100644
--- a/block.c
+++ b/block.c
@@ -1244,13 +1244,17 @@ ro_cleanup:
return ret;
}
-void bdrv_commit_all(void)
+int bdrv_commit_all(void)
{
BlockDriverState *bs;
QTAILQ_FOREACH(bs, &bdrv_states, list) {
- bdrv_commit(bs);
+ int ret = bdrv_commit(bs);
+ if (ret < 0) {
+ return ret;
+ }
}
+ return 0;
}
struct BdrvTrackedRequest {
diff --git a/block.h b/block.h
index 48d0bf3..415bb17 100644
--- a/block.h
+++ b/block.h
@@ -165,7 +165,7 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int
*psecs);
int bdrv_commit(BlockDriverState *bs);
-void bdrv_commit_all(void);
+int bdrv_commit_all(void);
int bdrv_change_backing_file(BlockDriverState *bs,
const char *backing_file, const char *backing_fmt);
void bdrv_register(BlockDriver *bdrv);
diff --git a/blockdev.c b/blockdev.c
index 96a893b..0e8666a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -627,12 +627,15 @@ void do_commit(Monitor *mon, const QDict *qdict)
{
const char *device = qdict_get_str(qdict, "device");
BlockDriverState *bs;
+ int ret;
if (!strcmp(device, "all")) {
- bdrv_commit_all();
+ ret = bdrv_commit_all();
+ if (ret == -EBUSY) {
+ qerror_report(QERR_DEVICE_IN_USE, device);
+ return;
+ }
} else {
- int ret;
-
bs = bdrv_find(device);
if (!bs) {
qerror_report(QERR_DEVICE_NOT_FOUND, device);
--
1.7.6.5
- [Qemu-devel] [PATCH 08/20] Add 'make check-block', (continued)
- [Qemu-devel] [PATCH 08/20] Add 'make check-block', Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 05/20] qcow2: Add error messages in qcow2_truncate, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 06/20] qemu-iotests: Mark some tests as quick, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 02/20] qed: do not evict in-use L2 table cache entries, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 01/20] Group snapshot: Fix format name for backing file, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 16/20] qcow2: Reduce number of I/O requests, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 03/20] qcow2: Add some tracing, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 17/20] coroutine: adding sigaltstack method (.c source), Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 18/20] coroutine: adding configure choose mechanism for coroutine backend, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 10/20] qapi: complete implementation of unions, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 04/20] block: handle -EBUSY in bdrv_commit_all(),
Kevin Wolf <=
- [Qemu-devel] [PATCH 20/20] test-coroutine: add performance test for nesting, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 07/20] make check: Add qemu-iotests subset, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 14/20] qcow2: Factor out count_cow_clusters, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 09/20] use QSIMPLEQ_FOREACH_SAFE when freeing list elements, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 12/20] add mode field to blockdev-snapshot-sync transaction item, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 19/20] coroutine: adding configure option for sigaltstack coroutine backend, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 13/20] qmp: convert blockdev-snapshot-sync to a wrapper around transactions, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 11/20] rename blockdev-group-snapshot-sync, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 15/20] qcow2: Add qcow2_alloc_clusters_at(), Kevin Wolf, 2012/03/12
- Re: [Qemu-devel] [PULL 00/20] Block patches, Anthony Liguori, 2012/03/12