From patchwork Mon Oct 25 15:17:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 69105 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 578B3B70B8 for ; Tue, 26 Oct 2010 02:24:18 +1100 (EST) Received: from localhost ([127.0.0.1]:45579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PAOu7-0005k8-Ju for incoming@patchwork.ozlabs.org; Mon, 25 Oct 2010 11:24:07 -0400 Received: from [140.186.70.92] (port=47623 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PAOnC-0001ev-82 for qemu-devel@nongnu.org; Mon, 25 Oct 2010 11:16:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PAOnA-0008C6-NC for qemu-devel@nongnu.org; Mon, 25 Oct 2010 11:16:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2146) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PAOnA-0008Br-Bs for qemu-devel@nongnu.org; Mon, 25 Oct 2010 11:16:56 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9PFGtqP024548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 25 Oct 2010 11:16:55 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o9PFGpGP030378; Mon, 25 Oct 2010 11:16:54 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Mon, 25 Oct 2010 17:17:34 +0200 Message-Id: <1288019856-16649-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1288019856-16649-1-git-send-email-kwolf@redhat.com> References: <1288019856-16649-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH 2/4] block: Allow bdrv_flush to return errors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This changes bdrv_flush to return 0 on success and -errno in case of failure. It's a requirement for implementing proper error handle in users of bdrv_flush. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block.c | 21 +++++++++++++++++---- block.h | 2 +- block/blkdebug.c | 4 ++-- block/blkverify.c | 4 ++-- block/cow.c | 4 ++-- block/qcow.c | 4 ++-- block/qcow2.c | 4 ++-- block/raw-posix.c | 4 ++-- block/raw-win32.c | 9 ++++++++- block/raw.c | 4 ++-- block/vdi.c | 4 ++-- block/vmdk.c | 4 ++-- block_int.h | 2 +- 13 files changed, 45 insertions(+), 25 deletions(-) diff --git a/block.c b/block.c index 985d0b7..6b505fb 100644 --- a/block.c +++ b/block.c @@ -1453,14 +1453,27 @@ const char *bdrv_get_device_name(BlockDriverState *bs) return bs->device_name; } -void bdrv_flush(BlockDriverState *bs) +int bdrv_flush(BlockDriverState *bs) { if (bs->open_flags & BDRV_O_NO_FLUSH) { - return; + return 0; + } + + if (bs->drv && bs->drv->bdrv_flush) { + return bs->drv->bdrv_flush(bs); } - if (bs->drv && bs->drv->bdrv_flush) - bs->drv->bdrv_flush(bs); + /* + * Some block drivers always operate in either writethrough or unsafe mode + * and don't support bdrv_flush therefore. Usually qemu doesn't know how + * the server works (because the behaviour is hardcoded or depends on + * server-side configuration), so we can't ensure that everything is safe + * on disk. Returning an error doesn't work because that would break guests + * even if the server operates in writethrough mode. + * + * Let's hope the user knows what he's doing. + */ + return 0; } void bdrv_flush_all(void) diff --git a/block.h b/block.h index a4facf2..78ecfac 100644 --- a/block.h +++ b/block.h @@ -142,7 +142,7 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque); /* Ensure contents are flushed to disk. */ -void bdrv_flush(BlockDriverState *bs); +int bdrv_flush(BlockDriverState *bs); void bdrv_flush_all(void); void bdrv_close_all(void); diff --git a/block/blkdebug.c b/block/blkdebug.c index 4d6ff0a..cd9eb80 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -397,9 +397,9 @@ static void blkdebug_close(BlockDriverState *bs) } } -static void blkdebug_flush(BlockDriverState *bs) +static int blkdebug_flush(BlockDriverState *bs) { - bdrv_flush(bs->file); + return bdrv_flush(bs->file); } static BlockDriverAIOCB *blkdebug_aio_flush(BlockDriverState *bs, diff --git a/block/blkverify.c b/block/blkverify.c index b2a12fe..0a8d691 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -116,12 +116,12 @@ static void blkverify_close(BlockDriverState *bs) s->test_file = NULL; } -static void blkverify_flush(BlockDriverState *bs) +static int blkverify_flush(BlockDriverState *bs) { BDRVBlkverifyState *s = bs->opaque; /* Only flush test file, the raw file is not important */ - bdrv_flush(s->test_file); + return bdrv_flush(s->test_file); } static int64_t blkverify_getlength(BlockDriverState *bs) diff --git a/block/cow.c b/block/cow.c index eedcc48..4cf543c 100644 --- a/block/cow.c +++ b/block/cow.c @@ -282,9 +282,9 @@ exit: return ret; } -static void cow_flush(BlockDriverState *bs) +static int cow_flush(BlockDriverState *bs) { - bdrv_flush(bs->file); + return bdrv_flush(bs->file); } static QEMUOptionParameter cow_create_options[] = { diff --git a/block/qcow.c b/block/qcow.c index 816103d..9cd547d 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -910,9 +910,9 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, return 0; } -static void qcow_flush(BlockDriverState *bs) +static int qcow_flush(BlockDriverState *bs) { - bdrv_flush(bs->file); + return bdrv_flush(bs->file); } static BlockDriverAIOCB *qcow_aio_flush(BlockDriverState *bs, diff --git a/block/qcow2.c b/block/qcow2.c index b816d87..537c479 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1148,9 +1148,9 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, return 0; } -static void qcow_flush(BlockDriverState *bs) +static int qcow_flush(BlockDriverState *bs) { - bdrv_flush(bs->file); + return bdrv_flush(bs->file); } static BlockDriverAIOCB *qcow_aio_flush(BlockDriverState *bs, diff --git a/block/raw-posix.c b/block/raw-posix.c index d0393e0..d0960b8 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -734,10 +734,10 @@ static int raw_create(const char *filename, QEMUOptionParameter *options) return result; } -static void raw_flush(BlockDriverState *bs) +static int raw_flush(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; - qemu_fdatasync(s->fd); + return qemu_fdatasync(s->fd); } diff --git a/block/raw-win32.c b/block/raw-win32.c index 503ed39..7f32778 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -150,7 +150,14 @@ static int raw_write(BlockDriverState *bs, int64_t sector_num, static void raw_flush(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; - FlushFileBuffers(s->hfile); + int ret; + + ret = FlushFileBuffers(s->hfile); + if (ret != 0) { + return -EIO; + } + + return 0; } static void raw_close(BlockDriverState *bs) diff --git a/block/raw.c b/block/raw.c index 9108779..1980deb 100644 --- a/block/raw.c +++ b/block/raw.c @@ -39,9 +39,9 @@ static void raw_close(BlockDriverState *bs) { } -static void raw_flush(BlockDriverState *bs) +static int raw_flush(BlockDriverState *bs) { - bdrv_flush(bs->file); + return bdrv_flush(bs->file); } static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs, diff --git a/block/vdi.c b/block/vdi.c index f72633c..3b51e53 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -900,10 +900,10 @@ static void vdi_close(BlockDriverState *bs) { } -static void vdi_flush(BlockDriverState *bs) +static int vdi_flush(BlockDriverState *bs) { logout("\n"); - bdrv_flush(bs->file); + return bdrv_flush(bs->file); } diff --git a/block/vmdk.c b/block/vmdk.c index 2d4ba42..872aeba 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -823,9 +823,9 @@ static void vmdk_close(BlockDriverState *bs) qemu_free(s->l2_cache); } -static void vmdk_flush(BlockDriverState *bs) +static int vmdk_flush(BlockDriverState *bs) { - bdrv_flush(bs->file); + return bdrv_flush(bs->file); } diff --git a/block_int.h b/block_int.h index 87e60b8..3c3adb5 100644 --- a/block_int.h +++ b/block_int.h @@ -59,7 +59,7 @@ struct BlockDriver { const uint8_t *buf, int nb_sectors); void (*bdrv_close)(BlockDriverState *bs); int (*bdrv_create)(const char *filename, QEMUOptionParameter *options); - void (*bdrv_flush)(BlockDriverState *bs); + int (*bdrv_flush)(BlockDriverState *bs); int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum); int (*bdrv_set_key)(BlockDriverState *bs, const char *key);