Skip to content

Commit b55c460

Browse files
dhowellsLinus Torvalds
authored andcommitted
iget: stop UFS from using iget() and read_inode()
Stop the UFS filesystem from using iget() and read_inode(). Replace ufs_read_inode() with ufs_iget(), and call that instead of iget(). ufs_iget() then uses iget_locked() directly and returns a proper error code instead of an inode in the event of an error. ufs_fill_super() returns any error incurred when getting the root inode instead of EINVAL. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: David Howells <dhowells@redhat.com> Cc: Evgeniy Dushistov <dushistov@mail.ru> Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b8e1343 commit b55c460

4 files changed

Lines changed: 33 additions & 23 deletions

File tree

‎fs/ufs/inode.c‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -714,26 +714,30 @@ static int ufs2_read_inode(struct inode *inode, struct ufs2_inode *ufs2_inode)
714714
return 0;
715715
}
716716

717-
void ufs_read_inode(struct inode * inode)
717+
struct inode *ufs_iget(struct super_block *sb, unsigned long ino)
718718
{
719-
struct ufs_inode_info *ufsi = UFS_I(inode);
720-
struct super_block * sb;
721-
struct ufs_sb_private_info * uspi;
719+
struct ufs_inode_info *ufsi;
720+
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
722721
struct buffer_head * bh;
722+
struct inode *inode;
723723
int err;
724724

725-
UFSD("ENTER, ino %lu\n", inode->i_ino);
726-
727-
sb = inode->i_sb;
728-
uspi = UFS_SB(sb)->s_uspi;
725+
UFSD("ENTER, ino %lu\n", ino);
729726

730-
if (inode->i_ino < UFS_ROOTINO ||
731-
inode->i_ino > (uspi->s_ncg * uspi->s_ipg)) {
727+
if (ino < UFS_ROOTINO || ino > (uspi->s_ncg * uspi->s_ipg)) {
732728
ufs_warning(sb, "ufs_read_inode", "bad inode number (%lu)\n",
733-
inode->i_ino);
734-
goto bad_inode;
729+
ino);
730+
return ERR_PTR(-EIO);
735731
}
736732

733+
inode = iget_locked(sb, ino);
734+
if (!inode)
735+
return ERR_PTR(-ENOMEM);
736+
if (!(inode->i_state & I_NEW))
737+
return inode;
738+
739+
ufsi = UFS_I(inode);
740+
737741
bh = sb_bread(sb, uspi->s_sbbase + ufs_inotofsba(inode->i_ino));
738742
if (!bh) {
739743
ufs_warning(sb, "ufs_read_inode", "unable to read inode %lu\n",
@@ -765,10 +769,12 @@ void ufs_read_inode(struct inode * inode)
765769
brelse(bh);
766770

767771
UFSD("EXIT\n");
768-
return;
772+
unlock_new_inode(inode);
773+
return inode;
769774

770775
bad_inode:
771-
make_bad_inode(inode);
776+
iget_failed(inode);
777+
return ERR_PTR(-EIO);
772778
}
773779

774780
static void ufs1_update_inode(struct inode *inode, struct ufs_inode *ufs_inode)

‎fs/ufs/namei.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ static struct dentry *ufs_lookup(struct inode * dir, struct dentry *dentry, stru
5757
lock_kernel();
5858
ino = ufs_inode_by_name(dir, dentry);
5959
if (ino) {
60-
inode = iget(dir->i_sb, ino);
61-
if (!inode) {
60+
inode = ufs_iget(dir->i_sb, ino);
61+
if (IS_ERR(inode)) {
6262
unlock_kernel();
63-
return ERR_PTR(-EACCES);
63+
return ERR_CAST(inode);
6464
}
6565
}
6666
unlock_kernel();

‎fs/ufs/super.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
633633
unsigned block_size, super_block_size;
634634
unsigned flags;
635635
unsigned super_block_offset;
636+
int ret = -EINVAL;
636637

637638
uspi = NULL;
638639
ubh = NULL;
@@ -1065,12 +1066,16 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
10651066
uspi->s_maxsymlinklen =
10661067
fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen);
10671068

1068-
inode = iget(sb, UFS_ROOTINO);
1069-
if (!inode || is_bad_inode(inode))
1069+
inode = ufs_iget(sb, UFS_ROOTINO);
1070+
if (IS_ERR(inode)) {
1071+
ret = PTR_ERR(inode);
10701072
goto failed;
1073+
}
10711074
sb->s_root = d_alloc_root(inode);
1072-
if (!sb->s_root)
1075+
if (!sb->s_root) {
1076+
ret = -ENOMEM;
10731077
goto dalloc_failed;
1078+
}
10741079

10751080
ufs_setup_cstotal(sb);
10761081
/*
@@ -1092,7 +1097,7 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
10921097
kfree(sbi);
10931098
sb->s_fs_info = NULL;
10941099
UFSD("EXIT (FAILED)\n");
1095-
return -EINVAL;
1100+
return ret;
10961101

10971102
failed_nomem:
10981103
UFSD("EXIT (NOMEM)\n");
@@ -1326,7 +1331,6 @@ static ssize_t ufs_quota_write(struct super_block *, int, const char *, size_t,
13261331
static const struct super_operations ufs_super_ops = {
13271332
.alloc_inode = ufs_alloc_inode,
13281333
.destroy_inode = ufs_destroy_inode,
1329-
.read_inode = ufs_read_inode,
13301334
.write_inode = ufs_write_inode,
13311335
.delete_inode = ufs_delete_inode,
13321336
.put_super = ufs_put_super,

‎fs/ufs/ufs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ extern void ufs_free_inode (struct inode *inode);
106106
extern struct inode * ufs_new_inode (struct inode *, int);
107107

108108
/* inode.c */
109-
extern void ufs_read_inode (struct inode *);
109+
extern struct inode *ufs_iget(struct super_block *, unsigned long);
110110
extern void ufs_put_inode (struct inode *);
111111
extern int ufs_write_inode (struct inode *, int);
112112
extern int ufs_sync_inode (struct inode *);

0 commit comments

Comments
 (0)