From patchwork Wed Mar 20 14:28:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 1059255 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=citrix.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44PXQj5Y8wz9sPM for ; Thu, 21 Mar 2019 01:30:53 +1100 (AEDT) Received: from localhost ([127.0.0.1]:48814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6cF1-00084c-Pv for incoming@patchwork.ozlabs.org; Wed, 20 Mar 2019 10:30:51 -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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" ...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); - if (conf->discard_granularity > 0) { + if (conf->discard_granularity == -1) { + conf->discard_granularity = 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); } 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 = g_strdup(id); file_layer = qdict_new(); + driver_layer = qdict_new(); 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, if (!qemu_strtoul(discard_enable, NULL, 2, &value) && !!value) { qdict_put_str(file_layer, "discard", "unmap"); + qdict_put_str(driver_layer, "discard", "unmap"); } } @@ -791,8 +799,6 @@ static XenBlockDrive *xen_block_drive_create(const char *id, */ qdict_put_str(file_layer, "locking", "off"); - driver_layer = qdict_new(); - qdict_put_str(driver_layer, "driver", driver); g_free(driver);