From patchwork Thu Mar 8 17:15:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 145593 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 9025AB6EE6 for ; Fri, 9 Mar 2012 04:25:07 +1100 (EST) Received: from localhost ([::1]:53992 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5gwu-0005VT-Vx for incoming@patchwork.ozlabs.org; Thu, 08 Mar 2012 12:16:20 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5gwX-0004oh-6O for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:15:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S5gwQ-0004qa-Ow for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:15:56 -0500 Received: from mail-yw0-f45.google.com ([209.85.213.45]:52155) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5gwQ-0004oW-I1 for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:15:50 -0500 Received: by mail-yw0-f45.google.com with SMTP id o21so436011yho.4 for ; Thu, 08 Mar 2012 09:15:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=Jb2boSsy9VnF1CwYxXCE3pQjYxj5RnLKhKfEkUeGvu0=; b=IQtaQTUR1VEZ7h2Rlzfx1HARcn9ltuGLrt8GwCBK+2owTG5jsql7Hk/QJQCbw/cHLt MlwgkaHEKfljdJSM6f8U9Ow7PDkJbYxwRA4cKSndScI0t2707pt0a1KVmiOtNdfyShtw K9eyWEmDfONG1C8v/z13pJe4jRVxYUqoLhVyQSGk2ft8Pt42lNrg/3KiI7JjvRAqIK4N KM83Mb9tNZEq82d5jGq6IJQ6civYb5JS+S8+G9NPI23XMtEr3wHVQOBUOc+GK11M5y3F jPr5WuyP5Z7MMBAefLbQJK4LkoM2rvdf2igl8po080EY9IQZ6THmAGEVhUKYTsmsuKx+ Liow== Received: by 10.50.15.231 with SMTP id a7mr7876023igd.20.1331226949680; Thu, 08 Mar 2012 09:15:49 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id s3sm2123819igw.17.2012.03.08.09.15.47 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 08 Mar 2012 09:15:48 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 8 Mar 2012 18:15:10 +0100 Message-Id: <1331226917-6658-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1331226917-6658-1-git-send-email-pbonzini@redhat.com> References: <1331226917-6658-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.213.45 Subject: [Qemu-devel] [RFC PATCH 10/17] ide/scsi: add discard_zeroes_data property 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 Now that the block layer guarantees stable semantics for discard, we can expose them to guests. Signed-off-by: Paolo Bonzini --- block.h | 7 +++++-- hw/ide/core.c | 6 +++++- hw/scsi-disk.c | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/block.h b/block.h index ef07bb0..e28321e 100644 --- a/block.h +++ b/block.h @@ -423,6 +423,7 @@ typedef struct BlockConf { uint32_t opt_io_size; int32_t bootindex; uint32_t discard_granularity; + uint32_t discard_zeroes_data; } BlockConf; static inline unsigned int get_physical_block_exp(BlockConf *conf) @@ -444,10 +445,12 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) _conf.logical_block_size, 512), \ DEFINE_PROP_UINT16("physical_block_size", _state, \ _conf.physical_block_size, 512), \ - DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \ + DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \ 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, \ + DEFINE_PROP_BIT("discard_zeroes_data", _state, \ + _conf.discard_zeroes_data, 0, false), \ + DEFINE_PROP_UINT32("discard_granularity", _state, \ _conf.discard_granularity, 0) #endif diff --git a/hw/ide/core.c b/hw/ide/core.c index f12470e..1530b61 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -128,7 +128,11 @@ static void ide_identify(IDEState *s) put_le16(p + 67, 120); put_le16(p + 68, 120); if (dev && dev->conf.discard_granularity) { - put_le16(p + 69, (1 << 14)); /* determinate TRIM behavior */ + int val; + + val = 0x4000; + val |= dev->conf.discard_zeroes_data ? 0x20 : 0; + put_le16(p + 69, val); /* determinate TRIM behavior */ } if (s->ncq_queues) { diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index add399e..f489078 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1295,8 +1295,11 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r) outbuf[13] = get_physical_block_exp(&s->qdev.conf); /* set TPE bit if the format supports discard */ - if (s->qdev.conf.discard_granularity) { + if (s->qdev.type == TYPE_DISK && s->qdev.conf.discard_granularity) { outbuf[14] = 0x80; + if (s->qdev.conf.discard_zeroes_data) { + outbuf[14] |= 0x40; + } } /* Protection, exponent and lowest lba field left blank. */