Index: src/xen_internal.c =================================================================== RCS file: /data/cvs/libxen/src/xen_internal.c,v retrieving revision 1.96 diff -u -p -r1.96 xen_internal.c --- src/xen_internal.c 29 Sep 2007 18:37:47 -0000 1.96 +++ src/xen_internal.c 22 Oct 2007 15:01:56 -0000 @@ -3035,24 +3035,27 @@ xenHypervisorNodeGetCellsFreeMemory(virC xen_op_v2_sys op_sys; int i, j, ret; xenUnifiedPrivatePtr priv; - static int nbNodeCells = -1; - virNodeInfo nodeInfo; + int nbNodeCells; + if (conn == NULL) { + virXenErrorFunc (VIR_ERR_INVALID_ARG, __FUNCTION__, + "invalid argument", 0); + return -1; + } - if (nbNodeCells == -1) { - if (xenDaemonNodeGetInfo(conn, &nodeInfo)) { - virXenErrorFunc (VIR_ERR_XEN_CALL, __FUNCTION__, - "cannot determine actual number of cells",0); - return -1; - } - nbNodeCells = nodeInfo.nodes; + nbNodeCells = xenNbCells(conn); + if (nbNodeCells < 0) { + virXenErrorFunc (VIR_ERR_XEN_CALL, __FUNCTION__, + "cannot determine actual number of cells",0); + return(-1); } - if ((conn == NULL) || (maxCells < 1) || (startCell >= nbNodeCells)) { + if ((maxCells < 1) || (startCell >= nbNodeCells)) { virXenErrorFunc (VIR_ERR_INVALID_ARG, __FUNCTION__, "invalid argument", 0); return -1; } + /* * Support only sys_interface_version >=4 */ Index: src/xen_unified.c =================================================================== RCS file: /data/cvs/libxen/src/xen_unified.c,v retrieving revision 1.24 diff -u -p -r1.24 xen_unified.c --- src/xen_unified.c 15 Oct 2007 21:38:56 -0000 1.24 +++ src/xen_unified.c 22 Oct 2007 15:01:56 -0000 @@ -37,6 +37,9 @@ #include "xs_internal.h" #include "xm_internal.h" +static int +xenUnifiedNodeGetInfo (virConnectPtr conn, virNodeInfoPtr info); + /* The five Xen drivers below us. */ static struct xenUnifiedDriver *drivers[XEN_UNIFIED_NR_DRIVERS] = { [XEN_UNIFIED_HYPERVISOR_OFFSET] = &xenHypervisorDriver, @@ -64,6 +67,62 @@ xenUnifiedError (virConnectPtr conn, vir errmsg, info, NULL, 0, 0, errmsg, info); } +/* + * Helper functions currently used in the NUMA code + * Those variables should not be accessed directly but through helper + * functions xenNbCells() and xenNbCpu() available to all Xen backends + */ +static int nbNodeCells = -1; +static int nbNodeCpus = -1; + +/** + * xenNumaInit: + * @conn: pointer to the hypervisor connection + * + * Initializer for previous variables. We currently assume that + * the number of physical CPU and the numebr of NUMA cell is fixed + * until reboot which might be false in future Xen implementations. + */ +static void +xenNumaInit(virConnectPtr conn) { + virNodeInfo nodeInfo; + int ret; + + ret = xenUnifiedNodeGetInfo(conn, &nodeInfo); + if (ret < 0) + return; + nbNodeCells = nodeInfo.nodes; + nbNodeCpus = nodeInfo.cpus; +} + +/** + * xenNbCells: + * @conn: pointer to the hypervisor connection + * + * Number of NUMa cells present in the actual Node + * + * Returns the number of NUMA cells available on that Node + */ +int xenNbCells(virConnectPtr conn) { + if (nbNodeCells < 0) + xenNumaInit(conn); + return(nbNodeCells); +} + +/** + * xenNbCpus: + * @conn: pointer to the hypervisor connection + * + * Number of NUMa cells present in the actual Node + * + * Returns the number of NUMA cells available on that Node + */ +int xenNbCpus(virConnectPtr conn) { + if (nbNodeCpus < 0) + xenNumaInit(conn); + return(nbNodeCpus); +} + /*----- Dispatch functions. -----*/ /* These dispatch functions follow the model used historically Index: src/xen_unified.h =================================================================== RCS file: /data/cvs/libxen/src/xen_unified.h,v retrieving revision 1.5 diff -u -p -r1.5 xen_unified.h --- src/xen_unified.h 6 Jul 2007 15:11:22 -0000 1.5 +++ src/xen_unified.h 22 Oct 2007 15:01:56 -0000 @@ -116,6 +116,9 @@ struct _xenUnifiedPrivate { typedef struct _xenUnifiedPrivate *xenUnifiedPrivatePtr; + +int xenNbCells(virConnectPtr conn); +int xenNbCpus(virConnectPtr conn); #ifdef __cplusplus } #endif