DAFS: Add explicit 'valid' field for index maps
[openafs.git] / src / tviced / serialize_state.h
1 /*
2  * Copyright 2006, Sine Nomine Associates 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  * demand attach fs
12  * fileserver state serialization
13  */
14
15 #ifndef _AFS_TVICED_SERIALIZE_STATE_H
16 #define _AFS_TVICED_SERIALIZE_STATE_H
17
18 #ifdef AFS_DEMAND_ATTACH_FS
19
20 #define FS_STATE_MAGIC 0x62FA841C
21 #define FS_STATE_VERSION 2
22
23 #define HOST_STATE_MAGIC 0x7B8C9DAE
24 #define HOST_STATE_VERSION 2
25
26 #define HOST_STATE_ENTRY_MAGIC 0xA8B9CADB
27
28 #define CALLBACK_STATE_MAGIC 0x89DE67BC
29 #define CALLBACK_STATE_VERSION 1
30
31 #define CALLBACK_STATE_TIMEOUT_MAGIC 0x99DD5511
32 #define CALLBACK_STATE_FEHASH_MAGIC 0x77BB33FF
33 #define CALLBACK_STATE_ENTRY_MAGIC 0x54637281
34
35 #define ACTIVE_VOLUME_STATE_MAGIC 0xAC7557CA
36 #define ACTIVE_VOLUME_STATE_VERSION 1
37
38 #define ACTIVE_VOLUME_STATE_AVEHASH_MAGIC 0xBADDF00D
39
40 #define HOST_STATE_VALID_WINDOW 1800 /* 30 minutes */
41
42 /* values for the 'valid' field in idx_map_entry_t */
43 #define FS_STATE_IDX_VALID 1
44
45 /*
46  * on-disk structures
47  */
48 struct disk_version_stamp {
49     afs_uint32 magic;
50     afs_uint32 version;
51 };
52
53 /* 1024 byte header structure */
54 struct fs_state_header {
55     struct disk_version_stamp stamp;  /* version stamp */
56     time_t timestamp;                 /* timestamp of save */
57     afs_uint32 sys_name;              /* sys name id for this machine */
58     afsUUID server_uuid;              /* server's UUID */
59     byte valid;                       /* whether header contents are valid */
60     byte endianness;                  /* endianness sanity check (0 for LE, 1 for BE) */
61     byte stats_detailed;              /* fs stats detailed sanity check */
62     byte padding1[1];                 /* padding */
63     afs_uint32 reserved1[23];         /* for expansion */
64     afs_uint64 avol_offset;           /* offset of active volumes structure */
65     afs_uint64 h_offset;              /* offset of host_state_header structure */
66     afs_uint64 cb_offset;             /* offset of callback_state_header structure */
67     afs_uint64 vlru_offset;           /* offset of vlru state structure */
68     afs_uint32 reserved2[56];         /* for expansion */
69     char server_version_string[128];  /* version string from AFS_component_version_number.c */
70     afs_uint32 reserved3[128];        /* for expansion */
71 };
72
73 /*
74  * host package serialization
75  */
76
77 /* 256 byte header for the host state data */
78 struct host_state_header {
79     struct disk_version_stamp stamp;  /* host state version stamp */
80     afs_uint32 records;               /* number of stored host records */
81     afs_uint32 index_max;             /* max index value encountered */
82     afs_uint32 reserved[60];          /* for expansion */
83 };
84
85 /* 32 byte host entry header */
86 struct host_state_entry_header {
87     afs_uint32 magic;         /* stamp */
88     afs_uint32 len;           /* number of bytes in this record */
89     afs_uint32 interfaces;    /* number of interfaces included in record */
90     afs_uint32 hcps;          /* number of hcps entries in record */
91     afs_uint32 reserved[4];
92 };
93
94 /* 36 byte host entry structure */
95 struct hostDiskEntry {
96     afs_uint32 host;            /* IP address of host interface that is
97                                  * currently being used, in network
98                                  * byte order */
99     afs_uint16 port;            /* port address of host */
100     afs_uint16 hostFlags;       /*  bit map */
101     byte Console;               /* XXXX This host is a console */
102     byte hcpsfailed;            /* Retry the cps call next time */
103     byte hcps_valid;            /* prlist_val not null */
104 #if FS_STATS_DETAILED
105     byte InSameNetwork;         /*Is host's addr in the same network as
106                                  * the File Server's? */
107 #else
108     byte padding1[1];           /* for padding */
109 #endif                          /* FS_STATS_DETAILED */
110     afs_uint32 hcps_len;        /* length of hcps */
111     afs_uint32 LastCall;        /* time of last call from host */
112     afs_uint32 ActiveCall;      /* time of any call but gettime */
113     afs_uint32 cpsCall;         /* time of last cps call from this host */
114     afs_uint32 cblist;          /* Call back list for this host */
115     afs_uint32 index;           /* index for correlating w/ callback dumps */
116 };
117
118 /*
119  * callback package serialization
120  */
121
122 /* 512 byte header */
123 struct callback_state_header {
124     struct disk_version_stamp stamp;    /* callback state version stamp */
125     afs_uint32 nFEs;                    /* number of FileEntry records */
126     afs_uint32 nCBs;                    /* number of CallBack records */
127     afs_uint32 fe_max;                  /* max FileEntry index */
128     afs_uint32 cb_max;                  /* max CallBack index */
129     afs_int32 tfirst;                   /* first valid timeout */
130     afs_uint32 reserved[115];           /* for expansion */
131     afs_uint64 timeout_offset;          /* offset of timeout queue heads */
132     afs_uint64 fehash_offset;           /* offset of file entry hash buckets */
133     afs_uint64 fe_offset;               /* offset of first file entry */
134 };
135
136 /* 32 byte header */
137 struct callback_state_timeout_header {
138     afs_uint32 magic;         /* magic number for timeout header */
139     afs_uint32 len;           /* total length of header and timeout records */
140     afs_uint32 records;       /* number of timeout records */
141     afs_uint32 reserved[5];
142 };
143
144 /* 32 byte header */
145 struct callback_state_fehash_header {
146     afs_uint32 magic;         /* magic number for fehash header */
147     afs_uint32 len;           /* total length of header and fehash bucket heads */
148     afs_uint32 records;       /* number of hash buckets */
149     afs_uint32 reserved[5];
150 };
151
152 /* 32 byte header */
153 struct callback_state_entry_header {
154     afs_uint32 magic;         /* magic number for FE entry */
155     afs_uint32 len;           /* number of bytes in this record */
156     afs_uint32 nCBs;          /* number of callbacks for this FE */
157     afs_uint32 reserved[5];
158 };
159
160 struct FEDiskEntry {
161     struct FileEntry fe;
162     afs_uint32 index;
163 };
164
165 struct CBDiskEntry {
166     struct CallBack cb;
167     afs_uint32 index;
168 };
169
170 /*
171  * active volumes state serialization
172  *
173  * these structures are meant to support
174  * automated salvaging of active volumes
175  * in the event of a fileserver crash
176  */
177
178 /* 512 byte header */
179 struct active_volume_state_header {
180     struct disk_version_stamp stamp;    /* callback state version stamp */
181     afs_uint32 nAVEs;                   /* number of ActiveVolumeEntry records */
182     afs_uint32 init_timestamp;          /* timestamp of AVE initialization */
183     afs_uint32 update_timetamp;         /* timestamp of last AVE update */
184     afs_uint32 reserved[119];           /* for expansion */
185     afs_uint64 avehash_offset;          /* offset of active volume entry hash buckets */
186     afs_uint64 ave_offset;              /* offset of first active volume entry */
187 };
188
189 /* 32 byte header */
190 struct active_volume_state_avehash_header {
191     afs_uint32 magic;         /* magic number for avehash header */
192     afs_uint32 len;           /* total length of header and avehash bucket heads */
193     afs_uint32 records;       /* number of hash buckets */
194     afs_uint32 reserved[5];
195 };
196
197 typedef afs_uint32 active_volume_state_avehash_entry;
198
199 /* active volume entry */
200 struct AVDiskEntry {
201     afs_uint32 volume;
202     afs_uint32 partition;
203     afs_uint32 hash_next;
204 };
205
206
207 /*
208  * dump runtime state
209  */
210 struct idx_map_entry_t {
211     byte valid;                            /* whether or not this entry has been populated */
212     afs_uint32 old_idx;                    /* host hash id from last runtime */
213     afs_uint32 new_idx;                    /* host hash id for this runtime */
214 };
215
216
217 /* verification process sanity check constants
218  *
219  * make them fairly large so we don't get
220  * false positives
221  */
222 #define FS_STATE_H_MAX_UUID_HASH_CHAIN_LEN    100000     /* max elements in a host uuid-hash chain */
223 #define FS_STATE_H_MAX_ADDR_HASH_CHAIN_LEN    2000000    /* max elements in a host ipv4-hash chain */
224 #define FS_STATE_FE_MAX_HASH_CHAIN_LEN        100000     /* max elements in a FE fid-hash chain */
225 #define FS_STATE_FCB_MAX_LIST_LEN             100000     /* max elements in a per-FE CB list */
226 #define FS_STATE_HCB_MAX_LIST_LEN             100000     /* max elements in a per-host CB list */
227 #define FS_STATE_TCB_MAX_LIST_LEN             100000     /* max elements in a per-timeout CB list */
228
229
230 /*
231  * main state serialization state structure
232  */
233
234 struct fs_dump_state {
235     enum {
236         FS_STATE_DUMP_MODE,
237         FS_STATE_LOAD_MODE
238     } mode;
239     struct {
240         byte do_host_restore;              /* whether host restore should be done */
241         byte some_steps_skipped;           /* whether some steps were skipped */
242         byte warnings_generated;           /* whether any warnings were generated during restore */
243     } flags;
244     afs_fsize_t file_len;
245     int fd;                                /* fd of the current dump file */
246     int bail;                              /* non-zero if something went wrong */
247     char * fn;                             /* name of the current dump file */
248     struct {                               /* memory map of dump file */
249         void * map;
250         void * cursor;
251         afs_foff_t offset;
252         afs_fsize_t size;
253     } mmap;
254     struct fs_state_header * hdr;          /* main header */
255     struct host_state_header * h_hdr;      /* header for host state data */
256     struct callback_state_header * cb_hdr; /* header for callback state data */
257     struct callback_state_timeout_header * cb_timeout_hdr;
258     struct callback_state_fehash_header * cb_fehash_hdr;
259     afs_uint64 eof_offset;                 /* current end of file offset */
260     struct {
261         int len;                           /* number of host entries in map */
262         struct idx_map_entry_t * entries;
263     } h_map;
264     struct {
265         int len;
266         struct idx_map_entry_t * entries;
267     } fe_map;
268     struct {
269         int len;
270         struct idx_map_entry_t * entries;
271     } cb_map;
272 };
273
274 /* prototypes */
275
276 /* serialize_state.c */
277 extern int fs_stateFileOpen(struct fs_dump_state *state);
278 extern int fs_stateWrite(struct fs_dump_state * state,
279                          void * buf, size_t len);
280 extern int fs_stateRead(struct fs_dump_state * state,
281                         void * buf, size_t len);
282 extern int fs_stateWriteV(struct fs_dump_state * state,
283                           struct iovec * iov, int niov);
284 extern int fs_stateReadV(struct fs_dump_state * state,
285                          struct iovec * iov, int niov);
286 extern int fs_stateSync(struct fs_dump_state * state);
287 extern int fs_stateWriteHeader(struct fs_dump_state * state,
288                                afs_uint64 * offset,
289                                void * hdr, size_t len);
290 extern int fs_stateReadHeader(struct fs_dump_state * state,
291                               afs_uint64 * offset,
292                               void * hdr, size_t len);
293 extern int fs_stateIncEOF(struct fs_dump_state * state,
294                           afs_int32 len);
295 extern int fs_stateSeek(struct fs_dump_state * state,
296                         afs_uint64 * offset);
297
298 /* host.c */
299 extern int h_stateSave(struct fs_dump_state * state);
300 extern int h_stateRestore(struct fs_dump_state * state);
301 extern int h_stateRestoreIndices(struct fs_dump_state * state);
302 extern int h_stateVerify(struct fs_dump_state * state);
303 extern int h_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new);
304
305 /* callback.c */
306 extern int cb_stateSave(struct fs_dump_state * state);
307 extern int cb_stateRestore(struct fs_dump_state * state);
308 extern int cb_stateRestoreIndices(struct fs_dump_state * state);
309 extern int cb_stateVerify(struct fs_dump_state * state);
310 extern int cb_stateVerifyHCBList(struct fs_dump_state * state, struct host * host);
311 extern int fe_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new);
312 extern int cb_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new);
313
314 #endif /* AFS_DEMAND_ATTACH_FS */
315 #endif /* _AFS_TVICED_SERIALIZE_STATE_H */