Merge branch 'linux-next' of git://git.infradead.org/~dedekind/ubi-2.6

* 'linux-next' of git://git.infradead.org/~dedekind/ubi-2.6: (22 commits)
UBI: always start the background thread
UBI: fix gcc warning
UBI: remove pre-sqnum images support
UBI: fix kernel-doc errors and warnings
UBI: fix checkpatch.pl errors and warnings
UBI: bugfix - do not torture PEB needlessly
UBI: rework scrubbing messages
UBI: implement multiple volumes rename
UBI: fix and re-work debugging stuff
UBI: amend commentaries
UBI: fix error message
UBI: improve mkvol request validation
UBI: add ubi_sync() interface
UBI: fix 64-bit calculations
UBI: fix LEB locking
UBI: fix memory leak on error path
UBI: do not forget to free internal volumes
UBI: fix memory leak
UBI: avoid unnecessary division operations
UBI: fix buffer padding
...

+1008 -616
+73 -26
drivers/mtd/ubi/build.c
··· 51 51 * @name: MTD device name or number string 52 52 * @vid_hdr_offs: VID header offset 53 53 */ 54 - struct mtd_dev_param 55 - { 54 + struct mtd_dev_param { 56 55 char name[MTD_PARAM_LEN_MAX]; 57 56 int vid_hdr_offs; 58 57 }; 59 58 60 59 /* Numbers of elements set in the @mtd_dev_param array */ 61 - static int mtd_devs = 0; 60 + static int mtd_devs; 62 61 63 62 /* MTD devices specification parameters */ 64 63 static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES]; ··· 159 160 } 160 161 161 162 /** 162 - * ubi_get_by_major - get UBI device description object by character device 163 - * major number. 163 + * ubi_get_by_major - get UBI device by character device major number. 164 164 * @major: major number 165 165 * 166 166 * This function is similar to 'ubi_get_device()', but it searches the device ··· 353 355 } 354 356 355 357 /** 358 + * free_user_volumes - free all user volumes. 359 + * @ubi: UBI device description object 360 + * 361 + * Normally the volumes are freed at the release function of the volume device 362 + * objects. However, on error paths the volumes have to be freed before the 363 + * device objects have been initialized. 364 + */ 365 + static void free_user_volumes(struct ubi_device *ubi) 366 + { 367 + int i; 368 + 369 + for (i = 0; i < ubi->vtbl_slots; i++) 370 + if (ubi->volumes[i]) { 371 + kfree(ubi->volumes[i]->eba_tbl); 372 + kfree(ubi->volumes[i]); 373 + } 374 + } 375 + 376 + /** 356 377 * uif_init - initialize user interfaces for an UBI device. 357 378 * @ubi: UBI device description object 358 379 * 359 380 * This function returns zero in case of success and a negative error code in 360 - * case of failure. 381 + * case of failure. Note, this function destroys all volumes if it failes. 361 382 */ 362 383 static int uif_init(struct ubi_device *ubi) 363 384 { 364 - int i, err; 385 + int i, err, do_free = 0; 365 386 dev_t dev; 366 387 367 388 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); ··· 401 384 402 385 ubi_assert(MINOR(dev) == 0); 403 386 cdev_init(&ubi->cdev, &ubi_cdev_operations); 404 - dbg_msg("%s major is %u", ubi->ubi_name, MAJOR(dev)); 387 + dbg_gen("%s major is %u", ubi->ubi_name, MAJOR(dev)); 405 388 ubi->cdev.owner = THIS_MODULE; 406 389 407 390 err = cdev_add(&ubi->cdev, dev, 1); ··· 427 410 428 411 out_volumes: 429 412 kill_volumes(ubi); 413 + do_free = 0; 430 414 out_sysfs: 431 415 ubi_sysfs_close(ubi); 432 416 cdev_del(&ubi->cdev); 433 417 out_unreg: 418 + if (do_free) 419 + free_user_volumes(ubi); 434 420 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); 435 421 ubi_err("cannot initialize UBI %s, error %d", ubi->ubi_name, err); 436 422 return err; ··· 442 422 /** 443 423 * uif_close - close user interfaces for an UBI device. 444 424 * @ubi: UBI device description object 425 + * 426 + * Note, since this function un-registers UBI volume device objects (@vol->dev), 427 + * the memory allocated voe the volumes is freed as well (in the release 428 + * function). 445 429 */ 446 430 static void uif_close(struct ubi_device *ubi) 447 431 { ··· 453 429 ubi_sysfs_close(ubi); 454 430 cdev_del(&ubi->cdev); 455 431 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); 432 + } 433 + 434 + /** 435 + * free_internal_volumes - free internal volumes. 436 + * @ubi: UBI device description object 437 + */ 438 + static void free_internal_volumes(struct ubi_device *ubi) 439 + { 440 + int i; 441 + 442 + for (i = ubi->vtbl_slots; 443 + i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { 444 + kfree(ubi->volumes[i]->eba_tbl); 445 + kfree(ubi->volumes[i]); 446 + } 456 447 } 457 448 458 449 /** ··· 514 475 out_wl: 515 476 ubi_wl_close(ubi); 516 477 out_vtbl: 478 + free_internal_volumes(ubi); 517 479 vfree(ubi->vtbl); 518 480 out_si: 519 481 ubi_scan_destroy_si(si); ··· 522 482 } 523 483 524 484 /** 525 - * io_init - initialize I/O unit for a given UBI device. 485 + * io_init - initialize I/O sub-system for a given UBI device. 526 486 * @ubi: UBI device description object 527 487 * 528 488 * If @ubi->vid_hdr_offset or @ubi->leb_start is zero, default offsets are ··· 570 530 ubi->min_io_size = ubi->mtd->writesize; 571 531 ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft; 572 532 573 - /* Make sure minimal I/O unit is power of 2 */ 533 + /* 534 + * Make sure minimal I/O unit is power of 2. Note, there is no 535 + * fundamental reason for this assumption. It is just an optimization 536 + * which allows us to avoid costly division operations. 537 + */ 574 538 if (!is_power_of_2(ubi->min_io_size)) { 575 539 ubi_err("min. I/O unit (%d) is not power of 2", 576 540 ubi->min_io_size); ··· 625 581 if (ubi->vid_hdr_offset < UBI_EC_HDR_SIZE || 626 582 ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE || 627 583 ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE || 628 - ubi->leb_start % ubi->min_io_size) { 584 + ubi->leb_start & (ubi->min_io_size - 1)) { 629 585 ubi_err("bad VID header (%d) or data offsets (%d)", 630 586 ubi->vid_hdr_offset, ubi->leb_start); 631 587 return -EINVAL; ··· 690 646 691 647 /* 692 648 * Clear the auto-resize flag in the volume in-memory copy of the 693 - * volume table, and 'ubi_resize_volume()' will propogate this change 649 + * volume table, and 'ubi_resize_volume()' will propagate this change 694 650 * to the flash. 695 651 */ 696 652 ubi->vtbl[vol_id].flags &= ~UBI_VTBL_AUTORESIZE_FLG; ··· 699 655 struct ubi_vtbl_record vtbl_rec; 700 656 701 657 /* 702 - * No avalilable PEBs to re-size the volume, clear the flag on 658 + * No available PEBs to re-size the volume, clear the flag on 703 659 * flash and exit. 704 660 */ 705 661 memcpy(&vtbl_rec, &ubi->vtbl[vol_id], ··· 726 682 727 683 /** 728 684 * ubi_attach_mtd_dev - attach an MTD device. 729 - * @mtd_dev: MTD device description object 685 + * @mtd: MTD device description object 730 686 * @ubi_num: number to assign to the new UBI device 731 687 * @vid_hdr_offset: VID header offset 732 688 * 733 689 * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number 734 690 * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in 735 - * which case this function finds a vacant device nubert and assings it 691 + * which case this function finds a vacant device number and assigns it 736 692 * automatically. Returns the new UBI device number in case of success and a 737 693 * negative error code in case of failure. 738 694 * ··· 742 698 int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) 743 699 { 744 700 struct ubi_device *ubi; 745 - int i, err; 701 + int i, err, do_free = 1; 746 702 747 703 /* 748 704 * Check if we already have the same MTD device attached. ··· 779 735 if (!ubi_devices[ubi_num]) 780 736 break; 781 737 if (ubi_num == UBI_MAX_DEVICES) { 782 - dbg_err("only %d UBI devices may be created", UBI_MAX_DEVICES); 738 + dbg_err("only %d UBI devices may be created", 739 + UBI_MAX_DEVICES); 783 740 return -ENFILE; 784 741 } 785 742 } else { ··· 805 760 806 761 mutex_init(&ubi->buf_mutex); 807 762 mutex_init(&ubi->ckvol_mutex); 763 + mutex_init(&ubi->mult_mutex); 808 764 mutex_init(&ubi->volumes_mutex); 809 765 spin_lock_init(&ubi->volumes_lock); 810 766 ··· 844 798 845 799 err = uif_init(ubi); 846 800 if (err) 847 - goto out_detach; 801 + goto out_nofree; 848 802 849 803 ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name); 850 804 if (IS_ERR(ubi->bgt_thread)) { ··· 870 824 ubi->beb_rsvd_pebs); 871 825 ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec); 872 826 873 - /* Enable the background thread */ 874 - if (!DBG_DISABLE_BGT) { 827 + if (!DBG_DISABLE_BGT) 875 828 ubi->thread_enabled = 1; 876 - wake_up_process(ubi->bgt_thread); 877 - } 829 + wake_up_process(ubi->bgt_thread); 878 830 879 831 ubi_devices[ubi_num] = ubi; 880 832 return ubi_num; 881 833 882 834 out_uif: 883 835 uif_close(ubi); 836 + out_nofree: 837 + do_free = 0; 884 838 out_detach: 885 - ubi_eba_close(ubi); 886 839 ubi_wl_close(ubi); 840 + if (do_free) 841 + free_user_volumes(ubi); 842 + free_internal_volumes(ubi); 887 843 vfree(ubi->vtbl); 888 844 out_free: 889 845 vfree(ubi->peb_buf1); ··· 947 899 kthread_stop(ubi->bgt_thread); 948 900 949 901 uif_close(ubi); 950 - ubi_eba_close(ubi); 951 902 ubi_wl_close(ubi); 903 + free_internal_volumes(ubi); 952 904 vfree(ubi->vtbl); 953 905 put_mtd_device(ubi->mtd); 954 906 vfree(ubi->peb_buf1); ··· 1092 1044 module_exit(ubi_exit); 1093 1045 1094 1046 /** 1095 - * bytes_str_to_int - convert a string representing number of bytes to an 1096 - * integer. 1047 + * bytes_str_to_int - convert a number of bytes string into an integer. 1097 1048 * @str: the string to convert 1098 1049 * 1099 1050 * This function returns positive resulting integer in case of success and a
+212 -22
drivers/mtd/ubi/cdev.c
··· 39 39 #include <linux/stat.h> 40 40 #include <linux/ioctl.h> 41 41 #include <linux/capability.h> 42 + #include <linux/uaccess.h> 42 43 #include <linux/smp_lock.h> 43 44 #include <mtd/ubi-user.h> 44 - #include <asm/uaccess.h> 45 45 #include <asm/div64.h> 46 46 #include "ubi.h" 47 47 ··· 116 116 else 117 117 mode = UBI_READONLY; 118 118 119 - dbg_msg("open volume %d, mode %d", vol_id, mode); 119 + dbg_gen("open volume %d, mode %d", vol_id, mode); 120 120 121 121 desc = ubi_open_volume(ubi_num, vol_id, mode); 122 122 unlock_kernel(); ··· 132 132 struct ubi_volume_desc *desc = file->private_data; 133 133 struct ubi_volume *vol = desc->vol; 134 134 135 - dbg_msg("release volume %d, mode %d", vol->vol_id, desc->mode); 135 + dbg_gen("release volume %d, mode %d", vol->vol_id, desc->mode); 136 136 137 137 if (vol->updating) { 138 138 ubi_warn("update of volume %d not finished, volume is damaged", ··· 141 141 vol->updating = 0; 142 142 vfree(vol->upd_buf); 143 143 } else if (vol->changing_leb) { 144 - dbg_msg("only %lld of %lld bytes received for atomic LEB change" 144 + dbg_gen("only %lld of %lld bytes received for atomic LEB change" 145 145 " for volume %d:%d, cancel", vol->upd_received, 146 146 vol->upd_bytes, vol->ubi->ubi_num, vol->vol_id); 147 147 vol->changing_leb = 0; ··· 183 183 return -EINVAL; 184 184 } 185 185 186 - dbg_msg("seek volume %d, offset %lld, origin %d, new offset %lld", 186 + dbg_gen("seek volume %d, offset %lld, origin %d, new offset %lld", 187 187 vol->vol_id, offset, origin, new_offset); 188 188 189 189 file->f_pos = new_offset; ··· 201 201 void *tbuf; 202 202 uint64_t tmp; 203 203 204 - dbg_msg("read %zd bytes from offset %lld of volume %d", 204 + dbg_gen("read %zd bytes from offset %lld of volume %d", 205 205 count, *offp, vol->vol_id); 206 206 207 207 if (vol->updating) { ··· 216 216 return 0; 217 217 218 218 if (vol->corrupted) 219 - dbg_msg("read from corrupted volume %d", vol->vol_id); 219 + dbg_gen("read from corrupted volume %d", vol->vol_id); 220 220 221 221 if (*offp + count > vol->used_bytes) 222 222 count_save = count = vol->used_bytes - *offp; ··· 285 285 char *tbuf; 286 286 uint64_t tmp; 287 287 288 - dbg_msg("requested: write %zd bytes to offset %lld of volume %u", 288 + dbg_gen("requested: write %zd bytes to offset %lld of volume %u", 289 289 count, *offp, vol->vol_id); 290 290 291 291 if (vol->vol_type == UBI_STATIC_VOLUME) ··· 295 295 off = do_div(tmp, vol->usable_leb_size); 296 296 lnum = tmp; 297 297 298 - if (off % ubi->min_io_size) { 298 + if (off & (ubi->min_io_size - 1)) { 299 299 dbg_err("unaligned position"); 300 300 return -EINVAL; 301 301 } ··· 304 304 count_save = count = vol->used_bytes - *offp; 305 305 306 306 /* We can write only in fractions of the minimum I/O unit */ 307 - if (count % ubi->min_io_size) { 307 + if (count & (ubi->min_io_size - 1)) { 308 308 dbg_err("unaligned write length"); 309 309 return -EINVAL; 310 310 } ··· 352 352 } 353 353 354 354 #else 355 - #define vol_cdev_direct_write(file, buf, count, offp) -EPERM 355 + #define vol_cdev_direct_write(file, buf, count, offp) (-EPERM) 356 356 #endif /* CONFIG_MTD_UBI_DEBUG_USERSPACE_IO */ 357 357 358 358 static ssize_t vol_cdev_write(struct file *file, const char __user *buf, ··· 437 437 break; 438 438 } 439 439 440 - rsvd_bytes = vol->reserved_pebs * (ubi->leb_size-vol->data_pad); 440 + rsvd_bytes = (long long)vol->reserved_pebs * 441 + ubi->leb_size-vol->data_pad; 441 442 if (bytes < 0 || bytes > rsvd_bytes) { 442 443 err = -EINVAL; 443 444 break; ··· 514 513 break; 515 514 } 516 515 517 - dbg_msg("erase LEB %d:%d", vol->vol_id, lnum); 516 + dbg_gen("erase LEB %d:%d", vol->vol_id, lnum); 518 517 err = ubi_eba_unmap_leb(ubi, vol, lnum); 519 518 if (err) 520 519 break; ··· 565 564 if (req->alignment > ubi->leb_size) 566 565 goto bad; 567 566 568 - n = req->alignment % ubi->min_io_size; 567 + n = req->alignment & (ubi->min_io_size - 1); 569 568 if (req->alignment != 1 && n) 570 569 goto bad; 571 570 ··· 573 572 err = -ENAMETOOLONG; 574 573 goto bad; 575 574 } 575 + 576 + n = strnlen(req->name, req->name_len + 1); 577 + if (n != req->name_len) 578 + goto bad; 576 579 577 580 return 0; 578 581 ··· 605 600 return 0; 606 601 } 607 602 603 + /** 604 + * rename_volumes - rename UBI volumes. 605 + * @ubi: UBI device description object 606 + * @req: volumes re-name request 607 + * 608 + * This is a helper function for the volume re-name IOCTL which validates the 609 + * the request, opens the volume and calls corresponding volumes management 610 + * function. Returns zero in case of success and a negative error code in case 611 + * of failure. 612 + */ 613 + static int rename_volumes(struct ubi_device *ubi, 614 + struct ubi_rnvol_req *req) 615 + { 616 + int i, n, err; 617 + struct list_head rename_list; 618 + struct ubi_rename_entry *re, *re1; 619 + 620 + if (req->count < 0 || req->count > UBI_MAX_RNVOL) 621 + return -EINVAL; 622 + 623 + if (req->count == 0) 624 + return 0; 625 + 626 + /* Validate volume IDs and names in the request */ 627 + for (i = 0; i < req->count; i++) { 628 + if (req->ents[i].vol_id < 0 || 629 + req->ents[i].vol_id >= ubi->vtbl_slots) 630 + return -EINVAL; 631 + if (req->ents[i].name_len < 0) 632 + return -EINVAL; 633 + if (req->ents[i].name_len > UBI_VOL_NAME_MAX) 634 + return -ENAMETOOLONG; 635 + req->ents[i].name[req->ents[i].name_len] = '\0'; 636 + n = strlen(req->ents[i].name); 637 + if (n != req->ents[i].name_len) 638 + err = -EINVAL; 639 + } 640 + 641 + /* Make sure volume IDs and names are unique */ 642 + for (i = 0; i < req->count - 1; i++) { 643 + for (n = i + 1; n < req->count; n++) { 644 + if (req->ents[i].vol_id == req->ents[n].vol_id) { 645 + dbg_err("duplicated volume id %d", 646 + req->ents[i].vol_id); 647 + return -EINVAL; 648 + } 649 + if (!strcmp(req->ents[i].name, req->ents[n].name)) { 650 + dbg_err("duplicated volume name \"%s\"", 651 + req->ents[i].name); 652 + return -EINVAL; 653 + } 654 + } 655 + } 656 + 657 + /* Create the re-name list */ 658 + INIT_LIST_HEAD(&rename_list); 659 + for (i = 0; i < req->count; i++) { 660 + int vol_id = req->ents[i].vol_id; 661 + int name_len = req->ents[i].name_len; 662 + const char *name = req->ents[i].name; 663 + 664 + re = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL); 665 + if (!re) { 666 + err = -ENOMEM; 667 + goto out_free; 668 + } 669 + 670 + re->desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_EXCLUSIVE); 671 + if (IS_ERR(re->desc)) { 672 + err = PTR_ERR(re->desc); 673 + dbg_err("cannot open volume %d, error %d", vol_id, err); 674 + kfree(re); 675 + goto out_free; 676 + } 677 + 678 + /* Skip this re-naming if the name does not really change */ 679 + if (re->desc->vol->name_len == name_len && 680 + !memcmp(re->desc->vol->name, name, name_len)) { 681 + ubi_close_volume(re->desc); 682 + kfree(re); 683 + continue; 684 + } 685 + 686 + re->new_name_len = name_len; 687 + memcpy(re->new_name, name, name_len); 688 + list_add_tail(&re->list, &rename_list); 689 + dbg_msg("will rename volume %d from \"%s\" to \"%s\"", 690 + vol_id, re->desc->vol->name, name); 691 + } 692 + 693 + if (list_empty(&rename_list)) 694 + return 0; 695 + 696 + /* Find out the volumes which have to be removed */ 697 + list_for_each_entry(re, &rename_list, list) { 698 + struct ubi_volume_desc *desc; 699 + int no_remove_needed = 0; 700 + 701 + /* 702 + * Volume @re->vol_id is going to be re-named to 703 + * @re->new_name, while its current name is @name. If a volume 704 + * with name @re->new_name currently exists, it has to be 705 + * removed, unless it is also re-named in the request (@req). 706 + */ 707 + list_for_each_entry(re1, &rename_list, list) { 708 + if (re->new_name_len == re1->desc->vol->name_len && 709 + !memcmp(re->new_name, re1->desc->vol->name, 710 + re1->desc->vol->name_len)) { 711 + no_remove_needed = 1; 712 + break; 713 + } 714 + } 715 + 716 + if (no_remove_needed) 717 + continue; 718 + 719 + /* 720 + * It seems we need to remove volume with name @re->new_name, 721 + * if it exists. 722 + */ 723 + desc = ubi_open_volume_nm(ubi->ubi_num, re->new_name, UBI_EXCLUSIVE); 724 + if (IS_ERR(desc)) { 725 + err = PTR_ERR(desc); 726 + if (err == -ENODEV) 727 + /* Re-naming into a non-existing volume name */ 728 + continue; 729 + 730 + /* The volume exists but busy, or an error occurred */ 731 + dbg_err("cannot open volume \"%s\", error %d", 732 + re->new_name, err); 733 + goto out_free; 734 + } 735 + 736 + re = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL); 737 + if (!re) { 738 + err = -ENOMEM; 739 + ubi_close_volume(desc); 740 + goto out_free; 741 + } 742 + 743 + re->remove = 1; 744 + re->desc = desc; 745 + list_add(&re->list, &rename_list); 746 + dbg_msg("will remove volume %d, name \"%s\"", 747 + re->desc->vol->vol_id, re->desc->vol->name); 748 + } 749 + 750 + mutex_lock(&ubi->volumes_mutex); 751 + err = ubi_rename_volumes(ubi, &rename_list); 752 + mutex_unlock(&ubi->volumes_mutex); 753 + 754 + out_free: 755 + list_for_each_entry_safe(re, re1, &rename_list, list) { 756 + ubi_close_volume(re->desc); 757 + list_del(&re->list); 758 + kfree(re); 759 + } 760 + return err; 761 + } 762 + 608 763 static int ubi_cdev_ioctl(struct inode *inode, struct file *file, 609 764 unsigned int cmd, unsigned long arg) 610 765 { ··· 786 621 { 787 622 struct ubi_mkvol_req req; 788 623 789 - dbg_msg("create volume"); 624 + dbg_gen("create volume"); 790 625 err = copy_from_user(&req, argp, sizeof(struct ubi_mkvol_req)); 791 626 if (err) { 792 627 err = -EFAULT; 793 628 break; 794 629 } 795 630 631 + req.name[req.name_len] = '\0'; 796 632 err = verify_mkvol_req(ubi, &req); 797 633 if (err) 798 634 break; 799 - 800 - req.name[req.name_len] = '\0'; 801 635 802 636 mutex_lock(&ubi->volumes_mutex); 803 637 err = ubi_create_volume(ubi, &req); ··· 816 652 { 817 653 int vol_id; 818 654 819 - dbg_msg("remove volume"); 655 + dbg_gen("remove volume"); 820 656 err = get_user(vol_id, (__user int32_t *)argp); 821 657 if (err) { 822 658 err = -EFAULT; ··· 830 666 } 831 667 832 668 mutex_lock(&ubi->volumes_mutex); 833 - err = ubi_remove_volume(desc); 669 + err = ubi_remove_volume(desc, 0); 834 670 mutex_unlock(&ubi->volumes_mutex); 835 671 836 672 /* ··· 849 685 uint64_t tmp; 850 686 struct ubi_rsvol_req req; 851 687 852 - dbg_msg("re-size volume"); 688 + dbg_gen("re-size volume"); 853 689 err = copy_from_user(&req, argp, sizeof(struct ubi_rsvol_req)); 854 690 if (err) { 855 691 err = -EFAULT; ··· 874 710 err = ubi_resize_volume(desc, pebs); 875 711 mutex_unlock(&ubi->volumes_mutex); 876 712 ubi_close_volume(desc); 713 + break; 714 + } 715 + 716 + /* Re-name volumes command */ 717 + case UBI_IOCRNVOL: 718 + { 719 + struct ubi_rnvol_req *req; 720 + 721 + dbg_msg("re-name volumes"); 722 + req = kmalloc(sizeof(struct ubi_rnvol_req), GFP_KERNEL); 723 + if (!req) { 724 + err = -ENOMEM; 725 + break; 726 + }; 727 + 728 + err = copy_from_user(req, argp, sizeof(struct ubi_rnvol_req)); 729 + if (err) { 730 + err = -EFAULT; 731 + kfree(req); 732 + break; 733 + } 734 + 735 + mutex_lock(&ubi->mult_mutex); 736 + err = rename_volumes(ubi, req); 737 + mutex_unlock(&ubi->mult_mutex); 738 + kfree(req); 877 739 break; 878 740 } 879 741 ··· 928 738 struct ubi_attach_req req; 929 739 struct mtd_info *mtd; 930 740 931 - dbg_msg("attach MTD device"); 741 + dbg_gen("attach MTD device"); 932 742 err = copy_from_user(&req, argp, sizeof(struct ubi_attach_req)); 933 743 if (err) { 934 744 err = -EFAULT; ··· 968 778 { 969 779 int ubi_num; 970 780 971 - dbg_msg("dettach MTD device"); 781 + dbg_gen("dettach MTD device"); 972 782 err = get_user(ubi_num, (__user int32_t *)argp); 973 783 if (err) { 974 784 err = -EFAULT;
+82 -76
drivers/mtd/ubi/debug.c
··· 24 24 * changes. 25 25 */ 26 26 27 - #ifdef CONFIG_MTD_UBI_DEBUG_MSG 27 + #ifdef CONFIG_MTD_UBI_DEBUG 28 28 29 29 #include "ubi.h" 30 30 ··· 34 34 */ 35 35 void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) 36 36 { 37 - dbg_msg("erase counter header dump:"); 38 - dbg_msg("magic %#08x", be32_to_cpu(ec_hdr->magic)); 39 - dbg_msg("version %d", (int)ec_hdr->version); 40 - dbg_msg("ec %llu", (long long)be64_to_cpu(ec_hdr->ec)); 41 - dbg_msg("vid_hdr_offset %d", be32_to_cpu(ec_hdr->vid_hdr_offset)); 42 - dbg_msg("data_offset %d", be32_to_cpu(ec_hdr->data_offset)); 43 - dbg_msg("hdr_crc %#08x", be32_to_cpu(ec_hdr->hdr_crc)); 44 - dbg_msg("erase counter header hexdump:"); 37 + printk(KERN_DEBUG "Erase counter header dump:\n"); 38 + printk(KERN_DEBUG "\tmagic %#08x\n", 39 + be32_to_cpu(ec_hdr->magic)); 40 + printk(KERN_DEBUG "\tversion %d\n", (int)ec_hdr->version); 41 + printk(KERN_DEBUG "\tec %llu\n", 42 + (long long)be64_to_cpu(ec_hdr->ec)); 43 + printk(KERN_DEBUG "\tvid_hdr_offset %d\n", 44 + be32_to_cpu(ec_hdr->vid_hdr_offset)); 45 + printk(KERN_DEBUG "\tdata_offset %d\n", 46 + be32_to_cpu(ec_hdr->data_offset)); 47 + printk(KERN_DEBUG "\thdr_crc %#08x\n", 48 + be32_to_cpu(ec_hdr->hdr_crc)); 49 + printk(KERN_DEBUG "erase counter header hexdump:\n"); 45 50 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 46 51 ec_hdr, UBI_EC_HDR_SIZE, 1); 47 52 } ··· 57 52 */ 58 53 void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) 59 54 { 60 - dbg_msg("volume identifier header dump:"); 61 - dbg_msg("magic %08x", be32_to_cpu(vid_hdr->magic)); 62 - dbg_msg("version %d", (int)vid_hdr->version); 63 - dbg_msg("vol_type %d", (int)vid_hdr->vol_type); 64 - dbg_msg("copy_flag %d", (int)vid_hdr->copy_flag); 65 - dbg_msg("compat %d", (int)vid_hdr->compat); 66 - dbg_msg("vol_id %d", be32_to_cpu(vid_hdr->vol_id)); 67 - dbg_msg("lnum %d", be32_to_cpu(vid_hdr->lnum)); 68 - dbg_msg("leb_ver %u", be32_to_cpu(vid_hdr->leb_ver)); 69 - dbg_msg("data_size %d", be32_to_cpu(vid_hdr->data_size)); 70 - dbg_msg("used_ebs %d", be32_to_cpu(vid_hdr->used_ebs)); 71 - dbg_msg("data_pad %d", be32_to_cpu(vid_hdr->data_pad)); 72 - dbg_msg("sqnum %llu", 55 + printk(KERN_DEBUG "Volume identifier header dump:\n"); 56 + printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic)); 57 + printk(KERN_DEBUG "\tversion %d\n", (int)vid_hdr->version); 58 + printk(KERN_DEBUG "\tvol_type %d\n", (int)vid_hdr->vol_type); 59 + printk(KERN_DEBUG "\tcopy_flag %d\n", (int)vid_hdr->copy_flag); 60 + printk(KERN_DEBUG "\tcompat %d\n", (int)vid_hdr->compat); 61 + printk(KERN_DEBUG "\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id)); 62 + printk(KERN_DEBUG "\tlnum %d\n", be32_to_cpu(vid_hdr->lnum)); 63 + printk(KERN_DEBUG "\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size)); 64 + printk(KERN_DEBUG "\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs)); 65 + printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad)); 66 + printk(KERN_DEBUG "\tsqnum %llu\n", 73 67 (unsigned long long)be64_to_cpu(vid_hdr->sqnum)); 74 - dbg_msg("hdr_crc %08x", be32_to_cpu(vid_hdr->hdr_crc)); 75 - dbg_msg("volume identifier header hexdump:"); 68 + printk(KERN_DEBUG "\thdr_crc %08x\n", be32_to_cpu(vid_hdr->hdr_crc)); 69 + printk(KERN_DEBUG "Volume identifier header hexdump:\n"); 70 + print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 71 + vid_hdr, UBI_VID_HDR_SIZE, 1); 76 72 } 77 73 78 74 /** ··· 82 76 */ 83 77 void ubi_dbg_dump_vol_info(const struct ubi_volume *vol) 84 78 { 85 - dbg_msg("volume information dump:"); 86 - dbg_msg("vol_id %d", vol->vol_id); 87 - dbg_msg("reserved_pebs %d", vol->reserved_pebs); 88 - dbg_msg("alignment %d", vol->alignment); 89 - dbg_msg("data_pad %d", vol->data_pad); 90 - dbg_msg("vol_type %d", vol->vol_type); 91 - dbg_msg("name_len %d", vol->name_len); 92 - dbg_msg("usable_leb_size %d", vol->usable_leb_size); 93 - dbg_msg("used_ebs %d", vol->used_ebs); 94 - dbg_msg("used_bytes %lld", vol->used_bytes); 95 - dbg_msg("last_eb_bytes %d", vol->last_eb_bytes); 96 - dbg_msg("corrupted %d", vol->corrupted); 97 - dbg_msg("upd_marker %d", vol->upd_marker); 79 + printk(KERN_DEBUG "Volume information dump:\n"); 80 + printk(KERN_DEBUG "\tvol_id %d\n", vol->vol_id); 81 + printk(KERN_DEBUG "\treserved_pebs %d\n", vol->reserved_pebs); 82 + printk(KERN_DEBUG "\talignment %d\n", vol->alignment); 83 + printk(KERN_DEBUG "\tdata_pad %d\n", vol->data_pad); 84 + printk(KERN_DEBUG "\tvol_type %d\n", vol->vol_type); 85 + printk(KERN_DEBUG "\tname_len %d\n", vol->name_len); 86 + printk(KERN_DEBUG "\tusable_leb_size %d\n", vol->usable_leb_size); 87 + printk(KERN_DEBUG "\tused_ebs %d\n", vol->used_ebs); 88 + printk(KERN_DEBUG "\tused_bytes %lld\n", vol->used_bytes); 89 + printk(KERN_DEBUG "\tlast_eb_bytes %d\n", vol->last_eb_bytes); 90 + printk(KERN_DEBUG "\tcorrupted %d\n", vol->corrupted); 91 + printk(KERN_DEBUG "\tupd_marker %d\n", vol->upd_marker); 98 92 99 93 if (vol->name_len <= UBI_VOL_NAME_MAX && 100 94 strnlen(vol->name, vol->name_len + 1) == vol->name_len) { 101 - dbg_msg("name %s", vol->name); 95 + printk(KERN_DEBUG "\tname %s\n", vol->name); 102 96 } else { 103 - dbg_msg("the 1st 5 characters of the name: %c%c%c%c%c", 104 - vol->name[0], vol->name[1], vol->name[2], 105 - vol->name[3], vol->name[4]); 97 + printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n", 98 + vol->name[0], vol->name[1], vol->name[2], 99 + vol->name[3], vol->name[4]); 106 100 } 107 101 } 108 102 ··· 115 109 { 116 110 int name_len = be16_to_cpu(r->name_len); 117 111 118 - dbg_msg("volume table record %d dump:", idx); 119 - dbg_msg("reserved_pebs %d", be32_to_cpu(r->reserved_pebs)); 120 - dbg_msg("alignment %d", be32_to_cpu(r->alignment)); 121 - dbg_msg("data_pad %d", be32_to_cpu(r->data_pad)); 122 - dbg_msg("vol_type %d", (int)r->vol_type); 123 - dbg_msg("upd_marker %d", (int)r->upd_marker); 124 - dbg_msg("name_len %d", name_len); 112 + printk(KERN_DEBUG "Volume table record %d dump:\n", idx); 113 + printk(KERN_DEBUG "\treserved_pebs %d\n", 114 + be32_to_cpu(r->reserved_pebs)); 115 + printk(KERN_DEBUG "\talignment %d\n", be32_to_cpu(r->alignment)); 116 + printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(r->data_pad)); 117 + printk(KERN_DEBUG "\tvol_type %d\n", (int)r->vol_type); 118 + printk(KERN_DEBUG "\tupd_marker %d\n", (int)r->upd_marker); 119 + printk(KERN_DEBUG "\tname_len %d\n", name_len); 125 120 126 121 if (r->name[0] == '\0') { 127 - dbg_msg("name NULL"); 122 + printk(KERN_DEBUG "\tname NULL\n"); 128 123 return; 129 124 } 130 125 131 126 if (name_len <= UBI_VOL_NAME_MAX && 132 127 strnlen(&r->name[0], name_len + 1) == name_len) { 133 - dbg_msg("name %s", &r->name[0]); 128 + printk(KERN_DEBUG "\tname %s\n", &r->name[0]); 134 129 } else { 135 - dbg_msg("1st 5 characters of the name: %c%c%c%c%c", 130 + printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n", 136 131 r->name[0], r->name[1], r->name[2], r->name[3], 137 132 r->name[4]); 138 133 } 139 - dbg_msg("crc %#08x", be32_to_cpu(r->crc)); 134 + printk(KERN_DEBUG "\tcrc %#08x\n", be32_to_cpu(r->crc)); 140 135 } 141 136 142 137 /** ··· 146 139 */ 147 140 void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv) 148 141 { 149 - dbg_msg("volume scanning information dump:"); 150 - dbg_msg("vol_id %d", sv->vol_id); 151 - dbg_msg("highest_lnum %d", sv->highest_lnum); 152 - dbg_msg("leb_count %d", sv->leb_count); 153 - dbg_msg("compat %d", sv->compat); 154 - dbg_msg("vol_type %d", sv->vol_type); 155 - dbg_msg("used_ebs %d", sv->used_ebs); 156 - dbg_msg("last_data_size %d", sv->last_data_size); 157 - dbg_msg("data_pad %d", sv->data_pad); 142 + printk(KERN_DEBUG "Volume scanning information dump:\n"); 143 + printk(KERN_DEBUG "\tvol_id %d\n", sv->vol_id); 144 + printk(KERN_DEBUG "\thighest_lnum %d\n", sv->highest_lnum); 145 + printk(KERN_DEBUG "\tleb_count %d\n", sv->leb_count); 146 + printk(KERN_DEBUG "\tcompat %d\n", sv->compat); 147 + printk(KERN_DEBUG "\tvol_type %d\n", sv->vol_type); 148 + printk(KERN_DEBUG "\tused_ebs %d\n", sv->used_ebs); 149 + printk(KERN_DEBUG "\tlast_data_size %d\n", sv->last_data_size); 150 + printk(KERN_DEBUG "\tdata_pad %d\n", sv->data_pad); 158 151 } 159 152 160 153 /** ··· 164 157 */ 165 158 void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type) 166 159 { 167 - dbg_msg("eraseblock scanning information dump:"); 168 - dbg_msg("ec %d", seb->ec); 169 - dbg_msg("pnum %d", seb->pnum); 160 + printk(KERN_DEBUG "eraseblock scanning information dump:\n"); 161 + printk(KERN_DEBUG "\tec %d\n", seb->ec); 162 + printk(KERN_DEBUG "\tpnum %d\n", seb->pnum); 170 163 if (type == 0) { 171 - dbg_msg("lnum %d", seb->lnum); 172 - dbg_msg("scrub %d", seb->scrub); 173 - dbg_msg("sqnum %llu", seb->sqnum); 174 - dbg_msg("leb_ver %u", seb->leb_ver); 164 + printk(KERN_DEBUG "\tlnum %d\n", seb->lnum); 165 + printk(KERN_DEBUG "\tscrub %d\n", seb->scrub); 166 + printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum); 175 167 } 176 168 } 177 169 ··· 182 176 { 183 177 char nm[17]; 184 178 185 - dbg_msg("volume creation request dump:"); 186 - dbg_msg("vol_id %d", req->vol_id); 187 - dbg_msg("alignment %d", req->alignment); 188 - dbg_msg("bytes %lld", (long long)req->bytes); 189 - dbg_msg("vol_type %d", req->vol_type); 190 - dbg_msg("name_len %d", req->name_len); 179 + printk(KERN_DEBUG "Volume creation request dump:\n"); 180 + printk(KERN_DEBUG "\tvol_id %d\n", req->vol_id); 181 + printk(KERN_DEBUG "\talignment %d\n", req->alignment); 182 + printk(KERN_DEBUG "\tbytes %lld\n", (long long)req->bytes); 183 + printk(KERN_DEBUG "\tvol_type %d\n", req->vol_type); 184 + printk(KERN_DEBUG "\tname_len %d\n", req->name_len); 191 185 192 186 memcpy(nm, req->name, 16); 193 187 nm[16] = 0; 194 - dbg_msg("the 1st 16 characters of the name: %s", nm); 188 + printk(KERN_DEBUG "\t1st 16 characters of name: %s\n", nm); 195 189 } 196 190 197 - #endif /* CONFIG_MTD_UBI_DEBUG_MSG */ 191 + #endif /* CONFIG_MTD_UBI_DEBUG */
+47 -27
drivers/mtd/ubi/debug.h
··· 24 24 #ifdef CONFIG_MTD_UBI_DEBUG 25 25 #include <linux/random.h> 26 26 27 - #define ubi_assert(expr) BUG_ON(!(expr)) 28 27 #define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__) 29 - #else 30 - #define ubi_assert(expr) ({}) 31 - #define dbg_err(fmt, ...) ({}) 32 - #endif 33 28 34 - #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT 35 - #define DBG_DISABLE_BGT 1 36 - #else 37 - #define DBG_DISABLE_BGT 0 38 - #endif 29 + #define ubi_assert(expr) do { \ 30 + if (unlikely(!(expr))) { \ 31 + printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \ 32 + __func__, __LINE__, current->pid); \ 33 + ubi_dbg_dump_stack(); \ 34 + } \ 35 + } while (0) 39 36 40 - #ifdef CONFIG_MTD_UBI_DEBUG_MSG 41 - /* Generic debugging message */ 42 37 #define dbg_msg(fmt, ...) \ 43 38 printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \ 44 39 current->pid, __func__, ##__VA_ARGS__) ··· 56 61 void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); 57 62 void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); 58 63 64 + #ifdef CONFIG_MTD_UBI_DEBUG_MSG 65 + /* General debugging messages */ 66 + #define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) 59 67 #else 60 - 61 - #define dbg_msg(fmt, ...) ({}) 62 - #define ubi_dbg_dump_stack() ({}) 63 - #define ubi_dbg_dump_ec_hdr(ec_hdr) ({}) 64 - #define ubi_dbg_dump_vid_hdr(vid_hdr) ({}) 65 - #define ubi_dbg_dump_vol_info(vol) ({}) 66 - #define ubi_dbg_dump_vtbl_record(r, idx) ({}) 67 - #define ubi_dbg_dump_sv(sv) ({}) 68 - #define ubi_dbg_dump_seb(seb, type) ({}) 69 - #define ubi_dbg_dump_mkvol_req(req) ({}) 70 - 71 - #endif /* CONFIG_MTD_UBI_DEBUG_MSG */ 68 + #define dbg_gen(fmt, ...) ({}) 69 + #endif 72 70 73 71 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA 74 - /* Messages from the eraseblock association unit */ 72 + /* Messages from the eraseblock association sub-system */ 75 73 #define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) 76 74 #else 77 75 #define dbg_eba(fmt, ...) ({}) 78 76 #endif 79 77 80 78 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL 81 - /* Messages from the wear-leveling unit */ 79 + /* Messages from the wear-leveling sub-system */ 82 80 #define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) 83 81 #else 84 82 #define dbg_wl(fmt, ...) ({}) 85 83 #endif 86 84 87 85 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO 88 - /* Messages from the input/output unit */ 86 + /* Messages from the input/output sub-system */ 89 87 #define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) 90 88 #else 91 89 #define dbg_io(fmt, ...) ({}) ··· 91 103 #else 92 104 #define dbg_bld(fmt, ...) ({}) 93 105 #define UBI_IO_DEBUG 0 106 + #endif 107 + 108 + #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT 109 + #define DBG_DISABLE_BGT 1 110 + #else 111 + #define DBG_DISABLE_BGT 0 94 112 #endif 95 113 96 114 #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS ··· 143 149 #define ubi_dbg_is_erase_failure() 0 144 150 #endif 145 151 152 + #else 153 + 154 + #define ubi_assert(expr) ({}) 155 + #define dbg_err(fmt, ...) ({}) 156 + #define dbg_msg(fmt, ...) ({}) 157 + #define dbg_gen(fmt, ...) ({}) 158 + #define dbg_eba(fmt, ...) ({}) 159 + #define dbg_wl(fmt, ...) ({}) 160 + #define dbg_io(fmt, ...) ({}) 161 + #define dbg_bld(fmt, ...) ({}) 162 + #define ubi_dbg_dump_stack() ({}) 163 + #define ubi_dbg_dump_ec_hdr(ec_hdr) ({}) 164 + #define ubi_dbg_dump_vid_hdr(vid_hdr) ({}) 165 + #define ubi_dbg_dump_vol_info(vol) ({}) 166 + #define ubi_dbg_dump_vtbl_record(r, idx) ({}) 167 + #define ubi_dbg_dump_sv(sv) ({}) 168 + #define ubi_dbg_dump_seb(seb, type) ({}) 169 + #define ubi_dbg_dump_mkvol_req(req) ({}) 170 + 171 + #define UBI_IO_DEBUG 0 172 + #define DBG_DISABLE_BGT 0 173 + #define ubi_dbg_is_bitflip() 0 174 + #define ubi_dbg_is_write_failure() 0 175 + #define ubi_dbg_is_erase_failure() 0 176 + 177 + #endif /* !CONFIG_MTD_UBI_DEBUG */ 146 178 #endif /* !__UBI_DEBUG_H__ */
+22 -55
drivers/mtd/ubi/eba.c
··· 19 19 */ 20 20 21 21 /* 22 - * The UBI Eraseblock Association (EBA) unit. 22 + * The UBI Eraseblock Association (EBA) sub-system. 23 23 * 24 - * This unit is responsible for I/O to/from logical eraseblock. 24 + * This sub-system is responsible for I/O to/from logical eraseblock. 25 25 * 26 26 * Although in this implementation the EBA table is fully kept and managed in 27 27 * RAM, which assumes poor scalability, it might be (partially) maintained on 28 28 * flash in future implementations. 29 29 * 30 - * The EBA unit implements per-logical eraseblock locking. Before accessing a 31 - * logical eraseblock it is locked for reading or writing. The per-logical 32 - * eraseblock locking is implemented by means of the lock tree. The lock tree 33 - * is an RB-tree which refers all the currently locked logical eraseblocks. The 34 - * lock tree elements are &struct ubi_ltree_entry objects. They are indexed by 35 - * (@vol_id, @lnum) pairs. 30 + * The EBA sub-system implements per-logical eraseblock locking. Before 31 + * accessing a logical eraseblock it is locked for reading or writing. The 32 + * per-logical eraseblock locking is implemented by means of the lock tree. The 33 + * lock tree is an RB-tree which refers all the currently locked logical 34 + * eraseblocks. The lock tree elements are &struct ubi_ltree_entry objects. 35 + * They are indexed by (@vol_id, @lnum) pairs. 36 36 * 37 37 * EBA also maintains the global sequence counter which is incremented each 38 38 * time a logical eraseblock is mapped to a physical eraseblock and it is ··· 189 189 le->users += 1; 190 190 spin_unlock(&ubi->ltree_lock); 191 191 192 - if (le_free) 193 - kfree(le_free); 194 - 192 + kfree(le_free); 195 193 return le; 196 194 } 197 195 ··· 221 223 */ 222 224 static void leb_read_unlock(struct ubi_device *ubi, int vol_id, int lnum) 223 225 { 224 - int free = 0; 225 226 struct ubi_ltree_entry *le; 226 227 227 228 spin_lock(&ubi->ltree_lock); 228 229 le = ltree_lookup(ubi, vol_id, lnum); 229 230 le->users -= 1; 230 231 ubi_assert(le->users >= 0); 232 + up_read(&le->mutex); 231 233 if (le->users == 0) { 232 234 rb_erase(&le->rb, &ubi->ltree); 233 - free = 1; 235 + kfree(le); 234 236 } 235 237 spin_unlock(&ubi->ltree_lock); 236 - 237 - up_read(&le->mutex); 238 - if (free) 239 - kfree(le); 240 238 } 241 239 242 240 /** ··· 268 274 */ 269 275 static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum) 270 276 { 271 - int free; 272 277 struct ubi_ltree_entry *le; 273 278 274 279 le = ltree_add_entry(ubi, vol_id, lnum); ··· 282 289 ubi_assert(le->users >= 0); 283 290 if (le->users == 0) { 284 291 rb_erase(&le->rb, &ubi->ltree); 285 - free = 1; 286 - } else 287 - free = 0; 288 - spin_unlock(&ubi->ltree_lock); 289 - if (free) 290 292 kfree(le); 293 + } 294 + spin_unlock(&ubi->ltree_lock); 291 295 292 296 return 1; 293 297 } ··· 297 307 */ 298 308 static void leb_write_unlock(struct ubi_device *ubi, int vol_id, int lnum) 299 309 { 300 - int free; 301 310 struct ubi_ltree_entry *le; 302 311 303 312 spin_lock(&ubi->ltree_lock); 304 313 le = ltree_lookup(ubi, vol_id, lnum); 305 314 le->users -= 1; 306 315 ubi_assert(le->users >= 0); 316 + up_write(&le->mutex); 307 317 if (le->users == 0) { 308 318 rb_erase(&le->rb, &ubi->ltree); 309 - free = 1; 310 - } else 311 - free = 0; 312 - spin_unlock(&ubi->ltree_lock); 313 - 314 - up_write(&le->mutex); 315 - if (free) 316 319 kfree(le); 320 + } 321 + spin_unlock(&ubi->ltree_lock); 317 322 } 318 323 319 324 /** ··· 501 516 struct ubi_vid_hdr *vid_hdr; 502 517 503 518 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); 504 - if (!vid_hdr) { 519 + if (!vid_hdr) 505 520 return -ENOMEM; 506 - } 507 521 508 522 mutex_lock(&ubi->buf_mutex); 509 523 ··· 736 752 /* If this is the last LEB @len may be unaligned */ 737 753 len = ALIGN(data_size, ubi->min_io_size); 738 754 else 739 - ubi_assert(len % ubi->min_io_size == 0); 755 + ubi_assert(!(len & (ubi->min_io_size - 1))); 740 756 741 757 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); 742 758 if (!vid_hdr) ··· 903 919 } 904 920 905 921 if (vol->eba_tbl[lnum] >= 0) { 906 - err = ubi_wl_put_peb(ubi, vol->eba_tbl[lnum], 1); 922 + err = ubi_wl_put_peb(ubi, vol->eba_tbl[lnum], 0); 907 923 if (err) 908 924 goto out_leb_unlock; 909 925 } ··· 1125 1141 } 1126 1142 1127 1143 /** 1128 - * ubi_eba_init_scan - initialize the EBA unit using scanning information. 1144 + * ubi_eba_init_scan - initialize the EBA sub-system using scanning information. 1129 1145 * @ubi: UBI device description object 1130 1146 * @si: scanning information 1131 1147 * ··· 1140 1156 struct ubi_scan_leb *seb; 1141 1157 struct rb_node *rb; 1142 1158 1143 - dbg_eba("initialize EBA unit"); 1159 + dbg_eba("initialize EBA sub-system"); 1144 1160 1145 1161 spin_lock_init(&ubi->ltree_lock); 1146 1162 mutex_init(&ubi->alc_mutex); ··· 1206 1222 ubi->rsvd_pebs += ubi->beb_rsvd_pebs; 1207 1223 } 1208 1224 1209 - dbg_eba("EBA unit is initialized"); 1225 + dbg_eba("EBA sub-system is initialized"); 1210 1226 return 0; 1211 1227 1212 1228 out_free: ··· 1216 1232 kfree(ubi->volumes[i]->eba_tbl); 1217 1233 } 1218 1234 return err; 1219 - } 1220 - 1221 - /** 1222 - * ubi_eba_close - close EBA unit. 1223 - * @ubi: UBI device description object 1224 - */ 1225 - void ubi_eba_close(const struct ubi_device *ubi) 1226 - { 1227 - int i, num_volumes = ubi->vtbl_slots + UBI_INT_VOL_COUNT; 1228 - 1229 - dbg_eba("close EBA unit"); 1230 - 1231 - for (i = 0; i < num_volumes; i++) { 1232 - if (!ubi->volumes[i]) 1233 - continue; 1234 - kfree(ubi->volumes[i]->eba_tbl); 1235 - } 1236 1235 }
+8 -8
drivers/mtd/ubi/gluebi.c
··· 111 111 struct ubi_device *ubi; 112 112 uint64_t tmp = from; 113 113 114 - dbg_msg("read %zd bytes from offset %lld", len, from); 114 + dbg_gen("read %zd bytes from offset %lld", len, from); 115 115 116 116 if (len < 0 || from < 0 || from + len > mtd->size) 117 117 return -EINVAL; ··· 162 162 struct ubi_device *ubi; 163 163 uint64_t tmp = to; 164 164 165 - dbg_msg("write %zd bytes to offset %lld", len, to); 165 + dbg_gen("write %zd bytes to offset %lld", len, to); 166 166 167 167 if (len < 0 || to < 0 || len + to > mtd->size) 168 168 return -EINVAL; ··· 215 215 struct ubi_volume *vol; 216 216 struct ubi_device *ubi; 217 217 218 - dbg_msg("erase %u bytes at offset %u", instr->len, instr->addr); 218 + dbg_gen("erase %u bytes at offset %u", instr->len, instr->addr); 219 219 220 220 if (instr->addr < 0 || instr->addr > mtd->size - mtd->erasesize) 221 221 return -EINVAL; ··· 249 249 if (err) 250 250 goto out_err; 251 251 252 - instr->state = MTD_ERASE_DONE; 253 - mtd_erase_callback(instr); 252 + instr->state = MTD_ERASE_DONE; 253 + mtd_erase_callback(instr); 254 254 return 0; 255 255 256 256 out_err: ··· 299 299 mtd->size = vol->used_bytes; 300 300 301 301 if (add_mtd_device(mtd)) { 302 - ubi_err("cannot not add MTD device\n"); 302 + ubi_err("cannot not add MTD device"); 303 303 kfree(mtd->name); 304 304 return -ENFILE; 305 305 } 306 306 307 - dbg_msg("added mtd%d (\"%s\"), size %u, EB size %u", 307 + dbg_gen("added mtd%d (\"%s\"), size %u, EB size %u", 308 308 mtd->index, mtd->name, mtd->size, mtd->erasesize); 309 309 return 0; 310 310 } ··· 322 322 int err; 323 323 struct mtd_info *mtd = &vol->gluebi_mtd; 324 324 325 - dbg_msg("remove mtd%d", mtd->index); 325 + dbg_gen("remove mtd%d", mtd->index); 326 326 err = del_mtd_device(mtd); 327 327 if (err) 328 328 return err;
+26 -22
drivers/mtd/ubi/io.c
··· 20 20 */ 21 21 22 22 /* 23 - * UBI input/output unit. 23 + * UBI input/output sub-system. 24 24 * 25 - * This unit provides a uniform way to work with all kinds of the underlying 26 - * MTD devices. It also implements handy functions for reading and writing UBI 27 - * headers. 25 + * This sub-system provides a uniform way to work with all kinds of the 26 + * underlying MTD devices. It also implements handy functions for reading and 27 + * writing UBI headers. 28 28 * 29 29 * We are trying to have a paranoid mindset and not to trust to what we read 30 - * from the flash media in order to be more secure and robust. So this unit 31 - * validates every single header it reads from the flash media. 30 + * from the flash media in order to be more secure and robust. So this 31 + * sub-system validates every single header it reads from the flash media. 32 32 * 33 33 * Some words about how the eraseblock headers are stored. 34 34 * ··· 79 79 * 512-byte chunks, we have to allocate one more buffer and copy our VID header 80 80 * to offset 448 of this buffer. 81 81 * 82 - * The I/O unit does the following trick in order to avoid this extra copy. 83 - * It always allocates a @ubi->vid_hdr_alsize bytes buffer for the VID header 84 - * and returns a pointer to offset @ubi->vid_hdr_shift of this buffer. When the 85 - * VID header is being written out, it shifts the VID header pointer back and 86 - * writes the whole sub-page. 82 + * The I/O sub-system does the following trick in order to avoid this extra 83 + * copy. It always allocates a @ubi->vid_hdr_alsize bytes buffer for the VID 84 + * header and returns a pointer to offset @ubi->vid_hdr_shift of this buffer. 85 + * When the VID header is being written out, it shifts the VID header pointer 86 + * back and writes the whole sub-page. 87 87 */ 88 88 89 89 #include <linux/crc32.h> ··· 156 156 /* 157 157 * -EUCLEAN is reported if there was a bit-flip which 158 158 * was corrected, so this is harmless. 159 + * 160 + * We do not report about it here unless debugging is 161 + * enabled. A corresponding message will be printed 162 + * later, when it is has been scrubbed. 159 163 */ 160 - ubi_msg("fixable bit-flip detected at PEB %d", pnum); 164 + dbg_msg("fixable bit-flip detected at PEB %d", pnum); 161 165 ubi_assert(len == read); 162 166 return UBI_IO_BITFLIPS; 163 167 } 164 168 165 169 if (read != len && retries++ < UBI_IO_RETRIES) { 166 - dbg_io("error %d while reading %d bytes from PEB %d:%d, " 167 - "read only %zd bytes, retry", 170 + dbg_io("error %d while reading %d bytes from PEB %d:%d," 171 + " read only %zd bytes, retry", 168 172 err, len, pnum, offset, read); 169 173 yield(); 170 174 goto retry; ··· 191 187 ubi_assert(len == read); 192 188 193 189 if (ubi_dbg_is_bitflip()) { 194 - dbg_msg("bit-flip (emulated)"); 190 + dbg_gen("bit-flip (emulated)"); 195 191 err = UBI_IO_BITFLIPS; 196 192 } 197 193 } ··· 395 391 { 396 392 int err, i, patt_count; 397 393 394 + ubi_msg("run torture test for PEB %d", pnum); 398 395 patt_count = ARRAY_SIZE(patterns); 399 396 ubi_assert(patt_count > 0); 400 397 ··· 439 434 } 440 435 441 436 err = patt_count; 437 + ubi_msg("PEB %d passed torture test, do not mark it a bad", pnum); 442 438 443 439 out: 444 440 mutex_unlock(&ubi->buf_mutex); ··· 705 699 706 700 if (hdr_crc != crc) { 707 701 if (verbose) { 708 - ubi_warn("bad EC header CRC at PEB %d, calculated %#08x," 709 - " read %#08x", pnum, crc, hdr_crc); 702 + ubi_warn("bad EC header CRC at PEB %d, calculated " 703 + "%#08x, read %#08x", pnum, crc, hdr_crc); 710 704 ubi_dbg_dump_ec_hdr(ec_hdr); 711 705 } 712 706 return UBI_IO_BAD_EC_HDR; ··· 1101 1095 } 1102 1096 1103 1097 /** 1104 - * paranoid_check_peb_ec_hdr - check that the erase counter header of a 1105 - * physical eraseblock is in-place and is all right. 1098 + * paranoid_check_peb_ec_hdr - check erase counter header. 1106 1099 * @ubi: UBI device description object 1107 1100 * @pnum: the physical eraseblock number to check 1108 1101 * ··· 1179 1174 } 1180 1175 1181 1176 /** 1182 - * paranoid_check_peb_vid_hdr - check that the volume identifier header of a 1183 - * physical eraseblock is in-place and is all right. 1177 + * paranoid_check_peb_vid_hdr - check volume identifier header. 1184 1178 * @ubi: UBI device description object 1185 1179 * @pnum: the physical eraseblock number to check 1186 1180 * ··· 1260 1256 1261 1257 fail: 1262 1258 ubi_err("paranoid check failed for PEB %d", pnum); 1263 - dbg_msg("hex dump of the %d-%d region", offset, offset + len); 1259 + ubi_msg("hex dump of the %d-%d region", offset, offset + len); 1264 1260 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1265 1261 ubi->dbg_peb_buf, len, 1); 1266 1262 err = 1;
+37 -13
drivers/mtd/ubi/kapi.c
··· 106 106 struct ubi_device *ubi; 107 107 struct ubi_volume *vol; 108 108 109 - dbg_msg("open device %d volume %d, mode %d", ubi_num, vol_id, mode); 109 + dbg_gen("open device %d volume %d, mode %d", ubi_num, vol_id, mode); 110 110 111 111 if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES) 112 112 return ERR_PTR(-EINVAL); ··· 215 215 struct ubi_device *ubi; 216 216 struct ubi_volume_desc *ret; 217 217 218 - dbg_msg("open volume %s, mode %d", name, mode); 218 + dbg_gen("open volume %s, mode %d", name, mode); 219 219 220 220 if (!name) 221 221 return ERR_PTR(-EINVAL); ··· 266 266 struct ubi_volume *vol = desc->vol; 267 267 struct ubi_device *ubi = vol->ubi; 268 268 269 - dbg_msg("close volume %d, mode %d", vol->vol_id, desc->mode); 269 + dbg_gen("close volume %d, mode %d", vol->vol_id, desc->mode); 270 270 271 271 spin_lock(&ubi->volumes_lock); 272 272 switch (desc->mode) { ··· 323 323 struct ubi_device *ubi = vol->ubi; 324 324 int err, vol_id = vol->vol_id; 325 325 326 - dbg_msg("read %d bytes from LEB %d:%d:%d", len, vol_id, lnum, offset); 326 + dbg_gen("read %d bytes from LEB %d:%d:%d", len, vol_id, lnum, offset); 327 327 328 328 if (vol_id < 0 || vol_id >= ubi->vtbl_slots || lnum < 0 || 329 329 lnum >= vol->used_ebs || offset < 0 || len < 0 || ··· 388 388 struct ubi_device *ubi = vol->ubi; 389 389 int vol_id = vol->vol_id; 390 390 391 - dbg_msg("write %d bytes to LEB %d:%d:%d", len, vol_id, lnum, offset); 391 + dbg_gen("write %d bytes to LEB %d:%d:%d", len, vol_id, lnum, offset); 392 392 393 393 if (vol_id < 0 || vol_id >= ubi->vtbl_slots) 394 394 return -EINVAL; ··· 397 397 return -EROFS; 398 398 399 399 if (lnum < 0 || lnum >= vol->reserved_pebs || offset < 0 || len < 0 || 400 - offset + len > vol->usable_leb_size || offset % ubi->min_io_size || 401 - len % ubi->min_io_size) 400 + offset + len > vol->usable_leb_size || 401 + offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1)) 402 402 return -EINVAL; 403 403 404 404 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM && ··· 438 438 struct ubi_device *ubi = vol->ubi; 439 439 int vol_id = vol->vol_id; 440 440 441 - dbg_msg("atomically write %d bytes to LEB %d:%d", len, vol_id, lnum); 441 + dbg_gen("atomically write %d bytes to LEB %d:%d", len, vol_id, lnum); 442 442 443 443 if (vol_id < 0 || vol_id >= ubi->vtbl_slots) 444 444 return -EINVAL; ··· 447 447 return -EROFS; 448 448 449 449 if (lnum < 0 || lnum >= vol->reserved_pebs || len < 0 || 450 - len > vol->usable_leb_size || len % ubi->min_io_size) 450 + len > vol->usable_leb_size || len & (ubi->min_io_size - 1)) 451 451 return -EINVAL; 452 452 453 453 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM && ··· 482 482 struct ubi_device *ubi = vol->ubi; 483 483 int err; 484 484 485 - dbg_msg("erase LEB %d:%d", vol->vol_id, lnum); 485 + dbg_gen("erase LEB %d:%d", vol->vol_id, lnum); 486 486 487 487 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) 488 488 return -EROFS; ··· 542 542 struct ubi_volume *vol = desc->vol; 543 543 struct ubi_device *ubi = vol->ubi; 544 544 545 - dbg_msg("unmap LEB %d:%d", vol->vol_id, lnum); 545 + dbg_gen("unmap LEB %d:%d", vol->vol_id, lnum); 546 546 547 547 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) 548 548 return -EROFS; ··· 579 579 struct ubi_volume *vol = desc->vol; 580 580 struct ubi_device *ubi = vol->ubi; 581 581 582 - dbg_msg("unmap LEB %d:%d", vol->vol_id, lnum); 582 + dbg_gen("unmap LEB %d:%d", vol->vol_id, lnum); 583 583 584 584 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) 585 585 return -EROFS; ··· 621 621 { 622 622 struct ubi_volume *vol = desc->vol; 623 623 624 - dbg_msg("test LEB %d:%d", vol->vol_id, lnum); 624 + dbg_gen("test LEB %d:%d", vol->vol_id, lnum); 625 625 626 626 if (lnum < 0 || lnum >= vol->reserved_pebs) 627 627 return -EINVAL; ··· 632 632 return vol->eba_tbl[lnum] >= 0; 633 633 } 634 634 EXPORT_SYMBOL_GPL(ubi_is_mapped); 635 + 636 + /** 637 + * ubi_sync - synchronize UBI device buffers. 638 + * @ubi_num: UBI device to synchronize 639 + * 640 + * The underlying MTD device may cache data in hardware or in software. This 641 + * function ensures the caches are flushed. Returns zero in case of success and 642 + * a negative error code in case of failure. 643 + */ 644 + int ubi_sync(int ubi_num) 645 + { 646 + struct ubi_device *ubi; 647 + 648 + ubi = ubi_get_device(ubi_num); 649 + if (!ubi) 650 + return -ENODEV; 651 + 652 + if (ubi->mtd->sync) 653 + ubi->mtd->sync(ubi->mtd); 654 + 655 + ubi_put_device(ubi); 656 + return 0; 657 + } 658 + EXPORT_SYMBOL_GPL(ubi_sync);
+1 -1
drivers/mtd/ubi/misc.c
··· 37 37 { 38 38 int i; 39 39 40 - ubi_assert(length % ubi->min_io_size == 0); 40 + ubi_assert(!(length & (ubi->min_io_size - 1))); 41 41 42 42 for (i = length - 1; i >= 0; i--) 43 43 if (((const uint8_t *)buf)[i] != 0xFF)
+47 -89
drivers/mtd/ubi/scan.c
··· 19 19 */ 20 20 21 21 /* 22 - * UBI scanning unit. 22 + * UBI scanning sub-system. 23 23 * 24 - * This unit is responsible for scanning the flash media, checking UBI 24 + * This sub-system is responsible for scanning the flash media, checking UBI 25 25 * headers and providing complete information about the UBI flash image. 26 26 * 27 27 * The scanning information is represented by a &struct ubi_scan_info' object. ··· 93 93 } 94 94 95 95 /** 96 - * validate_vid_hdr - check that volume identifier header is correct and 97 - * consistent. 96 + * validate_vid_hdr - check volume identifier header. 98 97 * @vid_hdr: the volume identifier header to check 99 98 * @sv: information about the volume this logical eraseblock belongs to 100 99 * @pnum: physical eraseblock number the VID header came from ··· 102 103 * non-zero if an inconsistency was found and zero if not. 103 104 * 104 105 * Note, UBI does sanity check of everything it reads from the flash media. 105 - * Most of the checks are done in the I/O unit. Here we check that the 106 + * Most of the checks are done in the I/O sub-system. Here we check that the 106 107 * information in the VID header is consistent to the information in other VID 107 108 * headers of the same volume. 108 109 */ ··· 246 247 struct ubi_vid_hdr *vh = NULL; 247 248 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); 248 249 249 - if (seb->sqnum == 0 && sqnum2 == 0) { 250 - long long abs, v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver); 251 - 250 + if (sqnum2 == seb->sqnum) { 252 251 /* 253 - * UBI constantly increases the logical eraseblock version 254 - * number and it can overflow. Thus, we have to bear in mind 255 - * that versions that are close to %0xFFFFFFFF are less then 256 - * versions that are close to %0. 257 - * 258 - * The UBI WL unit guarantees that the number of pending tasks 259 - * is not greater then %0x7FFFFFFF. So, if the difference 260 - * between any two versions is greater or equivalent to 261 - * %0x7FFFFFFF, there was an overflow and the logical 262 - * eraseblock with lower version is actually newer then the one 263 - * with higher version. 264 - * 265 - * FIXME: but this is anyway obsolete and will be removed at 266 - * some point. 252 + * This must be a really ancient UBI image which has been 253 + * created before sequence numbers support has been added. At 254 + * that times we used 32-bit LEB versions stored in logical 255 + * eraseblocks. That was before UBI got into mainline. We do not 256 + * support these images anymore. Well, those images will work 257 + * still work, but only if no unclean reboots happened. 267 258 */ 268 - dbg_bld("using old crappy leb_ver stuff"); 259 + ubi_err("unsupported on-flash UBI format\n"); 260 + return -EINVAL; 261 + } 269 262 270 - if (v1 == v2) { 271 - ubi_err("PEB %d and PEB %d have the same version %lld", 272 - seb->pnum, pnum, v1); 273 - return -EINVAL; 274 - } 275 - 276 - abs = v1 - v2; 277 - if (abs < 0) 278 - abs = -abs; 279 - 280 - if (abs < 0x7FFFFFFF) 281 - /* Non-overflow situation */ 282 - second_is_newer = (v2 > v1); 283 - else 284 - second_is_newer = (v2 < v1); 285 - } else 286 - /* Obviously the LEB with lower sequence counter is older */ 287 - second_is_newer = sqnum2 > seb->sqnum; 263 + /* Obviously the LEB with lower sequence counter is older */ 264 + second_is_newer = !!(sqnum2 > seb->sqnum); 288 265 289 266 /* 290 267 * Now we know which copy is newer. If the copy flag of the PEB with ··· 268 293 * check data CRC. For the second PEB we already have the VID header, 269 294 * for the first one - we'll need to re-read it from flash. 270 295 * 271 - * FIXME: this may be optimized so that we wouldn't read twice. 296 + * Note: this may be optimized so that we wouldn't read twice. 272 297 */ 273 298 274 299 if (second_is_newer) { ··· 354 379 } 355 380 356 381 /** 357 - * ubi_scan_add_used - add information about a physical eraseblock to the 358 - * scanning information. 382 + * ubi_scan_add_used - add physical eraseblock to the scanning information. 359 383 * @ubi: UBI device description object 360 384 * @si: scanning information 361 385 * @pnum: the physical eraseblock number ··· 374 400 int bitflips) 375 401 { 376 402 int err, vol_id, lnum; 377 - uint32_t leb_ver; 378 403 unsigned long long sqnum; 379 404 struct ubi_scan_volume *sv; 380 405 struct ubi_scan_leb *seb; ··· 382 409 vol_id = be32_to_cpu(vid_hdr->vol_id); 383 410 lnum = be32_to_cpu(vid_hdr->lnum); 384 411 sqnum = be64_to_cpu(vid_hdr->sqnum); 385 - leb_ver = be32_to_cpu(vid_hdr->leb_ver); 386 412 387 - dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, ver %u, bitflips %d", 388 - pnum, vol_id, lnum, ec, sqnum, leb_ver, bitflips); 413 + dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, bitflips %d", 414 + pnum, vol_id, lnum, ec, sqnum, bitflips); 389 415 390 416 sv = add_volume(si, vol_id, pnum, vid_hdr); 391 417 if (IS_ERR(sv) < 0) ··· 417 445 */ 418 446 419 447 dbg_bld("this LEB already exists: PEB %d, sqnum %llu, " 420 - "LEB ver %u, EC %d", seb->pnum, seb->sqnum, 421 - seb->leb_ver, seb->ec); 422 - 423 - /* 424 - * Make sure that the logical eraseblocks have different 425 - * versions. Otherwise the image is bad. 426 - */ 427 - if (seb->leb_ver == leb_ver && leb_ver != 0) { 428 - ubi_err("two LEBs with same version %u", leb_ver); 429 - ubi_dbg_dump_seb(seb, 0); 430 - ubi_dbg_dump_vid_hdr(vid_hdr); 431 - return -EINVAL; 432 - } 448 + "EC %d", seb->pnum, seb->sqnum, seb->ec); 433 449 434 450 /* 435 451 * Make sure that the logical eraseblocks have different 436 452 * sequence numbers. Otherwise the image is bad. 437 453 * 438 - * FIXME: remove 'sqnum != 0' check when leb_ver is removed. 454 + * However, if the sequence number is zero, we assume it must 455 + * be an ancient UBI image from the era when UBI did not have 456 + * sequence numbers. We still can attach these images, unless 457 + * there is a need to distinguish between old and new 458 + * eraseblocks, in which case we'll refuse the image in 459 + * 'compare_lebs()'. In other words, we attach old clean 460 + * images, but refuse attaching old images with duplicated 461 + * logical eraseblocks because there was an unclean reboot. 439 462 */ 440 463 if (seb->sqnum == sqnum && sqnum != 0) { 441 464 ubi_err("two LEBs with same sequence number %llu", ··· 470 503 seb->pnum = pnum; 471 504 seb->scrub = ((cmp_res & 2) || bitflips); 472 505 seb->sqnum = sqnum; 473 - seb->leb_ver = leb_ver; 474 506 475 507 if (sv->highest_lnum == lnum) 476 508 sv->last_data_size = ··· 506 540 seb->lnum = lnum; 507 541 seb->sqnum = sqnum; 508 542 seb->scrub = bitflips; 509 - seb->leb_ver = leb_ver; 510 543 511 544 if (sv->highest_lnum <= lnum) { 512 545 sv->highest_lnum = lnum; ··· 519 554 } 520 555 521 556 /** 522 - * ubi_scan_find_sv - find information about a particular volume in the 523 - * scanning information. 557 + * ubi_scan_find_sv - find volume in the scanning information. 524 558 * @si: scanning information 525 559 * @vol_id: the requested volume ID 526 560 * ··· 548 584 } 549 585 550 586 /** 551 - * ubi_scan_find_seb - find information about a particular logical 552 - * eraseblock in the volume scanning information. 587 + * ubi_scan_find_seb - find LEB in the volume scanning information. 553 588 * @sv: a pointer to the volume scanning information 554 589 * @lnum: the requested logical eraseblock 555 590 * ··· 608 645 * 609 646 * This function erases physical eraseblock 'pnum', and writes the erase 610 647 * counter header to it. This function should only be used on UBI device 611 - * initialization stages, when the EBA unit had not been yet initialized. This 612 - * function returns zero in case of success and a negative error code in case 613 - * of failure. 648 + * initialization stages, when the EBA sub-system had not been yet initialized. 649 + * This function returns zero in case of success and a negative error code in 650 + * case of failure. 614 651 */ 615 652 int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si, 616 653 int pnum, int ec) ··· 650 687 * @si: scanning information 651 688 * 652 689 * This function returns a free physical eraseblock. It is supposed to be 653 - * called on the UBI initialization stages when the wear-leveling unit is not 654 - * initialized yet. This function picks a physical eraseblocks from one of the 655 - * lists, writes the EC header if it is needed, and removes it from the list. 690 + * called on the UBI initialization stages when the wear-leveling sub-system is 691 + * not initialized yet. This function picks a physical eraseblocks from one of 692 + * the lists, writes the EC header if it is needed, and removes it from the 693 + * list. 656 694 * 657 695 * This function returns scanning physical eraseblock information in case of 658 696 * success and an error code in case of failure. ··· 706 742 } 707 743 708 744 /** 709 - * process_eb - read UBI headers, check them and add corresponding data 710 - * to the scanning information. 745 + * process_eb - read, check UBI headers, and add them to scanning information. 711 746 * @ubi: UBI device description object 712 747 * @si: scanning information 713 748 * @pnum: the physical eraseblock number ··· 714 751 * This function returns a zero if the physical eraseblock was successfully 715 752 * handled and a negative error code in case of failure. 716 753 */ 717 - static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum) 754 + static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, 755 + int pnum) 718 756 { 719 757 long long uninitialized_var(ec); 720 758 int err, bitflips = 0, vol_id, ec_corr = 0; ··· 728 764 return err; 729 765 else if (err) { 730 766 /* 731 - * FIXME: this is actually duty of the I/O unit to initialize 732 - * this, but MTD does not provide enough information. 767 + * FIXME: this is actually duty of the I/O sub-system to 768 + * initialize this, but MTD does not provide enough 769 + * information. 733 770 */ 734 771 si->bad_peb_count += 1; 735 772 return 0; ··· 895 930 for (pnum = 0; pnum < ubi->peb_count; pnum++) { 896 931 cond_resched(); 897 932 898 - dbg_msg("process PEB %d", pnum); 933 + dbg_gen("process PEB %d", pnum); 899 934 err = process_eb(ubi, si, pnum); 900 935 if (err < 0) 901 936 goto out_vidh; ··· 1044 1079 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 1045 1080 1046 1081 /** 1047 - * paranoid_check_si - check if the scanning information is correct and 1048 - * consistent. 1082 + * paranoid_check_si - check the scanning information. 1049 1083 * @ubi: UBI device description object 1050 1084 * @si: scanning information 1051 1085 * ··· 1229 1265 ubi_err("bad data_pad %d", sv->data_pad); 1230 1266 goto bad_vid_hdr; 1231 1267 } 1232 - 1233 - if (seb->leb_ver != be32_to_cpu(vidh->leb_ver)) { 1234 - ubi_err("bad leb_ver %u", seb->leb_ver); 1235 - goto bad_vid_hdr; 1236 - } 1237 1268 } 1238 1269 1239 1270 if (!last_seb) ··· 1258 1299 if (err < 0) { 1259 1300 kfree(buf); 1260 1301 return err; 1261 - } 1262 - else if (err) 1302 + } else if (err) 1263 1303 buf[pnum] = 1; 1264 1304 } 1265 1305
+9 -12
drivers/mtd/ubi/scan.h
··· 34 34 * @u: unions RB-tree or @list links 35 35 * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects 36 36 * @u.list: link in one of the eraseblock lists 37 - * @leb_ver: logical eraseblock version (obsolete) 38 37 * 39 38 * One object of this type is allocated for each physical eraseblock during 40 39 * scanning. ··· 48 49 struct rb_node rb; 49 50 struct list_head list; 50 51 } u; 51 - uint32_t leb_ver; 52 52 }; 53 53 54 54 /** ··· 57 59 * @leb_count: number of logical eraseblocks in this volume 58 60 * @vol_type: volume type 59 61 * @used_ebs: number of used logical eraseblocks in this volume (only for 60 - * static volumes) 62 + * static volumes) 61 63 * @last_data_size: amount of data in the last logical eraseblock of this 62 - * volume (always equivalent to the usable logical eraseblock size in case of 63 - * dynamic volumes) 64 + * volume (always equivalent to the usable logical eraseblock 65 + * size in case of dynamic volumes) 64 66 * @data_pad: how many bytes at the end of logical eraseblocks of this volume 65 - * are not used (due to volume alignment) 67 + * are not used (due to volume alignment) 66 68 * @compat: compatibility flags of this volume 67 69 * @rb: link in the volume RB-tree 68 70 * @root: root of the RB-tree containing all the eraseblock belonging to this 69 - * volume (&struct ubi_scan_leb objects) 71 + * volume (&struct ubi_scan_leb objects) 70 72 * 71 73 * One object of this type is allocated for each volume during scanning. 72 74 */ ··· 90 92 * @free: list of free physical eraseblocks 91 93 * @erase: list of physical eraseblocks which have to be erased 92 94 * @alien: list of physical eraseblocks which should not be used by UBI (e.g., 95 + * those belonging to "preserve"-compatible internal volumes) 93 96 * @bad_peb_count: count of bad physical eraseblocks 94 - * those belonging to "preserve"-compatible internal volumes) 95 97 * @vols_found: number of volumes found during scanning 96 98 * @highest_vol_id: highest volume ID 97 99 * @alien_peb_count: count of physical eraseblocks in the @alien list ··· 104 106 * @ec_count: a temporary variable used when calculating @mean_ec 105 107 * 106 108 * This data structure contains the result of scanning and may be used by other 107 - * UBI units to build final UBI data structures, further error-recovery and so 108 - * on. 109 + * UBI sub-systems to build final UBI data structures, further error-recovery 110 + * and so on. 109 111 */ 110 112 struct ubi_scan_info { 111 113 struct rb_root volumes; ··· 130 132 struct ubi_vid_hdr; 131 133 132 134 /* 133 - * ubi_scan_move_to_list - move a physical eraseblock from the volume tree to a 134 - * list. 135 + * ubi_scan_move_to_list - move a PEB from the volume tree to a list. 135 136 * 136 137 * @sv: volume scanning information 137 138 * @seb: scanning eraseblock infprmation
+17 -21
drivers/mtd/ubi/ubi-media.h
··· 98 98 * Compatibility constants used by internal volumes. 99 99 * 100 100 * @UBI_COMPAT_DELETE: delete this internal volume before anything is written 101 - * to the flash 101 + * to the flash 102 102 * @UBI_COMPAT_RO: attach this device in read-only mode 103 103 * @UBI_COMPAT_PRESERVE: preserve this internal volume - do not touch its 104 - * physical eraseblocks, don't allow the wear-leveling unit to move them 104 + * physical eraseblocks, don't allow the wear-leveling 105 + * sub-system to move them 105 106 * @UBI_COMPAT_REJECT: reject this UBI image 106 107 */ 107 108 enum { ··· 124 123 * struct ubi_ec_hdr - UBI erase counter header. 125 124 * @magic: erase counter header magic number (%UBI_EC_HDR_MAGIC) 126 125 * @version: version of UBI implementation which is supposed to accept this 127 - * UBI image 126 + * UBI image 128 127 * @padding1: reserved for future, zeroes 129 128 * @ec: the erase counter 130 129 * @vid_hdr_offset: where the VID header starts ··· 160 159 * struct ubi_vid_hdr - on-flash UBI volume identifier header. 161 160 * @magic: volume identifier header magic number (%UBI_VID_HDR_MAGIC) 162 161 * @version: UBI implementation version which is supposed to accept this UBI 163 - * image (%UBI_VERSION) 162 + * image (%UBI_VERSION) 164 163 * @vol_type: volume type (%UBI_VID_DYNAMIC or %UBI_VID_STATIC) 165 164 * @copy_flag: if this logical eraseblock was copied from another physical 166 - * eraseblock (for wear-leveling reasons) 165 + * eraseblock (for wear-leveling reasons) 167 166 * @compat: compatibility of this volume (%0, %UBI_COMPAT_DELETE, 168 - * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT) 167 + * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT) 169 168 * @vol_id: ID of this volume 170 169 * @lnum: logical eraseblock number 171 - * @leb_ver: version of this logical eraseblock (IMPORTANT: obsolete, to be 172 - * removed, kept only for not breaking older UBI users) 170 + * @padding1: reserved for future, zeroes 173 171 * @data_size: how many bytes of data this logical eraseblock contains 174 172 * @used_ebs: total number of used logical eraseblocks in this volume 175 173 * @data_pad: how many bytes at the end of this physical eraseblock are not 176 - * used 174 + * used 177 175 * @data_crc: CRC checksum of the data stored in this logical eraseblock 178 - * @padding1: reserved for future, zeroes 179 - * @sqnum: sequence number 180 176 * @padding2: reserved for future, zeroes 177 + * @sqnum: sequence number 178 + * @padding3: reserved for future, zeroes 181 179 * @hdr_crc: volume identifier header CRC checksum 182 180 * 183 181 * The @sqnum is the value of the global sequence counter at the time when this ··· 224 224 * checksum is correct, this physical eraseblock is selected (P1). Otherwise 225 225 * the older one (P) is selected. 226 226 * 227 - * Note, there is an obsolete @leb_ver field which was used instead of @sqnum 228 - * in the past. But it is not used anymore and we keep it in order to be able 229 - * to deal with old UBI images. It will be removed at some point. 230 - * 231 227 * There are 2 sorts of volumes in UBI: user volumes and internal volumes. 232 228 * Internal volumes are not seen from outside and are used for various internal 233 229 * UBI purposes. In this implementation there is only one internal volume - the ··· 244 248 * The @data_crc field contains the CRC checksum of the contents of the logical 245 249 * eraseblock if this is a static volume. In case of dynamic volumes, it does 246 250 * not contain the CRC checksum as a rule. The only exception is when the 247 - * data of the physical eraseblock was moved by the wear-leveling unit, then 248 - * the wear-leveling unit calculates the data CRC and stores it in the 249 - * @data_crc field. And of course, the @copy_flag is %in this case. 251 + * data of the physical eraseblock was moved by the wear-leveling sub-system, 252 + * then the wear-leveling sub-system calculates the data CRC and stores it in 253 + * the @data_crc field. And of course, the @copy_flag is %in this case. 250 254 * 251 255 * The @data_size field is used only for static volumes because UBI has to know 252 256 * how many bytes of data are stored in this eraseblock. For dynamic volumes, ··· 273 277 __u8 compat; 274 278 __be32 vol_id; 275 279 __be32 lnum; 276 - __be32 leb_ver; /* obsolete, to be removed, don't use */ 280 + __u8 padding1[4]; 277 281 __be32 data_size; 278 282 __be32 used_ebs; 279 283 __be32 data_pad; 280 284 __be32 data_crc; 281 - __u8 padding1[4]; 285 + __u8 padding2[4]; 282 286 __be64 sqnum; 283 - __u8 padding2[12]; 287 + __u8 padding3[12]; 284 288 __be32 hdr_crc; 285 289 } __attribute__ ((packed)); 286 290
+51 -24
drivers/mtd/ubi/ubi.h
··· 74 74 #define UBI_IO_RETRIES 3 75 75 76 76 /* 77 - * Error codes returned by the I/O unit. 77 + * Error codes returned by the I/O sub-system. 78 78 * 79 79 * UBI_IO_PEB_EMPTY: the physical eraseblock is empty, i.e. it contains only 80 - * 0xFF bytes 80 + * %0xFF bytes 81 81 * UBI_IO_PEB_FREE: the physical eraseblock is free, i.e. it contains only a 82 - * valid erase counter header, and the rest are %0xFF bytes 82 + * valid erase counter header, and the rest are %0xFF bytes 83 83 * UBI_IO_BAD_EC_HDR: the erase counter header is corrupted (bad magic or CRC) 84 84 * UBI_IO_BAD_VID_HDR: the volume identifier header is corrupted (bad magic or 85 - * CRC) 85 + * CRC) 86 86 * UBI_IO_BITFLIPS: bit-flips were detected and corrected 87 87 */ 88 88 enum { ··· 99 99 * @ec: erase counter 100 100 * @pnum: physical eraseblock number 101 101 * 102 - * This data structure is used in the WL unit. Each physical eraseblock has a 103 - * corresponding &struct wl_entry object which may be kept in different 104 - * RB-trees. See WL unit for details. 102 + * This data structure is used in the WL sub-system. Each physical eraseblock 103 + * has a corresponding &struct wl_entry object which may be kept in different 104 + * RB-trees. See WL sub-system for details. 105 105 */ 106 106 struct ubi_wl_entry { 107 107 struct rb_node rb; ··· 118 118 * @mutex: read/write mutex to implement read/write access serialization to 119 119 * the (@vol_id, @lnum) logical eraseblock 120 120 * 121 - * This data structure is used in the EBA unit to implement per-LEB locking. 122 - * When a logical eraseblock is being locked - corresponding 121 + * This data structure is used in the EBA sub-system to implement per-LEB 122 + * locking. When a logical eraseblock is being locked - corresponding 123 123 * &struct ubi_ltree_entry object is inserted to the lock tree (@ubi->ltree). 124 - * See EBA unit for details. 124 + * See EBA sub-system for details. 125 125 */ 126 126 struct ubi_ltree_entry { 127 127 struct rb_node rb; ··· 129 129 int lnum; 130 130 int users; 131 131 struct rw_semaphore mutex; 132 + }; 133 + 134 + /** 135 + * struct ubi_rename_entry - volume re-name description data structure. 136 + * @new_name_len: new volume name length 137 + * @new_name: new volume name 138 + * @remove: if not zero, this volume should be removed, not re-named 139 + * @desc: descriptor of the volume 140 + * @list: links re-name entries into a list 141 + * 142 + * This data structure is utilized in the multiple volume re-name code. Namely, 143 + * UBI first creates a list of &struct ubi_rename_entry objects from the 144 + * &struct ubi_rnvol_req request object, and then utilizes this list to do all 145 + * the job. 146 + */ 147 + struct ubi_rename_entry { 148 + int new_name_len; 149 + char new_name[UBI_VOL_NAME_MAX + 1]; 150 + int remove; 151 + struct ubi_volume_desc *desc; 152 + struct list_head list; 132 153 }; 133 154 134 155 struct ubi_volume_desc; ··· 227 206 int alignment; 228 207 int data_pad; 229 208 int name_len; 230 - char name[UBI_VOL_NAME_MAX+1]; 209 + char name[UBI_VOL_NAME_MAX + 1]; 231 210 232 211 int upd_ebs; 233 212 int ch_lnum; ··· 246 225 #ifdef CONFIG_MTD_UBI_GLUEBI 247 226 /* 248 227 * Gluebi-related stuff may be compiled out. 249 - * TODO: this should not be built into UBI but should be a separate 228 + * Note: this should not be built into UBI but should be a separate 250 229 * ubimtd driver which works on top of UBI and emulates MTD devices. 251 230 */ 252 231 struct ubi_volume_desc *gluebi_desc; ··· 256 235 }; 257 236 258 237 /** 259 - * struct ubi_volume_desc - descriptor of the UBI volume returned when it is 260 - * opened. 238 + * struct ubi_volume_desc - UBI volume descriptor returned when it is opened. 261 239 * @vol: reference to the corresponding volume description object 262 240 * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, or %UBI_EXCLUSIVE) 263 241 */ ··· 293 273 * @vtbl_size: size of the volume table in bytes 294 274 * @vtbl: in-RAM volume table copy 295 275 * @volumes_mutex: protects on-flash volume table and serializes volume 296 - * changes, like creation, deletion, update, resize 276 + * changes, like creation, deletion, update, re-size and re-name 297 277 * 298 278 * @max_ec: current highest erase counter value 299 279 * @mean_ec: current mean erase counter value ··· 313 293 * @move_to, @move_to_put @erase_pending, @wl_scheduled, and @works 314 294 * fields 315 295 * @move_mutex: serializes eraseblock moves 296 + * @work_sem: sycnhronizes the WL worker with use tasks 316 297 * @wl_scheduled: non-zero if the wear-leveling was scheduled 317 298 * @lookuptbl: a table to quickly find a &struct ubi_wl_entry object for any 318 299 * physical eraseblock ··· 337 316 * @ro_mode: if the UBI device is in read-only mode 338 317 * @leb_size: logical eraseblock size 339 318 * @leb_start: starting offset of logical eraseblocks within physical 340 - * eraseblocks 319 + * eraseblocks 341 320 * @ec_hdr_alsize: size of the EC header aligned to @hdrs_min_io_size 342 321 * @vid_hdr_alsize: size of the VID header aligned to @hdrs_min_io_size 343 322 * @vid_hdr_offset: starting offset of the volume identifier header (might be 344 - * unaligned) 323 + * unaligned) 345 324 * @vid_hdr_aloffset: starting offset of the VID header aligned to 346 325 * @hdrs_min_io_size 347 326 * @vid_hdr_shift: contains @vid_hdr_offset - @vid_hdr_aloffset ··· 352 331 * @peb_buf1: a buffer of PEB size used for different purposes 353 332 * @peb_buf2: another buffer of PEB size used for different purposes 354 333 * @buf_mutex: proptects @peb_buf1 and @peb_buf2 334 + * @ckvol_mutex: serializes static volume checking when opening 335 + * @mult_mutex: serializes operations on multiple volumes, like re-nameing 355 336 * @dbg_peb_buf: buffer of PEB size used for debugging 356 337 * @dbg_buf_mutex: proptects @dbg_peb_buf 357 338 */ ··· 379 356 struct mutex volumes_mutex; 380 357 381 358 int max_ec; 382 - /* TODO: mean_ec is not updated run-time, fix */ 359 + /* Note, mean_ec is not updated run-time - should be fixed */ 383 360 int mean_ec; 384 361 385 - /* EBA unit's stuff */ 362 + /* EBA sub-system's stuff */ 386 363 unsigned long long global_sqnum; 387 364 spinlock_t ltree_lock; 388 365 struct rb_root ltree; 389 366 struct mutex alc_mutex; 390 367 391 - /* Wear-leveling unit's stuff */ 368 + /* Wear-leveling sub-system's stuff */ 392 369 struct rb_root used; 393 370 struct rb_root free; 394 371 struct rb_root scrub; ··· 411 388 int thread_enabled; 412 389 char bgt_name[sizeof(UBI_BGT_NAME_PATTERN)+2]; 413 390 414 - /* I/O unit's stuff */ 391 + /* I/O sub-system's stuff */ 415 392 long long flash_size; 416 393 int peb_count; 417 394 int peb_size; ··· 434 411 void *peb_buf2; 435 412 struct mutex buf_mutex; 436 413 struct mutex ckvol_mutex; 414 + struct mutex mult_mutex; 437 415 #ifdef CONFIG_MTD_UBI_DEBUG 438 416 void *dbg_peb_buf; 439 417 struct mutex dbg_buf_mutex; ··· 451 427 /* vtbl.c */ 452 428 int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, 453 429 struct ubi_vtbl_record *vtbl_rec); 430 + int ubi_vtbl_rename_volumes(struct ubi_device *ubi, 431 + struct list_head *rename_list); 454 432 int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si); 455 433 456 434 /* vmt.c */ 457 435 int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req); 458 - int ubi_remove_volume(struct ubi_volume_desc *desc); 436 + int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl); 459 437 int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs); 438 + int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list); 460 439 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol); 461 440 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol); 462 441 ··· 474 447 const void __user *buf, int count); 475 448 476 449 /* misc.c */ 477 - int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf, int length); 450 + int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf, 451 + int length); 478 452 int ubi_check_volume(struct ubi_device *ubi, int vol_id); 479 453 void ubi_calculate_reserved(struct ubi_device *ubi); 480 454 ··· 505 477 int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, 506 478 struct ubi_vid_hdr *vid_hdr); 507 479 int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si); 508 - void ubi_eba_close(const struct ubi_device *ubi); 509 480 510 481 /* wl.c */ 511 482 int ubi_wl_get_peb(struct ubi_device *ubi, int dtype);
+18 -14
drivers/mtd/ubi/upd.c
··· 39 39 */ 40 40 41 41 #include <linux/err.h> 42 - #include <asm/uaccess.h> 42 + #include <linux/uaccess.h> 43 43 #include <asm/div64.h> 44 44 #include "ubi.h" 45 45 ··· 56 56 int err; 57 57 struct ubi_vtbl_record vtbl_rec; 58 58 59 - dbg_msg("set update marker for volume %d", vol->vol_id); 59 + dbg_gen("set update marker for volume %d", vol->vol_id); 60 60 61 61 if (vol->upd_marker) { 62 62 ubi_assert(ubi->vtbl[vol->vol_id].upd_marker); 63 - dbg_msg("already set"); 63 + dbg_gen("already set"); 64 64 return 0; 65 65 } 66 66 ··· 92 92 uint64_t tmp; 93 93 struct ubi_vtbl_record vtbl_rec; 94 94 95 - dbg_msg("clear update marker for volume %d", vol->vol_id); 95 + dbg_gen("clear update marker for volume %d", vol->vol_id); 96 96 97 97 memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id], 98 98 sizeof(struct ubi_vtbl_record)); ··· 133 133 int i, err; 134 134 uint64_t tmp; 135 135 136 - dbg_msg("start update of volume %d, %llu bytes", vol->vol_id, bytes); 136 + dbg_gen("start update of volume %d, %llu bytes", vol->vol_id, bytes); 137 137 ubi_assert(!vol->updating && !vol->changing_leb); 138 138 vol->updating = 1; 139 139 ··· 183 183 { 184 184 ubi_assert(!vol->updating && !vol->changing_leb); 185 185 186 - dbg_msg("start changing LEB %d:%d, %u bytes", 186 + dbg_gen("start changing LEB %d:%d, %u bytes", 187 187 vol->vol_id, req->lnum, req->bytes); 188 188 if (req->bytes == 0) 189 189 return ubi_eba_atomic_leb_change(ubi, vol, req->lnum, NULL, 0, ··· 237 237 int err; 238 238 239 239 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { 240 - len = ALIGN(len, ubi->min_io_size); 241 - memset(buf + len, 0xFF, len - len); 240 + int l = ALIGN(len, ubi->min_io_size); 242 241 243 - len = ubi_calc_data_len(ubi, buf, len); 242 + memset(buf + len, 0xFF, l - len); 243 + len = ubi_calc_data_len(ubi, buf, l); 244 244 if (len == 0) { 245 - dbg_msg("all %d bytes contain 0xFF - skip", len); 245 + dbg_gen("all %d bytes contain 0xFF - skip", len); 246 246 return 0; 247 247 } 248 248 249 - err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len, UBI_UNKNOWN); 249 + err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len, 250 + UBI_UNKNOWN); 250 251 } else { 251 252 /* 252 253 * When writing static volume, and this is the last logical ··· 268 267 269 268 /** 270 269 * ubi_more_update_data - write more update data. 270 + * @ubi: UBI device description object 271 271 * @vol: volume description object 272 272 * @buf: write data (user-space memory buffer) 273 273 * @count: how much bytes to write ··· 285 283 uint64_t tmp; 286 284 int lnum, offs, err = 0, len, to_write = count; 287 285 288 - dbg_msg("write %d of %lld bytes, %lld already passed", 286 + dbg_gen("write %d of %lld bytes, %lld already passed", 289 287 count, vol->upd_bytes, vol->upd_received); 290 288 291 289 if (ubi->ro_mode) ··· 386 384 387 385 /** 388 386 * ubi_more_leb_change_data - accept more data for atomic LEB change. 387 + * @ubi: UBI device description object 389 388 * @vol: volume description object 390 389 * @buf: write data (user-space memory buffer) 391 390 * @count: how much bytes to write ··· 403 400 { 404 401 int err; 405 402 406 - dbg_msg("write %d of %lld bytes, %lld already passed", 403 + dbg_gen("write %d of %lld bytes, %lld already passed", 407 404 count, vol->upd_bytes, vol->upd_received); 408 405 409 406 if (ubi->ro_mode) ··· 421 418 if (vol->upd_received == vol->upd_bytes) { 422 419 int len = ALIGN((int)vol->upd_bytes, ubi->min_io_size); 423 420 424 - memset(vol->upd_buf + vol->upd_bytes, 0xFF, len - vol->upd_bytes); 421 + memset(vol->upd_buf + vol->upd_bytes, 0xFF, 422 + len - vol->upd_bytes); 425 423 len = ubi_calc_data_len(ubi, vol->upd_buf, len); 426 424 err = ubi_eba_atomic_leb_change(ubi, vol, vol->ch_lnum, 427 425 vol->upd_buf, len, UBI_UNKNOWN);
+95 -53
drivers/mtd/ubi/vmt.c
··· 28 28 #include "ubi.h" 29 29 30 30 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 31 - static void paranoid_check_volumes(struct ubi_device *ubi); 31 + static int paranoid_check_volumes(struct ubi_device *ubi); 32 32 #else 33 - #define paranoid_check_volumes(ubi) 33 + #define paranoid_check_volumes(ubi) 0 34 34 #endif 35 35 36 36 static ssize_t vol_attribute_show(struct device *dev, ··· 127 127 { 128 128 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev); 129 129 130 + kfree(vol->eba_tbl); 130 131 kfree(vol); 131 132 } 132 133 ··· 202 201 */ 203 202 int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) 204 203 { 205 - int i, err, vol_id = req->vol_id, dont_free = 0; 204 + int i, err, vol_id = req->vol_id, do_free = 1; 206 205 struct ubi_volume *vol; 207 206 struct ubi_vtbl_record vtbl_rec; 208 207 uint64_t bytes; ··· 218 217 spin_lock(&ubi->volumes_lock); 219 218 if (vol_id == UBI_VOL_NUM_AUTO) { 220 219 /* Find unused volume ID */ 221 - dbg_msg("search for vacant volume ID"); 220 + dbg_gen("search for vacant volume ID"); 222 221 for (i = 0; i < ubi->vtbl_slots; i++) 223 222 if (!ubi->volumes[i]) { 224 223 vol_id = i; ··· 233 232 req->vol_id = vol_id; 234 233 } 235 234 236 - dbg_msg("volume ID %d, %llu bytes, type %d, name %s", 235 + dbg_gen("volume ID %d, %llu bytes, type %d, name %s", 237 236 vol_id, (unsigned long long)req->bytes, 238 237 (int)req->vol_type, req->name); 239 238 ··· 253 252 goto out_unlock; 254 253 } 255 254 256 - /* Calculate how many eraseblocks are requested */ 255 + /* Calculate how many eraseblocks are requested */ 257 256 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment; 258 257 bytes = req->bytes; 259 258 if (do_div(bytes, vol->usable_leb_size)) ··· 275 274 vol->data_pad = ubi->leb_size % vol->alignment; 276 275 vol->vol_type = req->vol_type; 277 276 vol->name_len = req->name_len; 278 - memcpy(vol->name, req->name, vol->name_len + 1); 277 + memcpy(vol->name, req->name, vol->name_len); 279 278 vol->ubi = ubi; 280 279 281 280 /* ··· 350 349 vtbl_rec.vol_type = UBI_VID_DYNAMIC; 351 350 else 352 351 vtbl_rec.vol_type = UBI_VID_STATIC; 353 - memcpy(vtbl_rec.name, vol->name, vol->name_len + 1); 352 + memcpy(vtbl_rec.name, vol->name, vol->name_len); 354 353 355 354 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); 356 355 if (err) ··· 361 360 ubi->vol_count += 1; 362 361 spin_unlock(&ubi->volumes_lock); 363 362 364 - paranoid_check_volumes(ubi); 365 - return 0; 363 + err = paranoid_check_volumes(ubi); 364 + return err; 366 365 367 366 out_sysfs: 368 367 /* 369 - * We have registered our device, we should not free the volume* 368 + * We have registered our device, we should not free the volume 370 369 * description object in this function in case of an error - it is 371 370 * freed by the release function. 372 371 * 373 372 * Get device reference to prevent the release function from being 374 373 * called just after sysfs has been closed. 375 374 */ 376 - dont_free = 1; 375 + do_free = 0; 377 376 get_device(&vol->dev); 378 377 volume_sysfs_close(vol); 379 378 out_gluebi: ··· 383 382 out_cdev: 384 383 cdev_del(&vol->cdev); 385 384 out_mapping: 386 - kfree(vol->eba_tbl); 385 + if (do_free) 386 + kfree(vol->eba_tbl); 387 387 out_acc: 388 388 spin_lock(&ubi->volumes_lock); 389 389 ubi->rsvd_pebs -= vol->reserved_pebs; 390 390 ubi->avail_pebs += vol->reserved_pebs; 391 391 out_unlock: 392 392 spin_unlock(&ubi->volumes_lock); 393 - if (dont_free) 394 - put_device(&vol->dev); 395 - else 393 + if (do_free) 396 394 kfree(vol); 395 + else 396 + put_device(&vol->dev); 397 397 ubi_err("cannot create volume %d, error %d", vol_id, err); 398 398 return err; 399 399 } ··· 402 400 /** 403 401 * ubi_remove_volume - remove volume. 404 402 * @desc: volume descriptor 403 + * @no_vtbl: do not change volume table if not zero 405 404 * 406 405 * This function removes volume described by @desc. The volume has to be opened 407 406 * in "exclusive" mode. Returns zero in case of success and a negative error 408 407 * code in case of failure. The caller has to have the @ubi->volumes_mutex 409 408 * locked. 410 409 */ 411 - int ubi_remove_volume(struct ubi_volume_desc *desc) 410 + int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl) 412 411 { 413 412 struct ubi_volume *vol = desc->vol; 414 413 struct ubi_device *ubi = vol->ubi; 415 414 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs; 416 415 417 - dbg_msg("remove UBI volume %d", vol_id); 416 + dbg_gen("remove UBI volume %d", vol_id); 418 417 ubi_assert(desc->mode == UBI_EXCLUSIVE); 419 418 ubi_assert(vol == ubi->volumes[vol_id]); 420 419 ··· 438 435 if (err) 439 436 goto out_err; 440 437 441 - err = ubi_change_vtbl_record(ubi, vol_id, NULL); 442 - if (err) 443 - goto out_err; 438 + if (!no_vtbl) { 439 + err = ubi_change_vtbl_record(ubi, vol_id, NULL); 440 + if (err) 441 + goto out_err; 442 + } 444 443 445 444 for (i = 0; i < vol->reserved_pebs; i++) { 446 445 err = ubi_eba_unmap_leb(ubi, vol, i); ··· 450 445 goto out_err; 451 446 } 452 447 453 - kfree(vol->eba_tbl); 454 - vol->eba_tbl = NULL; 455 448 cdev_del(&vol->cdev); 456 449 volume_sysfs_close(vol); 457 450 ··· 468 465 ubi->vol_count -= 1; 469 466 spin_unlock(&ubi->volumes_lock); 470 467 471 - paranoid_check_volumes(ubi); 472 - return 0; 468 + if (!no_vtbl) 469 + err = paranoid_check_volumes(ubi); 470 + return err; 473 471 474 472 out_err: 475 473 ubi_err("cannot remove volume %d, error %d", vol_id, err); ··· 501 497 if (ubi->ro_mode) 502 498 return -EROFS; 503 499 504 - dbg_msg("re-size volume %d to from %d to %d PEBs", 500 + dbg_gen("re-size volume %d to from %d to %d PEBs", 505 501 vol_id, vol->reserved_pebs, reserved_pebs); 506 502 507 503 if (vol->vol_type == UBI_STATIC_VOLUME && ··· 590 586 (long long)vol->used_ebs * vol->usable_leb_size; 591 587 } 592 588 593 - paranoid_check_volumes(ubi); 594 - return 0; 589 + err = paranoid_check_volumes(ubi); 590 + return err; 595 591 596 592 out_acc: 597 593 if (pebs > 0) { ··· 602 598 } 603 599 out_free: 604 600 kfree(new_mapping); 601 + return err; 602 + } 603 + 604 + /** 605 + * ubi_rename_volumes - re-name UBI volumes. 606 + * @ubi: UBI device description object 607 + * @rename_list: list of &struct ubi_rename_entry objects 608 + * 609 + * This function re-names or removes volumes specified in the re-name list. 610 + * Returns zero in case of success and a negative error code in case of 611 + * failure. 612 + */ 613 + int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list) 614 + { 615 + int err; 616 + struct ubi_rename_entry *re; 617 + 618 + err = ubi_vtbl_rename_volumes(ubi, rename_list); 619 + if (err) 620 + return err; 621 + 622 + list_for_each_entry(re, rename_list, list) { 623 + if (re->remove) { 624 + err = ubi_remove_volume(re->desc, 1); 625 + if (err) 626 + break; 627 + } else { 628 + struct ubi_volume *vol = re->desc->vol; 629 + 630 + spin_lock(&ubi->volumes_lock); 631 + vol->name_len = re->new_name_len; 632 + memcpy(vol->name, re->new_name, re->new_name_len + 1); 633 + spin_unlock(&ubi->volumes_lock); 634 + } 635 + } 636 + 637 + if (!err) 638 + err = paranoid_check_volumes(ubi); 605 639 return err; 606 640 } 607 641 ··· 657 615 int err, vol_id = vol->vol_id; 658 616 dev_t dev; 659 617 660 - dbg_msg("add volume %d", vol_id); 661 - ubi_dbg_dump_vol_info(vol); 618 + dbg_gen("add volume %d", vol_id); 662 619 663 620 /* Register character device for the volume */ 664 621 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); ··· 691 650 return err; 692 651 } 693 652 694 - paranoid_check_volumes(ubi); 695 - return 0; 653 + err = paranoid_check_volumes(ubi); 654 + return err; 696 655 697 656 out_gluebi: 698 657 err = ubi_destroy_gluebi(vol); ··· 713 672 { 714 673 int err; 715 674 716 - dbg_msg("free volume %d", vol->vol_id); 675 + dbg_gen("free volume %d", vol->vol_id); 717 676 718 677 ubi->volumes[vol->vol_id] = NULL; 719 678 err = ubi_destroy_gluebi(vol); ··· 727 686 * paranoid_check_volume - check volume information. 728 687 * @ubi: UBI device description object 729 688 * @vol_id: volume ID 689 + * 690 + * Returns zero if volume is all right and a a negative error code if not. 730 691 */ 731 - static void paranoid_check_volume(struct ubi_device *ubi, int vol_id) 692 + static int paranoid_check_volume(struct ubi_device *ubi, int vol_id) 732 693 { 733 694 int idx = vol_id2idx(ubi, vol_id); 734 695 int reserved_pebs, alignment, data_pad, vol_type, name_len, upd_marker; ··· 748 705 goto fail; 749 706 } 750 707 spin_unlock(&ubi->volumes_lock); 751 - return; 752 - } 753 - 754 - if (vol->exclusive) { 755 - /* 756 - * The volume may be being created at the moment, do not check 757 - * it (e.g., it may be in the middle of ubi_create_volume(). 758 - */ 759 - spin_unlock(&ubi->volumes_lock); 760 - return; 708 + return 0; 761 709 } 762 710 763 711 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 || ··· 761 727 goto fail; 762 728 } 763 729 764 - n = vol->alignment % ubi->min_io_size; 730 + n = vol->alignment & (ubi->min_io_size - 1); 765 731 if (vol->alignment != 1 && n) { 766 732 ubi_err("alignment is not multiple of min I/O unit"); 767 733 goto fail; ··· 858 824 859 825 if (alignment != vol->alignment || data_pad != vol->data_pad || 860 826 upd_marker != vol->upd_marker || vol_type != vol->vol_type || 861 - name_len!= vol->name_len || strncmp(name, vol->name, name_len)) { 827 + name_len != vol->name_len || strncmp(name, vol->name, name_len)) { 862 828 ubi_err("volume info is different"); 863 829 goto fail; 864 830 } 865 831 866 832 spin_unlock(&ubi->volumes_lock); 867 - return; 833 + return 0; 868 834 869 835 fail: 870 836 ubi_err("paranoid check failed for volume %d", vol_id); 871 - ubi_dbg_dump_vol_info(vol); 837 + if (vol) 838 + ubi_dbg_dump_vol_info(vol); 872 839 ubi_dbg_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id); 873 840 spin_unlock(&ubi->volumes_lock); 874 - BUG(); 841 + return -EINVAL; 875 842 } 876 843 877 844 /** 878 845 * paranoid_check_volumes - check information about all volumes. 879 846 * @ubi: UBI device description object 847 + * 848 + * Returns zero if volumes are all right and a a negative error code if not. 880 849 */ 881 - static void paranoid_check_volumes(struct ubi_device *ubi) 850 + static int paranoid_check_volumes(struct ubi_device *ubi) 882 851 { 883 - int i; 852 + int i, err = 0; 884 853 885 - for (i = 0; i < ubi->vtbl_slots; i++) 886 - paranoid_check_volume(ubi, i); 854 + for (i = 0; i < ubi->vtbl_slots; i++) { 855 + err = paranoid_check_volume(ubi, i); 856 + if (err) 857 + break; 858 + } 859 + 860 + return err; 887 861 } 888 862 #endif
+93 -34
drivers/mtd/ubi/vtbl.c
··· 115 115 } 116 116 117 117 /** 118 - * vtbl_check - check if volume table is not corrupted and contains sensible 119 - * data. 118 + * ubi_vtbl_rename_volumes - rename UBI volumes in the volume table. 119 + * @ubi: UBI device description object 120 + * @rename_list: list of &struct ubi_rename_entry objects 121 + * 122 + * This function re-names multiple volumes specified in @req in the volume 123 + * table. Returns zero in case of success and a negative error code in case of 124 + * failure. 125 + */ 126 + int ubi_vtbl_rename_volumes(struct ubi_device *ubi, 127 + struct list_head *rename_list) 128 + { 129 + int i, err; 130 + struct ubi_rename_entry *re; 131 + struct ubi_volume *layout_vol; 132 + 133 + list_for_each_entry(re, rename_list, list) { 134 + uint32_t crc; 135 + struct ubi_volume *vol = re->desc->vol; 136 + struct ubi_vtbl_record *vtbl_rec = &ubi->vtbl[vol->vol_id]; 137 + 138 + if (re->remove) { 139 + memcpy(vtbl_rec, &empty_vtbl_record, 140 + sizeof(struct ubi_vtbl_record)); 141 + continue; 142 + } 143 + 144 + vtbl_rec->name_len = cpu_to_be16(re->new_name_len); 145 + memcpy(vtbl_rec->name, re->new_name, re->new_name_len); 146 + memset(vtbl_rec->name + re->new_name_len, 0, 147 + UBI_VOL_NAME_MAX + 1 - re->new_name_len); 148 + crc = crc32(UBI_CRC32_INIT, vtbl_rec, 149 + UBI_VTBL_RECORD_SIZE_CRC); 150 + vtbl_rec->crc = cpu_to_be32(crc); 151 + } 152 + 153 + layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)]; 154 + for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) { 155 + err = ubi_eba_unmap_leb(ubi, layout_vol, i); 156 + if (err) 157 + return err; 158 + 159 + err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0, 160 + ubi->vtbl_size, UBI_LONGTERM); 161 + if (err) 162 + return err; 163 + } 164 + 165 + return 0; 166 + } 167 + 168 + /** 169 + * vtbl_check - check if volume table is not corrupted and sensible. 120 170 * @ubi: UBI device description object 121 171 * @vtbl: volume table 122 172 * ··· 177 127 const struct ubi_vtbl_record *vtbl) 178 128 { 179 129 int i, n, reserved_pebs, alignment, data_pad, vol_type, name_len; 180 - int upd_marker; 130 + int upd_marker, err; 181 131 uint32_t crc; 182 132 const char *name; 183 133 ··· 203 153 if (reserved_pebs == 0) { 204 154 if (memcmp(&vtbl[i], &empty_vtbl_record, 205 155 UBI_VTBL_RECORD_SIZE)) { 206 - dbg_err("bad empty record"); 156 + err = 2; 207 157 goto bad; 208 158 } 209 159 continue; ··· 211 161 212 162 if (reserved_pebs < 0 || alignment < 0 || data_pad < 0 || 213 163 name_len < 0) { 214 - dbg_err("negative values"); 164 + err = 3; 215 165 goto bad; 216 166 } 217 167 218 168 if (alignment > ubi->leb_size || alignment == 0) { 219 - dbg_err("bad alignment"); 169 + err = 4; 220 170 goto bad; 221 171 } 222 172 223 - n = alignment % ubi->min_io_size; 173 + n = alignment & (ubi->min_io_size - 1); 224 174 if (alignment != 1 && n) { 225 - dbg_err("alignment is not multiple of min I/O unit"); 175 + err = 5; 226 176 goto bad; 227 177 } 228 178 229 179 n = ubi->leb_size % alignment; 230 180 if (data_pad != n) { 231 181 dbg_err("bad data_pad, has to be %d", n); 182 + err = 6; 232 183 goto bad; 233 184 } 234 185 235 186 if (vol_type != UBI_VID_DYNAMIC && vol_type != UBI_VID_STATIC) { 236 - dbg_err("bad vol_type"); 187 + err = 7; 237 188 goto bad; 238 189 } 239 190 240 191 if (upd_marker != 0 && upd_marker != 1) { 241 - dbg_err("bad upd_marker"); 192 + err = 8; 242 193 goto bad; 243 194 } 244 195 245 196 if (reserved_pebs > ubi->good_peb_count) { 246 197 dbg_err("too large reserved_pebs, good PEBs %d", 247 198 ubi->good_peb_count); 199 + err = 9; 248 200 goto bad; 249 201 } 250 202 251 203 if (name_len > UBI_VOL_NAME_MAX) { 252 - dbg_err("too long volume name, max %d", 253 - UBI_VOL_NAME_MAX); 204 + err = 10; 254 205 goto bad; 255 206 } 256 207 257 208 if (name[0] == '\0') { 258 - dbg_err("NULL volume name"); 209 + err = 11; 259 210 goto bad; 260 211 } 261 212 262 213 if (name_len != strnlen(name, name_len + 1)) { 263 - dbg_err("bad name_len"); 214 + err = 12; 264 215 goto bad; 265 216 } 266 217 } ··· 286 235 return 0; 287 236 288 237 bad: 289 - ubi_err("volume table check failed, record %d", i); 238 + ubi_err("volume table check failed: record %d, error %d", i, err); 290 239 ubi_dbg_dump_vtbl_record(&vtbl[i], i); 291 240 return -EINVAL; 292 241 } ··· 338 287 vid_hdr->data_pad = cpu_to_be32(0); 339 288 vid_hdr->lnum = cpu_to_be32(copy); 340 289 vid_hdr->sqnum = cpu_to_be64(++si->max_sqnum); 341 - vid_hdr->leb_ver = cpu_to_be32(old_seb ? old_seb->leb_ver + 1: 0); 342 290 343 291 /* The EC header is already there, write the VID header */ 344 292 err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr); ··· 420 370 * to LEB 0. 421 371 */ 422 372 423 - dbg_msg("check layout volume"); 373 + dbg_gen("check layout volume"); 424 374 425 375 /* Read both LEB 0 and LEB 1 into memory */ 426 376 ubi_rb_for_each_entry(rb, seb, &sv->root, u.rb) { ··· 434 384 err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0, 435 385 ubi->vtbl_size); 436 386 if (err == UBI_IO_BITFLIPS || err == -EBADMSG) 437 - /* Scrub the PEB later */ 387 + /* 388 + * Scrub the PEB later. Note, -EBADMSG indicates an 389 + * uncorrectable ECC error, but we have our own CRC and 390 + * the data will be checked later. If the data is OK, 391 + * the PEB will be scrubbed (because we set 392 + * seb->scrub). If the data is not OK, the contents of 393 + * the PEB will be recovered from the second copy, and 394 + * seb->scrub will be cleared in 395 + * 'ubi_scan_add_used()'. 396 + */ 438 397 seb->scrub = 1; 439 398 else if (err) 440 399 goto out_free; ··· 459 400 if (!leb_corrupted[0]) { 460 401 /* LEB 0 is OK */ 461 402 if (leb[1]) 462 - leb_corrupted[1] = memcmp(leb[0], leb[1], ubi->vtbl_size); 403 + leb_corrupted[1] = memcmp(leb[0], leb[1], 404 + ubi->vtbl_size); 463 405 if (leb_corrupted[1]) { 464 406 ubi_warn("volume table copy #2 is corrupted"); 465 407 err = create_vtbl(ubi, si, 1, leb[0]); ··· 680 620 static int check_sv(const struct ubi_volume *vol, 681 621 const struct ubi_scan_volume *sv) 682 622 { 623 + int err; 624 + 683 625 if (sv->highest_lnum >= vol->reserved_pebs) { 684 - dbg_err("bad highest_lnum"); 626 + err = 1; 685 627 goto bad; 686 628 } 687 629 if (sv->leb_count > vol->reserved_pebs) { 688 - dbg_err("bad leb_count"); 630 + err = 2; 689 631 goto bad; 690 632 } 691 633 if (sv->vol_type != vol->vol_type) { 692 - dbg_err("bad vol_type"); 634 + err = 3; 693 635 goto bad; 694 636 } 695 637 if (sv->used_ebs > vol->reserved_pebs) { 696 - dbg_err("bad used_ebs"); 638 + err = 4; 697 639 goto bad; 698 640 } 699 641 if (sv->data_pad != vol->data_pad) { 700 - dbg_err("bad data_pad"); 642 + err = 5; 701 643 goto bad; 702 644 } 703 645 return 0; 704 646 705 647 bad: 706 - ubi_err("bad scanning information"); 648 + ubi_err("bad scanning information, error %d", err); 707 649 ubi_dbg_dump_sv(sv); 708 650 ubi_dbg_dump_vol_info(vol); 709 651 return -EINVAL; ··· 734 672 return -EINVAL; 735 673 } 736 674 737 - if (si->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT&& 675 + if (si->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT && 738 676 si->highest_vol_id < UBI_INTERNAL_VOL_START) { 739 677 ubi_err("too large volume ID %d found by scanning", 740 678 si->highest_vol_id); 741 679 return -EINVAL; 742 680 } 743 - 744 681 745 682 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { 746 683 cond_resched(); ··· 778 717 } 779 718 780 719 /** 781 - * ubi_read_volume_table - read volume table. 782 - * information. 720 + * ubi_read_volume_table - read the volume table. 783 721 * @ubi: UBI device description object 784 722 * @si: scanning information 785 723 * ··· 857 797 858 798 out_free: 859 799 vfree(ubi->vtbl); 860 - for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) 861 - if (ubi->volumes[i]) { 862 - kfree(ubi->volumes[i]); 863 - ubi->volumes[i] = NULL; 864 - } 800 + for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { 801 + kfree(ubi->volumes[i]); 802 + ubi->volumes[i] = NULL; 803 + } 865 804 return err; 866 805 } 867 806
+102 -106
drivers/mtd/ubi/wl.c
··· 19 19 */ 20 20 21 21 /* 22 - * UBI wear-leveling unit. 22 + * UBI wear-leveling sub-system. 23 23 * 24 - * This unit is responsible for wear-leveling. It works in terms of physical 25 - * eraseblocks and erase counters and knows nothing about logical eraseblocks, 26 - * volumes, etc. From this unit's perspective all physical eraseblocks are of 27 - * two types - used and free. Used physical eraseblocks are those that were 28 - * "get" by the 'ubi_wl_get_peb()' function, and free physical eraseblocks are 29 - * those that were put by the 'ubi_wl_put_peb()' function. 24 + * This sub-system is responsible for wear-leveling. It works in terms of 25 + * physical* eraseblocks and erase counters and knows nothing about logical 26 + * eraseblocks, volumes, etc. From this sub-system's perspective all physical 27 + * eraseblocks are of two types - used and free. Used physical eraseblocks are 28 + * those that were "get" by the 'ubi_wl_get_peb()' function, and free physical 29 + * eraseblocks are those that were put by the 'ubi_wl_put_peb()' function. 30 30 * 31 31 * Physical eraseblocks returned by 'ubi_wl_get_peb()' have only erase counter 32 - * header. The rest of the physical eraseblock contains only 0xFF bytes. 32 + * header. The rest of the physical eraseblock contains only %0xFF bytes. 33 33 * 34 - * When physical eraseblocks are returned to the WL unit by means of the 34 + * When physical eraseblocks are returned to the WL sub-system by means of the 35 35 * 'ubi_wl_put_peb()' function, they are scheduled for erasure. The erasure is 36 36 * done asynchronously in context of the per-UBI device background thread, 37 - * which is also managed by the WL unit. 37 + * which is also managed by the WL sub-system. 38 38 * 39 39 * The wear-leveling is ensured by means of moving the contents of used 40 40 * physical eraseblocks with low erase counter to free physical eraseblocks ··· 43 43 * The 'ubi_wl_get_peb()' function accepts data type hints which help to pick 44 44 * an "optimal" physical eraseblock. For example, when it is known that the 45 45 * physical eraseblock will be "put" soon because it contains short-term data, 46 - * the WL unit may pick a free physical eraseblock with low erase counter, and 47 - * so forth. 46 + * the WL sub-system may pick a free physical eraseblock with low erase 47 + * counter, and so forth. 48 48 * 49 - * If the WL unit fails to erase a physical eraseblock, it marks it as bad. 49 + * If the WL sub-system fails to erase a physical eraseblock, it marks it as 50 + * bad. 50 51 * 51 - * This unit is also responsible for scrubbing. If a bit-flip is detected in a 52 - * physical eraseblock, it has to be moved. Technically this is the same as 53 - * moving it for wear-leveling reasons. 52 + * This sub-system is also responsible for scrubbing. If a bit-flip is detected 53 + * in a physical eraseblock, it has to be moved. Technically this is the same 54 + * as moving it for wear-leveling reasons. 54 55 * 55 - * As it was said, for the UBI unit all physical eraseblocks are either "free" 56 - * or "used". Free eraseblock are kept in the @wl->free RB-tree, while used 57 - * eraseblocks are kept in a set of different RB-trees: @wl->used, 56 + * As it was said, for the UBI sub-system all physical eraseblocks are either 57 + * "free" or "used". Free eraseblock are kept in the @wl->free RB-tree, while 58 + * used eraseblocks are kept in a set of different RB-trees: @wl->used, 58 59 * @wl->prot.pnum, @wl->prot.aec, and @wl->scrub. 59 60 * 60 61 * Note, in this implementation, we keep a small in-RAM object for each physical 61 62 * eraseblock. This is surely not a scalable solution. But it appears to be good 62 63 * enough for moderately large flashes and it is simple. In future, one may 63 - * re-work this unit and make it more scalable. 64 + * re-work this sub-system and make it more scalable. 64 65 * 65 - * At the moment this unit does not utilize the sequence number, which was 66 - * introduced relatively recently. But it would be wise to do this because the 67 - * sequence number of a logical eraseblock characterizes how old is it. For 66 + * At the moment this sub-system does not utilize the sequence number, which 67 + * was introduced relatively recently. But it would be wise to do this because 68 + * the sequence number of a logical eraseblock characterizes how old is it. For 68 69 * example, when we move a PEB with low erase counter, and we need to pick the 69 70 * target PEB, we pick a PEB with the highest EC if our PEB is "old" and we 70 71 * pick target PEB with an average EC if our PEB is not very "old". This is a 71 - * room for future re-works of the WL unit. 72 + * room for future re-works of the WL sub-system. 72 73 * 73 - * FIXME: looks too complex, should be simplified (later). 74 + * Note: the stuff with protection trees looks too complex and is difficult to 75 + * understand. Should be fixed. 74 76 */ 75 77 76 78 #include <linux/slab.h> ··· 94 92 95 93 /* 96 94 * Maximum difference between two erase counters. If this threshold is 97 - * exceeded, the WL unit starts moving data from used physical eraseblocks with 98 - * low erase counter to free physical eraseblocks with high erase counter. 95 + * exceeded, the WL sub-system starts moving data from used physical 96 + * eraseblocks with low erase counter to free physical eraseblocks with high 97 + * erase counter. 99 98 */ 100 99 #define UBI_WL_THRESHOLD CONFIG_MTD_UBI_WL_THRESHOLD 101 100 102 101 /* 103 - * When a physical eraseblock is moved, the WL unit has to pick the target 102 + * When a physical eraseblock is moved, the WL sub-system has to pick the target 104 103 * physical eraseblock to move to. The simplest way would be just to pick the 105 104 * one with the highest erase counter. But in certain workloads this could lead 106 105 * to an unlimited wear of one or few physical eraseblock. Indeed, imagine a 107 106 * situation when the picked physical eraseblock is constantly erased after the 108 107 * data is written to it. So, we have a constant which limits the highest erase 109 - * counter of the free physical eraseblock to pick. Namely, the WL unit does 110 - * not pick eraseblocks with erase counter greater then the lowest erase 108 + * counter of the free physical eraseblock to pick. Namely, the WL sub-system 109 + * does not pick eraseblocks with erase counter greater then the lowest erase 111 110 * counter plus %WL_FREE_MAX_DIFF. 112 111 */ 113 112 #define WL_FREE_MAX_DIFF (2*UBI_WL_THRESHOLD) ··· 126 123 * @abs_ec: the absolute erase counter value when the protection ends 127 124 * @e: the wear-leveling entry of the physical eraseblock under protection 128 125 * 129 - * When the WL unit returns a physical eraseblock, the physical eraseblock is 130 - * protected from being moved for some "time". For this reason, the physical 131 - * eraseblock is not directly moved from the @wl->free tree to the @wl->used 132 - * tree. There is one more tree in between where this physical eraseblock is 133 - * temporarily stored (@wl->prot). 126 + * When the WL sub-system returns a physical eraseblock, the physical 127 + * eraseblock is protected from being moved for some "time". For this reason, 128 + * the physical eraseblock is not directly moved from the @wl->free tree to the 129 + * @wl->used tree. There is one more tree in between where this physical 130 + * eraseblock is temporarily stored (@wl->prot). 134 131 * 135 132 * All this protection stuff is needed because: 136 133 * o we don't want to move physical eraseblocks just after we have given them ··· 178 175 * @list: a link in the list of pending works 179 176 * @func: worker function 180 177 * @priv: private data of the worker function 181 - * 182 178 * @e: physical eraseblock to erase 183 179 * @torture: if the physical eraseblock has to be tortured 184 180 * ··· 475 473 } 476 474 477 475 switch (dtype) { 478 - case UBI_LONGTERM: 479 - /* 480 - * For long term data we pick a physical eraseblock 481 - * with high erase counter. But the highest erase 482 - * counter we can pick is bounded by the the lowest 483 - * erase counter plus %WL_FREE_MAX_DIFF. 484 - */ 485 - e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF); 486 - protect = LT_PROTECTION; 487 - break; 488 - case UBI_UNKNOWN: 489 - /* 490 - * For unknown data we pick a physical eraseblock with 491 - * medium erase counter. But we by no means can pick a 492 - * physical eraseblock with erase counter greater or 493 - * equivalent than the lowest erase counter plus 494 - * %WL_FREE_MAX_DIFF. 495 - */ 496 - first = rb_entry(rb_first(&ubi->free), 497 - struct ubi_wl_entry, rb); 498 - last = rb_entry(rb_last(&ubi->free), 499 - struct ubi_wl_entry, rb); 476 + case UBI_LONGTERM: 477 + /* 478 + * For long term data we pick a physical eraseblock with high 479 + * erase counter. But the highest erase counter we can pick is 480 + * bounded by the the lowest erase counter plus 481 + * %WL_FREE_MAX_DIFF. 482 + */ 483 + e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF); 484 + protect = LT_PROTECTION; 485 + break; 486 + case UBI_UNKNOWN: 487 + /* 488 + * For unknown data we pick a physical eraseblock with medium 489 + * erase counter. But we by no means can pick a physical 490 + * eraseblock with erase counter greater or equivalent than the 491 + * lowest erase counter plus %WL_FREE_MAX_DIFF. 492 + */ 493 + first = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, rb); 494 + last = rb_entry(rb_last(&ubi->free), struct ubi_wl_entry, rb); 500 495 501 - if (last->ec - first->ec < WL_FREE_MAX_DIFF) 502 - e = rb_entry(ubi->free.rb_node, 503 - struct ubi_wl_entry, rb); 504 - else { 505 - medium_ec = (first->ec + WL_FREE_MAX_DIFF)/2; 506 - e = find_wl_entry(&ubi->free, medium_ec); 507 - } 508 - protect = U_PROTECTION; 509 - break; 510 - case UBI_SHORTTERM: 511 - /* 512 - * For short term data we pick a physical eraseblock 513 - * with the lowest erase counter as we expect it will 514 - * be erased soon. 515 - */ 516 - e = rb_entry(rb_first(&ubi->free), 517 - struct ubi_wl_entry, rb); 518 - protect = ST_PROTECTION; 519 - break; 520 - default: 521 - protect = 0; 522 - e = NULL; 523 - BUG(); 496 + if (last->ec - first->ec < WL_FREE_MAX_DIFF) 497 + e = rb_entry(ubi->free.rb_node, 498 + struct ubi_wl_entry, rb); 499 + else { 500 + medium_ec = (first->ec + WL_FREE_MAX_DIFF)/2; 501 + e = find_wl_entry(&ubi->free, medium_ec); 502 + } 503 + protect = U_PROTECTION; 504 + break; 505 + case UBI_SHORTTERM: 506 + /* 507 + * For short term data we pick a physical eraseblock with the 508 + * lowest erase counter as we expect it will be erased soon. 509 + */ 510 + e = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, rb); 511 + protect = ST_PROTECTION; 512 + break; 513 + default: 514 + protect = 0; 515 + e = NULL; 516 + BUG(); 524 517 } 525 518 526 519 /* ··· 579 582 * This function returns zero in case of success and a negative error code in 580 583 * case of failure. 581 584 */ 582 - static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int torture) 585 + static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, 586 + int torture) 583 587 { 584 588 int err; 585 589 struct ubi_ec_hdr *ec_hdr; ··· 632 634 } 633 635 634 636 /** 635 - * check_protection_over - check if it is time to stop protecting some 636 - * physical eraseblocks. 637 + * check_protection_over - check if it is time to stop protecting some PEBs. 637 638 * @ubi: UBI device description object 638 639 * 639 640 * This function is called after each erase operation, when the absolute erase ··· 868 871 } 869 872 870 873 ubi_free_vid_hdr(ubi, vid_hdr); 874 + if (scrubbing && !protect) 875 + ubi_msg("scrubbed PEB %d, data moved to PEB %d", 876 + e1->pnum, e2->pnum); 877 + 871 878 spin_lock(&ubi->wl_lock); 872 879 if (protect) 873 880 prot_tree_add(ubi, e1, pe, protect); ··· 1055 1054 spin_unlock(&ubi->wl_lock); 1056 1055 1057 1056 /* 1058 - * One more erase operation has happened, take care about protected 1059 - * physical eraseblocks. 1057 + * One more erase operation has happened, take care about 1058 + * protected physical eraseblocks. 1060 1059 */ 1061 1060 check_protection_over(ubi); 1062 1061 ··· 1137 1136 } 1138 1137 1139 1138 /** 1140 - * ubi_wl_put_peb - return a physical eraseblock to the wear-leveling unit. 1139 + * ubi_wl_put_peb - return a PEB to the wear-leveling sub-system. 1141 1140 * @ubi: UBI device description object 1142 1141 * @pnum: physical eraseblock to return 1143 1142 * @torture: if this physical eraseblock has to be tortured ··· 1176 1175 /* 1177 1176 * User is putting the physical eraseblock which was selected 1178 1177 * as the target the data is moved to. It may happen if the EBA 1179 - * unit already re-mapped the LEB in 'ubi_eba_copy_leb()' but 1180 - * the WL unit has not put the PEB to the "used" tree yet, but 1181 - * it is about to do this. So we just set a flag which will 1182 - * tell the WL worker that the PEB is not needed anymore and 1183 - * should be scheduled for erasure. 1178 + * sub-system already re-mapped the LEB in 'ubi_eba_copy_leb()' 1179 + * but the WL sub-system has not put the PEB to the "used" tree 1180 + * yet, but it is about to do this. So we just set a flag which 1181 + * will tell the WL worker that the PEB is not needed anymore 1182 + * and should be scheduled for erasure. 1184 1183 */ 1185 1184 dbg_wl("PEB %d is the target of data moving", pnum); 1186 1185 ubi_assert(!ubi->move_to_put); ··· 1230 1229 { 1231 1230 struct ubi_wl_entry *e; 1232 1231 1233 - ubi_msg("schedule PEB %d for scrubbing", pnum); 1232 + dbg_msg("schedule PEB %d for scrubbing", pnum); 1234 1233 1235 1234 retry: 1236 1235 spin_lock(&ubi->wl_lock); ··· 1369 1368 int err; 1370 1369 1371 1370 if (kthread_should_stop()) 1372 - goto out; 1371 + break; 1373 1372 1374 1373 if (try_to_freeze()) 1375 1374 continue; ··· 1404 1403 cond_resched(); 1405 1404 } 1406 1405 1407 - out: 1408 1406 dbg_wl("background thread \"%s\" is killed", ubi->bgt_name); 1409 1407 return 0; 1410 1408 } ··· 1426 1426 } 1427 1427 1428 1428 /** 1429 - * ubi_wl_init_scan - initialize the wear-leveling unit using scanning 1430 - * information. 1429 + * ubi_wl_init_scan - initialize the WL sub-system using scanning information. 1431 1430 * @ubi: UBI device description object 1432 1431 * @si: scanning information 1433 1432 * ··· 1583 1584 } 1584 1585 1585 1586 /** 1586 - * ubi_wl_close - close the wear-leveling unit. 1587 + * ubi_wl_close - close the wear-leveling sub-system. 1587 1588 * @ubi: UBI device description object 1588 1589 */ 1589 1590 void ubi_wl_close(struct ubi_device *ubi) 1590 1591 { 1591 - dbg_wl("close the UBI wear-leveling unit"); 1592 - 1592 + dbg_wl("close the WL sub-system"); 1593 1593 cancel_pending(ubi); 1594 1594 protection_trees_destroy(ubi); 1595 1595 tree_destroy(&ubi->used); ··· 1600 1602 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 1601 1603 1602 1604 /** 1603 - * paranoid_check_ec - make sure that the erase counter of a physical eraseblock 1604 - * is correct. 1605 + * paranoid_check_ec - make sure that the erase counter of a PEB is correct. 1605 1606 * @ubi: UBI device description object 1606 1607 * @pnum: the physical eraseblock number to check 1607 1608 * @ec: the erase counter to check ··· 1641 1644 } 1642 1645 1643 1646 /** 1644 - * paranoid_check_in_wl_tree - make sure that a wear-leveling entry is present 1645 - * in a WL RB-tree. 1647 + * paranoid_check_in_wl_tree - check that wear-leveling entry is in WL RB-tree. 1646 1648 * @e: the wear-leveling entry to check 1647 1649 * @root: the root of the tree 1648 1650 * 1649 - * This function returns zero if @e is in the @root RB-tree and %1 if it 1650 - * is not. 1651 + * This function returns zero if @e is in the @root RB-tree and %1 if it is 1652 + * not. 1651 1653 */ 1652 1654 static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, 1653 1655 struct rb_root *root)
+3 -2
include/linux/mtd/ubi.h
··· 45 45 * @size: how many physical eraseblocks are reserved for this volume 46 46 * @used_bytes: how many bytes of data this volume contains 47 47 * @used_ebs: how many physical eraseblocks of this volume actually contain any 48 - * data 48 + * data 49 49 * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) 50 50 * @corrupted: non-zero if the volume is corrupted (static volumes only) 51 51 * @upd_marker: non-zero if the volume has update marker set 52 52 * @alignment: volume alignment 53 53 * @usable_leb_size: how many bytes are available in logical eraseblocks of 54 - * this volume 54 + * this volume 55 55 * @name_len: volume name length 56 56 * @name: volume name 57 57 * @cdev: UBI volume character device major and minor numbers ··· 152 152 int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum); 153 153 int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype); 154 154 int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum); 155 + int ubi_sync(int ubi_num); 155 156 156 157 /* 157 158 * This function is the same as the 'ubi_leb_read()' function, but it does not
+65 -11
include/mtd/ubi-user.h
··· 58 58 * device should be used. A &struct ubi_rsvol_req object has to be properly 59 59 * filled and a pointer to it has to be passed to the IOCTL. 60 60 * 61 + * UBI volumes re-name 62 + * ~~~~~~~~~~~~~~~~~~~ 63 + * 64 + * To re-name several volumes atomically at one go, the %UBI_IOCRNVOL command 65 + * of the UBI character device should be used. A &struct ubi_rnvol_req object 66 + * has to be properly filled and a pointer to it has to be passed to the IOCTL. 67 + * 61 68 * UBI volume update 62 69 * ~~~~~~~~~~~~~~~~~ 63 70 * ··· 111 104 #define UBI_IOCRMVOL _IOW(UBI_IOC_MAGIC, 1, int32_t) 112 105 /* Re-size an UBI volume */ 113 106 #define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req) 107 + /* Re-name volumes */ 108 + #define UBI_IOCRNVOL _IOW(UBI_IOC_MAGIC, 3, struct ubi_rnvol_req) 114 109 115 110 /* IOCTL commands of the UBI control character device */ 116 111 ··· 136 127 137 128 /* Maximum MTD device name length supported by UBI */ 138 129 #define MAX_UBI_MTD_NAME_LEN 127 130 + 131 + /* Maximum amount of UBI volumes that can be re-named at one go */ 132 + #define UBI_MAX_RNVOL 32 139 133 140 134 /* 141 135 * UBI data type hint constants. ··· 188 176 * it will be 512 in case of a 2KiB page NAND flash with 4 512-byte sub-pages. 189 177 * 190 178 * But in rare cases, if this optimizes things, the VID header may be placed to 191 - * a different offset. For example, the boot-loader might do things faster if the 192 - * VID header sits at the end of the first 2KiB NAND page with 4 sub-pages. As 193 - * the boot-loader would not normally need to read EC headers (unless it needs 194 - * UBI in RW mode), it might be faster to calculate ECC. This is weird example, 195 - * but it real-life example. So, in this example, @vid_hdr_offer would be 196 - * 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes 197 - * aligned, which is OK, as UBI is clever enough to realize this is 4th sub-page 198 - * of the first page and add needed padding. 179 + * a different offset. For example, the boot-loader might do things faster if 180 + * the VID header sits at the end of the first 2KiB NAND page with 4 sub-pages. 181 + * As the boot-loader would not normally need to read EC headers (unless it 182 + * needs UBI in RW mode), it might be faster to calculate ECC. This is weird 183 + * example, but it real-life example. So, in this example, @vid_hdr_offer would 184 + * be 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes 185 + * aligned, which is OK, as UBI is clever enough to realize this is 4th 186 + * sub-page of the first page and add needed padding. 199 187 */ 200 188 struct ubi_attach_req { 201 189 int32_t ubi_num; 202 190 int32_t mtd_num; 203 191 int32_t vid_hdr_offset; 204 - uint8_t padding[12]; 192 + int8_t padding[12]; 205 193 }; 206 194 207 195 /** ··· 263 251 } __attribute__ ((packed)); 264 252 265 253 /** 254 + * struct ubi_rnvol_req - volumes re-name request. 255 + * @count: count of volumes to re-name 256 + * @padding1: reserved for future, not used, has to be zeroed 257 + * @vol_id: ID of the volume to re-name 258 + * @name_len: name length 259 + * @padding2: reserved for future, not used, has to be zeroed 260 + * @name: new volume name 261 + * 262 + * UBI allows to re-name up to %32 volumes at one go. The count of volumes to 263 + * re-name is specified in the @count field. The ID of the volumes to re-name 264 + * and the new names are specified in the @vol_id and @name fields. 265 + * 266 + * The UBI volume re-name operation is atomic, which means that should power cut 267 + * happen, the volumes will have either old name or new name. So the possible 268 + * use-cases of this command is atomic upgrade. Indeed, to upgrade, say, volumes 269 + * A and B one may create temporary volumes %A1 and %B1 with the new contents, 270 + * then atomically re-name A1->A and B1->B, in which case old %A and %B will 271 + * be removed. 272 + * 273 + * If it is not desirable to remove old A and B, the re-name request has to 274 + * contain 4 entries: A1->A, A->A1, B1->B, B->B1, in which case old A1 and B1 275 + * become A and B, and old A and B will become A1 and B1. 276 + * 277 + * It is also OK to request: A1->A, A1->X, B1->B, B->Y, in which case old A1 278 + * and B1 become A and B, and old A and B become X and Y. 279 + * 280 + * In other words, in case of re-naming into an existing volume name, the 281 + * existing volume is removed, unless it is re-named as well at the same 282 + * re-name request. 283 + */ 284 + struct ubi_rnvol_req { 285 + int32_t count; 286 + int8_t padding1[12]; 287 + struct { 288 + int32_t vol_id; 289 + int16_t name_len; 290 + int8_t padding2[2]; 291 + char name[UBI_MAX_VOLUME_NAME + 1]; 292 + } ents[UBI_MAX_RNVOL]; 293 + } __attribute__ ((packed)); 294 + 295 + /** 266 296 * struct ubi_leb_change_req - a data structure used in atomic logical 267 297 * eraseblock change requests. 268 298 * @lnum: logical eraseblock number to change ··· 315 261 struct ubi_leb_change_req { 316 262 int32_t lnum; 317 263 int32_t bytes; 318 - uint8_t dtype; 319 - uint8_t padding[7]; 264 + int8_t dtype; 265 + int8_t padding[7]; 320 266 } __attribute__ ((packed)); 321 267 322 268 #endif /* __UBI_USER_H__ */