Btrfs: btrfs_mark_extent_written uses the wrong slot
authorShaohua Li <shaohua.li@intel.com>
Thu, 11 Feb 2010 07:43:00 +0000 (07:43 +0000)
committerChris Mason <chris.mason@oracle.com>
Fri, 12 Feb 2010 21:47:19 +0000 (16:47 -0500)
My test do: fallocate a big file and do write. The file is 512M, but
after file write is done btrfs-debug-tree shows:
item 6 key (257 EXTENT_DATA 0) itemoff 3516 itemsize 53
                extent data disk byte 1103101952 nr 536870912
                extent data offset 0 nr 399634432 ram 536870912
                extent compression 0
Looks like a regression introducted by
6c7d54ac87f338c479d9729e8392eca3f76e11e1, where we set wrong slot.

Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Acked-by: Yan Zheng <zheng.yan@oracle.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/file.c

index 413a30dafcdacaf62419f89c4be10b64c66926a1..a7fd9f3a750abe05ebd586e6db1dfda729a64aff 100644 (file)
@@ -720,13 +720,15 @@ again:
                                        inode->i_ino, orig_offset);
                BUG_ON(ret);
        }
-       fi = btrfs_item_ptr(leaf, path->slots[0],
-                          struct btrfs_file_extent_item);
        if (del_nr == 0) {
+               fi = btrfs_item_ptr(leaf, path->slots[0],
+                          struct btrfs_file_extent_item);
                btrfs_set_file_extent_type(leaf, fi,
                                           BTRFS_FILE_EXTENT_REG);
                btrfs_mark_buffer_dirty(leaf);
        } else {
+               fi = btrfs_item_ptr(leaf, del_slot - 1,
+                          struct btrfs_file_extent_item);
                btrfs_set_file_extent_type(leaf, fi,
                                           BTRFS_FILE_EXTENT_REG);
                btrfs_set_file_extent_num_bytes(leaf, fi,