Commit f074c267 authored by Al Viro's avatar Al Viro Committed by Zefan Li

get rid of s_files and files_lock

commit eee5cc27 upstream.

The only thing we need it for is alt-sysrq-r (emergency remount r/o)
and these days we can do just as well without going through the
list of files.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
[lizf: Backported to 3.4: adjust context]
Signed-off-by: default avatarZefan Li <lizefan@huawei.com>
parent 8f452aa3
...@@ -34,9 +34,6 @@ struct files_stat_struct files_stat = { ...@@ -34,9 +34,6 @@ struct files_stat_struct files_stat = {
.max_files = NR_FILE .max_files = NR_FILE
}; };
DECLARE_LGLOCK(files_lglock);
DEFINE_LGLOCK(files_lglock);
/* SLAB cache for file structures */ /* SLAB cache for file structures */
static struct kmem_cache *filp_cachep __read_mostly; static struct kmem_cache *filp_cachep __read_mostly;
...@@ -129,7 +126,6 @@ struct file *get_empty_filp(void) ...@@ -129,7 +126,6 @@ struct file *get_empty_filp(void)
if (security_file_alloc(f)) if (security_file_alloc(f))
goto fail_sec; goto fail_sec;
INIT_LIST_HEAD(&f->f_u.fu_list);
atomic_long_set(&f->f_count, 1); atomic_long_set(&f->f_count, 1);
rwlock_init(&f->f_owner.lock); rwlock_init(&f->f_owner.lock);
spin_lock_init(&f->f_lock); spin_lock_init(&f->f_lock);
...@@ -252,7 +248,6 @@ static void __fput(struct file *file) ...@@ -252,7 +248,6 @@ static void __fput(struct file *file)
} }
fops_put(file->f_op); fops_put(file->f_op);
put_pid(file->f_owner.pid); put_pid(file->f_owner.pid);
file_sb_list_del(file);
if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
i_readcount_dec(inode); i_readcount_dec(inode);
if (file->f_mode & FMODE_WRITE) if (file->f_mode & FMODE_WRITE)
...@@ -382,134 +377,10 @@ void put_filp(struct file *file) ...@@ -382,134 +377,10 @@ void put_filp(struct file *file)
{ {
if (atomic_long_dec_and_test(&file->f_count)) { if (atomic_long_dec_and_test(&file->f_count)) {
security_file_free(file); security_file_free(file);
file_sb_list_del(file);
file_free(file); file_free(file);
} }
} }
static inline int file_list_cpu(struct file *file)
{
#ifdef CONFIG_SMP
return file->f_sb_list_cpu;
#else
return smp_processor_id();
#endif
}
/* helper for file_sb_list_add to reduce ifdefs */
static inline void __file_sb_list_add(struct file *file, struct super_block *sb)
{
struct list_head *list;
#ifdef CONFIG_SMP
int cpu;
cpu = smp_processor_id();
file->f_sb_list_cpu = cpu;
list = per_cpu_ptr(sb->s_files, cpu);
#else
list = &sb->s_files;
#endif
list_add(&file->f_u.fu_list, list);
}
/**
* file_sb_list_add - add a file to the sb's file list
* @file: file to add
* @sb: sb to add it to
*
* Use this function to associate a file with the superblock of the inode it
* refers to.
*/
void file_sb_list_add(struct file *file, struct super_block *sb)
{
lg_local_lock(files_lglock);
__file_sb_list_add(file, sb);
lg_local_unlock(files_lglock);
}
/**
* file_sb_list_del - remove a file from the sb's file list
* @file: file to remove
* @sb: sb to remove it from
*
* Use this function to remove a file from its superblock.
*/
void file_sb_list_del(struct file *file)
{
if (!list_empty(&file->f_u.fu_list)) {
lg_local_lock_cpu(files_lglock, file_list_cpu(file));
list_del_init(&file->f_u.fu_list);
lg_local_unlock_cpu(files_lglock, file_list_cpu(file));
}
}
#ifdef CONFIG_SMP
/*
* These macros iterate all files on all CPUs for a given superblock.
* files_lglock must be held globally.
*/
#define do_file_list_for_each_entry(__sb, __file) \
{ \
int i; \
for_each_possible_cpu(i) { \
struct list_head *list; \
list = per_cpu_ptr((__sb)->s_files, i); \
list_for_each_entry((__file), list, f_u.fu_list)
#define while_file_list_for_each_entry \
} \
}
#else
#define do_file_list_for_each_entry(__sb, __file) \
{ \
struct list_head *list; \
list = &(sb)->s_files; \
list_for_each_entry((__file), list, f_u.fu_list)
#define while_file_list_for_each_entry \
}
#endif
/**
* mark_files_ro - mark all files read-only
* @sb: superblock in question
*
* All files are marked read-only. We don't care about pending
* delete files so this should be used in 'force' mode only.
*/
void mark_files_ro(struct super_block *sb)
{
struct file *f;
retry:
lg_global_lock(files_lglock);
do_file_list_for_each_entry(sb, f) {
struct vfsmount *mnt;
if (!S_ISREG(f->f_path.dentry->d_inode->i_mode))
continue;
if (!file_count(f))
continue;
if (!(f->f_mode & FMODE_WRITE))
continue;
spin_lock(&f->f_lock);
f->f_mode &= ~FMODE_WRITE;
spin_unlock(&f->f_lock);
if (file_check_writeable(f) != 0)
continue;
file_release_write(f);
mnt = mntget(f->f_path.mnt);
/* This can sleep, so we can't hold the spinlock. */
lg_global_unlock(files_lglock);
mnt_drop_write(mnt);
mntput(mnt);
goto retry;
} while_file_list_for_each_entry;
lg_global_unlock(files_lglock);
}
void __init files_init(unsigned long mempages) void __init files_init(unsigned long mempages)
{ {
unsigned long n; unsigned long n;
...@@ -525,6 +396,5 @@ void __init files_init(unsigned long mempages) ...@@ -525,6 +396,5 @@ void __init files_init(unsigned long mempages)
n = (mempages * (PAGE_SIZE / 1024)) / 10; n = (mempages * (PAGE_SIZE / 1024)) / 10;
files_stat.max_files = max_t(unsigned long, n, NR_FILE); files_stat.max_files = max_t(unsigned long, n, NR_FILE);
files_defer_init(); files_defer_init();
lg_lock_init(files_lglock);
percpu_counter_init(&nr_files, 0); percpu_counter_init(&nr_files, 0);
} }
...@@ -67,9 +67,6 @@ extern void chroot_fs_refs(struct path *, struct path *); ...@@ -67,9 +67,6 @@ extern void chroot_fs_refs(struct path *, struct path *);
/* /*
* file_table.c * file_table.c
*/ */
extern void file_sb_list_add(struct file *f, struct super_block *sb);
extern void file_sb_list_del(struct file *f);
extern void mark_files_ro(struct super_block *);
extern struct file *get_empty_filp(void); extern struct file *get_empty_filp(void);
/* /*
......
...@@ -672,7 +672,6 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, ...@@ -672,7 +672,6 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
f->f_path.dentry = dentry; f->f_path.dentry = dentry;
f->f_path.mnt = mnt; f->f_path.mnt = mnt;
f->f_pos = 0; f->f_pos = 0;
file_sb_list_add(f, inode->i_sb);
if (unlikely(f->f_mode & FMODE_PATH)) { if (unlikely(f->f_mode & FMODE_PATH)) {
f->f_op = &empty_fops; f->f_op = &empty_fops;
...@@ -730,7 +729,6 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, ...@@ -730,7 +729,6 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
mnt_drop_write(mnt); mnt_drop_write(mnt);
} }
} }
file_sb_list_del(f);
f->f_path.dentry = NULL; f->f_path.dentry = NULL;
f->f_path.mnt = NULL; f->f_path.mnt = NULL;
cleanup_file: cleanup_file:
......
...@@ -122,22 +122,7 @@ static struct super_block *alloc_super(struct file_system_type *type) ...@@ -122,22 +122,7 @@ static struct super_block *alloc_super(struct file_system_type *type)
s = NULL; s = NULL;
goto out; goto out;
} }
#ifdef CONFIG_SMP
s->s_files = alloc_percpu(struct list_head);
if (!s->s_files) {
security_sb_free(s);
kfree(s);
s = NULL;
goto out;
} else {
int i;
for_each_possible_cpu(i)
INIT_LIST_HEAD(per_cpu_ptr(s->s_files, i));
}
#else
INIT_LIST_HEAD(&s->s_files);
#endif
s->s_bdi = &default_backing_dev_info; s->s_bdi = &default_backing_dev_info;
INIT_HLIST_NODE(&s->s_instances); INIT_HLIST_NODE(&s->s_instances);
INIT_HLIST_BL_HEAD(&s->s_anon); INIT_HLIST_BL_HEAD(&s->s_anon);
...@@ -200,9 +185,6 @@ static struct super_block *alloc_super(struct file_system_type *type) ...@@ -200,9 +185,6 @@ static struct super_block *alloc_super(struct file_system_type *type)
*/ */
static inline void destroy_super(struct super_block *s) static inline void destroy_super(struct super_block *s)
{ {
#ifdef CONFIG_SMP
free_percpu(s->s_files);
#endif
security_sb_free(s); security_sb_free(s);
WARN_ON(!list_empty(&s->s_mounts)); WARN_ON(!list_empty(&s->s_mounts));
kfree(s->s_subtype); kfree(s->s_subtype);
...@@ -744,7 +726,8 @@ int do_remount_sb(struct super_block *sb, int flags, void *data, int force) ...@@ -744,7 +726,8 @@ int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
make sure there are no rw files opened */ make sure there are no rw files opened */
if (remount_ro) { if (remount_ro) {
if (force) { if (force) {
mark_files_ro(sb); sb->s_readonly_remount = 1;
smp_wmb();
} else { } else {
retval = sb_prepare_remount_readonly(sb); retval = sb_prepare_remount_readonly(sb);
if (retval) if (retval)
......
...@@ -976,12 +976,7 @@ static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index) ...@@ -976,12 +976,7 @@ static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
#define FILE_MNT_WRITE_RELEASED 2 #define FILE_MNT_WRITE_RELEASED 2
struct file { struct file {
/*
* fu_list becomes invalid after file_free is called and queued via
* fu_rcuhead for RCU freeing
*/
union { union {
struct list_head fu_list;
struct rcu_head fu_rcuhead; struct rcu_head fu_rcuhead;
} f_u; } f_u;
struct path f_path; struct path f_path;
...@@ -994,9 +989,6 @@ struct file { ...@@ -994,9 +989,6 @@ struct file {
* Must not be taken from IRQ context. * Must not be taken from IRQ context.
*/ */
spinlock_t f_lock; spinlock_t f_lock;
#ifdef CONFIG_SMP
int f_sb_list_cpu;
#endif
atomic_long_t f_count; atomic_long_t f_count;
unsigned int f_flags; unsigned int f_flags;
fmode_t f_mode; fmode_t f_mode;
...@@ -1443,11 +1435,6 @@ struct super_block { ...@@ -1443,11 +1435,6 @@ struct super_block {
struct list_head s_inodes; /* all inodes */ struct list_head s_inodes; /* all inodes */
struct hlist_bl_head s_anon; /* anonymous dentries for (nfs) exporting */ struct hlist_bl_head s_anon; /* anonymous dentries for (nfs) exporting */
#ifdef CONFIG_SMP
struct list_head __percpu *s_files;
#else
struct list_head s_files;
#endif
struct list_head s_mounts; /* list of mounts; _not_ for fs use */ struct list_head s_mounts; /* list of mounts; _not_ for fs use */
/* s_dentry_lru, s_nr_dentry_unused protected by dcache.c lru locks */ /* s_dentry_lru, s_nr_dentry_unused protected by dcache.c lru locks */
struct list_head s_dentry_lru; /* unused dentry lru */ struct list_head s_dentry_lru; /* unused dentry lru */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment