xref: /openbmc/linux/fs/xfs/xfs_buf_item.h (revision f35e839a)
1 /*
2  * Copyright (c) 2000-2001,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_BUF_ITEM_H__
19 #define	__XFS_BUF_ITEM_H__
20 
21 extern kmem_zone_t	*xfs_buf_item_zone;
22 
23 /*
24  * This flag indicates that the buffer contains on disk inodes
25  * and requires special recovery handling.
26  */
27 #define	XFS_BLF_INODE_BUF	(1<<0)
28 /*
29  * This flag indicates that the buffer should not be replayed
30  * during recovery because its blocks are being freed.
31  */
32 #define	XFS_BLF_CANCEL		(1<<1)
33 
34 /*
35  * This flag indicates that the buffer contains on disk
36  * user or group dquots and may require special recovery handling.
37  */
38 #define	XFS_BLF_UDQUOT_BUF	(1<<2)
39 #define XFS_BLF_PDQUOT_BUF	(1<<3)
40 #define	XFS_BLF_GDQUOT_BUF	(1<<4)
41 
42 #define	XFS_BLF_CHUNK		128
43 #define	XFS_BLF_SHIFT		7
44 #define	BIT_TO_WORD_SHIFT	5
45 #define	NBWORD			(NBBY * sizeof(unsigned int))
46 
47 /*
48  * This is the structure used to lay out a buf log item in the
49  * log.  The data map describes which 128 byte chunks of the buffer
50  * have been logged.
51  */
52 #define XFS_BLF_DATAMAP_SIZE	((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) / NBWORD)
53 
54 typedef struct xfs_buf_log_format {
55 	unsigned short	blf_type;	/* buf log item type indicator */
56 	unsigned short	blf_size;	/* size of this item */
57 	ushort		blf_flags;	/* misc state */
58 	ushort		blf_len;	/* number of blocks in this buf */
59 	__int64_t	blf_blkno;	/* starting blkno of this buf */
60 	unsigned int	blf_map_size;	/* used size of data bitmap in words */
61 	unsigned int	blf_data_map[XFS_BLF_DATAMAP_SIZE]; /* dirty bitmap */
62 } xfs_buf_log_format_t;
63 
64 /*
65  * All buffers now need to tell recovery where the magic number
66  * is so that it can verify and calculate the CRCs on the buffer correctly
67  * once the changes have been replayed into the buffer.
68  *
69  * The type value is held in the upper 5 bits of the blf_flags field, which is
70  * an unsigned 16 bit field. Hence we need to shift it 11 bits up and down.
71  */
72 #define XFS_BLFT_BITS	5
73 #define XFS_BLFT_SHIFT	11
74 #define XFS_BLFT_MASK	(((1 << XFS_BLFT_BITS) - 1) << XFS_BLFT_SHIFT)
75 
76 enum xfs_blft {
77 	XFS_BLFT_UNKNOWN_BUF = 0,
78 	XFS_BLFT_UDQUOT_BUF,
79 	XFS_BLFT_PDQUOT_BUF,
80 	XFS_BLFT_GDQUOT_BUF,
81 	XFS_BLFT_BTREE_BUF,
82 	XFS_BLFT_AGF_BUF,
83 	XFS_BLFT_AGFL_BUF,
84 	XFS_BLFT_AGI_BUF,
85 	XFS_BLFT_DINO_BUF,
86 	XFS_BLFT_SYMLINK_BUF,
87 	XFS_BLFT_DIR_BLOCK_BUF,
88 	XFS_BLFT_DIR_DATA_BUF,
89 	XFS_BLFT_DIR_FREE_BUF,
90 	XFS_BLFT_DIR_LEAF1_BUF,
91 	XFS_BLFT_DIR_LEAFN_BUF,
92 	XFS_BLFT_DA_NODE_BUF,
93 	XFS_BLFT_ATTR_LEAF_BUF,
94 	XFS_BLFT_ATTR_RMT_BUF,
95 	XFS_BLFT_SB_BUF,
96 	XFS_BLFT_MAX_BUF = (1 << XFS_BLFT_BITS),
97 };
98 
99 static inline void
100 xfs_blft_to_flags(struct xfs_buf_log_format *blf, enum xfs_blft type)
101 {
102 	ASSERT(type > XFS_BLFT_UNKNOWN_BUF && type < XFS_BLFT_MAX_BUF);
103 	blf->blf_flags &= ~XFS_BLFT_MASK;
104 	blf->blf_flags |= ((type << XFS_BLFT_SHIFT) & XFS_BLFT_MASK);
105 }
106 
107 static inline __uint16_t
108 xfs_blft_from_flags(struct xfs_buf_log_format *blf)
109 {
110 	return (blf->blf_flags & XFS_BLFT_MASK) >> XFS_BLFT_SHIFT;
111 }
112 
113 /*
114  * buf log item flags
115  */
116 #define	XFS_BLI_HOLD		0x01
117 #define	XFS_BLI_DIRTY		0x02
118 #define	XFS_BLI_STALE		0x04
119 #define	XFS_BLI_LOGGED		0x08
120 #define	XFS_BLI_INODE_ALLOC_BUF	0x10
121 #define XFS_BLI_STALE_INODE	0x20
122 #define	XFS_BLI_INODE_BUF	0x40
123 
124 #define XFS_BLI_FLAGS \
125 	{ XFS_BLI_HOLD,		"HOLD" }, \
126 	{ XFS_BLI_DIRTY,	"DIRTY" }, \
127 	{ XFS_BLI_STALE,	"STALE" }, \
128 	{ XFS_BLI_LOGGED,	"LOGGED" }, \
129 	{ XFS_BLI_INODE_ALLOC_BUF, "INODE_ALLOC" }, \
130 	{ XFS_BLI_STALE_INODE,	"STALE_INODE" }, \
131 	{ XFS_BLI_INODE_BUF,	"INODE_BUF" }
132 
133 
134 #ifdef __KERNEL__
135 
136 struct xfs_buf;
137 struct xfs_mount;
138 struct xfs_buf_log_item;
139 
140 /*
141  * This is the in core log item structure used to track information
142  * needed to log buffers.  It tracks how many times the lock has been
143  * locked, and which 128 byte chunks of the buffer are dirty.
144  */
145 typedef struct xfs_buf_log_item {
146 	xfs_log_item_t		bli_item;	/* common item structure */
147 	struct xfs_buf		*bli_buf;	/* real buffer pointer */
148 	unsigned int		bli_flags;	/* misc flags */
149 	unsigned int		bli_recur;	/* lock recursion count */
150 	atomic_t		bli_refcount;	/* cnt of tp refs */
151 	int			bli_format_count;	/* count of headers */
152 	struct xfs_buf_log_format *bli_formats;	/* array of in-log header ptrs */
153 	struct xfs_buf_log_format __bli_format;	/* embedded in-log header */
154 } xfs_buf_log_item_t;
155 
156 void	xfs_buf_item_init(struct xfs_buf *, struct xfs_mount *);
157 void	xfs_buf_item_relse(struct xfs_buf *);
158 void	xfs_buf_item_log(xfs_buf_log_item_t *, uint, uint);
159 uint	xfs_buf_item_dirty(xfs_buf_log_item_t *);
160 void	xfs_buf_attach_iodone(struct xfs_buf *,
161 			      void(*)(struct xfs_buf *, xfs_log_item_t *),
162 			      xfs_log_item_t *);
163 void	xfs_buf_iodone_callbacks(struct xfs_buf *);
164 void	xfs_buf_iodone(struct xfs_buf *, struct xfs_log_item *);
165 
166 void	xfs_trans_buf_set_type(struct xfs_trans *, struct xfs_buf *,
167 			       enum xfs_blft);
168 void	xfs_trans_buf_copy_type(struct xfs_buf *dst_bp, struct xfs_buf *src_bp);
169 
170 #endif	/* __KERNEL__ */
171 
172 #endif	/* __XFS_BUF_ITEM_H__ */
173