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