blob: 4ea2e67ac97cfad78175009d4c44fa3f096ac1ab [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * (C) 2003 David Woodhouse <dwmw2@infradead.org>
3 *
4 * Interface to Linux 2.5 block layer for MTD 'translation layers'.
5 *
6 */
7
8#include <linux/kernel.h>
9#include <linux/slab.h>
10#include <linux/module.h>
11#include <linux/list.h>
12#include <linux/fs.h>
13#include <linux/mtd/blktrans.h>
14#include <linux/mtd/mtd.h>
15#include <linux/blkdev.h>
16#include <linux/blkpg.h>
Rafael J. Wysocki83144182007-07-17 04:03:35 -070017#include <linux/freezer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/spinlock.h>
19#include <linux/hdreg.h>
20#include <linux/init.h>
Ingo Molnar48b19262006-03-31 02:29:41 -080021#include <linux/mutex.h>
Eric W. Biederman99f9b242007-04-19 01:58:33 -060022#include <linux/kthread.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Ben Dooks356d70f2007-05-28 20:28:34 +010025#include "mtdcore.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Ben Dooks356d70f2007-05-28 20:28:34 +010027static LIST_HEAD(blktrans_majors);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29struct mtd_blkcore_priv {
Christoph Hellwig3e67fe42007-04-22 20:40:57 +010030 struct task_struct *thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 struct request_queue *rq;
32 spinlock_t queue_lock;
33};
34
David Woodhouseeae9acd2008-08-05 18:08:25 +010035static int blktrans_discard_request(struct request_queue *q,
36 struct request *req)
37{
38 req->cmd_type = REQ_TYPE_LINUX_BLOCK;
39 req->cmd[0] = REQ_LB_OP_DISCARD;
40 return 0;
41}
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043static int do_blktrans_request(struct mtd_blktrans_ops *tr,
44 struct mtd_blktrans_dev *dev,
45 struct request *req)
46{
47 unsigned long block, nsect;
48 char *buf;
49
Tejun Heo83096eb2009-05-07 22:24:39 +090050 block = blk_rq_pos(req) << 9 >> tr->blkshift;
51 nsect = blk_rq_cur_sectors(req) << 9 >> tr->blkshift;
Richard Purdie19187672006-10-27 09:09:33 +010052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 buf = req->buffer;
54
David Woodhouseeae9acd2008-08-05 18:08:25 +010055 if (req->cmd_type == REQ_TYPE_LINUX_BLOCK &&
56 req->cmd[0] == REQ_LB_OP_DISCARD)
Tejun Heof06d9a22009-04-23 11:05:19 +090057 return tr->discard(dev, block, nsect);
David Woodhouseeae9acd2008-08-05 18:08:25 +010058
Jens Axboe4aff5e22006-08-10 08:44:47 +020059 if (!blk_fs_request(req))
Tejun Heof06d9a22009-04-23 11:05:19 +090060 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Tejun Heo83096eb2009-05-07 22:24:39 +090062 if (blk_rq_pos(req) + blk_rq_cur_sectors(req) >
63 get_capacity(req->rq_disk))
Tejun Heof06d9a22009-04-23 11:05:19 +090064 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 switch(rq_data_dir(req)) {
67 case READ:
Richard Purdie19187672006-10-27 09:09:33 +010068 for (; nsect > 0; nsect--, block++, buf += tr->blksize)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 if (tr->readsect(dev, block, buf))
Tejun Heof06d9a22009-04-23 11:05:19 +090070 return -EIO;
71 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 case WRITE:
74 if (!tr->writesect)
Tejun Heof06d9a22009-04-23 11:05:19 +090075 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Richard Purdie19187672006-10-27 09:09:33 +010077 for (; nsect > 0; nsect--, block++, buf += tr->blksize)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 if (tr->writesect(dev, block, buf))
Tejun Heof06d9a22009-04-23 11:05:19 +090079 return -EIO;
80 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 default:
Jeff Garzik9a292302006-10-01 12:16:00 -040083 printk(KERN_NOTICE "Unknown request %u\n", rq_data_dir(req));
Tejun Heof06d9a22009-04-23 11:05:19 +090084 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
86}
87
88static int mtd_blktrans_thread(void *arg)
89{
90 struct mtd_blktrans_ops *tr = arg;
91 struct request_queue *rq = tr->blkcore_priv->rq;
92
93 /* we might get involved when memory gets low, so use PF_MEMALLOC */
Rafael J. Wysocki83144182007-07-17 04:03:35 -070094 current->flags |= PF_MEMALLOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 spin_lock_irq(rq->queue_lock);
Christoph Hellwig3e67fe42007-04-22 20:40:57 +010097 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 struct request *req;
99 struct mtd_blktrans_dev *dev;
Tejun Heof06d9a22009-04-23 11:05:19 +0900100 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102 req = elv_next_request(rq);
103
104 if (!req) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 spin_unlock_irq(rq->queue_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 spin_lock_irq(rq->queue_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 continue;
110 }
111
112 dev = req->rq_disk->private_data;
113 tr = dev->tr;
114
115 spin_unlock_irq(rq->queue_lock);
116
Ingo Molnar48b19262006-03-31 02:29:41 -0800117 mutex_lock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 res = do_blktrans_request(tr, dev, req);
Ingo Molnar48b19262006-03-31 02:29:41 -0800119 mutex_unlock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 spin_lock_irq(rq->queue_lock);
122
Tejun Heof06d9a22009-04-23 11:05:19 +0900123 __blk_end_request_cur(req, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125 spin_unlock_irq(rq->queue_lock);
126
Christoph Hellwig3e67fe42007-04-22 20:40:57 +0100127 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
130static void mtd_blktrans_request(struct request_queue *rq)
131{
132 struct mtd_blktrans_ops *tr = rq->queuedata;
Christoph Hellwig3e67fe42007-04-22 20:40:57 +0100133 wake_up_process(tr->blkcore_priv->thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
136
Al Viroaf0e2a02008-03-02 10:35:06 -0500137static int blktrans_open(struct block_device *bdev, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Al Viroaf0e2a02008-03-02 10:35:06 -0500139 struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data;
140 struct mtd_blktrans_ops *tr = dev->tr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 int ret = -ENODEV;
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 if (!try_module_get(dev->mtd->owner))
144 goto out;
145
146 if (!try_module_get(tr->owner))
147 goto out_tr;
148
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000149 /* FIXME: Locking. A hot pluggable device can go away
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 (del_mtd_device can be called for it) without its module
151 being unloaded. */
152 dev->mtd->usecount++;
153
154 ret = 0;
155 if (tr->open && (ret = tr->open(dev))) {
156 dev->mtd->usecount--;
157 module_put(dev->mtd->owner);
158 out_tr:
159 module_put(tr->owner);
160 }
161 out:
162 return ret;
163}
164
Al Viroaf0e2a02008-03-02 10:35:06 -0500165static int blktrans_release(struct gendisk *disk, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Al Viroaf0e2a02008-03-02 10:35:06 -0500167 struct mtd_blktrans_dev *dev = disk->private_data;
168 struct mtd_blktrans_ops *tr = dev->tr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 int ret = 0;
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 if (tr->release)
172 ret = tr->release(dev);
173
174 if (!ret) {
175 dev->mtd->usecount--;
176 module_put(dev->mtd->owner);
177 module_put(tr->owner);
178 }
179
180 return ret;
181}
182
Christoph Hellwiga885c8c2006-01-08 01:02:50 -0800183static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
184{
185 struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data;
186
187 if (dev->tr->getgeo)
188 return dev->tr->getgeo(dev, geo);
189 return -ENOTTY;
190}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Al Viroaf0e2a02008-03-02 10:35:06 -0500192static int blktrans_ioctl(struct block_device *bdev, fmode_t mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 unsigned int cmd, unsigned long arg)
194{
Al Viroaf0e2a02008-03-02 10:35:06 -0500195 struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 struct mtd_blktrans_ops *tr = dev->tr;
197
198 switch (cmd) {
199 case BLKFLSBUF:
200 if (tr->flush)
201 return tr->flush(dev);
202 /* The core code did the work, we had nothing to do. */
203 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 default:
205 return -ENOTTY;
206 }
207}
208
Ben Dooks8f026f72007-05-28 19:51:59 +0100209static struct block_device_operations mtd_blktrans_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 .owner = THIS_MODULE,
Al Viroaf0e2a02008-03-02 10:35:06 -0500211 .open = blktrans_open,
212 .release = blktrans_release,
213 .locked_ioctl = blktrans_ioctl,
Christoph Hellwiga885c8c2006-01-08 01:02:50 -0800214 .getgeo = blktrans_getgeo,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215};
216
217int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
218{
219 struct mtd_blktrans_ops *tr = new->tr;
Chris Malley71a928c2008-05-19 20:11:50 +0100220 struct mtd_blktrans_dev *d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 int last_devnum = -1;
222 struct gendisk *gd;
223
Jean Delvareb3561ea2007-05-08 00:30:46 -0700224 if (mutex_trylock(&mtd_table_mutex)) {
Ingo Molnar48b19262006-03-31 02:29:41 -0800225 mutex_unlock(&mtd_table_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 BUG();
227 }
228
Chris Malley71a928c2008-05-19 20:11:50 +0100229 list_for_each_entry(d, &tr->devs, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (new->devnum == -1) {
231 /* Use first free number */
232 if (d->devnum != last_devnum+1) {
233 /* Found a free devnum. Plug it in here */
234 new->devnum = last_devnum+1;
235 list_add_tail(&new->list, &d->list);
236 goto added;
237 }
238 } else if (d->devnum == new->devnum) {
239 /* Required number taken */
240 return -EBUSY;
241 } else if (d->devnum > new->devnum) {
242 /* Required number was free */
243 list_add_tail(&new->list, &d->list);
244 goto added;
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 last_devnum = d->devnum;
247 }
248 if (new->devnum == -1)
249 new->devnum = last_devnum+1;
250
251 if ((new->devnum << tr->part_bits) > 256) {
252 return -EBUSY;
253 }
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 list_add_tail(&new->list, &tr->devs);
256 added:
David Woodhousece37ab42007-12-03 12:46:12 +0000257 mutex_init(&new->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if (!tr->writesect)
259 new->readonly = 1;
260
261 gd = alloc_disk(1 << tr->part_bits);
262 if (!gd) {
263 list_del(&new->list);
264 return -ENOMEM;
265 }
266 gd->major = tr->major;
267 gd->first_minor = (new->devnum) << tr->part_bits;
268 gd->fops = &mtd_blktrans_ops;
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000269
Todd Poynor65a8de32005-07-29 20:42:07 +0100270 if (tr->part_bits)
271 if (new->devnum < 26)
272 snprintf(gd->disk_name, sizeof(gd->disk_name),
273 "%s%c", tr->name, 'a' + new->devnum);
274 else
275 snprintf(gd->disk_name, sizeof(gd->disk_name),
276 "%s%c%c", tr->name,
277 'a' - 1 + new->devnum / 26,
278 'a' + new->devnum % 26);
279 else
280 snprintf(gd->disk_name, sizeof(gd->disk_name),
281 "%s%d", tr->name, new->devnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 /* 2.5 has capacity in units of 512 bytes while still
284 having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */
Richard Purdie19187672006-10-27 09:09:33 +0100285 set_capacity(gd, (new->size * tr->blksize) >> 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 gd->private_data = new;
288 new->blkcore_priv = gd;
289 gd->queue = tr->blkcore_priv->rq;
David Brownell1f24b5a2009-03-26 00:42:41 -0700290 gd->driverfs_dev = new->mtd->dev.parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 if (new->readonly)
293 set_disk_ro(gd, 1);
294
295 add_disk(gd);
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 return 0;
298}
299
300int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
301{
Jean Delvareb3561ea2007-05-08 00:30:46 -0700302 if (mutex_trylock(&mtd_table_mutex)) {
Ingo Molnar48b19262006-03-31 02:29:41 -0800303 mutex_unlock(&mtd_table_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 BUG();
305 }
306
307 list_del(&old->list);
308
309 del_gendisk(old->blkcore_priv);
310 put_disk(old->blkcore_priv);
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 return 0;
313}
314
315static void blktrans_notify_remove(struct mtd_info *mtd)
316{
Chris Malley71a928c2008-05-19 20:11:50 +0100317 struct mtd_blktrans_ops *tr;
318 struct mtd_blktrans_dev *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Chris Malley71a928c2008-05-19 20:11:50 +0100320 list_for_each_entry(tr, &blktrans_majors, list)
321 list_for_each_entry_safe(dev, next, &tr->devs, list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 if (dev->mtd == mtd)
323 tr->remove_dev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
326static void blktrans_notify_add(struct mtd_info *mtd)
327{
Chris Malley71a928c2008-05-19 20:11:50 +0100328 struct mtd_blktrans_ops *tr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 if (mtd->type == MTD_ABSENT)
331 return;
332
Chris Malley71a928c2008-05-19 20:11:50 +0100333 list_for_each_entry(tr, &blktrans_majors, list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 tr->add_mtd(tr, mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336
337static struct mtd_notifier blktrans_notifier = {
338 .add = blktrans_notify_add,
339 .remove = blktrans_notify_remove,
340};
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
343{
344 int ret, i;
345
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000346 /* Register the notifier if/when the first device type is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 registered, to prevent the link/init ordering from fucking
348 us over. */
349 if (!blktrans_notifier.list.next)
350 register_mtd_user(&blktrans_notifier);
351
Burman Yan95b93a02006-11-15 21:10:29 +0200352 tr->blkcore_priv = kzalloc(sizeof(*tr->blkcore_priv), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 if (!tr->blkcore_priv)
354 return -ENOMEM;
355
Ingo Molnar48b19262006-03-31 02:29:41 -0800356 mutex_lock(&mtd_table_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 ret = register_blkdev(tr->major, tr->name);
359 if (ret) {
360 printk(KERN_WARNING "Unable to register %s block device on major %d: %d\n",
361 tr->name, tr->major, ret);
362 kfree(tr->blkcore_priv);
Ingo Molnar48b19262006-03-31 02:29:41 -0800363 mutex_unlock(&mtd_table_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 return ret;
365 }
366 spin_lock_init(&tr->blkcore_priv->queue_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 tr->blkcore_priv->rq = blk_init_queue(mtd_blktrans_request, &tr->blkcore_priv->queue_lock);
369 if (!tr->blkcore_priv->rq) {
370 unregister_blkdev(tr->major, tr->name);
371 kfree(tr->blkcore_priv);
Ingo Molnar48b19262006-03-31 02:29:41 -0800372 mutex_unlock(&mtd_table_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 return -ENOMEM;
374 }
375
376 tr->blkcore_priv->rq->queuedata = tr;
Richard Purdie19187672006-10-27 09:09:33 +0100377 blk_queue_hardsect_size(tr->blkcore_priv->rq, tr->blksize);
David Woodhouseeae9acd2008-08-05 18:08:25 +0100378 if (tr->discard)
379 blk_queue_set_discard(tr->blkcore_priv->rq,
380 blktrans_discard_request);
381
Richard Purdie19187672006-10-27 09:09:33 +0100382 tr->blkshift = ffs(tr->blksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Christoph Hellwig3e67fe42007-04-22 20:40:57 +0100384 tr->blkcore_priv->thread = kthread_run(mtd_blktrans_thread, tr,
385 "%sd", tr->name);
386 if (IS_ERR(tr->blkcore_priv->thread)) {
Marcin Slusarz2cf3a112009-03-28 18:44:24 +0100387 int ret = PTR_ERR(tr->blkcore_priv->thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 blk_cleanup_queue(tr->blkcore_priv->rq);
389 unregister_blkdev(tr->major, tr->name);
390 kfree(tr->blkcore_priv);
Ingo Molnar48b19262006-03-31 02:29:41 -0800391 mutex_unlock(&mtd_table_mutex);
Marcin Slusarz2cf3a112009-03-28 18:44:24 +0100392 return ret;
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 INIT_LIST_HEAD(&tr->devs);
396 list_add(&tr->list, &blktrans_majors);
397
398 for (i=0; i<MAX_MTD_DEVICES; i++) {
399 if (mtd_table[i] && mtd_table[i]->type != MTD_ABSENT)
400 tr->add_mtd(tr, mtd_table[i]);
401 }
402
Ingo Molnar48b19262006-03-31 02:29:41 -0800403 mutex_unlock(&mtd_table_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 return 0;
406}
407
408int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
409{
Chris Malley71a928c2008-05-19 20:11:50 +0100410 struct mtd_blktrans_dev *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Ingo Molnar48b19262006-03-31 02:29:41 -0800412 mutex_lock(&mtd_table_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 /* Clean up the kernel thread */
Christoph Hellwig3e67fe42007-04-22 20:40:57 +0100415 kthread_stop(tr->blkcore_priv->thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 /* Remove it from the list of active majors */
418 list_del(&tr->list);
419
Chris Malley71a928c2008-05-19 20:11:50 +0100420 list_for_each_entry_safe(dev, next, &tr->devs, list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 tr->remove_dev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 blk_cleanup_queue(tr->blkcore_priv->rq);
424 unregister_blkdev(tr->major, tr->name);
425
Ingo Molnar48b19262006-03-31 02:29:41 -0800426 mutex_unlock(&mtd_table_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428 kfree(tr->blkcore_priv);
429
Eric Sesterhenn373ebfb2006-03-26 18:15:12 +0200430 BUG_ON(!list_empty(&tr->devs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 return 0;
432}
433
434static void __exit mtd_blktrans_exit(void)
435{
436 /* No race here -- if someone's currently in register_mtd_blktrans
437 we're screwed anyway. */
438 if (blktrans_notifier.list.next)
439 unregister_mtd_user(&blktrans_notifier);
440}
441
442module_exit(mtd_blktrans_exit);
443
444EXPORT_SYMBOL_GPL(register_mtd_blktrans);
445EXPORT_SYMBOL_GPL(deregister_mtd_blktrans);
446EXPORT_SYMBOL_GPL(add_mtd_blktrans_dev);
447EXPORT_SYMBOL_GPL(del_mtd_blktrans_dev);
448
449MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
450MODULE_LICENSE("GPL");
451MODULE_DESCRIPTION("Common interface to block layer for MTD 'translation layers'");