qemu: Support for overriding NOFILE limit

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.
This commit is contained in:
Michal Privoznik 2011-12-22 12:22:31 +01:00
parent 74ad69b708
commit d8db0f9690
6 changed files with 30 additions and 5 deletions

View 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"

View File

@ -299,11 +299,14 @@
# 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

View 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) {

View File

@ -105,6 +105,7 @@ struct qemud_driver {
unsigned int setProcessName : 1;
int maxProcesses;
int maxFiles;
int max_queued;

View 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;
}

View 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" }