]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDiskNameToIndex: ignore trailing digits
authorJim Meyering <meyering@redhat.com>
Fri, 19 Mar 2010 17:26:09 +0000 (18:26 +0100)
committerJim Meyering <meyering@redhat.com>
Tue, 23 Mar 2010 10:22:26 +0000 (11:22 +0100)
* src/util/util.c (virDiskNameToIndex): Accept sda1, and map it to "sda".
I.e., accept and ignore any string of trailing digits.

src/util/util.c

index 119f0cd0240b6003ee9565255e982ef7b9899c69..1188e5f5e89ca5c6262b5a7ae08e21c2ab8ac6a6 100644 (file)
@@ -2260,8 +2260,9 @@ const char *virEnumToString(const char *const*types,
     return types[type];
 }
 
-/* Translates a device name of the form (regex) "[fhv]d[a-z]+" into
- * the corresponding index (e.g. sda => 0, hdz => 25, vdaa => 26)
+/* Translates a device name of the form (regex) /^[fhv]d[a-z]+[0-9]*$/
+ * into the corresponding index (e.g. sda => 0, hdz => 25, vdaa => 26)
+ * Note that any trailing string of digits is simply ignored.
  * @param name The name of the device
  * @return name's index, or -1 on failure
  */
@@ -2285,12 +2286,17 @@ int virDiskNameToIndex(const char *name) {
         idx = (idx + (i < 1 ? 0 : 1)) * 26;
 
         if (!c_islower(*ptr))
-            return -1;
+            break;
 
         idx += *ptr - 'a';
         ptr++;
     }
 
+    /* Count the trailing digits.  */
+    size_t n_digits = strspn(ptr, "0123456789");
+    if (ptr[n_digits] != '\0')
+        return -1;
+
     return idx;
 }