qemu: Support for overriding NPROC limit

This patch adds max_processes option to qemu.conf which can be used to
override system default limit on number of processes that are allowed to
be running for qemu user.
This commit is contained in:
Jiri Denemark 2011-04-05 14:17:28 +02:00
parent 7b2cac1238
commit 87e78b2bc0
6 changed files with 44 additions and 0 deletions

View File

@ -13,11 +13,13 @@ module Libvirtd_qemu =
let str_val = del /\"/ "\"" . store /[^\"]*/ . del /\"/ "\""
let bool_val = store /0|1/
let int_val = store /[0-9]+/
let str_array_element = [ seq "el" . str_val ] . del /[ \t\n]*/ ""
let str_array_val = counter "el" . array_start . ( str_array_element . ( array_sep . str_array_element ) * ) ? . array_end
let str_entry (kw:string) = [ key kw . value_sep . str_val ]
let bool_entry (kw:string) = [ key kw . value_sep . bool_val ]
let int_entry (kw:string) = [ key kw . value_sep . int_val ]
let str_array_entry (kw:string) = [ key kw . value_sep . str_array_val ]
@ -45,6 +47,7 @@ module Libvirtd_qemu =
| bool_entry "clear_emulator_capabilities"
| bool_entry "allow_disk_format_probing"
| bool_entry "set_process_name"
| int_entry "max_processes"
(* Each enty in the config is one of the following three ... *)
let entry = vnc_entry

View File

@ -273,3 +273,10 @@
# its arguments) appear in process listings.
#
# 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.
#
# max_processes = 0

View File

@ -424,6 +424,10 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
CHECK_TYPE ("set_process_name", VIR_CONF_LONG);
if (p) driver->setProcessName = p->l;
p = virConfGetValue(conf, "max_processes");
CHECK_TYPE("max_processes", VIR_CONF_LONG);
if (p) driver->maxProcesses = p->l;
virConfFree (conf);
return 0;
}

View File

@ -105,6 +105,8 @@ struct qemud_driver {
unsigned int allowDiskFormatProbing : 1;
unsigned int setProcessName : 1;
int maxProcesses;
virCapsPtr caps;
/* An array of callbacks */

View File

@ -25,6 +25,8 @@
#include <unistd.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "qemu_process.h"
#include "qemu_domain.h"
@ -1811,6 +1813,25 @@ qemuProcessPrepareChardevDevice(virDomainDefPtr def ATTRIBUTE_UNUSED,
}
static int
qemuProcessLimits(struct qemud_driver *driver)
{
if (driver->maxProcesses > 0) {
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = driver->maxProcesses;
if (setrlimit(RLIMIT_NPROC, &rlim) < 0) {
virReportSystemError(errno,
_("cannot limit number of processes to %d"),
driver->maxProcesses);
return -1;
}
}
return 0;
}
struct qemuProcessHookData {
virConnectPtr conn;
virDomainObjPtr vm;
@ -1821,6 +1842,9 @@ static int qemuProcessHook(void *data)
{
struct qemuProcessHookData *h = data;
if (qemuProcessLimits(h->driver) < 0)
return -1;
/* This must take place before exec(), so that all QEMU
* memory allocation is on the correct NUMA node
*/

View File

@ -111,6 +111,8 @@ clear_emulator_capabilities = 0
allow_disk_format_probing = 1
vnc_auto_unix_socket = 1
max_processes = 12345
"
test Libvirtd_qemu.lns get conf =
@ -232,3 +234,5 @@ vnc_auto_unix_socket = 1
{ "allow_disk_format_probing" = "1" }
{ "#empty" }
{ "vnc_auto_unix_socket" = "1" }
{ "#empty" }
{ "max_processes" = "12345" }