diff options
author | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-05-17 09:12:26 -0400 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-05-20 13:26:04 -0400 |
commit | fbd0107f4d33be01c9fb2c630036bd66b7e3d4dc (patch) | |
tree | d8ebd19a5cba548daea0c33f774ff7847b9cc523 /drivers/mtd/ubi/scan.c | |
parent | 1fc2e3e59d78999fc4be7349af769cf6621b9e61 (diff) |
UBI: amend comments after all the renamings
This patch amends commentaries in scan.[ch] to match the new logic. Reminder -
we did the restructuring to prepare the code for adding the fastmap. This patch
also renames a couple of functions - it was too difficult to separate out that
change and I decided that it is not too bad to have it in the same patch with
commentaries changes.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'drivers/mtd/ubi/scan.c')
-rw-r--r-- | drivers/mtd/ubi/scan.c | 111 |
1 files changed, 55 insertions, 56 deletions
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index 06a2d7062136..93257f3c25d0 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c | |||
@@ -19,21 +19,21 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | * UBI scanning sub-system. | 22 | * UBI attaching sub-system. |
23 | * | 23 | * |
24 | * This sub-system is responsible for scanning the flash media, checking UBI | 24 | * This sub-system is responsible for attaching MTD devices and it also |
25 | * headers and providing complete information about the UBI flash image. | 25 | * implements flash media scanning. |
26 | * | 26 | * |
27 | * The attaching information is represented by a &struct ubi_attach_info' | 27 | * The attaching information is represented by a &struct ubi_attach_info' |
28 | * object. Information about found volumes is represented by | 28 | * object. Information about volumes is represented by &struct ubi_ainf_volume |
29 | * &struct ubi_ainf_volume objects which are kept in volume RB-tree with root | 29 | * objects which are kept in volume RB-tree with root at the @volumes field. |
30 | * at the @volumes field. The RB-tree is indexed by the volume ID. | 30 | * The RB-tree is indexed by the volume ID. |
31 | * | 31 | * |
32 | * Scanned logical eraseblocks are represented by &struct ubi_ainf_peb objects. | 32 | * Logical eraseblocks are represented by &struct ubi_ainf_peb objects. These |
33 | * These objects are kept in per-volume RB-trees with the root at the | 33 | * objects are kept in per-volume RB-trees with the root at the corresponding |
34 | * corresponding &struct ubi_ainf_volume object. To put it differently, we keep | 34 | * &struct ubi_ainf_volume object. To put it differently, we keep an RB-tree of |
35 | * an RB-tree of per-volume objects and each of these objects is the root of | 35 | * per-volume objects and each of these objects is the root of RB-tree of |
36 | * RB-tree of per-eraseblock objects. | 36 | * per-LEB objects. |
37 | * | 37 | * |
38 | * Corrupted physical eraseblocks are put to the @corr list, free physical | 38 | * Corrupted physical eraseblocks are put to the @corr list, free physical |
39 | * eraseblocks are put to the @free list and the physical eraseblock to be | 39 | * eraseblocks are put to the @free list and the physical eraseblock to be |
@@ -51,28 +51,29 @@ | |||
51 | * | 51 | * |
52 | * 1. Corruptions caused by power cuts. These are expected corruptions and UBI | 52 | * 1. Corruptions caused by power cuts. These are expected corruptions and UBI |
53 | * tries to handle them gracefully, without printing too many warnings and | 53 | * tries to handle them gracefully, without printing too many warnings and |
54 | * error messages. The idea is that we do not lose important data in these case | 54 | * error messages. The idea is that we do not lose important data in these |
55 | * - we may lose only the data which was being written to the media just before | 55 | * cases - we may lose only the data which were being written to the media just |
56 | * the power cut happened, and the upper layers (e.g., UBIFS) are supposed to | 56 | * before the power cut happened, and the upper layers (e.g., UBIFS) are |
57 | * handle such data losses (e.g., by using the FS journal). | 57 | * supposed to handle such data losses (e.g., by using the FS journal). |
58 | * | 58 | * |
59 | * When UBI detects a corruption (CRC-32 mismatch) in a PEB, and it looks like | 59 | * When UBI detects a corruption (CRC-32 mismatch) in a PEB, and it looks like |
60 | * the reason is a power cut, UBI puts this PEB to the @erase list, and all | 60 | * the reason is a power cut, UBI puts this PEB to the @erase list, and all |
61 | * PEBs in the @erase list are scheduled for erasure later. | 61 | * PEBs in the @erase list are scheduled for erasure later. |
62 | * | 62 | * |
63 | * 2. Unexpected corruptions which are not caused by power cuts. During | 63 | * 2. Unexpected corruptions which are not caused by power cuts. During |
64 | * scanning, such PEBs are put to the @corr list and UBI preserves them. | 64 | * attaching, such PEBs are put to the @corr list and UBI preserves them. |
65 | * Obviously, this lessens the amount of available PEBs, and if at some point | 65 | * Obviously, this lessens the amount of available PEBs, and if at some point |
66 | * UBI runs out of free PEBs, it switches to R/O mode. UBI also loudly informs | 66 | * UBI runs out of free PEBs, it switches to R/O mode. UBI also loudly informs |
67 | * about such PEBs every time the MTD device is attached. | 67 | * about such PEBs every time the MTD device is attached. |
68 | * | 68 | * |
69 | * However, it is difficult to reliably distinguish between these types of | 69 | * However, it is difficult to reliably distinguish between these types of |
70 | * corruptions and UBI's strategy is as follows. UBI assumes corruption type 2 | 70 | * corruptions and UBI's strategy is as follows (in case of attaching by |
71 | * if the VID header is corrupted and the data area does not contain all 0xFFs, | 71 | * scanning). UBI assumes corruption type 2 if the VID header is corrupted and |
72 | * and there were no bit-flips or integrity errors while reading the data area. | 72 | * the data area does not contain all 0xFFs, and there were no bit-flips or |
73 | * Otherwise UBI assumes corruption type 1. So the decision criteria are as | 73 | * integrity errors (e.g., ECC errors in case of NAND) while reading the data |
74 | * follows. | 74 | * area. Otherwise UBI assumes corruption type 1. So the decision criteria |
75 | * o If the data area contains only 0xFFs, there is no data, and it is safe | 75 | * are as follows. |
76 | * o If the data area contains only 0xFFs, there are no data, and it is safe | ||
76 | * to just erase this PEB - this is corruption type 1. | 77 | * to just erase this PEB - this is corruption type 1. |
77 | * o If the data area has bit-flips or data integrity errors (ECC errors on | 78 | * o If the data area has bit-flips or data integrity errors (ECC errors on |
78 | * NAND), it is probably a PEB which was being erased when power cut | 79 | * NAND), it is probably a PEB which was being erased when power cut |
@@ -102,7 +103,8 @@ static struct ubi_vid_hdr *vidh; | |||
102 | * @to_head: if not zero, add to the head of the list | 103 | * @to_head: if not zero, add to the head of the list |
103 | * @list: the list to add to | 104 | * @list: the list to add to |
104 | * | 105 | * |
105 | * This function adds physical eraseblock @pnum to free, erase, or alien lists. | 106 | * This function allocates a 'struct ubi_ainf_peb' object for physical |
107 | * eraseblock @pnum and adds it to the "free", "erase", or "alien" lists. | ||
106 | * If @to_head is not zero, PEB will be added to the head of the list, which | 108 | * If @to_head is not zero, PEB will be added to the head of the list, which |
107 | * basically means it will be processed first later. E.g., we add corrupted | 109 | * basically means it will be processed first later. E.g., we add corrupted |
108 | * PEBs (corrupted due to power cuts) to the head of the erase list to make | 110 | * PEBs (corrupted due to power cuts) to the head of the erase list to make |
@@ -144,9 +146,10 @@ static int add_to_list(struct ubi_attach_info *ai, int pnum, int ec, | |||
144 | * @pnum: physical eraseblock number to add | 146 | * @pnum: physical eraseblock number to add |
145 | * @ec: erase counter of the physical eraseblock | 147 | * @ec: erase counter of the physical eraseblock |
146 | * | 148 | * |
147 | * This function adds corrupted physical eraseblock @pnum to the 'corr' list. | 149 | * This function allocates a 'struct ubi_ainf_peb' object for a corrupted |
148 | * The corruption was presumably not caused by a power cut. Returns zero in | 150 | * physical eraseblock @pnum and adds it to the 'corr' list. The corruption |
149 | * case of success and a negative error code in case of failure. | 151 | * was presumably not caused by a power cut. Returns zero in case of success |
152 | * and a negative error code in case of failure. | ||
150 | */ | 153 | */ |
151 | static int add_corrupted(struct ubi_attach_info *ai, int pnum, int ec) | 154 | static int add_corrupted(struct ubi_attach_info *ai, int pnum, int ec) |
152 | { | 155 | { |
@@ -241,8 +244,8 @@ bad: | |||
241 | * If the volume corresponding to the @vid_hdr logical eraseblock is already | 244 | * If the volume corresponding to the @vid_hdr logical eraseblock is already |
242 | * present in the attaching information, this function does nothing. Otherwise | 245 | * present in the attaching information, this function does nothing. Otherwise |
243 | * it adds corresponding volume to the attaching information. Returns a pointer | 246 | * it adds corresponding volume to the attaching information. Returns a pointer |
244 | * to the scanning volume object in case of success and a negative error code | 247 | * to the allocated "av" object in case of success and a negative error code in |
245 | * in case of failure. | 248 | * case of failure. |
246 | */ | 249 | */ |
247 | static struct ubi_ainf_volume *add_volume(struct ubi_attach_info *ai, | 250 | static struct ubi_ainf_volume *add_volume(struct ubi_attach_info *ai, |
248 | int vol_id, int pnum, | 251 | int vol_id, int pnum, |
@@ -425,7 +428,7 @@ out_free_vidh: | |||
425 | } | 428 | } |
426 | 429 | ||
427 | /** | 430 | /** |
428 | * ubi_add_to_av - add physical eraseblock to the attaching information. | 431 | * ubi_add_to_av - add used physical eraseblock to the attaching information. |
429 | * @ubi: UBI device description object | 432 | * @ubi: UBI device description object |
430 | * @ai: attaching information | 433 | * @ai: attaching information |
431 | * @pnum: the physical eraseblock number | 434 | * @pnum: the physical eraseblock number |
@@ -692,8 +695,8 @@ out_free: | |||
692 | * the lists, writes the EC header if it is needed, and removes it from the | 695 | * the lists, writes the EC header if it is needed, and removes it from the |
693 | * list. | 696 | * list. |
694 | * | 697 | * |
695 | * This function returns scanning physical eraseblock information in case of | 698 | * This function returns a pointer to the "aeb" of the found free PEB in case |
696 | * success and an error code in case of failure. | 699 | * of success and an error code in case of failure. |
697 | */ | 700 | */ |
698 | struct ubi_ainf_peb *ubi_early_get_peb(struct ubi_device *ubi, | 701 | struct ubi_ainf_peb *ubi_early_get_peb(struct ubi_device *ubi, |
699 | struct ubi_attach_info *ai) | 702 | struct ubi_attach_info *ai) |
@@ -793,16 +796,18 @@ out_unlock: | |||
793 | } | 796 | } |
794 | 797 | ||
795 | /** | 798 | /** |
796 | * process_eb - read, check UBI headers, and add them to attaching information. | 799 | * scan_peb - scan and process UBI headers of a PEB. |
797 | * @ubi: UBI device description object | 800 | * @ubi: UBI device description object |
798 | * @ai: attaching information | 801 | * @ai: attaching information |
799 | * @pnum: the physical eraseblock number | 802 | * @pnum: the physical eraseblock number |
800 | * | 803 | * |
801 | * This function returns a zero if the physical eraseblock was successfully | 804 | * This function reads UBI headers of PEB @pnum, checks them, and adds |
802 | * handled and a negative error code in case of failure. | 805 | * information about this PEB to the corresponding list or RB-tree in the |
806 | * "attaching info" structure. Returns zero if the physical eraseblock was | ||
807 | * successfully handled and a negative error code in case of failure. | ||
803 | */ | 808 | */ |
804 | static int process_eb(struct ubi_device *ubi, struct ubi_attach_info *ai, | 809 | static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, |
805 | int pnum) | 810 | int pnum) |
806 | { | 811 | { |
807 | long long uninitialized_var(ec); | 812 | long long uninitialized_var(ec); |
808 | int err, bitflips = 0, vol_id, ec_err = 0; | 813 | int err, bitflips = 0, vol_id, ec_err = 0; |
@@ -814,11 +819,6 @@ static int process_eb(struct ubi_device *ubi, struct ubi_attach_info *ai, | |||
814 | if (err < 0) | 819 | if (err < 0) |
815 | return err; | 820 | return err; |
816 | else if (err) { | 821 | else if (err) { |
817 | /* | ||
818 | * FIXME: this is actually duty of the I/O sub-system to | ||
819 | * initialize this, but MTD does not provide enough | ||
820 | * information. | ||
821 | */ | ||
822 | ai->bad_peb_count += 1; | 822 | ai->bad_peb_count += 1; |
823 | return 0; | 823 | return 0; |
824 | } | 824 | } |
@@ -1033,18 +1033,17 @@ adjust_mean_ec: | |||
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | /** | 1035 | /** |
1036 | * check_what_we_have - check what PEB were found by scanning. | 1036 | * late_analysis - analyze the overall situation with PEB. |
1037 | * @ubi: UBI device description object | 1037 | * @ubi: UBI device description object |
1038 | * @ai: attaching information | 1038 | * @ai: attaching information |
1039 | * | 1039 | * |
1040 | * This is a helper function which takes a look what PEBs were found by | 1040 | * This is a helper function which takes a look what PEBs we have after we |
1041 | * scanning, and decides whether the flash is empty and should be formatted and | 1041 | * gather information about all of them ("ai" is compete). It decides whether |
1042 | * whether there are too many corrupted PEBs and we should not attach this | 1042 | * the flash is empty and should be formatted of whether there are too many |
1043 | * MTD device. Returns zero if we should proceed with attaching the MTD device, | 1043 | * corrupted PEBs and we should not attach this MTD device. Returns zero if we |
1044 | * and %-EINVAL if we should not. | 1044 | * should proceed with attaching the MTD device, and %-EINVAL if we should not. |
1045 | */ | 1045 | */ |
1046 | static int check_what_we_have(struct ubi_device *ubi, | 1046 | static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai) |
1047 | struct ubi_attach_info *ai) | ||
1048 | { | 1047 | { |
1049 | struct ubi_ainf_peb *aeb; | 1048 | struct ubi_ainf_peb *aeb; |
1050 | int max_corr, peb_count; | 1049 | int max_corr, peb_count; |
@@ -1112,7 +1111,8 @@ static int check_what_we_have(struct ubi_device *ubi, | |||
1112 | * @ubi: UBI device description object | 1111 | * @ubi: UBI device description object |
1113 | * | 1112 | * |
1114 | * 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 |
1115 | * information about it. In case of failure, an error code is returned. | 1114 | * information about it in form of a "struct ubi_attach_info" object. In case |
1115 | * of failure, an error code is returned. | ||
1116 | */ | 1116 | */ |
1117 | struct ubi_attach_info *ubi_scan(struct ubi_device *ubi) | 1117 | struct ubi_attach_info *ubi_scan(struct ubi_device *ubi) |
1118 | { | 1118 | { |
@@ -1151,7 +1151,7 @@ struct ubi_attach_info *ubi_scan(struct ubi_device *ubi) | |||
1151 | cond_resched(); | 1151 | cond_resched(); |
1152 | 1152 | ||
1153 | dbg_gen("process PEB %d", pnum); | 1153 | dbg_gen("process PEB %d", pnum); |
1154 | err = process_eb(ubi, ai, pnum); | 1154 | err = scan_peb(ubi, ai, pnum); |
1155 | if (err < 0) | 1155 | if (err < 0) |
1156 | goto out_vidh; | 1156 | goto out_vidh; |
1157 | } | 1157 | } |
@@ -1162,7 +1162,7 @@ struct ubi_attach_info *ubi_scan(struct ubi_device *ubi) | |||
1162 | if (ai->ec_count) | 1162 | if (ai->ec_count) |
1163 | ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count); | 1163 | ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count); |
1164 | 1164 | ||
1165 | err = check_what_we_have(ubi, ai); | 1165 | err = late_analysis(ubi, ai); |
1166 | if (err) | 1166 | if (err) |
1167 | goto out_vidh; | 1167 | goto out_vidh; |
1168 | 1168 | ||
@@ -1208,12 +1208,11 @@ out_ai: | |||
1208 | } | 1208 | } |
1209 | 1209 | ||
1210 | /** | 1210 | /** |
1211 | * destroy_av - free the scanning volume information | 1211 | * destroy_av - free volume attaching information. |
1212 | * @av: scanning volume information | 1212 | * @av: volume attaching information |
1213 | * @ai: attaching information | 1213 | * @ai: attaching information |
1214 | * | 1214 | * |
1215 | * This function destroys the volume RB-tree (@av->root) and the scanning | 1215 | * This function destroys the volume attaching information. |
1216 | * volume information. | ||
1217 | */ | 1216 | */ |
1218 | static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av) | 1217 | static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av) |
1219 | { | 1218 | { |