From patchwork Wed Jul 6 14:45:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9216455 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C78F607D9 for ; Wed, 6 Jul 2016 14:50:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1DA120009 for ; Wed, 6 Jul 2016 14:50:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E67C324B44; Wed, 6 Jul 2016 14:50:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 47AE120009 for ; Wed, 6 Jul 2016 14:50:45 +0000 (UTC) Received: from localhost ([::1]:33955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKoA0-0008Ln-FN for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Jul 2016 10:50:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKo4v-0002nK-0a for qemu-devel@nongnu.org; Wed, 06 Jul 2016 10:45:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKo4t-00081N-CY for qemu-devel@nongnu.org; Wed, 06 Jul 2016 10:45:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52388) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKo4m-0007yl-O2; Wed, 06 Jul 2016 10:45:20 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4007252777; Wed, 6 Jul 2016 14:45:20 +0000 (UTC) Received: from noname.str.redhat.com. (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u66EjDou012299; Wed, 6 Jul 2016 10:45:19 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 6 Jul 2016 16:45:07 +0200 Message-Id: <1467816309-16657-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1467816309-16657-1-git-send-email-kwolf@redhat.com> References: <1467816309-16657-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 06 Jul 2016 14:45:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 4/6] block/qdev: Allow configuring rerror/werror with qdev properties X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The rerror/werror policies are implemented in the devices, so that's where they should be configured. In comparison to the old options in -drive, the qdev properties are only added to those devices that actually support them. If the option isn't given (or "auto" is specified), the setting of the BlockBackend is used for compatibility with the old options. For block jobs, "auto" is the same as "enospc". Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/block-backend.c | 1 + blockjob.c | 1 + hw/block/block.c | 12 ++++++++++++ hw/block/virtio-blk.c | 1 + hw/core/qdev-properties.c | 13 +++++++++++++ hw/ide/qdev.c | 1 + hw/scsi/scsi-disk.c | 1 + include/hw/block/block.h | 8 ++++++++ include/hw/qdev-properties.h | 4 ++++ qapi/block-core.json | 4 +++- 10 files changed, 45 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index a862f65..4fedaf2 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1173,6 +1173,7 @@ BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read, return BLOCK_ERROR_ACTION_REPORT; case BLOCKDEV_ON_ERROR_IGNORE: return BLOCK_ERROR_ACTION_IGNORE; + case BLOCKDEV_ON_ERROR_AUTO: default: abort(); } diff --git a/blockjob.c b/blockjob.c index 205da9d..444ce6e 100644 --- a/blockjob.c +++ b/blockjob.c @@ -524,6 +524,7 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err, switch (on_err) { case BLOCKDEV_ON_ERROR_ENOSPC: + case BLOCKDEV_ON_ERROR_AUTO: action = (error == ENOSPC) ? BLOCK_ERROR_ACTION_STOP : BLOCK_ERROR_ACTION_REPORT; break; diff --git a/hw/block/block.c b/hw/block/block.c index 396b0d5..8dc9d84 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -54,6 +54,7 @@ void blkconf_blocksizes(BlockConf *conf) void blkconf_apply_backend_options(BlockConf *conf) { BlockBackend *blk = conf->blk; + BlockdevOnError rerror, werror; bool wce; switch (conf->wce) { @@ -64,7 +65,18 @@ void blkconf_apply_backend_options(BlockConf *conf) abort(); } + rerror = conf->rerror; + if (rerror == BLOCKDEV_ON_ERROR_AUTO) { + rerror = blk_get_on_error(blk, true); + } + + werror = conf->werror; + if (werror == BLOCKDEV_ON_ERROR_AUTO) { + werror = blk_get_on_error(blk, false); + } + blk_set_enable_write_cache(blk, wce); + blk_set_on_error(blk, rerror, werror); } void blkconf_geometry(BlockConf *conf, int *ptrans, diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index ecd8ea3..357ff90 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -960,6 +960,7 @@ static void virtio_blk_instance_init(Object *obj) static Property virtio_blk_properties[] = { DEFINE_BLOCK_PROPERTIES(VirtIOBlock, conf.conf), + DEFINE_BLOCK_ERROR_PROPERTIES(VirtIOBlock, conf.conf), DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, conf.conf), DEFINE_PROP_STRING("serial", VirtIOBlock, conf.serial), DEFINE_PROP_BIT("config-wce", VirtIOBlock, conf.config_wce, 0, true), diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index e3b2184..3deceee 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -539,6 +539,19 @@ PropertyInfo qdev_prop_losttickpolicy = { .set = set_enum, }; +/* --- Block device error handling policy --- */ + +QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError) != sizeof(int)); + +PropertyInfo qdev_prop_blockdev_on_error = { + .name = "BlockdevOnError", + .description = "Error handling policy, " + "report/ignore/enospc/stop/auto", + .enum_table = BlockdevOnError_lookup, + .get = get_enum, + .set = set_enum, +}; + /* --- BIOS CHS translation */ QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation) != sizeof(int)); diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index e2badc3..5b11f22 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -264,6 +264,7 @@ static int ide_drive_initfn(IDEDevice *dev) #define DEFINE_IDE_DEV_PROPERTIES() \ DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \ + DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf), \ DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \ DEFINE_PROP_UINT64("wwn", IDEDrive, dev.wwn, 0), \ DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\ diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 8c26a4e..8dbfc10 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2849,6 +2849,7 @@ static const TypeInfo scsi_disk_base_info = { #define DEFINE_SCSI_DISK_PROPERTIES() \ DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf), \ + DEFINE_BLOCK_ERROR_PROPERTIES(SCSIDiskState, qdev.conf), \ DEFINE_PROP_STRING("ver", SCSIDiskState, version), \ DEFINE_PROP_STRING("serial", SCSIDiskState, serial), \ DEFINE_PROP_STRING("vendor", SCSIDiskState, vendor), \ diff --git a/include/hw/block/block.h b/include/hw/block/block.h index e511dc3..36dce84 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -26,6 +26,8 @@ typedef struct BlockConf { /* geometry, not all devices use this */ uint32_t cyls, heads, secs; OnOffAuto wce; + BlockdevOnError rerror; + BlockdevOnError werror; } BlockConf; static inline unsigned int get_physical_block_exp(BlockConf *conf) @@ -58,6 +60,12 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) DEFINE_PROP_UINT32("heads", _state, _conf.heads, 0), \ DEFINE_PROP_UINT32("secs", _state, _conf.secs, 0) +#define DEFINE_BLOCK_ERROR_PROPERTIES(_state, _conf) \ + DEFINE_PROP_BLOCKDEV_ON_ERROR("rerror", _state, _conf.rerror, \ + BLOCKDEV_ON_ERROR_AUTO), \ + DEFINE_PROP_BLOCKDEV_ON_ERROR("werror", _state, _conf.werror, \ + BLOCKDEV_ON_ERROR_AUTO) + /* Configuration helpers */ void blkconf_serial(BlockConf *conf, char **serial); diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 034b75a..2a9d2f9 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -20,6 +20,7 @@ extern PropertyInfo qdev_prop_ptr; extern PropertyInfo qdev_prop_macaddr; extern PropertyInfo qdev_prop_on_off_auto; extern PropertyInfo qdev_prop_losttickpolicy; +extern PropertyInfo qdev_prop_blockdev_on_error; extern PropertyInfo qdev_prop_bios_chs_trans; extern PropertyInfo qdev_prop_fdc_drive_type; extern PropertyInfo qdev_prop_drive; @@ -161,6 +162,9 @@ extern PropertyInfo qdev_prop_arraylen; #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ LostTickPolicy) +#define DEFINE_PROP_BLOCKDEV_ON_ERROR(_n, _s, _f, _d) \ + DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \ + BlockdevOnError) #define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int) #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \ diff --git a/qapi/block-core.json b/qapi/block-core.json index ac8f5f6..6008986 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -664,10 +664,12 @@ # @stop: for guest operations, stop the virtual machine; # for jobs, pause the job # +# @auto: inherit the error handling policy of the backend (since: 2.7) +# # Since: 1.3 ## { 'enum': 'BlockdevOnError', - 'data': ['report', 'ignore', 'enospc', 'stop'] } + 'data': ['report', 'ignore', 'enospc', 'stop', 'auto'] } ## # @MirrorSyncMode: