Re: [PATCH 2/2] qemu: allow getting < max typed parameters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/01/2011 04:47 AM, Stefan Berger wrote:
On 10/31/2011 07:33 PM, Eric Blake wrote:
Since all virTypedParameter APIs allow us to return the number
of slots we actually populated, we should allow the user to
call with nparams too small (without overrunning their array)
or too large (ignoring the tail of the array that we can't fill),
rather than requiring that they get things exactly right.

* src/qemu/qemu_driver.c (qemuDomainGetBlkioParameters)
(qemuDomainGetMemoryParameters): Allow variable nparams on entry.
(qemuGetSchedulerParametersFlags): Drop redundant check.
(qemudDomainBlockStats, qemudDomainBlockStatsFlags): Rename...
(qemuDomainBlockStats, qemuDomainBlockStatsFlags): ...to this.
Don't return unavailable stats.

+ if (virStrcpyStatic(param->field,
+ VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES) == NULL) {
+ qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Field write bytes too long for destination"));
Existing but odd error message... "Field 'write bytes' is too long for
..." (?)

Yeah, that helps.

ACK

Pushed the series with this squashed in. I'm also working a followup for the XXX comment added below:

diff --git i/src/qemu/qemu_driver.c w/src/qemu/qemu_driver.c
index d70ab7a..f81cb88 100644
--- i/src/qemu/qemu_driver.c
+++ w/src/qemu/qemu_driver.c
@@ -6114,7 +6114,8 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom,
                 }
if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Field blkio weight too long for destination"));
+                                    _("Field name '%s' too long"),
+                                    VIR_DOMAIN_BLKIO_WEIGHT);
                     goto cleanup;
                 }
                 param->value.ui = val;
@@ -6136,7 +6137,8 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom,
             case 0: /* fill blkio weight here */
if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Field blkio weight too long for destination"));
+                                    _("Field name '%s' too long"),
+                                    VIR_DOMAIN_BLKIO_WEIGHT);
                     goto cleanup;
                 }
                 param->value.ui = persistentDef->blkio.weight;
@@ -6402,7 +6404,8 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
             case 0: /* fill memory hard limit here */
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT) == NULL) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Field memory hard limit too long for destination"));
+                                    _("Field name '%s' too long"),
+                                    VIR_DOMAIN_MEMORY_HARD_LIMIT);
                     goto cleanup;
                 }
                 param->value.ul = persistentDef->mem.hard_limit;
@@ -6411,7 +6414,8 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
             case 1: /* fill memory soft limit here */
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT) == NULL) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Field memory soft limit too long for destination"));
+                                    _("Field name '%s' too long"),
+                                    VIR_DOMAIN_MEMORY_SOFT_LIMIT);
                     goto cleanup;
                 }
                 param->value.ul = persistentDef->mem.soft_limit;
@@ -6420,7 +6424,8 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
             case 2: /* fill swap hard limit here */
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT) == NULL) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Field swap hard limit too long for destination"));
+                                    _("Field name '%s' too long"),
+                                    VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT);
                     goto cleanup;
                 }
                 param->value.ul = persistentDef->mem.swap_hard_limit;
@@ -6453,7 +6458,8 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
             }
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT) == NULL) {
                 qemuReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Field memory hard limit too long for destination"));
+                                _("Field name '%s' too long"),
+                                VIR_DOMAIN_MEMORY_HARD_LIMIT);
                 goto cleanup;
             }
             param->value.ul = val;
@@ -6468,7 +6474,8 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
             }
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT) == NULL) {
                 qemuReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Field memory soft limit too long for destination"));
+                                _("Field name '%s' too long"),
+                                VIR_DOMAIN_MEMORY_SOFT_LIMIT);
                 goto cleanup;
             }
             param->value.ul = val;
@@ -6483,7 +6490,8 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
             }
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT) == NULL) {
                 qemuReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Field swap hard limit too long for destination"));
+                                _("Field name '%s' too long"),
+                                VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT);
                 goto cleanup;
             }
             param->value.ul = val;
@@ -6973,9 +6981,11 @@ qemuGetSchedulerParametersFlags(virDomainPtr dom,
 out:
     params[0].value.ul = shares;
     params[0].type = VIR_TYPED_PARAM_ULLONG;
+    /* XXX make these field names public in libvirt.h */
     if (virStrcpyStatic(params[0].field, "cpu_shares") == NULL) {
         qemuReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Field cpu_shares too long for destination"));
+                        _("Field name '%s' too long"),
+                        "cpu_shares");
         goto cleanup;
     }

@@ -6987,8 +6997,8 @@ out:
             params[1].type = VIR_TYPED_PARAM_ULLONG;
             if (virStrcpyStatic(params[1].field, "vcpu_period") == NULL) {
                 qemuReportError(VIR_ERR_INTERNAL_ERROR,
-                                "%s",
- _("Field vcpu_period too long for destination"));
+                                _("Field name '%s' too long"),
+                                "vcpu_period");
                 goto cleanup;
             }
             saved_nparams++;
@@ -6999,8 +7009,8 @@ out:
             params[2].type = VIR_TYPED_PARAM_LLONG;
             if (virStrcpyStatic(params[2].field, "vcpu_quota") == NULL) {
                 qemuReportError(VIR_ERR_INTERNAL_ERROR,
-                                "%s",
- _("Field vcpu_quota too long for destination"));
+                                _("Field name '%s' too long"),
+                                "vcpu_quota");
                 goto cleanup;
             }
             saved_nparams++;
@@ -7215,8 +7225,9 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
         param = &params[tmp];
         if (virStrcpyStatic(param->field,
                             VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES) == NULL) {
-            qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Field write bytes too long for destination"));
+            qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                            _("Field name '%s' too long"),
+                            VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES);
             goto endjob;
         }
         param->type = VIR_TYPED_PARAM_LLONG;
@@ -7227,8 +7238,9 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
     if (tmp < *nparams && wr_req != -1) {
         if (virStrcpyStatic(param->field,
                             VIR_DOMAIN_BLOCK_STATS_WRITE_REQ) == NULL) {
-            qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Field write requests too long for destination"));
+            qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                            _("Field name '%s' too long"),
+                            VIR_DOMAIN_BLOCK_STATS_WRITE_REQ);
             goto endjob;
         }
         param->type = VIR_TYPED_PARAM_LLONG;
@@ -7239,8 +7251,9 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
     if (tmp < *nparams && rd_bytes != -1) {
         if (virStrcpyStatic(param->field,
                             VIR_DOMAIN_BLOCK_STATS_READ_BYTES) == NULL) {
-            qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Field read bytes too long for destination"));
+            qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                            _("Field name '%s' too long"),
+                            VIR_DOMAIN_BLOCK_STATS_READ_BYTES);
             goto endjob;
         }
         param->type = VIR_TYPED_PARAM_LLONG;
@@ -7251,8 +7264,9 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
     if (tmp < *nparams && rd_req != -1) {
         if (virStrcpyStatic(param->field,
                             VIR_DOMAIN_BLOCK_STATS_READ_REQ) == NULL) {
-            qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Field read requests too long for destination"));
+            qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                            _("Field name '%s' too long"),
+                            VIR_DOMAIN_BLOCK_STATS_READ_REQ);
             goto endjob;
         }
         param->type = VIR_TYPED_PARAM_LLONG;
@@ -7263,8 +7277,9 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
     if (tmp < *nparams && flush_req != -1) {
         if (virStrcpyStatic(param->field,
                             VIR_DOMAIN_BLOCK_STATS_FLUSH_REQ) == NULL) {
-            qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Field flush requests too long for destination"));
+            qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                            _("Field name '%s' too long"),
+                            VIR_DOMAIN_BLOCK_STATS_FLUSH_REQ);
             goto endjob;
         }
         param->type = VIR_TYPED_PARAM_LLONG;
@@ -7275,8 +7290,9 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
     if (tmp < *nparams && wr_total_times != -1) {
         if (virStrcpyStatic(param->field,
VIR_DOMAIN_BLOCK_STATS_WRITE_TOTAL_TIMES) == NULL) {
-            qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Field write total times too long for destination"));
+            qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                            _("Field name '%s' too long"),
+                            VIR_DOMAIN_BLOCK_STATS_WRITE_TOTAL_TIMES);
             goto endjob;
         }
         param->type = VIR_TYPED_PARAM_LLONG;
@@ -7287,8 +7303,9 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
     if (tmp < *nparams && rd_total_times != -1) {
         if (virStrcpyStatic(param->field,
VIR_DOMAIN_BLOCK_STATS_READ_TOTAL_TIMES) == NULL) {
-            qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Field read total times too long for destination"));
+            qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                            _("Field name '%s' too long"),
+                            VIR_DOMAIN_BLOCK_STATS_READ_TOTAL_TIMES);
             goto endjob;
         }
         param->type = VIR_TYPED_PARAM_LLONG;
@@ -7299,8 +7316,9 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
     if (tmp < *nparams && flush_total_times != -1) {
         if (virStrcpyStatic(param->field,
VIR_DOMAIN_BLOCK_STATS_READ_TOTAL_TIMES) == NULL) {
-            qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Field flush total times too long for destination"));
+            qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                            _("Field name '%s' too long"),
+                            VIR_DOMAIN_BLOCK_STATS_READ_TOTAL_TIMES);
             goto endjob;
         }
         param->type = VIR_TYPED_PARAM_LLONG;

--
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]