hw/block: Introduce rotational qdev property
PATCH 1/3 hw/block: Introduce rotational qdev property
The Linux kernel uses different I/O scheduler depending if the block device is a rotational device or not. Also it uses rotational devices to add entropy to the random pool.
This patch add a rotational qdev property so that the block device can be configured as a rotational device or a non-rotational device. Default to true to not change the default behavior.
--- blockdev.c | 4 ++++ include/hw/block/block.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-)
blockdev.c +4 -0
@@ -4037,6 +4037,10 @@ QemuOptsList qemu_common_drive_opts = { .name = BDRV_OPT_READ_ONLY, .type = QEMU_OPT_BOOL, .help = "open drive file as read-only", + },{ + .name = "rotational", + .type = QEMU_OPT_BOOL, + .help = "rotational drive (off, on)", }, THROTTLE_OPTS,
include/hw/block/block.h +3 -1
@@ -27,6 +27,7 @@ typedef struct BlockConf {uint32_t cyls, heads, secs;OnOffAuto wce;bool share_rw; +bool rotational;BlockdevOnError rerror;BlockdevOnError werror; } BlockConf;
@@ -56,7 +57,8 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) _conf.discard_granularity, -1), \DEFINE_PROP_ON_OFF_AUTO ("write-cache" , _state, _conf.wce, \ON_OFF_AUTO_AUTO ), \ - DEFINE_PROP_BOOL("share-rw", _state, _conf.share_rw, false) +DEFINE_PROP_BOOL ("share-rw" , _state, _conf.share_rw, false), \ + DEFINE_PROP_BOOL("rotational", _state, _conf.rotational, true)#define DEFINE_BLOCK_CHS_PROPERTIES (_state, _conf) \ DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \
Signature · 1 line
2.11.0
PATCH 2/3 scsi-disk: export rotational qdev property
Export the rotational qdev property to the block device characteristics VPD page.
--- hw/scsi/scsi-disk.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
hw/scsi/scsi-disk.c +14 -0
@@ -597,6 +597,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) outbuf[buflen++] =0x83 ;// device identification if (s->qdev.type ==TYPE_DISK ) { outbuf[buflen++] =0xb0 ;// block limits + outbuf[buflen++] =0xb1 ;/* block device characteristics */ outbuf[buflen++] =0xb2 ;// thin provisioning }break ;
@@ -739,6 +740,19 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) outbuf[43 ] = max_io_sectors &0xff ;break ; } +case 0xb1 :/* block device characteristics */ + { + buflen =0x40 ; +memset (outbuf +4 ,0 , buflen -4 ); + +/* medium rotation rate: 0 = not reported, 1 = non-rotating */ + outbuf[4 ] =0 ; + outbuf[5 ] = s->qdev.conf.rotational ?0 :1 ; + +/* nominal form factor */ + outbuf[7 ] =0 ;/* not reported */ +break ; + }case 0xb2 :/* thin provisioning */ { buflen =8 ;
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 2/3] scsi-disk: export rotational qdev property
Quoted 4 lines · Aurelien Jarno
Export the rotational qdev property to the block device characteristics VPD page.
Signed-off-by Aurelien Jarno <[email protected]>
Quoted 37 lines
--- hw/scsi/scsi-disk.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)hw/scsi/scsi-disk.c +14
-0@@ -597,6 +597,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) outbuf[buflen++] =0x83 ;// device identification if (s->qdev.type ==TYPE_DISK ) { outbuf[buflen++] =0xb0 ;// block limits + outbuf[buflen++] =0xb1 ;/* block device characteristics */ outbuf[buflen++] =0xb2 ;// thin provisioning }break ;@@ -739,6 +740,19 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) outbuf[43 ] = max_io_sectors &0xff ;break ; } +case 0xb1 :/* block device characteristics */ + { + buflen =0x40 ; +memset (outbuf +4 ,0 , buflen -4 ); + +/* medium rotation rate: 0 = not reported, 1 = non-rotating */ + outbuf[4 ] =0 ; + outbuf[5 ] = s->qdev.conf.rotational ?0 :1 ; + +/* nominal form factor */ + outbuf[7 ] =0 ;/* not reported */ +break ; + }case 0xb2 :/* thin provisioning */ { buflen =8 ;
PATCH 3/3 ide: export rotational qdev property
In reply to Aurelien JarnoExport the rotational qdev property in the IDENTIFY request.
--- hw/ide/core.c | 3 +++ 1 file changed, 3 insertions(+)
hw/ide/core.c +3 -0
@@ -191,6 +191,9 @@ static void ide_identify(IDEState *s)if (dev && dev->conf.discard_granularity) {put_le16 (p +169 ,1 );/* TRIM support */ } +if (dev && !dev->conf.rotational) { +put_le16 (p +217 ,1 );/* non-rotating device */ + }ide_identify_size (s); s->identify_set =1 ;
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 3/3] ide: export rotational qdev property
Quoted 3 lines · Aurelien Jarno
Export the rotational qdev property in the IDENTIFY request.
Signed-off-by Aurelien Jarno <[email protected]>
Quoted 19 lines
--- hw/ide/core.c | 3 +++ 1 file changed, 3 insertions(+)hw/ide/core.c +3
-0@@ -191,6 +191,9 @@ static void ide_identify(IDEState *s)if (dev && dev->conf.discard_granularity) {put_le16 (p +169 ,1 );/* TRIM support */ } +if (dev && !dev->conf.rotational) { +put_le16 (p +217 ,1 );/* non-rotating device */ + }ide_identify_size (s); s->identify_set =1 ;
Re: [Qemu-devel] [PATCH 3/3] ide: export rotational qdev property
In reply to Aurelien JarnoQuoted 13 lines · Aurelien Jarno
Export the rotational qdev property in the IDENTIFY request.
Signed-off-by Aurelien Jarno <[email protected]>--- hw/ide/core.c | 3 +++ 1 file changed, 3 insertions(+)hw/ide/core.c +0
-0
hw/ide/core.c static void ide_identify(IDEState *s) · line 199
Quoted 9 lines
hw/ide/core.c +3
-0@@ -191,6 +191,9 @@ static void ide_identify(IDEState *s)if (dev && dev->conf.discard_granularity) {put_le16 (p +169 ,1 );/* TRIM support */ } +if (dev && !dev->conf.rotational) { +put_le16 (p +217 ,1 );/* non-rotating device */ + }ide_identify_size (s); s->identify_set =1 ;
7.16.7.80 Word 217: Nominal media rotation rate
Word 217 is a copy of Nominal Media Rotation Rate (see A.11.5.4).
*flips page like it's a choose-your-own-adventure book*
OK, so 0x0001 just means "Non-rotational." I guess it probably does not matter that our default is "Rate not reported."
Looks like there's no relevant bits for packet identify data either, so:
A question about the series as a whole, though: if by default rotational is set to false, we will newly be setting this bit in IDENTIFY data with identical CLI invocations. Why is that OK?
Quoted 9 lines · Aurelien Jarno
The Linux kernel uses different I/O scheduler depending if the block device is a rotational device or not. Also it uses rotational devices to add entropy to the random pool.
This patch add a rotational qdev property so that the block device can be configured as a rotational device or a non-rotational device. Default to true to not change the default behavior.
Signed-off-by Aurelien Jarno <[email protected]>
Quoted 43 lines
--- blockdev.c | 4 ++++ include/hw/block/block.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-)blockdev.c +4
-0@@ -4037,6 +4037,10 @@ QemuOptsList qemu_common_drive_opts = { .name = BDRV_OPT_READ_ONLY, .type = QEMU_OPT_BOOL, .help = "open drive file as read-only", + },{ + .name = "rotational", + .type = QEMU_OPT_BOOL, + .help = "rotational drive (off, on)", }, THROTTLE_OPTS,include/hw/block/block.h +3
-1@@ -27,6 +27,7 @@ typedef struct BlockConf {uint32_t cyls, heads, secs;OnOffAuto wce;bool share_rw; +bool rotational;BlockdevOnError rerror;BlockdevOnError werror; } BlockConf;@@ -56,7 +57,8 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) _conf.discard_granularity, -1), \DEFINE_PROP_ON_OFF_AUTO ("write-cache" , _state, _conf.wce, \ON_OFF_AUTO_AUTO ), \ - DEFINE_PROP_BOOL("share-rw", _state, _conf.share_rw, false) +DEFINE_PROP_BOOL ("share-rw" , _state, _conf.share_rw, false), \ + DEFINE_PROP_BOOL("rotational", _state, _conf.rotational, true)#define DEFINE_BLOCK_CHS_PROPERTIES (_state, _conf) \ DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \
Quoted 8 lines · Aurelien Jarno
The Linux kernel uses different I/O scheduler depending if the block device is a rotational device or not. Also it uses rotational devices to add entropy to the random pool.
This patch add a rotational qdev property so that the block device can be configured as a rotational device or a non-rotational device. Default to true to not change the default behavior.
Quoted 5 lines
Signed-off-by Aurelien Jarno <[email protected]>--- blockdev.c | 4 ++++ include/hw/block/block.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-)
Please remember to send a 0/3 cover letter when sending a series (you can use 'git config format.coverletter auto' to make it easier).
The NBD server has the ability to expose to a client whether a given exported volume is rotational or not; so there may be some additional integration you should perform to make nbd-server properly export this new property.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 8 lines · Aurelien Jarno
The Linux kernel uses different I/O scheduler depending if the block device is a rotational device or not. Also it uses rotational devices to add entropy to the random pool.
This patch add a rotational qdev property so that the block device can be configured as a rotational device or a non-rotational device. Default to true to not change the default behavior.
Quoted 5 lines
Signed-off-by Aurelien Jarno <[email protected]>--- blockdev.c | 4 ++++ include/hw/block/block.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-)
Am 06.05.2017 um 14:43 hat Aurelien Jarno geschrieben:
Quoted 19 lines
The Linux kernel uses different I/O scheduler depending if the block device is a rotational device or not. Also it uses rotational devices to add entropy to the random pool.
This patch add a rotational qdev property so that the block device can be configured as a rotational device or a non-rotational device. Default to true to not change the default behavior.
Signed-off-by Aurelien Jarno <[email protected]>--- blockdev.c | 4 ++++ include/hw/block/block.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-)blockdev.c +0
-0
blockdev.c QemuOptsList qemu_common_drive_opts = { · line 4045
Quoted 9 lines
blockdev.c +4
-0@@ -4037,6 +4037,10 @@ QemuOptsList qemu_common_drive_opts = { .name = BDRV_OPT_READ_ONLY, .type = QEMU_OPT_BOOL, .help = "open drive file as read-only", + },{ + .name = "rotational", + .type = QEMU_OPT_BOOL, + .help = "rotational drive (off, on)", },
This hunk is wrong (and unnecessary). It makes the -drive parser parse rotational=... options without doing anything with them, so instead of correctly producing an error that this isn't a block driver option, it would be silently ignored.
-drive has a few legacy options that affect qdev devices, but we don't want to add anything new there; people can just use -device. So the fix for your patch is simply dropping this hunk.
Quoted 13 lines
include/hw/block/block.h +1
-0@@ -27,6 +27,7 @@ typedef struct BlockConf {uint32_t cyls, heads, secs;OnOffAuto wce;bool share_rw; +bool rotational;BlockdevOnError rerror;BlockdevOnError werror; } BlockConf;
include/hw/block/block.h static inline unsigned int get_physical_block_exp(BlockConf *conf) · line 64
Quoted 9 lines
include/hw/block/block.h +2
-1@@ -56,7 +57,8 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) _conf.discard_granularity, -1), \DEFINE_PROP_ON_OFF_AUTO ("write-cache" , _state, _conf.wce, \ON_OFF_AUTO_AUTO ), \ - DEFINE_PROP_BOOL("share-rw", _state, _conf.share_rw, false) +DEFINE_PROP_BOOL ("share-rw" , _state, _conf.share_rw, false), \ + DEFINE_PROP_BOOL("rotational", _state, _conf.rotational, true)#define DEFINE_BLOCK_CHS_PROPERTIES (_state, _conf) \ DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \
Also not sure about this one. It adds the property to all block devices, but only IDE and SCSI will actually look at it. Maybe it would be better to add this property only to the individual devices that actually support it.
Kevin