diff mbox

Btrfs: fix BUG_ON in btrfs_submit_compressed_write

Message ID 1466645526-27128-1-git-send-email-bo.li.liu@oracle.com (mailing list archive)
State Accepted
Headers show

Commit Message

Liu Bo June 23, 2016, 1:32 a.m. UTC
This is similar to btrfs_submit_compressed_read(), if we fail after
bio is allocated, then we can use bio_endio() and errors are saved
 in bio->bi_error.  But please note that we don't return errors to
its caller because the caller assumes it won't call endio to cleanup
on error.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/compression.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

David Sterba June 23, 2016, 9:09 a.m. UTC | #1
On Wed, Jun 22, 2016 at 06:32:06PM -0700, Liu Bo wrote:
> This is similar to btrfs_submit_compressed_read(), if we fail after
> bio is allocated, then we can use bio_endio() and errors are saved
>  in bio->bi_error.  But please note that we don't return errors to
> its caller because the caller assumes it won't call endio to cleanup
> on error.

This sounds strange, where do we notice that some of the bios failed?
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Liu Bo June 23, 2016, 5:41 p.m. UTC | #2
On Thu, Jun 23, 2016 at 11:09:52AM +0200, David Sterba wrote:
> On Wed, Jun 22, 2016 at 06:32:06PM -0700, Liu Bo wrote:
> > This is similar to btrfs_submit_compressed_read(), if we fail after
> > bio is allocated, then we can use bio_endio() and errors are saved
> >  in bio->bi_error.  But please note that we don't return errors to
> > its caller because the caller assumes it won't call endio to cleanup
> > on error.
> 
> This sounds strange, where do we notice that some of the bios failed?

bio_endio()
  -> end_compressed_bio_write()
     -> end_compressed_writeback()
        -> mapping_set_error(inode->i_mapping, -EIO);

Thanks,

-liubo
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba July 8, 2016, 2:47 p.m. UTC | #3
On Thu, Jun 23, 2016 at 10:41:11AM -0700, Liu Bo wrote:
> On Thu, Jun 23, 2016 at 11:09:52AM +0200, David Sterba wrote:
> > On Wed, Jun 22, 2016 at 06:32:06PM -0700, Liu Bo wrote:
> > > This is similar to btrfs_submit_compressed_read(), if we fail after
> > > bio is allocated, then we can use bio_endio() and errors are saved
> > >  in bio->bi_error.  But please note that we don't return errors to
> > > its caller because the caller assumes it won't call endio to cleanup
> > > on error.
> > 
> > This sounds strange, where do we notice that some of the bios failed?
> 
> bio_endio()
>   -> end_compressed_bio_write()
>      -> end_compressed_writeback()
>         -> mapping_set_error(inode->i_mapping, -EIO);

Thanks. We use the same logic in btrfs_submit_compressed_read as you
mention but I missed that first. Good riddance of the bug-ons.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 658c39b..7a4d9c8 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -402,7 +402,10 @@  int btrfs_submit_compressed_write(struct inode *inode, u64 start,
 			}
 
 			ret = btrfs_map_bio(root, WRITE, bio, 0, 1);
-			BUG_ON(ret); /* -ENOMEM */
+			if (ret) {
+				bio->bi_error = ret;
+				bio_endio(bio);
+			}
 
 			bio_put(bio);
 
@@ -432,7 +435,10 @@  int btrfs_submit_compressed_write(struct inode *inode, u64 start,
 	}
 
 	ret = btrfs_map_bio(root, WRITE, bio, 0, 1);
-	BUG_ON(ret); /* -ENOMEM */
+	if (ret) {
+		bio->bi_error = ret;
+		bio_endio(bio);
+	}
 
 	bio_put(bio);
 	return 0;