]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
* configure.in: activate pedantic flags
authorDaniel Veillard <veillard@redhat.com>
Thu, 8 Dec 2005 13:26:52 +0000 (13:26 +0000)
committerDaniel Veillard <veillard@redhat.com>
Thu, 8 Dec 2005 13:26:52 +0000 (13:26 +0000)
* src/libvir.c src/libvir_sym.version src/xen_internal.[ch]
  include/libvir.h: implementing hypervisor Version and Type interfaces
* src/virsh.c: adding a version command, WIP
Daniel

ChangeLog
configure.in
include/libvir.h
src/libvir.c
src/libvir_sym.version
src/virsh.c
src/xen_internal.c
src/xen_internal.h

index b80ef0b113fe3f564bd379b4ae9825e1ee7342b5..8cc8e4bab96f28d209047f45d73657aa6d189b3e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,12 @@
+Thu Dec  8 14:25:09 CET 2005 Daniel Veillard <veillard@redhat.com>
+
+       * configure.in: activate pedantic flags
+       * src/libvir.c src/libvir_sym.version src/xen_internal.[ch]
+         include/libvir.h: implementing hypervisor Version and Type interfaces
+       * src/virsh.c: adding a version command, WIP
+
 Thu Dec  8 11:19:48 CET 2005 Karel Zak <kzak@redhat.com>
+
        * src/Makefile.am src/virsh.c configure.in: adding readline support,
          and implement basic commands to virsh.
 
index 78148e0abec518482b0794b071a7211f9ac871f4..d735b1b85cfef478081216e34fc8c586594373e6 100644 (file)
@@ -65,15 +65,19 @@ dnl
 dnl specific tests to setup DV devel environments with debug etc ...
 dnl
 if [[ "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/libvir" ]] ; then
-    if test "${GCC}" = "yes" ; then
-       CFLAGS="-g -O -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wall"
-    fi
     STATIC_BINARIES="-static"
 else
     STATIC_BINARIES=
 fi
 AC_SUBST(STATIC_BINARIES)
 
+dnl
+dnl make CFLAGS very pedantic at least during the devel phase for everybody
+dnl
+    if test "${GCC}" = "yes" ; then
+       CFLAGS="-g -O -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wall"
+    fi
+
 dnl search for the low level Xen library
 AC_SEARCH_LIBS(xs_read, [xenstore], [], [AC_MSG_ERROR([Xen store library not found])])
 
