Commit | Line | Data |
---|---|---|
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 | ||
16 | int | |
17 | osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep) { | |
18 | int code; | |
19 | /* we can't control whether we sleep */ | |
20 | if (!VREFCOUNT_GT(avc,0) | |
21 | && avc->opens == 0 && (avc->f.states & CUnlinkedDel) == 0) { | |
22 | code = afs_FlushVCache(avc, slept); | |
23 | if (code == 0) | |
24 | return 1; | |
25 | } | |
26 | return 0; | |
27 | } | |
28 | ||
29 | extern char *makesname(); | |
30 | ||
31 | struct vcache * | |
32 | osi_NewVnode(void) { | |
33 | struct vcache *avc; | |
34 | char name[METER_NAMSZ]; | |
35 | ||
36 | avc = afs_osi_Alloc(sizeof(struct vcache)); | |
37 | ||
38 | memset(avc, 0, sizeof(struct vcache)); | |
39 | avc->v.v_number = ++afsvnumbers; | |
40 | avc->vc_rwlockid = OSI_NO_LOCKID; | |
41 | initnsema(&avc->vc_rwlock, 1, | |
42 | makesname(name, "vrw", avc->v.v_number)); | |
43 | #ifndef AFS_SGI53_ENV | |
44 | initnsema(&avc->v.v_sync, 0, | |
45 | makesname(name, "vsy", avc->v.v_number)); | |
46 | #endif | |
47 | #ifndef AFS_SGI62_ENV | |
48 | initnlock(&avc->v.v_lock, | |
49 | makesname(name, "vlk", avc->v.v_number)); | |
50 | #endif | |
51 | return avc; | |
52 | } | |
53 | ||
54 | void | |
55 | osi_PrePopulateVCache(struct vcache *avc) { | |
56 | avc->uncred = 0; | |
57 | memset(&(avc->f), 0, sizeof(struct fvcache)); | |
58 | } | |
59 | ||
60 | void | |
61 | osi_AttachVnode(struct vcache *avc, int seq) { } | |
62 | ||
63 | void | |
64 | osi_PostPopulateVCache(struct vcache *avc) { | |
65 | memset(&(avc->vc_bhv_desc), 0, sizeof(avc->vc_bhv_desc)); | |
66 | bhv_desc_init(&(avc->vc_bhv_desc), avc, avc, &Afs_vnodeops); | |
67 | ||
68 | #if defined(AFS_SGI65_ENV) | |
69 | vn_bhv_head_init(&(avc->v.v_bh), "afsvp"); | |
70 | vn_bhv_insert_initial(&(avc->v.v_bh), &(avc->vc_bhv_desc)); | |
71 | avc->v.v_mreg = avc->v.v_mregb = (struct pregion *)avc; | |
72 | # if defined(VNODE_TRACING) | |
73 | avc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0); | |
74 | # endif | |
75 | init_bitlock(&avc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache", | |
76 | avc->v.v_number); | |
77 | init_mutex(&avc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)avc); | |
78 | init_mutex(&avc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)avc); | |
79 | #else | |
80 | bhv_head_init(&(avc->v.v_bh)); | |
81 | bhv_insert_initial(&(avc->v.v_bh), &(avc->vc_bhv_desc)); | |
82 | #endif | |
83 | ||
84 | vnode_pcache_init(&avc->v); | |
85 | ||
86 | #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK) | |
87 | /* Above define is never true execpt in SGI test kernels. */ | |
88 | init_bitlock(&avc->v.v_flag, VLOCK, "vnode", avc->v.v_number); | |
89 | #endif | |
90 | ||
91 | #ifdef INTR_KTHREADS | |
92 | AFS_VN_INIT_BUF_LOCK(&(avc->v)); | |
93 | #endif | |
94 | ||
95 | vSetVfsp(avc, afs_globalVFS); | |
96 | vSetType(avc, VREG); | |
97 | ||
98 | VN_SET_DPAGES(&(avc->v), NULL); | |
99 | osi_Assert((avc->v.v_flag & VINACT) == 0); | |
100 | avc->v.v_flag = 0; | |
101 | osi_Assert(VN_GET_PGCNT(&(avc->v)) == 0); | |
102 | osi_Assert(avc->mapcnt == 0 && avc->vc_locktrips == 0); | |
103 | osi_Assert(avc->vc_rwlockid == OSI_NO_LOCKID); | |
104 | osi_Assert(avc->v.v_filocks == NULL); | |
105 | # if !defined(AFS_SGI65_ENV) | |
106 | osi_Assert(avc->v.v_filocksem == NULL); | |
107 | # endif | |
108 | osi_Assert(avc->cred == NULL); | |
109 | # if defined(AFS_SGI64_ENV) | |
110 | vnode_pcache_reinit(&avc->v); | |
111 | avc->v.v_rdev = NODEV; | |
112 | # endif | |
113 | vn_initlist((struct vnlist *)&avc->v); | |
114 | avc->lastr = 0; | |
115 | } | |
116 |