]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: store bootindex as unsigned int
authorPeter Krempa <pkrempa@redhat.com>
Tue, 29 Mar 2016 12:31:37 +0000 (14:31 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 6 Apr 2016 07:27:23 +0000 (09:27 +0200)
The value is never negative thus there's no need to store it in a signed
type.

src/bhyve/bhyve_command.c
src/conf/domain_conf.c
src/conf/domain_conf.h
src/qemu/qemu_command.c
src/qemu/qemu_command.h
src/qemu/qemu_driver.c

index 8ac4f71277eaf891d1329bbfa28eca4a1ca39eef..9ad3f9b528f9a81ffe56e524b5bd15275f8bd60c 100644 (file)
@@ -423,13 +423,12 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
     virDomainDiskDefPtr hdd, cd, userdef, diskdef;
     virBuffer devicemap;
     virCommandPtr cmd;
-    int best_idx;
+    unsigned int best_idx = UINT_MAX;
     size_t i;
 
     if (def->os.bootloaderArgs != NULL)
         return virBhyveProcessBuildCustomLoaderCmd(def);
 
-    best_idx = INT_MAX;
     devicemap = (virBuffer)VIR_BUFFER_INITIALIZER;
 
     /* Search disk list for CD or HDD device. We'll respect <boot order=''> if
index 3dd81197b7f5c0f2674abc1bddb061cca8605d25..3203dab58e2c9f535610d6aa9cdaa51d1092304a 100644 (file)
@@ -4412,7 +4412,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
                           unsigned int flags)
 {
     if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) && info->bootIndex)
-        virBufferAsprintf(buf, "<boot order='%d'/>\n", info->bootIndex);
+        virBufferAsprintf(buf, "<boot order='%u'/>\n", info->bootIndex);
 
     if (info->alias &&
         !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) {
@@ -4820,16 +4820,16 @@ virDomainDeviceBootParseXML(xmlNodePtr node,
                             virHashTablePtr bootHash)
 {
     char *order;
-    int boot;
     int ret = -1;
 
-    order = virXMLPropString(node, "order");
-    if (!order) {
+    if (!(order = virXMLPropString(node, "order"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("missing boot order attribute"));
         goto cleanup;
-    } else if (virStrToLong_i(order, NULL, 10, &boot) < 0 ||
-               boot <= 0) {
+    }
+
+    if (virStrToLong_uip(order, NULL, 10, &info->bootIndex) < 0 ||
+        info->bootIndex == 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("incorrect boot order '%s', expecting positive integer"),
                        order);
@@ -4848,7 +4848,6 @@ virDomainDeviceBootParseXML(xmlNodePtr node,
             goto cleanup;
     }
 
-    info->bootIndex = boot;
     ret = 0;
 
  cleanup:
@@ -22972,7 +22971,7 @@ virDomainDeviceInfoCheckBootIndex(virDomainDefPtr def ATTRIBUTE_UNUSED,
 
     if (info->bootIndex == newinfo->bootIndex) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("boot order %d is already used by another device"),
+                       _("boot order %u is already used by another device"),
                        newinfo->bootIndex);
         return -1;
     }
index fe9faebff6d65b7620acc32a9329139c2755ef53..f98b4f68686efc5459f2c762b36af9677057b454 100644 (file)
@@ -368,7 +368,7 @@ struct _virDomainDeviceInfo {
     char *romfile;
     /* bootIndex is only used for disk, network interface, hostdev
      * and redirdev devices */
-    int bootIndex;
+    unsigned int bootIndex;
 };
 
 
