All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHSET 0/7] xfsprogs: random fixes for 6.0
@ 2022-11-09  2:05 ` Darrick J. Wong
  2022-11-09  2:05   ` [PATCH 1/7] libxfs: consume the xfs_warn mountpoint argument Darrick J. Wong
                     ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Darrick J. Wong @ 2022-11-09  2:05 UTC (permalink / raw)
  To: cem, djwong; +Cc: linux-xfs

Hi all,

This is a rollup of all the random fixes I've collected for xfsprogs
6.0.  At this point it's just an assorted collection, no particular
theme.  Many of them are leftovers from the last posting.

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=xfsprogs-fixes-6.0
---
 db/btblock.c             |    2 +
 db/namei.c               |    2 +
 db/write.c               |    4 +-
 io/pread.c               |    2 +
 libfrog/linux.c          |    1 +
 libxfs/libxfs_api_defs.h |    2 +
 libxfs/libxfs_io.h       |    1 +
 libxfs/libxfs_priv.h     |    2 +
 libxfs/rdwr.c            |    8 +++++
 libxfs/util.c            |    1 +
 mkfs/xfs_mkfs.c          |    2 +
 repair/phase2.c          |    8 +++++
 repair/phase6.c          |    9 +++++
 repair/protos.h          |    1 +
 repair/xfs_repair.c      |   77 ++++++++++++++++++++++++++++++++++++++++------
 scrub/inodes.c           |    2 +
 16 files changed, 105 insertions(+), 19 deletions(-)


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/7] libxfs: consume the xfs_warn mountpoint argument
  2022-11-09  2:05 ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Darrick J. Wong
@ 2022-11-09  2:05   ` Darrick J. Wong
  2022-11-09  2:05   ` [PATCH 2/7] misc: add static to various sourcefile-local functions Darrick J. Wong
                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Darrick J. Wong @ 2022-11-09  2:05 UTC (permalink / raw)
  To: cem, djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

Fix these warnings because xfs_warn doesn't do anything in userspace:

xfs_alloc.c: In function ‘xfs_alloc_get_rec’:
xfs_alloc.c:246:34: warning: unused variable ‘mp’ [-Wunused-variable]
  246 |         struct xfs_mount        *mp = cur->bc_mp;
      |                                  ^~

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 libxfs/libxfs_priv.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index ad920cd9b6..b2c3f694b0 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -125,7 +125,7 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
 
 #define xfs_info(mp,fmt,args...)	cmn_err(CE_CONT, _(fmt), ## args)
 #define xfs_notice(mp,fmt,args...)	cmn_err(CE_NOTE, _(fmt), ## args)
