Skip to contentSkip to conversation

2.6.6 buffer.c: bio_alloc() check

PATCH In review Yury Umanets 2 participants 3 messages Jun 2, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 2.6.6 buffer.c: bio_alloc() check

[PATCH] 2.6.6 buffer.c: adds bio_alloc() check and error handling in fs/buffer.c.

 buffer.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+)
linux-2.6.6-modified/fs/buffer.c renamed from linux-2.6.6/fs/buffer.c +25 -0
diff -rupN ./linux-2.6.6/fs/buffer.c ./linux-2.6.6-modified/fs/buffer.c
@@ -2712,6 +2712,31 @@ void submit_bh(int rw, struct buffer_hea
 	 * submit_bio -> generic_make_request may further map this bio around
 	 */
 	bio = bio_alloc(GFP_NOIO, 1);
+	if (bio == NULL) {
+		char b[BDEVNAME_SIZE];
+                
+		printk(KERN_ERR "BIO allocation failed for buffer on device "
+			"%s, logical block %Lu\n", bdevname(bh->b_bdev, b), 
+			(unsigned long long)bh->b_blocknr);
+                
+		/* 
+		 * this is needed here as some of submit_bh() callers have to
+		 * wait until buffer is unlocked (that is IO is finished on it)
+		 * and check its state.
+		 */
+		if (rw == WRITE)
+			set_buffer_write_io_error(bh);
+		clear_buffer_uptodate(bh);
+		SetPageError(bh->b_page);
+                
+		/* 
+		 * making all future wait_on_buffer() callers do not wait
+		 * this buffer as it is errorneous. 
+		 */
+		if (buffer_locked(bh))
+			unlock_buffer(bh);
+		return;
+        }
 
 	bio->bi_sector = bh->b_blocknr * (bh->b_size >> 9);
 	bio->bi_bdev = bh->b_bdev;
Signature · 1 line
umka
#1 lore raw
Quoted 12 lines · Yury Umanets

[PATCH] 2.6.6 buffer.c: adds bio_alloc() check and error handling in fs/buffer.c.

 buffer.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+)

diff -rupN ./linux-2.6.6/fs/buffer.c ./linux-2.6.6-modified/fs/buffer.c

linux-2.6.6-modified/fs/buffer.c void submit_bh(int rw, struct buffer_hea · line 2715

Quoted 4 lines
linux-2.6.6-modified/fs/buffer.c renamed from linux-2.6.6/fs/buffer.c +1 -0
@@ -2712,6 +2712,31 @@ void submit_bh(int rw, struct buffer_hea
 	 * submit_bio -> generic_make_request may further map this bio around
 	 */
 	bio = bio_alloc(GFP_NOIO, 1);
+	if (bio == NULL) {

This is wrong, bio_alloc() never fails if it's called with __GFP_WAIT in the gfp mask.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 9 lines · Jens Axboe
Quoted 8 lines · Yury Umanets

[PATCH] 2.6.6 buffer.c: adds bio_alloc() check and error handling in fs/buffer.c.

 buffer.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+)
Quoted 11 lines

linux-2.6.6-modified/fs/buffer.c void submit_bh(int rw, struct buffer_hea · line 2715

Quoted 8 lines

diff -rupN ./linux-2.6.6/fs/buffer.c ./linux-2.6.6-modified/fs/buffer.c

linux-2.6.6-modified/fs/buffer.c renamed from linux-2.6.6/fs/buffer.c +1 -0
@@ -2712,6 +2712,31 @@ void submit_bh(int rw, struct buffer_hea
 	 * submit_bio -> generic_make_request may further map this bio around
 	 */
 	bio = bio_alloc(GFP_NOIO, 1);
+	if (bio == NULL) {

This is wrong, bio_alloc() never fails if it's called with __GFP_WAIT in the gfp mask.

Ok, I see. Thanks.

Signature · 1 line
umka