From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Jeff Layton <jlayton@poochiereds.net>,
"J . Bruce Fields" <bfields@fieldses.org>,
linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 07/14] ovl: decode pure-upper connectable file handles
Date: Tue, 17 Oct 2017 19:44:24 +0300 [thread overview]
Message-ID: <1508258671-10800-8-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1508258671-10800-1-git-send-email-amir73il@gmail.com>
Implement fh_to_parent() and get_parent() operations to reconnect
a pure upper overlay dentry.
This fixes a variant of xfstest test generic/426 which creates a
directory, encodes its file handle, drops caches and decodes it.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/export.c | 53 +++++++++++++++++++++++++++++++++++++++++++-----
fs/overlayfs/namei.c | 5 -----
fs/overlayfs/overlayfs.h | 5 +++++
3 files changed, 53 insertions(+), 10 deletions(-)
diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c
index 263415dd929b..9ec2fe659e38 100644
--- a/fs/overlayfs/export.c
+++ b/fs/overlayfs/export.c
@@ -138,7 +138,7 @@ static struct dentry *ovl_obtain_alias(struct super_block *sb,
}
dentry = d_obtain_alias(inode);
- if (IS_ERR(dentry))
+ if (IS_ERR(dentry) || dentry == dentry->d_sb->s_root)
return dentry;
if (dentry->d_fsdata) {
@@ -159,26 +159,33 @@ static struct dentry *ovl_obtain_alias(struct super_block *sb,
dentry->d_fsdata = oe;
ovl_dentry_set_upper_alias(dentry);
+ if (d_is_dir(upper) && ovl_is_opaquedir(upper))
+ ovl_dentry_set_opaque(dentry);
return dentry;
}
-static struct dentry *ovl_fh_to_dentry(struct super_block *sb, struct fid *fid,
- int fh_len, int fh_type)
+static struct dentry *ovl_fh_to_d(struct super_block *sb, struct fid *fid,
+ int fh_len, int fh_type, bool to_parent)
{
struct ovl_fs *ofs = sb->s_fs_info;
struct vfsmount *mnt = ofs->upper_mnt;
const struct export_operations *real_op;
+ struct dentry *(*fh_to_d)(struct super_block *, struct fid *, int, int);
struct dentry *upper;
/* TODO: handle decoding of non pure upper */
- if (!mnt)
+ if (!mnt || !mnt->mnt_sb->s_export_op)
return NULL;
real_op = mnt->mnt_sb->s_export_op;
+ fh_to_d = to_parent ? real_op->fh_to_parent : real_op->fh_to_dentry;
+ if (!fh_to_d)
+ return NULL;
+
/* TODO: decode ovl_fh format file handle */
- upper = real_op->fh_to_dentry(mnt->mnt_sb, fid, fh_len, fh_type);
+ upper = fh_to_d(mnt->mnt_sb, fid, fh_len, fh_type);
if (IS_ERR_OR_NULL(upper))
return upper;
@@ -186,7 +193,43 @@ static struct dentry *ovl_fh_to_dentry(struct super_block *sb, struct fid *fid,
return ovl_obtain_alias(sb, upper, NULL);
}
+static struct dentry *ovl_fh_to_dentry(struct super_block *sb, struct fid *fid,
+ int fh_len, int fh_type)
+{
+ return ovl_fh_to_d(sb, fid, fh_len, fh_type, false);
+}
+
+static struct dentry *ovl_fh_to_parent(struct super_block *sb, struct fid *fid,
+ int fh_len, int fh_type)
+{
+ return ovl_fh_to_d(sb, fid, fh_len, fh_type, true);
+}
+
+static struct dentry *ovl_get_parent(struct dentry *dentry)
+{
+ const struct export_operations *real_op;
+ struct dentry *upper;
+
+ /* TODO: handle connecting of non pure upper */
+ if (ovl_dentry_lower(dentry))
+ return ERR_PTR(-EACCES);
+
+ upper = ovl_dentry_upper(dentry);
+ real_op = upper->d_sb->s_export_op;
+ if (!real_op || !real_op->get_parent)
+ return ERR_PTR(-EACCES);
+
+ upper = real_op->get_parent(upper);
+ if (IS_ERR(upper))
+ return upper;
+
+ /* Find or instantiate a pure upper dentry */
+ return ovl_obtain_alias(dentry->d_sb, upper, NULL);
+}
+
const struct export_operations ovl_export_operations = {
.encode_fh = ovl_encode_inode_fh,
.fh_to_dentry = ovl_fh_to_dentry,
+ .fh_to_parent = ovl_fh_to_parent,
+ .get_parent = ovl_get_parent,
};
diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
index ce3d4930a721..d5313fb02e73 100644
--- a/fs/overlayfs/namei.c
+++ b/fs/overlayfs/namei.c
@@ -209,11 +209,6 @@ static struct dentry *ovl_decode_fh(struct ovl_fh *fh, struct vfsmount *mnt)
return origin;
}
-static bool ovl_is_opaquedir(struct dentry *dentry)
-{
- return ovl_check_dir_xattr(dentry, OVL_XATTR_OPAQUE);
-}
-
static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,
const char *name, unsigned int namelen,
size_t prelen, const char *post,
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 8ad3110a9b48..66a6447a0c2a 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -259,6 +259,11 @@ static inline bool ovl_is_impuredir(struct dentry *dentry)
return ovl_check_dir_xattr(dentry, OVL_XATTR_IMPURE);
}
+static inline bool ovl_is_opaquedir(struct dentry *dentry)
+{
+ return ovl_check_dir_xattr(dentry, OVL_XATTR_OPAQUE);
+}
+
/* namei.c */
int ovl_verify_origin(struct dentry *dentry, struct dentry *origin,
--
2.7.4
next prev parent reply other threads:[~2017-10-17 16:44 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-17 16:44 [PATCH 00/14] Overlayfs NFS export support Amir Goldstein
2017-10-17 16:44 ` [PATCH 01/14] ovl: hash all overlay inodes for NFS export Amir Goldstein
2017-10-17 16:44 ` [PATCH 02/14] ovl: grab i_count reference of lower inode Amir Goldstein
2017-10-17 16:44 ` [PATCH 03/14] ovl: use d_splice_alias() in place of d_add() in lookup Amir Goldstein
2017-10-17 16:44 ` [PATCH 04/14] ovl: copy up of disconnected dentries Amir Goldstein
2017-10-17 16:44 ` [PATCH 05/14] ovl: encode/decode pure-upper non-connectable file handles Amir Goldstein
2017-10-17 16:44 ` [PATCH 06/14] ovl: encode pure-upper connectable " Amir Goldstein
2017-10-18 18:35 ` Amir Goldstein
2017-10-17 16:44 ` Amir Goldstein [this message]
2017-10-17 16:44 ` [PATCH 08/14] ovl: encode/decode struct ovl_fh format " Amir Goldstein
2017-10-18 18:31 ` Amir Goldstein
2017-10-17 16:44 ` [PATCH 09/14] ovl: encode non-pure-upper non-connectable " Amir Goldstein
2017-10-17 16:44 ` [PATCH 10/14] ovl: obtain a non-pure-upper disconnected dentry Amir Goldstein
2017-10-17 16:44 ` [PATCH 11/14] ovl: decode non-pure-upper non-connectable file handles Amir Goldstein
2017-10-17 16:44 ` [PATCH 12/14] ovl: reconnect non-pure-upper dir " Amir Goldstein
2017-10-17 16:44 ` [PATCH 13/14] ovl: wire up NFS export support Amir Goldstein
2017-10-17 16:44 ` [PATCH 14/14] ovl: document NFS export Amir Goldstein
2017-10-18 18:43 ` [PATCH 00/14] Overlayfs NFS export support Amir Goldstein
2017-11-09 19:02 ` J . Bruce Fields
2017-11-09 19:20 ` Jeff Layton
2017-11-09 19:59 ` Amir Goldstein
2017-11-09 21:55 ` J . Bruce Fields
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=1508258671-10800-8-git-send-email-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=bfields@fieldses.org \
--cc=jlayton@poochiereds.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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;
as well as URLs for NNTP newsgroup(s).