mirror of
https://github.com/qemu/qemu.git
synced 2024-11-23 19:03:38 +08:00
block: Fix bdrv_commit return value
bdrv_commit() could return 0 or 1 on success, depending on whether or not the last sector was allocated in the overlay and whether the overlay format had a .bdrv_make_empty callback. Most callers ignored it, but qemu-img commit would print an error message while the operation actually succeeded. Also clean up the handling of I/O errors to return the real error code instead of -EIO. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Benoit Canet <benoit@irqsave.net>
This commit is contained in:
parent
3722290074
commit
dabfa6cc2e
15
block.c
15
block.c
@ -2089,13 +2089,13 @@ int bdrv_commit(BlockDriverState *bs)
|
||||
goto ro_cleanup;
|
||||
}
|
||||
if (ret) {
|
||||
if (bdrv_read(bs, sector, buf, n) != 0) {
|
||||
ret = -EIO;
|
||||
ret = bdrv_read(bs, sector, buf, n);
|
||||
if (ret < 0) {
|
||||
goto ro_cleanup;
|
||||
}
|
||||
|
||||
if (bdrv_write(bs->backing_hd, sector, buf, n) != 0) {
|
||||
ret = -EIO;
|
||||
ret = bdrv_write(bs->backing_hd, sector, buf, n);
|
||||
if (ret < 0) {
|
||||
goto ro_cleanup;
|
||||
}
|
||||
}
|
||||
@ -2103,6 +2103,9 @@ int bdrv_commit(BlockDriverState *bs)
|
||||
|
||||
if (drv->bdrv_make_empty) {
|
||||
ret = drv->bdrv_make_empty(bs);
|
||||
if (ret < 0) {
|
||||
goto ro_cleanup;
|
||||
}
|
||||
bdrv_flush(bs);
|
||||
}
|
||||
|
||||
@ -2110,9 +2113,11 @@ int bdrv_commit(BlockDriverState *bs)
|
||||
* Make sure all data we wrote to the backing device is actually
|
||||
* stable on disk.
|
||||
*/
|
||||
if (bs->backing_hd)
|
||||
if (bs->backing_hd) {
|
||||
bdrv_flush(bs->backing_hd);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
ro_cleanup:
|
||||
g_free(buf);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user