Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afs / OBSD / osi_vcache.c
CommitLineData
805e021f
CE
1/*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10#include <afsconfig.h>
11#include "afs/param.h"
12
13#include "afs/sysincludes.h" /*Standard vendor system headers */
14#include "afsincludes.h" /*AFS-based standard headers */
15
16int
17osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep) {
18 *slept = 0;
19
20 if (!VREFCOUNT_GT(avc,0)
21 && avc->opens == 0 && (avc->f.states & CUnlinkedDel) == 0) {
22 /*
23 * vgone() reclaims the vnode, which calls afs_FlushVCache(),
24 * then it puts the vnode on the free list.
25 * If we don't do this we end up with a cleaned vnode that's
26 * not on the free list.
27 */
28 AFS_GUNLOCK();
29 vgone(AFSTOV(avc));
30 AFS_GLOCK();
31 return 1;
32 }
33 return 0;
34}
35
36struct vcache *
37osi_NewVnode(void) {
38 struct vcache *tvc;
39
40 tvc = afs_osi_Alloc(sizeof(struct vcache));
41 tvc->v = NULL; /* important to clean this, or use memset 0 */
42
43 return tvc;
44}
45
46void
47osi_PrePopulateVCache(struct vcache *avc) {
48 memset(avc, 0, sizeof(struct vcache));
49}
50
51void
52osi_AttachVnode(struct vcache *avc, int seq) {
53 ReleaseWriteLock(&afs_xvcache);
54 AFS_GUNLOCK();
55 afs_obsd_getnewvnode(avc); /* includes one refcount */
56 AFS_GLOCK();
57 ObtainWriteLock(&afs_xvcache,337);
58 lockinit(&avc->rwlock, PINOD, "vcache", 0, 0);
59}
60
61void
62osi_PostPopulateVCache(struct vcache *avc) {
63 AFSTOV(avc)->v_mount = afs_globalVFS;
64 vSetType(avc, VREG);
65}
66