]> xenbits.xensource.com Git - libvirt.git/commitdiff
openvz: determine kb/pages only once
authorGuido Günther <agx@sigxcpu.org>
Mon, 7 May 2012 21:00:28 +0000 (23:00 +0200)
committerGuido Günther <agx@sigxcpu.org>
Tue, 15 May 2012 12:39:14 +0000 (14:39 +0200)
to save some syscalls (as suggested by Eric Blake)

src/Makefile.am
src/openvz/openvz_conf.c
src/openvz/openvz_driver.c
src/openvz/openvz_util.c [new file with mode: 0644]
src/openvz/openvz_util.h [new file with mode: 0644]

index 0dadc2985b528f0cbd1675a24a159b78e07995f7..2ecd18873ee96e7ec1aae5c7b75bbd439dbb98a2 100644 (file)
@@ -353,7 +353,8 @@ PHYP_DRIVER_SOURCES =                                               \
 
 OPENVZ_DRIVER_SOURCES =                                                \
                openvz/openvz_conf.c openvz/openvz_conf.h       \
-               openvz/openvz_driver.c openvz/openvz_driver.h
+               openvz/openvz_driver.c openvz/openvz_driver.h   \
+               openvz/openvz_util.c openvz/openvz_util.h
 
 VMWARE_DRIVER_SOURCES =                                                \
                vmware/vmware_driver.c vmware/vmware_driver.h   \
index 38068352fa7ae9faedbe018200fed032bd7c5738..5f107edce000c69562d65a0cf880b680ed692379 100644 (file)
@@ -45,6 +45,7 @@
 
 #include "virterror_internal.h"
 #include "openvz_conf.h"
+#include "openvz_util.h"
 #include "uuid.h"
 #include "buf.h"
 #include "memory.h"
@@ -470,16 +471,11 @@ openvzReadMemConf(virDomainDefPtr def, int veid)
     char *temp = NULL;
     unsigned long long barrier, limit;
     const char *param;
-    unsigned long kb_per_pages;
+    long kb_per_pages;
 
-    kb_per_pages = sysconf(_SC_PAGESIZE);
-    if (kb_per_pages > 0) {
-        kb_per_pages /= 1024;
-    } else {
-        openvzError(VIR_ERR_INTERNAL_ERROR,
-                    _("Can't determine page size"));
+    kb_per_pages = openvzKBPerPages();
+    if (kb_per_pages < 0)
         goto error;
-    }
 
     /* Memory allocation guarantee */
     param = "VMGUARPAGES";
index dafb57d0213aa23752f1b873b302480ac6365e15..c6d25d785026cede4ac0245df0d1f70fd121b9ff 100644 (file)
@@ -48,6 +48,7 @@
 #include "virterror_internal.h"
 #include "datatypes.h"
 #include "openvz_driver.h"
+#include "openvz_util.h"
 #include "buf.h"
 #include "util.h"
 #include "openvz_conf.h"
@@ -1683,14 +1684,9 @@ openvzDomainGetMemoryParameters(virDomainPtr domain,
 
     virCheckFlags(0, -1);
 
-    kb_per_pages = sysconf(_SC_PAGESIZE);
-    if (kb_per_pages > 0) {
-        kb_per_pages /= 1024;
-    } else {
-        openvzError(VIR_ERR_INTERNAL_ERROR,
-                    _("Can't determine page size"));
+    kb_per_pages = openvzKBPerPages();
+    if (kb_per_pages < 0)
         goto cleanup;
-    }
 
     if (*nparams == 0) {
         *nparams = OPENVZ_NB_MEM_PARAM;
@@ -1754,14 +1750,9 @@ openvzDomainSetMemoryParameters(virDomainPtr domain,
     int i, result = -1;
     long kb_per_pages;
 
-    kb_per_pages = sysconf(_SC_PAGESIZE);
-    if (kb_per_pages > 0) {
-        kb_per_pages /= 1024;
-    } else {
-        openvzError(VIR_ERR_INTERNAL_ERROR,
-                    _("Can't determine page size"));
+    kb_per_pages = openvzKBPerPages();
+    if (kb_per_pages < 0)
         goto cleanup;
-    }
 
     virCheckFlags(0, -1);
     if (virTypedParameterArrayValidate(params, nparams,
diff --git a/src/openvz/openvz_util.c b/src/openvz/openvz_util.c
new file mode 100644 (file)
index 0000000..61b55de
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * openvz_driver.c: core driver methods for managing OpenVZ VEs
+ *
+ * Copyright (C) 2012 Guido Günther
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "internal.h"
+
+#include "virterror_internal.h"
+
+#include "openvz_conf.h"
+#include "openvz_util.h"
+
+
+long
+openvzKBPerPages(void)
+{
+    static long kb_per_pages = 0;
+
+    if (kb_per_pages == 0) {
+        kb_per_pages = sysconf(_SC_PAGESIZE);
+        if (kb_per_pages > 0) {
+            kb_per_pages /= 1024;
+        } else {
+            openvzError(VIR_ERR_INTERNAL_ERROR,
+                        _("Can't determine page size"));
+            kb_per_pages = 0;
+            return -1;
+        }
+    }
+    return kb_per_pages;
+}
diff --git a/src/openvz/openvz_util.h b/src/openvz/openvz_util.h
new file mode 100644 (file)
index 0000000..a0d9bbb
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * openvz_driver.h: common util functions for managing openvz VPEs
+ *
+ * Copyright (C) 2012 Guido Günther
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ */
+
+
+#ifndef OPENVZ_UTIL_H
+# define OPENVZ_UTIL_H
+
+long openvzKBPerPages(void);
+
+#endif