Hi

"W. Wilson Ho" wrote:

>
>         I now believe it is a reiserfs/kernel bug.  I've managed to
> reproduce the bug in the following cases:
>

Ok, it appeared to be a known issue. When getting a problem do you have in your logs
something like:
"vs-: reiserfs_get_block: XXX YYY ZZZ UNKNOWN should not be found" or
"PAP-5710: reiserfs_paste_into_item: entry or pasted byte ([XXX YYY ZZZ UNKNOWN]) 
exists"?

If yes - you are hitting a problem known as "not perfect handling of race conditions
occuring during writing pages to a sparse file".

There are two fixes for this problem:
first is "expanding truncate" (although I am not sure which kernel it is for)
second changes reiserfs_get_block (patch against 2.4.8) to handle this race properly. 
It is
probably less tested then the first one, it survives your mmap test for me though.

Thanks,
vs




--- 1.4/include/linux/fs.h      Tue Jun 12 13:31:34 2001
+++ edited/include/linux/fs.h   Mon Jun 18 00:21:16 2001
@@ -1316,6 +1316,9 @@
 extern int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*);
 extern int cont_prepare_write(struct page*, unsigned, unsigned, get_block_t*,
                                unsigned long *);
+
+int generic_cont_expand(struct inode *inode, loff_t size) ;
+
 extern int block_sync_page(struct page *);
 
 int generic_block_bmap(struct address_space *, long, get_block_t *);
--- 1.4/kernel/ksyms.c  Mon Jun 11 15:15:27 2001
+++ edited/kernel/ksyms.c       Sun Jun 17 22:56:05 2001
@@ -200,6 +200,7 @@
 EXPORT_SYMBOL(block_read_full_page);
 EXPORT_SYMBOL(block_prepare_write);
 EXPORT_SYMBOL(block_sync_page);
+EXPORT_SYMBOL(generic_cont_expand);
 EXPORT_SYMBOL(cont_prepare_write);
 EXPORT_SYMBOL(generic_commit_write);
 EXPORT_SYMBOL(block_truncate_page);
--- 1.4/fs/buffer.c     Tue Jun 12 06:21:14 2001
+++ edited/fs/buffer.c  Mon Jun 18 00:44:16 2001
@@ -1743,6 +1743,47 @@
        return 0;
 }
 
+int generic_cont_expand(struct inode *inode, loff_t size)
+{
+       struct address_space *mapping = inode->i_mapping;
+       struct page *page;
+       unsigned long index, offset, limit;
+       int err;
+
+       limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
+       if (limit != RLIM_INFINITY) {
+               if (size > limit) {
+                       send_sig(SIGXFSZ, current, 0);
+                       size = limit;
+               }
+       }
+       offset = (size & (PAGE_CACHE_SIZE-1)); /* Within page */
+
+       /* ugh.  in prepare/commit_write, if from==to==start of block, we 
+       ** skip the prepare.  make sure we never send an offset for the start
+       ** of a block
+       */
+       if ((offset & (inode->i_sb->s_blocksize - 1)) == 0) {
+           offset++ ;
+       }
+       index = size >> PAGE_CACHE_SHIFT;
+       err = -ENOMEM;
+       page = grab_cache_page(mapping, index);
+       if (!page)
+               goto out;
+       err = mapping->a_ops->prepare_write(NULL, page, offset, offset);
+       if (!err) {
+               char *p = page_address(page) ;
+               err = mapping->a_ops->commit_write(NULL, page, offset, offset);
+       }
+       UnlockPage(page);
+       page_cache_release(page);
+       if (err > 0)
+               err = 0;
+out:
+       return err;
+}
+
 /*
  * For moronic filesystems that do not allow holes in file.
  * We may have to extend the file.
--- 1.2/fs/reiserfs/file.c      Sat Apr 28 11:27:17 2001
+++ edited/fs/reiserfs/file.c   Mon Jun 18 01:00:33 2001
@@ -116,6 +116,13 @@
         if (inode_items_version(inode) == ITEM_VERSION_1 && 
            attr->ia_size > MAX_NON_LFS)
             return -EFBIG ;
+
+       /* fill in hole pointers in the expanding truncate case. */
+        if (attr->ia_size > inode->i_size) {
+           error = generic_cont_expand(inode, attr->ia_size) ;
+           if (error)
+               return error ;
+       }
     }
 
     error = inode_change_ok(inode, attr) ;
--- 1.4/fs/reiserfs/inode.c     Wed Jun 13 14:38:36 2001
+++ edited/fs/reiserfs/inode.c  Sun Jun 17 23:23:47 2001
@@ -1959,7 +1959,7 @@
     /* we test for O_SYNC here so we can commit the transaction
     ** for any packed tails the file might have had
     */
-    if (f->f_flags & O_SYNC) {
+    if (f && (f->f_flags & O_SYNC)) {
        journal_begin(&th, inode->i_sb, 1) ;
        reiserfs_prepare_for_journal(inode->i_sb, 
                                     SB_BUFFER_WITH_SB(inode->i_sb), 1) ;

Reply via email to