Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | * fs/logfs/dev_bdev.c - Device access methods for block devices |
| 3 | * |
| 4 | * As should be obvious for Linux kernel code, license is GPLv2 |
| 5 | * |
| 6 | * Copyright (c) 2005-2008 Joern Engel <joern@logfs.org> |
| 7 | */ |
| 8 | #include "logfs.h" |
| 9 | #include <linux/bio.h> |
| 10 | #include <linux/blkdev.h> |
| 11 | #include <linux/buffer_head.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/gfp.h> |
Linus Torvalds | 268bb0c | 2011-05-20 12:50:29 -0700 | [diff] [blame] | 13 | #include <linux/prefetch.h> |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 14 | |
| 15 | #define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1)) |
| 16 | |
Mike Christie | 95fe6c1 | 2016-06-05 14:31:48 -0500 | [diff] [blame] | 17 | static int sync_request(struct page *page, struct block_device *bdev, int op) |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 18 | { |
| 19 | struct bio bio; |
| 20 | struct bio_vec bio_vec; |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 21 | |
| 22 | bio_init(&bio); |
Prasad Joshi | cd8bfa9 | 2012-04-02 09:23:04 +0530 | [diff] [blame] | 23 | bio.bi_max_vecs = 1; |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 24 | bio.bi_io_vec = &bio_vec; |
| 25 | bio_vec.bv_page = page; |
| 26 | bio_vec.bv_len = PAGE_SIZE; |
| 27 | bio_vec.bv_offset = 0; |
| 28 | bio.bi_vcnt = 1; |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 29 | bio.bi_bdev = bdev; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 30 | bio.bi_iter.bi_sector = page->index * (PAGE_SIZE >> 9); |
| 31 | bio.bi_iter.bi_size = PAGE_SIZE; |
Mike Christie | 95fe6c1 | 2016-06-05 14:31:48 -0500 | [diff] [blame] | 32 | bio_set_op_attrs(&bio, op, 0); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 33 | |
Mike Christie | 4e49ea4 | 2016-06-05 14:31:41 -0500 | [diff] [blame] | 34 | return submit_bio_wait(&bio); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static int bdev_readpage(void *_sb, struct page *page) |
| 38 | { |
| 39 | struct super_block *sb = _sb; |
| 40 | struct block_device *bdev = logfs_super(sb)->s_bdev; |
| 41 | int err; |
| 42 | |
| 43 | err = sync_request(page, bdev, READ); |
| 44 | if (err) { |
| 45 | ClearPageUptodate(page); |
| 46 | SetPageError(page); |
| 47 | } else { |
| 48 | SetPageUptodate(page); |
| 49 | ClearPageError(page); |
| 50 | } |
| 51 | unlock_page(page); |
| 52 | return err; |
| 53 | } |
| 54 | |
| 55 | static DECLARE_WAIT_QUEUE_HEAD(wq); |
| 56 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 57 | static void writeseg_end_io(struct bio *bio) |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 58 | { |
Kent Overstreet | 2c30c71 | 2013-11-07 12:20:26 -0800 | [diff] [blame] | 59 | struct bio_vec *bvec; |
| 60 | int i; |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 61 | struct super_block *sb = bio->bi_private; |
| 62 | struct logfs_super *super = logfs_super(sb); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 63 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 64 | BUG_ON(bio->bi_error); /* FIXME: Retry io or write elsewhere */ |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 65 | |
Kent Overstreet | 2c30c71 | 2013-11-07 12:20:26 -0800 | [diff] [blame] | 66 | bio_for_each_segment_all(bvec, bio, i) { |
| 67 | end_page_writeback(bvec->bv_page); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 68 | put_page(bvec->bv_page); |
Kent Overstreet | 2c30c71 | 2013-11-07 12:20:26 -0800 | [diff] [blame] | 69 | } |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 70 | bio_put(bio); |
| 71 | if (atomic_dec_and_test(&super->s_pending_writes)) |
| 72 | wake_up(&wq); |
| 73 | } |
| 74 | |
| 75 | static int __bdev_writeseg(struct super_block *sb, u64 ofs, pgoff_t index, |
| 76 | size_t nr_pages) |
| 77 | { |
| 78 | struct logfs_super *super = logfs_super(sb); |
| 79 | struct address_space *mapping = super->s_mapping_inode->i_mapping; |
| 80 | struct bio *bio; |
| 81 | struct page *page; |
Prasad Joshi | 9f0bbd8 | 2012-07-23 10:32:11 +0530 | [diff] [blame] | 82 | unsigned int max_pages; |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 83 | int i; |
| 84 | |
Sudip Mukherjee | ce4f2fd | 2015-11-05 18:43:49 -0800 | [diff] [blame] | 85 | max_pages = min_t(size_t, nr_pages, BIO_MAX_PAGES); |
Prasad Joshi | 9f0bbd8 | 2012-07-23 10:32:11 +0530 | [diff] [blame] | 86 | |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 87 | bio = bio_alloc(GFP_NOFS, max_pages); |
Joern Engel | 59fe27c | 2010-03-17 13:47:45 +0100 | [diff] [blame] | 88 | BUG_ON(!bio); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 89 | |
| 90 | for (i = 0; i < nr_pages; i++) { |
| 91 | if (i >= max_pages) { |
| 92 | /* Block layer cannot split bios :( */ |
| 93 | bio->bi_vcnt = i; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 94 | bio->bi_iter.bi_size = i * PAGE_SIZE; |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 95 | bio->bi_bdev = super->s_bdev; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 96 | bio->bi_iter.bi_sector = ofs >> 9; |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 97 | bio->bi_private = sb; |
| 98 | bio->bi_end_io = writeseg_end_io; |
Mike Christie | 95fe6c1 | 2016-06-05 14:31:48 -0500 | [diff] [blame] | 99 | bio_set_op_attrs(bio, REQ_OP_WRITE, 0); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 100 | atomic_inc(&super->s_pending_writes); |
Mike Christie | 4e49ea4 | 2016-06-05 14:31:41 -0500 | [diff] [blame] | 101 | submit_bio(bio); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 102 | |
| 103 | ofs += i * PAGE_SIZE; |
| 104 | index += i; |
| 105 | nr_pages -= i; |
| 106 | i = 0; |
| 107 | |
| 108 | bio = bio_alloc(GFP_NOFS, max_pages); |
| 109 | BUG_ON(!bio); |
| 110 | } |
| 111 | page = find_lock_page(mapping, index + i); |
| 112 | BUG_ON(!page); |
| 113 | bio->bi_io_vec[i].bv_page = page; |
| 114 | bio->bi_io_vec[i].bv_len = PAGE_SIZE; |
| 115 | bio->bi_io_vec[i].bv_offset = 0; |
| 116 | |
| 117 | BUG_ON(PageWriteback(page)); |
| 118 | set_page_writeback(page); |
| 119 | unlock_page(page); |
| 120 | } |
| 121 | bio->bi_vcnt = nr_pages; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 122 | bio->bi_iter.bi_size = nr_pages * PAGE_SIZE; |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 123 | bio->bi_bdev = super->s_bdev; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 124 | bio->bi_iter.bi_sector = ofs >> 9; |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 125 | bio->bi_private = sb; |
| 126 | bio->bi_end_io = writeseg_end_io; |
Mike Christie | 95fe6c1 | 2016-06-05 14:31:48 -0500 | [diff] [blame] | 127 | bio_set_op_attrs(bio, REQ_OP_WRITE, 0); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 128 | atomic_inc(&super->s_pending_writes); |
Mike Christie | 4e49ea4 | 2016-06-05 14:31:41 -0500 | [diff] [blame] | 129 | submit_bio(bio); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | static void bdev_writeseg(struct super_block *sb, u64 ofs, size_t len) |
| 134 | { |
| 135 | struct logfs_super *super = logfs_super(sb); |
| 136 | int head; |
| 137 | |
| 138 | BUG_ON(super->s_flags & LOGFS_SB_FLAG_RO); |
| 139 | |
| 140 | if (len == 0) { |
| 141 | /* This can happen when the object fit perfectly into a |
| 142 | * segment, the segment gets written per sync and subsequently |
| 143 | * closed. |
| 144 | */ |
| 145 | return; |
| 146 | } |
| 147 | head = ofs & (PAGE_SIZE - 1); |
| 148 | if (head) { |
| 149 | ofs -= head; |
| 150 | len += head; |
| 151 | } |
| 152 | len = PAGE_ALIGN(len); |
| 153 | __bdev_writeseg(sb, ofs, ofs >> PAGE_SHIFT, len >> PAGE_SHIFT); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 156 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 157 | static void erase_end_io(struct bio *bio) |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 158 | { |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 159 | struct super_block *sb = bio->bi_private; |
| 160 | struct logfs_super *super = logfs_super(sb); |
| 161 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 162 | BUG_ON(bio->bi_error); /* FIXME: Retry io or write elsewhere */ |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 163 | BUG_ON(bio->bi_vcnt == 0); |
| 164 | bio_put(bio); |
| 165 | if (atomic_dec_and_test(&super->s_pending_writes)) |
| 166 | wake_up(&wq); |
| 167 | } |
| 168 | |
| 169 | static int do_erase(struct super_block *sb, u64 ofs, pgoff_t index, |
| 170 | size_t nr_pages) |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 171 | { |
| 172 | struct logfs_super *super = logfs_super(sb); |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 173 | struct bio *bio; |
Prasad Joshi | 9f0bbd8 | 2012-07-23 10:32:11 +0530 | [diff] [blame] | 174 | unsigned int max_pages; |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 175 | int i; |
| 176 | |
Sudip Mukherjee | ce4f2fd | 2015-11-05 18:43:49 -0800 | [diff] [blame] | 177 | max_pages = min_t(size_t, nr_pages, BIO_MAX_PAGES); |
Prasad Joshi | 9f0bbd8 | 2012-07-23 10:32:11 +0530 | [diff] [blame] | 178 | |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 179 | bio = bio_alloc(GFP_NOFS, max_pages); |
Joern Engel | 59fe27c | 2010-03-17 13:47:45 +0100 | [diff] [blame] | 180 | BUG_ON(!bio); |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 181 | |
| 182 | for (i = 0; i < nr_pages; i++) { |
| 183 | if (i >= max_pages) { |
| 184 | /* Block layer cannot split bios :( */ |
| 185 | bio->bi_vcnt = i; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 186 | bio->bi_iter.bi_size = i * PAGE_SIZE; |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 187 | bio->bi_bdev = super->s_bdev; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 188 | bio->bi_iter.bi_sector = ofs >> 9; |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 189 | bio->bi_private = sb; |
| 190 | bio->bi_end_io = erase_end_io; |
Mike Christie | 95fe6c1 | 2016-06-05 14:31:48 -0500 | [diff] [blame] | 191 | bio_set_op_attrs(bio, REQ_OP_WRITE, 0); |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 192 | atomic_inc(&super->s_pending_writes); |
Mike Christie | 4e49ea4 | 2016-06-05 14:31:41 -0500 | [diff] [blame] | 193 | submit_bio(bio); |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 194 | |
| 195 | ofs += i * PAGE_SIZE; |
| 196 | index += i; |
| 197 | nr_pages -= i; |
| 198 | i = 0; |
| 199 | |
| 200 | bio = bio_alloc(GFP_NOFS, max_pages); |
| 201 | BUG_ON(!bio); |
| 202 | } |
| 203 | bio->bi_io_vec[i].bv_page = super->s_erase_page; |
| 204 | bio->bi_io_vec[i].bv_len = PAGE_SIZE; |
| 205 | bio->bi_io_vec[i].bv_offset = 0; |
| 206 | } |
| 207 | bio->bi_vcnt = nr_pages; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 208 | bio->bi_iter.bi_size = nr_pages * PAGE_SIZE; |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 209 | bio->bi_bdev = super->s_bdev; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 210 | bio->bi_iter.bi_sector = ofs >> 9; |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 211 | bio->bi_private = sb; |
| 212 | bio->bi_end_io = erase_end_io; |
Mike Christie | 95fe6c1 | 2016-06-05 14:31:48 -0500 | [diff] [blame] | 213 | bio_set_op_attrs(bio, REQ_OP_WRITE, 0); |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 214 | atomic_inc(&super->s_pending_writes); |
Mike Christie | 4e49ea4 | 2016-06-05 14:31:41 -0500 | [diff] [blame] | 215 | submit_bio(bio); |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static int bdev_erase(struct super_block *sb, loff_t to, size_t len, |
| 220 | int ensure_write) |
| 221 | { |
| 222 | struct logfs_super *super = logfs_super(sb); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 223 | |
| 224 | BUG_ON(to & (PAGE_SIZE - 1)); |
| 225 | BUG_ON(len & (PAGE_SIZE - 1)); |
| 226 | |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 227 | if (super->s_flags & LOGFS_SB_FLAG_RO) |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 228 | return -EROFS; |
| 229 | |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 230 | if (ensure_write) { |
| 231 | /* |
| 232 | * Object store doesn't care whether erases happen or not. |
| 233 | * But for the journal they are required. Otherwise a scan |
| 234 | * can find an old commit entry and assume it is the current |
| 235 | * one, travelling back in time. |
| 236 | */ |
| 237 | do_erase(sb, to, to >> PAGE_SHIFT, len >> PAGE_SHIFT); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 238 | } |
Joern Engel | 9421502 | 2010-03-04 21:30:58 +0100 | [diff] [blame] | 239 | |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | static void bdev_sync(struct super_block *sb) |
| 244 | { |
| 245 | struct logfs_super *super = logfs_super(sb); |
| 246 | |
| 247 | wait_event(wq, atomic_read(&super->s_pending_writes) == 0); |
| 248 | } |
| 249 | |
| 250 | static struct page *bdev_find_first_sb(struct super_block *sb, u64 *ofs) |
| 251 | { |
| 252 | struct logfs_super *super = logfs_super(sb); |
| 253 | struct address_space *mapping = super->s_mapping_inode->i_mapping; |
| 254 | filler_t *filler = bdev_readpage; |
| 255 | |
| 256 | *ofs = 0; |
| 257 | return read_cache_page(mapping, 0, filler, sb); |
| 258 | } |
| 259 | |
| 260 | static struct page *bdev_find_last_sb(struct super_block *sb, u64 *ofs) |
| 261 | { |
| 262 | struct logfs_super *super = logfs_super(sb); |
| 263 | struct address_space *mapping = super->s_mapping_inode->i_mapping; |
| 264 | filler_t *filler = bdev_readpage; |
| 265 | u64 pos = (super->s_bdev->bd_inode->i_size & ~0xfffULL) - 0x1000; |
| 266 | pgoff_t index = pos >> PAGE_SHIFT; |
| 267 | |
| 268 | *ofs = pos; |
| 269 | return read_cache_page(mapping, index, filler, sb); |
| 270 | } |
| 271 | |
| 272 | static int bdev_write_sb(struct super_block *sb, struct page *page) |
| 273 | { |
| 274 | struct block_device *bdev = logfs_super(sb)->s_bdev; |
| 275 | |
| 276 | /* Nothing special to do for block devices. */ |
| 277 | return sync_request(page, bdev, WRITE); |
| 278 | } |
| 279 | |
Al Viro | e5a0726 | 2010-07-26 12:06:00 +0400 | [diff] [blame] | 280 | static void bdev_put_device(struct logfs_super *s) |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 281 | { |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 282 | blkdev_put(s->s_bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 283 | } |
| 284 | |
Joern Engel | 6f485b41 | 2010-05-07 19:38:40 +0200 | [diff] [blame] | 285 | static int bdev_can_write_buf(struct super_block *sb, u64 ofs) |
| 286 | { |
| 287 | return 0; |
| 288 | } |
| 289 | |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 290 | static const struct logfs_device_ops bd_devops = { |
| 291 | .find_first_sb = bdev_find_first_sb, |
| 292 | .find_last_sb = bdev_find_last_sb, |
| 293 | .write_sb = bdev_write_sb, |
| 294 | .readpage = bdev_readpage, |
| 295 | .writeseg = bdev_writeseg, |
| 296 | .erase = bdev_erase, |
Joern Engel | 6f485b41 | 2010-05-07 19:38:40 +0200 | [diff] [blame] | 297 | .can_write_buf = bdev_can_write_buf, |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 298 | .sync = bdev_sync, |
| 299 | .put_device = bdev_put_device, |
| 300 | }; |
| 301 | |
Al Viro | 7d945a3 | 2010-07-26 11:53:30 +0400 | [diff] [blame] | 302 | int logfs_get_sb_bdev(struct logfs_super *p, struct file_system_type *type, |
| 303 | const char *devname) |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 304 | { |
| 305 | struct block_device *bdev; |
| 306 | |
Tejun Heo | d4d7762 | 2010-11-13 11:55:18 +0100 | [diff] [blame] | 307 | bdev = blkdev_get_by_path(devname, FMODE_READ|FMODE_WRITE|FMODE_EXCL, |
| 308 | type); |
Al Viro | 7d945a3 | 2010-07-26 11:53:30 +0400 | [diff] [blame] | 309 | if (IS_ERR(bdev)) |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 310 | return PTR_ERR(bdev); |
| 311 | |
| 312 | if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) { |
| 313 | int mtdnr = MINOR(bdev->bd_dev); |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 314 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); |
Al Viro | 7d945a3 | 2010-07-26 11:53:30 +0400 | [diff] [blame] | 315 | return logfs_get_sb_mtd(p, mtdnr); |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 316 | } |
| 317 | |
Al Viro | 0d85c79 | 2010-07-26 11:33:39 +0400 | [diff] [blame] | 318 | p->s_bdev = bdev; |
| 319 | p->s_mtd = NULL; |
| 320 | p->s_devops = &bd_devops; |
Al Viro | 7d945a3 | 2010-07-26 11:53:30 +0400 | [diff] [blame] | 321 | return 0; |
Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 322 | } |