Commit af1077fa authored by Darrick J. Wong's avatar Darrick J. Wong
Browse files

Merge tag 'scrub-cleanup-malloc-6.2_2022-11-16' of...

Merge tag 'scrub-cleanup-malloc-6.2_2022-11-16' of git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux

 into xfs-6.2-mergeA

xfs: clean up memory allocations in online fsck

This series standardizes the GFP_ flags that we use for memory
allocation in online scrub, and convert the callers away from the old
kmem_alloc code that was ported from Irix.

Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>

* tag 'scrub-cleanup-malloc-6.2_2022-11-16' of git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: pivot online scrub away from kmem.[ch]
  xfs: initialize the check_owner object fully
  xfs: standardize GFP flags usage in online scrub
parents 823ca26a 306195f3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -737,7 +737,7 @@ xchk_agfl(
		goto out;
	}
	sai.entries = kvcalloc(sai.agflcount, sizeof(xfs_agblock_t),
			GFP_KERNEL | __GFP_RETRY_MAYFAIL);
			       XCHK_GFP_FLAGS);
	if (!sai.entries) {
		error = -ENOMEM;
		goto out;
+1 −1
Original line number Diff line number Diff line
@@ -685,7 +685,7 @@ xrep_agfl_init_header(
		if (br->len)
			break;
		list_del(&br->list);
		kmem_free(br);
		kfree(br);
	}

	/* Write new AGFL to disk. */
+5 −6
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ xchk_setup_xattr_buf(
	if (ab) {
		if (sz <= ab->sz)
			return 0;
		kmem_free(ab);
		kvfree(ab);
		sc->buf = NULL;
	}

@@ -79,7 +79,8 @@ xchk_setup_xattr(
	 * without the inode lock held, which means we can sleep.
	 */
	if (sc->flags & XCHK_TRY_HARDER) {
		error = xchk_setup_xattr_buf(sc, XATTR_SIZE_MAX, GFP_KERNEL);
		error = xchk_setup_xattr_buf(sc, XATTR_SIZE_MAX,
				XCHK_GFP_FLAGS);
		if (error)
			return error;
	}
@@ -138,8 +139,7 @@ xchk_xattr_listent(
	 * doesn't work, we overload the seen_enough variable to convey
	 * the error message back to the main scrub function.
	 */
	error = xchk_setup_xattr_buf(sx->sc, valuelen,
			GFP_KERNEL | __GFP_RETRY_MAYFAIL);
	error = xchk_setup_xattr_buf(sx->sc, valuelen, XCHK_GFP_FLAGS);
	if (error == -ENOMEM)
		error = -EDEADLOCK;
	if (error) {
@@ -324,8 +324,7 @@ xchk_xattr_block(
		return 0;

	/* Allocate memory for block usage checking. */
	error = xchk_setup_xattr_buf(ds->sc, 0,
			GFP_KERNEL | __GFP_RETRY_MAYFAIL);
	error = xchk_setup_xattr_buf(ds->sc, 0, XCHK_GFP_FLAGS);
	if (error == -ENOMEM)
		return -EDEADLOCK;
	if (error)
+6 −5
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#include "xfs_trans_resv.h"
#include "xfs_mount.h"
#include "xfs_btree.h"
#include "scrub/scrub.h"
#include "scrub/bitmap.h"

/*
@@ -25,7 +26,7 @@ xbitmap_set(
{
	struct xbitmap_range	*bmr;

	bmr = kmem_alloc(sizeof(struct xbitmap_range), KM_MAYFAIL);
	bmr = kmalloc(sizeof(struct xbitmap_range), XCHK_GFP_FLAGS);
	if (!bmr)
		return -ENOMEM;

@@ -47,7 +48,7 @@ xbitmap_destroy(

	for_each_xbitmap_extent(bmr, n, bitmap) {
		list_del(&bmr->list);
		kmem_free(bmr);
		kfree(bmr);
	}
}

@@ -174,15 +175,15 @@ xbitmap_disunion(
			/* Total overlap, just delete ex. */
			lp = lp->next;
			list_del(&br->list);
			kmem_free(br);
			kfree(br);
			break;
		case 0:
			/*
			 * Deleting from the middle: add the new right extent
			 * and then shrink the left extent.
			 */
			new_br = kmem_alloc(sizeof(struct xbitmap_range),
					KM_MAYFAIL);
			new_br = kmalloc(sizeof(struct xbitmap_range),
					XCHK_GFP_FLAGS);
			if (!new_br) {
				error = -ENOMEM;
				goto out;
+8 −6
Original line number Diff line number Diff line
@@ -408,7 +408,6 @@ xchk_btree_check_owner(
	struct xfs_buf		*bp)
{
	struct xfs_btree_cur	*cur = bs->cur;
	struct check_owner	*co;

	/*
	 * In theory, xfs_btree_get_block should only give us a null buffer
@@ -431,10 +430,13 @@ xchk_btree_check_owner(
	 * later scanning.
	 */
	if (cur->bc_btnum == XFS_BTNUM_BNO || cur->bc_btnum == XFS_BTNUM_RMAP) {
		co = kmem_alloc(sizeof(struct check_owner),
				KM_MAYFAIL);
		struct check_owner	*co;

		co = kmalloc(sizeof(struct check_owner), XCHK_GFP_FLAGS);
		if (!co)
			return -ENOMEM;

		INIT_LIST_HEAD(&co->list);
		co->level = level;
		co->daddr = xfs_buf_daddr(bp);
		list_add_tail(&co->list, &bs->to_check);
@@ -649,7 +651,7 @@ xchk_btree(
		xchk_btree_set_corrupt(sc, cur, 0);
		return 0;
	}
	bs = kmem_zalloc(cur_sz, KM_NOFS | KM_MAYFAIL);
	bs = kzalloc(cur_sz, XCHK_GFP_FLAGS);
	if (!bs)
		return -ENOMEM;
	bs->cur = cur;
@@ -740,9 +742,9 @@ xchk_btree(
			error = xchk_btree_check_block_owner(bs, co->level,
					co->daddr);
		list_del(&co->list);
		kmem_free(co);
		kfree(co);
	}
	kmem_free(bs);
	kfree(bs);

	return error;
}
Loading