File libvirt-qemu-Set-RLIMIT_MEMLOCK-when-memoryBacking-locked-is-used.patch of Package libvirt

From 38163bdf950159dd6b75f1952ca3992055ac3a5f Mon Sep 17 00:00:00 2001
Message-Id: <38163bdf950159dd6b75f1952ca3992055ac3a5f.1374158624.git.jdenemar@redhat.com>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Fri, 28 Jun 2013 16:58:03 +0200
Subject: [PATCH] qemu: Set RLIMIT_MEMLOCK when memoryBacking/locked is used

https://bugzilla.redhat.com/show_bug.cgi?id=947118

If a domain is configured to have all its memory locked, we need to set
RLIMIT_MEMLOCK so that QEMU is actually allowed to lock the memory.

(cherry picked from commit 59cc0fe5aa00d472bdd19bfb40be219249cfd0c7)

Conflicts:
	src/qemu/qemu_command.c - no conflicts but the code had to be
	    changed as upstream commit 6d8ebc75 was not backported due
	    to the lack of VFIO related code in RHEL 6.5
---
 src/qemu/qemu_command.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1869e2d..da91c3b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4855,6 +4855,7 @@ qemuBuildCommandLine(virConnectPtr conn,
     int spice = 0;
     int usbcontroller = 0;
     bool usblegacy = false;
+    bool mlock = false;
     uname_normalize(&ut);
     int contOrder[] = {
         /* We don't add an explicit IDE or FD controller because the
@@ -5028,6 +5029,7 @@ qemuBuildCommandLine(virConnectPtr conn,
         virCommandAddArgFormat(cmd, "mlock=%s",
                                def->mem.locked ? "on" : "off");
     }
+    mlock = def->mem.locked;
 
     virCommandAddArg(cmd, "-smp");
     if (!(smp = qemuBuildSmpArgStr(def, caps)))
@@ -6801,6 +6803,9 @@ qemuBuildCommandLine(virConnectPtr conn,
         goto error;
     }
 
+    if (mlock)
+        virCommandSetMaxMemLock(cmd, qemuDomainMemoryLimit(def) * 1024);
+
     return cmd;
 
  no_memory:
-- 
1.8.3.2

openSUSE Build Service is sponsored by