#endif
/* Forward declarations */
-static Volume *attach2(Error * ec, VolId volumeId, char *path,
+static Volume *attach2(Error * ec, VolumeId volumeId, char *path,
struct DiskPartition64 *partp, Volume * vp,
int isbusy, int mode, int *acheckedOut);
static void ReallyFreeVolume(Volume * vp);
static int GetVolumeHeader(Volume * vp);
static void ReleaseVolumeHeader(struct volHeader *hd);
static void FreeVolumeHeader(Volume * vp);
-static void AddVolumeToHashTable(Volume * vp, int hashid);
+static void AddVolumeToHashTable(Volume * vp, VolumeId hashid);
static void DeleteVolumeFromHashTable(Volume * vp);
#if 0
static int VHold(Volume * vp);
static void LoadVolumeHeader(Error * ec, Volume * vp);
static int VCheckOffline(Volume * vp);
static int VCheckDetach(Volume * vp);
-static Volume * GetVolume(Error * ec, Error * client_ec, VolId volumeId,
+static Volume * GetVolume(Error * ec, Error * client_ec, VolumeId volumeId,
Volume * hint, const struct timespec *ts);
int LogLevel; /* Vice loglevel--not defined as extern so that it will be
static void *VInitVolumePackageThread(void *args);
static struct DiskPartition64 *VInitNextPartition(struct partition_queue *pq);
-static VolId VInitNextVolumeId(DIR *dirp);
+static VolumeId VInitNextVolumeId(DIR *dirp);
static int VInitPreAttachVolumes(int nthreads, struct volume_init_queue *vq);
#endif /* !AFS_DEMAND_ATTACH_FS */
};
struct VLRU_DiskEntry {
- afs_uint32 vid; /* volume ID */
+ VolumeId vid; /* volume ID */
afs_uint32 idx; /* generation */
afs_uint32 last_get; /* timestamp of last get */
};
Log("Scanning partitions on thread %d of %d\n", params->thread, params->nthreads);
while((partition = VInitNextPartition(pq))) {
DIR *dirp;
- VolId vid;
+ VolumeId vid;
Log("Partition %s: pre-attaching volumes\n", partition->name);
dirp = opendir(VPartitionPath(partition));
/**
* Find next volume id on the partition.
*/
-static VolId
+static VolumeId
VInitNextVolumeId(DIR *dirp)
{
struct dirent *d;
- VolId vid = 0;
+ VolumeId vid = 0;
char *ext;
while((d = readdir(dirp))) {
Log("Error looking up volume, code=%d\n", ec);
}
else if (dup) {
- Log("Warning: Duplicate volume id %d detected.\n", vp->hashid);
+ Log("Warning: Duplicate volume id %" AFS_VOLID_FMT " detected.\n", afs_printable_VolumeId_lu(vp->hashid));
}
else {
/* put pre-attached volume onto the hash table
code = VHold_r(vp);
if (code == 0) {
if (LogLevel >= 5)
- Log("VShutdown: Attempting to take volume %u offline.\n",
- vp->hashid);
+ Log("VShutdown: Attempting to take volume %" AFS_VOLID_FMT " offline.\n",
+ afs_printable_VolumeId_lu(vp->hashid));
/* next, take the volume offline (drops reference count) */
VOffline_r(vp, "File server was shut down");
VCreateReservation_r(vp);
if (LogLevel >= 5) {
- Log("VShutdownVolume_r: vid=%u, device=%d, state=%hu\n",
- vp->hashid, vp->partition->device, V_attachState(vp));
+ Log("VShutdownVolume_r: vid=%" AFS_VOLID_FMT ", device=%d, state=%hu\n",
+ afs_printable_VolumeId_lu(vp->hashid), vp->partition->device,
+ V_attachState(vp));
}
/* wait for other blocking ops to finish */
code = VHold_r(vp);
if (!code) {
if (LogLevel >= 5)
- Log("VShutdown: Attempting to take volume %u offline.\n",
- vp->hashid);
+ Log("VShutdown: Attempting to take volume %" AFS_VOLID_FMT " offline.\n",
+ afs_printable_VolumeId_lu(vp->hashid));
/* take the volume offline (drops reference count) */
VOffline_r(vp, "File server was shut down");
fdP = IH_OPEN(h);
if (fdP == NULL) {
Log("ReadHeader: Failed to open %s header file "
- "(volume=%u, inode=%s); errno=%d\n", HeaderName(magic), h->ih_vid,
+ "(volume=%" AFS_VOLID_FMT ", inode=%s); errno=%d\n", HeaderName(magic), afs_printable_VolumeId_lu(h->ih_vid),
PrintInode(stmp, h->ih_ino), errno);
*ec = VSALVAGE;
return;
nbytes = FDH_PREAD(fdP, to, size, 0);
if (nbytes < 0) {
Log("ReadHeader: Failed to read %s header file "
- "(volume=%u, inode=%s); errno=%d\n", HeaderName(magic), h->ih_vid,
+ "(volume=%" AFS_VOLID_FMT ", inode=%s); errno=%d\n", HeaderName(magic), afs_printable_VolumeId_lu(h->ih_vid),
PrintInode(stmp, h->ih_ino), errno);
*ec = VSALVAGE;
FDH_REALLYCLOSE(fdP);
}
if (nbytes != size) {
Log("ReadHeader: Incorrect number of bytes read from %s header file "
- "(volume=%u, inode=%s); expected=%d, read=%d\n",
- HeaderName(magic), h->ih_vid, PrintInode(stmp, h->ih_ino), size,
- (int)nbytes);
+ "(volume=%" AFS_VOLID_FMT ", inode=%s); expected=%d, read=%d\n",
+ HeaderName(magic), afs_printable_VolumeId_lu(h->ih_vid),
+ PrintInode(stmp, h->ih_ino), size, (int)nbytes);
*ec = VSALVAGE;
FDH_REALLYCLOSE(fdP);
return;
}
if (vsn->magic != magic) {
Log("ReadHeader: Incorrect magic for %s header file "
- "(volume=%u, inode=%s); expected=0x%x, read=0x%x\n",
- HeaderName(magic), h->ih_vid, PrintInode(stmp, h->ih_ino), magic,
- vsn->magic);
+ "(volume=%" AFS_VOLID_FMT ", inode=%s); expected=0x%x, read=0x%x\n",
+ HeaderName(magic), afs_printable_VolumeId_lu(h->ih_vid),
+ PrintInode(stmp, h->ih_ino), magic, vsn->magic);
*ec = VSALVAGE;
FDH_REALLYCLOSE(fdP);
return;
/* Check is conditional, in case caller wants to inspect version himself */
if (version && vsn->version != version) {
Log("ReadHeader: Incorrect version for %s header file "
- "(volume=%u, inode=%s); expected=%x, read=%x\n",
- HeaderName(magic), h->ih_vid, PrintInode(stmp, h->ih_ino),
+ "(volume=%" AFS_VOLID_FMT ", inode=%s); expected=%x, read=%x\n",
+ HeaderName(magic), afs_printable_VolumeId_lu(h->ih_vid), PrintInode(stmp, h->ih_ino),
version, vsn->version);
*ec = VSALVAGE;
}
Volume *
VPreAttachVolumeById_r(Error * ec,
char * partition,
- VolId volumeId)
+ VolumeId volumeId)
{
Volume *vp;
struct DiskPartition64 *partp;
return NULL;
}
+ /* ensure that any vp we pass to VPreAttachVolumeByVp_r
+ * is NOT in exclusive state.
+ */
+ retry:
vp = VLookupVolume_r(ec, volumeId, NULL);
+
if (*ec) {
return NULL;
}
+ if (vp && VIsExclusiveState(V_attachState(vp))) {
+ VCreateReservation_r(vp);
+ VWaitExclusiveState_r(vp);
+ VCancelReservation_r(vp);
+ vp = NULL;
+ goto retry; /* look up volume again */
+ }
+
+ /* vp == NULL or vp not exclusive both OK */
+
return VPreAttachVolumeByVp_r(ec, partp, vp, volumeId);
}
*
* @pre VOL_LOCK is held.
*
+ * @pre vp (if specified) must not be in exclusive state.
+ *
* @warning Returned volume object pointer does not have to
* equal the pointer passed in as argument vp. There
* are potential race conditions which can result in
VPreAttachVolumeByVp_r(Error * ec,
struct DiskPartition64 * partp,
Volume * vp,
- VolId vid)
+ VolumeId vid)
{
Volume *nvp = NULL;
*ec = 0;
+ /* don't proceed unless it's safe */
+ if (vp) {
+ opr_Assert(!VIsExclusiveState(V_attachState(vp)));
+ }
+
/* check to see if pre-attach already happened */
if (vp &&
(V_attachState(vp) != VOL_STATE_UNATTACHED) &&
* - volume is in an error state
* - volume is pre-attached
*/
- Log("VPreattachVolumeByVp_r: volume %u not in quiescent state (state %u flags 0x%x)\n",
- vid, V_attachState(vp), V_attachFlags(vp));
+ Log("VPreattachVolumeByVp_r: volume %" AFS_VOLID_FMT " not in quiescent state (state %u flags 0x%x)\n",
+ afs_printable_VolumeId_lu(vid), V_attachState(vp),
+ V_attachFlags(vp));
goto done;
} else if (vp) {
/* we're re-attaching a volume; clear out some old state */
VChangeState_r(vp, VOL_STATE_PREATTACHED);
if (LogLevel >= 5)
- Log("VPreAttachVolumeByVp_r: volume %u pre-attached\n", vp->hashid);
+ Log("VPreAttachVolumeByVp_r: volume %" AFS_VOLID_FMT " pre-attached\n", afs_printable_VolumeId_lu(vp->hashid));
done:
if (*ec)
struct DiskPartition64 *partp;
char path[64];
int isbusy = 0;
- VolId volumeId;
+ VolumeId volumeId;
int checkedOut;
#ifdef AFS_DEMAND_ATTACH_FS
VolumeStats stats_save;
}
}
if (LogLevel)
- Log("VOnline: volume %u (%s) attached and online\n", V_id(vp),
+ Log("VOnline: volume %" AFS_VOLID_FMT " (%s) attached and online\n", afs_printable_VolumeId_lu(V_id(vp)),
V_name(vp));
}
struct DiskPartition64 *partp;
char path[64];
int isbusy = 0;
- VolId volumeId;
+ VolumeId volumeId;
Volume * nvp = NULL;
VolumeStats stats_save;
int checkedOut;
VUpdateVolume_r(ec, vp, 0);
if (*ec) {
- Log("VAttachVolume: Error updating volume %u\n", vp->hashid);
+ Log("VAttachVolume: Error updating volume %" AFS_VOLID_FMT "\n",
+ afs_printable_VolumeId_lu(vp->hashid));
VPutVolume_r(vp);
goto done;
}
#endif /* !AFS_DEMAND_ATTACH_FS */
VAddToVolumeUpdateList_r(ec, vp);
if (*ec) {
- Log("VAttachVolume: Error adding volume %u to update list\n", vp->hashid);
+ Log("VAttachVolume: Error adding volume %" AFS_VOLID_FMT " to update list\n",
+ afs_printable_VolumeId_lu(vp->hashid));
if (vp)
VPutVolume_r(vp);
goto done;
}
}
if (LogLevel)
- Log("VOnline: volume %u (%s) attached and online\n", V_id(vp),
- V_name(vp));
+ Log("VOnline: volume %" AFS_VOLID_FMT " (%s) attached and online\n",
+ afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
done:
if (reserve) {
VCancelReservation_r(nvp);
* @post VOL_LOCK held
*/
static Volume *
-attach2(Error * ec, VolId volumeId, char *path, struct DiskPartition64 *partp,
+attach2(Error * ec, VolumeId volumeId, char *path, struct DiskPartition64 *partp,
Volume * vp, int isbusy, int mode, int *acheckedOut)
{
/* have we read in the header successfully? */
#ifdef AFS_DEMAND_ATTACH_FS
if (!VIsErrorState(V_attachState(vp))) {
if (VIsErrorState(error_state)) {
- Log("attach2: forcing vol %u to error state (state %u flags 0x%x ec %d)\n",
- vp->hashid, V_attachState(vp), V_attachFlags(vp), *ec);
+ Log("attach2: forcing vol %" AFS_VOLID_FMT " to error state (state %u flags 0x%x ec %d)\n",
+ afs_printable_VolumeId_lu(vp->hashid), V_attachState(vp),
+ V_attachFlags(vp), *ec);
}
VChangeState_r(vp, error_state);
}
of whether or not the volume is in service or on/off line. An error
code, however, is returned with an indication of the volume's status */
Volume *
-VGetVolume(Error * ec, Error * client_ec, VolId volumeId)
+VGetVolume(Error * ec, Error * client_ec, VolumeId volumeId)
{
Volume *retVal;
VOL_LOCK;
* VPutVolumeWithCall
*/
Volume *
-VGetVolumeWithCall(Error * ec, Error * client_ec, VolId volumeId,
+VGetVolumeWithCall(Error * ec, Error * client_ec, VolumeId volumeId,
const struct timespec *ts, struct VCallByVol *cbv)
{
Volume *retVal;
}
Volume *
-VGetVolume_r(Error * ec, VolId volumeId)
+VGetVolume_r(Error * ec, VolumeId volumeId)
{
return GetVolume(ec, NULL, volumeId, NULL, NULL);
}
* @note for LWP builds, 'timeout' must be NULL
*/
static Volume *
-GetVolume(Error * ec, Error * client_ec, VolId volumeId, Volume * hint,
+GetVolume(Error * ec, Error * client_ec, VolumeId volumeId, Volume * hint,
const struct timespec *timeout)
{
Volume *vp = hint;
/* Only log the error if it was a totally unexpected error. Simply
* a missing inode is likely to be caused by the volume being deleted */
if (errno != ENXIO || LogLevel)
- Log("Volume %u: couldn't reread volume header\n",
- vp->hashid);
+ Log("Volume %" AFS_VOLID_FMT ": couldn't reread volume header\n",
+ afs_printable_VolumeId_lu(vp->hashid));
#ifdef AFS_DEMAND_ATTACH_FS
if (VCanScheduleSalvage()) {
VRequestSalvage_r(ec, vp, SALVSYNC_ERROR, 0 /*flags*/);
strcpy(V_offlineMessage(vp),
"Forced offline due to internal error: volume needs to be salvaged");
- Log("Volume %u forced offline: it needs salvaging!\n", V_id(vp));
+ Log("Volume %" AFS_VOLID_FMT " forced offline: it needs salvaging!\n", afs_printable_VolumeId_lu(V_id(vp)));
V_inUse(vp) = 0;
vp->goingOffline = 0;
char hoststr[16];
peer = rx_PeerOf(rx_ConnectionOf(cbv->call));
- Log("Offlining volume %lu while client %s:%u is trying to read "
+ Log("Offlining volume %" AFS_VOLID_FMT " while client %s:%u is trying to read "
"from it; kicking client off with error %ld\n",
- (long unsigned) vp->hashid,
+ afs_printable_VolumeId_lu(vp->hashid),
afs_inet_ntoa_r(rx_HostOf(peer), hoststr),
(unsigned) ntohs(rx_PortOf(peer)),
(long) err);
IH_CONDSYNC(vp->vnodeIndex[vLarge].handle);
IH_CONDSYNC(vp->vnodeIndex[vSmall].handle);
IH_CONDSYNC(vp->diskDataHandle);
-#ifdef AFS_NT40_ENV
+#ifdef AFS_NAMEI_ENV
IH_CONDSYNC(vp->linkHandle);
-#endif /* AFS_NT40_ENV */
+#endif /* AFS_NAMEI_ENV */
}
IH_REALLYCLOSE(vp->vnodeIndex[vLarge].handle);
IH_CONDSYNC(vp->vnodeIndex[vLarge].handle);
IH_CONDSYNC(vp->vnodeIndex[vSmall].handle);
IH_CONDSYNC(vp->diskDataHandle);
-#ifdef AFS_NT40_ENV
+#ifdef AFS_NAMEI_ENV
IH_CONDSYNC(vp->linkHandle);
-#endif /* AFS_NT40_ENV */
+#endif /* AFS_NAMEI_ENV */
}
IH_RELEASE(vp->vnodeIndex[vLarge].handle);
#endif
if (*ec) {
- Log("VUpdateVolume: error updating volume header, volume %u (%s)\n",
- V_id(vp), V_name(vp));
+ Log("VUpdateVolume: error updating volume header, volume %" AFS_VOLID_FMT " (%s)\n",
+ afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
/* try to update on-disk header,
* while preventing infinite recursion */
if (!(flags & VOL_UPDATE_NOFORCEOFF)) {
V_inUse(vp) = 0;
VUpdateVolume_r(&ec, vp, VOL_UPDATE_NOFORCEOFF);
if (ec) {
- Log("VCheckDetach: volume header update for volume %u "
- "failed with errno %d\n", vp->hashid, errno);
+ Log("VCheckDetach: volume header update for volume %" AFS_VOLID_FMT " "
+ "failed with errno %d\n", afs_printable_VolumeId_lu(vp->hashid), errno);
}
}
VReleaseVolumeHandles_r(vp);
V_inUse(vp) = 0;
VUpdateVolume_r(&ec, vp, VOL_UPDATE_NOFORCEOFF);
if (ec) {
- Log("VCheckDetach: volume header update for volume %u failed with errno %d\n",
- vp->hashid, errno);
+ Log("VCheckDetach: volume header update for volume %" AFS_VOLID_FMT " failed with errno %d\n",
+ afs_printable_VolumeId_lu(vp->hashid), errno);
}
}
VReleaseVolumeHandles_r(vp);
*ec = VSALVAGING;
} else {
- Log("VRequestSalvage: volume %u online salvaged too many times; forced offline.\n", vp->hashid);
+ Log("VRequestSalvage: volume %" AFS_VOLID_FMT " online salvaged too many times; forced offline.\n", afs_printable_VolumeId_lu(vp->hashid));
/* make sure neither VScheduleSalvage_r nor
* VUpdateSalvagePriority_r try to schedule another salvage */
try_SALVSYNC(Volume *vp, char *partName, int *code) {
#ifdef SALVSYNC_BUILD_CLIENT
if (VCanUseSALVSYNC()) {
- Log("Scheduling salvage for volume %lu on part %s over SALVSYNC\n",
- afs_printable_uint32_lu(vp->hashid), partName);
+ Log("Scheduling salvage for volume %" AFS_VOLID_FMT " on part %s over SALVSYNC\n",
+ afs_printable_VolumeId_lu(vp->hashid), partName);
/* can't use V_id() since there's no guarantee
* we have the disk data header at this point */
try_FSSYNC(Volume *vp, char *partName, int *code) {
#ifdef FSSYNC_BUILD_CLIENT
if (VCanUseFSSYNC()) {
- Log("Scheduling salvage for volume %lu on part %s over FSSYNC\n",
- afs_printable_uint32_lu(vp->hashid), partName);
+ Log("Scheduling salvage for volume %" AFS_VOLID_FMT " on part %s over FSSYNC\n",
+ afs_printable_VolumeId_lu(vp->hashid), partName);
/*
* If we aren't the fileserver, tell the fileserver the volume
break;
case SYNC_DENIED:
ret = VCHECK_SALVAGE_DENIED;
- Log("VScheduleSalvage_r: Salvage request for volume %lu "
- "denied\n", afs_printable_uint32_lu(vp->hashid));
+ Log("VScheduleSalvage_r: Salvage request for volume %" AFS_VOLID_FMT " "
+ "denied\n", afs_printable_VolumeId_lu(vp->hashid));
break;
case SYNC_FAILED:
ret = VCHECK_SALVAGE_FAIL;
- Log("VScheduleSalvage_r: Salvage request for volume %lu "
- "failed\n", afs_printable_uint32_lu(vp->hashid));
+ Log("VScheduleSalvage_r: Salvage request for volume %" AFS_VOLID_FMT " "
+ "failed\n", afs_printable_VolumeId_lu(vp->hashid));
break;
default:
ret = VCHECK_SALVAGE_FAIL;
- Log("VScheduleSalvage_r: Salvage request for volume %lu "
+ Log("VScheduleSalvage_r: Salvage request for volume %" AFS_VOLID_FMT " "
"received unknown protocol error %d\n",
- afs_printable_uint32_lu(vp->hashid), code);
+ afs_printable_VolumeId_lu(vp->hashid), code);
break;
}
*
*/
void
-VGetVolumePath(Error * ec, VolId volumeId, char **partitionp, char **namep)
+VGetVolumePath(Error * ec, VolumeId volumeId, char **partitionp, char **namep)
{
static char partition[VMAXPATHLEN], name[VMAXPATHLEN];
char path[VMAXPATHLEN];
*ec = 0;
name[0] = OS_DIRSEPC;
snprintf(&name[1], (sizeof name) - 1, VFORMAT,
- afs_printable_uint32_lu(volumeId));
+ afs_printable_VolumeId_lu(volumeId));
for (dp = DiskPartitionList; dp; dp = dp->next) {
struct afs_stat_st status;
strcpy(path, VPartitionPath(dp));
VolumeExternalName(VolumeId volumeId)
{
static char name[VMAXPATHLEN];
- snprintf(name, sizeof name, VFORMAT, afs_printable_uint32_lu(volumeId));
+ snprintf(name, sizeof name, VFORMAT, afs_printable_VolumeId_lu(volumeId));
return name;
}
int
VolumeExternalName_r(VolumeId volumeId, char * name, size_t len)
{
- return snprintf(name, len, VFORMAT, afs_printable_uint32_lu(volumeId));
+ return snprintf(name, len, VFORMAT, afs_printable_VolumeId_lu(volumeId));
}
* asynchronous hash chain reordering to finish.
*/
static void
-AddVolumeToHashTable(Volume * vp, int hashid)
+AddVolumeToHashTable(Volume * vp, VolumeId hashid)
{
VolumeHashChainHead * head;
* hint volume object.
*/
Volume *
-VLookupVolume_r(Error * ec, VolId volumeId, Volume * hint)
+VLookupVolume_r(Error * ec, VolumeId volumeId, Volume * hint)
{
int looks = 0;
Volume * vp, *np;