[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 18/19] block: convert bdrv_commit() to use bdrv_r
From: |
Jeff Cody |
Subject: |
[Qemu-devel] [PATCH v3 18/19] block: convert bdrv_commit() to use bdrv_reopen() |
Date: |
Tue, 18 Sep 2012 14:53:23 -0400 |
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>
---
block.c | 48 +++++-------------------------------------------
1 file changed, 5 insertions(+), 43 deletions(-)
diff --git a/block.c b/block.c
index d625703..ebdbf61 100644
--- a/block.c
+++ b/block.c
@@ -1497,13 +1497,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;
@@ -1512,42 +1510,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;
@@ -1584,20 +1558,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.11.4
- [Qemu-devel] [PATCH v3 09/19] block: raw-posix image file reopen, (continued)
- [Qemu-devel] [PATCH v3 09/19] block: raw-posix image file reopen, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 10/19] block: raw image file reopen, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 12/19] block: qcow2 image file reopen, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 13/19] block: qcow image file reopen, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 14/19] block: vmdk image file reopen, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 01/19] block: correctly set the keep_read_only flag, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 08/19] block: purge s->aligned_buf and s->aligned_buf_size from raw-posix.c, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 17/19] block: vpc image file reopen, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 15/19] block: raw-win32 driver reopen support, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 11/19] block: qed image file reopen, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 18/19] block: convert bdrv_commit() to use bdrv_reopen(),
Jeff Cody <=
- [Qemu-devel] [PATCH v3 02/19] block: make bdrv_set_enable_write_cache() modify open_flags, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 16/19] block: vdi image file reopen, Jeff Cody, 2012/09/18
- [Qemu-devel] [PATCH v3 19/19] block: remove keep_read_only flag from BlockDriverState struct, Jeff Cody, 2012/09/18