23d813797d60e93e6ecac3d9c931f31614225353
[openafs.git] / src / afs / VNOPS / afs_vnop_attrs.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  * Portions Copyright (c) 2003 Apple Computer, Inc.
10  */
11
12 /*
13  * afs_vnop_attrs.c - setattr and getattr vnodeops
14  *
15  * Implements:
16  * afs_CopyOutAttrs
17  * afs_getattr
18  * afs_VAttrToAS
19  * afs_setattr
20  *
21  */
22
23 #include <afsconfig.h>
24 #include "afs/param.h"
25
26 RCSID
27     ("$Header$");
28
29 #include "afs/sysincludes.h"    /* Standard vendor system headers */
30 #include "afsincludes.h"        /* Afs-based standard headers */
31 #include "afs/afs_stats.h"      /* statistics */
32 #include "afs/afs_cbqueue.h"
33 #include "afs/nfsclient.h"
34 #include "afs/afs_osidnlc.h"
35
36 extern afs_rwlock_t afs_xcbhash;
37 struct afs_exporter *afs_nfsexporter;
38 extern struct vcache *afs_globalVp;
39 #if defined(AFS_HPUX110_ENV)
40 extern struct vfs *afs_globalVFS;
41 #endif
42
43 /* copy out attributes from cache entry */
44 int
45 afs_CopyOutAttrs(register struct vcache *avc, register struct vattr *attrs)
46 {
47     register struct volume *tvp;
48     register struct cell *tcell;
49     int fakedir = 0;
50
51     AFS_STATCNT(afs_CopyOutAttrs);
52     if (afs_fakestat_enable && avc->mvstat == 1)
53         fakedir = 1;
54     attrs->va_type = fakedir ? VDIR : vType(avc);
55 #if defined(AFS_SGI_ENV) || defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
56     attrs->va_mode = fakedir ? 0755 : (mode_t) (avc->m.Mode & 0xffff);
57 #else
58     attrs->va_mode = fakedir ? VDIR | 0755 : avc->m.Mode;
59 #endif
60
61     if (avc->m.Mode & (VSUID | VSGID)) {
62         /* setuid or setgid, make sure we're allowed to run them from this cell */
63         tcell = afs_GetCell(avc->fid.Cell, 0);
64         if (tcell && (tcell->states & CNoSUID))
65             attrs->va_mode &= ~(VSUID | VSGID);
66     }
67 #if defined(AFS_DARWIN_ENV)
68     {
69         extern u_int32_t afs_darwin_realmodes;
70         if (!afs_darwin_realmodes) {
71             /* Mac OS X uses the mode bits to determine whether a file or
72              * directory is accessible, and believes them, even though under
73              * AFS they're almost assuredly wrong, especially if the local uid
74              * does not match the AFS ID.  So we set the mode bits
75              * conservatively.
76              */
77             if (S_ISDIR(attrs->va_mode)) {
78                 /* all access bits need to be set for directories, since even
79                  * a mode 0 directory can still be used normally.
80                  */
81                 attrs->va_mode |= ACCESSPERMS;
82             } else {
83                 /* for other files, replicate the user bits to group and other */
84                 mode_t ubits = (attrs->va_mode & S_IRWXU) >> 6;
85                 attrs->va_mode |= ubits | (ubits << 3);
86             }
87         }
88     }
89 #endif /* AFS_DARWIN_ENV */
90     attrs->va_uid = fakedir ? 0 : avc->m.Owner;
91     attrs->va_gid = fakedir ? 0 : avc->m.Group; /* yeah! */
92 #if defined(AFS_SUN56_ENV)
93     attrs->va_fsid = avc->v.v_vfsp->vfs_fsid.val[0];
94 #elif defined(AFS_OSF_ENV)
95     attrs->va_fsid = avc->v.v_mount->m_stat.f_fsid.val[0];
96 #elif defined(AFS_DARWIN80_ENV)
97     VATTR_RETURN(attrs, va_fsid, vfs_statfs(vnode_mount(AFSTOV(avc)))->f_fsid.val[0]);
98 #elif defined(AFS_DARWIN70_ENV)
99     attrs->va_fsid = avc->v->v_mount->mnt_stat.f_fsid.val[0];
100 #else /* ! AFS_DARWIN70_ENV */
101     attrs->va_fsid = 1;
102 #endif 
103     if (avc->mvstat == 2) {
104         tvp = afs_GetVolume(&avc->fid, 0, READ_LOCK);
105         /* The mount point's vnode. */
106         if (tvp) {
107             attrs->va_nodeid =
108                 tvp->mtpoint.Fid.Vnode + (tvp->mtpoint.Fid.Volume << 16);
109             if (FidCmp(&afs_rootFid, &avc->fid) && !attrs->va_nodeid)
110                 attrs->va_nodeid = 2;
111             afs_PutVolume(tvp, READ_LOCK);
112         } else
113             attrs->va_nodeid = 2;
114     } else
115         attrs->va_nodeid = avc->fid.Fid.Vnode + (avc->fid.Fid.Volume << 16);
116     attrs->va_nodeid &= 0x7fffffff;     /* Saber C hates negative inode #s! */
117     attrs->va_nlink = fakedir ? 100 : avc->m.LinkCount;
118     attrs->va_size = fakedir ? 4096 : avc->m.Length;
119     attrs->va_atime.tv_sec = attrs->va_mtime.tv_sec = attrs->va_ctime.tv_sec =
120         fakedir ? 0 : (int)avc->m.Date;
121     /* set microseconds to be dataversion # so that we approximate NFS-style
122      * use of mtime as a dataversion #.  We take it mod 512K because
123      * microseconds *must* be less than a million, and 512K is the biggest
124      * power of 2 less than such.  DataVersions are typically pretty small
125      * anyway, so the difference between 512K and 1000000 shouldn't matter
126      * much, and "&" is a lot faster than "%".
127      */
128 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
129     /* nfs on these systems puts an 0 in nsec and stores the nfs usec (aka 
130      * dataversion) in va_gen */
131
132     attrs->va_atime.tv_nsec = attrs->va_mtime.tv_nsec =
133         attrs->va_ctime.tv_nsec = 0;
134     attrs->va_gen = hgetlo(avc->m.DataVersion);
135 #elif defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_OBSD_ENV)
136     attrs->va_atime.tv_nsec = attrs->va_mtime.tv_nsec =
137         attrs->va_ctime.tv_nsec =
138         (hgetlo(avc->m.DataVersion) & 0x7ffff) * 1000;
139 #else
140     attrs->va_atime.tv_usec = attrs->va_mtime.tv_usec =
141         attrs->va_ctime.tv_usec = (hgetlo(avc->m.DataVersion) & 0x7ffff);
142 #endif
143 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_OSF_ENV)
144     attrs->va_flags = 0;
145 #endif
146 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
147     attrs->va_blksize = PAGESIZE;       /* XXX Was 8192 XXX */
148 #else
149     attrs->va_blocksize = PAGESIZE;     /* XXX Was 8192 XXX */
150 #endif
151     attrs->va_rdev = 1;
152 #if defined(AFS_HPUX110_ENV)
153     if (afs_globalVFS)
154         attrs->va_fstype = afs_globalVFS->vfs_mtype;
155 #endif
156
157     /*
158      * Below return 0 (and not 1) blocks if the file is zero length. This conforms
159      * better with the other filesystems that do return 0.      
160      */
161 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
162     attrs->va_bytes = (attrs->va_size ? (attrs->va_size + 1023) : 1024);
163 #ifdef  va_bytes_rsv
164     attrs->va_bytes_rsv = -1;
165 #endif
166 #elif defined(AFS_HPUX_ENV)
167     attrs->va_blocks = (attrs->va_size ? ((attrs->va_size + 1023)>>10) : 0);
168 #elif defined(AFS_SGI_ENV)
169     attrs->va_blocks = BTOBB(attrs->va_size);
170 #elif defined(AFS_SUN5_ENV)
171     attrs->va_nblocks = (attrs->va_size ? ((attrs->va_size + 1023)>>10)<<1:0);
172 #else /* everything else */
173     attrs->va_blocks = (attrs->va_size ? ((attrs->va_size + 1023)>>10)<<1:0);
174 #endif
175     return 0;
176 }
177
178
179
180 #if     defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
181 int
182 afs_getattr(OSI_VC_DECL(avc), struct vattr *attrs, int flags,
183             struct AFS_UCRED *acred)
184 #else
185 int
186 afs_getattr(OSI_VC_DECL(avc), struct vattr *attrs, struct AFS_UCRED *acred)
187 #endif
188 {
189     afs_int32 code;
190     struct vrequest treq;
191     extern struct unixuser *afs_FindUser();
192     struct unixuser *au;
193     int inited = 0;
194     OSI_VC_CONVERT(avc);
195
196     AFS_STATCNT(afs_getattr);
197     afs_Trace2(afs_iclSetp, CM_TRACE_GETATTR, ICL_TYPE_POINTER, avc,
198                ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length));
199
200     if (afs_fakestat_enable && avc->mvstat == 1) {
201         struct afs_fakestat_state fakestat;
202
203         code = afs_InitReq(&treq, acred);
204         if (code)
205             return code;
206         afs_InitFakeStat(&fakestat);
207         code = afs_TryEvalFakeStat(&avc, &fakestat, &treq);
208         if (code) {
209             afs_PutFakeStat(&fakestat);
210             return code;
211         }
212
213         code = afs_CopyOutAttrs(avc, attrs);
214         afs_PutFakeStat(&fakestat);
215         return code;
216     }
217 #if defined(AFS_SUN5_ENV)
218     if (flags & ATTR_HINT) {
219         code = afs_CopyOutAttrs(avc, attrs);
220         return code;
221     }
222 #endif
223 #if defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
224     if (avc->states & CUBCinit) {
225         code = afs_CopyOutAttrs(avc, attrs);
226         return code;
227     }
228 #endif
229
230 #ifdef AFS_BOZONLOCK_ENV
231     afs_BozonLock(&avc->pvnLock, avc);
232 #endif
233
234     if (afs_shuttingdown)
235         return EIO;
236
237     if (!(avc->states & CStatd)) {
238         if (!(code = afs_InitReq(&treq, acred))) {
239             code = afs_VerifyVCache2(avc, &treq);
240             inited = 1;
241         }
242     } else
243         code = 0;
244
245 #ifdef AFS_BOZONLOCK_ENV
246     if (code == 0)
247         osi_FlushPages(avc, acred);
248     afs_BozonUnlock(&avc->pvnLock, avc);
249 #endif
250
251
252     if (code == 0) {
253         osi_FlushText(avc);     /* only needed to flush text if text locked last time */
254         code = afs_CopyOutAttrs(avc, attrs);
255
256         if (afs_nfsexporter) {
257             if (!inited) {
258                 if ((code = afs_InitReq(&treq, acred)))
259                     return code;
260                 inited = 1;
261             }
262             if (AFS_NFSXLATORREQ(acred)) {
263                 if ((vType(avc) != VDIR)
264                     && !afs_AccessOK(avc, PRSFS_READ, &treq,
265                                      CHECK_MODE_BITS |
266                                      CMB_ALLOW_EXEC_AS_READ)) {
267                     return EACCES;
268                 }
269             }
270             if ((au = afs_FindUser(treq.uid, -1, READ_LOCK))) {
271                 register struct afs_exporter *exporter = au->exporter;
272
273                 if (exporter && !(afs_nfsexporter->exp_states & EXP_UNIXMODE)) {
274                     unsigned int ubits;
275                     /*
276                      *  If the remote user wishes to enforce default Unix mode semantics,
277                      *  like in the nfs exporter case, we OR in the user bits
278                      *  into the group and other bits. We need to do this
279                      *  because there is no RFS_ACCESS call and thus nfs
280                      *  clients implement nfs_access by interpreting the 
281                      *  mode bits in the traditional way, which of course
282                      *  loses with afs.
283                      */
284                     ubits = (attrs->va_mode & 0700) >> 6;
285                     attrs->va_mode = attrs->va_mode | ubits | (ubits << 3);
286                     /* If it's the root of AFS, replace the inode number with the
287                      * inode number of the mounted on directory; otherwise this 
288                      * confuses getwd()... */
289 #ifdef AFS_LINUX22_ENV
290                     if (avc == afs_globalVp) {
291                         struct inode *ip = AFSTOV(avc)->i_sb->s_root->d_inode;
292                         attrs->va_nodeid = ip->i_ino;   /* VTOI()? */
293                     }
294 #else
295                     if (
296 #ifdef AFS_DARWIN_ENV               
297                         vnode_isvroot(AFSTOV(avc))
298 #else
299                         AFSTOV(avc)->v_flag & VROOT
300 #endif
301                         ) {
302                         struct vnode *vp = AFSTOV(avc);
303
304 #ifdef AFS_DARWIN80_ENV
305                         /* XXX vp = vnode_mount(vp)->mnt_vnodecovered; */
306                         vp = 0;
307 #else
308                         vp = vp->v_vfsp->vfs_vnodecovered;
309                         if (vp) {       /* Ignore weird failures */
310 #ifdef AFS_SGI62_ENV
311                             attrs->va_nodeid = VnodeToIno(vp);
312 #else
313                             struct inode *ip;
314
315                             ip = (struct inode *)VTOI(vp);
316                             if (ip)     /* Ignore weird failures */
317                                 attrs->va_nodeid = ip->i_number;
318 #endif
319                         }
320 #endif
321                     }
322 #endif /* AFS_LINUX22_ENV */
323                 }
324                 afs_PutUser(au, READ_LOCK);
325             }
326         }
327     }
328     if (!code)
329         return 0;
330     code = afs_CheckCode(code, &treq, 14);
331     return code;
332 }
333
334 /* convert a Unix request into a status store request */
335 int
336 afs_VAttrToAS(register struct vcache *avc, register struct vattr *av,
337               register struct AFSStoreStatus *as)
338 {
339     register int mask;
340     mask = 0;
341     AFS_STATCNT(afs_VAttrToAS);
342 #if     defined(AFS_DARWIN80_ENV)
343     if (VATTR_IS_ACTIVE(av, va_mode)) {
344 #elif   defined(AFS_AIX_ENV)
345 /* Boy, was this machine dependent bogosity hard to swallow????.... */
346     if (av->va_mode != -1) {
347 #elif   defined(AFS_LINUX22_ENV)
348     if (av->va_mask & ATTR_MODE) {
349 #elif   defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
350     if (av->va_mask & AT_MODE) {
351 #elif   defined(AFS_XBSD_ENV)
352     if (av->va_mode != (mode_t)VNOVAL) {
353 #else
354     if (av->va_mode != ((unsigned short)-1)) {
355 #endif
356         mask |= AFS_SETMODE;
357         as->UnixModeBits = av->va_mode & 0xffff;
358         if (avc->states & CForeign) {
359             ObtainWriteLock(&avc->lock, 127);
360             afs_FreeAllAxs(&(avc->Access));
361             ReleaseWriteLock(&avc->lock);
362         }
363     }
364 #if     defined(AFS_DARWIN80_ENV)
365     if (VATTR_IS_ACTIVE(av, va_gid)) {
366 #elif defined(AFS_LINUX22_ENV)
367     if (av->va_mask & ATTR_GID) {
368 #elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
369     if (av->va_mask & AT_GID) {
370 #elif defined(AFS_HPUX_ENV)
371 #if     defined(AFS_HPUX102_ENV)
372     if (av->va_gid != GID_NO_CHANGE) {
373 #else
374     if (av->va_gid != ((unsigned short)-1)) {
375 #endif
376 #elif   defined(AFS_XBSD_ENV)
377     if (av->va_gid != (gid_t)VNOVAL) {
378 #else
379     if (av->va_gid != -1) {
380 #endif /* AFS_LINUX22_ENV */
381         mask |= AFS_SETGROUP;
382         as->Group = av->va_gid;
383     }
384 #if     defined(AFS_DARWIN80_ENV)
385     if (VATTR_IS_ACTIVE(av, va_uid)) {
386 #elif defined(AFS_LINUX22_ENV)
387     if (av->va_mask & ATTR_UID) {
388 #elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
389     if (av->va_mask & AT_UID) {
390 #elif defined(AFS_HPUX_ENV)
391 #if     defined(AFS_HPUX102_ENV)
392     if (av->va_uid != UID_NO_CHANGE) {
393 #elif   defined(AFS_XBSD_ENV)
394     if (av->va_uid != (uid_t)VNOVAL) {
395 #else
396     if (av->va_uid != ((unsigned short)-1)) {
397 #endif
398 #else
399     if (av->va_uid != -1) {
400 #endif /* AFS_LINUX22_ENV */
401         mask |= AFS_SETOWNER;
402         as->Owner = av->va_uid;
403     }
404 #if     defined(AFS_DARWIN80_ENV)
405     if (VATTR_IS_ACTIVE(av, va_modify_time)) {
406 #elif   defined(AFS_LINUX22_ENV)
407     if (av->va_mask & ATTR_MTIME) {
408 #elif   defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
409     if (av->va_mask & AT_MTIME) {
410 #else
411     if (av->va_mtime.tv_sec != -1) {
412 #endif
413         mask |= AFS_SETMODTIME;
414 #ifndef AFS_SGI_ENV
415 #if     defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
416         if (av->va_mtime.tv_nsec == -1)
417 #else
418         if (av->va_mtime.tv_usec == -1)
419 #endif
420             as->ClientModTime = osi_Time();     /* special Sys V compat hack for Suns */
421         else
422 #endif
423             as->ClientModTime = av->va_mtime.tv_sec;
424     }
425     as->Mask = mask;
426     return 0;
427 }
428
429 /* We don't set CDirty bit in avc->states because setattr calls WriteVCache
430  * synchronously, therefore, it's not needed.
431  */
432 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
433 int
434 afs_setattr(OSI_VC_DECL(avc), register struct vattr *attrs, int flags,
435             struct AFS_UCRED *acred)
436 #else
437 int
438 afs_setattr(OSI_VC_DECL(avc), register struct vattr *attrs,
439             struct AFS_UCRED *acred)
440 #endif
441 {
442     struct vrequest treq;
443     struct AFSStoreStatus astat;
444     register afs_int32 code;
445     struct afs_fakestat_state fakestate;
446     OSI_VC_CONVERT(avc);
447
448     AFS_STATCNT(afs_setattr);
449 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX22_ENV)
450     afs_Trace4(afs_iclSetp, CM_TRACE_SETATTR, ICL_TYPE_POINTER, avc,
451                ICL_TYPE_INT32, attrs->va_mask, ICL_TYPE_OFFSET,
452                ICL_HANDLE_OFFSET(attrs->va_size), ICL_TYPE_OFFSET,
453                ICL_HANDLE_OFFSET(avc->m.Length));
454 #else
455     afs_Trace4(afs_iclSetp, CM_TRACE_SETATTR, ICL_TYPE_POINTER, avc,
456                ICL_TYPE_INT32, attrs->va_mode, ICL_TYPE_OFFSET,
457                ICL_HANDLE_OFFSET(attrs->va_size), ICL_TYPE_OFFSET,
458                ICL_HANDLE_OFFSET(avc->m.Length));
459 #endif
460     if ((code = afs_InitReq(&treq, acred)))
461         return code;
462
463     afs_InitFakeStat(&fakestate);
464     code = afs_EvalFakeStat(&avc, &fakestate, &treq);
465     if (code)
466         goto done;
467
468     if (avc->states & CRO) {
469         code = EROFS;
470         goto done;
471     }
472 #if defined(AFS_SGI_ENV)
473     /* ignore ATTR_LAZY calls - they are really only for keeping
474      * the access/mtime of mmaped files up to date
475      */
476     if (flags & ATTR_LAZY)
477         goto done;
478 #endif
479     /* if file size has changed, we need write access, otherwise (e.g.
480      * chmod) give it a shot; if it fails, we'll discard the status
481      * info.
482      */
483 #if     defined(AFS_DARWIN80_ENV)
484     if (VATTR_IS_ACTIVE(attrs, va_data_size)) {
485 #elif   defined(AFS_LINUX22_ENV)
486     if (attrs->va_mask & ATTR_SIZE) {
487 #elif   defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
488     if (attrs->va_mask & AT_SIZE) {
489 #elif   defined(AFS_OSF_ENV) || defined(AFS_XBSD_ENV)
490     if (attrs->va_size != VNOVAL) {
491 #elif   defined(AFS_AIX41_ENV)
492     if (attrs->va_size != -1) {
493 #else
494     if (attrs->va_size != ~0) {
495 #endif
496         if (!afs_AccessOK(avc, PRSFS_WRITE, &treq, DONT_CHECK_MODE_BITS)) {
497             code = EACCES;
498             goto done;
499         }
500     }
501
502     afs_VAttrToAS(avc, attrs, &astat);  /* interpret request */
503     code = 0;
504 #ifdef AFS_BOZONLOCK_ENV
505     afs_BozonLock(&avc->pvnLock, avc);
506 #endif
507 #if     defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
508     if (AFS_NFSXLATORREQ(acred)) {
509         avc->execsOrWriters++;
510     }
511 #endif
512
513 #if defined(AFS_SGI_ENV)
514     AFS_RWLOCK((vnode_t *) avc, VRWLOCK_WRITE);
515 #endif
516 #if     defined(AFS_DARWIN80_ENV)
517     if (VATTR_IS_ACTIVE(attrs, va_data_size)) {
518 #elif   defined(AFS_LINUX22_ENV)
519     if (attrs->va_mask & ATTR_SIZE) {
520 #elif   defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
521     if (attrs->va_mask & AT_SIZE) {
522 #elif   defined(AFS_OSF_ENV) || defined(AFS_XBSD_ENV)
523     if (attrs->va_size != VNOVAL) {
524 #else
525     if (attrs->va_size != -1) {
526 #endif
527         afs_size_t tsize = attrs->va_size;
528         ObtainWriteLock(&avc->lock, 128);
529         avc->states |= CDirty;
530         code = afs_TruncateAllSegments(avc, tsize, &treq, acred);
531         /* if date not explicitly set by this call, set it ourselves, since we
532          * changed the data */
533         if (!(astat.Mask & AFS_SETMODTIME)) {
534             astat.Mask |= AFS_SETMODTIME;
535             astat.ClientModTime = osi_Time();
536         }
537         if (code == 0) {
538             if (((avc->execsOrWriters <= 0) && (avc->states & CCreating) == 0)
539                 || (avc->execsOrWriters == 1 && AFS_NFSXLATORREQ(acred))) {
540                 code = afs_StoreAllSegments(avc, &treq, AFS_ASYNC);
541                 if (!code)
542                     avc->states &= ~CDirty;
543             }
544         } else
545             avc->states &= ~CDirty;
546
547         ReleaseWriteLock(&avc->lock);
548         hzero(avc->flushDV);
549         osi_FlushText(avc);     /* do this after releasing all locks */
550     }
551     if (code == 0) {
552         ObtainSharedLock(&avc->lock, 16);       /* lock entry */
553         code = afs_WriteVCache(avc, &astat, &treq);     /* send request */
554         ReleaseSharedLock(&avc->lock);  /* release lock */
555     }
556     if (code) {
557         ObtainWriteLock(&afs_xcbhash, 487);
558         afs_DequeueCallback(avc);
559         avc->states &= ~CStatd;
560         ReleaseWriteLock(&afs_xcbhash);
561         if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
562             osi_dnlc_purgedp(avc);
563         /* error?  erase any changes we made to vcache entry */
564     }
565 #if     defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
566     if (AFS_NFSXLATORREQ(acred)) {
567         avc->execsOrWriters--;
568     }
569 #endif
570 #ifdef AFS_BOZONLOCK_ENV
571     afs_BozonUnlock(&avc->pvnLock, avc);
572 #endif
573 #if defined(AFS_SGI_ENV)
574     AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE);
575 #endif
576   done:
577     afs_PutFakeStat(&fakestate);
578     code = afs_CheckCode(code, &treq, 15);
579     return code;
580 }