Re: [PATCH] xfs: do the assert for all the log done items in xfs_trans_cancel

kaixuxia
2020-09-17T08:07:41Z

On 2020/9/17 8:10, Darrick J. Wong wrote:
> On Wed, Sep 16, 2020 at 07:19:07PM +0800, xiakaixu1987@gmail.com wrote:
>> From: Kaixu Xia <kaixuxia@tencent.com>
>>
>> We should do the assert for all the log done items if they appear
>> here. This patch also add the XFS_ITEM_LOG_DONE flag to check if
>> the item is a log done item.
>>
>> Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
>> ---
>> fs/xfs/xfs_bmap_item.c | 2 +-
>> fs/xfs/xfs_extfree_item.c | 2 +-
>> fs/xfs/xfs_refcount_item.c | 2 +-
>> fs/xfs/xfs_rmap_item.c | 2 +-
>> fs/xfs/xfs_trans.c | 2 +-
>> fs/xfs/xfs_trans.h | 4 ++++
>> 6 files changed, 9 insertions(+), 5 deletions(-)
>>
>> diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c
>> index ec3691372e7c..2e49f48666f1 100644
>> --- a/fs/xfs/xfs_bmap_item.c
>> +++ b/fs/xfs/xfs_bmap_item.c
>> @@ -202,7 +202,7 @@ xfs_bud_item_release(
>> }
>>
>> static const struct xfs_item_ops xfs_bud_item_ops = {
>> - .flags = XFS_ITEM_RELEASE_WHEN_COMMITTED,
>> + .flags = XFS_ITEM_LOG_DONE_FLAG,
>> .iop_size = xfs_bud_item_size,
>> .iop_format = xfs_bud_item_format,
>> .iop_release = xfs_bud_item_release,
>> diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c
>> index 6cb8cd11072a..f2c6cb67262e 100644
>> --- a/fs/xfs/xfs_extfree_item.c
>> +++ b/fs/xfs/xfs_extfree_item.c
>> @@ -307,7 +307,7 @@ xfs_efd_item_release(
>> }
>>
>> static const struct xfs_item_ops xfs_efd_item_ops = {
>> - .flags = XFS_ITEM_RELEASE_WHEN_COMMITTED,
>> + .flags = XFS_ITEM_LOG_DONE_FLAG,
>> .iop_size = xfs_efd_item_size,
>> .iop_format = xfs_efd_item_format,
>> .iop_release = xfs_efd_item_release,
>> diff --git a/fs/xfs/xfs_refcount_item.c b/fs/xfs/xfs_refcount_item.c
>> index ca93b6488377..551bcc93acdd 100644
>> --- a/fs/xfs/xfs_refcount_item.c
>> +++ b/fs/xfs/xfs_refcount_item.c
>> @@ -208,7 +208,7 @@ xfs_cud_item_release(
>> }
>>
>> static const struct xfs_item_ops xfs_cud_item_ops = {
>> - .flags = XFS_ITEM_RELEASE_WHEN_COMMITTED,
>> + .flags = XFS_ITEM_LOG_DONE_FLAG,
>> .iop_size = xfs_cud_item_size,
>> .iop_format = xfs_cud_item_format,
>> .iop_release = xfs_cud_item_release,
>> diff --git a/fs/xfs/xfs_rmap_item.c b/fs/xfs/xfs_rmap_item.c
>> index dc5b0753cd51..427f90ef4509 100644
>> --- a/fs/xfs/xfs_rmap_item.c
>> +++ b/fs/xfs/xfs_rmap_item.c
>> @@ -231,7 +231,7 @@ xfs_rud_item_release(
>> }
>>
>> static const struct xfs_item_ops xfs_rud_item_ops = {
>> - .flags = XFS_ITEM_RELEASE_WHEN_COMMITTED,
>> + .flags = XFS_ITEM_LOG_DONE_FLAG,
>> .iop_size = xfs_rud_item_size,
>> .iop_format = xfs_rud_item_format,
>> .iop_release = xfs_rud_item_release,
>> diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
>> index 4257fdb03778..d33d0ba6f3bd 100644
>> --- a/fs/xfs/xfs_trans.c
>> +++ b/fs/xfs/xfs_trans.c
>> @@ -1050,7 +1050,7 @@ xfs_trans_cancel(
>> struct xfs_log_item *lip;
>>
>> list_for_each_entry(lip, &tp->t_items, li_trans)
>> - ASSERT(!(lip->li_type == XFS_LI_EFD));
>> + ASSERT(!(lip->li_ops->flags & XFS_ITEM_LOG_DONE));
>> }
>> #endif
>> xfs_trans_unreserve_and_mod_sb(tp);
>> diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h
>> index 7fb82eb92e65..b92138b13c40 100644
>> --- a/fs/xfs/xfs_trans.h
>> +++ b/fs/xfs/xfs_trans.h
>> @@ -85,6 +85,10 @@ struct xfs_item_ops {
>> * intents that never need to be written back in place.
>> */
>> #define XFS_ITEM_RELEASE_WHEN_COMMITTED (1 << 0)
>> +#define XFS_ITEM_LOG_DONE (1 << 1) /* log done item */
>> +
>> +#define XFS_ITEM_LOG_DONE_FLAG (XFS_ITEM_RELEASE_WHEN_COMMITTED | \
>> + XFS_ITEM_LOG_DONE)
>
> Please don't go adding more flags for a debugging check.
>
> You /could/ just detect intent-done items by the fact that their item
> ops don't have unpin or push methods, kind of like what we do for
> detecting intent items in log recovery.
>
> Oh wait, you mowed /that/ down too.

Yes, this patch and the next patch add two flags XFS_ITEM_LOG_INTENT and
XFS_ITEM_LOG_DONE to mark the log item is log intent item or log done item.

By now that we can use the struct xfs_item_ops methods to find the log
intent items and log done items, but I'm not sure if we will use these special
methods in other log items, for example, we use the iop_recover method in a log
item that is not a log intent item for a special purpose... Anyway, it's just
my half-thoughts:)

I will use the special methods to detect the log done items in the next version .

Thanks,
Kaixu
>
> --D
>
>>
>> void xfs_log_item_init(struct xfs_mount *mp, struct xfs_log_item *item,
>> int type, const struct xfs_item_ops *ops);
>> --
>> 2.20.0
>>

--
kaixuxia