All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Yang <liezhi.yang@windriver.com>
To: <tytso@mit.edu>, <sgh@sgh.dk>
Cc: <linux-ext4@vger.kernel.org>
Subject: [PATCH 1/2] inode.c: only update the icache for ext2_inode
Date: Fri, 3 Jan 2014 04:15:40 -0500	[thread overview]
Message-ID: <1388740541-28123-2-git-send-email-liezhi.yang@windriver.com> (raw)
In-Reply-To: <1388740541-28123-1-git-send-email-liezhi.yang@windriver.com>

We read the cache when:

bufsize == sizeof(struct ext2_inode)

so we should update the cache in the same rule, otherwise there would be
errors, for example:

cache[0]: cached ino 14 when bufsize = 128 by ext2fs_write_inode_full()
cache[1]: cached ino 14 when bufsize = 156 by ext2fs_read_inode_full()

Then update the cache:
cache[0]: cached ino 15 when bufsize = 156 by ext2fs_read_inode_full()

And the ino 14 would hit the cache[1] when bufsize = 128 (but it was
cached by bufsize = 156), so there would be errors.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 lib/ext2fs/inode.c |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c
index 573a8fa..cd85b47 100644
--- a/lib/ext2fs/inode.c
+++ b/lib/ext2fs/inode.c
@@ -614,10 +614,12 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
 #endif
 
 	/* Update the inode cache */
-	fs->icache->cache_last = (fs->icache->cache_last + 1) %
-		fs->icache->cache_size;
-	fs->icache->cache[fs->icache->cache_last].ino = ino;
-	fs->icache->cache[fs->icache->cache_last].inode = *inode;
+	if (bufsize == sizeof(struct ext2_inode)) {
+		fs->icache->cache_last = (fs->icache->cache_last + 1) %
+			fs->icache->cache_size;
+		fs->icache->cache[fs->icache->cache_last].ino = ino;
+		fs->icache->cache[fs->icache->cache_last].inode = *inode;
+	}
 
 	return 0;
 }
@@ -650,10 +652,12 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
 
 	/* Check to see if the inode cache needs to be updated */
 	if (fs->icache) {
-		for (i=0; i < fs->icache->cache_size; i++) {
-			if (fs->icache->cache[i].ino == ino) {
-				fs->icache->cache[i].inode = *inode;
-				break;
+		if (bufsize == sizeof(struct ext2_inode)) {
+			for (i=0; i < fs->icache->cache_size; i++) {
+				if (fs->icache->cache[i].ino == ino) {
+					fs->icache->cache[i].inode = *inode;
+					break;
+				}
 			}
 		}
 	} else {
-- 
1.7.10.4


  reply	other threads:[~2014-01-03  9:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-03  9:15 [PATCH 0/2] e2fsprogs: two fixes Robert Yang
2014-01-03  9:15 ` Robert Yang [this message]
2014-02-28  2:09   ` [PATCH 1/2] inode.c: only update the icache for ext2_inode Theodore Ts'o
2014-01-03  9:15 ` [PATCH 2/2] populate-extfs.sh: espace the space in the filename Robert Yang

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=1388740541-28123-2-git-send-email-liezhi.yang@windriver.com \
    --to=liezhi.yang@windriver.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sgh@sgh.dk \
    --cc=tytso@mit.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.