2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2006-2008 Sine Nomine Associates
15 Institution: The Information Technology Center, Carnegie-Mellon University
22 #include <afs/afssyscalls.h>
25 #define VolumeWriteable(vp) (V_type(vp)==readwriteVolume)
26 #define VolumeWriteable2(vol) (vol.type == readwriteVolume)
27 typedef bit32 FileOffset; /* Offset in this file */
28 #define Date afs_uint32
29 #include "daemon_com.h"
33 /** turn this on if you suspect a volume package locking bug */
34 #define VOL_LOCK_DEBUG 1
38 #define VOL_LOCK_ASSERT_HELD \
39 assert(vol_glock_holder == pthread_self())
40 #define VOL_LOCK_ASSERT_UNHELD \
41 assert(vol_glock_holder == 0)
42 #define _VOL_LOCK_SET_HELD \
43 vol_glock_holder = pthread_self()
44 #define _VOL_LOCK_SET_UNHELD \
46 #define VOL_LOCK_DBG_CV_WAIT_END \
48 VOL_LOCK_ASSERT_UNHELD; \
51 #define VOL_LOCK_DBG_CV_WAIT_BEGIN \
53 VOL_LOCK_ASSERT_HELD; \
54 _VOL_LOCK_SET_UNHELD; \
57 #define VOL_LOCK_ASSERT_HELD
58 #define VOL_LOCK_ASSERT_UNHELD
59 #define VOL_LOCK_DBG_CV_WAIT_BEGIN
60 #define VOL_LOCK_DBG_CV_WAIT_END
64 #ifdef AFS_PTHREAD_ENV
67 extern pthread_mutex_t vol_glock_mutex;
68 extern pthread_mutex_t vol_trans_mutex;
69 extern pthread_cond_t vol_put_volume_cond;
70 extern pthread_cond_t vol_sleep_cond;
71 extern pthread_cond_t vol_vinit_cond;
72 extern ih_init_params vol_io_params;
73 extern int vol_attach_threads;
75 extern pthread_t vol_glock_holder;
78 assert(pthread_mutex_lock(&vol_glock_mutex) == 0); \
79 assert(vol_glock_holder == 0); \
80 vol_glock_holder = pthread_self(); \
84 VOL_LOCK_ASSERT_HELD; \
85 vol_glock_holder = 0; \
86 assert(pthread_mutex_unlock(&vol_glock_mutex) == 0); \
88 #define VOL_CV_WAIT(cv) \
90 VOL_LOCK_DBG_CV_WAIT_BEGIN; \
91 assert(pthread_cond_wait((cv), &vol_glock_mutex) == 0); \
92 VOL_LOCK_DBG_CV_WAIT_END; \
94 #else /* !VOL_LOCK_DEBUG */
96 assert(pthread_mutex_lock(&vol_glock_mutex) == 0)
98 assert(pthread_mutex_unlock(&vol_glock_mutex) == 0)
99 #define VOL_CV_WAIT(cv) assert(pthread_cond_wait((cv), &vol_glock_mutex) == 0)
100 #endif /* !VOL_LOCK_DEBUG */
101 #define VSALVSYNC_LOCK \
102 assert(pthread_mutex_lock(&vol_salvsync_mutex) == 0)
103 #define VSALVSYNC_UNLOCK \
104 assert(pthread_mutex_unlock(&vol_salvsync_mutex) == 0)
105 #define VTRANS_LOCK \
106 assert(pthread_mutex_lock(&vol_trans_mutex) == 0)
107 #define VTRANS_UNLOCK \
108 assert(pthread_mutex_unlock(&vol_trans_mutex) == 0)
109 #else /* AFS_PTHREAD_ENV */
112 #define VSALVSYNC_LOCK
113 #define VSALVSYNC_UNLOCK
115 #define VTRANS_UNLOCK
116 #endif /* AFS_PTHREAD_ENV */
119 * volume package program type enumeration.
122 fileServer = 1, /**< the fileserver process */
123 volumeUtility = 2, /**< any miscellaneous volume utility */
124 salvager = 3, /**< standalone whole-partition salvager */
125 salvageServer = 4, /**< dafs online salvager */
126 debugUtility = 5, /**< fssync-debug or similar utility */
127 volumeServer = 6, /**< the volserver process */
128 volumeSalvager = 7, /**< the standalone single-volume salvager */
130 extern ProgramType programType; /* The type of program using the package */
132 /* Some initialization parameters for the volume package */
133 /* Add new initialization parameters here */
134 extern int (*V_BreakVolumeCallbacks) (VolumeId);
135 extern int (*vol_PollProc) (void);
137 #define DOPOLL ((vol_PollProc)? (*vol_PollProc)() : 0)
139 #ifdef AFS_DEMAND_ATTACH_FS
141 * variable error return code based upon programType and DAFS presence
143 #define DAFS_VSALVAGE ((programType == fileServer) ? VSALVAGING : VSALVAGE)
145 #define DAFS_VSALVAGE (VSALVAGE)
148 struct versionStamp { /* Version stamp for critical volume files */
149 bit32 magic; /* Magic number */
150 bit32 version; /* Version number of this file, or software
151 * that created this file */
154 #ifdef AFS_DEMAND_ATTACH_FS
156 * demand attach volume state enumeration.
158 * @note values must be contiguous in order for VIsValidState() to work correctly
161 VOL_STATE_UNATTACHED = 0, /**< volume is unattached */
162 VOL_STATE_PREATTACHED = 1, /**< volume has been pre-attached */
163 VOL_STATE_ATTACHING = 2, /**< volume is transitioning to fully attached */
164 VOL_STATE_ATTACHED = 3, /**< volume has been fully attached */
165 VOL_STATE_UPDATING = 4, /**< volume is updating on-disk structures */
166 VOL_STATE_GET_BITMAP = 5, /**< volume is getting bitmap entries */
167 VOL_STATE_HDR_LOADING = 6, /**< volume is loading disk header */
168 VOL_STATE_HDR_ATTACHING = 7, /**< volume is getting a header from the LRU */
169 VOL_STATE_SHUTTING_DOWN = 8, /**< volume is shutting down */
170 VOL_STATE_GOING_OFFLINE = 9, /**< volume is going offline */
171 VOL_STATE_OFFLINING = 10, /**< volume is transitioning to offline */
172 VOL_STATE_DETACHING = 11, /**< volume is transitioning to detached */
173 VOL_STATE_SALVSYNC_REQ = 12, /**< volume is blocked on a salvsync request */
174 VOL_STATE_SALVAGING = 13, /**< volume is being salvaged */
175 VOL_STATE_ERROR = 14, /**< volume is in an error state */
176 VOL_STATE_VNODE_ALLOC = 15, /**< volume is busy allocating a new vnode */
177 VOL_STATE_VNODE_GET = 16, /**< volume is busy getting vnode disk data */
178 VOL_STATE_VNODE_CLOSE = 17, /**< volume is busy closing vnodes */
179 VOL_STATE_VNODE_RELEASE = 18, /**< volume is busy releasing vnodes */
180 VOL_STATE_VLRU_ADD = 19, /**< volume is busy being added to a VLRU queue */
181 VOL_STATE_DELETED = 20, /**< volume has been deleted by the volserver */
182 /* please add new states directly above this line */
183 VOL_STATE_FREED = 21, /**< debugging aid */
184 VOL_STATE_COUNT = 22, /**< total number of valid states */
188 * V_attachFlags bits.
191 VOL_HDR_ATTACHED = 0x1, /**< volume header is attached to Volume struct */
192 VOL_HDR_LOADED = 0x2, /**< volume header contents are valid */
193 VOL_HDR_IN_LRU = 0x4, /**< volume header is in LRU */
194 VOL_IN_HASH = 0x8, /**< volume is in hash table */
195 VOL_ON_VBYP_LIST = 0x10, /**< volume is on VByP list */
196 VOL_IS_BUSY = 0x20, /**< volume is not to be free()d */
197 VOL_ON_VLRU = 0x40, /**< volume is on the VLRU */
198 VOL_HDR_DONTSALV = 0x80, /**< volume header DONTSALVAGE flag is set */
199 VOL_LOCKED = 0x100, /**< volume is disk-locked (@see VLockVolumeNB) */
202 /* VPrintExtendedCacheStats flags */
203 #define VOL_STATS_PER_CHAIN 0x1 /**< compute simple per-chain stats */
204 #define VOL_STATS_PER_CHAIN2 0x2 /**< compute per-chain stats that require scanning
205 * every element of the chain */
207 /* VLRU_SetOptions options */
208 #define VLRU_SET_THRESH 1
209 #define VLRU_SET_INTERVAL 2
210 #define VLRU_SET_MAX 3
211 #define VLRU_SET_ENABLED 4
217 VLRU_QUEUE_NEW = 0, /**< LRU queue for new volumes */
218 VLRU_QUEUE_MID = 1, /**< survivor generation */
219 VLRU_QUEUE_OLD = 2, /**< old generation */
220 VLRU_QUEUE_CANDIDATE = 3, /**< soft detach candidate pool */
221 VLRU_QUEUE_HELD = 4, /* volumes which are not allowed
222 * to be soft detached */
223 VLRU_QUEUE_INVALID = 5, /**< invalid queue id */
226 /* default scanner timing parameters */
227 #define VLRU_DEFAULT_OFFLINE_THRESH (60*60*2) /* 2 hours */
228 #define VLRU_DEFAULT_OFFLINE_INTERVAL (60*2) /* 2 minutes */
229 #define VLRU_DEFAULT_OFFLINE_MAX 8 /* 8 volumes */
233 * DAFS thread-specific options structure
235 typedef struct VThreadOptions {
236 int disallow_salvsync; /**< whether or not salvsync calls are allowed
237 * on this thread (deadlock prevention). */
239 extern pthread_key_t VThread_key;
240 extern VThreadOptions_t VThread_defaults;
242 #endif /* AFS_DEMAND_ATTACH_FS */
244 typedef struct VolumePackageOptions {
245 afs_uint32 nLargeVnodes; /**< size of large vnode cache */
246 afs_uint32 nSmallVnodes; /**< size of small vnode cache */
247 afs_uint32 volcache; /**< size of volume header cache */
249 afs_int32 canScheduleSalvage; /**< can we schedule salvages? (DAFS) */
250 /* (if 'no', we will just error out if we
252 afs_int32 canUseFSSYNC; /**< can we use the FSSYNC channel? */
253 afs_int32 canUseSALVSYNC; /**< can we use the SALVSYNC channel? (DAFS) */
254 afs_int32 unsafe_attach; /**< can we bypass checking the inUse vol
255 * header on attach? */
256 } VolumePackageOptions;
258 /* Magic numbers and version stamps for each type of file */
259 #define VOLUMEHEADERMAGIC ((bit32)0x88a1bb3c)
260 #define VOLUMEINFOMAGIC ((bit32)0x78a1b2c5)
261 #define SMALLINDEXMAGIC 0x99776655
262 #define LARGEINDEXMAGIC 0x88664433
263 #define MOUNTMAGIC 0x9a8b7c6d
264 #define ACLMAGIC 0x88877712
265 #define LINKTABLEMAGIC 0x99877712
267 #define VOLUMEHEADERVERSION 1
268 #define VOLUMEINFOVERSION 1
269 #define SMALLINDEXVERSION 1
270 #define LARGEINDEXVERSION 1
271 #define MOUNTVERSION 1
273 #define LINKTABLEVERSION 1
276 * Define whether we are keeping detailed statistics on volume dealings.
278 #define OPENAFS_VOL_STATS 1
280 #if OPENAFS_VOL_STATS
282 * Define various indices and counts used in keeping volume-level statistics.
284 #define VOL_STATS_NUM_RWINFO_FIELDS 4
286 #define VOL_STATS_SAME_NET 0 /*Within same site (total) */
287 #define VOL_STATS_SAME_NET_AUTH 1 /*Within same site (authenticated);
288 * (must be 1 more than above) */
289 #define VOL_STATS_DIFF_NET 2 /*From external site (total) */
290 #define VOL_STATS_DIFF_NET_AUTH 3 /*From external site (authenticated)
291 * (must be 1 more than above) */
293 #define VOL_STATS_NUM_TIME_RANGES 6
295 #define VOL_STATS_TIME_CAP_0 60 /*60 seconds */
296 #define VOL_STATS_TIME_CAP_1 600 /*10 minutes, in seconds */
297 #define VOL_STATS_TIME_CAP_2 3600 /*1 hour, in seconds */
298 #define VOL_STATS_TIME_CAP_3 86400 /*1 day, in seconds */
299 #define VOL_STATS_TIME_CAP_4 604800 /*1 week, in seconds */
301 #define VOL_STATS_NUM_TIME_FIELDS 6
303 #define VOL_STATS_TIME_IDX_0 0 /*0 secs to 60 secs */
304 #define VOL_STATS_TIME_IDX_1 1 /*1 min to 10 mins */
305 #define VOL_STATS_TIME_IDX_2 2 /*10 mins to 60 mins */
306 #define VOL_STATS_TIME_IDX_3 3 /*1 hr to 24 hrs */
307 #define VOL_STATS_TIME_IDX_4 4 /*1 day to 7 days */
308 #define VOL_STATS_TIME_IDX_5 5 /*Greater than 1 week */
309 #endif /* OPENAFS_VOL_STATS */
311 /* Volume header. This is the contents of the named file representing
312 * the volume. Read-only by the file server!
314 typedef struct VolumeHeader {
315 struct versionStamp stamp; /* Must be first field */
316 VolumeId id; /* Volume number */
317 VolumeId parent; /* Read-write volume number (or this volume
318 * number if this is a read-write volume) */
320 Inode smallVnodeIndex;
321 Inode largeVnodeIndex;
323 Inode volumeMountTable;
328 typedef struct VolumeDiskHeader {
329 struct versionStamp stamp; /* Must be first field */
330 VolumeId id; /* Volume number */
331 VolumeId parent; /* Read-write volume number (or this volume
332 * number if this is a read-write volume) */
333 afs_int32 volumeInfo_lo;
334 afs_int32 smallVnodeIndex_lo;
335 afs_int32 largeVnodeIndex_lo;
336 afs_int32 volumeAcl_lo;
337 afs_int32 volumeMountTable_lo;
338 afs_int32 volumeInfo_hi;
339 afs_int32 smallVnodeIndex_hi;
340 afs_int32 largeVnodeIndex_hi;
341 afs_int32 volumeAcl_hi;
342 afs_int32 volumeMountTable_hi;
343 afs_int32 linkTable_lo;
344 afs_int32 linkTable_hi;
345 /* If you add fields, add them before here and reduce the size of array */
347 } VolumeDiskHeader_t;
349 /* A vnode index file header */
350 struct IndexFileHeader {
351 struct versionStamp stamp;
355 /******************************************************************************/
356 /* Volume Data which is stored on disk and can also be maintained in memory. */
357 /******************************************************************************/
358 typedef struct VolumeDiskData {
359 struct versionStamp stamp; /* Must be first field */
360 VolumeId id; /* Volume id--unique over all systems */
361 #define VNAMESIZE 32 /* including 0 byte */
362 char name[VNAMESIZE]; /* Unofficial name for the volume */
363 byte inUse; /* Volume is being used (perhaps it is online),
364 * or the system crashed while it was used */
365 byte inService; /* Volume in service, not necessarily on line
366 * This bit is set by an operator/system
367 * programmer. Manually taking a volume offline
368 * always clears the inService bit. Taking
369 * it out of service also takes it offline */
370 byte blessed; /* Volume is administratively blessed with
371 * the ability to go on line. Set by a system
372 * administrator. Clearing this bit will
373 * take the volume offline */
374 byte needsSalvaged; /* Volume needs salvaged--an unrecoverable
375 * error occured to the volume. Note: a volume
376 * may still require salvage even if this
377 * flag isn't set--e.g. if a system crash
378 * occurred while the volume was on line. */
379 bit32 uniquifier; /* Next vnode uniquifier for this volume */
381 VolId parentId; /* Id of parent, if type==readonly */
382 VolId cloneId; /* Latest read-only clone, if type==readwrite,
383 * 0 if the volume has never been cloned. Note: the
384 * indicated volume does not necessarily exist (it
385 * may have been deleted since cloning). */
386 VolId backupId; /* Latest backup copy of this read write volume */
387 VolId restoredFromId; /* The id in the dump this volume was restored from--used simply
388 * to make sure that an incremental dump is not restored on top
389 * of something inappropriate: Note: this field itself is NEVER
391 byte needsCallback; /* Set by the salvager if anything was changed
392 * about the volume. Note: this is not set by
393 * clone/makebackups when setting the copy-on-write
394 * flag in directories; this flag is not seen by
396 #define DESTROY_ME 0xD3
397 byte destroyMe; /* If this is set to DESTROY_ME, then the salvager should destroy
398 * this volume; it is bogus (left over from an aborted volume move,
399 * for example). Note: if this flag is on, then inService should
400 * be OFF--only the salvager checks this flag */
401 #ifdef ALPHA_DUX40_ENV
402 #define DONT_SALVAGE 0xE6
403 #else /* ALPHA_DUX40_ENV */
404 #define DONT_SALVAGE 0xE5
405 #endif /* ALPHA_DUX40_ENV */
406 byte dontSalvage; /* If this is on, then don't bother salvaging this volume */
412 /* Administrative stuff */
413 int maxquota; /* Quota maximum, 1K blocks */
414 int minquota; /* Quota minimum, 1K blocks */
415 int maxfiles; /* Maximum number of files (i.e. inodes) */
416 bit32 accountNumber; /* Uninterpreted account number */
417 bit32 owner; /* The person administratively responsible
419 int reserved2[8]; /* Other administrative constraints */
421 /* Resource usage & statistics */
422 int filecount; /* Actual number of files */
423 int diskused; /* Actual disk space used, 1K blocks */
424 int dayUse; /* Metric for today's usage of this volume so far */
425 int weekUse[7]; /* Usage of the volume for the last week.
426 * weekUse[0] is for most recent complete 24 hour period
427 * of measurement; week[6] is 7 days ago */
428 Date dayUseDate; /* Date the dayUse statistics refer to; the week use stats
429 * are the preceding 7 days */
430 unsigned int volUpdateCounter; /*incremented at every update of volume*/
431 int reserved3[10]; /* Other stats here */
433 /* Server supplied dates */
434 Date creationDate; /* Creation date for a read/write
435 * volume; cloning date for original copy of
436 * a readonly volume (replicated volumes have
437 * the same creation date) */
438 Date accessDate; /* Last access time by a user, large granularity */
439 Date updateDate; /* Last modification by user */
440 Date expirationDate; /* 0 if it never expires */
441 Date backupDate; /* last time a backup clone was taken */
443 /* Time that this copy of this volume was made. NEVER backed up. This field is only
444 * set when the copy is created */
447 #if OPENAFS_VOL_STATS
448 bit32 stat_initialized; /*Are the stat fields below set up? */
452 #endif /* OPENAFS_VOL_STATS */
456 char offlineMessage[VMSGSIZE]; /* Why the volume is offline */
457 #if OPENAFS_VOL_STATS
458 #define VOL_STATS_BYTES 128
460 * Keep per-volume aggregate statistics on type and distance of access,
461 * along with authorship info.
463 bit32 stat_reads[VOL_STATS_NUM_RWINFO_FIELDS];
464 bit32 stat_writes[VOL_STATS_NUM_RWINFO_FIELDS];
465 bit32 stat_fileSameAuthor[VOL_STATS_NUM_TIME_FIELDS];
466 bit32 stat_fileDiffAuthor[VOL_STATS_NUM_TIME_FIELDS];
467 bit32 stat_dirSameAuthor[VOL_STATS_NUM_TIME_FIELDS];
468 bit32 stat_dirDiffAuthor[VOL_STATS_NUM_TIME_FIELDS];
470 char motd[VMSGSIZE]; /* Volume "message of the day" */
471 #endif /* OPENAFS_VOL_STATS */
476 /**************************************/
477 /* Memory resident volume information */
478 /**************************************/
481 * global volume package stats.
483 typedef struct VolPkgStats {
484 #ifdef AFS_DEMAND_ATTACH_FS
487 * extended volume package statistics
491 afs_uint32 state_levels[VOL_STATE_COUNT]; /**< volume state transition counters */
494 afs_uint64 hash_looks; /**< number of hash chain element traversals */
495 afs_uint64 hash_reorders; /**< number of hash chain reorders */
496 afs_uint64 salvages; /**< online salvages since fileserver start */
497 afs_uint64 vol_ops; /**< volume operations since fileserver start */
498 #endif /* AFS_DEMAND_ATTACH_FS */
500 afs_uint64 hdr_loads; /**< header loads from disk */
501 afs_uint64 hdr_gets; /**< header pulls out of LRU */
502 afs_uint64 attaches; /**< volume attaches since fileserver start */
503 afs_uint64 soft_detaches; /**< soft detach ops since fileserver start */
505 /* configuration parameters */
506 afs_uint32 hdr_cache_size; /**< size of volume header cache */
508 extern VolPkgStats VStats;
511 * volume header cache supporting structures
513 struct volume_hdr_LRU_stats {
519 struct volume_hdr_LRU_t {
521 struct volume_hdr_LRU_stats stats;
523 extern struct volume_hdr_LRU_t volume_hdr_LRU;
526 * volume hash chain supporting structures
528 typedef struct VolumeHashChainHead {
529 struct rx_queue queue;
531 /* someday we could put a per-chain lock here... */
532 #ifdef AFS_DEMAND_ATTACH_FS
536 /* per-chain statistics */
541 pthread_cond_t chain_busy_cv;
542 #endif /* AFS_DEMAND_ATTACH_FS */
543 } VolumeHashChainHead;
545 typedef struct VolumeHashTable {
548 VolumeHashChainHead * Table;
550 extern VolumeHashTable_t VolumeHashTable;
552 struct VolumeHashChainStats {
553 afs_int32 table_size;
555 #ifdef AFS_DEMAND_ATTACH_FS
556 afs_int32 chain_cacheCheck;
557 afs_int32 chain_busy;
558 afs_uint64 chain_looks;
559 afs_uint64 chain_gets;
560 afs_uint64 chain_reorders;
565 #ifdef AFS_DEMAND_ATTACH_FS
567 * DAFS extended per-volume statistics.
569 * @note this data lives across the entire
570 * lifetime of the fileserver process
572 typedef struct VolumeStats {
574 afs_uint64 hash_lookups; /**< hash table lookups */
575 afs_uint64 hash_short_circuits; /**< short circuited hash lookups (due to cacheCheck) */
576 afs_uint64 hdr_loads; /**< header loads from disk */
577 afs_uint64 hdr_gets; /**< header pulls out of LRU */
578 afs_uint16 attaches; /**< attaches of this volume since fileserver start */
579 afs_uint16 soft_detaches; /**< soft detaches of this volume */
580 afs_uint16 salvages; /**< online salvages since fileserver start */
581 afs_uint16 vol_ops; /**< volume operations since fileserver start */
584 afs_uint32 last_attach; /**< unix timestamp of last VAttach */
585 afs_uint32 last_get; /**< unix timestamp of last VGet/VHold */
586 afs_uint32 last_promote; /**< unix timestamp of last VLRU promote/demote */
587 afs_uint32 last_hdr_get; /**< unix timestamp of last GetVolumeHeader() */
588 afs_uint32 last_hdr_load; /**< unix timestamp of last LoadVolumeHeader() */
589 afs_uint32 last_salvage; /**< unix timestamp of last initiation of an online salvage */
590 afs_uint32 last_salvage_req; /**< unix timestamp of last SALVSYNC request */
591 afs_uint32 last_vol_op; /**< unix timestamp of last volume operation */
595 #define SALVAGE_PRIO_UPDATE_INTERVAL 3 /**< number of seconds between prio updates */
596 #define SALVAGE_COUNT_MAX 16 /**< number of online salvages we
597 * allow before moving the volume
598 * into a permanent error state
600 * once this threshold is reached,
601 * the operator will have to manually
602 * issue a 'bos salvage' to bring
603 * the volume back online
607 * DAFS online salvager state.
609 typedef struct VolumeOnlineSalvage {
610 afs_uint32 prio; /**< number of VGetVolume's since salvage requested */
611 int reason; /**< reason for requesting online salvage */
612 byte requested; /**< flag specifying that salvage should be scheduled */
613 byte scheduled; /**< flag specifying whether online salvage scheduled */
614 byte reserved[2]; /**< padding */
615 } VolumeOnlineSalvage;
618 * DAFS Volume LRU state.
620 typedef struct VolumeVLRUState {
621 struct rx_queue lru; /**< VLRU queue for this generation */
622 VLRUQueueName idx; /**< VLRU generation index */
624 #endif /* AFS_DEMAND_ATTACH_FS */
626 typedef struct Volume {
627 struct rx_queue q; /* Volume hash chain pointers */
628 VolumeId hashid; /* Volume number -- for hash table lookup */
629 struct volHeader *header; /* Cached disk data */
630 Device device; /* Unix device for the volume */
631 struct DiskPartition64
632 *partition; /* Information about the Unix partition */
634 IHandle_t *handle; /* Unix inode holding this index */
635 byte *bitmap; /* Index bitmap */
636 afs_uint32 bitmapSize; /* length of bitmap, in bytes */
637 afs_uint32 bitmapOffset; /* Which byte address of the first long to
638 * start search from in bitmap */
639 } vnodeIndex[nVNODECLASSES];
640 IHandle_t *linkHandle;
641 Unique nextVnodeUnique; /* Derived originally from volume uniquifier.
642 * This is the actual next version number to
643 * assign; the uniquifier is bumped by 200 and
644 * and written to disk every 200 file creates
645 * If the volume is shutdown gracefully, the
646 * uniquifier should be rewritten with the
647 * value nextVnodeVersion */
648 IHandle_t *diskDataHandle; /* Unix inode holding general volume info */
649 bit16 vnodeHashOffset; /* Computed by HashOffset function in vnode.h.
650 * Assigned to the volume when initialized.
651 * Added to vnode number for hash table index */
652 byte shuttingDown; /* This volume is going to be detached */
653 byte goingOffline; /* This volume is going offline */
654 bit32 cacheCheck; /* Online sequence number to be used to invalidate vnode cache entries
655 * that stayed around while a volume was offline */
656 short nUsers; /* Number of users of this volume header */
657 byte needsPutBack; /* For a volume utility, this flag is set if we need
658 * to give the volume back when we detach it. The server has
659 * certain modes where it doesn't detach the volume, and
660 * if we give it back spuriously, the server aborts. This field
661 * is meaningless on the file server */
662 byte specialStatus; /* An error code to return on VGetVolume: the
663 * volume is unavailable for the reason quoted,
664 * currently VBUSY or VMOVED */
665 afs_uint32 checkoutMode; /* for volume utilities, mode number for current checkout */
666 afs_uint32 updateTime; /* Time that this volume was put on the updated
667 * volume list--the list of volumes that will be
668 * salvaged should the file server crash */
669 struct rx_queue vnode_list; /**< linked list of cached vnodes for this volume */
670 #ifdef AFS_DEMAND_ATTACH_FS
671 VolState attach_state; /* what stage of attachment has been completed */
672 afs_uint32 attach_flags; /* flags related to attachment state */
673 pthread_cond_t attach_cv; /* state change condition variable */
674 short nWaiters; /* volume package internal ref count */
675 int chainCacheCheck; /* Volume hash chain cache check */
676 struct rx_queue vol_list; /* per-partition volume list (VByPList) */
678 VolumeOnlineSalvage salvage; /* online salvager state */
679 VolumeStats stats; /* per-volume statistics */
680 VolumeVLRUState vlru; /* state specific to the VLRU */
681 FSSYNC_VolOp_info * pending_vol_op; /* fssync command info for any pending vol ops */
682 #endif /* AFS_DEMAND_ATTACH_FS */
687 VolumeDiskData diskstuff; /* General volume info read from disk */
688 Volume *back; /* back pointer to current volume structure */
691 /* These macros are used to export fields within the volume header. This was added
692 to facilitate changing the actual representation */
694 #define V_device(vp) ((vp)->device)
695 #define V_partition(vp) ((vp)->partition)
696 #define V_diskDataHandle(vp) ((vp)->diskDataHandle)
697 #define V_vnodeIndex(vp) ((vp)->vnodeIndex)
698 #define V_nextVnodeUnique(vp) ((vp)->nextVnodeUnique)
699 #define V_linkHandle(vp) ((vp)->linkHandle)
700 #define V_checkoutMode(vp) ((vp)->checkoutMode)
701 #ifdef AFS_DEMAND_ATTACH_FS
702 #define V_attachState(vp) ((vp)->attach_state)
703 #define V_attachFlags(vp) ((vp)->attach_flags)
704 #define V_attachCV(vp) ((vp)->attach_cv)
705 #endif /* AFS_DEMAND_ATTACH_FS */
707 /* N.B. V_id must be this, rather than vp->id, or some programs will break, probably */
708 #define V_stamp(vp) ((vp)->header->diskstuff.stamp)
709 #define V_id(vp) ((vp)->header->diskstuff.id)
710 #define V_name(vp) ((vp)->header->diskstuff.name)
711 #define V_inUse(vp) ((vp)->header->diskstuff.inUse)
712 #define V_inService(vp) ((vp)->header->diskstuff.inService)
713 #define V_blessed(vp) ((vp)->header->diskstuff.blessed)
714 #define V_needsSalvaged(vp) ((vp)->header->diskstuff.needsSalvaged)
715 #define V_uniquifier(vp) ((vp)->header->diskstuff.uniquifier)
716 #define V_type(vp) ((vp)->header->diskstuff.type)
717 #define V_parentId(vp) ((vp)->header->diskstuff.parentId)
718 #define V_cloneId(vp) ((vp)->header->diskstuff.cloneId)
719 #define V_backupId(vp) ((vp)->header->diskstuff.backupId)
720 #define V_restoredFromId(vp) ((vp)->header->diskstuff.restoredFromId)
721 #define V_needsCallback(vp) ((vp)->header->diskstuff.needsCallback)
722 #define V_destroyMe(vp) ((vp)->header->diskstuff.destroyMe)
723 #define V_dontSalvage(vp) ((vp)->header->diskstuff.dontSalvage)
724 #define V_maxquota(vp) ((vp)->header->diskstuff.maxquota)
725 #define V_minquota(vp) ((vp)->header->diskstuff.minquota)
726 #define V_maxfiles(vp) ((vp)->header->diskstuff.maxfiles)
727 #define V_accountNumber(vp) ((vp)->header->diskstuff.accountNumber)
728 #define V_owner(vp) ((vp)->header->diskstuff.owner)
729 #define V_filecount(vp) ((vp)->header->diskstuff.filecount)
730 #define V_diskused(vp) ((vp)->header->diskstuff.diskused)
731 #define V_dayUse(vp) ((vp)->header->diskstuff.dayUse)
732 #define V_weekUse(vp) ((vp)->header->diskstuff.weekUse)
733 #define V_dayUseDate(vp) ((vp)->header->diskstuff.dayUseDate)
734 #define V_creationDate(vp) ((vp)->header->diskstuff.creationDate)
735 #define V_accessDate(vp) ((vp)->header->diskstuff.accessDate)
736 #define V_updateDate(vp) ((vp)->header->diskstuff.updateDate)
737 #define V_expirationDate(vp) ((vp)->header->diskstuff.expirationDate)
738 #define V_backupDate(vp) ((vp)->header->diskstuff.backupDate)
739 #define V_copyDate(vp) ((vp)->header->diskstuff.copyDate)
740 #define V_offlineMessage(vp) ((vp)->header->diskstuff.offlineMessage)
741 #define V_disk(vp) ((vp)->header->diskstuff)
742 #define V_motd(vp) ((vp)->header->diskstuff.motd)
743 #if OPENAFS_VOL_STATS
744 #define V_stat_initialized(vp) ((vp)->header->diskstuff.stat_initialized)
745 #define V_stat_area(vp) (((vp)->header->diskstuff.stat_reads))
746 #define V_stat_reads(vp, idx) (((vp)->header->diskstuff.stat_reads)[idx])
747 #define V_stat_writes(vp, idx) (((vp)->header->diskstuff.stat_writes)[idx])
748 #define V_stat_fileSameAuthor(vp, idx) (((vp)->header->diskstuff.stat_fileSameAuthor)[idx])
749 #define V_stat_fileDiffAuthor(vp, idx) (((vp)->header->diskstuff.stat_fileDiffAuthor)[idx])
750 #define V_stat_dirSameAuthor(vp, idx) (((vp)->header->diskstuff.stat_dirSameAuthor)[idx])
751 #define V_stat_dirDiffAuthor(vp, idx) (((vp)->header->diskstuff.stat_dirDiffAuthor)[idx])
752 #endif /* OPENAFS_VOL_STATS */
753 #define V_volUpCounter(vp) ((vp)->header->diskstuff.volUpdateCounter)
755 /* File offset computations. The offset values in the volume header are
756 computed with these macros -- when the file is written only!! */
757 #define VOLUME_MOUNT_TABLE_OFFSET(Volume) (sizeof (VolumeDiskData))
758 #define VOLUME_BITMAP_OFFSET(Volume) \
759 (sizeof (VolumeDiskData) + (Volume)->disk.mountTableSize)
762 extern char *VSalvageMessage; /* Canonical message when a volume is forced
764 extern Volume *VGetVolume(Error * ec, Error * client_ec, VolId volumeId);
765 extern Volume *VGetVolumeNoWait(Error * ec, Error * client_ec, VolId volumeId);
766 extern Volume *VGetVolume_r(Error * ec, VolId volumeId);
767 extern void VPutVolume(Volume *);
768 extern void VPutVolume_r(Volume *);
769 extern void VOffline(Volume * vp, char *message);
770 extern void VOffline_r(Volume * vp, char *message);
771 extern int VConnectFS(void);
772 extern int VConnectFS_r(void);
773 extern void VDisconnectFS(void);
774 extern void VDisconnectFS_r(void);
775 extern int VChildProcReconnectFS(void);
776 extern Volume *VAttachVolume(Error * ec, VolumeId volumeId, int mode);
777 extern Volume *VAttachVolume_r(Error * ec, VolumeId volumeId, int mode);
778 extern Volume *VCreateVolume(Error * ec, char *partname, VolId volumeId,
780 extern Volume *VCreateVolume_r(Error * ec, char *partname, VolId volumeId,
782 extern int VAllocBitmapEntry(Error * ec, Volume * vp,
783 struct vnodeIndex *index);
784 extern int VAllocBitmapEntry_r(Error * ec, Volume * vp,
785 struct vnodeIndex *index, int flags);
786 extern void VFreeBitMapEntry(Error * ec, struct vnodeIndex *index,
788 extern void VFreeBitMapEntry_r(Error * ec, struct vnodeIndex *index,
790 extern int VolumeNumber(char *name);
791 extern char *VolumeExternalName(VolumeId volumeId);
792 extern int VolumeExternalName_r(VolumeId volumeId, char *name, size_t len);
793 extern Volume *VAttachVolumeByName(Error * ec, char *partition, char *name,
795 extern Volume *VAttachVolumeByName_r(Error * ec, char *partition, char *name,
797 extern void VShutdown(void);
798 extern void VSetTranquil(void);
799 extern void VUpdateVolume(Error * ec, Volume * vp);
800 extern void VUpdateVolume_r(Error * ec, Volume * vp, int flags);
801 extern void VAddToVolumeUpdateList(Error * ec, Volume * vp);
802 extern void VAddToVolumeUpdateList_r(Error * ec, Volume * vp);
803 extern void VDetachVolume(Error * ec, Volume * vp);
804 extern void VDetachVolume_r(Error * ec, Volume * vp);
805 extern void VForceOffline(Volume * vp);
806 extern void VForceOffline_r(Volume * vp, int flags);
807 extern void VBumpVolumeUsage(Volume * vp);
808 extern void VBumpVolumeUsage_r(Volume * vp);
809 extern void VSetDiskUsage(void);
810 extern void VPrintCacheStats(void);
811 extern void VReleaseVnodeFiles_r(Volume * vp);
812 extern void VCloseVnodeFiles_r(Volume * vp);
813 extern struct DiskPartition64 *VGetPartition(char *name, int abortp);
814 extern struct DiskPartition64 *VGetPartition_r(char *name, int abortp);
815 extern void VOptDefaults(ProgramType pt, VolumePackageOptions * opts);
816 extern int VInitVolumePackage2(ProgramType pt, VolumePackageOptions * opts);
817 extern int VInitAttachVolumes(ProgramType pt);
818 extern void DiskToVolumeHeader(VolumeHeader_t * h, VolumeDiskHeader_t * dh);
819 extern void VolumeHeaderToDisk(VolumeDiskHeader_t * dh, VolumeHeader_t * h);
820 extern void AssignVolumeName(VolumeDiskData * vol, char *name, char *ext);
821 extern void VTakeOffline_r(Volume * vp);
822 extern void VTakeOffline(Volume * vp);
823 extern Volume * VLookupVolume_r(Error * ec, VolId volumeId, Volume * hint);
824 extern void VGetVolumePath(Error * ec, VolId volumeId, char **partitionp,
826 extern char *vol_DevName(dev_t adev, char *wpath);
829 extern void VLockFileInit(struct VLockFile *lf, const char *path);
830 extern void VLockFileReinit(struct VLockFile *lf);
831 extern int VLockFileLock(struct VLockFile *lf, afs_uint32 offset,
832 int locktype, int nonblock);
833 extern void VLockFileUnlock(struct VLockFile *lf, afs_uint32 offset);
835 #ifdef AFS_DEMAND_ATTACH_FS
836 extern Volume *VPreAttachVolumeByName(Error * ec, char *partition, char *name);
837 extern Volume *VPreAttachVolumeByName_r(Error * ec, char *partition, char *name);
838 extern Volume *VPreAttachVolumeById_r(Error * ec, char * partition,
840 extern Volume *VPreAttachVolumeByVp_r(Error * ec, struct DiskPartition64 * partp,
841 Volume * vp, VolId volume_id);
842 extern Volume *VGetVolumeByVp_r(Error * ec, Volume * vp);
843 extern int VShutdownByPartition_r(struct DiskPartition64 * dp);
844 extern int VShutdownVolume_r(Volume * vp);
845 extern int VConnectSALV(void);
846 extern int VConnectSALV_r(void);
847 extern int VReconnectSALV(void);
848 extern int VReconnectSALV_r(void);
849 extern int VDisconnectSALV(void);
850 extern int VDisconnectSALV_r(void);
851 extern void VPrintExtendedCacheStats(int flags);
852 extern void VPrintExtendedCacheStats_r(int flags);
853 extern void VLRU_SetOptions(int option, afs_uint32 val);
854 extern int VSetVolHashSize(int logsize);
855 extern int VRequestSalvage_r(Error * ec, Volume * vp, int reason, int flags);
856 extern int VUpdateSalvagePriority_r(Volume * vp);
857 extern int VRegisterVolOp_r(Volume * vp, FSSYNC_VolOp_info * vopinfo);
858 extern int VDeregisterVolOp_r(Volume * vp);
859 extern void VCancelReservation_r(Volume * vp);
860 extern int VChildProcReconnectFS_r(void);
861 extern void VOfflineForVolOp_r(Error *ec, Volume *vp, char *message);
864 extern void VDiskLockInit(struct VDiskLock *dl, struct VLockFile *lf,
866 extern int VGetDiskLock(struct VDiskLock *dl, int locktype, int nonblock);
867 extern void VReleaseDiskLock(struct VDiskLock *dl, int locktype);
868 #endif /* AFS_DEMAND_ATTACH_FS */
869 extern int VVolOpLeaveOnline_r(Volume * vp, FSSYNC_VolOp_info * vopinfo);
870 extern int VVolOpLeaveOnlineNoHeader_r(Volume * vp, FSSYNC_VolOp_info * vopinfo);
871 extern int VVolOpSetVBusy_r(Volume * vp, FSSYNC_VolOp_info * vopinfo);
873 extern void VPurgeVolume(Error * ec, Volume * vp);
875 extern afs_int32 VCanScheduleSalvage(void);
876 extern afs_int32 VCanUseFSSYNC(void);
877 extern afs_int32 VCanUseSALVSYNC(void);
878 extern afs_int32 VCanUnsafeAttach(void);
879 extern afs_int32 VReadVolumeDiskHeader(VolumeId volid,
880 struct DiskPartition64 * dp,
881 VolumeDiskHeader_t * hdr);
882 extern afs_int32 VWriteVolumeDiskHeader(VolumeDiskHeader_t * hdr,
883 struct DiskPartition64 * dp);
884 extern afs_int32 VCreateVolumeDiskHeader(VolumeDiskHeader_t * hdr,
885 struct DiskPartition64 * dp);
886 extern afs_int32 VDestroyVolumeDiskHeader(struct DiskPartition64 * dp,
887 VolumeId volid, VolumeId parent);
890 * VWalkVolumeHeaders header callback.
892 * @param[in] dp disk partition
893 * @param[in] name full path to the .vol header file
894 * @param[in] hdr the header data that was read from the .vol header
895 * @param[in] last 1 if this is the last attempt to read the vol header, 0
896 * otherwise. DAFS VWalkVolumeHeaders will retry reading the
897 * header once, if a non-fatal error occurs when reading the
898 * header, or if this function returns a positive error code.
899 * So, if there is a problem, this function will be called
900 * first with last=0, then with last=1, then the error function
901 * callback will be called. For non-DAFS, this is always 1.
902 * @param[in] rock the rock passed to VWalkVolumeHeaders
904 * @return operation status
906 * @retval negative a fatal error that should stop the walk immediately
907 * @retval positive an error with the volume header was encountered; the walk
908 * should continue, but the error function should be called on this
911 * @see VWalkVolumeHeaders
913 typedef int (*VWalkVolFunc)(struct DiskPartition64 *dp, const char *name,
914 struct VolumeDiskHeader *hdr, int last,
917 * VWalkVolumeHeaders error callback.
919 * This is called from VWalkVolumeHeaders when an invalid or otherwise
920 * problematic volume header is encountered. It is typically implemented as a
921 * wrapper to unlink the .vol file.
923 * @param[in] dp disk partition
924 * @param[in] name full path to the .vol header file
925 * @param[in] hdr header read in from the .vol file, or NULL if it could not
927 * @param[in] rock rock passed to VWalkVolumeHeaders
929 * @see VWalkVolumeHeaders
931 typedef void (*VWalkErrFunc)(struct DiskPartition64 *dp, const char *name,
932 struct VolumeDiskHeader *hdr, void *rock);
933 extern int VWalkVolumeHeaders(struct DiskPartition64 *dp, const char *partpath,
934 VWalkVolFunc volfunc, VWalkErrFunc errfunc,
937 /* Naive formula relating number of file size to number of 1K blocks in file */
938 /* Note: we charge 1 block for 0 length files so the user can't store
939 an inifite number of them; for most files, we give him the inode, vnode,
940 and indirect block overhead, for FREE! */
941 #define nBlocks(bytes) ((afs_sfsize_t)((bytes) == 0? 1: (((afs_sfsize_t)(bytes))+1023)/1024))
943 /* Client process id -- file server sends a Check volumes signal back to the client at this pid */
944 #define CLIENTPID "/vice/vol/clientpid"
946 /* Modes of attachment, for VAttachVolume[ByName] to convey to the file server */
947 #define V_READONLY 1 /* Absolutely no updates will be done to the volume */
948 #define V_CLONE 2 /* Cloning the volume: if it is read/write, then directory
949 * version numbers will change. Header will be updated. If
950 * the volume is read-only, the file server may continue to
951 * server it; it may also continue to server it in read/write
952 * mode if the writes are deferred */
953 #define V_VOLUPD 3 /* General update or volume purge is possible. Volume must
955 #define V_DUMP 4 /* A dump of the volume is requested; the volume can be served
956 * read-only during this time */
957 #define V_SECRETLY 5 /* Secret attach of the volume. This is used to attach a volume
958 * which the file server doesn't know about--and which it shouldn't
959 * know about yet, since the volume has just been created and
960 * is somewhat bogus. Required to make sure that a file server
961 * never knows about more than one copy of the same volume--when
962 * a volume is moved from one partition to another on a single
964 #define V_PEEK 6 /* "Peek" at the volume without telling the fileserver. This is
965 * similar to V_SECRETLY, but read-only. It is used in cases where
966 * not impacting fileserver performance is more important than
967 * getting the most recent data. */
971 /* VUpdateVolume_r flags */
972 #define VOL_UPDATE_WAIT 0x1 /* for demand attach, wait for other exclusive ops to end */
973 #define VOL_UPDATE_NOFORCEOFF 0x2 /* don't force offline on failure. this is to prevent
974 * infinite recursion between vupdate and vforceoff */
976 /* VForceOffline_r flags */
977 #define VOL_FORCEOFF_NOUPDATE 0x1 /* don't force update on forceoff. this is to prevent
978 * infinite recursion between vupdate and vforceoff */
980 /* VSyncVolume_r flags */
981 #define VOL_SYNC_WAIT 0x1 /* for demand attach, wait for other exclusive ops to end */
983 /* VAllocBitmapEntry_r flags */
984 #define VOL_ALLOC_BITMAP_WAIT 0x1 /* for demand attach, wait for other exclusive ops to end */
986 /* VRequestSalvage_r flags */
987 #define VOL_SALVAGE_INVALIDATE_HEADER 0x1 /* for demand attach fs, invalidate volume header cache */
990 #if defined(NEARINODE_HINT)
991 #define V_pref(vp,nearInode) nearInodeHash(V_id(vp),(nearInode)); (nearInode) %= V_partition(vp)->f_files
993 #define V_pref(vp,nearInode) nearInode = 0
994 #endif /* NEARINODE_HINT */
996 hdr_static_inline(unsigned int)
997 afs_printable_VolumeId_u(VolumeId d) { return (unsigned int) d; }
999 hdr_static_inline(unsigned int)
1000 afs_printable_VnodeId_u(VnodeId d) { return (unsigned int) d; }
1002 #endif /* __volume_h */