#include <afsconfig.h>
#include "afs/param.h"
+#ifdef AFS_FBSD70_ENV
+#include <sys/param.h>
+#include <sys/vnode.h>
+ void
+ vgonel(struct vnode *vp, struct thread *td);
+#endif
-RCSID
- ("$Header$");
#include "afs/sysincludes.h" /* Standard vendor system headers */
#include "afsincludes.h" /* Afs-based standard headers */
#include <limits.h>
#include <float.h>
+/*
+ * FreeBSD implementation notes:
+ * Most of these operations require us to frob vm_objects. Most
+ * functions require that the object be locked (with VM_OBJECT_LOCK)
+ * on entry and leave it locked on exit. In order to get the
+ * vm_object itself we call VOP_GETVOBJECT on the vnode; the
+ * locking protocol requires that we do so with the heavy vnode lock
+ * held and the vnode interlock unlocked, and it returns the same
+ * way.
+ *
+ * The locking protocol for vnodes is defined in
+ * kern/vnode_if.src and sys/vnode.h; the locking is still a work in
+ * progress, so some fields are (as of 5.1) still protected by Giant
+ * rather than an explicit lock.
+ */
+
+#ifdef AFS_FBSD60_ENV
+#define VOP_GETVOBJECT(vp, objp) (*(objp) = (vp)->v_object)
+#endif
+
+#if defined(AFS_FBSD80_ENV)
+#define lock_vnode(v) vn_lock((v), LK_EXCLUSIVE | LK_RETRY)
+#define unlock_vnode(v) VOP_UNLOCK((v), 0)
+#elif defined(AFS_FBSD50_ENV)
+#define lock_vnode(v) vn_lock((v), LK_EXCLUSIVE | LK_RETRY, curthread)
+#define unlock_vnode(v) VOP_UNLOCK((v), 0, curthread)
+#else
+#define lock_vnode(v) vn_lock((v), LK_EXCLUSIVE | LK_RETRY, curproc)
+#define unlock_vnode(v) VOP_UNLOCK((v), 0, curproc)
+/* need splvm() protection? */
+#define VM_OBJECT_LOCK(o)
+#define VM_OBJECT_UNLOCK(o)
+#endif
+
/* Try to discard pages, in order to recycle a vcache entry.
*
* We also make some sanity checks: ref count, open count, held locks.
* therefore obsolescent.
*
* OSF/1 Locking: VN_LOCK has been called.
+ * We do not lock the vnode here, but instead require that it be exclusive
+ * locked by code calling osi_VM_StoreAllSegments directly, or scheduling it
+ * from the bqueue - Matt
+ * Maybe better to just call vnode_pager_setsize()?
*/
int
osi_VM_FlushVCache(struct vcache *avc, int *slept)
return EBUSY;
/* if a lock is held, give up */
- if (CheckLock(&avc->lock) || afs_CheckBozonLock(&avc->pvnLock))
+ if (CheckLock(&avc->lock))
return EBUSY;
+ return(0);
+
AFS_GUNLOCK();
vp = AFSTOV(avc);
- simple_lock(&vp->v_interlock);
+#ifndef AFS_FBSD70_ENV
+ lock_vnode(vp);
+#endif
if (VOP_GETVOBJECT(vp, &obj) == 0) {
+ VM_OBJECT_LOCK(obj);
vm_object_page_remove(obj, 0, 0, FALSE);
-#if 0
+#if 1
if (obj->ref_count == 0) {
- vgonel(vp, curproc);
simple_lock(&vp->v_interlock);
+ vgonel(vp, curthread);
vp->v_tag = VT_AFS;
SetAfsVnode(vp);
}
#endif
+ VM_OBJECT_UNLOCK(obj);
}
- simple_unlock(&vp->v_interlock);
+#ifndef AFS_FBSD70_ENV
+ unlock_vnode(vp);
+#endif
AFS_GLOCK();
return 0;
AFS_GUNLOCK();
tries = 5;
vp = AFSTOV(avc);
+
+ /*
+ * I don't understand this. Why not just call vm_object_page_clean()
+ * and be done with it? I particularly don't understand why we're calling
+ * vget() here. Is there some reason to believe that the vnode might
+ * be being recycled at this point? I don't think there's any need for
+ * this loop, either -- if we keep the vnode locked all the time,
+ * that and the object lock will prevent any new pages from appearing.
+ * The loop is what causes the race condition. -GAW
+ */
do {
anyio = 0;
- simple_lock(&vp->v_interlock);
if (VOP_GETVOBJECT(vp, &obj) == 0 && (obj->flags & OBJ_MIGHTBEDIRTY)) {
#ifdef AFS_FBSD50_ENV
- if (!vget(vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY, curthread)) {
+ if (!vget(vp, LK_EXCLUSIVE | LK_RETRY, curthread)) {
#else
- if (!vget
- (vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ,
- curproc)) {
+ if (!vget(vp, LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curproc)) {
#endif
- if (VOP_GETVOBJECT(vp, &obj) == 0) {
- vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
- anyio = 1;
+ if (VOP_GETVOBJECT(vp, &obj) == 0) {
+ VM_OBJECT_LOCK(obj);
+ vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
+ VM_OBJECT_UNLOCK(obj);
+ anyio = 1;
+ }
+ vput(vp);
}
- vput(vp);
}
- } else
- simple_unlock(&vp->v_interlock);
} while (anyio && (--tries > 0));
AFS_GLOCK();
ObtainWriteLock(&avc->lock, 94);
* be some pages around when we return, newly created by concurrent activity.
*/
void
-osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync)
+osi_VM_TryToSmush(struct vcache *avc, afs_ucred_t *acred, int sync)
{
struct vnode *vp;
- struct vm_object *obj;
- int anyio, tries;
+ int tries, code;
+
+ SPLVAR;
- ReleaseWriteLock(&avc->lock);
- AFS_GUNLOCK();
- tries = 5;
vp = AFSTOV(avc);
- do {
- anyio = 0;
- simple_lock(&vp->v_interlock);
- if (VOP_GETVOBJECT(vp, &obj) == 0 && (obj->flags & OBJ_MIGHTBEDIRTY)) {
-#ifdef AFS_FBSD50_ENV
- if (!vget(vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY, curthread)) {
-#else
- if (!vget
- (vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ,
- curproc)) {
-#endif
- if (VOP_GETVOBJECT(vp, &obj) == 0) {
- vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
- anyio = 1;
- }
- vput(vp);
- }
- } else
- simple_unlock(&vp->v_interlock);
- } while (anyio && (--tries > 0));
- simple_lock(&vp->v_interlock);
- if (VOP_GETVOBJECT(vp, &obj) == 0) {
- vm_object_page_remove(obj, 0, 0, FALSE);
+
+ if (vp->v_iflag & VI_DOOMED) {
+ USERPRI;
+ return;
}
- simple_unlock(&vp->v_interlock);
- /*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0); */
- AFS_GLOCK();
- ObtainWriteLock(&avc->lock, 59);
+
+ if (vp->v_bufobj.bo_object != NULL) {
+ VM_OBJECT_LOCK(vp->v_bufobj.bo_object);
+ /*
+ * Do we really want OBJPC_SYNC? OBJPC_INVAL would be
+ * faster, if invalidation is really what we are being
+ * asked to do. (It would make more sense, too, since
+ * otherwise this function is practically identical to
+ * osi_VM_StoreAllSegments().) -GAW
+ */
+
+ /*
+ * Dunno. We no longer resemble osi_VM_StoreAllSegments,
+ * though maybe that's wrong, now. And OBJPC_SYNC is the
+ * common thing in 70 file systems, it seems. Matt.
+ */
+
+ vm_object_page_clean(vp->v_bufobj.bo_object, 0, 0, OBJPC_SYNC);
+ VM_OBJECT_UNLOCK(vp->v_bufobj.bo_object);
+ }
+
+ tries = 5;
+ code = osi_vinvalbuf(vp, V_SAVE, PCATCH, 0);
+ while (code && (tries > 0)) {
+ code = osi_vinvalbuf(vp, V_SAVE, PCATCH, 0);
+ --tries;
+ }
+ USERPRI;
}
/* Purge VM for a file when its callback is revoked.
* Locking: No lock is held, not even the global lock.
*/
void
-osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp)
+osi_VM_FlushPages(struct vcache *avc, afs_ucred_t *credp)
{
struct vnode *vp;
struct vm_object *obj;
vp = AFSTOV(avc);
- simple_lock(&vp->v_interlock);
+ ASSERT_VOP_LOCKED(vp, __func__);
if (VOP_GETVOBJECT(vp, &obj) == 0) {
+ VM_OBJECT_LOCK(obj);
vm_object_page_remove(obj, 0, 0, FALSE);
+ VM_OBJECT_UNLOCK(obj);
}
- simple_unlock(&vp->v_interlock);
/*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0); */
}
* it only works on Solaris.
*/
void
-osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred)
+osi_VM_Truncate(struct vcache *avc, int alen, afs_ucred_t *acred)
{
vnode_pager_setsize(AFSTOV(avc), alen);
}