Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * Copyright (C) 2016 Oracle.  All Rights Reserved.
 
  4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  5 */
  6#ifndef __XFS_RMAP_H__
  7#define __XFS_RMAP_H__
  8
  9struct xfs_perag;
 
 
 
 
 
 
 
 
 10
 11static inline void
 12xfs_rmap_ino_bmbt_owner(
 13	struct xfs_owner_info	*oi,
 14	xfs_ino_t		ino,
 15	int			whichfork)
 16{
 17	oi->oi_owner = ino;
 18	oi->oi_offset = 0;
 19	oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK;
 20	if (whichfork == XFS_ATTR_FORK)
 21		oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
 22}
 23
 24static inline void
 25xfs_rmap_ino_owner(
 26	struct xfs_owner_info	*oi,
 27	xfs_ino_t		ino,
 28	int			whichfork,
 29	xfs_fileoff_t		offset)
 30{
 31	oi->oi_owner = ino;
 32	oi->oi_offset = offset;
 33	oi->oi_flags = 0;
 34	if (whichfork == XFS_ATTR_FORK)
 35		oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
 36}
 37
 
 
 
 
 
 
 
 38static inline bool
 39xfs_rmap_should_skip_owner_update(
 40	const struct xfs_owner_info	*oi)
 41{
 42	return oi->oi_owner == XFS_RMAP_OWN_NULL;
 43}
 44
 
 
 
 
 
 
 
 45/* Reverse mapping functions. */
 46
 47struct xfs_buf;
 48
 49static inline __u64
 50xfs_rmap_irec_offset_pack(
 51	const struct xfs_rmap_irec	*irec)
 52{
 53	__u64			x;
 54
 55	x = XFS_RMAP_OFF(irec->rm_offset);
 56	if (irec->rm_flags & XFS_RMAP_ATTR_FORK)
 57		x |= XFS_RMAP_OFF_ATTR_FORK;
 58	if (irec->rm_flags & XFS_RMAP_BMBT_BLOCK)
 59		x |= XFS_RMAP_OFF_BMBT_BLOCK;
 60	if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
 61		x |= XFS_RMAP_OFF_UNWRITTEN;
 62	return x;
 63}
 64
 65static inline int
 66xfs_rmap_irec_offset_unpack(
 67	__u64			offset,
 68	struct xfs_rmap_irec	*irec)
 69{
 70	if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
 71		return -EFSCORRUPTED;
 72	irec->rm_offset = XFS_RMAP_OFF(offset);
 73	irec->rm_flags = 0;
 74	if (offset & XFS_RMAP_OFF_ATTR_FORK)
 75		irec->rm_flags |= XFS_RMAP_ATTR_FORK;
 76	if (offset & XFS_RMAP_OFF_BMBT_BLOCK)
 77		irec->rm_flags |= XFS_RMAP_BMBT_BLOCK;
 78	if (offset & XFS_RMAP_OFF_UNWRITTEN)
 79		irec->rm_flags |= XFS_RMAP_UNWRITTEN;
 80	return 0;
 81}
 82
 83static inline void
 84xfs_owner_info_unpack(
 85	const struct xfs_owner_info	*oinfo,
 86	uint64_t			*owner,
 87	uint64_t			*offset,
 88	unsigned int			*flags)
 89{
 90	unsigned int			r = 0;
 91
 92	*owner = oinfo->oi_owner;
 93	*offset = oinfo->oi_offset;
 94	if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK)
 95		r |= XFS_RMAP_ATTR_FORK;
 96	if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK)
 97		r |= XFS_RMAP_BMBT_BLOCK;
 98	*flags = r;
 99}
