
[ Upstream commit f8f9d952e42dd49ae534f61f2fa7ca0876cb9848 ]
When recovering intents, we capture newly created intent items as part of
committing recovered intent items. If intent recovery fails at a later
point, we forget to remove those newly created intent items from the AIL
and hang:
[root@localhost ~]# cat /proc/539/stack
[<0>] xfs_ail_push_all_sync+0x174/0x230
[<0>] xfs_unmount_flush_inodes+0x8d/0xd0
[<0>] xfs_mountfs+0x15f7/0x1e70
[<0>] xfs_fs_fill_super+0x10ec/0x1b20
[<0>] get_tree_bdev+0x3c8/0x730
[<0>] vfs_get_tree+0x89/0x2c0
[<0>] path_mount+0xecf/0x1800
[<0>] do_mount+0xf3/0x110
[<0>] __x64_sys_mount+0x154/0x1f0
[<0>] do_syscall_64+0x39/0x80
[<0>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
When newly created intent items fail to commit via transaction, intent
recovery hasn't created done items for these newly created intent items,
so the capture structure is the sole owner of the captured intent items.
We must release them explicitly or else they leak:
unreferenced object 0xffff888016719108 (size 432):
comm "mount", pid 529, jiffies 4294706839 (age 144.463s)
hex dump (first 32 bytes):
08 91 71 16 80 88 ff ff 08 91 71 16 80 88 ff ff ..q.......q.....
18 91 71 16 80 88 ff ff 18 91 71 16 80 88 ff ff ..q.......q.....
backtrace:
[<ffffffff8230c68f>] xfs_efi_init+0x18f/0x1d0
[<ffffffff8230c720>] xfs_extent_free_create_intent+0x50/0x150
[<ffffffff821b671a>] xfs_defer_create_intents+0x16a/0x340
[<ffffffff821bac3e>] xfs_defer_ops_capture_and_commit+0x8e/0xad0
[<ffffffff82322bb9>] xfs_cui_item_recover+0x819/0x980
[<ffffffff823289b6>] xlog_recover_process_intents+0x246/0xb70
[<ffffffff8233249a>] xlog_recover_finish+0x8a/0x9a0
[<ffffffff822eeafb>] xfs_log_mount_finish+0x2bb/0x4a0
[<ffffffff822c0f4f>] xfs_mountfs+0x14bf/0x1e70
[<ffffffff822d1f80>] xfs_fs_fill_super+0x10d0/0x1b20
[<ffffffff81a21fa2>] get_tree_bdev+0x3d2/0x6d0
[<ffffffff81a1ee09>] vfs_get_tree+0x89/0x2c0
[<ffffffff81a9f35f>] path_mount+0xecf/0x1800
[<ffffffff81a9fd83>] do_mount+0xf3/0x110
[<ffffffff81aa00e4>] __x64_sys_mount+0x154/0x1f0
[<ffffffff83968739>] do_syscall_64+0x39/0x80
Fix the problem above by abort intent items that don't have a done item
when recovery intents fail.
Fixes: e6fff81e48
("xfs: proper replay of deferred ops queued during log recovery")
Signed-off-by: Long Li <leo.lilong@huawei.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Signed-off-by: Leah Rumancik <leah.rumancik@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
132 lines
4.1 KiB
C
132 lines
4.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
/*
|
|
* Copyright (C) 2016 Oracle. All Rights Reserved.
|
|
* Author: Darrick J. Wong <darrick.wong@oracle.com>
|
|
*/
|
|
#ifndef __XFS_DEFER_H__
|
|
#define __XFS_DEFER_H__
|
|
|
|
struct xfs_btree_cur;
|
|
struct xfs_defer_op_type;
|
|
struct xfs_defer_capture;
|
|
|
|
/*
|
|
* Header for deferred operation list.
|
|
*/
|
|
enum xfs_defer_ops_type {
|
|
XFS_DEFER_OPS_TYPE_BMAP,
|
|
XFS_DEFER_OPS_TYPE_REFCOUNT,
|
|
XFS_DEFER_OPS_TYPE_RMAP,
|
|
XFS_DEFER_OPS_TYPE_FREE,
|
|
XFS_DEFER_OPS_TYPE_AGFL_FREE,
|
|
XFS_DEFER_OPS_TYPE_ATTR,
|
|
XFS_DEFER_OPS_TYPE_MAX,
|
|
};
|
|
|
|
/*
|
|
* Save a log intent item and a list of extents, so that we can replay
|
|
* whatever action had to happen to the extent list and file the log done
|
|
* item.
|
|
*/
|
|
struct xfs_defer_pending {
|
|
struct list_head dfp_list; /* pending items */
|
|
struct list_head dfp_work; /* work items */
|
|
struct xfs_log_item *dfp_intent; /* log intent item */
|
|
struct xfs_log_item *dfp_done; /* log done item */
|
|
unsigned int dfp_count; /* # extent items */
|
|
enum xfs_defer_ops_type dfp_type;
|
|
};
|
|
|
|
void xfs_defer_add(struct xfs_trans *tp, enum xfs_defer_ops_type type,
|
|
struct list_head *h);
|
|
int xfs_defer_finish_noroll(struct xfs_trans **tp);
|
|
int xfs_defer_finish(struct xfs_trans **tp);
|
|
void xfs_defer_cancel(struct xfs_trans *);
|
|
void xfs_defer_move(struct xfs_trans *dtp, struct xfs_trans *stp);
|
|
|
|
/* Description of a deferred type. */
|
|
struct xfs_defer_op_type {
|
|
struct xfs_log_item *(*create_intent)(struct xfs_trans *tp,
|
|
struct list_head *items, unsigned int count, bool sort);
|
|
void (*abort_intent)(struct xfs_log_item *intent);
|
|
struct xfs_log_item *(*create_done)(struct xfs_trans *tp,
|
|
struct xfs_log_item *intent, unsigned int count);
|
|
int (*finish_item)(struct xfs_trans *tp, struct xfs_log_item *done,
|
|
struct list_head *item, struct xfs_btree_cur **state);
|
|
void (*finish_cleanup)(struct xfs_trans *tp,
|
|
struct xfs_btree_cur *state, int error);
|
|
void (*cancel_item)(struct list_head *item);
|
|
unsigned int max_items;
|
|
};
|
|
|
|
extern const struct xfs_defer_op_type xfs_bmap_update_defer_type;
|
|
extern const struct xfs_defer_op_type xfs_refcount_update_defer_type;
|
|
extern const struct xfs_defer_op_type xfs_rmap_update_defer_type;
|
|
extern const struct xfs_defer_op_type xfs_extent_free_defer_type;
|
|
extern const struct xfs_defer_op_type xfs_agfl_free_defer_type;
|
|
extern const struct xfs_defer_op_type xfs_attr_defer_type;
|
|
|
|
|
|
/*
|
|
* Deferred operation item relogging limits.
|
|
*/
|
|
#define XFS_DEFER_OPS_NR_INODES 2 /* join up to two inodes */
|
|
#define XFS_DEFER_OPS_NR_BUFS 2 /* join up to two buffers */
|
|
|
|
/* Resources that must be held across a transaction roll. */
|
|
struct xfs_defer_resources {
|
|
/* held buffers */
|
|
struct xfs_buf *dr_bp[XFS_DEFER_OPS_NR_BUFS];
|
|
|
|
/* inodes with no unlock flags */
|
|
struct xfs_inode *dr_ip[XFS_DEFER_OPS_NR_INODES];
|
|
|
|
/* number of held buffers */
|
|
unsigned short dr_bufs;
|
|
|
|
/* bitmap of ordered buffers */
|
|
unsigned short dr_ordered;
|
|
|
|
/* number of held inodes */
|
|
unsigned short dr_inos;
|
|
};
|
|
|
|
/*
|
|
* This structure enables a dfops user to detach the chain of deferred
|
|
* operations from a transaction so that they can be continued later.
|
|
*/
|
|
struct xfs_defer_capture {
|
|
/* List of other capture structures. */
|
|
struct list_head dfc_list;
|
|
|
|
/* Deferred ops state saved from the transaction. */
|
|
struct list_head dfc_dfops;
|
|
unsigned int dfc_tpflags;
|
|
|
|
/* Block reservations for the data and rt devices. */
|
|
unsigned int dfc_blkres;
|
|
unsigned int dfc_rtxres;
|
|
|
|
/* Log reservation saved from the transaction. */
|
|
unsigned int dfc_logres;
|
|
|
|
struct xfs_defer_resources dfc_held;
|
|
};
|
|
|
|
/*
|
|
* Functions to capture a chain of deferred operations and continue them later.
|
|
* This doesn't normally happen except log recovery.
|
|
*/
|
|
int xfs_defer_ops_capture_and_commit(struct xfs_trans *tp,
|
|
struct list_head *capture_list);
|
|
void xfs_defer_ops_continue(struct xfs_defer_capture *d, struct xfs_trans *tp,
|
|
struct xfs_defer_resources *dres);
|
|
void xfs_defer_ops_capture_abort(struct xfs_mount *mp,
|
|
struct xfs_defer_capture *d);
|
|
void xfs_defer_resources_rele(struct xfs_defer_resources *dres);
|
|
|
|
int __init xfs_defer_init_item_caches(void);
|
|
void xfs_defer_destroy_item_caches(void);
|
|
|
|
#endif /* __XFS_DEFER_H__ */
|