xfs: split out inode log item format definition
[firefly-linux-kernel-4.4.55.git] / fs / xfs / xfs_log_format.h
1 /*
2  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 #ifndef __XFS_LOG_FORMAT_H__
19 #define __XFS_LOG_FORMAT_H__
20
21 /*
22  * On-disk Log Format definitions.
23  *
24  * This file contains all the on-disk format definitions used within the log. It
25  * includes the physical log structure itself, as well as all the log item
26  * format structures that are written into the log and intepreted by log
27  * recovery. We start with the physical log format definitions, and then work
28  * through all the log items definitions and everything they encode into the
29  * log.
30  */
31 typedef __uint32_t xlog_tid_t;
32
33 #define XLOG_MIN_ICLOGS         2
34 #define XLOG_MAX_ICLOGS         8
35 #define XLOG_HEADER_MAGIC_NUM   0xFEEDbabe      /* Invalid cycle number */
36 #define XLOG_VERSION_1          1
37 #define XLOG_VERSION_2          2               /* Large IClogs, Log sunit */
38 #define XLOG_VERSION_OKBITS     (XLOG_VERSION_1 | XLOG_VERSION_2)
39 #define XLOG_MIN_RECORD_BSIZE   (16*1024)       /* eventually 32k */
40 #define XLOG_BIG_RECORD_BSIZE   (32*1024)       /* 32k buffers */
41 #define XLOG_MAX_RECORD_BSIZE   (256*1024)
42 #define XLOG_HEADER_CYCLE_SIZE  (32*1024)       /* cycle data in header */
43 #define XLOG_MIN_RECORD_BSHIFT  14              /* 16384 == 1 << 14 */
44 #define XLOG_BIG_RECORD_BSHIFT  15              /* 32k == 1 << 15 */
45 #define XLOG_MAX_RECORD_BSHIFT  18              /* 256k == 1 << 18 */
46 #define XLOG_BTOLSUNIT(log, b)  (((b)+(log)->l_mp->m_sb.sb_logsunit-1) / \
47                                  (log)->l_mp->m_sb.sb_logsunit)
48 #define XLOG_LSUNITTOB(log, su) ((su) * (log)->l_mp->m_sb.sb_logsunit)
49
50 #define XLOG_HEADER_SIZE        512
51
52 #define XLOG_REC_SHIFT(log) \
53         BTOBB(1 << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
54          XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
55 #define XLOG_TOTAL_REC_SHIFT(log) \
56         BTOBB(XLOG_MAX_ICLOGS << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
57          XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
58
59 /* get lsn fields */
60 #define CYCLE_LSN(lsn) ((uint)((lsn)>>32))
61 #define BLOCK_LSN(lsn) ((uint)(lsn))
62
63 /* this is used in a spot where we might otherwise double-endian-flip */
64 #define CYCLE_LSN_DISK(lsn) (((__be32 *)&(lsn))[0])
65
66 static inline xfs_lsn_t xlog_assign_lsn(uint cycle, uint block)
67 {
68         return ((xfs_lsn_t)cycle << 32) | block;
69 }
70
71 static inline uint xlog_get_cycle(char *ptr)
72 {
73         if (be32_to_cpu(*(__be32 *)ptr) == XLOG_HEADER_MAGIC_NUM)
74                 return be32_to_cpu(*((__be32 *)ptr + 1));
75         else
76                 return be32_to_cpu(*(__be32 *)ptr);
77 }
78
79 /* Log Clients */
80 #define XFS_TRANSACTION         0x69
81 #define XFS_VOLUME              0x2
82 #define XFS_LOG                 0xaa
83
84 #define XLOG_UNMOUNT_TYPE       0x556e  /* Un for Unmount */
85
86 /* Region types for iovec's i_type */
87 #define XLOG_REG_TYPE_BFORMAT           1
88 #define XLOG_REG_TYPE_BCHUNK            2
89 #define XLOG_REG_TYPE_EFI_FORMAT        3
90 #define XLOG_REG_TYPE_EFD_FORMAT        4
91 #define XLOG_REG_TYPE_IFORMAT           5
92 #define XLOG_REG_TYPE_ICORE             6
93 #define XLOG_REG_TYPE_IEXT              7
94 #define XLOG_REG_TYPE_IBROOT            8
95 #define XLOG_REG_TYPE_ILOCAL            9
96 #define XLOG_REG_TYPE_IATTR_EXT         10
97 #define XLOG_REG_TYPE_IATTR_BROOT       11
98 #define XLOG_REG_TYPE_IATTR_LOCAL       12
99 #define XLOG_REG_TYPE_QFORMAT           13
100 #define XLOG_REG_TYPE_DQUOT             14
101 #define XLOG_REG_TYPE_QUOTAOFF          15
102 #define XLOG_REG_TYPE_LRHEADER          16
103 #define XLOG_REG_TYPE_UNMOUNT           17
104 #define XLOG_REG_TYPE_COMMIT            18
105 #define XLOG_REG_TYPE_TRANSHDR          19
106 #define XLOG_REG_TYPE_ICREATE           20
107 #define XLOG_REG_TYPE_MAX               20
108
109 /*
110  * Flags to log operation header
111  *
112  * The first write of a new transaction will be preceded with a start
113  * record, XLOG_START_TRANS.  Once a transaction is committed, a commit
114  * record is written, XLOG_COMMIT_TRANS.  If a single region can not fit into
115  * the remainder of the current active in-core log, it is split up into
116  * multiple regions.  Each partial region will be marked with a
117  * XLOG_CONTINUE_TRANS until the last one, which gets marked with XLOG_END_TRANS.
118  *
119  */
120 #define XLOG_START_TRANS        0x01    /* Start a new transaction */
121 #define XLOG_COMMIT_TRANS       0x02    /* Commit this transaction */
122 #define XLOG_CONTINUE_TRANS     0x04    /* Cont this trans into new region */
123 #define XLOG_WAS_CONT_TRANS     0x08    /* Cont this trans into new region */
124 #define XLOG_END_TRANS          0x10    /* End a continued transaction */
125 #define XLOG_UNMOUNT_TRANS      0x20    /* Unmount a filesystem transaction */
126
127
128 typedef struct xlog_op_header {
129         __be32     oh_tid;      /* transaction id of operation  :  4 b */
130         __be32     oh_len;      /* bytes in data region         :  4 b */
131         __u8       oh_clientid; /* who sent me this             :  1 b */
132         __u8       oh_flags;    /*                              :  1 b */
133         __u16      oh_res2;     /* 32 bit align                 :  2 b */
134 } xlog_op_header_t;
135
136
137 /* valid values for h_fmt */
138 #define XLOG_FMT_UNKNOWN  0
139 #define XLOG_FMT_LINUX_LE 1
140 #define XLOG_FMT_LINUX_BE 2
141 #define XLOG_FMT_IRIX_BE  3
142
143 /* our fmt */
144 #ifdef XFS_NATIVE_HOST
145 #define XLOG_FMT XLOG_FMT_LINUX_BE
146 #else
147 #define XLOG_FMT XLOG_FMT_LINUX_LE
148 #endif
149
150 typedef struct xlog_rec_header {
151         __be32    h_magicno;    /* log record (LR) identifier           :  4 */
152         __be32    h_cycle;      /* write cycle of log                   :  4 */
153         __be32    h_version;    /* LR version                           :  4 */
154         __be32    h_len;        /* len in bytes; should be 64-bit aligned: 4 */
155         __be64    h_lsn;        /* lsn of this LR                       :  8 */
156         __be64    h_tail_lsn;   /* lsn of 1st LR w/ buffers not committed: 8 */
157         __le32    h_crc;        /* crc of log record                    :  4 */
158         __be32    h_prev_block; /* block number to previous LR          :  4 */
159         __be32    h_num_logops; /* number of log operations in this LR  :  4 */
160         __be32    h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
161         /* new fields */
162         __be32    h_fmt;        /* format of log record                 :  4 */
163         uuid_t    h_fs_uuid;    /* uuid of FS                           : 16 */
164         __be32    h_size;       /* iclog size                           :  4 */
165 } xlog_rec_header_t;
166
167 typedef struct xlog_rec_ext_header {
168         __be32    xh_cycle;     /* write cycle of log                   : 4 */
169         __be32    xh_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE]; /*    : 256 */
170 } xlog_rec_ext_header_t;
171
172 /*
173  * Quite misnamed, because this union lays out the actual on-disk log buffer.
174  */
175 typedef union xlog_in_core2 {
176         xlog_rec_header_t       hic_header;
177         xlog_rec_ext_header_t   hic_xheader;
178         char                    hic_sector[XLOG_HEADER_SIZE];
179 } xlog_in_core_2_t;
180
181 /* not an on-disk structure, but needed by log recovery in userspace */
182 typedef struct xfs_log_iovec {
183         void            *i_addr;        /* beginning address of region */
184         int             i_len;          /* length in bytes of region */
185         uint            i_type;         /* type of region */
186 } xfs_log_iovec_t;
187
188
189 /*
190  * Inode Log Item Format definitions.
191  *
192  * This is the structure used to lay out an inode log item in the
193  * log.  The size of the inline data/extents/b-tree root to be logged
194  * (if any) is indicated in the ilf_dsize field.  Changes to this structure
195  * must be added on to the end.
196  */
197 typedef struct xfs_inode_log_format {
198         __uint16_t              ilf_type;       /* inode log item type */
199         __uint16_t              ilf_size;       /* size of this item */
200         __uint32_t              ilf_fields;     /* flags for fields logged */
201         __uint16_t              ilf_asize;      /* size of attr d/ext/root */
202         __uint16_t              ilf_dsize;      /* size of data/ext/root */
203         __uint64_t              ilf_ino;        /* inode number */
204         union {
205                 __uint32_t      ilfu_rdev;      /* rdev value for dev inode*/
206                 uuid_t          ilfu_uuid;      /* mount point value */
207         } ilf_u;
208         __int64_t               ilf_blkno;      /* blkno of inode buffer */
209         __int32_t               ilf_len;        /* len of inode buffer */
210         __int32_t               ilf_boffset;    /* off of inode in buffer */
211 } xfs_inode_log_format_t;
212
213 typedef struct xfs_inode_log_format_32 {
214         __uint16_t              ilf_type;       /* inode log item type */
215         __uint16_t              ilf_size;       /* size of this item */
216         __uint32_t              ilf_fields;     /* flags for fields logged */
217         __uint16_t              ilf_asize;      /* size of attr d/ext/root */
218         __uint16_t              ilf_dsize;      /* size of data/ext/root */
219         __uint64_t              ilf_ino;        /* inode number */
220         union {
221                 __uint32_t      ilfu_rdev;      /* rdev value for dev inode*/
222                 uuid_t          ilfu_uuid;      /* mount point value */
223         } ilf_u;
224         __int64_t               ilf_blkno;      /* blkno of inode buffer */
225         __int32_t               ilf_len;        /* len of inode buffer */
226         __int32_t               ilf_boffset;    /* off of inode in buffer */
227 } __attribute__((packed)) xfs_inode_log_format_32_t;
228
229 typedef struct xfs_inode_log_format_64 {
230         __uint16_t              ilf_type;       /* inode log item type */
231         __uint16_t              ilf_size;       /* size of this item */
232         __uint32_t              ilf_fields;     /* flags for fields logged */
233         __uint16_t              ilf_asize;      /* size of attr d/ext/root */
234         __uint16_t              ilf_dsize;      /* size of data/ext/root */
235         __uint32_t              ilf_pad;        /* pad for 64 bit boundary */
236         __uint64_t              ilf_ino;        /* inode number */
237         union {
238                 __uint32_t      ilfu_rdev;      /* rdev value for dev inode*/
239                 uuid_t          ilfu_uuid;      /* mount point value */
240         } ilf_u;
241         __int64_t               ilf_blkno;      /* blkno of inode buffer */
242         __int32_t               ilf_len;        /* len of inode buffer */
243         __int32_t               ilf_boffset;    /* off of inode in buffer */
244 } xfs_inode_log_format_64_t;
245
246 /*
247  * Flags for xfs_trans_log_inode flags field.
248  */
249 #define XFS_ILOG_CORE   0x001   /* log standard inode fields */
250 #define XFS_ILOG_DDATA  0x002   /* log i_df.if_data */
251 #define XFS_ILOG_DEXT   0x004   /* log i_df.if_extents */
252 #define XFS_ILOG_DBROOT 0x008   /* log i_df.i_broot */
253 #define XFS_ILOG_DEV    0x010   /* log the dev field */
254 #define XFS_ILOG_UUID   0x020   /* log the uuid field */
255 #define XFS_ILOG_ADATA  0x040   /* log i_af.if_data */
256 #define XFS_ILOG_AEXT   0x080   /* log i_af.if_extents */
257 #define XFS_ILOG_ABROOT 0x100   /* log i_af.i_broot */
258
259
260 /*
261  * The timestamps are dirty, but not necessarily anything else in the inode
262  * core.  Unlike the other fields above this one must never make it to disk
263  * in the ilf_fields of the inode_log_format, but is purely store in-memory in
264  * ili_fields in the inode_log_item.
265  */
266 #define XFS_ILOG_TIMESTAMP      0x4000
267
268 #define XFS_ILOG_NONCORE        (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
269                                  XFS_ILOG_DBROOT | XFS_ILOG_DEV | \
270                                  XFS_ILOG_UUID | XFS_ILOG_ADATA | \
271                                  XFS_ILOG_AEXT | XFS_ILOG_ABROOT)
272
273 #define XFS_ILOG_DFORK          (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
274                                  XFS_ILOG_DBROOT)
275
276 #define XFS_ILOG_AFORK          (XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
277                                  XFS_ILOG_ABROOT)
278
279 #define XFS_ILOG_ALL            (XFS_ILOG_CORE | XFS_ILOG_DDATA | \
280                                  XFS_ILOG_DEXT | XFS_ILOG_DBROOT | \
281                                  XFS_ILOG_DEV | XFS_ILOG_UUID | \
282                                  XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
283                                  XFS_ILOG_ABROOT | XFS_ILOG_TIMESTAMP)
284
285 static inline int xfs_ilog_fbroot(int w)
286 {
287         return (w == XFS_DATA_FORK ? XFS_ILOG_DBROOT : XFS_ILOG_ABROOT);
288 }
289
290 static inline int xfs_ilog_fext(int w)
291 {
292         return (w == XFS_DATA_FORK ? XFS_ILOG_DEXT : XFS_ILOG_AEXT);
293 }
294
295 static inline int xfs_ilog_fdata(int w)
296 {
297         return (w == XFS_DATA_FORK ? XFS_ILOG_DDATA : XFS_ILOG_ADATA);
298 }
299
300 /*
301  * Incore version of the on-disk inode core structures. We log this directly
302  * into the journal in host CPU format (for better or worse) and as such
303  * directly mirrors the xfs_dinode structure as it must contain all the same
304  * information.
305  */
306 typedef struct xfs_ictimestamp {
307         __int32_t       t_sec;          /* timestamp seconds */
308         __int32_t       t_nsec;         /* timestamp nanoseconds */
309 } xfs_ictimestamp_t;
310
311 /*
312  * NOTE:  This structure must be kept identical to struct xfs_dinode
313  *        in xfs_dinode.h except for the endianness annotations.
314  */
315 typedef struct xfs_icdinode {
316         __uint16_t      di_magic;       /* inode magic # = XFS_DINODE_MAGIC */
317         __uint16_t      di_mode;        /* mode and type of file */
318         __int8_t        di_version;     /* inode version */
319         __int8_t        di_format;      /* format of di_c data */
320         __uint16_t      di_onlink;      /* old number of links to file */
321         __uint32_t      di_uid;         /* owner's user id */
322         __uint32_t      di_gid;         /* owner's group id */
323         __uint32_t      di_nlink;       /* number of links to file */
324         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
325         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
326         __uint8_t       di_pad[6];      /* unused, zeroed space */
327         __uint16_t      di_flushiter;   /* incremented on flush */
328         xfs_ictimestamp_t di_atime;     /* time last accessed */
329         xfs_ictimestamp_t di_mtime;     /* time last modified */
330         xfs_ictimestamp_t di_ctime;     /* time created/inode modified */
331         xfs_fsize_t     di_size;        /* number of bytes in file */
332         xfs_drfsbno_t   di_nblocks;     /* # of direct & btree blocks used */
333         xfs_extlen_t    di_extsize;     /* basic/minimum extent size for file */
334         xfs_extnum_t    di_nextents;    /* number of extents in data fork */
335         xfs_aextnum_t   di_anextents;   /* number of extents in attribute fork*/
336         __uint8_t       di_forkoff;     /* attr fork offs, <<3 for 64b align */
337         __int8_t        di_aformat;     /* format of attr fork's data */
338         __uint32_t      di_dmevmask;    /* DMIG event mask */
339         __uint16_t      di_dmstate;     /* DMIG state info */
340         __uint16_t      di_flags;       /* random flags, XFS_DIFLAG_... */
341         __uint32_t      di_gen;         /* generation number */
342
343         /* di_next_unlinked is the only non-core field in the old dinode */
344         xfs_agino_t     di_next_unlinked;/* agi unlinked list ptr */
345
346         /* start of the extended dinode, writable fields */
347         __uint32_t      di_crc;         /* CRC of the inode */
348         __uint64_t      di_changecount; /* number of attribute changes */
349         xfs_lsn_t       di_lsn;         /* flush sequence */
350         __uint64_t      di_flags2;      /* more random flags */
351         __uint8_t       di_pad2[16];    /* more padding for future expansion */
352
353         /* fields only written to during inode creation */
354         xfs_ictimestamp_t di_crtime;    /* time created */
355         xfs_ino_t       di_ino;         /* inode number */
356         uuid_t          di_uuid;        /* UUID of the filesystem */
357
358         /* structure must be padded to 64 bit alignment */
359 } xfs_icdinode_t;
360
361 static inline uint xfs_icdinode_size(int version)
362 {
363         if (version == 3)
364                 return sizeof(struct xfs_icdinode);
365         return offsetof(struct xfs_icdinode, di_next_unlinked);
366 }
367 #endif /* __XFS_LOG_FORMAT_H__ */