mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: hch@infradead.org, viro@ftp.linux.org.uk, torvalds@osdl.org,
	akpm@osdl.org
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	dhowells@redhat.com
Subject: [PATCH 21/32] IGET: Stop JFFS2 from using iget() and read_inode() [try #2]
Date: Thu, 04 Oct 2007 16:57:49 +0100	[thread overview]
Message-ID: <20071004155749.2814.67604.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20071004155602.2814.47731.stgit@warthog.procyon.org.uk>

Stop the JFFS2 filesystem from using iget() and read_inode().  Replace
jffs2_read_inode() with jffs2_iget(), and call that instead of iget().
jffs2_iget() then uses iget_locked() directly and returns a proper error code
instead of an inode in the event of an error.

jffs2_do_fill_super() returns any error incurred when getting the root inode
instead of EINVAL.

Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/jffs2/dir.c      |    6 +++--
 fs/jffs2/fs.c       |   56 ++++++++++++++++++++++++++++++++-------------------
 fs/jffs2/os-linux.h |    2 +-
 fs/jffs2/super.c    |    1 -
 4 files changed, 39 insertions(+), 26 deletions(-)

diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c
index c1dfca3..ca0add3 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -101,10 +101,10 @@ static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
 		ino = fd->ino;
 	up(&dir_f->sem);
 	if (ino) {
-		inode = iget(dir_i->i_sb, ino);
-		if (!inode) {
+		inode = jffs2_iget(dir_i->i_sb, ino);
+		if (IS_ERR(inode)) {
 			printk(KERN_WARNING "iget() failed for ino #%u\n", ino);
-			return (ERR_PTR(-EIO));
+			return ERR_CAST(inode);
 		}
 	}
 
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 8bc727b..900be8b 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -227,16 +227,23 @@ void jffs2_clear_inode (struct inode *inode)
 	jffs2_do_clear_inode(c, f);
 }
 
-void jffs2_read_inode (struct inode *inode)
+struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)
 {
 	struct jffs2_inode_info *f;
 	struct jffs2_sb_info *c;
 	struct jffs2_raw_inode latest_node;
 	union jffs2_device_node jdev;
+	struct inode *inode;
 	dev_t rdev = 0;
 	int ret;
 
-	D1(printk(KERN_DEBUG "jffs2_read_inode(): inode->i_ino == %lu\n", inode->i_ino));
+	D1(printk(KERN_DEBUG "jffs2_iget(): ino == %lu\n", ino));
+
+	inode = iget_locked(sb, ino);
+	if (!inode)
+		return ERR_PTR(-ENOMEM);
+	if (!(inode->i_state & I_NEW))
+		return inode;
 
 	f = JFFS2_INODE_INFO(inode);
 	c = JFFS2_SB_INFO(inode->i_sb);
@@ -247,9 +254,9 @@ void jffs2_read_inode (struct inode *inode)
 	ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node);
 
 	if (ret) {
-		make_bad_inode(inode);
 		up(&f->sem);
-		return;
+		iget_failed(inode);
+		return ERR_PTR(ret);
 	}
 	inode->i_mode = jemode_to_cpu(latest_node.mode);
 	inode->i_uid = je16_to_cpu(latest_node.uid);
@@ -300,19 +307,14 @@ void jffs2_read_inode (struct inode *inode)
 		if (f->metadata->size != sizeof(jdev.old) &&
 		    f->metadata->size != sizeof(jdev.new)) {
 			printk(KERN_NOTICE "Device node has strange size %d\n", f->metadata->size);
-			up(&f->sem);
-			jffs2_do_clear_inode(c, f);
-			make_bad_inode(inode);
-			return;
+			goto error_io;
 		}
 		D1(printk(KERN_DEBUG "Reading device numbers from flash\n"));
