]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Set limits only when explicitly asked to do so
authorAndrea Bolognani <abologna@redhat.com>
Tue, 2 Mar 2021 17:20:47 +0000 (18:20 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Mon, 8 Mar 2021 21:41:40 +0000 (22:41 +0100)
The current code is written under the assumption that, for all
limits except the core size, asking for the limit to be set to
zero is a no-op, and so the operation is performed
unconditionally.

While this is the behavior we want for the QEMU driver, the
virCommand and virProcess facilities are generic, and should not
implement this kind of policy: asking for a limit to be set to
zero should result in that limit being set to zero every single
time.

Add some checks in the QEMU driver, effectively moving the
policy where it belongs.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_domain.c
src/qemu/qemu_migration.c
src/qemu/qemu_process.c

index 17fa71c21b7dc71fc2791e558ec209457d136296..54d8bd0d3a878a6c49a282d558764fa844c809df 100644 (file)
@@ -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;
 }
index d7231f68ae5ae2d741aae53219f71123f8878936..e44931dcfae57fba31258598f313a47ab0c90b51 100644 (file)
@@ -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;
         }
index 6684065534d5085bac63f055ba766be97fd6a2a7..89ede2775172f179900b45c7b0fc9ef829c194f1 100644 (file)
@@ -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");