<div dir="ltr">I have seen a similar case where /dev/null is missing (Docker using UnionFS).  While this patch fixes the issue, I am wondering why the target file should be missing to start with and whether *always* recreating missing target files could be masking more serious issues.  Any thoughts?<div>
<br></div><div>--Saied</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 28, 2014 at 8:27 AM, Tycho Andersen <span dir="ltr">&lt;<a href="mailto:tycho.andersen@canonical.com" target="_blank">tycho.andersen@canonical.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If the target of a bind mount doesn&#39;t exist, create it. In particular, this<br>
happens with /dev/ptmx across hosts under LXC. We could also mkdir -p any path<br>
to the target, although I&#39;m not sure if that is a case that occurrs in the<br>
wild.<br>
<br>
Signed-off-by: Tycho Andersen &lt;<a href="mailto:tycho.andersen@canonical.com">tycho.andersen@canonical.com</a>&gt;<br>
---<br>
 mount.c | 18 ++++++++++++++++++<br>
 1 file changed, 18 insertions(+)<br>
<br>
diff --git a/mount.c b/mount.c<br>
index 9bb8a17..2108907 100644<br>
--- a/mount.c<br>
+++ b/mount.c<br>
@@ -1346,6 +1346,24 @@ static int do_bind_mount(struct mount_info *mi)<br>
                root = rpath;<br>
 do_bind:<br>
                pr_info(&quot;\tBind %s to %s\n&quot;, root, mi-&gt;mountpoint);<br>
+<br>
+               if (access(mi-&gt;mountpoint, F_OK)) {<br>
+                       if (errno == ENOENT) {<br>
+                               FILE *f;<br>
+<br>
+                               f = fopen(mi-&gt;mountpoint, &quot;w&quot;);<br>
+                               if (!f) {<br>
+                                       pr_perror(&quot;couldn&#39;t write 0 length %s&quot;, mi-&gt;mountpoint);<br>
+                                       return -1;<br>
+                               }<br>
+<br>
+                               fclose(f);<br>
+                       } else {<br>
+                               pr_perror(&quot;Couldn&#39;t access %s&quot;, mi-&gt;mountpoint);<br>
+                               return -1;<br>
+                       }<br>
+               }<br>
+<br>
                if (mount(root, mi-&gt;mountpoint, NULL,<br>
                                        MS_BIND, NULL) &lt; 0) {<br>
                        pr_perror(&quot;Can&#39;t mount at %s&quot;, mi-&gt;mountpoint);<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
_______________________________________________<br>
CRIU mailing list<br>
<a href="mailto:CRIU@openvz.org">CRIU@openvz.org</a><br>
<a href="https://lists.openvz.org/mailman/listinfo/criu" target="_blank">https://lists.openvz.org/mailman/listinfo/criu</a><br>
</font></span></blockquote></div><br></div>