Skip to contentSkip to conversation

btrfs: not a disk error if the bio_add_page fails

PATCH Superseded Anand Jain 3 participants 7 messages Jan 3, 2018 – Jan 5, 2018 Btrfs file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

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 either
bio->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
index d766c73eb29a..8c1508a41f90 100644
@@ -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
#1 lore raw
Quoted 17 lines · Anand Jain

bio_add_page() can fail for logical reasons as from the bio_add_page() comments:- 'This will only fail if either
bio->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 +0 -0
index d766c73eb29a..8c1508a41f90 100644
@@ -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 -1
        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;
        }

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.”
author
#3 lore raw

PATCH v2 1/1 btrfs: not a disk error if the bio_add_page fails

In reply to Anand Jain

bio_add_page() can fail for logical reasons as from the bio_add_page() comments:- 'This will only fail if either
bio->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
index ecfe3118d9dd..57ac39a3f046 100644
@@ -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
author
#2 lore raw
In reply to Filipe Manana
Quoted 23 lines · Filipe Manana
Quoted 22 lines · Anand Jain

bio_add_page() can fail for logical reasons as from the bio_add_page() comments:- 'This will only fail if either
bio->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 +2 -1
index d766c73eb29a..8c1508a41f90 100644
@@ -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

#4 lore raw
In reply to Anand Jain
Quoted 5 lines · Anand Jain

bio_add_page() can fail for logical reasons as from the bio_add_page() comments:- 'This will only fail if either
bio->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.

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

---
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
index ecfe3118d9dd..57ac39a3f046 100644
@@ -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
#5 lore raw
Quoted 9 lines · Liu Bo
Quoted 5 lines · Anand Jain

bio_add_page() can fail for logical reasons as from the bio_add_page() comments:- 'This will only fail if either
bio->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.

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

---
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
index ecfe3118d9dd..57ac39a3f046 100644
@@ -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

author
#6 lore raw
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 the bio_add_page() comments:- 'This will only fail if either
bio->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.

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 after bio_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,
-liubo

Quoted 39 lines

thanks,

-liubo

Quoted 35 lines

---
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
index ecfe3118d9dd..57ac39a3f046 100644
@@ -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 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