index 86d0e60875a3c7a8a3f111a9f3152c45bcb25efb..581d57ed1fa4a22abd0f19de8e9dc684a5d0a1c3 100644 (file)
@@ -115,6 +115,7 @@ typedef enum {
 virConnectPtr          virConnectOpen          (const char *name);
 virConnectPtr          virConnectOpenReadOnly  (const char *name);
 int                    virConnectClose         (virConnectPtr conn);
+const char *           virConnectGetType       (virConnectPtr conn);
 unsigned long          virConnectGetVersion    (virConnectPtr conn);
 
 /*
index 52c82fbcd70d0b3efbfd55ff46d8b5a661880a57..5bfca607de02b5abfa37b6e6cc123a4c8aafe04b 100644 (file)
@@ -193,20 +193,47 @@ virConnectClose(virConnectPtr conn) {
     return(0);
 }
 
+/**
+ * virConnectGetType:
+ * @conn: pointer to the hypervisor connection
+ *
+ * Get the name of the Hypervisor software used.
+ *
+ * Returns NULL in case of error, a static zero terminated string otherwise.
+ */
+const char *
+virConnectGetType(virConnectPtr conn) {
+    if (conn == NULL)
+        return(NULL);
+    
+    return("Xen");
+}
+
 /**
  * virConnectGetVersion:
  * @conn: pointer to the hypervisor connection
  *
- * Get the version level of the Hypervisor running.
+ * Get the version level of the Hypervisor running. This may work only with 
+ * hypervisor call, i.e. with priviledged access to the hypervisor, not
+ * with a Read-Only connection.
  *
- * Returns -1 in case of error or major * 10,000 + minor * 100 + rev otherwise
+ * Returns -1 in case of error, 0 if the version can't be extracted by lack
+ *    of capacities otherwise major * 1,000,000 + minor * 1,000 + release
  */
 unsigned long
 virConnectGetVersion(virConnectPtr conn) {
+    unsigned long ver, ret;
+
     if (conn == NULL)
         return(-1);
-    TODO
-    return(-1);
+    
+    /* this can't be extracted from the Xenstore */
+    if (conn->handle < 0)
+        return(0);
+
+    ver = xenHypervisorGetVersion(conn->handle);
+    ret = (ver >> 16) * 1000000 + (ver & 0xFFFF) * 1000;
+    return(ret);
 }
 
 /**
index fb312815f2c057070a4a3d9ef29e3fb6352537f2..7fa7d7c3bd56362dd3a72ab464a5905c3013fee6 100644 (file)
@@ -12,6 +12,7 @@
        virDomainGetInfo;
        virDomainGetMaxMemory;
        virDomainGetName;
+       virConnectGetType;
        virDomainLookupByID;
        virDomainLookupByName;
        virDomainResume;
index 0ea7721aff3ca9a13511904783eedab364e39b8f..a9659a6eaac25e4457d932f062a35082464d7ca0 100644 (file)
@@ -191,6 +191,7 @@ static vshCmdInfo info_help[] = {
     { "syntax",   "help [<command>]" },
     { "help",     "print help" },
     { "desc",     "Prints global help or command specific help." },
+    { "version",  "Prints versionning informations." },
     { NULL, NULL }
 };
 
@@ -490,6 +491,55 @@ cmdIdof(vshControl *ctl, vshCmd *cmd) {
     return TRUE;
 }
 
+/*
+ * "version" command
+ */
+static vshCmdInfo info_version[] = {
+    { "syntax",   "version" },
+    { "help",     "show versions" },
+    { "desc",     "Display the version informations available" },
+    { NULL, NULL }
+};
+
+
+static int
+cmdVersion(vshControl *ctl, vshCmd *cmd) {
+    unsigned long hvVersion;
+    const char *hvType;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+    
+    hvType = virConnectGetType(ctl->conn);
+    if (hvType == NULL) {
+        vshError(ctl, FALSE, "Failed to get hypervisor type\n");
+        return FALSE;
+    }
+
+    hvVersion =  virConnectGetVersion(ctl->conn);
+    if (hvVersion < 0) {
+        vshError(ctl, FALSE, "failed get hypervisor version");
+        return FALSE;
+    }
+    if (hvVersion == 0) {
+        vshPrint(ctl, VSH_MESG,
+                 "Cannot extract running %s hypervisor version\n",
+                 hvType);
+    } else {
+        unsigned int major = hvVersion / 1000000;
+        unsigned int minor;
+        unsigned int rel;
+
+        hvVersion %= 1000000;
+        minor = hvVersion / 1000000;
+        rel = hvVersion % 1000000;
+
+        vshPrint(ctl, VSH_MESG, "Running hypervisor: %s %d.%d.%d\n", hvType,
+                 major, minor, rel);
+    }
+    return TRUE;
+}
+
 /*
  * "quit" command
  */
@@ -516,6 +566,7 @@ static vshCmdDef commands[] = {
     { "idof",       cmdIdof,       opts_idof,      info_idof },
     { "list",       cmdList,       NULL,           info_list },
     { "nameof",     cmdNameof,     opts_nameof,    info_nameof },
+    { "version",    cmdVersion,    NULL,           info_version },
     { "quit",       cmdQuit,       NULL,           info_quit },
     { NULL, NULL, NULL, NULL }
 };
index 0eb49b6dda57a6bb8658e4060da9cdd9d50f664a..0119dac544cebcda38eb32af30b915ec322b2861 100644 (file)
@@ -19,6 +19,7 @@
 #include <sys/ioctl.h>
 
 #include <xen/dom0_ops.h>
+#include <xen/version.h>
 #include <xen/xen.h>
 
 #ifndef __LINUX_PUBLIC_PRIVCMD_H__
@@ -106,6 +107,36 @@ xenHypervisorDoOp(int handle, dom0_op_t *op) {
     return(0);
 }
 
+/**
+ * xenHypervisorGetVersion:
+ * @handle: the handle to the Xen hypervisor
+ *
+ * Call the hypervisor to extracts his own internal API version
+ *
+ * Returns the hypervisor running version or 0 in case of error.
+ */
+unsigned long
+xenHypervisorGetVersion(int handle) {
+    int ret;
+    unsigned int cmd;
+    hypercall_t hc;
+
+    hc.op = __HYPERVISOR_xen_version;
+    hc.arg[0] = (unsigned long) XENVER_version; 
+    hc.arg[1] = 0;
+
+    cmd = _IOC(_IOC_NONE, 'P', 0, sizeof(hc));
+    ret = ioctl(handle, cmd, (unsigned long) &hc);
+
+    if (ret < 0)
+        return(0);
+    /*
+     * use unsigned long in case the version grows behind expectations
+     * allowed by int
+     */
+    return((unsigned long) ret);
+}
+
 /**
  * xenHypervisorGetDomainInfo:
  * @handle: the handle to the Xen hypervisor
index f4bc39d215bfa09577ce1192c8319349cc24bd24..ac40a5f4b38750878e7cd5e02f8060dc267fa6ed 100644 (file)
@@ -11,7 +11,9 @@
 #ifndef __VIR_XEN_INTERNAL_H__
 #define __VIR_XEN_INTERNAL_H__
 
+/* required for uint8_t, uint32_t, etc ... */
 #include <stdint.h>
+/* required for dom0_getdomaininfo_t */
 #include <xen/dom0_ops.h>
 
 #ifdef __cplusplus
@@ -20,6 +22,7 @@ extern "C" {
 
 int            xenHypervisorOpen               (void);
 int            xenHypervisorClose              (int handle);
+unsigned long  xenHypervisorGetVersion         (int handle);
 int            xenHypervisorGetDomainInfo      (int handle,
                                                 int domain,
                                                 dom0_getdomaininfo_t *info);