From nobody Tue May 21 16:24:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15530922863661015.4756516886633; Wed, 20 Mar 2019 07:31:26 -0700 (PDT) Received: from localhost ([127.0.0.1]:48818 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6cFX-0008PR-EV for importer@patchew.org; Wed, 20 Mar 2019 10:31:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6cCp-0006qm-Ag for qemu-devel@nongnu.org; Wed, 20 Mar 2019 10:28:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h6cCo-0001bl-6Q for qemu-devel@nongnu.org; Wed, 20 Mar 2019 10:28:35 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:61502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h6cCl-0001RO-HU; Wed, 20 Mar 2019 10:28:31 -0400 X-IronPort-AV: E=Sophos;i="5.60,249,1549929600"; d="scan'208";a="81130710" From: Paul Durrant To: , , Date: Wed, 20 Mar 2019 14:28:25 +0000 Message-ID: <20190320142825.24565-1-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb6 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PATCH] xen-block: only advertize discard to the frontend when it is enabled... 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: Anthony Perard , Kevin Wolf , Paul Durrant , Stefano Stabellini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" ...and properly enable it when synthesizing a drive. The Xen toolstack sets 'discard-enable' to '1' in xenstore when it wants to enable discard on a specified image. The code in xen_block_driver_create() correctly parses this and uses it to set 'discard' to 'unamp' for the file_layer, but fails to do the same for the driver_layer (which effectively disables it). Meanwhile the code in xen_block_realize() advertizes discard support to the frontend in the default case (because conf->discard_granularity defaults to -1), even when the underlying image may not handle it. This patch adds the missing option to the driver_layer in xen_block_driver_create() and checks whether BDRV_O_UNMAP is actually set on the block device before advertizing discard to the frontend. In the case that discard is supported it also makes sure that the granularity is set to the physical block size. Signed-off-by: Paul Durrant Reviewed-by: Anthony PERARD --- Cc: Stefano Stabellini Cc: Anthony Perard Cc: Kevin Wolf Cc: Max Reitz --- hw/block/xen-block.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 70fc2455e8..a848849f48 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -232,8 +232,14 @@ static void xen_block_realize(XenDevice *xendev, Error= **errp) blk_set_dev_ops(conf->blk, &xen_block_dev_ops, blockdev); blk_set_guest_block_size(conf->blk, conf->logical_block_size); =20 - if (conf->discard_granularity > 0) { + if (conf->discard_granularity =3D=3D -1) { + conf->discard_granularity =3D conf->physical_block_size; + } + + if (blk_get_flags(conf->blk) & BDRV_O_UNMAP) { xen_device_backend_printf(xendev, "feature-discard", "%u", 1); + xen_device_backend_printf(xendev, "discard-granularity", "%u", + conf->discard_granularity); } =20 xen_device_backend_printf(xendev, "feature-flush-cache", "%u", 1); @@ -755,6 +761,7 @@ static XenBlockDrive *xen_block_drive_create(const char= *id, drive->id =3D g_strdup(id); =20 file_layer =3D qdict_new(); + driver_layer =3D qdict_new(); =20 qdict_put_str(file_layer, "driver", "file"); qdict_put_str(file_layer, "filename", filename); @@ -782,6 +789,7 @@ static XenBlockDrive *xen_block_drive_create(const char= *id, =20 if (!qemu_strtoul(discard_enable, NULL, 2, &value) && !!value) { qdict_put_str(file_layer, "discard", "unmap"); + qdict_put_str(driver_layer, "discard", "unmap"); } } =20 @@ -791,8 +799,6 @@ static XenBlockDrive *xen_block_drive_create(const char= *id, */ qdict_put_str(file_layer, "locking", "off"); =20 - driver_layer =3D qdict_new(); - qdict_put_str(driver_layer, "driver", driver); g_free(driver); =20 --=20 2.20.1.2.gb21ebb6