index 9001d064ca6555718bccb34de2318758cbddf781..a6afaecc2b02adcf0f0eb5aed840589a99cc1be4 100644 (file)
@@ -1525,7 +1525,7 @@ qemuCheckIOThreads(const virDomainDef *def,
 char *
 qemuBuildDriveDevStr(const virDomainDef *def,
                      virDomainDiskDefPtr disk,
-                     int bootindex,
+                     unsigned int bootindex,
                      virQEMUCapsPtr qemuCaps)
 {
     virBuffer opt = VIR_BUFFER_INITIALIZER;
@@ -1770,7 +1770,7 @@ qemuBuildDriveDevStr(const virDomainDef *def,
     virBufferAsprintf(&opt, ",drive=%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias);
     virBufferAsprintf(&opt, ",id=%s", disk->info.alias);
     if (bootindex && virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX))
-        virBufferAsprintf(&opt, ",bootindex=%d", bootindex);
+        virBufferAsprintf(&opt, ",bootindex=%u", bootindex);
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKIO)) {
         if (disk->blockio.logical_block_size > 0)
             virBufferAsprintf(&opt, ",logical_block_size=%u",
@@ -1828,7 +1828,9 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
                               bool emitBootindex)
 {
     size_t i;
-    int bootCD = 0, bootFloppy = 0, bootDisk = 0;
+    unsigned int bootCD = 0;
+    unsigned int bootFloppy = 0;
+    unsigned int bootDisk = 0;
     virBuffer fdc_opts = VIR_BUFFER_INITIALIZER;
     char *fdc_opts_str = NULL;
 
@@ -1852,7 +1854,7 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
 
     for (i = 0; i < def->ndisks; i++) {
         char *optstr;
-        int bootindex = 0;
+        unsigned int bootindex = 0;
         virDomainDiskDefPtr disk = def->disks[i];
         bool withDeviceArg = false;
         bool deviceFlagMasked = false;
@@ -1945,7 +1947,7 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
                 VIR_FREE(optstr);
 
                 if (bootindex) {
-                    if (virAsprintf(&optstr, "bootindex%c=%d",
+                    if (virAsprintf(&optstr, "bootindex%c=%u",
                                     disk->info.addr.drive.unit
                                     ? 'B' : 'A',
                                     bootindex) < 0)
@@ -3046,7 +3048,7 @@ char *
 qemuBuildNicDevStr(virDomainDefPtr def,
                    virDomainNetDefPtr net,
                    int vlan,
-                   int bootindex,
+                   unsigned int bootindex,
                    size_t vhostfdSize,
                    virQEMUCapsPtr qemuCaps)
 {
@@ -3175,7 +3177,7 @@ qemuBuildNicDevStr(virDomainDefPtr def,
     if (qemuBuildRomStr(&buf, &net->info, qemuCaps) < 0)
         goto error;
     if (bootindex && virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX))
-        virBufferAsprintf(&buf, ",bootindex=%d", bootindex);
+        virBufferAsprintf(&buf, ",bootindex=%u", bootindex);
 
     if (virBufferCheckError(&buf) < 0)
         goto error;
@@ -4213,7 +4215,7 @@ qemuOpenPCIConfig(virDomainHostdevDefPtr dev)
 char *
 qemuBuildPCIHostdevDevStr(const virDomainDef *def,
                           virDomainHostdevDefPtr dev,
-                          int bootIndex, /* used iff dev->info->bootIndex == 0 */
+                          unsigned int bootIndex, /* used iff dev->info->bootIndex == 0 */
                           const char *configfd,
                           virQEMUCapsPtr qemuCaps)
 {
@@ -4258,7 +4260,7 @@ qemuBuildPCIHostdevDevStr(const virDomainDef *def,
     if (dev->info->bootIndex)
         bootIndex = dev->info->bootIndex;
     if (bootIndex)
-        virBufferAsprintf(&buf, ",bootindex=%d", bootIndex);
+        virBufferAsprintf(&buf, ",bootindex=%u", bootIndex);
     if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0)
         goto error;
     if (qemuBuildRomStr(&buf, dev->info, qemuCaps) < 0)
@@ -4324,7 +4326,7 @@ qemuBuildUSBHostdevDevStr(const virDomainDef *def,
     }
     virBufferAsprintf(&buf, ",id=%s", dev->info->alias);
     if (dev->info->bootIndex)
-        virBufferAsprintf(&buf, ",bootindex=%d", dev->info->bootIndex);
+        virBufferAsprintf(&buf, ",bootindex=%u", dev->info->bootIndex);
 
     if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0)
         goto error;
@@ -4577,7 +4579,7 @@ qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
                       dev->info->alias, dev->info->alias);
 
     if (dev->info->bootIndex)
-        virBufferAsprintf(&buf, ",bootindex=%d", dev->info->bootIndex);
+        virBufferAsprintf(&buf, ",bootindex=%u", dev->info->bootIndex);
 
     if (virBufferCheckError(&buf) < 0)
         goto error;
@@ -4790,7 +4792,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
                             const virDomainDef *def,
                             virQEMUCapsPtr qemuCaps,
                             qemuBuildCommandLineCallbacksPtr callbacks,
-                            int *bootHostdevNet)
+                            unsigned int *bootHostdevNet)
 {
     size_t i;
 
@@ -4883,7 +4885,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
 
             if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
                 char *configfd_name = NULL;
-                int bootIndex = hostdev->info->bootIndex;
+                unsigned int bootIndex = hostdev->info->bootIndex;
 
                 /* bootNet will be non-0 if boot order was set and no other
                  * net devices were encountered
@@ -7665,7 +7667,7 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd,
                               virDomainDefPtr def,
                               virDomainNetDefPtr net,
                               virQEMUCapsPtr qemuCaps,
-                              int bootindex)
+                              unsigned int bootindex)
 {
     virBuffer chardev_buf = VIR_BUFFER_INITIALIZER;
     virBuffer netdev_buf = VIR_BUFFER_INITIALIZER;
@@ -7750,7 +7752,7 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
                               virDomainNetDefPtr net,
                               virQEMUCapsPtr qemuCaps,
                               int vlan,
-                              int bootindex,
+                              unsigned int bootindex,
                               virNetDevVPortProfileOp vmop,
                               bool standalone,
                               size_t *nnicindexes,
@@ -8041,7 +8043,7 @@ qemuBuildNetCommandLine(virCommandPtr cmd,
                         bool emitBootindex,
                         size_t *nnicindexes,
                         int **nicindexes,
-                        int *bootHostdevNet)
+                        unsigned int *bootHostdevNet)
 {
     size_t i;
     int last_good_net = -1;
@@ -8052,7 +8054,7 @@ qemuBuildNetCommandLine(virCommandPtr cmd,
         if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))
             virCommandAddArgList(cmd, "-net", "none", NULL);
     } else {
-        int bootNet = 0;
+        unsigned int bootNet = 0;
 
         if (emitBootindex) {
             /* convert <boot dev='network'/> to bootindex since we didn't emit
@@ -8694,7 +8696,7 @@ qemuBuildRedirdevDevStr(const virDomainDef *def,
                              "supported by this version of QEMU"));
             goto error;
         }
-        virBufferAsprintf(&buf, ",bootindex=%d", dev->info.bootIndex);
+        virBufferAsprintf(&buf, ",bootindex=%u", dev->info.bootIndex);
     }
 
     if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
@@ -9203,7 +9205,7 @@ qemuBuildCommandLine(virConnectPtr conn,
     virCommandPtr cmd = NULL;
     bool emitBootindex = false;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
-    int bootHostdevNet = 0;
+    unsigned int bootHostdevNet = 0;
 
 
     VIR_DEBUG("conn=%p driver=%p def=%p mon=%p json=%d "
index 7c13d459f8c5ceab9902bf2b40c6d064699b99e1..a3e6a00a23dbe02a19fe148a7b8bbb0153691715 100644 (file)
@@ -105,7 +105,7 @@ char *qemuBuildNicStr(virDomainNetDefPtr net,
 char *qemuBuildNicDevStr(virDomainDefPtr def,
                          virDomainNetDefPtr net,
                          int vlan,
-                         int bootindex,
+                         unsigned int bootindex,
                          size_t vhostfdSize,
                          virQEMUCapsPtr qemuCaps);
 
@@ -121,7 +121,7 @@ char *qemuBuildDriveStr(virConnectPtr conn,
 /* Current, best practice */
 char *qemuBuildDriveDevStr(const virDomainDef *def,
                            virDomainDiskDefPtr disk,
-                           int bootindex,
+                           unsigned int bootindex,
                            virQEMUCapsPtr qemuCaps);
 
 /* Current, best practice */
@@ -151,7 +151,7 @@ char *qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem);
 /* Current, best practice */
 char *qemuBuildPCIHostdevDevStr(const virDomainDef *def,
                                 virDomainHostdevDefPtr dev,
-                                int bootIndex,
+                                unsigned int bootIndex,
                                 const char *configfd,
                                 virQEMUCapsPtr qemuCaps);
 
index 0434438b28ec9d6571fb7a3be2ebb1ea339e0895..eaabe5882d0bec5c584f3346d4a9014897b8b5f9 100644 (file)
@@ -6981,7 +6981,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
      */
     for (i = 0; i < vm->def->nnets; i++) {
         virDomainNetDefPtr net = vm->def->nets[i];
-        int bootIndex = net->info.bootIndex;
+        unsigned int bootIndex = net->info.bootIndex;
         char *model = net->model;
         virMacAddr mac = net->mac;