-#define xfs_warn(mp,fmt,args...)	cmn_err(CE_WARN, _(fmt), ## args)
+#define xfs_warn(mp,fmt,args...)	cmn_err((mp) ? CE_WARN : CE_WARN, _(fmt), ## args)
 #define xfs_err(mp,fmt,args...)		cmn_err(CE_ALERT, _(fmt), ## args)
 #define xfs_alert(mp,fmt,args...)	cmn_err(CE_ALERT, _(fmt), ## args)
 


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/7] misc: add static to various sourcefile-local functions
  2022-11-09  2:05 ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Darrick J. Wong
  2022-11-09  2:05   ` [PATCH 1/7] libxfs: consume the xfs_warn mountpoint argument Darrick J. Wong
@ 2022-11-09  2:05   ` Darrick J. Wong
  2022-11-09  2:05   ` [PATCH 3/7] misc: add missing includes Darrick J. Wong
                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Darrick J. Wong @ 2022-11-09  2:05 UTC (permalink / raw)
  To: cem, djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

These helper functions are not referenced outside the source file
they're defined in.  Mark them static.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 db/namei.c          |    2 +-
 io/pread.c          |    2 +-
 mkfs/xfs_mkfs.c     |    2 +-
 repair/xfs_repair.c |    2 +-
 scrub/inodes.c      |    2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)


diff --git a/db/namei.c b/db/namei.c
index f06ee3e959..6c57cc624e 100644
--- a/db/namei.c
+++ b/db/namei.c
@@ -441,7 +441,7 @@ list_leafdir(
 }
 
 /* Read the directory, display contents. */
-int
+static int
 listdir(
 	struct xfs_inode	*dp)
 {
diff --git a/io/pread.c b/io/pread.c
index 458a78b83c..0f1d8b97b0 100644
--- a/io/pread.c
+++ b/io/pread.c
@@ -113,7 +113,7 @@ alloc_buffer(
 	return 0;
 }
 
-void
+static void
 __dump_buffer(
 	void		*buf,
 	off64_t		offset,
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 9dd0e79c6b..e219ec166d 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3964,7 +3964,7 @@ cfgfile_parse_ini(
 	return 1;
 }
 
-void
+static void
 cfgfile_parse(
 	struct cli_params	*cli)
 {
diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index c94671d8d1..871b428d7d 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -750,7 +750,7 @@ check_fs_vs_host_sectsize(
 }
 
 /* Clear needsrepair after a successful repair run. */
-void
+static void
 clear_needsrepair(
 	struct xfs_mount	*mp)
 {
diff --git a/scrub/inodes.c b/scrub/inodes.c
index ffe7eb3344..78f0914b8d 100644
--- a/scrub/inodes.c
+++ b/scrub/inodes.c
@@ -163,7 +163,7 @@ alloc_ichunk(
 	return 0;
 }
 
-int
+static int
 render_ino_from_bulkstat(
 	struct scrub_ctx	*ctx,
 	char			*buf,


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/7] misc: add missing includes
  2022-11-09  2:05 ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Darrick J. Wong
  2022-11-09  2:05   ` [PATCH 1/7] libxfs: consume the xfs_warn mountpoint argument Darrick J. Wong
  2022-11-09  2:05   ` [PATCH 2/7] misc: add static to various sourcefile-local functions Darrick J. Wong
@ 2022-11-09  2:05   ` Darrick J. Wong
  2022-11-09  2:05   ` [PATCH 4/7] xfs_db: fix octal conversion logic Darrick J. Wong
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Darrick J. Wong @ 2022-11-09  2:05 UTC (permalink / raw)
  To: cem, djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

Add missing #include directives so that the compiler can typecheck
functions against their declarations.  IOWs, -Wmissing-declarations
found some things.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 libfrog/linux.c |    1 +
 libxfs/util.c   |    1 +
 2 files changed, 2 insertions(+)


diff --git a/libfrog/linux.c b/libfrog/linux.c
index a45d99ab5b..0d9bd355fc 100644
--- a/libfrog/linux.c
+++ b/libfrog/linux.c
@@ -12,6 +12,7 @@
 #include "platform_defs.h"
 #include "xfs.h"
 #include "init.h"
+#include "libfrog/platform.h"
 
 extern char *progname;
 static int max_block_alignment;
diff --git a/libxfs/util.c b/libxfs/util.c
index a41d50c4a7..6525f63de0 100644
--- a/libxfs/util.c
+++ b/libxfs/util.c
@@ -28,6 +28,7 @@
 #include "xfs_da_format.h"
 #include "xfs_da_btree.h"
 #include "xfs_dir2_priv.h"
+#include "xfs_health.h"
 
 /*
  * Calculate the worst case log unit reservation for a given superblock


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/7] xfs_db: fix octal conversion logic
  2022-11-09  2:05 ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Darrick J. Wong
                     ` (2 preceding siblings ...)
  2022-11-09  2:05   ` [PATCH 3/7] misc: add missing includes Darrick J. Wong
@ 2022-11-09  2:05   ` Darrick J. Wong
  2022-11-09  2:05   ` [PATCH 5/7] xfs_db: fix printing of reverse mapping record blockcounts Darrick J. Wong
                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Darrick J. Wong @ 2022-11-09  2:05 UTC (permalink / raw)
  To: cem, djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

Fix the backwards boolean logic here, which results in weird behavior.

# xfs_db -x -c /dev/sda
xfs_db> print fname
fname = "\000\000\000\000\000\000\000\000\000\000\000\000"
xfs_db> write fname "mo\0h5o"
fname = "mo\005o\000\000\000\000\000\000\000\000"
xfs_db> print fname
fname = "mo\005o\000\000\000\000\000\000\000\000"

Notice that we passed in octal-zero, 'h', '5', 'o', but the fs label is
set to octal-5, 'o' because of the incorrect loop logic.  -Wlogical-op
found this one.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 db/write.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


diff --git a/db/write.c b/db/write.c
index 70cb0518d0..6c67e839a9 100644
--- a/db/write.c
+++ b/db/write.c
@@ -479,7 +479,7 @@ convert_oct(
 		if (arg[count] == '\0')
 			break;
 
-		if ((arg[count] < '0') && (arg[count] > '7'))
+		if ((arg[count] < '0') || (arg[count] > '7'))
 			break;
 	}
 
@@ -553,7 +553,7 @@ convert_arg(
 
 			/* do octal conversion */
 			if (*ostr == '\\') {
-				if (*(ostr + 1) >= '0' || *(ostr + 1) <= '7') {
+				if (*(ostr + 1) >= '0' && *(ostr + 1) <= '7') {
 					ret = convert_oct(ostr + 1, &octval);
 					*rbuf++ = octval;
 					ostr += ret + 1;


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/7] xfs_db: fix printing of reverse mapping record blockcounts
  2022-11-09  2:05 ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Darrick J. Wong
                     ` (3 preceding siblings ...)
  2022-11-09  2:05   ` [PATCH 4/7] xfs_db: fix octal conversion logic Darrick J. Wong
@ 2022-11-09  2:05   ` Darrick J. Wong
  2022-11-09  2:05   ` [PATCH 6/7] xfs_repair: don't crash on unknown inode parents in dry run mode Darrick J. Wong
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Darrick J. Wong @ 2022-11-09  2:05 UTC (permalink / raw)
  To: cem, djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

FLDT_EXTLEN is the correct type for a 32-bit block count within an AG;
FLDT_REXTLEN is the type for a 21-bit file mapping block count.  This
code should have been using the first type, not the second.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 db/btblock.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/db/btblock.c b/db/btblock.c
index 24c6566980..c563fb0389 100644
--- a/db/btblock.c
+++ b/db/btblock.c
@@ -727,7 +727,7 @@ const field_t	rmapbt_key_flds[] = {
 
 const field_t	rmapbt_rec_flds[] = {
 	{ "startblock", FLDT_AGBLOCK, OI(RMAPBT_STARTBLOCK_BITOFF), C1, 0, TYP_DATA },
-	{ "blockcount", FLDT_REXTLEN, OI(RMAPBT_BLOCKCOUNT_BITOFF), C1, 0, TYP_NONE },
+	{ "blockcount", FLDT_EXTLEN, OI(RMAPBT_BLOCKCOUNT_BITOFF), C1, 0, TYP_NONE },
 	{ "owner", FLDT_INT64D, OI(RMAPBT_OWNER_BITOFF), C1, 0, TYP_NONE },
 	{ "offset", FLDT_RFILEOFFD, OI(RMAPBT_OFFSET_BITOFF), C1, 0, TYP_NONE },
 	{ "extentflag", FLDT_REXTFLG, OI(RMAPBT_EXNTFLAG_BITOFF), C1, 0,


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/7] xfs_repair: don't crash on unknown inode parents in dry run mode
  2022-11-09  2:05 ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Darrick J. Wong
                     ` (4 preceding siblings ...)
  2022-11-09  2:05   ` [PATCH 5/7] xfs_db: fix printing of reverse mapping record blockcounts Darrick J. Wong
@ 2022-11-09  2:05   ` Darrick J. Wong
  2022-11-09  2:05   ` [PATCH 7/7] xfs_repair: retain superblock buffer to avoid write hook deadlock Darrick J. Wong
  2022-11-18 14:46   ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Carlos Maiolino
  7 siblings, 0 replies; 12+ messages in thread
From: Darrick J. Wong @ 2022-11-09  2:05 UTC (permalink / raw)
  To: cem, djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

Fuzz testing of directory block headers exposed a debug assertion vector
in xfs_repair.  In normal (aka fixit) mode, if a single-block directory
has a totally trashed block, repair will zap the entire directory.
Phase 4 ignores any dirents pointing to the zapped directory, phase 6
ignores the freed directory, and everything is good.

However, in dry run mode, we don't actually free the inode.  Phase 4
still ignores any dirents pointing to the zapped directory, but phase 6
thinks the inode is still live and tries to walk it.  xfs_repair doesn't
know of any parents for the zapped directory and so trips the assertion.

The assertion is critical for fixit mode because we need all the parent
information to ensure consistency of the directory tree.  In dry run
mode we don't care, because we only have to print inconsistencies and
return 1.  Worse yet, (our) customers file bugs when xfs_repair crashes
during a -n scan, so this will generate support calls.

Make everyone's life easier by downgrading the assertion to a warning if
we're running in dry run mode.

Found by fuzzing bhdr.hdr.bno = zeroes in xfs/471.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 repair/phase6.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)


diff --git a/repair/phase6.c b/repair/phase6.c
index d8b23ba528..fefb9755f5 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -1836,7 +1836,14 @@ longform_dir2_entry_check_data(
 			continue;
 		}
 		parent = get_inode_parent(irec, ino_offset);
-		ASSERT(parent != 0);
+		if (parent == 0) {
+			if (no_modify)
+				do_warn(
+ _("unknown parent for inode %" PRIu64 "\n"),
+						inum);
+			else
+				ASSERT(parent != 0);
+		}
 		junkit = 0;
 		/*
 		 * bump up the link counts in parent and child


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 7/7] xfs_repair: retain superblock buffer to avoid write hook deadlock
  2022-11-09  2:05 ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Darrick J. Wong
                     ` (5 preceding siblings ...)
  2022-11-09  2:05   ` [PATCH 6/7] xfs_repair: don't crash on unknown inode parents in dry run mode Darrick J. Wong
@ 2022-11-09  2:05   ` Darrick J. Wong
  2022-11-18 14:45     ` Carlos Maiolino
  2022-11-18 14:46   ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Carlos Maiolino
  7 siblings, 1 reply; 12+ messages in thread
From: Darrick J. Wong @ 2022-11-09  2:05 UTC (permalink / raw)
  To: cem, djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

Every now and then I experience the following deadlock in xfs_repair
when I'm running the offline repair fuzz tests:

#0  futex_wait (private=0, expected=2, futex_word=0x55555566df70) at ../sysdeps/nptl/futex-internal.h:146
#1  __GI___lll_lock_wait (futex=futex@entry=0x55555566df70, private=0) at ./nptl/lowlevellock.c:49
#2  lll_mutex_lock_optimized (mutex=0x55555566df70) at ./nptl/pthread_mutex_lock.c:48
#3  ___pthread_mutex_lock (mutex=mutex@entry=0x55555566df70) at ./nptl/pthread_mutex_lock.c:93
#4  cache_shake (cache=cache@entry=0x55555566de60, priority=priority@entry=2, purge=purge@entry=false) at cache.c:231
#5  cache_node_get (cache=cache@entry=0x55555566de60, key=key@entry=0x7fffe55e01b0, nodep=nodep@entry=0x7fffe55e0168) at cache.c:452
#6  __cache_lookup (key=key@entry=0x7fffe55e01b0, flags=0, bpp=bpp@entry=0x7fffe55e0228) at rdwr.c:405
#7  libxfs_getbuf_flags (btp=0x55555566de00, blkno=0, len=<optimized out>, flags=<optimized out>, bpp=0x7fffe55e0228) at rdwr.c:457
#8  libxfs_buf_read_map (btp=0x55555566de00, map=map@entry=0x7fffe55e0280, nmaps=nmaps@entry=1, flags=flags@entry=0, bpp=bpp@entry=0x7fffe55e0278, ops=0x5555556233e0 <xfs_sb_buf_ops>)
    at rdwr.c:704
#9  libxfs_buf_read (ops=<optimized out>, bpp=0x7fffe55e0278, flags=0, numblks=<optimized out>, blkno=0, target=<optimized out>)
    at /storage/home/djwong/cdev/work/xfsprogs/build-x86_64/libxfs/libxfs_io.h:195
#10 libxfs_getsb (mp=mp@entry=0x7fffffffd690) at rdwr.c:162
#11 force_needsrepair (mp=0x7fffffffd690) at xfs_repair.c:924
#12 repair_capture_writeback (bp=<optimized out>) at xfs_repair.c:1000
#13 libxfs_bwrite (bp=0x7fffe011e530) at rdwr.c:869
#14 cache_shake (cache=cache@entry=0x55555566de60, priority=priority@entry=2, purge=purge@entry=false) at cache.c:240
#15 cache_node_get (cache=cache@entry=0x55555566de60, key=key@entry=0x7fffe55e0470, nodep=nodep@entry=0x7fffe55e0428) at cache.c:452
#16 __cache_lookup (key=key@entry=0x7fffe55e0470, flags=1, bpp=bpp@entry=0x7fffe55e0538) at rdwr.c:405
#17 libxfs_getbuf_flags (btp=0x55555566de00, blkno=12736, len=<optimized out>, flags=<optimized out>, bpp=0x7fffe55e0538) at rdwr.c:457
#18 __libxfs_buf_get_map (btp=<optimized out>, map=map@entry=0x7fffe55e05b0, nmaps=<optimized out>, flags=flags@entry=1, bpp=bpp@entry=0x7fffe55e0538) at rdwr.c:501
#19 libxfs_buf_get_map (btp=<optimized out>, map=map@entry=0x7fffe55e05b0, nmaps=<optimized out>, flags=flags@entry=1, bpp=bpp@entry=0x7fffe55e0538) at rdwr.c:525
#20 pf_queue_io (args=args@entry=0x5555556722c0, map=map@entry=0x7fffe55e05b0, nmaps=<optimized out>, flag=flag@entry=11) at prefetch.c:124
#21 pf_read_bmbt_reclist (args=0x5555556722c0, rp=<optimized out>, numrecs=78) at prefetch.c:220
#22 pf_scan_lbtree (dbno=dbno@entry=1211, level=level@entry=1, isadir=isadir@entry=1, args=args@entry=0x5555556722c0, func=0x55555557f240 <pf_scanfunc_bmap>) at prefetch.c:298
#23 pf_read_btinode (isadir=1, dino=<optimized out>, args=0x5555556722c0) at prefetch.c:385
#24 pf_read_inode_dirs (args=args@entry=0x5555556722c0, bp=bp@entry=0x7fffdc023790) at prefetch.c:459
#25 pf_read_inode_dirs (bp=<optimized out>, args=0x5555556722c0) at prefetch.c:411
#26 pf_batch_read (args=args@entry=0x5555556722c0, which=which@entry=PF_PRIMARY, buf=buf@entry=0x7fffd001d000) at prefetch.c:609
#27 pf_io_worker (param=0x5555556722c0) at prefetch.c:673
#28 start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#29 clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

From this stack trace, we see that xfs_repair's prefetch module is
getting some xfs_buf objects ahead of initiating a read (#19).  The
buffer cache has hit its limit, so it calls cache_shake (#14) to free
some unused xfs_bufs.  The buffer it finds is a dirty buffer, so it
calls libxfs_bwrite to flush it out to disk, which in turn invokes the
buffer write hook that xfs_repair set up in 3b7667cb to mark the ondisk
filesystem's superblock as NEEDSREPAIR until repair actually completes.

Unfortunately, the NEEDSREPAIR handler itself needs to grab the
superblock buffer, so it makes another call into the buffer cache (#9),
which sees that the cache is full and tries to shake it(#4).  Hence we
deadlock on cm_mutex because shaking is not reentrant.

Fix this by retaining a reference to the superblock buffer when possible
so that the writeback hook doesn't have to access the buffer cache to
set NEEDSREPAIR.

Fixes: 3b7667cb ("xfs_repair: set NEEDSREPAIR the first time we write to a filesystem")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 libxfs/libxfs_api_defs.h |    2 +
 libxfs/libxfs_io.h       |    1 +
 libxfs/rdwr.c            |    8 +++++
 repair/phase2.c          |    8 +++++
 repair/protos.h          |    1 +
 repair/xfs_repair.c      |   75 ++++++++++++++++++++++++++++++++++++++++------
 6 files changed, 86 insertions(+), 9 deletions(-)


diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
index 2716a731bf..f8efcce777 100644
--- a/libxfs/libxfs_api_defs.h
+++ b/libxfs/libxfs_api_defs.h
@@ -53,9 +53,11 @@
 #define xfs_buf_delwri_submit		libxfs_buf_delwri_submit
 #define xfs_buf_get			libxfs_buf_get
 #define xfs_buf_get_uncached		libxfs_buf_get_uncached
+#define xfs_buf_lock			libxfs_buf_lock
 #define xfs_buf_read			libxfs_buf_read
 #define xfs_buf_read_uncached		libxfs_buf_read_uncached
 #define xfs_buf_relse			libxfs_buf_relse
+#define xfs_buf_unlock			libxfs_buf_unlock
 #define xfs_bunmapi			libxfs_bunmapi
 #define xfs_bwrite			libxfs_bwrite
 #define xfs_calc_dquots_per_chunk	libxfs_calc_dquots_per_chunk
diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 9c0e2704d1..fae8642720 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -226,6 +226,7 @@ xfs_buf_hold(struct xfs_buf *bp)
 }
 
 void xfs_buf_lock(struct xfs_buf *bp);
+void xfs_buf_unlock(struct xfs_buf *bp);
 
 int libxfs_buf_get_uncached(struct xfs_buftarg *targ, size_t bblen, int flags,
 		struct xfs_buf **bpp);
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 20e0793c2f..d5aad3ea21 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -384,6 +384,14 @@ xfs_buf_lock(
 		pthread_mutex_lock(&bp->b_lock);
 }
 
+void
+xfs_buf_unlock(
+	struct xfs_buf	*bp)
+{
+	if (use_xfs_buf_lock)
+		pthread_mutex_unlock(&bp->b_lock);
+}
+
 static int
 __cache_lookup(
 	struct xfs_bufkey	*key,
diff --git a/repair/phase2.c b/repair/phase2.c
index 56a39bb456..2ada95aefd 100644
--- a/repair/phase2.c
+++ b/repair/phase2.c
@@ -370,6 +370,14 @@ phase2(
 	} else
 		do_log(_("Phase 2 - using internal log\n"));
 
+	/*
+	 * Now that we've set up the buffer cache the way we want it, try to
+	 * grab our own reference to the primary sb so that the hooks will not
+	 * have to call out to the buffer cache.
+	 */
+	if (mp->m_buf_writeback_fn)
+		retain_primary_sb(mp);
+
 	/* Zero log if applicable */
 	do_log(_("        - zero log...\n"));
 
diff --git a/repair/protos.h b/repair/protos.h
index 03ebae1413..83e471ff2a 100644
--- a/repair/protos.h
+++ b/repair/protos.h
@@ -16,6 +16,7 @@ int	get_sb(xfs_sb_t			*sbp,
 		xfs_off_t			off,
 		int			size,
 		xfs_agnumber_t		agno);
+int retain_primary_sb(struct xfs_mount *mp);
 void	write_primary_sb(xfs_sb_t	*sbp,
 			int		size);
 
diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index 871b428d7d..ff29bea974 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -749,6 +749,63 @@ check_fs_vs_host_sectsize(
 	}
 }
 
+/*
+ * If we set up a writeback function to set NEEDSREPAIR while the filesystem is
+ * dirty, there's a chance that calling libxfs_getsb could deadlock the buffer
+ * cache while trying to get the primary sb buffer if the first non-sb write to
+ * the filesystem is the result of a cache shake.  Retain a reference to the
+ * primary sb buffer to avoid all that.
+ */
+static struct xfs_buf *primary_sb_bp;	/* buffer for superblock */
+
+int
+retain_primary_sb(
+	struct xfs_mount	*mp)
+{
+	int			error;
+
+	error = -libxfs_buf_read(mp->m_ddev_targp, XFS_SB_DADDR,
+			XFS_FSS_TO_BB(mp, 1), 0, &primary_sb_bp,
+			&xfs_sb_buf_ops);
+	if (error)
+		return error;
+
+	libxfs_buf_unlock(primary_sb_bp);
+	return 0;
+}
+
+static void
+drop_primary_sb(void)
+{
+	if (!primary_sb_bp)
+		return;
+
+	libxfs_buf_lock(primary_sb_bp);
+	libxfs_buf_relse(primary_sb_bp);
+	primary_sb_bp = NULL;
+}
+
+static int
+get_primary_sb(
+	struct xfs_mount	*mp,
+	struct xfs_buf		**bpp)
+{
+	int			error;
+
+	*bpp = NULL;
+
+	if (!primary_sb_bp) {
+		error = retain_primary_sb(mp);
+		if (error)
+			return error;
+	}
+
+	libxfs_buf_lock(primary_sb_bp);
+	xfs_buf_hold(primary_sb_bp);
+	*bpp = primary_sb_bp;
+	return 0;
+}
+
 /* Clear needsrepair after a successful repair run. */
 static void
 clear_needsrepair(
@@ -769,15 +826,14 @@ clear_needsrepair(
 		do_warn(
 	_("Cannot clear needsrepair due to flush failure, err=%d.\n"),
 			error);
-		return;
+		goto drop;
 	}
 
 	/* Clear needsrepair from the superblock. */
-	bp = libxfs_getsb(mp);
-	if (!bp || bp->b_error) {
+	error = get_primary_sb(mp, &bp);
+	if (error) {
 		do_warn(
-	_("Cannot clear needsrepair from primary super, err=%d.\n"),
-			bp ? bp->b_error : ENOMEM);
+	_("Cannot clear needsrepair from primary super, err=%d.\n"), error);
 	} else {
 		mp->m_sb.sb_features_incompat &=
 				~XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR;
@@ -786,6 +842,8 @@ clear_needsrepair(
 	}
 	if (bp)
 		libxfs_buf_relse(bp);
+drop:
+	drop_primary_sb();
 }
 
 static void
@@ -808,11 +866,10 @@ force_needsrepair(
 	    xfs_sb_version_needsrepair(&mp->m_sb))
 		return;
 
-	bp = libxfs_getsb(mp);
-	if (!bp || bp->b_error) {
+	error = get_primary_sb(mp, &bp);
+	if (error) {
 		do_log(
-	_("couldn't get superblock to set needsrepair, err=%d\n"),
-				bp ? bp->b_error : ENOMEM);
+	_("couldn't get superblock to set needsrepair, err=%d\n"), error);
 	} else {
 		/*
 		 * It's possible that we need to set NEEDSREPAIR before we've


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 7/7] xfs_repair: retain superblock buffer to avoid write hook deadlock
  2022-11-09  2:05   ` [PATCH 7/7] xfs_repair: retain superblock buffer to avoid write hook deadlock Darrick J. Wong
