]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/xfs_trans.h
libxfs: fix xfs_trans_alloc reservation abuse
[thirdparty/xfsprogs-dev.git] / include / xfs_trans.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #ifndef __XFS_TRANS_H__
8 #define __XFS_TRANS_H__
9
10 struct xfs_mount;
11 struct xfs_buftarg;
12 struct xfs_buf;
13 struct xfs_buf_map;
14
15 /*
16 * Userspace Transaction interface
17 */
18
19 typedef struct xfs_log_item {
20 struct list_head li_trans; /* transaction list */
21 xfs_lsn_t li_lsn; /* last on-disk lsn */
22 struct xfs_mount *li_mountp; /* ptr to fs mount */
23 uint li_type; /* item type */
24 unsigned long li_flags; /* misc flags */
25 } xfs_log_item_t;
26
27 #define XFS_LI_DIRTY 3 /* log item dirty in transaction */
28
29 typedef struct xfs_inode_log_item {
30 xfs_log_item_t ili_item; /* common portion */
31 struct xfs_inode *ili_inode; /* inode pointer */
32 unsigned short ili_flags; /* misc flags */
33 unsigned int ili_fields; /* fields to be logged */
34 unsigned int ili_last_fields; /* fields when flushed*/
35 } xfs_inode_log_item_t;
36
37 typedef struct xfs_buf_log_item {
38 xfs_log_item_t bli_item; /* common item structure */
39 struct xfs_buf *bli_buf; /* real buffer pointer */
40 unsigned int bli_flags; /* misc flags */
41 unsigned int bli_recur; /* recursion count */
42 xfs_buf_log_format_t bli_format; /* in-log header */
43 } xfs_buf_log_item_t;
44
45 #define XFS_BLI_DIRTY (1<<0)
46 #define XFS_BLI_HOLD (1<<1)
47 #define XFS_BLI_STALE (1<<2)
48 #define XFS_BLI_INODE_ALLOC_BUF (1<<3)
49
50 typedef struct xfs_dq_logitem {
51 xfs_log_item_t qli_item; /* common portion */
52 struct xfs_dquot *qli_dquot; /* dquot ptr */
53 xfs_lsn_t qli_flush_lsn; /* lsn at last flush */
54 xfs_dq_logformat_t qli_format; /* logged structure */
55 } xfs_dq_logitem_t;
56
57 typedef struct xfs_qoff_logitem {
58 xfs_log_item_t qql_item; /* common portion */
59 struct xfs_qoff_logitem *qql_start_lip; /* qoff-start logitem, if any */
60 xfs_qoff_logformat_t qql_format; /* logged structure */
61 } xfs_qoff_logitem_t;
62
63 typedef struct xfs_trans {
64 unsigned int t_type; /* transaction type */
65 unsigned int t_log_res; /* amt of log space resvd */
66 unsigned int t_log_count; /* count for perm log res */
67 unsigned int t_blk_res; /* # of blocks resvd */
68 struct xfs_mount *t_mountp; /* ptr to fs mount struct */
69 unsigned int t_flags; /* misc flags */
70 long t_icount_delta; /* superblock icount change */
71 long t_ifree_delta; /* superblock ifree change */
72 long t_fdblocks_delta; /* superblock fdblocks chg */
73 long t_frextents_delta; /* superblock freextents chg */
74 struct list_head t_items; /* first log item desc chunk */
75 struct xfs_defer_ops *t_agfl_dfops; /* optional agfl fixup dfops */
76
77 } xfs_trans_t;
78
79 void xfs_trans_init(struct xfs_mount *);
80 int xfs_trans_roll(struct xfs_trans **);
81
82 int libxfs_trans_alloc(struct xfs_mount *mp, struct xfs_trans_res *resp,
83 uint blocks, uint rtextents, uint flags,
84 struct xfs_trans **tpp);
85 int libxfs_trans_alloc_rollable(struct xfs_mount *mp, uint blocks,
86 struct xfs_trans **tpp);
87 int libxfs_trans_alloc_empty(struct xfs_mount *mp, struct xfs_trans **tpp);
88 int libxfs_trans_commit(struct xfs_trans *);
89 void libxfs_trans_cancel(struct xfs_trans *);
90 struct xfs_buf *libxfs_trans_getsb(struct xfs_trans *, struct xfs_mount *, int);
91
92 int libxfs_trans_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
93 uint, uint, struct xfs_inode **);
94 void libxfs_trans_ijoin(struct xfs_trans *, struct xfs_inode *, uint);
95 void libxfs_trans_ijoin_ref(struct xfs_trans *, struct xfs_inode *, int);
96 void libxfs_trans_log_inode (struct xfs_trans *, struct xfs_inode *,
97 uint);
98 int libxfs_trans_roll_inode (struct xfs_trans **, struct xfs_inode *);
99
100 void libxfs_trans_brelse(struct xfs_trans *, struct xfs_buf *);
101 void libxfs_trans_binval(struct xfs_trans *, struct xfs_buf *);
102 void libxfs_trans_bjoin(struct xfs_trans *, struct xfs_buf *);
103 void libxfs_trans_bhold(struct xfs_trans *, struct xfs_buf *);
104 void libxfs_trans_dirty_buf(struct xfs_trans *, struct xfs_buf *);
105 void libxfs_trans_log_buf(struct xfs_trans *, struct xfs_buf *,
106 uint, uint);
107 bool libxfs_trans_ordered_buf(xfs_trans_t *, struct xfs_buf *);
108
109 struct xfs_buf *libxfs_trans_get_buf_map(struct xfs_trans *tp,
110 struct xfs_buftarg *btp,
111 struct xfs_buf_map *map, int nmaps,
112 uint flags);
113
114 int libxfs_trans_read_buf_map(struct xfs_mount *mp, struct xfs_trans *tp,
115 struct xfs_buftarg *btp,
116 struct xfs_buf_map *map, int nmaps,
117 uint flags, struct xfs_buf **bpp,
118 const struct xfs_buf_ops *ops);
119 static inline struct xfs_buf *
120 libxfs_trans_get_buf(
121 struct xfs_trans *tp,
122 struct xfs_buftarg *btp,
123 xfs_daddr_t blkno,
124 int numblks,
125 uint flags)
126 {
127 DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
128 return libxfs_trans_get_buf_map(tp, btp, &map, 1, flags);
129 }
130
131 static inline int
132 libxfs_trans_read_buf(
133 struct xfs_mount *mp,
134 struct xfs_trans *tp,
135 struct xfs_buftarg *btp,
136 xfs_daddr_t blkno,
137 int numblks,
138 uint flags,
139 struct xfs_buf **bpp,
140 const struct xfs_buf_ops *ops)
141 {
142 DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
143 return libxfs_trans_read_buf_map(mp, tp, btp, &map, 1, flags, bpp, ops);
144 }
145
146 void xfs_extent_free_init_defer_op(void);
147 void xfs_rmap_update_init_defer_op(void);
148 void xfs_refcount_update_init_defer_op(void);
149 void xfs_bmap_update_init_defer_op(void);
150
151 #endif /* __XFS_TRANS_H__ */