aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-05-18 05:41:17 -0400
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-05-20 13:26:04 -0400
commit47e1ec70b2c57f39752ae3210d89a625768f3e12 (patch)
tree6416115fb9753c5e44c6fd8d5eb15b8e55339af3
parent41e0cd9d4eeff0895e66cad5c70a90ba41023ea3 (diff)
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>
-rw-r--r--drivers/mtd/ubi/build.c65
-rw-r--r--drivers/mtd/ubi/scan.c52
-rw-r--r--drivers/mtd/ubi/scan.h2
-rw-r--r--drivers/mtd/ubi/ubi.h1
4 files changed, 58 insertions, 62 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index ecedd75aae03..2c5ed5ca9c33 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -550,10 +550,10 @@ static void uif_close(struct ubi_device *ubi)
550} 550}
551 551
552/** 552/**
553 * free_internal_volumes - free internal volumes. 553 * ubi_free_internal_volumes - free internal volumes.
554 * @ubi: UBI device description object 554 * @ubi: UBI device description object
555 */ 555 */
556static void free_internal_volumes(struct ubi_device *ubi) 556void ubi_free_internal_volumes(struct ubi_device *ubi)
557{ 557{
558 int i; 558 int i;
559 559
@@ -565,59 +565,6 @@ static void free_internal_volumes(struct ubi_device *ubi)
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 */
579static 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
610out_wl:
611 ubi_wl_close(ubi);
612out_vtbl:
613 free_internal_volumes(ubi);
614 vfree(ubi->vtbl);
615out_ai:
616 ubi_destroy_ai(ai);
617 return err;
618}
619
620/**
621 * io_init - initialize I/O sub-system for a given UBI device. 568 * io_init - initialize I/O sub-system for a given UBI device.
622 * @ubi: UBI device description object 569 * @ubi: UBI device description object
623 * 570 *
@@ -949,9 +896,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
949 if (err) 896 if (err)
950 goto out_free; 897 goto out_free;
951 898
952 err = attach_by_scanning(ubi); 899 err = ubi_attach(ubi);
953 if (err) { 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 goto out_debugging; 902 goto out_debugging;
956 } 903 }
957 904
@@ -1016,7 +963,7 @@ out_uif:
1016 uif_close(ubi); 963 uif_close(ubi);
1017out_detach: 964out_detach:
1018 ubi_wl_close(ubi); 965 ubi_wl_close(ubi);
1019 free_internal_volumes(ubi); 966 ubi_free_internal_volumes(ubi);
1020 vfree(ubi->vtbl); 967 vfree(ubi->vtbl);
1021out_debugging: 968out_debugging:
1022 ubi_debugging_exit_dev(ubi); 969 ubi_debugging_exit_dev(ubi);
@@ -1088,7 +1035,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1088 ubi_debugfs_exit_dev(ubi); 1035 ubi_debugfs_exit_dev(ubi);
1089 uif_close(ubi); 1036 uif_close(ubi);
1090 ubi_wl_close(ubi); 1037 ubi_wl_close(ubi);
1091 free_internal_volumes(ubi); 1038 ubi_free_internal_volumes(ubi);
1092 vfree(ubi->vtbl); 1039 vfree(ubi->vtbl);
1093 put_mtd_device(ubi->mtd); 1040 put_mtd_device(ubi->mtd);
1094 ubi_debugging_exit_dev(ubi); 1041 ubi_debugging_exit_dev(ubi);
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 93257f3c25d0..aecd8cfa3f47 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -1107,14 +1107,14 @@ static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai)
1107} 1107}
1108 1108
1109/** 1109/**
1110 * ubi_scan - scan an MTD device. 1110 * scan_all - scan entire MTD device.
1111 * @ubi: UBI device description object 1111 * @ubi: UBI device description object
1112 * 1112 *
1113 * This function does full scanning of an MTD device and returns complete 1113 * This function does full scanning of an MTD device and returns complete
1114 * information about it in form of a "struct ubi_attach_info" object. In case 1114 * information about it in form of a "struct ubi_attach_info" object. In case
1115 * of failure, an error code is returned. 1115 * of failure, an error code is returned.
1116 */ 1116 */
1117struct ubi_attach_info *ubi_scan(struct ubi_device *ubi) 1117static struct ubi_attach_info *scan_all(struct ubi_device *ubi)
1118{ 1118{
1119 int err, pnum; 1119 int err, pnum;
1120 struct rb_node *rb1, *rb2; 1120 struct rb_node *rb1, *rb2;
@@ -1208,6 +1208,54 @@ out_ai:
1208} 1208}
1209 1209
1210/** 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 */
1217int 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
1248out_wl:
1249 ubi_wl_close(ubi);
1250out_vtbl:
1251 ubi_free_internal_volumes(ubi);
1252 vfree(ubi->vtbl);
1253out_ai:
1254 ubi_destroy_ai(ai);
1255 return err;
1256}
1257
1258/**
1211 * destroy_av - free volume attaching information. 1259 * destroy_av - free volume attaching information.
1212 * @av: volume attaching information 1260 * @av: volume attaching information
1213 * @ai: attaching information 1261 * @ai: attaching information
diff --git a/drivers/mtd/ubi/scan.h b/drivers/mtd/ubi/scan.h
index a794577d0f30..3e0c4f494edf 100644
--- a/drivers/mtd/ubi/scan.h
+++ b/drivers/mtd/ubi/scan.h
@@ -164,7 +164,7 @@ struct ubi_ainf_volume *ubi_find_av(const struct ubi_attach_info *ai,
164void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av); 164void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av);
165struct ubi_ainf_peb *ubi_early_get_peb(struct ubi_device *ubi, 165struct ubi_ainf_peb *ubi_early_get_peb(struct ubi_device *ubi,
166 struct ubi_attach_info *ai); 166 struct ubi_attach_info *ai);
167struct ubi_attach_info *ubi_scan(struct ubi_device *ubi); 167int ubi_attach(struct ubi_device *ubi);
168void ubi_destroy_ai(struct ubi_attach_info *ai); 168void ubi_destroy_ai(struct ubi_attach_info *ai);
169 169
170#endif /* !__UBI_SCAN_H__ */ 170#endif /* !__UBI_SCAN_H__ */
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 9563e1b04f19..e09e558bc539 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -569,6 +569,7 @@ int ubi_volume_notify(struct ubi_device *ubi, struct ubi_volume *vol,
569int ubi_notify_all(struct ubi_device *ubi, int ntype, 569int ubi_notify_all(struct ubi_device *ubi, int ntype,
570 struct notifier_block *nb); 570 struct notifier_block *nb);
571int ubi_enumerate_volumes(struct notifier_block *nb); 571int ubi_enumerate_volumes(struct notifier_block *nb);
572void ubi_free_internal_volumes(struct ubi_device *ubi);
572 573
573/* kapi.c */ 574/* kapi.c */
574void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di); 575void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di);