From 6559a3520814a813902bc5ffeeea7738f5f99f37 Mon Sep 17 00:00:00 2001 From: Gao feng Date: Tue, 9 Jul 2013 11:15:11 +0100 Subject: [PATCH] LXC: hostdev: introduce lxcContainerSetupHostdevCapsMakePath 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 (cherry picked from commit c0d8c7c88579c612cf8a9776d276f8fd59d779f3) --- src/lxc/lxc_container.c | 26 ++++++++++++++++++++++++++ src/lxc/lxc_container.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 3245215ca4..682d0ebdf3 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -1532,6 +1532,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) diff --git a/src/lxc/lxc_container.h b/src/lxc/lxc_container.h index ada72f70d7..6f270d7f7a 100644 --- a/src/lxc/lxc_container.h +++ b/src/lxc/lxc_container.h @@ -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 */ -- 2.47.3