/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
*/
+#include <afsconfig.h>
#include <afs/param.h>
#include <afs/stds.h>
+#include <roken.h>
+
#include <windows.h>
#include <winsock2.h>
#include <nb30.h>
#include <string.h>
+#include <strsafe.h>
#include <malloc.h>
#include "afsd.h"
#include <osi.h>
osi_rwlock_t cm_volumeLock;
-long
+long
cm_ValidateVolume(void)
{
cm_volume_t * volp;
fprintf(stderr, "cm_ValidateVolume failure: volp->allNextp->magic != CM_VOLUME_MAGIC\n");
return -3;
}
- if ( count != 0 && volp == cm_data.allVolumesp ||
+ if ( count != 0 && volp == cm_data.allVolumesp ||
count > cm_data.maxVolumes ) {
afsi_log("cm_ValidateVolume failure: cm_data.allVolumep loop detected");
fprintf(stderr, "cm_ValidateVolume failure: cm_data.allVolumep loop detected\n");
fprintf(stderr, "cm_ValidateVolume failure: count != cm_data.currentVolumes\n");
return -5;
}
-
+
return 0;
}
cm_volume_t * volp;
for (volp = cm_data.allVolumesp; volp; volp=volp->allNextp) {
-
- if (volp->rw.ID)
- cm_VolumeStatusNotification(volp, volp->rw.ID, volp->rw.state, vl_alldown);
- if (volp->ro.ID)
- cm_VolumeStatusNotification(volp, volp->ro.ID, volp->ro.state, vl_alldown);
- if (volp->bk.ID)
- cm_VolumeStatusNotification(volp, volp->bk.ID, volp->bk.state, vl_alldown);
+ afs_uint32 volType;
+ for ( volType = RWVOL; volType < NUM_VOL_TYPES; volType++) {
+ if (volp->vol[volType].ID)
+ cm_VolumeStatusNotification(volp, volp->vol[volType].ID, volp->vol[volType].state, vl_alldown);
+ }
volp->cbExpiresRO = 0;
- lock_FinalizeMutex(&volp->mx);
+ volp->cbIssuedRO = 0;
+ volp->cbServerpRO = NULL;
+ lock_FinalizeRWLock(&volp->rw);
}
return 0;
static osi_once_t once;
if (osi_Once(&once)) {
- lock_InitializeRWLock(&cm_volumeLock, "cm global volume lock");
+ lock_InitializeRWLock(&cm_volumeLock, "cm global volume lock", LOCK_HIERARCHY_VOLUME_GLOBAL);
if ( newFile ) {
cm_data.allVolumesp = NULL;
cm_volume_t * volp;
for (volp = cm_data.allVolumesp; volp; volp=volp->allNextp) {
- lock_InitializeMutex(&volp->mx, "cm_volume_t mutex");
- volp->flags |= CM_VOLUMEFLAG_RESET;
- volp->rw.state = vl_unknown;
- volp->rw.serversp = NULL;
- volp->ro.state = vl_unknown;
- volp->ro.serversp = NULL;
- volp->bk.state = vl_unknown;
- volp->bk.serversp = NULL;
- if (volp->rw.ID)
- cm_VolumeStatusNotification(volp, volp->rw.ID, vl_alldown, volp->rw.state);
- if (volp->ro.ID)
- cm_VolumeStatusNotification(volp, volp->ro.ID, vl_alldown, volp->ro.state);
- if (volp->bk.ID)
- cm_VolumeStatusNotification(volp, volp->bk.ID, vl_alldown, volp->bk.state);
+ afs_uint32 volType;
+
+ lock_InitializeRWLock(&volp->rw, "cm_volume_t rwlock", LOCK_HIERARCHY_VOLUME);
+ _InterlockedOr(&volp->flags, CM_VOLUMEFLAG_RESET);
+ _InterlockedAnd(&volp->flags, ~CM_VOLUMEFLAG_UPDATING_VL);
+ volp->lastUpdateTime = 0;
+ for (volType = RWVOL; volType < NUM_VOL_TYPES; volType++) {
+ volp->vol[volType].state = vl_unknown;
+ volp->vol[volType].serversp = NULL;
+ if (volp->vol[volType].ID)
+ cm_VolumeStatusNotification(volp, volp->vol[volType].ID, vl_unknown, volp->vol[volType].state);
+ }
volp->cbExpiresRO = 0;
+ volp->cbIssuedRO = 0;
+ volp->cbServerpRO = NULL;
}
}
osi_EndOnce(&once);
/* returns true if the id is a decimal integer, in which case we interpret it
- * as an id. make the cache manager much simpler.
+ * as an id. make the cache manager much simpler.
* Stolen from src/volser/vlprocs.c */
int
cm_VolNameIsID(char *aname)
/*
- * Update a volume. Caller holds volume's lock (volp->mx).
+ * Update a volume. Caller holds a write lock on the volume (volp->rw).
*
*
* shadow / openafs / jhutz@CS.CMU.EDU {ANDREW.CMU.EDU} 01:38 (JHutz)
* first, and fall back to successively older versions if you get
* RXGEN_OPCODE.
*/
-#define MULTIHOMED 1
-long cm_UpdateVolume(struct cm_cell *cellp, cm_user_t *userp, cm_req_t *reqp,
+static long
+cm_GetEntryByName( struct cm_cell *cellp, const char *name,
+ struct vldbentry *vldbEntryp,
+ struct nvldbentry *nvldbEntryp,
+ struct uvldbentry *uvldbEntryp,
+ int *methodp,
+ cm_user_t *userp,
+ cm_req_t *reqp
+ )
+{
+ long code;
+ cm_conn_t *connp;
+ struct rx_connection * rxconnp;
+
+ osi_Log2(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s",
+ osi_LogSaveString(afsd_logp,cellp->name),
+ osi_LogSaveString(afsd_logp,name));
+ do {
+
+ code = cm_ConnByMServers(cellp->vlServersp, FALSE, userp, reqp, &connp);
+ if (code)
+ continue;
+
+ rxconnp = cm_GetRxConn(connp);
+ code = VL_GetEntryByNameU(rxconnp, name, uvldbEntryp);
+ *methodp = 2;
+ if ( code == RXGEN_OPCODE )
+ {
+ code = VL_GetEntryByNameN(rxconnp, name, nvldbEntryp);
+ *methodp = 1;
+ }
+ if ( code == RXGEN_OPCODE ) {
+ code = VL_GetEntryByNameO(rxconnp, name, vldbEntryp);
+ *methodp = 0;
+ }
+ rx_PutConnection(rxconnp);
+ } while (cm_Analyze(connp, userp, reqp, NULL, cellp, 0, NULL, cellp->vlServersp, NULL, code));
+ code = cm_MapVLRPCError(code, reqp);
+ if ( code )
+ osi_Log3(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s FAILURE, code 0x%x",
+ osi_LogSaveString(afsd_logp,cellp->name),
+ osi_LogSaveString(afsd_logp,name), code);
+ else
+ osi_Log2(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s SUCCESS",
+ osi_LogSaveString(afsd_logp,cellp->name),
+ osi_LogSaveString(afsd_logp,name));
+ return code;
+}
+
+static long
+cm_GetEntryByID( struct cm_cell *cellp, afs_uint32 id,
+ struct vldbentry *vldbEntryp,
+ struct nvldbentry *nvldbEntryp,
+ struct uvldbentry *uvldbEntryp,
+ int *methodp,
+ cm_user_t *userp,
+ cm_req_t *reqp
+ )
+{
+ char name[64];
+
+ StringCbPrintf(name, sizeof(name), "%u", id);
+
+ return cm_GetEntryByName(cellp, name, vldbEntryp, nvldbEntryp, uvldbEntryp, methodp, userp, reqp);
+}
+
+long cm_UpdateVolumeLocation(struct cm_cell *cellp, cm_user_t *userp, cm_req_t *reqp,
cm_volume_t *volp)
{
+ struct rx_connection *rxconnp;
cm_conn_t *connp;
- int i, j, k;
+ int i;
+ afs_uint32 j, k;
cm_serverRef_t *tsrp;
cm_server_t *tsp;
struct sockaddr_in tsockAddr;
u_long tempAddr;
struct vldbentry vldbEntry;
struct nvldbentry nvldbEntry;
-#ifdef MULTIHOMED
struct uvldbentry uvldbEntry;
-#endif
int method = -1;
int ROcount = 0;
+ int isMixed = 0;
long code;
enum volstatus rwNewstate = vl_online;
enum volstatus roNewstate = vl_online;
#ifdef AFS_FREELANCE_CLIENT
int freelance = 0;
#endif
+ afs_uint32 volType;
+ time_t now;
- /* clear out old bindings */
- if (volp->rw.serversp)
- cm_FreeServerList(&volp->rw.serversp, CM_FREESERVERLIST_DELETE);
- if (volp->ro.serversp)
- cm_FreeServerList(&volp->ro.serversp, CM_FREESERVERLIST_DELETE);
- if (volp->bk.serversp)
- cm_FreeServerList(&volp->bk.serversp, CM_FREESERVERLIST_DELETE);
+ lock_AssertWrite(&volp->rw);
+
+ /*
+ * If the last volume update was in the last five
+ * minutes and it did not exist, then avoid the RPC
+ * and return No Such Volume immediately.
+ */
+ now = time(NULL);
+ if ((volp->flags & CM_VOLUMEFLAG_NOEXIST) &&
+ (now < volp->lastUpdateTime + 600))
+ {
+ return CM_ERROR_NOSUCHVOLUME;
+ }
#ifdef AFS_FREELANCE_CLIENT
- if ( cellp->cellID == AFS_FAKE_ROOT_CELL_ID && volp->rw.ID == AFS_FAKE_ROOT_VOL_ID )
+ if (cellp->cellID == AFS_FAKE_ROOT_CELL_ID)
{
- freelance = 1;
+ freelance = 1;
memset(&vldbEntry, 0, sizeof(vldbEntry));
vldbEntry.flags |= VLF_RWEXISTS;
vldbEntry.volumeId[0] = AFS_FAKE_ROOT_VOL_ID;
} else
#endif
{
- /* now we have volume structure locked and held; make RPC to fill it */
- osi_Log2(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s", volp->cellp->name, volp->namep);
- do {
- code = cm_ConnByMServers(cellp->vlServersp, userp, reqp, &connp);
- if (code)
- continue;
-#ifdef MULTIHOMED
- code = VL_GetEntryByNameU(connp->callp, volp->namep, &uvldbEntry);
- method = 2;
- if ( code == RXGEN_OPCODE )
-#endif
- {
- code = VL_GetEntryByNameN(connp->callp, volp->namep, &nvldbEntry);
- method = 1;
- }
- if ( code == RXGEN_OPCODE ) {
- code = VL_GetEntryByNameO(connp->callp, volp->namep, &vldbEntry);
- method = 0;
+ while (volp->flags & CM_VOLUMEFLAG_UPDATING_VL) {
+ osi_Log3(afsd_logp, "cm_UpdateVolumeLocation sleeping name %s:%s flags 0x%x",
+ volp->cellp->name, volp->namep, volp->flags);
+ osi_SleepW((LONG_PTR) &volp->flags, &volp->rw);
+ lock_ObtainWrite(&volp->rw);
+ osi_Log3(afsd_logp, "cm_UpdateVolumeLocation awake name %s:%s flags 0x%x",
+ volp->cellp->name, volp->namep, volp->flags);
+ if (!(volp->flags & CM_VOLUMEFLAG_RESET)) {
+ osi_Log3(afsd_logp, "cm_UpdateVolumeLocation nothing to do, waking others name %s:%s flags 0x%x",
+ volp->cellp->name, volp->namep, volp->flags);
+ osi_Wakeup((LONG_PTR) &volp->flags);
+ return 0;
}
- } while (cm_Analyze(connp, userp, reqp, NULL, NULL, cellp->vlServersp, NULL, code));
- code = cm_MapVLRPCError(code, reqp);
- if ( code )
- osi_Log3(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s FAILURE, code 0x%x",
- volp->cellp->name, volp->namep, code);
- else
- osi_Log2(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s SUCCESS",
- volp->cellp->name, volp->namep);
- }
+ now = time(NULL);
+ }
- /* We can end up here with code == CM_ERROR_NOSUCHVOLUME if the base volume name
- * does not exist but there might exist a .readonly volume. If the base name
- * doesn't exist we will not care about the .backup that might be left behind
- * since there should be no method to access it.
- */
- if (code == CM_ERROR_NOSUCHVOLUME && volp->rw.ID == 0 && strlen(volp->namep) < (VL_MAXNAMELEN - 9)) {
- char name[VL_MAXNAMELEN];
+ /* Do not query again if the last update attempt failed in the last 60 seconds */
+ if ((volp->flags & CM_VOLUMEFLAG_RESET) && (volp->lastUpdateTime > now - 60))
+ {
+ osi_Log3(afsd_logp, "cm_UpdateVolumeLocation unsuccessful update in last 60 seconds -- name %s:%s flags 0x%x",
+ volp->cellp->name, volp->namep, volp->flags);
+ return(CM_ERROR_ALLDOWN);
+ }
+
+ _InterlockedOr(&volp->flags, CM_VOLUMEFLAG_UPDATING_VL);
+
+ /* Do not hold the volume lock across the RPC calls */
+ lock_ReleaseWrite(&volp->rw);
+
+ if (cellp->flags & CM_CELLFLAG_VLSERVER_INVALID)
+ cm_UpdateCell(cellp, 0);
- snprintf(name, VL_MAXNAMELEN, "%s.readonly", volp->namep);
-
/* now we have volume structure locked and held; make RPC to fill it */
- osi_Log2(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s", volp->cellp->name, name);
- do {
- code = cm_ConnByMServers(cellp->vlServersp, userp, reqp, &connp);
- if (code)
- continue;
-#ifdef MULTIHOMED
- code = VL_GetEntryByNameU(connp->callp, name, &uvldbEntry);
- method = 2;
- if ( code == RXGEN_OPCODE )
-#endif
- {
- code = VL_GetEntryByNameN(connp->callp, name, &nvldbEntry);
- method = 1;
- }
- if ( code == RXGEN_OPCODE ) {
- code = VL_GetEntryByNameO(connp->callp, name, &vldbEntry);
- method = 0;
+ code = cm_GetEntryByName(cellp, volp->namep, &vldbEntry, &nvldbEntry,
+ &uvldbEntry,
+ &method, userp, reqp);
+
+ /* We can end up here with code == CM_ERROR_NOSUCHVOLUME if the base volume name
+ * does not exist and is not a numeric string but there might exist a .readonly volume.
+ * If the base name doesn't exist we will not care about the .backup that might be left
+ * behind since there should be no method to access it.
+ */
+ if (code == CM_ERROR_NOSUCHVOLUME &&
+ _atoi64(volp->namep) == 0 &&
+ volp->vol[RWVOL].ID == 0 &&
+ strlen(volp->namep) < (VL_MAXNAMELEN - 9)) {
+ char name[VL_MAXNAMELEN];
+
+ snprintf(name, VL_MAXNAMELEN, "%s.readonly", volp->namep);
+
+ /* now we have volume structure locked and held; make RPC to fill it */
+ code = cm_GetEntryByName(cellp, name, &vldbEntry, &nvldbEntry,
+ &uvldbEntry,
+ &method, userp, reqp);
+ }
+
+ /*
+ * What if there was a volume rename? The volume name no longer exists but the
+ * volume id might. Try to refresh the volume location information based one
+ * of the readwrite or readonly volume id.
+ */
+ if (code == CM_ERROR_NOSUCHVOLUME) {
+ if (volp->vol[RWVOL].ID != 0) {
+ code = cm_GetEntryByID(cellp, volp->vol[RWVOL].ID, &vldbEntry, &nvldbEntry,
+ &uvldbEntry,
+ &method, userp, reqp);
+ } else if (volp->vol[ROVOL].ID != 0) {
+ code = cm_GetEntryByID(cellp, volp->vol[ROVOL].ID, &vldbEntry, &nvldbEntry,
+ &uvldbEntry,
+ &method, userp, reqp);
}
- } while (cm_Analyze(connp, userp, reqp, NULL, NULL, cellp->vlServersp, NULL, code));
- code = cm_MapVLRPCError(code, reqp);
- if ( code )
- osi_Log3(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s FAILURE, code 0x%x",
- volp->cellp->name, name, code);
- else
- osi_Log2(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s SUCCESS",
- volp->cellp->name, name);
+ }
+ lock_ObtainWrite(&volp->rw);
}
if (code == 0) {
afs_int32 bkID;
afs_int32 serverNumber[NMAXNSERVERS];
afs_int32 serverFlags[NMAXNSERVERS];
+ afsUUID serverUUID[NMAXNSERVERS];
afs_int32 rwServers_alldown = 1;
afs_int32 roServers_alldown = 1;
afs_int32 bkServers_alldown = 1;
rwServers_alldown = 0;
#endif
+ /* clear out old bindings */
+ for ( volType = RWVOL; volType < NUM_VOL_TYPES; volType++) {
+ if (volp->vol[volType].serversp)
+ cm_FreeServerList(&volp->vol[volType].serversp, CM_FREESERVERLIST_DELETE);
+ }
+
+ memset(serverUUID, 0, sizeof(serverUUID));
+
switch ( method ) {
case 0:
flags = vldbEntry.flags;
strncpy(name, nvldbEntry.name, VL_MAXNAMELEN);
name[VL_MAXNAMELEN - 1] = '\0';
break;
-#ifdef MULTIHOMED
case 2:
flags = uvldbEntry.flags;
nServers = uvldbEntry.nServers;
rwID = uvldbEntry.volumeId[0];
roID = uvldbEntry.volumeId[1];
bkID = uvldbEntry.volumeId[2];
- for ( i=0, j=0; i<nServers && j<NMAXNSERVERS; i++ ) {
- if ( !(uvldbEntry.serverFlags[i] & VLSERVER_FLAG_UUID) ) {
+ for ( i=0, j=0; code == 0 && i<nServers && j<NMAXNSERVERS; i++ ) {
+ if ( !(uvldbEntry.serverFlags[i] & VLSF_UUID) ) {
serverFlags[j] = uvldbEntry.serverFlags[i];
serverNumber[j] = uvldbEntry.serverNumber[i].time_low;
j++;
ListAddrByAttributes attrs;
afsUUID uuid;
- memset((char *)&attrs, 0, sizeof(attrs));
+ memset(&attrs, 0, sizeof(attrs));
attrs.Mask = VLADDR_UUID;
attrs.uuid = uvldbEntry.serverNumber[i];
- memset((char *)&uuid, 0, sizeof(uuid));
- memset((char *)&addrs, 0, sizeof(addrs));
+ memset(&uuid, 0, sizeof(uuid));
+ memset(&addrs, 0, sizeof(addrs));
do {
- code = cm_ConnByMServers(cellp->vlServersp, userp, reqp, &connp);
- if (code)
+ code = cm_ConnByMServers(cellp->vlServersp, FALSE, userp, reqp, &connp);
+ if (code)
continue;
-
- code = VL_GetAddrsU(connp->callp, &attrs, &uuid, &unique, &nentries, &addrs);
- if (code == 0 && nentries == 0)
- code = VL_NOENT;
- } while (cm_Analyze(connp, userp, reqp, NULL, NULL, cellp->vlServersp, NULL, code));
- code = cm_MapVLRPCError(code, reqp);
- if (code)
- return code;
+ rxconnp = cm_GetRxConn(connp);
+ code = VL_GetAddrsU(rxconnp, &attrs, &uuid, &unique, &nentries, &addrs);
+ rx_PutConnection(rxconnp);
+ } while (cm_Analyze(connp, userp, reqp, NULL, cellp, 0, NULL, cellp->vlServersp, NULL, code));
+
+ if ( code ) {
+ code = cm_MapVLRPCError(code, reqp);
+ osi_Log2(afsd_logp, "CALL VL_GetAddrsU serverNumber %u FAILURE, code 0x%x",
+ i, code);
+ continue;
+ }
+ osi_Log1(afsd_logp, "CALL VL_GetAddrsU serverNumber %u SUCCESS", i);
addrp = addrs.bulkaddrs_val;
for (k = 0; k < nentries && j < NMAXNSERVERS; j++, k++) {
serverFlags[j] = uvldbEntry.serverFlags[i];
serverNumber[j] = addrp[k];
+ serverUUID[j] = uuid;
}
- free(addrs.bulkaddrs_val); /* This is wrong */
+ xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
+
+ if (nentries == 0)
+ code = CM_ERROR_INVAL;
}
}
nServers = j; /* update the server count */
strncpy(name, uvldbEntry.name, VL_MAXNAMELEN);
name[VL_MAXNAMELEN - 1] = '\0';
break;
-#endif
}
/* decode the response */
lock_ObtainWrite(&cm_volumeLock);
- if (cm_VolNameIsID(volp->namep)) {
+ if (!cm_VolNameIsID(volp->namep)) {
size_t len;
len = strlen(name);
} else if (len >= 10 && strcmp(name + len - 9, ".readonly") == 0) {
name[len - 9] = '\0';
}
-
- osi_Log2(afsd_logp, "cm_UpdateVolume name %s -> %s", volp->namep, name);
- if (volp->flags & CM_VOLUMEFLAG_IN_HASH)
+ osi_Log2(afsd_logp, "cm_UpdateVolume name %s -> %s",
+ osi_LogSaveString(afsd_logp,volp->namep), osi_LogSaveString(afsd_logp,name));
+
+ if (volp->qflags & CM_VOLUME_QFLAG_IN_HASH)
cm_RemoveVolumeFromNameHashTable(volp);
strcpy(volp->namep, name);
cm_AddVolumeToNameHashTable(volp);
}
+ if (flags & VLF_DFSFILESET) {
+ _InterlockedOr(&volp->flags, CM_VOLUMEFLAG_DFS_VOLUME);
+ osi_Log1(afsd_logp, "cm_UpdateVolume Volume Group '%s' is a DFS File Set. Correct behavior is not implemented.",
+ osi_LogSaveString(afsd_logp, volp->namep));
+ }
+
if (flags & VLF_RWEXISTS) {
- if (volp->rw.ID != rwID) {
- if (volp->rw.flags & CM_VOLUMEFLAG_IN_HASH)
+ if (volp->vol[RWVOL].ID != rwID) {
+ if (volp->vol[RWVOL].qflags & CM_VOLUME_QFLAG_IN_HASH)
cm_RemoveVolumeFromIDHashTable(volp, RWVOL);
- volp->rw.ID = rwID;
+ volp->vol[RWVOL].ID = rwID;
cm_AddVolumeToIDHashTable(volp, RWVOL);
}
} else {
- if (volp->rw.flags & CM_VOLUMEFLAG_IN_HASH)
+ if (volp->vol[RWVOL].qflags & CM_VOLUME_QFLAG_IN_HASH)
cm_RemoveVolumeFromIDHashTable(volp, RWVOL);
- volp->rw.ID = 0;
+ volp->vol[RWVOL].ID = 0;
}
if (flags & VLF_ROEXISTS) {
- if (volp->ro.ID != roID) {
- if (volp->ro.flags & CM_VOLUMEFLAG_IN_HASH)
+ if (volp->vol[ROVOL].ID != roID) {
+ if (volp->vol[ROVOL].qflags & CM_VOLUME_QFLAG_IN_HASH)
cm_RemoveVolumeFromIDHashTable(volp, ROVOL);
- volp->ro.ID = roID;
+ volp->vol[ROVOL].ID = roID;
cm_AddVolumeToIDHashTable(volp, ROVOL);
}
} else {
- if (volp->ro.flags & CM_VOLUMEFLAG_IN_HASH)
+ if (volp->vol[ROVOL].qflags & CM_VOLUME_QFLAG_IN_HASH)
cm_RemoveVolumeFromIDHashTable(volp, ROVOL);
- volp->ro.ID = 0;
+ volp->vol[ROVOL].ID = 0;
}
if (flags & VLF_BACKEXISTS) {
- if (volp->bk.ID != bkID) {
- if (volp->bk.flags & CM_VOLUMEFLAG_IN_HASH)
+ if (volp->vol[BACKVOL].ID != bkID) {
+ if (volp->vol[BACKVOL].qflags & CM_VOLUME_QFLAG_IN_HASH)
cm_RemoveVolumeFromIDHashTable(volp, BACKVOL);
- volp->bk.ID = bkID;
+ volp->vol[BACKVOL].ID = bkID;
cm_AddVolumeToIDHashTable(volp, BACKVOL);
}
} else {
- if (volp->bk.flags & CM_VOLUMEFLAG_IN_HASH)
+ if (volp->vol[BACKVOL].qflags & CM_VOLUME_QFLAG_IN_HASH)
cm_RemoveVolumeFromIDHashTable(volp, BACKVOL);
- volp->bk.ID = 0;
+ volp->vol[BACKVOL].ID = 0;
}
lock_ReleaseWrite(&cm_volumeLock);
+
+ /* See if the replica sites are mixed versions */
+ for (i=0; i<nServers; i++) {
+ if (serverFlags[i] & VLSF_NEWREPSITE) {
+ isMixed = 1;
+ break;
+ }
+ }
+
for (i=0; i<nServers; i++) {
/* create a server entry */
tflags = serverFlags[i];
- if (tflags & VLSF_DONTUSE)
+ if (tflags & VLSF_DONTUSE)
continue;
+ tsockAddr.sin_port = htons(7000);
tsockAddr.sin_family = AF_INET;
tempAddr = htonl(serverNumber[i]);
tsockAddr.sin_addr.s_addr = tempAddr;
- tsp = cm_FindServer(&tsockAddr, CM_SERVER_FILE);
- if (!tsp)
- tsp = cm_NewServer(&tsockAddr, CM_SERVER_FILE,
- cellp);
+ tsp = cm_FindServer(&tsockAddr, CM_SERVER_FILE, FALSE);
+ if (tsp && (method == 2) && (tsp->flags & CM_SERVERFLAG_UUID)) {
+ /*
+ * Check to see if the uuid of the server we know at this address
+ * matches the uuid of the server we are being told about by the
+ * vlserver. If not, ...?
+ */
+ if (!afs_uuid_equal(&serverUUID[i], &tsp->uuid)) {
+ char uuid1[128], uuid2[128];
+ char hoststr[16];
+
+ afsUUID_to_string(&serverUUID[i], uuid1, sizeof(uuid1));
+ afsUUID_to_string(&tsp->uuid, uuid2, sizeof(uuid2));
+ afs_inet_ntoa_r(serverNumber[i], hoststr);
+
+ osi_Log3(afsd_logp, "cm_UpdateVolumeLocation UUIDs do not match! %s != %s (%s)",
+ osi_LogSaveString(afsd_logp, uuid1),
+ osi_LogSaveString(afsd_logp, uuid2),
+ osi_LogSaveString(afsd_logp, hoststr));
+ }
+ }
+ if (!tsp) {
+ /*
+ * cm_NewServer will probe the file server which in turn will
+ * update the state on the volume group object. Do not probe
+ * in this thread. It will block the thread and can result in
+ * a recursive call to cm_UpdateVolumeLocation().
+ */
+ lock_ReleaseWrite(&volp->rw);
+ tsp = cm_NewServer(&tsockAddr, CM_SERVER_FILE, cellp, &serverUUID[i], CM_FLAG_NOPROBE);
+ lock_ObtainWrite(&volp->rw);
+ }
+ osi_assertx(tsp != NULL, "null cm_server_t");
- /* if this server was created by fs setserverprefs */
- if ( !tsp->cellp )
+ /*
+ * if this server was created by fs setserverprefs
+ * then it won't have either a cell assignment or
+ * a server uuid.
+ */
+ if ( !tsp->cellp )
tsp->cellp = cellp;
+ if ( (method == 2) && !(tsp->flags & CM_SERVERFLAG_UUID) &&
+ !afs_uuid_is_nil(&serverUUID[i])) {
+ tsp->uuid = serverUUID[i];
+ _InterlockedOr(&tsp->flags, CM_SERVERFLAG_UUID);
+ }
- osi_assertx(tsp != NULL, "null cm_server_t");
-
/* and add it to the list(s). */
/*
* Each call to cm_NewServerRef() increments the
*/
if ((tflags & VLSF_RWVOL) && (flags & VLF_RWEXISTS)) {
tsrp = cm_NewServerRef(tsp, rwID);
- cm_InsertServerList(&volp->rw.serversp, tsrp);
-
- lock_ObtainWrite(&cm_serverLock);
- tsrp->refCount--; /* drop allocation reference */
- lock_ReleaseWrite(&cm_serverLock);
-
+ cm_InsertServerList(&volp->vol[RWVOL].serversp, tsrp);
if (!(tsp->flags & CM_SERVERFLAG_DOWN))
rwServers_alldown = 0;
}
- if ((tflags & VLSF_ROVOL) && (flags & VLF_ROEXISTS)) {
+ /*
+ * If there are mixed versions of RO releases on the replica
+ * sites, skip the servers with the out of date versions.
+ */
+ if ((tflags & VLSF_ROVOL) && (flags & VLF_ROEXISTS) &&
+ (!isMixed || (tflags & VLSF_NEWREPSITE))) {
tsrp = cm_NewServerRef(tsp, roID);
- cm_InsertServerList(&volp->ro.serversp, tsrp);
- lock_ObtainWrite(&cm_serverLock);
- tsrp->refCount--; /* drop allocation reference */
- lock_ReleaseWrite(&cm_serverLock);
+ cm_InsertServerList(&volp->vol[ROVOL].serversp, tsrp);
ROcount++;
if (!(tsp->flags & CM_SERVERFLAG_DOWN))
roServers_alldown = 0;
}
/* We don't use VLSF_BACKVOL !?! */
- /* Because only the backup on the server holding the RW
+ /* Because only the backup on the server holding the RW
* volume can be valid. This check prevents errors if a
* RW is moved but the old backup is not removed.
*/
if ((tflags & VLSF_RWVOL) && (flags & VLF_BACKEXISTS)) {
tsrp = cm_NewServerRef(tsp, bkID);
- cm_InsertServerList(&volp->bk.serversp, tsrp);
- lock_ObtainWrite(&cm_serverLock);
- tsrp->refCount--; /* drop allocation reference */
- lock_ReleaseWrite(&cm_serverLock);
+ cm_InsertServerList(&volp->vol[BACKVOL].serversp, tsrp);
if (!(tsp->flags & CM_SERVERFLAG_DOWN))
bkServers_alldown = 0;
}
/* Drop the reference obtained by cm_FindServer() */
cm_PutServer(tsp);
- }
+ }
/*
* Randomize RO list
*
- * If the first n servers have the same ipRank, then we
+ * If the first n servers have the same rank, then we
* randomly pick one among them and move it to the beginning.
* We don't bother to re-order the whole list because
* the rest of the list is used only if the first server is
* lists are length 1.
*/
if (ROcount > 1) {
- cm_RandomizeServer(&volp->ro.serversp);
+ cm_RandomizeServer(&volp->vol[ROVOL].serversp);
+ _InterlockedOr(&volp->vol[ROVOL].flags, CM_VOL_STATE_FLAG_REPLICATED);
+ }
+ else {
+ _InterlockedAnd(&volp->vol[ROVOL].flags, ~CM_VOL_STATE_FLAG_REPLICATED);
}
rwNewstate = rwServers_alldown ? vl_alldown : vl_online;
roNewstate = roServers_alldown ? vl_alldown : vl_online;
bkNewstate = bkServers_alldown ? vl_alldown : vl_online;
+
+ _InterlockedAnd(&volp->flags, ~CM_VOLUMEFLAG_NOEXIST);
+ } else if (code == CM_ERROR_NOSUCHVOLUME || code == VL_NOENT || code == VL_BADNAME) {
+ _InterlockedOr(&volp->flags, CM_VOLUMEFLAG_NOEXIST);
} else {
rwNewstate = roNewstate = bkNewstate = vl_alldown;
+
+ /*
+ * we are updating lastUpdateTime but didn't get an answer
+ * so clear the no exist flag.
+ */
+ _InterlockedAnd(&volp->flags, ~CM_VOLUMEFLAG_NOEXIST);
}
- if (volp->rw.state != rwNewstate) {
- if (volp->rw.ID)
- cm_VolumeStatusNotification(volp, volp->rw.ID, volp->rw.state, rwNewstate);
- volp->rw.state = rwNewstate;
+ if (volp->vol[RWVOL].state != rwNewstate) {
+ if (volp->vol[RWVOL].ID)
+ cm_VolumeStatusNotification(volp, volp->vol[RWVOL].ID, volp->vol[RWVOL].state, rwNewstate);
+ volp->vol[RWVOL].state = rwNewstate;
}
- if (volp->ro.state != roNewstate) {
- if (volp->ro.ID)
- cm_VolumeStatusNotification(volp, volp->ro.ID, volp->ro.state, roNewstate);
- volp->ro.state = roNewstate;
+ if (volp->vol[ROVOL].state != roNewstate) {
+ if (volp->vol[ROVOL].ID)
+ cm_VolumeStatusNotification(volp, volp->vol[ROVOL].ID, volp->vol[ROVOL].state, roNewstate);
+ volp->vol[ROVOL].state = roNewstate;
}
- if (volp->bk.state != bkNewstate) {
- if (volp->bk.ID)
- cm_VolumeStatusNotification(volp, volp->bk.ID, volp->bk.state, bkNewstate);
- volp->bk.state = bkNewstate;
+ if (volp->vol[BACKVOL].state != bkNewstate) {
+ if (volp->vol[BACKVOL].ID)
+ cm_VolumeStatusNotification(volp, volp->vol[BACKVOL].ID, volp->vol[BACKVOL].state, bkNewstate);
+ volp->vol[BACKVOL].state = bkNewstate;
}
+ volp->lastUpdateTime = time(NULL);
+ if (isMixed)
+ _InterlockedOr(&volp->flags, CM_VOLUMEFLAG_RO_MIXED);
+ else
+ _InterlockedAnd(&volp->flags, ~CM_VOLUMEFLAG_RO_MIXED);
+
+ if (code == 0)
+ _InterlockedAnd(&volp->flags, ~CM_VOLUMEFLAG_RESET);
+
+ _InterlockedAnd(&volp->flags, ~CM_VOLUMEFLAG_UPDATING_VL);
+ osi_Log4(afsd_logp, "cm_UpdateVolumeLocation done, waking others name %s:%s flags 0x%x code 0x%x",
+ osi_LogSaveString(afsd_logp,volp->cellp->name),
+ osi_LogSaveString(afsd_logp,volp->namep), volp->flags, code);
+ osi_Wakeup((LONG_PTR) &volp->flags);
+
return code;
}
+/* Requires read or write lock on cm_volumeLock */
void cm_GetVolume(cm_volume_t *volp)
{
- if (volp) {
- lock_ObtainWrite(&cm_volumeLock);
- volp->refCount++;
- lock_ReleaseWrite(&cm_volumeLock);
- }
+ InterlockedIncrement(&volp->refCount);
}
+cm_volume_t *cm_GetVolumeByFID(cm_fid_t *fidp)
+{
+ cm_volume_t *volp;
+ afs_uint32 hash;
+
+ lock_ObtainRead(&cm_volumeLock);
+ hash = CM_VOLUME_ID_HASH(fidp->volume);
+ /* The volumeID can be any one of the three types. So we must
+ * search the hash table for all three types until we find it.
+ * We will search in the order of RO, RW, BK.
+ */
+ for ( volp = cm_data.volumeROIDHashTablep[hash]; volp; volp = volp->vol[ROVOL].nextp) {
+ if ( fidp->cell == volp->cellp->cellID && fidp->volume == volp->vol[ROVOL].ID )
+ break;
+ }
+ if (!volp) {
+ /* try RW volumes */
+ for ( volp = cm_data.volumeRWIDHashTablep[hash]; volp; volp = volp->vol[RWVOL].nextp) {
+ if ( fidp->cell == volp->cellp->cellID && fidp->volume == volp->vol[RWVOL].ID )
+ break;
+ }
+ }
+ if (!volp) {
+ /* try BK volumes */
+ for ( volp = cm_data.volumeBKIDHashTablep[hash]; volp; volp = volp->vol[BACKVOL].nextp) {
+ if ( fidp->cell == volp->cellp->cellID && fidp->volume == volp->vol[BACKVOL].ID )
+ break;
+ }
+ }
-long cm_GetVolumeByID(cm_cell_t *cellp, afs_uint32 volumeID, cm_user_t *userp,
+ /* hold the volume if we found it */
+ if (volp)
+ cm_GetVolume(volp);
+
+ lock_ReleaseRead(&cm_volumeLock);
+ return volp;
+}
+
+long cm_FindVolumeByID(cm_cell_t *cellp, afs_uint32 volumeID, cm_user_t *userp,
cm_req_t *reqp, afs_uint32 flags, cm_volume_t **outVolpp)
{
cm_volume_t *volp;
#ifdef SEARCH_ALL_VOLUMES
for(volp = cm_data.allVolumesp; volp; volp=volp->allNextp) {
if (cellp == volp->cellp &&
- ((unsigned) volumeID == volp->rw.ID ||
- (unsigned) volumeID == volp->ro.ID ||
- (unsigned) volumeID == volp->bk.ID))
+ ((unsigned) volumeID == volp->vol[RWVOL].ID ||
+ (unsigned) volumeID == volp->vol[ROVOL].ID ||
+ (unsigned) volumeID == volp->vol[BACKVOL].ID))
break;
- }
+ }
volp2 = volp;
#endif /* SEARCH_ALL_VOLUMES */
* search the hash table for all three types until we find it.
* We will search in the order of RO, RW, BK.
*/
- for ( volp = cm_data.volumeROIDHashTablep[hash]; volp; volp = volp->ro.nextp) {
- if ( cellp == volp->cellp && volumeID == volp->ro.ID )
+ for ( volp = cm_data.volumeROIDHashTablep[hash]; volp; volp = volp->vol[ROVOL].nextp) {
+ if ( cellp == volp->cellp && volumeID == volp->vol[ROVOL].ID )
break;
}
if (!volp) {
/* try RW volumes */
- for ( volp = cm_data.volumeRWIDHashTablep[hash]; volp; volp = volp->rw.nextp) {
- if ( cellp == volp->cellp && volumeID == volp->rw.ID )
+ for ( volp = cm_data.volumeRWIDHashTablep[hash]; volp; volp = volp->vol[RWVOL].nextp) {
+ if ( cellp == volp->cellp && volumeID == volp->vol[RWVOL].ID )
break;
}
}
if (!volp) {
/* try BK volumes */
- for ( volp = cm_data.volumeBKIDHashTablep[hash]; volp; volp = volp->bk.nextp) {
- if ( cellp == volp->cellp && volumeID == volp->bk.ID )
+ for ( volp = cm_data.volumeBKIDHashTablep[hash]; volp; volp = volp->vol[BACKVOL].nextp) {
+ if ( cellp == volp->cellp && volumeID == volp->vol[BACKVOL].ID )
break;
}
}
osi_assertx(volp == volp2, "unexpected cm_vol_t");
#endif
- lock_ReleaseRead(&cm_volumeLock);
-
/* hold the volume if we found it */
- if (volp)
+ if (volp)
cm_GetVolume(volp);
-
+
+ lock_ReleaseRead(&cm_volumeLock);
+
/* return it held */
if (volp) {
- lock_ObtainMutex(&volp->mx);
-
- code = 0;
- if (volp->flags & CM_VOLUMEFLAG_RESET) {
- code = cm_UpdateVolume(cellp, userp, reqp, volp);
- if (code == 0)
- volp->flags &= ~CM_VOLUMEFLAG_RESET;
- }
- lock_ReleaseMutex(&volp->mx);
- if (code == 0) {
- *outVolpp = volp;
+ lock_ObtainWrite(&volp->rw);
- lock_ObtainWrite(&cm_volumeLock);
- cm_AdjustVolumeLRU(volp);
- lock_ReleaseWrite(&cm_volumeLock);
- } else
- cm_PutVolume(volp);
-
- return code;
+ code = 0;
+ if ((volp->flags & CM_VOLUMEFLAG_RESET) && !(flags & CM_GETVOL_FLAG_NO_RESET)) {
+ code = cm_UpdateVolumeLocation(cellp, userp, reqp, volp);
+ }
+ lock_ReleaseWrite(&volp->rw);
+ if (code == 0) {
+ *outVolpp = volp;
+
+ if (!(flags & CM_GETVOL_FLAG_NO_LRU_UPDATE)) {
+ lock_ObtainWrite(&cm_volumeLock);
+ cm_AdjustVolumeLRU(volp);
+ lock_ReleaseWrite(&cm_volumeLock);
+ }
+ } else {
+ lock_ObtainRead(&cm_volumeLock);
+ cm_PutVolume(volp);
+ lock_ReleaseRead(&cm_volumeLock);
+ }
+ return code;
}
-
+
/* otherwise, we didn't find it so consult the VLDB */
sprintf(volNameString, "%u", volumeID);
- code = cm_GetVolumeByName(cellp, volNameString, userp, reqp,
- flags, outVolpp);
+ code = cm_FindVolumeByName(cellp, volNameString, userp, reqp,
+ flags | CM_GETVOL_FLAG_IGNORE_LINKED_CELL, outVolpp);
+
+ if (code == CM_ERROR_NOSUCHVOLUME && cellp->linkedName[0] &&
+ !(flags & CM_GETVOL_FLAG_IGNORE_LINKED_CELL)) {
+ cm_cell_t *linkedCellp = cm_GetCell(cellp->linkedName, flags);
+
+ if (linkedCellp)
+ code = cm_FindVolumeByID(linkedCellp, volumeID, userp, reqp,
+ flags | CM_GETVOL_FLAG_IGNORE_LINKED_CELL,
+ outVolpp);
+ }
return code;
}
-long cm_GetVolumeByName(struct cm_cell *cellp, char *volumeNamep,
+long cm_FindVolumeByName(struct cm_cell *cellp, char *volumeNamep,
struct cm_user *userp, struct cm_req *reqp,
afs_uint32 flags, cm_volume_t **outVolpp)
{
if (cellp == volp->cellp && strcmp(name, volp->namep) == 0) {
break;
}
- }
+ }
volp2 = volp;
#endif /* SEARCH_ALL_VOLUMES */
#endif
if (!volp && (flags & CM_GETVOL_FLAG_CREATE)) {
+ afs_uint32 volType;
/* otherwise, get from VLDB */
- if ( cm_data.currentVolumes >= cm_data.maxVolumes ) {
+ /*
+ * Change to a write lock so that we have exclusive use of
+ * the first cm_volume_t with a refCount of 0 so that we
+ * have time to increment it.
+ */
+ lock_ConvertRToW(&cm_volumeLock);
+ if ( cm_data.currentVolumes >= cm_data.maxVolumes ) {
#ifdef RECYCLE_FROM_ALL_VOLUMES_LIST
for (volp = cm_data.allVolumesp; volp; volp=volp->allNextp) {
if ( volp->refCount == 0 ) {
#else
for ( volp = cm_data.volumeLRULastp;
volp;
- volp = (cm_volume_t *) osi_QPrev(&volp->q))
+ volp = (cm_volume_t *) osi_QPrev(&volp->q))
{
if ( volp->refCount == 0 ) {
/* There is one we can re-use */
if (!volp)
osi_panic("Exceeded Max Volumes", __FILE__, __LINE__);
- lock_ReleaseRead(&cm_volumeLock);
- lock_ObtainMutex(&volp->mx);
+ InterlockedIncrement(&volp->refCount);
+ lock_ReleaseWrite(&cm_volumeLock);
+ lock_ObtainWrite(&volp->rw);
lock_ObtainWrite(&cm_volumeLock);
osi_Log2(afsd_logp, "Recycling Volume %s:%s",
volp->cellp->name, volp->namep);
- if (volp->flags & CM_VOLUMEFLAG_IN_LRU_QUEUE)
+ /* The volp is removed from the LRU queue in order to
+ * prevent two threads from attempting to recycle the
+ * same object. This volp must be re-inserted back into
+ * the LRU queue before this function exits.
+ */
+ if (volp->qflags & CM_VOLUME_QFLAG_IN_LRU_QUEUE)
cm_RemoveVolumeFromLRU(volp);
- if (volp->flags & CM_VOLUMEFLAG_IN_HASH)
+ if (volp->qflags & CM_VOLUME_QFLAG_IN_HASH)
cm_RemoveVolumeFromNameHashTable(volp);
- if (volp->rw.flags & CM_VOLUMEFLAG_IN_HASH)
- cm_RemoveVolumeFromIDHashTable(volp, RWVOL);
- if (volp->ro.flags & CM_VOLUMEFLAG_IN_HASH)
- cm_RemoveVolumeFromIDHashTable(volp, ROVOL);
- if (volp->bk.flags & CM_VOLUMEFLAG_IN_HASH)
- cm_RemoveVolumeFromIDHashTable(volp, BACKVOL);
- if (volp->rw.ID)
- cm_VolumeStatusNotification(volp, volp->rw.ID, volp->rw.state, vl_unknown);
- if (volp->ro.ID)
- cm_VolumeStatusNotification(volp, volp->ro.ID, volp->ro.state, vl_unknown);
- if (volp->bk.ID)
- cm_VolumeStatusNotification(volp, volp->bk.ID, volp->bk.state, vl_unknown);
-
- volp->rw.ID = volp->ro.ID = volp->bk.ID = 0;
- volp->dotdotFid.cell = 0;
- volp->dotdotFid.volume = 0;
- volp->dotdotFid.unique = 0;
- volp->dotdotFid.vnode = 0;
+ for ( volType = RWVOL; volType < NUM_VOL_TYPES; volType++) {
+ if (volp->vol[volType].qflags & CM_VOLUME_QFLAG_IN_HASH)
+ cm_RemoveVolumeFromIDHashTable(volp, volType);
+ if (volp->vol[volType].ID)
+ cm_VolumeStatusNotification(volp, volp->vol[volType].ID, volp->vol[volType].state, vl_unknown);
+ volp->vol[volType].ID = 0;
+ cm_SetFid(&volp->vol[volType].dotdotFid, 0, 0, 0, 0);
+ lock_ReleaseWrite(&cm_volumeLock);
+ cm_FreeServerList(&volp->vol[volType].serversp, CM_FREESERVERLIST_DELETE);
+ lock_ObtainWrite(&cm_volumeLock);
+ }
} else {
volp = &cm_data.volumeBaseAddress[cm_data.currentVolumes++];
memset(volp, 0, sizeof(cm_volume_t));
volp->magic = CM_VOLUME_MAGIC;
volp->allNextp = cm_data.allVolumesp;
cm_data.allVolumesp = volp;
- lock_InitializeMutex(&volp->mx, "cm_volume_t mutex");
- lock_ReleaseRead(&cm_volumeLock);
- lock_ObtainMutex(&volp->mx);
+ lock_InitializeRWLock(&volp->rw, "cm_volume_t rwlock", LOCK_HIERARCHY_VOLUME);
+ lock_ReleaseWrite(&cm_volumeLock);
+ lock_ObtainWrite(&volp->rw);
lock_ObtainWrite(&cm_volumeLock);
+ volp->refCount = 1; /* starts off held */
}
volp->cellp = cellp;
strncpy(volp->namep, name, VL_MAXNAMELEN);
volp->namep[VL_MAXNAMELEN-1] = '\0';
- volp->refCount = 1; /* starts off held */
volp->flags = CM_VOLUMEFLAG_RESET;
- volp->rw.state = volp->ro.state = volp->bk.state = vl_unknown;
- volp->rw.nextp = volp->ro.nextp = volp->bk.nextp = NULL;
- volp->rw.flags = volp->ro.flags = volp->bk.flags = 0;
+ volp->lastUpdateTime = 0;
+
+ for ( volType = RWVOL; volType < NUM_VOL_TYPES; volType++) {
+ volp->vol[volType].state = vl_unknown;
+ volp->vol[volType].nextp = NULL;
+ volp->vol[volType].flags = 0;
+ }
volp->cbExpiresRO = 0;
+ volp->cbIssuedRO = 0;
+ volp->cbServerpRO = NULL;
+ volp->creationDateRO = 0;
cm_AddVolumeToNameHashTable(volp);
lock_ReleaseWrite(&cm_volumeLock);
}
else {
- lock_ReleaseRead(&cm_volumeLock);
- if (volp) {
+ if (volp)
cm_GetVolume(volp);
- lock_ObtainMutex(&volp->mx);
- } else {
+ lock_ReleaseRead(&cm_volumeLock);
+
+ if (!volp)
return CM_ERROR_NOSUCHVOLUME;
- }
+
+ lock_ObtainWrite(&volp->rw);
}
/* if we get here we are holding the mutex */
- if (volp->flags & CM_VOLUMEFLAG_RESET) {
- code = cm_UpdateVolume(cellp, userp, reqp, volp);
- if (code == 0)
- volp->flags &= ~CM_VOLUMEFLAG_RESET;
- }
- lock_ReleaseMutex(&volp->mx);
-
- if (code == 0 && (type == BACKVOL && volp->bk.ID == 0 ||
- type == ROVOL && volp->ro.ID == 0))
+ if ((volp->flags & CM_VOLUMEFLAG_RESET) && !(flags & CM_GETVOL_FLAG_NO_RESET)) {
+ code = cm_UpdateVolumeLocation(cellp, userp, reqp, volp);
+ }
+ lock_ReleaseWrite(&volp->rw);
+
+ if (code == 0 && (type == BACKVOL && volp->vol[BACKVOL].ID == 0 ||
+ type == ROVOL && volp->vol[ROVOL].ID == 0))
code = CM_ERROR_NOSUCHVOLUME;
if (code == 0) {
- *outVolpp = volp;
+ *outVolpp = volp;
lock_ObtainWrite(&cm_volumeLock);
- cm_AdjustVolumeLRU(volp);
+ if (!(volp->qflags & CM_VOLUME_QFLAG_IN_LRU_QUEUE) ||
+ (flags & CM_GETVOL_FLAG_NO_LRU_UPDATE))
+ cm_AdjustVolumeLRU(volp);
lock_ReleaseWrite(&cm_volumeLock);
- } else
- cm_PutVolume(volp);
+ } else {
+ /*
+ * do not return it to the caller but do insert it in the LRU
+ * otherwise it will be lost
+ */
+ lock_ObtainWrite(&cm_volumeLock);
+ if (!(volp->qflags & CM_VOLUME_QFLAG_IN_LRU_QUEUE) ||
+ (flags & CM_GETVOL_FLAG_NO_LRU_UPDATE))
+ cm_AdjustVolumeLRU(volp);
+ cm_PutVolume(volp);
+ lock_ReleaseWrite(&cm_volumeLock);
+ }
+
+ if (code == CM_ERROR_NOSUCHVOLUME && cellp->linkedName[0] &&
+ !(flags & CM_GETVOL_FLAG_IGNORE_LINKED_CELL)) {
+ cm_cell_t *linkedCellp = cm_GetCell(cellp->linkedName, flags);
+ if (linkedCellp)
+ code = cm_FindVolumeByName(linkedCellp, volumeNamep, userp, reqp,
+ flags | CM_GETVOL_FLAG_IGNORE_LINKED_CELL,
+ outVolpp);
+ }
return code;
-}
+}
-void cm_ForceUpdateVolume(cm_fid_t *fidp, cm_user_t *userp, cm_req_t *reqp)
+/*
+ * Only call this function in response to a VNOVOL or VMOVED error
+ * from a file server. Do not call it in response to CM_ERROR_NOSUCHVOLUME
+ * as that can lead to recursive calls.
+ */
+long cm_ForceUpdateVolume(cm_fid_t *fidp, cm_user_t *userp, cm_req_t *reqp)
{
cm_cell_t *cellp;
cm_volume_t *volp;
cm_volume_t *volp2;
#endif
afs_uint32 hash;
+ long code;
- if (!fidp) return;
+ if (!fidp)
+ return CM_ERROR_INVAL;
- cellp = cm_FindCellByID(fidp->cell);
- if (!cellp) return;
+ cellp = cm_FindCellByID(fidp->cell, 0);
+ if (!cellp)
+ return CM_ERROR_NOSUCHCELL;
/* search for the volume */
lock_ObtainRead(&cm_volumeLock);
#ifdef SEARCH_ALL_VOLUMES
for(volp = cm_data.allVolumesp; volp; volp=volp->allNextp) {
if (cellp == volp->cellp &&
- (fidp->volume == volp->rw.ID ||
- fidp->volume == volp->ro.ID ||
- fidp->volume == volp->bk.ID))
+ (fidp->volume == volp->vol[RWVOL].ID ||
+ fidp->volume == volp->vol[ROVOL].ID ||
+ fidp->volume == volp->vol[BACKVOL].ID))
break;
- }
+ }
#endif /* SEARCH_ALL_VOLUMES */
hash = CM_VOLUME_ID_HASH(fidp->volume);
* search the hash table for all three types until we find it.
* We will search in the order of RO, RW, BK.
*/
- for ( volp = cm_data.volumeROIDHashTablep[hash]; volp; volp = volp->ro.nextp) {
- if ( cellp == volp->cellp && fidp->volume == volp->ro.ID )
+ for ( volp = cm_data.volumeROIDHashTablep[hash]; volp; volp = volp->vol[ROVOL].nextp) {
+ if ( cellp == volp->cellp && fidp->volume == volp->vol[ROVOL].ID )
break;
}
if (!volp) {
/* try RW volumes */
- for ( volp = cm_data.volumeRWIDHashTablep[hash]; volp; volp = volp->rw.nextp) {
- if ( cellp == volp->cellp && fidp->volume == volp->rw.ID )
+ for ( volp = cm_data.volumeRWIDHashTablep[hash]; volp; volp = volp->vol[RWVOL].nextp) {
+ if ( cellp == volp->cellp && fidp->volume == volp->vol[RWVOL].ID )
break;
}
}
if (!volp) {
/* try BK volumes */
- for ( volp = cm_data.volumeBKIDHashTablep[hash]; volp; volp = volp->bk.nextp) {
- if ( cellp == volp->cellp && fidp->volume == volp->bk.ID )
+ for ( volp = cm_data.volumeBKIDHashTablep[hash]; volp; volp = volp->vol[BACKVOL].nextp) {
+ if ( cellp == volp->cellp && fidp->volume == volp->vol[BACKVOL].ID )
break;
}
}
#ifdef SEARCH_ALL_VOLUMES
osi_assertx(volp == volp2, "unexpected cm_vol_t");
#endif
+ /* hold the volume if we found it */
+ if (volp)
+ cm_GetVolume(volp);
lock_ReleaseRead(&cm_volumeLock);
- /* hold the volume if we found it */
- if (volp)
- cm_GetVolume(volp);
+ if (!volp)
+ return CM_ERROR_NOSUCHVOLUME;
/* update it */
cm_data.mountRootGen = time(NULL);
- lock_ObtainMutex(&volp->mx);
- volp->flags |= CM_VOLUMEFLAG_RESET;
-#ifdef COMMENT
- /* Mark the volume to be updated but don't update it now.
- * This function is called only from within cm_Analyze
- * when cm_ConnByMServers has failed with all servers down
- * The problem is that cm_UpdateVolume is going to call
- * cm_ConnByMServers which may cause a recursive chain
- * of calls each returning a retry on failure.
- * Instead, set the flag so the next time the volume is
- * accessed by Name or ID the UpdateVolume call will
- * occur.
- */
- code = cm_UpdateVolume(cellp, userp, reqp, volp);
- if (code == 0)
- volp->flags &= ~CM_VOLUMEFLAG_RESET;
-#endif
- lock_ReleaseMutex(&volp->mx);
+ lock_ObtainWrite(&volp->rw);
+ _InterlockedOr(&volp->flags, CM_VOLUMEFLAG_RESET);
+ volp->lastUpdateTime = 0;
+
+ code = cm_UpdateVolumeLocation(cellp, userp, reqp, volp);
+ lock_ReleaseWrite(&volp->rw);
+ lock_ObtainRead(&cm_volumeLock);
cm_PutVolume(volp);
+ lock_ReleaseRead(&cm_volumeLock);
+
+ return code;
}
/* find the appropriate servers from a volume */
-cm_serverRef_t **cm_GetVolServers(cm_volume_t *volp, afs_uint32 volume)
+cm_serverRef_t **cm_GetVolServers(cm_volume_t *volp, afs_uint32 volid, cm_user_t *userp, cm_req_t *reqp, afs_uint32 *replicated)
{
cm_serverRef_t **serverspp;
- cm_serverRef_t *current;;
+ cm_serverRef_t *current;
+ int firstTry = 1;
+ cm_vol_state_t *volstatep = NULL;
+
+ start:
+ volstatep = cm_VolumeStateByID(volp, volid);
lock_ObtainWrite(&cm_serverLock);
+ if (volstatep) {
+ if (replicated)
+ *replicated = (volstatep->flags & CM_VOL_STATE_FLAG_REPLICATED);
+ serverspp = &volstatep->serversp;
+ } else {
+ lock_ReleaseWrite(&cm_serverLock);
+ if (firstTry) {
+ afs_int32 code;
+ firstTry = 0;
+ lock_ObtainWrite(&volp->rw);
+ _InterlockedOr(&volp->flags, CM_VOLUMEFLAG_RESET);
+ volp->lastUpdateTime = 0;
+ code = cm_UpdateVolumeLocation(volp->cellp, userp, reqp, volp);
+ lock_ReleaseWrite(&volp->rw);
+ if (code == 0)
+ goto start;
+ }
+ return NULL;
+ }
- if (volume == volp->rw.ID)
- serverspp = &volp->rw.serversp;
- else if (volume == volp->ro.ID)
- serverspp = &volp->ro.serversp;
- else if (volume == volp->bk.ID)
- serverspp = &volp->bk.serversp;
- else
- osi_panic("bad volume ID in cm_GetVolServers", __FILE__, __LINE__);
-
+ /*
+ * Increment the refCount on deleted items as well.
+ * They will be freed by cm_FreeServerList when they get to zero
+ */
for (current = *serverspp; current; current = current->next)
- current->refCount++;
+ cm_GetServerRef(current, TRUE);
lock_ReleaseWrite(&cm_serverLock);
void cm_PutVolume(cm_volume_t *volp)
{
- lock_ObtainWrite(&cm_volumeLock);
- osi_assertx(volp->refCount-- > 0, "cm_volume_t refCount 0");
- lock_ReleaseWrite(&cm_volumeLock);
+ afs_int32 refCount = InterlockedDecrement(&volp->refCount);
+ osi_assertx(refCount >= 0, "cm_volume_t refCount underflow has occurred");
}
/* return the read-only volume, if there is one, or the read-write volume if
{
long id;
- lock_ObtainMutex(&volp->mx);
- if (volp->ro.ID && volp->ro.serversp)
- id = volp->ro.ID;
+ lock_ObtainRead(&volp->rw);
+ if (volp->vol[ROVOL].ID && !cm_IsServerListEmpty(volp->vol[ROVOL].serversp))
+ id = volp->vol[ROVOL].ID;
else
- id = volp->rw.ID;
- lock_ReleaseMutex(&volp->mx);
+ id = volp->vol[RWVOL].ID;
+ lock_ReleaseRead(&volp->rw);
return id;
}
-void cm_RefreshVolumes(void)
+void cm_RefreshVolumes(int lifetime)
{
cm_volume_t *volp;
- cm_scache_t *scp;
-
- cm_data.mountRootGen = time(NULL);
+ afs_int32 refCount;
+ time_t now;
- /* force a re-loading of volume data from the vldb */
- lock_ObtainWrite(&cm_volumeLock);
- for (volp = cm_data.allVolumesp; volp; volp=volp->allNextp) {
- volp->refCount++;
- lock_ReleaseWrite(&cm_volumeLock);
+ now = time(NULL);
- lock_ObtainMutex(&volp->mx);
- volp->flags |= CM_VOLUMEFLAG_RESET;
- lock_ReleaseMutex(&volp->mx);
-
- lock_ObtainWrite(&cm_volumeLock);
- osi_assertx(volp->refCount-- > 0, "cm_volume_t refCount 0");
- }
- lock_ReleaseWrite(&cm_volumeLock);
+ /* force mount point target updates */
+ if (cm_data.mountRootGen + lifetime <= now)
+ cm_data.mountRootGen = now;
- /* force mount points to be re-evaluated so that
- * if the volume location has changed we will pick
- * that up
+ /*
+ * force a re-loading of volume data from the vldb
+ * if the lifetime for the cached data has expired
*/
- for ( scp = cm_data.scacheLRUFirstp;
- scp;
- scp = (cm_scache_t *) osi_QNext(&scp->q)) {
- if ( scp->fileType == CM_SCACHETYPE_MOUNTPOINT
-#ifdef AFS_FREELANCE_CLIENT
- && !(scp->fid.cell == AFS_FAKE_ROOT_CELL_ID && scp->fid.volume == AFS_FAKE_ROOT_VOL_ID)
-#endif
- ) {
- lock_ObtainMutex(&scp->mx);
- scp->mountPointStringp[0] = '\0';
- lock_ReleaseMutex(&scp->mx);
+ lock_ObtainRead(&cm_volumeLock);
+ for (volp = cm_data.allVolumesp; volp; volp=volp->allNextp) {
+ InterlockedIncrement(&volp->refCount);
+ lock_ReleaseRead(&cm_volumeLock);
+
+ if (!(volp->flags & CM_VOLUMEFLAG_RESET) ||
+ (volp->flags & CM_VOLUMEFLAG_NOEXIST)) {
+ lock_ObtainWrite(&volp->rw);
+ if (volp->flags & CM_VOLUMEFLAG_NOEXIST) {
+ _InterlockedAnd(&volp->flags, ~CM_VOLUMEFLAG_NOEXIST);
+ }
+
+ if (volp->flags & CM_VOLUMEFLAG_RO_MIXED) {
+ if (volp->lastUpdateTime + 300 <= now) {
+ _InterlockedOr(&volp->flags, CM_VOLUMEFLAG_RESET);
+ volp->lastUpdateTime = 0;
+ }
+ } else {
+ if (volp->lastUpdateTime + lifetime <= now) {
+ _InterlockedOr(&volp->flags, CM_VOLUMEFLAG_RESET);
+ volp->lastUpdateTime = 0;
+ }
+ }
+ lock_ReleaseWrite(&volp->rw);
}
- }
+ lock_ObtainRead(&cm_volumeLock);
+ refCount = InterlockedDecrement(&volp->refCount);
+ osi_assertx(refCount >= 0, "cm_volume_t refCount underflow");
+ }
+ lock_ReleaseRead(&cm_volumeLock);
}
-
-/* The return code is 0 if the volume is not online and
- * 1 if the volume is online
- */
-long
-cm_CheckOfflineVolume(cm_volume_t *volp, afs_uint32 volID)
+void
+cm_CheckOfflineVolumeState(cm_volume_t *volp, cm_vol_state_t *statep, afs_uint32 volID,
+ afs_uint32 *onlinep, afs_uint32 *volumeUpdatedp)
{
cm_conn_t *connp;
long code;
char *OfflineMsg;
char *MOTD;
cm_req_t req;
- struct rx_connection * callp;
+ struct rx_connection * rxconnp;
char volName[32];
char offLineMsg[256];
char motd[256];
- long online = 0;
+ long alldown, alldeleted;
cm_serverRef_t *serversp;
+ cm_fid_t vfid;
+ cm_scache_t *vscp = NULL;
Name = volName;
OfflineMsg = offLineMsg;
MOTD = motd;
- lock_ObtainMutex(&volp->mx);
+ if (statep->ID != 0 && (!volID || volID == statep->ID)) {
+ /* create fid for volume root so that VNOVOL and VMOVED errors can be processed */
+ cm_SetFid(&vfid, volp->cellp->cellID, statep->ID, 1, 1);
- if (volp->rw.ID != 0 && (!volID || volID == volp->rw.ID) &&
- (volp->rw.state == vl_busy || volp->rw.state == vl_offline)) {
- cm_InitReq(&req);
-
- for (serversp = volp->rw.serversp; serversp; serversp = serversp->next) {
- if (serversp->status == srv_busy || serversp->status == srv_offline)
- serversp->status = srv_not_busy;
+ if (!statep->serversp && !(*volumeUpdatedp)) {
+ cm_InitReq(&req);
+ code = cm_UpdateVolumeLocation(volp->cellp, cm_rootUserp, &req, volp);
+ *volumeUpdatedp = 1;
}
- do {
- code = cm_ConnFromVolume(volp, volp->rw.ID, cm_rootUserp, &req, &connp);
- if (code)
- continue;
+ lock_ObtainRead(&cm_serverLock);
+ if (statep->serversp) {
+ alldown = 1;
+ alldeleted = 1;
+ for (serversp = statep->serversp; serversp; serversp = serversp->next) {
+ if (serversp->status == srv_deleted)
+ continue;
- callp = cm_GetRxConn(connp);
- code = RXAFS_GetVolumeStatus(callp, volp->rw.ID,
- &volStat, &Name, &OfflineMsg, &MOTD);
- rx_PutConnection(callp);
-
- } while (cm_Analyze(connp, cm_rootUserp, &req, NULL, NULL, NULL, NULL, code));
- code = cm_MapRPCError(code, &req);
-
- if (code == 0 && volStat.Online) {
- cm_VolumeStatusNotification(volp, volp->rw.ID, volp->rw.state, vl_online);
- volp->rw.state = vl_online;
- online = 1;
- } else if (code == CM_ERROR_NOACCESS) {
- cm_VolumeStatusNotification(volp, volp->rw.ID, volp->rw.state, vl_unknown);
- volp->rw.state = vl_unknown;
- online = 1;
- }
- }
+ alldeleted = 0;
- if (volp->ro.ID != 0 && (!volID || volID == volp->ro.ID) &&
- (volp->ro.state == vl_busy || volp->ro.state == vl_offline)) {
- cm_InitReq(&req);
+ if (!(serversp->server->flags & CM_SERVERFLAG_DOWN))
+ alldown = 0;
- for (serversp = volp->ro.serversp; serversp; serversp = serversp->next) {
- if (serversp->status == srv_busy || serversp->status == srv_offline)
- serversp->status = srv_not_busy;
- }
+ if (serversp->status == srv_busy || serversp->status == srv_offline)
+ serversp->status = srv_not_busy;
+ }
+ lock_ReleaseRead(&cm_serverLock);
- do {
- code = cm_ConnFromVolume(volp, volp->ro.ID, cm_rootUserp, &req, &connp);
- if (code)
- continue;
+ if (alldeleted && !(*volumeUpdatedp)) {
+ cm_InitReq(&req);
+ code = cm_UpdateVolumeLocation(volp->cellp, cm_rootUserp, &req, volp);
+ *volumeUpdatedp = 1;
+ }
- callp = cm_GetRxConn(connp);
- code = RXAFS_GetVolumeStatus(callp, volp->ro.ID,
- &volStat, &Name, &OfflineMsg, &MOTD);
- rx_PutConnection(callp);
-
- } while (cm_Analyze(connp, cm_rootUserp, &req, NULL, NULL, NULL, NULL, code));
- code = cm_MapRPCError(code, &req);
-
- if (code == 0 && volStat.Online) {
- cm_VolumeStatusNotification(volp, volp->ro.ID, volp->ro.state, vl_online);
- volp->ro.state = vl_online;
- online = 1;
- } else if (code == CM_ERROR_NOACCESS) {
- cm_VolumeStatusNotification(volp, volp->ro.ID, volp->ro.state, vl_unknown);
- volp->ro.state = vl_unknown;
- online = 1;
+ if (statep->state == vl_busy || statep->state == vl_offline || statep->state == vl_unknown ||
+ (!alldown && statep->state == vl_alldown)) {
+ cm_InitReq(&req);
+ req.flags |= CM_REQ_OFFLINE_VOL_CHK;
+ lock_ReleaseWrite(&volp->rw);
+
+ code = cm_GetSCache(&vfid, NULL, &vscp, cm_rootUserp, &req);
+ if (code = 0) {
+ lock_ObtainWrite(&vscp->rw);
+ code = cm_SyncOp(vscp, NULL, cm_rootUserp, &req, PRSFS_READ,
+ CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
+ lock_ReleaseWrite(&vscp->rw);
+ if (code == 0) {
+ do {
+ code = cm_ConnFromVolume(volp, statep->ID, cm_rootUserp, &req, &connp);
+ if (code)
+ continue;
+
+ rxconnp = cm_GetRxConn(connp);
+ code = RXAFS_GetVolumeStatus(rxconnp, statep->ID,
+ &volStat, &Name, &OfflineMsg, &MOTD);
+ rx_PutConnection(rxconnp);
+ } while (cm_Analyze(connp, cm_rootUserp, &req, &vfid, NULL, 0, NULL, NULL, NULL, code));
+ code = cm_MapRPCError(code, &req);
+ }
+
+ lock_ObtainWrite(&vscp->rw);
+ cm_SyncOpDone(vscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
+ lock_ReleaseWrite(&vscp->rw);
+ cm_ReleaseSCache(vscp);
+ }
+ lock_ObtainWrite(&volp->rw);
+ if (code == 0 && volStat.Online) {
+ cm_VolumeStatusNotification(volp, statep->ID, statep->state, vl_online);
+ statep->state = vl_online;
+ *onlinep = 1;
+ } else if (code == CM_ERROR_NOACCESS) {
+ cm_VolumeStatusNotification(volp, statep->ID, statep->state, vl_unknown);
+ statep->state = vl_unknown;
+ *onlinep = 1;
+ }
+ } else if (alldown && statep->state != vl_alldown) {
+ cm_VolumeStatusNotification(volp, statep->ID, statep->state, vl_alldown);
+ statep->state = vl_alldown;
+ }
+ } else {
+ lock_ReleaseRead(&cm_serverLock);
+ if (statep->state != vl_alldown) {
+ cm_VolumeStatusNotification(volp, statep->ID, statep->state, vl_alldown);
+ statep->state = vl_alldown;
+ }
}
}
+}
- if (volp->bk.ID != 0 && (!volID || volID == volp->bk.ID) &&
- (volp->bk.state == vl_busy || volp->bk.state == vl_offline)) {
- cm_InitReq(&req);
-
- for (serversp = volp->bk.serversp; serversp; serversp = serversp->next) {
- if (serversp->status == srv_busy || serversp->status == srv_offline)
- serversp->status = srv_not_busy;
- }
+/* The return code is 0 if the volume is not online and
+ * 1 if the volume is online
+ */
+long
+cm_CheckOfflineVolume(cm_volume_t *volp, afs_uint32 volID)
+{
+ long code;
+ cm_req_t req;
+ afs_uint32 online = 0;
+ afs_uint32 volumeUpdated = 0;
- do {
- code = cm_ConnFromVolume(volp, volp->bk.ID, cm_rootUserp, &req, &connp);
- if (code)
- continue;
+ lock_ObtainWrite(&volp->rw);
- callp = cm_GetRxConn(connp);
- code = RXAFS_GetVolumeStatus(callp, volp->bk.ID,
- &volStat, &Name, &OfflineMsg, &MOTD);
- rx_PutConnection(callp);
-
- } while (cm_Analyze(connp, cm_rootUserp, &req, NULL, NULL, NULL, NULL, code));
- code = cm_MapRPCError(code, &req);
-
- if (code == 0 && volStat.Online) {
- cm_VolumeStatusNotification(volp, volp->bk.ID, volp->bk.state, vl_online);
- volp->bk.state = vl_online;
- online = 1;
- } else if (code == CM_ERROR_NOACCESS) {
- cm_VolumeStatusNotification(volp, volp->bk.ID, volp->bk.state, vl_unknown);
- volp->bk.state = vl_unknown;
- online = 1;
- }
+ if (volp->flags & CM_VOLUMEFLAG_RESET) {
+ cm_InitReq(&req);
+ code = cm_UpdateVolumeLocation(volp->cellp, cm_rootUserp, &req, volp);
+ volumeUpdated = 1;
}
- lock_ReleaseMutex(&volp->mx);
+ cm_CheckOfflineVolumeState(volp, &volp->vol[RWVOL], volID, &online, &volumeUpdated);
+ cm_CheckOfflineVolumeState(volp, &volp->vol[ROVOL], volID, &online, &volumeUpdated);
+ cm_CheckOfflineVolumeState(volp, &volp->vol[BACKVOL], volID, &online, &volumeUpdated);
+
+ lock_ReleaseWrite(&volp->rw);
return online;
}
-/* called from the Daemon thread */
+/*
+ * called from the Daemon thread.
+ * when checking the offline status, check those of the most recently used volumes first.
+ */
void cm_CheckOfflineVolumes(void)
{
cm_volume_t *volp;
+ afs_int32 refCount;
+ extern int daemon_ShutdownFlag;
+ extern int powerStateSuspended;
- lock_ObtainWrite(&cm_volumeLock);
- for (volp = cm_data.allVolumesp; volp; volp=volp->allNextp) {
- volp->refCount++;
- lock_ReleaseWrite(&cm_volumeLock);
-
- cm_CheckOfflineVolume(volp, 0);
-
- lock_ObtainWrite(&cm_volumeLock);
- osi_assertx(volp->refCount-- > 0, "cm_volume_t refCount 0");
+ lock_ObtainRead(&cm_volumeLock);
+ for (volp = cm_data.volumeLRULastp;
+ volp && !daemon_ShutdownFlag && !powerStateSuspended;
+ volp=(cm_volume_t *) osi_QPrev(&volp->q)) {
+ /*
+ * Skip volume entries that did not exist last time
+ * the vldb was queried. For those entries wait until
+ * the next actual request is received for the volume
+ * before checking its state.
+ */
+ if ((volp->qflags & CM_VOLUME_QFLAG_IN_HASH) &&
+ !(volp->flags & CM_VOLUMEFLAG_NOEXIST)) {
+ InterlockedIncrement(&volp->refCount);
+ lock_ReleaseRead(&cm_volumeLock);
+ cm_CheckOfflineVolume(volp, 0);
+ lock_ObtainRead(&cm_volumeLock);
+ refCount = InterlockedDecrement(&volp->refCount);
+ osi_assertx(refCount >= 0, "cm_volume_t refCount underflow");
+ }
}
- lock_ReleaseWrite(&cm_volumeLock);
+ lock_ReleaseRead(&cm_volumeLock);
}
cm_serverRef_t *tsrp;
cm_server_t *tsp;
int someBusy = 0, someOffline = 0, allOffline = 1, allBusy = 1, allDown = 1;
+ char addr[16];
if (!volp || !statep) {
#ifdef DEBUG
lock_ObtainWrite(&cm_serverLock);
for (tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
tsp = tsrp->server;
- cm_GetServerNoLock(tsp);
- if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
- allDown = 0;
- if (tsrp->status == srv_busy) {
- allOffline = 0;
- someBusy = 1;
- } else if (tsrp->status == srv_offline) {
- allBusy = 0;
- someOffline = 1;
+ sprintf(addr, "%d.%d.%d.%d",
+ ((tsp->addr.sin_addr.s_addr & 0xff)),
+ ((tsp->addr.sin_addr.s_addr & 0xff00)>> 8),
+ ((tsp->addr.sin_addr.s_addr & 0xff0000)>> 16),
+ ((tsp->addr.sin_addr.s_addr & 0xff000000)>> 24));
+
+ if (tsrp->status == srv_deleted) {
+ osi_Log2(afsd_logp, "cm_UpdateVolumeStatusInt volume %d server reference %s deleted",
+ statep->ID, osi_LogSaveString(afsd_logp,addr));
+ continue;
+ }
+ if (tsp) {
+ cm_GetServerNoLock(tsp);
+ if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
+ allDown = 0;
+ if (tsrp->status == srv_busy) {
+ osi_Log2(afsd_logp, "cm_UpdateVolumeStatusInt volume %d server reference %s busy",
+ statep->ID, osi_LogSaveString(afsd_logp,addr));
+ allOffline = 0;
+ someBusy = 1;
+ } else if (tsrp->status == srv_offline) {
+ osi_Log2(afsd_logp, "cm_UpdateVolumeStatusInt volume %d server reference %s offline",
+ statep->ID, osi_LogSaveString(afsd_logp,addr));
+ allBusy = 0;
+ someOffline = 1;
+ } else {
+ osi_Log2(afsd_logp, "cm_UpdateVolumeStatusInt volume %d server reference %s online",
+ statep->ID, osi_LogSaveString(afsd_logp,addr));
+ allOffline = 0;
+ allBusy = 0;
+ }
} else {
- allOffline = 0;
- allBusy = 0;
+ osi_Log2(afsd_logp, "cm_UpdateVolumeStatusInt volume %d server reference %s down",
+ statep->ID, osi_LogSaveString(afsd_logp,addr));
}
+ cm_PutServerNoLock(tsp);
}
- cm_PutServerNoLock(tsp);
- }
+ }
lock_ReleaseWrite(&cm_serverLock);
+ osi_Log5(afsd_logp, "cm_UpdateVolumeStatusInt allDown %d allBusy %d someBusy %d someOffline %d allOffline %d",
+ allDown, allBusy, someBusy, someOffline, allOffline);
+
if (allDown)
newStatus = vl_alldown;
- else if (allBusy || (someBusy && someOffline))
+ else if (allBusy || (someBusy && someOffline))
newStatus = vl_busy;
else if (allOffline)
newStatus = vl_offline;
cm_UpdateVolumeStatus(cm_volume_t *volp, afs_uint32 volID)
{
- if (volp->rw.ID == volID) {
- cm_UpdateVolumeStatusInt(volp, &volp->rw);
- } else if (volp->ro.ID == volID) {
- cm_UpdateVolumeStatusInt(volp, &volp->ro);
- } else if (volp->bk.ID == volID) {
- cm_UpdateVolumeStatusInt(volp, &volp->bk);
+ if (volp->vol[RWVOL].ID == volID) {
+ cm_UpdateVolumeStatusInt(volp, &volp->vol[RWVOL]);
+ } else if (volp->vol[ROVOL].ID == volID) {
+ cm_UpdateVolumeStatusInt(volp, &volp->vol[ROVOL]);
+ } else if (volp->vol[BACKVOL].ID == volID) {
+ cm_UpdateVolumeStatusInt(volp, &volp->vol[BACKVOL]);
} else {
/*
* If we are called with volID == 0 then something has gone wrong.
* Most likely a race occurred in the server volume list maintenance.
- * Since we don't know which volume's status should be updated,
- * just update all of them that are known to exist. Better to be
+ * Since we don't know which volume's status should be updated,
+ * just update all of them that are known to exist. Better to be
* correct than fast.
*/
- if (volp->rw.ID != 0)
- cm_UpdateVolumeStatusInt(volp, &volp->rw);
- if (volp->ro.ID != 0)
- cm_UpdateVolumeStatusInt(volp, &volp->ro);
- if (volp->bk.ID != 0)
- cm_UpdateVolumeStatusInt(volp, &volp->bk);
+ afs_uint32 volType;
+ for ( volType = RWVOL; volType < NUM_VOL_TYPES; volType++) {
+ if (volp->vol[volType].ID != 0)
+ cm_UpdateVolumeStatusInt(volp, &volp->vol[volType]);
+ }
}
}
** RO list according to the changed rank of server.
*/
void cm_ChangeRankVolume(cm_server_t *tsp)
-{
+{
int code;
cm_volume_t* volp;
+ afs_int32 refCount;
/* find volumes which might have RO copy on server*/
- lock_ObtainWrite(&cm_volumeLock);
+ lock_ObtainRead(&cm_volumeLock);
for(volp = cm_data.allVolumesp; volp; volp=volp->allNextp)
{
code = 1 ; /* assume that list is unchanged */
- volp->refCount++;
- lock_ReleaseWrite(&cm_volumeLock);
- lock_ObtainMutex(&volp->mx);
+ InterlockedIncrement(&volp->refCount);
+ lock_ReleaseRead(&cm_volumeLock);
+ lock_ObtainWrite(&volp->rw);
- if ((tsp->cellp==volp->cellp) && (volp->ro.serversp))
- code =cm_ChangeRankServer(&volp->ro.serversp, tsp);
+ if ((tsp->cellp==volp->cellp) && (volp->vol[ROVOL].serversp))
+ code =cm_ChangeRankServer(&volp->vol[ROVOL].serversp, tsp);
/* this volume list was changed */
if ( !code )
- cm_RandomizeServer(&volp->ro.serversp);
+ cm_RandomizeServer(&volp->vol[ROVOL].serversp);
- lock_ReleaseMutex(&volp->mx);
- lock_ObtainWrite(&cm_volumeLock);
- osi_assertx(volp->refCount-- > 0, "cm_volume_t refCount 0");
+ lock_ReleaseWrite(&volp->rw);
+ lock_ObtainRead(&cm_volumeLock);
+ refCount = InterlockedDecrement(&volp->refCount);
+ osi_assertx(refCount >= 0, "cm_volume_t refCount underflow");
}
- lock_ReleaseWrite(&cm_volumeLock);
-}
+ lock_ReleaseRead(&cm_volumeLock);
+}
-/* dump all volumes that have reference count > 0 to a file.
- * cookie is used to identify this batch for easy parsing,
- * and it a string provided by a caller
+/* dump all volumes that have reference count > 0 to a file.
+ * cookie is used to identify this batch for easy parsing,
+ * and it a string provided by a caller
*/
int cm_DumpVolumes(FILE *outputFile, char *cookie, int lock)
{
int zilch;
cm_volume_t *volp;
char output[1024];
-
+
if (lock) {
lock_ObtainRead(&cm_scacheLock);
lock_ObtainRead(&cm_volumeLock);
}
-
- sprintf(output, "%s - dumping volumes - cm_data.currentVolumes=%d, cm_data.maxVolumes=%d\r\n", cookie, cm_data.currentVolumes, cm_data.maxVolumes);
+
+ sprintf(output, "%s - dumping volumes - cm_data.currentVolumes=%d, cm_data.maxVolumes=%d\r\n",
+ cookie, cm_data.currentVolumes, cm_data.maxVolumes);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
-
+
for (volp = cm_data.allVolumesp; volp; volp=volp->allNextp)
{
- cm_scache_t *scp;
- int scprefs = 0;
+ time_t t;
+ char *srvStr = NULL;
+ afs_uint32 srvStrRpc = TRUE;
+ char *cbt = NULL;
+ char *cdrot = NULL;
+
+ if (volp->cbServerpRO) {
+ if (!((volp->cbServerpRO->flags & CM_SERVERFLAG_UUID) &&
+ UuidToString((UUID *)&volp->cbServerpRO->uuid, &srvStr) == RPC_S_OK)) {
+ srvStr = malloc(16);
+ if (srvStr != NULL)
+ afs_inet_ntoa_r(volp->cbServerpRO->addr.sin_addr.s_addr, srvStr);
+ srvStrRpc = FALSE;
+ }
+ }
+ if (volp->cbExpiresRO) {
+ t = volp->cbExpiresRO;
+ cbt = ctime(&t);
+ if (cbt) {
+ cbt = strdup(cbt);
+ cbt[strlen(cbt)-1] = '\0';
+ }
+ }
+ if (volp->creationDateRO) {
+ t = volp->creationDateRO;
+ cdrot = ctime(&t);
+ if (cdrot) {
+ cdrot = strdup(cdrot);
+ cdrot[strlen(cdrot)-1] = '\0';
+ }
+ }
- for (scp = cm_data.allSCachesp; scp; scp = scp->allNextp)
- {
- if (scp->volp == volp)
- scprefs++;
- }
-
- sprintf(output, "%s - volp=0x%p cell=%s name=%s rwID=%u roID=%u bkID=%u flags=0x%x fid (cell=%d, volume=%d, vnode=%d, unique=%d) refCount=%u scpRefs=%u\r\n",
- cookie, volp, volp->cellp->name, volp->namep, volp->rw.ID, volp->ro.ID, volp->bk.ID, volp->flags,
- volp->dotdotFid.cell, volp->dotdotFid.volume, volp->dotdotFid.vnode, volp->dotdotFid.unique,
- volp->refCount, scprefs);
+ sprintf(output,
+ "%s - volp=0x%p cell=%s name=%s rwID=%u roID=%u bkID=%u flags=0x%x:%x "
+ "cbServerpRO='%s' cbExpiresRO='%s' creationDateRO='%s' refCount=%u\r\n",
+ cookie, volp, volp->cellp->name, volp->namep, volp->vol[RWVOL].ID,
+ volp->vol[ROVOL].ID, volp->vol[BACKVOL].ID, volp->flags, volp->qflags,
+ srvStr ? srvStr : "<none>", cbt ? cbt : "<none>", cdrot ? cdrot : "<none>",
+ volp->refCount);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+
+ if (srvStr) {
+ if (srvStrRpc)
+ RpcStringFree(&srvStr);
+ else
+ free(srvStr);
+ }
+ if (cbt)
+ free(cbt);
+ if (cdrot)
+ free(cdrot);
}
sprintf(output, "%s - Done dumping volumes.\r\n", cookie);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
-
+
if (lock) {
lock_ReleaseRead(&cm_volumeLock);
lock_ReleaseRead(&cm_scacheLock);
}
- return (0);
+ return (0);
}
-/*
+/*
* String hash function used by SDBM project.
* It was chosen because it is fast and provides
* decent coverage.
void cm_AddVolumeToNameHashTable(cm_volume_t *volp)
{
int i;
-
- if (volp->flags & CM_VOLUMEFLAG_IN_HASH)
+
+ if (volp->qflags & CM_VOLUME_QFLAG_IN_HASH)
return;
i = CM_VOLUME_NAME_HASH(volp->namep);
volp->nameNextp = cm_data.volumeNameHashTablep[i];
cm_data.volumeNameHashTablep[i] = volp;
- volp->flags |= CM_VOLUMEFLAG_IN_HASH;
+ _InterlockedOr(&volp->qflags, CM_VOLUME_QFLAG_IN_HASH);
}
/* call with volume write-locked and mutex held */
cm_volume_t **lvolpp;
cm_volume_t *tvolp;
int i;
-
- if (volp->flags & CM_VOLUMEFLAG_IN_HASH) {
+
+ if (volp->qflags & CM_VOLUME_QFLAG_IN_HASH) {
/* hash it out first */
i = CM_VOLUME_NAME_HASH(volp->namep);
for (lvolpp = &cm_data.volumeNameHashTablep[i], tvolp = cm_data.volumeNameHashTablep[i];
lvolpp = &tvolp->nameNextp, tvolp = tvolp->nameNextp) {
if (tvolp == volp) {
*lvolpp = volp->nameNextp;
- volp->flags &= ~CM_VOLUMEFLAG_IN_HASH;
+ _InterlockedAnd(&volp->qflags, ~CM_VOLUME_QFLAG_IN_HASH);
volp->nameNextp = NULL;
break;
}
int i;
struct cm_vol_state * statep;
- switch (volType) {
- case RWVOL:
- statep = &volp->rw;
- break;
- case ROVOL:
- statep = &volp->ro;
- break;
- case BACKVOL:
- statep = &volp->bk;
- break;
- default:
- return;
- }
+ statep = cm_VolumeStateByType(volp, volType);
- if (statep->flags & CM_VOLUMEFLAG_IN_HASH)
+ if (statep->qflags & CM_VOLUME_QFLAG_IN_HASH)
return;
i = CM_VOLUME_ID_HASH(statep->ID);
statep->nextp = cm_data.volumeRWIDHashTablep[i];
cm_data.volumeRWIDHashTablep[i] = volp;
break;
- case ROVOL:
+ case ROVOL:
statep->nextp = cm_data.volumeROIDHashTablep[i];
cm_data.volumeROIDHashTablep[i] = volp;
break;
cm_data.volumeBKIDHashTablep[i] = volp;
break;
}
- statep->flags |= CM_VOLUMEFLAG_IN_HASH;
+ _InterlockedOr(&statep->qflags, CM_VOLUME_QFLAG_IN_HASH);
}
cm_volume_t *tvolp;
struct cm_vol_state * statep;
int i;
-
- switch (volType) {
- case RWVOL:
- statep = &volp->rw;
- break;
- case ROVOL:
- statep = &volp->ro;
- break;
- case BACKVOL:
- statep = &volp->bk;
- break;
- default:
- return;
- }
- if (statep->flags & CM_VOLUMEFLAG_IN_HASH) {
+ statep = cm_VolumeStateByType(volp, volType);
+
+ if (statep->qflags & CM_VOLUME_QFLAG_IN_HASH) {
/* hash it out first */
i = CM_VOLUME_ID_HASH(statep->ID);
lvolpp = &cm_data.volumeBKIDHashTablep[i];
tvolp = cm_data.volumeBKIDHashTablep[i];
break;
+ default:
+ osi_assertx(0, "invalid volume type");
}
do {
if (tvolp == volp) {
*lvolpp = statep->nextp;
- statep->flags &= ~CM_VOLUMEFLAG_IN_HASH;
+ _InterlockedAnd(&statep->qflags, ~CM_VOLUME_QFLAG_IN_HASH);
statep->nextp = NULL;
break;
}
- switch (volType) {
- case RWVOL:
- lvolpp = &tvolp->rw.nextp;
- tvolp = tvolp->rw.nextp;
- break;
- case ROVOL:
- lvolpp = &tvolp->ro.nextp;
- tvolp = tvolp->ro.nextp;
- break;
- case BACKVOL:
- lvolpp = &tvolp->bk.nextp;
- tvolp = tvolp->bk.nextp;
- break;
- }
+ lvolpp = &tvolp->vol[volType].nextp;
+ tvolp = tvolp->vol[volType].nextp;
} while(tvolp);
}
}
/* must be called with cm_volumeLock write-locked! */
void cm_AdjustVolumeLRU(cm_volume_t *volp)
{
+ lock_AssertWrite(&cm_volumeLock);
+
+ if (volp == cm_data.volumeLRUFirstp)
+ return;
+
+ if (volp->qflags & CM_VOLUME_QFLAG_IN_LRU_QUEUE)
+ osi_QRemoveHT((osi_queue_t **) &cm_data.volumeLRUFirstp, (osi_queue_t **) &cm_data.volumeLRULastp, &volp->q);
+ osi_QAddH((osi_queue_t **) &cm_data.volumeLRUFirstp, (osi_queue_t **) &cm_data.volumeLRULastp, &volp->q);
+ _InterlockedOr(&volp->qflags, CM_VOLUME_QFLAG_IN_LRU_QUEUE);
+
+ osi_assertx(cm_data.volumeLRULastp != NULL, "null cm_data.volumeLRULastp");
+}
+
+/* must be called with cm_volumeLock write-locked! */
+void cm_MoveVolumeToLRULast(cm_volume_t *volp)
+{
+ lock_AssertWrite(&cm_volumeLock);
+
if (volp == cm_data.volumeLRULastp)
- cm_data.volumeLRULastp = (cm_volume_t *) osi_QPrev(&volp->q);
- if (volp->flags & CM_VOLUMEFLAG_IN_LRU_QUEUE)
+ return;
+
+ if (volp->qflags & CM_VOLUME_QFLAG_IN_LRU_QUEUE)
osi_QRemoveHT((osi_queue_t **) &cm_data.volumeLRUFirstp, (osi_queue_t **) &cm_data.volumeLRULastp, &volp->q);
- osi_QAdd((osi_queue_t **) &cm_data.volumeLRUFirstp, &volp->q);
- volp->flags |= CM_VOLUMEFLAG_IN_LRU_QUEUE;
- if (!cm_data.volumeLRULastp)
- cm_data.volumeLRULastp = volp;
+ osi_QAddT((osi_queue_t **) &cm_data.volumeLRUFirstp, (osi_queue_t **) &cm_data.volumeLRULastp, &volp->q);
+ _InterlockedOr(&volp->qflags, CM_VOLUME_QFLAG_IN_LRU_QUEUE);
+
+ osi_assertx(cm_data.volumeLRULastp != NULL, "null cm_data.volumeLRULastp");
}
/* must be called with cm_volumeLock write-locked! */
void cm_RemoveVolumeFromLRU(cm_volume_t *volp)
{
- if (volp->flags & CM_VOLUMEFLAG_IN_LRU_QUEUE) {
- if (volp == cm_data.volumeLRULastp)
- cm_data.volumeLRULastp = (cm_volume_t *) osi_QPrev(&volp->q);
+ lock_AssertWrite(&cm_volumeLock);
+
+ if (volp->qflags & CM_VOLUME_QFLAG_IN_LRU_QUEUE) {
osi_QRemoveHT((osi_queue_t **) &cm_data.volumeLRUFirstp, (osi_queue_t **) &cm_data.volumeLRULastp, &volp->q);
- volp->flags &= ~CM_VOLUMEFLAG_IN_LRU_QUEUE;
+ _InterlockedAnd(&volp->qflags, ~CM_VOLUME_QFLAG_IN_LRU_QUEUE);
}
+
+ osi_assertx(cm_data.volumeLRULastp != NULL, "null cm_data.volumeLRULastp");
}
static char * volstatus_str(enum volstatus vs)
char volstr[CELL_MAXNAMELEN + VL_MAXNAMELEN]="";
char *ext = "";
- if (volID == volp->rw.ID)
+ if (volID == volp->vol[RWVOL].ID)
ext = "";
- else if (volID == volp->ro.ID)
+ else if (volID == volp->vol[ROVOL].ID)
ext = ".readonly";
- else if (volID == volp->bk.ID)
+ else if (volID == volp->vol[BACKVOL].ID)
ext = ".backup";
else
ext = ".nomatch";
osi_LogSaveString(afsd_logp, volstr), volID, volstatus_str(old), volstatus_str(new));
cm_VolStatus_Change_Notification(volp->cellp->cellID, volID, new);
-}
+}
enum volstatus cm_GetVolumeStatus(cm_volume_t *volp, afs_uint32 volID)
{
- if (volp->rw.ID == volID) {
- return volp->rw.state;
- } else if (volp->ro.ID == volID) {
- return volp->ro.state;
- } else if (volp->bk.ID == volID) {
- return volp->bk.state;
- } else {
+ cm_vol_state_t * statep = cm_VolumeStateByID(volp, volID);
+ if (statep)
+ return statep->state;
+ else
return vl_unknown;
- }
}
/* Renew .readonly volume callbacks that are more than
* 30 minutes old. (A volume callback is issued for 2 hours.)
*/
-void
+void
cm_VolumeRenewROCallbacks(void)
{
cm_volume_t * volp;
time_t minexp = time(NULL) + 90 * 60;
+ extern int daemon_ShutdownFlag;
+ extern int powerStateSuspended;
lock_ObtainRead(&cm_volumeLock);
- for (volp = cm_data.allVolumesp; volp; volp=volp->allNextp) {
+ for (volp = cm_data.allVolumesp;
+ volp && !daemon_ShutdownFlag && !powerStateSuspended;
+ volp=volp->allNextp) {
if ( volp->cbExpiresRO > 0 && volp->cbExpiresRO < minexp) {
cm_req_t req;
cm_fid_t fid;
cm_scache_t * scp;
- fid.cell = volp->cellp->cellID;
- fid.volume = volp->ro.ID;
- fid.vnode = 1;
- fid.unique = 1;
+ cm_SetFid(&fid, volp->cellp->cellID, volp->vol[ROVOL].ID, 1, 1);
cm_InitReq(&req);
lock_ReleaseRead(&cm_volumeLock);
- if (cm_GetSCache(&fid, &scp, cm_rootUserp, &req) == 0) {
- lock_ObtainMutex(&scp->mx);
+ if (cm_GetSCache(&fid, NULL, &scp, cm_rootUserp, &req) == 0) {
+ lock_ObtainWrite(&scp->rw);
cm_GetCallback(scp, cm_rootUserp, &req, 1);
- lock_ReleaseMutex(&scp->mx);
+ lock_ReleaseWrite(&scp->rw);
cm_ReleaseSCache(scp);
}
lock_ObtainRead(&cm_volumeLock);
}
lock_ReleaseRead(&cm_volumeLock);
}
+
+cm_vol_state_t *
+cm_VolumeStateByType(cm_volume_t *volp, afs_uint32 volType)
+{
+ return &volp->vol[volType];
+}
+
+cm_vol_state_t *
+cm_VolumeStateByID(cm_volume_t *volp, afs_uint32 id)
+{
+ cm_vol_state_t * statep = NULL;
+
+ if (id == volp->vol[RWVOL].ID)
+ statep = &volp->vol[RWVOL];
+ else if (id == volp->vol[ROVOL].ID)
+ statep = &volp->vol[ROVOL];
+ else if (id == volp->vol[BACKVOL].ID)
+ statep = &volp->vol[BACKVOL];
+
+ return(statep);
+}
+
+cm_vol_state_t *
+cm_VolumeStateByName(cm_volume_t *volp, char *volname)
+{
+ size_t len = strlen(volname);
+ cm_vol_state_t *statep;
+
+ if (cm_stricmp_utf8N(".readonly", &volname[len-9]) == 0)
+ statep = &volp->vol[ROVOL];
+ else if (cm_stricmp_utf8N(".backup", &volname[len-7]) == 0)
+ statep = &volp->vol[BACKVOL];
+ else
+ statep = &volp->vol[RWVOL];
+
+ return statep;
+}
+
+afs_int32
+cm_VolumeType(cm_volume_t *volp, afs_uint32 id)
+{
+ if (id == volp->vol[RWVOL].ID)
+ return(RWVOL);
+ else if (id == volp->vol[ROVOL].ID)
+ return(ROVOL);
+ else if (id == volp->vol[BACKVOL].ID)
+ return (BACKVOL);
+
+ return -1;
+}
+
+LONG_PTR
+cm_ChecksumVolumeServerList(struct cm_fid *fidp, cm_user_t *userp, cm_req_t *reqp)
+{
+ LONG_PTR cksum = 0;
+ long code;
+ afs_uint32 replicated;
+ cm_serverRef_t **serverspp;
+
+ code = cm_GetServerList(fidp, userp, reqp, &replicated, &serverspp);
+ if (code == 0) {
+ cksum = cm_ChecksumServerList(*serverspp);
+ cm_FreeServerList(serverspp, 0);
+ }
+ return cksum;
+}
+
+afs_int32
+cm_IsVolumeReplicated(cm_fid_t *fidp)
+{
+ afs_int32 replicated = 0;
+ cm_volume_t *volp;
+ cm_vol_state_t * volstatep;
+
+ volp = cm_GetVolumeByFID(fidp);
+ if (volp) {
+ volstatep = cm_VolumeStateByID(volp, fidp->volume);
+ replicated = (volstatep->flags & CM_VOL_STATE_FLAG_REPLICATED);
+ cm_PutVolume(volp);
+ }
+
+ return replicated;
+}