From: Oleg Drokin <green@namesys.com>

Fix BUG_ON(!buffer_mapped(bh)) in submit_bh()

Ok, so the final version of the patch is here.
I presume we don't need to clear page-dirty if there are no buffers
in the page at all (actually I am not even sure this situation might
happen).




 fs/reiserfs/tail_conversion.c |   13 +++++++++++++
 1 files changed, 13 insertions(+)

diff -puN fs/reiserfs/tail_conversion.c~reiserfs-unmapped-buffer-fix fs/reiserfs/tail_conversion.c
--- 25/fs/reiserfs/tail_conversion.c~reiserfs-unmapped-buffer-fix	2003-06-26 17:35:24.000000000 -0700
+++ 25-akpm/fs/reiserfs/tail_conversion.c	2003-06-26 17:35:24.000000000 -0700
@@ -143,6 +143,16 @@ void reiserfs_unmap_buffer(struct buffer
     }
     clear_buffer_dirty(bh) ;
     lock_buffer(bh) ;
+    /* Remove the buffer from whatever list it belongs to. We are mostly
+       interested in removing it from per-sb j_dirty_buffers list, to avoid
+        BUG() on attempt to write not mapped buffer */
+    if ( !list_empty(&bh->b_assoc_buffers) && bh->b_page) {
+	struct inode *inode = bh->b_page->mapping->host;
+	struct reiserfs_journal *j = SB_JOURNAL(inode->i_sb);
+	spin_lock(&j->j_dirty_buffers_lock);
+	list_del_init(&bh->b_assoc_buffers);
+	spin_unlock(&j->j_dirty_buffers_lock);
+    }
     clear_buffer_mapped(bh) ;
     clear_buffer_req(bh) ;
     clear_buffer_new(bh);
@@ -180,6 +190,9 @@ unmap_buffers(struct page *page, loff_t 
         }
 	bh = next ;
       } while (bh != head) ;
+      if ( PAGE_SIZE == bh->b_size ) {
+	ClearPageDirty(page);
+      }
     }
   } 
 }

_