[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 7/9] qcow2: Implement .bdrv_inactivate
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH v2 7/9] qcow2: Implement .bdrv_inactivate |
Date: |
Wed, 13 Jan 2016 17:37:14 +0100 |
The callback has to ensure that closing or flushing the image afterwards
wouldn't cause a write access to the image files. This means that just
the caches have to be written out, which is part of the existing
.bdrv_close implementation.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
block/qcow2.c | 45 ++++++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 9e4abf3..519e2ae 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1685,6 +1685,32 @@ fail:
return ret;
}
+static int qcow2_inactivate(BlockDriverState *bs)
+{
+ BDRVQcow2State *s = bs->opaque;
+ int ret, result = 0;
+
+ ret = qcow2_cache_flush(bs, s->l2_table_cache);
+ if (ret) {
+ result = ret;
+ error_report("Failed to flush the L2 table cache: %s",
+ strerror(-ret));
+ }
+
+ ret = qcow2_cache_flush(bs, s->refcount_block_cache);
+ if (ret) {
+ result = ret;
+ error_report("Failed to flush the refcount block cache: %s",
+ strerror(-ret));
+ }
+
+ if (result == 0) {
+ qcow2_mark_clean(bs);
+ }
+
+ return result;
+}
+
static void qcow2_close(BlockDriverState *bs)
{
BDRVQcow2State *s = bs->opaque;
@@ -1693,23 +1719,7 @@ static void qcow2_close(BlockDriverState *bs)
s->l1_table = NULL;
if (!(bs->open_flags & BDRV_O_INACTIVE)) {
- int ret1, ret2;
-
- ret1 = qcow2_cache_flush(bs, s->l2_table_cache);
- ret2 = qcow2_cache_flush(bs, s->refcount_block_cache);
-
- if (ret1) {
- error_report("Failed to flush the L2 table cache: %s",
- strerror(-ret1));
- }
- if (ret2) {
- error_report("Failed to flush the refcount block cache: %s",
- strerror(-ret2));
- }
-
- if (!ret1 && !ret2) {
- qcow2_mark_clean(bs);
- }
+ qcow2_inactivate(bs);
}
cache_clean_timer_del(bs);
@@ -3340,6 +3350,7 @@ BlockDriver bdrv_qcow2 = {
.bdrv_refresh_limits = qcow2_refresh_limits,
.bdrv_invalidate_cache = qcow2_invalidate_cache,
+ .bdrv_inactivate = qcow2_inactivate,
.create_opts = &qcow2_create_opts,
.bdrv_check = qcow2_check,
--
1.8.3.1
- [Qemu-devel] [PATCH v2 0/9] block/qcow2: Migration handoff fixes and cleanups, Kevin Wolf, 2016/01/13
- [Qemu-devel] [PATCH v2 1/9] qcow2: Write feature table only for v3 images, Kevin Wolf, 2016/01/13
- [Qemu-devel] [PATCH v2 3/9] block: Assert no write requests under BDRV_O_INCOMING, Kevin Wolf, 2016/01/13
- [Qemu-devel] [PATCH v2 2/9] qcow2: Write full header on image creation, Kevin Wolf, 2016/01/13
- [Qemu-devel] [PATCH v2 4/9] block: Fix error path in bdrv_invalidate_cache(), Kevin Wolf, 2016/01/13
- [Qemu-devel] [PATCH v2 6/9] block: Inactivate BDS when migration completes, Kevin Wolf, 2016/01/13
- [Qemu-devel] [PATCH v2 7/9] qcow2: Implement .bdrv_inactivate,
Kevin Wolf <=
- [Qemu-devel] [PATCH v2 8/9] qcow2: Fix BDRV_O_INACTIVE handling in qcow2_invalidate_cache(), Kevin Wolf, 2016/01/13
- [Qemu-devel] [PATCH v2 5/9] block: Rename BDRV_O_INCOMING to BDRV_O_INACTIVE, Kevin Wolf, 2016/01/13
- [Qemu-devel] [PATCH v2 9/9] qcow2: Make image inaccessible after failed qcow2_invalidate_cache(), Kevin Wolf, 2016/01/13
- Re: [Qemu-devel] [PATCH v2 0/9] block/qcow2: Migration handoff fixes and cleanups, Kevin Wolf, 2016/01/19