linux-fsdevel.vger.kernel.org archive mirror
 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 08/32] IGET: Stop autofs from using iget() and read_inode() [try #2]
Date: Thu, 04 Oct 2007 16:56:43 +0100	[thread overview]
Message-ID: <20071004155643.2814.67700.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20071004155602.2814.47731.stgit@warthog.procyon.org.uk>

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

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

 fs/autofs/autofs_i.h |    1 +
 fs/autofs/inode.c    |   27 ++++++++++++++++++---------
 fs/autofs/root.c     |   22 ++++++++++++++++++----
 3 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/fs/autofs/autofs_i.h b/fs/autofs/autofs_i.h
index 8b4cca3..901a3e6 100644
--- a/fs/autofs/autofs_i.h
+++ b/fs/autofs/autofs_i.h
@@ -150,6 +150,7 @@ extern const struct file_operations autofs_root_operations;
 
 int autofs_fill_super(struct super_block *, void *, int);
 void autofs_kill_sb(struct super_block *sb);
+struct inode *autofs_iget(struct super_block *, unsigned long);
 
 /* Queue management functions */
 
diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c
index e7204d7..fc6a15e 100644
--- a/fs/autofs/inode.c
+++ b/fs/autofs/inode.c
@@ -52,10 +52,7 @@ out_kill_sb:
 	kill_anon_super(sb);
 }
 
-static void autofs_read_inode(struct inode *inode);
-
 static const struct super_operations autofs_sops = {
-	.read_inode	= autofs_read_inode,
 	.statfs		= simple_statfs,
 };
 
@@ -164,7 +161,9 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
 	s->s_time_gran = 1;
 	sbi->sb = s;
 
-	root_inode = iget(s, AUTOFS_ROOT_INO);
+	root_inode = autofs_iget(s, AUTOFS_ROOT_INO);
+	if (IS_ERR(root_inode))
+		goto fail_free;
 	root = d_alloc_root(root_inode);
 	pipe = NULL;
 
@@ -230,11 +229,17 @@ fail_unlock:
 	return -EINVAL;
 }
 
-static void autofs_read_inode(struct inode *inode)
+struct inode *autofs_iget(struct super_block *sb, unsigned long ino)
 {
-	ino_t ino = inode->i_ino;
 	unsigned int n;
-	struct autofs_sb_info *sbi = autofs_sbi(inode->i_sb);
+	struct autofs_sb_info *sbi = autofs_sbi(sb);
+	struct inode *inode;
+
+	inode = iget_locked(sb, ino);
+	if (!inode)
+		return ERR_PTR(-ENOMEM);
+	if (!(inode->i_state & I_NEW))
+		return inode;
 
 	/* Initialize to the default case (stub directory) */
 
@@ -250,7 +255,7 @@ static void autofs_read_inode(struct inode *inode)
 		inode->i_op = &autofs_root_inode_operations;
 		inode->i_fop = &autofs_root_operations;
 		inode->i_uid = inode->i_gid = 0; /* Changed in read_super */
-		return;
+		goto done;
 	} 
 	
 	inode->i_uid = inode->i_sb->s_root->d_inode->i_uid;
@@ -263,7 +268,7 @@ static void autofs_read_inode(struct inode *inode)
 		n = ino - AUTOFS_FIRST_SYMLINK;
 		if (n >= AUTOFS_MAX_SYMLINKS || !test_bit(n,sbi->symlink_bitmap)) {
 			printk("autofs: Looking for bad symlink inode %u\n", (unsigned int) ino);
-			return;
+			goto done;
 		}
 		
 		inode->i_op = &autofs_symlink_inode_operations;
@@ -275,4 +280,8 @@ static void autofs_read_inode(struct inode *inode)
 		inode->i_size = sl->len;
 		inode->i_nlink = 1;
 	}
+
+done:
+	unlock_new_inode(inode);
+	return inode;
 }
diff --git a/fs/autofs/root.c b/fs/autofs/root.c
index c148953..3aec567 100644
--- a/fs/autofs/root.c
+++ b/fs/autofs/root.c
@@ -114,8 +114,8 @@ static int try_to_fill_dentry(struct dentry *dentry, struct super_block *sb, str
 	dentry->d_time = (unsigned long) ent;
 	
 	if (!dentry->d_inode) {
-		inode = iget(sb, ent->ino);
-		if (!inode) {
+		inode = autofs_iget(sb, ent->ino);
+		if (IS_ERR(inode)) {
 			/* Failed, but leave pending for next time */
 			return 1;
 		}
@@ -274,6 +274,7 @@ static int autofs_root_symlink(struct inode *dir, struct dentry *dentry, const c
 	unsigned int n;
 	int slsize;
 	struct autofs_symlink *sl;
+	struct inode *inode;
 
 	DPRINTK(("autofs_root_symlink: %s <- ", symname));
 	autofs_say(dentry->d_name.name,dentry->d_name.len);
@@ -331,7 +332,12 @@ static int autofs_root_symlink(struct inode *dir, struct dentry *dentry, const c
 	ent->dentry = NULL;	/* We don't keep the dentry for symlinks */
 
 	autofs_hash_insert(dh,ent);
-	d_instantiate(dentry, iget(dir->i_sb,ent->ino));
+
+	inode = autofs_iget(dir->i_sb, ent->ino);
+	if (IS_ERR(inode))
+		return PTR_ERR(inode);
+
+	d_instantiate(dentry, inode);
 	unlock_kernel();
 	return 0;
 }
@@ -428,6 +434,7 @@ static int autofs_root_mkdir(struct inode *dir, struct dentry *dentry, int mode)
 	struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
 	struct autofs_dirhash *dh = &sbi->dirhash;
 	struct autofs_dir_ent *ent;
+	struct inode *inode;
 	ino_t ino;
 
 	lock_kernel();
@@ -469,7 +476,14 @@ static int autofs_root_mkdir(struct inode *dir, struct dentry *dentry, int mode)
 	autofs_hash_insert(dh,ent);
 
 	inc_nlink(dir);
-	d_instantiate(dentry, iget(dir->i_sb,ino));
+
+	inode = autofs_iget(dir->i_sb, ino);
+	if (IS_ERR(inode)) {
+		drop_nlink(dir);
+		return PTR_ERR(inode);
+	}
+
+	d_instantiate(dentry, inode);
 	unlock_kernel();
 
 	return 0;


  parent reply	other threads:[~2007-10-04 15:57 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-04 15:56 [PATCH 00/32] Remove iget() and read_inode() [try #2] 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 ` David Howells [this message]
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 ` [PATCH 21/32] IGET: Stop JFFS2 from using iget() and " David Howells
2007-10-04 15:57 ` [PATCH 22/32] IGET: Stop JFS " 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=20071004155643.2814.67700.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;
as well as URLs for NNTP newsgroup(s).