Commit 47e1ec70b2c57f39752ae3210d89a625768f3e12

Authored by Artem Bityutskiy
1 parent 41e0cd9d4e

UBI: move and rename attach_by_scanning

Rename the 'attach_by_scanning()' function to 'ubi_attach()' and move it to
scan.c. Richard will plug his fastmap stuff there.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

Showing 4 changed files with 58 additions and 62 deletions Side-by-side Diff

drivers/mtd/ubi/build.c
... ... @@ -550,10 +550,10 @@
550 550 }
551 551  
552 552 /**
553   - * free_internal_volumes - free internal volumes.
  553 + * ubi_free_internal_volumes - free internal volumes.
554 554 * @ubi: UBI device description object
555 555 */
556   -static void free_internal_volumes(struct ubi_device *ubi)
  556 +void ubi_free_internal_volumes(struct ubi_device *ubi)
557 557 {
558 558 int i;
559 559  
... ... @@ -565,59 +565,6 @@
565 565 }
566 566  
567 567 /**
568   - * attach_by_scanning - attach an MTD device using scanning method.
569   - * @ubi: UBI device descriptor
570   - *
571   - * This function returns zero in case of success and a negative error code in
572   - * case of failure.
573   - *
574   - * Note, currently this is the only method to attach UBI devices. Hopefully in
575   - * the future we'll have more scalable attaching methods and avoid full media
576   - * scanning. But even in this case scanning will be needed as a fall-back
577   - * attaching method if there are some on-flash table corruptions.
578   - */
579   -static int attach_by_scanning(struct ubi_device *ubi)
580   -{
581   - int err;
582   - struct ubi_attach_info *ai;
583   -
584   - ai = ubi_scan(ubi);
585   - if (IS_ERR(ai))
586   - return PTR_ERR(ai);
587   -
588   - ubi->bad_peb_count = ai->bad_peb_count;
589   - ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count;
590   - ubi->corr_peb_count = ai->corr_peb_count;
591   - ubi->max_ec = ai->max_ec;
592   - ubi->mean_ec = ai->mean_ec;
593   - ubi_msg("max. sequence number: %llu", ai->max_sqnum);
594   -
595   - err = ubi_read_volume_table(ubi, ai);
596   - if (err)
597   - goto out_ai;
598   -
599   - err = ubi_wl_init(ubi, ai);
600   - if (err)
601   - goto out_vtbl;
602   -
603   - err = ubi_eba_init(ubi, ai);
604   - if (err)
605   - goto out_wl;
606   -
607   - ubi_destroy_ai(ai);
608   - return 0;
609   -
610   -out_wl:
611   - ubi_wl_close(ubi);
612   -out_vtbl:
613   - free_internal_volumes(ubi);
614   - vfree(ubi->vtbl);
615   -out_ai:
616   - ubi_destroy_ai(ai);
617   - return err;
618   -}
619   -
620   -/**
621 568 * io_init - initialize I/O sub-system for a given UBI device.
622 569 * @ubi: UBI device description object
623 570 *
624 571  
... ... @@ -949,9 +896,9 @@
949 896 if (err)
950 897 goto out_free;
951 898  
952   - err = attach_by_scanning(ubi);
  899 + err = ubi_attach(ubi);
953 900 if (err) {
954   - ubi_err("failed to attach by scanning, error %d", err);
  901 + ubi_err("failed to attach mtd%d, error %d", mtd->index, err);
955 902 goto out_debugging;
956 903 }
957 904  
... ... @@ -1016,7 +963,7 @@
1016 963 uif_close(ubi);
1017 964 out_detach:
1018 965 ubi_wl_close(ubi);
1019   - free_internal_volumes(ubi);
  966 + ubi_free_internal_volumes(ubi);
1020 967 vfree(ubi->vtbl);
1021 968 out_debugging:
1022 969 ubi_debugging_exit_dev(ubi);
... ... @@ -1088,7 +1035,7 @@
1088 1035 ubi_debugfs_exit_dev(ubi);
1089 1036 uif_close(ubi);
1090 1037 ubi_wl_close(ubi);
1091   - free_internal_volumes(ubi);
  1038 + ubi_free_internal_volumes(ubi);
1092 1039 vfree(ubi->vtbl);
1093 1040 put_mtd_device(ubi->mtd);
1094 1041 ubi_debugging_exit_dev(ubi);
drivers/mtd/ubi/scan.c
... ... @@ -1107,14 +1107,14 @@
1107 1107 }
1108 1108  
1109 1109 /**
1110   - * ubi_scan - scan an MTD device.
  1110 + * scan_all - scan entire MTD device.
1111 1111 * @ubi: UBI device description object
1112 1112 *
1113 1113 * This function does full scanning of an MTD device and returns complete
1114 1114 * information about it in form of a "struct ubi_attach_info" object. In case
1115 1115 * of failure, an error code is returned.
1116 1116 */
1117   -struct ubi_attach_info *ubi_scan(struct ubi_device *ubi)
  1117 +static struct ubi_attach_info *scan_all(struct ubi_device *ubi)
1118 1118 {
1119 1119 int err, pnum;
1120 1120 struct rb_node *rb1, *rb2;
... ... @@ -1205,6 +1205,54 @@
1205 1205 out_ai:
1206 1206 ubi_destroy_ai(ai);
1207 1207 return ERR_PTR(err);
  1208 +}
  1209 +
  1210 +/**
  1211 + * ubi_attach - attach an MTD device.
  1212 + * @ubi: UBI device descriptor
  1213 + *
  1214 + * This function returns zero in case of success and a negative error code in
  1215 + * case of failure.
  1216 + */
  1217 +int ubi_attach(struct ubi_device *ubi)
  1218 +{
  1219 + int err;
  1220 + struct ubi_attach_info *ai;
  1221 +
  1222 + ai = scan_all(ubi);
  1223 + if (IS_ERR(ai))
  1224 + return PTR_ERR(ai);
  1225 +
  1226 + ubi->bad_peb_count = ai->bad_peb_count;
  1227 + ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count;
  1228 + ubi->corr_peb_count = ai->corr_peb_count;
  1229 + ubi->max_ec = ai->max_ec;
  1230 + ubi->mean_ec = ai->mean_ec;
  1231 + ubi_msg("max. sequence number: %llu", ai->max_sqnum);
  1232 +
  1233 + err = ubi_read_volume_table(ubi, ai);
  1234 + if (err)
  1235 + goto out_ai;
  1236 +
  1237 + err = ubi_wl_init(ubi, ai);
  1238 + if (err)
  1239 + goto out_vtbl;
  1240 +
  1241 + err = ubi_eba_init(ubi, ai);
  1242 + if (err)
  1243 + goto out_wl;
  1244 +
  1245 + ubi_destroy_ai(ai);
  1246 + return 0;
  1247 +
  1248 +out_wl:
  1249 + ubi_wl_close(ubi);
  1250 +out_vtbl:
  1251 + ubi_free_internal_volumes(ubi);
  1252 + vfree(ubi->vtbl);
  1253 +out_ai:
  1254 + ubi_destroy_ai(ai);
  1255 + return err;
1208 1256 }
1209 1257  
1210 1258 /**
drivers/mtd/ubi/scan.h
... ... @@ -164,7 +164,7 @@
164 164 void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av);
165 165 struct ubi_ainf_peb *ubi_early_get_peb(struct ubi_device *ubi,
166 166 struct ubi_attach_info *ai);
167   -struct ubi_attach_info *ubi_scan(struct ubi_device *ubi);
  167 +int ubi_attach(struct ubi_device *ubi);
168 168 void ubi_destroy_ai(struct ubi_attach_info *ai);
169 169  
170 170 #endif /* !__UBI_SCAN_H__ */
drivers/mtd/ubi/ubi.h
... ... @@ -569,6 +569,7 @@
569 569 int ubi_notify_all(struct ubi_device *ubi, int ntype,
570 570 struct notifier_block *nb);
571 571 int ubi_enumerate_volumes(struct notifier_block *nb);
  572 +void ubi_free_internal_volumes(struct ubi_device *ubi);
572 573  
573 574 /* kapi.c */
574 575 void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di);