Skip to content

Commit 77b8a75

Browse files
author
Al Viro
committed
simplify get_cramfs_inode()
simply don't hash the inodes that don't have real inumber instead of skipping them during iget5_locked(); as the result, simple iget_locked() would do and we can get rid of cramfs ->drop_inode() as well. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent b69257f commit 77b8a75

1 file changed

Lines changed: 38 additions & 50 deletions

File tree

‎fs/cramfs/inode.c‎

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -39,66 +39,55 @@ static DEFINE_MUTEX(read_mutex);
3939
#define CRAMINO(x) (((x)->offset && (x)->size)?(x)->offset<<2:1)
4040
#define OFFSET(x) ((x)->i_ino)
4141

42-
43-
static int cramfs_iget5_test(struct inode *inode, void *opaque)
44-
{
45-
struct cramfs_inode *cramfs_inode = opaque;
46-
return inode->i_ino == CRAMINO(cramfs_inode) && inode->i_ino != 1;
47-
}
48-
49-
static int cramfs_iget5_set(struct inode *inode, void *opaque)
42+
static void setup_inode(struct inode *inode, struct cramfs_inode * cramfs_inode)
5043
{
51-
struct cramfs_inode *cramfs_inode = opaque;
52-
inode->i_ino = CRAMINO(cramfs_inode);
53-
return 0;
44+
static struct timespec zerotime;
45+
inode->i_mode = cramfs_inode->mode;
46+
inode->i_uid = cramfs_inode->uid;
47+
inode->i_size = cramfs_inode->size;
48+
inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1;
49+
inode->i_gid = cramfs_inode->gid;
50+
/* Struct copy intentional */
51+
inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime;
52+
/* inode->i_nlink is left 1 - arguably wrong for directories,
53+
but it's the best we can do without reading the directory
54+
contents. 1 yields the right result in GNU find, even
55+
without -noleaf option. */
56+
if (S_ISREG(inode->i_mode)) {
57+
inode->i_fop = &generic_ro_fops;
58+
inode->i_data.a_ops = &cramfs_aops;
59+
} else if (S_ISDIR(inode->i_mode)) {
60+
inode->i_op = &cramfs_dir_inode_operations;
61+
inode->i_fop = &cramfs_directory_operations;
62+
} else if (S_ISLNK(inode->i_mode)) {
63+
inode->i_op = &page_symlink_inode_operations;
64+
inode->i_data.a_ops = &cramfs_aops;
65+
} else {
66+
init_special_inode(inode, inode->i_mode,
67+
old_decode_dev(cramfs_inode->size));
68+
}
5469
}
5570

5671
static struct inode *get_cramfs_inode(struct super_block *sb,
5772
struct cramfs_inode * cramfs_inode)
5873
{
59-
struct inode *inode = iget5_locked(sb, CRAMINO(cramfs_inode),
60-
cramfs_iget5_test, cramfs_iget5_set,
61-
cramfs_inode);
62-
static struct timespec zerotime;
63-
64-
if (inode && (inode->i_state & I_NEW)) {
65-
inode->i_mode = cramfs_inode->mode;
66-
inode->i_uid = cramfs_inode->uid;
67-
inode->i_size = cramfs_inode->size;
68-
inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1;
69-
inode->i_gid = cramfs_inode->gid;
70-
/* Struct copy intentional */
71-
inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime;
72-
/* inode->i_nlink is left 1 - arguably wrong for directories,
73-
but it's the best we can do without reading the directory
74-
contents. 1 yields the right result in GNU find, even
75-
without -noleaf option. */
76-
if (S_ISREG(inode->i_mode)) {
77-
inode->i_fop = &generic_ro_fops;
78-
inode->i_data.a_ops = &cramfs_aops;
79-
} else if (S_ISDIR(inode->i_mode)) {
80-
inode->i_op = &cramfs_dir_inode_operations;
81-
inode->i_fop = &cramfs_directory_operations;
82-
} else if (S_ISLNK(inode->i_mode)) {
83-
inode->i_op = &page_symlink_inode_operations;
84-
inode->i_data.a_ops = &cramfs_aops;
85-
} else {
86-
init_special_inode(inode, inode->i_mode,
87-
old_decode_dev(cramfs_inode->size));
74+
struct inode *inode;
75+
if (CRAMINO(cramfs_inode) == 1) {
76+
inode = new_inode(sb);
77+
if (inode) {
78+
inode->i_ino = 1;
79+
setup_inode(inode, cramfs_inode);
80+
}
81+
} else {
82+
inode = iget_locked(sb, CRAMINO(cramfs_inode));
83+
if (inode) {
84+
setup_inode(inode, cramfs_inode);
85+
unlock_new_inode(inode);
8886
}
89-
unlock_new_inode(inode);
9087
}
9188
return inode;
9289
}
9390

94-
static void cramfs_drop_inode(struct inode *inode)
95-
{
96-
if (inode->i_ino == 1)
97-
generic_delete_inode(inode);
98-
else
99-
generic_drop_inode(inode);
100-
}
101-
10291
/*
10392
* We have our own block cache: don't fill up the buffer cache
10493
* with the rom-image, because the way the filesystem is set
@@ -542,7 +531,6 @@ static const struct super_operations cramfs_ops = {
542531
.put_super = cramfs_put_super,
543532
.remount_fs = cramfs_remount,
544533
.statfs = cramfs_statfs,
545-
.drop_inode = cramfs_drop_inode,
546534
};
547535

548536
static int cramfs_get_sb(struct file_system_type *fs_type,

0 commit comments

Comments
 (0)