[libvirt] [PATCH 03/12] [v7] virNodeGetCPUTime: Implement public API

Eric Blake eblake at redhat.com
Tue Jun 14 21:09:59 UTC 2011


On 06/14/2011 03:04 AM, Daniel P. Berrange wrote:
> On Tue, Jun 07, 2011 at 10:00:23AM +0900, Minoru Usui wrote:
>> virNodeGetCPUTime: Implement public API

>> + * @cpuNum: number of node cpu. (VIR_CPU_STATS_ALL_CPUS means total cpu 
>> + *          statistics)

Trailing whitespace; tsk-tsk.  'make syntax-check' caught it.

>>
>> + * Here is the sample code snippet:
>> + *
>> + * if ((virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, 0) == 0) &&
>> + *     (nparams != 0)) {
>> + *     params = vshMalloc(ctl, sizeof(virCPUStats) * nparams);
>> + *     memset(params, 0, sizeof(virCPUStats) * nparams);
>> + *     if (virNodeGetCPUStats(conn, cpuNum, params, &nparams, 0)) {
>> + *         vshError(ctl, "%s", _("Unable to get node cpu stats"));
>> + *         goto error;
>> + *     }
>> + * }
> 
> The example code should stick to using standard libc APIs for
> demonstration purposes, because applications developing against
> libvirt don't have use of vshMalloc or vshError. Just use normal
> malloc() and fprintf(stderr) here instead.

Copy and paste from a previous example, so I've fixed that, too.

> 
> 
>> + *
>> + * This function doesn't requires privileged access to the hypervisor.

s/requires/require/

> 
> ACK if the comment is changed.

Pushed with this squashed in (along with 2/12 unchanged):

diff --git i/src/libvirt.c w/src/libvirt.c
index ccb00cd..ace0120 100644
--- i/src/libvirt.c
+++ w/src/libvirt.c
@@ -3008,16 +3008,15 @@ error:
  * array, i.e. (sizeof(@virTypedParameter) * @nparams) bytes and call
the API
  * again.
  *
- * Here is the sample code snippet:
+ * Here is a sample code snippet:
  *
  * if ((virDomainGetMemoryParameters(dom, NULL, &nparams, 0) == 0) &&
  *     (nparams != 0)) {
- *     params = vshMalloc(ctl, sizeof(*params) * nparams);
+ *     if ((params = malloc(sizeof(*params) * nparams)) == NULL)
+ *         goto error;
  *     memset(params, 0, sizeof(*params) * nparams);
- *     if (virDomainGetMemoryParameters(dom, params, &nparams, 0)) {
- *         vshError(ctl, "%s", _("Unable to get memory parameters"));
+ *     if (virDomainGetMemoryParameters(dom, params, &nparams, 0))
  *         goto error;
- *     }
  * }
  *
  * This function requires privileged access to the hypervisor. This
function
@@ -5288,7 +5287,7 @@ error:
 /**
  * virNodeGetCPUStats:
  * @conn: pointer to the hypervisor connection.
- * @cpuNum: number of node cpu. (VIR_CPU_STATS_ALL_CPUS means total cpu
+ * @cpuNum: number of node cpu. (VIR_CPU_STATS_ALL_CPUS means total cpu
  *          statistics)
  * @params: pointer to node cpu time parameter objects
  * @nparams: number of node cpu time parameter (this value should be
same or
@@ -5307,19 +5306,18 @@ error:
  * array, i.e. (sizeof(@virCPUStats) * @nparams) bytes and call
  * the API again.
  *
- * Here is the sample code snippet:
+ * Here is a sample code snippet:
  *
  * if ((virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, 0) == 0) &&
  *     (nparams != 0)) {
- *     params = vshMalloc(ctl, sizeof(virCPUStats) * nparams);
+ *     if ((params = malloc(sizeof(virCPUStats) * nparams)) == NULL)
+ *         goto error;
  *     memset(params, 0, sizeof(virCPUStats) * nparams);
- *     if (virNodeGetCPUStats(conn, cpuNum, params, &nparams, 0)) {
- *         vshError(ctl, "%s", _("Unable to get node cpu stats"));
+ *     if (virNodeGetCPUStats(conn, cpuNum, params, &nparams, 0))
  *         goto error;
- *     }
  * }
  *
- * This function doesn't requires privileged access to the hypervisor.
+ * This function doesn't require privileged access to the hypervisor.
  * This function expects the caller to allocate the @params.
  *
  * CPU time Statistics:

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110614/f09436ad/attachment-0001.sig>


More information about the libvir-list mailing list