Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / vol / partition.h
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
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
8 *
9 * Portions Copyright (c) 2006 Sine Nomine Associates
10 */
11
12 /*
13 System: VICE-TWO
14 Module: partition.h
15 Institution: The Information Technology Center, Carnegie-Mellon University
16
17 */
18
19 #ifndef AFS_VOL_PARTITION_H
20 #define AFS_VOL_PARTITION_H
21
22 #include <afs/param.h>
23 #include "nfs.h"
24 #if defined(AFS_HPUX_ENV)
25 #define AFS_DSKDEV "/dev/dsk"
26 #define AFS_RDSKDEV "/dev/rdsk/"
27 #define AFS_LVOLDEV "/dev/vg0"
28 #define AFS_ACVOLDEV "/dev/ac"
29 #define AFS_RACVOLDEV "/dev/ac/r"
30 #else
31 #define AFS_DSKDEV "/dev"
32 #define AFS_RDSKDEV "/dev/r"
33 #endif
34
35 #include "lock.h"
36 #ifdef AFS_DEMAND_ATTACH_FS
37 # include <pthread.h>
38 #endif
39
40 /* All Vice partitions on a server will have the following name prefix */
41 #define VICE_PARTITION_PREFIX "/vicep"
42 #define VICE_PREFIX_SIZE (sizeof(VICE_PARTITION_PREFIX)-1)
43
44 /* If a file by this name exists in a /vicepX directory, it means that
45 * this directory should be used as an AFS partition even if it's not
46 * on a separate partition (for instance if it's part of a large /).
47 * This feature only works with the NAMEI fileserver.
48 */
49 #ifdef AFS_NAMEI_ENV
50 #define VICE_ALWAYSATTACH_FILE "AlwaysAttach"
51 #endif
52
53 /* If a file by this name exists in a /vicepX directory, it means that
54 * this directory should NOT be used as an AFS partition.
55 */
56 #define VICE_NEVERATTACH_FILE "NeverAttach"
57
58 /**
59 * abstraction for files used for file-locking.
60 */
61 struct VLockFile {
62 FD_t fd; /**< fd holding the lock(s) */
63 char *path; /**< path to the lock file */
64 int refcount; /**< how many locks we have on the file */
65
66 #ifdef AFS_PTHREAD_ENV
67 pthread_mutex_t mutex; /**< lock for the VLockFile struct */
68 #endif /* AFS_PTHREAD_ENV */
69 };
70
71 #ifdef AFS_DEMAND_ATTACH_FS
72 /*
73 * flag bits for 'flags' in struct VDiskLock.
74 */
75 #define VDISKLOCK_ACQUIRING 0x1 /**< is someone waiting for an fs lock? */
76 #define VDISKLOCK_ACQUIRED 0x2 /**< we have an fs lock */
77
78 /**
79 * on-disk locking mechanism.
80 */
81 struct VDiskLock {
82 struct VLockFile *lockfile; /**< file holding the locks */
83 afs_uint32 offset; /**< what offset we lock in the file */
84
85 struct Lock rwlock; /**< rw lock for inter-thread locking */
86 pthread_mutex_t mutex; /**< lock for the DiskLock object itself */
87 pthread_cond_t cv; /**< cond var for 'acquiring' changes */
88
89 int lockers; /**< # of callers that have this locked; */
90
91 unsigned int flags; /**< see above for flag bits */
92 };
93 #endif /* AFS_DEMAND_ATTACH_FS */
94
95
96 /* For NT, the roles of "name" and "devName" are no longer reversed.
97 * That is, "name" refers to the canonical name (/vicep) style and
98 * "devName" refers to drive name.
99 *
100 * The NT version of VInitPartition does the intial setup. There is an NT
101 * variant for VGetPartition as well. Also, the VolPartitionInfo RPC does
102 * a swap before sending the data out on the wire.
103 */
104 struct DiskPartition64 {
105 struct DiskPartition64 *next;
106 char *name; /* Mounted partition name */
107 char *devName; /* Device mounted on */
108 Device device; /* device number */
109 afs_int32 index; /* partition index (0<=x<=VOLMAXPARTS) */
110 FD_t lock_fd; /* File descriptor of this partition if locked; otherwise -1;
111 * Not used by the file server */
112 afs_int64 free; /* Total number of blocks (1K) presumed
113 * available on this partition (accounting
114 * for the minfree parameter for the
115 * partition). This is adjusted
116 * approximately by the sizes of files
117 * and directories read/written, and
118 * periodically the superblock is read and
119 * this is recomputed. This number can
120 * be negative, if the partition starts
121 * out too full */
122 afs_int64 totalUsable; /* Total number of blocks available on this
123 * partition, taking into account the minfree
124 * parameter for the partition (see the
125 * 4.2bsd command tunefs, but note that the
126 * bug mentioned there--that the superblock
127 * is not reread--does not apply here. The
128 * superblock is re-read periodically by
129 * VSetPartitionDiskUsage().) */
130 afs_int64 minFree; /* Number blocks to be kept free, as last read
131 * from the superblock */
132 int flags;
133 afs_int64 f_files; /* total number of files in this partition */
134 #ifdef AFS_DEMAND_ATTACH_FS
135 struct {
136 struct rx_queue head; /* list of volumes on this partition (VByPList) */
137 afs_uint32 len; /* length of volume list */
138 int busy; /* asynch vol list op in progress */
139 pthread_cond_t cv; /* vol_list.busy change cond var */
140 } vol_list;
141 struct VLockFile headerLockFile;
142 struct VDiskLock headerLock; /* lock for the collective headers on the partition */
143
144 struct VLockFile volLockFile; /* lock file for individual volume locks */
145 #endif /* AFS_DEMAND_ATTACH_FS */
146 };
147
148 struct DiskPartitionStats64 {
149 afs_int64 free;
150 afs_int64 totalUsable;
151 afs_int64 minFree;
152 afs_int64 f_files;
153 #ifdef AFS_DEMAND_ATTACH_FS
154 afs_int32 vol_list_len;
155 #endif
156 };
157
158 #define PART_DONTUPDATE 1
159 #define PART_DUPLICATE 2 /* NT - used if we find more than one partition
160 * using the same drive. Will be dumped before
161 * all partitions attached.
162 */
163
164 #ifdef AFS_NT40_ENV
165 #include <WINNT/vptab.h>
166 #endif
167
168
169 struct Volume; /* Potentially forward definition */
170
171 extern struct DiskPartition64 *DiskPartitionList;
172 extern struct DiskPartition64 *VGetPartition(char * name, int abortp);
173 extern struct DiskPartition64 *VGetPartition_r(char * name, int abortp);
174 #ifdef AFS_DEMAND_ATTACH_FS
175 extern struct DiskPartition64 *VGetPartitionById(afs_int32 index, int abortp);
176 extern struct DiskPartition64 *VGetPartitionById_r(afs_int32 index, int abortp);
177 extern int VPartHeaderLock(struct DiskPartition64 *dp, int locktype);
178 extern void VPartHeaderUnlock(struct DiskPartition64 *dp, int locktype);
179 #endif
180 extern int VAttachPartitions(void);
181 extern void VLockPartition(char *name);
182 extern void VLockPartition_r(char *name);
183 extern void VUnlockPartition(char *name);
184 extern void VUnlockPartition_r(char *name);
185 extern void VResetDiskUsage(void);
186 extern void VResetDiskUsage_r(void);
187 extern void VSetPartitionDiskUsage(struct DiskPartition64 *dp);
188 extern void VSetPartitionDiskUsage_r(struct DiskPartition64 *dp);
189 extern char *VPartitionPath(struct DiskPartition64 *p);
190 extern void VAdjustDiskUsage(Error * ec, struct Volume *vp,
191 afs_sfsize_t blocks, afs_sfsize_t checkBlocks);
192 extern int VDiskUsage(struct Volume *vp, afs_sfsize_t blocks);
193 extern void VPrintDiskStats(void);
194 extern int VInitPartitionPackage(void);
195
196 #endif /* AFS_VOL_PARTITION_H */