[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libvir] [PATCH] virsh NUMA command freecell



  Useful for testing the virNodeGetCellsFreeMemory() call, it requires the
3 precedent NUMA patches. The patch lack the documentation update.
The function takes an optional argument which is the cell number.
If no cell is provided it will print the total free memory available 
on the Node. A more useful function would be to find the cell with the
most available memory, but that one should still be useful and not just
for testing.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libxen/src/virsh.c,v
retrieving revision 1.101
diff -u -p -r1.101 virsh.c
--- src/virsh.c	29 Aug 2007 07:47:09 -0000	1.101
+++ src/virsh.c	26 Sep 2007 13:05:01 -0000
@@ -1562,6 +1562,48 @@ cmdDominfo(vshControl * ctl, vshCmd * cm
 }
 
 /*
+ * "freecell" command
+ */
+static vshCmdInfo info_freecell[] = {
+    {"syntax", "freecell [<cellno>]"},
+    {"help", gettext_noop("NUMA free memory")},
+    {"desc", gettext_noop("display available free memory for the NUMA cell.")},
+    {NULL, NULL}
+};
+
+static vshCmdOptDef opts_freecell[] = {
+    {"cellno", VSH_OT_DATA, 0, gettext_noop("NUMA cell number")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdFreecell(vshControl * ctl, vshCmd * cmd)
+{
+    int ret;
+    int cell, cell_given;
+    long long memory;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+
+    cell = vshCommandOptInt(cmd, "cellno", &cell_given);
+    if (!cell_given) {
+        cell = -1;
+    }
+
+    ret = virNodeGetCellsFreeMemory(ctl->conn, &memory, cell, 1);
+    if (ret != 1)
+        return FALSE;
+    
+    if (cell == -1)
+	vshPrint(ctl, "%s: %lli kB\n", _("Total"), memory);
+    else
+	vshPrint(ctl, "%d: %lli kB\n", cell, memory);
+
+    return TRUE;
+}
+
+/*
  * "vcpuinfo" command
  */
 static vshCmdInfo info_vcpuinfo[] = {
@@ -3661,6 +3703,7 @@ static vshCmdDef commands[] = {
     {"domblkstat", cmdDomblkstat, opts_domblkstat, info_domblkstat},
     {"domifstat", cmdDomIfstat, opts_domifstat, info_domifstat},
     {"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml},
+    {"freecell", cmdFreecell, opts_freecell, info_freecell},
     {"hostname", cmdHostname, NULL, info_hostname},
     {"list", cmdList, opts_list, info_list},
     {"migrate", cmdMigrate, opts_migrate, info_migrate},

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]