[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 18/19] block: convert bdrv_commit() to use bdrv_reop
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 18/19] block: convert bdrv_commit() to use bdrv_reopen() |
Date: |
Mon, 24 Sep 2012 16:26:47 +0200 |
From: Jeff Cody <address@hidden>
Currently, bdrv_commit() reopens images r/w itself, via risky
_delete() and _open() calls. Use the new safe method for drive reopen.
Signed-off-by: Jeff Cody <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 48 +++++-------------------------------------------
1 files changed, 5 insertions(+), 43 deletions(-)
diff --git a/block.c b/block.c
index c7c1a3b..84544d2 100644
--- a/block.c
+++ b/block.c
@@ -1501,13 +1501,11 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult
*res, BdrvCheckMode fix)
int bdrv_commit(BlockDriverState *bs)
{
BlockDriver *drv = bs->drv;
- BlockDriver *backing_drv;
int64_t sector, total_sectors;
int n, ro, open_flags;
- int ret = 0, rw_ret = 0;
+ int ret = 0;
uint8_t *buf;
char filename[1024];
- BlockDriverState *bs_rw, *bs_ro;
if (!drv)
return -ENOMEDIUM;
@@ -1516,42 +1514,18 @@ int bdrv_commit(BlockDriverState *bs)
return -ENOTSUP;
}
- if (bs->backing_hd->keep_read_only) {
- return -EACCES;
- }
-
if (bdrv_in_use(bs) || bdrv_in_use(bs->backing_hd)) {
return -EBUSY;
}
- backing_drv = bs->backing_hd->drv;
ro = bs->backing_hd->read_only;
strncpy(filename, bs->backing_hd->filename, sizeof(filename));
open_flags = bs->backing_hd->open_flags;
if (ro) {
- /* re-open as RW */
- bdrv_delete(bs->backing_hd);
- bs->backing_hd = NULL;
- bs_rw = bdrv_new("");
- rw_ret = bdrv_open(bs_rw, filename, open_flags | BDRV_O_RDWR,
- backing_drv);
- if (rw_ret < 0) {
- bdrv_delete(bs_rw);
- /* try to re-open read-only */
- bs_ro = bdrv_new("");
- ret = bdrv_open(bs_ro, filename, open_flags & ~BDRV_O_RDWR,
- backing_drv);
- if (ret < 0) {
- bdrv_delete(bs_ro);
- /* drive not functional anymore */
- bs->drv = NULL;
- return ret;
- }
- bs->backing_hd = bs_ro;
- return rw_ret;
+ if (bdrv_reopen(bs->backing_hd, open_flags | BDRV_O_RDWR, NULL)) {
+ return -EACCES;
}
- bs->backing_hd = bs_rw;
}
total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
@@ -1588,20 +1562,8 @@ ro_cleanup:
g_free(buf);
if (ro) {
- /* re-open as RO */
- bdrv_delete(bs->backing_hd);
- bs->backing_hd = NULL;
- bs_ro = bdrv_new("");
- ret = bdrv_open(bs_ro, filename, open_flags & ~BDRV_O_RDWR,
- backing_drv);
- if (ret < 0) {
- bdrv_delete(bs_ro);
- /* drive not functional anymore */
- bs->drv = NULL;
- return ret;
- }
- bs->backing_hd = bs_ro;
- bs->backing_hd->keep_read_only = 0;
+ /* ignoring error return here */
+ bdrv_reopen(bs->backing_hd, open_flags & ~BDRV_O_RDWR, NULL);
}
return ret;
--
1.7.6.5
- [Qemu-devel] [PATCH 03/19] block: make bdrv_set_enable_write_cache() modify open_flags, (continued)
- [Qemu-devel] [PATCH 03/19] block: make bdrv_set_enable_write_cache() modify open_flags, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 10/19] block: raw-posix image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 05/19] block: move aio initialization into a helper function, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 13/19] block: qcow2 image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 06/19] block: move open flag parsing in raw block drivers to helper functions, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 08/19] block: use BDRV_O_NOCACHE instead of s->aligned_buf in raw-posix.c, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 12/19] block: qed image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 11/19] block: raw image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 09/19] block: purge s->aligned_buf and s->aligned_buf_size from raw-posix.c, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 07/19] block: do not parse BDRV_O_CACHE_WB in block drivers, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 18/19] block: convert bdrv_commit() to use bdrv_reopen(),
Kevin Wolf <=
- [Qemu-devel] [PATCH 04/19] block: Framework for reopening files safely, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 14/19] block: qcow image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 15/19] block: vmdk image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 17/19] block: vpc image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 16/19] block: vdi image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 19/19] block: remove keep_read_only flag from BlockDriverState struct, Kevin Wolf, 2012/09/24
- Re: [Qemu-devel] [PULL 00/19] Block patches, Anthony Liguori, 2012/09/25