#include <osi.h>
#include "afsd.h"
+#include "smb.h"
#ifdef DEBUG
extern void afsi_log(char *pattern, ...);
long cm_BufWrite(void *vscp, osi_hyper_t *offsetp, long length, long flags,
cm_user_t *userp, cm_req_t *reqp)
{
- /* store the data back from this buffer; the buffer is locked and held,
- * but the vnode involved isn't locked, yet. It is held by its
- * reference from the buffer, which won't change until the buffer is
- * released by our caller. Thus, we don't have to worry about holding
- * bufp->scp.
+ /*
+ * store the data back from this buffer; the buffer is locked and held,
+ * 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;
cm_scache_t *scp = vscp;
int require_64bit_ops = 0;
int call_was_64bit = 0;
int scp_locked = flags & CM_BUF_WRITE_SCP_LOCKED;
+ int storedata_excl = 0;
osi_assertx(userp != NULL, "null cm_user_t");
osi_assertx(scp != NULL, "null cm_scache_t");
memset(&volSync, 0, sizeof(volSync));
- /* now, the buffer may or may not be filled with good data (buf_GetNewLocked
+ /*
+ * now, the buffer may or may not be filled with good data (buf_GetNewLocked
* drops lots of locks, and may indeed return a properly initialized
* buffer, although more likely it will just return a new, empty, buffer.
*/
/* Serialize StoreData RPC's; for rationale see cm_scache.c */
(void) cm_SyncOp(scp, NULL, userp, reqp, 0, CM_SCACHESYNC_STOREDATA_EXCL);
+ storedata_excl = 1;
code = cm_SetupStoreBIOD(scp, offsetp, length, &biod, userp, reqp);
if (code) {
if (biod.length == 0) {
osi_Log0(afsd_logp, "cm_SetupStoreBIOD length 0");
cm_ReleaseBIOD(&biod, 1, 0, 1); /* should be a NOOP */
- cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_STOREDATA_EXCL);
- if (!scp_locked)
- lock_ReleaseWrite(&scp->rw);
- return 0;
+ code = 0;
+ goto exit_storedata_excl;
}
/* prepare the output status for the store */
require_64bit_ops = 1;
}
+ InterlockedIncrement(&scp->activeRPCs);
lock_ReleaseWrite(&scp->rw);
/* now we're ready to do the store operation */
}
nbytes -= wbytes;
#endif /* USE_RX_IOVEC */
+
+ /*
+ * Rx supports an out of band signalling mechanism that permits
+ * RPC specific status information to be communicated in the
+ * reverse direction of the channel. For RXAFS_StoreData, the
+ * 0-bit is set once all of the permission checks have completed
+ * and the volume/vnode locks have been obtained by the file
+ * server. The signal is intended to notify the Unix afs client
+ * that is performing store-on-close that it is safe to permit
+ * the close operation to complete while the store continues
+ * in the background. All of the callbacks have been broken
+ * and the locks will not be dropped until the RPC completes
+ * which prevents any other operation from being initiated on
+ * the vnode until the store is finished.
+ *
+ * The Windows client does not perform store-on-close. Instead
+ * it uses the CM_SCACHESYNC_STOREDATA_EXCL request flag and
+ * CM_SCACHEFLAG_DATASTORING scache state to ensure that store
+ * operations are serialized. The 0-bit signal permits the
+ * CM_SCACHEFLAG_DATASTORING state to the dropped which in
+ * turn permits another thread to prep its own BIOD in parallel.
+ * This is safe because it is impossible for that second store
+ * RPC to complete before this one does.
+ */
+ if ( storedata_excl && (rx_GetRemoteStatus(rxcallp) & 1)) {
+ lock_ObtainWrite(&scp->rw);
+ cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_STOREDATA_EXCL);
+ lock_ReleaseWrite(&scp->rw);
+ storedata_excl = 0;
+ }
} /* while more bytes to write */
} /* if RPC started successfully */
cm_MergeStatus(NULL, scp, &outStatus, &volSync, userp, reqp, CM_MERGEFLAG_STOREDATA);
} else {
+ InterlockedDecrement(&scp->activeRPCs);
if (code == CM_ERROR_SPACE)
_InterlockedOr(&scp->flags, CM_SCACHEFLAG_OUTOFSPACE);
else if (code == CM_ERROR_QUOTA)
_InterlockedOr(&scp->flags, CM_SCACHEFLAG_OVERQUOTA);
}
- cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_STOREDATA_EXCL);
+
+ exit_storedata_excl:
+ if (storedata_excl)
+ cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_STOREDATA_EXCL);
if (!scp_locked)
lock_ReleaseWrite(&scp->rw);
require_64bit_ops = 1;
}
+ InterlockedIncrement(&scp->activeRPCs);
lock_ReleaseWrite(&scp->rw);
cm_AFSFidFromFid(&tfid, &scp->fid);
if (LargeIntegerGreaterThanOrEqualTo(t, scp->length))
_InterlockedAnd(&scp->mask, ~CM_SCACHEMASK_LENGTH);
cm_MergeStatus(NULL, scp, &outStatus, &volSync, userp, reqp, CM_MERGEFLAG_STOREDATA);
+ } else {
+ InterlockedDecrement(&scp->activeRPCs);
}
cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_STOREDATA_EXCL);
osi_hyper_t toffset;
long length;
long code = 0;
+ afs_uint32 req_flags = reqp->flags;
if (scp->flags & CM_SCACHEFLAG_DELETED) {
osi_Log4(afsd_logp, "Skipping BKG store - Deleted scp 0x%p, offset 0x%x:%08x, length 0x%x", scp, p2, p1, p3);
} else {
/* Retries will be performed by the BkgDaemon thread if appropriate */
- afs_uint32 req_flags = reqp->flags;
reqp->flags |= CM_REQ_NORETRY;
toffset.LowPart = p1;
biop->offset = firstModOffset;
bufp = NULL; /* this buffer and reference added to the queue */
- /* compute the window surrounding *inOffsetp of size cm_chunkSize */
- scanStart = *inOffsetp;
+ /* compute the window surrounding firstModOffset of size cm_chunkSize */
+ scanStart = firstModOffset;
scanStart.LowPart &= (-cm_chunkSize);
thyper = ConvertLongToLargeInteger(cm_chunkSize);
scanEnd = LargeIntegerAdd(scanStart, thyper);
osi_queueData_t *qdp;
osi_queueData_t *nqdp;
int flags;
+ int reportErrorToRedir = 0;
/* Give back reserved buffers */
if (biop->reserved)
bufp->error = code;
bufp->dataVersion = CM_BUF_VERSION_BAD;
bufp->dirtyCounter++;
+ reportErrorToRedir = 1;
break;
case CM_ERROR_TIMEDOUT:
case CM_ERROR_ALLDOWN:
buf_Release(bufp);
bufp = NULL;
}
+
+ if (RDR_Initialized && reportErrorToRedir) {
+ DWORD status;
+ smb_MapNTError(cm_MapRPCError(code, biop->reqp), &status, TRUE);
+ RDR_SetFileStatus( &scp->fid, status);
+ }
} else {
if (!scp_locked)
lock_ObtainWrite(&scp->rw);
return 0;
}
+ InterlockedIncrement(&scp->activeRPCs);
lock_ReleaseWrite(&scp->rw);
scp_locked = 0;
if (code == 0)
cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, CM_MERGEFLAG_FETCHDATA);
+ else
+ InterlockedDecrement(&scp->activeRPCs);
return code;
}
require_64bit_ops = 1;
}
+ InterlockedIncrement(&scp->activeRPCs);
osi_Log2(afsd_logp, "cm_GetData: fetching data scp %p DV 0x%x", scp, scp->dataVersion);
#ifdef AFS_FREELANCE_CLIENT
if (code == 0)
cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, CM_MERGEFLAG_FETCHDATA);
+ else
+ InterlockedDecrement(&scp->activeRPCs);
return code;
}