mirror of
https://github.com/team-infusion-developers/android_kernel_samsung_msm8976.git
synced 2024-09-21 11:53:01 +00:00
Simplify and fix pad_wbuf
A comment in the old code read: /* The math in this function can surely use some love */ And indeed it did. In the case that area->a_used_bytes is exactly 4096 bytes below segment size it fell apart. pad_wbuf is now split into two helpers that are significantly less complicated. Signed-off-by: Joern Engel <joern@logfs.org>
This commit is contained in:
parent
1932191726
commit
81def6b986
|
@ -93,49 +93,57 @@ void __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len,
|
||||||
} while (len);
|
} while (len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static void pad_partial_page(struct logfs_area *area)
|
||||||
* bdev_writeseg will write full pages. Memset the tail to prevent data leaks.
|
|
||||||
*/
|
|
||||||
static void pad_wbuf(struct logfs_area *area, int final)
|
|
||||||
{
|
{
|
||||||
struct super_block *sb = area->a_sb;
|
struct super_block *sb = area->a_sb;
|
||||||
struct logfs_super *super = logfs_super(sb);
|
|
||||||
struct page *page;
|
struct page *page;
|
||||||
u64 ofs = dev_ofs(sb, area->a_segno, area->a_used_bytes);
|
u64 ofs = dev_ofs(sb, area->a_segno, area->a_used_bytes);
|
||||||
pgoff_t index = ofs >> PAGE_SHIFT;
|
pgoff_t index = ofs >> PAGE_SHIFT;
|
||||||
long offset = ofs & (PAGE_SIZE-1);
|
long offset = ofs & (PAGE_SIZE-1);
|
||||||
u32 len = PAGE_SIZE - offset;
|
u32 len = PAGE_SIZE - offset;
|
||||||
|
|
||||||
if (len == PAGE_SIZE) {
|
if (len % PAGE_SIZE) {
|
||||||
/* The math in this function can surely use some love */
|
page = get_mapping_page(sb, index, 0);
|
||||||
len = 0;
|
|
||||||
}
|
|
||||||
if (len) {
|
|
||||||
BUG_ON(area->a_used_bytes >= super->s_segsize);
|
|
||||||
|
|
||||||
page = get_mapping_page(area->a_sb, index, 0);
|
|
||||||
BUG_ON(!page); /* FIXME: reserve a pool */
|
BUG_ON(!page); /* FIXME: reserve a pool */
|
||||||
memset(page_address(page) + offset, 0xff, len);
|
memset(page_address(page) + offset, 0xff, len);
|
||||||
SetPagePrivate(page);
|
SetPagePrivate(page);
|
||||||
page_cache_release(page);
|
page_cache_release(page);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!final)
|
static void pad_full_pages(struct logfs_area *area)
|
||||||
return;
|
{
|
||||||
|
struct super_block *sb = area->a_sb;
|
||||||
|
struct logfs_super *super = logfs_super(sb);
|
||||||
|
u64 ofs = dev_ofs(sb, area->a_segno, area->a_used_bytes);
|
||||||
|
u32 len = super->s_segsize - area->a_used_bytes;
|
||||||
|
pgoff_t index = PAGE_CACHE_ALIGN(ofs) >> PAGE_CACHE_SHIFT;
|
||||||
|
pgoff_t no_indizes = len >> PAGE_CACHE_SHIFT;
|
||||||
|
struct page *page;
|
||||||
|
|
||||||
area->a_used_bytes += len;
|
while (no_indizes) {
|
||||||
for ( ; area->a_used_bytes < super->s_segsize;
|
page = get_mapping_page(sb, index, 0);
|
||||||
area->a_used_bytes += PAGE_SIZE) {
|
|
||||||
/* Memset another page */
|
|
||||||
index++;
|
|
||||||
page = get_mapping_page(area->a_sb, index, 0);
|
|
||||||
BUG_ON(!page); /* FIXME: reserve a pool */
|
BUG_ON(!page); /* FIXME: reserve a pool */
|
||||||
memset(page_address(page), 0xff, PAGE_SIZE);
|
SetPageUptodate(page);
|
||||||
|
memset(page_address(page), 0xff, PAGE_CACHE_SIZE);
|
||||||
SetPagePrivate(page);
|
SetPagePrivate(page);
|
||||||
page_cache_release(page);
|
page_cache_release(page);
|
||||||
|
index++;
|
||||||
|
no_indizes--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bdev_writeseg will write full pages. Memset the tail to prevent data leaks.
|
||||||
|
* Also make sure we allocate (and memset) all pages for final writeout.
|
||||||
|
*/
|
||||||
|
static void pad_wbuf(struct logfs_area *area, int final)
|
||||||
|
{
|
||||||
|
pad_partial_page(area);
|
||||||
|
if (final)
|
||||||
|
pad_full_pages(area);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We have to be careful with the alias tree. Since lookup is done by bix,
|
* We have to be careful with the alias tree. Since lookup is done by bix,
|
||||||
* it needs to be normalized, so 14, 15, 16, etc. all match when dealing with
|
* it needs to be normalized, so 14, 15, 16, etc. all match when dealing with
|
||||||
|
|
Loading…
Reference in a new issue