Skip to content

Commit 52fcf70

Browse files
dhowellsLinus Torvalds
authored andcommitted
iget: stop EXT2 from using iget() and read_inode()
Stop the EXT2 filesystem from using iget() and read_inode(). Replace ext2_read_inode() with ext2_iget(), and call that instead of iget(). ext2_iget() then uses iget_locked() directly and returns a proper error code instead of an inode in the event of an error. ext2_fill_super() returns any error incurred when getting the root inode instead of EINVAL. [[email protected]: coding-style fixes] Signed-off-by: David Howells <[email protected]> Acked-by: "Theodore Ts'o" <[email protected]> Cc: <[email protected]> Acked-by: Christoph Hellwig <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 298384c commit 52fcf70

File tree

4 files changed

+46
-29
lines changed

4 files changed

+46
-29
lines changed

fs/ext2/ext2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ extern void ext2_check_inodes_bitmap (struct super_block *);
124124
extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
125125

126126
/* inode.c */
127-
extern void ext2_read_inode (struct inode *);
127+
extern struct inode *ext2_iget (struct super_block *, unsigned long);
128128
extern int ext2_write_inode (struct inode *, int);
129129
extern void ext2_put_inode (struct inode *);
130130
extern void ext2_delete_inode (struct inode *);

fs/ext2/inode.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,22 +1181,33 @@ void ext2_get_inode_flags(struct ext2_inode_info *ei)
11811181
ei->i_flags |= EXT2_DIRSYNC_FL;
11821182
}
11831183

1184-
void ext2_read_inode (struct inode * inode)
1184+
struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
11851185
{
1186-
struct ext2_inode_info *ei = EXT2_I(inode);
1187-
ino_t ino = inode->i_ino;
1186+
struct ext2_inode_info *ei;
11881187
struct buffer_head * bh;
1189-
struct ext2_inode * raw_inode = ext2_get_inode(inode->i_sb, ino, &bh);
1188+
struct ext2_inode *raw_inode;
1189+
struct inode *inode;
1190+
long ret = -EIO;
11901191
int n;
11911192

1193+
inode = iget_locked(sb, ino);
1194+
if (!inode)
1195+
return ERR_PTR(-ENOMEM);
1196+
if (!(inode->i_state & I_NEW))
1197+
return inode;
1198+
1199+
ei = EXT2_I(inode);
11921200
#ifdef CONFIG_EXT2_FS_POSIX_ACL
11931201
ei->i_acl = EXT2_ACL_NOT_CACHED;
11941202
ei->i_default_acl = EXT2_ACL_NOT_CACHED;
11951203
#endif
11961204
ei->i_block_alloc_info = NULL;
11971205

1198-
if (IS_ERR(raw_inode))
1206+
raw_inode = ext2_get_inode(inode->i_sb, ino, &bh);
1207+
if (IS_ERR(raw_inode)) {
1208+
ret = PTR_ERR(raw_inode);
11991209
goto bad_inode;
1210+
}
12001211

12011212
inode->i_mode = le16_to_cpu(raw_inode->i_mode);
12021213
inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
@@ -1220,6 +1231,7 @@ void ext2_read_inode (struct inode * inode)
12201231
if (inode->i_nlink == 0 && (inode->i_mode == 0 || ei->i_dtime)) {
12211232
/* this inode is deleted */
12221233
brelse (bh);
1234+
ret = -ESTALE;
12231235
goto bad_inode;
12241236
}
12251237
inode->i_blocks = le32_to_cpu(raw_inode->i_blocks);
@@ -1286,11 +1298,12 @@ void ext2_read_inode (struct inode * inode)
12861298
}
12871299
brelse (bh);
12881300
ext2_set_inode_flags(inode);
1289-
return;
1301+
unlock_new_inode(inode);
1302+
return inode;
12901303

12911304
bad_inode:
1292-
make_bad_inode(inode);
1293-
return;
1305+
iget_failed(inode);
1306+
return ERR_PTR(ret);
12941307
}
12951308

12961309
static int ext2_update_inode(struct inode * inode, int do_sync)

