提交 169b8793 编写于 作者: V Vladimir Sementsov-Ogievskiy 提交者: Max Reitz

qcow2: store bitmaps on reopening image as read-only

Store bitmaps and mark them read-only on reopening image as read-only.
Signed-off-by: NVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: NMax Reitz <mreitz@redhat.com>
Message-id: 20170628120530.31251-21-vsementsov@virtuozzo.com
Signed-off-by: NMax Reitz <mreitz@redhat.com>
上级 5f72826e
......@@ -1366,3 +1366,25 @@ fail:
bitmap_list_free(bm_list);
}
int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp)
{
BdrvDirtyBitmap *bitmap;
Error *local_err = NULL;
qcow2_store_persistent_dirty_bitmaps(bs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return -EINVAL;
}
for (bitmap = bdrv_dirty_bitmap_next(bs, NULL); bitmap != NULL;
bitmap = bdrv_dirty_bitmap_next(bs, bitmap))
{
if (bdrv_dirty_bitmap_get_persistance(bitmap)) {
bdrv_dirty_bitmap_set_readonly(bitmap, true);
}
}
return 0;
}
......@@ -1555,6 +1555,11 @@ static int qcow2_reopen_prepare(BDRVReopenState *state,
/* We need to write out any unwritten data if we reopen read-only. */
if ((state->flags & BDRV_O_RDWR) == 0) {
ret = qcow2_reopen_bitmaps_ro(state->bs, errp);
if (ret < 0) {
goto fail;
}
ret = bdrv_flush(state->bs);
if (ret < 0) {
goto fail;
......
......@@ -648,5 +648,6 @@ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
bool qcow2_load_autoloading_dirty_bitmaps(BlockDriverState *bs, Error **errp);
int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp);
void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp);
int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp);
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册