Skip to content

Instantly share code, notes, and snippets.

@tuxillo
Created June 13, 2013 19:40
Show Gist options
  • Save tuxillo/5776698 to your computer and use it in GitHub Desktop.
Save tuxillo/5776698 to your computer and use it in GitHub Desktop.
/*
* Main tasks to be performed.
* 1) When inode is NULL recycle the vnode
* 2) When the inode has 0 links:
* - Check if in the TAILQ, if so remove.
* - Destroy the inode.
* - Recycle the vnode.
* 3) If none of the above, add the node to the TAILQ
* when it has a valid fd and there is room on the
* queue.
*
*/
static int
dirfs_inactive(struct vop_inactive_args *ap)
{
struct vnode *vp = ap->a_vp;
dirfs_mount_t dmp = VFS_TO_DIRFS(vp->v_mount);
dirfs_node_t dnp = VP_TO_NODE(vp);
dirfs_node_t d1, d2;
/* Degenerate case */
if (dnp == NULL) {
vrecycle(vp);
return 0;
}
dirfs_mount_gettoken(dmp);
/*
* Deal with the case the inode has 0 links which means it was unlinked.
* First remove it from the TAILQ, if there, and then destroy the inode
* and recycle the vnode.
*/
if (dnp->dn_links == 0) {
TAILQ_FOREACH_MUTABLE(d1, &dmp->dm_fdlist, dn_fdentry, d2) {
if (dnp == dn1) {
TAILQ_REMOVE(&dmp->dm_fdlist, d1, dn_fdentry);
break;
}
}
dirfs_node_free(dnp);
vrecycle(vp);
} else {
dirfs_node_lock(dnp);
if ((dnp->dn_state & DIRFS_PASVFD) == 0 &&
dnp->dn_fd != DIRFS_NOFD) {
TAILQ_INSERT_TAIL(&dmp->dm_fdlist, dnp, dn_fdentry);
dnp->dn_state |= DIRFS_PASVFD;
dbg(5, "Added. dnp->dn_state=%d\n", dnp->dn_state);
}
dirfs_node_unlock(dnp);
}
dirfs_mount_reltoken(dmp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment