Skip to contentSkip to conversation

man/man2/move_mount.2: document EINVAL on multiple instances

PATCH Superseded [email protected] 6 participants 26 messages Oct 6, 2025 – Oct 22, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 man/man2/move_mount.2: document EINVAL on multiple instances

From: Luca Boccassi <[email protected]>

open_tree() with OPEN_TREE_CLONE is needed to apply a mount multiple times, otherwise EINVAL is returned by move_mount().

---
As requested by Aleksa on https://github.com/brauner/man-pages-md/pull/19
and based on the 'fs' branch where move_mount(2) was added

 man/man2/move_mount.2 | 7 +++++++
 1 file changed, 7 insertions(+)
man/man2/move_mount.2 +7 -0
index 13063ac1f..e3dfc1ea8 100644
@@ -457,6 +457,13 @@ which would otherwise cause the unbindable mounts to be propagated
 was attempted,
 but one of the listed restrictions was violated.
 .TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via
+.BR open_tree (2)
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).
+.TP
 .B ELOOP
 Too many symbolic links encountered
 when resolving one of
Signature · 1 line
2.47.3
#1 lore raw

Hi Luca,

Quoted 18 lines · On Mon, Oct 06, 2025 at 11:38:12AM +0100, [email protected] wrote:

From: Luca Boccassi <[email protected]>

open_tree() with OPEN_TREE_CLONE is needed to apply a mount multiple times, otherwise EINVAL is returned by move_mount().

---
As requested by Aleksa on https://github.com/brauner/man-pages-md/pull/19
and based on the 'fs' branch where move_mount(2) was added

 man/man2/move_mount.2 | 7 +++++++
 1 file changed, 7 insertions(+)
man/man2/move_mount.2 +0 -0
index 13063ac1f..e3dfc1ea8 100644

man/man2/move_mount.2 which would otherwise cause the unbindable mounts to be propagated · line 461

Quoted 5 lines
man/man2/move_mount.2 +2 -0
@@ -457,6 +457,13 @@ which would otherwise cause the unbindable mounts to be propagated
 was attempted,
 but one of the listed restrictions was violated.
 .TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via

Please use semantic newlines. See man-pages(7):

$ MANWIDTH=72 man 7 man-pages | sed -n '/Use semantic newlines/,/^$/p'
   Use semantic newlines
     In the source of a manual page, new sentences should be started on
     new lines, long sentences should be split  into  lines  at  clause
     breaks  (commas,  semicolons, colons, and so on), and long clauses
     should be split at phrase boundaries.  This convention,  sometimes
     known as "semantic newlines", makes it easier to see the effect of
     patches, which often operate at the level of individual sentences,
     clauses, or phrases.

To be precise, that would mean breaking the line after period in this case.

man/man2/move_mount.2 which would otherwise cause the unbindable mounts to be propagated · line 465

Quoted 4 lines
man/man2/move_mount.2 +4 -0
+.BR open_tree (2)
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).

The parenthetical in that position makes it unclear if you're saying that one should use open_tree(2) with OPEN_TREE_CLONE since Linux 6.15, or if you're saying that this error can happen since that version. Would you mind clarifying? I think if you mean that the error can happen since Linux 6.15, we could make it part of the paragraph tag, as in unshare(2).

alx@devuan:~$ man -w 2 unshare
/usr/local/man/man2/unshare.2
alx@devuan:~$ MANWIDTH=72
alx@devuan:~$ man -w 2 unshare | xargs mansect ERRORS | man /dev/stdin | grep -C3 'since Linux'
            Cannot allocate sufficient memory to copy parts of caller’s context
            that need to be unshared.

ENOSPC (since Linux 3.7)
CLONE_NEWPID was specified in flags, but the limit on the nesting depth of PID namespaces would have been exceeded; see pid_name‐ spaces(7).

ENOSPC (since Linux 4.9; beforehand EUSERS)
CLONE_NEWUSER was specified in flags, and the call would cause the
limit on the number of nested user namespaces to be exceeded. See
user_namespaces(7).
--
From Linux 3.11 to Linux 4.8, the error diagnosed in this case was EUSERS.

ENOSPC (since Linux 4.9)
One of the values in flags specified the creation of a new user namespace, but doing so would have caused the limit defined by the
corresponding file in /proc/sys/user to be exceeded. For further
--
ID or the effective group ID of the caller does not have a mapping in the parent namespace (see user_namespaces(7)).

EPERM (since Linux 3.9)
CLONE_NEWUSER was specified in flags and the caller is in a chroot environment (i.e., the caller’s root directory does not match the root directory of the mount namespace in which it resides).

Have a lovely day!
Alex

Quoted 7 lines
man/man2/move_mount.2 +1 -0
+.TP
 .B ELOOP
 Too many symbolic links encountered
 when resolving one of
Signature · 1 line
2.47.3
Signature · 2 lines
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
#2 lore raw
Quoted 44 lines · Alejandro Colomar

Hi Luca,

Quoted 18 lines · On Mon, Oct 06, 2025 at 11:38:12AM +0100, [email protected] wrote:

From: Luca Boccassi <[email protected]>

open_tree() with OPEN_TREE_CLONE is needed to apply a mount multiple times, otherwise EINVAL is returned by move_mount().

---
As requested by Aleksa on https://github.com/brauner/man-pages-md/pull/19
and based on the 'fs' branch where move_mount(2) was added

 man/man2/move_mount.2 | 7 +++++++
 1 file changed, 7 insertions(+)
man/man2/move_mount.2 +0 -0
index 13063ac1f..e3dfc1ea8 100644

man/man2/move_mount.2 which would otherwise cause the unbindable mounts to be propagated · line 461

