Skip to content

Commit 298384c

Browse files
dhowellsLinus Torvalds
authored andcommitted
iget: stop EFS from using iget() and read_inode()
Stop the EFS filesystem from using iget() and read_inode(). Replace efs_read_inode() with efs_iget(), and call that instead of iget(). efs_iget() then uses iget_locked() directly and returns a proper error code instead of an inode in the event of an error. efs_fill_super() returns any error incurred when getting the root inode instead of EACCES. [[email protected]: coding-style fixes] Signed-off-by: David Howells <[email protected]> Acked-by: Christoph Hellwig <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ce634ab commit 298384c

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

fs/efs/inode.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,26 @@ static inline void extent_copy(efs_extent *src, efs_extent *dst) {
4545
return;
4646
}
4747

48-
void efs_read_inode(struct inode *inode)
48+
struct inode *efs_iget(struct super_block *super, unsigned long ino)
4949
{
5050
int i, inode_index;
5151
dev_t device;
5252
u32 rdev;
5353
struct buffer_head *bh;
54-
struct efs_sb_info *sb = SUPER_INFO(inode->i_sb);
55-
struct efs_inode_info *in = INODE_INFO(inode);
54+
struct efs_sb_info *sb = SUPER_INFO(super);
55+
struct efs_inode_info *in;
5656
efs_block_t block, offset;
5757
struct efs_dinode *efs_inode;
58-
58+
struct inode *inode;
59+
60+
inode = iget_locked(super, ino);
61+
if (IS_ERR(inode))
62+
return ERR_PTR(-ENOMEM);
63+
if (!(inode->i_state & I_NEW))
64+
return inode;
65+
66+
in = INODE_INFO(inode);
67+
5968
/*
6069
** EFS layout:
6170
**
@@ -159,13 +168,13 @@ void efs_read_inode(struct inode *inode)
159168
break;
160169
}
161170

162-
return;
171+
unlock_new_inode(inode);
172+
return inode;
163173

164174
read_inode_error:
165175
printk(KERN_WARNING "EFS: failed to read inode %lu\n", inode->i_ino);
166-
make_bad_inode(inode);
167-
168-
return;
176+
iget_failed(inode);
177+
return ERR_PTR(-EIO);
169178
}
170179

171180
static inline efs_block_t

fs/efs/namei.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ struct dentry *efs_lookup(struct inode *dir, struct dentry *dentry, struct namei
6666
lock_kernel();
6767
inodenum = efs_find_entry(dir, dentry->d_name.name, dentry->d_name.len);
6868
if (inodenum) {
69-
if (!(inode = iget(dir->i_sb, inodenum))) {
69+
inode = efs_iget(dir->i_sb, inodenum);
70+
if (IS_ERR(inode)) {
7071
unlock_kernel();
71-
return ERR_PTR(-EACCES);
72+
return ERR_CAST(inode);
7273
}
7374
}
7475
unlock_kernel();
@@ -84,12 +85,11 @@ static struct inode *efs_nfs_get_inode(struct super_block *sb, u64 ino,
8485

8586
if (ino == 0)
8687
return ERR_PTR(-ESTALE);
87-
inode = iget(sb, ino);
88-
if (inode == NULL)
89-
return ERR_PTR(-ENOMEM);
88+
inode = efs_iget(sb, ino);
89+
if (IS_ERR(inode))
90+
return ERR_CAST(inode);
9091

91-
if (is_bad_inode(inode) ||
92-
(generation && inode->i_generation != generation)) {
92+
if (generation && inode->i_generation != generation) {
9393
iput(inode);
9494
return ERR_PTR(-ESTALE);
9595
}
@@ -116,7 +116,7 @@ struct dentry *efs_get_parent(struct dentry *child)
116116
struct dentry *parent;
117117
struct inode *inode;
118118
efs_ino_t ino;
119-
int error;
119+
long error;
120120

121121
lock_kernel();
122122

@@ -125,10 +125,11 @@ struct dentry *efs_get_parent(struct dentry *child)
125125
if (!ino)
126126
goto fail;
127127

128-
error = -EACCES;
129-
inode = iget(child->d_inode->i_sb, ino);
130-
if (!inode)
128+
inode = efs_iget(child->d_inode->i_sb, ino);
129+
if (IS_ERR(inode)) {
130+
error = PTR_ERR(inode);
131131
goto fail;
132+
}
132133

133134
error = -ENOMEM;
134135
parent = d_alloc_anon(inode);

fs/efs/super.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ static int efs_remount(struct super_block *sb, int *flags, char *data)
107107
static const struct super_operations efs_superblock_operations = {
108108
.alloc_inode = efs_alloc_inode,
109109
.destroy_inode = efs_destroy_inode,
110-
.read_inode = efs_read_inode,
111110
.put_super = efs_put_super,
112111
.statfs = efs_statfs,
113112
.remount_fs = efs_remount,
@@ -247,6 +246,7 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
247246
struct efs_sb_info *sb;
248247
struct buffer_head *bh;
249248
struct inode *root;
249+
int ret = -EINVAL;
250250

251251
sb = kzalloc(sizeof(struct efs_sb_info), GFP_KERNEL);
252252
if (!sb)
@@ -303,12 +303,18 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
303303
}
304304
s->s_op = &efs_superblock_operations;
305305
s->s_export_op = &efs_export_ops;
306-
root = iget(s, EFS_ROOTINODE);
306+
root = efs_iget(s, EFS_ROOTINODE);
307+
if (IS_ERR(root)) {
308+
printk(KERN_ERR "EFS: get root inode failed\n");
309+
ret = PTR_ERR(root);
310+
goto out_no_fs;
311+
}
312+
307313
s->s_root = d_alloc_root(root);
308-
309314
if (!(s->s_root)) {
310-
printk(KERN_ERR "EFS: get root inode failed\n");
315+
printk(KERN_ERR "EFS: get root dentry failed\n");
311316
iput(root);
317+
ret = -ENOMEM;
312318
goto out_no_fs;
313319
}
314320

@@ -318,7 +324,7 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
318324
out_no_fs:
319325
s->s_fs_info = NULL;
320326
kfree(sb);
321-
return -EINVAL;
327+
return ret;
322328
}
323329

324330
static int efs_statfs(struct dentry *dentry, struct kstatfs *buf) {

include/linux/efs_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern const struct inode_operations efs_dir_inode_operations;
4141
extern const struct file_operations efs_dir_operations;
4242
extern const struct address_space_operations efs_symlink_aops;
4343

44-
extern void efs_read_inode(struct inode *);
44+
extern struct inode *efs_iget(struct super_block *, unsigned long);
4545
extern efs_block_t efs_map_block(struct inode *, efs_block_t);
4646
extern int efs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4747

0 commit comments

Comments
 (0)