aboutsummaryrefslogtreecommitdiffstats
path: root/fs/logfs/segment.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/logfs/segment.c')
-rw-r--r--fs/logfs/segment.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/fs/logfs/segment.c b/fs/logfs/segment.c
index 1a14f9910d55..f77ce2b470ba 100644
--- a/fs/logfs/segment.c
+++ b/fs/logfs/segment.c
@@ -10,6 +10,7 @@
10 * three kinds of objects: inodes, dentries and blocks, both data and indirect. 10 * three kinds of objects: inodes, dentries and blocks, both data and indirect.
11 */ 11 */
12#include "logfs.h" 12#include "logfs.h"
13#include <linux/slab.h>
13 14
14static int logfs_mark_segment_bad(struct super_block *sb, u32 segno) 15static int logfs_mark_segment_bad(struct super_block *sb, u32 segno)
15{ 16{
@@ -93,50 +94,58 @@ void __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len,
93 } while (len); 94 } while (len);
94} 95}
95 96
96/* 97static void pad_partial_page(struct logfs_area *area)
97 * bdev_writeseg will write full pages. Memset the tail to prevent data leaks.
98 */
99static void pad_wbuf(struct logfs_area *area, int final)
100{ 98{
101 struct super_block *sb = area->a_sb; 99 struct super_block *sb = area->a_sb;
102 struct logfs_super *super = logfs_super(sb);
103 struct page *page; 100 struct page *page;
104 u64 ofs = dev_ofs(sb, area->a_segno, area->a_used_bytes); 101 u64 ofs = dev_ofs(sb, area->a_segno, area->a_used_bytes);
105 pgoff_t index = ofs >> PAGE_SHIFT; 102 pgoff_t index = ofs >> PAGE_SHIFT;
106 long offset = ofs & (PAGE_SIZE-1); 103 long offset = ofs & (PAGE_SIZE-1);
107 u32 len = PAGE_SIZE - offset; 104 u32 len = PAGE_SIZE - offset;
108 105
109 if (len == PAGE_SIZE) { 106 if (len % PAGE_SIZE) {
110 /* The math in this function can surely use some love */ 107 page = get_mapping_page(sb, index, 0);
111 len = 0;
112 }
113 if (len) {
114 BUG_ON(area->a_used_bytes >= super->s_segsize);
115
116 page = get_mapping_page(area->a_sb, index, 0);
117 BUG_ON(!page); /* FIXME: reserve a pool */ 108 BUG_ON(!page); /* FIXME: reserve a pool */
118 memset(page_address(page) + offset, 0xff, len); 109 memset(page_address(page) + offset, 0xff, len);
119 SetPagePrivate(page); 110 SetPagePrivate(page);
120 page_cache_release(page); 111 page_cache_release(page);
121 } 112 }
113}
122 114
123 if (!final) 115static void pad_full_pages(struct logfs_area *area)
124 return; 116{
117 struct super_block *sb = area->a_sb;
118 struct logfs_super *super = logfs_super(sb);
119 u64 ofs = dev_ofs(sb, area->a_segno, area->a_used_bytes);
120 u32 len = super->s_segsize - area->a_used_bytes;
121 pgoff_t index = PAGE_CACHE_ALIGN(ofs) >> PAGE_CACHE_SHIFT;
122 pgoff_t no_indizes = len >> PAGE_CACHE_SHIFT;
123 struct page *page;
125 124
126 area->a_used_bytes += len; 125 while (no_indizes) {
127 for ( ; area->a_used_bytes < super->s_segsize; 126 page = get_mapping_page(sb, index, 0);
128 area->a_used_bytes += PAGE_SIZE) {
129 /* Memset another page */
130 index++;
131 page = get_mapping_page(area->a_sb, index, 0);
132 BUG_ON(!page); /* FIXME: reserve a pool */ 127 BUG_ON(!page); /* FIXME: reserve a pool */
133 memset(page_address(page), 0xff, PAGE_SIZE); 128 SetPageUptodate(page);
129 memset(page_address(page), 0xff, PAGE_CACHE_SIZE);
134 SetPagePrivate(page); 130 SetPagePrivate(page);
135 page_cache_release(page); 131 page_cache_release(page);
132 index++;
133 no_indizes--;
136 } 134 }
137} 135}
138 136
139/* 137/*
138 * bdev_writeseg will write full pages. Memset the tail to prevent data leaks.
139 * Also make sure we allocate (and memset) all pages for final writeout.
140 */
141static void pad_wbuf(struct logfs_area *area, int final)
142{
143 pad_partial_page(area);
144 if (final)
145 pad_full_pages(area);
146}
147
148/*
140 * We have to be careful with the alias tree. Since lookup is done by bix, 149 * We have to be careful with the alias tree. Since lookup is done by bix,
141 * it needs to be normalized, so 14, 15, 16, etc. all match when dealing with 150 * it needs to be normalized, so 14, 15, 16, etc. all match when dealing with
142 * indirect blocks. So always use it through accessor functions. 151 * indirect blocks. So always use it through accessor functions.
@@ -174,14 +183,8 @@ static int btree_write_alias(struct super_block *sb, struct logfs_block *block,
174 return 0; 183 return 0;
175} 184}
176 185
177static gc_level_t btree_block_level(struct logfs_block *block)
178{
179 return expand_level(block->ino, block->level);
180}
181
182static struct logfs_block_ops btree_block_ops = { 186static struct logfs_block_ops btree_block_ops = {
183 .write_block = btree_write_block, 187 .write_block = btree_write_block,
184 .block_level = btree_block_level,
185 .free_block = __free_block, 188 .free_block = __free_block,
186 .write_alias = btree_write_alias, 189 .write_alias = btree_write_alias,
187}; 190};
@@ -683,7 +686,7 @@ int logfs_segment_delete(struct inode *inode, struct logfs_shadow *shadow)
683 return 0; 686 return 0;
684} 687}
685 688
686static void freeseg(struct super_block *sb, u32 segno) 689void freeseg(struct super_block *sb, u32 segno)
687{ 690{
688 struct logfs_super *super = logfs_super(sb); 691 struct logfs_super *super = logfs_super(sb);
689 struct address_space *mapping = super->s_mapping_inode->i_mapping; 692 struct address_space *mapping = super->s_mapping_inode->i_mapping;
@@ -910,7 +913,7 @@ err:
910 for (i--; i >= 0; i--) 913 for (i--; i >= 0; i--)
911 free_area(super->s_area[i]); 914 free_area(super->s_area[i]);
912 free_area(super->s_journal_area); 915 free_area(super->s_journal_area);
913 mempool_destroy(super->s_alias_pool); 916 logfs_mempool_destroy(super->s_alias_pool);
914 return -ENOMEM; 917 return -ENOMEM;
915} 918}
916 919