#include <afsconfig.h>
#include <afs/param.h>
-RCSID
- ("$Header$");
#include <rx/xdr.h>
#include <afs/afsint.h>
#ifdef AFS_DEMAND_ATTACH_FS
pthread_mutex_t vol_salvsync_mutex;
+
+/*
+ * Set this to 1 to disallow SALVSYNC communication in all threads; used
+ * during shutdown, since the salvageserver may have gone away.
+ */
+static volatile sig_atomic_t vol_disallow_salvsync = 0;
#endif /* AFS_DEMAND_ATTACH_FS */
#ifdef AFS_OSF_ENV
static int VCheckOffline(register Volume * vp);
static int VCheckDetach(register Volume * vp);
static Volume * GetVolume(Error * ec, Error * client_ec, VolId volumeId, Volume * hint, int flags);
-#if 0
+#ifdef AFS_DEMAND_ATTACH_FS
static int VolumeExternalName_r(VolumeId volumeId, char * name, size_t len);
#endif
/* online salvager */
static int VCheckSalvage(register Volume * vp);
static int VUpdateSalvagePriority_r(Volume * vp);
+#ifdef SALVSYNC_BUILD_CLIENT
static int VScheduleSalvage_r(Volume * vp);
-static int VCancelSalvage_r(Volume * vp, int reason);
+#endif
/* Volume hash table */
static void VReorderHash_r(VolumeHashChainHead * head, Volume * pp, Volume * vp);
/* VLRU */
static void VLRU_ComputeConstants(void);
static void VInitVLRU(void);
-static void VLRU_Init_Node_r(volatile Volume * vp);
-static void VLRU_Add_r(volatile Volume * vp);
-static void VLRU_Delete_r(volatile Volume * vp);
-static void VLRU_UpdateAccess_r(volatile Volume * vp);
+static void VLRU_Init_Node_r(Volume * vp);
+static void VLRU_Add_r(Volume * vp);
+static void VLRU_Delete_r(Volume * vp);
+static void VLRU_UpdateAccess_r(Volume * vp);
static void * VLRU_ScannerThread(void * args);
static void VLRU_Scan_r(int idx);
static void VLRU_Promote_r(int idx);
static void VLRU_Demote_r(int idx);
-static void VLRU_SwitchQueues(volatile Volume * vp, int new_idx, int append);
+static void VLRU_SwitchQueues(Volume * vp, int new_idx, int append);
/* soft detach */
-static int VCheckSoftDetach(volatile Volume * vp, afs_uint32 thresh);
-static int VCheckSoftDetachCandidate(volatile Volume * vp, afs_uint32 thresh);
-static int VSoftDetachVolume_r(volatile Volume * vp, afs_uint32 thresh);
+static int VCheckSoftDetach(Volume * vp, afs_uint32 thresh);
+static int VCheckSoftDetachCandidate(Volume * vp, afs_uint32 thresh);
+static int VSoftDetachVolume_r(Volume * vp, afs_uint32 thresh);
pthread_key_t VThread_key;
#ifdef AFS_PTHREAD_ENV
static void *
VInitVolumePackageThread(void * args) {
- int errors = 0; /* Number of errors while finding vice partitions. */
- DIR *dirp;
- struct dirent *dp;
struct DiskPartition64 *diskP;
struct vinitvolumepackage_thread_t * params;
struct diskpartition_queue_t * dpq;
* shutdown all remaining volumes
*/
+#ifdef AFS_DEMAND_ATTACH_FS
+
void
VShutdown_r(void)
{
int i;
- register Volume *vp, *np;
- register afs_int32 code;
-#ifdef AFS_DEMAND_ATTACH_FS
struct DiskPartition64 * diskP;
struct diskpartition_queue_t * dpq;
vshutdown_thread_t params;
}
Log("VShutdown: complete.\n");
+}
+
#else /* AFS_DEMAND_ATTACH_FS */
+
+void
+VShutdown_r(void)
+{
+ int i;
+ register Volume *vp, *np;
+ register afs_int32 code;
Log("VShutdown: shutting down on-line volumes...\n");
for (i = 0; i < VolumeHashTable.Size; i++) {
/* try to hold first volume in the hash table */
}
}
Log("VShutdown: complete.\n");
-#endif /* AFS_DEMAND_ATTACH_FS */
}
+#endif /* AFS_DEMAND_ATTACH_FS */
+
void
VShutdown(void)
VOL_UNLOCK;
}
+/**
+ * stop new activity (e.g. SALVSYNC) from occurring
+ *
+ * Use this to make the volume package less busy; for example, during
+ * shutdown. This doesn't actually shutdown/detach anything in the
+ * volume package, but prevents certain processes from ocurring. For
+ * example, preventing new SALVSYNC communication in DAFS. In theory, we
+ * could also use this to prevent new volume attachment, or prevent
+ * other programs from checking out volumes, etc.
+ */
+void
+VSetTranquil(void)
+{
+#ifdef AFS_DEMAND_ATTACH_FS
+ /* make sure we don't try to contact the salvageserver, since it may
+ * not be around anymore */
+ vol_disallow_salvsync = 1;
+#endif
+}
+
#ifdef AFS_DEMAND_ATTACH_FS
/*
* demand attach fs
if (thr_left) {
/* try to assign any leftover threads to partitions that
* had volume lengths closer to needing thread_target+1 */
- int max_residue, max_id;
+ int max_residue, max_id = 0;
/* compute the residues */
for (diskP = DiskPartitionList; diskP; diskP = diskP->next) {
static void *
VShutdownThread(void * args)
{
- struct rx_queue *qp;
- Volume * vp;
vshutdown_thread_t * params;
- int part, code, found, pass, schedule_version_save, count;
+ int found, pass, schedule_version_save, count;
struct DiskPartition64 *diskP;
struct diskpartition_queue_t * dpq;
Device id;
int
VShutdownByPartition_r(struct DiskPartition64 * dp)
{
- int pass, retVal;
+ int pass;
int pass_stats[4];
int total;
Log("VShutdownByPartition: shut down %d volumes on %s (pass[0]=%d, pass[1]=%d, pass[2]=%d, pass[3]=%d)\n",
total, VPartitionPath(dp), pass_stats[0], pass_stats[1], pass_stats[2], pass_stats[3]);
- return retVal;
+ return 0;
}
/* internal shutdown functionality
switch(V_attachState(vp)) {
case VOL_STATE_SALVAGING:
- /* make sure salvager knows we don't want
- * the volume back */
- VCancelSalvage_r(vp, SALVSYNC_SHUTDOWN);
+ /* Leave salvaging volumes alone. Any in-progress salvages will
+ * continue working after viced shuts down. This is intentional.
+ */
+
case VOL_STATE_PREATTACHED:
case VOL_STATE_ERROR:
VChangeState_r(vp, VOL_STATE_UNATTACHED);
VOffline_r(vp, "File server was shut down");
}
break;
+ default:
+ break;
}
VCancelReservation_r(vp);
VolumeHeaderToDisk(VolumeDiskHeader_t * dh, VolumeHeader_t * h)
{
- memset((char *)dh, 0, sizeof(VolumeDiskHeader_t));
+ memset(dh, 0, sizeof(VolumeDiskHeader_t));
dh->stamp = h->stamp;
dh->id = h->id;
dh->parent = h->parent;
void
DiskToVolumeHeader(VolumeHeader_t * h, VolumeDiskHeader_t * dh)
{
- memset((char *)h, 0, sizeof(VolumeHeader_t));
+ memset(h, 0, sizeof(VolumeHeader_t));
h->stamp = dh->stamp;
h->id = dh->id;
h->parent = dh->parent;
char path[64];
int isbusy = 0;
VolId volumeId;
- Volume * nvp;
+ Volume * nvp = NULL;
VolumeStats stats_save;
*ec = 0;
}
#ifdef AFS_DEMAND_ATTACH_FS
+# ifdef FSSYNC_BUILD_CLIENT
disk_header_loaded:
+#endif
if (!*ec) {
/* check for pending volume operations */
break;
case FSSYNC_VolOpRunningUnknown:
- vp->pending_vol_op->vol_op_state =
- (VVolOpLeaveOnline_r(vp, vp->pending_vol_op) ?
- FSSYNC_VolOpRunningOnline : FSSYNC_VolOpRunningOffline);
- /* fall through */
+ if (VVolOpLeaveOnline_r(vp, vp->pending_vol_op)) {
+ vp->pending_vol_op->vol_op_state = FSSYNC_VolOpRunningOnline;
+ break;
+ } else {
+ vp->pending_vol_op->vol_op_state = FSSYNC_VolOpRunningOffline;
+ /* fall through to take volume offline */
+ }
case FSSYNC_VolOpRunningOffline:
/* mark the volume down */
if (VVolOpSetVBusy_r(vp, vp->pending_vol_op)) {
vp->specialStatus = VBUSY;
}
+ default:
+ break;
}
}
* area and mark it as initialized.
*/
if (!(V_stat_initialized(vp))) {
- memset((char *)(V_stat_area(vp)), 0, VOL_STATS_BYTES);
+ memset((V_stat_area(vp)), 0, VOL_STATS_BYTES);
V_stat_initialized(vp) = 1;
}
#endif /* OPENAFS_VOL_STATS */
*/
/* only valid before/during demand attachment */
- assert(!vp->pending_vol_op || vp->pending_vol_op != FSSYNC_VolOpRunningUnknown);
+ assert(!vp->pending_vol_op || vp->pending_vol_op->vol_op_state != FSSYNC_VolOpRunningUnknown);
/* deny getvolume due to running mutually exclusive vol op */
if (vp->pending_vol_op && vp->pending_vol_op->vol_op_state==FSSYNC_VolOpRunningOffline) {
void
VOffline_r(Volume * vp, char *message)
{
+#ifndef AFS_DEMAND_ATTACH_FS
Error error;
VolumeId vid = V_id(vp);
+#endif
assert(programType != volumeUtility);
if (!V_inUse(vp)) {
if ((programType != fileServer) &&
(V_inUse(vp) == programType) &&
((V_checkoutMode(vp) == V_VOLUPD) ||
+ (V_checkoutMode(vp) == V_SECRETLY) ||
((V_checkoutMode(vp) == V_CLONE) &&
(VolumeWriteable(vp))))) {
V_inUse(vp) = 0;
if ((programType != fileServer) &&
(V_inUse(vp) == programType) &&
((V_checkoutMode(vp) == V_VOLUPD) ||
+ (V_checkoutMode(vp) == V_SECRETLY) ||
((V_checkoutMode(vp) == V_CLONE) &&
(VolumeWriteable(vp))))) {
V_inUse(vp) = 0;
static int
VCheckOffline(register Volume * vp)
{
- Volume * rvp = NULL;
int ret = 0;
if (vp->goingOffline && !vp->nUsers) {
vp->salvage.requested = 1;
vp->salvage.reason = reason;
vp->stats.last_salvage = FT_ApproxTime();
+ if (VIsSalvager(V_inUse(vp))) {
+ Log("VRequestSalvage: volume %u appears to be salvaging, but we\n", vp->hashid);
+ Log(" didn't request a salvage. Forcing it offline waiting for the\n");
+ Log(" salvage to finish; if you are sure no salvage is running,\n");
+ Log(" run a salvage manually.\n");
+
+ /* make sure neither VScheduleSalvage_r nor
+ * VUpdateSalvagePriority_r try to schedule another salvage */
+ vp->salvage.requested = vp->salvage.scheduled = 0;
+
+ /* these stats aren't correct, but doing this makes them
+ * slightly closer to being correct */
+ vp->stats.salvages++;
+ vp->stats.last_salvage_req = FT_ApproxTime();
+ IncUInt64(&VStats.salvages);
+
+ VChangeState_r(vp, VOL_STATE_ERROR);
+ *ec = VSALVAGE;
+ code = 1;
+
+ } else if (vp->stats.salvages < SALVAGE_COUNT_MAX) {
+ VChangeState_r(vp, VOL_STATE_SALVAGING);
+ *ec = VSALVAGING;
+ } else {
+ Log("VRequestSalvage: volume %u online salvaged too many times; forced offline.\n", vp->hashid);
+ VChangeState_r(vp, VOL_STATE_ERROR);
+ *ec = VSALVAGE;
+ code = 1;
+ }
if (flags & VOL_SALVAGE_INVALIDATE_HEADER) {
/* Instead of ReleaseVolumeHeader, we do FreeVolumeHeader()
so that the the next VAttachVolumeByVp_r() invocation
*/
FreeVolumeHeader(vp);
}
- if (vp->stats.salvages < SALVAGE_COUNT_MAX) {
- VChangeState_r(vp, VOL_STATE_SALVAGING);
- *ec = VSALVAGING;
- } else {
- Log("VRequestSalvage: volume %u online salvaged too many times; forced offline.\n", vp->hashid);
- VChangeState_r(vp, VOL_STATE_ERROR);
- *ec = VSALVAGE;
- code = 1;
- }
}
return code;
}
static int
VUpdateSalvagePriority_r(Volume * vp)
{
- int code, ret=0;
- afs_uint32 now;
+ int ret=0;
#ifdef SALVSYNC_BUILD_CLIENT
+ afs_uint32 now;
+ int code;
+
vp->salvage.prio++;
now = FT_ApproxTime();
}
+#ifdef SALVSYNC_BUILD_CLIENT
/**
* schedule a salvage with the salvage server.
*
static int
VScheduleSalvage_r(Volume * vp)
{
- int code, ret=0;
-#ifdef SALVSYNC_BUILD_CLIENT
+ int ret=0;
+ int code;
VolState state_save;
VThreadOptions_t * thread_opts;
char partName[16];
if (thread_opts == NULL) {
thread_opts = &VThread_defaults;
}
- if (thread_opts->disallow_salvsync) {
+ if (thread_opts->disallow_salvsync || vol_disallow_salvsync) {
return 1;
}
}
}
}
-#endif /* SALVSYNC_BUILD_CLIENT */
- return ret;
-}
-
-/**
- * ask salvageserver to cancel a scheduled salvage operation.
- *
- * @param[in] vp pointer to volume object
- * @param[in] reason SALVSYNC protocol reason code
- *
- * @return operation status
- * @retval 0 success
- * @retval 1 request failed
- *
- * @pre VOL_LOCK is held.
- *
- * @post salvageserver is sent a request to cancel the volume salvage.
- * volume is transitioned to a hard error state.
- *
- * @internal volume package internal use only.
- */
-static int
-VCancelSalvage_r(Volume * vp, int reason)
-{
- int code, ret = 0;
-
-#ifdef SALVSYNC_BUILD_CLIENT
- if (vp->salvage.scheduled) {
- VChangeState_r(vp, VOL_STATE_SALVSYNC_REQ);
- VOL_UNLOCK;
-
- /* can't use V_id() since there's no guarantee
- * we have the disk data header at this point */
- code = SALVSYNC_SalvageVolume(vp->hashid,
- VPartitionPath(vp->partition),
- SALVSYNC_CANCEL,
- reason,
- 0,
- NULL);
-
- VOL_LOCK;
- VChangeState_r(vp, VOL_STATE_ERROR);
-
- if (code == SYNC_OK) {
- vp->salvage.scheduled = 0;
- vp->salvage.requested = 0;
- } else {
- ret = 1;
- }
- }
-#endif /* SALVSYNC_BUILD_CLIENT */
return ret;
}
-
-#ifdef SALVSYNC_BUILD_CLIENT
/**
* connect to the salvageserver SYNC service.
*
int
VDisconnectSALV(void)
{
- int retVal;
VOL_LOCK;
VDisconnectSALV_r();
VOL_UNLOCK;
- return retVal;
+ return 0;
}
/**
*ec = 0;
name[0] = '/';
- (void)afs_snprintf(&name[1], (sizeof name) - 1, VFORMAT, afs_cast_uint32(volumeId));
+ (void)afs_snprintf(&name[1], (sizeof name) - 1, VFORMAT, afs_printable_uint32_lu(volumeId));
for (dp = DiskPartitionList; dp; dp = dp->next) {
struct afs_stat status;
strcpy(path, VPartitionPath(dp));
VolumeExternalName(VolumeId volumeId)
{
static char name[VMAXPATHLEN];
- (void)afs_snprintf(name, sizeof name, VFORMAT, afs_cast_uint32(volumeId));
+ (void)afs_snprintf(name, sizeof name, VFORMAT, afs_printable_uint32_lu(volumeId));
return name;
}
static int
VolumeExternalName_r(VolumeId volumeId, char * name, size_t len)
{
- return afs_snprintf(name, len, VFORMAT, afs_cast_uint32(volumeId));
+ return afs_snprintf(name, len, VFORMAT, afs_printable_uint32_lu(volumeId));
}
#endif
* All we need to do is bzero the entire VOL_STATS_BYTES of
* the detailed volume statistics area.
*/
- memset((char *)(V_stat_area(vp)), 0, VOL_STATS_BYTES);
+ memset((V_stat_area(vp)), 0, VOL_STATS_BYTES);
#endif /* OPENAFS_VOL_STATS */
}
VBumpVolumeUsage_r(register Volume * vp)
{
unsigned int now = FT_ApproxTime();
+ V_accessDate(vp) = now;
if (now - V_dayUseDate(vp) > OneDay)
VAdjustVolumeStatistics_r(vp);
/*
* @internal volume package interal use only.
*/
static void
-VLRU_Init_Node_r(volatile Volume * vp)
+VLRU_Init_Node_r(Volume * vp)
{
if (!VLRU_enabled)
return;
* @internal volume package internal use only.
*/
static void
-VLRU_Add_r(volatile Volume * vp)
+VLRU_Add_r(Volume * vp)
{
int idx;
VolState state_save;
* @internal volume package internal use only.
*/
static void
-VLRU_Delete_r(volatile Volume * vp)
+VLRU_Delete_r(Volume * vp)
{
int idx;
* @internal volume package internal use only.
*/
static void
-VLRU_UpdateAccess_r(volatile Volume * vp)
+VLRU_UpdateAccess_r(Volume * vp)
{
- afs_uint32 live_interval;
Volume * rvp = NULL;
if (!VLRU_enabled)
* @internal volume package internal use only.
*/
static void
-VLRU_SwitchQueues(volatile Volume * vp, int new_idx, int append)
+VLRU_SwitchQueues(Volume * vp, int new_idx, int append)
{
if (queue_IsNotOnQueue(&vp->vlru))
return;
VLRU_ScannerThread(void * args)
{
afs_uint32 now, min_delay, delay;
- afs_uint32 next_scan[VLRU_GENERATIONS];
- afs_uint32 next_promotion[VLRU_GENERATIONS];
int i, min_idx, min_op, overdue, state;
/* set t=0 for promotion cycle to be
int len, chaining, promote;
afs_uint32 now, thresh;
struct rx_queue *qp, *nqp;
- Volume * vp, *start, *end;
+ Volume * vp, *start = NULL, *end = NULL;
/* get exclusive access to two chains, and drop the glock */
VLRU_Wait_r(&volume_LRU.q[idx]);
int len, chaining, demote;
afs_uint32 now, thresh;
struct rx_queue *qp, *nqp;
- Volume * vp, *start, *end;
+ Volume * vp, *start = NULL, *end = NULL;
Volume ** salv_flag_vec = NULL;
int salv_vec_offset = 0;
{
afs_uint32 now, thresh;
struct rx_queue *qp, *nqp;
- volatile Volume * vp;
+ Volume * vp;
int i, locked = 1;
assert(idx == VLRU_QUEUE_NEW || idx == VLRU_QUEUE_CANDIDATE);
/* check whether volume is safe to soft detach
* caller MUST NOT hold a ref count on vp */
static int
-VCheckSoftDetach(volatile Volume * vp, afs_uint32 thresh)
+VCheckSoftDetach(Volume * vp, afs_uint32 thresh)
{
int ret=0;
/* check whether volume should be made a
* soft detach candidate */
static int
-VCheckSoftDetachCandidate(volatile Volume * vp, afs_uint32 thresh)
+VCheckSoftDetachCandidate(Volume * vp, afs_uint32 thresh)
{
int idx, ret = 0;
if (vp->nUsers || vp->nWaiters)
*
* caller MUST NOT hold a ref count on vp */
static int
-VSoftDetachVolume_r(volatile Volume * vp, afs_uint32 thresh)
+VSoftDetachVolume_r(Volume * vp, afs_uint32 thresh)
{
afs_uint32 ts_save;
int ret = 0;
V_attachFlags(vp) &= ~(VOL_ON_VLRU);
VCancelReservation_r(vp);
return 0;
+ default:
+ break;
}
/* hold the volume and take it offline.
static int everLogged = 0;
#ifdef AFS_DEMAND_ATTACH_FS
- VolState vp_save, back_save;
+ VolState vp_save = 0, back_save = 0;
/* XXX debug 9/19/05 we've apparently got
* a ref counting bug somewhere that's
void
VPrintExtendedCacheStats_r(int flags)
{
- int i, j;
+ int i;
afs_uint32 vol_sum = 0;
struct stats {
double min;