[PATCH] qemu: Support for overriding NOFILE limit

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

 



This patch adds max_files option to qemu.conf which can be used to
override system default limit on number of opened files that are
allowed for qemu user.
---
 src/qemu/libvirtd_qemu.aug      |    1 +
 src/qemu/qemu.conf              |    4 +++-
 src/qemu/qemu_conf.c            |    4 ++++
 src/qemu/qemu_conf.h            |    1 +
 src/qemu/qemu_process.c         |   16 ++++++++++++++--
 src/qemu/test_libvirtd_qemu.aug |    4 ++++
 6 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index ad34e42..078e9c4 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -50,6 +50,7 @@ module Libvirtd_qemu =
                  | bool_entry "allow_disk_format_probing"
                  | bool_entry "set_process_name"
                  | int_entry "max_processes"
+                 | int_entry "max_files"
                  | str_entry "lock_manager"
                  | int_entry "max_queued"
                  | int_entry "keepalive_interval"
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index c3f264f..6125d3b 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -301,9 +301,11 @@
 
 # If max_processes is set to a positive integer, libvirt will use it to set
 # maximum number of processes that can be run by qemu user. This can be used to
-# override default value set by host OS.
+# override default value set by host OS. The same apply to max_files which
+# set limit to maximum number of opened files.
 #
 # max_processes = 0
+# max_files = 0
 
 # To enable 'Sanlock' project based locking of the file
 # content (to prevent two VMs writing to the same
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 3766119..bc0a646 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -443,6 +443,10 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
     CHECK_TYPE("max_processes", VIR_CONF_LONG);
     if (p) driver->maxProcesses = p->l;
 
+    p = virConfGetValue(conf, "max_files");
+    CHECK_TYPE("max_files", VIR_CONF_LONG);
+    if (p) driver->maxFiles = p->l;
+
     p = virConfGetValue (conf, "lock_manager");
     CHECK_TYPE ("lock_manager", VIR_CONF_STRING);
     if (p && p->str) {
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 8161269..f5a0f60 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -105,6 +105,7 @@ struct qemud_driver {
     unsigned int setProcessName : 1;
 
     int maxProcesses;
+    int maxFiles;
 
     int max_queued;
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 9123f4c..105b895 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2166,9 +2166,9 @@ qemuProcessPrepareChardevDevice(virDomainDefPtr def ATTRIBUTE_UNUSED,
 static int
 qemuProcessLimits(struct qemud_driver *driver)
 {
-    if (driver->maxProcesses > 0) {
-        struct rlimit rlim;
+    struct rlimit rlim;
 
+    if (driver->maxProcesses > 0) {
         rlim.rlim_cur = rlim.rlim_max = driver->maxProcesses;
         if (setrlimit(RLIMIT_NPROC, &rlim) < 0) {
             virReportSystemError(errno,
@@ -2178,6 +2178,18 @@ qemuProcessLimits(struct qemud_driver *driver)
         }
     }
 
+    if (driver->maxFiles > 0) {
+        /* Max number of opened files is one greater than
+         * actual limit. See man setrlimit */
+        rlim.rlim_cur = rlim.rlim_max = driver->maxFiles + 1;
+        if (setrlimit(RLIMIT_NOFILE, &rlim) < 0) {
+            virReportSystemError(errno,
+                                 _("cannot set max opened files to %d"),
+                                 driver->maxFiles);
+            return -1;
+        }
+    }
+
     return 0;
 }
 
diff --git a/src/qemu/test_libvirtd_qemu.aug b/src/qemu/test_libvirtd_qemu.aug
index f7476ae..f841936 100644
--- a/src/qemu/test_libvirtd_qemu.aug
+++ b/src/qemu/test_libvirtd_qemu.aug
@@ -114,6 +114,8 @@ vnc_auto_unix_socket = 1
 
 max_processes = 12345
 
+max_files = 67890
+
 lock_manager = \"fcntl\"
 
 keepalive_interval = 1
@@ -242,6 +244,8 @@ keepalive_count = 42
 { "#empty" }
 { "max_processes" = "12345" }
 { "#empty" }
+{ "max_files" = "67890" }
+{ "#empty" }
 { "lock_manager" = "fcntl" }
 { "#empty" }
 { "keepalive_interval" = "1" }
-- 
1.7.3.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]