2 * Copyright 2006, Sine Nomine Associates and others.
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
12 * fileserver state serialization
15 #ifndef _AFS_TVICED_SERIALIZE_STATE_H
16 #define _AFS_TVICED_SERIALIZE_STATE_H
18 #ifdef AFS_DEMAND_ATTACH_FS
20 #define FS_STATE_MAGIC 0x62FA841C
21 #define FS_STATE_VERSION 2
23 #define HOST_STATE_MAGIC 0x7B8C9DAE
24 #define HOST_STATE_VERSION 2
26 #define HOST_STATE_ENTRY_MAGIC 0xA8B9CADB
28 #define CALLBACK_STATE_MAGIC 0x89DE67BC
29 #define CALLBACK_STATE_VERSION 1
31 #define CALLBACK_STATE_TIMEOUT_MAGIC 0x99DD5511
32 #define CALLBACK_STATE_FEHASH_MAGIC 0x77BB33FF
33 #define CALLBACK_STATE_ENTRY_MAGIC 0x54637281
35 #define ACTIVE_VOLUME_STATE_MAGIC 0xAC7557CA
36 #define ACTIVE_VOLUME_STATE_VERSION 1
38 #define ACTIVE_VOLUME_STATE_AVEHASH_MAGIC 0xBADDF00D
40 #define HOST_STATE_VALID_WINDOW 1800 /* 30 minutes */
45 struct disk_version_stamp {
50 /* 1024 byte header structure */
51 struct fs_state_header {
52 struct disk_version_stamp stamp; /* version stamp */
53 time_t timestamp; /* timestamp of save */
54 afs_uint32 sys_name; /* sys name id for this machine */
55 afsUUID server_uuid; /* server's UUID */
56 byte valid; /* whether header contents are valid */
57 byte endianness; /* endianness sanity check (0 for LE, 1 for BE) */
58 byte stats_detailed; /* fs stats detailed sanity check */
59 byte padding1[1]; /* padding */
60 afs_uint32 reserved1[23]; /* for expansion */
61 afs_uint64 avol_offset; /* offset of active volumes structure */
62 afs_uint64 h_offset; /* offset of host_state_header structure */
63 afs_uint64 cb_offset; /* offset of callback_state_header structure */
64 afs_uint64 vlru_offset; /* offset of vlru state structure */
65 afs_uint32 reserved2[56]; /* for expansion */
66 char server_version_string[128]; /* version string from AFS_component_version_number.c */
67 afs_uint32 reserved3[128]; /* for expansion */
71 * host package serialization
74 /* 256 byte header for the host state data */
75 struct host_state_header {
76 struct disk_version_stamp stamp; /* host state version stamp */
77 afs_uint32 records; /* number of stored host records */
78 afs_uint32 index_max; /* max index value encountered */
79 afs_uint32 reserved[60]; /* for expansion */
82 /* 32 byte host entry header */
83 struct host_state_entry_header {
84 afs_uint32 magic; /* stamp */
85 afs_uint32 len; /* number of bytes in this record */
86 afs_uint32 interfaces; /* number of interfaces included in record */
87 afs_uint32 hcps; /* number of hcps entries in record */
88 afs_uint32 reserved[4];
91 /* 36 byte host entry structure */
92 struct hostDiskEntry {
93 afs_uint32 host; /* IP address of host interface that is
94 * currently being used, in network
96 afs_uint16 port; /* port address of host */
97 afs_uint16 hostFlags; /* bit map */
98 byte Console; /* XXXX This host is a console */
99 byte hcpsfailed; /* Retry the cps call next time */
100 byte hcps_valid; /* prlist_val not null */
101 #if FS_STATS_DETAILED
102 byte InSameNetwork; /*Is host's addr in the same network as
103 * the File Server's? */
105 byte padding1[1]; /* for padding */
106 #endif /* FS_STATS_DETAILED */
107 afs_uint32 hcps_len; /* length of hcps */
108 afs_uint32 LastCall; /* time of last call from host */
109 afs_uint32 ActiveCall; /* time of any call but gettime */
110 afs_uint32 cpsCall; /* time of last cps call from this host */
111 afs_uint32 cblist; /* Call back list for this host */
112 afs_uint32 index; /* index for correlating w/ callback dumps */
116 * callback package serialization
119 /* 512 byte header */
120 struct callback_state_header {
121 struct disk_version_stamp stamp; /* callback state version stamp */
122 afs_uint32 nFEs; /* number of FileEntry records */
123 afs_uint32 nCBs; /* number of CallBack records */
124 afs_uint32 fe_max; /* max FileEntry index */
125 afs_uint32 cb_max; /* max CallBack index */
126 afs_int32 tfirst; /* first valid timeout */
127 afs_uint32 reserved[115]; /* for expansion */
128 afs_uint64 timeout_offset; /* offset of timeout queue heads */
129 afs_uint64 fehash_offset; /* offset of file entry hash buckets */
130 afs_uint64 fe_offset; /* offset of first file entry */
134 struct callback_state_timeout_header {
135 afs_uint32 magic; /* magic number for timeout header */
136 afs_uint32 len; /* total length of header and timeout records */
137 afs_uint32 records; /* number of timeout records */
138 afs_uint32 reserved[5];
142 struct callback_state_fehash_header {
143 afs_uint32 magic; /* magic number for fehash header */
144 afs_uint32 len; /* total length of header and fehash bucket heads */
145 afs_uint32 records; /* number of hash buckets */
146 afs_uint32 reserved[5];
150 struct callback_state_entry_header {
151 afs_uint32 magic; /* magic number for FE entry */
152 afs_uint32 len; /* number of bytes in this record */
153 afs_uint32 nCBs; /* number of callbacks for this FE */
154 afs_uint32 reserved[5];
168 * active volumes state serialization
170 * these structures are meant to support
171 * automated salvaging of active volumes
172 * in the event of a fileserver crash
175 /* 512 byte header */
176 struct active_volume_state_header {
177 struct disk_version_stamp stamp; /* callback state version stamp */
178 afs_uint32 nAVEs; /* number of ActiveVolumeEntry records */
179 afs_uint32 init_timestamp; /* timestamp of AVE initialization */
180 afs_uint32 update_timetamp; /* timestamp of last AVE update */
181 afs_uint32 reserved[119]; /* for expansion */
182 afs_uint64 avehash_offset; /* offset of active volume entry hash buckets */
183 afs_uint64 ave_offset; /* offset of first active volume entry */
187 struct active_volume_state_avehash_header {
188 afs_uint32 magic; /* magic number for avehash header */
189 afs_uint32 len; /* total length of header and avehash bucket heads */
190 afs_uint32 records; /* number of hash buckets */
191 afs_uint32 reserved[5];
194 typedef afs_uint32 active_volume_state_avehash_entry;
196 /* active volume entry */
199 afs_uint32 partition;
200 afs_uint32 hash_next;
207 struct idx_map_entry_t {
208 afs_uint32 old_idx; /* host hash id from last runtime */
209 afs_uint32 new_idx; /* host hash id for this runtime */
213 /* verification process sanity check constants
215 * make them fairly large so we don't get
218 #define FS_STATE_H_MAX_UUID_HASH_CHAIN_LEN 100000 /* max elements in a host uuid-hash chain */
219 #define FS_STATE_H_MAX_ADDR_HASH_CHAIN_LEN 2000000 /* max elements in a host ipv4-hash chain */
220 #define FS_STATE_FE_MAX_HASH_CHAIN_LEN 100000 /* max elements in a FE fid-hash chain */
221 #define FS_STATE_FCB_MAX_LIST_LEN 100000 /* max elements in a per-FE CB list */
222 #define FS_STATE_HCB_MAX_LIST_LEN 100000 /* max elements in a per-host CB list */
223 #define FS_STATE_TCB_MAX_LIST_LEN 100000 /* max elements in a per-timeout CB list */
227 * main state serialization state structure
230 struct fs_dump_state {
236 byte do_host_restore; /* whether host restore should be done */
237 byte some_steps_skipped; /* whether some steps were skipped */
238 byte warnings_generated; /* whether any warnings were generated during restore */
240 afs_fsize_t file_len;
241 int fd; /* fd of the current dump file */
242 int bail; /* non-zero if something went wrong */
243 char * fn; /* name of the current dump file */
244 struct { /* memory map of dump file */
250 struct fs_state_header * hdr; /* main header */
251 struct host_state_header * h_hdr; /* header for host state data */
252 struct callback_state_header * cb_hdr; /* header for callback state data */
253 struct callback_state_timeout_header * cb_timeout_hdr;
254 struct callback_state_fehash_header * cb_fehash_hdr;
255 afs_uint64 eof_offset; /* current end of file offset */
257 int len; /* number of host entries in map */
258 struct idx_map_entry_t * entries;
262 struct idx_map_entry_t * entries;
266 struct idx_map_entry_t * entries;
272 /* serialize_state.c */
273 extern int fs_stateFileOpen(struct fs_dump_state *state);
274 extern int fs_stateWrite(struct fs_dump_state * state,
275 void * buf, size_t len);
276 extern int fs_stateRead(struct fs_dump_state * state,
277 void * buf, size_t len);
278 extern int fs_stateWriteV(struct fs_dump_state * state,
279 struct iovec * iov, int niov);
280 extern int fs_stateReadV(struct fs_dump_state * state,
281 struct iovec * iov, int niov);
282 extern int fs_stateSync(struct fs_dump_state * state);
283 extern int fs_stateWriteHeader(struct fs_dump_state * state,
285 void * hdr, size_t len);
286 extern int fs_stateReadHeader(struct fs_dump_state * state,
288 void * hdr, size_t len);
289 extern int fs_stateIncEOF(struct fs_dump_state * state,
291 extern int fs_stateSeek(struct fs_dump_state * state,
292 afs_uint64 * offset);
295 extern int h_stateSave(struct fs_dump_state * state);
296 extern int h_stateRestore(struct fs_dump_state * state);
297 extern int h_stateRestoreIndices(struct fs_dump_state * state);
298 extern int h_stateVerify(struct fs_dump_state * state);
299 extern int h_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new);
302 extern int cb_stateSave(struct fs_dump_state * state);
303 extern int cb_stateRestore(struct fs_dump_state * state);
304 extern int cb_stateRestoreIndices(struct fs_dump_state * state);
305 extern int cb_stateVerify(struct fs_dump_state * state);
306 extern int cb_stateVerifyHCBList(struct fs_dump_state * state, struct host * host);
307 extern int fe_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new);
308 extern int cb_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new);
310 #endif /* AFS_DEMAND_ATTACH_FS */
311 #endif /* _AFS_TVICED_SERIALIZE_STATE_H */