linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Chandan Rajendra <chandan@linux.vnet.ibm.com>,
	Vivek Goyal <vgoyal@redhat.com>,
	linux-unionfs@vger.kernel.org
Subject: [PATCH v8 4/9] ovl: factor out ovl_map_dev_ino() helper
Date: Tue,  7 Nov 2017 18:58:04 +0200	[thread overview]
Message-ID: <1510073889-11657-5-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1510073889-11657-1-git-send-email-amir73il@gmail.com>

A helper for ovl_getattr() to map the values of st_dev and st_ino
according to constant st_ino rules.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/overlayfs/inode.c | 52 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index b772e5a2a730..6c54ecff56ee 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -58,6 +58,34 @@ int ovl_setattr(struct dentry *dentry, struct iattr *attr)
 	return err;
 }
 
+static int ovl_map_dev_ino(struct dentry *dentry, struct kstat *stat)
+{
+	bool samefs = ovl_same_sb(dentry->d_sb);
+
+	if (samefs) {
+		/*
+		 * When all layers are on the same fs, all real inode
+		 * number are unique, so we use the overlay st_dev,
+		 * which is friendly to du -x.
+		 */
+		stat->dev = dentry->d_sb->s_dev;
+	} else if (S_ISDIR(dentry->d_inode->i_mode)) {
+		/*
+		 * Always use the overlay st_dev for directories, so 'find
+		 * -xdev' will scan the entire overlay mount and won't cross the
+		 * overlay mount boundaries.
+		 *
+		 * If not all layers are on the same fs the pair {real st_ino;
+		 * overlay st_dev} is not unique, so use the non persistent
+		 * overlay st_ino for directories.
+		 */
+		stat->dev = dentry->d_sb->s_dev;
+		stat->ino = dentry->d_inode->i_ino;
+	}
+
+	return 0;
+}
+
 int ovl_getattr(const struct path *path, struct kstat *stat,
 		u32 request_mask, unsigned int flags)
 {
@@ -75,13 +103,10 @@ int ovl_getattr(const struct path *path, struct kstat *stat,
 		goto out;
 
 	/*
-	 * When all layers are on the same fs, all real inode number are
-	 * unique, so we use the overlay st_dev, which is friendly to du -x.
-	 *
-	 * We also use st_ino of the copy up origin, if we know it.
+	 * When all layers are on the same fs, we use st_ino of copy up origin.
 	 * This guaranties constant st_dev/st_ino across copy up.
 	 *
-	 * If filesystem supports NFS export ops, this also guaranties
+	 * If lower filesystem supports NFS file handles, this also guaranties
 	 * persistent st_ino across mount cycle.
 	 */
 	if (ovl_same_sb(dentry->d_sb)) {
@@ -108,21 +133,12 @@ int ovl_getattr(const struct path *path, struct kstat *stat,
 			    ovl_test_flag(OVL_INDEX, d_inode(dentry)))
 				stat->ino = lowerstat.ino;
 		}
-		stat->dev = dentry->d_sb->s_dev;
-	} else if (is_dir) {
-		/*
-		 * If not all layers are on the same fs the pair {real st_ino;
-		 * overlay st_dev} is not unique, so use the non persistent
-		 * overlay st_ino.
-		 *
-		 * Always use the overlay st_dev for directories, so 'find
-		 * -xdev' will scan the entire overlay mount and won't cross the
-		 * overlay mount boundaries.
-		 */
-		stat->dev = dentry->d_sb->s_dev;
-		stat->ino = dentry->d_inode->i_ino;
 	}
 
+	err = ovl_map_dev_ino(dentry, stat);
+	if (err)
+		goto out;
+
 	/*
 	 * It's probably not worth it to count subdirs to get the
 	 * correct link count.  nlink=1 seems to pacify 'find' and
-- 
2.7.4

  parent reply	other threads:[~2017-11-07 16:57 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-07 16:58 [PATCH v8 0/9] Overlayfs: constant st_ino/d_ino for non-samefs Amir Goldstein
2017-11-07 16:58 ` [PATCH v8 1/9] ovl: move include of ovl_entry.h into overlayfs.h Amir Goldstein
2017-11-07 16:58 ` [PATCH v8 2/9] ovl: re-structure overlay lower layers in-memory Amir Goldstein
2017-11-07 16:58 ` [PATCH v8 3/9] ovl: allocate anonymous devs for lowerdirs Amir Goldstein
2017-11-07 16:58 ` Amir Goldstein [this message]
2017-11-07 16:58 ` [PATCH v8 5/9] ovl: return anonymous st_dev for lower inodes Amir Goldstein
2017-11-07 16:58 ` [PATCH v8 6/9] ovl: relax same fs constraint for constant st_ino Amir Goldstein
2017-11-07 16:58 ` [PATCH v8 7/9] ovl: constant st_ino for non-samefs with xino Amir Goldstein
2017-11-07 16:58 ` [PATCH v8 8/9] ovl: consistent d_ino " Amir Goldstein
2017-11-07 16:58 ` [PATCH v8 9/9] ovl: add support for 'xino' mount option Amir Goldstein
2017-11-07 19:39 ` [PATCH v8 0/9] Overlayfs: constant st_ino/d_ino for non-samefs Vivek Goyal
2017-11-07 19:56   ` Amir Goldstein
2017-11-08 10:53 ` Miklos Szeredi
2017-11-08 12:01   ` Amir Goldstein
2017-11-08 13:40     ` Amir Goldstein
2017-11-08 16:50       ` Amir Goldstein
2017-11-09  9:33         ` Miklos Szeredi
2017-11-09 11:25           ` Amir Goldstein
2017-11-10  9:24             ` Amir Goldstein
2017-11-08 18:16       ` Amir Goldstein
2018-03-17  8:29   ` Amir Goldstein
2018-03-22 14:19     ` Miklos Szeredi
2018-03-22 15:07       ` Amir Goldstein
2018-03-22 15:36         ` Miklos Szeredi
2018-03-23 14:00           ` Vivek Goyal
2018-03-23 16:05             ` Miklos Szeredi

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=1510073889-11657-5-git-send-email-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=chandan@linux.vnet.ibm.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;
as well as URLs for NNTP newsgroup(s).