block.c 16 KB

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