コード例 #1
0
ファイル: vnode_pager.c プロジェクト: JabirTech/Source
/* Create the VM system backing object for this vnode */
int
vnode_create_vobject(struct vnode *vp, off_t isize, struct thread *td)
{
	vm_object_t object;
	vm_ooffset_t size = isize;
	struct vattr va;

	if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
		return (0);

	while ((object = vp->v_object) != NULL) {
		VM_OBJECT_WLOCK(object);
		if (!(object->flags & OBJ_DEAD)) {
			VM_OBJECT_WUNLOCK(object);
			return (0);
		}
		VOP_UNLOCK(vp, 0);
		vm_object_set_flag(object, OBJ_DISCONNECTWNT);
		VM_OBJECT_SLEEP(object, object, PDROP | PVM, "vodead", 0);
		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
	}

	if (size == 0) {
		if (vn_isdisk(vp, NULL)) {
			size = IDX_TO_OFF(INT_MAX);
		} else {
			if (VOP_GETATTR(vp, &va, td->td_ucred))
				return (0);
			size = va.va_size;
		}
	}

	object = vnode_pager_alloc(vp, size, 0, 0, td->td_ucred);
	/*
	 * Dereference the reference we just created.  This assumes
	 * that the object is associated with the vp.
	 */
	VM_OBJECT_WLOCK(object);
	object->ref_count--;
	VM_OBJECT_WUNLOCK(object);
	vrele(vp);

	KASSERT(vp->v_object != NULL, ("vnode_create_vobject: NULL object"));

	return (0);
}
コード例 #2
0
ファイル: ufs_extattr.c プロジェクト: MarginC/kame
/*
 * Enable an EA using the passed file system, backing vnode, attribute name,
 * namespace, and proc.  Will perform a VOP_OPEN() on the vp, so expects vp
 * to be locked when passed in.  The vnode will be returned unlocked,
 * regardless of success/failure of the function.  As a result, the caller
 * will always need to vrele(), but not vput().
 */
static int
ufs_extattr_enable_with_open(struct ufsmount *ump, struct vnode *vp,
    int attrnamespace, const char *attrname, struct proc *p)
{
	int error;

	error = VOP_OPEN(vp, FREAD|FWRITE, p->p_ucred, p);
	if (error) {
		printf("ufs_extattr_enable_with_open.VOP_OPEN(): failed "
		    "with %d\n", error);
		VOP_UNLOCK(vp, 0, p);
		return (error);
	}

#if 0
	/* - XXX */
	/*
	 * XXX: Note, should VOP_CLOSE() if vfs_object_create() fails, but due
	 * to a similar piece of code in vn_open(), we don't.
	 */
	if (vn_canvmio(vp) == TRUE)
		if ((error = vfs_object_create(vp, p, p->p_ucred)) != 0) {
			/*
			 * XXX: bug replicated from vn_open(): should
			 * VOP_CLOSE() here.
			 */
			VOP_UNLOCK(vp, 0, p);
			return (error);
		}
#endif

	vp->v_writecount++;

	vref(vp);

	VOP_UNLOCK(vp, 0, p);

	error = ufs_extattr_enable(ump, attrnamespace, attrname, vp, p);
	if (error != 0)
		vn_close(vp, FREAD|FWRITE, p->p_ucred, p);
	return (error);
}