mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
bsdacct: turn the acct_lock from on-the-struct to global
Don't use per-bsd-acct-struct lock, but work with a global one. This lock is taken for short periods, so it doesn't seem it'll become a bottleneck, but it will allow us to easily avoid many locking difficulties in the future. So this is a mostly s/acct_globals.lock/acct_lock/ over the file. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Cc: Balbir Singh <balbir@in.ibm.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
e59a04a7aa
commit
a75d979765
1 changed files with 21 additions and 21 deletions
|
@ -83,7 +83,6 @@ static void do_acct_process(struct pid_namespace *ns, struct file *);
|
||||||
* the cache line to have the data after getting the lock.
|
* the cache line to have the data after getting the lock.
|
||||||
*/
|
*/
|
||||||
struct bsd_acct_struct {
|
struct bsd_acct_struct {
|
||||||
spinlock_t lock;
|
|
||||||
volatile int active;
|
volatile int active;
|
||||||
volatile int needcheck;
|
volatile int needcheck;
|
||||||
struct file *file;
|
struct file *file;
|
||||||
|
@ -91,8 +90,9 @@ struct bsd_acct_struct {
|
||||||
struct timer_list timer;
|
struct timer_list timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct bsd_acct_struct acct_globals __cacheline_aligned =
|
static DEFINE_SPINLOCK(acct_lock);
|
||||||
{__SPIN_LOCK_UNLOCKED(acct_globals.lock)};
|
|
||||||
|
static struct bsd_acct_struct acct_globals __cacheline_aligned;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called whenever the timer says to check the free space.
|
* Called whenever the timer says to check the free space.
|
||||||
|
@ -114,11 +114,11 @@ static int check_free_space(struct file *file)
|
||||||
sector_t resume;
|
sector_t resume;
|
||||||
sector_t suspend;
|
sector_t suspend;
|
||||||
|
|
||||||
spin_lock(&acct_globals.lock);
|
spin_lock(&acct_lock);
|
||||||
res = acct_globals.active;
|
res = acct_globals.active;
|
||||||
if (!file || !acct_globals.needcheck)
|
if (!file || !acct_globals.needcheck)
|
||||||
goto out;
|
goto out;
|
||||||
spin_unlock(&acct_globals.lock);
|
spin_unlock(&acct_lock);
|
||||||
|
|
||||||
/* May block */
|
/* May block */
|
||||||
if (vfs_statfs(file->f_path.dentry, &sbuf))
|
if (vfs_statfs(file->f_path.dentry, &sbuf))
|
||||||
|
@ -140,7 +140,7 @@ static int check_free_space(struct file *file)
|
||||||
* If some joker switched acct_globals.file under us we'ld better be
|
* If some joker switched acct_globals.file under us we'ld better be
|
||||||
* silent and _not_ touch anything.
|
* silent and _not_ touch anything.
|
||||||
*/
|
*/
|
||||||
spin_lock(&acct_globals.lock);
|
spin_lock(&acct_lock);
|
||||||
if (file != acct_globals.file) {
|
if (file != acct_globals.file) {
|
||||||
if (act)
|
if (act)
|
||||||
res = act>0;
|
res = act>0;
|
||||||
|
@ -165,7 +165,7 @@ static int check_free_space(struct file *file)
|
||||||
add_timer(&acct_globals.timer);
|
add_timer(&acct_globals.timer);
|
||||||
res = acct_globals.active;
|
res = acct_globals.active;
|
||||||
out:
|
out:
|
||||||
spin_unlock(&acct_globals.lock);
|
spin_unlock(&acct_lock);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ out:
|
||||||
* Close the old accounting file (if currently open) and then replace
|
* Close the old accounting file (if currently open) and then replace
|
||||||
* it with file (if non-NULL).
|
* it with file (if non-NULL).
|
||||||
*
|
*
|
||||||
* NOTE: acct_globals.lock MUST be held on entry and exit.
|
* NOTE: acct_lock MUST be held on entry and exit.
|
||||||
*/
|
*/
|
||||||
static void acct_file_reopen(struct file *file)
|
static void acct_file_reopen(struct file *file)
|
||||||
{
|
{
|
||||||
|
@ -201,11 +201,11 @@ static void acct_file_reopen(struct file *file)
|
||||||
}
|
}
|
||||||
if (old_acct) {
|
if (old_acct) {
|
||||||
mnt_unpin(old_acct->f_path.mnt);
|
mnt_unpin(old_acct->f_path.mnt);
|
||||||
spin_unlock(&acct_globals.lock);
|
spin_unlock(&acct_lock);
|
||||||
do_acct_process(old_ns, old_acct);
|
do_acct_process(old_ns, old_acct);
|
||||||
filp_close(old_acct, NULL);
|
filp_close(old_acct, NULL);
|
||||||
put_pid_ns(old_ns);
|
put_pid_ns(old_ns);
|
||||||
spin_lock(&acct_globals.lock);
|
spin_lock(&acct_lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,10 +235,10 @@ static int acct_on(char *name)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock(&acct_globals.lock);
|
spin_lock(&acct_lock);
|
||||||
mnt_pin(file->f_path.mnt);
|
mnt_pin(file->f_path.mnt);
|
||||||
acct_file_reopen(file);
|
acct_file_reopen(file);
|
||||||
spin_unlock(&acct_globals.lock);
|
spin_unlock(&acct_lock);
|
||||||
|
|
||||||
mntput(file->f_path.mnt); /* it's pinned, now give up active reference */
|
mntput(file->f_path.mnt); /* it's pinned, now give up active reference */
|
||||||
|
|
||||||
|
@ -272,9 +272,9 @@ asmlinkage long sys_acct(const char __user *name)
|
||||||
} else {
|
} else {
|
||||||
error = security_acct(NULL);
|
error = security_acct(NULL);
|
||||||
if (!error) {
|
if (!error) {
|
||||||
spin_lock(&acct_globals.lock);
|
spin_lock(&acct_lock);
|
||||||
acct_file_reopen(NULL);
|
acct_file_reopen(NULL);
|
||||||
spin_unlock(&acct_globals.lock);
|
spin_unlock(&acct_lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
|
@ -289,10 +289,10 @@ asmlinkage long sys_acct(const char __user *name)
|
||||||
*/
|
*/
|
||||||
void acct_auto_close_mnt(struct vfsmount *m)
|
void acct_auto_close_mnt(struct vfsmount *m)
|
||||||
{
|
{
|
||||||
spin_lock(&acct_globals.lock);
|
spin_lock(&acct_lock);
|
||||||
if (acct_globals.file && acct_globals.file->f_path.mnt == m)
|
if (acct_globals.file && acct_globals.file->f_path.mnt == m)
|
||||||
acct_file_reopen(NULL);
|
acct_file_reopen(NULL);
|
||||||
spin_unlock(&acct_globals.lock);
|
spin_unlock(&acct_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -304,12 +304,12 @@ void acct_auto_close_mnt(struct vfsmount *m)
|
||||||
*/
|
*/
|
||||||
void acct_auto_close(struct super_block *sb)
|
void acct_auto_close(struct super_block *sb)
|
||||||
{
|
{
|
||||||
spin_lock(&acct_globals.lock);
|
spin_lock(&acct_lock);
|
||||||
if (acct_globals.file &&
|
if (acct_globals.file &&
|
||||||
acct_globals.file->f_path.mnt->mnt_sb == sb) {
|
acct_globals.file->f_path.mnt->mnt_sb == sb) {
|
||||||
acct_file_reopen(NULL);
|
acct_file_reopen(NULL);
|
||||||
}
|
}
|
||||||
spin_unlock(&acct_globals.lock);
|
spin_unlock(&acct_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -594,15 +594,15 @@ void acct_process(void)
|
||||||
if (!acct_globals.file)
|
if (!acct_globals.file)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
spin_lock(&acct_globals.lock);
|
spin_lock(&acct_lock);
|
||||||
file = acct_globals.file;
|
file = acct_globals.file;
|
||||||
if (unlikely(!file)) {
|
if (unlikely(!file)) {
|
||||||
spin_unlock(&acct_globals.lock);
|
spin_unlock(&acct_lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
get_file(file);
|
get_file(file);
|
||||||
ns = get_pid_ns(acct_globals.ns);
|
ns = get_pid_ns(acct_globals.ns);
|
||||||
spin_unlock(&acct_globals.lock);
|
spin_unlock(&acct_lock);
|
||||||
|
|
||||||
do_acct_process(ns, file);
|
do_acct_process(ns, file);
|
||||||
fput(file);
|
fput(file);
|
||||||
|
|
Loading…
Reference in a new issue