xref: /openbmc/linux/fs/xfs/xfs_refcount_item.h (revision 60772e48)
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_REFCOUNT_ITEM_H__
21 #define	__XFS_REFCOUNT_ITEM_H__
22 
23 /*
24  * There are (currently) two pairs of refcount btree redo item types:
25  * increase and decrease.  The log items for these are CUI (refcount
26  * update intent) and CUD (refcount update done).  The redo item type
27  * is encoded in the 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
31  * transaction that records the associated refcountbt updates.
32  *
33  * Should the system crash after the commit of the first transaction
34  * but before the commit of the final transaction in a series, log
35  * recovery will use the redo information recorded by the intent items
36  * to replay the refcountbt metadata updates.
37  */
38 
39 /* kernel only CUI/CUD definitions */
40 
41 struct xfs_mount;
42 struct kmem_zone;
43 
44 /*
45  * Max number of extents in fast allocation path.
46  */
47 #define	XFS_CUI_MAX_FAST_EXTENTS	16
48 
49 /*
50  * Define CUI flag bits. Manipulated by set/clear/test_bit operators.
51  */
52 #define	XFS_CUI_RECOVERED		1
53 
54 /*
55  * This is the "refcount update intent" log item.  It is used to log
56  * the fact that some reverse mappings need to change.  It is used in
57  * conjunction with the "refcount update done" log item described
58  * below.
59  *
60  * These log items follow the same rules as struct xfs_efi_log_item;
61  * see the comments about that structure (in xfs_extfree_item.h) for
62  * more details.
63  */
64 struct xfs_cui_log_item {
65 	struct xfs_log_item		cui_item;
66 	atomic_t			cui_refcount;
67 	atomic_t			cui_next_extent;
68 	unsigned long			cui_flags;	/* misc flags */
69 	struct xfs_cui_log_format	cui_format;
70 };
71 
72 static inline size_t
73 xfs_cui_log_item_sizeof(
74 	unsigned int		nr)
75 {
76 	return offsetof(struct xfs_cui_log_item, cui_format) +
77 			xfs_cui_log_format_sizeof(nr);
78 }
79 
80 /*
81  * This is the "refcount update done" log item.  It is used to log the
82  * fact that some refcountbt updates mentioned in an earlier cui item
83  * have been performed.
84  */
85 struct xfs_cud_log_item {
86 	struct xfs_log_item		cud_item;
87 	struct xfs_cui_log_item		*cud_cuip;
88 	struct xfs_cud_log_format	cud_format;
89 };
90 
91 extern struct kmem_zone	*xfs_cui_zone;
92 extern struct kmem_zone	*xfs_cud_zone;
93 
94 struct xfs_cui_log_item *xfs_cui_init(struct xfs_mount *, uint);
95 struct xfs_cud_log_item *xfs_cud_init(struct xfs_mount *,
96 		struct xfs_cui_log_item *);
97 void xfs_cui_item_free(struct xfs_cui_log_item *);
98 void xfs_cui_release(struct xfs_cui_log_item *);
99 int xfs_cui_recover(struct xfs_mount *mp, struct xfs_cui_log_item *cuip,
100 		struct xfs_defer_ops *dfops);
101 
102 #endif	/* __XFS_REFCOUNT_ITEM_H__ */
103