Quoted 5 lines
man/man2/move_mount.2 +2 -0
@@ -457,6 +457,13 @@ which would otherwise cause the unbindable mounts to be propagated
 was attempted,
 but one of the listed restrictions was violated.
 .TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via

Please use semantic newlines. See man-pages(7):

$ MANWIDTH=72 man 7 man-pages | sed -n '/Use semantic newlines/,/^$/p'
   Use semantic newlines
     In the source of a manual page, new sentences should be started on
     new lines, long sentences should be split  into  lines  at  clause
     breaks  (commas,  semicolons, colons, and so on), and long clauses
     should be split at phrase boundaries.  This convention,  sometimes
     known as "semantic newlines", makes it easier to see the effect of
     patches, which often operate at the level of individual sentences,
     clauses, or phrases.

To be precise, that would mean breaking the line after period in this case.

Quoted 11 lines

man/man2/move_mount.2 which would otherwise cause the unbindable mounts to be propagated · line 465

Quoted 4 lines
man/man2/move_mount.2 +4 -0
+.BR open_tree (2)
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).

The parenthetical in that position makes it unclear if you're saying that one should use open_tree(2) with OPEN_TREE_CLONE since Linux 6.15, or if you're saying that this error can happen since that version. Would you mind clarifying? I think if you mean that the error can happen since Linux 6.15, we could make it part of the paragraph tag, as in unshare(2).

I meant the former, the error is always there, but OPEN_TREE_CLONE can be used since 6.15 to avoid it. Sent v2 with this and the other fix, thanks for the prompt review.

#3 lore raw

Hi Luca,

Quoted 3 lines · Luca Boccassi
Quoted 3 lines
Quoted 3 lines

.TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via

[...]

Quoted 12 lines
Quoted 11 lines

man/man2/move_mount.2 which would otherwise cause the unbindable mounts to be propagated · line 465

Quoted 4 lines

+.BR open_tree (2)

man/man2/move_mount.2 +3 -0
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).

The parenthetical in that position makes it unclear if you're saying that one should use open_tree(2) with OPEN_TREE_CLONE since Linux 6.15, or if you're saying that this error can happen since that version. Would you mind clarifying? I think if you mean that the error can happen since Linux 6.15, we could make it part of the paragraph tag, as in unshare(2).

Quoted 3 lines

I meant the former, the error is always there, but OPEN_TREE_CLONE can be used since 6.15 to avoid it. Sent v2 with this and the other fix, thanks for the prompt review.

Hmmm, I see. Why not use open_tree(2) and OPEN_TREE_CLONE before 6.15? The syscall and flag existed, AFAICS. I think we should clarify --at least in the commit message--, why that version is important.

Cheers,
Alex

Signature · 2 lines
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
#4 lore raw
Quoted 20 lines · Alejandro Colomar

Hi Luca,

Quoted 3 lines · Luca Boccassi
Quoted 3 lines
Quoted 3 lines

.TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via

[...]

Quoted 12 lines
Quoted 11 lines

man/man2/move_mount.2 which would otherwise cause the unbindable mounts to be propagated · line 465

Quoted 4 lines

+.BR open_tree (2)

man/man2/move_mount.2 +3 -0
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).

The parenthetical in that position makes it unclear if you're saying that one should use open_tree(2) with OPEN_TREE_CLONE since Linux 6.15, or if you're saying that this error can happen since that version. Would you mind clarifying? I think if you mean that the error can happen since Linux 6.15, we could make it part of the paragraph tag, as in unshare(2).

Quoted 7 lines
Quoted 3 lines

I meant the former, the error is always there, but OPEN_TREE_CLONE can be used since 6.15 to avoid it. Sent v2 with this and the other fix, thanks for the prompt review.

Hmmm, I see. Why not use open_tree(2) and OPEN_TREE_CLONE before 6.15? The syscall and flag existed, AFAICS. I think we should clarify --at least in the commit message--, why that version is important.

It was just not supported at all, so it would still fail with EINVAL before 6.15 even with the clone.
Would you like me to send a v3 or would you prefer to amend the commit message yourself?

#5 lore raw

Hi Luca,

Quoted 20 lines · Luca Boccassi
Quoted 20 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

.TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via

[...]

Quoted 15 lines
Quoted 11 lines

man/man2/move_mount.2 which would otherwise cause the unbindable mounts to be propagated · line 465

Quoted 4 lines

+.BR open_tree (2)

man/man2/move_mount.2 +3 -0
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).

The parenthetical in that position makes it unclear if you're saying that one should use open_tree(2) with OPEN_TREE_CLONE since Linux 6.15, or if you're saying that this error can happen since that version. Would you mind clarifying? I think if you mean that the error can happen since Linux 6.15, we could make it part of the paragraph tag, as in unshare(2).

I meant the former, the error is always there, but OPEN_TREE_CLONE can be used since 6.15 to avoid it. Sent v2 with this and the other fix, thanks for the prompt review.

Quoted 6 lines
Quoted 3 lines

Hmmm, I see. Why not use open_tree(2) and OPEN_TREE_CLONE before 6.15? The syscall and flag existed, AFAICS. I think we should clarify --at least in the commit message--, why that version is important.

It was just not supported at all, so it would still fail with EINVAL before 6.15 even with the clone.

Thanks! What's the exact commit (or set of commits) that changed this? That would be useful for the commit message.

Quoted 2 lines

Would you like me to send a v3 or would you prefer to amend the commit message yourself?

I can amend myself.

Cheers,
Alex

Signature · 2 lines
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
#6 lore raw
Quoted 31 lines · Alejandro Colomar

Hi Luca,

Quoted 20 lines · Luca Boccassi
Quoted 20 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

.TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via

[...]

Quoted 15 lines
Quoted 11 lines

man/man2/move_mount.2 which would otherwise cause the unbindable mounts to be propagated · line 465

Quoted 4 lines

+.BR open_tree (2)

man/man2/move_mount.2 +3 -0
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).

The parenthetical in that position makes it unclear if you're saying that one should use open_tree(2) with OPEN_TREE_CLONE since Linux 6.15, or if you're saying that this error can happen since that version. Would you mind clarifying? I think if you mean that the error can happen since Linux 6.15, we could make it part of the paragraph tag, as in unshare(2).

I meant the former, the error is always there, but OPEN_TREE_CLONE can be used since 6.15 to avoid it. Sent v2 with this and the other fix, thanks for the prompt review.

Quoted 6 lines
Quoted 3 lines

Hmmm, I see. Why not use open_tree(2) and OPEN_TREE_CLONE before 6.15? The syscall and flag existed, AFAICS. I think we should clarify --at least in the commit message--, why that version is important.

It was just not supported at all, so it would still fail with EINVAL before 6.15 even with the clone.

Quoted 7 lines

Thanks! What's the exact commit (or set of commits) that changed this? That would be useful for the commit message.

Quoted 2 lines

Would you like me to send a v3 or would you prefer to amend the commit message yourself?

I can amend myself.

Sorry, I am not a kernel dev so I do not know where it was introduced exactly, and quickly skimming the commits list doesn't immediately reveal anything. I only know that by testing it, it works on 6.15 and fails earlier.

#7 lore raw

Hi Luca,

Quoted 13 lines · Luca Boccassi
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines

Hmmm, I see. Why not use open_tree(2) and OPEN_TREE_CLONE before 6.15? The syscall and flag existed, AFAICS. I think we should clarify --at least in the commit message--, why that version is important.

It was just not supported at all, so it would still fail with EINVAL before 6.15 even with the clone.

Thanks! What's the exact commit (or set of commits) that changed this? That would be useful for the commit message.

Quoted 2 lines

Would you like me to send a v3 or would you prefer to amend the commit message yourself?

Quoted 6 lines
Quoted 1 line

I can amend myself.

Sorry, I am not a kernel dev so I do not know where it was introduced exactly, and quickly skimming the commits list doesn't immediately reveal anything. I only know that by testing it, it works on 6.15 and fails earlier.

Okay, I'll wait a few days to apply the patch, in case Aleksa can comment on this. I think it would be interesting to know. But if by the end of this week we don't have any comments, I'll merge it.

Thanks!

Have a lovely day!
Alex

Signature · 2 lines
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
#8 lore raw

BTW, I'll add Askar, since it was involved in the discussion of Aleksa's patches.

Quoted 36 lines · Alejandro Colomar

Hi Luca,

Quoted 13 lines · Luca Boccassi
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines

Hmmm, I see. Why not use open_tree(2) and OPEN_TREE_CLONE before 6.15? The syscall and flag existed, AFAICS. I think we should clarify --at least in the commit message--, why that version is important.

It was just not supported at all, so it would still fail with EINVAL before 6.15 even with the clone.

Thanks! What's the exact commit (or set of commits) that changed this? That would be useful for the commit message.

Quoted 2 lines

Would you like me to send a v3 or would you prefer to amend the commit message yourself?

Quoted 6 lines
Quoted 1 line

I can amend myself.

Sorry, I am not a kernel dev so I do not know where it was introduced exactly, and quickly skimming the commits list doesn't immediately reveal anything. I only know that by testing it, it works on 6.15 and fails earlier.

Okay, I'll wait a few days to apply the patch, in case Aleksa can comment on this. I think it would be interesting to know. But if by the end of this week we don't have any comments, I'll merge it.

Thanks!

Have a lovely day!
Alex

Signature · 2 lines
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
Signature · 2 lines
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
#9 lore raw
In reply to Luca Boccassi
Quoted 38 lines · Luca Boccassi
Quoted 37 lines · Alejandro Colomar

Hi Luca,

Quoted 20 lines · Luca Boccassi
Quoted 20 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

.TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via

[...]

Quoted 15 lines
Quoted 11 lines

Review

Quoted 4 lines

+.BR open_tree (2)

(quoted diff) +3 -0
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).

The parenthetical in that position makes it unclear if you're saying that one should use open_tree(2) with OPEN_TREE_CLONE since Linux 6.15, or if you're saying that this error can happen since that version. Would you mind clarifying? I think if you mean that the error can happen since Linux 6.15, we could make it part of the paragraph tag, as in unshare(2).

I meant the former, the error is always there, but OPEN_TREE_CLONE can be used since 6.15 to avoid it. Sent v2 with this and the other fix, thanks for the prompt review.

Quoted 6 lines
Quoted 3 lines

Hmmm, I see. Why not use open_tree(2) and OPEN_TREE_CLONE before 6.15? The syscall and flag existed, AFAICS. I think we should clarify --at least in the commit message--, why that version is important.

It was just not supported at all, so it would still fail with EINVAL before 6.15 even with the clone.

Thanks! What's the exact commit (or set of commits) that changed this? That would be useful for the commit message.

Quoted 2 lines

Would you like me to send a v3 or would you prefer to amend the commit message yourself?

Quoted 6 lines
Quoted 1 line

I can amend myself.

Sorry, I am not a kernel dev so I do not know where it was introduced exactly, and quickly skimming the commits list doesn't immediately reveal anything. I only know that by testing it, it works on 6.15 and fails earlier.

If I'm understanding the new error entry correctly, this might be commit c5c12f871a30 ("fs: create detached mounts from detached mounts"), but Christian can probably verify that.

