[libvirt] [PATCH] fix index creation for disks > {sd,hd,xvd,vd}z

Calling virDiskNameToIndex with a disk name > {sd,hd,xvd,vd}z, such as vdaa, generates a bogus index. Account for iterations through the loop. Old behaviour: vda -> 0 vdz -> 25 vdaa -> 0 vdaz -> 25 New behaviour: vda -> 0 vdz -> 25 vdaa -> 26 vdaz -> 51 This was discovered by Sanjay Rao, thanks for the report. Signed-off-by: Chris Wright <chrisw@redhat.com> Cc: Mark Wagner <mwagner@redhat.com> Cc: Sanjay Rao <srao@redhat.com> --- src/domain_conf.c | 2 +- src/util.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/domain_conf.c b/src/domain_conf.c index 6a35064..b5897a7 100644 --- a/src/domain_conf.c +++ b/src/domain_conf.c @@ -3395,7 +3395,7 @@ char *virDomainConfigFile(virConnectPtr conn, /* Translates a device name of the form (regex) "[fhv]d[a-z]+" into * the corresponding bus,index combination (e.g. sda => (0,0), sdi (1,1), - * hdd => (1,1), vdaa => (0,27)) + * hdd => (1,1), vdaa => (0,26)) * @param disk The disk device * @param busIdx parsed bus number * @param devIdx parsed device number diff --git a/src/util.c b/src/util.c index ca14be1..56390d7 100644 --- a/src/util.c +++ b/src/util.c @@ -1055,7 +1055,7 @@ const char *virEnumToString(const char *const*types, } /* Translates a device name of the form (regex) "[fhv]d[a-z]+" into - * the corresponding index (e.g. sda => 1, hdz => 26, vdaa => 27) + * the corresponding index (e.g. sda => 0, hdz => 25, vdaa => 26) * @param name The name of the device * @return name's index, or -1 on failure */ @@ -1075,8 +1075,8 @@ int virDiskNameToIndex(const char *name) { if (!ptr) return -1; - while (*ptr) { - idx = idx * 26; + for (i = 0; *ptr; i++) { + idx = (idx + i) * 26; if (!c_islower(*ptr)) return -1;

On Wed, Oct 08, 2008 at 06:23:05PM -0700, Chris Wright wrote:
Calling virDiskNameToIndex with a disk name > {sd,hd,xvd,vd}z, such as vdaa, generates a bogus index. Account for iterations through the loop.
Old behaviour: vda -> 0 vdz -> 25 vdaa -> 0 vdaz -> 25
New behaviour: vda -> 0 vdz -> 25 vdaa -> 26 vdaz -> 51
This was discovered by Sanjay Rao, thanks for the report.
ACK. Good to know someone's testing scalability with > 26 disks :-) Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Wed, Oct 08, 2008 at 06:23:05PM -0700, Chris Wright wrote:
Calling virDiskNameToIndex with a disk name > {sd,hd,xvd,vd}z, such as vdaa, generates a bogus index. Account for iterations through the loop.
Old behaviour: vda -> 0 vdz -> 25 vdaa -> 0 vdaz -> 25
New behaviour: vda -> 0 vdz -> 25 vdaa -> 26 vdaz -> 51
This was discovered by Sanjay Rao, thanks for the report.
Ah, right ! Commited, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (3)
-
Chris Wright
-
Daniel P. Berrange
-
Daniel Veillard