#include <osi.h>
#include "afsd.h"
-#include "afsdifs.h"
-
#define CM_BUF_SIZE 4096
long buf_bufferSize = CM_BUF_SIZE;
bufferp = NULL;
- lock_ObtainMutex(&scp->mx);
+ lock_ObtainWrite(&scp->rw);
/* start by looking up the file's end */
code = cm_SyncOp(scp, NULL, userp, &req, 0,
if (code)
goto done;
+ cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
+
/* now we have the entry locked, look up the length */
fileLength = scp->length;
buf_Release(bufferp);
bufferp = NULL;
}
- lock_ReleaseMutex(&scp->mx);
+ lock_ReleaseWrite(&scp->rw);
- lock_ObtainRead(&scp->bufCreateLock);
- code = buf_Get(scp, &thyper, &bufferp);
- lock_ReleaseRead(&scp->bufCreateLock);
+ code = buf_Get(scp, &thyper, &req, &bufferp);
- lock_ObtainMutex(&scp->mx);
+ lock_ObtainWrite(&scp->rw);
if (code) goto done;
bufferOffset = thyper;
if (code)
goto done;
+ cm_SyncOpDone(scp, bufferp, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_READ);
+
if (cm_HaveBuffer(scp, bufferp, 0)) break;
/* otherwise, load the buffer and try again */
} /* while 1 */
done:
- lock_ReleaseMutex(&scp->mx);
+ lock_ReleaseWrite(&scp->rw);
//lock_ReleaseMutex(&fidp->mx);
if (bufferp)
buf_Release(bufferp);
if (code == 0 && sequential)
- cm_ConsiderPrefetch(scp, &lastByte, userp, &req);
+ cm_ConsiderPrefetch(scp, &lastByte, *readp, userp, &req);
return code;
}
long written = 0;
osi_hyper_t fileLength; /* file's length at start of write */
osi_hyper_t minLength; /* don't read past this */
- long nbytes; /* # of bytes to transfer this iteration */
+ afs_uint32 nbytes; /* # of bytes to transfer this iteration */
cm_buf_t *bufferp;
osi_hyper_t thyper; /* hyper tmp variable */
osi_hyper_t bufferOffset;
- long bufIndex; /* index in buffer where our data is */
+ afs_uint32 bufIndex; /* index in buffer where our data is */
int doWriteBack;
- osi_hyper_t writeBackOffset; /* offset of region to write back when
+ osi_hyper_t writeBackOffset;/* offset of region to write back when
* I/O is done */
DWORD filter = 0;
cm_req_t req;
bufferp = NULL;
doWriteBack = 0;
- lock_ObtainMutex(&scp->mx);
+ lock_ObtainWrite(&scp->rw);
/* start by looking up the file's end */
code = cm_SyncOp(scp, NULL, userp, &req, 0,
if (code)
goto done;
+ cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_SETSTATUS | CM_SCACHESYNC_GETSTATUS);
+
#if 0
/* make sure we have a writable FD */
if (!(fidp->flags & SMB_FID_OPENWRITE)) {
buf_Release(bufferp);
bufferp = NULL;
}
- lock_ReleaseMutex(&scp->mx);
+ lock_ReleaseWrite(&scp->rw);
- lock_ObtainRead(&scp->bufCreateLock);
- code = buf_Get(scp, &thyper, &bufferp);
- lock_ReleaseRead(&scp->bufCreateLock);
+ code = buf_Get(scp, &thyper, &req, &bufferp);
lock_ObtainMutex(&bufferp->mx);
- lock_ObtainMutex(&scp->mx);
+ lock_ObtainWrite(&scp->rw);
if (code)
goto done;
| CM_SCACHESYNC_BUFLOCKED);
if (code)
goto done;
-
+
+ cm_SyncOpDone(scp, bufferp,
+ CM_SCACHESYNC_NEEDCALLBACK
+ | CM_SCACHESYNC_WRITE
+ | CM_SCACHESYNC_BUFLOCKED);
+
/* If we're overwriting the entire buffer, or
* if we're writing at or past EOF, mark the
* buffer as current so we don't call
(count >= buf_bufferSize ||
LargeIntegerGreaterThanOrEqualTo(LargeIntegerAdd(offset, ConvertLongToLargeInteger(count)), minLength))) {
if (count < buf_bufferSize
- && bufferp->dataVersion == -1)
+ && bufferp->dataVersion == CM_BUF_VERSION_BAD)
memset(bufferp->datap, 0,
buf_bufferSize);
bufferp->dataVersion = scp->dataVersion;
lock_ReleaseMutex(&bufferp->mx);
code = cm_GetBuffer(scp, bufferp, NULL, userp,
&req);
- lock_ReleaseMutex(&scp->mx);
+ lock_ReleaseWrite(&scp->rw);
lock_ObtainMutex(&bufferp->mx);
- lock_ObtainMutex(&scp->mx);
+ lock_ObtainWrite(&scp->rw);
if (code)
break;
}
nbytes = count; /* don't go past end of request */
/* now copy the data */
-#ifdef DJGPP
- if (dosflag)
- dosmemget((dos_ptr)op, nbytes, bufferp->datap + bufIndex);
- else
-#endif /* DJGPP */
- memcpy(bufferp->datap + bufIndex, op, nbytes);
- buf_SetDirty(bufferp);
-
- /* and record the last writer */
- if (bufferp->userp != userp) {
- cm_HoldUser(userp);
- if (bufferp->userp)
- cm_ReleaseUser(bufferp->userp);
- bufferp->userp = userp;
- }
+ memcpy(bufferp->datap + bufIndex, op, nbytes);
+ buf_SetDirty(bufferp, bufIndex, nbytes, userp);
/* adjust counters, pointers, etc. */
op += nbytes;
} /* while 1 */
done:
- lock_ReleaseMutex(&scp->mx);
+ lock_ReleaseWrite(&scp->rw);
if (bufferp) {
lock_ReleaseMutex(&bufferp->mx);
buf_Release(bufferp);
}
-#if 0
- if (code == 0 /* && filter != 0 && (fidp->flags & SMB_FID_NTOPEN)
- && (fidp->NTopen_dscp->flags & CM_SCACHEFLAG_ANYWATCH)*/) {
- smb_NotifyChange(FILE_ACTION_MODIFIED, filter,
- fidp->NTopen_dscp, fidp->NTopen_pathp,
- NULL, TRUE);
- }
-#endif
-
if (code == 0 && doWriteBack) {
- lock_ObtainMutex(&scp->mx);
- cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_ASYNCSTORE);
- lock_ReleaseMutex(&scp->mx);
- cm_QueueBKGRequest(scp, cm_BkgStore, writeBackOffset.LowPart,
- writeBackOffset.HighPart, cm_chunkSize, 0, userp);
- }
-
+ lock_ObtainWrite(&scp->rw);
+ code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_ASYNCSTORE);
+ lock_ReleaseWrite(&scp->rw);
+ if (code == 0)
+ cm_QueueBKGRequest(scp, cm_BkgStore, writeBackOffset.LowPart,
+ writeBackOffset.HighPart, cm_chunkSize, 0, userp);
+ }
+
+ /* cm_SyncOpDone is called when cm_BkgStore completes */
return code;
}