From nobody Wed Nov 5 16:41:38 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1535293242278828.3073092609432; Sun, 26 Aug 2018 07:20:42 -0700 (PDT) Received: from localhost ([::1]:49275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftvuD-0008Pn-12 for importer@patchew.org; Sun, 26 Aug 2018 10:20:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftvl9-00082n-H1 for qemu-devel@nongnu.org; Sun, 26 Aug 2018 10:11:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ftvl6-0006z7-CL for qemu-devel@nongnu.org; Sun, 26 Aug 2018 10:11:19 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:59580) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ftvl4-0006U4-23; Sun, 26 Aug 2018 10:11:16 -0400 Received: from 85-76-74-234-nat.elisa-mobile.fi ([85.76.74.234] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ftvkQ-0004AQ-L3; Sun, 26 Aug 2018 16:10:34 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1ftvkB-0004mU-Aw; Sun, 26 Aug 2018 17:10:19 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=tIayN8VvOXFSjag15nwXruEc+i8MtAiQ6/Go9TLK9Lo=; b=BYOF7A0ZwylfrwSZNWj+ehFQIZ9CzW1YOpmB35r8SwqSFdmoxdoII8kSLRXr6H4XPzwBAyHZVjtLI7EbKYtSEzFk9K/7bJwdifVdYa7dIdHIrYuC+dfEpZrc0Xc5Z4P/dIly9agcqVujxa1m//4HJk98bNqEPSzs9aOo//c1jBofU4aOSW494rd4IIkfmbmK6Rn3x1KvOSOYP14QvOOt+ZSdbI07FcpJF+353LKCdajXcHxtNkAIZWd2YPP3GhP7UwQ5abC27ZRSG4ao2l4G3eC6C6bTrqVsq+7JxEwuHmRoM62G3vqHLEsP1wrY0/xrBCBa9O6uC4lvWtYQBFvz9g==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Sun, 26 Aug 2018 17:09:39 +0300 Message-Id: <2827c309182950530885b95f0582677b8d99d347.1535291602.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH 8/9] block: Allow changing 'detect-zeroes' on reopen 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: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 'detect-zeroes' is one of the basic BlockdevOptions available for all drivers, but it's silently ignored by bdrv_reopen_prepare/commit(), so the user cannot change it and doesn't get an error explaining that it can't be changed. This should update the detect-zeroes setting, but does nothing: (qemu) qemu-io virtio0 "reopen -o detect-zeroes=3Don" This should return an error but also does nothing: (qemu) qemu-io virtio0 "reopen -o discard=3Doff,detect-zeroes=3Dunmap" Since there's no reason why we shouldn't allow changing it and the implementation is simple let's just do it. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 63 +++++++++++++++++++++++++++++++----------------= ---- include/block/block.h | 1 + 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/block.c b/block.c index 21f1eb9cd1..9aed5c19f4 100644 --- a/block.c +++ b/block.c @@ -764,6 +764,30 @@ static void bdrv_join_options(BlockDriverState *bs, QD= ict *options, } } =20 +static BlockdevDetectZeroesOptions bdrv_parse_detect_zeroes(QemuOpts *opts, + int open_flags, + Error **errp) +{ + Error *local_err =3D NULL; + const char *value =3D qemu_opt_get(opts, "detect-zeroes"); + BlockdevDetectZeroesOptions detect_zeroes =3D + qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, value, + BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return detect_zeroes; + } + + if (detect_zeroes =3D=3D BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP && + !(open_flags & BDRV_O_UNMAP)) + { + error_setg(errp, "setting detect-zeroes to unmap is not allowed " + "without setting discard operation to unmap"); + } + + return detect_zeroes; +} + /** * Set open flags for a given discard mode * @@ -1328,7 +1352,6 @@ static int bdrv_open_common(BlockDriverState *bs, Blo= ckBackend *file, const char *driver_name =3D NULL; const char *node_name =3D NULL; const char *discard; - const char *detect_zeroes; QemuOpts *opts; BlockDriver *drv; Error *local_err =3D NULL; @@ -1417,29 +1440,12 @@ static int bdrv_open_common(BlockDriverState *bs, B= lockBackend *file, } } =20 - detect_zeroes =3D qemu_opt_get(opts, "detect-zeroes"); - if (detect_zeroes) { - BlockdevDetectZeroesOptions value =3D - qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, - detect_zeroes, - BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, - &local_err); - if (local_err) { - error_propagate(errp, local_err); - ret =3D -EINVAL; - goto fail_opts; - } - - if (value =3D=3D BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP && - !(bs->open_flags & BDRV_O_UNMAP)) - { - error_setg(errp, "setting detect-zeroes to unmap is not allowe= d " - "without setting discard operation to unmap"); - ret =3D -EINVAL; - goto fail_opts; - } - - bs->detect_zeroes =3D value; + bs->detect_zeroes =3D + bdrv_parse_detect_zeroes(opts, bs->open_flags, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto fail_opts; } =20 if (filename !=3D NULL) { @@ -3187,6 +3193,14 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_stat= e, BlockReopenQueue *queue, } } =20 + reopen_state->detect_zeroes =3D + bdrv_parse_detect_zeroes(opts, reopen_state->flags, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto error; + } + /* node-name and driver must be unchanged. Put them back into the QDic= t, so * that they are checked at the end of this function. */ value =3D qemu_opt_get(opts, "node-name"); @@ -3344,6 +3358,7 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state) bs->options =3D reopen_state->options; bs->open_flags =3D reopen_state->flags; bs->read_only =3D !(reopen_state->flags & BDRV_O_RDWR); + bs->detect_zeroes =3D reopen_state->detect_zeroes; =20 /* Remove child references from bs->options and bs->explicit_options */ QLIST_FOREACH(child, &bs->children, next) { diff --git a/include/block/block.h b/include/block/block.h index 4e0871aaf9..f71fa5a1c4 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -184,6 +184,7 @@ typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueu= eEntry) BlockReopenQueue; typedef struct BDRVReopenState { BlockDriverState *bs; int flags; + BlockdevDetectZeroesOptions detect_zeroes; uint64_t perm, shared_perm; QDict *options; QDict *explicit_options; --=20 2.11.0