[CRIU] [PATCH] mount: Create target of bind mount if it doesn't exist

Tycho Andersen tycho.andersen at canonical.com
Thu Aug 28 08:27:20 PDT 2014


If the target of a bind mount doesn't exist, create it. In particular, this
happens with /dev/ptmx across hosts under LXC. We could also mkdir -p any path
to the target, although I'm not sure if that is a case that occurrs in the
wild.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 mount.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/mount.c b/mount.c
index 9bb8a17..2108907 100644
--- a/mount.c
+++ b/mount.c
@@ -1346,6 +1346,24 @@ static int do_bind_mount(struct mount_info *mi)
 		root = rpath;
 do_bind:
 		pr_info("\tBind %s to %s\n", root, mi->mountpoint);
+
+		if (access(mi->mountpoint, F_OK)) {
+			if (errno == ENOENT) {
+				FILE *f;
+
+				f = fopen(mi->mountpoint, "w");
+				if (!f) {
+					pr_perror("couldn't write 0 length %s", mi->mountpoint);
+					return -1;
+				}
+
+				fclose(f);
+			} else {
+				pr_perror("Couldn't access %s", mi->mountpoint);
+				return -1;
+			}
+		}
+
 		if (mount(root, mi->mountpoint, NULL,
 					MS_BIND, NULL) < 0) {
 			pr_perror("Can't mount at %s", mi->mountpoint);
-- 
1.9.1



More information about the CRIU mailing list