diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 17fa71c21b..54d8bd0d3a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9259,9 +9259,10 @@ qemuDomainAdjustMaxMemLock(virDomainObjPtr vm, vm->original_memlock = 0; } - /* Trying to set the memory locking limit to zero is a no-op */ - if (virProcessSetMaxMemLock(vm->pid, bytes) < 0) + if (bytes > 0 && + virProcessSetMaxMemLock(vm->pid, bytes) < 0) { return -1; + } return 0; } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index d7231f68ae..e44931dcfa 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2950,6 +2950,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, } if (STREQ_NULLABLE(protocol, "rdma") && + vm->def->mem.hard_limit > 0 && virProcessSetMaxMemLock(vm->pid, vm->def->mem.hard_limit << 10) < 0) { goto stopjob; } @@ -4199,6 +4200,7 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver, switch (spec->destType) { case MIGRATION_DEST_HOST: if (STREQ(spec->dest.host.protocol, "rdma") && + vm->def->mem.hard_limit > 0 && virProcessSetMaxMemLock(vm->pid, vm->def->mem.hard_limit << 10) < 0) { goto exit_monitor; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6684065534..89ede27751 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7018,9 +7018,18 @@ qemuProcessLaunch(virConnectPtr conn, * significant amount of memory, so we need to set the limit accordingly */ maxMemLock = qemuDomainGetMemLockLimitBytes(vm->def, false); - virCommandSetMaxMemLock(cmd, maxMemLock); - virCommandSetMaxProcesses(cmd, cfg->maxProcesses); - virCommandSetMaxFiles(cmd, cfg->maxFiles); + /* For all these settings, zero indicates that the limit should + * not be set explicitly and the default/inherited limit should + * be applied instead */ + if (maxMemLock > 0) + virCommandSetMaxMemLock(cmd, maxMemLock); + if (cfg->maxProcesses > 0) + virCommandSetMaxProcesses(cmd, cfg->maxProcesses); + if (cfg->maxFiles > 0) + virCommandSetMaxFiles(cmd, cfg->maxFiles); + + /* In this case, however, zero means that core dumps should be + * disabled, and so we always need to set the limit explicitly */ virCommandSetMaxCoreSize(cmd, cfg->maxCore); VIR_DEBUG("Setting up security labelling");