btrfs: not a disk error if the bio_add_page fails
PATCH 1/1 btrfs: not a disk error if the bio_add_page fails
bio_add_page() can fail for logical reasons as from the bio_add_page() comments:- 'This will only fail if eitherbio->bi_vcnt == bio->bi_max_vecs or it's a cloned bio.' Don't inc the write error statistics for this. And set -EINVAL instead of -EIO.
--- fs/btrfs/scrub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/scrub.c +4 -4
@@ -4618,15 +4618,15 @@ static int write_page_nocow(struct scrub_ctx *sctx, bio->bi_opf =REQ_OP_WRITE |REQ_SYNC ; ret =bio_add_page (bio, page,PAGE_SIZE ,0 );if (ret !=PAGE_SIZE ) { -leave_with_eio:bio_put (bio); +return -EINVAL ; + } + +if (btrfsic_submit_bio_wait (bio)) {btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_WRITE_ERRS );return -EIO ; } -if (btrfsic_submit_bio_wait (bio)) - goto leave_with_eio; -bio_put (bio);return 0 ; }
Signature · 1 line
2.15.0
Quoted 17 lines · Anand Jain
bio_add_page()can fail for logical reasons as from thebio_add_page()comments:- 'This will only fail if eitherbio->bi_vcnt==bio->bi_max_vecsor it's a cloned bio.' Don't inc the write error statistics for this. And set-EINVALinstead of-EIO.Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/scrub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)fs/btrfs/scrub.c +0
-0@@ -4618,15 +4618,15 @@ static int write_page_nocow(struct scrub_ctx *sctx, bio->bi_opf =REQ_OP_WRITE |REQ_SYNC ; ret =bio_add_page (bio, page,PAGE_SIZE ,0 );
fs/btrfs/scrub.c static int write_page_nocow(struct scrub_ctx *sctx, · line 4628
Quoted 10 lines
fs/btrfs/scrub.c +4
-1if (ret !=PAGE_SIZE ) { -leave_with_eio:bio_put (bio); +return -EINVAL ; + } + +if (btrfsic_submit_bio_wait (bio)) {btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_WRITE_ERRS );return -EIO ; }
You are now introducing a leak of the bio. Missing bio_put(bio) before returning.
Quoted 14 lines
fs/btrfs/scrub.c +0
-4-if (btrfsic_submit_bio_wait (bio)) - goto leave_with_eio; -bio_put (bio);return 0 ; } --2.15.0
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
PATCH v2 1/1 btrfs: not a disk error if the bio_add_page fails
In reply to Anand Jainbio_add_page() can fail for logical reasons as from the bio_add_page() comments:- 'This will only fail if eitherbio->bi_vcnt == bio->bi_max_vecs or it's a cloned bio.' Don't inc the write error statistics for this. And set -EINVAL instead of -EIO.
---v1->v2: Add missing bio_put(). Thanks Filipe.
fs/btrfs/scrub.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/btrfs/scrub.c +5 -4
@@ -4617,15 +4617,16 @@ static int write_page_nocow(struct scrub_ctx *sctx, bio->bi_opf =REQ_OP_WRITE |REQ_SYNC ; ret =bio_add_page (bio, page,PAGE_SIZE ,0 );if (ret !=PAGE_SIZE ) { -leave_with_eio: +bio_put (bio); +return -EINVAL ; + } + +if (btrfsic_submit_bio_wait (bio)) {bio_put (bio);btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_WRITE_ERRS );return -EIO ; } -if (btrfsic_submit_bio_wait (bio)) - goto leave_with_eio; -bio_put (bio);return 0 ; }
Signature · 1 line
2.15.0
Quoted 23 lines · Filipe Manana
Quoted 22 lines · Anand Jain
bio_add_page()can fail for logical reasons as from thebio_add_page()comments:- 'This will only fail if eitherbio->bi_vcnt==bio->bi_max_vecsor it's a cloned bio.' Don't inc the write error statistics for this. And set-EINVALinstead of-EIO.Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/scrub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)fs/btrfs/scrub.c +2
-1@@ -4618,15 +4618,15 @@ static int write_page_nocow(struct scrub_ctx *sctx, bio->bi_opf =REQ_OP_WRITE |REQ_SYNC ; ret =bio_add_page (bio, page,PAGE_SIZE ,0 );if (ret !=PAGE_SIZE ) { -leave_with_eio:bio_put (bio); +return -EINVAL ; + }
Quoted 8 lines
fs/btrfs/scrub.c static int write_page_nocow(struct scrub_ctx *sctx, · line 4628
Quoted 5 lines
fs/btrfs/scrub.c +2
-0+ +if (btrfsic_submit_bio_wait (bio)) {btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_WRITE_ERRS );return -EIO ; }You are now introducing a leak of the bio. Missing
bio_put(bio)before returning.
Oops. My bad. Thanks. Now fixed in v2.
- Anand
Quoted 17 lines
Quoted 14 lines
fs/btrfs/scrub.c +0
-4-if (btrfsic_submit_bio_wait (bio)) - goto leave_with_eio; -bio_put (bio);return 0 ; } --2.15.0
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 5 lines · Anand Jain
bio_add_page()can fail for logical reasons as from thebio_add_page()comments:- 'This will only fail if eitherbio->bi_vcnt==bio->bi_max_vecsor it's a cloned bio.' Don't inc the write error statistics for this. And set-EINVALinstead of-EIO.
It's correct to skip increasing counter, but why -EINVAL? (its caller only cares about if it's non-zero.)
thanks,
-liubo
Quoted 39 lines
Signed-off-by Anand Jain <[email protected]>---
v1->v2: Add missingbio_put(). Thanks Filipe.fs/btrfs/scrub.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)fs/btrfs/scrub.c +5
-4@@ -4617,15 +4617,16 @@ static int write_page_nocow(struct scrub_ctx *sctx, bio->bi_opf =REQ_OP_WRITE |REQ_SYNC ; ret =bio_add_page (bio, page,PAGE_SIZE ,0 );if (ret !=PAGE_SIZE ) { -leave_with_eio: +bio_put (bio); +return -EINVAL ; + } + +if (btrfsic_submit_bio_wait (bio)) {bio_put (bio);btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_WRITE_ERRS );return -EIO ; } -if (btrfsic_submit_bio_wait (bio)) - goto leave_with_eio; -bio_put (bio);return 0 ; }Signature · 6 lines
2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Liu Bo
Quoted 5 lines · Anand Jain
bio_add_page()can fail for logical reasons as from thebio_add_page()comments:- 'This will only fail if eitherbio->bi_vcnt==bio->bi_max_vecsor it's a cloned bio.' Don't inc the write error statistics for this. And set-EINVALinstead of-EIO.It's correct to skip increasing counter, but why
-EINVAL? (its caller only cares about if it's non-zero.)
Well...there is no chance that bio_add_page() could return non-PAGE_SIZE as this bio has been just created, we can remove the error handling after bio_add_page().
thanks,
-liubo
Quoted 47 lines
thanks,
-liubo
Quoted 39 lines
Signed-off-by Anand Jain <[email protected]>---
v1->v2: Add missingbio_put(). Thanks Filipe.fs/btrfs/scrub.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)fs/btrfs/scrub.c +5
-4@@ -4617,15 +4617,16 @@ static int write_page_nocow(struct scrub_ctx *sctx, bio->bi_opf =REQ_OP_WRITE |REQ_SYNC ; ret =bio_add_page (bio, page,PAGE_SIZE ,0 );if (ret !=PAGE_SIZE ) { -leave_with_eio: +bio_put (bio); +return -EINVAL ; + } + +if (btrfsic_submit_bio_wait (bio)) {bio_put (bio);btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_WRITE_ERRS );return -EIO ; } -if (btrfsic_submit_bio_wait (bio)) - goto leave_with_eio; -bio_put (bio);return 0 ; }Signature · 6 lines
2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Liu Bo
Quoted 7 lines · Liu Bo
Quoted 5 lines · Anand Jain
bio_add_page()can fail for logical reasons as from thebio_add_page()comments:- 'This will only fail if eitherbio->bi_vcnt==bio->bi_max_vecsor it's a cloned bio.' Don't inc the write error statistics for this. And set-EINVALinstead of-EIO.
Quoted 6 lines
Quoted 2 lines
It's correct to skip increasing counter, but why
-EINVAL? (its caller only cares about if it's non-zero.)Well...there is no chance that
bio_add_page()could return non-PAGE_SIZE as this bio has been just created, we can remove the error handling afterbio_add_page().
Ah. right, bio_add_page() can't fail in this thread, its not a bio clone, and its the first call to bio_add_page(). Will remove error handling part.
Thanks, Anand
Quoted 54 lines
thanks,
-liuboQuoted 39 lines
thanks,
-liubo
Quoted 35 lines
Signed-off-by Anand Jain <[email protected]>---
v1->v2: Add missingbio_put(). Thanks Filipe.fs/btrfs/scrub.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)fs/btrfs/scrub.c +5
-4@@ -4617,15 +4617,16 @@ static int write_page_nocow(struct scrub_ctx *sctx, bio->bi_opf =REQ_OP_WRITE |REQ_SYNC ; ret =bio_add_page (bio, page,PAGE_SIZE ,0 );if (ret !=PAGE_SIZE ) { -leave_with_eio: +bio_put (bio); +return -EINVAL ; + } + +if (btrfsic_submit_bio_wait (bio)) {bio_put (bio);btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_WRITE_ERRS );return -EIO ; } -if (btrfsic_submit_bio_wait (bio)) - goto leave_with_eio; -bio_put (bio);return 0 ; }Signature · 1 line
2.15.0Quoted 8 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html