Just to double check that I understand this new error explanation -- the issue is that you had a file descriptor that you thought was a detached mount object but it was actually attached at some point, and the suggestion is to create a new detached bind-mount to use with move_mount(2)? Do you really get EINVAL in that case or does this move the mount?

Signature · 4 lines
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
https://www.cyphar.com/
#10 lore raw
Quoted 51 lines · Aleksa Sarai
Quoted 38 lines · Luca Boccassi
Quoted 37 lines · Alejandro Colomar

Hi Luca,

Quoted 20 lines · Luca Boccassi
Quoted 20 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

.TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via

[...]

Quoted 15 lines
Quoted 11 lines

Review

Quoted 4 lines

+.BR open_tree (2)

(quoted diff) +3 -0
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).

The parenthetical in that position makes it unclear if you're saying that one should use open_tree(2) with OPEN_TREE_CLONE since Linux 6.15, or if you're saying that this error can happen since that version. Would you mind clarifying? I think if you mean that the error can happen since Linux 6.15, we could make it part of the paragraph tag, as in unshare(2).

I meant the former, the error is always there, but OPEN_TREE_CLONE can be used since 6.15 to avoid it. Sent v2 with this and the other fix, thanks for the prompt review.

Quoted 6 lines
Quoted 3 lines

Hmmm, I see. Why not use open_tree(2) and OPEN_TREE_CLONE before 6.15? The syscall and flag existed, AFAICS. I think we should clarify --at least in the commit message--, why that version is important.

It was just not supported at all, so it would still fail with EINVAL before 6.15 even with the clone.

Thanks! What's the exact commit (or set of commits) that changed this? That would be useful for the commit message.

Quoted 2 lines

Would you like me to send a v3 or would you prefer to amend the commit message yourself?

Quoted 6 lines
Quoted 1 line

I can amend myself.

Sorry, I am not a kernel dev so I do not know where it was introduced exactly, and quickly skimming the commits list doesn't immediately reveal anything. I only know that by testing it, it works on 6.15 and fails earlier.

If I'm understanding the new error entry correctly, this might be commit c5c12f871a30 ("fs: create detached mounts from detached mounts"), but Christian can probably verify that.

Quoted 6 lines

Just to double check that I understand this new error explanation -- the issue is that you had a file descriptor that you thought was a detached mount object but it was actually attached at some point, and the suggestion is to create a new detached bind-mount to use with move_mount(2)? Do you really get EINVAL in that case or does this move the mount?

Almost - the use case is that I prep an image as a detached mount, and then I want to apply it multiple times, without having to reopen it again and again. If I just do 'move_mount()' multiple times, the second one returns EINVAL. From 6.15, I can do open_tree with OPEN_TREE_CLONE before applying with move_mount, and everything works.

#11 lore raw
Quoted 59 lines · Luca Boccassi
Quoted 51 lines · Aleksa Sarai
Quoted 38 lines · Luca Boccassi
Quoted 37 lines · Alejandro Colomar

Hi Luca,

Quoted 20 lines · Luca Boccassi
Quoted 20 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

.TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via

[...]

Quoted 15 lines
Quoted 11 lines

Review

Quoted 4 lines

+.BR open_tree (2)

(quoted diff) +3 -0
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).

The parenthetical in that position makes it unclear if you're saying that one should use open_tree(2) with OPEN_TREE_CLONE since Linux 6.15, or if you're saying that this error can happen since that version. Would you mind clarifying? I think if you mean that the error can happen since Linux 6.15, we could make it part of the paragraph tag, as in unshare(2).

I meant the former, the error is always there, but OPEN_TREE_CLONE can be used since 6.15 to avoid it. Sent v2 with this and the other fix, thanks for the prompt review.

Quoted 6 lines
Quoted 3 lines

Hmmm, I see. Why not use open_tree(2) and OPEN_TREE_CLONE before 6.15? The syscall and flag existed, AFAICS. I think we should clarify --at least in the commit message--, why that version is important.

It was just not supported at all, so it would still fail with EINVAL before 6.15 even with the clone.

Thanks! What's the exact commit (or set of commits) that changed this? That would be useful for the commit message.

Quoted 2 lines

Would you like me to send a v3 or would you prefer to amend the commit message yourself?

Quoted 6 lines
Quoted 1 line

I can amend myself.

Sorry, I am not a kernel dev so I do not know where it was introduced exactly, and quickly skimming the commits list doesn't immediately reveal anything. I only know that by testing it, it works on 6.15 and fails earlier.

If I'm understanding the new error entry correctly, this might be commit c5c12f871a30 ("fs: create detached mounts from detached mounts"), but Christian can probably verify that.

Quoted 6 lines

Just to double check that I understand this new error explanation -- the issue is that you had a file descriptor that you thought was a detached mount object but it was actually attached at some point, and the suggestion is to create a new detached bind-mount to use with move_mount(2)? Do you really get EINVAL in that case or does this move the mount?

Quoted 5 lines

Almost - the use case is that I prep an image as a detached mount, and then I want to apply it multiple times, without having to reopen it again and again. If I just do 'move_mount()' multiple times, the second one returns EINVAL. From 6.15, I can do open_tree with OPEN_TREE_CLONE before applying with move_mount, and everything works.

Before each move_mount(2) or just doing it once before all of them? My quick testing seems to indicate that it needs to be before each one.

I just tried the example in move_mount(2) that I copied from David, and it doesn't actually work for the reason you outlined (it doesn't work at all without OPEN_TREE_CLONE, with OPEN_TREE_CLONE the first move works because it's an attachment but the rest fail with -EINVAL).

