int code;
tfile = (struct osi_file *)osi_UFSOpen(inode);
+ if (!tfile)
+ return EIO;
+
#if defined(AFS_AIX41_ENV)
AFS_GUNLOCK();
code = VNOP_RDWR(tfile->vnode, UIO_WRITE, FWRITE, tuiop, NULL, NULL,
#elif defined(AFS_SUN5_ENV)
AFS_GUNLOCK();
# ifdef AFS_SUN510_ENV
- {
- caller_context_t ct;
-
- VOP_RWLOCK(tfile->vnode, 1, &ct);
- code = VOP_WRITE(tfile->vnode, tuiop, 0, afs_osi_credp, &ct);
- VOP_RWUNLOCK(tfile->vnode, 1, &ct);
- }
+ VOP_RWLOCK(tfile->vnode, 1, NULL);
+ code = VOP_WRITE(tfile->vnode, tuiop, 0, afs_osi_credp, NULL);
+ VOP_RWUNLOCK(tfile->vnode, 1, NULL);
# else
VOP_RWLOCK(tfile->vnode, 1);
code = VOP_WRITE(tfile->vnode, tuiop, 0, afs_osi_credp);
# endif
AFS_GLOCK();
if (code == ENOSPC)
- afs_warnuser
- ("\n\n\n*** Cache partition is full - decrease cachesize!!! ***\n\n\n");
+ afs_WarnENOSPC();
#elif defined(AFS_SGI_ENV)
AFS_GUNLOCK();
avc->f.states |= CWritingUFS;
#endif
struct uio *tuiop = NULL;
afs_int32 code;
- struct vrequest treq;
+ struct vrequest *treq = NULL;
AFS_STATCNT(afs_write);
return ENETDOWN;
startDate = osi_Time();
- if ((code = afs_InitReq(&treq, acred)))
+ if ((code = afs_CreateReq(&treq, acred)))
return code;
/* otherwise we read */
totalLength = AFS_UIO_RESID(auio);
#endif
if (!noLock)
ReleaseWriteLock(&avc->lock);
+ afs_DestroyReq(treq);
return (EFBIG);
}
#endif
#else
afs_FakeOpen(avc);
#endif
- avc->f.states |= CDirty;
while (totalLength > 0) {
- tdc = afs_ObtainDCacheForWriting(avc, filePos, totalLength, &treq,
+ /*
+ * Note that we must set CDirty for every iteration of this loop.
+ * CDirty may get cleared below (such as during afs_DoPartialStore),
+ * but we're still writing to the file, so make sure CDirty is set
+ * here.
+ */
+ avc->f.states |= CDirty;
+
+ tdc = afs_ObtainDCacheForWriting(avc, filePos, totalLength, treq,
noLock);
if (!tdc) {
error = EIO;
error = code;
ZapDCE(tdc); /* bad data */
cfile = afs_CFileOpen(&tdc->f.inode);
+ osi_Assert(cfile);
afs_CFileTruncate(cfile, 0);
afs_CFileClose(cfile);
afs_AdjustSize(tdc, 0); /* sets f.chunkSize to 0 */
#else
if (filePos > avc->f.m.Length) {
if (AFS_IS_DISCON_RW)
- afs_PopulateDCache(avc, filePos, &treq);
+ afs_PopulateDCache(avc, filePos, treq);
afs_Trace4(afs_iclSetp, CM_TRACE_SETLENGTH, ICL_TYPE_STRING,
__FILE__, ICL_TYPE_LONG, __LINE__, ICL_TYPE_OFFSET,
ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_OFFSET,
* the high-level write op.
*/
if (!noLock) {
- code = afs_DoPartialWrite(avc, &treq);
+ code = afs_DoPartialWrite(avc, treq);
if (code) {
error = code;
break;
#if !defined(AFS_VM_RDWR_ENV) || defined(AFS_FAKEOPEN_ENV)
afs_FakeClose(avc, acred);
#endif
- error = afs_CheckCode(error, &treq, 7);
+ error = afs_CheckCode(error, treq, 7);
/* This set is here so we get the CheckCode. */
if (error && !avc->vc_error)
avc->vc_error = error;
afs_fsync(avc, acred);
}
#endif
+ afs_DestroyReq(treq);
return error;
}
#endif
{
afs_int32 code;
+ afs_int32 code_checkcode = 0;
struct brequest *tb;
- struct vrequest treq;
+ struct vrequest *treq = NULL;
#ifdef AFS_SGI65_ENV
struct flid flid;
#endif
AFS_STATCNT(afs_close);
afs_Trace2(afs_iclSetp, CM_TRACE_CLOSE, ICL_TYPE_POINTER, avc,
ICL_TYPE_INT32, aflags);
- code = afs_InitReq(&treq, acred);
+ code = afs_CreateReq(&treq, acred);
if (code)
return code;
afs_InitFakeStat(&fakestat);
- code = afs_EvalFakeStat(&avc, &fakestat, &treq);
+ code = afs_EvalFakeStat(&avc, &fakestat, treq);
if (code) {
afs_PutFakeStat(&fakestat);
+ afs_DestroyReq(treq);
return code;
}
AFS_DISCON_LOCK();
#ifdef AFS_SUN5_ENV
if (avc->flockCount) {
- HandleFlock(avc, LOCK_UN, &treq, 0, 1 /*onlymine */ );
+ HandleFlock(avc, LOCK_UN, treq, 0, 1 /*onlymine */ );
}
#endif
#if defined(AFS_SGI_ENV)
if (!lastclose) {
afs_PutFakeStat(&fakestat);
AFS_DISCON_UNLOCK();
+ afs_DestroyReq(treq);
return 0;
}
/* unlock any locks for pid - could be wrong for child .. */
# ifdef AFS_SGI65_ENV
get_current_flid(&flid);
cleanlocks((vnode_t *) avc, flid.fl_pid, flid.fl_sysid);
- HandleFlock(avc, LOCK_UN, &treq, flid.fl_pid, 1 /*onlymine */ );
+ HandleFlock(avc, LOCK_UN, treq, flid.fl_pid, 1 /*onlymine */ );
# else
# ifdef AFS_SGI64_ENV
cleanlocks((vnode_t *) avc, flp);
# else /* AFS_SGI64_ENV */
cleanlocks((vnode_t *) avc, u.u_procp->p_epid, u.u_procp->p_sysid);
# endif /* AFS_SGI64_ENV */
- HandleFlock(avc, LOCK_UN, &treq, OSI_GET_CURRENT_PID(), 1 /*onlymine */ );
+ HandleFlock(avc, LOCK_UN, treq, OSI_GET_CURRENT_PID(), 1 /*onlymine */ );
# endif /* AFS_SGI65_ENV */
/* afs_chkpgoob will drop and re-acquire the global lock. */
afs_chkpgoob(&avc->v, btoc(avc->f.m.Length));
* with the close. */
afs_PutFakeStat(&fakestat);
AFS_DISCON_UNLOCK();
+ afs_DestroyReq(treq);
return 0;
}
#else
if (avc->flockCount) { /* Release Lock */
- HandleFlock(avc, LOCK_UN, &treq, 0, 1 /*onlymine */ );
+ HandleFlock(avc, LOCK_UN, treq, 0, 1 /*onlymine */ );
}
#endif
if (aflags & (FWRITE | FTRUNC)) {
if (afs_BBusy() || (AFS_NFSXLATORREQ(acred)) || AFS_IS_DISCONNECTED) {
/* do it yourself if daemons are all busy */
ObtainWriteLock(&avc->lock, 124);
- code = afs_StoreOnLastReference(avc, &treq);
+ code = afs_StoreOnLastReference(avc, treq);
ReleaseWriteLock(&avc->lock);
#if defined(AFS_SGI_ENV)
AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE);
tb->flags |= BUWAIT;
afs_osi_Sleep(tb);
}
- code = tb->code;
+ code = tb->code_raw;
+ code_checkcode = tb->code_checkcode;
afs_BRelease(tb);
}
/* VNOVNODE is "acceptable" error code from close, since
* may happen when deleting a file on another machine while
- * it is open here. We do the same for ENOENT since in afs_CheckCode we map VNOVNODE -> ENOENT */
- if (code == VNOVNODE || code == ENOENT)
+ * it is open here. */
+ if (code == VNOVNODE)
code = 0;
/* Ensure last closer gets the error. If another thread caused
#ifdef AFS_AIX32_ENV
osi_ReleaseVM(avc, acred);
#endif
- /* printf("avc->vc_error=%d\n", avc->vc_error); */
- code = avc->vc_error;
+ /* We don't know what the original raw error code was, so set
+ * 'code' to 0. But we have the afs_CheckCode-translated error
+ * code, so put that in code_checkcode. We cannot just set code
+ * to avc->vc_error, since vc_error is a checkcode-translated
+ * error code, and 'code' is supposed to be a raw error code. */
+ code = 0;
+ code_checkcode = avc->vc_error;
avc->vc_error = 0;
}
ReleaseWriteLock(&avc->lock);
afs_warnuser("afs: failed to store file (network problems)\n");
}
#ifdef AFS_SUN5_ENV
- else if (code == ENOSPC) {
+ else if (code == ENOSPC || code_checkcode == ENOSPC) {
afs_warnuser
("afs: failed to store file (over quota or partition full)\n");
}
#else
- else if (code == ENOSPC) {
+ else if (code == ENOSPC || code_checkcode == ENOSPC) {
afs_warnuser("afs: failed to store file (partition full)\n");
- } else if (code == EDQUOT) {
+ } else if (code == EDQUOT || code_checkcode == EDQUOT) {
afs_warnuser("afs: failed to store file (over quota)\n");
}
#endif
- else if (code != 0)
- afs_warnuser("afs: failed to store file (%d)\n", code);
+ else if (code || code_checkcode)
+ afs_warnuser("afs: failed to store file (%d/%d)\n", code, code_checkcode);
/* finally, we flush any text pages lying around here */
hzero(avc->flushDV);
#ifdef AFS_AIX32_ENV
osi_ReleaseVM(avc, acred);
#endif
- code = avc->vc_error;
+ code = 0;
+ code_checkcode = avc->vc_error;
avc->vc_error = 0;
}
#if defined(AFS_FBSD80_ENV)
}
AFS_DISCON_UNLOCK();
afs_PutFakeStat(&fakestat);
- code = afs_CheckCode(code, &treq, 5);
+
+ if (code_checkcode) {
+ code = code_checkcode;
+ } else {
+ code = afs_CheckCode(code, treq, 5);
+ }
+ afs_DestroyReq(treq);
return code;
}
#endif
{
afs_int32 code;
- struct vrequest treq;
+ struct vrequest *treq = NULL;
OSI_VC_CONVERT(avc);
if (avc->vc_error)
AFS_STATCNT(afs_fsync);
afs_Trace1(afs_iclSetp, CM_TRACE_FSYNC, ICL_TYPE_POINTER, avc);
- if ((code = afs_InitReq(&treq, acred)))
+ if ((code = afs_CreateReq(&treq, acred)))
return code;
AFS_DISCON_LOCK();
#if defined(AFS_SGI_ENV)
/* put the file back */
UpgradeSToWLock(&avc->lock, 41);
- code = afs_StoreAllSegments(avc, &treq, AFS_SYNC);
+ code = afs_StoreAllSegments(avc, treq, AFS_SYNC);
ConvertWToSLock(&avc->lock);
} else {
UpgradeSToWLock(&avc->lock, 711);
}
#endif
AFS_DISCON_UNLOCK();
- code = afs_CheckCode(code, &treq, 33);
+ code = afs_CheckCode(code, treq, 33);
+ afs_DestroyReq(treq);
ReleaseSharedLock(&avc->lock);
return code;
}