Freezing filesystem activity

Siddharth Aggarwal saggarwa at cs.utah.edu
Thu Dec 30 22:48:11 PST 2004


I want to freeze any filesystem activity in the kernel (a pseudo driver)
i.e. while my driver code is executing (this code basically flushes
buffer cache blocks to disk), I donot want any other filesystem
operations coming in. I tried this by locking the filesystem before my
code and unlocking right after as shown below. There is a problem because
it causes a hang (rather it seems as if

1. The flush is happening indefinitely
as if the filesystem never got locked and hence more disk updates keep
coming in

or

2. The filesystem unlock is not happening properly and hence nothing can
proceed.

Any suggestions to rectify or probe this problem?

Thanks,
Sid.

my_code()
{
 vp = lock_filesystem();
 sync(); // flush to disk
 unlock_filesystem(vp);
}

struct vnode * lock_filesystem()
{
    NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/", curproc);
    if ((error = vn_open(&nd, FREAD, 0)) != 0) {
        printf ("Error opening filesystem \n");
        return 0;
    }
    vp = nd.ni_vp;
    vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
    NDFREE(&nd, NDF_ONLY_PNBUF);
    return vp;
}

unlock_filesystem(struct vnode * vp)
{
    VOP_UNLOCK(vp, 0, curproc);
}



More information about the freebsd-fs mailing list