Windows: Add cm_req_t parameter to buf_Get* functions
[openafs.git] / src / WINNT / afsd / rawops.c
index 0a6b07e..c06af5e 100644 (file)
@@ -10,8 +10,6 @@
 #include <osi.h>
 #include "afsd.h"
 
-#include "afsdifs.h"
-
 #define CM_BUF_SIZE            4096
 long buf_bufferSize = CM_BUF_SIZE;
 
@@ -33,7 +31,7 @@ long ReadData(cm_scache_t *scp, osi_hyper_t offset, long count, char *op,
 
     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,
@@ -82,13 +80,11 @@ long ReadData(cm_scache_t *scp, osi_hyper_t offset, long count, char *op,
                 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;
 
@@ -136,13 +132,13 @@ long ReadData(cm_scache_t *scp, osi_hyper_t offset, long count, char *op,
     } /* 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;
 }       
@@ -161,7 +157,7 @@ long WriteData(cm_scache_t *scp, osi_hyper_t offset, long count, char *op,
     osi_hyper_t bufferOffset;
     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;
@@ -171,7 +167,7 @@ long WriteData(cm_scache_t *scp, osi_hyper_t offset, long count, char *op,
     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,
@@ -245,14 +241,12 @@ long WriteData(cm_scache_t *scp, osi_hyper_t offset, long count, char *op,
                 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;
 
@@ -290,7 +284,7 @@ long WriteData(cm_scache_t *scp, osi_hyper_t offset, long count, char *op,
                      (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;
@@ -302,9 +296,9 @@ long WriteData(cm_scache_t *scp, osi_hyper_t offset, long count, char *op,
                 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;
             }
@@ -328,15 +322,7 @@ long WriteData(cm_scache_t *scp, osi_hyper_t offset, long count, char *op,
 
         /* now copy the data */
        memcpy(bufferp->datap + bufIndex, op, nbytes);
-        buf_SetDirty(bufferp, bufIndex, nbytes);
-
-        /* and record the last writer */
-        if (bufferp->userp != userp) {
-            cm_HoldUser(userp);
-            if (bufferp->userp) 
-                cm_ReleaseUser(bufferp->userp);
-            bufferp->userp = userp;
-        }
+        buf_SetDirty(bufferp, bufIndex, nbytes, userp);
 
         /* adjust counters, pointers, etc. */
         op += nbytes;
@@ -348,18 +334,19 @@ long WriteData(cm_scache_t *scp, osi_hyper_t offset, long count, char *op,
     } /* while 1 */
 
   done:
-    lock_ReleaseMutex(&scp->mx);
+    lock_ReleaseWrite(&scp->rw);
     if (bufferp) {
         lock_ReleaseMutex(&bufferp->mx);
         buf_Release(bufferp);
     }
 
     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 */