Linux-XFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] xfs: allow parent directory scans to be interrupted with fatal signals
@ 2019-11-26 16:15 Darrick J. Wong
  2019-11-27 13:05 ` Brian Foster
  0 siblings, 1 reply; 2+ messages in thread
From: Darrick J. Wong @ 2019-11-26 16:15 UTC (permalink / raw)
  To: xfs

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

Allow a fatal signal to interrupt us when we're scanning a directory to
verify a parent pointer.

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

diff --git a/fs/xfs/scrub/parent.c b/fs/xfs/scrub/parent.c
index 17100a83e23e..5705adc43a75 100644
--- a/fs/xfs/scrub/parent.c
+++ b/fs/xfs/scrub/parent.c
@@ -32,8 +32,10 @@ xchk_setup_parent(
 
 struct xchk_parent_ctx {
 	struct dir_context	dc;
+	struct xfs_scrub	*sc;
 	xfs_ino_t		ino;
 	xfs_nlink_t		nlink;
+	bool			cancelled;
 };
 
 /* Look for a single entry in a directory pointing to an inode. */
@@ -47,11 +49,21 @@ xchk_parent_actor(
 	unsigned		type)
 {
 	struct xchk_parent_ctx	*spc;
+	int			error = 0;
 
 	spc = container_of(dc, struct xchk_parent_ctx, dc);
 	if (spc->ino == ino)
 		spc->nlink++;
-	return 0;
+
+	/*
+	 * If we're facing a fatal signal, bail out.  Store the cancellation
+	 * status separately because the VFS readdir code squashes error codes
+	 * into short directory reads.
+	 */
+	if (xchk_should_terminate(spc->sc, &error))
+		spc->cancelled = true;
+
+	return error;
 }
 
 /* Count the number of dentries in the parent dir that point to this inode. */
@@ -62,10 +74,9 @@ xchk_parent_count_parent_dentries(
 	xfs_nlink_t		*nlink)
 {
 	struct xchk_parent_ctx	spc = {
-		.dc.actor = xchk_parent_actor,
-		.dc.pos = 0,
-		.ino = sc->ip->i_ino,
-		.nlink = 0,
+		.dc.actor	= xchk_parent_actor,
+		.ino		= sc->ip->i_ino,
+		.sc		= sc,
 	};
 	size_t			bufsize;
 	loff_t			oldpos;
@@ -97,6 +108,10 @@ xchk_parent_count_parent_dentries(
 		error = xfs_readdir(sc->tp, parent, &spc.dc, bufsize);
 		if (error)
 			goto out;
+		if (spc.cancelled) {
+			error = -EAGAIN;
+			goto out;
+		}
 		if (oldpos == spc.dc.pos)
 			break;
 		oldpos = spc.dc.pos;

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

* Re: [PATCH] xfs: allow parent directory scans to be interrupted with fatal signals
  2019-11-26 16:15 [PATCH] xfs: allow parent directory scans to be interrupted with fatal signals Darrick J. Wong
@ 2019-11-27 13:05 ` Brian Foster
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Foster @ 2019-11-27 13:05 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: xfs

On Tue, Nov 26, 2019 at 08:15:17AM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Allow a fatal signal to interrupt us when we're scanning a directory to
> verify a parent pointer.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  fs/xfs/scrub/parent.c |   25 ++++++++++++++++++++-----
>  1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/xfs/scrub/parent.c b/fs/xfs/scrub/parent.c
> index 17100a83e23e..5705adc43a75 100644
> --- a/fs/xfs/scrub/parent.c
> +++ b/fs/xfs/scrub/parent.c
> @@ -32,8 +32,10 @@ xchk_setup_parent(
>  
>  struct xchk_parent_ctx {
>  	struct dir_context	dc;
> +	struct xfs_scrub	*sc;
>  	xfs_ino_t		ino;
>  	xfs_nlink_t		nlink;
> +	bool			cancelled;
>  };
>  
>  /* Look for a single entry in a directory pointing to an inode. */
> @@ -47,11 +49,21 @@ xchk_parent_actor(
>  	unsigned		type)
>  {
>  	struct xchk_parent_ctx	*spc;
> +	int			error = 0;
>  
>  	spc = container_of(dc, struct xchk_parent_ctx, dc);
>  	if (spc->ino == ino)
>  		spc->nlink++;
> -	return 0;
> +
> +	/*
> +	 * If we're facing a fatal signal, bail out.  Store the cancellation
> +	 * status separately because the VFS readdir code squashes error codes
> +	 * into short directory reads.
> +	 */
> +	if (xchk_should_terminate(spc->sc, &error))
> +		spc->cancelled = true;
> +
> +	return error;
>  }
>  
>  /* Count the number of dentries in the parent dir that point to this inode. */
> @@ -62,10 +74,9 @@ xchk_parent_count_parent_dentries(
>  	xfs_nlink_t		*nlink)
>  {
>  	struct xchk_parent_ctx	spc = {
> -		.dc.actor = xchk_parent_actor,
> -		.dc.pos = 0,
> -		.ino = sc->ip->i_ino,
> -		.nlink = 0,
> +		.dc.actor	= xchk_parent_actor,
> +		.ino		= sc->ip->i_ino,
> +		.sc		= sc,
>  	};
>  	size_t			bufsize;
>  	loff_t			oldpos;
> @@ -97,6 +108,10 @@ xchk_parent_count_parent_dentries(
>  		error = xfs_readdir(sc->tp, parent, &spc.dc, bufsize);
>  		if (error)
>  			goto out;
> +		if (spc.cancelled) {
> +			error = -EAGAIN;
> +			goto out;
> +		}
>  		if (oldpos == spc.dc.pos)
>  			break;
>  		oldpos = spc.dc.pos;
> 


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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-26 16:15 [PATCH] xfs: allow parent directory scans to be interrupted with fatal signals Darrick J. Wong
2019-11-27 13:05 ` Brian Foster

Linux-XFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-xfs/0 linux-xfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-xfs linux-xfs/ https://lore.kernel.org/linux-xfs \
		linux-xfs@vger.kernel.org
	public-inbox-index linux-xfs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-xfs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git