1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6 #ifndef __XFS_LOG_FORMAT_H__
7 #define __XFS_LOG_FORMAT_H__
8
9 struct xfs_mount;
10 struct xfs_trans_res;
11
12 /*
13 * On-disk Log Format definitions.
14 *
15 * This file contains all the on-disk format definitions used within the log. It
16 * includes the physical log structure itself, as well as all the log item
17 * format structures that are written into the log and intepreted by log
18 * recovery. We start with the physical log format definitions, and then work
19 * through all the log items definitions and everything they encode into the
20 * log.
21 */
22 typedef uint32_t xlog_tid_t;
23
24 #define XLOG_MIN_ICLOGS 2
25 #define XLOG_MAX_ICLOGS 8
26 #define XLOG_HEADER_MAGIC_NUM 0xFEEDbabe /* Invalid cycle number */
27 #define XLOG_VERSION_1 1
28 #define XLOG_VERSION_2 2 /* Large IClogs, Log sunit */
29 #define XLOG_VERSION_OKBITS (XLOG_VERSION_1 | XLOG_VERSION_2)
30 #define XLOG_MIN_RECORD_BSIZE (16*1024) /* eventually 32k */
31 #define XLOG_BIG_RECORD_BSIZE (32*1024) /* 32k buffers */
32 #define XLOG_MAX_RECORD_BSIZE (256*1024)
33 #define XLOG_HEADER_CYCLE_SIZE (32*1024) /* cycle data in header */
34 #define XLOG_MIN_RECORD_BSHIFT 14 /* 16384 == 1 << 14 */
35 #define XLOG_BIG_RECORD_BSHIFT 15 /* 32k == 1 << 15 */
36 #define XLOG_MAX_RECORD_BSHIFT 18 /* 256k == 1 << 18 */
37
38 #define XLOG_HEADER_SIZE 512
39
40 /* Minimum number of transactions that must fit in the log (defined by mkfs) */
41 #define XFS_MIN_LOG_FACTOR 3
42
43 #define XLOG_REC_SHIFT(log) \
44 BTOBB(1 << (xfs_has_logv2(log->l_mp) ? \
45 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
46 #define XLOG_TOTAL_REC_SHIFT(log) \
47 BTOBB(XLOG_MAX_ICLOGS << (xfs_has_logv2(log->l_mp) ? \
48 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
49
50 /* get lsn fields */
51 #define CYCLE_LSN(lsn) ((uint)((lsn)>>32))
52 #define BLOCK_LSN(lsn) ((uint)(lsn))
53
54 /* this is used in a spot where we might otherwise double-endian-flip */
55 #define CYCLE_LSN_DISK(lsn) (((__be32 *)&(lsn))[0])
56
xlog_assign_lsn(uint cycle,uint block)57 static inline xfs_lsn_t xlog_assign_lsn(uint cycle, uint block)
58 {
59 return ((xfs_lsn_t)cycle << 32) | block;
60 }
61
xlog_get_cycle(char * ptr)62 static inline uint xlog_get_cycle(char *ptr)
63 {
64 if (be32_to_cpu(*(__be32 *)ptr) == XLOG_HEADER_MAGIC_NUM)
65 return be32_to_cpu(*((__be32 *)ptr + 1));
66 else
67 return be32_to_cpu(*(__be32 *)ptr);
68 }
69
70 /* Log Clients */
71 #define XFS_TRANSACTION 0x69
72 #define XFS_VOLUME 0x2
73 #define XFS_LOG 0xaa
74
75 #define XLOG_UNMOUNT_TYPE 0x556e /* Un for Unmount */
76
77 /*
78 * Log item for unmount records.
79 *
80 * The unmount record used to have a string "Unmount filesystem--" in the
81 * data section where the "Un" was really a magic number (XLOG_UNMOUNT_TYPE).
82 * We just write the magic number now; see xfs_log_unmount_write.
83 */
84 struct xfs_unmount_log_format {
85 uint16_t magic; /* XLOG_UNMOUNT_TYPE */
86 uint16_t pad1;
87 uint32_t pad2; /* may as well make it 64 bits */
88 };
89
90 /* Region types for iovec's i_type */
91 #define XLOG_REG_TYPE_BFORMAT 1
92 #define XLOG_REG_TYPE_BCHUNK 2
93 #define XLOG_REG_TYPE_EFI_FORMAT 3
94 #define XLOG_REG_TYPE_EFD_FORMAT 4
95 #define XLOG_REG_TYPE_IFORMAT 5
96 #define XLOG_REG_TYPE_ICORE 6
97 #define XLOG_REG_TYPE_IEXT 7
98 #define XLOG_REG_TYPE_IBROOT 8
99 #define XLOG_REG_TYPE_ILOCAL 9
100 #define XLOG_REG_TYPE_IATTR_EXT 10
101 #define XLOG_REG_TYPE_IATTR_BROOT 11
102 #define XLOG_REG_TYPE_IATTR_LOCAL 12
103 #define XLOG_REG_TYPE_QFORMAT 13
104 #define XLOG_REG_TYPE_DQUOT 14
105 #define XLOG_REG_TYPE_QUOTAOFF 15
106 #define XLOG_REG_TYPE_LRHEADER 16
107 #define XLOG_REG_TYPE_UNMOUNT 17
108 #define XLOG_REG_TYPE_COMMIT 18
109 #define XLOG_REG_TYPE_TRANSHDR 19
110 #define XLOG_REG_TYPE_ICREATE 20
111 #define XLOG_REG_TYPE_RUI_FORMAT 21
112 #define XLOG_REG_TYPE_RUD_FORMAT 22
113 #define XLOG_REG_TYPE_CUI_FORMAT 23
114 #define XLOG_REG_TYPE_CUD_FORMAT 24
115 #define XLOG_REG_TYPE_BUI_FORMAT 25
116 #define XLOG_REG_TYPE_BUD_FORMAT 26
117 #define XLOG_REG_TYPE_MAX 26
118
119 /*
120 * Flags to log operation header
121 *
122 * The first write of a new transaction will be preceded with a start
123 * record, XLOG_START_TRANS. Once a transaction is committed, a commit
124 * record is written, XLOG_COMMIT_TRANS. If a single region can not fit into
125 * the remainder of the current active in-core log, it is split up into
126 * multiple regions. Each partial region will be marked with a
127 * XLOG_CONTINUE_TRANS until the last one, which gets marked with XLOG_END_TRANS.
128 *
129 */
130 #define XLOG_START_TRANS 0x01 /* Start a new transaction */
131 #define XLOG_COMMIT_TRANS 0x02 /* Commit this transaction */
132 #define XLOG_CONTINUE_TRANS 0x04 /* Cont this trans into new region */
133 #define XLOG_WAS_CONT_TRANS 0x08 /* Cont this trans into new region */
134 #define XLOG_END_TRANS 0x10 /* End a continued transaction */
135 #define XLOG_UNMOUNT_TRANS 0x20 /* Unmount a filesystem transaction */
136
137
138 typedef struct xlog_op_header {
139 __be32 oh_tid; /* transaction id of operation : 4 b */
140 __be32 oh_len; /* bytes in data region : 4 b */
141 __u8 oh_clientid; /* who sent me this : 1 b */
142 __u8 oh_flags; /* : 1 b */
143 __u16 oh_res2; /* 32 bit align : 2 b */
144 } xlog_op_header_t;
145
146 /* valid values for h_fmt */
147 #define XLOG_FMT_UNKNOWN 0
148 #define XLOG_FMT_LINUX_LE 1
149 #define XLOG_FMT_LINUX_BE 2
150 #define XLOG_FMT_IRIX_BE 3
151
152 /* our fmt */
153 #ifdef XFS_NATIVE_HOST
154 #define XLOG_FMT XLOG_FMT_LINUX_BE
155 #else
156 #define XLOG_FMT XLOG_FMT_LINUX_LE
157 #endif
158
159 typedef struct xlog_rec_header {
160 __be32 h_magicno; /* log record (LR) identifier : 4 */
161 __be32 h_cycle; /* write cycle of log : 4 */
162 __be32 h_version; /* LR version : 4 */
163 __be32 h_len; /* len in bytes; should be 64-bit aligned: 4 */
164 __be64 h_lsn; /* lsn of this LR : 8 */
165 __be64 h_tail_lsn; /* lsn of 1st LR w/ buffers not committed: 8 */
166 __le32 h_crc; /* crc of log record : 4 */
167 __be32 h_prev_block; /* block number to previous LR : 4 */
168 __be32 h_num_logops; /* number of log operations in this LR : 4 */
169 __be32 h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
170 /* new fields */
171 __be32 h_fmt; /* format of log record : 4 */
172 uuid_t h_fs_uuid; /* uuid of FS : 16 */
173 __be32 h_size; /* iclog size : 4 */
174 } xlog_rec_header_t;
175
176 typedef struct xlog_rec_ext_header {
177 __be32 xh_cycle; /* write cycle of log : 4 */
178 __be32 xh_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE]; /* : 256 */
179 } xlog_rec_ext_header_t;
180
181 /*
182 * Quite misnamed, because this union lays out the actual on-disk log buffer.
183 */
184 typedef union xlog_in_core2 {
185 xlog_rec_header_t hic_header;
186 xlog_rec_ext_header_t hic_xheader;
187 char hic_sector[XLOG_HEADER_SIZE];
188 } xlog_in_core_2_t;
189
190 /* not an on-disk structure, but needed by log recovery in userspace */
191 typedef struct xfs_log_iovec {
192 void *i_addr; /* beginning address of region */
193 int i_len; /* length in bytes of region */
194 uint i_type; /* type of region */
195 } xfs_log_iovec_t;
196
197
198 /*
199 * Transaction Header definitions.
200 *
201 * This is the structure written in the log at the head of every transaction. It
202 * identifies the type and id of the transaction, and contains the number of
203 * items logged by the transaction so we know how many to expect during
204 * recovery.
205 *
206 * Do not change the below structure without redoing the code in
207 * xlog_recover_add_to_trans() and xlog_recover_add_to_cont_trans().
208 */
209 typedef struct xfs_trans_header {
210 uint th_magic; /* magic number */
211 uint th_type; /* transaction type */
212 int32_t th_tid; /* transaction id (unused) */
213 uint th_num_items; /* num items logged by trans */
214 } xfs_trans_header_t;
215
216 #define XFS_TRANS_HEADER_MAGIC 0x5452414e /* TRAN */
217
218 /*
219 * The only type valid for th_type in CIL-enabled file system logs:
220 */
221 #define XFS_TRANS_CHECKPOINT 40
222
223 /*
224 * Log item types.
225 */
226 #define XFS_LI_EFI 0x1236
227 #define XFS_LI_EFD 0x1237
228 #define XFS_LI_IUNLINK 0x1238
229 #define XFS_LI_INODE 0x123b /* aligned ino chunks, var-size ibufs */
230 #define XFS_LI_BUF 0x123c /* v2 bufs, variable sized inode bufs */
231 #define XFS_LI_DQUOT 0x123d
232 #define XFS_LI_QUOTAOFF 0x123e
233 #define XFS_LI_ICREATE 0x123f
234 #define XFS_LI_RUI 0x1240 /* rmap update intent */
235 #define XFS_LI_RUD 0x1241
236 #define XFS_LI_CUI 0x1242 /* refcount update intent */
237 #define XFS_LI_CUD 0x1243
238 #define XFS_LI_BUI 0x1244 /* bmbt update intent */
239 #define XFS_LI_BUD 0x1245
240
241 #define XFS_LI_TYPE_DESC \
242 { XFS_LI_EFI, "XFS_LI_EFI" }, \
243 { XFS_LI_EFD, "XFS_LI_EFD" }, \
244 { XFS_LI_IUNLINK, "XFS_LI_IUNLINK" }, \
245 { XFS_LI_INODE, "XFS_LI_INODE" }, \
246 { XFS_LI_BUF, "XFS_LI_BUF" }, \
247 { XFS_LI_DQUOT, "XFS_LI_DQUOT" }, \
248 { XFS_LI_QUOTAOFF, "XFS_LI_QUOTAOFF" }, \
249 { XFS_LI_ICREATE, "XFS_LI_ICREATE" }, \
250 { XFS_LI_RUI, "XFS_LI_RUI" }, \
251 { XFS_LI_RUD, "XFS_LI_RUD" }, \
252 { XFS_LI_CUI, "XFS_LI_CUI" }, \
253 { XFS_LI_CUD, "XFS_LI_CUD" }, \
254 { XFS_LI_BUI, "XFS_LI_BUI" }, \
255 { XFS_LI_BUD, "XFS_LI_BUD" }
256
257 /*
258 * Inode Log Item Format definitions.
259 *
260 * This is the structure used to lay out an inode log item in the
261 * log. The size of the inline data/extents/b-tree root to be logged
262 * (if any) is indicated in the ilf_dsize field. Changes to this structure
263 * must be added on to the end.
264 */
265 struct xfs_inode_log_format {
266 uint16_t ilf_type; /* inode log item type */
267 uint16_t ilf_size; /* size of this item */
268 uint32_t ilf_fields; /* flags for fields logged */
269 uint16_t ilf_asize; /* size of attr d/ext/root */
270 uint16_t ilf_dsize; /* size of data/ext/root */
271 uint32_t ilf_pad; /* pad for 64 bit boundary */
272 uint64_t ilf_ino; /* inode number */
273 union {
274 uint32_t ilfu_rdev; /* rdev value for dev inode*/
275 uint8_t __pad[16]; /* unused */
276 } ilf_u;
277 int64_t ilf_blkno; /* blkno of inode buffer */
278 int32_t ilf_len; /* len of inode buffer */
279 int32_t ilf_boffset; /* off of inode in buffer */
280 };
281
282 /*
283 * Old 32 bit systems will log in this format without the 64 bit
284 * alignment padding. Recovery will detect this and convert it to the
285 * correct format.
286 */
287 struct xfs_inode_log_format_32 {
288 uint16_t ilf_type; /* inode log item type */
289 uint16_t ilf_size; /* size of this item */
290 uint32_t ilf_fields; /* flags for fields logged */
291 uint16_t ilf_asize; /* size of attr d/ext/root */
292 uint16_t ilf_dsize; /* size of data/ext/root */
293 uint64_t ilf_ino; /* inode number */
294 union {
295 uint32_t ilfu_rdev; /* rdev value for dev inode*/
296 uint8_t __pad[16]; /* unused */
297 } ilf_u;
298 int64_t ilf_blkno; /* blkno of inode buffer */
299 int32_t ilf_len; /* len of inode buffer */
300 int32_t ilf_boffset; /* off of inode in buffer */
301 } __attribute__((packed));
302
303
304 /*
305 * Flags for xfs_trans_log_inode flags field.
306 */
307 #define XFS_ILOG_CORE 0x001 /* log standard inode fields */
308 #define XFS_ILOG_DDATA 0x002 /* log i_df.if_data */
309 #define XFS_ILOG_DEXT 0x004 /* log i_df.if_extents */
310 #define XFS_ILOG_DBROOT 0x008 /* log i_df.i_broot */
311 #define XFS_ILOG_DEV 0x010 /* log the dev field */
312 #define XFS_ILOG_UUID 0x020 /* added long ago, but never used */
313 #define XFS_ILOG_ADATA 0x040 /* log i_af.if_data */
314 #define XFS_ILOG_AEXT 0x080 /* log i_af.if_extents */
315 #define XFS_ILOG_ABROOT 0x100 /* log i_af.i_broot */
316 #define XFS_ILOG_DOWNER 0x200 /* change the data fork owner on replay */
317 #define XFS_ILOG_AOWNER 0x400 /* change the attr fork owner on replay */
318
319
320 /*
321 * The timestamps are dirty, but not necessarily anything else in the inode
322 * core. Unlike the other fields above this one must never make it to disk
323 * in the ilf_fields of the inode_log_format, but is purely store in-memory in
324 * ili_fields in the inode_log_item.
325 */
326 #define XFS_ILOG_TIMESTAMP 0x4000
327
328 #define XFS_ILOG_NONCORE (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
329 XFS_ILOG_DBROOT | XFS_ILOG_DEV | \
330 XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
331 XFS_ILOG_ABROOT | XFS_ILOG_DOWNER | \
332 XFS_ILOG_AOWNER)
333
334 #define XFS_ILOG_DFORK (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
335 XFS_ILOG_DBROOT)
336
337 #define XFS_ILOG_AFORK (XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
338 XFS_ILOG_ABROOT)
339
340 #define XFS_ILOG_ALL (XFS_ILOG_CORE | XFS_ILOG_DDATA | \
341 XFS_ILOG_DEXT | XFS_ILOG_DBROOT | \
342 XFS_ILOG_DEV | XFS_ILOG_ADATA | \
343 XFS_ILOG_AEXT | XFS_ILOG_ABROOT | \
344 XFS_ILOG_TIMESTAMP | XFS_ILOG_DOWNER | \
345 XFS_ILOG_AOWNER)
346
xfs_ilog_fbroot(int w)347 static inline int xfs_ilog_fbroot(int w)
348 {
349 return (w == XFS_DATA_FORK ? XFS_ILOG_DBROOT : XFS_ILOG_ABROOT);
350 }
351
xfs_ilog_fext(int w)352 static inline int xfs_ilog_fext(int w)
353 {
354 return (w == XFS_DATA_FORK ? XFS_ILOG_DEXT : XFS_ILOG_AEXT);
355 }
356
xfs_ilog_fdata(int w)357 static inline int xfs_ilog_fdata(int w)
358 {
359 return (w == XFS_DATA_FORK ? XFS_ILOG_DDATA : XFS_ILOG_ADATA);
360 }
361
362 /*
363 * Incore version of the on-disk inode core structures. We log this directly
364 * into the journal in host CPU format (for better or worse) and as such
365 * directly mirrors the xfs_dinode structure as it must contain all the same
366 * information.
367 */
368 typedef uint64_t xfs_log_timestamp_t;
369
370 /* Legacy timestamp encoding format. */
371 struct xfs_log_legacy_timestamp {
372 int32_t t_sec; /* timestamp seconds */
373 int32_t t_nsec; /* timestamp nanoseconds */
374 };
375
376 /*
377 * Define the format of the inode core that is logged. This structure must be
378 * kept identical to struct xfs_dinode except for the endianness annotations.
379 */
380 struct xfs_log_dinode {
381 uint16_t di_magic; /* inode magic # = XFS_DINODE_MAGIC */
382 uint16_t di_mode; /* mode and type of file */
383 int8_t di_version; /* inode version */
384 int8_t di_format; /* format of di_c data */
385 uint8_t di_pad3[2]; /* unused in v2/3 inodes */
386 uint32_t di_uid; /* owner's user id */
387 uint32_t di_gid; /* owner's group id */
388 uint32_t di_nlink; /* number of links to file */
389 uint16_t di_projid_lo; /* lower part of owner's project id */
390 uint16_t di_projid_hi; /* higher part of owner's project id */
391 uint8_t di_pad[6]; /* unused, zeroed space */
392 uint16_t di_flushiter; /* incremented on flush */
393 xfs_log_timestamp_t di_atime; /* time last accessed */
394 xfs_log_timestamp_t di_mtime; /* time last modified */
395 xfs_log_timestamp_t di_ctime; /* time created/inode modified */
396 xfs_fsize_t di_size; /* number of bytes in file */
397 xfs_rfsblock_t di_nblocks; /* # of direct & btree blocks used */
398 xfs_extlen_t di_extsize; /* basic/minimum extent size for file */
399 xfs_extnum_t di_nextents; /* number of extents in data fork */
400 xfs_aextnum_t di_anextents; /* number of extents in attribute fork*/
401 uint8_t di_forkoff; /* attr fork offs, <<3 for 64b align */
402 int8_t di_aformat; /* format of attr fork's data */
403 uint32_t di_dmevmask; /* DMIG event mask */
404 uint16_t di_dmstate; /* DMIG state info */
405 uint16_t di_flags; /* random flags, XFS_DIFLAG_... */
406 uint32_t di_gen; /* generation number */
407
408 /* di_next_unlinked is the only non-core field in the old dinode */
409 xfs_agino_t di_next_unlinked;/* agi unlinked list ptr */
410
411 /* start of the extended dinode, writable fields */
412 uint32_t di_crc; /* CRC of the inode */
413 uint64_t di_changecount; /* number of attribute changes */
414
415 /*
416 * The LSN we write to this field during formatting is not a reflection
417 * of the current on-disk LSN. It should never be used for recovery
418 * sequencing, nor should it be recovered into the on-disk inode at all.
419 * See xlog_recover_inode_commit_pass2() and xfs_log_dinode_to_disk()
420 * for details.
421 */
422 xfs_lsn_t di_lsn;
423
424 uint64_t di_flags2; /* more random flags */
425 uint32_t di_cowextsize; /* basic cow extent size for file */
426 uint8_t di_pad2[12]; /* more padding for future expansion */
427
428 /* fields only written to during inode creation */
429 xfs_log_timestamp_t di_crtime; /* time created */
430 xfs_ino_t di_ino; /* inode number */
431 uuid_t di_uuid; /* UUID of the filesystem */
432
433 /* structure must be padded to 64 bit alignment */
434 };
435
436 #define xfs_log_dinode_size(mp) \
437 (xfs_has_v3inodes((mp)) ? \
438 sizeof(struct xfs_log_dinode) : \
439 offsetof(struct xfs_log_dinode, di_next_unlinked))
440
441 /*
442 * Buffer Log Format definitions
443 *
444 * These are the physical dirty bitmap definitions for the log format structure.
445 */
446 #define XFS_BLF_CHUNK 128
447 #define XFS_BLF_SHIFT 7
448 #define BIT_TO_WORD_SHIFT 5
449 #define NBWORD (NBBY * sizeof(unsigned int))
450
451 /*
452 * This flag indicates that the buffer contains on disk inodes
453 * and requires special recovery handling.
454 */
455 #define XFS_BLF_INODE_BUF (1<<0)
456
457 /*
458 * This flag indicates that the buffer should not be replayed
459 * during recovery because its blocks are being freed.
460 */
461 #define XFS_BLF_CANCEL (1<<1)
462
463 /*
464 * This flag indicates that the buffer contains on disk
465 * user or group dquots and may require special recovery handling.
466 */
467 #define XFS_BLF_UDQUOT_BUF (1<<2)
468 #define XFS_BLF_PDQUOT_BUF (1<<3)
469 #define XFS_BLF_GDQUOT_BUF (1<<4)
470
471 /*
472 * This is the structure used to lay out a buf log item in the log. The data
473 * map describes which 128 byte chunks of the buffer have been logged.
474 *
475 * The placement of blf_map_size causes blf_data_map to start at an odd
476 * multiple of sizeof(unsigned int) offset within the struct. Because the data
477 * bitmap size will always be an even number, the end of the data_map (and
478 * therefore the structure) will also be at an odd multiple of sizeof(unsigned
479 * int). Some 64-bit compilers will insert padding at the end of the struct to
480 * ensure 64-bit alignment of blf_blkno, but 32-bit ones will not. Therefore,
481 * XFS_BLF_DATAMAP_SIZE must be an odd number to make the padding explicit and
482 * keep the structure size consistent between 32-bit and 64-bit platforms.
483 */
484 #define __XFS_BLF_DATAMAP_SIZE ((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) / NBWORD)
485 #define XFS_BLF_DATAMAP_SIZE (__XFS_BLF_DATAMAP_SIZE + 1)
486
487 typedef struct xfs_buf_log_format {
488 unsigned short blf_type; /* buf log item type indicator */
489 unsigned short blf_size; /* size of this item */
490 unsigned short blf_flags; /* misc state */
491 unsigned short blf_len; /* number of blocks in this buf */
492 int64_t blf_blkno; /* starting blkno of this buf */
493 unsigned int blf_map_size; /* used size of data bitmap in words */
494 unsigned int blf_data_map[XFS_BLF_DATAMAP_SIZE]; /* dirty bitmap */
495 } xfs_buf_log_format_t;
496
497 /*
498 * All buffers now need to tell recovery where the magic number
499 * is so that it can verify and calculate the CRCs on the buffer correctly
500 * once the changes have been replayed into the buffer.
501 *
502 * The type value is held in the upper 5 bits of the blf_flags field, which is
503 * an unsigned 16 bit field. Hence we need to shift it 11 bits up and down.
504 */
505 #define XFS_BLFT_BITS 5
506 #define XFS_BLFT_SHIFT 11
507 #define XFS_BLFT_MASK (((1 << XFS_BLFT_BITS) - 1) << XFS_BLFT_SHIFT)
508
509 enum xfs_blft {
510 XFS_BLFT_UNKNOWN_BUF = 0,
511 XFS_BLFT_UDQUOT_BUF,
512 XFS_BLFT_PDQUOT_BUF,
513 XFS_BLFT_GDQUOT_BUF,
514 XFS_BLFT_BTREE_BUF,
515 XFS_BLFT_AGF_BUF,
516 XFS_BLFT_AGFL_BUF,
517 XFS_BLFT_AGI_BUF,
518 XFS_BLFT_DINO_BUF,
519 XFS_BLFT_SYMLINK_BUF,
520 XFS_BLFT_DIR_BLOCK_BUF,
521 XFS_BLFT_DIR_DATA_BUF,
522 XFS_BLFT_DIR_FREE_BUF,
523 XFS_BLFT_DIR_LEAF1_BUF,
524 XFS_BLFT_DIR_LEAFN_BUF,
525 XFS_BLFT_DA_NODE_BUF,
526 XFS_BLFT_ATTR_LEAF_BUF,
527 XFS_BLFT_ATTR_RMT_BUF,
528 XFS_BLFT_SB_BUF,
529 XFS_BLFT_RTBITMAP_BUF,
530 XFS_BLFT_RTSUMMARY_BUF,
531 XFS_BLFT_MAX_BUF = (1 << XFS_BLFT_BITS),
532 };
533
534 static inline void
xfs_blft_to_flags(struct xfs_buf_log_format * blf,enum xfs_blft type)535 xfs_blft_to_flags(struct xfs_buf_log_format *blf, enum xfs_blft type)
536 {
537 ASSERT(type > XFS_BLFT_UNKNOWN_BUF && type < XFS_BLFT_MAX_BUF);
538 blf->blf_flags &= ~XFS_BLFT_MASK;
539 blf->blf_flags |= ((type << XFS_BLFT_SHIFT) & XFS_BLFT_MASK);
540 }
541
542 static inline uint16_t
xfs_blft_from_flags(struct xfs_buf_log_format * blf)543 xfs_blft_from_flags(struct xfs_buf_log_format *blf)
544 {
545 return (blf->blf_flags & XFS_BLFT_MASK) >> XFS_BLFT_SHIFT;
546 }
547
548 /*
549 * EFI/EFD log format definitions
550 */
551 typedef struct xfs_extent {
552 xfs_fsblock_t ext_start;
553 xfs_extlen_t ext_len;
554 } xfs_extent_t;
555
556 /*
557 * Since an xfs_extent_t has types (start:64, len: 32)
558 * there are different alignments on 32 bit and 64 bit kernels.
559 * So we provide the different variants for use by a
560 * conversion routine.
561 */
562 typedef struct xfs_extent_32 {
563 uint64_t ext_start;
564 uint32_t ext_len;
565 } __attribute__((packed)) xfs_extent_32_t;
566
567 typedef struct xfs_extent_64 {
568 uint64_t ext_start;
569 uint32_t ext_len;
570 uint32_t ext_pad;
571 } xfs_extent_64_t;
572
573 /*
574 * This is the structure used to lay out an efi log item in the
575 * log. The efi_extents field is a variable size array whose
576 * size is given by efi_nextents.
577 */
578 typedef struct xfs_efi_log_format {
579 uint16_t efi_type; /* efi log item type */
580 uint16_t efi_size; /* size of this item */
581 uint32_t efi_nextents; /* # extents to free */
582 uint64_t efi_id; /* efi identifier */
583 xfs_extent_t efi_extents[1]; /* array of extents to free */
584 } xfs_efi_log_format_t;
585
586 typedef struct xfs_efi_log_format_32 {
587 uint16_t efi_type; /* efi log item type */
588 uint16_t efi_size; /* size of this item */
589 uint32_t efi_nextents; /* # extents to free */
590 uint64_t efi_id; /* efi identifier */
591 xfs_extent_32_t efi_extents[1]; /* array of extents to free */
592 } __attribute__((packed)) xfs_efi_log_format_32_t;
593
594 typedef struct xfs_efi_log_format_64 {
595 uint16_t efi_type; /* efi log item type */
596 uint16_t efi_size; /* size of this item */
597 uint32_t efi_nextents; /* # extents to free */
598 uint64_t efi_id; /* efi identifier */
599 xfs_extent_64_t efi_extents[1]; /* array of extents to free */
600 } xfs_efi_log_format_64_t;
601
602 /*
603 * This is the structure used to lay out an efd log item in the
604 * log. The efd_extents array is a variable size array whose
605 * size is given by efd_nextents;
606 */
607 typedef struct xfs_efd_log_format {
608 uint16_t efd_type; /* efd log item type */
609 uint16_t efd_size; /* size of this item */
610 uint32_t efd_nextents; /* # of extents freed */
611 uint64_t efd_efi_id; /* id of corresponding efi */
612 xfs_extent_t efd_extents[1]; /* array of extents freed */
613 } xfs_efd_log_format_t;
614
615 typedef struct xfs_efd_log_format_32 {
616 uint16_t efd_type; /* efd log item type */
617 uint16_t efd_size; /* size of this item */
618 uint32_t efd_nextents; /* # of extents freed */
619 uint64_t efd_efi_id; /* id of corresponding efi */
620 xfs_extent_32_t efd_extents[1]; /* array of extents freed */
621 } __attribute__((packed)) xfs_efd_log_format_32_t;
622
623 typedef struct xfs_efd_log_format_64 {
624 uint16_t efd_type; /* efd log item type */
625 uint16_t efd_size; /* size of this item */
626 uint32_t efd_nextents; /* # of extents freed */
627 uint64_t efd_efi_id; /* id of corresponding efi */
628 xfs_extent_64_t efd_extents[1]; /* array of extents freed */
629 } xfs_efd_log_format_64_t;
630
631 /*
632 * RUI/RUD (reverse mapping) log format definitions
633 */
634 struct xfs_map_extent {
635 uint64_t me_owner;
636 uint64_t me_startblock;
637 uint64_t me_startoff;
638 uint32_t me_len;
639 uint32_t me_flags;
640 };
641
642 /* rmap me_flags: upper bits are flags, lower byte is type code */
643 #define XFS_RMAP_EXTENT_MAP 1
644 #define XFS_RMAP_EXTENT_MAP_SHARED 2
645 #define XFS_RMAP_EXTENT_UNMAP 3
646 #define XFS_RMAP_EXTENT_UNMAP_SHARED 4
647 #define XFS_RMAP_EXTENT_CONVERT 5
648 #define XFS_RMAP_EXTENT_CONVERT_SHARED 6
649 #define XFS_RMAP_EXTENT_ALLOC 7
650 #define XFS_RMAP_EXTENT_FREE 8
651 #define XFS_RMAP_EXTENT_TYPE_MASK 0xFF
652
653 #define XFS_RMAP_EXTENT_ATTR_FORK (1U << 31)
654 #define XFS_RMAP_EXTENT_BMBT_BLOCK (1U << 30)
655 #define XFS_RMAP_EXTENT_UNWRITTEN (1U << 29)
656
657 #define XFS_RMAP_EXTENT_FLAGS (XFS_RMAP_EXTENT_TYPE_MASK | \
658 XFS_RMAP_EXTENT_ATTR_FORK | \
659 XFS_RMAP_EXTENT_BMBT_BLOCK | \
660 XFS_RMAP_EXTENT_UNWRITTEN)
661
662 /*
663 * This is the structure used to lay out an rui log item in the
664 * log. The rui_extents field is a variable size array whose
665 * size is given by rui_nextents.
666 */
667 struct xfs_rui_log_format {
668 uint16_t rui_type; /* rui log item type */
669 uint16_t rui_size; /* size of this item */
670 uint32_t rui_nextents; /* # extents to free */
671 uint64_t rui_id; /* rui identifier */
672 struct xfs_map_extent rui_extents[]; /* array of extents to rmap */
673 };
674
675 static inline size_t
xfs_rui_log_format_sizeof(unsigned int nr)676 xfs_rui_log_format_sizeof(
677 unsigned int nr)
678 {
679 return sizeof(struct xfs_rui_log_format) +
680 nr * sizeof(struct xfs_map_extent);
681 }
682
683 /*
684 * This is the structure used to lay out an rud log item in the
685 * log. The rud_extents array is a variable size array whose
686 * size is given by rud_nextents;
687 */
688 struct xfs_rud_log_format {
689 uint16_t rud_type; /* rud log item type */
690 uint16_t rud_size; /* size of this item */
691 uint32_t __pad;
692 uint64_t rud_rui_id; /* id of corresponding rui */
693 };
694
695 /*
696 * CUI/CUD (refcount update) log format definitions
697 */
698 struct xfs_phys_extent {
699 uint64_t pe_startblock;
700 uint32_t pe_len;
701 uint32_t pe_flags;
702 };
703
704 /* refcount pe_flags: upper bits are flags, lower byte is type code */
705 /* Type codes are taken directly from enum xfs_refcount_intent_type. */
706 #define XFS_REFCOUNT_EXTENT_TYPE_MASK 0xFF
707
708 #define XFS_REFCOUNT_EXTENT_FLAGS (XFS_REFCOUNT_EXTENT_TYPE_MASK)
709
710 /*
711 * This is the structure used to lay out a cui log item in the
712 * log. The cui_extents field is a variable size array whose
713 * size is given by cui_nextents.
714 */
715 struct xfs_cui_log_format {
716 uint16_t cui_type; /* cui log item type */
717 uint16_t cui_size; /* size of this item */
718 uint32_t cui_nextents; /* # extents to free */
719 uint64_t cui_id; /* cui identifier */
720 struct xfs_phys_extent cui_extents[]; /* array of extents */
721 };
722
723 static inline size_t
xfs_cui_log_format_sizeof(unsigned int nr)724 xfs_cui_log_format_sizeof(
725 unsigned int nr)
726 {
727 return sizeof(struct xfs_cui_log_format) +
728 nr * sizeof(struct xfs_phys_extent);
729 }
730
731 /*
732 * This is the structure used to lay out a cud log item in the
733 * log. The cud_extents array is a variable size array whose
734 * size is given by cud_nextents;
735 */
736 struct xfs_cud_log_format {
737 uint16_t cud_type; /* cud log item type */
738 uint16_t cud_size; /* size of this item */
739 uint32_t __pad;
740 uint64_t cud_cui_id; /* id of corresponding cui */
741 };
742
743 /*
744 * BUI/BUD (inode block mapping) log format definitions
745 */
746
747 /* bmbt me_flags: upper bits are flags, lower byte is type code */
748 /* Type codes are taken directly from enum xfs_bmap_intent_type. */
749 #define XFS_BMAP_EXTENT_TYPE_MASK 0xFF
750
751 #define XFS_BMAP_EXTENT_ATTR_FORK (1U << 31)
752 #define XFS_BMAP_EXTENT_UNWRITTEN (1U << 30)
753
754 #define XFS_BMAP_EXTENT_FLAGS (XFS_BMAP_EXTENT_TYPE_MASK | \
755 XFS_BMAP_EXTENT_ATTR_FORK | \
756 XFS_BMAP_EXTENT_UNWRITTEN)
757
758 /*
759 * This is the structure used to lay out an bui log item in the
760 * log. The bui_extents field is a variable size array whose
761 * size is given by bui_nextents.
762 */
763 struct xfs_bui_log_format {
764 uint16_t bui_type; /* bui log item type */
765 uint16_t bui_size; /* size of this item */
766 uint32_t bui_nextents; /* # extents to free */
767 uint64_t bui_id; /* bui identifier */
768 struct xfs_map_extent bui_extents[]; /* array of extents to bmap */
769 };
770
771 static inline size_t
xfs_bui_log_format_sizeof(unsigned int nr)772 xfs_bui_log_format_sizeof(
773 unsigned int nr)
774 {
775 return sizeof(struct xfs_bui_log_format) +
776 nr * sizeof(struct xfs_map_extent);
777 }
778
779 /*
780 * This is the structure used to lay out an bud log item in the
781 * log. The bud_extents array is a variable size array whose
782 * size is given by bud_nextents;
783 */
784 struct xfs_bud_log_format {
785 uint16_t bud_type; /* bud log item type */
786 uint16_t bud_size; /* size of this item */
787 uint32_t __pad;
788 uint64_t bud_bui_id; /* id of corresponding bui */
789 };
790
791 /*
792 * Dquot Log format definitions.
793 *
794 * The first two fields must be the type and size fitting into
795 * 32 bits : log_recovery code assumes that.
796 */
797 typedef struct xfs_dq_logformat {
798 uint16_t qlf_type; /* dquot log item type */
799 uint16_t qlf_size; /* size of this item */
800 xfs_dqid_t qlf_id; /* usr/grp/proj id : 32 bits */
801 int64_t qlf_blkno; /* blkno of dquot buffer */
802 int32_t qlf_len; /* len of dquot buffer */
803 uint32_t qlf_boffset; /* off of dquot in buffer */
804 } xfs_dq_logformat_t;
805
806 /*
807 * log format struct for QUOTAOFF records.
808 * The first two fields must be the type and size fitting into
809 * 32 bits : log_recovery code assumes that.
810 * We write two LI_QUOTAOFF logitems per quotaoff, the last one keeps a pointer
811 * to the first and ensures that the first logitem is taken out of the AIL
812 * only when the last one is securely committed.
813 */
814 typedef struct xfs_qoff_logformat {
815 unsigned short qf_type; /* quotaoff log item type */
816 unsigned short qf_size; /* size of this item */
817 unsigned int qf_flags; /* USR and/or GRP */
818 char qf_pad[12]; /* padding for future */
819 } xfs_qoff_logformat_t;
820
821 /*
822 * Disk quotas status in m_qflags, and also sb_qflags. 16 bits.
823 */
824 #define XFS_UQUOTA_ACCT 0x0001 /* user quota accounting ON */
825 #define XFS_UQUOTA_ENFD 0x0002 /* user quota limits enforced */
826 #define XFS_UQUOTA_CHKD 0x0004 /* quotacheck run on usr quotas */
827 #define XFS_PQUOTA_ACCT 0x0008 /* project quota accounting ON */
828 #define XFS_OQUOTA_ENFD 0x0010 /* other (grp/prj) quota limits enforced */
829 #define XFS_OQUOTA_CHKD 0x0020 /* quotacheck run on other (grp/prj) quotas */
830 #define XFS_GQUOTA_ACCT 0x0040 /* group quota accounting ON */
831
832 /*
833 * Conversion to and from the combined OQUOTA flag (if necessary)
834 * is done only in xfs_sb_qflags_to_disk() and xfs_sb_qflags_from_disk()
835 */
836 #define XFS_GQUOTA_ENFD 0x0080 /* group quota limits enforced */
837 #define XFS_GQUOTA_CHKD 0x0100 /* quotacheck run on group quotas */
838 #define XFS_PQUOTA_ENFD 0x0200 /* project quota limits enforced */
839 #define XFS_PQUOTA_CHKD 0x0400 /* quotacheck run on project quotas */
840
841 #define XFS_ALL_QUOTA_ACCT \
842 (XFS_UQUOTA_ACCT | XFS_GQUOTA_ACCT | XFS_PQUOTA_ACCT)
843 #define XFS_ALL_QUOTA_ENFD \
844 (XFS_UQUOTA_ENFD | XFS_GQUOTA_ENFD | XFS_PQUOTA_ENFD)
845 #define XFS_ALL_QUOTA_CHKD \
846 (XFS_UQUOTA_CHKD | XFS_GQUOTA_CHKD | XFS_PQUOTA_CHKD)
847
848 #define XFS_MOUNT_QUOTA_ALL (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
849 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|\
850 XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD|\
851 XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD|\
852 XFS_PQUOTA_CHKD)
853
854 /*
855 * Inode create log item structure
856 *
857 * Log recovery assumes the first two entries are the type and size and they fit
858 * in 32 bits. Also in host order (ugh) so they have to be 32 bit aligned so
859 * decoding can be done correctly.
860 */
861 struct xfs_icreate_log {
862 uint16_t icl_type; /* type of log format structure */
863 uint16_t icl_size; /* size of log format structure */
864 __be32 icl_ag; /* ag being allocated in */
865 __be32 icl_agbno; /* start block of inode range */
866 __be32 icl_count; /* number of inodes to initialise */
867 __be32 icl_isize; /* size of inodes */
868 __be32 icl_length; /* length of extent to initialise */
869 __be32 icl_gen; /* inode generation number to use */
870 };
871
872 #endif /* __XFS_LOG_FORMAT_H__ */
873