vol-salvage: Move global vars into SalvInfo struct
[openafs.git] / src / vol / vol-salvage.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
10 /*
11  *      Module:         vol-salvage.h
12  */
13
14 #ifndef __vol_salvage_h_
15 #define __vol_salvage_h_
16
17 #define SalvageVersion "2.4"
18
19 #include "salvage.h"
20 #include "volinodes.h"
21
22 /* salvager data structures */
23 struct InodeSummary {           /* Inode summary file--an entry for each
24                                  * volume in the inode file for a partition */
25     VolId volumeId;             /* Volume id */
26     VolId RWvolumeId;           /* RW volume associated */
27     int index;                  /* index into inode file (0, 1, 2 ...) */
28     int nInodes;                /* Number of inodes for this volume */
29     int nSpecialInodes;         /* Number of special inodes, i.e.  volume
30                                  * header, index, etc.  These are all
31                                  * marked (viceinode.h) and will all be sorted
32                                  * to the beginning of the information for
33                                  * this volume.  Read-only volumes should
34                                  * ONLY have special inodes (all the other
35                                  * inodes look as if they belong to the
36                                  * original RW volume). */
37     Unique maxUniquifier;       /* The maximum uniquifier found in all the inodes.
38                                  * This is only useful for RW volumes and is used
39                                  * to compute a new volume uniquifier in the event
40                                  * that the header needs to be recreated. The inode
41                                  * uniquifier may be a truncated version of vnode
42                                  * uniquifier (AFS_3DISPARES). The real maxUniquifer
43                                  * is from the vnodes and later calcuated from it */
44     struct VolumeSummary *volSummary;
45     /* Either a pointer to the original volume
46      * header summary, or constructed summary
47      * information */
48 };
49 #define readOnly(isp)   ((isp)->volumeId != (isp)->RWvolumeId)
50
51 struct VolumeSummary {          /* Volume summary an entry for each
52                                  * volume in a volume directory.
53                                  * Assumption: one volume directory per
54                                  * partition */
55     char *fileName;             /* File name on the partition for the volume
56                                  * header */
57     struct VolumeHeader header;
58     /* volume number, rw volume number, inode
59      * numbers of each major component of
60      * the volume */
61     IHandle_t *volumeInfoHandle;
62     byte wouldNeedCallback;     /* set if the file server should issue
63                                  * call backs for all the files in this volume when
64                                  * the volume goes back on line */
65 };
66
67 struct VnodeInfo {
68     IHandle_t *handle;          /* Inode containing this index */
69     afs_sfsize_t nVnodes;       /* Total number of vnodes in index */
70     afs_sfsize_t nAllocatedVnodes;      /* Total number actually used */
71     int volumeBlockCount;       /* Total number of blocks used by volume */
72     Inode *inodes;              /* Directory only */
73     struct VnodeEssence {
74         short count;            /* Number of references to vnode; MUST BE SIGNED */
75         unsigned claimed:1;     /* Set when a parent directory containing an entry
76                                  * referencing this vnode is found.  The claim
77                                  * is that the parent in "parent" can point to
78                                  * this vnode, and no other */
79         unsigned changed:1;     /* Set if any parameters (other than the count)
80                                  * in the vnode change.   It is determined if the
81                                  * link count has changed by noting whether it is
82                                  * 0 after scanning all directories */
83         unsigned salvaged:1;    /* Set if this directory vnode has already been salvaged. */
84         unsigned todelete:1;    /* Set if this vnode is to be deleted (should not be claimed) */
85         afs_fsize_t blockCount;
86         /* Number of blocks (1K) used by this vnode,
87          * approximately */
88         VnodeId parent;         /* parent in vnode */
89         Unique unique;          /* Must match entry! */
90         char *name;             /* Name of directory entry */
91         int modeBits;           /* File mode bits */
92         Inode InodeNumber;      /* file's inode */
93         int type;               /* File type */
94         int author;             /* File author */
95         int owner;              /* File owner */
96         int group;              /* File group */
97     } *vnodes;
98 };
99
100 struct DirSummary {
101     struct DirHandle dirHandle;
102     VnodeId vnodeNumber;
103     Unique unique;
104     unsigned haveDot, haveDotDot;
105     VolumeId rwVid;
106     int copied;                 /* If the copy-on-write stuff has been applied */
107     VnodeId parent;
108     char *name;
109     char *vname;
110     IHandle_t *ds_linkH;
111 };
112
113 struct SalvInfo;
114
115 #define ORPH_IGNORE 0
116 #define ORPH_REMOVE 1
117 #define ORPH_ATTACH 2
118
119
120 /* command line options */
121 extern int debug;                       /* -d flag */
122 extern int Testing;                     /* -n flag */
123 extern int ListInodeOption;             /* -i flag */
124 extern int ShowRootFiles;               /* -r flag */
125 extern int RebuildDirs;                 /* -sal flag */
126 extern int Parallel;                    /* -para X flag */
127 extern int PartsPerDisk;                /* Salvage up to 8 partitions on same disk sequentially */
128 extern int forceR;                      /* -b flag */
129 extern int ShowLog;                     /* -showlog flag */
130 extern int ShowSuid;                    /* -showsuid flag */
131 extern int ShowMounts;                  /* -showmounts flag */
132 extern int orphans;                     /* -orphans option */
133 extern int Showmode;
134
135 #ifndef AFS_NT40_ENV
136 extern int useSyslog;                   /* -syslog flag */
137 extern int useSyslogFacility;           /* -syslogfacility option */
138 #endif
139
140 #define MAXPARALLEL     32
141
142 extern int OKToZap;                     /* -o flag */
143 extern int ForceSalvage;                /* If salvage should occur despite the DONT_SALVAGE flag
144                                          * in the volume header */
145
146
147 #define ROOTINODE       2       /* Root inode of a 4.2 Unix file system
148                                  * partition */
149
150
151
152 extern char * tmpdir;
153 extern FILE *logFile;           /* one of {/usr/afs/logs,/vice/file}/SalvageLog */
154
155
156 #ifdef AFS_NT40_ENV
157 /* For NT, we can fork the per partition salvagers to gain the required
158  * safety against Aborts. But there's too many complex data structures at
159  * the per volume salvager layer to easilty copy the data across.
160  * childJobNumber is resset from -1 to the job number if this is a
161  * per partition child of the main salvager. This information is passed
162  * out-of-band in the extra data area setup for the now unused parent/child
163  * data transfer.
164  */
165 #define SALVAGER_MAGIC 0x00BBaaDD
166 #define NOT_CHILD -1            /* job numbers start at 0 */
167 /* If new options need to be passed to child, add them here. */
168 typedef struct {
169     int cj_magic;
170     int cj_number;
171     char cj_part[32];
172 } childJob_t;
173
174 /* Child job this process is running. */
175 extern childJob_t myjob;
176
177 extern int nt_SalvagePartition(char *partName, int jobn);
178 extern int nt_SetupPartitionSalvage(void *datap, int len);
179
180 typedef struct {
181     struct InodeSummary *svgp_inodeSummaryp;
182     int svgp_count;
183     struct SalvInfo *svgp_salvinfo;
184 } SVGParms_t;
185 #endif /* AFS_NT40_ENV */
186
187 extern int canfork;
188
189
190 /* prototypes */
191 extern void Exit(int code) AFS_NORETURN;
192 extern int Fork(void);
193 extern int Wait(char *prog);
194 extern char *ToString(const char *s);
195 extern void AskOffline(struct SalvInfo *salvinfo, VolumeId volumeId);
196 extern void AskOnline(struct SalvInfo *salvinfo, VolumeId volumeId);
197 extern void CheckLogFile(char * log_path);
198 #ifndef AFS_NT40_ENV
199 extern void TimeStampLogFile(char * log_path);
200 #endif
201 extern void ClearROInUseBit(struct VolumeSummary *summary);
202 extern void CopyAndSalvage(struct SalvInfo *salvinfo, struct DirSummary *dir);
203 extern int CopyInode(Device device, Inode inode1, Inode inode2, int rwvolume);
204 extern void CopyOnWrite(struct SalvInfo *salvinfo, struct DirSummary *dir);
205 extern void CountVolumeInodes(register struct ViceInodeInfo *ip, int maxInodes,
206                        register struct InodeSummary *summary);
207 extern void DeleteExtraVolumeHeaderFile(struct SalvInfo *salvinfo,
208                                         struct VolumeSummary *vsp);
209 extern void DistilVnodeEssence(struct SalvInfo *salvinfo, VolumeId vid,
210                                VnodeClass class, Inode ino, Unique * maxu);
211 extern int GetInodeSummary(struct SalvInfo *salvinfo, FILE *inodeFile,
212                            VolumeId singleVolumeNumber);
213 extern int GetVolumeSummary(struct SalvInfo *salvinfo,
214                             VolumeId singleVolumeNumber);
215 extern int JudgeEntry(void *dirVal, char *name, afs_int32 vnodeNumber,
216                       afs_int32 unique);
217 extern void MaybeZapVolume(struct SalvInfo *salvinfo, struct InodeSummary *isp,
218                            char *message, int deleteMe, int check);
219 extern void ObtainSalvageLock(void);
220 extern void ObtainSharedSalvageLock(void);
221 extern void PrintInodeList(struct SalvInfo *salvinfo);
222 extern void PrintInodeSummary(struct SalvInfo *salvinfo);
223 extern void PrintVolumeSummary(struct SalvInfo *salvinfo);
224 extern int QuickCheck(struct SalvInfo *salvinfo, struct InodeSummary *isp,
225                       int nVols);
226 extern void RemoveTheForce(char *path);
227 extern void SalvageDir(struct SalvInfo *salvinfo, char *name, VolumeId rwVid,
228                        struct VnodeInfo *dirVnodeInfo, IHandle_t * alinkH,
229                        int i, struct DirSummary *rootdir, int *rootdirfound);
230 extern void SalvageFileSysParallel(struct DiskPartition64 *partP);
231 extern void SalvageFileSys(struct DiskPartition64 *partP, VolumeId singleVolumeNumber);
232 extern void SalvageFileSys1(struct DiskPartition64 *partP,
233                             VolumeId singleVolumeNumber);
234 extern int SalvageHeader(struct SalvInfo *salvinfo, struct stuff *sp,
235                         struct InodeSummary *isp, int check, int *deleteMe);
236 extern int SalvageIndex(struct SalvInfo *salvinfo, Inode ino, VnodeClass class,
237                         int RW, struct ViceInodeInfo *ip, int nInodes,
238                         struct VolumeSummary *volSummary, int check);
239 extern int SalvageVnodes(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp,
240                         struct InodeSummary *thisIsp,
241                         struct ViceInodeInfo *inodes, int check);
242 extern int SalvageVolume(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp,
243                          IHandle_t * alinkH);
244 extern void DoSalvageVolumeGroup(struct SalvInfo *salvinfo,
245                                  struct InodeSummary *isp, int nVols);
246 #ifdef AFS_NT40_ENV
247 extern void SalvageVolumeGroup(struct InodeSummary *isp, int nVols);
248 #else
249 #define SalvageVolumeGroup DoSalvageVolumeGroup
250 #endif
251 extern int SalvageVolumeHeaderFile(struct SalvInfo *salvinfo,
252                                    struct InodeSummary *isp,
253                                    struct ViceInodeInfo *inodes, int RW,
254                                    int check, int *deleteMe);
255 extern void showlog(void);
256 extern int UseTheForceLuke(char *path);
257
258
259
260 #endif /* __vol_salvage_h_ */