static struct AFSCallStatistics AFSCallStats;
struct fs_stats_FullPerfStats afs_FullPerfStats;
extern int AnonymousID;
-#if OPENAFS_VOL_STATS
static const char nullString[] = "";
-#endif /* OPENAFS_VOL_STATS */
struct afs_FSStats {
afs_int32 NothingYet;
* locktype : indicates what kind of lock to take on vnodes
* rights : returns a pointer to caller's rights
* anyrights : returns a pointer to anonymous' rights
+ * remote : indicates that the volume is a remote RW replica
*
* Returns:
* 0 on success
AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
int chkforDir, Vnode ** parent,
struct client **client, int locktype,
- afs_int32 * rights, afs_int32 * anyrights)
+ afs_int32 * rights, afs_int32 * anyrights, int remote)
{
struct acl_accessList *aCL; /* Internal access List */
int aCLSize; /* size of the access list */
goto gvpdone;
}
}
- if ((errorCode =
- SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
- (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
- (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
- goto gvpdone;
- if (chkforDir == MustBeDIR)
- osi_Assert((*parent) == 0);
- if (!(*client)) {
- if ((errorCode = GetClient(tcon, client)) != 0)
+ /*
+ * If the remote flag is set, the current call is dealing with a remote RW
+ * replica, and it can be assumed that the appropriate access checks were
+ * done by the calling server hosting the master volume.
+ */
+ if (!remote) {
+ if ((errorCode = SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
+ (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
+ (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
goto gvpdone;
+ if (chkforDir == MustBeDIR)
+ osi_Assert((*parent) == 0);
if (!(*client)) {
- errorCode = EINVAL;
- goto gvpdone;
+ if ((errorCode = GetClient(tcon, client)) != 0)
+ goto gvpdone;
+ if (!(*client)) {
+ errorCode = EINVAL;
+ goto gvpdone;
+ }
+ }
+ GetRights(*client, aCL, rights, anyrights);
+ /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
+ if ((*targetptr)->disk.type != vDirectory) {
+ /* anyuser can't be owner, so only have to worry about rights, not anyrights */
+ if ((*targetptr)->disk.owner == (*client)->ViceId)
+ (*rights) |= PRSFS_ADMINISTER;
+ else
+ (*rights) &= ~PRSFS_ADMINISTER;
}
- }
- GetRights(*client, aCL, rights, anyrights);
- /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
- if ((*targetptr)->disk.type != vDirectory) {
- /* anyuser can't be owner, so only have to worry about rights, not anyrights */
- if ((*targetptr)->disk.owner == (*client)->ViceId)
- (*rights) |= PRSFS_ADMINISTER;
- else
- (*rights) &= ~PRSFS_ADMINISTER;
- }
#ifdef ADMIN_IMPLICIT_LOOKUP
- /* admins get automatic lookup on everything */
- if (!VanillaUser(*client))
- (*rights) |= PRSFS_LOOKUP;
+ /* admins get automatic lookup on everything */
+ if (!VanillaUser(*client))
+ (*rights) |= PRSFS_LOOKUP;
#endif /* ADMIN_IMPLICIT_LOOKUP */
+ }
gvpdone:
if (errorCode)
rx_KeepAliveOn(acall);
{
return GetVolumePackageWithCall(acall, NULL, Fid, volptr, targetptr,
chkforDir, parent, client, locktype,
- rights, anyrights);
+ rights, anyrights, 0);
}
if (size > len)
size = len;
- buff = (char *)malloc(COPYBUFFSIZE);
+ buff = malloc(COPYBUFFSIZE);
if (buff == NULL) {
return EIO;
}
IH_RELEASE(newH);
FDH_REALLYCLOSE(targFdP);
rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
- if (!rc) {
+ if (rc) {
ViceLog(0,
("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
rc, V_id(volptr), volptr->partition->name));
* Update the target file's (or dir's) status block after the specified
* operation is complete. Note that some other fields maybe updated by
* the individual module.
+ * If remote is set, the volume is a RW replica and access checks can
+ * be skipped.
*/
/* XXX INCOMPLETE - More attention is needed here! */
Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
struct client *client, AFSStoreStatus * InStatus,
Vnode * parentptr, Volume * volptr,
- afs_fsize_t length)
+ afs_fsize_t length, int remote)
{
Date currDate; /*Current date */
int writeIdx; /*Write index to bump */
targetptr->disk.author = client->ViceId;
if (Caller & TVS_SDATA) {
targetptr->disk.dataVersion++;
- if (VanillaUser(client)) {
+ if (!remote && VanillaUser(client)) {
targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
#ifdef CREATE_SGUID_ADMIN_ONLY
targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
}
if (InStatus->Mask & AFS_SETOWNER) {
/* admin is allowed to do chmod, chown as well as chown, chmod. */
- if (VanillaUser(client)) {
+ if (!remote && VanillaUser(client)) {
targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
#ifdef CREATE_SGUID_ADMIN_ONLY
targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
int modebits = InStatus->UnixModeBits;
#define CREATE_SGUID_ADMIN_ONLY 1
#ifdef CREATE_SGUID_ADMIN_ONLY
- if (VanillaUser(client))
+ if (!remote && VanillaUser(client))
modebits = modebits & 0777;
#endif
- if (VanillaUser(client)) {
+ if (!remote && VanillaUser(client)) {
targetptr->disk.modeBits = modebits;
} else {
targetptr->disk.modeBits = modebits;
return VSALVAGE;
}
- *targetptr = VAllocVnode(&errorCode, volptr, FileType);
+ *targetptr = VAllocVnode(&errorCode, volptr, FileType, 0, 0);
if (errorCode != 0) {
VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
return (errorCode);
if (strlen(Name) > 0) {
strcpy(V_name(volptr), Name);
}
-#if OPENAFS_VOL_STATS
/*
* We don't overwrite the motd field, since it's now being used
* for stats
*/
-#else
- if (strlen(Motd) > 0) {
- strcpy(V_motd(volptr), Motd);
- }
-#endif
VUpdateVolume(&errorCode, volptr);
return (errorCode);
RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
char **motd, Volume * volptr)
{
- int temp;
status->Vid = V_id(volptr);
status->ParentId = V_parentId(volptr);
status->MinQuota = V_minquota(volptr);
status->MaxQuota = V_maxquota(volptr);
status->BlocksInUse = V_diskused(volptr);
- status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
- status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
+ status->PartBlocksAvail = RoundInt64ToInt31(volptr->partition->free);
+ status->PartMaxBlocks = RoundInt64ToInt31(volptr->partition->totalUsable);
/* now allocate and copy these things; they're freed by the RXGEN stub */
- temp = strlen(V_name(volptr)) + 1;
- *name = malloc(temp);
+ *name = strdup(V_name(volptr));
if (!*name) {
ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
}
- strcpy(*name, V_name(volptr));
- temp = strlen(V_offlineMessage(volptr)) + 1;
- *offMsg = malloc(temp);
+ *offMsg = strdup(V_offlineMessage(volptr));
if (!*offMsg) {
ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
}
- strcpy(*offMsg, V_offlineMessage(volptr));
-#if OPENAFS_VOL_STATS
*motd = malloc(1);
if (!*motd) {
ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
}
strcpy(*motd, nullString);
-#else
- temp = strlen(V_motd(volptr)) + 1;
- *motd = malloc(temp);
- if (!*motd) {
- ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
- }
- strcpy(*motd, V_motd(volptr));
-#endif /* OPENAFS_VOL_STATS */
return 0;
} /*RXGetVolumeStatus */
GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
afs_int32 anyrights, Vnode * parentptr)
{
+ int Time =FT_ApproxTime();
+
/* initialize return status from a vnode */
status->InterfaceVersion = 1;
status->SyncCounter = status->dataVersionHigh = status->lockCount =
Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
status->ServerModTime = targetptr->disk.serverModifyTime;
status->Group = targetptr->disk.group;
- status->lockCount = targetptr->disk.lock.lockCount;
+ status->lockCount = Time > targetptr->disk.lock.lockTime ? 0 : targetptr->disk.lock.lockCount;
status->errorCode = 0;
} /*GetStatus */
if ((errorCode =
GetVolumePackageWithCall(acall, cbv, Fid, &volptr, &targetptr, DONTCHECK,
&parentwhentargetnotdir, &client, READ_LOCK,
- &rights, &anyrights)))
+ &rights, &anyrights, 0)))
goto Bad_FetchData;
SetVolumeSync(Sync, volptr);
}
/* allocate space for return output parameters */
- OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
- malloc(nfiles * sizeof(struct AFSFetchStatus));
+ OutStats->AFSBulkStats_val = malloc(nfiles * sizeof(struct AFSFetchStatus));
if (!OutStats->AFSBulkStats_val) {
ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
}
OutStats->AFSBulkStats_len = nfiles;
- CallBacks->AFSCBs_val = (struct AFSCallBack *)
- malloc(nfiles * sizeof(struct AFSCallBack));
+ CallBacks->AFSCBs_val = malloc(nfiles * sizeof(struct AFSCallBack));
if (!CallBacks->AFSCBs_val) {
ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
}
}
/* allocate space for return output parameters */
- OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
- malloc(nfiles * sizeof(struct AFSFetchStatus));
+ OutStats->AFSBulkStats_val = calloc(nfiles, sizeof(struct AFSFetchStatus));
if (!OutStats->AFSBulkStats_val) {
ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
}
OutStats->AFSBulkStats_len = nfiles;
- CallBacks->AFSCBs_val = (struct AFSCallBack *)
- malloc(nfiles * sizeof(struct AFSCallBack));
+ CallBacks->AFSCBs_val = calloc(nfiles, sizeof(struct AFSCallBack));
if (!CallBacks->AFSCBs_val) {
ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
}
CallBacks->AFSCBs_len = nfiles;
/* Zero out return values to avoid leaking information on partial succes */
- memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
- memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
memset(Sync, 0, sizeof(*Sync));
if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
&parentwhentargetnotdir, &client, READ_LOCK,
&rights, &anyrights))) {
tstatus = &OutStats->AFSBulkStats_val[i];
- tstatus->errorCode = errorCode;
+
+ if (thost->hostFlags & HERRORTRANS) {
+ tstatus->errorCode = sys_error_to_et(errorCode);
+ } else {
+ tstatus->errorCode = errorCode;
+ }
+
PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
(Vnode *) 0, volptr, &client);
parentwhentargetnotdir = (Vnode *) 0;
Check_PermissionRights(targetptr, client, rights,
CHK_FETCHSTATUS, 0))) {
tstatus = &OutStats->AFSBulkStats_val[i];
- tstatus->errorCode = errorCode;
+
+ if (thost->hostFlags & HERRORTRANS) {
+ tstatus->errorCode = sys_error_to_et(errorCode);
+ } else {
+ tstatus->errorCode = errorCode;
+ }
+
(void)PutVolumePackage(acall, parentwhentargetnotdir,
targetptr, (Vnode *) 0, volptr,
&client);
volptr = (Volume *) 0;
client = (struct client *)0;
}
+ errorCode = 0;
Bad_InlineBulkStatus:
/* Update and store volume/vnode and parent vnodes back */
osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
AUD_ID, t_client ? t_client->ViceId : 0,
AUD_FIDS, Fids, AUD_END);
- return 0;
+ return errorCode;
} /*SRXAFS_InlineBulkStatus */
/* set volume synchronization information */
SetVolumeSync(Sync, volptr);
- if ((targetptr->disk.type == vSymlink)) {
+ if (targetptr->disk.type == vSymlink) {
/* Should we return a better error code here??? */
errorCode = EISDIR;
goto Bad_StoreData;
rx_KeepAliveOff(acall);
/* Update the status of the target's vnode */
Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
- targetptr, volptr, 0);
+ targetptr, volptr, 0, 0);
rx_KeepAliveOn(acall);
/* Get the updated File's status back to the caller */
/* Update the status of the target's vnode */
Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
(parentwhentargetnotdir ? parentwhentargetnotdir
- : targetptr), volptr, 0);
+ : targetptr), volptr, 0, 0);
rx_KeepAliveOn(acall);
/* update the status of the new file's vnode */
Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
- parentptr, volptr, 0);
+ parentptr, volptr, 0, 0);
rx_KeepAliveOn(acall);
/* update the status of the new symbolic link file vnode */
Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
- parentptr, volptr, strlen((char *)LinkContents));
+ parentptr, volptr, strlen((char *)LinkContents), 0);
/* Write the contents of the symbolic link name into the target inode */
fdP = IH_OPEN(targetptr->handle);
/* update the status for the target vnode */
Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
- parentptr, volptr, 0);
+ parentptr, volptr, 0, 0);
/* Actually create the New directory in the directory package */
SetDirHandle(&dir, targetptr);
(void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
(Vnode *) 0, volptr, &client);
- if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
+ if (errorCode == VREADONLY) /* presumably, we already granted this lock */
errorCode = 0; /* under our generous policy re RO vols */
ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
(void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
(Vnode *) 0, volptr, &client);
- if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
+ if (errorCode == VREADONLY) /* presumably, we already granted this lock */
errorCode = 0; /* under our generous policy re RO vols */
ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
part = part->next) {
- stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
- stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
+ stats->Disks[i].TotalBlocks = RoundInt64ToInt31(part->totalUsable);
+ stats->Disks[i].BlocksAvailable = RoundInt64ToInt31(part->free);
memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
i++;
* for the File Server.
*/
dataBytes = sizeof(struct afs_Stats);
- dataBuffP = (afs_int32 *) malloc(dataBytes);
+ dataBuffP = malloc(dataBytes);
memcpy(dataBuffP, &afs_cmstats, dataBytes);
a_dataP->AFS_CollData_len = dataBytes >> 2;
a_dataP->AFS_CollData_val = dataBuffP;
*/
dataBytes = sizeof(struct afs_PerfStats);
- dataBuffP = (afs_int32 *) malloc(dataBytes);
+ dataBuffP = malloc(dataBytes);
memcpy(dataBuffP, &afs_perfstats, dataBytes);
a_dataP->AFS_CollData_len = dataBytes >> 2;
a_dataP->AFS_CollData_val = dataBuffP;
*/
dataBytes = sizeof(struct fs_stats_FullPerfStats);
- dataBuffP = (afs_int32 *) malloc(dataBytes);
+ dataBuffP = malloc(dataBytes);
memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
a_dataP->AFS_CollData_len = dataBytes >> 2;
a_dataP->AFS_CollData_val = dataBuffP;
afs_perfstats.numPerfCalls++;
dataBytes = sizeof(struct cbcounters);
- dataBuffP = (afs_int32 *) malloc(dataBytes);
+ dataBuffP = malloc(dataBytes);
{
extern struct cbcounters cbstuff;
dataBuffP[0]=cbstuff.DeleteFiles;
if (!FidArray && !CallBackArray) {
ViceLog(1,
("SAFS_GiveUpAllCallBacks: host=%x\n",
- (rx_PeerOf(tcon) ? rx_PeerOf(tcon)->host : 0)));
+ (rx_PeerOf(tcon) ? rx_HostOf(rx_PeerOf(tcon)) : 0)));
errorCode = GetClient(tcon, &client);
if (!errorCode) {
H_LOCK;
ViceLog(0,
("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
- (rx_PeerOf(tcon) ? rx_PeerOf(tcon)->host : 0)));
+ (rx_PeerOf(tcon) ? rx_HostOf(rx_PeerOf(tcon)) : 0)));
errorCode = EINVAL;
goto Bad_GiveUpCallBacks;
}
goto Bad_GetCaps;
dataBytes = 1 * sizeof(afs_int32);
- dataBuffP = (afs_uint32 *) malloc(dataBytes);
+ dataBuffP = malloc(dataBytes);
dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
if (saneacls)
return 0;
}
+/* client is held, but not locked */
+static int
+FlushClientCPS(struct client *client, void *arock)
+{
+ ObtainWriteLock(&client->lock);
+
+ client->prfail = 2; /* Means re-eval client's cps */
+
+ if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
+ free(client->CPS.prlist_val);
+ client->CPS.prlist_val = NULL;
+ client->CPS.prlist_len = 0;
+ }
+
+ ReleaseWriteLock(&client->lock);
+
+ return 0;
+}
+
afs_int32
SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
afs_int32 nids, naddrs;
afs_int32 *vd, *addr;
Error errorCode = 0; /* return code to caller */
- struct client *client = 0;
ViceLog(1, ("SRXAFS_FlushCPS\n"));
FS_LOCK;
AFSCallStats.TotalCalls++;
FS_UNLOCK;
+
+ if (!viced_SuperUser(acall)) {
+ errorCode = EPERM;
+ goto Bad_FlushCPS;
+ }
+
nids = vids->ViceIds_len; /* # of users in here */
naddrs = addrs->IPAddrs_len; /* # of hosts in here */
if (nids < 0 || naddrs < 0) {
for (i = 0; i < nids; i++, vd++) {
if (!*vd)
continue;
- client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
- if (!client)
- continue;
-
- client->prfail = 2; /* Means re-eval client's cps */
-#ifdef notdef
- if (client->tcon) {
- rx_SetRock(((struct rx_connection *)client->tcon), 0);
- }
-#endif
- if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
- free(client->CPS.prlist_val);
- client->CPS.prlist_val = NULL;
- client->CPS.prlist_len = 0;
- }
- ReleaseWriteLock(&client->lock);
- PutClient(&client);
+ h_EnumerateClients(*vd, FlushClientCPS, NULL);
}
addr = addrs->IPAddrs_val;
&rights, &anyrights)))
goto Bad_GetVolumeStatus;
- if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
- errorCode = EACCES;
- goto Bad_GetVolumeStatus;
- }
(void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
Bad_GetVolumeStatus:
ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
/* next is to guarantee out strings exist for stub */
if (*Name == 0) {
- *Name = (char *)malloc(1);
+ *Name = malloc(1);
**Name = 0;
}
if (*Motd == 0) {
- *Motd = (char *)malloc(1);
+ *Motd = malloc(1);
**Motd = 0;
}
if (*OfflineMsg == 0) {
- *OfflineMsg = (char *)malloc(1);
+ *OfflineMsg = malloc(1);
**OfflineMsg = 0;
}
errorCode = CallPostamble(tcon, errorCode, thost);
FreeSendBuffer((struct afs_buffer *)tbuffer);
#endif /* HAVE_PIOV */
if (sync) {
- FDH_SYNC(fdP);
+ (void) FDH_SYNC(fdP);
}
if (errorCode) {
Error tmp_errorCode = 0;