Skip to content

Commit e33ab08

Browse files
dhowellsLinus Torvalds
authored andcommitted
iget: stop BFS from using iget() and read_inode()
Stop the BFS filesystem from using iget() and read_inode(). Replace bfs_read_inode() with bfs_iget(), and call that instead of iget(). bfs_iget() then uses iget_locked() directly and returns a proper error code instead of an inode in the event of an error. bfs_fill_super() returns any error incurred when getting the root inode instead of EINVAL. [[email protected]: build fix] Signed-off-by: David Howells <[email protected]> Acked-by: Christoph Hellwig <[email protected]> Signed-off-by: Kamalesh Babulal <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 96eb541 commit e33ab08

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

fs/bfs/bfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ static inline struct bfs_inode_info *BFS_I(struct inode *inode)
4444
#define printf(format, args...) \
4545
printk(KERN_ERR "BFS-fs: %s(): " format, __FUNCTION__, ## args)
4646

47+
/* inode.c */
48+
extern struct inode *bfs_iget(struct super_block *sb, unsigned long ino);
4749

4850
/* file.c */
4951
extern const struct inode_operations bfs_file_inops;

fs/bfs/dir.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ static struct dentry *bfs_lookup(struct inode *dir, struct dentry *dentry,
148148
if (bh) {
149149
unsigned long ino = (unsigned long)le16_to_cpu(de->ino);
150150
brelse(bh);
151-
inode = iget(dir->i_sb, ino);
152-
if (!inode) {
151+
inode = bfs_iget(dir->i_sb, ino);
152+
if (IS_ERR(inode)) {
153153
unlock_kernel();
154-
return ERR_PTR(-EACCES);
154+
return ERR_CAST(inode);
155155
}
156156
}
157157
unlock_kernel();

fs/bfs/inode.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,30 @@ MODULE_LICENSE("GPL");
3232

3333
void dump_imap(const char *prefix, struct super_block *s);
3434

35-
static void bfs_read_inode(struct inode *inode)
35+
struct inode *bfs_iget(struct super_block *sb, unsigned long ino)
3636
{
37-
unsigned long ino = inode->i_ino;
3837
struct bfs_inode *di;
38+
struct inode *inode;
3939
struct buffer_head *bh;
4040
int block, off;
4141

42+
inode = iget_locked(sb, ino);
43+
if (IS_ERR(inode))
44+
return ERR_PTR(-ENOMEM);
45+
if (!(inode->i_state & I_NEW))
46+
return inode;
47+
4248
if ((ino < BFS_ROOT_INO) || (ino > BFS_SB(inode->i_sb)->si_lasti)) {
4349
printf("Bad inode number %s:%08lx\n", inode->i_sb->s_id, ino);
44-
make_bad_inode(inode);
45-
return;
50+
goto error;
4651
}
4752

4853
block = (ino - BFS_ROOT_INO) / BFS_INODES_PER_BLOCK + 1;
4954
bh = sb_bread(inode->i_sb, block);
5055
if (!bh) {
5156
printf("Unable to read inode %s:%08lx\n", inode->i_sb->s_id,
5257
ino);
53-
make_bad_inode(inode);
54-
return;
58+
goto error;
5559
}
5660

5761
off = (ino - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK;
@@ -85,6 +89,12 @@ static void bfs_read_inode(struct inode *inode)
8589
inode->i_ctime.tv_nsec = 0;
8690

8791
brelse(bh);
92+
unlock_new_inode(inode);
93+
return inode;
94+
95+
error:
96+
iget_failed(inode);
97+
return ERR_PTR(-EIO);
8898
}
8999

90100
static int bfs_write_inode(struct inode *inode, int unused)
@@ -276,7 +286,6 @@ static void destroy_inodecache(void)
276286
static const struct super_operations bfs_sops = {
277287
.alloc_inode = bfs_alloc_inode,
278288
.destroy_inode = bfs_destroy_inode,
279-
.read_inode = bfs_read_inode,
280289
.write_inode = bfs_write_inode,
281290
.delete_inode = bfs_delete_inode,
282291
.put_super = bfs_put_super,
@@ -312,6 +321,7 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
312321
struct inode *inode;
313322
unsigned i, imap_len;
314323
struct bfs_sb_info *info;
324+
long ret = -EINVAL;
315325

316326
info = kzalloc(sizeof(*info), GFP_KERNEL);
317327
if (!info)
@@ -346,14 +356,16 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
346356
set_bit(i, info->si_imap);
347357

348358
s->s_op = &bfs_sops;
349-
inode = iget(s, BFS_ROOT_INO);
350-
if (!inode) {
359+
inode = bfs_iget(s, BFS_ROOT_INO);
360+
if (IS_ERR(inode)) {
361+
ret = PTR_ERR(inode);
351362
kfree(info->si_imap);
352363
goto out;
353364
}
354365
s->s_root = d_alloc_root(inode);
355366
if (!s->s_root) {
356367
iput(inode);
368+
ret = -ENOMEM;
357369
kfree(info->si_imap);
358370
goto out;
359371
}
@@ -404,7 +416,7 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
404416
brelse(bh);
405417
kfree(info);
406418
s->s_fs_info = NULL;
407-
return -EINVAL;
419+
return ret;
408420
}
409421

410422
static int bfs_get_sb(struct file_system_type *fs_type,

0 commit comments

Comments
 (0)