]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/xfs_trans.h
xfs_repair: rebuild block mappings from rmapbt data
[thirdparty/xfsprogs-dev.git] / include / xfs_trans.h
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
b626fb59
DC
2/*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
b626fb59
DC
5 */
6
7#ifndef __XFS_TRANS_H__
8#define __XFS_TRANS_H__
9
10struct xfs_mount;
11struct xfs_buftarg;
12struct xfs_buf;
13struct xfs_buf_map;
14
15/*
16 * Userspace Transaction interface
17 */
18
05a3a389
DW
19struct xfs_item_ops {
20 uint64_t (*iop_sort)(struct xfs_log_item *lip);
21 int (*iop_precommit)(struct xfs_trans *tp, struct xfs_log_item *lip);
22};
23
b626fb59 24typedef struct xfs_log_item {
2fdd378a
DC
25 struct list_head li_trans; /* transaction list */
26 xfs_lsn_t li_lsn; /* last on-disk lsn */
b626fb59
DC
27 struct xfs_mount *li_mountp; /* ptr to fs mount */
28 uint li_type; /* item type */
2fdd378a 29 unsigned long li_flags; /* misc flags */
2b8ea826 30 struct xfs_buf *li_buf; /* real buffer pointer */
2efa10f3 31 struct list_head li_bio_list; /* buffer item list */
05a3a389 32 const struct xfs_item_ops *li_ops; /* function list */
b626fb59
DC
33} xfs_log_item_t;
34
2fdd378a
DC
35#define XFS_LI_DIRTY 3 /* log item dirty in transaction */
36
ed8d09e1 37struct xfs_inode_log_item {
b626fb59
DC
38 xfs_log_item_t ili_item; /* common portion */
39 struct xfs_inode *ili_inode; /* inode pointer */
c0860494 40 unsigned short ili_lock_flags; /* lock flags */
a565e345 41 unsigned int ili_dirty_flags; /* dirty in current tx */
b626fb59 42 unsigned int ili_last_fields; /* fields when flushed*/
5539639c
ES
43 unsigned int ili_fields; /* fields to be logged */
44 unsigned int ili_fsync_fields; /* ignored by userspace */
686bddf9 45 spinlock_t ili_lock;
ed8d09e1 46};
b626fb59
DC
47
48typedef struct xfs_buf_log_item {
49 xfs_log_item_t bli_item; /* common item structure */
50 struct xfs_buf *bli_buf; /* real buffer pointer */
51 unsigned int bli_flags; /* misc flags */
52 unsigned int bli_recur; /* recursion count */
cebe02e2 53 xfs_buf_log_format_t __bli_format; /* in-log header */
b626fb59
DC
54} xfs_buf_log_item_t;
55
56#define XFS_BLI_DIRTY (1<<0)
57#define XFS_BLI_HOLD (1<<1)
58#define XFS_BLI_STALE (1<<2)
59#define XFS_BLI_INODE_ALLOC_BUF (1<<3)
e30de1a1 60#define XFS_BLI_ORDERED (1<<4)
b626fb59 61
b626fb59
DC
62typedef struct xfs_qoff_logitem {
63 xfs_log_item_t qql_item; /* common portion */
64 struct xfs_qoff_logitem *qql_start_lip; /* qoff-start logitem, if any */
65 xfs_qoff_logformat_t qql_format; /* logged structure */
66} xfs_qoff_logitem_t;
67
68typedef struct xfs_trans {
9543cb30
DC
69 unsigned int t_log_res; /* amt of log space resvd */
70 unsigned int t_log_count; /* count for perm log res */
71 unsigned int t_blk_res; /* # of blocks resvd */
72 unsigned int t_blk_res_used; /* # of resvd blocks used */
73 unsigned int t_rtx_res; /* # of rt extents resvd */
74 unsigned int t_rtx_res_used; /* # of resvd rt extents used */
75 unsigned int t_flags; /* misc flags */
9cdecd7e 76 xfs_agnumber_t t_highest_agno; /* highest AGF locked */
9543cb30
DC
77 struct xfs_mount *t_mountp; /* ptr to fs mount struct */
78 struct xfs_dquot_acct *t_dqinfo; /* acctg info for dquots */
79 long t_icount_delta; /* superblock icount change */
80 long t_ifree_delta; /* superblock ifree change */
81 long t_fdblocks_delta;/* superblock fdblocks chg */
82 long t_frextents_delta;/* superblock freextents chg*/
83 struct list_head t_items; /* log item descriptors */
92a8736e 84 struct list_head t_dfops; /* deferred operations */
b626fb59
DC
85} xfs_trans_t;
86
87void xfs_trans_init(struct xfs_mount *);
d67406c9 88int xfs_trans_roll(struct xfs_trans **);
b626fb59 89
9074815c
CH
90int libxfs_trans_alloc(struct xfs_mount *mp, struct xfs_trans_res *resp,
91 uint blocks, uint rtextents, uint flags,
92 struct xfs_trans **tpp);
d2b662c2 93int libxfs_trans_alloc_inode(struct xfs_inode *ip, struct xfs_trans_res *resv,
36bd1bdd
DW
94 unsigned int dblocks, unsigned int rblocks, bool force,
95 struct xfs_trans **tpp);
225e4bb2
DW
96int libxfs_trans_alloc_rollable(struct xfs_mount *mp, uint blocks,
97 struct xfs_trans **tpp);
3680a764 98int libxfs_trans_alloc_empty(struct xfs_mount *mp, struct xfs_trans **tpp);
de5a3f46 99int libxfs_trans_commit(struct xfs_trans *);
3d7434fe 100void libxfs_trans_cancel(struct xfs_trans *);
b3bcb8f0
DW
101int libxfs_trans_reserve_more(struct xfs_trans *tp, uint blocks,
102 uint rtextents);
ac0a2228
BF
103
104/* cancel dfops associated with a transaction */
105void xfs_defer_cancel(struct xfs_trans *);
106
37e6f885 107struct xfs_buf *libxfs_trans_getsb(struct xfs_trans *);
b626fb59 108
b626fb59 109void libxfs_trans_ijoin(struct xfs_trans *, struct xfs_inode *, uint);
b626fb59
DC
110void libxfs_trans_log_inode (struct xfs_trans *, struct xfs_inode *,
111 uint);
d67406c9 112int libxfs_trans_roll_inode (struct xfs_trans **, struct xfs_inode *);
b626fb59
DC
113
114void libxfs_trans_brelse(struct xfs_trans *, struct xfs_buf *);
115void libxfs_trans_binval(struct xfs_trans *, struct xfs_buf *);
116void libxfs_trans_bjoin(struct xfs_trans *, struct xfs_buf *);
117void libxfs_trans_bhold(struct xfs_trans *, struct xfs_buf *);
9833c1a4 118void libxfs_trans_bhold_release(struct xfs_trans *, struct xfs_buf *);
59630067 119void libxfs_trans_dirty_buf(struct xfs_trans *, struct xfs_buf *);
b626fb59
DC
120void libxfs_trans_log_buf(struct xfs_trans *, struct xfs_buf *,
121 uint, uint);
38fa71a7 122bool libxfs_trans_ordered_buf(xfs_trans_t *, struct xfs_buf *);
b626fb59 123
51409fcc
DW
124int libxfs_trans_get_buf_map(struct xfs_trans *tp, struct xfs_buftarg *btp,
125 struct xfs_buf_map *map, int nmaps, xfs_buf_flags_t flags,
126 struct xfs_buf **bpp);
b626fb59
DC
127
128int libxfs_trans_read_buf_map(struct xfs_mount *mp, struct xfs_trans *tp,
129 struct xfs_buftarg *btp,
130 struct xfs_buf_map *map, int nmaps,
3a3f5b14 131 xfs_buf_flags_t flags, struct xfs_buf **bpp,
b626fb59 132 const struct xfs_buf_ops *ops);
7f15a547 133static inline int
b626fb59
DC
134libxfs_trans_get_buf(
135 struct xfs_trans *tp,
136 struct xfs_buftarg *btp,
137 xfs_daddr_t blkno,
138 int numblks,
7f15a547
DW
139 uint flags,
140 struct xfs_buf **bpp)
b626fb59
DC
141{
142 DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
51409fcc 143
7f15a547 144 return libxfs_trans_get_buf_map(tp, btp, &map, 1, flags, bpp);
b626fb59
DC
145}
146
147static inline int
148libxfs_trans_read_buf(
149 struct xfs_mount *mp,
150 struct xfs_trans *tp,
151 struct xfs_buftarg *btp,
152 xfs_daddr_t blkno,
153 int numblks,
3a3f5b14 154 xfs_buf_flags_t flags,
b626fb59
DC
155 struct xfs_buf **bpp,
156 const struct xfs_buf_ops *ops)
157{
158 DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
159 return libxfs_trans_read_buf_map(mp, tp, btp, &map, 1, flags, bpp, ops);
160}
161
1826a6b0 162#define xfs_log_item_in_current_chkpt(lip) (false)
1826a6b0 163
e49ec9ed
DW
164/* Contorted mess to make gcc shut up about unused vars. */
165#define xlog_grant_push_threshold(log, need) \
166 ((log) == (log) ? NULLCOMMITLSN : NULLCOMMITLSN)
167
168/* from xfs_log.h */
169/*
170 * By comparing each component, we don't have to worry about extra
171 * endian issues in treating two 32 bit numbers as one 64 bit number
172 */
173static inline xfs_lsn_t _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2)
174{
175 if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2))
176 return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999;
177
178 if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2))
179 return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999;
180
181 return 0;
182}
183
184#define XFS_LSN_CMP(a, b) _lsn_cmp(a, b)
185
b626fb59 186#endif /* __XFS_TRANS_H__ */