Lines Matching +full:ubi +full:- +full:volume +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
6 * Driver parameter handling strongly based on drivers/mtd/ubi/build.c
13 * Read-only block devices on top of UBI volumes
16 * UBI volume. The implementation is provided by creating a static 1-to-1
17 * mapping between the block device and the UBI volume.
24 * This feature is compiled in the UBI core, and adds a 'block' parameter
25 * to allow early creation of block devices on top of UBI volumes. Runtime
26 * block creation/removal for UBI volumes is provided through two UBI ioctls:
37 #include <linux/mtd/ubi.h>
39 #include <linux/blk-mq.h>
45 #include "ubi-media.h"
46 #include "ubi.h"
54 /* Maximum number of comma-separated items in the 'block=' parameter */
106 return -EINVAL;
110 pr_warn("UBI: block: empty 'block=' parameter - ignored\n");
115 pr_err("UBI: block: parameter \"%s\" is too long, max. is %d\n",
117 return -EINVAL;
123 if (buf[len - 1] == '\n')
124 buf[len - 1] = '\0';
131 /* Two parameters: can be 'ubi, vol_id' or 'ubi, vol_name' */
132 ret = kstrtoint(tokens[0], 10, &param->ubi_num);
134 return -EINVAL;
137 ret = kstrtoint(tokens[1], 10, &param->vol_id);
139 param->vol_id = -1;
140 strcpy(param->name, tokens[1]);
145 strcpy(param->name, tokens[0]);
146 param->ubi_num = -1;
147 param->vol_id = -1;
159 MODULE_PARM_DESC(block, "Attach block devices to UBI volumes. Parameter format: block=<path|dev,num|dev,name>.\n"
161 "UBI volumes may be specified by their number, name, or path to the device node.\n"
163 "Using the UBI volume path:\n"
164 "ubi.block=/dev/ubi0_0\n"
165 "Using the UBI device, and the volume name:\n"
166 "ubi.block=0,rootfs\n"
167 "Using both UBI device number and UBI volume number:\n"
168 "ubi.block=0,0\n");
175 if (dev->ubi_num == ubi_num && dev->vol_id == vol_id)
183 struct ubiblock *dev = req->q->queuedata;
188 int offset = do_div(pos, dev->leb_size);
201 ubi_sgl_init(&pdu->usgl);
202 blk_rq_map_sg(req->q, req, pdu->usgl.sg);
209 if (offset + to_read > dev->leb_size)
210 to_read = dev->leb_size - offset;
212 ret = ubi_read_sg(dev->desc, leb, &pdu->usgl, offset, to_read);
216 bytes_left -= to_read;
232 struct ubiblock *dev = disk->private_data;
235 mutex_lock(&dev->dev_mutex);
236 if (dev->refcnt > 0) {
238 * The volume is already open, just increase the reference
245 * We want users to be aware they should only mount us as read-only.
250 ret = -EROFS;
253 dev->desc = ubi_open_volume(dev->ubi_num, dev->vol_id, UBI_READONLY);
254 if (IS_ERR(dev->desc)) {
255 dev_err(disk_to_dev(dev->gd), "failed to open ubi volume %d_%d",
256 dev->ubi_num, dev->vol_id);
257 ret = PTR_ERR(dev->desc);
258 dev->desc = NULL;
263 dev->refcnt++;
264 mutex_unlock(&dev->dev_mutex);
268 mutex_unlock(&dev->dev_mutex);
274 struct ubiblock *dev = gd->private_data;
276 mutex_lock(&dev->dev_mutex);
277 dev->refcnt--;
278 if (dev->refcnt == 0) {
279 ubi_close_volume(dev->desc);
280 dev->desc = NULL;
282 mutex_unlock(&dev->dev_mutex);
288 geo->heads = 1;
289 geo->cylinders = 1;
290 geo->sectors = get_capacity(bdev->bd_disk);
291 geo->start = 0;
305 switch (req_op(bd->rq)) {
307 return ubiblock_read(bd->rq);
319 sg_init_table(pdu->usgl.sg, UBI_MAX_SG_COUNT);
330 u64 size = vi->used_bytes >> 9;
332 if (vi->used_bytes % 512) {
333 if (vi->vol_type == UBI_DYNAMIC_VOLUME)
334 pr_warn("UBI: block: volume size is not a multiple of 512, last %llu bytes are ignored!\n",
335 vi->used_bytes - (size << 9));
337 pr_info("UBI: block: volume size is not a multiple of 512, last %llu bytes are ignored!\n",
338 vi->used_bytes - (size << 9));
342 return -EFBIG;
364 /* Check that the volume isn't already handled */
366 if (find_dev_nolock(vi->ubi_num, vi->vol_id)) {
367 ret = -EEXIST;
373 ret = -ENOMEM;
377 mutex_init(&dev->dev_mutex);
379 dev->ubi_num = vi->ubi_num;
380 dev->vol_id = vi->vol_id;
381 dev->leb_size = vi->usable_leb_size;
383 dev->tag_set.ops = &ubiblock_mq_ops;
384 dev->tag_set.queue_depth = 64;
385 dev->tag_set.numa_node = NUMA_NO_NODE;
386 dev->tag_set.flags = BLK_MQ_F_BLOCKING;
387 dev->tag_set.cmd_size = sizeof(struct ubiblock_pdu);
388 dev->tag_set.driver_data = dev;
389 dev->tag_set.nr_hw_queues = 1;
391 ret = blk_mq_alloc_tag_set(&dev->tag_set);
394 dev->ubi_num, dev->vol_id);
400 gd = blk_mq_alloc_disk(&dev->tag_set, &lim, dev);
406 gd->fops = &ubiblock_ops;
407 gd->major = ubiblock_major;
408 gd->minors = 1;
409 gd->first_minor = idr_alloc(&ubiblock_minor_idr, dev, 0, 0, GFP_KERNEL);
410 if (gd->first_minor < 0) {
412 dev->ubi_num, dev->vol_id);
413 ret = -ENODEV;
416 gd->flags |= GENHD_FL_NO_PART;
417 gd->private_data = dev;
418 sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
420 dev->gd = gd;
422 dev->rq = gd->queue;
424 list_add_tail(&dev->list, &ubiblock_devices);
427 ret = device_add_disk(vi->dev, dev->gd, NULL);
431 dev_info(disk_to_dev(dev->gd), "created from ubi%d:%d(%s)",
432 dev->ubi_num, dev->vol_id, vi->name);
437 list_del(&dev->list);
438 idr_remove(&ubiblock_minor_idr, gd->first_minor);
442 blk_mq_free_tag_set(&dev->tag_set);
453 int id = dev->gd->first_minor;
456 del_gendisk(dev->gd);
458 dev_info(disk_to_dev(dev->gd), "released");
459 put_disk(dev->gd);
460 blk_mq_free_tag_set(&dev->tag_set);
470 dev = find_dev_nolock(vi->ubi_num, vi->vol_id);
472 ret = -ENODEV;
477 mutex_lock(&dev->dev_mutex);
478 if (dev->refcnt > 0) {
479 ret = -EBUSY;
484 list_del(&dev->list);
486 mutex_unlock(&dev->dev_mutex);
493 mutex_unlock(&dev->dev_mutex);
511 dev = find_dev_nolock(vi->ubi_num, vi->vol_id);
514 return -ENODEV;
520 if (ret == -EFBIG) {
521 dev_warn(disk_to_dev(dev->gd),
522 "the volume is too big (%d LEBs), cannot resize",
523 vi->size);
528 mutex_lock(&dev->dev_mutex);
530 if (get_capacity(dev->gd) != disk_capacity) {
531 set_capacity(dev->gd, disk_capacity);
532 dev_info(disk_to_dev(dev->gd), "resized to %lld bytes",
533 vi->used_bytes);
535 mutex_unlock(&dev->dev_mutex);
545 if (ubi_num == -1) {
546 /* No ubi num, name must be a vol device path */
548 if (err || vi->ubi_num != cur_ubi_num || vi->vol_id != cur_vol_id)
554 if (vol_id == -1) {
555 /* Got ubi_num, but no vol_id, name must be volume name */
556 if (vi->ubi_num != ubi_num)
560 if (len < 1 || vi->name_len != len)
563 if (strcmp(name, vi->name))
569 if (vi->ubi_num != ubi_num)
572 if (vi->vol_id != vol_id)
586 * newly added volume create the ubiblock device for it.
591 if (!match_volume_desc(vi, p->name, p->ubi_num, p->vol_id))
597 "UBI: block: can't add '%s' volume on ubi%d_%d, err=%d\n",
598 vi->name, p->ubi_num, p->vol_id, ret);
611 ubiblock_create_from_param(&nt->vi);
614 ubiblock_remove(&nt->vi);
617 ubiblock_resize(&nt->vi);
621 * If the volume is static, a content update might mean the
624 if (nt->vi.vol_type == UBI_STATIC_VOLUME)
625 ubiblock_resize(&nt->vi);
645 WARN_ON(dev->desc);
647 list_del(&dev->list);