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