* [PATCH]Fix for map_private_extent_buffer to handle extent which is not page alignment
@ 2008-12-04 14:08 Liu Hui
2008-12-04 14:21 ` Liu Hui
0 siblings, 1 reply; 3+ messages in thread
From: Liu Hui @ 2008-12-04 14:08 UTC (permalink / raw)
To: linux-btrfs
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);
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH]Fix for map_private_extent_buffer to handle extent which is not page alignment
2008-12-04 14:08 [PATCH]Fix for map_private_extent_buffer to handle extent which is not page alignment Liu Hui
@ 2008-12-04 14:21 ` Liu Hui
2008-12-04 14:28 ` Liu Hui
0 siblings, 1 reply; 3+ messages in thread
From: Liu Hui @ 2008-12-04 14:21 UTC (permalink / raw)
To: linux-btrfs
There is a little problem with the first ASCII figure, here is the new one.
|-extent1-|
+-----++-----+
|page1||page2|
+-----++-----+
Thanks,
Liu Hui
2008/12/4 Liu Hui <onlyflyer@gmail.com>:
> 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);
>
--
Thanks & Best Regards
Liu Hui
--
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH]Fix for map_private_extent_buffer to handle extent which is not page alignment
2008-12-04 14:21 ` Liu Hui
@ 2008-12-04 14:28 ` Liu Hui
0 siblings, 0 replies; 3+ messages in thread
From: Liu Hui @ 2008-12-04 14:28 UTC (permalink / raw)
To: linux-btrfs
Hi,
I don't know why GMAIL mix my ASCII figure, the figure for extent1 is
still not correct. Here is the newest one, hope GMAIL works.
|-extent1-|
+-----++-----+
|page1||page2|
+-----++-----+
Thanks
2008/12/4 Liu Hui <onlyflyer@gmail.com>:
> There is a little problem with the first ASCII figure, here is the new one.
> |-extent1-|
> +-----++-----+
> |page1||page2|
> +-----++-----+
>
> Thanks,
> Liu Hui
>
> 2008/12/4 Liu Hui <onlyflyer@gmail.com>:
>> 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);
>>
>
> --
> Thanks & Best Regards
> Liu Hui
> --
>
--
Thanks & Best Regards
Liu Hui
--
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-12-04 14:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-04 14:08 [PATCH]Fix for map_private_extent_buffer to handle extent which is not page alignment Liu Hui
2008-12-04 14:21 ` Liu Hui
2008-12-04 14:28 ` Liu Hui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox