]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
* include/libvir.h src/libvir.c src/virsh.c: adding the extraction
authorDaniel Veillard <veillard@redhat.com>
Tue, 6 Dec 2005 16:12:49 +0000 (16:12 +0000)
committerDaniel Veillard <veillard@redhat.com>
Tue, 6 Dec 2005 16:12:49 +0000 (16:12 +0000)
  of the number of virtual CPUs for both interfaces.
Daniel

ChangeLog
include/libvir.h
src/libvir.c
src/virsh.c

index c03566953e778f5a96ca6f0fa06321f30bb3fc29..00a140c75f44d34642d1571cae02700c9c4caa90 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Dec  6 17:12:52 CET 2005 Daniel Veillard <veillard@redhat.com>
+
+       * include/libvir.h src/libvir.c src/virsh.c: adding the extraction
+         of the number of virtual CPUs for both interfaces.
+
 Tue Dec  6 14:46:50 CET 2005 Daniel Veillard <veillard@redhat.com>
 
        * include/libvir.h src/libvir.c src/virsh.c: tweaking of the 
index 1105cf76563b19a751002eec1c70d3d18190ea7a..ed8a738d94b8a9592f01b7d28b310590b7c76b3b 100644 (file)
@@ -70,9 +70,10 @@ typedef enum {
 typedef struct _virDomainInfo virDomainInfo;
 
 struct _virDomainInfo {
-    unsigned char state;       /* the running state, a virDomainFlags */
-    unsigned long maxMem;      /* the maximum number of bytes allowed */
-    unsigned long memory;      /* the number of bytes used by the domain */
+    unsigned char state;       /* the running state, one of virDomainFlags */
+    unsigned long maxMem;      /* the maximum memory in bytes allowed */
+    unsigned long memory;      /* the memory in bytes used by the domain */
+    unsigned short nrVirtCpu;  /* the number of virtual CPUs for the domain */
 
     /*
      * Informations below are only available to clients with a connection
index 07afe836332dd81466b55d8c4968ce32e65cb244..27265c8c6a1735f78ed5893545109db0ba9ed736 100644 (file)
@@ -298,6 +298,8 @@ virDomainLookupByName(virConnectPtr conn, const char *name) {
     return(NULL);
 }
 
+#if 0
+/* Not used ATM */
 /**
  * virConnectDoStoreQuery:
  * @conn: pointer to the hypervisor connection
@@ -319,6 +321,34 @@ virConnectDoStoreQuery(virConnectPtr conn, const char *path) {
 
     ret = xs_read(conn->xshandle, t, path, &len);
 
+done:
+    if (t != NULL)
+       xs_transaction_end(conn->xshandle, t, 0);
+    return(ret);
+}
+#endif
+
+/**
+ * virConnectDoStoreList:
+ * @conn: pointer to the hypervisor connection
+ * @path: the absolute path of the directory in the store to list
+ * @nb: OUT pointer to the number of items found
+ *
+ * Internal API querying the Xenstore for a list
+ *
+ * Returns a string which must be freed by the caller or NULL in case of error
+ */
+static char **
+virConnectDoStoreList(virConnectPtr conn, const char *path, unsigned int *nb) {
+    struct xs_transaction_handle* t;
+    char **ret = NULL;
+
+    t = xs_transaction_start(conn->xshandle);
+    if (t == NULL)
+        goto done;
+
+    ret = xs_directory(conn->xshandle, t, path, nb);
+
 done:
     if (t != NULL)
        xs_transaction_end(conn->xshandle, t, 0);
@@ -542,7 +572,9 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) {
        return(-1);
     memset(info, 0, sizeof(virDomainInfo));
     if (domain->conn->flags & VIR_CONNECT_RO) {
-        char *tmp;
+        char *tmp, **tmp2;
+       unsigned int nb_vcpus;
+       char request[200];
 
        tmp = virDomainDoStoreQuery(domain, "running");
        if (tmp != NULL) {
@@ -561,6 +593,8 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) {
            info->memory = 0;
            info->maxMem = 0;
        }
+#if 0
+        /* doesn't seems to work */
        tmp = virDomainDoStoreQuery(domain, "cpu_time");
        if (tmp != NULL) {
            info->cpuTime = atol(tmp);
@@ -568,6 +602,15 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) {
        } else {
            info->cpuTime = 0;
        }
+#endif
+        snprintf(request, 199, "/local/domain/%d/cpu", domain->handle);
+       request[199] = 0;
+       tmp2 = virConnectDoStoreList(domain->conn, request, &nb_vcpus);
+       if (tmp2 != NULL) {
+           info->nrVirtCpu = nb_vcpus;
+           free(tmp2);
+       }
+
     } else {
         xc_domaininfo_t dominfo;
 
@@ -604,6 +647,7 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) {
        info->cpuTime = dominfo.cpu_time;
        info->memory = dominfo.tot_pages * 4096;
        info->maxMem = dominfo.max_pages * 4096;
+       info->nrVirtCpu = dominfo.nr_online_vcpus;
     }
     return(0);
 }
index 6c9705f1c575a992fdfb53851f16c349153b9cf3..f1d17553f280582cb61a63e4e3de39462d21ed2c 100644 (file)
@@ -48,11 +48,12 @@ static void printDomain(virDomainPtr dom) {
            default:
                break;
        }
+       printf("%d vCPU, ", info.nrVirtCpu);
        if (info.cpuTime != 0) {
            float cpuUsed = info.cpuTime;
 
            cpuUsed /= 1000000000;
-           printf("%.1f s CPU time, ", cpuUsed);
+           printf("%.1fs time, ", cpuUsed);
        }
        mem = info.memory;
        mem /= 1024 * 1024;