Liu Hui
2008-Dec-04 14:08 UTC
[PATCH]Fix for map_private_extent_buffer to handle extent which is not page alignment
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); -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Liu Hui
2008-Dec-04 14:21 UTC
Re: [PATCH]Fix for map_private_extent_buffer to handle extent which is not page alignment
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 -- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Liu Hui
2008-Dec-04 14:28 UTC
Re: [PATCH]Fix for map_private_extent_buffer to handle extent which is not page alignment
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 -- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html