Clean up brlocks/lglocks
PATCH 1/1 Clean up brlocks/lglocks
From: Andi Kleen <[email protected]>
lglocks and brlocks are currently generated with some complicated macros in lglock.h. But there's no reason, I can see, to not just use common utility functions that get pointers to the lglock.
Since there are at least two users it makes sense to share this code in a library.
This will also make it later possible to dynamically allocate lglocks.
In general the users now look more like normal function calls with pointers, not magic macros.
The patch is rather large because I move over all users in one go to keep it bisectable. This impacts the VFS somewhat in terms of lines changed. But no actual behaviour change.
--- fs/dcache.c | 10 ++-- fs/file_table.c | 23 ++++---- fs/internal.h | 3 +- fs/namei.c | 26 ++++---- fs/namespace.c | 124 +++++++++++++++++++------------------- fs/pnode.c | 4 +- include/linux/lglock.h | 152 ++++++++--------------------------------------- kernel/Makefile | 2 +- kernel/lglock.c | 101 ++++++++++++++++++++++++++++++++ 9 files changed, 222 insertions(+), 223 deletions(-) create mode 100644 kernel/lglock.c
fs/dcache.c +5 -5
@@ -2415,7 +2415,7 @@ static int prepend_path(const struct path *path, struct path *root,bool slash = false;int error =0 ; -br_read_lock (vfsmount_lock); +br_read_lock (&vfsmount_lock);while (dentry != root->dentry || vfsmnt != root->mnt) {struct dentry * parent;
@@ -2446,7 +2446,7 @@ out:if (!error && !slash) error =prepend (buffer, buflen,"/" ,1 ); -br_read_unlock (vfsmount_lock); +br_read_unlock (&vfsmount_lock);return error; global_root:
@@ -2801,11 +2801,11 @@ int path_is_under(struct path *path1, struct path *path2)struct dentry *dentry = path1->dentry;int res; -br_read_lock (vfsmount_lock); +br_read_lock (&vfsmount_lock);if (mnt != path2->mnt) {for (;;) {if (mnt->mnt_parent == mnt) { -br_read_unlock (vfsmount_lock); +br_read_unlock (&vfsmount_lock);return 0 ; }if (mnt->mnt_parent == path2->mnt)
@@ -2815,7 +2815,7 @@ int path_is_under(struct path *path1, struct path *path2) dentry = mnt->mnt_mountpoint; } res =is_subdir (dentry, path2->dentry); -br_read_unlock (vfsmount_lock); +br_read_unlock (&vfsmount_lock);return res; }EXPORT_SYMBOL (path_is_under);
fs/file_table.c +11 -12
@@ -34,7 +34,6 @@ struct files_stat_struct files_stat = { .max_files = NR_FILE }; -DECLARE_LGLOCK (files_lglock);DEFINE_LGLOCK (files_lglock);/* SLAB cache for file structures */
@@ -422,9 +421,9 @@ static inline void __file_sb_list_add(struct file *file, struct super_block *sb)*/ void file_sb_list_add (struct file *file,struct super_block *sb) { -lg_local_lock (files_lglock); +lg_local_lock (&files_lglock);__file_sb_list_add (file, sb); -lg_local_unlock (files_lglock); +lg_local_unlock (&files_lglock); }/**
@@ -437,9 +436,9 @@ void file_sb_list_add(struct file *file, struct super_block *sb)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)); +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)); +lg_local_unlock_cpu (&files_lglock,file_list_cpu (file)); } }
@@ -478,7 +477,7 @@ int fs_may_remount_ro(struct super_block *sb) {struct file *file;/* Check that no files are currently opened for writing. */ -lg_global_lock (files_lglock); +lg_global_lock (&files_lglock);do_file_list_for_each_entry (sb, file) {struct inode *inode = file->f_path.dentry->d_inode;
@@ -490,10 +489,10 @@ int fs_may_remount_ro(struct super_block *sb)if (S_ISREG (inode->i_mode) && (file->f_mode &FMODE_WRITE )) goto too_bad; } while_file_list_for_each_entry; -lg_global_unlock (files_lglock); +lg_global_unlock (&files_lglock);return 1 ;/* Tis' cool bro. */ too_bad: -lg_global_unlock (files_lglock); +lg_global_unlock (&files_lglock);return 0 ; }
@@ -509,7 +508,7 @@ void mark_files_ro(struct super_block *sb)struct file *f; retry: -lg_global_lock (files_lglock); +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))
@@ -526,12 +525,12 @@ retry: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); +lg_global_unlock (&files_lglock);mnt_drop_write (mnt);mntput (mnt); goto retry; } while_file_list_for_each_entry; -lg_global_unlock (files_lglock); +lg_global_unlock (&files_lglock); }void __init files_init (unsigned long mempages)
@@ -549,6 +548,6 @@ void __init files_init(unsigned long mempages) n = (mempages * (PAGE_SIZE /1024 )) /10 ; files_stat.max_files = max_t(unsigned long, n, NR_FILE);files_defer_init (); -lg_lock_init (files_lglock); +lg_lock_init (&files_lglock,"files_lglock" );percpu_counter_init (&nr_files,0 ); }
fs/internal.h +1 -2
@@ -77,8 +77,7 @@ extern void mnt_make_shortterm(struct vfsmount *);extern void __init mnt_init (void ); -DECLARE_BRLOCK (vfsmount_lock); - +extern struct lglock vfsmount_lock;/* * fs_struct.c
fs/namei.c +13 -13
@@ -461,7 +461,7 @@ static int unlazy_walk(struct nameidata *nd, struct dentry *dentry)mntget (nd->path.mnt);rcu_read_unlock (); -br_read_unlock (vfsmount_lock); +br_read_unlock (&vfsmount_lock); nd->flags &= ~LOOKUP_RCU ;return 0 ;
@@ -519,14 +519,14 @@ static int complete_walk(struct nameidata *nd)if (unlikely (!__d_rcu_to_refcount (dentry, nd->seq))) {spin_unlock (&dentry->d_lock);rcu_read_unlock (); -br_read_unlock (vfsmount_lock); +br_read_unlock (&vfsmount_lock);return -ECHILD ; }BUG_ON (nd->inode != dentry->d_inode);spin_unlock (&dentry->d_lock);mntget (nd->path.mnt);rcu_read_unlock (); -br_read_unlock (vfsmount_lock); +br_read_unlock (&vfsmount_lock); }if (likely (!(nd->flags &LOOKUP_JUMPED )))
@@ -691,15 +691,15 @@ int follow_up(struct path *path)struct vfsmount *parent;struct dentry *mountpoint; -br_read_lock (vfsmount_lock); +br_read_lock (&vfsmount_lock); parent = path->mnt->mnt_parent;if (parent == path->mnt) { -br_read_unlock (vfsmount_lock); +br_read_unlock (&vfsmount_lock);return 0 ; }mntget (parent); mountpoint =dget (path->mnt->mnt_mountpoint); -br_read_unlock (vfsmount_lock); +br_read_unlock (&vfsmount_lock);dput (path->dentry); path->dentry = mountpoint;mntput (path->mnt);
@@ -840,7 +840,7 @@ static int follow_managed(struct path *path, unsigned flags)/* Something is mounted on this dentry in another * namespace and/or whatever was mounted there in this * namespace got unmounted before we managed to get the -* vfsmount_lock */ +* &vfsmount_lock */ }/* Handle an automount point */
@@ -965,7 +965,7 @@ failed:if (!(nd->flags &LOOKUP_ROOT )) nd->root.mnt =NULL ;rcu_read_unlock (); -br_read_unlock (vfsmount_lock); +br_read_unlock (&vfsmount_lock);return -ECHILD ; }
@@ -1257,7 +1257,7 @@ static void terminate_walk(struct nameidata *nd)if (!(nd->flags &LOOKUP_ROOT )) nd->root.mnt =NULL ;rcu_read_unlock (); -br_read_unlock (vfsmount_lock); +br_read_unlock (&vfsmount_lock); } }
@@ -1491,7 +1491,7 @@ static int path_init(int dfd, const char *name, unsigned int flags, nd->path = nd->root; nd->inode = inode;if (flags &LOOKUP_RCU ) { -br_read_lock (vfsmount_lock); +br_read_lock (&vfsmount_lock);rcu_read_lock (); nd->seq =__read_seqcount_begin (&nd->path.dentry->d_seq); }else {
@@ -1504,7 +1504,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,if (*name=='/' ) {if (flags &LOOKUP_RCU ) { -br_read_lock (vfsmount_lock); +br_read_lock (&vfsmount_lock);rcu_read_lock ();set_root_rcu (nd); }else {
@@ -1517,7 +1517,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,struct fs_struct *fs = current->fs;unsigned seq; -br_read_lock (vfsmount_lock); +br_read_lock (&vfsmount_lock);rcu_read_lock (); do {
@@ -1553,7 +1553,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,if (fput_needed) *fp = file; nd->seq =__read_seqcount_begin (&nd->path.dentry->d_seq); -br_read_lock (vfsmount_lock); +br_read_lock (&vfsmount_lock);rcu_read_lock (); }else {path_get (&file->f_path);
fs/namespace.c +62 -62
380 lines not on this page · raw message
fs/pnode.c +2 -2
@@ -273,12 +273,12 @@ int propagate_mnt(struct vfsmount *dest_mnt, struct dentry *dest_dentry, prev_src_mnt = child; } out: -br_write_lock (vfsmount_lock); +br_write_lock (&vfsmount_lock);while (!list_empty (&tmp_list)) { child = list_first_entry(&tmp_list, struct vfsmount, mnt_hash);umount_tree (child,0 , &umount_list); } -br_write_unlock (vfsmount_lock); +br_write_unlock (&vfsmount_lock);release_mounts (&umount_list);return ret; }
include/linux/lglock.h +26 -126
167 lines not on this page · raw message
kernel/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o \ hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \ async.o range.o -obj-y += groups.o +obj-y += groups.o lglock.o ifdef CONFIG_FUNCTION_TRACER # Do not trace debug files and internal ftrace files
kernel/lglock.c new file +101 -0
101 lines not on this page · raw message
Signature · 1 line
1.7.4.4
Quoted 3 lines · On Wed, 28 Sep 2011 16:30:44 -0700 Andi Kleen <[email protected]> wrote:
lglocks and brlocks are currently generated with some complicated macros in
lglock.h. But there's no reason, I can see, to not just use common utility functions that get pointers to the lglock.
https://lkml.org/lkml/2011/8/24/454 makes me suspect that there's a bug in brlocks, or they're being misused in some way. However the code doesn't have an identifiable maintainer, so things just sit there.
I guess these problems don't preclude cosmetic cleanups, but it's all a bit regrettable.