public inbox for linux-unionfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Vivek Goyal <vgoyal@redhat.com>, linux-unionfs@vger.kernel.org
Subject: [PATCH v2 2/5] ovl: enforce 'strict' feature requirements with metacopy=on
Date: Thu,  1 Nov 2018 02:48:10 +0200	[thread overview]
Message-ID: <20181101004813.31349-3-amir73il@gmail.com> (raw)
In-Reply-To: <20181101004813.31349-1-amir73il@gmail.com>

Some overlayfs features require file handle support from underlying
filesystems and extended attributes support from upper filesystem.
We should prefer to fail the mount if those feature requirements are
not met, but for backward compatibility, we write a warning to log
and disable the feature instead.

When user asks explicitly via mount option to enable the new metacopy
feature, we do not need to worry about backward compatibility and we
can fail the mount if any of the feature requirements are not met.

Fixes: d5791044d2e5 ("ovl: Provide a mount option metacopy=on/off...")
Cc: <stable@vger.kernel.org> # v4.19
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/overlayfs/super.c | 84 +++++++++++++++++++++++++-------------------
 1 file changed, 47 insertions(+), 37 deletions(-)

diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index d91d2ba70d54..20135dd28192 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -608,6 +608,10 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
 		config->workdir = NULL;
 	}
 
+	/* Show index=off in /proc/mounts for forced r/o mount */
+	if (!config->upperdir)
+		config->index = false;
+
 	err = ovl_parse_redirect_mode(config, config->redirect_mode);
 	if (err)
 		return err;
@@ -814,13 +818,17 @@ static int ovl_lower_dir(const char *name, struct path *path,
 	 * file handles, so they require that all layers support them.
 	 */
 	fh_type = ovl_can_decode_fh(path->dentry->d_sb);
-	if ((ofs->config.nfs_export ||
-	     (ofs->config.index && ofs->config.upperdir)) && !fh_type) {
-		ofs->config.index = false;
-		ofs->config.nfs_export = false;
-		pr_warn("overlayfs: fs on '%s' does not support file handles, falling back to index=off,nfs_export=off.\n",
-			name);
-	}
+	err = ovl_feature_check(&ofs->config, &ofs->config.nfs_export,
+				fh_type, "NFS export",
+				"lower fs file handles support");
+	if (err)
+		goto out_put;
+
+	err = ovl_feature_check(&ofs->config, &ofs->config.index,
+				fh_type, "inodes index",
+				"lower fs file handles support");
+	if (err)
+		goto out_put;
 
 	/* Check if lower fs has 32bit inode numbers */
 	if (fh_type != FILEID_INO32_GEN)
@@ -1092,34 +1100,35 @@ static int ovl_make_workdir(struct ovl_fs *ofs, struct path *workpath)
 	err = ovl_do_setxattr(ofs->workdir, OVL_XATTR_OPAQUE, "0", 1, 0);
 	if (err) {
 		ofs->noxattr = true;
-		ofs->config.index = false;
-		pr_warn("overlayfs: upper fs does not support xattr, falling back to index=off.\n");
-		err = ovl_feature_check(&ofs->config, &ofs->config.metacopy,
-					!ofs->noxattr,
-					"metadata only copy up",
-					"upper fs xattr support");
-		if (err)
-			goto out;
+		pr_warn("overlayfs: upper fs does not support xattr.\n");
 	} else {
 		vfs_removexattr(ofs->workdir, OVL_XATTR_OPAQUE);
 	}
 
+	/* metacopy depends on redirect_dir which depend on xattr */
+	err = ovl_feature_check(&ofs->config, &ofs->config.metacopy,
+				!ofs->noxattr, "metadata only copy up",
+				"upper fs xattr support");
+	if (err)
+		goto out;
+
 	/* Check if upper/work fs supports file handles */
 	fh_type = ovl_can_decode_fh(ofs->workdir->d_sb);
-	if (ofs->config.index && !fh_type) {
-		ofs->config.index = false;
-		pr_warn("overlayfs: upper fs does not support file handles, falling back to index=off.\n");
-	}
+	err = ovl_feature_check(&ofs->config, &ofs->config.index,
+				!ofs->noxattr && fh_type, "inodes index",
+				"upper fs file handles and xattr support");
+	if (err)
+		goto out;
 
 	/* Check if upper fs has 32bit inode numbers */
 	if (fh_type != FILEID_INO32_GEN)
 		ofs->xino_bits = 0;
 
 	/* NFS export of r/w mount depends on index */
-	if (ofs->config.nfs_export && !ofs->config.index) {
-		pr_warn("overlayfs: NFS export requires \"index=on\", falling back to nfs_export=off.\n");
-		ofs->config.nfs_export = false;
-	}
+	err = ovl_feature_check(&ofs->config, &ofs->config.nfs_export,
+				ofs->config.index, "NFS export",
+				"\"index=on\" and upper fs file handles");
+
 out:
 	mnt_drop_write(mnt);
 	return err;
@@ -1377,10 +1386,13 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
 	} else if (!ofs->config.upperdir && stacklen == 1) {
 		pr_err("overlayfs: at least 2 lowerdir are needed while upperdir nonexistent\n");
 		goto out_err;
-	} else if (!ofs->config.upperdir && ofs->config.nfs_export &&
-		   ofs->config.redirect_follow) {
-		pr_warn("overlayfs: NFS export requires \"redirect_dir=nofollow\" on non-upper mount, falling back to nfs_export=off.\n");
-		ofs->config.nfs_export = false;
+	} else if (!ofs->config.upperdir) {
+		err = ovl_feature_check(&ofs->config, &ofs->config.nfs_export,
+					!ofs->config.redirect_follow,
+					"NFS export",
+					"\"redirect_dir=nofollow\" on non-upper mount");
+		if (err)
+			goto out_err;
 	}
 
 	err = -ENOMEM;
@@ -1522,18 +1534,16 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
 	}
 
 	/* Show index=off in /proc/mounts for forced r/o mount */
-	if (!ofs->indexdir) {
+	if (!ofs->indexdir)
 		ofs->config.index = false;
-		if (ofs->upper_mnt && ofs->config.nfs_export) {
-			pr_warn("overlayfs: NFS export requires an index dir, falling back to nfs_export=off.\n");
-			ofs->config.nfs_export = false;
-		}
-	}
 
-	if (ofs->config.metacopy && ofs->config.nfs_export) {
-		pr_warn("overlayfs: NFS export is not supported with metadata only copy up, falling back to nfs_export=off.\n");
-		ofs->config.nfs_export = false;
-	}
+	/* NFS export is not supported with metacopy or without index */
+	err = ovl_feature_check(&ofs->config, &ofs->config.nfs_export,
+				(ofs->indexdir || !ofs->upper_mnt) &&
+				!ofs->config.metacopy, "NFS export",
+				"\"metacopy=off\" and \"index=on\" on an upper mount");
+	if (err)
+		goto out_free_oe;
 
 	if (ofs->config.nfs_export)
 		sb->s_export_op = &ovl_export_operations;
-- 
2.17.1

  parent reply	other threads:[~2018-11-01  0:48 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-01  0:48 [PATCH v2 0/5] Overlayfs strict feature requirements Amir Goldstein
2018-11-01  0:48 ` [PATCH v2 1/5] ovl: return error on mount if metacopy cannot be enabled Amir Goldstein
2018-11-01 13:03   ` Vivek Goyal
2018-11-01 13:11     ` Miklos Szeredi
2018-11-01 20:41       ` Miklos Szeredi
2018-11-01 21:22         ` Amir Goldstein
2018-11-01 21:39           ` Miklos Szeredi
2018-11-05 12:57             ` Amir Goldstein
2018-11-07 11:26               ` Miklos Szeredi
2018-11-07 11:59                 ` Amir Goldstein
2018-11-07 12:09                   ` Miklos Szeredi
2018-11-01 21:25         ` Vivek Goyal
2018-11-01 21:35           ` Miklos Szeredi
2018-11-01  0:48 ` Amir Goldstein [this message]
2018-11-01  0:48 ` [PATCH v2 3/5] ovl: enforce 'strict' upper fs requirements with metacopy=on Amir Goldstein
2018-11-01  0:48 ` [PATCH v2 4/5] ovl: enforce 'strict' unique uuid requirement " Amir Goldstein
2018-11-01  0:48 ` [PATCH v2 5/5] ovl: enforce 'strict' upper fs and feature requirements with strict=on Amir Goldstein
2018-11-01  7:42 ` [PATCH v2 0/5] Overlayfs strict feature requirements Amir Goldstein
2018-11-01 13:16 ` Vivek Goyal
2018-11-01 13:42   ` Amir Goldstein
2018-11-01 14:02     ` Vivek Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181101004813.31349-3-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=vgoyal@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox