xref: /linux/fs/xfs/xfs_refcount_item.h (revision 509955823cc9cc225c05673b1b83d70ca70c5c60)
1baf4bcacSDarrick J. Wong /*
2baf4bcacSDarrick J. Wong  * Copyright (C) 2016 Oracle.  All Rights Reserved.
3baf4bcacSDarrick J. Wong  *
4baf4bcacSDarrick J. Wong  * Author: Darrick J. Wong <darrick.wong@oracle.com>
5baf4bcacSDarrick J. Wong  *
6baf4bcacSDarrick J. Wong  * This program is free software; you can redistribute it and/or
7baf4bcacSDarrick J. Wong  * modify it under the terms of the GNU General Public License
8baf4bcacSDarrick J. Wong  * as published by the Free Software Foundation; either version 2
9baf4bcacSDarrick J. Wong  * of the License, or (at your option) any later version.
10baf4bcacSDarrick J. Wong  *
11baf4bcacSDarrick J. Wong  * This program is distributed in the hope that it would be useful,
12baf4bcacSDarrick J. Wong  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13baf4bcacSDarrick J. Wong  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14baf4bcacSDarrick J. Wong  * GNU General Public License for more details.
15baf4bcacSDarrick J. Wong  *
16baf4bcacSDarrick J. Wong  * You should have received a copy of the GNU General Public License
17baf4bcacSDarrick J. Wong  * along with this program; if not, write the Free Software Foundation,
18baf4bcacSDarrick J. Wong  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
19baf4bcacSDarrick J. Wong  */
20baf4bcacSDarrick J. Wong #ifndef	__XFS_REFCOUNT_ITEM_H__
21baf4bcacSDarrick J. Wong #define	__XFS_REFCOUNT_ITEM_H__
22baf4bcacSDarrick J. Wong 
23baf4bcacSDarrick J. Wong /*
24baf4bcacSDarrick J. Wong  * There are (currently) two pairs of refcount btree redo item types:
25baf4bcacSDarrick J. Wong  * increase and decrease.  The log items for these are CUI (refcount
26baf4bcacSDarrick J. Wong  * update intent) and CUD (refcount update done).  The redo item type
27baf4bcacSDarrick J. Wong  * is encoded in the flags field of each xfs_map_extent.
28baf4bcacSDarrick J. Wong  *
29baf4bcacSDarrick J. Wong  * *I items should be recorded in the *first* of a series of rolled
30baf4bcacSDarrick J. Wong  * transactions, and the *D items should be recorded in the same
31baf4bcacSDarrick J. Wong  * transaction that records the associated refcountbt updates.
32baf4bcacSDarrick J. Wong  *
33baf4bcacSDarrick J. Wong  * Should the system crash after the commit of the first transaction
34baf4bcacSDarrick J. Wong  * but before the commit of the final transaction in a series, log
35baf4bcacSDarrick J. Wong  * recovery will use the redo information recorded by the intent items
36baf4bcacSDarrick J. Wong  * to replay the refcountbt metadata updates.
37baf4bcacSDarrick J. Wong  */
38baf4bcacSDarrick J. Wong 
39baf4bcacSDarrick J. Wong /* kernel only CUI/CUD definitions */
40baf4bcacSDarrick J. Wong 
41baf4bcacSDarrick J. Wong struct xfs_mount;
42baf4bcacSDarrick J. Wong struct kmem_zone;
43baf4bcacSDarrick J. Wong 
44baf4bcacSDarrick J. Wong /*
45baf4bcacSDarrick J. Wong  * Max number of extents in fast allocation path.
46baf4bcacSDarrick J. Wong  */
47baf4bcacSDarrick J. Wong #define	XFS_CUI_MAX_FAST_EXTENTS	16
48baf4bcacSDarrick J. Wong 
49baf4bcacSDarrick J. Wong /*
50baf4bcacSDarrick J. Wong  * Define CUI flag bits. Manipulated by set/clear/test_bit operators.
51baf4bcacSDarrick J. Wong  */
52baf4bcacSDarrick J. Wong #define	XFS_CUI_RECOVERED		1
53baf4bcacSDarrick J. Wong 
54baf4bcacSDarrick J. Wong /*
55baf4bcacSDarrick J. Wong  * This is the "refcount update intent" log item.  It is used to log
56baf4bcacSDarrick J. Wong  * the fact that some reverse mappings need to change.  It is used in
57baf4bcacSDarrick J. Wong  * conjunction with the "refcount update done" log item described
58baf4bcacSDarrick J. Wong  * below.
59baf4bcacSDarrick J. Wong  *
60baf4bcacSDarrick J. Wong  * These log items follow the same rules as struct xfs_efi_log_item;
61baf4bcacSDarrick J. Wong  * see the comments about that structure (in xfs_extfree_item.h) for
62baf4bcacSDarrick J. Wong  * more details.
63baf4bcacSDarrick J. Wong  */
64baf4bcacSDarrick J. Wong struct xfs_cui_log_item {
65baf4bcacSDarrick J. Wong 	struct xfs_log_item		cui_item;
66baf4bcacSDarrick J. Wong 	atomic_t			cui_refcount;
67baf4bcacSDarrick J. Wong 	atomic_t			cui_next_extent;
68baf4bcacSDarrick J. Wong 	unsigned long			cui_flags;	/* misc flags */
69baf4bcacSDarrick J. Wong 	struct xfs_cui_log_format	cui_format;
70baf4bcacSDarrick J. Wong };
71baf4bcacSDarrick J. Wong 
72baf4bcacSDarrick J. Wong static inline size_t
73baf4bcacSDarrick J. Wong xfs_cui_log_item_sizeof(
74baf4bcacSDarrick J. Wong 	unsigned int		nr)
75baf4bcacSDarrick J. Wong {
76baf4bcacSDarrick J. Wong 	return offsetof(struct xfs_cui_log_item, cui_format) +
77baf4bcacSDarrick J. Wong 			xfs_cui_log_format_sizeof(nr);
78baf4bcacSDarrick J. Wong }
79baf4bcacSDarrick J. Wong 
80baf4bcacSDarrick J. Wong /*
81baf4bcacSDarrick J. Wong  * This is the "refcount update done" log item.  It is used to log the
82baf4bcacSDarrick J. Wong  * fact that some refcountbt updates mentioned in an earlier cui item
83baf4bcacSDarrick J. Wong  * have been performed.
84baf4bcacSDarrick J. Wong  */
85baf4bcacSDarrick J. Wong struct xfs_cud_log_item {
86baf4bcacSDarrick J. Wong 	struct xfs_log_item		cud_item;
87baf4bcacSDarrick J. Wong 	struct xfs_cui_log_item		*cud_cuip;
88baf4bcacSDarrick J. Wong 	struct xfs_cud_log_format	cud_format;
89baf4bcacSDarrick J. Wong };
90baf4bcacSDarrick J. Wong 
91baf4bcacSDarrick J. Wong extern struct kmem_zone	*xfs_cui_zone;
92baf4bcacSDarrick J. Wong extern struct kmem_zone	*xfs_cud_zone;
93baf4bcacSDarrick J. Wong 
94baf4bcacSDarrick J. Wong struct xfs_cui_log_item *xfs_cui_init(struct xfs_mount *, uint);
95baf4bcacSDarrick J. Wong struct xfs_cud_log_item *xfs_cud_init(struct xfs_mount *,
96baf4bcacSDarrick J. Wong 		struct xfs_cui_log_item *);
97baf4bcacSDarrick J. Wong void xfs_cui_item_free(struct xfs_cui_log_item *);
98baf4bcacSDarrick J. Wong void xfs_cui_release(struct xfs_cui_log_item *);
99*50995582SDarrick J. Wong int xfs_cui_recover(struct xfs_mount *mp, struct xfs_cui_log_item *cuip,
100*50995582SDarrick J. Wong 		struct xfs_defer_ops *dfops);
101baf4bcacSDarrick J. Wong 
102baf4bcacSDarrick J. Wong #endif	/* __XFS_REFCOUNT_ITEM_H__ */
103