[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH 11/17] ide/scsi: prepare for flipping the discar
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [RFC PATCH 11/17] ide/scsi: prepare for flipping the discard defaults |
Date: |
Thu, 8 Mar 2012 18:15:11 +0100 |
Let a discard_granularity equal to -1 represent "enabled with default
granularity". Also, Linux requires the discard_granularity to be
a power of two because it uses it with an AND, make the user obey.
Signed-off-by: Paolo Bonzini <address@hidden>
---
block.h | 6 +++---
hw/ide/qdev.c | 6 +++++-
hw/scsi-disk.c | 12 ++++++++++++
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/block.h b/block.h
index e28321e..aa224d3 100644
--- a/block.h
+++ b/block.h
@@ -422,7 +422,7 @@ typedef struct BlockConf {
uint16_t min_io_size;
uint32_t opt_io_size;
int32_t bootindex;
- uint32_t discard_granularity;
+ int32_t discard_granularity;
uint32_t discard_zeroes_data;
} BlockConf;
@@ -450,8 +450,8 @@ static inline unsigned int get_physical_block_exp(BlockConf
*conf)
DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1), \
DEFINE_PROP_BIT("discard_zeroes_data", _state, \
_conf.discard_zeroes_data, 0, false), \
- DEFINE_PROP_UINT32("discard_granularity", _state, \
- _conf.discard_granularity, 0)
+ DEFINE_PROP_INT32("discard_granularity", _state, \
+ _conf.discard_granularity, 0)
#endif
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index f6a4896..5c7141f 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -121,8 +121,12 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind
kind)
IDEState *s = bus->ifs + dev->unit;
const char *serial;
DriveInfo *dinfo;
+ int discard_granularity;
- if (dev->conf.discard_granularity && dev->conf.discard_granularity != 512)
{
+ discard_granularity = dev->conf.discard_granularity;
+ if (discard_granularity == -1) {
+ dev->conf.discard_granularity = 512;
+ } else if (discard_granularity && 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 f489078..00d355e 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1577,12 +1577,24 @@ static int scsi_initfn(SCSIDevice *dev)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
DriveInfo *dinfo;
+ int discard_granularity;
if (!s->qdev.conf.bs) {
error_report("drive property not set");
return -1;
}
+ discard_granularity = s->qdev.conf.discard_granularity;
+ if (discard_granularity == -1) {
+ s->qdev.conf.discard_granularity = s->qdev.conf.logical_block_size;
+ } else if (discard_granularity < s->qdev.conf.logical_block_size) {
+ error_report("scsi-block: invalid discard_granularity");
+ return -1;
+ } else if (discard_granularity & (discard_granularity - 1)) {
+ error_report("scsi-block: discard_granularity not a power of two");
+ return -1;
+ }
+
if (!s->removable && !bdrv_is_inserted(s->qdev.conf.bs)) {
error_report("Device needs media, but drive is empty");
return -1;
--
1.7.7.6
- Re: [Qemu-devel] [RFC PATCH 04/17] qed: implement bdrv_aio_discard, (continued)
- [Qemu-devel] [RFC PATCH 10/17] ide/scsi: add discard_zeroes_data property, Paolo Bonzini, 2012/03/08
- [Qemu-devel] [RFC PATCH 09/17] ide: issue discard asynchronously but serialize the pieces, Paolo Bonzini, 2012/03/08
- [Qemu-devel] [RFC PATCH 05/17] block: pass around qiov for write_zeroes operation, Paolo Bonzini, 2012/03/08
- [Qemu-devel] [RFC PATCH 12/17] ide/scsi: turn on discard, Paolo Bonzini, 2012/03/08
- [Qemu-devel] [RFC PATCH 01/17] qemu-iotests: add a simple test for write_zeroes, Paolo Bonzini, 2012/03/08
- [Qemu-devel] [RFC PATCH 11/17] ide/scsi: prepare for flipping the discard defaults,
Paolo Bonzini <=
- [Qemu-devel] [RFC PATCH 16/17] qemu-io: fix the alloc command, Paolo Bonzini, 2012/03/08
- [Qemu-devel] [RFC PATCH 07/17] block: make high level discard operation always zero, Paolo Bonzini, 2012/03/08
[Qemu-devel] [RFC PATCH 08/17] block: kill the write zeroes operation, Paolo Bonzini, 2012/03/08
[Qemu-devel] [RFC PATCH 15/17] raw: add get_info, Paolo Bonzini, 2012/03/08
[Qemu-devel] [RFC PATCH 14/17] block: support FALLOC_FL_PUNCH_HOLE trimming, Paolo Bonzini, 2012/03/08