Skip to contentSkip to conversation

xm --version

PATCH New aq 1 participant 1 message Jun 6, 2005 Arm/actions semi architecture

lore
Share & tools
lore

aq

author
#0 lore raw

PATCH 1/1 xm --version

This patch adds to xm a long-missing function: showing xen version and few extra information (thanks go to Keir and Mark for some suggestions). Here is the ouput of "xm info" after applying the patch (against -unstable [email protected]):

---
#xm info
system : Linux
host : ubuntu
xen_release : 3.0-devel
xen_compile_by : root@localdomain
xen_compiler : gcc version 3.3.5 (Debian 1:3.3.5-8ubuntu2)
xen_compile_date : Mon Jun 6 00:30:22 EST 2005
dom0_release : 2.6.11.10-xen0
dom0_version : #3 Mon Jun 6 00:32:05 EST 2005
machine : i686
cores : 1
hyperthreads_per_core : 1
cpu_mhz : 1094
memory : 511
free_memory : 122
----

You get the point. And here is what the patch does:

- extend xen_version hypercall. the new hypercall keeps the old behavior if executing it with 0 as its parameter. But if give it the address of version_op_t structure (see version.h in the patch), it returns extra stuffs like xen_extraversion, compile date, compiler, etc...
- libxc now has a new function to get xen version (and stuffs):
xc_xen_version()
- extend python wrapper for xc_xen_version() and use it in XendNode.py to get xen version and stuffs.

Any comment?

# diffstat xminfo2.patch 
 tools/libxc/xc.h                  |   11 +++++++++++
 tools/libxc/xc_misc.c             |   18 ++++++++++++++++++
 tools/python/xen/lowlevel/xc/xc.c |   29 +++++++++++++++++++++++++++++
 tools/python/xen/xend/XendNode.py |   12 ++++++++----
 xen/common/kernel.c               |   22 ++++++++++++++++++----
 xen/include/public/version.h      |   22 ++++++++++++++++++++++
 6 files changed, 106 insertions(+), 8 deletions(-)
tools/libxc/xc.h +11 -0
diff -Nurp -X dontdiff.xen xeno-today/tools/libxc/xc.h xeno.0606/tools/libxc/xc.h
@@ -25,6 +25,7 @@ typedef int64_t            s64;
 #include <xen/dom0_ops.h>
 #include <xen/event_channel.h>
 #include <xen/sched_ctl.h>
+#include <xen/version.h>
 
 /*
  *  DEFINITIONS FOR CPU BARRIERS
@@ -505,4 +506,14 @@ long xc_get_tot_pages(int xc_handle, u32
 /* Execute a privileged dom0 operation. */
 int xc_dom0_op(int xc_handle, dom0_op_t *op);
 
+/* This struct is for libxc to get xen version and extra stuffs. */ 
+typedef version_op_t xc_version_t;
+
+/**
+ * Get xen version 
+ *
+ * @return a long value which encodes XEN_VERSION and XEN_SUBVERSION on success, -1 on failure.
+ */
+long xc_xen_version(int xc_handle, xc_version_t *version); 
+ 
 #endif /* __XC_H__ */
tools/libxc/xc_misc.c +18 -0
diff -Nurp -X dontdiff.xen xeno-today/tools/libxc/xc_misc.c xeno.0606/tools/libxc/xc_misc.c
@@ -130,3 +130,21 @@ int xc_msr_write(int xc_handle, int cpu_
     
     return rc;
 }
+
+long xc_xen_version(int xc_handle, xc_version_t *v)
+{
+    long ret;
+    privcmd_hypercall_t hypercall;
+
+    hypercall.op = __HYPERVISOR_xen_version;
+    hypercall.arg[0] = (unsigned long)v;
+
+    if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0)
+    {
+        if (errno == EACCES)
+            PERROR("Could not obtain xen version");
+        return -1;
+    }
+
+    return ret;
+}
tools/python/xen/lowlevel/xc/xc.c +29 -0
diff -Nurp -X dontdiff.xen xeno-today/tools/python/xen/lowlevel/xc/xc.c xeno.0606/tools/python/xen/lowlevel/xc/xc.c
@@ -827,6 +827,29 @@ static PyObject *pyxc_domain_memory_incr
     return zero;
 }
 
