Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
logfs_abi.h
Go to the documentation of this file.
1 /*
2  * fs/logfs/logfs_abi.h
3  *
4  * As should be obvious for Linux kernel code, license is GPLv2
5  *
6  * Copyright (c) 2005-2008 Joern Engel <[email protected]>
7  *
8  * Public header for logfs.
9  */
10 #ifndef FS_LOGFS_LOGFS_ABI_H
11 #define FS_LOGFS_LOGFS_ABI_H
12 
13 /* For out-of-kernel compiles */
14 #ifndef BUILD_BUG_ON
15 #define BUILD_BUG_ON(condition)
16 #endif
17 
18 #define SIZE_CHECK(type, size) \
19 static inline void check_##type(void) \
20 { \
21  BUILD_BUG_ON(sizeof(struct type) != (size)); \
22 }
23 
24 /*
25  * Throughout the logfs code, we're constantly dealing with blocks at
26  * various positions or offsets. To remove confusion, we stricly
27  * distinguish between a "position" - the logical position within a
28  * file and an "offset" - the physical location within the device.
29  *
30  * Any usage of the term offset for a logical location or position for
31  * a physical one is a bug and should get fixed.
32  */
33 
34 /*
35  * Block are allocated in one of several segments depending on their
36  * level. The following levels are used:
37  * 0 - regular data block
38  * 1 - i1 indirect blocks
39  * 2 - i2 indirect blocks
40  * 3 - i3 indirect blocks
41  * 4 - i4 indirect blocks
42  * 5 - i5 indirect blocks
43  * 6 - ifile data blocks
44  * 7 - ifile i1 indirect blocks
45  * 8 - ifile i2 indirect blocks
46  * 9 - ifile i3 indirect blocks
47  * 10 - ifile i4 indirect blocks
48  * 11 - ifile i5 indirect blocks
49  * Potential levels to be used in the future:
50  * 12 - gc recycled blocks, long-lived data
51  * 13 - replacement blocks, short-lived data
52  *
53  * Levels 1-11 are necessary for robust gc operations and help separate
54  * short-lived metadata from longer-lived file data. In the future,
55  * file data should get separated into several segments based on simple
56  * heuristics. Old data recycled during gc operation is expected to be
57  * long-lived. New data is of uncertain life expectancy. New data
58  * used to replace older blocks in existing files is expected to be
59  * short-lived.
60  */
61 
62 
63 /* Magic numbers. 64bit for superblock, 32bit for statfs f_type */
64 #define LOGFS_MAGIC 0x7a3a8e5cb9d5bf67ull
65 #define LOGFS_MAGIC_U32 0xc97e8168u
66 
67 /*
68  * Various blocksize related macros. Blocksize is currently fixed at 4KiB.
69  * Sooner or later that should become configurable and the macros replaced
70  * by something superblock-dependent. Pointers in indirect blocks are and
71  * will remain 64bit.
72  *
73  * LOGFS_BLOCKSIZE - self-explaining
74  * LOGFS_BLOCK_FACTOR - number of pointers per indirect block
75  * LOGFS_BLOCK_BITS - log2 of LOGFS_BLOCK_FACTOR, used for shifts
76  */
77 #define LOGFS_BLOCKSIZE (4096ull)
78 #define LOGFS_BLOCK_FACTOR (LOGFS_BLOCKSIZE / sizeof(u64))
79 #define LOGFS_BLOCK_BITS (9)
80 
81 /*
82  * Number of blocks at various levels of indirection. There are 16 direct
83  * block pointers plus a single indirect pointer.
84  */
85 #define I0_BLOCKS (16)
86 #define I1_BLOCKS LOGFS_BLOCK_FACTOR
87 #define I2_BLOCKS (LOGFS_BLOCK_FACTOR * I1_BLOCKS)
88 #define I3_BLOCKS (LOGFS_BLOCK_FACTOR * I2_BLOCKS)
89 #define I4_BLOCKS (LOGFS_BLOCK_FACTOR * I3_BLOCKS)
90 #define I5_BLOCKS (LOGFS_BLOCK_FACTOR * I4_BLOCKS)
91 
92 #define INDIRECT_INDEX I0_BLOCKS
93 #define LOGFS_EMBEDDED_FIELDS (I0_BLOCKS + 1)
94 
95 /*
96  * Sizes at which files require another level of indirection. Files smaller
97  * than LOGFS_EMBEDDED_SIZE can be completely stored in the inode itself,
98  * similar like ext2 fast symlinks.
99  *
100  * Data at a position smaller than LOGFS_I0_SIZE is accessed through the
101  * direct pointers, else through the 1x indirect pointer and so forth.
102  */
103 #define LOGFS_EMBEDDED_SIZE (LOGFS_EMBEDDED_FIELDS * sizeof(u64))
104 #define LOGFS_I0_SIZE (I0_BLOCKS * LOGFS_BLOCKSIZE)
105 #define LOGFS_I1_SIZE (I1_BLOCKS * LOGFS_BLOCKSIZE)
106 #define LOGFS_I2_SIZE (I2_BLOCKS * LOGFS_BLOCKSIZE)
107 #define LOGFS_I3_SIZE (I3_BLOCKS * LOGFS_BLOCKSIZE)
108 #define LOGFS_I4_SIZE (I4_BLOCKS * LOGFS_BLOCKSIZE)
109 #define LOGFS_I5_SIZE (I5_BLOCKS * LOGFS_BLOCKSIZE)
110 
111 /*
112  * Each indirect block pointer must have this flag set, if all block pointers
113  * behind it are set, i.e. there is no hole hidden in the shadow of this
114  * indirect block pointer.
115  */
116 #define LOGFS_FULLY_POPULATED (1ULL << 63)
117 #define pure_ofs(ofs) (ofs & ~LOGFS_FULLY_POPULATED)
118 
119 /*
120  * LogFS needs to separate data into levels. Each level is defined as the
121  * maximal possible distance from the master inode (inode of the inode file).
122  * Data blocks reside on level 0, 1x indirect block on level 1, etc.
123  * Inodes reside on level 6, indirect blocks for the inode file on levels 7-11.
124  * This effort is necessary to guarantee garbage collection to always make
125  * progress.
126  *
127  * LOGFS_MAX_INDIRECT is the maximal indirection through indirect blocks,
128  * LOGFS_MAX_LEVELS is one more for the actual data level of a file. It is
129  * the maximal number of levels for one file.
130  * LOGFS_NO_AREAS is twice that, as the inode file and regular files are
131  * effectively stacked on top of each other.
132  */
133 #define LOGFS_MAX_INDIRECT (5)
134 #define LOGFS_MAX_LEVELS (LOGFS_MAX_INDIRECT + 1)
135 #define LOGFS_NO_AREAS (2 * LOGFS_MAX_LEVELS)
136 
137 /* Maximum size of filenames */
138 #define LOGFS_MAX_NAMELEN (255)
139 
140 /* Number of segments in the primary journal. */
141 #define LOGFS_JOURNAL_SEGS (16)
142 
143 /* Maximum number of free/erased/etc. segments in journal entries */
144 #define MAX_CACHED_SEGS (64)
145 
146 
147 /*
148  * LOGFS_OBJECT_HEADERSIZE is the size of a single header in the object store,
149  * LOGFS_MAX_OBJECTSIZE the size of the largest possible object, including
150  * its header,
151  * LOGFS_SEGMENT_RESERVE is the amount of space reserved for each segment for
152  * its segment header and the padded space at the end when no further objects
153  * fit.
154  */
155 #define LOGFS_OBJECT_HEADERSIZE (0x1c)
156 #define LOGFS_SEGMENT_HEADERSIZE (0x18)
157 #define LOGFS_MAX_OBJECTSIZE (LOGFS_OBJECT_HEADERSIZE + LOGFS_BLOCKSIZE)
158 #define LOGFS_SEGMENT_RESERVE \
159  (LOGFS_SEGMENT_HEADERSIZE + LOGFS_MAX_OBJECTSIZE - 1)
160 
161 /*
162  * Segment types:
163  * SEG_SUPER - Data or indirect block
164  * SEG_JOURNAL - Inode
165  * SEG_OSTORE - Dentry
166  */
167 enum {
168  SEG_SUPER = 0x01,
169  SEG_JOURNAL = 0x02,
170  SEG_OSTORE = 0x03,
171 };
172 
192 };
193 
195 
196 #define LOGFS_FEATURES_INCOMPAT (0ull)
197 #define LOGFS_FEATURES_RO_COMPAT (0ull)
198 #define LOGFS_FEATURES_COMPAT (0ull)
199 
230 
238  __u8 pad0[6];
239 
243 
246 
249 
252 
254 
257 };
258 
260 
261 /*
262  * Object types:
263  * OBJ_BLOCK - Data or indirect block
264  * OBJ_INODE - Inode
265  * OBJ_DENTRY - Dentry
266  */
267 enum {
268  OBJ_BLOCK = 0x04,
269  OBJ_INODE = 0x05,
270  OBJ_DENTRY = 0x06,
271 };
272 
292 } __attribute__((packed));
296 /*
297  * Reserved inode numbers:
298  * LOGFS_INO_MASTER - master inode (for inode file)
299  * LOGFS_INO_ROOT - root directory
300  * LOGFS_INO_SEGFILE - per-segment used bytes and erase count
301  */
302 enum {
308 };
309 
310 /*
311  * Inode flags. High bits should never be written to the medium. They are
312  * reserved for in-memory usage.
313  * Low bits should either remain in sync with the corresponding FS_*_FL or
314  * reuse slots that obviously don't make sense for logfs.
315  *
316  * LOGFS_IF_DIRTY Inode must be written back
317  * LOGFS_IF_ZOMBIE Inode has been deleted
318  * LOGFS_IF_STILLBORN -ENOSPC happened when creating inode
319  */
320 #define LOGFS_IF_COMPRESSED 0x00000004 /* == FS_COMPR_FL */
321 #define LOGFS_IF_DIRTY 0x20000000
322 #define LOGFS_IF_ZOMBIE 0x40000000
323 #define LOGFS_IF_STILLBORN 0x80000000
324 
325 /* Flags available to chattr */
326 #define LOGFS_FL_USER_VISIBLE (LOGFS_IF_COMPRESSED)
327 #define LOGFS_FL_USER_MODIFIABLE (LOGFS_IF_COMPRESSED)
328 /* Flags inherited from parent directory on file/directory creation */
329 #define LOGFS_FL_INHERITED (LOGFS_IF_COMPRESSED)
330 
354 
357 
361 
364 
366 };
367 
369 
370 #define INODE_POINTER_OFS \
371  (offsetof(struct logfs_disk_inode, di_data) / sizeof(__be64))
372 #define INODE_USED_OFS \
373  (offsetof(struct logfs_disk_inode, di_used_bytes) / sizeof(__be64))
374 #define INODE_SIZE_OFS \
375  (offsetof(struct logfs_disk_inode, di_size) / sizeof(__be64))
376 #define INODE_HEIGHT_OFS (0)
377 
386 /* FIXME: add 6 bytes of padding to remove the __packed */
392 } __attribute__((packed));
393 
395 
396 #define RESERVED 0xffffffff
397 #define BADSEG 0xffffffff
398 
413 };
414 
416 
435 };
436 
438 
439 /*
440  * Life expectency of data.
441  * VIM_DEFAULT - default vim
442  * VIM_SEGFILE - for segment file only - very short-living
443  * VIM_GC - GC'd data - likely long-living
444  */
445 enum logfs_vim {
448 };
449 
469 } __attribute__((packed));
473 #define MAX_JOURNAL_HEADER \
474  (sizeof(struct logfs_journal_header) + sizeof(struct logfs_je_area))
475 
490 
493 
496 
500 };
501 
503 
515 
518  u8 pad[7];
519 
521 };
522 
524 
534 };
535 
537 
546  __be32 ec[0];
547 };
548 
550 
557 };
558 
560 
567 };
568 
570 
579  u8 pad[5];
581 };
582 
584 
591 enum {
594 };
595 
596 /*
597  * Journal entries come in groups of 16. First group contains unique
598  * entries, next groups contain one entry per level
599  *
600  * JE_FIRST - smallest possible journal entry number
601  *
602  * JEG_BASE - base group, containing unique entries
603  * JE_COMMIT - commit entry, validates all previous entries
604  * JE_DYNSB - dynamic superblock, anything that ought to be in the
605  * superblock but cannot because it is read-write data
606  * JE_ANCHOR - anchor aka master inode aka inode file's inode
607  * JE_ERASECOUNT erasecounts for all journal segments
608  * JE_SPILLOUT - unused
609  * JE_SEG_ALIAS - aliases segments
610  * JE_AREA - area description
611  *
612  * JE_LAST - largest possible journal entry number
613  */
614 enum {
615  JE_FIRST = 0x01,
616 
617  JEG_BASE = 0x00,
618  JE_COMMIT = 0x02,
619  JE_DYNSB = 0x03,
620  JE_ANCHOR = 0x04,
622  JE_SPILLOUT = 0x06,
623  JE_OBJ_ALIAS = 0x0d,
624  JE_AREA = 0x0e,
625 
626  JE_LAST = 0x0e,
627 };
628 
629 #endif