]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Support for overriding NOFILE limit
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 22 Dec 2011 11:22:31 +0000 (12:22 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 22 Dec 2011 16:49:04 +0000 (17:49 +0100)
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
src/qemu/qemu.conf
src/qemu/qemu_conf.c
src/qemu/qemu_conf.h
src/qemu/qemu_process.c
src/qemu/test_libvirtd_qemu.aug

index ad34e42daa5cbb13dd9c0baf9cf5881e7a797802..078e9c41a7c96c4547bd02b33981305662663742 100644 (file)
@@ -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"
index c3f264f4ecc448a5383131f07ab58e69294e31e4..4ec5e6c0ffd52433cf3424daa8ef96231656ef7a 100644 (file)
 # set_process_name = 1
 
 
-# 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.
+# If max_processes is set to a positive integer, libvirt will use
+# it to set the maximum number of processes that can be run by qemu
+# user. This can be used to override default value set by host OS.
+# The same applies to max_files which sets the limit on the 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
index 37661193880f862ee9d18e8b075928a66728534b..bc0a646b6c36ffb2839824314cdbe8e7cc726560 100644 (file)
@@ -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) {
index 8161269fa76d8e950e775383dde687c7ba4a5bd7..f5a0f6065faefb6ac46c962b9ea171bb64bbc2a7 100644 (file)
@@ -105,6 +105,7 @@ struct qemud_driver {
     unsigned int setProcessName : 1;
 
     int maxProcesses;
+    int maxFiles;
 
     int max_queued;
 
index 9123f4c85e9b610afca8449a89a1f047dc94d4e0..105b895f512ea66a3c0861704cfcc7e717a455f4 100644 (file)
@@ -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;
 }
 
index f7476ae5d5d62a594594395d2d99b8cb15572595..f8419367a13e7823fe65c71ec28393bddd8f75dc 100644 (file)
@@ -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" }