[btrfs-devel][patch]handle special case when compute last page's index

Yan Zheng yanzheng at 21cn.com
Wed Sep 19 07:58:22 PDT 2007


Hello,

When i_size is multiples of PAGE_CACHE_SIZE, the last page's index
computed by the right-shift is larger than the correct value.

Regards
YZ


diff -r d0921c0349a9 extent_map.c
--- a/extent_map.c	Fri Sep 14 10:23:29 2007 -0400
+++ b/extent_map.c	Wed Sep 19 16:50:16 2007 +0800
@@ -1527,6 +1527,11 @@ int extent_write_full_page(struct extent

 	if (page->index == end_index) {
 		size_t offset = i_size & (PAGE_CACHE_SIZE - 1);
+		if (!offset) {
+			clear_extent_dirty(tree, start, page_end, GFP_NOFS);
+			unlock_page(page);
+			return 0;
+		}
 		zero_user_page(page, offset,
 			       PAGE_CACHE_SIZE - offset, KM_USER0);
 	}
diff -r d0921c0349a9 inode.c
--- a/inode.c	Fri Sep 14 10:23:29 2007 -0400
+++ b/inode.c	Wed Sep 19 17:06:20 2007 +0800
@@ -1922,7 +1923,9 @@ int btrfs_defrag_file(struct file *file)

 	mutex_lock(&inode->i_mutex);
 	last_index = inode->i_size >> PAGE_CACHE_SHIFT;
-	for (i = 0; i <= last_index; i++) {
+	if (inode->i_size & (PAGE_CACHE_SIZE - 1))
+		last_index++;
+	for (i = 0; i < last_index; i++) {
 		if (i == ra_index) {
 			ra_index = force_ra(inode->i_mapping, &file->f_ra,
 					    file, ra_index, last_index);



More information about the Btrfs-devel mailing list