diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c index 8120f136af93..cdf660344c28 100644 --- a/fs/xfs/xfs_discard.c +++ b/fs/xfs/xfs_discard.c @@ -200,12 +200,12 @@ xfs_trim_gather_extents( error = xfs_alloc_lookup_le(cur, tcur->start, 0, &i); if (!error && !i) error = xfs_alloc_lookup_ge(cur, tcur->start, 0, &i); - } else if (tcur->restart_bno == NULLAGBLOCK) { - /* first time through a by-len starts with max length */ - cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag); - error = xfs_alloc_lookup_ge(cur, 0, tcur->count, &i); } else { - /* nth time through a by-len starts where we left off */ + /* + * A by-len walk starts at the last record of the longest + * length (restart_bno is NULLAGBLOCK until the first batch + * ends) and then where the previous batch stopped. + */ cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag); error = xfs_alloc_lookup_le(cur, tcur->restart_bno, tcur->count, &i);