Skip to content

Commit

Permalink
mount: Use the new lowerdir+ and datadir+ options
Browse files Browse the repository at this point in the history
These were added in Linux 6.7 and replace the old append mechanism
which now no longer work. See commit 24e16e385f for details of this.

Also, I added a check that we're actually using the real new mount api
rather than the legacy implementation of it, because otherwise we will
not see error reports during fsconfig, which this code relies on.

Signed-off-by: Alexander Larsson <[email protected]>
  • Loading branch information
alexlarsson committed Jan 29, 2024
1 parent bd6ce95 commit f884f57
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions libcomposefs/lcfs-mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,14 @@ static errint_t lcfs_mount_ovl(struct lcfs_mount_state_s *state, char *imagemoun
if (fd_fs < 0)
return -errno;

int res = syscall_fsconfig(fd_fs, FSCONFIG_SET_STRING, "metacopy", "on", 0);
/* Ensure overlayfs is fully supporting the new mount api, not just
via the legacy mechanism that doesn't validate options */
int res = syscall_fsconfig(fd_fs, FSCONFIG_SET_STRING, "unsupported",
"unsupported", 0);
if (res == 0)
return -ENOSYS;

res = syscall_fsconfig(fd_fs, FSCONFIG_SET_STRING, "metacopy", "on", 0);
if (res < 0)
return -errno;

Expand All @@ -395,34 +402,29 @@ static errint_t lcfs_mount_ovl(struct lcfs_mount_state_s *state, char *imagemoun
}

/* Here we're using the new mechanism to append to lowerdir that was added in
* 6.5 (commit b36a5780cb44), because that is the only way to handle escaping
* 6.7 (24e16e385f227), because that is the only way to handle escaping
* of commas (i.e. we don't need to in this case) with the new mount api.
* Also, since 6.5 has data-only lowerdir support we can just always use it.
* Also, since 6.7 has data-only lowerdir support we can just always use it.
*
* For older kernels a lack of append support will make the mount fail with EINVAL
* and print an "empty lowerdir" error, and a lack of comma in the options will
* cause the fsconfig to fail with EINVAL. If any of these happen we fall back to
* For older kernels a lack of append support will make the mount fail with EINVAL,
* and a lack of comma in the options will cause the fsconfig to fail with EINVAL. If any of these happen we fall back to
* the legacy implementation (via ENOSYS).
*/
res = syscall_fsconfig(fd_fs, FSCONFIG_SET_STRING, "lowerdir", imagemount, 0);
/* EINVAL probably the lack of support for commas in options as per above, fallback */
if (errno == EINVAL)
return -ENOSYS;
if (res < 0)
res = syscall_fsconfig(fd_fs, FSCONFIG_SET_STRING, "lowerdir+",
imagemount, 0);
if (res < 0) {
/* EINVAL lack of support for appending as per above, fallback */
if (errno == EINVAL)
return -ENOSYS;
return -errno;
}

for (size_t i = 0; i < state->options->n_objdirs; i++) {
const char *objdir = state->options->objdirs[i];
cleanup_free char *opt = malloc(strlen(objdir) + 2 + 1);
if (opt == NULL)
return -ENOMEM;
strcpy(opt, "::"); /* starting with : means we append a dataonly lowerdir */
strcat(opt, objdir);

res = syscall_fsconfig(fd_fs, FSCONFIG_SET_STRING, "lowerdir",
opt, 0);
res = syscall_fsconfig(fd_fs, FSCONFIG_SET_STRING, "datadir+",
objdir, 0);
if (res < 0) {
/* EINVAL probably the lack of support for commas in options as per above, fallback */
/* EINVAL lack of support for appending as per above, fallback */
if (errno == EINVAL)
return -ENOSYS;
return -errno;
Expand All @@ -433,7 +435,7 @@ static errint_t lcfs_mount_ovl(struct lcfs_mount_state_s *state, char *imagemoun
res = syscall_fsconfig(fd_fs, FSCONFIG_SET_STRING, "upperdir",
options->upperdir, 0);
if (res < 0) {
/* EINVAL probably the lack of support for commas in options as per above, fallback */
/* EINVAL lack of support for appending as per above, fallback */
if (errno == EINVAL)
return -ENOSYS;
return -errno;
Expand Down

0 comments on commit f884f57

Please sign in to comment.