]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
LXC: hostdev: introduce lxcContainerSetupHostdevCapsMakePath
authorGao feng <gaofeng@cn.fujitsu.com>
Tue, 9 Jul 2013 10:15:11 +0000 (11:15 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 9 Jul 2013 10:15:11 +0000 (11:15 +0100)
This helper function is used to create parent directory for
the hostdev which will be added to the container. If the
parent directory of this hostdev doesn't exist, the mknod of
the hostdev will fail. eg with /dev/net/tun

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

index c8420db7a13c91b4a0ed85a2fb2f1de84901e2e7..0c60d330f13962f480d0f718b196e7d0e5627ba2 100644 (file)
@@ -1544,6 +1544,32 @@ cleanup:
 }
 
 
+int lxcContainerSetupHostdevCapsMakePath(const char *dev)
+{
+    int ret = -1;
+    char *dir, *tmp;
+
+    if (VIR_STRDUP(dir, dev) < 0)
+        return -1;
+
+    if ((tmp = strrchr(dir, '/'))) {
+        *tmp = '\0';
+        if (virFileMakePath(dir) < 0) {
+            virReportSystemError(errno,
+                                 _("Failed to create directory for '%s' dev '%s'"),
+                                 dir, dev);
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+
+cleanup:
+    VIR_FREE(dir);
+    return ret;
+}
+
+
 static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_UNUSED,
                                                virDomainHostdevDefPtr def ATTRIBUTE_UNUSED,
                                                virSecurityManagerPtr securityDriver ATTRIBUTE_UNUSED)
index ada72f70d709719a602f819691175e81decc5621..6f270d7f7a81f52f0ff5573f8af1e55fda2e1d81 100644 (file)
@@ -63,6 +63,8 @@ int lxcContainerStart(virDomainDefPtr def,
 
 int lxcContainerAvailable(int features);
 
+int lxcContainerSetupHostdevCapsMakePath(const char *dev);
+
 virArch lxcContainerGetAlt32bitArch(virArch arch);
 
 #endif /* LXC_CONTAINER_H */