move_mount() can also be used in conjunction with file descriptors returned from open_tree(2) or open(2):

       int fd = open_tree(AT_FDCWD, "/mnt", 0); /* open("/mnt", O_PATH); */
       move_mount(fd, "", AT_FDCWD, "/mnt2", MOVE_MOUNT_F_EMPTY_PATH);
       move_mount(fd, "", AT_FDCWD, "/mnt3", MOVE_MOUNT_F_EMPTY_PATH);
       move_mount(fd, "", AT_FDCWD, "/mnt4", MOVE_MOUNT_F_EMPTY_PATH);

This would move the mount object mounted at /mnt to /mnt2, then /mnt3, and then /mnt4.

This example needs to be reworked then...

I'm taking a look at where the error is coming from. As far as I can see, I think it's from the check_mnt() section in do_move_mount().

Signature · 4 lines
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
https://www.cyphar.com/
#12 lore raw
Quoted 61 lines · Aleksa Sarai
Quoted 59 lines · Luca Boccassi
Quoted 57 lines · Aleksa Sarai
Quoted 38 lines · Luca Boccassi
Quoted 37 lines · Alejandro Colomar

Hi Luca,

Quoted 20 lines · Luca Boccassi
Quoted 20 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

.TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via

[...]

Quoted 15 lines
Quoted 11 lines

Review

Quoted 4 lines

+.BR open_tree (2)

(quoted diff) +3 -0
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).

The parenthetical in that position makes it unclear if you're saying that one should use open_tree(2) with OPEN_TREE_CLONE since Linux 6.15, or if you're saying that this error can happen since that version. Would you mind clarifying? I think if you mean that the error can happen since Linux 6.15, we could make it part of the paragraph tag, as in unshare(2).

I meant the former, the error is always there, but OPEN_TREE_CLONE can be used since 6.15 to avoid it. Sent v2 with this and the other fix, thanks for the prompt review.

Quoted 6 lines
Quoted 3 lines

Hmmm, I see. Why not use open_tree(2) and OPEN_TREE_CLONE before 6.15? The syscall and flag existed, AFAICS. I think we should clarify --at least in the commit message--, why that version is important.

It was just not supported at all, so it would still fail with EINVAL before 6.15 even with the clone.

Thanks! What's the exact commit (or set of commits) that changed this? That would be useful for the commit message.

Quoted 2 lines

Would you like me to send a v3 or would you prefer to amend the commit message yourself?

Quoted 6 lines
Quoted 1 line

I can amend myself.

Sorry, I am not a kernel dev so I do not know where it was introduced exactly, and quickly skimming the commits list doesn't immediately reveal anything. I only know that by testing it, it works on 6.15 and fails earlier.

If I'm understanding the new error entry correctly, this might be commit c5c12f871a30 ("fs: create detached mounts from detached mounts"), but Christian can probably verify that.

Just to double check that I understand this new error explanation -- the issue is that you had a file descriptor that you thought was a detached mount object but it was actually attached at some point, and the suggestion is to create a new detached bind-mount to use with move_mount(2)? Do you really get EINVAL in that case or does this move the mount?

Quoted 8 lines
Quoted 5 lines

Almost - the use case is that I prep an image as a detached mount, and then I want to apply it multiple times, without having to reopen it again and again. If I just do 'move_mount()' multiple times, the second one returns EINVAL. From 6.15, I can do open_tree with OPEN_TREE_CLONE before applying with move_mount, and everything works.

Before each move_mount(2) or just doing it once before all of them? My quick testing seems to indicate that it needs to be before each one.

Yep, a clone before each move is what I am doing, otherwise it doesn't work

#13 lore raw
In reply to Luca Boccassi

Luca Boccassi <[email protected]>:

Quoted 5 lines

Almost - the use case is that I prep an image as a detached mount, and then I want to apply it multiple times, without having to reopen it again and again. If I just do 'move_mount()' multiple times, the second one returns EINVAL. From 6.15, I can do open_tree with OPEN_TREE_CLONE before applying with move_mount, and everything works.

This sounds like a bug. Please, give all reproduction steps. Both for EINVAL and for non-working open_tree before 6.15. I want to reproduce it.

Signature · 1 line
Askar Safin
#14 lore raw
Quoted 10 lines · Askar Safin

Luca Boccassi <[email protected]>:

Quoted 5 lines

Almost - the use case is that I prep an image as a detached mount, and then I want to apply it multiple times, without having to reopen it again and again. If I just do 'move_mount()' multiple times, the second one returns EINVAL. From 6.15, I can do open_tree with OPEN_TREE_CLONE before applying with move_mount, and everything works.

This sounds like a bug. Please, give all reproduction steps. Both for EINVAL and for non-working open_tree before 6.15. I want to reproduce it.

IIRC Christian said this was working as intended? Just fsmount() to create a detached mount, and then try to apply it multiple times with multiple move_mount(), and the second and subsequent ones will fail with EINVAL

#15 lore raw

Luca Boccassi <[email protected]>:

Quoted 4 lines

IIRC Christian said this was working as intended? Just fsmount() to create a detached mount, and then try to apply it multiple times with multiple move_mount(), and the second and subsequent ones will fail with EINVAL

I just tested current mainline kernel (67029a49db6c).
And move_mount doesn't return EINVAL in this case (move_mount succeds). This means that either EINVAL is not intended, either current mainline kernel is buggy.

I tested this in Qemu in very minimal environment (rdinit=/bin/busybox sh).

See C source below.

Signature · 44 lines
Askar Safin

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/mount.h>

#define ASSERT(cond) if (!(cond)) { \
    fprintf (stderr, "%s: assertion failed\n", #cond); \
    exit (1); \
}

#define ASSERT_ERRNO(cond) if (!(cond)) { \
    fprintf (stderr, "%d: ", __LINE__); \
    perror (#cond); \
    exit (1); \
}

