.. | .. |
---|
9 | 9 | #include "xfs_format.h" |
---|
10 | 10 | #include "xfs_log_format.h" |
---|
11 | 11 | #include "xfs_trans_resv.h" |
---|
12 | | -#include "xfs_sb.h" |
---|
13 | 12 | #include "xfs_mount.h" |
---|
14 | | -#include "xfs_defer.h" |
---|
15 | 13 | #include "xfs_inode.h" |
---|
16 | 14 | #include "xfs_trans.h" |
---|
17 | | -#include "xfs_error.h" |
---|
18 | 15 | #include "xfs_btree.h" |
---|
19 | 16 | #include "xfs_rmap_btree.h" |
---|
20 | 17 | #include "xfs_trace.h" |
---|
21 | | -#include "xfs_log.h" |
---|
22 | 18 | #include "xfs_rmap.h" |
---|
23 | 19 | #include "xfs_alloc.h" |
---|
24 | 20 | #include "xfs_bit.h" |
---|
.. | .. |
---|
30 | 26 | #include "xfs_rtalloc.h" |
---|
31 | 27 | |
---|
32 | 28 | /* Convert an xfs_fsmap to an fsmap. */ |
---|
33 | | -void |
---|
| 29 | +static void |
---|
34 | 30 | xfs_fsmap_from_internal( |
---|
35 | 31 | struct fsmap *dest, |
---|
36 | 32 | struct xfs_fsmap *src) |
---|
.. | .. |
---|
150 | 146 | dest->fmr_owner = XFS_FMR_OWN_FREE; |
---|
151 | 147 | break; |
---|
152 | 148 | default: |
---|
| 149 | + ASSERT(0); |
---|
153 | 150 | return -EFSCORRUPTED; |
---|
154 | 151 | } |
---|
155 | 152 | return 0; |
---|
.. | .. |
---|
158 | 155 | /* getfsmap query state */ |
---|
159 | 156 | struct xfs_getfsmap_info { |
---|
160 | 157 | struct xfs_fsmap_head *head; |
---|
161 | | - xfs_fsmap_format_t formatter; /* formatting fn */ |
---|
162 | | - void *format_arg; /* format buffer */ |
---|
| 158 | + struct fsmap *fsmap_recs; /* mapping records */ |
---|
163 | 159 | struct xfs_buf *agf_bp; /* AGF, for refcount queries */ |
---|
164 | 160 | xfs_daddr_t next_daddr; /* next daddr we expect */ |
---|
165 | 161 | u64 missing_owner; /* owner of holes */ |
---|
.. | .. |
---|
227 | 223 | return 0; |
---|
228 | 224 | } |
---|
229 | 225 | |
---|
| 226 | +static inline void |
---|
| 227 | +xfs_getfsmap_format( |
---|
| 228 | + struct xfs_mount *mp, |
---|
| 229 | + struct xfs_fsmap *xfm, |
---|
| 230 | + struct xfs_getfsmap_info *info) |
---|
| 231 | +{ |
---|
| 232 | + struct fsmap *rec; |
---|
| 233 | + |
---|
| 234 | + trace_xfs_getfsmap_mapping(mp, xfm); |
---|
| 235 | + |
---|
| 236 | + rec = &info->fsmap_recs[info->head->fmh_entries++]; |
---|
| 237 | + xfs_fsmap_from_internal(rec, xfm); |
---|
| 238 | +} |
---|
| 239 | + |
---|
230 | 240 | /* |
---|
231 | 241 | * Format a reverse mapping for getfsmap, having translated rm_startblock |
---|
232 | 242 | * into the appropriate daddr units. |
---|
.. | .. |
---|
254 | 264 | rec_daddr += XFS_FSB_TO_BB(mp, rec->rm_blockcount); |
---|
255 | 265 | if (info->next_daddr < rec_daddr) |
---|
256 | 266 | info->next_daddr = rec_daddr; |
---|
257 | | - return XFS_BTREE_QUERY_RANGE_CONTINUE; |
---|
| 267 | + return 0; |
---|
258 | 268 | } |
---|
259 | 269 | |
---|
260 | 270 | /* Are we just counting mappings? */ |
---|
.. | .. |
---|
266 | 276 | info->head->fmh_entries++; |
---|
267 | 277 | |
---|
268 | 278 | if (info->last) |
---|
269 | | - return XFS_BTREE_QUERY_RANGE_CONTINUE; |
---|
| 279 | + return 0; |
---|
270 | 280 | |
---|
271 | 281 | info->head->fmh_entries++; |
---|
272 | 282 | |
---|
273 | 283 | rec_daddr += XFS_FSB_TO_BB(mp, rec->rm_blockcount); |
---|
274 | 284 | if (info->next_daddr < rec_daddr) |
---|
275 | 285 | info->next_daddr = rec_daddr; |
---|
276 | | - return XFS_BTREE_QUERY_RANGE_CONTINUE; |
---|
| 286 | + return 0; |
---|
277 | 287 | } |
---|
278 | 288 | |
---|
279 | 289 | /* |
---|
.. | .. |
---|
283 | 293 | */ |
---|
284 | 294 | if (rec_daddr > info->next_daddr) { |
---|
285 | 295 | if (info->head->fmh_entries >= info->head->fmh_count) |
---|
286 | | - return XFS_BTREE_QUERY_RANGE_ABORT; |
---|
| 296 | + return -ECANCELED; |
---|
287 | 297 | |
---|
288 | 298 | fmr.fmr_device = info->dev; |
---|
289 | 299 | fmr.fmr_physical = info->next_daddr; |
---|
.. | .. |
---|
291 | 301 | fmr.fmr_offset = 0; |
---|
292 | 302 | fmr.fmr_length = rec_daddr - info->next_daddr; |
---|
293 | 303 | fmr.fmr_flags = FMR_OF_SPECIAL_OWNER; |
---|
294 | | - error = info->formatter(&fmr, info->format_arg); |
---|
295 | | - if (error) |
---|
296 | | - return error; |
---|
297 | | - info->head->fmh_entries++; |
---|
| 304 | + xfs_getfsmap_format(mp, &fmr, info); |
---|
298 | 305 | } |
---|
299 | 306 | |
---|
300 | 307 | if (info->last) |
---|
.. | .. |
---|
302 | 309 | |
---|
303 | 310 | /* Fill out the extent we found */ |
---|
304 | 311 | if (info->head->fmh_entries >= info->head->fmh_count) |
---|
305 | | - return XFS_BTREE_QUERY_RANGE_ABORT; |
---|
| 312 | + return -ECANCELED; |
---|
306 | 313 | |
---|
307 | 314 | trace_xfs_fsmap_mapping(mp, info->dev, info->agno, rec); |
---|
308 | 315 | |
---|
.. | .. |
---|
326 | 333 | if (shared) |
---|
327 | 334 | fmr.fmr_flags |= FMR_OF_SHARED; |
---|
328 | 335 | } |
---|
329 | | - error = info->formatter(&fmr, info->format_arg); |
---|
330 | | - if (error) |
---|
331 | | - return error; |
---|
332 | | - info->head->fmh_entries++; |
---|
333 | 336 | |
---|
| 337 | + xfs_getfsmap_format(mp, &fmr, info); |
---|
334 | 338 | out: |
---|
335 | 339 | rec_daddr += XFS_FSB_TO_BB(mp, rec->rm_blockcount); |
---|
336 | 340 | if (info->next_daddr < rec_daddr) |
---|
337 | 341 | info->next_daddr = rec_daddr; |
---|
338 | | - return XFS_BTREE_QUERY_RANGE_CONTINUE; |
---|
| 342 | + return 0; |
---|
339 | 343 | } |
---|
340 | 344 | |
---|
341 | 345 | /* Transform a rmapbt irec into a fsmap */ |
---|
.. | .. |
---|
350 | 354 | xfs_fsblock_t fsb; |
---|
351 | 355 | xfs_daddr_t rec_daddr; |
---|
352 | 356 | |
---|
353 | | - fsb = XFS_AGB_TO_FSB(mp, cur->bc_private.a.agno, rec->rm_startblock); |
---|
| 357 | + fsb = XFS_AGB_TO_FSB(mp, cur->bc_ag.agno, rec->rm_startblock); |
---|
354 | 358 | rec_daddr = XFS_FSB_TO_DADDR(mp, fsb); |
---|
355 | 359 | |
---|
356 | 360 | return xfs_getfsmap_helper(cur->bc_tp, info, rec, rec_daddr); |
---|
.. | .. |
---|
368 | 372 | struct xfs_rmap_irec irec; |
---|
369 | 373 | xfs_daddr_t rec_daddr; |
---|
370 | 374 | |
---|
371 | | - rec_daddr = XFS_AGB_TO_DADDR(mp, cur->bc_private.a.agno, |
---|
| 375 | + rec_daddr = XFS_AGB_TO_DADDR(mp, cur->bc_ag.agno, |
---|
372 | 376 | rec->ar_startblock); |
---|
373 | 377 | |
---|
374 | 378 | irec.rm_startblock = rec->ar_startblock; |
---|
.. | .. |
---|
798 | 802 | #endif /* CONFIG_XFS_RT */ |
---|
799 | 803 | |
---|
800 | 804 | /* |
---|
801 | | - * Get filesystem's extents as described in head, and format for |
---|
802 | | - * output. Calls formatter to fill the user's buffer until all |
---|
803 | | - * extents are mapped, until the passed-in head->fmh_count slots have |
---|
804 | | - * been filled, or until the formatter short-circuits the loop, if it |
---|
805 | | - * is tracking filled-in extents on its own. |
---|
| 805 | + * Get filesystem's extents as described in head, and format for output. Fills |
---|
| 806 | + * in the supplied records array until there are no more reverse mappings to |
---|
| 807 | + * return or head.fmh_entries == head.fmh_count. In the second case, this |
---|
| 808 | + * function returns -ECANCELED to indicate that more records would have been |
---|
| 809 | + * returned. |
---|
806 | 810 | * |
---|
807 | 811 | * Key to Confusion |
---|
808 | 812 | * ---------------- |
---|
.. | .. |
---|
822 | 826 | xfs_getfsmap( |
---|
823 | 827 | struct xfs_mount *mp, |
---|
824 | 828 | struct xfs_fsmap_head *head, |
---|
825 | | - xfs_fsmap_format_t formatter, |
---|
826 | | - void *arg) |
---|
| 829 | + struct fsmap *fsmap_recs) |
---|
827 | 830 | { |
---|
828 | 831 | struct xfs_trans *tp = NULL; |
---|
829 | 832 | struct xfs_fsmap dkeys[2]; /* per-dev keys */ |
---|
.. | .. |
---|
898 | 901 | |
---|
899 | 902 | info.next_daddr = head->fmh_keys[0].fmr_physical + |
---|
900 | 903 | head->fmh_keys[0].fmr_length; |
---|
901 | | - info.formatter = formatter; |
---|
902 | | - info.format_arg = arg; |
---|
| 904 | + info.fsmap_recs = fsmap_recs; |
---|
903 | 905 | info.head = head; |
---|
| 906 | + |
---|
| 907 | + /* |
---|
| 908 | + * If fsmap runs concurrently with a scrub, the freeze can be delayed |
---|
| 909 | + * indefinitely as we walk the rmapbt and iterate over metadata |
---|
| 910 | + * buffers. Freeze quiesces the log (which waits for the buffer LRU to |
---|
| 911 | + * be emptied) and that won't happen while we're reading buffers. |
---|
| 912 | + */ |
---|
| 913 | + sb_start_write(mp->m_super); |
---|
904 | 914 | |
---|
905 | 915 | /* For each device we support... */ |
---|
906 | 916 | for (i = 0; i < XFS_GETFSMAP_DEVS; i++) { |
---|
.. | .. |
---|
941 | 951 | |
---|
942 | 952 | if (tp) |
---|
943 | 953 | xfs_trans_cancel(tp); |
---|
| 954 | + sb_end_write(mp->m_super); |
---|
944 | 955 | head->fmh_oflags = FMH_OF_DEV_T; |
---|
945 | 956 | return error; |
---|
946 | 957 | } |
---|