100
101static inline void
102xfs_owner_info_pack(
103	struct xfs_owner_info	*oinfo,
104	uint64_t		owner,
105	uint64_t		offset,
106	unsigned int		flags)
107{
108	oinfo->oi_owner = owner;
109	oinfo->oi_offset = XFS_RMAP_OFF(offset);
110	oinfo->oi_flags = 0;
111	if (flags & XFS_RMAP_ATTR_FORK)
112		oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
113	if (flags & XFS_RMAP_BMBT_BLOCK)
114		oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK;
115}
116
117int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
118		   struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len,
119		   const struct xfs_owner_info *oinfo);
120int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
121		  struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len,
122		  const struct xfs_owner_info *oinfo);
123
124int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
125		uint64_t owner, uint64_t offset, unsigned int flags,
126		struct xfs_rmap_irec *irec, int *stat);
127int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
128		xfs_extlen_t len, uint64_t owner, uint64_t offset,
129		unsigned int flags, int *stat);
130int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
131		xfs_extlen_t len, uint64_t owner, uint64_t offset,
132		unsigned int flags);
133int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
134		int *stat);
135
136typedef int (*xfs_rmap_query_range_fn)(
137	struct xfs_btree_cur		*cur,
138	const struct xfs_rmap_irec	*rec,
139	void				*priv);
140
141int xfs_rmap_query_range(struct xfs_btree_cur *cur,
142		const struct xfs_rmap_irec *low_rec,
143		const struct xfs_rmap_irec *high_rec,
144		xfs_rmap_query_range_fn fn, void *priv);
145int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn,
146		void *priv);
147
148enum xfs_rmap_intent_type {
149	XFS_RMAP_MAP,
150	XFS_RMAP_MAP_SHARED,
151	XFS_RMAP_UNMAP,
152	XFS_RMAP_UNMAP_SHARED,
153	XFS_RMAP_CONVERT,
154	XFS_RMAP_CONVERT_SHARED,
155	XFS_RMAP_ALLOC,
156	XFS_RMAP_FREE,
157};
158
159struct xfs_rmap_intent {
160	struct list_head			ri_list;
161	enum xfs_rmap_intent_type		ri_type;
162	int					ri_whichfork;
163	uint64_t				ri_owner;
 
164	struct xfs_bmbt_irec			ri_bmap;
165};
166
167/* functions for updating the rmapbt based on bmbt map/unmap operations */
168void xfs_rmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
169		int whichfork, struct xfs_bmbt_irec *imap);
170void xfs_rmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip,
171		int whichfork, struct xfs_bmbt_irec *imap);
172void xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_trans *tp,
173		struct xfs_inode *ip, int whichfork,
174		struct xfs_bmbt_irec *imap);
175void xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
176		xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
177void xfs_rmap_free_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
178		xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
 
 
 
 
 
179
180void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp,
181		struct xfs_btree_cur *rcur, int error);
182int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
183		uint64_t owner, int whichfork, xfs_fileoff_t startoff,
184		xfs_fsblock_t startblock, xfs_filblks_t blockcount,
185		xfs_exntst_t state, struct xfs_btree_cur **pcur);
186
 
 
 