int
main (void)
{
    ASSERT_ERRNO (mkdir ("/a", 0777) == 0);
    ASSERT_ERRNO (mkdir ("/b", 0777) == 0);
    ASSERT_ERRNO (mkdir ("/c", 0777) == 0);
    {
        {
            int fsfd = fsopen ("tmpfs", 0);
            ASSERT_ERRNO (fsfd != -1);
            ASSERT_ERRNO (fsconfig (fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) == 0);
            {
                int mntfd = fsmount (fsfd, 0, 0);
                ASSERT_ERRNO (mntfd != -1);
                ASSERT_ERRNO (move_mount (mntfd, "", AT_FDCWD, "/a", MOVE_MOUNT_F_EMPTY_PATH) == 0);
                ASSERT_ERRNO (move_mount (mntfd, "", AT_FDCWD, "/b", MOVE_MOUNT_F_EMPTY_PATH) == 0);
                ASSERT_ERRNO (move_mount (mntfd, "", AT_FDCWD, "/c", MOVE_MOUNT_F_EMPTY_PATH) == 0);
                ASSERT_ERRNO (close (mntfd) == 0);
            }
            ASSERT_ERRNO (close (fsfd) == 0);
        }
        ASSERT_ERRNO (umount ("/c") == 0);
    }
}
#16 lore raw
In reply to Luca Boccassi

Okay, I spent some more time researching this.

By default move_mount should work in your case.

But if we try to move mount, residing under shared mount, then move_mount will not work. This is documented here:

https://elixir.bootlin.com/linux/v6.17/source/Documentation/filesystems/sharedsubtree.rst#L497

"/" is shared by default if we booted using systemd. This is why you observing EINVAL.

I just found that this is already documented in move_mount(2):

EINVAL The source mount object's parent mount has shared mount propagation, and thus cannot be moved (as described in mount_name‐ spaces(7)).

So everything is working as intended, and no changes to manual pages are needed.

On the other hand, this is a good idea to add a bigger warning to move_mount(2) (and to mount(2), it is affected, too). I. e. to add something like this to main text of move_mount (as opposed to "ERRORS"):
"Note that systemd makes "/" shared by default. Moving mounts residing under shared mounts is prohibited, so attempting to move attached mount using move_mount likely will not work".

