- Lock down the accounting code globals with a subsystem mutex.
Reviewed by: jhb, mdodd
This commit is contained in:
parent
8e05457085
commit
4f39d5d511
@ -92,6 +92,9 @@ static struct vnode *savacctp;
|
|||||||
static struct ucred *savacctcred;
|
static struct ucred *savacctcred;
|
||||||
static int savacctflags;
|
static int savacctflags;
|
||||||
|
|
||||||
|
static struct mtx acct_mtx;
|
||||||
|
MTX_SYSINIT(acct, &acct_mtx, "accounting", MTX_DEF);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Values associated with enabling and disabling accounting
|
* Values associated with enabling and disabling accounting
|
||||||
*/
|
*/
|
||||||
@ -153,6 +156,8 @@ acct(td, uap)
|
|||||||
* If accounting was previously enabled, kill the old space-watcher,
|
* If accounting was previously enabled, kill the old space-watcher,
|
||||||
* close the file, and (if no new file was specified, leave).
|
* close the file, and (if no new file was specified, leave).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
mtx_lock(&acct_mtx);
|
||||||
if (acctp != NULLVP || savacctp != NULLVP) {
|
if (acctp != NULLVP || savacctp != NULLVP) {
|
||||||
callout_stop(&acctwatch_callout);
|
callout_stop(&acctwatch_callout);
|
||||||
error = vn_close((acctp != NULLVP ? acctp : savacctp),
|
error = vn_close((acctp != NULLVP ? acctp : savacctp),
|
||||||
@ -175,6 +180,7 @@ acct(td, uap)
|
|||||||
callout_init(&acctwatch_callout, 0);
|
callout_init(&acctwatch_callout, 0);
|
||||||
acctwatch(NULL);
|
acctwatch(NULL);
|
||||||
done2:
|
done2:
|
||||||
|
mtx_unlock(&acct_mtx);
|
||||||
mtx_unlock(&Giant);
|
mtx_unlock(&Giant);
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
@ -194,13 +200,18 @@ acct_process(td)
|
|||||||
struct acct acct;
|
struct acct acct;
|
||||||
struct rusage *r;
|
struct rusage *r;
|
||||||
struct timeval ut, st, tmp;
|
struct timeval ut, st, tmp;
|
||||||
int t;
|
int t, ret;
|
||||||
struct vnode *vp;
|
struct vnode *vp;
|
||||||
|
struct ucred *uc;
|
||||||
|
|
||||||
|
mtx_lock(&acct_mtx);
|
||||||
|
|
||||||
/* If accounting isn't enabled, don't bother */
|
/* If accounting isn't enabled, don't bother */
|
||||||
vp = acctp;
|
vp = acctp;
|
||||||
if (vp == NULLVP)
|
if (vp == NULLVP) {
|
||||||
|
mtx_unlock(&acct_mtx);
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get process accounting information.
|
* Get process accounting information.
|
||||||
@ -266,9 +277,15 @@ acct_process(td)
|
|||||||
* Write the accounting information to the file.
|
* Write the accounting information to the file.
|
||||||
*/
|
*/
|
||||||
VOP_LEASE(vp, td, acctcred, LEASE_WRITE);
|
VOP_LEASE(vp, td, acctcred, LEASE_WRITE);
|
||||||
return (vn_rdwr(UIO_WRITE, vp, (caddr_t)&acct, sizeof (acct),
|
uc = crhold(acctcred);
|
||||||
(off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, acctcred, NOCRED,
|
vref(vp);
|
||||||
(int *)0, td));
|
mtx_unlock(&acct_mtx);
|
||||||
|
ret = vn_rdwr(UIO_WRITE, vp, (caddr_t)&acct, sizeof (acct),
|
||||||
|
(off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, uc, NOCRED,
|
||||||
|
(int *)0, td);
|
||||||
|
vrele(vp);
|
||||||
|
crfree(uc);
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -323,12 +340,15 @@ acctwatch(a)
|
|||||||
{
|
{
|
||||||
struct statfs sb;
|
struct statfs sb;
|
||||||
|
|
||||||
|
mtx_lock(&acct_mtx);
|
||||||
|
|
||||||
if (savacctp != NULLVP) {
|
if (savacctp != NULLVP) {
|
||||||
if (savacctp->v_type == VBAD) {
|
if (savacctp->v_type == VBAD) {
|
||||||
(void) vn_close(savacctp, savacctflags, savacctcred,
|
(void) vn_close(savacctp, savacctflags, savacctcred,
|
||||||
NULL);
|
NULL);
|
||||||
savacctp = NULLVP;
|
savacctp = NULLVP;
|
||||||
savacctcred = NOCRED;
|
savacctcred = NOCRED;
|
||||||
|
mtx_unlock(&acct_mtx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(void)VFS_STATFS(savacctp->v_mount, &sb, (struct thread *)0);
|
(void)VFS_STATFS(savacctp->v_mount, &sb, (struct thread *)0);
|
||||||
@ -348,6 +368,7 @@ acctwatch(a)
|
|||||||
acctp = NULLVP;
|
acctp = NULLVP;
|
||||||
crfree(acctcred);
|
crfree(acctcred);
|
||||||
acctcred = NOCRED;
|
acctcred = NOCRED;
|
||||||
|
mtx_unlock(&acct_mtx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(void)VFS_STATFS(acctp->v_mount, &sb, (struct thread *)0);
|
(void)VFS_STATFS(acctp->v_mount, &sb, (struct thread *)0);
|
||||||
@ -360,4 +381,5 @@ acctwatch(a)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
callout_reset(&acctwatch_callout, acctchkfreq * hz, acctwatch, NULL);
|
callout_reset(&acctwatch_callout, acctchkfreq * hz, acctwatch, NULL);
|
||||||
|
mtx_unlock(&acct_mtx);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user