Skip to content

Commit 6723ca9

Browse files
author
Chandan Babu R
committed
Merge tag 'expand-bmap-intent-usage_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC
xfs: support attrfork and unwritten BUIs In preparation for atomic extent swapping and the online repair functionality that wants atomic extent swaps, enhance the BUI code so that we can support deferred work on the extended attribute fork and on unwritten extents. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org> * tag 'expand-bmap-intent-usage_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux: xfs: xfs_bmap_finish_one should map unwritten extents properly xfs: support deferred bmap updates on the attr fork
2 parents 4e3f7e7 + 6c8127e commit 6723ca9

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6172,17 +6172,8 @@ xfs_bmap_split_extent(
61726172
return error;
61736173
}
61746174

6175-
/* Deferred mapping is only for real extents in the data fork. */
6176-
static bool
6177-
xfs_bmap_is_update_needed(
6178-
struct xfs_bmbt_irec *bmap)
6179-
{
6180-
return bmap->br_startblock != HOLESTARTBLOCK &&
6181-
bmap->br_startblock != DELAYSTARTBLOCK;
6182-
}
6183-
61846175
/* Record a bmap intent. */
6185-
static int
6176+
static inline void
61866177
__xfs_bmap_add(
61876178
struct xfs_trans *tp,
61886179
enum xfs_bmap_intent_type type,
@@ -6192,6 +6183,11 @@ __xfs_bmap_add(
61926183
{
61936184
struct xfs_bmap_intent *bi;
61946185

6186+
if ((whichfork != XFS_DATA_FORK && whichfork != XFS_ATTR_FORK) ||
6187+
bmap->br_startblock == HOLESTARTBLOCK ||
6188+
bmap->br_startblock == DELAYSTARTBLOCK)
6189+
return;
6190+
61956191
bi = kmem_cache_alloc(xfs_bmap_intent_cache, GFP_KERNEL | __GFP_NOFAIL);
61966192
INIT_LIST_HEAD(&bi->bi_list);
61976193
bi->bi_type = type;
@@ -6200,33 +6196,28 @@ __xfs_bmap_add(
62006196
bi->bi_bmap = *bmap;
62016197

62026198
xfs_bmap_defer_add(tp, bi);
6203-
return 0;
62046199
}
62056200

62066201
/* Map an extent into a file. */
62076202
void
62086203
xfs_bmap_map_extent(
62096204
struct xfs_trans *tp,
62106205
struct xfs_inode *ip,
6206+
int whichfork,
62116207
struct xfs_bmbt_irec *PREV)
62126208
{
6213-
if (!xfs_bmap_is_update_needed(PREV))
6214-
return;
6215-
6216-
__xfs_bmap_add(tp, XFS_BMAP_MAP, ip, XFS_DATA_FORK, PREV);
6209+
__xfs_bmap_add(tp, XFS_BMAP_MAP, ip, whichfork, PREV);
62176210
}
62186211

62196212
/* Unmap an extent out of a file. */
62206213
void
62216214
xfs_bmap_unmap_extent(
62226215
struct xfs_trans *tp,
62236216
struct xfs_inode *ip,
6217+
int whichfork,
62246218
struct xfs_bmbt_irec *PREV)
62256219
{
6226-
if (!xfs_bmap_is_update_needed(PREV))
6227-
return;
6228-
6229-
__xfs_bmap_add(tp, XFS_BMAP_UNMAP, ip, XFS_DATA_FORK, PREV);
6220+
__xfs_bmap_add(tp, XFS_BMAP_UNMAP, ip, whichfork, PREV);
62306221
}
62316222

62326223
/*
@@ -6240,29 +6231,31 @@ xfs_bmap_finish_one(
62406231
{
62416232
struct xfs_bmbt_irec *bmap = &bi->bi_bmap;
62426233
int error = 0;
6234+
int flags = 0;
6235+
6236+
if (bi->bi_whichfork == XFS_ATTR_FORK)
6237+
flags |= XFS_BMAPI_ATTRFORK;
62436238

62446239
ASSERT(tp->t_highest_agno == NULLAGNUMBER);
62456240

62466241
trace_xfs_bmap_deferred(bi);
62476242

6248-
if (WARN_ON_ONCE(bi->bi_whichfork != XFS_DATA_FORK)) {
6249-
xfs_bmap_mark_sick(bi->bi_owner, bi->bi_whichfork);
6250-
return -EFSCORRUPTED;
6251-
}
6252-
6253-
if (XFS_TEST_ERROR(false, tp->t_mountp,
6254-
XFS_ERRTAG_BMAP_FINISH_ONE))
6243+
if (XFS_TEST_ERROR(false, tp->t_mountp, XFS_ERRTAG_BMAP_FINISH_ONE))
62556244
return -EIO;
62566245

62576246
switch (bi->bi_type) {
62586247
case XFS_BMAP_MAP:
6248+
if (bi->bi_bmap.br_state == XFS_EXT_UNWRITTEN)
6249+
flags |= XFS_BMAPI_PREALLOC;
62596250
error = xfs_bmapi_remap(tp, bi->bi_owner, bmap->br_startoff,
6260-
bmap->br_blockcount, bmap->br_startblock, 0);
6251+
bmap->br_blockcount, bmap->br_startblock,
6252+
flags);
62616253
bmap->br_blockcount = 0;
62626254
break;
62636255
case XFS_BMAP_UNMAP:
62646256
error = __xfs_bunmapi(tp, bi->bi_owner, bmap->br_startoff,
6265-
&bmap->br_blockcount, XFS_BMAPI_REMAP, 1);
6257+
&bmap->br_blockcount, flags | XFS_BMAPI_REMAP,
6258+
1);
62666259
break;
62676260
default:
62686261
ASSERT(0);

fs/xfs/libxfs/xfs_bmap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ struct xfs_bmap_intent {
247247

248248
int xfs_bmap_finish_one(struct xfs_trans *tp, struct xfs_bmap_intent *bi);
249249
void xfs_bmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
250-
struct xfs_bmbt_irec *imap);
250+
int whichfork, struct xfs_bmbt_irec *imap);
251251
void xfs_bmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip,
252-
struct xfs_bmbt_irec *imap);
252+
int whichfork, struct xfs_bmbt_irec *imap);
253253

254254
static inline uint32_t xfs_bmap_fork_to_state(int whichfork)
255255
{

fs/xfs/xfs_bmap_util.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,16 +1305,16 @@ xfs_swap_extent_rmap(
13051305
}
13061306

13071307
/* Remove the mapping from the donor file. */
1308-
xfs_bmap_unmap_extent(tp, tip, &uirec);
1308+
xfs_bmap_unmap_extent(tp, tip, XFS_DATA_FORK, &uirec);
13091309

13101310
/* Remove the mapping from the source file. */
1311-
xfs_bmap_unmap_extent(tp, ip, &irec);
1311+
xfs_bmap_unmap_extent(tp, ip, XFS_DATA_FORK, &irec);
13121312

13131313
/* Map the donor file's blocks into the source file. */
1314-
xfs_bmap_map_extent(tp, ip, &uirec);
1314+
xfs_bmap_map_extent(tp, ip, XFS_DATA_FORK, &uirec);
13151315

13161316
/* Map the source file's blocks into the donor file. */
1317-
xfs_bmap_map_extent(tp, tip, &irec);
1317+
xfs_bmap_map_extent(tp, tip, XFS_DATA_FORK, &irec);
13181318

13191319
error = xfs_defer_finish(tpp);
13201320
tp = *tpp;

fs/xfs/xfs_reflink.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ xfs_reflink_end_cow_extent(
806806
* If the extent we're remapping is backed by storage (written
807807
* or not), unmap the extent and drop its refcount.
808808
*/
809-
xfs_bmap_unmap_extent(tp, ip, &data);
809+
xfs_bmap_unmap_extent(tp, ip, XFS_DATA_FORK, &data);
810810
xfs_refcount_decrease_extent(tp, &data);
811811
xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT,
812812
-data.br_blockcount);
@@ -830,7 +830,7 @@ xfs_reflink_end_cow_extent(
830830
xfs_refcount_free_cow_extent(tp, del.br_startblock, del.br_blockcount);
831831

832832
/* Map the new blocks into the data fork. */
833-
xfs_bmap_map_extent(tp, ip, &del);
833+
xfs_bmap_map_extent(tp, ip, XFS_DATA_FORK, &del);
834834

835835
/* Charge this new data fork mapping to the on-disk quota. */
836836
xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_DELBCOUNT,
@@ -1294,7 +1294,7 @@ xfs_reflink_remap_extent(
12941294
* If the extent we're unmapping is backed by storage (written
12951295
* or not), unmap the extent and drop its refcount.
12961296
*/
1297-
xfs_bmap_unmap_extent(tp, ip, &smap);
1297+
xfs_bmap_unmap_extent(tp, ip, XFS_DATA_FORK, &smap);
12981298
xfs_refcount_decrease_extent(tp, &smap);
12991299
qdelta -= smap.br_blockcount;
13001300
} else if (smap.br_startblock == DELAYSTARTBLOCK) {
@@ -1319,7 +1319,7 @@ xfs_reflink_remap_extent(
13191319
*/
13201320
if (dmap_written) {
13211321
xfs_refcount_increase_extent(tp, dmap);
1322-
xfs_bmap_map_extent(tp, ip, dmap);
1322+
xfs_bmap_map_extent(tp, ip, XFS_DATA_FORK, dmap);
13231323
qdelta += dmap->br_blockcount;
13241324
}
13251325

0 commit comments

Comments
 (0)