xref: /openbmc/linux/fs/xfs/xfs_rmap_item.h (revision 239480ab)
1 /*
2  * Copyright (C) 2016 Oracle.  All Rights Reserved.
3  *
4  * Author: Darrick J. Wong <darrick.wong@oracle.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it would be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write the Free Software Foundation,
18  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 #ifndef	__XFS_RMAP_ITEM_H__
21 #define	__XFS_RMAP_ITEM_H__
22 
23 /*
24  * There are (currently) three pairs of rmap btree redo item types: map, unmap,
25  * and convert.  The common abbreviations for these are RUI (rmap update
26  * intent) and RUD (rmap update done).  The redo item type is encoded in the
27  * flags field of each xfs_map_extent.
28  *
29  * *I items should be recorded in the *first* of a series of rolled
30  * transactions, and the *D items should be recorded in the same transaction
31  * that records the associated rmapbt updates.  Typically, the first
32  * transaction will record a bmbt update, followed by some number of
33  * transactions containing rmapbt updates, and finally transactions with any
34  * bnobt/cntbt updates.
35  *
36  * Should the system crash after the commit of the first transaction but
37  * before the commit of the final transaction in a series, log recovery will
38  * use the redo information recorded by the intent items to replay the
39  * (rmapbt/bnobt/cntbt) metadata updates in the non-first transaction.
40  */
41 
42 /* kernel only RUI/RUD definitions */
43 
44 struct xfs_mount;
45 struct kmem_zone;
46 
47 /*
48  * Max number of extents in fast allocation path.
49  */
50 #define	XFS_RUI_MAX_FAST_EXTENTS	16
51 
52 /*
53  * Define RUI flag bits. Manipulated by set/clear/test_bit operators.
54  */
55 #define	XFS_RUI_RECOVERED		1
56 
57 /*
58  * This is the "rmap update intent" log item.  It is used to log the fact that
59  * some reverse mappings need to change.  It is used in conjunction with the
60  * "rmap update done" log item described below.
61  *
62  * These log items follow the same rules as struct xfs_efi_log_item; see the
63  * comments about that structure (in xfs_extfree_item.h) for more details.
64  */
65 struct xfs_rui_log_item {
66 	struct xfs_log_item		rui_item;
67 	atomic_t			rui_refcount;
68 	atomic_t			rui_next_extent;
69 	unsigned long			rui_flags;	/* misc flags */
70 	struct xfs_rui_log_format	rui_format;
71 };
72 
73 static inline size_t
74 xfs_rui_log_item_sizeof(
75 	unsigned int		nr)
76 {
77 	return offsetof(struct xfs_rui_log_item, rui_format) +
78 			xfs_rui_log_format_sizeof(nr);
79 }
80 
81 /*
82  * This is the "rmap update done" log item.  It is used to log the fact that
83  * some rmapbt updates mentioned in an earlier rui item have been performed.
84  */
85 struct xfs_rud_log_item {
86 	struct xfs_log_item		rud_item;
87 	struct xfs_rui_log_item		*rud_ruip;
88 	struct xfs_rud_log_format	rud_format;
89 };
90 
91 extern struct kmem_zone	*xfs_rui_zone;
92 extern struct kmem_zone	*xfs_rud_zone;
93 
94 struct xfs_rui_log_item *xfs_rui_init(struct xfs_mount *, uint);
95 struct xfs_rud_log_item *xfs_rud_init(struct xfs_mount *,
96 		struct xfs_rui_log_item *);
97 int xfs_rui_copy_format(struct xfs_log_iovec *buf,
98 		struct xfs_rui_log_format *dst_rui_fmt);
99 void xfs_rui_item_free(struct xfs_rui_log_item *);
100 void xfs_rui_release(struct xfs_rui_log_item *);
101 int xfs_rui_recover(struct xfs_mount *mp, struct xfs_rui_log_item *ruip);
102 
103 #endif	/* __XFS_RMAP_ITEM_H__ */
104