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 v7 6/8] ovl: recalc d_ino for dir cache in non-samefs case
Date: Thu,  2 Nov 2017 22:38:09 +0200	[thread overview]
Message-ID: <1509655091-13630-7-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1509655091-13630-1-git-send-email-amir73il@gmail.com>

st_ino returned by stat(2) for dirs on non-samefs is the non persistent
overlay i_ino. Update the dir cache with volatile overlay i_ino values.
Overlay dir cache and inode cache may get out of sync after child inodes
exit and re-enter inode cache. This means that user may see inconsistent
st_ino/d_ino, but user can already see inconsistent st_ino of same object
in different times, so this is better than nothing.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/overlayfs/readdir.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c
index 4f2479b6ef91..4ec95806285e 100644
--- a/fs/overlayfs/readdir.c
+++ b/fs/overlayfs/readdir.c
@@ -120,6 +120,10 @@ static bool ovl_calc_d_ino(struct ovl_readdir_data *rdd,
 	if (!rdd->dentry)
 		return false;
 
+	/* Always recalc d_ino from i_ino for dir on non-samefs */
+	if (p->type == DT_DIR && !ovl_same_sb(rdd->dentry->d_sb))
+		return true;
+
 	/* Always recalc d_ino for parent */
 	if (strcmp(p->name, "..") == 0)
 		return true;
@@ -459,9 +463,6 @@ static int ovl_cache_update_ino(struct path *path, struct ovl_cache_entry *p)
 	u64 ino = p->real_ino;
 	int err = 0;
 
-	if (!ovl_same_sb(dir->d_sb))
-		goto out;
-
 	if (p->name[0] == '.') {
 		if (p->len == 1) {
 			this = dget(dir);
@@ -484,6 +485,19 @@ static int ovl_cache_update_ino(struct path *path, struct ovl_cache_entry *p)
 	}
 
 get:
+	/*
+	 * st_ino for dirs on non-samefs is the non persistent overlay i_ino.
+	 * Update the dir cache with volatile overlay i_ino, even though
+	 * dir cache and inode cache may get out of sync after child inodes
+	 * exit and re-enter inode cache. This means that user may see
+	 * inconsistent st_ino/d_ino, but user can already see inconsistent
+	 * st_ino of same object in different times.
+	 */
+	if (p->type == DT_DIR && !ovl_same_sb(dir->d_sb)) {
+		ino = this->d_inode->i_ino;
+		goto out;
+	}
+
 	type = ovl_path_type(this);
 	if (OVL_TYPE_ORIGIN(type)) {
 		struct kstat stat;
@@ -494,7 +508,8 @@ static int ovl_cache_update_ino(struct path *path, struct ovl_cache_entry *p)
 		if (err)
 			goto fail;
 
-		WARN_ON_ONCE(dir->d_sb->s_dev != stat.dev);
+		if (ovl_same_sb(dir->d_sb))
+			WARN_ON_ONCE(dir->d_sb->s_dev != stat.dev);
 		ino = stat.ino;
 	}
 
-- 
2.7.4

  parent reply	other threads:[~2017-11-02 20:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-02 20:38 [PATCH v7 0/8] Overlayfs: constant st_ino/d_ino for non-samefs Amir Goldstein
2017-11-02 20:38 ` [PATCH v7 1/8] ovl: move include of ovl_entry.h into overlayfs.h Amir Goldstein
2017-11-02 20:38 ` [PATCH v7 2/8] ovl: re-structure overlay lower layers in-memory Amir Goldstein
2017-11-02 20:38 ` [PATCH v7 3/8] ovl: allocate anonymous devs for lowerdirs Amir Goldstein
2017-11-02 20:38 ` [PATCH v7 4/8] ovl: return anonymous st_dev for lower inodes Amir Goldstein
2017-11-02 20:38 ` [PATCH v7 5/8] ovl: relax same fs constraint for constant st_ino Amir Goldstein
2017-11-06 20:43   ` Vivek Goyal
2017-11-06 21:06     ` Amir Goldstein
2017-11-06 21:10       ` Amir Goldstein
2017-11-02 20:38 ` Amir Goldstein [this message]
2017-11-02 20:38 ` [PATCH v7 7/8] ovl: update cache version of impure parent on rename Amir Goldstein
2017-11-06  9:17   ` Miklos Szeredi
2017-11-06 10:06     ` Amir Goldstein
2017-11-06 10:39       ` Miklos Szeredi
2017-11-06 10:59         ` Amir Goldstein
2017-11-02 20:38 ` [PATCH v7 8/8] ovl: ovl_iterate_real() for all pure upper/lower in non-samefs case Amir Goldstein
2017-11-06  9:35   ` Miklos Szeredi
2017-11-06 10:08     ` Amir Goldstein
2017-11-06 10:54       ` Amir Goldstein
2017-11-06 11:45     ` Amir Goldstein
2017-11-06 13:57       ` Miklos Szeredi
2017-11-06 14:30         ` Amir Goldstein
2017-11-06 14:52           ` 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=1509655091-13630-7-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).