1 // SPDX-License-Identifier: GPL-2.0+ 1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 2 /* 3 * Copyright (C) 2016 Oracle. All Rights Rese 3 * Copyright (C) 2016 Oracle. All Rights Reserved. 4 * Author: Darrick J. Wong <darrick.wong@oracl 4 * Author: Darrick J. Wong <darrick.wong@oracle.com> 5 */ 5 */ 6 #ifndef __XFS_RMAP_H__ 6 #ifndef __XFS_RMAP_H__ 7 #define __XFS_RMAP_H__ 7 #define __XFS_RMAP_H__ 8 8 9 struct xfs_perag; 9 struct xfs_perag; 10 10 11 static inline void 11 static inline void 12 xfs_rmap_ino_bmbt_owner( 12 xfs_rmap_ino_bmbt_owner( 13 struct xfs_owner_info *oi, 13 struct xfs_owner_info *oi, 14 xfs_ino_t ino, 14 xfs_ino_t ino, 15 int whichfork) 15 int whichfork) 16 { 16 { 17 oi->oi_owner = ino; 17 oi->oi_owner = ino; 18 oi->oi_offset = 0; 18 oi->oi_offset = 0; 19 oi->oi_flags = XFS_OWNER_INFO_BMBT_BLO 19 oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK; 20 if (whichfork == XFS_ATTR_FORK) 20 if (whichfork == XFS_ATTR_FORK) 21 oi->oi_flags |= XFS_OWNER_INFO 21 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK; 22 } 22 } 23 23 24 static inline void 24 static inline void 25 xfs_rmap_ino_owner( 25 xfs_rmap_ino_owner( 26 struct xfs_owner_info *oi, 26 struct xfs_owner_info *oi, 27 xfs_ino_t ino, 27 xfs_ino_t ino, 28 int whichfork, 28 int whichfork, 29 xfs_fileoff_t offset) 29 xfs_fileoff_t offset) 30 { 30 { 31 oi->oi_owner = ino; 31 oi->oi_owner = ino; 32 oi->oi_offset = offset; 32 oi->oi_offset = offset; 33 oi->oi_flags = 0; 33 oi->oi_flags = 0; 34 if (whichfork == XFS_ATTR_FORK) 34 if (whichfork == XFS_ATTR_FORK) 35 oi->oi_flags |= XFS_OWNER_INFO 35 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK; 36 } 36 } 37 37 38 static inline bool 38 static inline bool 39 xfs_rmap_should_skip_owner_update( 39 xfs_rmap_should_skip_owner_update( 40 const struct xfs_owner_info *oi) 40 const struct xfs_owner_info *oi) 41 { 41 { 42 return oi->oi_owner == XFS_RMAP_OWN_NU 42 return oi->oi_owner == XFS_RMAP_OWN_NULL; 43 } 43 } 44 44 45 /* Reverse mapping functions. */ 45 /* Reverse mapping functions. */ 46 46 47 struct xfs_buf; 47 struct xfs_buf; 48 48 49 static inline __u64 49 static inline __u64 50 xfs_rmap_irec_offset_pack( 50 xfs_rmap_irec_offset_pack( 51 const struct xfs_rmap_irec *irec) 51 const struct xfs_rmap_irec *irec) 52 { 52 { 53 __u64 x; 53 __u64 x; 54 54 55 x = XFS_RMAP_OFF(irec->rm_offset); 55 x = XFS_RMAP_OFF(irec->rm_offset); 56 if (irec->rm_flags & XFS_RMAP_ATTR_FOR 56 if (irec->rm_flags & XFS_RMAP_ATTR_FORK) 57 x |= XFS_RMAP_OFF_ATTR_FORK; 57 x |= XFS_RMAP_OFF_ATTR_FORK; 58 if (irec->rm_flags & XFS_RMAP_BMBT_BLO 58 if (irec->rm_flags & XFS_RMAP_BMBT_BLOCK) 59 x |= XFS_RMAP_OFF_BMBT_BLOCK; 59 x |= XFS_RMAP_OFF_BMBT_BLOCK; 60 if (irec->rm_flags & XFS_RMAP_UNWRITTE 60 if (irec->rm_flags & XFS_RMAP_UNWRITTEN) 61 x |= XFS_RMAP_OFF_UNWRITTEN; 61 x |= XFS_RMAP_OFF_UNWRITTEN; 62 return x; 62 return x; 63 } 63 } 64 64 65 static inline xfs_failaddr_t 65 static inline xfs_failaddr_t 66 xfs_rmap_irec_offset_unpack( 66 xfs_rmap_irec_offset_unpack( 67 __u64 offset, 67 __u64 offset, 68 struct xfs_rmap_irec *irec) 68 struct xfs_rmap_irec *irec) 69 { 69 { 70 if (offset & ~(XFS_RMAP_OFF_MASK | XFS 70 if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS)) 71 return __this_address; 71 return __this_address; 72 72 73 irec->rm_offset = XFS_RMAP_OFF(offset) 73 irec->rm_offset = XFS_RMAP_OFF(offset); 74 irec->rm_flags = 0; 74 irec->rm_flags = 0; 75 if (offset & XFS_RMAP_OFF_ATTR_FORK) 75 if (offset & XFS_RMAP_OFF_ATTR_FORK) 76 irec->rm_flags |= XFS_RMAP_ATT 76 irec->rm_flags |= XFS_RMAP_ATTR_FORK; 77 if (offset & XFS_RMAP_OFF_BMBT_BLOCK) 77 if (offset & XFS_RMAP_OFF_BMBT_BLOCK) 78 irec->rm_flags |= XFS_RMAP_BMB 78 irec->rm_flags |= XFS_RMAP_BMBT_BLOCK; 79 if (offset & XFS_RMAP_OFF_UNWRITTEN) 79 if (offset & XFS_RMAP_OFF_UNWRITTEN) 80 irec->rm_flags |= XFS_RMAP_UNW 80 irec->rm_flags |= XFS_RMAP_UNWRITTEN; 81 return NULL; 81 return NULL; 82 } 82 } 83 83 84 static inline void 84 static inline void 85 xfs_owner_info_unpack( 85 xfs_owner_info_unpack( 86 const struct xfs_owner_info *oinfo 86 const struct xfs_owner_info *oinfo, 87 uint64_t *owner 87 uint64_t *owner, 88 uint64_t *offse 88 uint64_t *offset, 89 unsigned int *flags 89 unsigned int *flags) 90 { 90 { 91 unsigned int r = 0; 91 unsigned int r = 0; 92 92 93 *owner = oinfo->oi_owner; 93 *owner = oinfo->oi_owner; 94 *offset = oinfo->oi_offset; 94 *offset = oinfo->oi_offset; 95 if (oinfo->oi_flags & XFS_OWNER_INFO_A 95 if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK) 96 r |= XFS_RMAP_ATTR_FORK; 96 r |= XFS_RMAP_ATTR_FORK; 97 if (oinfo->oi_flags & XFS_OWNER_INFO_B 97 if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK) 98 r |= XFS_RMAP_BMBT_BLOCK; 98 r |= XFS_RMAP_BMBT_BLOCK; 99 *flags = r; 99 *flags = r; 100 } 100 } 101 101 102 static inline void 102 static inline void 103 xfs_owner_info_pack( 103 xfs_owner_info_pack( 104 struct xfs_owner_info *oinfo, 104 struct xfs_owner_info *oinfo, 105 uint64_t owner, 105 uint64_t owner, 106 uint64_t offset, 106 uint64_t offset, 107 unsigned int flags) 107 unsigned int flags) 108 { 108 { 109 oinfo->oi_owner = owner; 109 oinfo->oi_owner = owner; 110 oinfo->oi_offset = XFS_RMAP_OFF(offset 110 oinfo->oi_offset = XFS_RMAP_OFF(offset); 111 oinfo->oi_flags = 0; 111 oinfo->oi_flags = 0; 112 if (flags & XFS_RMAP_ATTR_FORK) 112 if (flags & XFS_RMAP_ATTR_FORK) 113 oinfo->oi_flags |= XFS_OWNER_I 113 oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK; 114 if (flags & XFS_RMAP_BMBT_BLOCK) 114 if (flags & XFS_RMAP_BMBT_BLOCK) 115 oinfo->oi_flags |= XFS_OWNER_I 115 oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK; 116 } 116 } 117 117 118 int xfs_rmap_alloc(struct xfs_trans *tp, struc 118 int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp, 119 struct xfs_perag *pag, xfs_ 119 struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len, 120 const struct xfs_owner_info 120 const struct xfs_owner_info *oinfo); 121 int xfs_rmap_free(struct xfs_trans *tp, struct 121 int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp, 122 struct xfs_perag *pag, xfs_a 122 struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len, 123 const struct xfs_owner_info 123 const struct xfs_owner_info *oinfo); 124 124 125 int xfs_rmap_lookup_le(struct xfs_btree_cur *c 125 int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno, 126 uint64_t owner, uint64_t offse 126 uint64_t owner, uint64_t offset, unsigned int flags, 127 struct xfs_rmap_irec *irec, in 127 struct xfs_rmap_irec *irec, int *stat); 128 int xfs_rmap_lookup_eq(struct xfs_btree_cur *c 128 int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno, 129 xfs_extlen_t len, uint64_t own 129 xfs_extlen_t len, uint64_t owner, uint64_t offset, 130 unsigned int flags, int *stat) 130 unsigned int flags, int *stat); 131 int xfs_rmap_insert(struct xfs_btree_cur *rcur 131 int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno, 132 xfs_extlen_t len, uint64_t own 132 xfs_extlen_t len, uint64_t owner, uint64_t offset, 133 unsigned int flags); 133 unsigned int flags); 134 int xfs_rmap_get_rec(struct xfs_btree_cur *cur 134 int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec, 135 int *stat); 135 int *stat); 136 136 137 typedef int (*xfs_rmap_query_range_fn)( 137 typedef int (*xfs_rmap_query_range_fn)( 138 struct xfs_btree_cur *cur, 138 struct xfs_btree_cur *cur, 139 const struct xfs_rmap_irec *rec, 139 const struct xfs_rmap_irec *rec, 140 void *priv) 140 void *priv); 141 141 142 int xfs_rmap_query_range(struct xfs_btree_cur 142 int xfs_rmap_query_range(struct xfs_btree_cur *cur, 143 const struct xfs_rmap_irec *lo 143 const struct xfs_rmap_irec *low_rec, 144 const struct xfs_rmap_irec *hi 144 const struct xfs_rmap_irec *high_rec, 145 xfs_rmap_query_range_fn fn, vo 145 xfs_rmap_query_range_fn fn, void *priv); 146 int xfs_rmap_query_all(struct xfs_btree_cur *c 146 int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn, 147 void *priv); 147 void *priv); 148 148 149 enum xfs_rmap_intent_type { 149 enum xfs_rmap_intent_type { 150 XFS_RMAP_MAP, 150 XFS_RMAP_MAP, 151 XFS_RMAP_MAP_SHARED, 151 XFS_RMAP_MAP_SHARED, 152 XFS_RMAP_UNMAP, 152 XFS_RMAP_UNMAP, 153 XFS_RMAP_UNMAP_SHARED, 153 XFS_RMAP_UNMAP_SHARED, 154 XFS_RMAP_CONVERT, 154 XFS_RMAP_CONVERT, 155 XFS_RMAP_CONVERT_SHARED, 155 XFS_RMAP_CONVERT_SHARED, 156 XFS_RMAP_ALLOC, 156 XFS_RMAP_ALLOC, 157 XFS_RMAP_FREE, 157 XFS_RMAP_FREE, 158 }; 158 }; 159 159 160 #define XFS_RMAP_INTENT_STRINGS \ 160 #define XFS_RMAP_INTENT_STRINGS \ 161 { XFS_RMAP_MAP, "map" 161 { XFS_RMAP_MAP, "map" }, \ 162 { XFS_RMAP_MAP_SHARED, "map_s 162 { XFS_RMAP_MAP_SHARED, "map_shared" }, \ 163 { XFS_RMAP_UNMAP, "unmap 163 { XFS_RMAP_UNMAP, "unmap" }, \ 164 { XFS_RMAP_UNMAP_SHARED, "unmap 164 { XFS_RMAP_UNMAP_SHARED, "unmap_shared" }, \ 165 { XFS_RMAP_CONVERT, "cvt" 165 { XFS_RMAP_CONVERT, "cvt" }, \ 166 { XFS_RMAP_CONVERT_SHARED, "cvt_s 166 { XFS_RMAP_CONVERT_SHARED, "cvt_shared" }, \ 167 { XFS_RMAP_ALLOC, "alloc 167 { XFS_RMAP_ALLOC, "alloc" }, \ 168 { XFS_RMAP_FREE, "free" 168 { XFS_RMAP_FREE, "free" } 169 169 170 struct xfs_rmap_intent { 170 struct xfs_rmap_intent { 171 struct list_head 171 struct list_head ri_list; 172 enum xfs_rmap_intent_type 172 enum xfs_rmap_intent_type ri_type; 173 int 173 int ri_whichfork; 174 uint64_t 174 uint64_t ri_owner; 175 struct xfs_bmbt_irec 175 struct xfs_bmbt_irec ri_bmap; 176 struct xfs_perag 176 struct xfs_perag *ri_pag; 177 }; 177 }; 178 178 179 /* functions for updating the rmapbt based on 179 /* functions for updating the rmapbt based on bmbt map/unmap operations */ 180 void xfs_rmap_map_extent(struct xfs_trans *tp, 180 void xfs_rmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip, 181 int whichfork, struct xfs_bmbt 181 int whichfork, struct xfs_bmbt_irec *imap); 182 void xfs_rmap_unmap_extent(struct xfs_trans *t 182 void xfs_rmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip, 183 int whichfork, struct xfs_bmbt 183 int whichfork, struct xfs_bmbt_irec *imap); 184 void xfs_rmap_convert_extent(struct xfs_mount 184 void xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_trans *tp, 185 struct xfs_inode *ip, int whic 185 struct xfs_inode *ip, int whichfork, 186 struct xfs_bmbt_irec *imap); 186 struct xfs_bmbt_irec *imap); 187 void xfs_rmap_alloc_extent(struct xfs_trans *t 187 void xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_agnumber_t agno, 188 xfs_agblock_t bno, xfs_extlen_ 188 xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner); 189 void xfs_rmap_free_extent(struct xfs_trans *tp 189 void xfs_rmap_free_extent(struct xfs_trans *tp, xfs_agnumber_t agno, 190 xfs_agblock_t bno, xfs_extlen_ 190 xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner); 191 191 192 int xfs_rmap_finish_one(struct xfs_trans *tp, 192 int xfs_rmap_finish_one(struct xfs_trans *tp, struct xfs_rmap_intent *ri, 193 struct xfs_btree_cur **pcur); 193 struct xfs_btree_cur **pcur); 194 int __xfs_rmap_finish_intent(struct xfs_btree_ 194 int __xfs_rmap_finish_intent(struct xfs_btree_cur *rcur, 195 enum xfs_rmap_intent_type op, 195 enum xfs_rmap_intent_type op, xfs_agblock_t bno, 196 xfs_extlen_t len, const struct 196 xfs_extlen_t len, const struct xfs_owner_info *oinfo, 197 bool unwritten); 197 bool unwritten); 198 198 199 int xfs_rmap_lookup_le_range(struct xfs_btree_ 199 int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno, 200 uint64_t owner, uint64_t offse 200 uint64_t owner, uint64_t offset, unsigned int flags, 201 struct xfs_rmap_irec *irec, in 201 struct xfs_rmap_irec *irec, int *stat); 202 int xfs_rmap_compare(const struct xfs_rmap_ire 202 int xfs_rmap_compare(const struct xfs_rmap_irec *a, 203 const struct xfs_rmap_irec *b) 203 const struct xfs_rmap_irec *b); 204 union xfs_btree_rec; 204 union xfs_btree_rec; 205 xfs_failaddr_t xfs_rmap_btrec_to_irec(const un 205 xfs_failaddr_t xfs_rmap_btrec_to_irec(const union xfs_btree_rec *rec, 206 struct xfs_rmap_irec *irec); 206 struct xfs_rmap_irec *irec); 207 xfs_failaddr_t xfs_rmap_check_irec(struct xfs_ 207 xfs_failaddr_t xfs_rmap_check_irec(struct xfs_perag *pag, 208 const struct xfs_rmap_irec *ir 208 const struct xfs_rmap_irec *irec); 209 209 210 int xfs_rmap_has_records(struct xfs_btree_cur 210 int xfs_rmap_has_records(struct xfs_btree_cur *cur, xfs_agblock_t bno, 211 xfs_extlen_t len, enum xbtree_ 211 xfs_extlen_t len, enum xbtree_recpacking *outcome); 212 212 213 struct xfs_rmap_matches { 213 struct xfs_rmap_matches { 214 /* Number of owner matches. */ 214 /* Number of owner matches. */ 215 unsigned long long matches; 215 unsigned long long matches; 216 216 217 /* Number of non-owner matches. */ 217 /* Number of non-owner matches. */ 218 unsigned long long non_owner_matc 218 unsigned long long non_owner_matches; 219 219 220 /* Number of non-owner matches that co 220 /* Number of non-owner matches that conflict with the owner matches. */ 221 unsigned long long bad_non_owner_ 221 unsigned long long bad_non_owner_matches; 222 }; 222 }; 223 223 224 int xfs_rmap_count_owners(struct xfs_btree_cur 224 int xfs_rmap_count_owners(struct xfs_btree_cur *cur, xfs_agblock_t bno, 225 xfs_extlen_t len, const struct 225 xfs_extlen_t len, const struct xfs_owner_info *oinfo, 226 struct xfs_rmap_matches *rmatc 226 struct xfs_rmap_matches *rmatch); 227 int xfs_rmap_has_other_keys(struct xfs_btree_c 227 int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno, 228 xfs_extlen_t len, const struct 228 xfs_extlen_t len, const struct xfs_owner_info *oinfo, 229 bool *has_other); 229 bool *has_other); 230 int xfs_rmap_map_raw(struct xfs_btree_cur *cur 230 int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap); 231 231 232 extern const struct xfs_owner_info XFS_RMAP_OI 232 extern const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE; 233 extern const struct xfs_owner_info XFS_RMAP_OI 233 extern const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER; 234 extern const struct xfs_owner_info XFS_RMAP_OI 234 extern const struct xfs_owner_info XFS_RMAP_OINFO_FS; 235 extern const struct xfs_owner_info XFS_RMAP_OI 235 extern const struct xfs_owner_info XFS_RMAP_OINFO_LOG; 236 extern const struct xfs_owner_info XFS_RMAP_OI 236 extern const struct xfs_owner_info XFS_RMAP_OINFO_AG; 237 extern const struct xfs_owner_info XFS_RMAP_OI 237 extern const struct xfs_owner_info XFS_RMAP_OINFO_INOBT; 238 extern const struct xfs_owner_info XFS_RMAP_OI 238 extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES; 239 extern const struct xfs_owner_info XFS_RMAP_OI 239 extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC; 240 extern const struct xfs_owner_info XFS_RMAP_OI 240 extern const struct xfs_owner_info XFS_RMAP_OINFO_COW; 241 241 242 extern struct kmem_cache *xfs_rmap_inte 242 extern struct kmem_cache *xfs_rmap_intent_cache; 243 243 244 int __init xfs_rmap_intent_init_cache(void); 244 int __init xfs_rmap_intent_init_cache(void); 245 void xfs_rmap_intent_destroy_cache(void); 245 void xfs_rmap_intent_destroy_cache(void); 246 246 247 /* 247 /* 248 * Parameters for tracking reverse mapping cha 248 * Parameters for tracking reverse mapping changes. The hook function arg 249 * parameter is enum xfs_rmap_intent_type, and 249 * parameter is enum xfs_rmap_intent_type, and the rest is below. 250 */ 250 */ 251 struct xfs_rmap_update_params { 251 struct xfs_rmap_update_params { 252 xfs_agblock_t startb 252 xfs_agblock_t startblock; 253 xfs_extlen_t blockc 253 xfs_extlen_t blockcount; 254 struct xfs_owner_info oinfo; 254 struct xfs_owner_info oinfo; 255 bool unwrit 255 bool unwritten; 256 }; 256 }; 257 257 258 #ifdef CONFIG_XFS_LIVE_HOOKS 258 #ifdef CONFIG_XFS_LIVE_HOOKS 259 259 260 struct xfs_rmap_hook { 260 struct xfs_rmap_hook { 261 struct xfs_hook rmap_h 261 struct xfs_hook rmap_hook; 262 }; 262 }; 263 263 264 void xfs_rmap_hook_disable(void); 264 void xfs_rmap_hook_disable(void); 265 void xfs_rmap_hook_enable(void); 265 void xfs_rmap_hook_enable(void); 266 266 267 int xfs_rmap_hook_add(struct xfs_perag *pag, s 267 int xfs_rmap_hook_add(struct xfs_perag *pag, struct xfs_rmap_hook *hook); 268 void xfs_rmap_hook_del(struct xfs_perag *pag, 268 void xfs_rmap_hook_del(struct xfs_perag *pag, struct xfs_rmap_hook *hook); 269 void xfs_rmap_hook_setup(struct xfs_rmap_hook 269 void xfs_rmap_hook_setup(struct xfs_rmap_hook *hook, notifier_fn_t mod_fn); 270 #endif 270 #endif 271 271 272 #endif /* __XFS_RMAP_H__ */ 272 #endif /* __XFS_RMAP_H__ */ 273 273
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.