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