linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] xfs: strengthen online checking
@ 2020-06-30 15:41 Darrick J. Wong
  2020-06-30 15:41 ` [PATCH 1/2] xfs: rtbitmap scrubber should verify written extents Darrick J. Wong
  2020-06-30 15:41 ` [PATCH 2/2] xfs: rtbitmap scrubber should check inode size Darrick J. Wong
  0 siblings, 2 replies; 5+ messages in thread
From: Darrick J. Wong @ 2020-06-30 15:41 UTC (permalink / raw)
  To: darrick.wong; +Cc: linux-xfs

Hi all,

This series fixes some missed checks in the realtime bitmap scrubber.
We previously did not check the size of the rtbitmap file, nor did we
actually check that the extent map does not contain holes or unwritten
extents.

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

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=scrub-fixes
---
 fs/xfs/scrub/rtbitmap.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)


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

* [PATCH 1/2] xfs: rtbitmap scrubber should verify written extents
  2020-06-30 15:41 [PATCH 0/2] xfs: strengthen online checking Darrick J. Wong
@ 2020-06-30 15:41 ` Darrick J. Wong
  2020-06-30 21:05   ` Allison Collins
  2020-06-30 15:41 ` [PATCH 2/2] xfs: rtbitmap scrubber should check inode size Darrick J. Wong
  1 sibling, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2020-06-30 15:41 UTC (permalink / raw)
  To: darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Ensure that the realtime bitmap file is backed entirely by written
extents.  No holes, no unwritten blocks, etc.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/scrub/rtbitmap.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)


diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
index c642bc206c41..c777c98c50c3 100644
--- a/fs/xfs/scrub/rtbitmap.c
+++ b/fs/xfs/scrub/rtbitmap.c
@@ -13,6 +13,7 @@
 #include "xfs_trans.h"
 #include "xfs_rtalloc.h"
 #include "xfs_inode.h"
+#include "xfs_bmap.h"
 #include "scrub/scrub.h"
 #include "scrub/common.h"
 
@@ -58,6 +59,41 @@ xchk_rtbitmap_rec(
 	return 0;
 }
 
+/* Make sure the entire rtbitmap file is mapped with written extents. */
+STATIC int
+xchk_rtbitmap_check_extents(
+	struct xfs_scrub	*sc)
+{
+	struct xfs_mount	*mp = sc->mp;
+	struct xfs_bmbt_irec	map;
+	xfs_rtblock_t		off;
+	int			nmap;
+	int			error = 0;
+
+	for (off = 0; off < mp->m_sb.sb_rbmblocks;) {
+		if (xchk_should_terminate(sc, &error) ||
+		    (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
+			break;
+
+		/* Make sure we have a written extent. */
+		nmap = 1;
+		error = xfs_bmapi_read(mp->m_rbmip, off,
+				mp->m_sb.sb_rbmblocks - off, &map, &nmap,
+				XFS_DATA_FORK);
+		if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, off, &error))
+			break;
+
+		if (nmap != 1 || !xfs_bmap_is_written_extent(&map)) {
+			xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, off);
+			break;
+		}
+
+		off += map.br_blockcount;
+	}
+
+	return error;
+}
+
 /* Scrub the realtime bitmap. */
 int
 xchk_rtbitmap(
@@ -70,6 +106,10 @@ xchk_rtbitmap(
 	if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
 		return error;
 
+	error = xchk_rtbitmap_check_extents(sc);
+	if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
+		return error;
+
 	error = xfs_rtalloc_query_all(sc->tp, xchk_rtbitmap_rec, sc);
 	if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, 0, &error))
 		goto out;


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

* [PATCH 2/2] xfs: rtbitmap scrubber should check inode size
  2020-06-30 15:41 [PATCH 0/2] xfs: strengthen online checking Darrick J. Wong
  2020-06-30 15:41 ` [PATCH 1/2] xfs: rtbitmap scrubber should verify written extents Darrick J. Wong
@ 2020-06-30 15:41 ` Darrick J. Wong
  2020-06-30 21:05   ` Allison Collins
  1 sibling, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2020-06-30 15:41 UTC (permalink / raw)
  To: darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Make sure the rtbitmap is large enough to store the entire bitmap.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/scrub/rtbitmap.c |    7 +++++++
 1 file changed, 7 insertions(+)


diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
index c777c98c50c3..76e4ffe0315b 100644
--- a/fs/xfs/scrub/rtbitmap.c
+++ b/fs/xfs/scrub/rtbitmap.c
@@ -101,6 +101,13 @@ xchk_rtbitmap(
 {
 	int			error;
 
+	/* Is the size of the rtbitmap correct? */
+	if (sc->mp->m_rbmip->i_d.di_size !=
+	    XFS_FSB_TO_B(sc->mp, sc->mp->m_sb.sb_rbmblocks)) {
+		xchk_ino_set_corrupt(sc, sc->mp->m_rbmip->i_ino);
+		return 0;
+	}
+
 	/* Invoke the fork scrubber. */
 	error = xchk_metadata_inode_forks(sc);
 	if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))


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

