code = cm_Lock(scp, sLockType, LOffset, LLength, key, 0, userp, reqp, NULL);
if (code == 0) {
- cm_Unlock(scp, sLockType, LOffset, LLength, key, userp, reqp);
+ cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, reqp);
} else {
/* In this case, we allow the file open to go through even
though we can't enforce mandatory locking on the
(*ldpp) = (cm_lock_data_t *)malloc(sizeof(cm_lock_data_t));
if (!*ldpp) {
code = ENOMEM;
- goto _syncopdone;
+ goto _done;
}
(*ldpp)->key = key;
goto _done;
}
- _syncopdone:
- cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
-
_done:
lock_ReleaseWrite(&scp->rw);
cm_lock_data_t ** ldpp)
{
osi_Log2(afsd_logp,"cm_CheckNTOpenDone scp 0x%p ldp 0x%p", scp, *ldpp);
+ lock_ObtainWrite(&scp->rw);
if (*ldpp) {
- lock_ObtainWrite(&scp->rw);
cm_Unlock(scp, (*ldpp)->sLockType, (*ldpp)->LOffset, (*ldpp)->LLength,
- (*ldpp)->key, userp, reqp);
- lock_ReleaseWrite(&scp->rw);
+ (*ldpp)->key, 0, userp, reqp);
free(*ldpp);
*ldpp = NULL;
}
+ cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
+ lock_ReleaseWrite(&scp->rw);
return 0;
}
/*
return code;
thyper.HighPart = 0; thyper.LowPart = 0;
- code = buf_Get(scp, &thyper, &bufferp);
+ code = buf_Get(scp, &thyper, reqp, &bufferp);
if (code)
return code;
bufferp = NULL;
}
- code = buf_Get(scp, &thyper, &bufferp);
+ code = buf_Get(scp, &thyper, reqp, &bufferp);
if (code) {
/* if buf_Get() fails we do not have a buffer object to lock */
bufferp = NULL;
sp = (cm_lookupSearch_t *) rockp;
- cm_FsStringToNormString(dep->name, -1, matchName, lengthof(matchName));
+ if (cm_FsStringToNormString(dep->name, -1, matchName, lengthof(matchName)) == 0) {
+ /* Can't normalize FS string. */
+ return 0;
+ }
+
if (sp->caseFold)
match = cm_NormStrCmpI(matchName, sp->nsearchNamep);
else
long cm_ReadMountPoint(cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp)
{
long code;
- cm_buf_t *bufp;
+ cm_buf_t *bufp = NULL;
osi_hyper_t thyper;
int tlen;
if (scp->mountPointStringp[0])
return 0;
- /* otherwise, we have to read it in */
- lock_ReleaseWrite(&scp->rw);
-
- thyper.LowPart = thyper.HighPart = 0;
- code = buf_Get(scp, &thyper, &bufp);
+#ifdef AFS_FREELANCE_CLIENT
+ /* File servers do not have data for freelance entries */
+ if (cm_freelanceEnabled &&
+ scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
+ scp->fid.volume==AFS_FAKE_ROOT_VOL_ID )
+ {
+ code = cm_FreelanceFetchMountPointString(scp);
+ } else
+#endif /* AFS_FREELANCE_CLIENT */
+ {
+ /* otherwise, we have to read it in */
+ lock_ReleaseWrite(&scp->rw);
- lock_ObtainWrite(&scp->rw);
- if (code)
- return code;
+ thyper.LowPart = thyper.HighPart = 0;
+ code = buf_Get(scp, &thyper, reqp, &bufp);
- while (1) {
- code = cm_SyncOp(scp, bufp, userp, reqp, 0,
- CM_SCACHESYNC_READ | CM_SCACHESYNC_NEEDCALLBACK);
+ lock_ObtainWrite(&scp->rw);
if (code)
- goto done;
+ return code;
- cm_SyncOpDone(scp, bufp, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_READ);
+ while (1) {
+ code = cm_SyncOp(scp, bufp, userp, reqp, 0,
+ CM_SCACHESYNC_READ | CM_SCACHESYNC_NEEDCALLBACK);
+ if (code)
+ goto done;
- if (cm_HaveBuffer(scp, bufp, 0))
- break;
+ cm_SyncOpDone(scp, bufp, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_READ);
- /* otherwise load buffer */
- code = cm_GetBuffer(scp, bufp, NULL, userp, reqp);
- if (code)
+ if (cm_HaveBuffer(scp, bufp, 0))
+ break;
+
+ /* otherwise load buffer */
+ code = cm_GetBuffer(scp, bufp, NULL, userp, reqp);
+ if (code)
+ goto done;
+ }
+ /* locked, has callback, has valid data in buffer */
+ if ((tlen = scp->length.LowPart) > MOUNTPOINTLEN - 1)
+ return CM_ERROR_TOOBIG;
+ if (tlen <= 0) {
+ code = CM_ERROR_INVAL;
goto done;
- }
- /* locked, has callback, has valid data in buffer */
- if ((tlen = scp->length.LowPart) > MOUNTPOINTLEN - 1)
- return CM_ERROR_TOOBIG;
- if (tlen <= 0) {
- code = CM_ERROR_INVAL;
- goto done;
- }
+ }
- /* someone else did the work while we were out */
- if (scp->mountPointStringp[0]) {
- code = 0;
- goto done;
- }
+ /* someone else did the work while we were out */
+ if (scp->mountPointStringp[0]) {
+ code = 0;
+ goto done;
+ }
- /* otherwise, copy out the link */
- memcpy(scp->mountPointStringp, bufp->datap, tlen);
+ /* otherwise, copy out the link */
+ memcpy(scp->mountPointStringp, bufp->datap, tlen);
- /* now make it null-terminated. Note that the original contents of a
- * link that is a mount point is "#volname." where "." is there just to
- * be turned into a null. That is, we can trash the last char of the
- * link without damaging the vol name. This is a stupid convention,
- * but that's the protocol.
- */
- scp->mountPointStringp[tlen-1] = 0;
- code = 0;
+ /* now make it null-terminated. Note that the original contents of a
+ * link that is a mount point is "#volname." where "." is there just to
+ * be turned into a null. That is, we can trash the last char of the
+ * link without damaging the vol name. This is a stupid convention,
+ * but that's the protocol.
+ */
+ scp->mountPointStringp[tlen-1] = 0;
+ code = 0;
- done:
- if (bufp)
- buf_Release(bufp);
+ done:
+ if (bufp)
+ buf_Release(bufp);
+ }
return code;
}
size_t vnLength;
int targetType;
+ *outScpp = NULL;
+
if (scp->mountRootFid.cell != 0 && scp->mountRootGen >= cm_data.mountRootGen) {
tfid = scp->mountRootFid;
lock_ReleaseWrite(&scp->rw);
/* normal mt pt */
volNamep = cm_FsStrDup(mpNamep + 1);
- cellp = cm_FindCellByID(scp->fid.cell, 0);
+#ifdef AFS_FREELANCE_CLIENT
+ /*
+ * Mount points in the Freelance cell should default
+ * to the workstation cell.
+ */
+ if (cm_freelanceEnabled &&
+ scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
+ scp->fid.volume==AFS_FAKE_ROOT_VOL_ID )
+ {
+ fschar_t rootCellName[256]="";
+ cm_GetRootCellName(rootCellName);
+ cellp = cm_GetCell(rootCellName, 0);
+ } else
+#endif /* AFS_FREELANCE_CLIENT */
+ cellp = cm_FindCellByID(scp->fid.cell, 0);
}
if (!cellp) {
}
long cm_LookupInternal(cm_scache_t *dscp, clientchar_t *cnamep, long flags, cm_user_t *userp,
- cm_req_t *reqp, cm_scache_t **outpScpp)
+ cm_req_t *reqp, cm_scache_t **outScpp)
{
long code;
int dnlcHit = 1; /* did we hit in the dnlc? yes, we did */
normchar_t *nnamep = NULL;
fschar_t *fnamep = NULL;
+ *outScpp = NULL;
+
memset(&rock, 0, sizeof(rock));
if (dscp->fid.vnode == 1 && dscp->fid.unique == 1
}
nnamep = cm_ClientStringToNormStringAlloc(cnamep, -1, NULL);
+ if (!nnamep) {
+ code = CM_ERROR_NOSUCHFILE;
+ goto done;
+ }
fnamep = cm_ClientStringToFsStringAlloc(cnamep, -1, NULL);
+ if (!fnamep) {
+ code = CM_ERROR_NOSUCHFILE;
+ goto done;
+ }
if (flags & CM_FLAG_NOMOUNTCHASE) {
/* In this case, we should go and call cm_Dir* functions
cm_ClientStrCmpI(cnamep, _C("ipc$")))
{
/* nonexistent dir on freelance root, so add it */
- fschar_t fullname[CELL_MAXNAMELEN] = ".";
+ fschar_t fullname[CELL_MAXNAMELEN + 1] = "."; /* +1 so that when we skip the . the size is still CELL_MAXNAMELEN */
int found = 0;
osi_Log1(afsd_logp,"cm_Lookup adding mount for non-existent directory: %S",
code = cm_FreelanceAddSymlink(fnamep, fullname, &rock.fid);
}
}
- if (!found || code < 0) { /* add mount point failed, so give up */
+ if (!found || code) { /* add mount point failed, so give up */
if (flags & CM_FLAG_CHECKPATH)
code = CM_ERROR_NOSUCHPATH;
else
}
/* copy back pointer */
- *outpScpp = tscp;
+ *outScpp = tscp;
/* insert scache in dnlc */
if ( !dnlcHit && !(flags & CM_FLAG_NOMOUNTCHASE) && rock.ExactFound ) {
if (nnamep)
free(nnamep);
nnamep = cm_ClientStringToNormStringAlloc(cnamep, -1, NULL);
- cm_dnlcEnter(dscp, nnamep, tscp);
+ if (nnamep)
+ cm_dnlcEnter(dscp, nnamep, tscp);
}
lock_ReleaseRead(&dscp->rw);
}
}
long cm_EvaluateVolumeReference(clientchar_t * namep, long flags, cm_user_t * userp,
- cm_req_t *reqp, cm_scache_t ** outpScpp)
+ cm_req_t *reqp, cm_scache_t ** outScpp)
{
afs_uint32 code = 0;
fschar_t cellName[CELL_MAXNAMELEN];
cm_SetFid(&fid, cellp->cellID, volume, 1, 1);
- code = cm_GetSCache(&fid, outpScpp, userp, reqp);
+ code = cm_GetSCache(&fid, outScpp, userp, reqp);
_exit_cleanup:
if (fnamep)
#ifdef DEBUG_REFCOUNT
long cm_LookupDbg(cm_scache_t *dscp, clientchar_t *namep, long flags, cm_user_t *userp,
- cm_req_t *reqp, cm_scache_t **outpScpp, char * file, long line)
+ cm_req_t *reqp, cm_scache_t **outScpp, char * file, long line)
#else
long cm_Lookup(cm_scache_t *dscp, clientchar_t *namep, long flags, cm_user_t *userp,
- cm_req_t *reqp, cm_scache_t **outpScpp)
+ cm_req_t *reqp, cm_scache_t **outScpp)
#endif
{
long code;
if (dscp == cm_data.rootSCachep &&
cm_ClientStrCmpNI(namep, _C(CM_PREFIX_VOL), CM_PREFIX_VOL_CCH) == 0) {
- return cm_EvaluateVolumeReference(namep, flags, userp, reqp, outpScpp);
+ return cm_EvaluateVolumeReference(namep, flags, userp, reqp, outScpp);
}
if (cm_ExpandSysName(namep, NULL, 0, 0) > 0) {
#endif
if (code == 0) {
- *outpScpp = scp;
+ *outScpp = scp;
return 0;
}
if (scp) {
afsi_log("%s:%d cm_LookupInternal (2) code 0x%x dscp 0x%p ref %d scp 0x%p ref %d", file, line, code, dscp, dscp->refCount, scp, scp ? scp->refCount : 0);
osi_Log3(afsd_logp, "cm_LookupInternal (2) code 0x%x dscp 0x%p scp 0x%p", code, dscp, scp);
#endif
- *outpScpp = scp;
+ *outScpp = scp;
return code;
}
}
afsi_log("%s:%d cm_LookupInternal (2) code 0x%x dscp 0x%p ref %d scp 0x%p ref %d", file, line, code, dscp, dscp->refCount, scp, scp ? scp->refCount : 0);
osi_Log3(afsd_logp, "cm_LookupInternal (2) code 0x%x dscp 0x%p scp 0x%p", code, dscp, scp);
#endif
- *outpScpp = scp;
+ *outScpp = scp;
return code;
}
cm_ReleaseSCache(scp);
if (code == 0) {
lock_ObtainWrite(&scp->rw);
- scp->flags |= CM_SCACHEFLAG_DELETED;
+ if (--scp->linkCount == 0)
+ scp->flags |= CM_SCACHEFLAG_DELETED;
+ cm_DiscardSCache(scp);
lock_ReleaseWrite(&scp->rw);
}
}
lock_AssertWrite(&linkScp->rw);
if (!linkScp->mountPointStringp[0]) {
- /* read the link data */
- lock_ReleaseWrite(&linkScp->rw);
- thyper.LowPart = thyper.HighPart = 0;
- code = buf_Get(linkScp, &thyper, &bufp);
- lock_ObtainWrite(&linkScp->rw);
- if (code)
- return code;
- while (1) {
- code = cm_SyncOp(linkScp, bufp, userp, reqp, 0,
- CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_READ);
- if (code) {
- buf_Release(bufp);
+
+#ifdef AFS_FREELANCE_CLIENT
+ /* File servers do not have data for freelance entries */
+ if (cm_freelanceEnabled &&
+ linkScp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
+ linkScp->fid.volume==AFS_FAKE_ROOT_VOL_ID )
+ {
+ code = cm_FreelanceFetchMountPointString(linkScp);
+ } else
+#endif /* AFS_FREELANCE_CLIENT */
+ {
+ /* read the link data from the file server*/
+ lock_ReleaseWrite(&linkScp->rw);
+ thyper.LowPart = thyper.HighPart = 0;
+ code = buf_Get(linkScp, &thyper, reqp, &bufp);
+ lock_ObtainWrite(&linkScp->rw);
+ if (code)
return code;
- }
- cm_SyncOpDone(linkScp, bufp, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_READ);
+ while (1) {
+ code = cm_SyncOp(linkScp, bufp, userp, reqp, 0,
+ CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_READ);
+ if (code) {
+ buf_Release(bufp);
+ return code;
+ }
+ cm_SyncOpDone(linkScp, bufp, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_READ);
- if (cm_HaveBuffer(linkScp, bufp, 0))
- break;
+ if (cm_HaveBuffer(linkScp, bufp, 0))
+ break;
- code = cm_GetBuffer(linkScp, bufp, NULL, userp, reqp);
- if (code) {
+ code = cm_GetBuffer(linkScp, bufp, NULL, userp, reqp);
+ if (code) {
+ buf_Release(bufp);
+ return code;
+ }
+ } /* while loop to get the data */
+
+ /* now if we still have no link read in,
+ * copy the data from the buffer */
+ if ((temp = linkScp->length.LowPart) >= MOUNTPOINTLEN) {
buf_Release(bufp);
- return code;
+ return CM_ERROR_TOOBIG;
+ }
+
+ /* otherwise, it fits; make sure it is still null (could have
+ * lost race with someone else referencing this link above),
+ * and if so, copy in the data.
+ */
+ if (!linkScp->mountPointStringp[0]) {
+ strncpy(linkScp->mountPointStringp, bufp->datap, temp);
+ linkScp->mountPointStringp[temp] = 0; /* null terminate */
}
- } /* while loop to get the data */
-
- /* now if we still have no link read in,
- * copy the data from the buffer */
- if ((temp = linkScp->length.LowPart) >= MOUNTPOINTLEN) {
buf_Release(bufp);
- return CM_ERROR_TOOBIG;
}
+
+ if ( !strnicmp(linkScp->mountPointStringp, "msdfs:", strlen("msdfs:")) )
+ linkScp->fileType = CM_SCACHETYPE_DFSLINK;
- /* otherwise, it fits; make sure it is still null (could have
- * lost race with someone else referencing this link above),
- * and if so, copy in the data.
- */
- if (!linkScp->mountPointStringp[0]) {
- strncpy(linkScp->mountPointStringp, bufp->datap, temp);
- linkScp->mountPointStringp[temp] = 0; /* null terminate */
-
- if ( !strnicmp(linkScp->mountPointStringp, "msdfs:", strlen("msdfs:")) )
- linkScp->fileType = CM_SCACHETYPE_DFSLINK;
- }
- buf_Release(bufp);
} /* don't have sym link contents cached */
return 0;
StringCchCatA(tsp->data,lengthof(tsp->data), "\\");
StringCchCatA(tsp->data,lengthof(tsp->data), pathSuffixp);
}
+
if (code == 0) {
clientchar_t * cpath = cm_FsStringToClientStringAlloc(tsp->data, -1, NULL);
+ if (cpath != NULL) {
cm_ClientStrCpy(tsp->wdata, lengthof(tsp->wdata), cpath);
free(cpath);
*newSpaceBufferp = tsp;
} else {
+ code = CM_ERROR_NOSUCHPATH;
+ }
+ }
+
+ if (code != 0) {
cm_FreeSpace(tsp);
if (code == CM_ERROR_PATH_NOT_COVERED && reqp->tidPathp && reqp->relPathp) {
int fid_count = 0; /* number of fids processed in this path walk */
int i;
+ *outScpp = NULL;
+
#ifdef DEBUG_REFCOUNT
afsi_log("%s:%d cm_NameI rootscp 0x%p ref %d", file, line, rootSCachep, rootSCachep->refCount);
osi_Log4(afsd_logp,"cm_NameI rootscp 0x%p path %S tidpath %S flags 0x%x",
- rootSCachep, pathp ? pathp : "<NULL>", tidPathp ? tidPathp : "<NULL>",
+ rootSCachep, pathp ? pathp : L"<NULL>", tidPathp ? tidPathp : L"<NULL>",
flags);
#endif
fid_count = i+1;
} else {
/* add the new fid to the list */
- for ( i=0; i<fid_count; i++) {
- if ( !cm_FidCmp(&nscp->fid, &fids[i]) ) {
- code = CM_ERROR_TOO_MANY_SYMLINKS;
- cm_ReleaseSCache(nscp);
- nscp = NULL;
- break;
- }
- }
- if (i == fid_count && fid_count < MAX_FID_COUNT) {
- fids[fid_count++] = nscp->fid;
- }
+ if (fid_count == MAX_FID_COUNT) {
+ code = CM_ERROR_TOO_MANY_SYMLINKS;
+ cm_ReleaseSCache(nscp);
+ nscp = NULL;
+ break;
+ }
+ fids[fid_count++] = nscp->fid;
}
}
cm_ReleaseSCache(tscp);
#ifdef DEBUG_REFCOUNT
- afsi_log("%s:%d cm_NameI code 0x%x outScpp 0x%p ref %d", file, line, code, *outScpp, (*outScpp)->refCount);
+ afsi_log("%s:%d cm_NameI code 0x%x outScpp 0x%p ref %d", file, line, code, *outScpp, (*outScpp) ? (*outScpp)->refCount : 0);
#endif
osi_Log2(afsd_logp,"cm_NameI code 0x%x outScpp 0x%p", code, *outScpp);
return code;
cm_space_t *spacep;
cm_scache_t *newRootScp;
+ *outScpp = NULL;
+
osi_Log1(afsd_logp, "Evaluating symlink scp 0x%p", linkScp);
code = cm_AssembleLink(linkScp, "", &newRootScp, &spacep, userp, reqp);
}
cm_EndDirOp(&dirop);
+ /* Update the linked object status */
+ if (code == 0) {
+ lock_ObtainWrite(&sscp->rw);
+ cm_MergeStatus(NULL, sscp, &newLinkStatus, &volSync, userp, 0);
+ lock_ReleaseWrite(&sscp->rw);
+ }
+
free(fnamep);
return code;
cm_dirOp_t newDirOp;
fschar_t * newNamep = NULL;
int free_oldNamep = FALSE;
+ cm_scache_t *oldScp = NULL, *newScp = NULL;
if (cOldNamep == NULL || cNewNamep == NULL ||
cm_ClientStrLen(cOldNamep) == 0 ||
cm_ClientStrLen(cNewNamep) == 0)
return CM_ERROR_INVAL;
+ /*
+ * Before we permit the operation, make sure that we do not already have
+ * an object in the destination directory that has a case-insensitive match
+ * for this name UNLESS the matching object is the object we are renaming.
+ */
+ code = cm_Lookup(oldDscp, cOldNamep, 0, userp, reqp, &oldScp);
+ if (code) {
+ osi_Log2(afsd_logp, "cm_Rename oldDscp 0x%p cOldName %S old name lookup failed",
+ oldDscp, osi_LogSaveStringW(afsd_logp, cOldNamep));
+ goto done;
+ }
+
+ code = cm_Lookup(newDscp, cNewNamep, CM_FLAG_CASEFOLD, userp, reqp, &newScp);
+ if (code == 0) {
+ /* found a matching object with the new name */
+ if (cm_FidCmp(&oldScp->fid, &newScp->fid)) {
+ /* and they don't match so return an error */
+ osi_Log2(afsd_logp, "cm_Rename newDscp 0x%p cNewName %S new name already exists",
+ newDscp, osi_LogSaveStringW(afsd_logp, cNewNamep));
+ code = CM_ERROR_EXISTS;
+ }
+ cm_ReleaseSCache(newScp);
+ newScp = NULL;
+ } else if (code == CM_ERROR_AMBIGUOUS_FILENAME) {
+ code = CM_ERROR_EXISTS;
+ } else {
+ code = 0;
+ }
+ if (code)
+ goto done;
+
if (oldNamep == NULL) {
code = -1;
#ifdef USE_BPLUS
userp, CM_MERGEFLAG_DIROP);
lock_ReleaseWrite(&oldDscp->rw);
- if (code == 0) {
- if (cm_CheckDirOpForSingleChange(&oldDirOp)) {
-
+ if (code == 0 && cm_CheckDirOpForSingleChange(&oldDirOp)) {
#ifdef USE_BPLUS
- diropCode = cm_BPlusDirLookup(&oldDirOp, cOldNamep, &fileFid);
- if (diropCode == CM_ERROR_INEXACT_MATCH)
- diropCode = 0;
- else if (diropCode == EINVAL)
+ diropCode = cm_BPlusDirLookup(&oldDirOp, cOldNamep, &fileFid);
+ if (diropCode == CM_ERROR_INEXACT_MATCH)
+ diropCode = 0;
+ else if (diropCode == EINVAL)
#endif
- diropCode = cm_DirLookup(&oldDirOp, oldNamep, &fileFid);
+ diropCode = cm_DirLookup(&oldDirOp, oldNamep, &fileFid);
- if (diropCode == 0) {
- if (oneDir) {
- diropCode = cm_DirCreateEntry(&oldDirOp, newNamep, &fileFid);
-#ifdef USE_BPLUS
- cm_BPlusDirCreateEntry(&oldDirOp, cNewNamep, &fileFid);
+ if (diropCode == 0) {
+ if (oneDir) {
+ diropCode = cm_DirCreateEntry(&oldDirOp, newNamep, &fileFid);
+#ifdef USE_BPLUS
+ cm_BPlusDirCreateEntry(&oldDirOp, cNewNamep, &fileFid);
#endif
- }
+ }
- if (diropCode == 0) {
- diropCode = cm_DirDeleteEntry(&oldDirOp, oldNamep);
+ if (diropCode == 0) {
+ diropCode = cm_DirDeleteEntry(&oldDirOp, oldNamep);
#ifdef USE_BPLUS
- cm_BPlusDirDeleteEntry(&oldDirOp, cOldNamep);
-#endif
- }
+ cm_BPlusDirDeleteEntry(&oldDirOp, cOldNamep);
+#endif
}
}
}
userp, CM_MERGEFLAG_DIROP);
lock_ReleaseWrite(&newDscp->rw);
+#if 0
+ /*
+ * The following optimization does not work.
+ * When the file server processed a RXAFS_Rename() request the
+ * FID of the object being moved between directories is not
+ * preserved. The client does not know the new FID nor the
+ * version number of the target. Not only can we not create
+ * the directory entry in the new directory, but we can't
+ * preserve the cached data for the file. It must be re-read
+ * from the file server. - jaltman, 2009/02/20
+ */
if (code == 0) {
/* we only make the local change if we successfully made
the change in the old directory AND there was only one
#endif
}
}
+#endif /* 0 */
cm_EndDirOp(&newDirOp);
}
+ /*
+ * After the rename the file server has invalidated the callbacks
+ * on the file that was moved nor do we have a directory reference
+ * to it anymore.
+ */
+ lock_ObtainWrite(&oldScp->rw);
+ cm_DiscardSCache(oldScp);
+ lock_ReleaseWrite(&oldScp->rw);
+
done:
+ if (oldScp)
+ cm_ReleaseSCache(oldScp);
+
if (free_oldNamep)
free(oldNamep);
if (INTERSECT_RANGE(range, fileLock->range)) {
if (IS_LOCK_ACTIVE(fileLock)) {
- if (fileLock->key == key) {
+ if (cm_KeyEquals(&fileLock->key, &key, 0)) {
/* If there is an active lock for this client, it
is safe to substract ranges.*/
cm_LockRangeSubtract(&range, &fileLock->range);
}
} else if (IS_LOCK_LOST(fileLock) &&
- (fileLock->key == key || fileLock->lockType == LockWrite)) {
+ (cm_KeyEquals(&fileLock->key, &key, 0) || fileLock->lockType == LockWrite)) {
code = CM_ERROR_BADFD;
break;
}
if (INTERSECT_RANGE(range, fileLock->range)) {
if (IS_LOCK_ACTIVE(fileLock)) {
- if (fileLock->key == key) {
+ if (cm_KeyEquals(&fileLock->key, &key, 0)) {
if (fileLock->lockType == LockWrite) {
/* if there is an active lock for this client, it
osi_Log4(afsd_logp, "cm_Lock scp 0x%x type 0x%x offset %d length %d",
scp, sLockType, (unsigned long)LOffset.QuadPart, (unsigned long)LLength.QuadPart);
- osi_Log3(afsd_logp, "... allowWait %d key 0x%x:%x", allowWait,
- (unsigned long)(key >> 32), (unsigned long)(key & 0xffffffff));
+ osi_Log4(afsd_logp, "... allowWait %d key <0x%x, 0x%x, 0x%x>", allowWait,
+ key.process_id, key.session_id, key.file_id);
/*
A client C can OBTAIN a lock L on cm_scache_t S iff (both 3 and 4):
(cm_file_lock_t *)((char *) q - offsetof(cm_file_lock_t, fileq));
if (IS_LOCK_LOST(fileLock)) {
- if (fileLock->key == key) {
+ if (cm_KeyEquals(&fileLock->key, &key, 0)) {
code = CM_ERROR_BADFD;
break;
} else if (fileLock->lockType == LockWrite && INTERSECT_RANGE(range, fileLock->range)) {
return code;
}
-static int cm_KeyEquals(cm_key_t k1, cm_key_t k2, int flags);
-
/* Called with scp->rw held */
long cm_UnlockByKey(cm_scache_t * scp,
cm_key_t key,
osi_queue_t *q, *qn;
int n_unlocks = 0;
- osi_Log4(afsd_logp, "cm_UnlockByKey scp 0x%p key 0x%x:%x flags=0x%x",
- scp,
- (unsigned long)(key >> 32),
- (unsigned long)(key & 0xffffffff),
- flags);
+ osi_Log4(afsd_logp, "cm_UnlockByKey scp 0x%p key <0x%x,0x%x,0x%x",
+ scp, key.process_id, key.session_id, key.file_id);
+ osi_Log1(afsd_logp, " flags=0x%x", flags);
lock_ObtainWrite(&cm_scacheLock);
(unsigned long) fileLock->range.offset,
(unsigned long) fileLock->range.length,
fileLock->lockType);
- osi_Log3(afsd_logp, " key[0x%x:%x] flags[0x%x]",
- (unsigned long)(fileLock->key >> 32),
- (unsigned long)(fileLock->key & 0xffffffff),
+ osi_Log4(afsd_logp, " key<0x%x, 0x%x, 0x%x> flags[0x%x]",
+ fileLock->key.process_id, fileLock->key.session_id, fileLock->key.file_id,
fileLock->flags);
if (cm_FidCmp(&fileLock->fid, &fileLock->scp->fid)) {
#endif
if (!IS_LOCK_DELETED(fileLock) &&
- cm_KeyEquals(fileLock->key, key, flags)) {
+ cm_KeyEquals(&fileLock->key, &key, flags)) {
osi_Log3(afsd_logp, "...Unlock range [%d,+%d] type %d",
fileLock->range.offset,
fileLock->range.length,
unsigned char sLockType,
LARGE_INTEGER LOffset, LARGE_INTEGER LLength,
cm_key_t key,
+ afs_uint32 flags,
cm_user_t *userp,
cm_req_t *reqp)
{
cm_file_lock_t *fileLock;
osi_queue_t *q;
int release_userp = FALSE;
+ int exact_match = !(flags & CM_UNLOCK_FLAG_MATCH_RANGE);
+ int lock_found = 0;
+ LARGE_INTEGER RangeEnd;
osi_Log4(afsd_logp, "cm_Unlock scp 0x%p type 0x%x offset %d length %d",
scp, sLockType, (unsigned long)LOffset.QuadPart, (unsigned long)LLength.QuadPart);
- osi_Log2(afsd_logp, "... key 0x%x:%x",
- (unsigned long) (key >> 32), (unsigned long) (key & 0xffffffff));
+ osi_Log4(afsd_logp, "... key <0x%x,0x%x,0x%x> flags 0x%x",
+ key.process_id, key.session_id, key.file_id, flags);
+
+ if (!exact_match)
+ RangeEnd.QuadPart = LOffset.QuadPart + LLength.QuadPart;
+ try_again:
lock_ObtainRead(&cm_scacheLock);
for (q = scp->fileLocksH; q; q = osi_QNext(q)) {
osi_assertx(FALSE, "invalid fid value");
}
#endif
- if (!IS_LOCK_DELETED(fileLock) &&
- fileLock->key == key &&
- fileLock->range.offset == LOffset.QuadPart &&
- fileLock->range.length == LLength.QuadPart) {
- break;
+ if (exact_match) {
+ if (!IS_LOCK_DELETED(fileLock) &&
+ cm_KeyEquals(&fileLock->key, &key, 0) &&
+ fileLock->range.offset == LOffset.QuadPart &&
+ fileLock->range.length == LLength.QuadPart) {
+ lock_found = 1;
+ break;
+ }
+ } else {
+
+ if (!IS_LOCK_DELETED(fileLock) &&
+ cm_KeyEquals(&fileLock->key, &key, 0) &&
+ fileLock->range.offset >= LOffset.QuadPart &&
+ fileLock->range.offset < RangeEnd.QuadPart &&
+ (fileLock->range.offset + fileLock->range.length) <= RangeEnd.QuadPart) {
+ lock_found = 1;
+ break;
+ }
}
}
if (!q) {
- osi_Log0(afsd_logp, "cm_Unlock lock not found; failure");
-
lock_ReleaseRead(&cm_scacheLock);
- /* The lock didn't exist anyway. *shrug* */
- return CM_ERROR_RANGE_NOT_LOCKED;
+ if (lock_found && !exact_match) {
+ code = 0;
+ goto done;
+ } else {
+ osi_Log0(afsd_logp, "cm_Unlock lock not found; failure");
+
+ /* The lock didn't exist anyway. *shrug* */
+ return CM_ERROR_RANGE_NOT_LOCKED;
+ }
}
/* discard lock record */
}
}
- if (release_userp)
+ if (release_userp) {
cm_ReleaseUser(userp);
+ release_userp = FALSE;
+ }
+
+ if (!exact_match)
+ goto try_again; /* might be more than one lock in the range */
done:
}
scp->serverLock = -1;
- scp->lockDataVersion = -1;
+ scp->lockDataVersion = CM_SCACHE_VERSION_BAD;
lock_ReleaseWrite(&cm_scacheLock);
}
(unsigned)(oldFileLock->range.offset & 0xffffffff),
(unsigned)(oldFileLock->range.length >> 32),
(unsigned)(oldFileLock->range.length & 0xffffffff));
- osi_Log3(afsd_logp, " key(%x:%x) flags=%x",
- (unsigned)(oldFileLock->key >> 32),
- (unsigned)(oldFileLock->key & 0xffffffff),
+ osi_Log4(afsd_logp, " key<0x%x,0x%x,0x%x> flags=%x",
+ oldFileLock->key.process_id, oldFileLock->key.session_id, oldFileLock->key.file_id,
(unsigned)(oldFileLock->flags));
/* if the lock has already been granted, then we have nothing to do */
((char *) q - offsetof(cm_file_lock_t, fileq));
if (IS_LOCK_LOST(fileLock)) {
- if (fileLock->key == oldFileLock->key) {
+ if (cm_KeyEquals(&fileLock->key, &oldFileLock->key, 0)) {
code = CM_ERROR_BADFD;
oldFileLock->flags |= CM_FILELOCK_FLAG_LOST;
osi_Log1(afsd_logp, " found lost lock %p for same key. Marking lock as lost",
return code;
}
-cm_key_t cm_GenerateKey(unsigned int session_id, unsigned long process_id, unsigned int file_id)
+cm_key_t cm_GenerateKey(afs_uint16 session_id, afs_offs_t process_id, afs_uint16 file_id)
{
-#ifdef DEBUG
- osi_assertx((process_id & 0xffffffff) == process_id, "unexpected process_id");
- osi_assertx((session_id & 0xffff) == session_id, "unexpected session_id");
- osi_assertx((file_id & 0xffff) == file_id, "unexpected file_id");
-#endif
+ cm_key_t key;
+
+ key.process_id = process_id;
+ key.session_id = session_id;
+ key.file_id = file_id;
- return
- (((cm_key_t) (process_id & 0xffffffff)) << 32) |
- (((cm_key_t) (session_id & 0xffff)) << 16) |
- (((cm_key_t) (file_id & 0xffff)));
+ return key;
}
-static int cm_KeyEquals(cm_key_t k1, cm_key_t k2, int flags)
+int cm_KeyEquals(cm_key_t *k1, cm_key_t *k2, int flags)
{
- if (flags & CM_UNLOCK_BY_FID) {
- return ((k1 & 0xffffffff) == (k2 & 0xffffffff));
- } else {
- return (k1 == k2);
- }
+ return (k1->session_id == k2->session_id) && (k1->file_id == k2->file_id) &&
+ ((flags & CM_UNLOCK_BY_FID) || (k1->process_id == k2->process_id));
}
void cm_ReleaseAllLocks(void)