[libvirt] [PATCH] Ensure that /dev exists in the container root filesystem

From: "Daniel P. Berrange" <berrange@redhat.com> If booting a container with a root FS that isn't the host's root, we must ensure that the /dev mount point exists. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/lxc/lxc_container.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 0ab4026..678a9d5 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -868,7 +868,7 @@ static int lxcContainerMountProcFuse(virDomainDefPtr def ATTRIBUTE_UNUSED, static int lxcContainerMountFSDev(virDomainDefPtr def, const char *stateDir) { - int ret; + int ret = -1; char *path = NULL; VIR_DEBUG("Mount /dev/ stateDir=%s", stateDir); @@ -877,14 +877,24 @@ static int lxcContainerMountFSDev(virDomainDefPtr def, stateDir, def->name)) < 0) return ret; + if (virFileMakePath("/dev") < 0) { + virReportSystemError(errno, "%s", + _("Cannot create /dev")); + goto cleanup; + } + VIR_DEBUG("Tring to move %s to /dev", path); - if ((ret = mount(path, "/dev", NULL, MS_MOVE, NULL)) < 0) { + if (mount(path, "/dev", NULL, MS_MOVE, NULL) < 0) { virReportSystemError(errno, _("Failed to mount %s on /dev"), path); + goto cleanup; } + ret = 0; + +cleanup: VIR_FREE(path); return ret; } -- 1.8.3.1

On 08/13/2013 07:59 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
If booting a container with a root FS that isn't the host's root, we must ensure that the /dev mount point exists.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/lxc/lxc_container.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
ACK.
+ VIR_DEBUG("Tring to move %s to /dev", path);
While you're touching this, s/Tring/Trying/ -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 08/13/2013 09:59 PM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
If booting a container with a root FS that isn't the host's root, we must ensure that the /dev mount point exists.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/lxc/lxc_container.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
ACK
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 0ab4026..678a9d5 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -868,7 +868,7 @@ static int lxcContainerMountProcFuse(virDomainDefPtr def ATTRIBUTE_UNUSED, static int lxcContainerMountFSDev(virDomainDefPtr def, const char *stateDir) { - int ret; + int ret = -1; char *path = NULL;
VIR_DEBUG("Mount /dev/ stateDir=%s", stateDir); @@ -877,14 +877,24 @@ static int lxcContainerMountFSDev(virDomainDefPtr def, stateDir, def->name)) < 0) return ret;
+ if (virFileMakePath("/dev") < 0) { + virReportSystemError(errno, "%s", + _("Cannot create /dev")); + goto cleanup; + } + VIR_DEBUG("Tring to move %s to /dev", path);
- if ((ret = mount(path, "/dev", NULL, MS_MOVE, NULL)) < 0) { + if (mount(path, "/dev", NULL, MS_MOVE, NULL) < 0) { virReportSystemError(errno, _("Failed to mount %s on /dev"), path); + goto cleanup; }
+ ret = 0; + +cleanup: VIR_FREE(path); return ret; }
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Gao feng