FILEDESC_LOCK() implementation
Poul-Henning Kamp
phk at phk.freebsd.dk
Mon Jun 12 05:48:47 UTC 2006
In message <20060612054115.GA42379 at xor.obsecurity.org>, Kris Kennaway writes:
>I wonder if something better can be done with the funky home-grown
>locking in FILEDESC_LOCK() (see <sys/filedesc.h>) to make it more
>light-weight?
It probably can.
What's needed is a combined short/long lock, where you can either
grab lock for sleepable locking (like for instance sxlocks) or only
grab a quick version (like a mutex) for lightweight operations.
See vfs_syscalls.c for examples like:
FILEDESC_LOCK(fdp);
if (chroot_allow_open_directories == 0 ||
(chroot_allow_open_directories == 1 && fdp->fd_rdir != rootvnode)) {
error = chroot_refuse_vdir_fds(fdp);
if (error) {
FILEDESC_UNLOCK(fdp);
return (error);
}
}
oldvp = fdp->fd_rdir;
fdp->fd_rdir = vp;
VREF(fdp->fd_rdir);
if (!fdp->fd_jdir) {
fdp->fd_jdir = vp;
VREF(fdp->fd_jdir);
}
FILEDESC_UNLOCK(fdp);
and
FILEDESC_LOCK_FAST(fdp);
vp = fdp->fd_cdir;
fdp->fd_cdir = nd.ni_vp;
FILEDESC_UNLOCK_FAST(fdp);
respectively
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
More information about the freebsd-current
mailing list