+static PyObject *pyxc_xen_version(PyObject *self,
+                                    PyObject *args,
+                                    PyObject *kwds)
+{
+    xc_version_t v;
+    long ret;
+    XcObject *xc = (XcObject *)self;
+
+    if (!PyArg_ParseTuple(args, ""))
+        return NULL;
+    
+    if ((ret = xc_xen_version(xc->xc_handle, &v)) == -1)
+        return PyErr_SetFromErrno(xc_error);
+
+    return Py_BuildValue("{s:i,s:i,s:s,s:s,s:s,s:s,s:s}", 
+                         "version", ret >> 16, 
+                         "subversion", ret & 0xFFFF,
+                         "extraversion", v.extraversion,
+                         "compile_by", v.compile_by,
+                         "compile_domain", v.compile_domain,
+                         "compiler", v.compiler,
+                         "compile_date", v.compile_date);
+}
 
 static PyMethodDef pyxc_methods[] = {
     { "handle",
@@ -1110,6 +1133,12 @@ static PyMethodDef pyxc_methods[] = {
       " mem_kb [long]: .\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
+    { "xen_version", 
+      (PyCFunction)pyxc_xen_version, 
+       METH_KEYWORDS, "\n"
+      "Get Xen version\n"
+      "Returns: [dict] xen version and extra stuffs on success; empty list on error.\n" },
+
     { NULL, NULL, 0, NULL }
 };
 
tools/python/xen/xend/XendNode.py +8 -4
diff -Nurp -X dontdiff.xen xeno-today/tools/python/xen/xend/XendNode.py xeno.0606/tools/python/xen/xend/XendNode.py
@@ -35,10 +35,15 @@ class XendNode:
 
     def nodeinfo(self):
         (sys, host, rel, ver, mch) = os.uname()
+        xen_ver = self.xc.xen_version()
         return [['system',  sys],
-                ['host',    host],
-                ['release', rel],
-                ['version', ver],
+                ['host', host],
+                ['xen_release', "%i.%i%s" %(xen_ver['version'], xen_ver['subversion'], xen_ver['extraversion'])],
+                ['xen_compile_by', "%s@%s" %(xen_ver['compile_by'], xen_ver['compile_domain'])],
+                ['xen_compiler', xen_ver['compiler']],
+                ['xen_compile_date', xen_ver['compile_date']],
+                ['dom0_release', rel],
+                ['dom0_version', ver],
                 ['machine', mch]]
 
     def physinfo(self):
@@ -50,7 +55,6 @@ class XendNode:
                 ['free_memory', pinfo['free_pages']/256]]
         return info
         
-        
 
 def instance():
     global inst
xen/common/kernel.c +18 -4
diff -Nurp -X dontdiff.xen xeno-today/xen/common/kernel.c xeno.0606/xen/common/kernel.c
@@ -15,6 +15,9 @@
 #include <xen/sched.h>
 #include <asm/current.h>
 
+#include <public/version.h>
+#include <xen/string.h>
+
 void cmdline_parse(char *cmdline)
 {
     char opt[100], *optval, *p = cmdline, *q;
@@ -83,11 +86,22 @@ void cmdline_parse(char *cmdline)
  * Simple hypercalls.
  */
 
-long do_xen_version(int cmd)
+long do_xen_version(version_op_t *op)
 {
-    if ( cmd != 0 )
-        return -ENOSYS;
-    return (XEN_VERSION<<16) | (XEN_SUBVERSION);
+    version_op_t vop;
+    if (op != NULL)  /* return extra stuffs */ 
+    {
+        if (copy_from_user(&vop, op, sizeof(vop)) != 0)
+            return -EFAULT;
+        strncpy(vop.extraversion, XEN_EXTRAVERSION, sizeof(vop.extraversion));
+        strncpy(vop.compile_by, XEN_COMPILE_BY, sizeof(vop.compile_by));
+        strncpy(vop.compile_domain, XEN_COMPILE_DOMAIN, sizeof(vop.compile_domain));
+        strncpy(vop.compiler, XEN_COMPILER, sizeof(vop.compiler));
+        strncpy(vop.compile_date, XEN_COMPILE_DATE, sizeof(vop.compile_date));
+        if (copy_to_user(op, &vop, sizeof(vop)) != 0)
+            return -EFAULT;
+    }
+    return (XEN_VERSION<<16) | (XEN_SUBVERSION); /* always return version & subversion */ 
 }
 
 long do_vm_assist(unsigned int cmd, unsigned int type)
xen/include/public/version.h +22 -0
diff -Nurp -X dontdiff.xen xeno-today/xen/include/public/version.h xeno.0606/xen/include/public/version.h
@@ -0,0 +1,22 @@
+/******************************************************************************
+ * version.h
+ * 
+ * Xen extraversion and stuffs.
+ * 
+ * Copyright (c) 2005, Nguyen Anh Quynh <[email protected]>
+ */
+
+#ifndef __XEN_PUBLIC_VERSION_H__
+#define __XEN_PUBLIC_VERSION_H__
+
+/* This struct is for xen hypercall only. Usually you dont need it. */ 
+typedef struct _version_op_st 
+{
+    char extraversion[8];           /*  0 */
+    char compile_by[16];            /*  8 */
+    char compile_domain[32];        /* 24 */
+    char compiler[64];              /* 56 */
+    char compile_date[32];          /* 120 */
+} PACKED version_op_t;  /* 152 bytes */
+
+#endif /* __XEN_PUBLIC_VERSION_H__ */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel