afs: Handle osi_NewVnode failures
[openafs.git] / src / afs / OBSD / osi_vcache.c
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
16 int
17 osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep)
18 {
19     *slept = 0;
20
21     if (!VREFCOUNT_GT(avc,0)
22         && avc->opens == 0 && (avc->f.states & CUnlinkedDel) == 0) {
23         /*
24          * vgone() reclaims the vnode, which calls afs_FlushVCache(),
25          * then it puts the vnode on the free list.
26          * If we don't do this we end up with a cleaned vnode that's
27          * not on the free list.
28          */
29         AFS_GUNLOCK();
30         vgone(AFSTOV(avc));
31         AFS_GLOCK();
32         return 1;
33     }
34     return 0;
35 }
36
37 struct vcache *
38 osi_NewVnode(void)
39 {
40     struct vcache *tvc;
41
42     tvc = afs_osi_Alloc(sizeof(struct vcache));
43     if (tvc == NULL) {
44         return NULL;
45     }
46     tvc->v = NULL; /* important to clean this, or use memset 0 */
47
48     return tvc;
49 }
50
51 void
52 osi_PrePopulateVCache(struct vcache *avc)
53 {
54     memset(avc, 0, sizeof(struct vcache));
55 }
56
57 void
58 osi_AttachVnode(struct vcache *avc, int seq)
59 {
60     ReleaseWriteLock(&afs_xvcache);
61     AFS_GUNLOCK();
62     afs_obsd_getnewvnode(avc);  /* includes one refcount */
63     AFS_GLOCK();
64     ObtainWriteLock(&afs_xvcache,337);
65     lockinit(&avc->rwlock, PINOD, "vcache", 0, 0);
66 }
67
68 void
69 osi_PostPopulateVCache(struct vcache *avc)
70 {
71     AFSTOV(avc)->v_mount = afs_globalVFS;
72     vSetType(avc, VREG);
73 }
74
75 int
76 osi_vnhold(struct vcache *avc)
77 {
78     return afs_vget(AFSTOV(avc), 0);
79 }