From patchwork Tue Feb 26 14:59:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 10830459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BCF91399 for ; Tue, 26 Feb 2019 14:58:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 497952C93D for ; Tue, 26 Feb 2019 14:58:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DA872C93F; Tue, 26 Feb 2019 14:58:54 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 952DC2C93D for ; Tue, 26 Feb 2019 14:58:53 +0000 (UTC) Received: from localhost ([127.0.0.1]:56749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyeC5-0002cX-0O for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Feb 2019 09:58:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyeBR-0002Gg-JW for qemu-devel@nongnu.org; Tue, 26 Feb 2019 09:58:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyeBQ-0000lW-G1 for qemu-devel@nongnu.org; Tue, 26 Feb 2019 09:58:13 -0500 Received: from relay.sw.ru ([185.231.240.75]:47164) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyeBG-0000D1-CP; Tue, 26 Feb 2019 09:58:02 -0500 Received: from [172.16.24.44] (helo=iris.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gyeAi-0008T8-NO; Tue, 26 Feb 2019 17:57:28 +0300 From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Tue, 26 Feb 2019 17:59:30 +0300 Message-Id: <20190226145930.5000-1-den@openvz.org> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/1] block: propagate discard aligment from format drivers to the guest 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 , "Denis V. Lunev" , Fam Zheng , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Nowaday SCSI drivers in guests are able to alight UNMAP requests before sending to the device. Right now QEMU provides an ability to set this via "discard_granularity" property of the block device which could be used by management layer. Though, in particular, from the point of QEMU, there is pdiscard_granularity on the format driver level, f.e. on QCOW2 or iSCSI. It would be beneficial to pass this value as a default for this property. Technically this should reduce the amount of useless UNMAP requests from the guest to the host. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Max Reitz CC: Paolo Bonzini CC: Fam Zheng --- block/block-backend.c | 13 +++++++++++++ hw/scsi/scsi-disk.c | 4 ++-- include/sysemu/block-backend.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index f6ea824308..17a709a551 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -21,11 +21,13 @@ #include "qapi/qapi-events-block.h" #include "qemu/id.h" #include "qemu/option.h" +#include "qemu/units.h" #include "trace.h" #include "migration/misc.h" /* Number of coroutines to reserve per attached device model */ #define COROUTINE_POOL_RESERVATION 64 +#define DEFAULT_DISCARD_GRANULARITY (4 * KiB) #define NOT_DONE 0x7fffffff /* used while emulated sync operation in progress */ @@ -2042,6 +2044,17 @@ int blk_probe_geometry(BlockBackend *blk, HDGeometry *geo) return bdrv_probe_geometry(blk_bs(blk), geo); } +int blk_discard_granularity(BlockBackend *blk) +{ + BlockDriverState *bs = blk_bs(blk); + + if (bs == NULL) { + return DEFAULT_DISCARD_GRANULARITY; + } + + return bs->bl.pdiscard_alignment; +} + /* * Updates the BlockBackendRootState object with data from the currently * attached BlockDriverState. diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index d4e83aef0e..f0ff099114 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -43,7 +43,6 @@ #define SCSI_MAX_INQUIRY_LEN 256 #define SCSI_MAX_MODE_LEN 256 -#define DEFAULT_DISCARD_GRANULARITY (4 * KiB) #define DEFAULT_MAX_UNMAP_SIZE (1 * GiB) #define DEFAULT_MAX_IO_SIZE INT_MAX /* 2 GB - 1 block */ @@ -2338,7 +2337,8 @@ static void scsi_realize(SCSIDevice *dev, Error **errp) if (s->qdev.conf.discard_granularity == -1) { s->qdev.conf.discard_granularity = - MAX(s->qdev.conf.logical_block_size, DEFAULT_DISCARD_GRANULARITY); + MAX(s->qdev.conf.logical_block_size, + blk_discard_granularity(s->qdev.conf.blk)); } if (!s->version) { diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 832a4bf168..18428e685d 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -218,6 +218,7 @@ int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size); int blk_probe_blocksizes(BlockBackend *blk, BlockSizes *bsz); int blk_probe_geometry(BlockBackend *blk, HDGeometry *geo); +int blk_discard_granularity(BlockBackend *blk); BlockAIOCB *blk_abort_aio_request(BlockBackend *blk, BlockCompletionFunc *cb, void *opaque, int ret);