diff options
Diffstat (limited to 'fs/logfs/segment.c')
-rw-r--r-- | fs/logfs/segment.c | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/fs/logfs/segment.c b/fs/logfs/segment.c index 1a14f9910d55..801a3a141625 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 | ||
14 | static int logfs_mark_segment_bad(struct super_block *sb, u32 segno) | 15 | static 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 | /* | 97 | static void pad_partial_page(struct logfs_area *area) |
97 | * bdev_writeseg will write full pages. Memset the tail to prevent data leaks. | ||
98 | */ | ||
99 | static 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) | 115 | static 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 | */ | ||
141 | static 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. |
@@ -683,7 +692,7 @@ int logfs_segment_delete(struct inode *inode, struct logfs_shadow *shadow) | |||
683 | return 0; | 692 | return 0; |
684 | } | 693 | } |
685 | 694 | ||
686 | static void freeseg(struct super_block *sb, u32 segno) | 695 | void freeseg(struct super_block *sb, u32 segno) |
687 | { | 696 | { |
688 | struct logfs_super *super = logfs_super(sb); | 697 | struct logfs_super *super = logfs_super(sb); |
689 | struct address_space *mapping = super->s_mapping_inode->i_mapping; | 698 | struct address_space *mapping = super->s_mapping_inode->i_mapping; |