]> xenbits.xensource.com Git - libvirt.git/commitdiff
LXC: Move virLXCControllerChown to lxc_container.c
authorGao feng <gaofeng@cn.fujitsu.com>
Tue, 16 Jul 2013 02:00:02 +0000 (10:00 +0800)
committerEric Blake <eblake@redhat.com>
Tue, 16 Jul 2013 15:59:14 +0000 (09:59 -0600)
lxc driver will use this function to change the owner
of hot added devices.

Move virLXCControllerChown to lxc_container.c and Rename
it to lxcContainerChown.

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
src/lxc/lxc_container.c
src/lxc/lxc_container.h
src/lxc/lxc_controller.c

index 4d652880468e5a2b4f5234a3cb343211bf3852be..bf6443cf39e98eea16d75604ec090b797fc4ede1 100644 (file)
@@ -2122,3 +2122,24 @@ int lxcContainerAvailable(int features)
     VIR_DEBUG("container support is enabled");
     return 0;
 }
+
+int lxcContainerChown(virDomainDefPtr def, const char *path)
+{
+    uid_t uid;
+    gid_t gid;
+
+    if (!def->idmap.uidmap)
+        return 0;
+
+    uid = def->idmap.uidmap[0].target;
+    gid = def->idmap.gidmap[0].target;
+
+    if (chown(path, uid, gid) < 0) {
+        virReportSystemError(errno,
+                             _("Failed to change owner of %s to %u:%u"),
+                             path, uid, gid);
+        return -1;
+    }
+
+    return 0;
+}
index 6f270d7f7a81f52f0ff5573f8af1e55fda2e1d81..0e3b5918fc2c452c23ec5bd7a513fcdfef2e4085 100644 (file)
@@ -67,4 +67,6 @@ int lxcContainerSetupHostdevCapsMakePath(const char *dev);
 
 virArch lxcContainerGetAlt32bitArch(virArch arch);
 
+int lxcContainerChown(virDomainDefPtr def, const char *path);
+
 #endif /* LXC_CONTAINER_H */
index 38b632e355da113756126e58797e3bec65595e79..4907af48b92c8acda9ff9143df0afe003bdfe712 100644 (file)
@@ -1113,27 +1113,6 @@ cleanup2:
     return rc;
 }
 
-static int
-virLXCControllerChown(virLXCControllerPtr ctrl, char *path)
-{
-    uid_t uid;
-    gid_t gid;
-
-    if (!ctrl->def->idmap.uidmap)
-        return 0;
-
-    uid = ctrl->def->idmap.uidmap[0].target;
-    gid = ctrl->def->idmap.gidmap[0].target;
-
-    if (chown(path, uid, gid) < 0) {
-        virReportSystemError(errno,
-                             _("Failed to change owner of %s to %u:%u"),
-                             path, uid, gid);
-        return -1;
-    }
-
-    return 0;
-}
 
 static int
 virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map,
@@ -1248,7 +1227,7 @@ static int virLXCControllerSetupDev(virLXCControllerPtr ctrl)
         goto cleanup;
     }
 
-    if (virLXCControllerChown(ctrl, dev) < 0)
+    if (lxcContainerChown(ctrl->def, dev) < 0)
         goto cleanup;
 
     ret = 0;
@@ -1296,7 +1275,7 @@ static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl)
             goto cleanup;
         }
 
-        if (virLXCControllerChown(ctrl, path) < 0)
+        if (lxcContainerChown(ctrl->def, path) < 0)
             goto cleanup;
 
         VIR_FREE(path);
@@ -1369,7 +1348,7 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl,
         goto cleanup;
     }
 
-    if (virLXCControllerChown(ctrl, dst) < 0)
+    if (lxcContainerChown(ctrl->def, dst) < 0)
         goto cleanup;
 
     /* Labelling normally operates on src, but we need
@@ -1627,8 +1606,8 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl)
         goto cleanup;
     }
 
-    if ((virLXCControllerChown(ctrl, ctrl->devptmx) < 0) ||
-        (virLXCControllerChown(ctrl, devpts) < 0))
+    if ((lxcContainerChown(ctrl->def, ctrl->devptmx) < 0) ||
+        (lxcContainerChown(ctrl->def, devpts) < 0))
          goto cleanup;
 
     ret = 0;
@@ -1666,7 +1645,7 @@ virLXCControllerSetupConsoles(virLXCControllerPtr ctrl,
         }
 
         /* Change the owner of tty device to the root user of container */
-        if (virLXCControllerChown(ctrl, ttyHostPath) < 0)
+        if (lxcContainerChown(ctrl->def, ttyHostPath) < 0)
             goto cleanup;
 
         VIR_FREE(ttyHostPath);