<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 24, 2022 at 3:07 PM Rob Landley <<a href="mailto:rob@landley.net">rob@landley.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 6/21/22 11:30, Yi-yo Chiang via Toybox wrote:<br>
> `mount -o private mountpoint` should change the mount propagation type<br>
> of mountpoint to MS_PRIVATE. This didn't work because it falls into<br>
> the "read /etc/fstab" branch (one argument), and fails when mountpoint<br>
> is not found in the fstab, or fstab is not found (Android case).<br>
<br>
I think you want to do "mount -o remount,private mountpoint"?<br>
<br></blockquote><div><br></div><div>No i really just want `-o private`, in fact I want </div><div> mount("", <mountpoint>, "", MS_PRIVATE, "");</div><div><br></div><div>MS_PRIVATE, MS_SHARED, MS_SLAVE, MS_UNBINDABLE are special semantics that *changes the subtree propagation type* of an existing mount point. It doesn't alter or remount the underlying filesystem.</div><div><br></div><div>If MS_BIND or MS_REMOUNT is given, then MS_PRIVATE, MS_SHARD... would be ignored. (man 2 mount)</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> `mount -o private blah mountpoint` kind of works, as long as `blah`<br>
> doesn't look like a directory, otherwise toybox would assume bind mount<br>
> and MS_BIND would win over MS_PRIVATE.<br>
<br>
Is mountpoint an existing mountpoint? Because you should either get an overmount<br>
or an "is already mounted" error, unless MS_PRIVATE is being _REALLY_ magic in<br>
the kernel behind the scenes and doing an implicit -o remount?<br></blockquote><div><br></div><div>Yes mountpoint must be an already mounted mountpoint, so I can do this right now</div><div>$ mount --bind mnt mnt</div><div>$ mount -o private xxxxxx mnt</div><div>which bind mounts /mnt to itself and changes its propagation type to MS_PRIVATE.</div><div><br></div><div>If I do this instead</div><div>$ mount --bind mnt mnt</div><div>$ mount -o private mnt mnt</div><div>then toybox thinks the second command is a bind mount, and calls `mount("mnt", "mnt", fs_type, MS_PRIVATE|MS_BIND, "")`, and the kernel would ignore the MS_PRIVATE flag as MS_BIND is also given.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> Even if `blah mountpoint` looks sufficient unlike a bind mount, the<br>
> underlying mount() syscall would be a bit off,<br>
> mount(blah, mountpoint, "ext3", MS_SILENT|MS_PRIVATE, "")<br>
<br>
Yes, it would. Among other things, no MS_REMOUNT flag...<br></blockquote><div><br></div><div>No MS_REMOUNT is the desired behavior here.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> The "ext3" (or whatever comes first in /proc/filesystems) is because<br>
> unspecified `-t` defaults to `-t auto`, which means "try mount FS in<br>
> /proc/filesystems one-by-one", which is not what we want here. We don't<br>
> want to mount anything, but change an existing mountpoint's propagation<br>
> type.<br>
<br>
That's what -o remount does. Are you saying you want -o remount to be implicit here?<br></blockquote><div><br></div><div>No we really don't want MS_REMOUNT if we are changing the propagation type flags.</div><div><br></div><div>mount(<ignored>, mountpoint, <ignored>, MS_REMOUNT|flags, fs_flags);</div><div>=> change mount flags, if MS_PRIVATE (& friends) is specified in |flags|, it is ignored by kernel.</div><div><br class="gmail-Apple-interchange-newline">mount(<ignored>, mountpoint, <ignored>, MS_PRIVATE, <ignored>); (or MS_SHARED...)<br></div><div>=> change the propagation type of mountpoint, that's it.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> This patch adds "mount -o private mountpoint" machinery and unit test.<br>
<br>
Not looking like it makes MS_REMOUNT implicit when<br>
MS_PRIVATE/SHARED/SLAVE/UNBINDABLE is giving with one argument...<br>
<br>
+testing "-o private not_a_mountpoint" \<br>
+ "mount -o private '${mountpoint}' 2>/dev/null || echo error" "error\n" "" ""<br>
<br>
Because you didn't tell it WHAT to mount, so yes it should error if this isn't a<br>
remount. (Did your patch change this behavior?)<br></blockquote><div><br></div><div>Yes my patch added this behavior. It changes so that if one of the propagation type flags is given, and only one argument is given, and no '-o remount' is given, then perform `mount("", mountpoint, "", MS_PRIVATE, "")`.</div><div>This test case is expected to fail because ${mountpoint} was not a mounted mountpoint, so mount(2) could not chnage its propagation type.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
+testing "-o bind,private dir dir (MS_BIND wins MS_PRIVATE)" \<br>
+ "mount -o bind,private '${mountpoint}' '${mountpoint}' 2>&1 &&<br>
+ umount '${mountpoint}' && echo yes" "yes\n" "" ""<br>
<br>
You're bind mounting a directory on itself and adding the private flag: did that<br>
not already work? (If it wasn't _already_ a mount point, I mean.)<br></blockquote><div><br></div><div>yeah it works already right now. I added this case to check my changes didn't break any existing behavior.</div><div>$ mount -o bind,private dir dir #=> still a bind mount</div><div>$ mount -o private dir #=> was *mount by fstab*, now changed to *change mount propagation type*</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I admit I haven't tested the private/shared/slave stuff much because it ties<br>
into namespaces/containers which I have a big todo hairball for. but I think I<br>
tested this at one point? I note that mount.tests is one of the big things I<br>
want to get tests running under mkroot for, because "run as root, leave the<br>
system in a bad state if it didn't finish cleanly" is not something I want to do<br>
on my development laptop a lot. Getting that to work soonish has been the focus<br>
of my recent sh.c commits...<br>
<br></blockquote><div><br></div><div>100% agree. I once naively run `make tests` with root just to see if it works, it end up leaving my system in a weird state and I had to reboot and fix my rootfs... After that I always run tests on an android device.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Rob<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><table width="90%" border="0" cellspacing="0" cellpadding="0" style="margin:0px;padding:0px;font-family:"Times New Roman";max-width:348px"><tbody style="margin:0px;padding:0px"><tr style="margin:0px;padding:0px"><td style="padding:0px"><table border="0" cellspacing="0" cellpadding="0" style="margin:0px;padding:20px 0px 0px"><tbody style="margin:0px;padding:0px"><tr style="margin:0px;padding:0px"><td valign="top" style="padding:0px 20px 0px 0px;vertical-align:top;border-right:1px solid rgb(213,213,213)"><img src="https://i.imgur.com/eGpkLls.png" width="200" height="64"><br></td><td style="padding:0px 0px 0px 20px"><table border="0" cellspacing="0" cellpadding="0" style="margin:0px;padding:0px"><tbody style="margin:0px;padding:0px"><tr style="margin:0px;padding:0px"><td colspan="2" style="font-family:Arial,Helvetica,Verdana,sans-serif;padding:1px 0px 5px;font-size:13px;line-height:13px;color:rgb(56,58,53);font-weight:700">Yi-yo Chiang</td></tr><tr style="margin:0px;padding:0px"><td colspan="2" style="font-family:Arial,Helvetica,Verdana,sans-serif;padding:0px 0px 5px;font-size:11px;line-height:13px;color:rgb(56,58,53)">Software Engineer</td></tr><tr style="margin:0px;padding:0px"><td colspan="2" style="font-family:Arial,Helvetica,Verdana,sans-serif;padding:0px 0px 5px;font-size:11px;line-height:13px;color:rgb(56,58,53)"><a href="mailto:yochiang@google.com" target="_blank">yochiang@google.com</a></td></tr><tr style="margin:0px;padding:0px"><td colspan="2" style="font-family:Arial,Helvetica,Verdana,sans-serif;padding:0px 0px 3px;font-size:11px;line-height:13px;color:rgb(3,112,248)"></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table><div><font size="1">I support flexible work schedules, and I’m sending this email now because it is within the hours I’m working today. Please do not feel obliged to reply straight away - I understand that you will reply during the hours you work, which may not match mine.</font><br></div></div></div></div>