From mboxrd@z Thu Jan 1 00:00:00 1970 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) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 8 Mar 2012 18:15:10 +0100 Message-Id: <1331226917-6658-11-git-send-email-pbonzini@redhat.com> In-Reply-To: <1331226917-6658-1-git-send-email-pbonzini@redhat.com> References: <1331226917-6658-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [RFC PATCH 10/17] ide/scsi: add discard_zeroes_data property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@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. */ -- 1.7.7.6