-		if (jffs2_read_dnode(c, f, f->metadata, (char *)&jdev, 0, f->metadata->size) < 0) {
+		ret = jffs2_read_dnode(c, f, f->metadata, (char *)&jdev, 0, f->metadata->size);
+		if (ret < 0) {
 			/* Eep */
 			printk(KERN_NOTICE "Read device numbers for inode %lu failed\n", (unsigned long)inode->i_ino);
-			up(&f->sem);
-			jffs2_do_clear_inode(c, f);
-			make_bad_inode(inode);
-			return;
+			goto error;
 		}
 		if (f->metadata->size == sizeof(jdev.old))
 			rdev = old_decode_dev(je16_to_cpu(jdev.old));
@@ -332,6 +334,16 @@ void jffs2_read_inode (struct inode *inode)
 	up(&f->sem);
 
 	D1(printk(KERN_DEBUG "jffs2_read_inode() returning\n"));
+	unlock_new_inode(inode);
+	return inode;
+
+error_io:
+	ret = -EIO;
+error:
+	up(&f->sem);
+	jffs2_do_clear_inode(c, f);
+	iget_failed(inode);
+	return ERR_PTR(ret);
 }
 
 void jffs2_dirty_inode(struct inode *inode)
@@ -511,15 +523,16 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
 	if ((ret = jffs2_do_mount_fs(c)))
 		goto out_inohash;
 
-	ret = -EINVAL;
-
 	D1(printk(KERN_DEBUG "jffs2_do_fill_super(): Getting root inode\n"));
