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 06/14] ovl: encode pure-upper connectable file handles
Date: Tue, 17 Oct 2017 19:44:23 +0300 [thread overview]
Message-ID: <1508258671-10800-7-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1508258671-10800-1-git-send-email-amir73il@gmail.com>
To allow reconnecting of pure upper overlay dentry based on its
real parent, we restrict the implementation to encoding of overlay
dentries with pure upper ancestry up to overlay root.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/export.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 61 insertions(+), 9 deletions(-)
diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c
index 33914f23530e..263415dd929b 100644
--- a/fs/overlayfs/export.c
+++ b/fs/overlayfs/export.c
@@ -17,15 +17,40 @@
#include "overlayfs.h"
#include "ovl_entry.h"
+/* Check if dentry is pure upper ancestry up to root */
+static bool ovl_is_pure_upper_or_root(struct dentry *dentry, int connectable)
+{
+ struct dentry *parent = NULL;
+
+ /* For non-connectable non-dir we don't need to check ancestry */
+ if (!d_is_dir(dentry) && !connectable)
+ return !ovl_dentry_lower(dentry);
+
+ dget(dentry);
+ while (!IS_ROOT(dentry) && !ovl_dentry_lower(dentry)) {
+ parent = dget_parent(dentry);
+ dput(dentry);
+ dentry = parent;
+ }
+ dput(dentry);
+
+ return dentry == dentry->d_sb->s_root;
+}
+
/* TODO: add export_operations method dentry_to_fh() ??? */
static int ovl_dentry_to_fh(struct dentry *dentry, struct fid *fid,
int *max_len, int connectable)
{
- struct dentry *lower = ovl_dentry_lower(dentry);
int type;
- /* TODO: handle encoding of non pure upper */
- if (lower)
+ /*
+ * Overlay root dir inode is hashed and encoded as pure upper, because
+ * root dir dentry is born upper and not indexed. It is not a problem
+ * that root dir is not indexed, because root dentry is pinned to cache.
+ *
+ * TODO: handle encoding of non pure upper.
+ */
+ if (!ovl_is_pure_upper_or_root(dentry, connectable))
return FILEID_INVALID;
/*
@@ -40,20 +65,47 @@ static int ovl_dentry_to_fh(struct dentry *dentry, struct fid *fid,
return type;
}
+/* Find an alias of inode. If @dir is non NULL, find a child alias */
+static struct dentry *ovl_find_alias(struct inode *inode, struct inode *dir)
+{
+ struct dentry *parent, *child;
+ struct dentry *alias = NULL;
+
+ /* Parent inode is never provided when encoding a directory */
+ if (!dir || WARN_ON(!S_ISDIR(dir->i_mode) || S_ISDIR(inode->i_mode)))
+ return d_find_alias(inode);
+
+ /*
+ * Run all of the dentries associated with this parent. Since this is
+ * a directory, there damn well better only be one item on this list.
+ */
+ spin_lock(&dir->i_lock);
+ hlist_for_each_entry(parent, &dir->i_dentry, d_u.d_alias) {
+ /* Find an alias of inode who is a child of parent */
+ spin_lock(&parent->d_lock);
+ list_for_each_entry(child, &parent->d_subdirs, d_child) {
+ if (child->d_inode == inode) {
+ alias = dget(child);
+ break;
+ }
+ }
+ spin_unlock(&parent->d_lock);
+ }
+ spin_unlock(&dir->i_lock);
+
+ return alias;
+}
+
static int ovl_encode_inode_fh(struct inode *inode, u32 *fh, int *max_len,
struct inode *parent)
{
- struct dentry *dentry = d_find_alias(inode);
+ struct dentry *dentry = ovl_find_alias(inode, parent);
int type;
if (!dentry)
return FILEID_INVALID;
- /* TODO: handle encoding of non-dir connectable file handle */
- if (parent)
- return FILEID_INVALID;
-
- type = ovl_dentry_to_fh(dentry, (struct fid *)fh, max_len, 0);
+ type = ovl_dentry_to_fh(dentry, (struct fid *)fh, max_len, !!parent);
dput(dentry);
return type;
--
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 ` Amir Goldstein [this message]
2017-10-18 18:35 ` [PATCH 06/14] ovl: encode pure-upper connectable " Amir Goldstein
2017-10-17 16:44 ` [PATCH 07/14] ovl: decode " Amir Goldstein
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-7-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).