render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Mark McLoughlin 743adf
From: Mark McLoughlin <markmc@redhat.com>
Mark McLoughlin 743adf
Subject: [PATCH] chown kernel/initrd before spawning qemu
Mark McLoughlin 743adf
Mark McLoughlin 743adf
If we're running qemu unprivileged, we need to chown any supplied kernel
Mark McLoughlin 743adf
or initrd before spawning it.
Mark McLoughlin 743adf
Mark McLoughlin 743adf
* src/qemu_driver.c: rename qemuDomainSetDiskOwnership() to
Mark McLoughlin 743adf
  qemuDomainSetFileOwnership(), pass it a path string instead of a disk
Mark McLoughlin 743adf
  definition and use it for chowning the kernel/initrd in
Mark McLoughlin 743adf
  qemuDomainSetAllDeviceOwnership()
Mark McLoughlin 743adf
---
Mark McLoughlin 743adf
 src/qemu_driver.c |   20 ++++++++++++--------
Mark McLoughlin 743adf
 1 files changed, 12 insertions(+), 8 deletions(-)
Mark McLoughlin 743adf
Mark McLoughlin 743adf
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
Mark McLoughlin 743adf
index 412b68d..bd58435 100644
Mark McLoughlin 743adf
--- a/src/qemu_driver.c
Mark McLoughlin 743adf
+++ b/src/qemu_driver.c
Mark McLoughlin 743adf
@@ -1684,18 +1684,18 @@ static int qemuDomainSetHostdevOwnership(virConnectPtr conn,
Mark McLoughlin 743adf
 
Mark McLoughlin 743adf
 }
Mark McLoughlin 743adf
 
Mark McLoughlin 743adf
-static int qemuDomainSetDiskOwnership(virConnectPtr conn,
Mark McLoughlin 743adf
-                                      virDomainDiskDefPtr def,
Mark McLoughlin 743adf
+static int qemuDomainSetFileOwnership(virConnectPtr conn,
Mark McLoughlin 743adf
+                                      const char *path,
Mark McLoughlin 743adf
                                       uid_t uid, gid_t gid)
Mark McLoughlin 743adf
 {
Mark McLoughlin 743adf
 
Mark McLoughlin 743adf
-    if (!def->src)
Mark McLoughlin 743adf
+    if (!path)
Mark McLoughlin 743adf
         return 0;
Mark McLoughlin 743adf
 
Mark McLoughlin 743adf
-    VIR_DEBUG("Setting ownership on %s to %d:%d", def->src, uid, gid);
Mark McLoughlin 743adf
-    if (chown(def->src, uid, gid) < 0) {
Mark McLoughlin 743adf
+    VIR_DEBUG("Setting ownership on %s to %d:%d", path, uid, gid);
Mark McLoughlin 743adf
+    if (chown(path, uid, gid) < 0) {
Mark McLoughlin 743adf
         virReportSystemError(conn, errno, _("cannot set ownership on %s"),
Mark McLoughlin 743adf
-                             def->src);
Mark McLoughlin 743adf
+                             path);
Mark McLoughlin 743adf
         return -1;
Mark McLoughlin 743adf
     }
Mark McLoughlin 743adf
     return 0;
Mark McLoughlin 743adf
@@ -1725,7 +1725,7 @@ static int qemuDomainSetDeviceOwnership(virConnectPtr conn,
Mark McLoughlin 743adf
             (def->data.disk->readonly || def->data.disk->shared))
Mark McLoughlin 743adf
             return 0;
Mark McLoughlin 743adf
 
Mark McLoughlin 743adf
-        return qemuDomainSetDiskOwnership(conn, def->data.disk, uid, gid);
Mark McLoughlin 743adf
+        return qemuDomainSetFileOwnership(conn, def->data.disk->src, uid, gid);
Mark McLoughlin 743adf
 
Mark McLoughlin 743adf
     case VIR_DOMAIN_DEVICE_HOSTDEV:
Mark McLoughlin 743adf
         return qemuDomainSetHostdevOwnership(conn, def->data.hostdev, uid, gid);
Mark McLoughlin 743adf
@@ -1753,12 +1753,16 @@ static int qemuDomainSetAllDeviceOwnership(virConnectPtr conn,
Mark McLoughlin 743adf
     uid = restore ? 0 : driver->user;
Mark McLoughlin 743adf
     gid = restore ? 0 : driver->group;
Mark McLoughlin 743adf
 
Mark McLoughlin 743adf
+    if (qemuDomainSetFileOwnership(conn, def->os.kernel, uid, gid) < 0 ||
Mark McLoughlin 743adf
+        qemuDomainSetFileOwnership(conn, def->os.initrd, uid, gid) < 0)
Mark McLoughlin 743adf
+        return -1;
Mark McLoughlin 743adf
+
Mark McLoughlin 743adf
     for (i = 0 ; i < def->ndisks ; i++) {
Mark McLoughlin 743adf
         if (restore &&
Mark McLoughlin 743adf
             (def->disks[i]->readonly || def->disks[i]->shared))
Mark McLoughlin 743adf
             continue;
Mark McLoughlin 743adf
 
Mark McLoughlin 743adf
-        if (qemuDomainSetDiskOwnership(conn, def->disks[i], uid, gid) < 0)
Mark McLoughlin 743adf
+        if (qemuDomainSetFileOwnership(conn, def->disks[i]->src, uid, gid) < 0)
Mark McLoughlin 743adf
             return -1;
Mark McLoughlin 743adf
     }
Mark McLoughlin 743adf
 
Mark McLoughlin 743adf
-- 
Mark McLoughlin 743adf
1.6.2.5
Mark McLoughlin 743adf