[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 5/7] block: Parse "backing" option to reference e
From: |
Fam Zheng |
Subject: |
[Qemu-devel] [PATCH v4 5/7] block: Parse "backing" option to reference existing BDS |
Date: |
Fri, 22 Nov 2013 13:24:52 +0800 |
Signed-off-by: Fam Zheng <address@hidden>
---
block.c | 37 ++++++++++++++++++++++++++++++++-----
include/block/block_int.h | 3 +++
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/block.c b/block.c
index 3bf4c8a..a5da656 100644
--- a/block.c
+++ b/block.c
@@ -1166,11 +1166,33 @@ int bdrv_open(BlockDriverState *bs, const char
*filename, QDict *options,
/* If there is a backing file, use it */
if ((flags & BDRV_O_NO_BACKING) == 0) {
QDict *backing_options;
-
- qdict_extract_subqdict(options, &backing_options, "backing.");
- ret = bdrv_open_backing_file(bs, backing_options, &local_err);
- if (ret < 0) {
- goto close_and_fail;
+ const char *backing_bs;
+
+ backing_bs = qdict_get_try_str(options, "backing");
+ if (backing_bs) {
+ bs->backing_hd = bdrv_find(backing_bs);
+ qdict_del(options, "backing");
+ if (bs->backing_hd) {
+ bdrv_ref(bs->backing_hd);
+ assert(!bs->backing_blocker);
+ error_setg(&bs->backing_blocker,
+ "device is used as backing hd of '%s'",
+ bs->device_name);
+ bdrv_op_block_all(bs->backing_hd, bs->backing_blocker);
+ pstrcpy(bs->backing_file, sizeof(bs->backing_file),
+ bs->backing_hd->filename);
+ pstrcpy(bs->backing_format, sizeof(bs->backing_format),
+ bs->backing_hd->drv->format_name);
+ } else {
+ error_setg(errp, "Backing device not found: %s", backing_bs);
+ goto close_and_fail;
+ }
+ } else {
+ qdict_extract_subqdict(options, &backing_options, "backing.");
+ ret = bdrv_open_backing_file(bs, backing_options, &local_err);
+ if (ret < 0) {
+ goto close_and_fail;
+ }
}
}
@@ -1461,6 +1483,11 @@ void bdrv_close(BlockDriverState *bs)
if (bs->drv) {
if (bs->backing_hd) {
+ if (error_is_set(&bs->backing_blocker)) {
+ bdrv_op_unblock_all(bs->backing_hd,
+ bs->backing_blocker);
+ error_free(bs->backing_blocker);
+ }
bdrv_unref(bs->backing_hd);
bs->backing_hd = NULL;
}
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 60edc80..6db30c9 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -316,6 +316,9 @@ struct BlockDriverState {
BlockJob *job;
QDict *options;
+
+ /* For backing reference, block the operations of named backing device */
+ Error *backing_blocker;
};
int get_tmp_filename(char *filename, int size);
--
1.8.4.2
- Re: [Qemu-devel] [PATCH v4 2/7] block: Introduce op_blockers to BlockDriverState, (continued)
[Qemu-devel] [PATCH v4 3/7] block: Replace in_use with operation blocker, Fam Zheng, 2013/11/22
[Qemu-devel] [PATCH v4 4/7] block: Add checks of blocker in block operations, Fam Zheng, 2013/11/22
[Qemu-devel] [PATCH v4 5/7] block: Parse "backing" option to reference existing BDS,
Fam Zheng <=
[Qemu-devel] [PATCH v4 6/7] qmp: add command 'blockdev-backup', Fam Zheng, 2013/11/22
[Qemu-devel] [PATCH v4 7/7] block: Allow backup on referenced named BlockDriverState, Fam Zheng, 2013/11/22
Re: [Qemu-devel] [PATCH v4 0/7] Drop in_use from BlockDriverState and enable point-in-time snapshot exporting over NBD, Stefan Hajnoczi, 2013/11/22