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