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