-	root_i = iget(sb, 1);
-	if (is_bad_inode(root_i)) {
+	root_i = jffs2_iget(sb, 1);
+	if (IS_ERR(root_i)) {
 		D1(printk(KERN_WARNING "get root inode failed\n"));
-		goto out_root_i;
+		ret = PTR_ERR(root_i);
+		goto out_root;
 	}
 
+	ret = -ENOMEM;
+
 	D1(printk(KERN_DEBUG "jffs2_do_fill_super(): d_alloc_root()\n"));
 	sb->s_root = d_alloc_root(root_i);
 	if (!sb->s_root)
@@ -535,6 +548,7 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
 
  out_root_i:
 	iput(root_i);
+out_root:
 	jffs2_free_ino_caches(c);
 	jffs2_free_raw_node_refs(c);
 	if (jffs2_blocks_use_vmalloc(c))
@@ -604,9 +618,9 @@ struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
 		   jffs2_do_unlink() would need the alloc_sem and we have it.
 		   Just iget() it, and if read_inode() is necessary that's OK.
 		*/
-		inode = iget(OFNI_BS_2SFFJ(c), inum);
-		if (!inode)
-			return ERR_PTR(-ENOMEM);
+		inode = jffs2_iget(OFNI_BS_2SFFJ(c), inum);
+		if (IS_ERR(inode))
+			return ERR_CAST(inode);
 	}
 	if (is_bad_inode(inode)) {
 		printk(KERN_NOTICE "Eep. read_inode() failed for ino #%u. nlink %d\n",
diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h
index 80daea9..c1ca2f9 100644
--- a/fs/jffs2/os-linux.h
+++ b/fs/jffs2/os-linux.h
@@ -174,7 +174,7 @@ extern const struct inode_operations jffs2_symlink_inode_operations;
 
 /* fs.c */
 int jffs2_setattr (struct dentry *, struct iattr *);
-void jffs2_read_inode (struct inode *);
+struct inode *jffs2_iget(struct super_block *, unsigned long);
 void jffs2_clear_inode (struct inode *);
 void jffs2_dirty_inode(struct inode *inode);
 struct inode *jffs2_new_inode (struct inode *dir_i, int mode,
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index be2b70c..d7d2ff6 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -65,7 +65,6 @@ static const struct super_operations jffs2_super_operations =
 {
 	.alloc_inode =	jffs2_alloc_inode,
 	.destroy_inode =jffs2_destroy_inode,
-	.read_inode =	jffs2_read_inode,
 	.put_super =	jffs2_put_super,
 	.write_super =	jffs2_write_super,
 	.statfs =	jffs2_statfs,


  parent reply	other threads:[~2007-10-04 16:05 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-04 15:56 [PATCH 00/32] Remove " David Howells
2007-10-04 15:56 ` [PATCH 01/32] Add an ERR_CAST() macro to complement ERR_PTR and co. " David Howells
2007-10-05 14:46   ` Christoph Hellwig
2007-10-05 15:47   ` David Howells
2007-10-05 16:07     ` Sam Ravnborg
2007-10-05 16:19     ` David Howells
2007-10-05 16:21   ` Randy Dunlap
2007-10-04 15:56 ` [PATCH 02/32] Convert ERR_PTR(PTR_ERR(p)) instances to ERR_CAST(p) " David Howells
2007-10-04 15:56 ` [PATCH 03/32] IGET: Introduce a function to register iget failure " David Howells
2007-10-05 14:47   ` Christoph Hellwig
2007-10-04 15:56 ` [PATCH 04/32] IGET: Use iget_failed() in AFS " David Howells
2007-10-04 15:56 ` [PATCH 05/32] IGET: Use iget_failed() in GFS2 " David Howells
2007-10-04 15:56 ` [PATCH 06/32] IGET: Mark iget() and read_inode() as being obsolete " David Howells
2007-10-05 14:47   ` Christoph Hellwig
2007-10-05 15:12   ` David Howells
2007-10-05 15:21   ` David Howells
2007-10-05 15:29     ` Christoph Hellwig
2007-10-04 15:56 ` [PATCH 07/32] IGET: Stop AFFS from using iget() and read_inode() " David Howells
2007-10-04 15:56 ` [PATCH 08/32] IGET: Stop autofs " David Howells
2007-10-04 15:56 ` [PATCH 09/32] IGET: Stop BEFS " David Howells
2007-10-04 15:56 ` [PATCH 10/32] IGET: Stop BFS " David Howells
2007-10-04 15:56 ` [PATCH 11/32] IGET: Stop CIFS " David Howells
2007-10-04 15:57 ` [PATCH 12/32] IGET: Stop EFS " David Howells
2007-10-04 15:57 ` [PATCH 13/32] IGET: Stop EXT2 " David Howells
2007-10-05 12:05   ` Theodore Tso
2007-10-04 15:57 ` [PATCH 14/32] IGET: Stop EXT3 " David Howells
2007-10-09 15:41   ` Jan Kara
2007-10-04 15:57 ` [PATCH 15/32] IGET: Stop EXT4 " David Howells
2007-10-09 15:45   ` Jan Kara
2007-10-04 15:57 ` [PATCH 16/32] IGET: Stop FAT " David Howells
2007-10-04 15:57 ` [PATCH 17/32] IGET: Stop FreeVXFS " David Howells
2007-10-04 15:57 ` [PATCH 18/32] IGET: Stop FUSE " David Howells
2007-10-04 15:57 ` [PATCH 19/32] IGET: Stop HFSPLUS " David Howells
2007-10-04 15:57 ` [PATCH 20/32] IGET: Stop ISOFS from using " David Howells
2007-10-04 15:57 ` David Howells [this message]
2007-10-04 15:57 ` [PATCH 22/32] IGET: Stop JFS from using iget() and " David Howells
2007-10-04 15:57 ` [PATCH 23/32] IGET: Stop the MINIX filesystem " David Howells
2007-10-04 15:58 ` [PATCH 24/32] IGET: Stop PROCFS " David Howells
2007-10-04 15:58 ` [PATCH 25/32] IGET: Stop QNX4 " David Howells
2007-10-04 15:58 ` [PATCH 26/32] IGET: Stop ROMFS " David Howells
2007-10-04 15:58 ` [PATCH 27/32] IGET: Stop the SYSV filesystem " David Howells
2007-10-04 15:58 ` [PATCH 28/32] IGET: Stop UFS " David Howells
2007-10-04 15:58 ` [PATCH 29/32] IGET: Stop OPENPROMFS " David Howells
2007-10-04 15:58 ` [PATCH 30/32] IGET: Stop HOSTFS " David Howells
2007-10-04 15:58 ` [PATCH 31/32] IGET: Stop HPPFS " David Howells
2007-10-04 15:58 ` [PATCH 32/32] IGET: Remove iget() and the read_inode() super op as being obsolete " David Howells
2007-10-05 14:44 ` [PATCH 00/32] Remove iget() and read_inode() " David Howells

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=20071004155749.2814.67604.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=akpm@osdl.org \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    --cc=viro@ftp.linux.org.uk \
    /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

Powered by JetHome