Abstract /vicepX header traversal
[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
37
38 /* All Vice partitions on a server will have the following name prefix */
39 #define VICE_PARTITION_PREFIX   "/vicep"
40 #define VICE_PREFIX_SIZE        (sizeof(VICE_PARTITION_PREFIX)-1)
41
42 /* If a file by this name exists in a /vicepX directory, it means that
43  * this directory should be used as an AFS partition even if it's not
44  * on a separate partition (for instance if it's part of a large /).
45  * This feature only works with the NAMEI fileserver.
46  */
47 #ifdef AFS_NAMEI_ENV
48 #define VICE_ALWAYSATTACH_FILE  "AlwaysAttach"
49 #endif
50
51 #ifdef AFS_DEMAND_ATTACH_FS
52
53 /**
54  * abstraction for files used for file-locking.
55  */
56 struct VLockFile {
57     FD_t fd;                /**< fd holding the lock(s) */
58     char *path;             /**< path to the lock file */
59
60     pthread_mutex_t mutex;  /**< lock for the VLockFile struct */
61     int refcount;           /**< how many locks we have on the file */
62 };
63
64 /*
65  * flag bits for 'flags' in struct VDiskLock.
66  */
67 #define VDISKLOCK_ACQUIRING  0x1   /**< is someone waiting for an fs lock? */
68 #define VDISKLOCK_ACQUIRED   0x2   /**< we have an fs lock */
69
70 /**
71  * on-disk locking mechanism.
72  */
73 struct VDiskLock {
74     struct VLockFile *lockfile; /**< file holding the locks */
75     afs_uint32 offset;          /**< what offset we lock in the file */
76
77     struct Lock rwlock;         /**< rw lock for inter-thread locking */
78     pthread_mutex_t mutex;      /**< lock for the DiskLock object itself */
79     pthread_cond_t cv;          /**< cond var for 'acquiring' changes */
80
81     int lockers;                /**< # of callers that have this locked; */
82
83     unsigned int flags;         /**< see above for flag bits */
84 };
85 #endif /* AFS_DEMAND_ATTACH_FS */
86
87
88 /* For NT, the roles of "name" and "devName" are reversed. That is, "name"
89  * refers to the drive letter name and "devName" refers to the /vicep style
90  * or name. The reason for this is that a lot of places assume that "name"
91  * is the right thing to use to access the partition. Silly of them isn't it?
92  * The NT version of VInitPartition does the intial setup. There is an NT
93  * variant for VGetPartition as well. Also, the VolPartitionInfo RPC does
94  * a swap before sending the data out on the wire.
95  */
96 struct DiskPartition64 {
97     struct DiskPartition64 *next;
98     char *name;                 /* Mounted partition name */
99     char *devName;              /* Device mounted on */
100     Device device;              /* device number */
101     afs_int32 index;            /* partition index (0<=x<=VOLMAXPARTS) */
102     FD_t lock_fd;               /* File descriptor of this partition if locked; otherwise -1;
103                                  * Not used by the file server */
104     afs_int64 free;             /* Total number of blocks (1K) presumed
105                                  * available on this partition (accounting
106                                  * for the minfree parameter for the
107                                  * partition).  This is adjusted
108                                  * approximately by the sizes of files
109                                  * and directories read/written, and
110                                  * periodically the superblock is read and
111                                  * this is recomputed.  This number can
112                                  * be negative, if the partition starts
113                                  * out too full */
114     afs_int64 totalUsable;      /* Total number of blocks available on this
115                                  * partition, taking into account the minfree
116                                  * parameter for the partition (see the
117                                  * 4.2bsd command tunefs, but note that the
118                                  * bug mentioned there--that the superblock
119                                  * is not reread--does not apply here.  The
120                                  * superblock is re-read periodically by
121                                  * VSetPartitionDiskUsage().) */
122     afs_int64 minFree;          /* Number blocks to be kept free, as last read
123                                  * from the superblock */
124     int flags;
125     afs_int64 f_files;          /* total number of files in this partition */
126 #ifdef AFS_DEMAND_ATTACH_FS
127     struct {
128         struct rx_queue head;   /* list of volumes on this partition (VByPList) */
129         afs_uint32 len;         /* length of volume list */
130         int busy;               /* asynch vol list op in progress */
131         pthread_cond_t cv;      /* vol_list.busy change cond var */
132     } vol_list;
133     struct VLockFile headerLockFile;
134     struct VDiskLock headerLock; /* lock for the collective headers on the partition */
135 #endif /* AFS_DEMAND_ATTACH_FS */
136 };
137
138 struct DiskPartitionStats64 {
139     afs_int64 free;
140     afs_int64 totalUsable;
141     afs_int64 minFree;
142     afs_int64 f_files;
143 #ifdef AFS_DEMAND_ATTACH_FS
144     afs_int32 vol_list_len;
145 #endif
146 };
147
148 #define PART_DONTUPDATE 1
149 #define PART_DUPLICATE  2       /* NT - used if we find more than one partition 
150                                  * using the same drive. Will be dumped before
151                                  * all partitions attached.
152                                  */
153
154 #ifdef AFS_NT40_ENV
155 #include <WINNT/vptab.h>
156 extern int VValidVPTEntry(struct vptab *vptp);
157 #endif
158
159
160 struct Volume;                  /* Potentially forward definition */
161
162 extern struct DiskPartition64 *DiskPartitionList;
163 extern struct DiskPartition64 *VGetPartition(char * name, int abortp);
164 extern struct DiskPartition64 *VGetPartition_r(char * name, int abortp);
165 #ifdef AFS_DEMAND_ATTACH_FS
166 extern struct DiskPartition64 *VGetPartitionById(afs_int32 index, int abortp);
167 extern struct DiskPartition64 *VGetPartitionById_r(afs_int32 index, int abortp);
168 extern int VPartHeaderLock(struct DiskPartition64 *dp, int locktype);
169 extern void VPartHeaderUnlock(struct DiskPartition64 *dp, int locktype);
170 #endif
171 extern int VAttachPartitions(void);
172 extern void VLockPartition(char *name);
173 extern void VLockPartition_r(char *name);
174 extern void VUnlockPartition(char *name);
175 extern void VUnlockPartition_r(char *name);
176 extern void VResetDiskUsage(void);
177 extern void VResetDiskUsage_r(void);
178 extern void VSetPartitionDiskUsage(register struct DiskPartition64 *dp);
179 extern void VSetPartitionDiskUsage_r(register struct DiskPartition64 *dp);
180 extern char *VPartitionPath(struct DiskPartition64 *p);
181 extern void VAdjustDiskUsage(Error * ec, struct Volume *vp,
182                              afs_sfsize_t blocks, afs_sfsize_t checkBlocks);
183 extern int VDiskUsage(struct Volume *vp, afs_sfsize_t blocks);
184 extern void VPrintDiskStats(void);
185 extern int VInitPartitionPackage(void);
186
187 #endif /* AFS_VOL_PARTITION_H */