From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6kVF-0003wn-KD for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:25:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6kVA-0008M4-Ks for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:25:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36382) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6kVA-0008Lu-Ca for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:25:08 -0500 From: Kevin Wolf Date: Fri, 24 Jan 2014 18:21:47 +0100 Message-Id: <1390584136-24703-65-git-send-email-kwolf@redhat.com> In-Reply-To: <1390584136-24703-1-git-send-email-kwolf@redhat.com> References: <1390584136-24703-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 64/93] block: Fix bdrv_commit return value List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org 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 Reviewed-by: Benoit Canet --- block.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index 72bccb1..2106ae9 100644 --- a/block.c +++ b/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); -- 1.8.1.4