All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: fix error code in xfs_iflush_cluster()
@ 2020-05-13  9:48 ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2020-05-13  9:48 UTC (permalink / raw)
  To: Darrick J. Wong, Brian Foster; +Cc: linux-xfs, kernel-janitors

Originally this function used to always return -EFSCORRUPTED on error
but now we're trying to return more informative error codes.
Unfortunately, there was one error path missed.  If this kmem_alloc()
allocation fails then we need to return -ENOMEM instead of success.

Fixes: f20192991d79 ("xfs: simplify inode flush error handling")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 fs/xfs/xfs_inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index ab31a5dec7aab..63aeda7cbafb0 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -3505,8 +3505,10 @@ xfs_iflush_cluster(
 
 	cilist_size = igeo->inodes_per_cluster * sizeof(struct xfs_inode *);
 	cilist = kmem_alloc(cilist_size, KM_MAYFAIL|KM_NOFS);
-	if (!cilist)
+	if (!cilist) {
+		error = -ENOMEM;
 		goto out_put;
+	}
 
 	mask = ~(igeo->inodes_per_cluster - 1);
 	first_index = XFS_INO_TO_AGINO(mp, ip->i_ino) & mask;
-- 
2.26.2


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

* [PATCH] xfs: fix error code in xfs_iflush_cluster()
@ 2020-05-13  9:48 ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2020-05-13  9:48 UTC (permalink / raw)
  To: Darrick J. Wong, Brian Foster; +Cc: linux-xfs, kernel-janitors

Originally this function used to always return -EFSCORRUPTED on error
but now we're trying to return more informative error codes.
Unfortunately, there was one error path missed.  If this kmem_alloc()
allocation fails then we need to return -ENOMEM instead of success.

Fixes: f20192991d79 ("xfs: simplify inode flush error handling")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 fs/xfs/xfs_inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index ab31a5dec7aab..63aeda7cbafb0 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -3505,8 +3505,10 @@ xfs_iflush_cluster(
 
 	cilist_size = igeo->inodes_per_cluster * sizeof(struct xfs_inode *);
 	cilist = kmem_alloc(cilist_size, KM_MAYFAIL|KM_NOFS);
-	if (!cilist)
+	if (!cilist) {
+		error = -ENOMEM;
 		goto out_put;
+	}
 
 	mask = ~(igeo->inodes_per_cluster - 1);
 	first_index = XFS_INO_TO_AGINO(mp, ip->i_ino) & mask;
-- 
2.26.2

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

* Re: [PATCH] xfs: fix error code in xfs_iflush_cluster()
  2020-05-13  9:48 ` Dan Carpenter
@ 2020-05-13 13:29   ` Brian Foster
  -1 siblings, 0 replies; 10+ messages in thread
From: Brian Foster @ 2020-05-13 13:29 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Darrick J. Wong, linux-xfs, kernel-janitors

On Wed, May 13, 2020 at 12:48:03PM +0300, Dan Carpenter wrote:
> Originally this function used to always return -EFSCORRUPTED on error
> but now we're trying to return more informative error codes.
> Unfortunately, there was one error path missed.  If this kmem_alloc()
> allocation fails then we need to return -ENOMEM instead of success.
> 
> Fixes: f20192991d79 ("xfs: simplify inode flush error handling")

This logic predates that patch, and I think it may be by design. Inode
cluster flushing is an optimization to flush other dirty inodes in the
same cluster we're about to queue for writeback. If the cluster flush
fails due to an operational error such as memory allocation failure, we
don't want to report an error because that would shutdown the fs when
otherwise the side effect would be that the other inodes in the cluster
would be flushed individually. This is distinct from failing to flush a
particular inode due to corruption, which is a fatal filesystem error.

Brian

> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  fs/xfs/xfs_inode.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
> index ab31a5dec7aab..63aeda7cbafb0 100644
> --- a/fs/xfs/xfs_inode.c
> +++ b/fs/xfs/xfs_inode.c
> @@ -3505,8 +3505,10 @@ xfs_iflush_cluster(
>  
>  	cilist_size = igeo->inodes_per_cluster * sizeof(struct xfs_inode *);
>  	cilist = kmem_alloc(cilist_size, KM_MAYFAIL|KM_NOFS);
> -	if (!cilist)
> +	if (!cilist) {
> +		error = -ENOMEM;
>  		goto out_put;
> +	}
>  
>  	mask = ~(igeo->inodes_per_cluster - 1);
>  	first_index = XFS_INO_TO_AGINO(mp, ip->i_ino) & mask;
> -- 
> 2.26.2
> 


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

* Re: [PATCH] xfs: fix error code in xfs_iflush_cluster()
@ 2020-05-13 13:29   ` Brian Foster
  0 siblings, 0 replies; 10+ messages in thread
From: Brian Foster @ 2020-05-13 13:29 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Darrick J. Wong, linux-xfs, kernel-janitors

On Wed, May 13, 2020 at 12:48:03PM +0300, Dan Carpenter wrote:
> Originally this function used to always return -EFSCORRUPTED on error
> but now we're trying to return more informative error codes.
> Unfortunately, there was one error path missed.  If this kmem_alloc()
> allocation fails then we need to return -ENOMEM instead of success.
> 
> Fixes: f20192991d79 ("xfs: simplify inode flush error handling")

This logic predates that patch, and I think it may be by design. Inode
cluster flushing is an optimization to flush other dirty inodes in the
same cluster we're about to queue for writeback. If the cluster flush
fails due to an operational error such as memory allocation failure, we
don't want to report an error because that would shutdown the fs when
otherwise the side effect would be that the other inodes in the cluster
would be flushed individually. This is distinct from failing to flush a
particular inode due to corruption, which is a fatal filesystem error.

Brian

> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  fs/xfs/xfs_inode.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
> index ab31a5dec7aab..63aeda7cbafb0 100644
> --- a/fs/xfs/xfs_inode.c
> +++ b/fs/xfs/xfs_inode.c
> @@ -3505,8 +3505,10 @@ xfs_iflush_cluster(
>  
>  	cilist_size = igeo->inodes_per_cluster * sizeof(struct xfs_inode *);
>  	cilist = kmem_alloc(cilist_size, KM_MAYFAIL|KM_NOFS);
> -	if (!cilist)
> +	if (!cilist) {
> +		error = -ENOMEM;
>  		goto out_put;
> +	}
>  
>  	mask = ~(igeo->inodes_per_cluster - 1);
>  	first_index = XFS_INO_TO_AGINO(mp, ip->i_ino) & mask;
> -- 
> 2.26.2
> 

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

* Re: [PATCH] xfs: fix error code in xfs_iflush_cluster()
  2020-05-13 13:29   ` Brian Foster
@ 2020-05-13 13:39     ` Dan Carpenter
  -1 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2020-05-13 13:39 UTC (permalink / raw)
  To: Brian Foster; +Cc: Darrick J. Wong, linux-xfs, kernel-janitors

Oh yeah.  You're right.  This patch isn't correct.  Sorry about that.

I worry that there are several static analyzer's which will warn about
this code...

regards,
dan carpenter


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

* Re: [PATCH] xfs: fix error code in xfs_iflush_cluster()
@ 2020-05-13 13:39     ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2020-05-13 13:39 UTC (permalink / raw)
  To: Brian Foster; +Cc: Darrick J. Wong, linux-xfs, kernel-janitors

Oh yeah.  You're right.  This patch isn't correct.  Sorry about that.

I worry that there are several static analyzer's which will warn about
this code...

regards,
dan carpenter

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

* Re: [PATCH] xfs: fix error code in xfs_iflush_cluster()
  2020-05-13 13:39     ` Dan Carpenter
@ 2020-05-13 15:17       ` Darrick J. Wong
  -1 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2020-05-13 15:17 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Brian Foster, linux-xfs, kernel-janitors

On Wed, May 13, 2020 at 04:39:05PM +0300, Dan Carpenter wrote:
> Oh yeah.  You're right.  This patch isn't correct.  Sorry about that.
> 
> I worry that there are several static analyzer's which will warn about
> this code...

/me wonders if this particular instance ought to have a breadcrumb to
remind future readers that we can handle the lack of memory, e.g.

cilist = kmem_alloc(..., KM_MAYFAIL...);
if (!cilist) {
	/* memory is tight, so defer the inode cluster flush */
	goto out_put;
}

--D

> regards,
> dan carpenter
> 

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

* Re: [PATCH] xfs: fix error code in xfs_iflush_cluster()
@ 2020-05-13 15:17       ` Darrick J. Wong
  0 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2020-05-13 15:17 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Brian Foster, linux-xfs, kernel-janitors

On Wed, May 13, 2020 at 04:39:05PM +0300, Dan Carpenter wrote:
> Oh yeah.  You're right.  This patch isn't correct.  Sorry about that.
> 
> I worry that there are several static analyzer's which will warn about
> this code...

/me wonders if this particular instance ought to have a breadcrumb to
remind future readers that we can handle the lack of memory, e.g.

cilist = kmem_alloc(..., KM_MAYFAIL...);
if (!cilist) {
	/* memory is tight, so defer the inode cluster flush */
	goto out_put;
}

--D

> regards,
> dan carpenter
> 

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

* Re: [PATCH] xfs: fix error code in xfs_iflush_cluster()
  2020-05-13 15:17       ` Darrick J. Wong
@ 2020-05-13 21:09         ` Dave Chinner
  -1 siblings, 0 replies; 10+ messages in thread
From: Dave Chinner @ 2020-05-13 21:09 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Dan Carpenter, Brian Foster, linux-xfs, kernel-janitors

On Wed, May 13, 2020 at 08:17:54AM -0700, Darrick J. Wong wrote:
> On Wed, May 13, 2020 at 04:39:05PM +0300, Dan Carpenter wrote:
> > Oh yeah.  You're right.  This patch isn't correct.  Sorry about that.
> > 
> > I worry that there are several static analyzer's which will warn about
> > this code...
> 
> /me wonders if this particular instance ought to have a breadcrumb to
> remind future readers that we can handle the lack of memory, e.g.
> 
> cilist = kmem_alloc(..., KM_MAYFAIL...);
> if (!cilist) {
> 	/* memory is tight, so defer the inode cluster flush */
> 	goto out_put;
> }

I'm working on patches that make this memory allocation go away
altogether, so I'd suggest just ignoring it for now.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH] xfs: fix error code in xfs_iflush_cluster()
@ 2020-05-13 21:09         ` Dave Chinner
  0 siblings, 0 replies; 10+ messages in thread
From: Dave Chinner @ 2020-05-13 21:09 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Dan Carpenter, Brian Foster, linux-xfs, kernel-janitors

On Wed, May 13, 2020 at 08:17:54AM -0700, Darrick J. Wong wrote:
> On Wed, May 13, 2020 at 04:39:05PM +0300, Dan Carpenter wrote:
> > Oh yeah.  You're right.  This patch isn't correct.  Sorry about that.
> > 
> > I worry that there are several static analyzer's which will warn about
> > this code...
> 
> /me wonders if this particular instance ought to have a breadcrumb to
> remind future readers that we can handle the lack of memory, e.g.
> 
> cilist = kmem_alloc(..., KM_MAYFAIL...);
> if (!cilist) {
> 	/* memory is tight, so defer the inode cluster flush */
> 	goto out_put;
> }

I'm working on patches that make this memory allocation go away
altogether, so I'd suggest just ignoring it for now.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13  9:48 [PATCH] xfs: fix error code in xfs_iflush_cluster() Dan Carpenter
2020-05-13  9:48 ` Dan Carpenter
2020-05-13 13:29 ` Brian Foster
2020-05-13 13:29   ` Brian Foster
2020-05-13 13:39   ` Dan Carpenter
2020-05-13 13:39     ` Dan Carpenter
2020-05-13 15:17     ` Darrick J. Wong
2020-05-13 15:17       ` Darrick J. Wong
2020-05-13 21:09       ` Dave Chinner
2020-05-13 21:09         ` Dave Chinner

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.