From: "Liu Hui" <onlyflyer@gmail.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH]Fix for map_private_extent_buffer to handle extent which is not page alignment
Date: Thu, 4 Dec 2008 22:08:36 +0800 [thread overview]
Message-ID: <2c3b11250812040608r6eb4eb59xcdb6f53a72b5feb6@mail.gmail.com> (raw)
Hi,
Now, BTRFS only supports page alignment extent. But in
map_private_extent(), there are already some codes to handle the
extent which is not page alignment. For example,
map_private_extent_buffer also wants to handle a extent which is 7K
length properly. The problem is the codes are not enough, e.g. in the
following figure, map_private_extent_buffer can handle extent1, but it
can't take the right behavior to handle extent2. This patch fixs it.
PS:Please use the mono font to view the ASCII figures, thanks.
|-extent1-|
+-----++-----+
|page1||page2|
+-----++-----+
|-extent2-|
+-----++-----+
|page1||page2|
+-----++-----+
--
Thanks & Best Regards
Liu Hui
--
diff --git a/extent_io.c b/extent_io.c
index c3dfe2a..cac47d1 100644
--- a/extent_io.c
+++ b/extent_io.c
@@ -3426,9 +3426,11 @@ int map_private_extent_buffer(struct
extent_buffer *eb, unsigned long start,
char *kaddr;
struct page *p;
size_t start_offset = eb->start & ((u64)PAGE_CACHE_SIZE - 1);
+ size_t last_offset;
unsigned long i = (start_offset + start) >> PAGE_CACHE_SHIFT;
unsigned long end_i = (start_offset + start + min_len - 1) >>
PAGE_CACHE_SHIFT;
+ unsigned long last_i = (start_offset + eb->len - 1) >> PAGE_CACHE_SHIFT;
if (i != end_i)
return -EINVAL;
@@ -3440,8 +3442,16 @@ int map_private_extent_buffer(struct
extent_buffer *eb, unsigned long start,
offset = 0;
*map_start = ((u64)i << PAGE_CACHE_SHIFT) - start_offset;
}
+
+ if (i == last_i)
+ last_offset = ((u64)(i + 1) << PAGE_CACHE_SHIFT) - start_offset
+ - eb->len;
+ else
+ last_offset = 0;
+
if (start + min_len > eb->len) {
-printk("bad mapping eb start %Lu len %lu, wanted %lu %lu\n",
eb->start, eb->len, start, min_len);
+ printk("bad mapping eb start %Lu len %lu, wanted %lu %lu\n",
+ eb->start, eb->len, start, min_len);
WARN_ON(1);
}
@@ -3449,7 +3459,7 @@ printk("bad mapping eb start %Lu len %lu, wanted
%lu %lu\n", eb->start, eb->len,
kaddr = kmap_atomic(p, km);
*token = kaddr;
*map = kaddr + offset;
- *map_len = PAGE_CACHE_SIZE - offset;
+ *map_len = PAGE_CACHE_SIZE - offset - last_offset;
return 0;
}
EXPORT_SYMBOL(map_private_extent_buffer);
next reply other threads:[~2008-12-04 14:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-04 14:08 Liu Hui [this message]
2008-12-04 14:21 ` [PATCH]Fix for map_private_extent_buffer to handle extent which is not page alignment Liu Hui
2008-12-04 14:28 ` Liu Hui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2c3b11250812040608r6eb4eb59xcdb6f53a72b5feb6@mail.gmail.com \
--to=onlyflyer@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox