Skip to content

Commit 10ea615

Browse files
author
Chandan Babu R
committed
Merge tag 'bmap-intent-cleanups-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC
xfs: bmap log intent cleanups The next major target of online repair are metadata that are persisted in blocks mapped by a file fork. In other words, we want to repair directories, extended attributes, symbolic links, and the realtime free space information. For file-based metadata, we assume that the space metadata is correct, which enables repair to construct new versions of the metadata in a temporary file. We then need to swap the file fork mappings of the two files atomically. With this patchset, we begin constructing such a facility based on the existing bmap log items and a new extent swap log item. This series cleans up a few parts of the file block mapping log intent code before we start adding support for realtime bmap intents. Most of it involves cleaning up tracepoints so that more of the data extraction logic ends up in the tracepoint code and not the tracepoint call site, which should reduce overhead further when tracepoints are disabled. There is also a change to pass bmap intents all the way back to the bmap code instead of unboxing the intent values and re-boxing them after the _finish_one function completes. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org> * tag 'bmap-intent-cleanups-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux: xfs: add a xattr_entry helper xfs: move xfs_bmap_defer_add to xfs_bmap_item.c xfs: reuse xfs_bmap_update_cancel_item xfs: add a bi_entry helper xfs: remove xfs_trans_set_bmap_flags xfs: clean up bmap log intent item tracepoint callsites xfs: split tracepoint classes for deferred items
2 parents 74acb70 + c75f1a2 commit 10ea615

File tree

7 files changed

+226
-158
lines changed

7 files changed

+226
-158
lines changed

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "xfs_icache.h"
3838
#include "xfs_iomap.h"
3939
#include "xfs_health.h"
40+
#include "xfs_bmap_item.h"
4041

4142
struct kmem_cache *xfs_bmap_intent_cache;
4243

@@ -6191,24 +6192,14 @@ __xfs_bmap_add(
61916192
{
61926193
struct xfs_bmap_intent *bi;
61936194

6194-
trace_xfs_bmap_defer(tp->t_mountp,
6195-
XFS_FSB_TO_AGNO(tp->t_mountp, bmap->br_startblock),
6196-
type,
6197-
XFS_FSB_TO_AGBNO(tp->t_mountp, bmap->br_startblock),
6198-
ip->i_ino, whichfork,
6199-
bmap->br_startoff,
6200-
bmap->br_blockcount,
6201-
bmap->br_state);
6202-
62036195
bi = kmem_cache_alloc(xfs_bmap_intent_cache, GFP_KERNEL | __GFP_NOFAIL);
62046196
INIT_LIST_HEAD(&bi->bi_list);
62056197
bi->bi_type = type;
62066198
bi->bi_owner = ip;
62076199
bi->bi_whichfork = whichfork;
62086200
bi->bi_bmap = *bmap;
62096201

6210-
xfs_bmap_update_get_group(tp->t_mountp, bi);
6211-
xfs_defer_add(tp, &bi->bi_list, &xfs_bmap_update_defer_type);
6202+
xfs_bmap_defer_add(tp, bi);
62126203
return 0;
62136204
}
62146205

@@ -6252,13 +6243,7 @@ xfs_bmap_finish_one(
62526243

62536244
ASSERT(tp->t_highest_agno == NULLAGNUMBER);
62546245

6255-
trace_xfs_bmap_deferred(tp->t_mountp,
6256-
XFS_FSB_TO_AGNO(tp->t_mountp, bmap->br_startblock),
6257-
bi->bi_type,
6258-
XFS_FSB_TO_AGBNO(tp->t_mountp, bmap->br_startblock),
6259-
bi->bi_owner->i_ino, bi->bi_whichfork,
6260-
bmap->br_startoff, bmap->br_blockcount,
6261-
bmap->br_state);
6246+
trace_xfs_bmap_deferred(bi);
62626247

62636248
if (WARN_ON_ONCE(bi->bi_whichfork != XFS_DATA_FORK)) {
62646249
xfs_bmap_mark_sick(bi->bi_owner, bi->bi_whichfork);

fs/xfs/libxfs/xfs_bmap.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ enum xfs_bmap_intent_type {
232232
XFS_BMAP_UNMAP,
233233
};
234234

235+
#define XFS_BMAP_INTENT_STRINGS \
236+
{ XFS_BMAP_MAP, "map" }, \
237+
{ XFS_BMAP_UNMAP, "unmap" }
238+
235239
struct xfs_bmap_intent {
236240
struct list_head bi_list;
237241
enum xfs_bmap_intent_type bi_type;
@@ -241,9 +245,6 @@ struct xfs_bmap_intent {
241245
struct xfs_bmbt_irec bi_bmap;
242246
};
243247

244-
void xfs_bmap_update_get_group(struct xfs_mount *mp,
245-
struct xfs_bmap_intent *bi);
246-
247248
int xfs_bmap_finish_one(struct xfs_trans *tp, struct xfs_bmap_intent *bi);
248249
void xfs_bmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
249250
struct xfs_bmbt_irec *imap);

fs/xfs/xfs_attr_item.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ xfs_attr_free_item(
391391
kmem_cache_free(xfs_attr_intent_cache, attr);
392392
}
393393

394+
static inline struct xfs_attr_intent *attri_entry(const struct list_head *e)
395+
{
396+
return list_entry(e, struct xfs_attr_intent, xattri_list);
397+
}
398+
394399
/* Process an attr. */
395400
STATIC int
396401
xfs_attr_finish_item(
@@ -399,11 +404,10 @@ xfs_attr_finish_item(
399404
struct list_head *item,
400405
struct xfs_btree_cur **state)
401406
{
402-
struct xfs_attr_intent *attr;
407+
struct xfs_attr_intent *attr = attri_entry(item);
403408
struct xfs_da_args *args;
404409
int error;
405410

406-
attr = container_of(item, struct xfs_attr_intent, xattri_list);
407411
args = attr->xattri_da_args;
408412

409413
/* Reset trans after EAGAIN cycle since the transaction is new */
@@ -443,9 +447,8 @@ STATIC void
443447
xfs_attr_cancel_item(
444448
struct list_head *item)
445449
{
446-
struct xfs_attr_intent *attr;
450+
struct xfs_attr_intent *attr = attri_entry(item);
447451

448-
attr = container_of(item, struct xfs_attr_intent, xattri_list);
449452
xfs_attr_free_item(attr);
450453
}
451454

fs/xfs/xfs_bmap_item.c

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "xfs_log_priv.h"
2626
#include "xfs_log_recover.h"
2727
#include "xfs_ag.h"
28+
#include "xfs_trace.h"
2829

2930
struct kmem_cache *xfs_bui_cache;
3031
struct kmem_cache *xfs_bud_cache;
@@ -221,44 +222,24 @@ static const struct xfs_item_ops xfs_bud_item_ops = {
221222
.iop_intent = xfs_bud_item_intent,
222223
};
223224

225+
static inline struct xfs_bmap_intent *bi_entry(const struct list_head *e)
226+
{
227+
return list_entry(e, struct xfs_bmap_intent, bi_list);
228+
}
229+
224230
/* Sort bmap intents by inode. */
225231
static int
226232
xfs_bmap_update_diff_items(
227233
void *priv,
228234
const struct list_head *a,
229235
const struct list_head *b)
230236
{
231-
struct xfs_bmap_intent *ba;
232-
struct xfs_bmap_intent *bb;
237+
struct xfs_bmap_intent *ba = bi_entry(a);
238+
struct xfs_bmap_intent *bb = bi_entry(b);
233239

234-
ba = container_of(a, struct xfs_bmap_intent, bi_list);
235-
bb = container_of(b, struct xfs_bmap_intent, bi_list);
236240
return ba->bi_owner->i_ino - bb->bi_owner->i_ino;
237241
}
238242

239-
/* Set the map extent flags for this mapping. */
240-
static void
241-
xfs_trans_set_bmap_flags(
242-
struct xfs_map_extent *map,
243-
enum xfs_bmap_intent_type type,
244-
int whichfork,
245-
xfs_exntst_t state)
246-
{
247-
map->me_flags = 0;
248-
switch (type) {
249-
case XFS_BMAP_MAP:
250-
case XFS_BMAP_UNMAP:
251-
map->me_flags = type;
252-
break;
253-
default:
254-
ASSERT(0);
255-
}
256-
if (state == XFS_EXT_UNWRITTEN)
257-
map->me_flags |= XFS_BMAP_EXTENT_UNWRITTEN;
258-
if (whichfork == XFS_ATTR_FORK)
259-
map->me_flags |= XFS_BMAP_EXTENT_ATTR_FORK;
260-
}
261-
262243
/* Log bmap updates in the intent item. */
263244
STATIC void
264245
xfs_bmap_update_log_item(
@@ -281,8 +262,19 @@ xfs_bmap_update_log_item(
281262
map->me_startblock = bi->bi_bmap.br_startblock;
282263
map->me_startoff = bi->bi_bmap.br_startoff;
283264
map->me_len = bi->bi_bmap.br_blockcount;
284-
xfs_trans_set_bmap_flags(map, bi->bi_type, bi->bi_whichfork,
285-
bi->bi_bmap.br_state);
265+
266+
switch (bi->bi_type) {
267+
case XFS_BMAP_MAP:
268+
case XFS_BMAP_UNMAP:
269+
map->me_flags = bi->bi_type;
270+
break;
271+
default:
272+
ASSERT(0);
273+
}
274+
if (bi->bi_bmap.br_state == XFS_EXT_UNWRITTEN)
275+
map->me_flags |= XFS_BMAP_EXTENT_UNWRITTEN;
276+
if (bi->bi_whichfork == XFS_ATTR_FORK)
277+
map->me_flags |= XFS_BMAP_EXTENT_ATTR_FORK;
286278
}
287279

288280
static struct xfs_log_item *
@@ -325,7 +317,7 @@ xfs_bmap_update_create_done(
325317
}
326318

327319
/* Take a passive ref to the AG containing the space we're mapping. */
328-
void
320+
static inline void
329321
xfs_bmap_update_get_group(
330322
struct xfs_mount *mp,
331323
struct xfs_bmap_intent *bi)
@@ -344,6 +336,18 @@ xfs_bmap_update_get_group(
344336
bi->bi_pag = xfs_perag_intent_get(mp, agno);
345337
}
346338

339+
/* Add this deferred BUI to the transaction. */
340+
void
341+
xfs_bmap_defer_add(
342+
struct xfs_trans *tp,
343+
struct xfs_bmap_intent *bi)
344+
{
345+
trace_xfs_bmap_defer(bi);
346+
347+
xfs_bmap_update_get_group(tp->t_mountp, bi);
348+
xfs_defer_add(tp, &bi->bi_list, &xfs_bmap_update_defer_type);
349+
}
350+
347351
/* Release a passive AG ref after finishing mapping work. */
348352
static inline void
349353
xfs_bmap_update_put_group(
@@ -352,6 +356,17 @@ xfs_bmap_update_put_group(
352356
xfs_perag_intent_put(bi->bi_pag);
353357
}
354358

359+
/* Cancel a deferred bmap update. */
360+
STATIC void
361+
xfs_bmap_update_cancel_item(
362+
struct list_head *item)
363+
{
364+
struct xfs_bmap_intent *bi = bi_entry(item);
365+
366+
xfs_bmap_update_put_group(bi);
367+
kmem_cache_free(xfs_bmap_intent_cache, bi);
368+
}
369+
355370
/* Process a deferred bmap update. */
356371
STATIC int
357372
xfs_bmap_update_finish_item(
@@ -360,19 +375,16 @@ xfs_bmap_update_finish_item(
360375
struct list_head *item,
361376
struct xfs_btree_cur **state)
362377
{
363-
struct xfs_bmap_intent *bi;
378+
struct xfs_bmap_intent *bi = bi_entry(item);
364379
int error;
365380

366-
bi = container_of(item, struct xfs_bmap_intent, bi_list);
367-
368381
error = xfs_bmap_finish_one(tp, bi);
369382
if (!error && bi->bi_bmap.br_blockcount > 0) {
370383
ASSERT(bi->bi_type == XFS_BMAP_UNMAP);
371384
return -EAGAIN;
372385
}
373386

374-
xfs_bmap_update_put_group(bi);
375-
kmem_cache_free(xfs_bmap_intent_cache, bi);
387+
xfs_bmap_update_cancel_item(item);
376388
return error;
377389
}
378390

@@ -384,19 +396,6 @@ xfs_bmap_update_abort_intent(
384396
xfs_bui_release(BUI_ITEM(intent));
385397
}
386398

387-
/* Cancel a deferred bmap update. */
388-
STATIC void
389-
xfs_bmap_update_cancel_item(
390-
struct list_head *item)
391-
{
392-
struct xfs_bmap_intent *bi;
393-
394-
bi = container_of(item, struct xfs_bmap_intent, bi_list);
395-
396-
xfs_bmap_update_put_group(bi);
397-
kmem_cache_free(xfs_bmap_intent_cache, bi);
398-
}
399-
400399
/* Is this recovered BUI ok? */
401400
static inline bool
402401
xfs_bui_validate(

fs/xfs/xfs_bmap_item.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,8 @@ struct xfs_bud_log_item {
6868
extern struct kmem_cache *xfs_bui_cache;
6969
extern struct kmem_cache *xfs_bud_cache;
7070

71+
struct xfs_bmap_intent;
72+
73+
void xfs_bmap_defer_add(struct xfs_trans *tp, struct xfs_bmap_intent *bi);
74+
7175
#endif /* __XFS_BMAP_ITEM_H__ */

fs/xfs/xfs_trace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "xfs_iomap.h"
3939
#include "xfs_buf_mem.h"
4040
#include "xfs_btree_mem.h"
41+
#include "xfs_bmap.h"
4142

4243
/*
4344
* We include this last to have the helpers above available for the trace

0 commit comments

Comments
 (0)