Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Jun 2006 05:48:41 +0000
From:      "Poul-Henning Kamp" <phk@phk.freebsd.dk>
To:        Kris Kennaway <kris@obsecurity.org>
Cc:        current@FreeBSD.org
Subject:   Re: FILEDESC_LOCK() implementation 
Message-ID:  <33721.1150091321@critter.freebsd.dk>
In-Reply-To: Your message of "Mon, 12 Jun 2006 01:41:15 -0400." <20060612054115.GA42379@xor.obsecurity.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <20060612054115.GA42379@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@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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?33721.1150091321>