Skip to contentSkip to conversation

Btrfs: Fix page count calculation

PATCH In review Yan, Zheng 2 participants 2 messages Jan 18, 2011 – Jan 19, 2011 Btrfs file system

lore
Share & tools
lore

Yan, Zheng

author
#0 lore raw

PATCH 1/1 Btrfs: Fix page count calculation

take offset of start position into account when calculating page count.

---

fs/btrfs/file.c +4 -4
index 66836d8..ef94e46 100644
@@ -970,8 +970,8 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
 		size_t write_bytes = min(iov_iter_count(&i),
 					 nrptrs * (size_t)PAGE_CACHE_SIZE -
 					 offset);
-		size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >>
-					PAGE_CACHE_SHIFT;
+		size_t num_pages = (write_bytes + offset +
+				    PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
 
 		WARN_ON(num_pages > nrptrs);
 		memset(pages, 0, sizeof(struct page *) * nrptrs);
@@ -1001,8 +1001,8 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
 
 		copied = btrfs_copy_from_user(pos, num_pages,
 					   write_bytes, pages, &i);
-		dirty_pages = (copied + PAGE_CACHE_SIZE - 1) >>
-					PAGE_CACHE_SHIFT;
+		dirty_pages = (copied + offset + PAGE_CACHE_SIZE - 1) >>
+				PAGE_CACHE_SHIFT;
 
 		if (num_pages > dirty_pages) {
 			if (copied > 0)
#1 lore raw

Excerpts from Yan, Zheng's message of 2011-01-18 00:34:40 -0500:

Quoted 1 line

take offset of start position into account when calculating page count.

Thanks Yan, do you have a test case that exposes this? I'd like to add it to xfsqa if it makes sense.

-chris