diff mbox series

[04/45] FIXUP: xfs: make metabtree reservations global

Message ID 20250409075557.3535745-5-hch@lst.de (mailing list archive)
State New
Headers show
Series [01/45] xfs: generalize the freespace and reserved blocks handling | expand

Commit Message

Christoph Hellwig April 9, 2025, 7:55 a.m. UTC
---
 include/spinlock.h   |  5 +++++
 include/xfs_mount.h  |  4 ++++
 libxfs/libxfs_priv.h |  1 +
 mkfs/xfs_mkfs.c      | 25 ++++---------------------
 4 files changed, 14 insertions(+), 21 deletions(-)

Comments

Darrick J. Wong April 9, 2025, 3:43 p.m. UTC | #1
On Wed, Apr 09, 2025 at 09:55:07AM +0200, Christoph Hellwig wrote:
> ---
>  include/spinlock.h   |  5 +++++
>  include/xfs_mount.h  |  4 ++++
>  libxfs/libxfs_priv.h |  1 +
>  mkfs/xfs_mkfs.c      | 25 ++++---------------------
>  4 files changed, 14 insertions(+), 21 deletions(-)
> 
> diff --git a/include/spinlock.h b/include/spinlock.h
> index 82973726b101..73bd8c078fea 100644
> --- a/include/spinlock.h
> +++ b/include/spinlock.h
> @@ -22,4 +22,9 @@ typedef pthread_mutex_t	spinlock_t;
>  #define spin_trylock(l)		(pthread_mutex_trylock(l) != EBUSY)
>  #define spin_unlock(l)		pthread_mutex_unlock(l)
>  
> +#define mutex_init(l)		pthread_mutex_init(l, NULL)
> +#define mutex_lock(l)		pthread_mutex_lock(l)
> +#define mutex_trylock(l)	(pthread_mutex_trylock(l) != EBUSY)
> +#define mutex_unlock(l)		pthread_mutex_unlock(l)
> +
>  #endif /* __LIBXFS_SPINLOCK_H__ */
> diff --git a/include/xfs_mount.h b/include/xfs_mount.h
> index e0f72fc32b25..0acf952eb9d7 100644
> --- a/include/xfs_mount.h
> +++ b/include/xfs_mount.h
> @@ -164,6 +164,10 @@ typedef struct xfs_mount {
>  	atomic64_t		m_allocbt_blks;
>  	spinlock_t		m_perag_lock;	/* lock for m_perag_tree */
>  
> +	pthread_mutex_t		m_metafile_resv_lock;
> +	uint64_t		m_metafile_resv_target;
> +	uint64_t		m_metafile_resv_used;
> +	uint64_t		m_metafile_resv_avail;
>  } xfs_mount_t;
>  
>  #define M_IGEO(mp)		(&(mp)->m_ino_geo)
> diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
> index cb4800de0b11..82952b0db629 100644
> --- a/libxfs/libxfs_priv.h
> +++ b/libxfs/libxfs_priv.h
> @@ -151,6 +151,7 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
>  
>  #define xfs_force_shutdown(d,n)		((void) 0)
>  #define xfs_mod_delalloc(a,b,c)		((void) 0)
> +#define xfs_mod_sb_delalloc(sb, d)	((void) 0)
>  
>  /* stop unused var warnings by assigning mp to itself */
>  
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index 3f4455d46383..39e3349205fb 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -5102,8 +5102,6 @@ check_rt_meta_prealloc(
>  	struct xfs_mount	*mp)
>  {
>  	struct xfs_perag	*pag = NULL;
> -	struct xfs_rtgroup	*rtg = NULL;
> -	xfs_filblks_t		ask;
>  	int			error;
>  
>  	/*
> @@ -5123,27 +5121,12 @@ check_rt_meta_prealloc(
>  		}
>  	}
>  
> -	/* Realtime metadata btree inode */
> -	while ((rtg = xfs_rtgroup_next(mp, rtg))) {
> -		ask = libxfs_rtrmapbt_calc_reserves(mp);
> -		error = -libxfs_metafile_resv_init(rtg_rmap(rtg), ask);
> -		if (error)
> -			prealloc_fail(mp, error, ask, _("realtime rmap btree"));
> -
> -		ask = libxfs_rtrefcountbt_calc_reserves(mp);
> -		error = -libxfs_metafile_resv_init(rtg_refcount(rtg), ask);
> -		if (error)
> -			prealloc_fail(mp, error, ask,
> -					_("realtime refcount btree"));
> -	}
> +	error = -libxfs_metafile_resv_init(mp);
> +	if (error)
> +		prealloc_fail(mp, error, 0, _("metafile"));

Could this be _("metadata files") so that the error message becomes:

mkfs.xfs: cannot handle expansion of metadata files; need 55 free blocks, have 7

With that changed,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

>  
> -	/* Unreserve the realtime metadata reservations. */
> -	while ((rtg = xfs_rtgroup_next(mp, rtg))) {
> -		libxfs_metafile_resv_free(rtg_rmap(rtg));
> -		libxfs_metafile_resv_free(rtg_refcount(rtg));
> -	}
> +	libxfs_metafile_resv_free(mp);
>  
> -	/* Unreserve the per-AG reservations. */
>  	while ((pag = xfs_perag_next(mp, pag)))
>  		libxfs_ag_resv_free(pag);
>  
> -- 
> 2.47.2
> 
>
Christoph Hellwig April 10, 2025, 6 a.m. UTC | #2
On Wed, Apr 09, 2025 at 08:43:03AM -0700, Darrick J. Wong wrote:
> > +	error = -libxfs_metafile_resv_init(mp);
> > +	if (error)
> > +		prealloc_fail(mp, error, 0, _("metafile"));
> 
> Could this be _("metadata files") so that the error message becomes:
> 
> mkfs.xfs: cannot handle expansion of metadata files; need 55 free blocks, have 7
> 
> With that changed,

Sure.
diff mbox series

Patch

diff --git a/include/spinlock.h b/include/spinlock.h
index 82973726b101..73bd8c078fea 100644
--- a/include/spinlock.h
+++ b/include/spinlock.h
@@ -22,4 +22,9 @@  typedef pthread_mutex_t	spinlock_t;
 #define spin_trylock(l)		(pthread_mutex_trylock(l) != EBUSY)
 #define spin_unlock(l)		pthread_mutex_unlock(l)
 
+#define mutex_init(l)		pthread_mutex_init(l, NULL)
+#define mutex_lock(l)		pthread_mutex_lock(l)
+#define mutex_trylock(l)	(pthread_mutex_trylock(l) != EBUSY)
+#define mutex_unlock(l)		pthread_mutex_unlock(l)
+
 #endif /* __LIBXFS_SPINLOCK_H__ */
diff --git a/include/xfs_mount.h b/include/xfs_mount.h
index e0f72fc32b25..0acf952eb9d7 100644
--- a/include/xfs_mount.h
+++ b/include/xfs_mount.h
@@ -164,6 +164,10 @@  typedef struct xfs_mount {
 	atomic64_t		m_allocbt_blks;
 	spinlock_t		m_perag_lock;	/* lock for m_perag_tree */
 
+	pthread_mutex_t		m_metafile_resv_lock;
+	uint64_t		m_metafile_resv_target;
+	uint64_t		m_metafile_resv_used;
+	uint64_t		m_metafile_resv_avail;
 } xfs_mount_t;
 
 #define M_IGEO(mp)		(&(mp)->m_ino_geo)
diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index cb4800de0b11..82952b0db629 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -151,6 +151,7 @@  enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
 
 #define xfs_force_shutdown(d,n)		((void) 0)
 #define xfs_mod_delalloc(a,b,c)		((void) 0)
+#define xfs_mod_sb_delalloc(sb, d)	((void) 0)
 
 /* stop unused var warnings by assigning mp to itself */
 
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 3f4455d46383..39e3349205fb 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -5102,8 +5102,6 @@  check_rt_meta_prealloc(
 	struct xfs_mount	*mp)
 {
 	struct xfs_perag	*pag = NULL;
-	struct xfs_rtgroup	*rtg = NULL;
-	xfs_filblks_t		ask;
 	int			error;
 
 	/*
@@ -5123,27 +5121,12 @@  check_rt_meta_prealloc(
 		}
 	}
 
-	/* Realtime metadata btree inode */
-	while ((rtg = xfs_rtgroup_next(mp, rtg))) {
-		ask = libxfs_rtrmapbt_calc_reserves(mp);
-		error = -libxfs_metafile_resv_init(rtg_rmap(rtg), ask);
-		if (error)
-			prealloc_fail(mp, error, ask, _("realtime rmap btree"));
-
-		ask = libxfs_rtrefcountbt_calc_reserves(mp);
-		error = -libxfs_metafile_resv_init(rtg_refcount(rtg), ask);
-		if (error)
-			prealloc_fail(mp, error, ask,
-					_("realtime refcount btree"));
-	}
+	error = -libxfs_metafile_resv_init(mp);
+	if (error)
+		prealloc_fail(mp, error, 0, _("metafile"));
 
-	/* Unreserve the realtime metadata reservations. */
-	while ((rtg = xfs_rtgroup_next(mp, rtg))) {
-		libxfs_metafile_resv_free(rtg_rmap(rtg));
-		libxfs_metafile_resv_free(rtg_refcount(rtg));
-	}
+	libxfs_metafile_resv_free(mp);
 
-	/* Unreserve the per-AG reservations. */
 	while ((pag = xfs_perag_next(mp, pag)))
 		libxfs_ag_resv_free(pag);