Skip to content

Commit be67725

Browse files
Miklos Szeredigregkh
authored andcommitted
ovl: automatically enable redirect_dir on metacopy=on
commit d47748e upstream. Current behavior is to automatically disable metacopy if redirect_dir is not enabled and proceed with the mount. If "metacopy=on" mount option was given, then this behavior can confuse the user: no mount failure, yet metacopy is disabled. This patch makes metacopy=on imply redirect_dir=on. The converse is also true: turning off full redirect with redirect_dir= {off|follow|nofollow} will disable metacopy. If both metacopy=on and redirect_dir={off|follow|nofollow} is specified, then mount will fail, since there's no way to correctly resolve the conflict. Reported-by: Daniel Walsh <dwalsh@redhat.com> Fixes: d579104 ("ovl: Provide a mount option metacopy=on/off...") Cc: <stable@vger.kernel.org> # v4.19 Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent dee4ce1 commit be67725

2 files changed

Lines changed: 35 additions & 7 deletions

File tree

‎Documentation/filesystems/overlayfs.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ pointed by REDIRECT. This should not be possible on local system as setting
286286
"trusted." xattrs will require CAP_SYS_ADMIN. But it should be possible
287287
for untrusted layers like from a pen drive.
288288

289+
Note: redirect_dir={off|nofollow|follow(*)} conflicts with metacopy=on, and
290+
results in an error.
291+
292+
(*) redirect_dir=follow only conflicts with metacopy=on if upperdir=... is
293+
given.
294+
289295
Sharing and copying layers
290296
--------------------------
291297

‎fs/overlayfs/super.c‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
472472
{
473473
char *p;
474474
int err;
475+
bool metacopy_opt = false, redirect_opt = false;
475476

476477
config->redirect_mode = kstrdup(ovl_redirect_mode_def(), GFP_KERNEL);
477478
if (!config->redirect_mode)
@@ -516,6 +517,7 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
516517
config->redirect_mode = match_strdup(&args[0]);
517518
if (!config->redirect_mode)
518519
return -ENOMEM;
520+
redirect_opt = true;
519521
break;
520522

521523
case OPT_INDEX_ON:
@@ -548,6 +550,7 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
548550

549551
case OPT_METACOPY_ON:
550552
config->metacopy = true;
553+
metacopy_opt = true;
551554
break;
552555

553556
case OPT_METACOPY_OFF:
@@ -572,13 +575,32 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
572575
if (err)
573576
return err;
574577

575-
/* metacopy feature with upper requires redirect_dir=on */
576-
if (config->upperdir && config->metacopy && !config->redirect_dir) {
577-
pr_warn("overlayfs: metadata only copy up requires \"redirect_dir=on\", falling back to metacopy=off.\n");
578-
config->metacopy = false;
579-
} else if (config->metacopy && !config->redirect_follow) {
580-
pr_warn("overlayfs: metadata only copy up requires \"redirect_dir=follow\" on non-upper mount, falling back to metacopy=off.\n");
581-
config->metacopy = false;
578+
/*
579+
* This is to make the logic below simpler. It doesn't make any other
580+
* difference, since config->redirect_dir is only used for upper.
581+
*/
582+
if (!config->upperdir && config->redirect_follow)
583+
config->redirect_dir = true;
584+
585+
/* Resolve metacopy -> redirect_dir dependency */
586+
if (config->metacopy && !config->redirect_dir) {
587+
if (metacopy_opt && redirect_opt) {
588+
pr_err("overlayfs: conflicting options: metacopy=on,redirect_dir=%s\n",
589+
config->redirect_mode);
590+
return -EINVAL;
591+
}
592+
if (redirect_opt) {
593+
/*
594+
* There was an explicit redirect_dir=... that resulted
595+
* in this conflict.
596+
*/
597+
pr_info("overlayfs: disabling metacopy due to redirect_dir=%s\n",
598+
config->redirect_mode);
599+
config->metacopy = false;
600+
} else {
601+
/* Automatically enable redirect otherwise. */
602+
config->redirect_follow = config->redirect_dir = true;
603+
}
582604
}
583605

584606
return 0;

0 commit comments

Comments
 (0)