提交 1d1fe1ee 编写于 作者: D David Howells 提交者: Linus Torvalds

iget: stop EXT4 from using iget() and read_inode()

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

ext4_fill_super() returns any error incurred when getting the root inode
instead of EINVAL.
Signed-off-by: NDavid Howells <dhowells@redhat.com>
Acked-by: N"Theodore Ts'o" <tytso@mit.edu>
Acked-by: NJan Kara <jack@suse.cz>
Cc: <linux-ext4@vger.kernel.org>
Acked-by: NChristoph Hellwig <hch@lst.de>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 473043dc
...@@ -782,14 +782,15 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino) ...@@ -782,14 +782,15 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count); unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
ext4_group_t block_group; ext4_group_t block_group;
int bit; int bit;
struct buffer_head *bitmap_bh = NULL; struct buffer_head *bitmap_bh;
struct inode *inode = NULL; struct inode *inode = NULL;
long err = -EIO;
/* Error cases - e2fsck has already cleaned up for us */ /* Error cases - e2fsck has already cleaned up for us */
if (ino > max_ino) { if (ino > max_ino) {
ext4_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"bad orphan ino %lu! e2fsck was run?", ino); "bad orphan ino %lu! e2fsck was run?", ino);
goto out; goto error;
} }
block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
...@@ -798,16 +799,29 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino) ...@@ -798,16 +799,29 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
if (!bitmap_bh) { if (!bitmap_bh) {
ext4_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"inode bitmap error for orphan %lu", ino); "inode bitmap error for orphan %lu", ino);
goto out; goto error;
} }
/* Having the inode bit set should be a 100% indicator that this /* Having the inode bit set should be a 100% indicator that this
* is a valid orphan (no e2fsck run on fs). Orphans also include * is a valid orphan (no e2fsck run on fs). Orphans also include
* inodes that were being truncated, so we can't check i_nlink==0. * inodes that were being truncated, so we can't check i_nlink==0.
*/ */
if (!ext4_test_bit(bit, bitmap_bh->b_data) || if (!ext4_test_bit(bit, bitmap_bh->b_data))
!(inode = iget(sb, ino)) || is_bad_inode(inode) || goto bad_orphan;
NEXT_ORPHAN(inode) > max_ino) {
inode = ext4_iget(sb, ino);
if (IS_ERR(inode))
goto iget_failed;
if (NEXT_ORPHAN(inode) > max_ino)
goto bad_orphan;
brelse(bitmap_bh);
return inode;
iget_failed:
err = PTR_ERR(inode);
inode = NULL;
bad_orphan:
ext4_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"bad orphan inode %lu! e2fsck was run?", ino); "bad orphan inode %lu! e2fsck was run?", ino);
printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n", printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
...@@ -820,16 +834,14 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino) ...@@ -820,16 +834,14 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n", printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n",
NEXT_ORPHAN(inode)); NEXT_ORPHAN(inode));
printk(KERN_NOTICE "max_ino=%lu\n", max_ino); printk(KERN_NOTICE "max_ino=%lu\n", max_ino);
}
/* Avoid freeing blocks if we got a bad deleted inode */ /* Avoid freeing blocks if we got a bad deleted inode */
if (inode && inode->i_nlink == 0) if (inode->i_nlink == 0)
inode->i_blocks = 0; inode->i_blocks = 0;
iput(inode); iput(inode);
inode = NULL;
} }
out:
brelse(bitmap_bh); brelse(bitmap_bh);
return inode; error:
return ERR_PTR(err);
} }
unsigned long ext4_count_free_inodes (struct super_block * sb) unsigned long ext4_count_free_inodes (struct super_block * sb)
......
...@@ -2680,21 +2680,31 @@ static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode, ...@@ -2680,21 +2680,31 @@ static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
} }
} }
void ext4_read_inode(struct inode * inode) struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
{ {
struct ext4_iloc iloc; struct ext4_iloc iloc;
struct ext4_inode *raw_inode; struct ext4_inode *raw_inode;
struct ext4_inode_info *ei = EXT4_I(inode); struct ext4_inode_info *ei;
struct buffer_head *bh; struct buffer_head *bh;
struct inode *inode;
long ret;
int block; int block;
inode = iget_locked(sb, ino);
if (!inode)
return ERR_PTR(-ENOMEM);
if (!(inode->i_state & I_NEW))
return inode;
ei = EXT4_I(inode);
#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
ei->i_acl = EXT4_ACL_NOT_CACHED; ei->i_acl = EXT4_ACL_NOT_CACHED;
ei->i_default_acl = EXT4_ACL_NOT_CACHED; ei->i_default_acl = EXT4_ACL_NOT_CACHED;
#endif #endif
ei->i_block_alloc_info = NULL; ei->i_block_alloc_info = NULL;
if (__ext4_get_inode_loc(inode, &iloc, 0)) ret = __ext4_get_inode_loc(inode, &iloc, 0);
if (ret < 0)
goto bad_inode; goto bad_inode;
bh = iloc.bh; bh = iloc.bh;
raw_inode = ext4_raw_inode(&iloc); raw_inode = ext4_raw_inode(&iloc);
...@@ -2720,6 +2730,7 @@ void ext4_read_inode(struct inode * inode) ...@@ -2720,6 +2730,7 @@ void ext4_read_inode(struct inode * inode)
!(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) { !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) {
/* this inode is deleted */ /* this inode is deleted */
brelse (bh); brelse (bh);
ret = -ESTALE;
goto bad_inode; goto bad_inode;
} }
/* The only unlinked inodes we let through here have /* The only unlinked inodes we let through here have
...@@ -2758,6 +2769,7 @@ void ext4_read_inode(struct inode * inode) ...@@ -2758,6 +2769,7 @@ void ext4_read_inode(struct inode * inode)
if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize > if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
EXT4_INODE_SIZE(inode->i_sb)) { EXT4_INODE_SIZE(inode->i_sb)) {
brelse (bh); brelse (bh);
ret = -EIO;
goto bad_inode; goto bad_inode;
} }
if (ei->i_extra_isize == 0) { if (ei->i_extra_isize == 0) {
...@@ -2811,11 +2823,12 @@ void ext4_read_inode(struct inode * inode) ...@@ -2811,11 +2823,12 @@ void ext4_read_inode(struct inode * inode)
} }
brelse (iloc.bh); brelse (iloc.bh);
ext4_set_inode_flags(inode); ext4_set_inode_flags(inode);
return; unlock_new_inode(inode);
return inode;
bad_inode: bad_inode:
make_bad_inode(inode); iget_failed(inode);
return; return ERR_PTR(ret);
} }
static int ext4_inode_blocks_set(handle_t *handle, static int ext4_inode_blocks_set(handle_t *handle,
......
...@@ -1039,17 +1039,11 @@ static struct dentry *ext4_lookup(struct inode * dir, struct dentry *dentry, str ...@@ -1039,17 +1039,11 @@ static struct dentry *ext4_lookup(struct inode * dir, struct dentry *dentry, str
if (!ext4_valid_inum(dir->i_sb, ino)) { if (!ext4_valid_inum(dir->i_sb, ino)) {
ext4_error(dir->i_sb, "ext4_lookup", ext4_error(dir->i_sb, "ext4_lookup",
"bad inode number: %lu", ino); "bad inode number: %lu", ino);
inode = NULL; return ERR_PTR(-EIO);
} else
inode = iget(dir->i_sb, ino);
if (!inode)
return ERR_PTR(-EACCES);
if (is_bad_inode(inode)) {
iput(inode);
return ERR_PTR(-ENOENT);
} }
inode = ext4_iget(dir->i_sb, ino);
if (IS_ERR(inode))
return ERR_CAST(inode);
} }
return d_splice_alias(inode, dentry); return d_splice_alias(inode, dentry);
} }
...@@ -1078,18 +1072,13 @@ struct dentry *ext4_get_parent(struct dentry *child) ...@@ -1078,18 +1072,13 @@ struct dentry *ext4_get_parent(struct dentry *child)
if (!ext4_valid_inum(child->d_inode->i_sb, ino)) { if (!ext4_valid_inum(child->d_inode->i_sb, ino)) {
ext4_error(child->d_inode->i_sb, "ext4_get_parent", ext4_error(child->d_inode->i_sb, "ext4_get_parent",
"bad inode number: %lu", ino); "bad inode number: %lu", ino);
inode = NULL; return ERR_PTR(-EIO);
} else
inode = iget(child->d_inode->i_sb, ino);
if (!inode)
return ERR_PTR(-EACCES);
if (is_bad_inode(inode)) {
iput(inode);
return ERR_PTR(-ENOENT);
} }
inode = ext4_iget(child->d_inode->i_sb, ino);
if (IS_ERR(inode))
return ERR_CAST(inode);
parent = d_alloc_anon(inode); parent = d_alloc_anon(inode);
if (!parent) { if (!parent) {
iput(inode); iput(inode);
......
...@@ -779,12 +779,11 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input) ...@@ -779,12 +779,11 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
"No reserved GDT blocks, can't resize"); "No reserved GDT blocks, can't resize");
return -EPERM; return -EPERM;
} }
inode = iget(sb, EXT4_RESIZE_INO); inode = ext4_iget(sb, EXT4_RESIZE_INO);
if (!inode || is_bad_inode(inode)) { if (IS_ERR(inode)) {
ext4_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Error opening resize inode"); "Error opening resize inode");
iput(inode); return PTR_ERR(inode);
return -ENOENT;
} }
} }
......
...@@ -777,11 +777,10 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb, ...@@ -777,11 +777,10 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb,
* Currently we don't know the generation for parent directory, so * Currently we don't know the generation for parent directory, so
* a generation of 0 means "accept any" * a generation of 0 means "accept any"
*/ */
inode = iget(sb, ino); inode = ext4_iget(sb, ino);
if (inode == NULL) if (IS_ERR(inode))
return ERR_PTR(-ENOMEM); return ERR_CAST(inode);
if (is_bad_inode(inode) || if (generation && inode->i_generation != generation) {
(generation && inode->i_generation != generation)) {
iput(inode); iput(inode);
return ERR_PTR(-ESTALE); return ERR_PTR(-ESTALE);
} }
...@@ -850,7 +849,6 @@ static struct quotactl_ops ext4_qctl_operations = { ...@@ -850,7 +849,6 @@ static struct quotactl_ops ext4_qctl_operations = {
static const struct super_operations ext4_sops = { static const struct super_operations ext4_sops = {
.alloc_inode = ext4_alloc_inode, .alloc_inode = ext4_alloc_inode,
.destroy_inode = ext4_destroy_inode, .destroy_inode = ext4_destroy_inode,
.read_inode = ext4_read_inode,
.write_inode = ext4_write_inode, .write_inode = ext4_write_inode,
.dirty_inode = ext4_dirty_inode, .dirty_inode = ext4_dirty_inode,
.delete_inode = ext4_delete_inode, .delete_inode = ext4_delete_inode,
...@@ -1805,6 +1803,7 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1805,6 +1803,7 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)
unsigned long journal_devnum = 0; unsigned long journal_devnum = 0;
unsigned long def_mount_opts; unsigned long def_mount_opts;
struct inode *root; struct inode *root;
int ret = -EINVAL;
int blocksize; int blocksize;
int db_count; int db_count;
int i; int i;
...@@ -2237,19 +2236,24 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) ...@@ -2237,19 +2236,24 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)
* so we can safely mount the rest of the filesystem now. * so we can safely mount the rest of the filesystem now.
*/ */
root = iget(sb, EXT4_ROOT_INO); root = ext4_iget(sb, EXT4_ROOT_INO);
sb->s_root = d_alloc_root(root); if (IS_ERR(root)) {
if (!sb->s_root) {
printk(KERN_ERR "EXT4-fs: get root inode failed\n"); printk(KERN_ERR "EXT4-fs: get root inode failed\n");
iput(root); ret = PTR_ERR(root);
goto failed_mount4; goto failed_mount4;
} }
if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
dput(sb->s_root); iput(root);
sb->s_root = NULL;
printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n"); printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n");
goto failed_mount4; goto failed_mount4;
} }
sb->s_root = d_alloc_root(root);
if (!sb->s_root) {
printk(KERN_ERR "EXT4-fs: get root dentry failed\n");
iput(root);
ret = -ENOMEM;
goto failed_mount4;
}
ext4_setup_super (sb, es, sb->s_flags & MS_RDONLY); ext4_setup_super (sb, es, sb->s_flags & MS_RDONLY);
...@@ -2330,7 +2334,7 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) ...@@ -2330,7 +2334,7 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
kfree(sbi); kfree(sbi);
lock_kernel(); lock_kernel();
return -EINVAL; return ret;
} }
/* /*
...@@ -2366,8 +2370,8 @@ static journal_t *ext4_get_journal(struct super_block *sb, ...@@ -2366,8 +2370,8 @@ static journal_t *ext4_get_journal(struct super_block *sb,
* things happen if we iget() an unused inode, as the subsequent * things happen if we iget() an unused inode, as the subsequent
* iput() will try to delete it. */ * iput() will try to delete it. */
journal_inode = iget(sb, journal_inum); journal_inode = ext4_iget(sb, journal_inum);
if (!journal_inode) { if (IS_ERR(journal_inode)) {
printk(KERN_ERR "EXT4-fs: no journal found.\n"); printk(KERN_ERR "EXT4-fs: no journal found.\n");
return NULL; return NULL;
} }
...@@ -2380,7 +2384,7 @@ static journal_t *ext4_get_journal(struct super_block *sb, ...@@ -2380,7 +2384,7 @@ static journal_t *ext4_get_journal(struct super_block *sb,
jbd_debug(2, "Journal inode found at %p: %Ld bytes\n", jbd_debug(2, "Journal inode found at %p: %Ld bytes\n",
journal_inode, journal_inode->i_size); journal_inode, journal_inode->i_size);
if (is_bad_inode(journal_inode) || !S_ISREG(journal_inode->i_mode)) { if (!S_ISREG(journal_inode->i_mode)) {
printk(KERN_ERR "EXT4-fs: invalid journal inode.\n"); printk(KERN_ERR "EXT4-fs: invalid journal inode.\n");
iput(journal_inode); iput(journal_inode);
return NULL; return NULL;
......
...@@ -1024,7 +1024,7 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, ...@@ -1024,7 +1024,7 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
struct buffer_head *bh_result, struct buffer_head *bh_result,
int create, int extend_disksize); int create, int extend_disksize);
extern void ext4_read_inode (struct inode *); extern struct inode *ext4_iget(struct super_block *, unsigned long);
extern int ext4_write_inode (struct inode *, int); extern int ext4_write_inode (struct inode *, int);
extern int ext4_setattr (struct dentry *, struct iattr *); extern int ext4_setattr (struct dentry *, struct iattr *);
extern void ext4_delete_inode (struct inode *); extern void ext4_delete_inode (struct inode *);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册