* Re: [PATCH 1/2] xfs: rtbitmap scrubber should verify written extents
  2020-06-30 15:41 ` [PATCH 1/2] xfs: rtbitmap scrubber should verify written extents Darrick J. Wong
@ 2020-06-30 21:05   ` Allison Collins
  0 siblings, 0 replies; 5+ messages in thread
From: Allison Collins @ 2020-06-30 21:05 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs



On 6/30/20 8:41 AM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Ensure that the realtime bitmap file is backed entirely by written
> extents.  No holes, no unwritten blocks, etc.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Ok, makes sense to me
Reviewed-by: Allison Collins <allison.henderson@oracle.com>

> ---
>   fs/xfs/scrub/rtbitmap.c |   40 ++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 40 insertions(+)
> 
> 
> diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
> index c642bc206c41..c777c98c50c3 100644
> --- a/fs/xfs/scrub/rtbitmap.c
> +++ b/fs/xfs/scrub/rtbitmap.c
> @@ -13,6 +13,7 @@
>   #include "xfs_trans.h"
>   #include "xfs_rtalloc.h"
>   #include "xfs_inode.h"
> +#include "xfs_bmap.h"
>   #include "scrub/scrub.h"
>   #include "scrub/common.h"
>   
> @@ -58,6 +59,41 @@ xchk_rtbitmap_rec(
>   	return 0;
>   }
>   
> +/* Make sure the entire rtbitmap file is mapped with written extents. */
> +STATIC int
> +xchk_rtbitmap_check_extents(
> +	struct xfs_scrub	*sc)
> +{
> +	struct xfs_mount	*mp = sc->mp;
> +	struct xfs_bmbt_irec	map;
> +	xfs_rtblock_t		off;
> +	int			nmap;
> +	int			error = 0;
> +
> +	for (off = 0; off < mp->m_sb.sb_rbmblocks;) {
> +		if (xchk_should_terminate(sc, &error) ||
> +		    (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
> +			break;
> +
> +		/* Make sure we have a written extent. */
> +		nmap = 1;
> +		error = xfs_bmapi_read(mp->m_rbmip, off,
> +				mp->m_sb.sb_rbmblocks - off, &map, &nmap,
> +				XFS_DATA_FORK);
> +		if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, off, &error))
> +			break;
> +
> +		if (nmap != 1 || !xfs_bmap_is_written_extent(&map)) {
> +			xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, off);
> +			break;
> +		}
> +
> +		off += map.br_blockcount;
> +	}
> +
> +	return error;
> +}
> +
>   /* Scrub the realtime bitmap. */
>   int
>   xchk_rtbitmap(
> @@ -70,6 +106,10 @@ xchk_rtbitmap(
>   	if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
>   		return error;
>   
> +	error = xchk_rtbitmap_check_extents(sc);
> +	if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
> +		return error;
> +
>   	error = xfs_rtalloc_query_all(sc->tp, xchk_rtbitmap_rec, sc);
>   	if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, 0, &error))
>   		goto out;
> 

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

* Re: [PATCH 2/2] xfs: rtbitmap scrubber should check inode size
  2020-06-30 15:41 ` [PATCH 2/2] xfs: rtbitmap scrubber should check inode size Darrick J. Wong
@ 2020-06-30 21:05   ` Allison Collins
  0 siblings, 0 replies; 5+ messages in thread
From: Allison Collins @ 2020-06-30 21:05 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs



On 6/30/20 8:41 AM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Make sure the rtbitmap is large enough to store the entire bitmap.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Looks good
Reviewed-by: Allison Collins <allison.henderson@oracle.com>

> ---
>   fs/xfs/scrub/rtbitmap.c |    7 +++++++
>   1 file changed, 7 insertions(+)
> 
> 
> diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
> index c777c98c50c3..76e4ffe0315b 100644
> --- a/fs/xfs/scrub/rtbitmap.c
> +++ b/fs/xfs/scrub/rtbitmap.c
> @@ -101,6 +101,13 @@ xchk_rtbitmap(
>   {
>   	int			error;
>   
> +	/* Is the size of the rtbitmap correct? */
> +	if (sc->mp->m_rbmip->i_d.di_size !=
> +	    XFS_FSB_TO_B(sc->mp, sc->mp->m_sb.sb_rbmblocks)) {
> +		xchk_ino_set_corrupt(sc, sc->mp->m_rbmip->i_ino);
> +		return 0;
> +	}
> +
>   	/* Invoke the fork scrubber. */
>   	error = xchk_metadata_inode_forks(sc);
>   	if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
> 

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

end of thread, other threads:[~2020-06-30 21:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-30 15:41 [PATCH 0/2] xfs: strengthen online checking Darrick J. Wong
2020-06-30 15:41 ` [PATCH 1/2] xfs: rtbitmap scrubber should verify written extents Darrick J. Wong
2020-06-30 21:05   ` Allison Collins
2020-06-30 15:41 ` [PATCH 2/2] xfs: rtbitmap scrubber should check inode size Darrick J. Wong
2020-06-30 21:05   ` Allison Collins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).