* but the vnode involved may or may not be locked depending on whether
* or not the CM_BUF_WRITE_SCP_LOCKED flag is set.
*/
- long code, code1;
+ long code;
cm_scache_t *scp = vscp;
afs_int32 nbytes;
afs_int32 save_nbytes;
}
}
- code1 = rx_EndCall(rxcallp, code);
+ /* Prefer rx_EndCall error over StoreData error. Note that this will
+ * never set 'code' to 0 if we passed in a non-zero code. */
+ code = rx_EndCall(rxcallp, code);
- if ((code == RXGEN_OPCODE || code1 == RXGEN_OPCODE) && SERVERHAS64BIT(connp)) {
+ if (code == RXGEN_OPCODE && SERVERHAS64BIT(connp)) {
SET_SERVERHASNO64BIT(connp);
qdp = NULL;
nbytes = save_nbytes;
goto retry;
}
- /* Prefer rx_EndCall error over StoreData error */
- if (code1 != 0) {
- osi_Log2(afsd_logp, "rx_EndCall converted 0x%x to 0x%x", code, code1);
- code = code1;
- }
} while (cm_Analyze(connp, userp, reqp, &scp->fid, NULL, 1, &outStatus, &volSync, NULL, NULL, code));
code = cm_MapRPCError(code, reqp);
AFSStoreStatus inStatus;
AFSVolSync volSync;
AFSFid tfid;
- long code, code1;
+ long code;
osi_hyper_t truncPos;
cm_conn_t *connp;
struct rx_call *rxcallp;
int call_was_64bit = 0;
memset(&volSync, 0, sizeof(volSync));
+ memset(&inStatus, 0, sizeof(inStatus));
osi_Log2(afsd_logp, "cm_StoreMini scp 0x%p userp 0x%p", scp, userp);
osi_Log0(afsd_logp, "EndRXAFS_StoreData SUCCESS");
}
}
- code1 = rx_EndCall(rxcallp, code);
+ code = rx_EndCall(rxcallp, code);
- if ((code == RXGEN_OPCODE || code1 == RXGEN_OPCODE) && SERVERHAS64BIT(connp)) {
+ if (code == RXGEN_OPCODE && SERVERHAS64BIT(connp)) {
SET_SERVERHASNO64BIT(connp);
goto retry;
}
-
- /* prefer StoreData error over rx_EndCall error */
- if (code == 0 && code1 != 0)
- code = code1;
} while (cm_Analyze(connp, userp, reqp, &scp->fid, NULL, 1, &outStatus, &volSync, NULL, NULL, code));
code = cm_MapRPCError(code, reqp);
osi_hyper_t scanStart; /* where to start scan for dirty pages */
osi_hyper_t scanEnd; /* where to stop scan for dirty pages */
osi_hyper_t firstModOffset; /* offset of first modified page in range */
+ osi_hyper_t tblocksize;
long temp;
long code;
long flags; /* flags to cm_SyncOp */
+ int blockSize = cm_data.blockSize; /* need a signed version */
+
+ tblocksize = ConvertLongToLargeInteger(cm_data.buf_blockSize);
/* clear things out */
biop->scp = scp; /* do not hold; held by caller */
/* reserve a chunk's worth of buffers */
lock_ReleaseWrite(&scp->rw);
- biop->reserved = (cm_chunkSize / cm_data.buf_blockSize);
+ biop->reserved = (cm_chunkSize / blockSize);
buf_ReserveBuffers(biop->reserved);
lock_ObtainWrite(&scp->rw);
bufp = NULL;
- for (temp = 0; temp < inSize; temp += cm_data.buf_blockSize) {
+ for (temp = 0; temp < inSize; temp += blockSize) {
thyper = ConvertLongToLargeInteger(temp);
tbase = LargeIntegerAdd(*inOffsetp, thyper);
lock_ReleaseMutex(&bufp->mx);
buf_Release(bufp);
bufp = NULL;
- buf_UnreserveBuffers(cm_chunkSize / cm_data.buf_blockSize);
+ buf_UnreserveBuffers(cm_chunkSize / blockSize);
return code;
}
osi_QAddH((osi_queue_t **) &biop->bufListp,
(osi_queue_t **) &biop->bufListEndp,
&qdp->q);
- biop->length = cm_data.buf_blockSize;
+ biop->length = blockSize;
firstModOffset = bufp->offset;
biop->offset = firstModOffset;
bufp = NULL; /* this buffer and reference added to the queue */
thyper = ConvertLongToLargeInteger(cm_chunkSize);
scanEnd = LargeIntegerAdd(scanStart, thyper);
+ /* do not scan beyond the end of the file */
+ if (scanEnd.QuadPart > scp->length.QuadPart) {
+ scanEnd = scp->length;
+ scanEnd.LowPart &= (-blockSize);
+ if (scanEnd.LowPart < scp->length.LowPart)
+ scanEnd.LowPart += blockSize;
+ }
+
+ /* do not leave out a requested portion of the range */
+ if (scanEnd.QuadPart < inOffsetp->QuadPart + inSize) {
+ scanEnd.QuadPart = inOffsetp->QuadPart + inSize;
+ }
+
flags = CM_SCACHESYNC_GETSTATUS
| CM_SCACHESYNC_STOREDATA
| CM_SCACHESYNC_BUFLOCKED;
/* start by looking backwards until scanStart */
- /* hyper version of cm_data.buf_blockSize */
- thyper = ConvertLongToLargeInteger(cm_data.buf_blockSize);
- tbase = LargeIntegerSubtract(firstModOffset, thyper);
+ tbase = LargeIntegerSubtract(firstModOffset, tblocksize);
while(LargeIntegerGreaterThanOrEqualTo(tbase, scanStart)) {
/* see if we can find the buffer */
bufp = buf_Find(&scp->fid, &tbase);
bufp = NULL; /* added to the queue */
/* update biod info describing the transfer */
- biop->offset = LargeIntegerSubtract(biop->offset, thyper);
- biop->length += cm_data.buf_blockSize;
+ biop->offset = LargeIntegerSubtract(biop->offset, tblocksize);
+ biop->length += blockSize;
/* update loop pointer */
- tbase = LargeIntegerSubtract(tbase, thyper);
+ tbase = LargeIntegerSubtract(tbase, tblocksize);
} /* while loop looking for pages preceding the one we found */
/* now, find later dirty, contiguous pages, and add them to the list */
- /* hyper version of cm_data.buf_blockSize */
- thyper = ConvertLongToLargeInteger(cm_data.buf_blockSize);
- tbase = LargeIntegerAdd(firstModOffset, thyper);
+ tbase = LargeIntegerAdd(firstModOffset, tblocksize);
while(LargeIntegerLessThan(tbase, scanEnd)) {
/* see if we can find the buffer */
bufp = buf_Find(&scp->fid, &tbase);
bufp = NULL;
/* update biod info describing the transfer */
- biop->length += cm_data.buf_blockSize;
+ biop->length += blockSize;
/* update loop pointer */
- tbase = LargeIntegerAdd(tbase, thyper);
+ tbase = LargeIntegerAdd(tbase, tblocksize);
} /* while loop looking for pages following the first page we found */
/* finally, we're done */
long cm_GetBuffer(cm_scache_t *scp, cm_buf_t *bufp, int *cpffp, cm_user_t *userp,
cm_req_t *reqp)
{
- long code=0, code1=0;
+ long code=0;
afs_uint32 nbytes; /* bytes in transfer */
afs_uint32 nbytes_hi = 0; /* high-order 32 bits of bytes in transfer */
afs_uint64 length_found = 0;
/* now make the call */
do {
+ long code1;
+
code = cm_ConnFromFID(&scp->fid, userp, reqp, &connp);
if (code)
continue;
nbytes_hi = ntohl(nbytes_hi);
} else {
nbytes_hi = 0;
- code = rx_Error(rxcallp);
- code1 = rx_EndCall(rxcallp, code);
+ code = rx_EndCall(rxcallp, RX_PROTOCOL_ERROR);
rxcallp = NULL;
}
}
osi_Log1(afsd_logp, "CALL EndRXAFS_FetchData skipped due to error %d", code);
}
+ code1 = code;
if (rxcallp)
code1 = rx_EndCall(rxcallp, code);
scp_locked = 0;
}
code = 0;
- /* Prefer the error value from FetchData over rx_EndCall */
- } else if (code == 0 && code1 != 0)
+ } else {
+ /* Prefer the error from rx_EndCall over any other error */
code = code1;
+ }
osi_Log0(afsd_logp, "CALL FetchData DONE");
} while (cm_Analyze(connp, userp, reqp, &scp->fid, NULL, 0, &afsStatus, &volSync, NULL, NULL, code));
* a provided buffer. Called with scp locked. The scp is locked on return.
*/
long cm_GetData(cm_scache_t *scp, osi_hyper_t *offsetp, char *datap, int data_length,
- cm_user_t *userp, cm_req_t *reqp)
+ int * bytes_readp, cm_user_t *userp, cm_req_t *reqp)
{
- long code=0, code1=0;
+ long code=0;
afs_uint32 nbytes; /* bytes in transfer */
afs_uint32 nbytes_hi = 0; /* high-order 32 bits of bytes in transfer */
afs_uint64 length_found = 0;
int first_read = 1;
int scp_locked = 1;
+ if (bytes_readp)
+ *bytes_readp = 0;
+
memset(&afsStatus, 0, sizeof(afsStatus));
memset(&callback, 0, sizeof(callback));
memset(&volSync, 0, sizeof(volSync));
/* now make the call */
do {
+ long code1;
+
code = cm_ConnFromFID(&scp->fid, userp, reqp, &connp);
if (code)
continue;
nbytes_hi = ntohl(nbytes_hi);
} else {
nbytes_hi = 0;
- code = rx_Error(rxcallp);
- code1 = rx_EndCall(rxcallp, code);
+ code = rx_EndCall(rxcallp, RX_PROTOCOL_ERROR);
rxcallp = NULL;
}
}
osi_Log1(afsd_logp, "CALL EndRXAFS_FetchData skipped due to error %d", code);
}
+ code1 = code;
if (rxcallp)
code1 = rx_EndCall(rxcallp, code);
scp_locked = 0;
}
code = 0;
- /* Prefer the error value from FetchData over rx_EndCall */
- } else if (code == 0 && code1 != 0)
+ } else {
+ /* Prefer the error from rx_EndCall over any other error */
code = code1;
+ }
osi_Log0(afsd_logp, "CALL FetchData DONE");
} while (cm_Analyze(connp, userp, reqp, &scp->fid, NULL, 0, &afsStatus, &volSync, NULL, NULL, code));
else
InterlockedDecrement(&scp->activeRPCs);
+ *bytes_readp = (long) (bufferp - datap);
+
return code;
}
long
cm_VerifyStoreData(cm_bulkIO_t *biod, cm_scache_t *savedScp)
{
- long code=0, code1=0;
+ long code=0;
afs_uint32 nbytes; /* bytes in transfer */
afs_uint32 nbytes_hi = 0; /* high-order 32 bits of bytes in transfer */
afs_uint64 length_found = 0;
/* now make the call */
do {
+ long code1;
+
code = cm_ConnFromFID(&scp->fid, userp, reqp, &connp);
if (code)
continue;
nbytes_hi = ntohl(nbytes_hi);
} else {
nbytes_hi = 0;
- code = rx_Error(rxcallp);
- code1 = rx_EndCall(rxcallp, code);
+ code = rx_EndCall(rxcallp, RX_PROTOCOL_ERROR);
rxcallp = NULL;
}
}
osi_Log1(afsd_logp, "CALL EndRXAFS_FetchData skipped due to error %d", code);
}
+ code1 = code;
if (rxcallp)
code1 = rx_EndCall(rxcallp, code);
scp_locked = 0;
}
code = 0;
- /* Prefer the error value from FetchData over rx_EndCall */
- } else if (code == 0 && code1 != 0)
+ } else {
+ /* Prefer the error from rx_EndCall over any other error */
code = code1;
+ }
osi_Log0(afsd_logp, "CALL FetchData DONE");
} while (cm_Analyze(connp, userp, reqp, &scp->fid, NULL, 0, &afsStatus, &volSync, NULL, NULL, code));