From patchwork Thu Oct 20 11:16:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 120790 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6D2C4B6F88 for ; Thu, 20 Oct 2011 22:19:03 +1100 (EST) Received: from localhost ([::1]:48728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGqcf-00017M-9E for incoming@patchwork.ozlabs.org; Thu, 20 Oct 2011 07:17:17 -0400 Received: from eggs.gnu.org ([140.186.70.92]:55699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGqcR-0000zB-07 for qemu-devel@nongnu.org; Thu, 20 Oct 2011 07:17:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RGqcO-0001Tq-3B for qemu-devel@nongnu.org; Thu, 20 Oct 2011 07:17:02 -0400 Received: from mail-iy0-f173.google.com ([209.85.210.173]:57898) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGqcN-0001Qa-Jk for qemu-devel@nongnu.org; Thu, 20 Oct 2011 07:17:00 -0400 Received: by mail-iy0-f173.google.com with SMTP id l21so3766477iak.4 for ; Thu, 20 Oct 2011 04:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=ZRc0CqXldbrAEbqWRjyhUIl0rlDQAS7eczG7MwziP1A=; b=fC6XjyxdUcf5sv/Pz0PmR1DG4Tcnrx5puaTg1YHkLF/PRkRJxIsP4EIAnoIU3r8laE FnKB0IM5M52GZL75V3yv1x3YBavWo2wxrc2bgdCu92b36dVixtXafClTJAwPTXJmipdZ Azh7KJuHNEHhK36NHCP5C5g88xMP3ZVtBMbOU= Received: by 10.42.147.197 with SMTP id o5mr18286169icv.54.1319109418886; Thu, 20 Oct 2011 04:16:58 -0700 (PDT) Received: from localhost.localdomain (93-34-218-143.ip51.fastwebnet.it. [93.34.218.143]) by mx.google.com with ESMTPS id n30sm22979754ibl.4.2011.10.20.04.16.56 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 20 Oct 2011 04:16:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 20 Oct 2011 13:16:24 +0200 Message-Id: <1319109385-7927-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1319109385-7927-1-git-send-email-pbonzini@redhat.com> References: <1319109385-7927-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.173 Cc: kwolf@redhat.com, stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v2 6/7] block: change flush to co_flush X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Since coroutine operation is now mandatory, convert all bdrv_flush implementations to coroutines. For qcow2, this means taking the lock. Other implementations are simpler and just forward bdrv_flush to the underlying protocol, so they can avoid the lock. The bdrv_flush callback is then unused and can be eliminated. Signed-off-by: Paolo Bonzini --- block.c | 2 -- block/cow.c | 6 +++--- block/qcow.c | 11 +++++------ block/qcow2.c | 14 +++++++------- block/raw-win32.c | 4 ++-- block/rbd.c | 4 ++-- block/vdi.c | 6 +++--- block/vmdk.c | 8 ++++---- block/vpc.c | 6 +++--- block_int.h | 1 - 10 files changed, 29 insertions(+), 33 deletions(-) diff --git a/block.c b/block.c index 28508f2..81fb709 100644 --- a/block.c +++ b/block.c @@ -2892,8 +2892,6 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) qemu_coroutine_yield(); return co.ret; } - } else if (bs->drv->bdrv_flush) { - return bs->drv->bdrv_flush(bs); } else { /* * Some block drivers always operate in either writethrough or unsafe diff --git a/block/cow.c b/block/cow.c index bd00042..dc3b71d 100644 --- a/block/cow.c +++ b/block/cow.c @@ -306,9 +306,9 @@ exit: return ret; } -static int cow_flush(BlockDriverState *bs) +static coroutine_fn int cow_co_flush(BlockDriverState *bs) { - return bdrv_flush(bs->file); + return bdrv_co_flush(bs->file); } static QEMUOptionParameter cow_create_options[] = { @@ -334,7 +334,7 @@ static BlockDriver bdrv_cow = { .bdrv_write = cow_co_write, .bdrv_close = cow_close, .bdrv_create = cow_create, - .bdrv_flush = cow_flush, + .bdrv_co_flush = cow_co_flush, .bdrv_is_allocated = cow_is_allocated, .create_options = cow_create_options, diff --git a/block/qcow.c b/block/qcow.c index f93e3eb..ab36b29 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -781,10 +781,9 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, return 0; } -static BlockDriverAIOCB *qcow_aio_flush(BlockDriverState *bs, - BlockDriverCompletionFunc *cb, void *opaque) +static coroutine_fn int qcow_co_flush(BlockDriverState *bs) { - return bdrv_aio_flush(bs->file, cb, opaque); + return bdrv_co_flush(bs->file); } static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) @@ -824,9 +823,9 @@ static BlockDriver bdrv_qcow = { .bdrv_is_allocated = qcow_is_allocated, .bdrv_set_key = qcow_set_key, .bdrv_make_empty = qcow_make_empty, - .bdrv_co_readv = qcow_co_readv, - .bdrv_co_writev = qcow_co_writev, - .bdrv_aio_flush = qcow_aio_flush, + .bdrv_co_readv = qcow_co_readv, + .bdrv_co_writev = qcow_co_writev, + .bdrv_co_flush = qcow_co_flush, .bdrv_write_compressed = qcow_write_compressed, .bdrv_get_info = qcow_get_info, diff --git a/block/qcow2.c b/block/qcow2.c index 4dc980c..3758dbf 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1092,24 +1092,24 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num, return 0; } -static BlockDriverAIOCB *qcow2_aio_flush(BlockDriverState *bs, - BlockDriverCompletionFunc *cb, - void *opaque) +static int qcow2_co_flush(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; int ret; + qemu_co_mutex_lock(&s->lock); ret = qcow2_cache_flush(bs, s->l2_table_cache); if (ret < 0) { - return NULL; + return ret; } ret = qcow2_cache_flush(bs, s->refcount_block_cache); if (ret < 0) { - return NULL; + return ret; } + qemu_co_mutex_unlock(&s->lock); - return bdrv_aio_flush(bs->file, cb, opaque); + return bdrv_co_flush(bs->file); } static int64_t qcow2_vm_state_offset(BDRVQcowState *s) @@ -1230,7 +1230,7 @@ static BlockDriver bdrv_qcow2 = { .bdrv_co_readv = qcow2_co_readv, .bdrv_co_writev = qcow2_co_writev, - .bdrv_aio_flush = qcow2_aio_flush, + .bdrv_co_flush = qcow2_co_flush, .bdrv_discard = qcow2_discard, .bdrv_truncate = qcow2_truncate, diff --git a/block/raw-win32.c b/block/raw-win32.c index b7dd357..2fa7437 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -281,7 +281,7 @@ static BlockDriver bdrv_file = { .bdrv_file_open = raw_open, .bdrv_close = raw_close, .bdrv_create = raw_create, - .bdrv_flush = raw_flush, + .bdrv_co_flush = raw_flush, .bdrv_read = raw_read, .bdrv_write = raw_write, .bdrv_truncate = raw_truncate, @@ -409,7 +409,7 @@ static BlockDriver bdrv_host_device = { .bdrv_probe_device = hdev_probe_device, .bdrv_file_open = hdev_open, .bdrv_close = raw_close, - .bdrv_flush = raw_flush, + .bdrv_co_flush = raw_flush, .bdrv_has_zero_init = hdev_has_zero_init, .bdrv_read = raw_read, diff --git a/block/rbd.c b/block/rbd.c index 3068c82..c684e0c 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -705,7 +705,7 @@ static BlockDriverAIOCB *qemu_rbd_aio_writev(BlockDriverState *bs, return rbd_aio_rw_vector(bs, sector_num, qiov, nb_sectors, cb, opaque, 1); } -static int qemu_rbd_flush(BlockDriverState *bs) +static int qemu_rbd_co_flush(BlockDriverState *bs) { #if LIBRBD_VERSION_CODE >= LIBRBD_VERSION(0, 1, 1) /* rbd_flush added in 0.1.1 */ @@ -851,7 +851,7 @@ static BlockDriver bdrv_rbd = { .bdrv_file_open = qemu_rbd_open, .bdrv_close = qemu_rbd_close, .bdrv_create = qemu_rbd_create, - .bdrv_flush = qemu_rbd_flush, + .bdrv_co_flush = qemu_rbd_co_flush, .bdrv_get_info = qemu_rbd_getinfo, .create_options = qemu_rbd_create_options, .bdrv_getlength = qemu_rbd_getlength, diff --git a/block/vdi.c b/block/vdi.c index 1d5ad2b..883046d 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -936,10 +936,10 @@ static void vdi_close(BlockDriverState *bs) { } -static int vdi_flush(BlockDriverState *bs) +static coroutine_fn int vdi_co_flush(BlockDriverState *bs) { logout("\n"); - return bdrv_flush(bs->file); + return bdrv_co_flush(bs->file); } @@ -975,7 +975,7 @@ static BlockDriver bdrv_vdi = { .bdrv_open = vdi_open, .bdrv_close = vdi_close, .bdrv_create = vdi_create, - .bdrv_flush = vdi_flush, + .bdrv_co_flush = vdi_co_flush, .bdrv_is_allocated = vdi_is_allocated, .bdrv_make_empty = vdi_make_empty, diff --git a/block/vmdk.c b/block/vmdk.c index 3b376ed..6be592f 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1494,14 +1494,14 @@ static void vmdk_close(BlockDriverState *bs) vmdk_free_extents(bs); } -static int vmdk_flush(BlockDriverState *bs) +static coroutine_fn int vmdk_co_flush(BlockDriverState *bs) { int i, ret, err; BDRVVmdkState *s = bs->opaque; - ret = bdrv_flush(bs->file); + ret = bdrv_co_flush(bs->file); for (i = 0; i < s->num_extents; i++) { - err = bdrv_flush(s->extents[i].file); + err = bdrv_co_flush(s->extents[i].file); if (err < 0) { ret = err; } @@ -1568,7 +1568,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_write = vmdk_co_write, .bdrv_close = vmdk_close, .bdrv_create = vmdk_create, - .bdrv_flush = vmdk_flush, + .bdrv_co_flush = vmdk_co_flush, .bdrv_is_allocated = vmdk_is_allocated, .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size, diff --git a/block/vpc.c b/block/vpc.c index f900693..570361c 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -467,9 +467,9 @@ static coroutine_fn int vpc_co_write(BlockDriverState *bs, int64_t sector_num, return ret; } -static int vpc_flush(BlockDriverState *bs) +static coroutine_fn int vpc_co_flush(BlockDriverState *bs) { - return bdrv_flush(bs->file); + return bdrv_co_flush(bs->file); } /* @@ -673,7 +673,7 @@ static BlockDriver bdrv_vpc = { .bdrv_open = vpc_open, .bdrv_read = vpc_co_read, .bdrv_write = vpc_co_write, - .bdrv_flush = vpc_flush, + .bdrv_co_flush = vpc_co_flush, .bdrv_close = vpc_close, .bdrv_create = vpc_create, diff --git a/block_int.h b/block_int.h index 384598f..bc3b07e 100644 --- a/block_int.h +++ b/block_int.h @@ -62,7 +62,6 @@ struct BlockDriver { const uint8_t *buf, int nb_sectors); void (*bdrv_close)(BlockDriverState *bs); int (*bdrv_create)(const char *filename, QEMUOptionParameter *options); - int (*bdrv_flush)(BlockDriverState *bs); int (*bdrv_discard)(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,