diff options
Diffstat (limited to 'fs/logfs/dev_mtd.c')
-rw-r--r-- | fs/logfs/dev_mtd.c | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/fs/logfs/dev_mtd.c b/fs/logfs/dev_mtd.c index 339e17e9133d..eb423ebcf538 100644 --- a/fs/logfs/dev_mtd.c +++ b/fs/logfs/dev_mtd.c | |||
@@ -13,7 +13,8 @@ | |||
13 | 13 | ||
14 | #define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1)) | 14 | #define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1)) |
15 | 15 | ||
16 | static int mtd_read(struct super_block *sb, loff_t ofs, size_t len, void *buf) | 16 | static int logfs_mtd_read(struct super_block *sb, loff_t ofs, size_t len, |
17 | void *buf) | ||
17 | { | 18 | { |
18 | struct mtd_info *mtd = logfs_super(sb)->s_mtd; | 19 | struct mtd_info *mtd = logfs_super(sb)->s_mtd; |
19 | size_t retlen; | 20 | size_t retlen; |
@@ -31,7 +32,8 @@ static int mtd_read(struct super_block *sb, loff_t ofs, size_t len, void *buf) | |||
31 | return 0; | 32 | return 0; |
32 | } | 33 | } |
33 | 34 | ||
34 | static int mtd_write(struct super_block *sb, loff_t ofs, size_t len, void *buf) | 35 | static int loffs_mtd_write(struct super_block *sb, loff_t ofs, size_t len, |
36 | void *buf) | ||
35 | { | 37 | { |
36 | struct logfs_super *super = logfs_super(sb); | 38 | struct logfs_super *super = logfs_super(sb); |
37 | struct mtd_info *mtd = super->s_mtd; | 39 | struct mtd_info *mtd = super->s_mtd; |
@@ -60,14 +62,15 @@ static int mtd_write(struct super_block *sb, loff_t ofs, size_t len, void *buf) | |||
60 | * asynchronous properties. So just to prevent the first implementor of such | 62 | * asynchronous properties. So just to prevent the first implementor of such |
61 | * a thing from breaking logfs in 2350, we do the usual pointless dance to | 63 | * a thing from breaking logfs in 2350, we do the usual pointless dance to |
62 | * declare a completion variable and wait for completion before returning | 64 | * declare a completion variable and wait for completion before returning |
63 | * from mtd_erase(). What an exercise in futility! | 65 | * from logfs_mtd_erase(). What an exercise in futility! |
64 | */ | 66 | */ |
65 | static void logfs_erase_callback(struct erase_info *ei) | 67 | static void logfs_erase_callback(struct erase_info *ei) |
66 | { | 68 | { |
67 | complete((struct completion *)ei->priv); | 69 | complete((struct completion *)ei->priv); |
68 | } | 70 | } |
69 | 71 | ||
70 | static int mtd_erase_mapping(struct super_block *sb, loff_t ofs, size_t len) | 72 | static int logfs_mtd_erase_mapping(struct super_block *sb, loff_t ofs, |
73 | size_t len) | ||
71 | { | 74 | { |
72 | struct logfs_super *super = logfs_super(sb); | 75 | struct logfs_super *super = logfs_super(sb); |
73 | struct address_space *mapping = super->s_mapping_inode->i_mapping; | 76 | struct address_space *mapping = super->s_mapping_inode->i_mapping; |
@@ -84,7 +87,7 @@ static int mtd_erase_mapping(struct super_block *sb, loff_t ofs, size_t len) | |||
84 | return 0; | 87 | return 0; |
85 | } | 88 | } |
86 | 89 | ||
87 | static int mtd_erase(struct super_block *sb, loff_t ofs, size_t len, | 90 | static int logfs_mtd_erase(struct super_block *sb, loff_t ofs, size_t len, |
88 | int ensure_write) | 91 | int ensure_write) |
89 | { | 92 | { |
90 | struct mtd_info *mtd = logfs_super(sb)->s_mtd; | 93 | struct mtd_info *mtd = logfs_super(sb)->s_mtd; |
@@ -109,10 +112,10 @@ static int mtd_erase(struct super_block *sb, loff_t ofs, size_t len, | |||
109 | wait_for_completion(&complete); | 112 | wait_for_completion(&complete); |
110 | if (ei.state != MTD_ERASE_DONE) | 113 | if (ei.state != MTD_ERASE_DONE) |
111 | return -EIO; | 114 | return -EIO; |
112 | return mtd_erase_mapping(sb, ofs, len); | 115 | return logfs_mtd_erase_mapping(sb, ofs, len); |
113 | } | 116 | } |
114 | 117 | ||
115 | static void mtd_sync(struct super_block *sb) | 118 | static void logfs_mtd_sync(struct super_block *sb) |
116 | { | 119 | { |
117 | struct mtd_info *mtd = logfs_super(sb)->s_mtd; | 120 | struct mtd_info *mtd = logfs_super(sb)->s_mtd; |
118 | 121 | ||
@@ -120,12 +123,12 @@ static void mtd_sync(struct super_block *sb) | |||
120 | mtd->sync(mtd); | 123 | mtd->sync(mtd); |
121 | } | 124 | } |
122 | 125 | ||
123 | static int mtd_readpage(void *_sb, struct page *page) | 126 | static int logfs_mtd_readpage(void *_sb, struct page *page) |
124 | { | 127 | { |
125 | struct super_block *sb = _sb; | 128 | struct super_block *sb = _sb; |
126 | int err; | 129 | int err; |
127 | 130 | ||
128 | err = mtd_read(sb, page->index << PAGE_SHIFT, PAGE_SIZE, | 131 | err = logfs_mtd_read(sb, page->index << PAGE_SHIFT, PAGE_SIZE, |
129 | page_address(page)); | 132 | page_address(page)); |
130 | if (err == -EUCLEAN || err == -EBADMSG) { | 133 | if (err == -EUCLEAN || err == -EBADMSG) { |
131 | /* -EBADMSG happens regularly on power failures */ | 134 | /* -EBADMSG happens regularly on power failures */ |
@@ -143,11 +146,11 @@ static int mtd_readpage(void *_sb, struct page *page) | |||
143 | return err; | 146 | return err; |
144 | } | 147 | } |
145 | 148 | ||
146 | static struct page *mtd_find_first_sb(struct super_block *sb, u64 *ofs) | 149 | static struct page *logfs_mtd_find_first_sb(struct super_block *sb, u64 *ofs) |
147 | { | 150 | { |
148 | struct logfs_super *super = logfs_super(sb); | 151 | struct logfs_super *super = logfs_super(sb); |
149 | struct address_space *mapping = super->s_mapping_inode->i_mapping; | 152 | struct address_space *mapping = super->s_mapping_inode->i_mapping; |
150 | filler_t *filler = mtd_readpage; | 153 | filler_t *filler = logfs_mtd_readpage; |
151 | struct mtd_info *mtd = super->s_mtd; | 154 | struct mtd_info *mtd = super->s_mtd; |
152 | 155 | ||
153 | if (!mtd->block_isbad) | 156 | if (!mtd->block_isbad) |
@@ -163,11 +166,11 @@ static struct page *mtd_find_first_sb(struct super_block *sb, u64 *ofs) | |||
163 | return read_cache_page(mapping, *ofs >> PAGE_SHIFT, filler, sb); | 166 | return read_cache_page(mapping, *ofs >> PAGE_SHIFT, filler, sb); |
164 | } | 167 | } |
165 | 168 | ||
166 | static struct page *mtd_find_last_sb(struct super_block *sb, u64 *ofs) | 169 | static struct page *logfs_mtd_find_last_sb(struct super_block *sb, u64 *ofs) |
167 | { | 170 | { |
168 | struct logfs_super *super = logfs_super(sb); | 171 | struct logfs_super *super = logfs_super(sb); |
169 | struct address_space *mapping = super->s_mapping_inode->i_mapping; | 172 | struct address_space *mapping = super->s_mapping_inode->i_mapping; |
170 | filler_t *filler = mtd_readpage; | 173 | filler_t *filler = logfs_mtd_readpage; |
171 | struct mtd_info *mtd = super->s_mtd; | 174 | struct mtd_info *mtd = super->s_mtd; |
172 | 175 | ||
173 | if (!mtd->block_isbad) | 176 | if (!mtd->block_isbad) |
@@ -184,7 +187,7 @@ static struct page *mtd_find_last_sb(struct super_block *sb, u64 *ofs) | |||
184 | return read_cache_page(mapping, *ofs >> PAGE_SHIFT, filler, sb); | 187 | return read_cache_page(mapping, *ofs >> PAGE_SHIFT, filler, sb); |
185 | } | 188 | } |
186 | 189 | ||
187 | static int __mtd_writeseg(struct super_block *sb, u64 ofs, pgoff_t index, | 190 | static int __logfs_mtd_writeseg(struct super_block *sb, u64 ofs, pgoff_t index, |
188 | size_t nr_pages) | 191 | size_t nr_pages) |
189 | { | 192 | { |
190 | struct logfs_super *super = logfs_super(sb); | 193 | struct logfs_super *super = logfs_super(sb); |
@@ -196,8 +199,8 @@ static int __mtd_writeseg(struct super_block *sb, u64 ofs, pgoff_t index, | |||
196 | page = find_lock_page(mapping, index + i); | 199 | page = find_lock_page(mapping, index + i); |
197 | BUG_ON(!page); | 200 | BUG_ON(!page); |
198 | 201 | ||
199 | err = mtd_write(sb, page->index << PAGE_SHIFT, PAGE_SIZE, | 202 | err = loffs_mtd_write(sb, page->index << PAGE_SHIFT, PAGE_SIZE, |
200 | page_address(page)); | 203 | page_address(page)); |
201 | unlock_page(page); | 204 | unlock_page(page); |
202 | page_cache_release(page); | 205 | page_cache_release(page); |
203 | if (err) | 206 | if (err) |
@@ -206,7 +209,7 @@ static int __mtd_writeseg(struct super_block *sb, u64 ofs, pgoff_t index, | |||
206 | return 0; | 209 | return 0; |
207 | } | 210 | } |
208 | 211 | ||
209 | static void mtd_writeseg(struct super_block *sb, u64 ofs, size_t len) | 212 | static void logfs_mtd_writeseg(struct super_block *sb, u64 ofs, size_t len) |
210 | { | 213 | { |
211 | struct logfs_super *super = logfs_super(sb); | 214 | struct logfs_super *super = logfs_super(sb); |
212 | int head; | 215 | int head; |
@@ -227,15 +230,15 @@ static void mtd_writeseg(struct super_block *sb, u64 ofs, size_t len) | |||
227 | len += head; | 230 | len += head; |
228 | } | 231 | } |
229 | len = PAGE_ALIGN(len); | 232 | len = PAGE_ALIGN(len); |
230 | __mtd_writeseg(sb, ofs, ofs >> PAGE_SHIFT, len >> PAGE_SHIFT); | 233 | __logfs_mtd_writeseg(sb, ofs, ofs >> PAGE_SHIFT, len >> PAGE_SHIFT); |
231 | } | 234 | } |
232 | 235 | ||
233 | static void mtd_put_device(struct logfs_super *s) | 236 | static void logfs_mtd_put_device(struct logfs_super *s) |
234 | { | 237 | { |
235 | put_mtd_device(s->s_mtd); | 238 | put_mtd_device(s->s_mtd); |
236 | } | 239 | } |
237 | 240 | ||
238 | static int mtd_can_write_buf(struct super_block *sb, u64 ofs) | 241 | static int logfs_mtd_can_write_buf(struct super_block *sb, u64 ofs) |
239 | { | 242 | { |
240 | struct logfs_super *super = logfs_super(sb); | 243 | struct logfs_super *super = logfs_super(sb); |
241 | void *buf; | 244 | void *buf; |
@@ -244,7 +247,7 @@ static int mtd_can_write_buf(struct super_block *sb, u64 ofs) | |||
244 | buf = kmalloc(super->s_writesize, GFP_KERNEL); | 247 | buf = kmalloc(super->s_writesize, GFP_KERNEL); |
245 | if (!buf) | 248 | if (!buf) |
246 | return -ENOMEM; | 249 | return -ENOMEM; |
247 | err = mtd_read(sb, ofs, super->s_writesize, buf); | 250 | err = logfs_mtd_read(sb, ofs, super->s_writesize, buf); |
248 | if (err) | 251 | if (err) |
249 | goto out; | 252 | goto out; |
250 | if (memchr_inv(buf, 0xff, super->s_writesize)) | 253 | if (memchr_inv(buf, 0xff, super->s_writesize)) |
@@ -255,14 +258,14 @@ out: | |||
255 | } | 258 | } |
256 | 259 | ||
257 | static const struct logfs_device_ops mtd_devops = { | 260 | static const struct logfs_device_ops mtd_devops = { |
258 | .find_first_sb = mtd_find_first_sb, | 261 | .find_first_sb = logfs_mtd_find_first_sb, |
259 | .find_last_sb = mtd_find_last_sb, | 262 | .find_last_sb = logfs_mtd_find_last_sb, |
260 | .readpage = mtd_readpage, | 263 | .readpage = logfs_mtd_readpage, |
261 | .writeseg = mtd_writeseg, | 264 | .writeseg = logfs_mtd_writeseg, |
262 | .erase = mtd_erase, | 265 | .erase = logfs_mtd_erase, |
263 | .can_write_buf = mtd_can_write_buf, | 266 | .can_write_buf = logfs_mtd_can_write_buf, |
264 | .sync = mtd_sync, | 267 | .sync = logfs_mtd_sync, |
265 | .put_device = mtd_put_device, | 268 | .put_device = logfs_mtd_put_device, |
266 | }; | 269 | }; |
267 | 270 | ||
268 | int logfs_get_sb_mtd(struct logfs_super *s, int mtdnr) | 271 | int logfs_get_sb_mtd(struct logfs_super *s, int mtdnr) |