fs/ext2/namei.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, str
6363
ino = ext2_inode_by_name(dir, dentry);
6464
inode = NULL;
6565
if (ino) {
66-
inode = iget(dir->i_sb, ino);
67-
if (!inode)
68-
return ERR_PTR(-EACCES);
66+
inode = ext2_iget(dir->i_sb, ino);
67+
if (IS_ERR(inode))
68+
return ERR_CAST(inode);
6969
}
7070
return d_splice_alias(inode, dentry);
7171
}
@@ -83,10 +83,10 @@ struct dentry *ext2_get_parent(struct dentry *child)
8383
ino = ext2_inode_by_name(child->d_inode, &dotdot);
8484
if (!ino)
8585
return ERR_PTR(-ENOENT);
86-
inode = iget(child->d_inode->i_sb, ino);
86+
inode = ext2_iget(child->d_inode->i_sb, ino);
8787

88-
if (!inode)
89-
return ERR_PTR(-EACCES);
88+
if (IS_ERR(inode))
89+
return ERR_CAST(inode);
9090
parent = d_alloc_anon(inode);
9191
if (!parent) {
9292
iput(inode);

fs/ext2/super.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ static ssize_t ext2_quota_write(struct super_block *sb, int type, const char *da
296296
static const struct super_operations ext2_sops = {
297297
.alloc_inode = ext2_alloc_inode,
298298
.destroy_inode = ext2_destroy_inode,
299-
.read_inode = ext2_read_inode,
300299
.write_inode = ext2_write_inode,
301300
.delete_inode = ext2_delete_inode,
302301
.put_super = ext2_put_super,
@@ -326,11 +325,10 @@ static struct inode *ext2_nfs_get_inode(struct super_block *sb,
326325
* it might be "neater" to call ext2_get_inode first and check
327326
* if the inode is valid.....
328327
*/
329-
inode = iget(sb, ino);
330-
if (inode == NULL)
331-
return ERR_PTR(-ENOMEM);
332-
if (is_bad_inode(inode) ||
333-
(generation && inode->i_generation != generation)) {
328+
inode = ext2_iget(sb, ino);
329+
if (IS_ERR(inode))
330+
return ERR_CAST(inode);
331+
if (generation && inode->i_generation != generation) {
334332
/* we didn't find the right inode.. */
335333
iput(inode);
336334
return ERR_PTR(-ESTALE);
@@ -746,6 +744,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
746744
unsigned long logic_sb_block;
747745
unsigned long offset = 0;
748746
unsigned long def_mount_opts;
747+
long ret = -EINVAL;
749748
int blocksize = BLOCK_SIZE;
750749
int db_count;
751750
int i, j;
@@ -1041,19 +1040,24 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
10411040
sb->s_op = &ext2_sops;
10421041
sb->s_export_op = &ext2_export_ops;
10431042
sb->s_xattr = ext2_xattr_handlers;
1044-
root = iget(sb, EXT2_ROOT_INO);
1045-
sb->s_root = d_alloc_root(root);
1046-
if (!sb->s_root) {
1047-
iput(root);
1048-
printk(KERN_ERR "EXT2-fs: get root inode failed\n");
1043+
root = ext2_iget(sb, EXT2_ROOT_INO);
1044+
if (IS_ERR(root)) {
1045+
ret = PTR_ERR(root);
10491046
goto failed_mount3;
10501047
}
10511048
if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
1052-
dput(sb->s_root);
1053-
sb->s_root = NULL;
1049+
iput(root);
10541050
printk(KERN_ERR "EXT2-fs: corrupt root inode, run e2fsck\n");
10551051
goto failed_mount3;
10561052
}
1053+
1054+
sb->s_root = d_alloc_root(root);
1055+
if (!sb->s_root) {
1056+
iput(root);
1057+
printk(KERN_ERR "EXT2-fs: get root inode failed\n");
1058+
ret = -ENOMEM;
1059+
goto failed_mount3;
1060+
}
10571061
if (EXT2_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL))
10581062
ext2_warning(sb, __FUNCTION__,
10591063
"mounting ext3 filesystem as ext2");
@@ -1080,7 +1084,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
10801084
failed_sbi:
10811085
sb->s_fs_info = NULL;
10821086
kfree(sbi);
1083-
return -EINVAL;
1087+
return ret;
10841088
}
10851089

10861090
static void ext2_commit_super (struct super_block * sb,

0 commit comments

Comments
 (0)