block.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  2. * Copyright (c) 2014 Ezequiel Garcia
  3. * Copyright (c) 2011 Free Electrons
  4. *
  5. * Driver parameter handling strongly based on drivers/mtd/ubi/build.c
  6. * Copyright (c) International Business Machines Corp., 2006
  7. * Copyright (c) Nokia Corporation, 2007
  8. * Authors: Artem Bityutskiy, Frank Haverkamp
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, version 2.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  17. * the GNU General Public License for more details.
  18. */
  19. /*
  20. * Read-only block devices on top of UBI volumes
  21. *
  22. * A simple implementation to allow a block device to be layered on top of a
  23. * UBI volume. The implementation is provided by creating a static 1-to-1
  24. * mapping between the block device and the UBI volume.
  25. *
  26. * The addressed byte is obtained from the addressed block sector, which is
  27. * mapped linearly into the corresponding LEB:
  28. *
  29. * LEB number = addressed byte / LEB size
  30. *
  31. * This feature is compiled in the UBI core, and adds a 'block' parameter
  32. * to allow early creation of block devices on top of UBI volumes. Runtime
  33. * block creation/removal for UBI volumes is provided through two UBI ioctls:
  34. * UBI_IOCVOLCRBLK and UBI_IOCVOLRMBLK.
  35. */
  36. #include <linux/module.h>
  37. #include <linux/init.h>
  38. #include <linux/err.h>
  39. #include <linux/kernel.h>
  40. #include <linux/list.h>
  41. #include <linux/mutex.h>
  42. #include <linux/slab.h>
  43. #include <linux/mtd/ubi.h>
  44. #include <linux/workqueue.h>
  45. #include <linux/blkdev.h>
  46. #include <linux/blk-mq.h>
  47. #include <linux/hdreg.h>
  48. #include <linux/scatterlist.h>
  49. #include <asm/div64.h>
  50. #include "ubi-media.h"
  51. #include "ubi.h"
  52. /* Maximum number of supported devices */
  53. #define UBIBLOCK_MAX_DEVICES 32
  54. /* Maximum length of the 'block=' parameter */
  55. #define UBIBLOCK_PARAM_LEN 63
  56. /* Maximum number of comma-separated items in the 'block=' parameter */
  57. #define UBIBLOCK_PARAM_COUNT 2
  58. struct ubiblock_param {
  59. int ubi_num;
  60. int vol_id;
  61. char name[UBIBLOCK_PARAM_LEN+1];
  62. };
  63. struct ubiblock_pdu {
  64. struct work_struct work;
  65. struct ubi_sgl usgl;
  66. };
  67. /* Numbers of elements set in the @ubiblock_param array */
  68. static int ubiblock_devs __initdata;
  69. /* MTD devices specification parameters */
  70. static struct ubiblock_param ubiblock_param[UBIBLOCK_MAX_DEVICES] __initdata;
  71. struct ubiblock {
  72. struct ubi_volume_desc *desc;
  73. int ubi_num;
  74. int vol_id;
  75. int refcnt;
  76. int leb_size;
  77. struct gendisk *gd;
  78. struct request_queue *rq;
  79. struct workqueue_struct *wq;
  80. struct mutex dev_mutex;
  81. struct list_head list;
  82. struct blk_mq_tag_set tag_set;
  83. };
  84. /* Linked list of all ubiblock instances */
  85. static LIST_HEAD(ubiblock_devices);
  86. static DEFINE_MUTEX(devices_mutex);
  87. static int ubiblock_major;
  88. static int __init ubiblock_set_param(const char *val,
  89. const struct kernel_param *kp)
  90. {
  91. int i, ret;
  92. size_t len;
  93. struct ubiblock_param *param;
  94. char buf[UBIBLOCK_PARAM_LEN];
  95. char *pbuf = &buf[0];
  96. char *tokens[UBIBLOCK_PARAM_COUNT];
  97. if (!val)
  98. return -EINVAL;
  99. len = strnlen(val, UBIBLOCK_PARAM_LEN);
  100. if (len == 0) {
  101. pr_warn("UBI: block: empty 'block=' parameter - ignored\n");
  102. return 0;
  103. }
  104. if (len == UBIBLOCK_PARAM_LEN) {
  105. pr_err("UBI: block: parameter \"%s\" is too long, max. is %d\n",
  106. val, UBIBLOCK_PARAM_LEN);
  107. return -EINVAL;
  108. }
  109. strcpy(buf, val);
  110. /* Get rid of the final newline */
  111. if (buf[len - 1] == '\n')
  112. buf[len - 1] = '\0';
  113. for (i = 0; i < UBIBLOCK_PARAM_COUNT; i++)
  114. tokens[i] = strsep(&pbuf, ",");
  115. param = &ubiblock_param[ubiblock_devs];
  116. if (tokens[1]) {
  117. /* Two parameters: can be 'ubi, vol_id' or 'ubi, vol_name' */
  118. ret = kstrtoint(tokens[0], 10, &param->ubi_num);
  119. if (ret < 0)
  120. return -EINVAL;
  121. /* Second param can be a number or a name */
  122. ret = kstrtoint(tokens[1], 10, &param->vol_id);
  123. if (ret < 0) {
  124. param->vol_id = -1;
  125. strcpy(param->name, tokens[1]);
  126. }
  127. } else {
  128. /* One parameter: must be device path */
  129. strcpy(param->name, tokens[0]);
  130. param->ubi_num = -1;
  131. param->vol_id = -1;
  132. }
  133. ubiblock_devs++;
  134. return 0;
  135. }
  136. static struct kernel_param_ops ubiblock_param_ops = {
  137. .set = ubiblock_set_param,
  138. };
  139. module_param_cb(block, &ubiblock_param_ops, NULL, 0);
  140. MODULE_PARM_DESC(block, "Attach block devices to UBI volumes. Parameter format: block=<path|dev,num|dev,name>.\n"
  141. "Multiple \"block\" parameters may be specified.\n"
  142. "UBI volumes may be specified by their number, name, or path to the device node.\n"
  143. "Examples\n"
  144. "Using the UBI volume path:\n"
  145. "ubi.block=/dev/ubi0_0\n"
  146. "Using the UBI device, and the volume name:\n"
  147. "ubi.block=0,rootfs\n"
  148. "Using both UBI device number and UBI volume number:\n"
  149. "ubi.block=0,0\n");
  150. static struct ubiblock *find_dev_nolock(int ubi_num, int vol_id)
  151. {
  152. struct ubiblock *dev;
  153. list_for_each_entry(dev, &ubiblock_devices, list)
  154. if (dev->ubi_num == ubi_num && dev->vol_id == vol_id)
  155. return dev;
  156. return NULL;
  157. }
  158. static int ubiblock_read(struct ubiblock_pdu *pdu)
  159. {
  160. int ret, leb, offset, bytes_left, to_read;
  161. u64 pos;
  162. struct request *req = blk_mq_rq_from_pdu(pdu);
  163. struct ubiblock *dev = req->q->queuedata;
  164. to_read = blk_rq_bytes(req);
  165. pos = blk_rq_pos(req) << 9;
  166. /* Get LEB:offset address to read from */
  167. offset = do_div(pos, dev->leb_size);
  168. leb = pos;
  169. bytes_left = to_read;
  170. while (bytes_left) {
  171. /*
  172. * We can only read one LEB at a time. Therefore if the read
  173. * length is larger than one LEB size, we split the operation.
  174. */
  175. if (offset + to_read > dev->leb_size)
  176. to_read = dev->leb_size - offset;
  177. ret = ubi_read_sg(dev->desc, leb, &pdu->usgl, offset, to_read);
  178. if (ret < 0)
  179. return ret;
  180. bytes_left -= to_read;
  181. to_read = bytes_left;
  182. leb += 1;
  183. offset = 0;
  184. }
  185. return 0;
  186. }
  187. static int ubiblock_open(struct block_device *bdev, fmode_t mode)
  188. {
  189. struct ubiblock *dev = bdev->bd_disk->private_data;
  190. int ret;
  191. mutex_lock(&dev->dev_mutex);
  192. if (dev->refcnt > 0) {
  193. /*
  194. * The volume is already open, just increase the reference
  195. * counter.
  196. */
  197. goto out_done;
  198. }
  199. /*
  200. * We want users to be aware they should only mount us as read-only.
  201. * It's just a paranoid check, as write requests will get rejected
  202. * in any case.
  203. */
  204. if (mode & FMODE_WRITE) {
  205. ret = -EPERM;
  206. goto out_unlock;
  207. }
  208. dev->desc = ubi_open_volume(dev->ubi_num, dev->vol_id, UBI_READONLY);
  209. if (IS_ERR(dev->desc)) {
  210. dev_err(disk_to_dev(dev->gd), "failed to open ubi volume %d_%d",
  211. dev->ubi_num, dev->vol_id);
  212. ret = PTR_ERR(dev->desc);
  213. dev->desc = NULL;
  214. goto out_unlock;
  215. }
  216. out_done:
  217. dev->refcnt++;
  218. mutex_unlock(&dev->dev_mutex);
  219. return 0;
  220. out_unlock:
  221. mutex_unlock(&dev->dev_mutex);
  222. return ret;
  223. }
  224. static void ubiblock_release(struct gendisk *gd, fmode_t mode)
  225. {
  226. struct ubiblock *dev = gd->private_data;
  227. mutex_lock(&dev->dev_mutex);
  228. dev->refcnt--;
  229. if (dev->refcnt == 0) {
  230. ubi_close_volume(dev->desc);
  231. dev->desc = NULL;
  232. }
  233. mutex_unlock(&dev->dev_mutex);
  234. }
  235. static int ubiblock_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  236. {
  237. /* Some tools might require this information */
  238. geo->heads = 1;
  239. geo->cylinders = 1;
  240. geo->sectors = get_capacity(bdev->bd_disk);
  241. geo->start = 0;
  242. return 0;
  243. }
  244. static const struct block_device_operations ubiblock_ops = {
  245. .owner = THIS_MODULE,
  246. .open = ubiblock_open,
  247. .release = ubiblock_release,
  248. .getgeo = ubiblock_getgeo,
  249. };
  250. static void ubiblock_do_work(struct work_struct *work)
  251. {
  252. int ret;
  253. struct ubiblock_pdu *pdu = container_of(work, struct ubiblock_pdu, work);
  254. struct request *req = blk_mq_rq_from_pdu(pdu);
  255. blk_mq_start_request(req);
  256. /*
  257. * It is safe to ignore the return value of blk_rq_map_sg() because
  258. * the number of sg entries is limited to UBI_MAX_SG_COUNT
  259. * and ubi_read_sg() will check that limit.
  260. */
  261. blk_rq_map_sg(req->q, req, pdu->usgl.sg);
  262. ret = ubiblock_read(pdu);
  263. rq_flush_dcache_pages(req);
  264. blk_mq_end_request(req, ret);
  265. }
  266. static int ubiblock_queue_rq(struct blk_mq_hw_ctx *hctx,
  267. const struct blk_mq_queue_data *bd)
  268. {
  269. struct request *req = bd->rq;
  270. struct ubiblock *dev = hctx->queue->queuedata;
  271. struct ubiblock_pdu *pdu = blk_mq_rq_to_pdu(req);
  272. if (req->cmd_type != REQ_TYPE_FS)
  273. return BLK_MQ_RQ_QUEUE_ERROR;
  274. if (rq_data_dir(req) != READ)
  275. return BLK_MQ_RQ_QUEUE_ERROR; /* Write not implemented */
  276. ubi_sgl_init(&pdu->usgl);
  277. queue_work(dev->wq, &pdu->work);
  278. return BLK_MQ_RQ_QUEUE_OK;
  279. }
  280. static int ubiblock_init_request(void *data, struct request *req,
  281. unsigned int hctx_idx,
  282. unsigned int request_idx,
  283. unsigned int numa_node)
  284. {
  285. struct ubiblock_pdu *pdu = blk_mq_rq_to_pdu(req);
  286. sg_init_table(pdu->usgl.sg, UBI_MAX_SG_COUNT);
  287. INIT_WORK(&pdu->work, ubiblock_do_work);
  288. return 0;
  289. }
  290. static struct blk_mq_ops ubiblock_mq_ops = {
  291. .queue_rq = ubiblock_queue_rq,
  292. .init_request = ubiblock_init_request,
  293. .map_queue = blk_mq_map_queue,
  294. };
  295. int ubiblock_create(struct ubi_volume_info *vi)
  296. {
  297. struct ubiblock *dev;
  298. struct gendisk *gd;
  299. u64 disk_capacity = vi->used_bytes >> 9;
  300. int ret;
  301. if ((sector_t)disk_capacity != disk_capacity)
  302. return -EFBIG;
  303. /* Check that the volume isn't already handled */
  304. mutex_lock(&devices_mutex);
  305. if (find_dev_nolock(vi->ubi_num, vi->vol_id)) {
  306. mutex_unlock(&devices_mutex);
  307. return -EEXIST;
  308. }
  309. mutex_unlock(&devices_mutex);
  310. dev = kzalloc(sizeof(struct ubiblock), GFP_KERNEL);
  311. if (!dev)
  312. return -ENOMEM;
  313. mutex_init(&dev->dev_mutex);
  314. dev->ubi_num = vi->ubi_num;
  315. dev->vol_id = vi->vol_id;
  316. dev->leb_size = vi->usable_leb_size;
  317. /* Initialize the gendisk of this ubiblock device */
  318. gd = alloc_disk(1);
  319. if (!gd) {
  320. pr_err("UBI: block: alloc_disk failed");
  321. ret = -ENODEV;
  322. goto out_free_dev;
  323. }
  324. gd->fops = &ubiblock_ops;
  325. gd->major = ubiblock_major;
  326. gd->first_minor = dev->ubi_num * UBI_MAX_VOLUMES + dev->vol_id;
  327. gd->private_data = dev;
  328. sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
  329. set_capacity(gd, disk_capacity);
  330. dev->gd = gd;
  331. dev->tag_set.ops = &ubiblock_mq_ops;
  332. dev->tag_set.queue_depth = 64;
  333. dev->tag_set.numa_node = NUMA_NO_NODE;
  334. dev->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
  335. dev->tag_set.cmd_size = sizeof(struct ubiblock_pdu);
  336. dev->tag_set.driver_data = dev;
  337. dev->tag_set.nr_hw_queues = 1;
  338. ret = blk_mq_alloc_tag_set(&dev->tag_set);
  339. if (ret) {
  340. dev_err(disk_to_dev(dev->gd), "blk_mq_alloc_tag_set failed");
  341. goto out_put_disk;
  342. }
  343. dev->rq = blk_mq_init_queue(&dev->tag_set);
  344. if (IS_ERR(dev->rq)) {
  345. dev_err(disk_to_dev(gd), "blk_mq_init_queue failed");
  346. ret = PTR_ERR(dev->rq);
  347. goto out_free_tags;
  348. }
  349. blk_queue_max_segments(dev->rq, UBI_MAX_SG_COUNT);
  350. dev->rq->queuedata = dev;
  351. dev->gd->queue = dev->rq;
  352. /*
  353. * Create one workqueue per volume (per registered block device).
  354. * Rembember workqueues are cheap, they're not threads.
  355. */
  356. dev->wq = alloc_workqueue("%s", 0, 0, gd->disk_name);
  357. if (!dev->wq) {
  358. ret = -ENOMEM;
  359. goto out_free_queue;
  360. }
  361. mutex_lock(&devices_mutex);
  362. list_add_tail(&dev->list, &ubiblock_devices);
  363. mutex_unlock(&devices_mutex);
  364. /* Must be the last step: anyone can call file ops from now on */
  365. add_disk(dev->gd);
  366. dev_info(disk_to_dev(dev->gd), "created from ubi%d:%d(%s)",
  367. dev->ubi_num, dev->vol_id, vi->name);
  368. return 0;
  369. out_free_queue:
  370. blk_cleanup_queue(dev->rq);
  371. out_free_tags:
  372. blk_mq_free_tag_set(&dev->tag_set);
  373. out_put_disk:
  374. put_disk(dev->gd);
  375. out_free_dev:
  376. kfree(dev);
  377. return ret;
  378. }
  379. static void ubiblock_cleanup(struct ubiblock *dev)
  380. {
  381. /* Stop new requests to arrive */
  382. del_gendisk(dev->gd);
  383. /* Flush pending work */
  384. destroy_workqueue(dev->wq);
  385. /* Finally destroy the blk queue */
  386. blk_cleanup_queue(dev->rq);
  387. blk_mq_free_tag_set(&dev->tag_set);
  388. dev_info(disk_to_dev(dev->gd), "released");
  389. put_disk(dev->gd);
  390. }
  391. int ubiblock_remove(struct ubi_volume_info *vi)
  392. {
  393. struct ubiblock *dev;
  394. mutex_lock(&devices_mutex);
  395. dev = find_dev_nolock(vi->ubi_num, vi->vol_id);
  396. if (!dev) {
  397. mutex_unlock(&devices_mutex);
  398. return -ENODEV;
  399. }
  400. /* Found a device, let's lock it so we can check if it's busy */
  401. mutex_lock(&dev->dev_mutex);
  402. if (dev->refcnt > 0) {
  403. mutex_unlock(&dev->dev_mutex);
  404. mutex_unlock(&devices_mutex);
  405. return -EBUSY;
  406. }
  407. /* Remove from device list */
  408. list_del(&dev->list);
  409. mutex_unlock(&devices_mutex);
  410. ubiblock_cleanup(dev);
  411. mutex_unlock(&dev->dev_mutex);
  412. kfree(dev);
  413. return 0;
  414. }
  415. static int ubiblock_resize(struct ubi_volume_info *vi)
  416. {
  417. struct ubiblock *dev;
  418. u64 disk_capacity = vi->used_bytes >> 9;
  419. /*
  420. * Need to lock the device list until we stop using the device,
  421. * otherwise the device struct might get released in
  422. * 'ubiblock_remove()'.
  423. */
  424. mutex_lock(&devices_mutex);
  425. dev = find_dev_nolock(vi->ubi_num, vi->vol_id);
  426. if (!dev) {
  427. mutex_unlock(&devices_mutex);
  428. return -ENODEV;
  429. }
  430. if ((sector_t)disk_capacity != disk_capacity) {
  431. mutex_unlock(&devices_mutex);
  432. dev_warn(disk_to_dev(dev->gd), "the volume is too big (%d LEBs), cannot resize",
  433. vi->size);
  434. return -EFBIG;
  435. }
  436. mutex_lock(&dev->dev_mutex);
  437. if (get_capacity(dev->gd) != disk_capacity) {
  438. set_capacity(dev->gd, disk_capacity);
  439. dev_info(disk_to_dev(dev->gd), "resized to %lld bytes",
  440. vi->used_bytes);
  441. }
  442. mutex_unlock(&dev->dev_mutex);
  443. mutex_unlock(&devices_mutex);
  444. return 0;
  445. }
  446. static int ubiblock_notify(struct notifier_block *nb,
  447. unsigned long notification_type, void *ns_ptr)
  448. {
  449. struct ubi_notification *nt = ns_ptr;
  450. switch (notification_type) {
  451. case UBI_VOLUME_ADDED:
  452. /*
  453. * We want to enforce explicit block device creation for
  454. * volumes, so when a volume is added we do nothing.
  455. */
  456. break;
  457. case UBI_VOLUME_REMOVED:
  458. ubiblock_remove(&nt->vi);
  459. break;
  460. case UBI_VOLUME_RESIZED:
  461. ubiblock_resize(&nt->vi);
  462. break;
  463. case UBI_VOLUME_UPDATED:
  464. /*
  465. * If the volume is static, a content update might mean the
  466. * size (i.e. used_bytes) was also changed.
  467. */
  468. if (nt->vi.vol_type == UBI_STATIC_VOLUME)
  469. ubiblock_resize(&nt->vi);
  470. break;
  471. default:
  472. break;
  473. }
  474. return NOTIFY_OK;
  475. }
  476. static struct notifier_block ubiblock_notifier = {
  477. .notifier_call = ubiblock_notify,
  478. };
  479. static struct ubi_volume_desc * __init
  480. open_volume_desc(const char *name, int ubi_num, int vol_id)
  481. {
  482. if (ubi_num == -1)
  483. /* No ubi num, name must be a vol device path */
  484. return ubi_open_volume_path(name, UBI_READONLY);
  485. else if (vol_id == -1)
  486. /* No vol_id, must be vol_name */
  487. return ubi_open_volume_nm(ubi_num, name, UBI_READONLY);
  488. else
  489. return ubi_open_volume(ubi_num, vol_id, UBI_READONLY);
  490. }
  491. static void __init ubiblock_create_from_param(void)
  492. {
  493. int i, ret = 0;
  494. struct ubiblock_param *p;
  495. struct ubi_volume_desc *desc;
  496. struct ubi_volume_info vi;
  497. /*
  498. * If there is an error creating one of the ubiblocks, continue on to
  499. * create the following ubiblocks. This helps in a circumstance where
  500. * the kernel command-line specifies multiple block devices and some
  501. * may be broken, but we still want the working ones to come up.
  502. */
  503. for (i = 0; i < ubiblock_devs; i++) {
  504. p = &ubiblock_param[i];
  505. desc = open_volume_desc(p->name, p->ubi_num, p->vol_id);
  506. if (IS_ERR(desc)) {
  507. pr_err(
  508. "UBI: block: can't open volume on ubi%d_%d, err=%ld",
  509. p->ubi_num, p->vol_id, PTR_ERR(desc));
  510. continue;
  511. }
  512. ubi_get_volume_info(desc, &vi);
  513. ubi_close_volume(desc);
  514. ret = ubiblock_create(&vi);
  515. if (ret) {
  516. pr_err(
  517. "UBI: block: can't add '%s' volume on ubi%d_%d, err=%d",
  518. vi.name, p->ubi_num, p->vol_id, ret);
  519. continue;
  520. }
  521. }
  522. }
  523. static void ubiblock_remove_all(void)
  524. {
  525. struct ubiblock *next;
  526. struct ubiblock *dev;
  527. list_for_each_entry_safe(dev, next, &ubiblock_devices, list) {
  528. /* The module is being forcefully removed */
  529. WARN_ON(dev->desc);
  530. /* Remove from device list */
  531. list_del(&dev->list);
  532. ubiblock_cleanup(dev);
  533. kfree(dev);
  534. }
  535. }
  536. int __init ubiblock_init(void)
  537. {
  538. int ret;
  539. ubiblock_major = register_blkdev(0, "ubiblock");
  540. if (ubiblock_major < 0)
  541. return ubiblock_major;
  542. /*
  543. * Attach block devices from 'block=' module param.
  544. * Even if one block device in the param list fails to come up,
  545. * still allow the module to load and leave any others up.
  546. */
  547. ubiblock_create_from_param();
  548. /*
  549. * Block devices are only created upon user requests, so we ignore
  550. * existing volumes.
  551. */
  552. ret = ubi_register_volume_notifier(&ubiblock_notifier, 1);
  553. if (ret)
  554. goto err_unreg;
  555. return 0;
  556. err_unreg:
  557. unregister_blkdev(ubiblock_major, "ubiblock");
  558. ubiblock_remove_all();
  559. return ret;
  560. }
  561. void __exit ubiblock_exit(void)
  562. {
  563. ubi_unregister_volume_notifier(&ubiblock_notifier);
  564. ubiblock_remove_all();
  565. unregister_blkdev(ubiblock_major, "ubiblock");
  566. }