@@ -77,15 +77,13 @@ spufs_new_inode(struct super_block *sb, umode_t mode)
{
struct inode *inode;
- inode = new_inode(sb);
+ inode = simple_new_inode(sb);
if (!inode)
goto out;
- inode->i_ino = get_next_ino();
inode->i_mode = mode;
inode->i_uid = current_fsuid();
inode->i_gid = current_fsgid();
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
out:
return inode;
}
@@ -93,15 +93,13 @@ static void hypfs_delete_tree(struct dentry *root)
static struct inode *hypfs_make_inode(struct super_block *sb, umode_t mode)
{
- struct inode *ret = new_inode(sb);
+ struct inode *ret = simple_new_inode(sb);
if (ret) {
struct hypfs_sb_info *hypfs_info = sb->s_fs_info;
- ret->i_ino = get_next_ino();
ret->i_mode = mode;
ret->i_uid = hypfs_info->uid;
ret->i_gid = hypfs_info->gid;
- ret->i_atime = ret->i_mtime = ret->i_ctime = current_time(ret);
if (S_ISDIR(mode))
set_nlink(ret, 2);
}
@@ -53,21 +53,17 @@ static int qibfs_mknod(struct inode *dir, struct dentry *dentry,
void *data)
{
int error;
- struct inode *inode = new_inode(dir->i_sb);
+ struct inode *inode = simple_new_inode(dir->i_sb);
if (!inode) {
error = -EPERM;
goto bail;
}
- inode->i_ino = get_next_ino();
inode->i_mode = mode;
inode->i_uid = GLOBAL_ROOT_UID;
inode->i_gid = GLOBAL_ROOT_GID;
inode->i_blocks = 0;
- inode->i_atime = current_time(inode);
- inode->i_mtime = inode->i_atime;
- inode->i_ctime = inode->i_atime;
inode->i_private = data;
if (S_ISDIR(mode)) {
inode->i_op = &simple_dir_inode_operations;
@@ -134,13 +134,11 @@ static int ibmasmfs_fill_super(struct super_block *sb, struct fs_context *fc)
static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode)
{
- struct inode *ret = new_inode(sb);
+ struct inode *ret = simple_new_inode(sb);
- if (ret) {
- ret->i_ino = get_next_ino();
+ if (ret)
ret->i_mode = mode;
- ret->i_atime = ret->i_mtime = ret->i_ctime = current_time(ret);
- }
+
return ret;
}
@@ -26,13 +26,11 @@ DEFINE_RAW_SPINLOCK(oprofilefs_lock);
static struct inode *oprofilefs_get_inode(struct super_block *sb, int mode)
{
- struct inode *inode = new_inode(sb);
+ struct inode *inode = simple_new_inode(sb);
- if (inode) {
- inode->i_ino = get_next_ino();
+ if (inode)
inode->i_mode = mode;
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
- }
+
return inode;
}
@@ -1385,18 +1385,12 @@ ffs_sb_make_inode(struct super_block *sb, void *data,
ENTER();
- inode = new_inode(sb);
+ inode = simple_new_inode(sb);
if (likely(inode)) {
- struct timespec64 ts = current_time(inode);
-
- inode->i_ino = get_next_ino();
inode->i_mode = perms->mode;
inode->i_uid = perms->uid;
inode->i_gid = perms->gid;
- inode->i_atime = ts;
- inode->i_mtime = ts;
- inode->i_ctime = ts;
inode->i_private = data;
if (fops)
inode->i_fop = fops;
@@ -359,7 +359,7 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
struct inode *autofs_get_inode(struct super_block *sb, umode_t mode)
{
- struct inode *inode = new_inode(sb);
+ struct inode *inode = simple_new_inode(sb);
if (inode == NULL)
return NULL;
@@ -369,8 +369,6 @@ struct inode *autofs_get_inode(struct super_block *sb, umode_t mode)
inode->i_uid = d_inode(sb->s_root)->i_uid;
inode->i_gid = d_inode(sb->s_root)->i_gid;
}
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
- inode->i_ino = get_next_ino();
if (S_ISDIR(mode)) {
set_nlink(inode, 2);
@@ -586,19 +586,6 @@ static void entry_status(Node *e, char *page)
}
}
-static struct inode *bm_get_inode(struct super_block *sb, int mode)
-{
- struct inode *inode = new_inode(sb);
-
- if (inode) {
- inode->i_ino = get_next_ino();
- inode->i_mode = mode;
- inode->i_atime = inode->i_mtime = inode->i_ctime =
- current_time(inode);
- }
- return inode;
-}
-
static void bm_evict_inode(struct inode *inode)
{
Node *e = inode->i_private;
@@ -711,12 +698,13 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
if (d_really_is_positive(dentry))
goto out2;
- inode = bm_get_inode(sb, S_IFREG | 0644);
+ inode = simple_new_inode(sb);
err = -ENOMEM;
if (!inode)
goto out2;
+ inode->i_mode = S_IFREG | 0644;
err = simple_pin_fs(&bm_fs, &bm_fs_type);
if (err) {
iput(inode);
@@ -61,17 +61,6 @@ static const struct inode_operations debugfs_symlink_inode_operations = {
.setattr = debugfs_setattr,
};
-static struct inode *debugfs_get_inode(struct super_block *sb)
-{
- struct inode *inode = new_inode(sb);
- if (inode) {
- inode->i_ino = get_next_ino();
- inode->i_atime = inode->i_mtime =
- inode->i_ctime = current_time(inode);
- }
- return inode;
-}
-
struct debugfs_mount_opts {
kuid_t uid;
kgid_t gid;
@@ -383,7 +372,7 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
if (IS_ERR(dentry))
return dentry;
- inode = debugfs_get_inode(dentry->d_sb);
+ inode = simple_new_inode(dentry->d_sb);
if (unlikely(!inode)) {
pr_err("out of free dentries, can not create file '%s'\n",
name);
@@ -539,7 +528,7 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
if (IS_ERR(dentry))
return dentry;
- inode = debugfs_get_inode(dentry->d_sb);
+ inode = simple_new_inode(dentry->d_sb);
if (unlikely(!inode)) {
pr_err("out of free dentries, can not create directory '%s'\n",
name);
@@ -581,7 +570,7 @@ struct dentry *debugfs_create_automount(const char *name,
if (IS_ERR(dentry))
return dentry;
- inode = debugfs_get_inode(dentry->d_sb);
+ inode = simple_new_inode(dentry->d_sb);
if (unlikely(!inode)) {
pr_err("out of free dentries, can not create automount '%s'\n",
name);
@@ -639,7 +628,7 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
return dentry;
}
- inode = debugfs_get_inode(dentry->d_sb);
+ inode = simple_new_inode(dentry->d_sb);
if (unlikely(!inode)) {
pr_err("out of free dentries, can not create symlink '%s'\n",
name);
@@ -16,12 +16,10 @@ struct inode *efivarfs_get_inode(struct super_block *sb,
const struct inode *dir, int mode,
dev_t dev, bool is_removable)
{
- struct inode *inode = new_inode(sb);
+ struct inode *inode = simple_new_inode(sb);
if (inode) {
- inode->i_ino = get_next_ino();
inode->i_mode = mode;
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
inode->i_flags = is_removable ? 0 : S_IMMUTABLE;
switch (mode & S_IFMT) {
case S_IFREG:
@@ -232,17 +232,15 @@ static struct dentry *fuse_ctl_add_dentry(struct dentry *parent,
if (!dentry)
return NULL;
- inode = new_inode(fuse_control_sb);
+ inode = simple_new_inode(fuse_control_sb);
if (!inode) {
dput(dentry);
return NULL;
}
- inode->i_ino = get_next_ino();
inode->i_mode = mode;
inode->i_uid = fc->user_id;
inode->i_gid = fc->group_id;
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
/* setting ->i_op to NULL is not allowed */
if (iop)
inode->i_op = iop;
@@ -739,13 +739,11 @@ static struct inode *hugetlbfs_get_root(struct super_block *sb,
{
struct inode *inode;
- inode = new_inode(sb);
+ inode = simple_new_inode(sb);
if (inode) {
- inode->i_ino = get_next_ino();
inode->i_mode = S_IFDIR | ctx->mode;
inode->i_uid = ctx->uid;
inode->i_gid = ctx->gid;
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
inode->i_op = &hugetlbfs_dir_inode_operations;
inode->i_fop = &simple_dir_operations;
/* directory inodes start off with i_nlink == 2 (for "." entry) */
@@ -780,16 +778,14 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb,
return NULL;
}
- inode = new_inode(sb);
+ inode = simple_new_inode(sb);
if (inode) {
struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode);
- inode->i_ino = get_next_ino();
inode_init_owner(inode, dir, mode);
lockdep_set_class(&inode->i_mapping->i_mmap_rwsem,
&hugetlbfs_i_mmap_rwsem_key);
inode->i_mapping->a_ops = &hugetlbfs_aops;
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
inode->i_mapping->private_data = resv_map;
info->seals = F_SEAL_SEAL;
switch (mode & S_IFMT) {
@@ -595,6 +595,18 @@ int simple_write_end(struct file *file, struct address_space *mapping,
}
EXPORT_SYMBOL(simple_write_end);
+struct inode *simple_new_inode(struct super_block *sb)
+{
+ struct inode *inode = new_inode(sb);
+ if (inode) {
+ inode->i_ino = get_next_ino();
+ inode->i_atime = inode->i_mtime =
+ inode->i_ctime = current_time(inode);
+ }
+ return inode;
+}
+EXPORT_SYMBOL(simple_new_inode);
+
/*
* the inodes created here are not hashed. If you use iunique to generate
* unique inode values later for this filesystem, then you must take care
@@ -371,13 +371,11 @@ static void dlmfs_evict_inode(struct inode *inode)
static struct inode *dlmfs_get_root_inode(struct super_block *sb)
{
- struct inode *inode = new_inode(sb);
+ struct inode *inode = simple_new_inode(sb);
umode_t mode = S_IFDIR | 0755;
if (inode) {
- inode->i_ino = get_next_ino();
inode_init_owner(inode, NULL, mode);
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
inc_nlink(inode);
inode->i_fop = &simple_dir_operations;
@@ -392,15 +390,13 @@ static struct inode *dlmfs_get_inode(struct inode *parent,
umode_t mode)
{
struct super_block *sb = parent->i_sb;
- struct inode * inode = new_inode(sb);
+ struct inode * inode = simple_new_inode(sb);
struct dlmfs_inode_private *ip;
if (!inode)
return NULL;
- inode->i_ino = get_next_ino();
inode_init_owner(inode, parent, mode);
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
ip = DLMFS_I(inode);
ip->ip_conn = DLMFS_I(parent)->ip_conn;
@@ -1856,15 +1856,13 @@ struct inode *proc_pid_make_inode(struct super_block * sb,
/* We need a new inode */
- inode = new_inode(sb);
+ inode = simple_new_inode(sb);
if (!inode)
goto out;
/* Common stuff */
ei = PROC_I(inode);
inode->i_mode = mode;
- inode->i_ino = get_next_ino();
- inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
inode->i_op = &proc_def_inode_operations;
/*
@@ -434,12 +434,10 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
struct inode *inode;
struct proc_inode *ei;
- inode = new_inode(sb);
+ inode = simple_new_inode(sb);
if (!inode)
return ERR_PTR(-ENOMEM);
- inode->i_ino = get_next_ino();
-
ei = PROC_I(inode);
spin_lock(&sysctl_lock);
@@ -454,7 +452,6 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
head->count++;
spin_unlock(&sysctl_lock);
- inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
inode->i_mode = table->mode;
if (!S_ISDIR(table->mode)) {
inode->i_mode |= S_IFREG;
@@ -208,16 +208,6 @@ static const struct inode_operations pstore_dir_inode_operations = {
.unlink = pstore_unlink,
};
-static struct inode *pstore_get_inode(struct super_block *sb)
-{
- struct inode *inode = new_inode(sb);
- if (inode) {
- inode->i_ino = get_next_ino();
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
- }
- return inode;
-}
-
enum {
Opt_kmsg_bytes, Opt_err
};
@@ -316,7 +306,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
return rc;
rc = -ENOMEM;
- inode = pstore_get_inode(root->d_sb);
+ inode = simple_new_inode(root->d_sb);
if (!inode)
goto fail;
inode->i_mode = S_IFREG | 0444;
@@ -394,7 +384,7 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent)
parse_options(data);
- inode = pstore_get_inode(sb);
+ inode = simple_new_inode(sb);
if (inode) {
inode->i_mode = S_IFDIR | 0750;
inode->i_op = &pstore_dir_inode_operations;
@@ -63,15 +63,13 @@ static const struct address_space_operations ramfs_aops = {
struct inode *ramfs_get_inode(struct super_block *sb,
const struct inode *dir, umode_t mode, dev_t dev)
{
- struct inode * inode = new_inode(sb);
+ struct inode * inode = simple_new_inode(sb);
if (inode) {
- inode->i_ino = get_next_ino();
inode_init_owner(inode, dir, mode);
inode->i_mapping->a_ops = &ramfs_aops;
mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
mapping_set_unevictable(inode->i_mapping);
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
switch (mode & S_IFMT) {
default:
init_special_inode(inode, mode, dev);
@@ -124,16 +124,6 @@ static const struct inode_operations tracefs_dir_inode_operations = {
.rmdir = tracefs_syscall_rmdir,
};
-static struct inode *tracefs_get_inode(struct super_block *sb)
-{
- struct inode *inode = new_inode(sb);
- if (inode) {
- inode->i_ino = get_next_ino();
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
- }
- return inode;
-}
-
struct tracefs_mount_opts {
kuid_t uid;
kgid_t gid;
@@ -403,7 +393,7 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode,
if (IS_ERR(dentry))
return NULL;
- inode = tracefs_get_inode(dentry->d_sb);
+ inode = simple_new_inode(dentry->d_sb);
if (unlikely(!inode))
return failed_creating(dentry);
@@ -424,7 +414,7 @@ static struct dentry *__create_dir(const char *name, struct dentry *parent,
if (IS_ERR(dentry))
return NULL;
- inode = tracefs_get_inode(dentry->d_sb);
+ inode = simple_new_inode(dentry->d_sb);
if (unlikely(!inode))
return failed_creating(dentry);
@@ -3088,6 +3088,7 @@ extern void clear_inode(struct inode *);
extern void __destroy_inode(struct inode *);
extern struct inode *new_inode_pseudo(struct super_block *sb);
extern struct inode *new_inode(struct super_block *sb);
+extern struct inode *simple_new_inode(struct super_block *sb);
extern void free_inode_nonrcu(struct inode *inode);
extern int should_remove_suid(struct dentry *);
extern int file_remove_privs(struct file *);
@@ -296,15 +296,13 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
struct inode *inode;
int ret = -ENOMEM;
- inode = new_inode(sb);
+ inode = simple_new_inode(sb);
if (!inode)
goto err;
- inode->i_ino = get_next_ino();
inode->i_mode = mode;
inode->i_uid = current_fsuid();
inode->i_gid = current_fsgid();
- inode->i_mtime = inode->i_ctime = inode->i_atime = current_time(inode);
if (S_ISREG(mode)) {
struct mqueue_inode_info *info;
@@ -112,15 +112,10 @@ static struct inode *bpf_get_inode(struct super_block *sb,
return ERR_PTR(-EINVAL);
}
- inode = new_inode(sb);
+ inode = simple_new_inode(sb);
if (!inode)
return ERR_PTR(-ENOSPC);
- inode->i_ino = get_next_ino();
- inode->i_atime = current_time(inode);
- inode->i_mtime = inode->i_atime;
- inode->i_ctime = inode->i_atime;
-
inode_init_owner(inode, dir, mode);
return inode;
@@ -2246,12 +2246,10 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
if (shmem_reserve_inode(sb))
return NULL;
- inode = new_inode(sb);
+ inode = simple_new_inode(sb);
if (inode) {
- inode->i_ino = get_next_ino();
inode_init_owner(inode, dir, mode);
inode->i_blocks = 0;
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
inode->i_generation = prandom_u32();
info = SHMEM_I(inode);
memset(info, 0, (char *)inode - (char *)info);
@@ -467,12 +467,10 @@ struct rpc_filelist {
static struct inode *
rpc_get_inode(struct super_block *sb, umode_t mode)
{
- struct inode *inode = new_inode(sb);
+ struct inode *inode = simple_new_inode(sb);
if (!inode)
return NULL;
- inode->i_ino = get_next_ino();
inode->i_mode = mode;
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
switch (mode & S_IFMT) {
case S_IFDIR:
inode->i_fop = &simple_dir_operations;
@@ -212,7 +212,7 @@ static int __aafs_setup_d_inode(struct inode *dir, struct dentry *dentry,
const struct file_operations *fops,
const struct inode_operations *iops)
{
- struct inode *inode = new_inode(dir->i_sb);
+ struct inode *inode = simple_new_inode(dir->i_sb);
AA_BUG(!dir);
AA_BUG(!dentry);
@@ -220,9 +220,7 @@ static int __aafs_setup_d_inode(struct inode *dir, struct dentry *dentry,
if (!inode)
return -ENOMEM;
- inode->i_ino = get_next_ino();
inode->i_mode = mode;
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
inode->i_private = data;
if (S_ISDIR(mode)) {
inode->i_op = iops ? iops : &simple_dir_inode_operations;
@@ -2540,15 +2538,13 @@ static int aa_mk_null_file(struct dentry *parent)
error = PTR_ERR(dentry);
goto out;
}
- inode = new_inode(parent->d_inode->i_sb);
+ inode = simple_new_inode(parent->d_inode->i_sb);
if (!inode) {
error = -ENOMEM;
goto out1;
}
- inode->i_ino = get_next_ino();
inode->i_mode = S_IFCHR | S_IRUGO | S_IWUGO;
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
init_special_inode(inode, S_IFCHR | S_IRUGO | S_IWUGO,
MKDEV(MEM_MAJOR, 3));
d_instantiate(dentry, inode);
@@ -136,15 +136,13 @@ static struct dentry *securityfs_create_dentry(const char *name, umode_t mode,
goto out1;
}
- inode = new_inode(dir->i_sb);
+ inode = simple_new_inode(dir->i_sb);
if (!inode) {
error = -ENOMEM;
goto out1;
}
- inode->i_ino = get_next_ino();
inode->i_mode = mode;
- inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
inode->i_private = data;
if (S_ISDIR(mode)) {
inode->i_op = &simple_dir_inode_operations;
It is a common special case for new_inode to initialize the time to the current time and the inode to get_next_ino(). Introduce a core function that does it and use it throughout Linux. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> --- arch/powerpc/platforms/cell/spufs/inode.c | 4 +--- arch/s390/hypfs/inode.c | 4 +--- drivers/infiniband/hw/qib/qib_fs.c | 6 +----- drivers/misc/ibmasm/ibmasmfs.c | 8 +++----- drivers/oprofile/oprofilefs.c | 8 +++----- drivers/usb/gadget/function/f_fs.c | 8 +------- fs/autofs/inode.c | 4 +--- fs/binfmt_misc.c | 16 ++-------------- fs/debugfs/inode.c | 19 ++++--------------- fs/efivarfs/inode.c | 4 +--- fs/fuse/control.c | 4 +--- fs/hugetlbfs/inode.c | 8 ++------ fs/libfs.c | 12 ++++++++++++ fs/ocfs2/dlmfs/dlmfs.c | 8 ++------ fs/proc/base.c | 4 +--- fs/proc/proc_sysctl.c | 5 +---- fs/pstore/inode.c | 14 ++------------ fs/ramfs/inode.c | 4 +--- fs/tracefs/inode.c | 14 ++------------ include/linux/fs.h | 1 + ipc/mqueue.c | 4 +--- kernel/bpf/inode.c | 7 +------ mm/shmem.c | 4 +--- net/sunrpc/rpc_pipe.c | 4 +--- security/apparmor/apparmorfs.c | 8 ++------ security/inode.c | 4 +--- 26 files changed, 50 insertions(+), 136 deletions(-)