Remove some unused variables.
[dragonfly.git] / sys / vfs / hammer / hammer_disk.h
CommitLineData
8750964d
MD
1/*
2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
d5530d22 34 * $DragonFly: src/sys/vfs/hammer/hammer_disk.h,v 1.17 2008/01/16 01:15:36 dillon Exp $
8750964d
MD
35 */
36
37#ifndef _SYS_UUID_H_
38#include <sys/uuid.h>
39#endif
40
41/*
42 * The structures below represent the on-disk format for a HAMMER
43 * filesystem. Note that all fields for on-disk structures are naturally
44 * aligned. The host endian format is used - compatibility is possible
45 * if the implementation detects reversed endian and adjusts data accordingly.
46 *
47 * Most of HAMMER revolves around the concept of an object identifier. An
48 * obj_id is a 64 bit quantity which uniquely identifies a filesystem object
49 * FOR THE ENTIRE LIFE OF THE FILESYSTEM. This uniqueness allows backups
50 * and mirrors to retain varying amounts of filesystem history by removing
51 * any possibility of conflict through identifier reuse.
52 *
53 * A HAMMER filesystem may spam multiple volumes.
54 *
55 * A HAMMER filesystem uses a 16K filesystem buffer size. All filesystem
c60bb2c5
MD
56 * I/O is done in multiples of 16K. Most buffer-sized headers such as those
57 * used by volumes, super-clusters, clusters, and basic filesystem buffers
58 * use fixed-sized A-lists which are heavily dependant on HAMMER_BUFSIZE.
8750964d
MD
59 */
60#define HAMMER_BUFSIZE 16384
61#define HAMMER_BUFMASK (HAMMER_BUFSIZE - 1)
4d75d829 62#define HAMMER_MAXDATA (256*1024)
8750964d
MD
63
64/*
65 * Hammer transction ids are 64 bit unsigned integers and are usually
66 * synchronized with the time of day in nanoseconds.
67 */
68typedef u_int64_t hammer_tid_t;
69
66325755 70#define HAMMER_MAX_TID 0xFFFFFFFFFFFFFFFFULL
6b4f890b
MD
71#define HAMMER_MIN_KEY -0x8000000000000000LL
72#define HAMMER_MAX_KEY 0x7FFFFFFFFFFFFFFFLL
66325755 73
8750964d
MD
74/*
75 * Most HAMMER data structures are embedded in 16K filesystem buffers.
76 * All filesystem buffers except those designated as pure-data buffers
77 * contain this 128-byte header.
78 *
79 * This structure contains an embedded A-List used to manage space within
80 * the filesystem buffer. It is not used by volume or cluster header
81 * buffers, or by pure-data buffers. The granularity is variable and
82 * depends on the type of filesystem buffer. BLKSIZE is just a minimum.
83 */
84
85#define HAMMER_FSBUF_HEAD_SIZE 128
86#define HAMMER_FSBUF_MAXBLKS 256
9775c955 87#define HAMMER_FSBUF_BLKMASK (HAMMER_FSBUF_MAXBLKS - 1)
c60bb2c5 88#define HAMMER_FSBUF_METAELMS HAMMER_ALIST_METAELMS_256_1LYR /* 11 */
8750964d
MD
89
90struct hammer_fsbuf_head {
91 u_int64_t buf_type;
92 u_int32_t buf_crc;
93 u_int32_t buf_reserved07;
c60bb2c5 94 u_int32_t reserved[6];
8750964d
MD
95 struct hammer_almeta buf_almeta[HAMMER_FSBUF_METAELMS];
96};
97
98typedef struct hammer_fsbuf_head *hammer_fsbuf_head_t;
99
c60bb2c5
MD
100/*
101 * Note: Pure-data buffers contain pure-data and have no buf_type.
102 * Piecemeal data buffers do have a header and use HAMMER_FSBUF_DATA.
103 */
8750964d 104#define HAMMER_FSBUF_VOLUME 0xC8414D4DC5523031ULL /* HAMMER01 */
c60bb2c5 105#define HAMMER_FSBUF_SUPERCL 0xC8414D52C3555052ULL /* HAMRSUPR */
8750964d
MD
106#define HAMMER_FSBUF_CLUSTER 0xC8414D52C34C5553ULL /* HAMRCLUS */
107#define HAMMER_FSBUF_RECORDS 0xC8414D52D2454353ULL /* HAMRRECS */
108#define HAMMER_FSBUF_BTREE 0xC8414D52C2545245ULL /* HAMRBTRE */
109#define HAMMER_FSBUF_DATA 0xC8414D52C4415441ULL /* HAMRDATA */
110
111#define HAMMER_FSBUF_VOLUME_REV 0x313052C54D4D41C8ULL /* (reverse endian) */
112
113/*
114 * The B-Tree structures need hammer_fsbuf_head.
115 */
116#include "hammer_btree.h"
117
118/*
119 * HAMMER Volume header
120 *
121 * A HAMMER filesystem is built from any number of block devices, Each block
c60bb2c5
MD
122 * device contains a volume header followed by however many super-clusters
123 * and clusters fit into the volume. Clusters cannot be migrated but the
124 * data they contain can, so HAMMER can use a truncated cluster for any
125 * extra space at the end of the volume.
8750964d
MD
126 *
127 * The volume containing the root cluster is designated as the master volume.
128 * The root cluster designation can be moved to any volume.
129 *
130 * The volume header takes up an entire 16K filesystem buffer and includes
c60bb2c5
MD
131 * a one or two-layered A-list to manage the clusters making up the volume.
132 * A volume containing up to 32768 clusters (2TB) can be managed with a
133 * single-layered A-list. A two-layer A-list is capable of managing up
7f7c1f84
MD
134 * to 4096 super-clusters with each super-cluster containing 32768 clusters
135 * (8192 TB per volume total). The number of volumes is limited to 32768
c60bb2c5
MD
136 * but it only takes 512 to fill out a 64 bit address space so for all
137 * intents and purposes the filesystem has no limits.
138 *
139 * cluster addressing within a volume depends on whether a single or
140 * duel-layer A-list is used. If a duel-layer A-list is used a 16K
7f7c1f84 141 * super-cluster buffer is needed for every 32768 clusters in the volume.
c60bb2c5
MD
142 * However, because the A-list's hinting is grouped in multiples of 16
143 * we group 16 super-cluster buffers together (starting just after the
144 * volume header), followed by 16384x16 clusters, and repeat.
145 *
7f7c1f84
MD
146 * The number of super-clusters is limited to 4096 because the A-list's
147 * master radix is stored as a 32 bit signed quantity which will overflow
148 * if more then 4096*32768 elements is specified. XXX
149 *
c60bb2c5
MD
150 * NOTE: A 32768-element single-layer and 16384-element duel-layer A-list
151 * is the same size.
a89aec1b
MD
152 *
153 * Special field notes:
154 *
155 * vol_bot_beg - offset of boot area (mem_beg - bot_beg bytes)
156 * vol_mem_beg - offset of memory log (clu_beg - mem_beg bytes)
157 * vol_clo_beg - offset of cluster #0 in volume
158 *
159 * The memory log area allows a kernel to cache new records and data
160 * in memory without allocating space in the actual filesystem to hold
161 * the records and data. In the event that a filesystem becomes full,
162 * any records remaining in memory can be flushed to the memory log
163 * area. This allows the kernel to immediately return success.
8750964d 164 */
c60bb2c5 165#define HAMMER_VOL_MAXCLUSTERS 32768 /* 1-layer */
7f7c1f84 166#define HAMMER_VOL_MAXSUPERCLUSTERS 4096 /* 2-layer */
c60bb2c5
MD
167#define HAMMER_VOL_SUPERCLUSTER_GROUP 16
168#define HAMMER_VOL_METAELMS_1LYR HAMMER_ALIST_METAELMS_32K_1LYR
169#define HAMMER_VOL_METAELMS_2LYR HAMMER_ALIST_METAELMS_16K_2LYR
8750964d 170
a89aec1b
MD
171#define HAMMER_BOOT_MINBYTES (32*1024)
172#define HAMMER_BOOT_NOMBYTES (64LL*1024*1024)
173#define HAMMER_BOOT_MAXBYTES (256LL*1024*1024)
174
175#define HAMMER_MEM_MINBYTES (256*1024)
176#define HAMMER_MEM_NOMBYTES (1LL*1024*1024*1024)
177#define HAMMER_MEM_MAXBYTES (64LL*1024*1024*1024)
178
8750964d
MD
179struct hammer_volume_ondisk {
180 struct hammer_fsbuf_head head;
a89aec1b
MD
181 int64_t vol_bot_beg; /* byte offset of boot area or 0 */
182 int64_t vol_mem_beg; /* byte offset of memory log or 0 */
183 int64_t vol_clo_beg; /* byte offset of first cl/supercl in volume */
184 int64_t vol_clo_end; /* byte offset of volume EOF */
8750964d
MD
185 int64_t vol_locked; /* reserved clusters are >= this offset */
186
187 uuid_t vol_fsid; /* identify filesystem */
188 uuid_t vol_fstype; /* identify filesystem type */
189 char vol_name[64]; /* Name of volume */
190
191 int32_t vol_no; /* volume number within filesystem */
192 int32_t vol_count; /* number of volumes making up FS */
193
194 u_int32_t vol_version; /* version control information */
9775c955 195 u_int32_t vol_reserved01;
8750964d
MD
196 u_int32_t vol_flags; /* volume flags */
197 u_int32_t vol_rootvol; /* which volume is the root volume? */
198
199 int32_t vol_clsize; /* cluster size (same for all volumes) */
9775c955 200 int32_t vol_nclusters;
8750964d
MD
201 u_int32_t vol_reserved06;
202 u_int32_t vol_reserved07;
203
fbc6e32a
MD
204 int32_t vol_blocksize; /* for statfs only */
205 int64_t vol_nblocks; /* total allocatable hammer bufs */
206
207 /*
208 * This statistical information can get out of sync after a crash
209 * and is recovered slowly.
210 */
27ea2398 211 int64_t vol_stat_bytes; /* for statfs only */
fbc6e32a
MD
212 int64_t unused08; /* for statfs only */
213 int64_t vol_stat_data_bufs; /* hammer bufs allocated to data */
214 int64_t vol_stat_rec_bufs; /* hammer bufs allocated to records */
215 int64_t vol_stat_idx_bufs; /* hammer bufs allocated to B-Tree */
27ea2398 216
8750964d
MD
217 /*
218 * These fields are initialized and space is reserved in every
219 * volume making up a HAMMER filesytem, but only the master volume
220 * contains valid data.
221 */
fbc6e32a
MD
222 int64_t vol0_stat_bytes; /* for statfs only */
223 int64_t vol0_stat_inodes; /* for statfs only */
224 int64_t vol0_stat_data_bufs; /* hammer bufs allocated to data */
225 int64_t vol0_stat_rec_bufs; /* hammer bufs allocated to records */
226 int64_t vol0_stat_idx_bufs; /* hammer bufs allocated to B-Tree */
227
427e5fc6
MD
228 int32_t vol0_root_clu_no; /* root cluster no (index) in rootvol */
229 hammer_tid_t vol0_root_clu_id; /* root cluster id */
8750964d
MD
230 hammer_tid_t vol0_nexttid; /* next TID */
231 u_int64_t vol0_recid; /* fs-wide record id allocator */
66325755 232 u_int64_t vol0_synchronized_rec_id; /* XXX */
8750964d
MD
233
234 char reserved[1024];
235
c60bb2c5
MD
236 /*
237 * Meta elements for the volume header's A-list, which is either a
238 * 1-layer A-list capable of managing 32768 clusters, or a 2-layer
239 * A-list capable of managing 16384 super-clusters (each of which
240 * can handle 32768 clusters).
241 */
242 union {
9775c955
MD
243 struct hammer_almeta super[HAMMER_VOL_METAELMS_2LYR];
244 struct hammer_almeta normal[HAMMER_VOL_METAELMS_1LYR];
c60bb2c5 245 } vol_almeta;
8750964d
MD
246 u_int32_t vol0_bitmap[1024];
247};
248
8cd0a023
MD
249typedef struct hammer_volume_ondisk *hammer_volume_ondisk_t;
250
c60bb2c5
MD
251#define HAMMER_VOLF_VALID 0x0001 /* valid entry */
252#define HAMMER_VOLF_OPEN 0x0002 /* volume is open */
427e5fc6 253#define HAMMER_VOLF_USINGSUPERCL 0x0004 /* using superclusters */
c60bb2c5
MD
254
255/*
256 * HAMMER Super-cluster header
257 *
258 * A super-cluster is used to increase the maximum size of a volume.
259 * HAMMER's volume header can manage up to 32768 direct clusters or
260 * 16384 super-clusters. Each super-cluster (which is basically just
261 * a 16K filesystem buffer) can manage up to 32768 clusters. So adding
262 * a super-cluster layer allows a HAMMER volume to be sized upwards of
263 * around 32768TB instead of 2TB.
264 *
265 * Any volume initially formatted to be over 32G reserves space for the layer
266 * but the layer is only enabled if the volume exceeds 2TB.
267 */
268#define HAMMER_SUPERCL_METAELMS HAMMER_ALIST_METAELMS_32K_1LYR
9775c955 269#define HAMMER_SCL_MAXCLUSTERS HAMMER_VOL_MAXCLUSTERS
c60bb2c5
MD
270
271struct hammer_supercl_ondisk {
272 struct hammer_fsbuf_head head;
273 uuid_t vol_fsid; /* identify filesystem - sanity check */
274 uuid_t vol_fstype; /* identify filesystem type - sanity check */
275 int32_t reserved[1024];
276
9775c955 277 struct hammer_almeta scl_meta[HAMMER_SUPERCL_METAELMS];
c60bb2c5 278};
8750964d 279
8cd0a023
MD
280typedef struct hammer_supercl_ondisk *hammer_supercl_ondisk_t;
281
8750964d
MD
282/*
283 * HAMMER Cluster header
284 *
c60bb2c5
MD
285 * A cluster is limited to 64MB and is made up of 4096 16K filesystem
286 * buffers. The cluster header contains four A-lists to manage these
287 * buffers.
288 *
289 * master_alist - This is a non-layered A-list which manages pure-data
290 * allocations and allocations on behalf of other A-lists.
291 *
292 * btree_alist - This is a layered A-list which manages filesystem buffers
293 * containing B-Tree nodes.
8750964d 294 *
c60bb2c5
MD
295 * record_alist - This is a layered A-list which manages filesystem buffers
296 * containing records.
297 *
298 * mdata_alist - This is a layered A-list which manages filesystem buffers
299 * containing piecemeal record data.
300 *
301 * General storage management works like this: All the A-lists except the
302 * master start in an all-allocated state. Now lets say you wish to allocate
303 * a B-Tree node out the btree_alist. If the allocation fails you allocate
304 * a pure data block out of master_alist and then free that block in
305 * btree_alist, thereby assigning more space to the btree_alist, and then
306 * retry your allocation out of the btree_alist. In the reverse direction,
307 * filesystem buffers can be garbage collected back to master_alist simply
308 * by doing whole-buffer allocations in btree_alist and then freeing the
309 * space in master_alist. The whole-buffer-allocation approach to garbage
310 * collection works because A-list allocations are always power-of-2 sized
311 * and aligned.
8750964d 312 */
c60bb2c5
MD
313#define HAMMER_CLU_MAXBUFFERS 4096
314#define HAMMER_CLU_MASTER_METAELMS HAMMER_ALIST_METAELMS_4K_1LYR
315#define HAMMER_CLU_SLAVE_METAELMS HAMMER_ALIST_METAELMS_4K_2LYR
9775c955 316#define HAMMER_CLU_MAXBYTES (HAMMER_CLU_MAXBUFFERS * HAMMER_BUFSIZE)
8750964d
MD
317
318struct hammer_cluster_ondisk {
319 struct hammer_fsbuf_head head;
320 uuid_t vol_fsid; /* identify filesystem - sanity check */
321 uuid_t vol_fstype; /* identify filesystem type - sanity check */
322
8750964d 323 hammer_tid_t clu_id; /* unique cluster self identification */
8cd0a023 324 hammer_tid_t clu_gen; /* generation number */
8750964d
MD
325 int32_t vol_no; /* cluster contained in volume (sanity) */
326 u_int32_t clu_flags; /* cluster flags */
327
328 int32_t clu_start; /* start of data (byte offset) */
329 int32_t clu_limit; /* end of data (byte offset) */
330 int32_t clu_no; /* cluster index in volume (sanity) */
331 u_int32_t clu_reserved03;
332
333 u_int32_t clu_reserved04;
334 u_int32_t clu_reserved05;
335 u_int32_t clu_reserved06;
336 u_int32_t clu_reserved07;
337
fbc6e32a 338 /*
4d75d829
MD
339 * These fields are mostly heuristics to aid in locality of
340 * reference allocations.
fbc6e32a 341 */
9775c955
MD
342 int32_t idx_data; /* data append point (element no) */
343 int32_t idx_index; /* index append point (element no) */
344 int32_t idx_record; /* record prepend point (element no) */
c0ade690 345 int32_t idx_ldata; /* large block data append pt (buf_no) */
8750964d 346
fbc6e32a
MD
347 /*
348 * These fields can become out of sync after a filesystem crash
349 * and are cleaned up in the background. They are used for
350 * reporting only.
351 */
352 int32_t stat_inodes; /* number of inodes in cluster */
353 int32_t stat_data_bufs; /* hammer bufs allocated to data */
354 int32_t stat_rec_bufs; /* hammer bufs allocated to records */
355 int32_t stat_idx_bufs; /* hammer bufs allocated to B-Tree */
356
8750964d 357 /*
c60bb2c5 358 * Specify the range of information stored in this cluster as two
8cd0a023
MD
359 * btree elements. These elements match the left and right
360 * boundary elements in the internal B-Tree node of the parent
361 * cluster that points to the root of our cluster. Because these
362 * are boundary elements, the right boundary is range-NONinclusive.
8750964d 363 */
c60bb2c5
MD
364 struct hammer_base_elm clu_btree_beg;
365 struct hammer_base_elm clu_btree_end;
8750964d
MD
366
367 /*
c60bb2c5
MD
368 * The cluster's B-Tree root can change as a side effect of insertion
369 * and deletion operations so store an offset instead of embedding
8cd0a023
MD
370 * the root node. The parent_offset is stale if the generation number
371 * does not match.
372 *
373 * Parent linkages are explicit.
8750964d 374 */
c60bb2c5
MD
375 int32_t clu_btree_root;
376 int32_t clu_btree_parent_vol_no;
377 int32_t clu_btree_parent_clu_no;
8cd0a023
MD
378 int32_t clu_btree_parent_offset;
379 hammer_tid_t clu_btree_parent_clu_gen;
8750964d 380
4d75d829
MD
381 /*
382 * The synchronized record id is used for recovery purposes.
383 */
384 u_int64_t synchronized_tid;
385 u_int32_t reserved16[510];
8750964d 386
9775c955
MD
387 struct hammer_almeta clu_master_meta[HAMMER_CLU_MASTER_METAELMS];
388 struct hammer_almeta clu_btree_meta[HAMMER_CLU_SLAVE_METAELMS];
389 struct hammer_almeta clu_record_meta[HAMMER_CLU_SLAVE_METAELMS];
390 struct hammer_almeta clu_mdata_meta[HAMMER_CLU_SLAVE_METAELMS];
4d75d829
MD
391
392 /*
393 * A straight bitmap records which filesystem buffers contain records.
394 * The recovery code reconstructs the A-lists using this bitmap.
395 */
396 u_int32_t clu_record_buf_bitmap[HAMMER_CLU_MAXBUFFERS / 32];
8750964d
MD
397};
398
8cd0a023
MD
399typedef struct hammer_cluster_ondisk *hammer_cluster_ondisk_t;
400
4d75d829
MD
401/*
402 * Cluster clu_flags
403 *
404 * OPEN - A cluster is marked open and synchronized to disk prior to any
405 * modifications being made to either the cluster header or any cluster
406 * buffers. If initial access to a cluster finds this flag set, the
407 * cluster is recovered before any further operations are performed on it.
408 */
fbc6e32a
MD
409#define HAMMER_CLUF_OPEN 0x0001 /* cluster is dirty */
410
8750964d
MD
411/*
412 * HAMMER records are 96 byte entities encoded into 16K filesystem buffers.
413 * Each record has a 64 byte header and a 32 byte extension. 170 records
414 * fit into each buffer. Storage is managed by the buffer's A-List.
415 *
416 * Each record may have an explicit data reference to a block of data up
417 * to 2^31-1 bytes in size within the current cluster. Note that multiple
418 * records may share the same or overlapping data references.
419 */
420
421/*
422 * All HAMMER records have a common 64-byte base and a 32-byte extension.
423 *
424 * Many HAMMER record types reference out-of-band data within the cluster.
425 * This data can also be stored in-band in the record itself if it is small
426 * enough. Either way, (data_offset, data_len) points to it.
427 *
d5530d22 428 * Key comparison order: obj_id, rec_type, key, delete_tid
8750964d
MD
429 */
430struct hammer_base_record {
427e5fc6
MD
431 /*
432 * 40 byte base element info - same base as used in B-Tree internal
433 * and leaf node element arrays.
434 *
435 * Fields: obj_id, key, create_tid, delete_tid, rec_type, obj_type,
436 * reserved07.
437 */
438 struct hammer_base_elm base; /* 00 base element info */
8750964d 439
8750964d
MD
440 int32_t data_len; /* 28 size of data (remainder zero-fill) */
441 u_int32_t data_crc; /* 2C data sanity check */
442 u_int64_t rec_id; /* 30 record id (iterator for recovery) */
427e5fc6
MD
443 int32_t data_offset; /* 38 cluster-relative data reference or 0 */
444 u_int32_t reserved07; /* 3C */
8750964d
MD
445 /* 40 */
446};
447
c60bb2c5
MD
448/*
449 * Record types are fairly straightforward. The B-Tree includes the record
450 * type in its index sort.
451 *
452 * In particular please note that it is possible to create a pseudo-
453 * filesystem within a HAMMER filesystem by creating a special object
454 * type within a directory. Pseudo-filesystems are used as replication
455 * targets and even though they are built within a HAMMER filesystem they
456 * get their own obj_id space (and thus can serve as a replication target)
457 * and look like a mount point to the system.
8cd0a023
MD
458 *
459 * Inter-cluster records are special-cased in the B-Tree. These records
460 * are referenced from a B-Tree INTERNAL node, NOT A LEAF. This means
461 * that the element in the B-Tree node is actually a boundary element whos
462 * base element fields, including rec_type, reflect the boundary, NOT
463 * the inter-cluster record type.
464 *
465 * HAMMER_RECTYPE_CLUSTER - only set in the actual inter-cluster record,
466 * not set in the left or right boundary elements around the inter-cluster
467 * reference of an internal node in the B-Tree (because doing so would
468 * interfere with the boundary tests).
b3deaf57
MD
469 *
470 * NOTE: hammer_ip_delete_range_all() deletes all record types greater
471 * then HAMMER_RECTYPE_INODE.
c60bb2c5 472 */
8750964d 473#define HAMMER_RECTYPE_UNKNOWN 0
66325755 474#define HAMMER_RECTYPE_LOWEST 1 /* lowest record type avail */
8750964d 475#define HAMMER_RECTYPE_INODE 1 /* inode in obj_id space */
c60bb2c5 476#define HAMMER_RECTYPE_PSEUDO_INODE 2 /* pseudo filesysem */
8cd0a023 477#define HAMMER_RECTYPE_CLUSTER 3 /* inter-cluster reference */
66325755
MD
478#define HAMMER_RECTYPE_DATA 0x10
479#define HAMMER_RECTYPE_DIRENTRY 0x11
480#define HAMMER_RECTYPE_DB 0x12
481#define HAMMER_RECTYPE_EXT 0x13 /* ext attributes */
7a04d74f
MD
482#define HAMMER_RECTYPE_FIX 0x14 /* fixed attribute */
483
484#define HAMMER_FIXKEY_SYMLINK 1
8750964d 485
66325755 486#define HAMMER_OBJTYPE_UNKNOWN 0 /* (never exists on-disk) */
8750964d
MD
487#define HAMMER_OBJTYPE_DIRECTORY 1
488#define HAMMER_OBJTYPE_REGFILE 2
489#define HAMMER_OBJTYPE_DBFILE 3
490#define HAMMER_OBJTYPE_FIFO 4
c60bb2c5
MD
491#define HAMMER_OBJTYPE_CDEV 5
492#define HAMMER_OBJTYPE_BDEV 6
493#define HAMMER_OBJTYPE_SOFTLINK 7
494#define HAMMER_OBJTYPE_PSEUDOFS 8 /* pseudo filesystem obj */
495
8750964d
MD
496/*
497 * Generic full-sized record
498 */
499struct hammer_generic_record {
500 struct hammer_base_record base;
501 char filler[32];
502};
503
504/*
505 * A HAMMER inode record.
506 *
507 * This forms the basis for a filesystem object. obj_id is the inode number,
508 * key1 represents the pseudo filesystem id for security partitioning
509 * (preventing cross-links and/or restricting a NFS export and specifying the
510 * security policy), and key2 represents the data retention policy id.
511 *
512 * Inode numbers are 64 bit quantities which uniquely identify a filesystem
513 * object for the ENTIRE life of the filesystem, even after the object has
514 * been deleted. For all intents and purposes inode numbers are simply
515 * allocated by incrementing a sequence space.
516 *
517 * There is an important distinction between the data stored in the inode
518 * record and the record's data reference. The record references a
519 * hammer_inode_data structure but the filesystem object size and hard link
520 * count is stored in the inode record itself. This allows multiple inodes
521 * to share the same hammer_inode_data structure. This is possible because
522 * any modifications will lay out new data. The HAMMER implementation need
523 * not use the data-sharing ability when laying down new records.
524 *
525 * A HAMMER inode is subject to the same historical storage requirements
526 * as any other record. In particular any change in filesystem or hard link
527 * count will lay down a new inode record when the filesystem is synced to
528 * disk. This can lead to a lot of junk records which get cleaned up by
529 * the data retention policy.
530 *
531 * The ino_atime and ino_mtime fields are a special case. Modifications to
532 * these fields do NOT lay down a new record by default, though the values
533 * are effectively frozen for snapshots which access historical versions
534 * of the inode record due to other operations. This means that atime will
535 * not necessarily be accurate in snapshots, backups, or mirrors. mtime
536 * will be accurate in backups and mirrors since it can be regenerated from
537 * the mirroring stream.
538 *
539 * Because nlinks is historically retained the hardlink count will be
540 * accurate when accessing a HAMMER filesystem snapshot.
541 */
542struct hammer_inode_record {
543 struct hammer_base_record base;
544 u_int64_t ino_atime; /* last access time (not historical) */
545 u_int64_t ino_mtime; /* last modified time (not historical) */
546 u_int64_t ino_size; /* filesystem object size */
547 u_int64_t ino_nlinks; /* hard links */
548};
549
550/*
551 * Data records specify the entire contents of a regular file object,
552 * including attributes. Small amounts of data can theoretically be
553 * embedded in the record itself but the use of this ability verses using
554 * an out-of-band data reference depends on the implementation.
555 */
556struct hammer_data_record {
557 struct hammer_base_record base;
558 char filler[32];
559};
560
561/*
562 * A directory entry specifies the HAMMER filesystem object id, a copy of
563 * the file type, and file name (either embedded or as out-of-band data).
564 * If the file name is short enough to fit into den_name[] (including a
565 * terminating nul) then it will be embedded in the record, otherwise it
566 * is stored out-of-band. The base record's data reference always points
567 * to the nul-terminated filename regardless.
568 *
569 * Directory entries are indexed with a 128 bit namekey rather then an
570 * offset. A portion of the namekey is an iterator or randomizer to deal
571 * with collisions.
66325755 572 *
6b4f890b
MD
573 * NOTE: base.base.obj_type holds the filesystem object type of obj_id,
574 * e.g. a den_type equivalent.
575 *
576 * NOTE: den_name / the filename data reference is NOT terminated with \0.
66325755 577 *
8750964d
MD
578 */
579struct hammer_entry_record {
580 struct hammer_base_record base;
581 u_int64_t obj_id; /* object being referenced */
582 u_int64_t reserved01;
66325755 583 char den_name[16]; /* short file names fit in record */
8750964d
MD
584};
585
f3b0f382
MD
586/*
587 * Spike record
588 */
589struct hammer_spike_record {
590 struct hammer_base_record base;
591 int32_t clu_no;
592 int32_t vol_no;
593 hammer_tid_t clu_id;
594 char reserved[16];
595};
596
8750964d
MD
597/*
598 * Hammer rollup record
599 */
c60bb2c5 600union hammer_record_ondisk {
8750964d
MD
601 struct hammer_base_record base;
602 struct hammer_generic_record generic;
f3b0f382 603 struct hammer_spike_record spike;
8750964d
MD
604 struct hammer_inode_record inode;
605 struct hammer_data_record data;
606 struct hammer_entry_record entry;
607};
608
c60bb2c5 609typedef union hammer_record_ondisk *hammer_record_ondisk_t;
8750964d
MD
610
611/*
612 * Filesystem buffer for records
613 */
614#define HAMMER_RECORD_NODES \
7f7c1f84 615 ((HAMMER_BUFSIZE - sizeof(struct hammer_fsbuf_head) - 32) / \
c60bb2c5 616 sizeof(union hammer_record_ondisk))
8750964d 617
195c19a1
MD
618#define HAMMER_RECORD_SIZE (64+32)
619
8750964d
MD
620struct hammer_fsbuf_recs {
621 struct hammer_fsbuf_head head;
622 char unused[32];
c60bb2c5 623 union hammer_record_ondisk recs[HAMMER_RECORD_NODES];
8750964d
MD
624};
625
626/*
627 * Filesystem buffer for piecemeal data. Note that this does not apply
628 * to dedicated pure-data buffers as such buffers do not have a header.
629 */
630
631#define HAMMER_DATA_SIZE (HAMMER_BUFSIZE - sizeof(struct hammer_fsbuf_head))
632#define HAMMER_DATA_BLKSIZE 64
9775c955 633#define HAMMER_DATA_BLKMASK (HAMMER_DATA_BLKSIZE-1)
8750964d
MD
634#define HAMMER_DATA_NODES (HAMMER_DATA_SIZE / HAMMER_DATA_BLKSIZE)
635
636struct hammer_fsbuf_data {
637 struct hammer_fsbuf_head head;
638 u_int8_t data[HAMMER_DATA_NODES][HAMMER_DATA_BLKSIZE];
639};
640
9775c955
MD
641/*
642 * Filesystem buffer rollup
643 */
644union hammer_fsbuf_ondisk {
645 struct hammer_fsbuf_head head;
646 struct hammer_fsbuf_btree btree;
647 struct hammer_fsbuf_recs record;
648 struct hammer_fsbuf_data data;
649};
650
651typedef union hammer_fsbuf_ondisk *hammer_fsbuf_ondisk_t;
8750964d
MD
652
653/*
654 * HAMMER UNIX Attribute data
655 *
656 * The data reference in a HAMMER inode record points to this structure. Any
657 * modifications to the contents of this structure will result in a record
658 * replacement operation.
659 *
66325755
MD
660 * short_data_off allows a small amount of data to be embedded in the
661 * hammer_inode_data structure. HAMMER typically uses this to represent
662 * up to 64 bytes of data, or to hold symlinks. Remember that allocations
663 * are in powers of 2 so 64, 192, 448, or 960 bytes of embedded data is
664 * support (64+64, 64+192, 64+448 64+960).
665 *
666 * parent_obj_id is only valid for directories (which cannot be hard-linked),
667 * and specifies the parent directory obj_id. This field will also be set
668 * for non-directory inodes as a recovery aid, but can wind up specifying
669 * stale information. However, since object id's are not reused, the worse
670 * that happens is that the recovery code is unable to use it.
8750964d
MD
671 */
672struct hammer_inode_data {
673 u_int16_t version; /* inode data version */
674 u_int16_t mode; /* basic unix permissions */
675 u_int32_t uflags; /* chflags */
7a04d74f
MD
676 u_int32_t rmajor; /* used by device nodes */
677 u_int32_t rminor; /* used by device nodes */
66325755
MD
678 u_int64_t ctime;
679 u_int64_t parent_obj_id;/* parent directory obj_id */
8750964d
MD
680 uuid_t uid;
681 uuid_t gid;
8cd0a023 682 /* XXX device, softlink extension */
8750964d
MD
683};
684
685#define HAMMER_INODE_DATA_VERSION 1
686
7a04d74f
MD
687#define HAMMER_OBJID_ROOT 1
688
c60bb2c5
MD
689/*
690 * Rollup various structures embedded as record data
691 */
427e5fc6 692union hammer_data_ondisk {
c60bb2c5
MD
693 struct hammer_inode_data inode;
694};
695