diff -r 22ccddf93c40 tools/libxc/xc.h --- a/tools/libxc/xc.h Mon Jul 4 08:21:35 2005 +++ b/tools/libxc/xc.h Mon Jul 4 23:50:33 2005 @@ -4,6 +4,7 @@ * A library for low-level access to the Xen control interfaces. * * Copyright (c) 2003-2004, K A Fraser. + * Copyright (c) 2005, Nguyen Anh Quynh */ #ifndef __XC_H__ @@ -26,6 +27,7 @@ #include #include #include +#include /* * DEFINITIONS FOR CPU BARRIERS @@ -506,4 +508,22 @@ /* Execute a privileged dom0 operation. */ int xc_dom0_op(int xc_handle, dom0_op_t *op); +/* These structs are for libxc to get xen version and extra stuffs. */ +typedef xen_compile_info_t xc_xen_compile_info_t; +typedef xen_extraversion_t xc_xen_extraversion_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_xen_extraversion_t extraversion); + +/** + * Get xen compile info + * + * @return 0 on success, -1 on failure. + */ +int xc_xen_compile_info(int xc_handle, xc_xen_compile_info_t *version); + #endif /* __XC_H__ */ diff -r 22ccddf93c40 tools/libxc/xc_misc.c --- a/tools/libxc/xc_misc.c Mon Jul 4 08:21:35 2005 +++ b/tools/libxc/xc_misc.c Mon Jul 4 23:50:33 2005 @@ -130,3 +130,43 @@ return rc; } + +long xc_xen_version(int xc_handle, xc_xen_extraversion_t extraversion) +{ + long ret; + privcmd_hypercall_t hypercall; + + hypercall.op = __HYPERVISOR_xen_version; + hypercall.arg[0] = XENVER_version; + ret = do_xen_hypercall(xc_handle, &hypercall); + + hypercall.arg[0] = XENVER_extraversion; + hypercall.arg[1] = (unsigned long)extraversion; + + if (do_xen_hypercall(xc_handle, &hypercall) < 0) + { + if (errno == EACCES) + PERROR("Could not obtain xen version"); + return -1; + } + + return ret; +} + +int xc_xen_compile_info(int xc_handle, xc_xen_compile_info_t *info) +{ + privcmd_hypercall_t hypercall; + + hypercall.op = __HYPERVISOR_xen_version; + hypercall.arg[0] = XENVER_compile_info; + hypercall.arg[1] = (unsigned long)info; + + if (do_xen_hypercall(xc_handle, &hypercall) < 0) + { + if (errno == EACCES) + PERROR("Could not obtain xen compile information"); + return -1; + } + + return 0; +} diff -r 22ccddf93c40 tools/python/xen/lowlevel/xc/xc.c --- a/tools/python/xen/lowlevel/xc/xc.c Mon Jul 4 08:21:35 2005 +++ b/tools/python/xen/lowlevel/xc/xc.c Mon Jul 4 23:50:33 2005 @@ -2,6 +2,7 @@ * Xc.c * * Copyright (c) 2003-2004, K A Fraser (University of Cambridge) + * Copyright (c) 2005, Nguyen Anh Quynh */ #include @@ -686,9 +687,11 @@ if ( xc_physinfo(xc->xc_handle, &info) != 0 ) return PyErr_SetFromErrno(xc_error); - return Py_BuildValue("{s:i,s:i,s:l,s:l,s:l}", + return Py_BuildValue("{s:i,s:i,s:i,s:i,s:l,s:l,s:l}", "ht_per_core", info.ht_per_core, "cores", info.cores, + "sockets", info.sockets, + "nodes", info.nodes, "total_pages", info.total_pages, "free_pages", info.free_pages, "cpu_khz", info.cpu_khz); @@ -806,6 +809,45 @@ return zero; } +static PyObject *pyxc_xen_version(PyObject *self, + PyObject *args, + PyObject *kwds) +{ + xc_xen_extraversion_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}", + "version", ret >> 16, + "subversion", ret & 0xFFFF, + "extraversion", v); +} + +static PyObject *pyxc_xen_compile_info(PyObject *self, + PyObject *args, + PyObject *kwds) +{ + xc_xen_compile_info_t v; + XcObject *xc = (XcObject *)self; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + + if (xc_xen_compile_info(xc->xc_handle, &v) == -1) + return PyErr_SetFromErrno(xc_error); + + return Py_BuildValue("{s:s,s:s,s:s,s:s}", + "compile_by", v.compile_by, + "compile_domain", v.compile_domain, + "compiler", v.compiler, + "compile_date", v.compile_date); +} static PyMethodDef pyxc_methods[] = { { "handle", @@ -1081,6 +1123,18 @@ " 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 extraversion on success; empty list on error.\n" }, + + { "xen_compile_info", + (PyCFunction)pyxc_xen_compile_info, + METH_KEYWORDS, "\n" + "Get Xen compile information\n" + "Returns: [dict] xen compile information on success; empty list on error.\n" }, + { NULL, NULL, 0, NULL } }; diff -r 22ccddf93c40 tools/python/xen/xend/XendNode.py --- a/tools/python/xen/xend/XendNode.py Mon Jul 4 08:21:35 2005 +++ b/tools/python/xen/xend/XendNode.py Mon Jul 4 23:50:33 2005 @@ -35,15 +35,24 @@ def nodeinfo(self): (sys, host, rel, ver, mch) = os.uname() + xen_ver = self.xc.xen_version() + xen_info = self.xc.xen_compile_info() 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_info['compile_by'], xen_info['compile_domain'])], + ['xen_compiler', xen_info['compiler']], + ['xen_compile_date', xen_info['compile_date']], + ['dom0_release', rel], + ['dom0_version', ver], ['machine', mch]] def physinfo(self): pinfo = self.xc.physinfo() - info = [['cores', pinfo['cores']], + info = [['logical_cpus', pinfo['nodes'] * pinfo['sockets'] * pinfo['cores'] * pinfo['ht_per_core']], + ['nodes', pinfo['nodes']], + ['sockets_per_node', pinfo['sockets']], + ['cores_per_socket', pinfo['cores']], ['hyperthreads_per_core', pinfo['ht_per_core']], ['cpu_mhz', pinfo['cpu_khz']/1000], ['memory', pinfo['total_pages']/256],