]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
virsh-domain: use correct base for virStrToLong_ui
authorPavel Hrdina <phrdina@redhat.com>
Wed, 21 Oct 2015 10:43:29 +0000 (12:43 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 27 Oct 2015 14:26:44 +0000 (15:26 +0100)
While parsing device addresses we should use correct base and don't
count on auto-detect.  For example, PCI address uses hex numbers, but
each number starting with 0 will be auto-detected as octal number and
that's wrong.  Another wrong use-case is for PCI address if for example
bus is 10, than it's incorrectly parsed as decimal number.

PCI and CCW addresses have all values as hex numbers, IDE and SCSI
addresses are in decimal numbers.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
tools/virsh-domain.c

index 3f032f419a52585acf8e26956b6845383b717b7c..12e85e36890eb03082861a0dbf1f992075fe7145 100644 (file)
@@ -455,19 +455,19 @@ static int str2PCIAddress(const char *str, struct PCIAddress *pciAddr)
 
     domain = (char *)str;
 
-    if (virStrToLong_ui(domain, &bus, 0, &pciAddr->domain) != 0)
+    if (virStrToLong_ui(domain, &bus, 16, &pciAddr->domain) != 0)
         return -1;
 
     bus++;
-    if (virStrToLong_ui(bus, &slot, 0, &pciAddr->bus) != 0)
+    if (virStrToLong_ui(bus, &slot, 16, &pciAddr->bus) != 0)
         return -1;
 
     slot++;
-    if (virStrToLong_ui(slot, &function, 0, &pciAddr->slot) != 0)
+    if (virStrToLong_ui(slot, &function, 16, &pciAddr->slot) != 0)
         return -1;
 
     function++;
-    if (virStrToLong_ui(function, NULL, 0, &pciAddr->function) != 0)
+    if (virStrToLong_ui(function, NULL, 16, &pciAddr->function) != 0)
         return -1;
 
     return 0;
@@ -484,15 +484,15 @@ static int str2SCSIAddress(const char *str, struct SCSIAddress *scsiAddr)
 
     controller = (char *)str;
 
-    if (virStrToLong_uip(controller, &bus, 0, &scsiAddr->controller) != 0)
+    if (virStrToLong_uip(controller, &bus, 10, &scsiAddr->controller) != 0)
         return -1;
 
     bus++;
-    if (virStrToLong_uip(bus, &unit, 0, &scsiAddr->bus) != 0)
+    if (virStrToLong_uip(bus, &unit, 10, &scsiAddr->bus) != 0)
         return -1;
 
     unit++;
-    if (virStrToLong_ullp(unit, NULL, 0, &scsiAddr->unit) != 0)
+    if (virStrToLong_ullp(unit, NULL, 10, &scsiAddr->unit) != 0)
         return -1;
 
     return 0;
@@ -509,15 +509,15 @@ static int str2IDEAddress(const char *str, struct IDEAddress *ideAddr)
 
     controller = (char *)str;
 
-    if (virStrToLong_ui(controller, &bus, 0, &ideAddr->controller) != 0)
+    if (virStrToLong_ui(controller, &bus, 10, &ideAddr->controller) != 0)
         return -1;
 
     bus++;
-    if (virStrToLong_ui(bus, &unit, 0, &ideAddr->bus) != 0)
+    if (virStrToLong_ui(bus, &unit, 10, &ideAddr->bus) != 0)
         return -1;
 
     unit++;
-    if (virStrToLong_ui(unit, NULL, 0, &ideAddr->unit) != 0)
+    if (virStrToLong_ui(unit, NULL, 10, &ideAddr->unit) != 0)
         return -1;
 
     return 0;
@@ -534,15 +534,15 @@ static int str2CCWAddress(const char *str, struct CCWAddress *ccwAddr)
 
     cssid = (char *)str;
 
-    if (virStrToLong_ui(cssid, &ssid, 0, &ccwAddr->cssid) != 0)
+    if (virStrToLong_ui(cssid, &ssid, 16, &ccwAddr->cssid) != 0)
         return -1;
 
     ssid++;
-    if (virStrToLong_ui(ssid, &devno, 0, &ccwAddr->ssid) != 0)
+    if (virStrToLong_ui(ssid, &devno, 16, &ccwAddr->ssid) != 0)
         return -1;
 
     devno++;
-    if (virStrToLong_ui(devno, NULL, 0, &ccwAddr->devno) != 0)
+    if (virStrToLong_ui(devno, NULL, 16, &ccwAddr->devno) != 0)
         return -1;
 
     return 0;
@@ -739,8 +739,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
         } else if (STRPREFIX((const char *)target, "hd")) {
             if (diskAddr.type == DISK_ADDR_TYPE_IDE) {
                 virBufferAsprintf(&buf,
-                                  "<address type='drive' controller='%d'"
-                                  " bus='%d' unit='%d' />\n",
+                                  "<address type='drive' controller='%u'"
+                                  " bus='%u' unit='%u' />\n",
                                   diskAddr.addr.ide.controller, diskAddr.addr.ide.bus,
                                   diskAddr.addr.ide.unit);
             } else {