(I personally don't have plans to submit this as a patch.)

Signature · 1 line
Askar Safin
#17 lore raw

Hi Askar,

Quoted 20 lines · Askar Safin

Okay, I spent some more time researching this.

By default move_mount should work in your case.

But if we try to move mount, residing under shared mount, then move_mount will not work. This is documented here:

https://elixir.bootlin.com/linux/v6.17/source/Documentation/filesystems/sharedsubtree.rst#L497

"/" is shared by default if we booted using systemd. This is why you observing EINVAL.

I just found that this is already documented in move_mount(2):

EINVAL The source mount object's parent mount has shared mount propagation, and thus cannot be moved (as described in mount_name‐ spaces(7)).

So everything is working as intended, and no changes to manual pages are needed.

Quoted 6 lines

On the other hand, this is a good idea to add a bigger warning to move_mount(2) (and to mount(2), it is affected, too). I. e. to add something like this to main text of move_mount (as opposed to "ERRORS"):
"Note that systemd makes "/" shared by default. Moving mounts residing under shared mounts is prohibited, so attempting to move attached mount using move_mount likely will not work".

Maybe under a CAVEATS section?

Have a lovely day!
Alex

Quoted 4 lines

(I personally don't have plans to submit this as a patch.)

Signature · 1 line
Askar Safin
Signature · 2 lines
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
#18 lore raw
Quoted 1 line · Alejandro Colomar

Maybe under a CAVEATS section?

Yes, good idea.

Signature · 1 line
Askar Safin
#19 lore raw
In reply to Askar Safin
Quoted 13 lines · Askar Safin

Okay, I spent some more time researching this.

By default move_mount should work in your case.

But if we try to move mount, residing under shared mount, then move_mount will not work. This is documented here:

https://elixir.bootlin.com/linux/v6.17/source/Documentation/filesystems/sharedsubtree.rst#L497

"/" is shared by default if we booted using systemd. This is why you observing EINVAL.

Quoted 7 lines

I just found that this is already documented in move_mount(2):

EINVAL The source mount object's parent mount has shared mount propagation, and thus cannot be moved (as described in mount_name‐ spaces(7)).

So everything is working as intended, and no changes to manual pages are needed.

I don't think so. This was in a mount namespace, so it was not shared, it was a new image, so not shared either, and '/' was not involved at all. It's probably because you tried with a tmpfs instead of an actual image.

But it really doesn't matter, I just wanted to save some time for other people by documenting this, but it's really not worth having a discussion over it, feel free to just disregard it. Thanks.

#20 lore raw

Hi Luca,

Quoted 22 lines · Luca Boccassi
Quoted 13 lines · Askar Safin

Okay, I spent some more time researching this.

By default move_mount should work in your case.

But if we try to move mount, residing under shared mount, then move_mount will not work. This is documented here:

https://elixir.bootlin.com/linux/v6.17/source/Documentation/filesystems/sharedsubtree.rst#L497

"/" is shared by default if we booted using systemd. This is why you observing EINVAL.

Quoted 7 lines

I just found that this is already documented in move_mount(2):

EINVAL The source mount object's parent mount has shared mount propagation, and thus cannot be moved (as described in mount_name‐ spaces(7)).

So everything is working as intended, and no changes to manual pages are needed.

Quoted 8 lines

I don't think so. This was in a mount namespace, so it was not shared, it was a new image, so not shared either, and '/' was not involved at all. It's probably because you tried with a tmpfs instead of an actual image.

But it really doesn't matter, I just wanted to save some time for other people by documenting this, but it's really not worth having a discussion over it, feel free to just disregard it. Thanks.

I appreciate you wanting to save time for other people by documenting it. But we should also make sure we understand it fully before documenting it. I'd like us to continue this discussion, to be able to understand it and thus document it. I appreciate Aleksa and Askar's efforts in understanding this, and the discussion too, which helps me understand it too. I can't blindly take patches without review, and this discussion helps a lot.

Have a lovely day!
Alex

Signature · 2 lines
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
#21 lore raw

Hi Alex,

Quoted 14 lines · Alejandro Colomar
Quoted 4 lines · Luca Boccassi
Quoted 2 lines · Askar Safin

So everything is working as intended, and no changes to manual pages are needed.

Quoted 8 lines

I don't think so. This was in a mount namespace, so it was not shared, it was a new image, so not shared either, and '/' was not involved at all. It's probably because you tried with a tmpfs instead of an actual image.

But it really doesn't matter, I just wanted to save some time for other people by documenting this, but it's really not worth having a discussion over it, feel free to just disregard it. Thanks.

Quoted 7 lines

I appreciate you wanting to save time for other people by documenting it. But we should also make sure we understand it fully before documenting it. I'd like us to continue this discussion, to be able to understand it and thus document it. I appreciate Aleksa and Askar's efforts in understanding this, and the discussion too, which helps me understand it too. I can't blindly take patches without review, and this discussion helps a lot.

I have some unsolicited project management advice to offer.

I think you should say "won't" rather than "can't" in your final sentence. You are defending a point of policy--rightly so, in my view. If someone wants to argue your preference on the subject, policy is the correct ground upon which to engage.

The practice of distinguishing mechanism from policy is a valuable skill in domains outside of software design where we most often speak of them.

It's even more important in the instant context to articulate matters of policy when a contributor indulges a passive-aggressive outburst like Luca's, above. Confusion of mechanism with policy is the lever by which that sort of emotionalism operates; obviously we _could_ just do whatever a contributor wants without discussion and without interrogating the wisdom of doing so.

Regards,
Branden

#22 lore raw

Hi Branden, Luca,

Quoted 23 lines · G. Branden Robinson
Quoted 14 lines · Alejandro Colomar
Quoted 4 lines · Luca Boccassi
Quoted 2 lines · Askar Safin

So everything is working as intended, and no changes to manual pages are needed.

Quoted 8 lines

I don't think so. This was in a mount namespace, so it was not shared, it was a new image, so not shared either, and '/' was not involved at all. It's probably because you tried with a tmpfs instead of an actual image.

But it really doesn't matter, I just wanted to save some time for other people by documenting this, but it's really not worth having a discussion over it, feel free to just disregard it. Thanks.

Quoted 7 lines

I appreciate you wanting to save time for other people by documenting it. But we should also make sure we understand it fully before documenting it. I'd like us to continue this discussion, to be able to understand it and thus document it. I appreciate Aleksa and Askar's efforts in understanding this, and the discussion too, which helps me understand it too. I can't blindly take patches without review, and this discussion helps a lot.

Quoted 6 lines

I have some unsolicited project management advice to offer.

I think you should say "won't" rather than "can't" in your final sentence. You are defending a point of policy--rightly so, in my view. If someone wants to argue your preference on the subject, policy is the correct ground upon which to engage.

Actually, I think I should have said "shouldn't" instead of "can't".

I technically can (in the sense that nothing stops me from doing 'git am && git push' if I wanted to), so "can't" is not appropriate.

And I don't know what I'll do tomorrow, so "won't" is not appropriate either; I always reserve the right to change my mind later.

However, as a guideline, I "shouldn't" merge stuff without understanding it. Sometimes there are reasons for doing so, such as not having knowledgeable reviewers at hand, and not being knowledgeable myself. In this specific case, we have Aleksa and Askar willing to help, which is why I want to follow the policy.

Quoted 2 lines

The practice of distinguishing mechanism from policy is a valuable skill in domains outside of software design where we most often speak of them.

Thanks for correcting me on this.

Quoted 6 lines

It's even more important in the instant context to articulate matters of policy when a contributor indulges a passive-aggressive outburst like Luca's, above. Confusion of mechanism with policy is the lever by which that sort of emotionalism operates; obviously we _could_ just do whatever a contributor wants without discussion and without interrogating the wisdom of doing so.

I was trying to be nice with Luca. I think confronting his message, which I agree was a bit passive-aggressive, can be counter-productive in this case, where I'm interested in having him continue discussing this matter with Aleksa and Askar.

And in the case of Luca, I have a story, which I should disclose for context.

A year ago or so, I contributed (or tried to) to systemd, for my first time, and I experienced what looked to me terrible project management.
<https://github.com/systemd/systemd/pull/35275>
<https://github.com/systemd/systemd/pull/35226>
We had a heated fight, and they banned me from systemd. I didn't know Luca before, nor any of the systemd maintainers.

After some time, and seeing Luca engage (aggressively) with other people elsewhere (mostly, LWN), I have a theory, that Luca's aggressive behavior might be related to receiving a lot of hate by his work in systemd. I still don't know if it's a cause or a consequence, though.

So, I wanted to show Luca the management style we're used to here, and that a maintainer can be nice with contributors, even if they disagree.

Even if Luca has behaved in a way that I don't like elsewhere, I'd like to give him the opportunity to be nice here. And for that, I was ready to indulge his previous message.

Luca, I still would like you to engage in discussion with Aleksa and Askar to better understand this matter. Please do so. Taking some extra time to fully understand it now, can help document this better, and save many times that amount of time to other programmers.

Peace and love. :)

Have a lovely day!
Alex

Signature · 2 lines
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
#23 lore raw
In reply to Luca Boccassi

Luca Boccassi <[email protected]>:

Quoted 1 line

I don't think so. This was in a mount namespace, so it was not shared,

If it was not shared, then this seems like a bug. Please, say me reproduction steps, I will try to fix the bug.

If you don't have reproduction steps, then, at very least, say something like "this happens at line xxx of this big program".

Also, note that "unshare(CLONE_NEWNS)" and "unshare --mount" behave
differently: if you do "unshare(CLONE_NEWNS)", then all shared mounts continue to be shared. But if you do "unshare --mount", then it internally does "unshare(CLONE_NEWNS)" and then equivalent of "mount --make-rprivate", i. e. makes all mounts inside new namespace private.

Quoted 1 line

it was a new image, so not shared either, and '/' was not involved at

When you make a new mount under existing shared mount, it becomes shared, too. (I just checked this.) Also, on systemd, all mounts (not only '/') are shared by default, I just checked this, too.

Signature · 1 line
Askar Safin
#24 lore raw
In reply to Luca Boccassi
Quoted 59 lines · Luca Boccassi
Quoted 51 lines · Aleksa Sarai
Quoted 38 lines · Luca Boccassi
Quoted 37 lines · Alejandro Colomar

Hi Luca,

Quoted 20 lines · Luca Boccassi
Quoted 20 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

.TP
+.B EINVAL
+The source mount is already mounted somewhere else. Clone it via

[...]

Quoted 15 lines
Quoted 11 lines

Review

Quoted 4 lines

+.BR open_tree (2)

(quoted diff) +3 -0
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source instead (since Linux 6.15).

The parenthetical in that position makes it unclear if you're saying that one should use open_tree(2) with OPEN_TREE_CLONE since Linux 6.15, or if you're saying that this error can happen since that version. Would you mind clarifying? I think if you mean that the error can happen since Linux 6.15, we could make it part of the paragraph tag, as in unshare(2).

I meant the former, the error is always there, but OPEN_TREE_CLONE can be used since 6.15 to avoid it. Sent v2 with this and the other fix, thanks for the prompt review.

Quoted 6 lines
Quoted 3 lines

Hmmm, I see. Why not use open_tree(2) and OPEN_TREE_CLONE before 6.15? The syscall and flag existed, AFAICS. I think we should clarify --at least in the commit message--, why that version is important.

It was just not supported at all, so it would still fail with EINVAL before 6.15 even with the clone.

Thanks! What's the exact commit (or set of commits) that changed this? That would be useful for the commit message.

Quoted 2 lines

Would you like me to send a v3 or would you prefer to amend the commit message yourself?

Quoted 6 lines
Quoted 1 line

I can amend myself.

Sorry, I am not a kernel dev so I do not know where it was introduced exactly, and quickly skimming the commits list doesn't immediately reveal anything. I only know that by testing it, it works on 6.15 and fails earlier.

If I'm understanding the new error entry correctly, this might be commit c5c12f871a30 ("fs: create detached mounts from detached mounts"), but Christian can probably verify that.

Quoted 6 lines

Just to double check that I understand this new error explanation -- the issue is that you had a file descriptor that you thought was a detached mount object but it was actually attached at some point, and the suggestion is to create a new detached bind-mount to use with move_mount(2)? Do you really get EINVAL in that case or does this move the mount?

Quoted 5 lines

Almost - the use case is that I prep an image as a detached mount, and then I want to apply it multiple times, without having to reopen it again and again. If I just do 'move_mount()' multiple times, the second one returns EINVAL. From 6.15, I can do open_tree with OPEN_TREE_CLONE before applying with move_mount, and everything works.

Your use-case was to create a new detached filesystem via fsmount(). And then send that fd to multiple different mount namespaces. One of those mount namespaces would manage to attach that mount. At that point it's not possible to attach that mount in another different mount namespace again. IOW, it's fine to move it around in the same mount namespace but it's not fine to move it _across_ mount namespaces after it has been attached to one. Only a detached mount can be moved across mount namespaces freely.

And fyi, your original idea wouldn't have been able to address the use-case. Even if it would've worked you would've simply moved the same mount between different mount points defeating the purpose of having it available at multiple locations.

Being able to create detached mounts from detached mounts mounts enables that use-case. Now you can distribute the same filesystem across different mount namespaces.

#25 lore raw

PATCH v2 1/1 man/man2/move_mount.2: document EINVAL on multiple instances

In reply to [email protected]

From: Luca Boccassi <[email protected]>

open_tree() with OPEN_TREE_CLONE is needed to apply a mount multiple times, otherwise EINVAL is returned by move_mount(). Available since 6.15.

---
As requested by Aleksa on https://github.com/brauner/man-pages-md/pull/19
and based on the 'fs' branch where move_mount(2) was added

v2: semantic line break, clarify purpose of mentioning a version

 man/man2/move_mount.2 | 8 ++++++++
 1 file changed, 8 insertions(+)
man/man2/move_mount.2 +8 -0
index 13063ac1f..968e6a81a 100644
@@ -457,6 +457,14 @@ which would otherwise cause the unbindable mounts to be propagated
 was attempted,
 but one of the listed restrictions was violated.
 .TP
+.B EINVAL
+The source mount is already mounted somewhere else.
+Since Linux 6.15 it is possible to clone the mount via
+.BR open_tree (2)
+with
+.B \%OPEN_TREE_CLONE
+and use that as the source to avoid this error.
+.TP
 .B ELOOP
 Too many symbolic links encountered
 when resolving one of
Signature · 1 line
2.47.3