[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 03/16] block: add bdrv_open_backing_file
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH v3 03/16] block: add bdrv_open_backing_file |
Date: |
Thu, 18 Oct 2012 16:49:17 +0200 |
Mirroring runs without the backing file so that it can be copied outside
QEMU. However, we need to add it at the time the job is completed and
QEMU switches to the target. Factor out the common bits of opening an
image and completing a mirroring operation.
The new function does not assume that the file is closed immediately after
it returns failure, so it keeps the BDRV_O_NO_BACKING flag up-to-date.
Signed-off-by: Paolo Bonzini <address@hidden>
---
v2->v3: keep_read_only does not exist anymore
block.c | 56 ++++++++++++++++++++++++++++++++++++++------------------
block.h | 1 +
2 file modificati, 39 inserzioni(+), 18 rimozioni(-)
diff --git a/block.c b/block.c
index f94e001..4787312 100644
--- a/block.c
+++ b/block.c
@@ -734,6 +734,42 @@ int bdrv_file_open(BlockDriverState **pbs, const char
*filename, int flags)
return 0;
}
+int bdrv_open_backing_file(BlockDriverState *bs)
+{
+ char backing_filename[PATH_MAX];
+ int back_flags, ret;
+ BlockDriver *back_drv = NULL;
+
+ if (bs->backing_hd != NULL) {
+ return 0;
+ }
+
+ bs->open_flags &= ~BDRV_O_NO_BACKING;
+ if (bs->backing_file[0] == '\0') {
+ return 0;
+ }
+
+ bs->backing_hd = bdrv_new("");
+ bdrv_get_full_backing_filename(bs, backing_filename,
+ sizeof(backing_filename));
+
+ if (bs->backing_format[0] != '\0') {
+ back_drv = bdrv_find_format(bs->backing_format);
+ }
+
+ /* backing files always opened read-only */
+ back_flags = bs->open_flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT);
+
+ ret = bdrv_open(bs->backing_hd, backing_filename, back_flags, back_drv);
+ if (ret < 0) {
+ bdrv_delete(bs->backing_hd);
+ bs->backing_hd = NULL;
+ bs->open_flags |= BDRV_O_NO_BACKING;
+ return ret;
+ }
+ return 0;
+}
+
/*
* Opens a disk image (raw, qcow2, vmdk, ...)
*/
@@ -821,24 +857,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename,
int flags,
}
/* If there is a backing file, use it */
- if ((flags & BDRV_O_NO_BACKING) == 0 && bs->backing_file[0] != '\0') {
- char backing_filename[PATH_MAX];
- int back_flags;
- BlockDriver *back_drv = NULL;
-
- bs->backing_hd = bdrv_new("");
- bdrv_get_full_backing_filename(bs, backing_filename,
- sizeof(backing_filename));
-
- if (bs->backing_format[0] != '\0') {
- back_drv = bdrv_find_format(bs->backing_format);
- }
-
- /* backing files always opened read-only */
- back_flags =
- flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
-
- ret = bdrv_open(bs->backing_hd, backing_filename, back_flags,
back_drv);
+ if ((flags & BDRV_O_NO_BACKING) == 0) {
+ ret = bdrv_open_backing_file(bs);
if (ret < 0) {
bdrv_close(bs);
return ret;
diff --git a/block.h b/block.h
index ed4b90d..096fa09 100644
--- a/block.h
+++ b/block.h
@@ -133,6 +133,7 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState
*bs_top);
void bdrv_delete(BlockDriverState *bs);
int bdrv_parse_cache_flags(const char *mode, int *flags);
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
+int bdrv_open_backing_file(BlockDriverState *bs);
int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
BlockDriver *drv);
BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
--
1.7.12.1
- [Qemu-devel] [PULL for Kevin 00/16] Block job improvements part 2, Paolo Bonzini, 2012/10/18
- [Qemu-devel] [PATCH v3 01/16] block: add bdrv_query_info, Paolo Bonzini, 2012/10/18
- [Qemu-devel] [PATCH v3 02/16] block: add bdrv_query_stats, Paolo Bonzini, 2012/10/18
- [Qemu-devel] [PATCH v3 03/16] block: add bdrv_open_backing_file,
Paolo Bonzini <=
- [Qemu-devel] [PATCH v3 04/16] block: introduce new dirty bitmap functionality, Paolo Bonzini, 2012/10/18
- [Qemu-devel] [PATCH v3 05/16] block: export dirty bitmap information in query-block, Paolo Bonzini, 2012/10/18
- [Qemu-devel] [PATCH v3 06/16] block: rename block_job_complete to block_job_completed, Paolo Bonzini, 2012/10/18
- [Qemu-devel] [PATCH v3 07/16] block: add block-job-complete, Paolo Bonzini, 2012/10/18
- [Qemu-devel] [PATCH v3 08/16] block: introduce BLOCK_JOB_READY event, Paolo Bonzini, 2012/10/18
- [Qemu-devel] [PATCH v3 09/16] mirror: introduce mirror job, Paolo Bonzini, 2012/10/18
- [Qemu-devel] [PATCH v3 13/16] iostatus: forward block_job_iostatus_reset to block job, Paolo Bonzini, 2012/10/18
- [Qemu-devel] [PATCH v3 14/16] mirror: add support for on-source-error/on-target-error, Paolo Bonzini, 2012/10/18