mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
Move common locking for filemon_inuse and struct filemon* to filemon_pid_check().
This keeps the lock for the filemon_inuse list held only while reading the list. Sponsored by: EMC / Isilon Storage Division MFC after: 2 weeks
This commit is contained in:
parent
144811cc61
commit
1ab9f216d2
1 changed files with 5 additions and 135 deletions
|
|
@ -1,6 +1,7 @@
|
|||
/*-
|
||||
* Copyright (c) 2011, David E. O'Brien.
|
||||
* Copyright (c) 2009-2011, Juniper Networks, Inc.
|
||||
* Copyright (c) 2015, EMC Corp.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -86,17 +87,21 @@ filemon_pid_check(struct proc *p)
|
|||
{
|
||||
struct filemon *filemon;
|
||||
|
||||
filemon_lock_read();
|
||||
sx_slock(&proctree_lock);
|
||||
while (p != initproc) {
|
||||
TAILQ_FOREACH(filemon, &filemons_inuse, link) {
|
||||
if (p->p_pid == filemon->pid) {
|
||||
sx_sunlock(&proctree_lock);
|
||||
filemon_filemon_lock(filemon);
|
||||
filemon_unlock_read();
|
||||
return (filemon);
|
||||
}
|
||||
}
|
||||
p = proc_realparent(p);
|
||||
}
|
||||
sx_sunlock(&proctree_lock);
|
||||
filemon_unlock_read();
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
|
@ -138,13 +143,7 @@ filemon_wrapper_chdir(struct thread *td, struct chdir_args *uap)
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = sys_chdir(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
copyinstr(uap->path, filemon->fname1,
|
||||
sizeof(filemon->fname1), &done);
|
||||
|
||||
|
|
@ -157,9 +156,6 @@ filemon_wrapper_chdir(struct thread *td, struct chdir_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -177,13 +173,7 @@ filemon_wrapper_execve(struct thread *td, struct execve_args *uap)
|
|||
copyinstr(uap->fname, fname, sizeof(fname), &done);
|
||||
|
||||
if ((ret = sys_execve(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
len = snprintf(filemon->msgbufr,
|
||||
sizeof(filemon->msgbufr), "E %d %s\n",
|
||||
curproc->p_pid, fname);
|
||||
|
|
@ -193,9 +183,6 @@ filemon_wrapper_execve(struct thread *td, struct execve_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -215,13 +202,7 @@ filemon_wrapper_freebsd32_execve(struct thread *td,
|
|||
copyinstr(uap->fname, fname, sizeof(fname), &done);
|
||||
|
||||
if ((ret = freebsd32_execve(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
len = snprintf(filemon->msgbufr,
|
||||
sizeof(filemon->msgbufr), "E %d %s\n",
|
||||
curproc->p_pid, fname);
|
||||
|
|
@ -231,9 +212,6 @@ filemon_wrapper_freebsd32_execve(struct thread *td,
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -248,13 +226,7 @@ filemon_wrapper_fork(struct thread *td, struct fork_args *uap)
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = sys_fork(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
len = snprintf(filemon->msgbufr,
|
||||
sizeof(filemon->msgbufr), "F %d %ld\n",
|
||||
curproc->p_pid, (long)curthread->td_retval[0]);
|
||||
|
|
@ -264,9 +236,6 @@ filemon_wrapper_fork(struct thread *td, struct fork_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -281,13 +250,7 @@ filemon_wrapper_open(struct thread *td, struct open_args *uap)
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = sys_open(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
copyinstr(uap->path, filemon->fname1,
|
||||
sizeof(filemon->fname1), &done);
|
||||
|
||||
|
|
@ -313,9 +276,6 @@ filemon_wrapper_open(struct thread *td, struct open_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -330,13 +290,7 @@ filemon_wrapper_openat(struct thread *td, struct openat_args *uap)
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = sys_openat(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
copyinstr(uap->path, filemon->fname1,
|
||||
sizeof(filemon->fname1), &done);
|
||||
|
||||
|
|
@ -375,9 +329,6 @@ filemon_wrapper_openat(struct thread *td, struct openat_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -392,13 +343,7 @@ filemon_wrapper_rename(struct thread *td, struct rename_args *uap)
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = sys_rename(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
copyinstr(uap->from, filemon->fname1,
|
||||
sizeof(filemon->fname1), &done);
|
||||
copyinstr(uap->to, filemon->fname2,
|
||||
|
|
@ -413,9 +358,6 @@ filemon_wrapper_rename(struct thread *td, struct rename_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -430,13 +372,7 @@ filemon_wrapper_link(struct thread *td, struct link_args *uap)
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = sys_link(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
copyinstr(uap->path, filemon->fname1,
|
||||
sizeof(filemon->fname1), &done);
|
||||
copyinstr(uap->link, filemon->fname2,
|
||||
|
|
@ -451,9 +387,6 @@ filemon_wrapper_link(struct thread *td, struct link_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -468,13 +401,7 @@ filemon_wrapper_symlink(struct thread *td, struct symlink_args *uap)
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = sys_symlink(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
copyinstr(uap->path, filemon->fname1,
|
||||
sizeof(filemon->fname1), &done);
|
||||
copyinstr(uap->link, filemon->fname2,
|
||||
|
|
@ -489,9 +416,6 @@ filemon_wrapper_symlink(struct thread *td, struct symlink_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -507,13 +431,7 @@ filemon_wrapper_linkat(struct thread *td, struct linkat_args *uap)
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = sys_linkat(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
copyinstr(uap->path1, filemon->fname1,
|
||||
sizeof(filemon->fname1), &done);
|
||||
copyinstr(uap->path2, filemon->fname2,
|
||||
|
|
@ -528,9 +446,6 @@ filemon_wrapper_linkat(struct thread *td, struct linkat_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -546,13 +461,7 @@ filemon_wrapper_stat(struct thread *td, struct stat_args *uap)
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = sys_stat(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
copyinstr(uap->path, filemon->fname1,
|
||||
sizeof(filemon->fname1), &done);
|
||||
|
||||
|
|
@ -565,9 +474,6 @@ filemon_wrapper_stat(struct thread *td, struct stat_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -584,13 +490,7 @@ filemon_wrapper_freebsd32_stat(struct thread *td,
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = freebsd32_stat(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
copyinstr(uap->path, filemon->fname1,
|
||||
sizeof(filemon->fname1), &done);
|
||||
|
||||
|
|
@ -603,9 +503,6 @@ filemon_wrapper_freebsd32_stat(struct thread *td,
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -622,13 +519,7 @@ filemon_wrapper_sys_exit(struct thread *td, struct sys_exit_args *uap)
|
|||
/* Get timestamp before locking. */
|
||||
getmicrotime(&now);
|
||||
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
len = snprintf(filemon->msgbufr, sizeof(filemon->msgbufr),
|
||||
"X %d %d\n", curproc->p_pid, uap->rval);
|
||||
|
||||
|
|
@ -649,9 +540,6 @@ filemon_wrapper_sys_exit(struct thread *td, struct sys_exit_args *uap)
|
|||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
|
||||
sys_sys_exit(td, uap);
|
||||
}
|
||||
|
||||
|
|
@ -664,13 +552,7 @@ filemon_wrapper_unlink(struct thread *td, struct unlink_args *uap)
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = sys_unlink(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
copyinstr(uap->path, filemon->fname1,
|
||||
sizeof(filemon->fname1), &done);
|
||||
|
||||
|
|
@ -683,9 +565,6 @@ filemon_wrapper_unlink(struct thread *td, struct unlink_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
@ -699,13 +578,7 @@ filemon_wrapper_vfork(struct thread *td, struct vfork_args *uap)
|
|||
struct filemon *filemon;
|
||||
|
||||
if ((ret = sys_vfork(td, uap)) == 0) {
|
||||
/* Grab a read lock on the filemon inuse list. */
|
||||
filemon_lock_read();
|
||||
|
||||
if ((filemon = filemon_pid_check(curproc)) != NULL) {
|
||||
/* Lock the found filemon structure. */
|
||||
filemon_filemon_lock(filemon);
|
||||
|
||||
len = snprintf(filemon->msgbufr,
|
||||
sizeof(filemon->msgbufr), "F %d %ld\n",
|
||||
curproc->p_pid, (long)curthread->td_retval[0]);
|
||||
|
|
@ -715,9 +588,6 @@ filemon_wrapper_vfork(struct thread *td, struct vfork_args *uap)
|
|||
/* Unlock the found filemon structure. */
|
||||
filemon_filemon_unlock(filemon);
|
||||
}
|
||||
|
||||
/* Release the read lock. */
|
||||
filemon_unlock_read();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
|
|
|||
Loading…
Reference in a new issue