@ 2022-11-18 14:45     ` Carlos Maiolino
  2022-11-21 17:05       ` Darrick J. Wong
  0 siblings, 1 reply; 12+ messages in thread
From: Carlos Maiolino @ 2022-11-18 14:45 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

> Fix this by retaining a reference to the superblock buffer when possible
> so that the writeback hook doesn't have to access the buffer cache to
> set NEEDSREPAIR.

This is the same one you sent for 5.19 that opened a discussion between
retaining it at specific points, or at 'mount' time, wasn't it? Anyway, I think
this is ok, we can try to do it at mount time in the future.


> 
> Fixes: 3b7667cb ("xfs_repair: set NEEDSREPAIR the first time we write to a filesystem")
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  libxfs/libxfs_api_defs.h |    2 +
>  libxfs/libxfs_io.h       |    1 +
>  libxfs/rdwr.c            |    8 +++++
>  repair/phase2.c          |    8 +++++
>  repair/protos.h          |    1 +
>  repair/xfs_repair.c      |   75 ++++++++++++++++++++++++++++++++++++++++------
>  6 files changed, 86 insertions(+), 9 deletions(-)
> 
> 
> diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
> index 2716a731bf..f8efcce777 100644
> --- a/libxfs/libxfs_api_defs.h
> +++ b/libxfs/libxfs_api_defs.h
> @@ -53,9 +53,11 @@
>  #define xfs_buf_delwri_submit		libxfs_buf_delwri_submit
>  #define xfs_buf_get			libxfs_buf_get
>  #define xfs_buf_get_uncached		libxfs_buf_get_uncached
> +#define xfs_buf_lock			libxfs_buf_lock
>  #define xfs_buf_read			libxfs_buf_read
>  #define xfs_buf_read_uncached		libxfs_buf_read_uncached
>  #define xfs_buf_relse			libxfs_buf_relse
> +#define xfs_buf_unlock			libxfs_buf_unlock
>  #define xfs_bunmapi			libxfs_bunmapi
>  #define xfs_bwrite			libxfs_bwrite
>  #define xfs_calc_dquots_per_chunk	libxfs_calc_dquots_per_chunk
> diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
> index 9c0e2704d1..fae8642720 100644
> --- a/libxfs/libxfs_io.h
> +++ b/libxfs/libxfs_io.h
> @@ -226,6 +226,7 @@ xfs_buf_hold(struct xfs_buf *bp)
>  }
> 
>  void xfs_buf_lock(struct xfs_buf *bp);
> +void xfs_buf_unlock(struct xfs_buf *bp);
> 
>  int libxfs_buf_get_uncached(struct xfs_buftarg *targ, size_t bblen, int flags,
>  		struct xfs_buf **bpp);
> diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
> index 20e0793c2f..d5aad3ea21 100644
> --- a/libxfs/rdwr.c
> +++ b/libxfs/rdwr.c
> @@ -384,6 +384,14 @@ xfs_buf_lock(
>  		pthread_mutex_lock(&bp->b_lock);
>  }
> 
> +void
> +xfs_buf_unlock(
> +	struct xfs_buf	*bp)
> +{
> +	if (use_xfs_buf_lock)
> +		pthread_mutex_unlock(&bp->b_lock);
> +}
> +
>  static int
>  __cache_lookup(
>  	struct xfs_bufkey	*key,
> diff --git a/repair/phase2.c b/repair/phase2.c
> index 56a39bb456..2ada95aefd 100644
> --- a/repair/phase2.c
> +++ b/repair/phase2.c
> @@ -370,6 +370,14 @@ phase2(
>  	} else
>  		do_log(_("Phase 2 - using internal log\n"));
> 
> +	/*
> +	 * Now that we've set up the buffer cache the way we want it, try to
> +	 * grab our own reference to the primary sb so that the hooks will not
> +	 * have to call out to the buffer cache.
> +	 */
> +	if (mp->m_buf_writeback_fn)
> +		retain_primary_sb(mp);
> +
>  	/* Zero log if applicable */
>  	do_log(_("        - zero log...\n"));
> 
> diff --git a/repair/protos.h b/repair/protos.h
> index 03ebae1413..83e471ff2a 100644
> --- a/repair/protos.h
> +++ b/repair/protos.h
> @@ -16,6 +16,7 @@ int	get_sb(xfs_sb_t			*sbp,
>  		xfs_off_t			off,
>  		int			size,
>  		xfs_agnumber_t		agno);
> +int retain_primary_sb(struct xfs_mount *mp);
>  void	write_primary_sb(xfs_sb_t	*sbp,
>  			int		size);
> 
> diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
> index 871b428d7d..ff29bea974 100644
> --- a/repair/xfs_repair.c
> +++ b/repair/xfs_repair.c
> @@ -749,6 +749,63 @@ check_fs_vs_host_sectsize(
>  	}
>  }
> 
> +/*
> + * If we set up a writeback function to set NEEDSREPAIR while the filesystem is
> + * dirty, there's a chance that calling libxfs_getsb could deadlock the buffer
> + * cache while trying to get the primary sb buffer if the first non-sb write to
> + * the filesystem is the result of a cache shake.  Retain a reference to the
> + * primary sb buffer to avoid all that.
> + */
> +static struct xfs_buf *primary_sb_bp;	/* buffer for superblock */
> +
> +int
> +retain_primary_sb(
> +	struct xfs_mount	*mp)
> +{
> +	int			error;
> +
> +	error = -libxfs_buf_read(mp->m_ddev_targp, XFS_SB_DADDR,
> +			XFS_FSS_TO_BB(mp, 1), 0, &primary_sb_bp,
> +			&xfs_sb_buf_ops);
> +	if (error)
> +		return error;
> +
> +	libxfs_buf_unlock(primary_sb_bp);
> +	return 0;
> +}
> +
> +static void
> +drop_primary_sb(void)
> +{
> +	if (!primary_sb_bp)
> +		return;
> +
> +	libxfs_buf_lock(primary_sb_bp);
> +	libxfs_buf_relse(primary_sb_bp);
> +	primary_sb_bp = NULL;
> +}
> +
> +static int
> +get_primary_sb(
> +	struct xfs_mount	*mp,
> +	struct xfs_buf		**bpp)
> +{
> +	int			error;
> +
> +	*bpp = NULL;
> +
> +	if (!primary_sb_bp) {
> +		error = retain_primary_sb(mp);
> +		if (error)
> +			return error;
> +	}
> +
> +	libxfs_buf_lock(primary_sb_bp);
> +	xfs_buf_hold(primary_sb_bp);
> +	*bpp = primary_sb_bp;
> +	return 0;
> +}
> +
>  /* Clear needsrepair after a successful repair run. */
>  static void
>  clear_needsrepair(
> @@ -769,15 +826,14 @@ clear_needsrepair(
>  		do_warn(
>  	_("Cannot clear needsrepair due to flush failure, err=%d.\n"),
>  			error);
> -		return;
> +		goto drop;
>  	}
> 
>  	/* Clear needsrepair from the superblock. */
> -	bp = libxfs_getsb(mp);
> -	if (!bp || bp->b_error) {
> +	error = get_primary_sb(mp, &bp);
> +	if (error) {
>  		do_warn(
> -	_("Cannot clear needsrepair from primary super, err=%d.\n"),
> -			bp ? bp->b_error : ENOMEM);
> +	_("Cannot clear needsrepair from primary super, err=%d.\n"), error);
>  	} else {
>  		mp->m_sb.sb_features_incompat &=
>  				~XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR;
> @@ -786,6 +842,8 @@ clear_needsrepair(
>  	}
>  	if (bp)
>  		libxfs_buf_relse(bp);
> +drop:
> +	drop_primary_sb();
>  }
> 
>  static void
> @@ -808,11 +866,10 @@ force_needsrepair(
>  	    xfs_sb_version_needsrepair(&mp->m_sb))
>  		return;
> 
> -	bp = libxfs_getsb(mp);
> -	if (!bp || bp->b_error) {
> +	error = get_primary_sb(mp, &bp);
> +	if (error) {
>  		do_log(
> -	_("couldn't get superblock to set needsrepair, err=%d\n"),
> -				bp ? bp->b_error : ENOMEM);
> +	_("couldn't get superblock to set needsrepair, err=%d\n"), error);
>  	} else {
>  		/*
>  		 * It's possible that we need to set NEEDSREPAIR before we've
> 

-- 
Carlos Maiolino

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHSET 0/7] xfsprogs: random fixes for 6.0
  2022-11-09  2:05 ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Darrick J. Wong
                     ` (6 preceding siblings ...)
  2022-11-09  2:05   ` [PATCH 7/7] xfs_repair: retain superblock buffer to avoid write hook deadlock Darrick J. Wong
@ 2022-11-18 14:46   ` Carlos Maiolino
  2022-11-21 17:06     ` Darrick J. Wong
  7 siblings, 1 reply; 12+ messages in thread
From: Carlos Maiolino @ 2022-11-18 14:46 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Tue, Nov 08, 2022 at 06:05:00PM -0800, Darrick J. Wong wrote:
> Hi all,
> 
> This is a rollup of all the random fixes I've collected for xfsprogs
> 6.0.  At this point it's just an assorted collection, no particular
> theme.  Many of them are leftovers from the last posting.
> 
> If you're going to start using this mess, you probably ought to just
> pull from my git trees, which are linked below.
> 
> This is an extraordinary way to destroy everything.  Enjoy!
> Comments and questions are, as always, welcome.
> 
> --D
> 
> xfsprogs git tree:
> https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=xfsprogs-fixes-6.0
> ---
>  db/btblock.c             |    2 +
>  db/namei.c               |    2 +
>  db/write.c               |    4 +-
>  io/pread.c               |    2 +
>  libfrog/linux.c          |    1 +
>  libxfs/libxfs_api_defs.h |    2 +
>  libxfs/libxfs_io.h       |    1 +
>  libxfs/libxfs_priv.h     |    2 +
>  libxfs/rdwr.c            |    8 +++++
>  libxfs/util.c            |    1 +
>  mkfs/xfs_mkfs.c          |    2 +
>  repair/phase2.c          |    8 +++++
>  repair/phase6.c          |    9 +++++
>  repair/protos.h          |    1 +
>  repair/xfs_repair.c      |   77 ++++++++++++++++++++++++++++++++++++++++------
>  scrub/inodes.c           |    2 +
>  16 files changed, 105 insertions(+), 19 deletions(-)
> 

The whole series looks good. Will test

Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>

-- 
Carlos Maiolino

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 7/7] xfs_repair: retain superblock buffer to avoid write hook deadlock
  2022-11-18 14:45     ` Carlos Maiolino
@ 2022-11-21 17:05       ` Darrick J. Wong
  0 siblings, 0 replies; 12+ messages in thread
From: Darrick J. Wong @ 2022-11-21 17:05 UTC (permalink / raw)
  To: Carlos Maiolino; +Cc: linux-xfs

On Fri, Nov 18, 2022 at 03:45:03PM +0100, Carlos Maiolino wrote:
> > Fix this by retaining a reference to the superblock buffer when possible
> > so that the writeback hook doesn't have to access the buffer cache to
> > set NEEDSREPAIR.
> 
> This is the same one you sent for 5.19 that opened a discussion between
> retaining it at specific points, or at 'mount' time, wasn't it? Anyway, I think
> this is ok, we can try to do it at mount time in the future.

Correct, it hasn't changed since then.

--D

> 
> > 
> > Fixes: 3b7667cb ("xfs_repair: set NEEDSREPAIR the first time we write to a filesystem")
> > Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> > ---
> >  libxfs/libxfs_api_defs.h |    2 +
> >  libxfs/libxfs_io.h       |    1 +
> >  libxfs/rdwr.c            |    8 +++++
> >  repair/phase2.c          |    8 +++++
> >  repair/protos.h          |    1 +
> >  repair/xfs_repair.c      |   75 ++++++++++++++++++++++++++++++++++++++++------
> >  6 files changed, 86 insertions(+), 9 deletions(-)
> > 
> > 
> > diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
> > index 2716a731bf..f8efcce777 100644
> > --- a/libxfs/libxfs_api_defs.h
> > +++ b/libxfs/libxfs_api_defs.h
> > @@ -53,9 +53,11 @@
> >  #define xfs_buf_delwri_submit		libxfs_buf_delwri_submit
> >  #define xfs_buf_get			libxfs_buf_get
> >  #define xfs_buf_get_uncached		libxfs_buf_get_uncached
> > +#define xfs_buf_lock			libxfs_buf_lock
> >  #define xfs_buf_read			libxfs_buf_read
> >  #define xfs_buf_read_uncached		libxfs_buf_read_uncached
> >  #define xfs_buf_relse			libxfs_buf_relse
> > +#define xfs_buf_unlock			libxfs_buf_unlock
> >  #define xfs_bunmapi			libxfs_bunmapi
> >  #define xfs_bwrite			libxfs_bwrite
> >  #define xfs_calc_dquots_per_chunk	libxfs_calc_dquots_per_chunk
> > diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
> > index 9c0e2704d1..fae8642720 100644
> > --- a/libxfs/libxfs_io.h
> > +++ b/libxfs/libxfs_io.h
> > @@ -226,6 +226,7 @@ xfs_buf_hold(struct xfs_buf *bp)
> >  }
> > 
> >  void xfs_buf_lock(struct xfs_buf *bp);
> > +void xfs_buf_unlock(struct xfs_buf *bp);
> > 
> >  int libxfs_buf_get_uncached(struct xfs_buftarg *targ, size_t bblen, int flags,
> >  		struct xfs_buf **bpp);
> > diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
> > index 20e0793c2f..d5aad3ea21 100644
> > --- a/libxfs/rdwr.c
> > +++ b/libxfs/rdwr.c
> > @@ -384,6 +384,14 @@ xfs_buf_lock(
> >  		pthread_mutex_lock(&bp->b_lock);
> >  }
> > 
> > +void
> > +xfs_buf_unlock(
> > +	struct xfs_buf	*bp)
> > +{
> > +	if (use_xfs_buf_lock)
> > +		pthread_mutex_unlock(&bp->b_lock);
> > +}
> > +
> >  static int
> >  __cache_lookup(
> >  	struct xfs_bufkey	*key,
> > diff --git a/repair/phase2.c b/repair/phase2.c
> > index 56a39bb456..2ada95aefd 100644
> > --- a/repair/phase2.c
> > +++ b/repair/phase2.c
> > @@ -370,6 +370,14 @@ phase2(
> >  	} else
> >  		do_log(_("Phase 2 - using internal log\n"));
> > 
> > +	/*
> > +	 * Now that we've set up the buffer cache the way we want it, try to
> > +	 * grab our own reference to the primary sb so that the hooks will not
> > +	 * have to call out to the buffer cache.
> > +	 */
> > +	if (mp->m_buf_writeback_fn)
> > +		retain_primary_sb(mp);
> > +
> >  	/* Zero log if applicable */
> >  	do_log(_("        - zero log...\n"));
> > 
> > diff --git a/repair/protos.h b/repair/protos.h
> > index 03ebae1413..83e471ff2a 100644
> > --- a/repair/protos.h
> > +++ b/repair/protos.h
> > @@ -16,6 +16,7 @@ int	get_sb(xfs_sb_t			*sbp,
> >  		xfs_off_t			off,
> >  		int			size,
> >  		xfs_agnumber_t		agno);
> > +int retain_primary_sb(struct xfs_mount *mp);
> >  void	write_primary_sb(xfs_sb_t	*sbp,
> >  			int		size);
> > 
> > diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
> > index 871b428d7d..ff29bea974 100644
> > --- a/repair/xfs_repair.c
> > +++ b/repair/xfs_repair.c
> > @@ -749,6 +749,63 @@ check_fs_vs_host_sectsize(
> >  	}
> >  }
> > 
> > +/*
> > + * If we set up a writeback function to set NEEDSREPAIR while the filesystem is
> > + * dirty, there's a chance that calling libxfs_getsb could deadlock the buffer
> > + * cache while trying to get the primary sb buffer if the first non-sb write to
> > + * the filesystem is the result of a cache shake.  Retain a reference to the
> > + * primary sb buffer to avoid all that.
> > + */
> > +static struct xfs_buf *primary_sb_bp;	/* buffer for superblock */
> > +
> > +int
> > +retain_primary_sb(
> > +	struct xfs_mount	*mp)
> > +{
> > +	int			error;
> > +
> > +	error = -libxfs_buf_read(mp->m_ddev_targp, XFS_SB_DADDR,
> > +			XFS_FSS_TO_BB(mp, 1), 0, &primary_sb_bp,
> > +			&xfs_sb_buf_ops);
> > +	if (error)
> > +		return error;
> > +
> > +	libxfs_buf_unlock(primary_sb_bp);
> > +	return 0;
> > +}
> > +
> > +static void
> > +drop_primary_sb(void)
> > +{
> > +	if (!primary_sb_bp)
> > +		return;
> > +
> > +	libxfs_buf_lock(primary_sb_bp);
> > +	libxfs_buf_relse(primary_sb_bp);
> > +	primary_sb_bp = NULL;
> > +}
> > +
> > +static int
> > +get_primary_sb(
> > +	struct xfs_mount	*mp,
> > +	struct xfs_buf		**bpp)
> > +{
> > +	int			error;
> > +
> > +	*bpp = NULL;
> > +
> > +	if (!primary_sb_bp) {
> > +		error = retain_primary_sb(mp);
> > +		if (error)
> > +			return error;
> > +	}
> > +
> > +	libxfs_buf_lock(primary_sb_bp);
> > +	xfs_buf_hold(primary_sb_bp);
> > +	*bpp = primary_sb_bp;
> > +	return 0;
> > +}
> > +
> >  /* Clear needsrepair after a successful repair run. */
> >  static void
> >  clear_needsrepair(
> > @@ -769,15 +826,14 @@ clear_needsrepair(
> >  		do_warn(
> >  	_("Cannot clear needsrepair due to flush failure, err=%d.\n"),
> >  			error);
> > -		return;
> > +		goto drop;
> >  	}
> > 
> >  	/* Clear needsrepair from the superblock. */
> > -	bp = libxfs_getsb(mp);
> > -	if (!bp || bp->b_error) {
> > +	error = get_primary_sb(mp, &bp);
> > +	if (error) {
> >  		do_warn(
> > -	_("Cannot clear needsrepair from primary super, err=%d.\n"),
> > -			bp ? bp->b_error : ENOMEM);
> > +	_("Cannot clear needsrepair from primary super, err=%d.\n"), error);
> >  	} else {
> >  		mp->m_sb.sb_features_incompat &=
> >  				~XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR;
> > @@ -786,6 +842,8 @@ clear_needsrepair(
> >  	}
> >  	if (bp)
> >  		libxfs_buf_relse(bp);
> > +drop:
> > +	drop_primary_sb();
> >  }
> > 
> >  static void
> > @@ -808,11 +866,10 @@ force_needsrepair(
> >  	    xfs_sb_version_needsrepair(&mp->m_sb))
> >  		return;
> > 
> > -	bp = libxfs_getsb(mp);
> > -	if (!bp || bp->b_error) {
> > +	error = get_primary_sb(mp, &bp);
> > +	if (error) {
> >  		do_log(
> > -	_("couldn't get superblock to set needsrepair, err=%d\n"),
> > -				bp ? bp->b_error : ENOMEM);
> > +	_("couldn't get superblock to set needsrepair, err=%d\n"), error);
> >  	} else {
> >  		/*
> >  		 * It's possible that we need to set NEEDSREPAIR before we've
> > 
> 
> -- 
> Carlos Maiolino

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHSET 0/7] xfsprogs: random fixes for 6.0
  2022-11-18 14:46   ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Carlos Maiolino
@ 2022-11-21 17:06     ` Darrick J. Wong
  0 siblings, 0 replies; 12+ messages in thread
From: Darrick J. Wong @ 2022-11-21 17:06 UTC (permalink / raw)
  To: Carlos Maiolino; +Cc: linux-xfs

On Fri, Nov 18, 2022 at 03:46:15PM +0100, Carlos Maiolino wrote:
> On Tue, Nov 08, 2022 at 06:05:00PM -0800, Darrick J. Wong wrote:
> > Hi all,
> > 
> > This is a rollup of all the random fixes I've collected for xfsprogs
> > 6.0.  At this point it's just an assorted collection, no particular
> > theme.  Many of them are leftovers from the last posting.
> > 
> > If you're going to start using this mess, you probably ought to just
> > pull from my git trees, which are linked below.
> > 
> > This is an extraordinary way to destroy everything.  Enjoy!
> > Comments and questions are, as always, welcome.
> > 
> > --D
> > 
> > xfsprogs git tree:
> > https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=xfsprogs-fixes-6.0
> > ---
> >  db/btblock.c             |    2 +
> >  db/namei.c               |    2 +
> >  db/write.c               |    4 +-
> >  io/pread.c               |    2 +
> >  libfrog/linux.c          |    1 +
> >  libxfs/libxfs_api_defs.h |    2 +
> >  libxfs/libxfs_io.h       |    1 +
> >  libxfs/libxfs_priv.h     |    2 +
> >  libxfs/rdwr.c            |    8 +++++
> >  libxfs/util.c            |    1 +
> >  mkfs/xfs_mkfs.c          |    2 +
> >  repair/phase2.c          |    8 +++++
> >  repair/phase6.c          |    9 +++++
> >  repair/protos.h          |    1 +
> >  repair/xfs_repair.c      |   77 ++++++++++++++++++++++++++++++++++++++++------
> >  scrub/inodes.c           |    2 +
> >  16 files changed, 105 insertions(+), 19 deletions(-)
> > 
> 
> The whole series looks good. Will test
> 
> Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>

Thank you!

--D

> -- 
> Carlos Maiolino

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-11-21 17:06 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <3bbCi5OklUNOpVog9KVqiGD2TPkUD4x6PJjtZuKJCzP-QYMXvnqh7kZB8Vnp2BnxW6jn-dlyN7DIFoDTnryqNw==@protonmail.internalid>
2022-11-09  2:05 ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Darrick J. Wong
2022-11-09  2:05   ` [PATCH 1/7] libxfs: consume the xfs_warn mountpoint argument Darrick J. Wong
2022-11-09  2:05   ` [PATCH 2/7] misc: add static to various sourcefile-local functions Darrick J. Wong
2022-11-09  2:05   ` [PATCH 3/7] misc: add missing includes Darrick J. Wong
2022-11-09  2:05   ` [PATCH 4/7] xfs_db: fix octal conversion logic Darrick J. Wong
2022-11-09  2:05   ` [PATCH 5/7] xfs_db: fix printing of reverse mapping record blockcounts Darrick J. Wong
2022-11-09  2:05   ` [PATCH 6/7] xfs_repair: don't crash on unknown inode parents in dry run mode Darrick J. Wong
2022-11-09  2:05   ` [PATCH 7/7] xfs_repair: retain superblock buffer to avoid write hook deadlock Darrick J. Wong
2022-11-18 14:45     ` Carlos Maiolino
2022-11-21 17:05       ` Darrick J. Wong
2022-11-18 14:46   ` [PATCHSET 0/7] xfsprogs: random fixes for 6.0 Carlos Maiolino
2022-11-21 17:06     ` Darrick J. Wong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.