virtio-blk: assign a default serial number if none provided
PATCH 1/1 virtio-blk: assign a default serial number if none provided
This patch applies on-top of John's virtio-blk serial patches.
Generate default serial numbers for virtio drives based on DriveInfo.unit which is incremented for each additional virtio-blk device. This provides a per-virtio-blk number to use in the default string: QM%05d that is used in hw/ide/core.c. The resulting serial number looks like: QM00001, etc.
--- hw/virtio-blk.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
hw/virtio-blk.c +3 -0
@@ -518,6 +518,9 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)bdrv_guess_geometry (s->bs, &cylinders, &heads, &secs);strncpy (s->sn,drive_get_serial (s->bs),sizeof (s->sn)); +if (strlen (s->sn) ==0 ) { +snprintf (s->sn,sizeof (s->sn),"QM%05d" , conf->dinfo->unit); + } s->vq =virtio_add_queue (&s->vdev,128 , virtio_blk_handle_output);
Signature · 8 lines
1.6.3.3 -- Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
02.06.2010 05:48, Ryan Harper wrote:
[]
Quoted 2 lines
hw/virtio-blk.c | 3 ++++ if (
strlen(s->sn)== 0) {
Just out of curiocity (not that it is wrong or inefficient):
why
strlen(s->sn)
and not, say,
!s->sn[0]
?
/mjt
Quoted 11 lines · Michael Tokarev
02.06.2010 05:48, Ryan Harper wrote:
[]Quoted 2 lines
hw/virtio-blk.c | 3 ++++ if (
strlen(s->sn)== 0) {Just out of curiocity (not that it is wrong or inefficient):
why
strlen(s->sn)
and not, say,
!s->sn[0]
?
Just matching how it's done in hw/ide/core.c:ide_init_drive()
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 6 lines · Ryan Harper
Quoted 5 lines · Michael Tokarev
02.06.2010 05:48, Ryan Harper wrote:
[]Quoted 2 lines
hw/virtio-blk.c | 3 ++++ if (
strlen(s->sn)== 0) {
Quoted 8 lines
Quoted 6 lines
Just out of curiocity (not that it is wrong or inefficient):
why
strlen(s->sn)
and not, say,
!s->sn[0]
?Just matching how it's done in hw/ide/core.c:ide_init_drive()
I cleaned it up there the other day.
[PATCH 11/14] ide: Turn drive serial into a qdev property ide-drive.serial
http://thread.gmane.org/gmane.comp.emulators.qemu/72441/focus=72432
http://repo.or.cz/w/qemu/kevin.git/commit/ebf5f0ff455a794faca404e62e5dd6d5bdf2fb9b
Quoted 8 lines · Ryan Harper
This patch applies on-top of John's virtio-blk serial patches.
Generate default serial numbers for virtio drives based on DriveInfo.unit which is incremented for each additional virtio-blk device. This provides a per-virtio-blk number to use in the default string: QM%05d that is used in
hw/ide/core.c. The resulting serial number looks like: QM00001, etc.Signed-off-by Ryan Harper <[email protected]>
I think that there's a problem with this approach in that hot plug A, hot plug B, hot unplug A is not the same as hot plug B.
So you might get guest boot failures and no easy way to figure out why. For guests that need S/N, I think they really must be persistent.
Quoted 27 lines
--- hw/virtio-blk.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)hw/virtio-blk.c +3
-0@@ -518,6 +518,9 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)bdrv_guess_geometry (s->bs, &cylinders, &heads, &secs);strncpy (s->sn,drive_get_serial (s->bs),sizeof (s->sn)); +if (strlen (s->sn) ==0 ) { +snprintf (s->sn,sizeof (s->sn),"QM%05d" , conf->dinfo->unit); + } s->vq =virtio_add_queue (&s->vdev,128 , virtio_blk_handle_output);Signature · 8 lines
1.6.3.3 -- Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Ryan Harper
This patch applies on-top of John's virtio-blk serial patches.
Generate default serial numbers for virtio drives based on DriveInfo.unit which is incremented for each additional virtio-blk device. This provides a per-virtio-blk number to use in the default string: QM%05d that is used in
hw/ide/core.c. The resulting serial number looks like: QM00001, etc.
Quoted 8 lines
Quoted 1 line
Signed-off-by Ryan Harper <[email protected]>I think that there's a problem with this approach in that hot plug A, hot plug B, hot unplug A is not the same as hot plug B.
So you might get guest boot failures and no easy way to figure out why. For guests that need S/N, I think they really must be persistent.
That's true; though I think most boot drives boot via either LVM or UUID which will remain persistent. That said, if you are relying on the by-id; then of course the user will need to specify serial versus having one auto-generated.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 18 lines · Ryan Harper
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Ryan Harper
This patch applies on-top of John's virtio-blk serial patches.
Generate default serial numbers for virtio drives based on DriveInfo.unit which is incremented for each additional virtio-blk device. This provides a per-virtio-blk number to use in the default string: QM%05d that is used in
hw/ide/core.c. The resulting serial number looks like: QM00001, etc.Quoted 8 lines
Quoted 1 line
Signed-off-by Ryan Harper <[email protected]>I think that there's a problem with this approach in that hot plug A, hot plug B, hot unplug A is not the same as hot plug B.
So you might get guest boot failures and no easy way to figure out why. For guests that need S/N, I think they really must be persistent.
Quoted 4 lines
That's true; though I think most boot drives boot via either LVM or UUID which will remain persistent. That said, if you are relying on the by-id; then of course the user will need to specify serial versus having one auto-generated.
I guess the question then would be, if you don't rely on the S/N, why do you want to set it?
Quoted 5 lines
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Ryan Harper
Quoted 16 lines · Michael S. Tsirkin
Quoted 8 lines · Ryan Harper
This patch applies on-top of John's virtio-blk serial patches.
Generate default serial numbers for virtio drives based on DriveInfo.unit which is incremented for each additional virtio-blk device. This provides a per-virtio-blk number to use in the default string: QM%05d that is used in
hw/ide/core.c. The resulting serial number looks like: QM00001, etc.Signed-off-by Ryan Harper <[email protected]>I think that there's a problem with this approach in that hot plug A, hot plug B, hot unplug A is not the same as hot plug B.
So you might get guest boot failures and no easy way to figure out why. For guests that need S/N, I think they really must be persistent.
Quoted 7 lines
Quoted 4 lines
That's true; though I think most boot drives boot via either LVM or UUID which will remain persistent. That said, if you are relying on the by-id; then of course the user will need to specify serial versus having one auto-generated.
I guess the question then would be, if you don't rely on the S/N, why do you want to set it?
Functional similarity; we have default serial numbers for ide and scsi. scsi is hotpluggable and would suffer the same issue; and of course ide doesn't do hotplug. I don't think most folks will encounter the above scenario and that having the same default serial numbers being generated like we do ide and scsi is reasonable.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]