187int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
188		uint64_t owner, uint64_t offset, unsigned int flags,
189		struct xfs_rmap_irec *irec, int	*stat);
190int xfs_rmap_compare(const struct xfs_rmap_irec *a,
191		const struct xfs_rmap_irec *b);
192union xfs_btree_rec;
193int xfs_rmap_btrec_to_irec(const union xfs_btree_rec *rec,
194		struct xfs_rmap_irec *irec);
195int xfs_rmap_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
196		xfs_extlen_t len, bool *exists);
197int xfs_rmap_record_exists(struct xfs_btree_cur *cur, xfs_agblock_t bno,
198		xfs_extlen_t len, const struct xfs_owner_info *oinfo,
199		bool *has_rmap);
200int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno,
201		xfs_extlen_t len, const struct xfs_owner_info *oinfo,
202		bool *has_rmap);
203int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap);
204
205extern const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE;
206extern const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER;
207extern const struct xfs_owner_info XFS_RMAP_OINFO_FS;
208extern const struct xfs_owner_info XFS_RMAP_OINFO_LOG;
209extern const struct xfs_owner_info XFS_RMAP_OINFO_AG;
210extern const struct xfs_owner_info XFS_RMAP_OINFO_INOBT;
211extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES;
212extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC;
213extern const struct xfs_owner_info XFS_RMAP_OINFO_COW;
214
215extern struct kmem_cache	*xfs_rmap_intent_cache;
216
217int __init xfs_rmap_intent_init_cache(void);
218void xfs_rmap_intent_destroy_cache(void);
219
220#endif	/* __XFS_RMAP_H__ */
v4.17
 
  1/*
  2 * Copyright (C) 2016 Oracle.  All Rights Reserved.
  3 *
  4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
  5 *
  6 * This program is free software; you can redistribute it and/or
  7 * modify it under the terms of the GNU General Public License
  8 * as published by the Free Software Foundation; either version 2
  9 * of the License, or (at your option) any later version.
 10 *
 11 * This program is distributed in the hope that it would be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU General Public License for more details.
 15 *
 16 * You should have received a copy of the GNU General Public License
 17 * along with this program; if not, write the Free Software Foundation,
 18 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
 19 */
 20#ifndef __XFS_RMAP_H__
 21#define __XFS_RMAP_H__
 22
 23static inline void
 24xfs_rmap_ag_owner(
 25	struct xfs_owner_info	*oi,
 26	uint64_t		owner)
 27{
 28	oi->oi_owner = owner;
 29	oi->oi_offset = 0;
 30	oi->oi_flags = 0;
 31}
 32
 33static inline void
 34xfs_rmap_ino_bmbt_owner(
 35	struct xfs_owner_info	*oi,
 36	xfs_ino_t		ino,
 37	int			whichfork)
 38{
 39	oi->oi_owner = ino;
 40	oi->oi_offset = 0;
 41	oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK;
 42	if (whichfork == XFS_ATTR_FORK)
 43		oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
 44}
 45
 46static inline void
 47xfs_rmap_ino_owner(
 48	struct xfs_owner_info	*oi,
 49	xfs_ino_t		ino,
 50	int			whichfork,
 51	xfs_fileoff_t		offset)
 52{
 53	oi->oi_owner = ino;
 54	oi->oi_offset = offset;
 55	oi->oi_flags = 0;
 56	if (whichfork == XFS_ATTR_FORK)
 57		oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
 58}
 59
 60static inline void
 61xfs_rmap_skip_owner_update(
 62	struct xfs_owner_info	*oi)
 63{
 64	xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_NULL);
 65}
 66
 67static inline bool
 68xfs_rmap_should_skip_owner_update(
 69	struct xfs_owner_info	*oi)
 70{
 71	return oi->oi_owner == XFS_RMAP_OWN_NULL;
 72}
 73
 74static inline void
 75xfs_rmap_any_owner_update(
 76	struct xfs_owner_info	*oi)
 77{
 78	xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_UNKNOWN);
 79}
 80
 81/* Reverse mapping functions. */
 82
 83struct xfs_buf;
 84
 85static inline __u64
 86xfs_rmap_irec_offset_pack(
 87	const struct xfs_rmap_irec	*irec)
 88{
 89	__u64			x;
 90
 91	x = XFS_RMAP_OFF(irec->rm_offset);
 92	if (irec->rm_flags & XFS_RMAP_ATTR_FORK)
 93		x |= XFS_RMAP_OFF_ATTR_FORK;
 94	if (irec->rm_flags & XFS_RMAP_BMBT_BLOCK)
 95		x |= XFS_RMAP_OFF_BMBT_BLOCK;
 96	if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
 97		x |= XFS_RMAP_OFF_UNWRITTEN;
 98	return x;
 99}
100
101static inline int
102xfs_rmap_irec_offset_unpack(
103	__u64			offset,
104	struct xfs_rmap_irec	*irec)
105{
106	if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
107		return -EFSCORRUPTED;
108	irec->rm_offset = XFS_RMAP_OFF(offset);
 
109	if (offset & XFS_RMAP_OFF_ATTR_FORK)
110		irec->rm_flags |= XFS_RMAP_ATTR_FORK;
111	if (offset & XFS_RMAP_OFF_BMBT_BLOCK)
112		irec->rm_flags |= XFS_RMAP_BMBT_BLOCK;
113	if (offset & XFS_RMAP_OFF_UNWRITTEN)
114		irec->rm_flags |= XFS_RMAP_UNWRITTEN;
115	return 0;
116}
117
118static inline void
119xfs_owner_info_unpack(
120	struct xfs_owner_info	*oinfo,
121	uint64_t		*owner,
122	uint64_t		*offset,
123	unsigned int		*flags)
124{
125	unsigned int		r = 0;
126
127	*owner = oinfo->oi_owner;
128	*offset = oinfo->oi_offset;
129	if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK)
130		r |= XFS_RMAP_ATTR_FORK;
131	if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK)
132		r |= XFS_RMAP_BMBT_BLOCK;
133	*flags = r;
134}
135
136static inline void
137xfs_owner_info_pack(
138	struct xfs_owner_info	*oinfo,
139	uint64_t		owner,
140	uint64_t		offset,
141	unsigned int		flags)
142{
143	oinfo->oi_owner = owner;
144	oinfo->oi_offset = XFS_RMAP_OFF(offset);
145	oinfo->oi_flags = 0;
146	if (flags & XFS_RMAP_ATTR_FORK)
147		oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
148	if (flags & XFS_RMAP_BMBT_BLOCK)
149		oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK;
150}
151
152int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
153		   xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
154		   struct xfs_owner_info *oinfo);
155int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
156		  xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
157		  struct xfs_owner_info *oinfo);
158
159int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
160		xfs_extlen_t len, uint64_t owner, uint64_t offset,
161		unsigned int flags, int *stat);
162int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
163		xfs_extlen_t len, uint64_t owner, uint64_t offset,
164		unsigned int flags, int *stat);
165int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
166		xfs_extlen_t len, uint64_t owner, uint64_t offset,
167		unsigned int flags);
168int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
169		int *stat);
170
171typedef int (*xfs_rmap_query_range_fn)(
172	struct xfs_btree_cur	*cur,
173	struct xfs_rmap_irec	*rec,
174	void			*priv);
175
176int xfs_rmap_query_range(struct xfs_btree_cur *cur,
177		struct xfs_rmap_irec *low_rec, struct xfs_rmap_irec *high_rec,
 
178		xfs_rmap_query_range_fn fn, void *priv);
179int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn,
180		void *priv);
181
182enum xfs_rmap_intent_type {
183	XFS_RMAP_MAP,
184	XFS_RMAP_MAP_SHARED,
185	XFS_RMAP_UNMAP,
186	XFS_RMAP_UNMAP_SHARED,
187	XFS_RMAP_CONVERT,
188	XFS_RMAP_CONVERT_SHARED,
189	XFS_RMAP_ALLOC,
190	XFS_RMAP_FREE,
191};
192
193struct xfs_rmap_intent {
194	struct list_head			ri_list;
195	enum xfs_rmap_intent_type		ri_type;
 
196	uint64_t				ri_owner;
197	int					ri_whichfork;
198	struct xfs_bmbt_irec			ri_bmap;
199};
200
201/* functions for updating the rmapbt based on bmbt map/unmap operations */
202int xfs_rmap_map_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
203		struct xfs_inode *ip, int whichfork,
204		struct xfs_bmbt_irec *imap);
205int xfs_rmap_unmap_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
 
206		struct xfs_inode *ip, int whichfork,
207		struct xfs_bmbt_irec *imap);
208int xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
209		struct xfs_inode *ip, int whichfork,
210		struct xfs_bmbt_irec *imap);
211int xfs_rmap_alloc_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
212		xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
213		uint64_t owner);
214int xfs_rmap_free_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
215		xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
216		uint64_t owner);
217
218void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp,
219		struct xfs_btree_cur *rcur, int error);
220int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
221		uint64_t owner, int whichfork, xfs_fileoff_t startoff,
222		xfs_fsblock_t startblock, xfs_filblks_t blockcount,
223		xfs_exntst_t state, struct xfs_btree_cur **pcur);
224
225int xfs_rmap_find_left_neighbor(struct xfs_btree_cur *cur, xfs_agblock_t bno,
226		uint64_t owner, uint64_t offset, unsigned int flags,
227		struct xfs_rmap_irec *irec, int	*stat);
228int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
229		uint64_t owner, uint64_t offset, unsigned int flags,
230		struct xfs_rmap_irec *irec, int	*stat);
231int xfs_rmap_compare(const struct xfs_rmap_irec *a,
232		const struct xfs_rmap_irec *b);
233union xfs_btree_rec;
234int xfs_rmap_btrec_to_irec(union xfs_btree_rec *rec,
235		struct xfs_rmap_irec *irec);
236int xfs_rmap_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
237		xfs_extlen_t len, bool *exists);
238int xfs_rmap_record_exists(struct xfs_btree_cur *cur, xfs_agblock_t bno,
239		xfs_extlen_t len, struct xfs_owner_info *oinfo,
 
 
 
240		bool *has_rmap);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
242#endif	/* __XFS_RMAP_H__ */