salvager: avoid needing temp files to stay around
[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 } *inodeSummary;
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     int nVnodes;                /* Total number of vnodes in index */
70     int 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 #define ORPH_IGNORE 0
114 #define ORPH_REMOVE 1
115 #define ORPH_ATTACH 2
116
117
118 /* command line options */
119 extern int debug;                       /* -d flag */
120 extern int Testing;                     /* -n flag */
121 extern int ListInodeOption;             /* -i flag */
122 extern int ShowRootFiles;               /* -r flag */
123 extern int RebuildDirs;                 /* -sal flag */
124 extern int Parallel;                    /* -para X flag */
125 extern int PartsPerDisk;                /* Salvage up to 8 partitions on same disk sequentially */
126 extern int forceR;                      /* -b flag */
127 extern int ShowLog;                     /* -showlog flag */
128 extern int ShowSuid;                    /* -showsuid flag */
129 extern int ShowMounts;                  /* -showmounts flag */
130 extern int orphans;                     /* -orphans option */
131 extern int Showmode;
132
133 #ifndef AFS_NT40_ENV
134 extern int useSyslog;                   /* -syslog flag */
135 extern int useSyslogFacility;           /* -syslogfacility option */
136 #endif
137
138 #define MAXPARALLEL     32
139
140 extern int OKToZap;                     /* -o flag */
141 extern int ForceSalvage;                /* If salvage should occur despite the DONT_SALVAGE flag
142                                          * in the volume header */
143
144
145 #define ROOTINODE       2       /* Root inode of a 4.2 Unix file system
146                                  * partition */
147 extern Device fileSysDevice;    /* The device number of the current
148                                  * partition being salvaged */
149 #ifdef AFS_NT40_ENV
150 extern char fileSysPath[8];
151 #else
152 extern char *fileSysPath;       /* The path of the mounted partition currently
153                                  * being salvaged, i.e. the directory
154                                  * containing the volume headers */
155 #endif /* AFS_NT40_ENV */
156 extern char *fileSysPathName;   /* NT needs this to make name pretty in log. */
157 extern IHandle_t *VGLinkH;      /* Link handle for current volume group. */
158 extern int VGLinkH_cnt;         /* # of references to lnk handle. */
159 extern struct DiskPartition64 *fileSysPartition;        /* Partition  being salvaged */
160 #ifndef AFS_NT40_ENV
161 extern char *fileSysDeviceName; /* The block device where the file system
162                                  * being salvaged was mounted */
163 extern char *filesysfulldev;
164 #endif /* AFS_NT40_ENV */
165 extern int VolumeChanged;       /* Set by any routine which would change the volume in
166                                  * a way which would require callback is to be broken if the
167                                  * volume was put back on line by an active file server */
168
169 extern VolumeDiskData VolInfo;  /* A copy of the last good or salvaged volume header dealt with */
170
171 extern int nVolumesInInodeFile; /* Number of read-write volumes summarized */
172 extern int inodeFd;             /* File descriptor for inode file */
173
174
175 extern struct VnodeInfo vnodeInfo[nVNODECLASSES];
176
177
178 extern struct VolumeSummary *volumeSummaryp;    /* Holds all the volumes in a part */
179 extern int nVolumes;            /* Number of volumes (read-write and read-only)
180                                  * in volume summary */
181
182 extern char * tmpdir;
183 extern FILE *logFile;           /* one of {/usr/afs/logs,/vice/file}/SalvageLog */
184
185
186 #ifdef AFS_NT40_ENV
187 /* For NT, we can fork the per partition salvagers to gain the required
188  * safety against Aborts. But there's too many complex data structures at
189  * the per volume salvager layer to easilty copy the data across.
190  * childJobNumber is resset from -1 to the job number if this is a
191  * per partition child of the main salvager. This information is passed
192  * out-of-band in the extra data area setup for the now unused parent/child
193  * data transfer.
194  */
195 #define SALVAGER_MAGIC 0x00BBaaDD
196 #define NOT_CHILD -1            /* job numbers start at 0 */
197 /* If new options need to be passed to child, add them here. */
198 typedef struct {
199     int cj_magic;
200     int cj_number;
201     char cj_part[32];
202 } childJob_t;
203
204 /* Child job this process is running. */
205 extern childJob_t myjob;
206
207 extern int nt_SalvagePartition(char *partName, int jobn);
208 extern int nt_SetupPartitionSalvage(void *datap, int len);
209
210 typedef struct {
211     struct InodeSummary *svgp_inodeSummaryp;
212     int svgp_count;
213 } SVGParms_t;
214 #endif /* AFS_NT40_ENV */
215
216 extern int canfork;
217
218
219 /* prototypes */
220 extern void Exit(int code);
221 extern int Fork(void);
222 extern int Wait(char *prog);
223 extern char *ToString(char *s);
224 extern void AskOffline(VolumeId volumeId, char * partition);
225 extern void AskOnline(VolumeId volumeId, char *partition);
226 extern void CheckLogFile(char * log_path);
227 #ifndef AFS_NT40_ENV
228 extern void TimeStampLogFile(char * log_path);
229 #endif
230 extern void ClearROInUseBit(struct VolumeSummary *summary);
231 extern void CopyAndSalvage(register struct DirSummary *dir);
232 extern int CopyInode(Device device, Inode inode1, Inode inode2, int rwvolume);
233 extern void CopyOnWrite(register struct DirSummary *dir);
234 extern void CountVolumeInodes(register struct ViceInodeInfo *ip, int maxInodes,
235                        register struct InodeSummary *summary);
236 extern void DeleteExtraVolumeHeaderFile(register struct VolumeSummary *vsp);
237 extern void DistilVnodeEssence(VolumeId vid, VnodeClass class, Inode ino,
238                                Unique * maxu);
239 extern int GetInodeSummary(FILE *inodeFile, VolumeId singleVolumeNumber);
240 extern void GetVolumeSummary(VolumeId singleVolumeNumber);
241 extern int JudgeEntry(void *dirVal, char *name, afs_int32 vnodeNumber,
242                       afs_int32 unique);
243 extern void MaybeZapVolume(register struct InodeSummary *isp, char *message,
244                            int deleteMe, int check);
245 extern void ObtainSalvageLock(void);
246 extern void PrintInodeList(void);
247 extern void PrintInodeSummary(void);
248 extern void PrintVolumeSummary(void);
249 extern int QuickCheck(register struct InodeSummary *isp, int nVols);
250 extern void RemoveTheForce(char *path);
251 extern void SalvageDir(char *name, VolumeId rwVid, struct VnodeInfo *dirVnodeInfo,
252                        IHandle_t * alinkH, int i, struct DirSummary *rootdir,
253                        int *rootdirfound);
254 extern void SalvageFileSysParallel(struct DiskPartition64 *partP);
255 extern void SalvageFileSys(struct DiskPartition64 *partP, VolumeId singleVolumeNumber);
256 extern void SalvageFileSys1(struct DiskPartition64 *partP,
257                             VolumeId singleVolumeNumber);
258 extern int SalvageHeader(register struct stuff *sp, struct InodeSummary *isp,
259                          int check, int *deleteMe);
260 extern int SalvageIndex(Inode ino, VnodeClass class, int RW,
261                         register struct ViceInodeInfo *ip, int nInodes,
262                         struct VolumeSummary *volSummary, int check);
263 extern int SalvageVnodes(register struct InodeSummary *rwIsp,
264                          register struct InodeSummary *thisIsp,
265                          register struct ViceInodeInfo *inodes, int check);
266 extern int SalvageVolume(register struct InodeSummary *rwIsp, IHandle_t * alinkH);
267 extern void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols);
268 #ifdef AFS_NT40_ENV
269 extern void SalvageVolumeGroup(register struct InodeSummary *isp, int nVols);
270 #else
271 #define SalvageVolumeGroup DoSalvageVolumeGroup
272 #endif
273 extern int SalvageVolumeHeaderFile(register struct InodeSummary *isp,
274                                    register struct ViceInodeInfo *inodes, int RW,
275                                    int check, int *deleteMe);
276 extern void showlog(void);
277 extern int UseTheForceLuke(char *path);
278
279
280
281 #endif /* __vol_salvage_h_ */