ide: Adds wwn=hex qdev option allowing the user to specify a disk's World Wide Name
PATCH v2 3/3 ide: Adds wwn=hex qdev option allowing the user to specify a disk's World Wide Name
Linux guests can address disks by their unique World Wide Name number (e.g. /dev/disk/by-id/wwn-0x5001517959123522) This patch adds support for assigning a World Wide Name number to a virtual IDE disk.
--- hw/ide/core.c | 29 +++++++++++++++++++++++------ hw/ide/internal.h | 5 ++++- hw/ide/qdev.c | 3 ++- 3 files changed, 29 insertions(+), 8 deletions(-)
hw/ide/core.c +23 -6
@@ -143,8 +143,12 @@ static void ide_identify(IDEState *s)put_le16 (p +82 , (1 <<14 ) | (1 <<5 ) |1 );/* 13=flush_cache_ext,12=flush_cache,10=lba48 */ put_le16 (p +83 , (1 <<14 ) | (1 <<13 ) | (1 <<12 ) | (1 <<10 )); -/* 14=set to 1, 1=SMART self test, 0=SMART error logging */ -put_le16 (p +84 , (1 <<14 ) |0 ); +/* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */ +if (s->wwn) { +put_le16 (p +84 , (1 <<14 ) | (1 <<8 ) |0 ); + }else { +put_le16 (p +84 , (1 <<14 ) |0 ); + }/* 14 = NOP supported, 5=WCACHE enabled, 0=SMART feature set enabled */ if (bdrv_enable_write_cache (s->bs))put_le16 (p +85 , (1 <<14 ) | (1 <<5 ) |1 );
@@ -152,8 +156,12 @@ static void ide_identify(IDEState *s)put_le16 (p +85 , (1 <<14 ) |1 );/* 13=flush_cache_ext,12=flush_cache,10=lba48 */ put_le16 (p +86 , (1 <<14 ) | (1 <<13 ) | (1 <<12 ) | (1 <<10 )); -/* 14=set to 1, 1=smart self test, 0=smart error logging */ -put_le16 (p +87 , (1 <<14 ) |0 ); +/* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */ +if (s->wwn) { +put_le16 (p +87 , (1 <<14 ) | (1 <<8 ) |0 ); + }else { +put_le16 (p +87 , (1 <<14 ) |0 ); + }put_le16 (p +88 ,0x3f | (1 <<13 ));/* udma5 set and supported */ put_le16 (p +93 ,1 | (1 <<14 ) |0x2000 );put_le16 (p +100 , s->nb_sectors);
@@ -163,6 +171,13 @@ static void ide_identify(IDEState *s)if (dev && dev->conf.physical_block_size)put_le16 (p +106 ,0x6000 |get_physical_block_exp (&dev->conf)); +if (s->wwn) { +/* LE 16-bit words 111-108 contain 64-bit World Wide Name */ +put_le16 (p +108 , s->wwn >>48 ); +put_le16 (p +109 , s->wwn >>32 ); +put_le16 (p +110 , s->wwn >>16 ); +put_le16 (p +111 , s->wwn); + }if (dev && dev->conf.discard_granularity) {put_le16 (p +169 ,1 );/* TRIM support */ }
@@ -1834,7 +1849,8 @@ static const BlockDevOps ide_cd_block_ops = { };int ide_init_drive (IDEState *s,BlockDriverState *bs,IDEDriveKind kind, -const char *version,const char *serial,const char *model) +const char *version,const char *serial,const char *model, +uint64_t wwn) {int cylinders, heads, secs;uint64_t nb_sectors;
@@ -1860,6 +1876,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, s->heads = heads; s->sectors = secs; s->nb_sectors = nb_sectors; + s->wwn = wwn;/* The SMART values should be preserved across power cycles but they aren't. */ s->smart_enabled =1 ;
@@ -1994,7 +2011,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,if (ide_init_drive (&bus->ifs[i], dinfo->bdrv, dinfo->media_cd ?IDE_CD :IDE_HD ,NULL , *dinfo->serial ? dinfo->serial :NULL , -NULL ) <0 ) { +NULL ,0 ) <0 ) {error_report ("Can't set up IDE drive %s" , dinfo->id);exit (1 ); }
hw/ide/internal.h +4 -1
@@ -349,6 +349,7 @@ struct IDEState {int drive_serial;char drive_serial_str[21 ];char drive_model_str[41 ]; +uint64_t wwn;/* ide regs */ uint8_t feature;uint8_t error;
@@ -470,6 +471,7 @@ struct IDEDevice {char *version;char *serial;char *model; +uint64_t wwn; };#define BM_STATUS_DMAING 0x01
@@ -536,7 +538,8 @@ void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);uint32_t ide_data_readl (void *opaque,uint32_t addr);int ide_init_drive (IDEState *s,BlockDriverState *bs,IDEDriveKind kind, -const char *version,const char *serial,const char *model); +const char *version,const char *serial,const char *model, +uint64_t wwn);void ide_init2 (IDEBus *bus,qemu_irq irq);void ide_init2_with_non_qdev_drives (IDEBus *bus,DriveInfo *hd0,DriveInfo *hd1,qemu_irq irq);
hw/ide/qdev.c +2 -1
@@ -137,7 +137,7 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) }if (ide_init_drive (s, dev->conf.bs, kind, - dev->version, serial, dev->model) <0 ) { + dev->version, serial, dev->model, dev->wwn) <0 ) {return -1 ; }
@@ -174,6 +174,7 @@ static int ide_drive_initfn(IDEDevice *dev)#define DEFINE_IDE_DEV_PROPERTIES () \ DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \ DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \ + DEFINE_PROP_HEX64("wwn", IDEDrive, dev.wwn, 0), \ DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\ DEFINE_PROP_STRING("model", IDEDrive, dev.model)
Signature · 1 line
1.7.5.4
Il 13/03/2012 13:31, Floris Bos ha scritto:
Quoted 16 lines
Linux guests can address disks by their unique World Wide Name number (e.g.
/dev/disk/by-id/wwn-0x5001517959123522) This patch adds support for assigning a World Wide Name number to a virtual IDE disk.Signed-off-by Floris Bos <[email protected]>--- hw/ide/core.c | 29 +++++++++++++++++++++++------ hw/ide/internal.h | 5 ++++- hw/ide/qdev.c | 3 ++- 3 files changed, 29 insertions(+), 8 deletions(-)hw/ide/core.c +0
-0
hw/ide/core.c static void ide_identify(IDEState *s) · line 145
Quoted 3 lines
hw/ide/core.c +0
-0@@ -143,8 +143,12 @@ static void ide_identify(IDEState *s)put_le16 (p +82 , (1 <<14 ) | (1 <<5 ) |1 );/* 13=flush_cache_ext,12=flush_cache,10=lba48 */ put_le16 (p +83 , (1 <<14 ) | (1 <<13 ) | (1 <<12 ) | (1 <<10 ));
Bit 14 should not be set here. Not your fault, but perhaps you can fix it too?
Quoted 30 lines
hw/ide/core.c +12
-4-/* 14=set to 1, 1=SMART self test, 0=SMART error logging */ -put_le16 (p +84 , (1 <<14 ) |0 ); +/* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */ +if (s->wwn) { +put_le16 (p +84 , (1 <<14 ) | (1 <<8 ) |0 ); + }else { +put_le16 (p +84 , (1 <<14 ) |0 ); + }/* 14 = NOP supported, 5=WCACHE enabled, 0=SMART feature set enabled */ if (bdrv_enable_write_cache (s->bs))put_le16 (p +85 , (1 <<14 ) | (1 <<5 ) |1 );@@ -152,8 +156,12 @@ static void ide_identify(IDEState *s)put_le16 (p +85 , (1 <<14 ) |1 );/* 13=flush_cache_ext,12=flush_cache,10=lba48 */ put_le16 (p +86 , (1 <<14 ) | (1 <<13 ) | (1 <<12 ) | (1 <<10 )); -/* 14=set to 1, 1=smart self test, 0=smart error logging */ -put_le16 (p +87 , (1 <<14 ) |0 ); +/* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */ +if (s->wwn) { +put_le16 (p +87 , (1 <<14 ) | (1 <<8 ) |0 ); + }else { +put_le16 (p +87 , (1 <<14 ) |0 ); + }put_le16 (p +88 ,0x3f | (1 <<13 ));/* udma5 set and supported */ put_le16 (p +93 ,1 | (1 <<14 ) |0x2000 );put_le16 (p +100 , s->nb_sectors);@@ -163,6 +171,13 @@ static void ide_identify(IDEState *s)if (dev && dev->conf.physical_block_size)put_le16 (p +106 ,0x6000 |get_physical_block_exp (&dev->conf));
hw/ide/core.c static void ide_identify(IDEState *s) · line 183
Quoted 10 lines
hw/ide/core.c +7
-0+if (s->wwn) { +/* LE 16-bit words 111-108 contain 64-bit World Wide Name */ +put_le16 (p +108 , s->wwn >>48 ); +put_le16 (p +109 , s->wwn >>32 ); +put_le16 (p +110 , s->wwn >>16 ); +put_le16 (p +111 , s->wwn); + }if (dev && dev->conf.discard_granularity) {put_le16 (p +169 ,1 );/* TRIM support */ }
Words 84, 87, 108-111 should also be set in the ide_atapi_identify routine:
- 84 and 87 to 0x4000 if no WWN, 0x4100 if WWN provided
- 108..111 to the WWN in the same awkward-endian layout.
Otherwise looks good.
Paolo
Quoted 78 lines
hw/ide/core.c +4
-2@@ -1834,7 +1849,8 @@ static const BlockDevOps ide_cd_block_ops = { };int ide_init_drive (IDEState *s,BlockDriverState *bs,IDEDriveKind kind, -const char *version,const char *serial,const char *model) +const char *version,const char *serial,const char *model, +uint64_t wwn) {int cylinders, heads, secs;uint64_t nb_sectors;@@ -1860,6 +1876,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, s->heads = heads; s->sectors = secs; s->nb_sectors = nb_sectors; + s->wwn = wwn;/* The SMART values should be preserved across power cycles but they aren't. */ s->smart_enabled =1 ;@@ -1994,7 +2011,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,if (ide_init_drive (&bus->ifs[i], dinfo->bdrv, dinfo->media_cd ?IDE_CD :IDE_HD ,NULL , *dinfo->serial ? dinfo->serial :NULL , -NULL ) <0 ) { +NULL ,0 ) <0 ) {error_report ("Can't set up IDE drive %s" , dinfo->id);exit (1 ); }hw/ide/internal.h +4
-1@@ -349,6 +349,7 @@ struct IDEState {int drive_serial;char drive_serial_str[21 ];char drive_model_str[41 ]; +uint64_t wwn;/* ide regs */ uint8_t feature;uint8_t error;@@ -470,6 +471,7 @@ struct IDEDevice {char *version;char *serial;char *model; +uint64_t wwn; };#define BM_STATUS_DMAING 0x01@@ -536,7 +538,8 @@ void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);uint32_t ide_data_readl (void *opaque,uint32_t addr);int ide_init_drive (IDEState *s,BlockDriverState *bs,IDEDriveKind kind, -const char *version,const char *serial,const char *model); +const char *version,const char *serial,const char *model, +uint64_t wwn);void ide_init2 (IDEBus *bus,qemu_irq irq);void ide_init2_with_non_qdev_drives (IDEBus *bus,DriveInfo *hd0,DriveInfo *hd1,qemu_irq irq);hw/ide/qdev.c +2
-1@@ -137,7 +137,7 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) }if (ide_init_drive (s, dev->conf.bs, kind, - dev->version, serial, dev->model) <0 ) { + dev->version, serial, dev->model, dev->wwn) <0 ) {return -1 ; }@@ -174,6 +174,7 @@ static int ide_drive_initfn(IDEDevice *dev)#define DEFINE_IDE_DEV_PROPERTIES () \ DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \ DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \ + DEFINE_PROP_HEX64("wwn", IDEDrive, dev.wwn, 0), \ DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\ DEFINE_PROP_STRING("model", IDEDrive, dev.model)
Am 13.03.2012 14:01, schrieb Paolo Bonzini:
Quoted 12 lines
Il 13/03/2012 13:31, Floris Bos ha scritto:
Quoted 11 lines
Linux guests can address disks by their unique World Wide Name number (e.g.
/dev/disk/by-id/wwn-0x5001517959123522) This patch adds support for assigning a World Wide Name number to a virtual IDE disk.Signed-off-by Floris Bos <[email protected]>--- hw/ide/core.c | 29 +++++++++++++++++++++++------ hw/ide/internal.h | 5 ++++- hw/ide/qdev.c | 3 ++- 3 files changed, 29 insertions(+), 8 deletions(-)
Quoted 11 lines
hw/ide/core.c static void ide_identify(IDEState *s) · line 145
Quoted 8 lines
hw/ide/core.c +0
-0@@ -143,8 +143,12 @@ static void ide_identify(IDEState *s)put_le16 (p +82 , (1 <<14 ) | (1 <<5 ) |1 );/* 13=flush_cache_ext,12=flush_cache,10=lba48 */ put_le16 (p +83 , (1 <<14 ) | (1 <<13 ) | (1 <<12 ) | (1 <<10 ));Bit 14 should not be set here. Not your fault, but perhaps you can fix it too?
Table in the spec says: "14 - Shall be set to one"
Quoted 43 lines
Quoted 30 lines
hw/ide/core.c +12
-4-/* 14=set to 1, 1=SMART self test, 0=SMART error logging */ -put_le16 (p +84 , (1 <<14 ) |0 ); +/* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */ +if (s->wwn) { +put_le16 (p +84 , (1 <<14 ) | (1 <<8 ) |0 ); + }else { +put_le16 (p +84 , (1 <<14 ) |0 ); + }/* 14 = NOP supported, 5=WCACHE enabled, 0=SMART feature set enabled */ if (bdrv_enable_write_cache (s->bs))put_le16 (p +85 , (1 <<14 ) | (1 <<5 ) |1 );@@ -152,8 +156,12 @@ static void ide_identify(IDEState *s)put_le16 (p +85 , (1 <<14 ) |1 );/* 13=flush_cache_ext,12=flush_cache,10=lba48 */ put_le16 (p +86 , (1 <<14 ) | (1 <<13 ) | (1 <<12 ) | (1 <<10 )); -/* 14=set to 1, 1=smart self test, 0=smart error logging */ -put_le16 (p +87 , (1 <<14 ) |0 ); +/* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */ +if (s->wwn) { +put_le16 (p +87 , (1 <<14 ) | (1 <<8 ) |0 ); + }else { +put_le16 (p +87 , (1 <<14 ) |0 ); + }put_le16 (p +88 ,0x3f | (1 <<13 ));/* udma5 set and supported */ put_le16 (p +93 ,1 | (1 <<14 ) |0x2000 );put_le16 (p +100 , s->nb_sectors);@@ -163,6 +171,13 @@ static void ide_identify(IDEState *s)if (dev && dev->conf.physical_block_size)put_le16 (p +106 ,0x6000 |get_physical_block_exp (&dev->conf));hw/ide/core.c static void ide_identify(IDEState *s) · line 183
Quoted 10 lines
hw/ide/core.c +7
-0+if (s->wwn) { +/* LE 16-bit words 111-108 contain 64-bit World Wide Name */ +put_le16 (p +108 , s->wwn >>48 ); +put_le16 (p +109 , s->wwn >>32 ); +put_le16 (p +110 , s->wwn >>16 ); +put_le16 (p +111 , s->wwn); + }if (dev && dev->conf.discard_granularity) {put_le16 (p +169 ,1 );/* TRIM support */ }Words 84, 87, 108-111 should also be set in the
ide_atapi_identifyroutine:
Quoted 3 lines
- 84 and 87 to
0x4000if no WWN,0x4100if WWN provided- 108..111 to the WWN in the same awkward-endian layout.
What about ide_cfata_identify, while we're at it? Or isn't it supported there?
But both of them are more missing features than bugs. I'll defer to Floris whether he wants to send another version.
Kevin
Il 13/03/2012 14:22, Kevin Wolf ha scritto:
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
put_le16(p + 82, (1 << 14) | (1 << 5) | 1); /* 13=flush_cache_ext,12=flush_cache,10=lba48 */ put_le16(p + 83, (1 << 14) | (1 << 13) | (1 <<12) | (1 << 10));Bit 14 should not be set here. Not your fault, but perhaps you can fix it too?
Table in the spec says: "14 - Shall be set to one"
uff, I hate those pages. The wrong one is word 86. Bit 14 is reserved there. It's wrong in ide_cfata_identify, too.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
hw/ide/core.c +6
-2-/* 14=set to 1, 1=SMART self test, 0=SMART error logging */ -put_le16 (p +84 , (1 <<14 ) |0 ); +/* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */ +if (s->wwn) { +put_le16 (p +84 , (1 <<14 ) | (1 <<8 ) |0 ); + }else { +put_le16 (p +84 , (1 <<14 ) |0 ); + }/* 14 = NOP supported, 5=WCACHE enabled, 0=SMART feature set enabled */ if (bdrv_enable_write_cache (s->bs))
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hw/ide/core.c static void ide_identify(IDEState *s) · line 158
Quoted 5 lines
put_le16(p + 85, (1 << 14) | (1 << 5) | 1);hw/ide/core.c +0
-0@@ -152,8 +156,12 @@ static void ide_identify(IDEState *s)put_le16 (p +85 , (1 <<14 ) |1 );/* 13=flush_cache_ext,12=flush_cache,10=lba48 */ put_le16 (p +86 , (1 <<14 ) | (1 <<13 ) | (1 <<12 ) | (1 <<10 ));What about
ide_cfata_identify, while we're at it? Or isn't it supported there?
No idea.
Paolo
Quoted 1 line · Paolo Bonzini
Words 84, 87, 108-111 should also be set in the
ide_atapi_identifyroutine: - 84 and 87 to0x4000if no WWN,0x4100if WWN provided - 108..111 to the WWN in the same awkward-endian layout. Otherwise looks good. Paolo
I leave it to someone else to write a patch for the ATAPI/CF-ATA stuff. I'm not sure if there's a real use-case for WWN's for removable storage.
And I am not so familiar with the ATA specification that I feel confident enough to make changes that also result in different behavior when no WWN is present. 84 and 87 are currently not set at all in ide_atapi_identify.
Yours sincerely,
Floris Bos
Il 13/03/2012 14:53, Floris Bos / Maxnet ha scritto:
Quoted 5 lines
Quoted 4 lines
Words 84, 87, 108-111 should also be set in the
ide_atapi_identify
routine: - 84 and 87 to0x4000if no WWN,0x4100if WWN provided - 108..111 to the WWN in the same awkward-endian layout. Otherwise looks good. Paolo
Quoted 7 lines
I leave it to someone else to write a patch for the ATAPI/CF-ATA stuff. I'm not sure if there's a real use-case for WWN's for removable storage.
And I am not so familiar with the ATA specification that I feel confident enough to make changes that also result in different behavior when no WWN is present.
84 and 87 are currently not set at all inide_atapi_identify.
Fair enough, thanks!
Paolo
Am 13.03.2012 14:53, schrieb Floris Bos / Maxnet:
Quoted 8 lines · Paolo Bonzini
Quoted 4 lines
Words 84, 87, 108-111 should also be set in the
ide_atapi_identify
routine: - 84 and 87 to0x4000if no WWN,0x4100if WWN provided - 108..111 to the WWN in the same awkward-endian layout. Otherwise looks good. PaoloI leave it to someone else to write a patch for the ATAPI/CF-ATA stuff. I'm not sure if there's a real use-case for WWN's for removable storage.
Okay, fine with me. Applied your patches to the block branch now.
Kevin