From patchwork Fri Feb 22 21:23:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 222657 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D1D422C02A8 for ; Sat, 23 Feb 2013 08:26:05 +1100 (EST) Received: from localhost ([::1]:42775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9083-0004ec-Nu for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2013 16:26:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U906e-0002vV-B5 for qemu-devel@nongnu.org; Fri, 22 Feb 2013 16:24:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U906b-0003rr-0y for qemu-devel@nongnu.org; Fri, 22 Feb 2013 16:24:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12872) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U906a-0003rk-Nm for qemu-devel@nongnu.org; Fri, 22 Feb 2013 16:24:32 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1MLOVTJ031583 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 22 Feb 2013 16:24:31 -0500 Received: from dhcp-200-207.str.redhat.com (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1MLNuFk010868; Fri, 22 Feb 2013 16:24:30 -0500 From: Kevin Wolf To: anthony@codemonkey.ws Date: Fri, 22 Feb 2013 22:23:50 +0100 Message-Id: <1361568231-18198-22-git-send-email-kwolf@redhat.com> In-Reply-To: <1361568231-18198-1-git-send-email-kwolf@redhat.com> References: <1361568231-18198-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 21/22] blockdev: enable discard by default X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini Because discard is now a host parameter, we can always fake it as enabled in the guest. This is an extension of the current choice to ignore "not supported" errors from the host when discard_granularity is set to nonzero. The default granularity is set to the logical block size or 4k, whichever is largest, because cluster sizes below 4k are rarely used and 4K is a typical block size for files. Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- hw/block-common.h | 2 +- hw/ide/qdev.c | 5 ++++- hw/scsi-disk.c | 13 ++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/hw/block-common.h b/hw/block-common.h index bb808f7..dd11532 100644 --- a/hw/block-common.h +++ b/hw/block-common.h @@ -50,7 +50,7 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \ DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1), \ DEFINE_PROP_UINT32("discard_granularity", _state, \ - _conf.discard_granularity, 0) + _conf.discard_granularity, -1) #define DEFINE_BLOCK_CHS_PROPERTIES(_state, _conf) \ DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \ diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index c436b38..fd06da7 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -143,7 +143,10 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus); IDEState *s = bus->ifs + dev->unit; - if (dev->conf.discard_granularity && dev->conf.discard_granularity != 512) { + if (dev->conf.discard_granularity == -1) { + dev->conf.discard_granularity = 512; + } else if (dev->conf.discard_granularity && + dev->conf.discard_granularity != 512) { error_report("discard_granularity must be 512 for ide"); return -1; } diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 28e75bb..d411586 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -41,9 +41,11 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0) #include #endif -#define SCSI_DMA_BUF_SIZE 131072 -#define SCSI_MAX_INQUIRY_LEN 256 -#define SCSI_MAX_MODE_LEN 256 +#define SCSI_DMA_BUF_SIZE 131072 +#define SCSI_MAX_INQUIRY_LEN 256 +#define SCSI_MAX_MODE_LEN 256 + +#define DEFAULT_DISCARD_GRANULARITY 4096 typedef struct SCSIDiskState SCSIDiskState; @@ -2059,6 +2061,11 @@ static int scsi_initfn(SCSIDevice *dev) return -1; } + if (s->qdev.conf.discard_granularity == -1) { + s->qdev.conf.discard_granularity = + MAX(s->qdev.conf.logical_block_size, DEFAULT_DISCARD_GRANULARITY); + } + if (!s->version) { s->version = g_strdup(qemu_get_version()); }