Re: FILEDESC_LOCK() implementation

From: Poul-Henning Kamp <phk_at_phk.freebsd.dk>
Date: Mon, 12 Jun 2006 05:48:41 +0000
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.
Received on Mon Jun 12 2006 - 03:48:47 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:57 UTC