diff options
46 files changed, 1587 insertions, 2097 deletions
diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig index 4dcc752a0c0b..738ee8dc16cd 100644 --- a/drivers/mtd/ubi/Kconfig +++ b/drivers/mtd/ubi/Kconfig | |||
@@ -52,12 +52,4 @@ config MTD_UBI_GLUEBI | |||
52 | work on top of UBI. Do not enable this unless you use legacy | 52 | work on top of UBI. Do not enable this unless you use legacy |
53 | software. | 53 | software. |
54 | 54 | ||
55 | config MTD_UBI_DEBUG | ||
56 | bool "UBI debugging" | ||
57 | depends on SYSFS | ||
58 | select DEBUG_FS | ||
59 | select KALLSYMS | ||
60 | help | ||
61 | This option enables UBI debugging. | ||
62 | |||
63 | endif # MTD_UBI | 55 | endif # MTD_UBI |
diff --git a/drivers/mtd/ubi/Makefile b/drivers/mtd/ubi/Makefile index c9302a5452b0..a0803ac74712 100644 --- a/drivers/mtd/ubi/Makefile +++ b/drivers/mtd/ubi/Makefile | |||
@@ -1,7 +1,6 @@ | |||
1 | obj-$(CONFIG_MTD_UBI) += ubi.o | 1 | obj-$(CONFIG_MTD_UBI) += ubi.o |
2 | 2 | ||
3 | ubi-y += vtbl.o vmt.o upd.o build.o cdev.o kapi.o eba.o io.o wl.o scan.o | 3 | ubi-y += vtbl.o vmt.o upd.o build.o cdev.o kapi.o eba.o io.o wl.o attach.o |
4 | ubi-y += misc.o | 4 | ubi-y += misc.o debug.o |
5 | 5 | ||
6 | ubi-$(CONFIG_MTD_UBI_DEBUG) += debug.o | ||
7 | obj-$(CONFIG_MTD_UBI_GLUEBI) += gluebi.o | 6 | obj-$(CONFIG_MTD_UBI_GLUEBI) += gluebi.o |
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/attach.c index 12c43b44f815..bd27cbbb4066 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/attach.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 scanning information is represented by a &struct ubi_scan_info' object. | 27 | * The attaching information is represented by a &struct ubi_attach_info' |
28 | * Information about found volumes is represented by &struct ubi_scan_volume | 28 | * object. Information about volumes is represented by &struct ubi_ainf_volume |
29 | * objects which are kept in volume RB-tree with root at the @volumes field. | 29 | * objects which are kept in volume RB-tree with root at the @volumes field. |
30 | * 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_scan_leb 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_scan_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 |
@@ -88,11 +89,7 @@ | |||
88 | #include <linux/random.h> | 89 | #include <linux/random.h> |
89 | #include "ubi.h" | 90 | #include "ubi.h" |
90 | 91 | ||
91 | #ifdef CONFIG_MTD_UBI_DEBUG | 92 | static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai); |
92 | static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si); | ||
93 | #else | ||
94 | #define paranoid_check_si(ubi, si) 0 | ||
95 | #endif | ||
96 | 93 | ||
97 | /* Temporary variables used during scanning */ | 94 | /* Temporary variables used during scanning */ |
98 | static struct ubi_ec_hdr *ech; | 95 | static struct ubi_ec_hdr *ech; |
@@ -100,13 +97,18 @@ static struct ubi_vid_hdr *vidh; | |||
100 | 97 | ||
101 | /** | 98 | /** |
102 | * add_to_list - add physical eraseblock to a list. | 99 | * add_to_list - add physical eraseblock to a list. |
103 | * @si: scanning information | 100 | * @ai: attaching information |
104 | * @pnum: physical eraseblock number to add | 101 | * @pnum: physical eraseblock number to add |
102 | * @vol_id: the last used volume id for the PEB | ||
103 | * @lnum: the last used LEB number for the PEB | ||
105 | * @ec: erase counter of the physical eraseblock | 104 | * @ec: erase counter of the physical eraseblock |
106 | * @to_head: if not zero, add to the head of the list | 105 | * @to_head: if not zero, add to the head of the list |
107 | * @list: the list to add to | 106 | * @list: the list to add to |
108 | * | 107 | * |
109 | * This function adds physical eraseblock @pnum to free, erase, or alien lists. | 108 | * This function allocates a 'struct ubi_ainf_peb' object for physical |
109 | * eraseblock @pnum and adds it to the "free", "erase", or "alien" lists. | ||
110 | * It stores the @lnum and @vol_id alongside, which can both be | ||
111 | * %UBI_UNKNOWN if they are not available, not readable, or not assigned. | ||
110 | * If @to_head is not zero, PEB will be added to the head of the list, which | 112 | * If @to_head is not zero, PEB will be added to the head of the list, which |
111 | * basically means it will be processed first later. E.g., we add corrupted | 113 | * basically means it will be processed first later. E.g., we add corrupted |
112 | * PEBs (corrupted due to power cuts) to the head of the erase list to make | 114 | * PEBs (corrupted due to power cuts) to the head of the erase list to make |
@@ -114,65 +116,68 @@ static struct ubi_vid_hdr *vidh; | |||
114 | * returns zero in case of success and a negative error code in case of | 116 | * returns zero in case of success and a negative error code in case of |
115 | * failure. | 117 | * failure. |
116 | */ | 118 | */ |
117 | static int add_to_list(struct ubi_scan_info *si, int pnum, int ec, int to_head, | 119 | static int add_to_list(struct ubi_attach_info *ai, int pnum, int vol_id, |
118 | struct list_head *list) | 120 | int lnum, int ec, int to_head, struct list_head *list) |
119 | { | 121 | { |
120 | struct ubi_scan_leb *seb; | 122 | struct ubi_ainf_peb *aeb; |
121 | 123 | ||
122 | if (list == &si->free) { | 124 | if (list == &ai->free) { |
123 | dbg_bld("add to free: PEB %d, EC %d", pnum, ec); | 125 | dbg_bld("add to free: PEB %d, EC %d", pnum, ec); |
124 | } else if (list == &si->erase) { | 126 | } else if (list == &ai->erase) { |
125 | dbg_bld("add to erase: PEB %d, EC %d", pnum, ec); | 127 | dbg_bld("add to erase: PEB %d, EC %d", pnum, ec); |
126 | } else if (list == &si->alien) { | 128 | } else if (list == &ai->alien) { |
127 | dbg_bld("add to alien: PEB %d, EC %d", pnum, ec); | 129 | dbg_bld("add to alien: PEB %d, EC %d", pnum, ec); |
128 | si->alien_peb_count += 1; | 130 | ai->alien_peb_count += 1; |
129 | } else | 131 | } else |
130 | BUG(); | 132 | BUG(); |
131 | 133 | ||
132 | seb = kmem_cache_alloc(si->scan_leb_slab, GFP_KERNEL); | 134 | aeb = kmem_cache_alloc(ai->aeb_slab_cache, GFP_KERNEL); |
133 | if (!seb) | 135 | if (!aeb) |
134 | return -ENOMEM; | 136 | return -ENOMEM; |
135 | 137 | ||
136 | seb->pnum = pnum; | 138 | aeb->pnum = pnum; |
137 | seb->ec = ec; | 139 | aeb->vol_id = vol_id; |
140 | aeb->lnum = lnum; | ||
141 | aeb->ec = ec; | ||
138 | if (to_head) | 142 | if (to_head) |
139 | list_add(&seb->u.list, list); | 143 | list_add(&aeb->u.list, list); |
140 | else | 144 | else |
141 | list_add_tail(&seb->u.list, list); | 145 | list_add_tail(&aeb->u.list, list); |
142 | return 0; | 146 | return 0; |
143 | } | 147 | } |
144 | 148 | ||
145 | /** | 149 | /** |
146 | * add_corrupted - add a corrupted physical eraseblock. | 150 | * add_corrupted - add a corrupted physical eraseblock. |
147 | * @si: scanning information | 151 | * @ai: attaching information |
148 | * @pnum: physical eraseblock number to add | 152 | * @pnum: physical eraseblock number to add |
149 | * @ec: erase counter of the physical eraseblock | 153 | * @ec: erase counter of the physical eraseblock |
150 | * | 154 | * |
151 | * This function adds corrupted physical eraseblock @pnum to the 'corr' list. | 155 | * This function allocates a 'struct ubi_ainf_peb' object for a corrupted |
152 | * The corruption was presumably not caused by a power cut. Returns zero in | 156 | * physical eraseblock @pnum and adds it to the 'corr' list. The corruption |
153 | * case of success and a negative error code in case of failure. | 157 | * was presumably not caused by a power cut. Returns zero in case of success |
158 | * and a negative error code in case of failure. | ||
154 | */ | 159 | */ |
155 | static int add_corrupted(struct ubi_scan_info *si, int pnum, int ec) | 160 | static int add_corrupted(struct ubi_attach_info *ai, int pnum, int ec) |
156 | { | 161 | { |
157 | struct ubi_scan_leb *seb; | 162 | struct ubi_ainf_peb *aeb; |
158 | 163 | ||
159 | dbg_bld("add to corrupted: PEB %d, EC %d", pnum, ec); | 164 | dbg_bld("add to corrupted: PEB %d, EC %d", pnum, ec); |
160 | 165 | ||
161 | seb = kmem_cache_alloc(si->scan_leb_slab, GFP_KERNEL); | 166 | aeb = kmem_cache_alloc(ai->aeb_slab_cache, GFP_KERNEL); |
162 | if (!seb) | 167 | if (!aeb) |
163 | return -ENOMEM; | 168 | return -ENOMEM; |
164 | 169 | ||
165 | si->corr_peb_count += 1; | 170 | ai->corr_peb_count += 1; |
166 | seb->pnum = pnum; | 171 | aeb->pnum = pnum; |
167 | seb->ec = ec; | 172 | aeb->ec = ec; |
168 | list_add(&seb->u.list, &si->corr); | 173 | list_add(&aeb->u.list, &ai->corr); |
169 | return 0; | 174 | return 0; |
170 | } | 175 | } |
171 | 176 | ||
172 | /** | 177 | /** |
173 | * validate_vid_hdr - check volume identifier header. | 178 | * validate_vid_hdr - check volume identifier header. |
174 | * @vid_hdr: the volume identifier header to check | 179 | * @vid_hdr: the volume identifier header to check |
175 | * @sv: information about the volume this logical eraseblock belongs to | 180 | * @av: information about the volume this logical eraseblock belongs to |
176 | * @pnum: physical eraseblock number the VID header came from | 181 | * @pnum: physical eraseblock number the VID header came from |
177 | * | 182 | * |
178 | * This function checks that data stored in @vid_hdr is consistent. Returns | 183 | * This function checks that data stored in @vid_hdr is consistent. Returns |
@@ -184,15 +189,15 @@ static int add_corrupted(struct ubi_scan_info *si, int pnum, int ec) | |||
184 | * headers of the same volume. | 189 | * headers of the same volume. |
185 | */ | 190 | */ |
186 | static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr, | 191 | static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr, |
187 | const struct ubi_scan_volume *sv, int pnum) | 192 | const struct ubi_ainf_volume *av, int pnum) |
188 | { | 193 | { |
189 | int vol_type = vid_hdr->vol_type; | 194 | int vol_type = vid_hdr->vol_type; |
190 | int vol_id = be32_to_cpu(vid_hdr->vol_id); | 195 | int vol_id = be32_to_cpu(vid_hdr->vol_id); |
191 | int used_ebs = be32_to_cpu(vid_hdr->used_ebs); | 196 | int used_ebs = be32_to_cpu(vid_hdr->used_ebs); |
192 | int data_pad = be32_to_cpu(vid_hdr->data_pad); | 197 | int data_pad = be32_to_cpu(vid_hdr->data_pad); |
193 | 198 | ||
194 | if (sv->leb_count != 0) { | 199 | if (av->leb_count != 0) { |
195 | int sv_vol_type; | 200 | int av_vol_type; |
196 | 201 | ||
197 | /* | 202 | /* |
198 | * This is not the first logical eraseblock belonging to this | 203 | * This is not the first logical eraseblock belonging to this |
@@ -200,28 +205,28 @@ static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr, | |||
200 | * to the data in previous logical eraseblock headers. | 205 | * to the data in previous logical eraseblock headers. |
201 | */ | 206 | */ |
202 | 207 | ||
203 | if (vol_id != sv->vol_id) { | 208 | if (vol_id != av->vol_id) { |
204 | dbg_err("inconsistent vol_id"); | 209 | ubi_err("inconsistent vol_id"); |
205 | goto bad; | 210 | goto bad; |
206 | } | 211 | } |
207 | 212 | ||
208 | if (sv->vol_type == UBI_STATIC_VOLUME) | 213 | if (av->vol_type == UBI_STATIC_VOLUME) |
209 | sv_vol_type = UBI_VID_STATIC; | 214 | av_vol_type = UBI_VID_STATIC; |
210 | else | 215 | else |
211 | sv_vol_type = UBI_VID_DYNAMIC; | 216 | av_vol_type = UBI_VID_DYNAMIC; |
212 | 217 | ||
213 | if (vol_type != sv_vol_type) { | 218 | if (vol_type != av_vol_type) { |
214 | dbg_err("inconsistent vol_type"); | 219 | ubi_err("inconsistent vol_type"); |
215 | goto bad; | 220 | goto bad; |
216 | } | 221 | } |
217 | 222 | ||
218 | if (used_ebs != sv->used_ebs) { | 223 | if (used_ebs != av->used_ebs) { |
219 | dbg_err("inconsistent used_ebs"); | 224 | ubi_err("inconsistent used_ebs"); |
220 | goto bad; | 225 | goto bad; |
221 | } | 226 | } |
222 | 227 | ||
223 | if (data_pad != sv->data_pad) { | 228 | if (data_pad != av->data_pad) { |
224 | dbg_err("inconsistent data_pad"); | 229 | ubi_err("inconsistent data_pad"); |
225 | goto bad; | 230 | goto bad; |
226 | } | 231 | } |
227 | } | 232 | } |
@@ -230,74 +235,74 @@ static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr, | |||
230 | 235 | ||
231 | bad: | 236 | bad: |
232 | ubi_err("inconsistent VID header at PEB %d", pnum); | 237 | ubi_err("inconsistent VID header at PEB %d", pnum); |
233 | ubi_dbg_dump_vid_hdr(vid_hdr); | 238 | ubi_dump_vid_hdr(vid_hdr); |
234 | ubi_dbg_dump_sv(sv); | 239 | ubi_dump_av(av); |
235 | return -EINVAL; | 240 | return -EINVAL; |
236 | } | 241 | } |
237 | 242 | ||
238 | /** | 243 | /** |
239 | * add_volume - add volume to the scanning information. | 244 | * add_volume - add volume to the attaching information. |
240 | * @si: scanning information | 245 | * @ai: attaching information |
241 | * @vol_id: ID of the volume to add | 246 | * @vol_id: ID of the volume to add |
242 | * @pnum: physical eraseblock number | 247 | * @pnum: physical eraseblock number |
243 | * @vid_hdr: volume identifier header | 248 | * @vid_hdr: volume identifier header |
244 | * | 249 | * |
245 | * If the volume corresponding to the @vid_hdr logical eraseblock is already | 250 | * If the volume corresponding to the @vid_hdr logical eraseblock is already |
246 | * present in the scanning information, this function does nothing. Otherwise | 251 | * present in the attaching information, this function does nothing. Otherwise |
247 | * it adds corresponding volume to the scanning information. Returns a pointer | 252 | * it adds corresponding volume to the attaching information. Returns a pointer |
248 | * to the scanning volume object in case of success and a negative error code | 253 | * to the allocated "av" object in case of success and a negative error code in |
249 | * in case of failure. | 254 | * case of failure. |
250 | */ | 255 | */ |
251 | static struct ubi_scan_volume *add_volume(struct ubi_scan_info *si, int vol_id, | 256 | static struct ubi_ainf_volume *add_volume(struct ubi_attach_info *ai, |
252 | int pnum, | 257 | int vol_id, int pnum, |
253 | const struct ubi_vid_hdr *vid_hdr) | 258 | const struct ubi_vid_hdr *vid_hdr) |
254 | { | 259 | { |
255 | struct ubi_scan_volume *sv; | 260 | struct ubi_ainf_volume *av; |
256 | struct rb_node **p = &si->volumes.rb_node, *parent = NULL; | 261 | struct rb_node **p = &ai->volumes.rb_node, *parent = NULL; |
257 | 262 | ||
258 | ubi_assert(vol_id == be32_to_cpu(vid_hdr->vol_id)); | 263 | ubi_assert(vol_id == be32_to_cpu(vid_hdr->vol_id)); |
259 | 264 | ||
260 | /* Walk the volume RB-tree to look if this volume is already present */ | 265 | /* Walk the volume RB-tree to look if this volume is already present */ |
261 | while (*p) { | 266 | while (*p) { |
262 | parent = *p; | 267 | parent = *p; |
263 | sv = rb_entry(parent, struct ubi_scan_volume, rb); | 268 | av = rb_entry(parent, struct ubi_ainf_volume, rb); |
264 | 269 | ||
265 | if (vol_id == sv->vol_id) | 270 | if (vol_id == av->vol_id) |
266 | return sv; | 271 | return av; |
267 | 272 | ||
268 | if (vol_id > sv->vol_id) | 273 | if (vol_id > av->vol_id) |
269 | p = &(*p)->rb_left; | 274 | p = &(*p)->rb_left; |
270 | else | 275 | else |
271 | p = &(*p)->rb_right; | 276 | p = &(*p)->rb_right; |
272 | } | 277 | } |
273 | 278 | ||
274 | /* The volume is absent - add it */ | 279 | /* The volume is absent - add it */ |
275 | sv = kmalloc(sizeof(struct ubi_scan_volume), GFP_KERNEL); | 280 | av = kmalloc(sizeof(struct ubi_ainf_volume), GFP_KERNEL); |
276 | if (!sv) | 281 | if (!av) |
277 | return ERR_PTR(-ENOMEM); | 282 | return ERR_PTR(-ENOMEM); |
278 | 283 | ||
279 | sv->highest_lnum = sv->leb_count = 0; | 284 | av->highest_lnum = av->leb_count = 0; |
280 | sv->vol_id = vol_id; | 285 | av->vol_id = vol_id; |
281 | sv->root = RB_ROOT; | 286 | av->root = RB_ROOT; |
282 | sv->used_ebs = be32_to_cpu(vid_hdr->used_ebs); | 287 | av->used_ebs = be32_to_cpu(vid_hdr->used_ebs); |
283 | sv->data_pad = be32_to_cpu(vid_hdr->data_pad); | 288 | av->data_pad = be32_to_cpu(vid_hdr->data_pad); |
284 | sv->compat = vid_hdr->compat; | 289 | av->compat = vid_hdr->compat; |
285 | sv->vol_type = vid_hdr->vol_type == UBI_VID_DYNAMIC ? UBI_DYNAMIC_VOLUME | 290 | av->vol_type = vid_hdr->vol_type == UBI_VID_DYNAMIC ? UBI_DYNAMIC_VOLUME |
286 | : UBI_STATIC_VOLUME; | 291 | : UBI_STATIC_VOLUME; |
287 | if (vol_id > si->highest_vol_id) | 292 | if (vol_id > ai->highest_vol_id) |
288 | si->highest_vol_id = vol_id; | 293 | ai->highest_vol_id = vol_id; |
289 | 294 | ||
290 | rb_link_node(&sv->rb, parent, p); | 295 | rb_link_node(&av->rb, parent, p); |
291 | rb_insert_color(&sv->rb, &si->volumes); | 296 | rb_insert_color(&av->rb, &ai->volumes); |
292 | si->vols_found += 1; | 297 | ai->vols_found += 1; |
293 | dbg_bld("added volume %d", vol_id); | 298 | dbg_bld("added volume %d", vol_id); |
294 | return sv; | 299 | return av; |
295 | } | 300 | } |
296 | 301 | ||
297 | /** | 302 | /** |
298 | * compare_lebs - find out which logical eraseblock is newer. | 303 | * compare_lebs - find out which logical eraseblock is newer. |
299 | * @ubi: UBI device description object | 304 | * @ubi: UBI device description object |
300 | * @seb: first logical eraseblock to compare | 305 | * @aeb: first logical eraseblock to compare |
301 | * @pnum: physical eraseblock number of the second logical eraseblock to | 306 | * @pnum: physical eraseblock number of the second logical eraseblock to |
302 | * compare | 307 | * compare |
303 | * @vid_hdr: volume identifier header of the second logical eraseblock | 308 | * @vid_hdr: volume identifier header of the second logical eraseblock |
@@ -306,7 +311,7 @@ static struct ubi_scan_volume *add_volume(struct ubi_scan_info *si, int vol_id, | |||
306 | * case of success this function returns a positive value, in case of failure, a | 311 | * case of success this function returns a positive value, in case of failure, a |
307 | * negative error code is returned. The success return codes use the following | 312 | * negative error code is returned. The success return codes use the following |
308 | * bits: | 313 | * bits: |
309 | * o bit 0 is cleared: the first PEB (described by @seb) is newer than the | 314 | * o bit 0 is cleared: the first PEB (described by @aeb) is newer than the |
310 | * second PEB (described by @pnum and @vid_hdr); | 315 | * second PEB (described by @pnum and @vid_hdr); |
311 | * o bit 0 is set: the second PEB is newer; | 316 | * o bit 0 is set: the second PEB is newer; |
312 | * o bit 1 is cleared: no bit-flips were detected in the newer LEB; | 317 | * o bit 1 is cleared: no bit-flips were detected in the newer LEB; |
@@ -314,7 +319,7 @@ static struct ubi_scan_volume *add_volume(struct ubi_scan_info *si, int vol_id, | |||
314 | * o bit 2 is cleared: the older LEB is not corrupted; | 319 | * o bit 2 is cleared: the older LEB is not corrupted; |
315 | * o bit 2 is set: the older LEB is corrupted. | 320 | * o bit 2 is set: the older LEB is corrupted. |
316 | */ | 321 | */ |
317 | static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb, | 322 | static int compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb, |
318 | int pnum, const struct ubi_vid_hdr *vid_hdr) | 323 | int pnum, const struct ubi_vid_hdr *vid_hdr) |
319 | { | 324 | { |
320 | void *buf; | 325 | void *buf; |
@@ -323,7 +328,7 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb, | |||
323 | struct ubi_vid_hdr *vh = NULL; | 328 | struct ubi_vid_hdr *vh = NULL; |
324 | unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); | 329 | unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); |
325 | 330 | ||
326 | if (sqnum2 == seb->sqnum) { | 331 | if (sqnum2 == aeb->sqnum) { |
327 | /* | 332 | /* |
328 | * This must be a really ancient UBI image which has been | 333 | * This must be a really ancient UBI image which has been |
329 | * created before sequence numbers support has been added. At | 334 | * created before sequence numbers support has been added. At |
@@ -337,7 +342,7 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb, | |||
337 | } | 342 | } |
338 | 343 | ||
339 | /* Obviously the LEB with lower sequence counter is older */ | 344 | /* Obviously the LEB with lower sequence counter is older */ |
340 | second_is_newer = !!(sqnum2 > seb->sqnum); | 345 | second_is_newer = (sqnum2 > aeb->sqnum); |
341 | 346 | ||
342 | /* | 347 | /* |
343 | * Now we know which copy is newer. If the copy flag of the PEB with | 348 | * Now we know which copy is newer. If the copy flag of the PEB with |
@@ -356,7 +361,7 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb, | |||
356 | return 1; | 361 | return 1; |
357 | } | 362 | } |
358 | } else { | 363 | } else { |
359 | if (!seb->copy_flag) { | 364 | if (!aeb->copy_flag) { |
360 | /* It is not a copy, so it is newer */ | 365 | /* It is not a copy, so it is newer */ |
361 | dbg_bld("first PEB %d is newer, copy_flag is unset", | 366 | dbg_bld("first PEB %d is newer, copy_flag is unset", |
362 | pnum); | 367 | pnum); |
@@ -367,13 +372,13 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb, | |||
367 | if (!vh) | 372 | if (!vh) |
368 | return -ENOMEM; | 373 | return -ENOMEM; |
369 | 374 | ||
370 | pnum = seb->pnum; | 375 | pnum = aeb->pnum; |
371 | err = ubi_io_read_vid_hdr(ubi, pnum, vh, 0); | 376 | err = ubi_io_read_vid_hdr(ubi, pnum, vh, 0); |
372 | if (err) { | 377 | if (err) { |
373 | if (err == UBI_IO_BITFLIPS) | 378 | if (err == UBI_IO_BITFLIPS) |
374 | bitflips = 1; | 379 | bitflips = 1; |
375 | else { | 380 | else { |
376 | dbg_err("VID of PEB %d header is bad, but it " | 381 | ubi_err("VID of PEB %d header is bad, but it " |
377 | "was OK earlier, err %d", pnum, err); | 382 | "was OK earlier, err %d", pnum, err); |
378 | if (err > 0) | 383 | if (err > 0) |
379 | err = -EIO; | 384 | err = -EIO; |
@@ -429,9 +434,9 @@ out_free_vidh: | |||
429 | } | 434 | } |
430 | 435 | ||
431 | /** | 436 | /** |
432 | * ubi_scan_add_used - add physical eraseblock to the scanning information. | 437 | * ubi_add_to_av - add used physical eraseblock to the attaching information. |
433 | * @ubi: UBI device description object | 438 | * @ubi: UBI device description object |
434 | * @si: scanning information | 439 | * @ai: attaching information |
435 | * @pnum: the physical eraseblock number | 440 | * @pnum: the physical eraseblock number |
436 | * @ec: erase counter | 441 | * @ec: erase counter |
437 | * @vid_hdr: the volume identifier header | 442 | * @vid_hdr: the volume identifier header |
@@ -444,14 +449,13 @@ out_free_vidh: | |||
444 | * to be picked, while the older one has to be dropped. This function returns | 449 | * to be picked, while the older one has to be dropped. This function returns |
445 | * zero in case of success and a negative error code in case of failure. | 450 | * zero in case of success and a negative error code in case of failure. |
446 | */ | 451 | */ |
447 | int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | 452 | int ubi_add_to_av(struct ubi_device *ubi, struct ubi_attach_info *ai, int pnum, |
448 | int pnum, int ec, const struct ubi_vid_hdr *vid_hdr, | 453 | int ec, const struct ubi_vid_hdr *vid_hdr, int bitflips) |
449 | int bitflips) | ||
450 | { | 454 | { |
451 | int err, vol_id, lnum; | 455 | int err, vol_id, lnum; |
452 | unsigned long long sqnum; | 456 | unsigned long long sqnum; |
453 | struct ubi_scan_volume *sv; | 457 | struct ubi_ainf_volume *av; |
454 | struct ubi_scan_leb *seb; | 458 | struct ubi_ainf_peb *aeb; |
455 | struct rb_node **p, *parent = NULL; | 459 | struct rb_node **p, *parent = NULL; |
456 | 460 | ||
457 | vol_id = be32_to_cpu(vid_hdr->vol_id); | 461 | vol_id = be32_to_cpu(vid_hdr->vol_id); |
@@ -461,25 +465,25 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
461 | dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, bitflips %d", | 465 | dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, bitflips %d", |
462 | pnum, vol_id, lnum, ec, sqnum, bitflips); | 466 | pnum, vol_id, lnum, ec, sqnum, bitflips); |
463 | 467 | ||
464 | sv = add_volume(si, vol_id, pnum, vid_hdr); | 468 | av = add_volume(ai, vol_id, pnum, vid_hdr); |
465 | if (IS_ERR(sv)) | 469 | if (IS_ERR(av)) |
466 | return PTR_ERR(sv); | 470 | return PTR_ERR(av); |
467 | 471 | ||
468 | if (si->max_sqnum < sqnum) | 472 | if (ai->max_sqnum < sqnum) |
469 | si->max_sqnum = sqnum; | 473 | ai->max_sqnum = sqnum; |
470 | 474 | ||
471 | /* | 475 | /* |
472 | * Walk the RB-tree of logical eraseblocks of volume @vol_id to look | 476 | * Walk the RB-tree of logical eraseblocks of volume @vol_id to look |
473 | * if this is the first instance of this logical eraseblock or not. | 477 | * if this is the first instance of this logical eraseblock or not. |
474 | */ | 478 | */ |
475 | p = &sv->root.rb_node; | 479 | p = &av->root.rb_node; |
476 | while (*p) { | 480 | while (*p) { |
477 | int cmp_res; | 481 | int cmp_res; |
478 | 482 | ||
479 | parent = *p; | 483 | parent = *p; |
480 | seb = rb_entry(parent, struct ubi_scan_leb, u.rb); | 484 | aeb = rb_entry(parent, struct ubi_ainf_peb, u.rb); |
481 | if (lnum != seb->lnum) { | 485 | if (lnum != aeb->lnum) { |
482 | if (lnum < seb->lnum) | 486 | if (lnum < aeb->lnum) |
483 | p = &(*p)->rb_left; | 487 | p = &(*p)->rb_left; |
484 | else | 488 | else |
485 | p = &(*p)->rb_right; | 489 | p = &(*p)->rb_right; |
@@ -491,8 +495,8 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
491 | * logical eraseblock present. | 495 | * logical eraseblock present. |
492 | */ | 496 | */ |
493 | 497 | ||
494 | dbg_bld("this LEB already exists: PEB %d, sqnum %llu, " | 498 | dbg_bld("this LEB already exists: PEB %d, sqnum %llu, EC %d", |
495 | "EC %d", seb->pnum, seb->sqnum, seb->ec); | 499 | aeb->pnum, aeb->sqnum, aeb->ec); |
496 | 500 | ||
497 | /* | 501 | /* |
498 | * Make sure that the logical eraseblocks have different | 502 | * Make sure that the logical eraseblocks have different |
@@ -507,11 +511,11 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
507 | * images, but refuse attaching old images with duplicated | 511 | * images, but refuse attaching old images with duplicated |
508 | * logical eraseblocks because there was an unclean reboot. | 512 | * logical eraseblocks because there was an unclean reboot. |
509 | */ | 513 | */ |
510 | if (seb->sqnum == sqnum && sqnum != 0) { | 514 | if (aeb->sqnum == sqnum && sqnum != 0) { |
511 | ubi_err("two LEBs with same sequence number %llu", | 515 | ubi_err("two LEBs with same sequence number %llu", |
512 | sqnum); | 516 | sqnum); |
513 | ubi_dbg_dump_seb(seb, 0); | 517 | ubi_dump_aeb(aeb, 0); |
514 | ubi_dbg_dump_vid_hdr(vid_hdr); | 518 | ubi_dump_vid_hdr(vid_hdr); |
515 | return -EINVAL; | 519 | return -EINVAL; |
516 | } | 520 | } |
517 | 521 | ||
@@ -519,7 +523,7 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
519 | * Now we have to drop the older one and preserve the newer | 523 | * Now we have to drop the older one and preserve the newer |
520 | * one. | 524 | * one. |
521 | */ | 525 | */ |
522 | cmp_res = compare_lebs(ubi, seb, pnum, vid_hdr); | 526 | cmp_res = compare_lebs(ubi, aeb, pnum, vid_hdr); |
523 | if (cmp_res < 0) | 527 | if (cmp_res < 0) |
524 | return cmp_res; | 528 | return cmp_res; |
525 | 529 | ||
@@ -528,23 +532,26 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
528 | * This logical eraseblock is newer than the one | 532 | * This logical eraseblock is newer than the one |
529 | * found earlier. | 533 | * found earlier. |
530 | */ | 534 | */ |
531 | err = validate_vid_hdr(vid_hdr, sv, pnum); | 535 | err = validate_vid_hdr(vid_hdr, av, pnum); |
532 | if (err) | 536 | if (err) |
533 | return err; | 537 | return err; |
534 | 538 | ||
535 | err = add_to_list(si, seb->pnum, seb->ec, cmp_res & 4, | 539 | err = add_to_list(ai, aeb->pnum, aeb->vol_id, |
536 | &si->erase); | 540 | aeb->lnum, aeb->ec, cmp_res & 4, |
541 | &ai->erase); | ||
537 | if (err) | 542 | if (err) |
538 | return err; | 543 | return err; |
539 | 544 | ||
540 | seb->ec = ec; | 545 | aeb->ec = ec; |
541 | seb->pnum = pnum; | 546 | aeb->pnum = pnum; |
542 | seb->scrub = ((cmp_res & 2) || bitflips); | 547 | aeb->vol_id = vol_id; |
543 | seb->copy_flag = vid_hdr->copy_flag; | 548 | aeb->lnum = lnum; |
544 | seb->sqnum = sqnum; | 549 | aeb->scrub = ((cmp_res & 2) || bitflips); |
550 | aeb->copy_flag = vid_hdr->copy_flag; | ||
551 | aeb->sqnum = sqnum; | ||
545 | 552 | ||
546 | if (sv->highest_lnum == lnum) | 553 | if (av->highest_lnum == lnum) |
547 | sv->last_data_size = | 554 | av->last_data_size = |
548 | be32_to_cpu(vid_hdr->data_size); | 555 | be32_to_cpu(vid_hdr->data_size); |
549 | 556 | ||
550 | return 0; | 557 | return 0; |
@@ -553,92 +560,64 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
553 | * This logical eraseblock is older than the one found | 560 | * This logical eraseblock is older than the one found |
554 | * previously. | 561 | * previously. |
555 | */ | 562 | */ |
556 | return add_to_list(si, pnum, ec, cmp_res & 4, | 563 | return add_to_list(ai, pnum, vol_id, lnum, ec, |
557 | &si->erase); | 564 | cmp_res & 4, &ai->erase); |
558 | } | 565 | } |
559 | } | 566 | } |
560 | 567 | ||
561 | /* | 568 | /* |
562 | * We've met this logical eraseblock for the first time, add it to the | 569 | * We've met this logical eraseblock for the first time, add it to the |
563 | * scanning information. | 570 | * attaching information. |
564 | */ | 571 | */ |
565 | 572 | ||
566 | err = validate_vid_hdr(vid_hdr, sv, pnum); | 573 | err = validate_vid_hdr(vid_hdr, av, pnum); |
567 | if (err) | 574 | if (err) |
568 | return err; | 575 | return err; |
569 | 576 | ||
570 | seb = kmem_cache_alloc(si->scan_leb_slab, GFP_KERNEL); | 577 | aeb = kmem_cache_alloc(ai->aeb_slab_cache, GFP_KERNEL); |
571 | if (!seb) | 578 | if (!aeb) |
572 | return -ENOMEM; | 579 | return -ENOMEM; |
573 | 580 | ||
574 | seb->ec = ec; | 581 | aeb->ec = ec; |
575 | seb->pnum = pnum; | 582 | aeb->pnum = pnum; |
576 | seb->lnum = lnum; | 583 | aeb->vol_id = vol_id; |
577 | seb->scrub = bitflips; | 584 | aeb->lnum = lnum; |
578 | seb->copy_flag = vid_hdr->copy_flag; | 585 | aeb->scrub = bitflips; |
579 | seb->sqnum = sqnum; | 586 | aeb->copy_flag = vid_hdr->copy_flag; |
580 | 587 | aeb->sqnum = sqnum; | |
581 | if (sv->highest_lnum <= lnum) { | 588 | |
582 | sv->highest_lnum = lnum; | 589 | if (av->highest_lnum <= lnum) { |
583 | sv->last_data_size = be32_to_cpu(vid_hdr->data_size); | 590 | av->highest_lnum = lnum; |
591 | av->last_data_size = be32_to_cpu(vid_hdr->data_size); | ||
584 | } | 592 | } |
585 | 593 | ||
586 | sv->leb_count += 1; | 594 | av->leb_count += 1; |
587 | rb_link_node(&seb->u.rb, parent, p); | 595 | rb_link_node(&aeb->u.rb, parent, p); |
588 | rb_insert_color(&seb->u.rb, &sv->root); | 596 | rb_insert_color(&aeb->u.rb, &av->root); |
589 | return 0; | 597 | return 0; |
590 | } | 598 | } |
591 | 599 | ||
592 | /** | 600 | /** |
593 | * ubi_scan_find_sv - find volume in the scanning information. | 601 | * ubi_find_av - find volume in the attaching information. |
594 | * @si: scanning information | 602 | * @ai: attaching information |
595 | * @vol_id: the requested volume ID | 603 | * @vol_id: the requested volume ID |
596 | * | 604 | * |
597 | * This function returns a pointer to the volume description or %NULL if there | 605 | * This function returns a pointer to the volume description or %NULL if there |
598 | * are no data about this volume in the scanning information. | 606 | * are no data about this volume in the attaching information. |
599 | */ | ||
600 | struct ubi_scan_volume *ubi_scan_find_sv(const struct ubi_scan_info *si, | ||
601 | int vol_id) | ||
602 | { | ||
603 | struct ubi_scan_volume *sv; | ||
604 | struct rb_node *p = si->volumes.rb_node; | ||
605 | |||
606 | while (p) { | ||
607 | sv = rb_entry(p, struct ubi_scan_volume, rb); | ||
608 | |||
609 | if (vol_id == sv->vol_id) | ||
610 | return sv; | ||
611 | |||
612 | if (vol_id > sv->vol_id) | ||
613 | p = p->rb_left; | ||
614 | else | ||
615 | p = p->rb_right; | ||
616 | } | ||
617 | |||
618 | return NULL; | ||
619 | } | ||
620 | |||
621 | /** | ||
622 | * ubi_scan_find_seb - find LEB in the volume scanning information. | ||
623 | * @sv: a pointer to the volume scanning information | ||
624 | * @lnum: the requested logical eraseblock | ||
625 | * | ||
626 | * This function returns a pointer to the scanning logical eraseblock or %NULL | ||
627 | * if there are no data about it in the scanning volume information. | ||
628 | */ | 607 | */ |
629 | struct ubi_scan_leb *ubi_scan_find_seb(const struct ubi_scan_volume *sv, | 608 | struct ubi_ainf_volume *ubi_find_av(const struct ubi_attach_info *ai, |
630 | int lnum) | 609 | int vol_id) |
631 | { | 610 | { |
632 | struct ubi_scan_leb *seb; | 611 | struct ubi_ainf_volume *av; |
633 | struct rb_node *p = sv->root.rb_node; | 612 | struct rb_node *p = ai->volumes.rb_node; |
634 | 613 | ||
635 | while (p) { | 614 | while (p) { |
636 | seb = rb_entry(p, struct ubi_scan_leb, u.rb); | 615 | av = rb_entry(p, struct ubi_ainf_volume, rb); |
637 | 616 | ||
638 | if (lnum == seb->lnum) | 617 | if (vol_id == av->vol_id) |
639 | return seb; | 618 | return av; |
640 | 619 | ||
641 | if (lnum > seb->lnum) | 620 | if (vol_id > av->vol_id) |
642 | p = p->rb_left; | 621 | p = p->rb_left; |
643 | else | 622 | else |
644 | p = p->rb_right; | 623 | p = p->rb_right; |
@@ -648,34 +627,34 @@ struct ubi_scan_leb *ubi_scan_find_seb(const struct ubi_scan_volume *sv, | |||
648 | } | 627 | } |
649 | 628 | ||
650 | /** | 629 | /** |
651 | * ubi_scan_rm_volume - delete scanning information about a volume. | 630 | * ubi_remove_av - delete attaching information about a volume. |
652 | * @si: scanning information | 631 | * @ai: attaching information |
653 | * @sv: the volume scanning information to delete | 632 | * @av: the volume attaching information to delete |
654 | */ | 633 | */ |
655 | void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv) | 634 | void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av) |
656 | { | 635 | { |
657 | struct rb_node *rb; | 636 | struct rb_node *rb; |
658 | struct ubi_scan_leb *seb; | 637 | struct ubi_ainf_peb *aeb; |
659 | 638 | ||
660 | dbg_bld("remove scanning information about volume %d", sv->vol_id); | 639 | dbg_bld("remove attaching information about volume %d", av->vol_id); |
661 | 640 | ||
662 | while ((rb = rb_first(&sv->root))) { | 641 | while ((rb = rb_first(&av->root))) { |
663 | seb = rb_entry(rb, struct ubi_scan_leb, u.rb); | 642 | aeb = rb_entry(rb, struct ubi_ainf_peb, u.rb); |
664 | rb_erase(&seb->u.rb, &sv->root); | 643 | rb_erase(&aeb->u.rb, &av->root); |
665 | list_add_tail(&seb->u.list, &si->erase); | 644 | list_add_tail(&aeb->u.list, &ai->erase); |
666 | } | 645 | } |
667 | 646 | ||
668 | rb_erase(&sv->rb, &si->volumes); | 647 | rb_erase(&av->rb, &ai->volumes); |
669 | kfree(sv); | 648 | kfree(av); |
670 | si->vols_found -= 1; | 649 | ai->vols_found -= 1; |
671 | } | 650 | } |
672 | 651 | ||
673 | /** | 652 | /** |
674 | * ubi_scan_erase_peb - erase a physical eraseblock. | 653 | * early_erase_peb - erase a physical eraseblock. |
675 | * @ubi: UBI device description object | 654 | * @ubi: UBI device description object |
676 | * @si: scanning information | 655 | * @ai: attaching information |
677 | * @pnum: physical eraseblock number to erase; | 656 | * @pnum: physical eraseblock number to erase; |
678 | * @ec: erase counter value to write (%UBI_SCAN_UNKNOWN_EC if it is unknown) | 657 | * @ec: erase counter value to write (%UBI_UNKNOWN if it is unknown) |
679 | * | 658 | * |
680 | * This function erases physical eraseblock 'pnum', and writes the erase | 659 | * This function erases physical eraseblock 'pnum', and writes the erase |
681 | * counter header to it. This function should only be used on UBI device | 660 | * counter header to it. This function should only be used on UBI device |
@@ -683,8 +662,8 @@ void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv) | |||
683 | * This function returns zero in case of success and a negative error code in | 662 | * This function returns zero in case of success and a negative error code in |
684 | * case of failure. | 663 | * case of failure. |
685 | */ | 664 | */ |
686 | int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si, | 665 | static int early_erase_peb(struct ubi_device *ubi, |
687 | int pnum, int ec) | 666 | const struct ubi_attach_info *ai, int pnum, int ec) |
688 | { | 667 | { |
689 | int err; | 668 | int err; |
690 | struct ubi_ec_hdr *ec_hdr; | 669 | struct ubi_ec_hdr *ec_hdr; |
@@ -716,9 +695,9 @@ out_free: | |||
716 | } | 695 | } |
717 | 696 | ||
718 | /** | 697 | /** |
719 | * ubi_scan_get_free_peb - get a free physical eraseblock. | 698 | * ubi_early_get_peb - get a free physical eraseblock. |
720 | * @ubi: UBI device description object | 699 | * @ubi: UBI device description object |
721 | * @si: scanning information | 700 | * @ai: attaching information |
722 | * | 701 | * |
723 | * This function returns a free physical eraseblock. It is supposed to be | 702 | * This function returns a free physical eraseblock. It is supposed to be |
724 | * called on the UBI initialization stages when the wear-leveling sub-system is | 703 | * called on the UBI initialization stages when the wear-leveling sub-system is |
@@ -726,20 +705,20 @@ out_free: | |||
726 | * the lists, writes the EC header if it is needed, and removes it from the | 705 | * the lists, writes the EC header if it is needed, and removes it from the |
727 | * list. | 706 | * list. |
728 | * | 707 | * |
729 | * This function returns scanning physical eraseblock information in case of | 708 | * This function returns a pointer to the "aeb" of the found free PEB in case |
730 | * success and an error code in case of failure. | 709 | * of success and an error code in case of failure. |
731 | */ | 710 | */ |
732 | struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi, | 711 | struct ubi_ainf_peb *ubi_early_get_peb(struct ubi_device *ubi, |
733 | struct ubi_scan_info *si) | 712 | struct ubi_attach_info *ai) |
734 | { | 713 | { |
735 | int err = 0; | 714 | int err = 0; |
736 | struct ubi_scan_leb *seb, *tmp_seb; | 715 | struct ubi_ainf_peb *aeb, *tmp_aeb; |
737 | 716 | ||
738 | if (!list_empty(&si->free)) { | 717 | if (!list_empty(&ai->free)) { |
739 | seb = list_entry(si->free.next, struct ubi_scan_leb, u.list); | 718 | aeb = list_entry(ai->free.next, struct ubi_ainf_peb, u.list); |
740 | list_del(&seb->u.list); | 719 | list_del(&aeb->u.list); |
741 | dbg_bld("return free PEB %d, EC %d", seb->pnum, seb->ec); | 720 | dbg_bld("return free PEB %d, EC %d", aeb->pnum, aeb->ec); |
742 | return seb; | 721 | return aeb; |
743 | } | 722 | } |
744 | 723 | ||
745 | /* | 724 | /* |
@@ -748,18 +727,18 @@ struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi, | |||
748 | * so forth. We don't want to take care about bad eraseblocks here - | 727 | * so forth. We don't want to take care about bad eraseblocks here - |
749 | * they'll be handled later. | 728 | * they'll be handled later. |
750 | */ | 729 | */ |
751 | list_for_each_entry_safe(seb, tmp_seb, &si->erase, u.list) { | 730 | list_for_each_entry_safe(aeb, tmp_aeb, &ai->erase, u.list) { |
752 | if (seb->ec == UBI_SCAN_UNKNOWN_EC) | 731 | if (aeb->ec == UBI_UNKNOWN) |
753 | seb->ec = si->mean_ec; | 732 | aeb->ec = ai->mean_ec; |
754 | 733 | ||
755 | err = ubi_scan_erase_peb(ubi, si, seb->pnum, seb->ec+1); | 734 | err = early_erase_peb(ubi, ai, aeb->pnum, aeb->ec+1); |
756 | if (err) | 735 | if (err) |
757 | continue; | 736 | continue; |
758 | 737 | ||
759 | seb->ec += 1; | 738 | aeb->ec += 1; |
760 | list_del(&seb->u.list); | 739 | list_del(&aeb->u.list); |
761 | dbg_bld("return PEB %d, EC %d", seb->pnum, seb->ec); | 740 | dbg_bld("return PEB %d, EC %d", aeb->pnum, aeb->ec); |
762 | return seb; | 741 | return aeb; |
763 | } | 742 | } |
764 | 743 | ||
765 | ubi_err("no free eraseblocks"); | 744 | ubi_err("no free eraseblocks"); |
@@ -814,7 +793,7 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr, | |||
814 | ubi_err("PEB %d contains corrupted VID header, and the data does not " | 793 | ubi_err("PEB %d contains corrupted VID header, and the data does not " |
815 | "contain all 0xFF, this may be a non-UBI PEB or a severe VID " | 794 | "contain all 0xFF, this may be a non-UBI PEB or a severe VID " |
816 | "header corruption which requires manual inspection", pnum); | 795 | "header corruption which requires manual inspection", pnum); |
817 | ubi_dbg_dump_vid_hdr(vid_hdr); | 796 | ubi_dump_vid_hdr(vid_hdr); |
818 | dbg_msg("hexdump of PEB %d offset %d, length %d", | 797 | dbg_msg("hexdump of PEB %d offset %d, length %d", |
819 | pnum, ubi->leb_start, ubi->leb_size); | 798 | pnum, ubi->leb_start, ubi->leb_size); |
820 | ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | 799 | ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, |
@@ -827,16 +806,18 @@ out_unlock: | |||
827 | } | 806 | } |
828 | 807 | ||
829 | /** | 808 | /** |
830 | * process_eb - read, check UBI headers, and add them to scanning information. | 809 | * scan_peb - scan and process UBI headers of a PEB. |
831 | * @ubi: UBI device description object | 810 | * @ubi: UBI device description object |
832 | * @si: scanning information | 811 | * @ai: attaching information |
833 | * @pnum: the physical eraseblock number | 812 | * @pnum: the physical eraseblock number |
834 | * | 813 | * |
835 | * This function returns a zero if the physical eraseblock was successfully | 814 | * This function reads UBI headers of PEB @pnum, checks them, and adds |
836 | * handled and a negative error code in case of failure. | 815 | * information about this PEB to the corresponding list or RB-tree in the |
816 | * "attaching info" structure. Returns zero if the physical eraseblock was | ||
817 | * successfully handled and a negative error code in case of failure. | ||
837 | */ | 818 | */ |
838 | static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | 819 | static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, |
839 | int pnum) | 820 | int pnum) |
840 | { | 821 | { |
841 | long long uninitialized_var(ec); | 822 | long long uninitialized_var(ec); |
842 | int err, bitflips = 0, vol_id, ec_err = 0; | 823 | int err, bitflips = 0, vol_id, ec_err = 0; |
@@ -848,12 +829,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
848 | if (err < 0) | 829 | if (err < 0) |
849 | return err; | 830 | return err; |
850 | else if (err) { | 831 | else if (err) { |
851 | /* | 832 | ai->bad_peb_count += 1; |
852 | * FIXME: this is actually duty of the I/O sub-system to | ||
853 | * initialize this, but MTD does not provide enough | ||
854 | * information. | ||
855 | */ | ||
856 | si->bad_peb_count += 1; | ||
857 | return 0; | 833 | return 0; |
858 | } | 834 | } |
859 | 835 | ||
@@ -867,13 +843,13 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
867 | bitflips = 1; | 843 | bitflips = 1; |
868 | break; | 844 | break; |
869 | case UBI_IO_FF: | 845 | case UBI_IO_FF: |
870 | si->empty_peb_count += 1; | 846 | ai->empty_peb_count += 1; |
871 | return add_to_list(si, pnum, UBI_SCAN_UNKNOWN_EC, 0, | 847 | return add_to_list(ai, pnum, UBI_UNKNOWN, UBI_UNKNOWN, |
872 | &si->erase); | 848 | UBI_UNKNOWN, 0, &ai->erase); |
873 | case UBI_IO_FF_BITFLIPS: | 849 | case UBI_IO_FF_BITFLIPS: |
874 | si->empty_peb_count += 1; | 850 | ai->empty_peb_count += 1; |
875 | return add_to_list(si, pnum, UBI_SCAN_UNKNOWN_EC, 1, | 851 | return add_to_list(ai, pnum, UBI_UNKNOWN, UBI_UNKNOWN, |
876 | &si->erase); | 852 | UBI_UNKNOWN, 1, &ai->erase); |
877 | case UBI_IO_BAD_HDR_EBADMSG: | 853 | case UBI_IO_BAD_HDR_EBADMSG: |
878 | case UBI_IO_BAD_HDR: | 854 | case UBI_IO_BAD_HDR: |
879 | /* | 855 | /* |
@@ -882,7 +858,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
882 | * moved and EC be re-created. | 858 | * moved and EC be re-created. |
883 | */ | 859 | */ |
884 | ec_err = err; | 860 | ec_err = err; |
885 | ec = UBI_SCAN_UNKNOWN_EC; | 861 | ec = UBI_UNKNOWN; |
886 | bitflips = 1; | 862 | bitflips = 1; |
887 | break; | 863 | break; |
888 | default: | 864 | default: |
@@ -911,7 +887,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
911 | */ | 887 | */ |
912 | ubi_err("erase counter overflow, max is %d", | 888 | ubi_err("erase counter overflow, max is %d", |
913 | UBI_MAX_ERASECOUNTER); | 889 | UBI_MAX_ERASECOUNTER); |
914 | ubi_dbg_dump_ec_hdr(ech); | 890 | ubi_dump_ec_hdr(ech); |
915 | return -EINVAL; | 891 | return -EINVAL; |
916 | } | 892 | } |
917 | 893 | ||
@@ -933,7 +909,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
933 | ubi->image_seq != image_seq) { | 909 | ubi->image_seq != image_seq) { |
934 | ubi_err("bad image sequence number %d in PEB %d, " | 910 | ubi_err("bad image sequence number %d in PEB %d, " |
935 | "expected %d", image_seq, pnum, ubi->image_seq); | 911 | "expected %d", image_seq, pnum, ubi->image_seq); |
936 | ubi_dbg_dump_ec_hdr(ech); | 912 | ubi_dump_ec_hdr(ech); |
937 | return -EINVAL; | 913 | return -EINVAL; |
938 | } | 914 | } |
939 | } | 915 | } |
@@ -957,7 +933,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
957 | * PEB, bit it is not marked as bad yet. This may also | 933 | * PEB, bit it is not marked as bad yet. This may also |
958 | * be a result of power cut during erasure. | 934 | * be a result of power cut during erasure. |
959 | */ | 935 | */ |
960 | si->maybe_bad_peb_count += 1; | 936 | ai->maybe_bad_peb_count += 1; |
961 | case UBI_IO_BAD_HDR: | 937 | case UBI_IO_BAD_HDR: |
962 | if (ec_err) | 938 | if (ec_err) |
963 | /* | 939 | /* |
@@ -984,23 +960,27 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
984 | return err; | 960 | return err; |
985 | else if (!err) | 961 | else if (!err) |
986 | /* This corruption is caused by a power cut */ | 962 | /* This corruption is caused by a power cut */ |
987 | err = add_to_list(si, pnum, ec, 1, &si->erase); | 963 | err = add_to_list(ai, pnum, UBI_UNKNOWN, |
964 | UBI_UNKNOWN, ec, 1, &ai->erase); | ||
988 | else | 965 | else |
989 | /* This is an unexpected corruption */ | 966 | /* This is an unexpected corruption */ |
990 | err = add_corrupted(si, pnum, ec); | 967 | err = add_corrupted(ai, pnum, ec); |
991 | if (err) | 968 | if (err) |
992 | return err; | 969 | return err; |
993 | goto adjust_mean_ec; | 970 | goto adjust_mean_ec; |
994 | case UBI_IO_FF_BITFLIPS: | 971 | case UBI_IO_FF_BITFLIPS: |
995 | err = add_to_list(si, pnum, ec, 1, &si->erase); | 972 | err = add_to_list(ai, pnum, UBI_UNKNOWN, UBI_UNKNOWN, |
973 | ec, 1, &ai->erase); | ||
996 | if (err) | 974 | if (err) |
997 | return err; | 975 | return err; |
998 | goto adjust_mean_ec; | 976 | goto adjust_mean_ec; |
999 | case UBI_IO_FF: | 977 | case UBI_IO_FF: |
1000 | if (ec_err) | 978 | if (ec_err) |
1001 | err = add_to_list(si, pnum, ec, 1, &si->erase); | 979 | err = add_to_list(ai, pnum, UBI_UNKNOWN, |
980 | UBI_UNKNOWN, ec, 1, &ai->erase); | ||
1002 | else | 981 | else |
1003 | err = add_to_list(si, pnum, ec, 0, &si->free); | 982 | err = add_to_list(ai, pnum, UBI_UNKNOWN, |
983 | UBI_UNKNOWN, ec, 0, &ai->free); | ||
1004 | if (err) | 984 | if (err) |
1005 | return err; | 985 | return err; |
1006 | goto adjust_mean_ec; | 986 | goto adjust_mean_ec; |
@@ -1019,7 +999,8 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
1019 | case UBI_COMPAT_DELETE: | 999 | case UBI_COMPAT_DELETE: |
1020 | ubi_msg("\"delete\" compatible internal volume %d:%d" | 1000 | ubi_msg("\"delete\" compatible internal volume %d:%d" |
1021 | " found, will remove it", vol_id, lnum); | 1001 | " found, will remove it", vol_id, lnum); |
1022 | err = add_to_list(si, pnum, ec, 1, &si->erase); | 1002 | err = add_to_list(ai, pnum, vol_id, lnum, |
1003 | ec, 1, &ai->erase); | ||
1023 | if (err) | 1004 | if (err) |
1024 | return err; | 1005 | return err; |
1025 | return 0; | 1006 | return 0; |
@@ -1034,7 +1015,8 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
1034 | case UBI_COMPAT_PRESERVE: | 1015 | case UBI_COMPAT_PRESERVE: |
1035 | ubi_msg("\"preserve\" compatible internal volume %d:%d" | 1016 | ubi_msg("\"preserve\" compatible internal volume %d:%d" |
1036 | " found", vol_id, lnum); | 1017 | " found", vol_id, lnum); |
1037 | err = add_to_list(si, pnum, ec, 0, &si->alien); | 1018 | err = add_to_list(ai, pnum, vol_id, lnum, |
1019 | ec, 0, &ai->alien); | ||
1038 | if (err) | 1020 | if (err) |
1039 | return err; | 1021 | return err; |
1040 | return 0; | 1022 | return 0; |
@@ -1049,40 +1031,40 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
1049 | if (ec_err) | 1031 | if (ec_err) |
1050 | ubi_warn("valid VID header but corrupted EC header at PEB %d", | 1032 | ubi_warn("valid VID header but corrupted EC header at PEB %d", |
1051 | pnum); | 1033 | pnum); |
1052 | err = ubi_scan_add_used(ubi, si, pnum, ec, vidh, bitflips); | 1034 | err = ubi_add_to_av(ubi, ai, pnum, ec, vidh, bitflips); |
1053 | if (err) | 1035 | if (err) |
1054 | return err; | 1036 | return err; |
1055 | 1037 | ||
1056 | adjust_mean_ec: | 1038 | adjust_mean_ec: |
1057 | if (!ec_err) { | 1039 | if (!ec_err) { |
1058 | si->ec_sum += ec; | 1040 | ai->ec_sum += ec; |
1059 | si->ec_count += 1; | 1041 | ai->ec_count += 1; |
1060 | if (ec > si->max_ec) | 1042 | if (ec > ai->max_ec) |
1061 | si->max_ec = ec; | 1043 | ai->max_ec = ec; |
1062 | if (ec < si->min_ec) | 1044 | if (ec < ai->min_ec) |
1063 | si->min_ec = ec; | 1045 | ai->min_ec = ec; |
1064 | } | 1046 | } |
1065 | 1047 | ||
1066 | return 0; | 1048 | return 0; |
1067 | } | 1049 | } |
1068 | 1050 | ||
1069 | /** | 1051 | /** |
1070 | * check_what_we_have - check what PEB were found by scanning. | 1052 | * late_analysis - analyze the overall situation with PEB. |
1071 | * @ubi: UBI device description object | 1053 | * @ubi: UBI device description object |
1072 | * @si: scanning information | 1054 | * @ai: attaching information |
1073 | * | 1055 | * |
1074 | * This is a helper function which takes a look what PEBs were found by | 1056 | * This is a helper function which takes a look what PEBs we have after we |
1075 | * scanning, and decides whether the flash is empty and should be formatted and | 1057 | * gather information about all of them ("ai" is compete). It decides whether |
1076 | * whether there are too many corrupted PEBs and we should not attach this | 1058 | * the flash is empty and should be formatted of whether there are too many |
1077 | * MTD device. Returns zero if we should proceed with attaching the MTD device, | 1059 | * corrupted PEBs and we should not attach this MTD device. Returns zero if we |
1078 | * and %-EINVAL if we should not. | 1060 | * should proceed with attaching the MTD device, and %-EINVAL if we should not. |
1079 | */ | 1061 | */ |
1080 | static int check_what_we_have(struct ubi_device *ubi, struct ubi_scan_info *si) | 1062 | static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai) |
1081 | { | 1063 | { |
1082 | struct ubi_scan_leb *seb; | 1064 | struct ubi_ainf_peb *aeb; |
1083 | int max_corr, peb_count; | 1065 | int max_corr, peb_count; |
1084 | 1066 | ||
1085 | peb_count = ubi->peb_count - si->bad_peb_count - si->alien_peb_count; | 1067 | peb_count = ubi->peb_count - ai->bad_peb_count - ai->alien_peb_count; |
1086 | max_corr = peb_count / 20 ?: 8; | 1068 | max_corr = peb_count / 20 ?: 8; |
1087 | 1069 | ||
1088 | /* | 1070 | /* |
@@ -1090,25 +1072,25 @@ static int check_what_we_have(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1090 | * unclean reboots. However, many of them may indicate some problems | 1072 | * unclean reboots. However, many of them may indicate some problems |
1091 | * with the flash HW or driver. | 1073 | * with the flash HW or driver. |
1092 | */ | 1074 | */ |
1093 | if (si->corr_peb_count) { | 1075 | if (ai->corr_peb_count) { |
1094 | ubi_err("%d PEBs are corrupted and preserved", | 1076 | ubi_err("%d PEBs are corrupted and preserved", |
1095 | si->corr_peb_count); | 1077 | ai->corr_peb_count); |
1096 | printk(KERN_ERR "Corrupted PEBs are:"); | 1078 | printk(KERN_ERR "Corrupted PEBs are:"); |
1097 | list_for_each_entry(seb, &si->corr, u.list) | 1079 | list_for_each_entry(aeb, &ai->corr, u.list) |
1098 | printk(KERN_CONT " %d", seb->pnum); | 1080 | printk(KERN_CONT " %d", aeb->pnum); |
1099 | printk(KERN_CONT "\n"); | 1081 | printk(KERN_CONT "\n"); |
1100 | 1082 | ||
1101 | /* | 1083 | /* |
1102 | * If too many PEBs are corrupted, we refuse attaching, | 1084 | * If too many PEBs are corrupted, we refuse attaching, |
1103 | * otherwise, only print a warning. | 1085 | * otherwise, only print a warning. |
1104 | */ | 1086 | */ |
1105 | if (si->corr_peb_count >= max_corr) { | 1087 | if (ai->corr_peb_count >= max_corr) { |
1106 | ubi_err("too many corrupted PEBs, refusing"); | 1088 | ubi_err("too many corrupted PEBs, refusing"); |
1107 | return -EINVAL; | 1089 | return -EINVAL; |
1108 | } | 1090 | } |
1109 | } | 1091 | } |
1110 | 1092 | ||
1111 | if (si->empty_peb_count + si->maybe_bad_peb_count == peb_count) { | 1093 | if (ai->empty_peb_count + ai->maybe_bad_peb_count == peb_count) { |
1112 | /* | 1094 | /* |
1113 | * All PEBs are empty, or almost all - a couple PEBs look like | 1095 | * All PEBs are empty, or almost all - a couple PEBs look like |
1114 | * they may be bad PEBs which were not marked as bad yet. | 1096 | * they may be bad PEBs which were not marked as bad yet. |
@@ -1124,8 +1106,8 @@ static int check_what_we_have(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1124 | * 2. Flash contains non-UBI data and we do not want to format | 1106 | * 2. Flash contains non-UBI data and we do not want to format |
1125 | * it and destroy possibly important information. | 1107 | * it and destroy possibly important information. |
1126 | */ | 1108 | */ |
1127 | if (si->maybe_bad_peb_count <= 2) { | 1109 | if (ai->maybe_bad_peb_count <= 2) { |
1128 | si->is_empty = 1; | 1110 | ai->is_empty = 1; |
1129 | ubi_msg("empty MTD device detected"); | 1111 | ubi_msg("empty MTD device detected"); |
1130 | get_random_bytes(&ubi->image_seq, | 1112 | get_random_bytes(&ubi->image_seq, |
1131 | sizeof(ubi->image_seq)); | 1113 | sizeof(ubi->image_seq)); |
@@ -1141,40 +1123,41 @@ static int check_what_we_have(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1141 | } | 1123 | } |
1142 | 1124 | ||
1143 | /** | 1125 | /** |
1144 | * ubi_scan - scan an MTD device. | 1126 | * scan_all - scan entire MTD device. |
1145 | * @ubi: UBI device description object | 1127 | * @ubi: UBI device description object |
1146 | * | 1128 | * |
1147 | * This function does full scanning of an MTD device and returns complete | 1129 | * This function does full scanning of an MTD device and returns complete |
1148 | * information about it. In case of failure, an error code is returned. | 1130 | * information about it in form of a "struct ubi_attach_info" object. In case |
1131 | * of failure, an error code is returned. | ||
1149 | */ | 1132 | */ |
1150 | struct ubi_scan_info *ubi_scan(struct ubi_device *ubi) | 1133 | static struct ubi_attach_info *scan_all(struct ubi_device *ubi) |
1151 | { | 1134 | { |
1152 | int err, pnum; | 1135 | int err, pnum; |
1153 | struct rb_node *rb1, *rb2; | 1136 | struct rb_node *rb1, *rb2; |
1154 | struct ubi_scan_volume *sv; | 1137 | struct ubi_ainf_volume *av; |
1155 | struct ubi_scan_leb *seb; | 1138 | struct ubi_ainf_peb *aeb; |
1156 | struct ubi_scan_info *si; | 1139 | struct ubi_attach_info *ai; |
1157 | 1140 | ||
1158 | si = kzalloc(sizeof(struct ubi_scan_info), GFP_KERNEL); | 1141 | ai = kzalloc(sizeof(struct ubi_attach_info), GFP_KERNEL); |
1159 | if (!si) | 1142 | if (!ai) |
1160 | return ERR_PTR(-ENOMEM); | 1143 | return ERR_PTR(-ENOMEM); |
1161 | 1144 | ||
1162 | INIT_LIST_HEAD(&si->corr); | 1145 | INIT_LIST_HEAD(&ai->corr); |
1163 | INIT_LIST_HEAD(&si->free); | 1146 | INIT_LIST_HEAD(&ai->free); |
1164 | INIT_LIST_HEAD(&si->erase); | 1147 | INIT_LIST_HEAD(&ai->erase); |
1165 | INIT_LIST_HEAD(&si->alien); | 1148 | INIT_LIST_HEAD(&ai->alien); |
1166 | si->volumes = RB_ROOT; | 1149 | ai->volumes = RB_ROOT; |
1167 | 1150 | ||
1168 | err = -ENOMEM; | 1151 | err = -ENOMEM; |
1169 | si->scan_leb_slab = kmem_cache_create("ubi_scan_leb_slab", | 1152 | ai->aeb_slab_cache = kmem_cache_create("ubi_aeb_slab_cache", |
1170 | sizeof(struct ubi_scan_leb), | 1153 | sizeof(struct ubi_ainf_peb), |
1171 | 0, 0, NULL); | 1154 | 0, 0, NULL); |
1172 | if (!si->scan_leb_slab) | 1155 | if (!ai->aeb_slab_cache) |
1173 | goto out_si; | 1156 | goto out_ai; |
1174 | 1157 | ||
1175 | ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); | 1158 | ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); |
1176 | if (!ech) | 1159 | if (!ech) |
1177 | goto out_si; | 1160 | goto out_ai; |
1178 | 1161 | ||
1179 | vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); | 1162 | vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); |
1180 | if (!vidh) | 1163 | if (!vidh) |
@@ -1184,7 +1167,7 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi) | |||
1184 | cond_resched(); | 1167 | cond_resched(); |
1185 | 1168 | ||
1186 | dbg_gen("process PEB %d", pnum); | 1169 | dbg_gen("process PEB %d", pnum); |
1187 | err = process_eb(ubi, si, pnum); | 1170 | err = scan_peb(ubi, ai, pnum); |
1188 | if (err < 0) | 1171 | if (err < 0) |
1189 | goto out_vidh; | 1172 | goto out_vidh; |
1190 | } | 1173 | } |
@@ -1192,10 +1175,10 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi) | |||
1192 | dbg_msg("scanning is finished"); | 1175 | dbg_msg("scanning is finished"); |
1193 | 1176 | ||
1194 | /* Calculate mean erase counter */ | 1177 | /* Calculate mean erase counter */ |
1195 | if (si->ec_count) | 1178 | if (ai->ec_count) |
1196 | si->mean_ec = div_u64(si->ec_sum, si->ec_count); | 1179 | ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count); |
1197 | 1180 | ||
1198 | err = check_what_we_have(ubi, si); | 1181 | err = late_analysis(ubi, ai); |
1199 | if (err) | 1182 | if (err) |
1200 | goto out_vidh; | 1183 | goto out_vidh; |
1201 | 1184 | ||
@@ -1203,55 +1186,102 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi) | |||
1203 | * In case of unknown erase counter we use the mean erase counter | 1186 | * In case of unknown erase counter we use the mean erase counter |
1204 | * value. | 1187 | * value. |
1205 | */ | 1188 | */ |
1206 | ubi_rb_for_each_entry(rb1, sv, &si->volumes, rb) { | 1189 | ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) { |
1207 | ubi_rb_for_each_entry(rb2, seb, &sv->root, u.rb) | 1190 | ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) |
1208 | if (seb->ec == UBI_SCAN_UNKNOWN_EC) | 1191 | if (aeb->ec == UBI_UNKNOWN) |
1209 | seb->ec = si->mean_ec; | 1192 | aeb->ec = ai->mean_ec; |
1210 | } | 1193 | } |
1211 | 1194 | ||
1212 | list_for_each_entry(seb, &si->free, u.list) { | 1195 | list_for_each_entry(aeb, &ai->free, u.list) { |
1213 | if (seb->ec == UBI_SCAN_UNKNOWN_EC) | 1196 | if (aeb->ec == UBI_UNKNOWN) |
1214 | seb->ec = si->mean_ec; | 1197 | aeb->ec = ai->mean_ec; |
1215 | } | 1198 | } |
1216 | 1199 | ||
1217 | list_for_each_entry(seb, &si->corr, u.list) | 1200 | list_for_each_entry(aeb, &ai->corr, u.list) |
1218 | if (seb->ec == UBI_SCAN_UNKNOWN_EC) | 1201 | if (aeb->ec == UBI_UNKNOWN) |
1219 | seb->ec = si->mean_ec; | 1202 | aeb->ec = ai->mean_ec; |
1220 | 1203 | ||
1221 | list_for_each_entry(seb, &si->erase, u.list) | 1204 | list_for_each_entry(aeb, &ai->erase, u.list) |
1222 | if (seb->ec == UBI_SCAN_UNKNOWN_EC) | 1205 | if (aeb->ec == UBI_UNKNOWN) |
1223 | seb->ec = si->mean_ec; | 1206 | aeb->ec = ai->mean_ec; |
1224 | 1207 | ||
1225 | err = paranoid_check_si(ubi, si); | 1208 | err = self_check_ai(ubi, ai); |
1226 | if (err) | 1209 | if (err) |
1227 | goto out_vidh; | 1210 | goto out_vidh; |
1228 | 1211 | ||
1229 | ubi_free_vid_hdr(ubi, vidh); | 1212 | ubi_free_vid_hdr(ubi, vidh); |
1230 | kfree(ech); | 1213 | kfree(ech); |
1231 | 1214 | ||
1232 | return si; | 1215 | return ai; |
1233 | 1216 | ||
1234 | out_vidh: | 1217 | out_vidh: |
1235 | ubi_free_vid_hdr(ubi, vidh); | 1218 | ubi_free_vid_hdr(ubi, vidh); |
1236 | out_ech: | 1219 | out_ech: |
1237 | kfree(ech); | 1220 | kfree(ech); |
1238 | out_si: | 1221 | out_ai: |
1239 | ubi_scan_destroy_si(si); | 1222 | ubi_destroy_ai(ai); |
1240 | return ERR_PTR(err); | 1223 | return ERR_PTR(err); |
1241 | } | 1224 | } |
1242 | 1225 | ||
1243 | /** | 1226 | /** |
1244 | * destroy_sv - free the scanning volume information | 1227 | * ubi_attach - attach an MTD device. |
1245 | * @sv: scanning volume information | 1228 | * @ubi: UBI device descriptor |
1246 | * @si: scanning information | ||
1247 | * | 1229 | * |
1248 | * This function destroys the volume RB-tree (@sv->root) and the scanning | 1230 | * This function returns zero in case of success and a negative error code in |
1249 | * volume information. | 1231 | * case of failure. |
1250 | */ | 1232 | */ |
1251 | static void destroy_sv(struct ubi_scan_info *si, struct ubi_scan_volume *sv) | 1233 | int ubi_attach(struct ubi_device *ubi) |
1252 | { | 1234 | { |
1253 | struct ubi_scan_leb *seb; | 1235 | int err; |
1254 | struct rb_node *this = sv->root.rb_node; | 1236 | struct ubi_attach_info *ai; |
1237 | |||
1238 | ai = scan_all(ubi); | ||
1239 | if (IS_ERR(ai)) | ||
1240 | return PTR_ERR(ai); | ||
1241 | |||
1242 | ubi->bad_peb_count = ai->bad_peb_count; | ||
1243 | ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count; | ||
1244 | ubi->corr_peb_count = ai->corr_peb_count; | ||
1245 | ubi->max_ec = ai->max_ec; | ||
1246 | ubi->mean_ec = ai->mean_ec; | ||
1247 | ubi_msg("max. sequence number: %llu", ai->max_sqnum); | ||
1248 | |||
1249 | err = ubi_read_volume_table(ubi, ai); | ||
1250 | if (err) | ||
1251 | goto out_ai; | ||
1252 | |||
1253 | err = ubi_wl_init(ubi, ai); | ||
1254 | if (err) | ||
1255 | goto out_vtbl; | ||
1256 | |||
1257 | err = ubi_eba_init(ubi, ai); | ||
1258 | if (err) | ||
1259 | goto out_wl; | ||
1260 | |||
1261 | ubi_destroy_ai(ai); | ||
1262 | return 0; | ||
1263 | |||
1264 | out_wl: | ||
1265 | ubi_wl_close(ubi); | ||
1266 | out_vtbl: | ||
1267 | ubi_free_internal_volumes(ubi); | ||
1268 | vfree(ubi->vtbl); | ||
1269 | out_ai: | ||
1270 | ubi_destroy_ai(ai); | ||
1271 | return err; | ||
1272 | } | ||
1273 | |||
1274 | /** | ||
1275 | * destroy_av - free volume attaching information. | ||
1276 | * @av: volume attaching information | ||
1277 | * @ai: attaching information | ||
1278 | * | ||
1279 | * This function destroys the volume attaching information. | ||
1280 | */ | ||
1281 | static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av) | ||
1282 | { | ||
1283 | struct ubi_ainf_peb *aeb; | ||
1284 | struct rb_node *this = av->root.rb_node; | ||
1255 | 1285 | ||
1256 | while (this) { | 1286 | while (this) { |
1257 | if (this->rb_left) | 1287 | if (this->rb_left) |
@@ -1259,224 +1289,222 @@ static void destroy_sv(struct ubi_scan_info *si, struct ubi_scan_volume *sv) | |||
1259 | else if (this->rb_right) | 1289 | else if (this->rb_right) |
1260 | this = this->rb_right; | 1290 | this = this->rb_right; |
1261 | else { | 1291 | else { |
1262 | seb = rb_entry(this, struct ubi_scan_leb, u.rb); | 1292 | aeb = rb_entry(this, struct ubi_ainf_peb, u.rb); |
1263 | this = rb_parent(this); | 1293 | this = rb_parent(this); |
1264 | if (this) { | 1294 | if (this) { |
1265 | if (this->rb_left == &seb->u.rb) | 1295 | if (this->rb_left == &aeb->u.rb) |
1266 | this->rb_left = NULL; | 1296 | this->rb_left = NULL; |
1267 | else | 1297 | else |
1268 | this->rb_right = NULL; | 1298 | this->rb_right = NULL; |
1269 | } | 1299 | } |
1270 | 1300 | ||
1271 | kmem_cache_free(si->scan_leb_slab, seb); | 1301 | kmem_cache_free(ai->aeb_slab_cache, aeb); |
1272 | } | 1302 | } |
1273 | } | 1303 | } |
1274 | kfree(sv); | 1304 | kfree(av); |
1275 | } | 1305 | } |
1276 | 1306 | ||
1277 | /** | 1307 | /** |
1278 | * ubi_scan_destroy_si - destroy scanning information. | 1308 | * ubi_destroy_ai - destroy attaching information. |
1279 | * @si: scanning information | 1309 | * @ai: attaching information |
1280 | */ | 1310 | */ |
1281 | void ubi_scan_destroy_si(struct ubi_scan_info *si) | 1311 | void ubi_destroy_ai(struct ubi_attach_info *ai) |
1282 | { | 1312 | { |
1283 | struct ubi_scan_leb *seb, *seb_tmp; | 1313 | struct ubi_ainf_peb *aeb, *aeb_tmp; |
1284 | struct ubi_scan_volume *sv; | 1314 | struct ubi_ainf_volume *av; |
1285 | struct rb_node *rb; | 1315 | struct rb_node *rb; |
1286 | 1316 | ||
1287 | list_for_each_entry_safe(seb, seb_tmp, &si->alien, u.list) { | 1317 | list_for_each_entry_safe(aeb, aeb_tmp, &ai->alien, u.list) { |
1288 | list_del(&seb->u.list); | 1318 | list_del(&aeb->u.list); |
1289 | kmem_cache_free(si->scan_leb_slab, seb); | 1319 | kmem_cache_free(ai->aeb_slab_cache, aeb); |
1290 | } | 1320 | } |
1291 | list_for_each_entry_safe(seb, seb_tmp, &si->erase, u.list) { | 1321 | list_for_each_entry_safe(aeb, aeb_tmp, &ai->erase, u.list) { |
1292 | list_del(&seb->u.list); | 1322 | list_del(&aeb->u.list); |
1293 | kmem_cache_free(si->scan_leb_slab, seb); | 1323 | kmem_cache_free(ai->aeb_slab_cache, aeb); |
1294 | } | 1324 | } |
1295 | list_for_each_entry_safe(seb, seb_tmp, &si->corr, u.list) { | 1325 | list_for_each_entry_safe(aeb, aeb_tmp, &ai->corr, u.list) { |
1296 | list_del(&seb->u.list); | 1326 | list_del(&aeb->u.list); |
1297 | kmem_cache_free(si->scan_leb_slab, seb); | 1327 | kmem_cache_free(ai->aeb_slab_cache, aeb); |
1298 | } | 1328 | } |
1299 | list_for_each_entry_safe(seb, seb_tmp, &si->free, u.list) { | 1329 | list_for_each_entry_safe(aeb, aeb_tmp, &ai->free, u.list) { |
1300 | list_del(&seb->u.list); | 1330 | list_del(&aeb->u.list); |
1301 | kmem_cache_free(si->scan_leb_slab, seb); | 1331 | kmem_cache_free(ai->aeb_slab_cache, aeb); |
1302 | } | 1332 | } |
1303 | 1333 | ||
1304 | /* Destroy the volume RB-tree */ | 1334 | /* Destroy the volume RB-tree */ |
1305 | rb = si->volumes.rb_node; | 1335 | rb = ai->volumes.rb_node; |
1306 | while (rb) { | 1336 | while (rb) { |
1307 | if (rb->rb_left) | 1337 | if (rb->rb_left) |
1308 | rb = rb->rb_left; | 1338 | rb = rb->rb_left; |
1309 | else if (rb->rb_right) | 1339 | else if (rb->rb_right) |
1310 | rb = rb->rb_right; | 1340 | rb = rb->rb_right; |
1311 | else { | 1341 | else { |
1312 | sv = rb_entry(rb, struct ubi_scan_volume, rb); | 1342 | av = rb_entry(rb, struct ubi_ainf_volume, rb); |
1313 | 1343 | ||
1314 | rb = rb_parent(rb); | 1344 | rb = rb_parent(rb); |
1315 | if (rb) { | 1345 | if (rb) { |
1316 | if (rb->rb_left == &sv->rb) | 1346 | if (rb->rb_left == &av->rb) |
1317 | rb->rb_left = NULL; | 1347 | rb->rb_left = NULL; |
1318 | else | 1348 | else |
1319 | rb->rb_right = NULL; | 1349 | rb->rb_right = NULL; |
1320 | } | 1350 | } |
1321 | 1351 | ||
1322 | destroy_sv(si, sv); | 1352 | destroy_av(ai, av); |
1323 | } | 1353 | } |
1324 | } | 1354 | } |
1325 | 1355 | ||
1326 | if (si->scan_leb_slab) | 1356 | if (ai->aeb_slab_cache) |
1327 | kmem_cache_destroy(si->scan_leb_slab); | 1357 | kmem_cache_destroy(ai->aeb_slab_cache); |
1328 | 1358 | ||
1329 | kfree(si); | 1359 | kfree(ai); |
1330 | } | 1360 | } |
1331 | 1361 | ||
1332 | #ifdef CONFIG_MTD_UBI_DEBUG | ||
1333 | |||
1334 | /** | 1362 | /** |
1335 | * paranoid_check_si - check the scanning information. | 1363 | * self_check_ai - check the attaching information. |
1336 | * @ubi: UBI device description object | 1364 | * @ubi: UBI device description object |
1337 | * @si: scanning information | 1365 | * @ai: attaching information |
1338 | * | 1366 | * |
1339 | * This function returns zero if the scanning information is all right, and a | 1367 | * This function returns zero if the attaching information is all right, and a |
1340 | * negative error code if not or if an error occurred. | 1368 | * negative error code if not or if an error occurred. |
1341 | */ | 1369 | */ |
1342 | static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) | 1370 | static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai) |
1343 | { | 1371 | { |
1344 | int pnum, err, vols_found = 0; | 1372 | int pnum, err, vols_found = 0; |
1345 | struct rb_node *rb1, *rb2; | 1373 | struct rb_node *rb1, *rb2; |
1346 | struct ubi_scan_volume *sv; | 1374 | struct ubi_ainf_volume *av; |
1347 | struct ubi_scan_leb *seb, *last_seb; | 1375 | struct ubi_ainf_peb *aeb, *last_aeb; |
1348 | uint8_t *buf; | 1376 | uint8_t *buf; |
1349 | 1377 | ||
1350 | if (!ubi->dbg->chk_gen) | 1378 | if (!ubi->dbg->chk_gen) |
1351 | return 0; | 1379 | return 0; |
1352 | 1380 | ||
1353 | /* | 1381 | /* |
1354 | * At first, check that scanning information is OK. | 1382 | * At first, check that attaching information is OK. |
1355 | */ | 1383 | */ |
1356 | ubi_rb_for_each_entry(rb1, sv, &si->volumes, rb) { | 1384 | ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) { |
1357 | int leb_count = 0; | 1385 | int leb_count = 0; |
1358 | 1386 | ||
1359 | cond_resched(); | 1387 | cond_resched(); |
1360 | 1388 | ||
1361 | vols_found += 1; | 1389 | vols_found += 1; |
1362 | 1390 | ||
1363 | if (si->is_empty) { | 1391 | if (ai->is_empty) { |
1364 | ubi_err("bad is_empty flag"); | 1392 | ubi_err("bad is_empty flag"); |
1365 | goto bad_sv; | 1393 | goto bad_av; |
1366 | } | 1394 | } |
1367 | 1395 | ||
1368 | if (sv->vol_id < 0 || sv->highest_lnum < 0 || | 1396 | if (av->vol_id < 0 || av->highest_lnum < 0 || |
1369 | sv->leb_count < 0 || sv->vol_type < 0 || sv->used_ebs < 0 || | 1397 | av->leb_count < 0 || av->vol_type < 0 || av->used_ebs < 0 || |
1370 | sv->data_pad < 0 || sv->last_data_size < 0) { | 1398 | av->data_pad < 0 || av->last_data_size < 0) { |
1371 | ubi_err("negative values"); | 1399 | ubi_err("negative values"); |
1372 | goto bad_sv; | 1400 | goto bad_av; |
1373 | } | 1401 | } |
1374 | 1402 | ||
1375 | if (sv->vol_id >= UBI_MAX_VOLUMES && | 1403 | if (av->vol_id >= UBI_MAX_VOLUMES && |
1376 | sv->vol_id < UBI_INTERNAL_VOL_START) { | 1404 | av->vol_id < UBI_INTERNAL_VOL_START) { |
1377 | ubi_err("bad vol_id"); | 1405 | ubi_err("bad vol_id"); |
1378 | goto bad_sv; | 1406 | goto bad_av; |
1379 | } | 1407 | } |
1380 | 1408 | ||
1381 | if (sv->vol_id > si->highest_vol_id) { | 1409 | if (av->vol_id > ai->highest_vol_id) { |
1382 | ubi_err("highest_vol_id is %d, but vol_id %d is there", | 1410 | ubi_err("highest_vol_id is %d, but vol_id %d is there", |
1383 | si->highest_vol_id, sv->vol_id); | 1411 | ai->highest_vol_id, av->vol_id); |
1384 | goto out; | 1412 | goto out; |
1385 | } | 1413 | } |
1386 | 1414 | ||
1387 | if (sv->vol_type != UBI_DYNAMIC_VOLUME && | 1415 | if (av->vol_type != UBI_DYNAMIC_VOLUME && |
1388 | sv->vol_type != UBI_STATIC_VOLUME) { | 1416 | av->vol_type != UBI_STATIC_VOLUME) { |
1389 | ubi_err("bad vol_type"); | 1417 | ubi_err("bad vol_type"); |
1390 | goto bad_sv; | 1418 | goto bad_av; |
1391 | } | 1419 | } |
1392 | 1420 | ||
1393 | if (sv->data_pad > ubi->leb_size / 2) { | 1421 | if (av->data_pad > ubi->leb_size / 2) { |
1394 | ubi_err("bad data_pad"); | 1422 | ubi_err("bad data_pad"); |
1395 | goto bad_sv; | 1423 | goto bad_av; |
1396 | } | 1424 | } |
1397 | 1425 | ||
1398 | last_seb = NULL; | 1426 | last_aeb = NULL; |
1399 | ubi_rb_for_each_entry(rb2, seb, &sv->root, u.rb) { | 1427 | ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) { |
1400 | cond_resched(); | 1428 | cond_resched(); |
1401 | 1429 | ||
1402 | last_seb = seb; | 1430 | last_aeb = aeb; |
1403 | leb_count += 1; | 1431 | leb_count += 1; |
1404 | 1432 | ||
1405 | if (seb->pnum < 0 || seb->ec < 0) { | 1433 | if (aeb->pnum < 0 || aeb->ec < 0) { |
1406 | ubi_err("negative values"); | 1434 | ubi_err("negative values"); |
1407 | goto bad_seb; | 1435 | goto bad_aeb; |
1408 | } | 1436 | } |
1409 | 1437 | ||
1410 | if (seb->ec < si->min_ec) { | 1438 | if (aeb->ec < ai->min_ec) { |
1411 | ubi_err("bad si->min_ec (%d), %d found", | 1439 | ubi_err("bad ai->min_ec (%d), %d found", |
1412 | si->min_ec, seb->ec); | 1440 | ai->min_ec, aeb->ec); |
1413 | goto bad_seb; | 1441 | goto bad_aeb; |
1414 | } | 1442 | } |
1415 | 1443 | ||
1416 | if (seb->ec > si->max_ec) { | 1444 | if (aeb->ec > ai->max_ec) { |
1417 | ubi_err("bad si->max_ec (%d), %d found", | 1445 | ubi_err("bad ai->max_ec (%d), %d found", |
1418 | si->max_ec, seb->ec); | 1446 | ai->max_ec, aeb->ec); |
1419 | goto bad_seb; | 1447 | goto bad_aeb; |
1420 | } | 1448 | } |
1421 | 1449 | ||
1422 | if (seb->pnum >= ubi->peb_count) { | 1450 | if (aeb->pnum >= ubi->peb_count) { |
1423 | ubi_err("too high PEB number %d, total PEBs %d", | 1451 | ubi_err("too high PEB number %d, total PEBs %d", |
1424 | seb->pnum, ubi->peb_count); | 1452 | aeb->pnum, ubi->peb_count); |
1425 | goto bad_seb; | 1453 | goto bad_aeb; |
1426 | } | 1454 | } |
1427 | 1455 | ||
1428 | if (sv->vol_type == UBI_STATIC_VOLUME) { | 1456 | if (av->vol_type == UBI_STATIC_VOLUME) { |
1429 | if (seb->lnum >= sv->used_ebs) { | 1457 | if (aeb->lnum >= av->used_ebs) { |
1430 | ubi_err("bad lnum or used_ebs"); | 1458 | ubi_err("bad lnum or used_ebs"); |
1431 | goto bad_seb; | 1459 | goto bad_aeb; |
1432 | } | 1460 | } |
1433 | } else { | 1461 | } else { |
1434 | if (sv->used_ebs != 0) { | 1462 | if (av->used_ebs != 0) { |
1435 | ubi_err("non-zero used_ebs"); | 1463 | ubi_err("non-zero used_ebs"); |
1436 | goto bad_seb; | 1464 | goto bad_aeb; |
1437 | } | 1465 | } |
1438 | } | 1466 | } |
1439 | 1467 | ||
1440 | if (seb->lnum > sv->highest_lnum) { | 1468 | if (aeb->lnum > av->highest_lnum) { |
1441 | ubi_err("incorrect highest_lnum or lnum"); | 1469 | ubi_err("incorrect highest_lnum or lnum"); |
1442 | goto bad_seb; | 1470 | goto bad_aeb; |
1443 | } | 1471 | } |
1444 | } | 1472 | } |
1445 | 1473 | ||
1446 | if (sv->leb_count != leb_count) { | 1474 | if (av->leb_count != leb_count) { |
1447 | ubi_err("bad leb_count, %d objects in the tree", | 1475 | ubi_err("bad leb_count, %d objects in the tree", |
1448 | leb_count); | 1476 | leb_count); |
1449 | goto bad_sv; | 1477 | goto bad_av; |
1450 | } | 1478 | } |
1451 | 1479 | ||
1452 | if (!last_seb) | 1480 | if (!last_aeb) |
1453 | continue; | 1481 | continue; |
1454 | 1482 | ||
1455 | seb = last_seb; | 1483 | aeb = last_aeb; |
1456 | 1484 | ||
1457 | if (seb->lnum != sv->highest_lnum) { | 1485 | if (aeb->lnum != av->highest_lnum) { |
1458 | ubi_err("bad highest_lnum"); | 1486 | ubi_err("bad highest_lnum"); |
1459 | goto bad_seb; | 1487 | goto bad_aeb; |
1460 | } | 1488 | } |
1461 | } | 1489 | } |
1462 | 1490 | ||
1463 | if (vols_found != si->vols_found) { | 1491 | if (vols_found != ai->vols_found) { |
1464 | ubi_err("bad si->vols_found %d, should be %d", | 1492 | ubi_err("bad ai->vols_found %d, should be %d", |
1465 | si->vols_found, vols_found); | 1493 | ai->vols_found, vols_found); |
1466 | goto out; | 1494 | goto out; |
1467 | } | 1495 | } |
1468 | 1496 | ||
1469 | /* Check that scanning information is correct */ | 1497 | /* Check that attaching information is correct */ |
1470 | ubi_rb_for_each_entry(rb1, sv, &si->volumes, rb) { | 1498 | ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) { |
1471 | last_seb = NULL; | 1499 | last_aeb = NULL; |
1472 | ubi_rb_for_each_entry(rb2, seb, &sv->root, u.rb) { | 1500 | ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) { |
1473 | int vol_type; | 1501 | int vol_type; |
1474 | 1502 | ||
1475 | cond_resched(); | 1503 | cond_resched(); |
1476 | 1504 | ||
1477 | last_seb = seb; | 1505 | last_aeb = aeb; |
1478 | 1506 | ||
1479 | err = ubi_io_read_vid_hdr(ubi, seb->pnum, vidh, 1); | 1507 | err = ubi_io_read_vid_hdr(ubi, aeb->pnum, vidh, 1); |
1480 | if (err && err != UBI_IO_BITFLIPS) { | 1508 | if (err && err != UBI_IO_BITFLIPS) { |
1481 | ubi_err("VID header is not OK (%d)", err); | 1509 | ubi_err("VID header is not OK (%d)", err); |
1482 | if (err > 0) | 1510 | if (err > 0) |
@@ -1486,52 +1514,52 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1486 | 1514 | ||
1487 | vol_type = vidh->vol_type == UBI_VID_DYNAMIC ? | 1515 | vol_type = vidh->vol_type == UBI_VID_DYNAMIC ? |
1488 | UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME; | 1516 | UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME; |
1489 | if (sv->vol_type != vol_type) { | 1517 | if (av->vol_type != vol_type) { |
1490 | ubi_err("bad vol_type"); | 1518 | ubi_err("bad vol_type"); |
1491 | goto bad_vid_hdr; | 1519 | goto bad_vid_hdr; |
1492 | } | 1520 | } |
1493 | 1521 | ||
1494 | if (seb->sqnum != be64_to_cpu(vidh->sqnum)) { | 1522 | if (aeb->sqnum != be64_to_cpu(vidh->sqnum)) { |
1495 | ubi_err("bad sqnum %llu", seb->sqnum); | 1523 | ubi_err("bad sqnum %llu", aeb->sqnum); |
1496 | goto bad_vid_hdr; | 1524 | goto bad_vid_hdr; |
1497 | } | 1525 | } |
1498 | 1526 | ||
1499 | if (sv->vol_id != be32_to_cpu(vidh->vol_id)) { | 1527 | if (av->vol_id != be32_to_cpu(vidh->vol_id)) { |
1500 | ubi_err("bad vol_id %d", sv->vol_id); | 1528 | ubi_err("bad vol_id %d", av->vol_id); |
1501 | goto bad_vid_hdr; | 1529 | goto bad_vid_hdr; |
1502 | } | 1530 | } |
1503 | 1531 | ||
1504 | if (sv->compat != vidh->compat) { | 1532 | if (av->compat != vidh->compat) { |
1505 | ubi_err("bad compat %d", vidh->compat); | 1533 | ubi_err("bad compat %d", vidh->compat); |
1506 | goto bad_vid_hdr; | 1534 | goto bad_vid_hdr; |
1507 | } | 1535 | } |
1508 | 1536 | ||
1509 | if (seb->lnum != be32_to_cpu(vidh->lnum)) { | 1537 | if (aeb->lnum != be32_to_cpu(vidh->lnum)) { |
1510 | ubi_err("bad lnum %d", seb->lnum); | 1538 | ubi_err("bad lnum %d", aeb->lnum); |
1511 | goto bad_vid_hdr; | 1539 | goto bad_vid_hdr; |
1512 | } | 1540 | } |
1513 | 1541 | ||
1514 | if (sv->used_ebs != be32_to_cpu(vidh->used_ebs)) { | 1542 | if (av->used_ebs != be32_to_cpu(vidh->used_ebs)) { |
1515 | ubi_err("bad used_ebs %d", sv->used_ebs); | 1543 | ubi_err("bad used_ebs %d", av->used_ebs); |
1516 | goto bad_vid_hdr; | 1544 | goto bad_vid_hdr; |
1517 | } | 1545 | } |
1518 | 1546 | ||
1519 | if (sv->data_pad != be32_to_cpu(vidh->data_pad)) { | 1547 | if (av->data_pad != be32_to_cpu(vidh->data_pad)) { |
1520 | ubi_err("bad data_pad %d", sv->data_pad); | 1548 | ubi_err("bad data_pad %d", av->data_pad); |
1521 | goto bad_vid_hdr; | 1549 | goto bad_vid_hdr; |
1522 | } | 1550 | } |
1523 | } | 1551 | } |
1524 | 1552 | ||
1525 | if (!last_seb) | 1553 | if (!last_aeb) |
1526 | continue; | 1554 | continue; |
1527 | 1555 | ||
1528 | if (sv->highest_lnum != be32_to_cpu(vidh->lnum)) { | 1556 | if (av->highest_lnum != be32_to_cpu(vidh->lnum)) { |
1529 | ubi_err("bad highest_lnum %d", sv->highest_lnum); | 1557 | ubi_err("bad highest_lnum %d", av->highest_lnum); |
1530 | goto bad_vid_hdr; | 1558 | goto bad_vid_hdr; |
1531 | } | 1559 | } |
1532 | 1560 | ||
1533 | if (sv->last_data_size != be32_to_cpu(vidh->data_size)) { | 1561 | if (av->last_data_size != be32_to_cpu(vidh->data_size)) { |
1534 | ubi_err("bad last_data_size %d", sv->last_data_size); | 1562 | ubi_err("bad last_data_size %d", av->last_data_size); |
1535 | goto bad_vid_hdr; | 1563 | goto bad_vid_hdr; |
1536 | } | 1564 | } |
1537 | } | 1565 | } |
@@ -1553,21 +1581,21 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1553 | buf[pnum] = 1; | 1581 | buf[pnum] = 1; |
1554 | } | 1582 | } |
1555 | 1583 | ||
1556 | ubi_rb_for_each_entry(rb1, sv, &si->volumes, rb) | 1584 | ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) |
1557 | ubi_rb_for_each_entry(rb2, seb, &sv->root, u.rb) | 1585 | ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) |
1558 | buf[seb->pnum] = 1; | 1586 | buf[aeb->pnum] = 1; |
1559 | 1587 | ||
1560 | list_for_each_entry(seb, &si->free, u.list) | 1588 | list_for_each_entry(aeb, &ai->free, u.list) |
1561 | buf[seb->pnum] = 1; | 1589 | buf[aeb->pnum] = 1; |
1562 | 1590 | ||
1563 | list_for_each_entry(seb, &si->corr, u.list) | 1591 | list_for_each_entry(aeb, &ai->corr, u.list) |
1564 | buf[seb->pnum] = 1; | 1592 | buf[aeb->pnum] = 1; |
1565 | 1593 | ||
1566 | list_for_each_entry(seb, &si->erase, u.list) | 1594 | list_for_each_entry(aeb, &ai->erase, u.list) |
1567 | buf[seb->pnum] = 1; | 1595 | buf[aeb->pnum] = 1; |
1568 | 1596 | ||
1569 | list_for_each_entry(seb, &si->alien, u.list) | 1597 | list_for_each_entry(aeb, &ai->alien, u.list) |
1570 | buf[seb->pnum] = 1; | 1598 | buf[aeb->pnum] = 1; |
1571 | 1599 | ||
1572 | err = 0; | 1600 | err = 0; |
1573 | for (pnum = 0; pnum < ubi->peb_count; pnum++) | 1601 | for (pnum = 0; pnum < ubi->peb_count; pnum++) |
@@ -1581,25 +1609,23 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1581 | goto out; | 1609 | goto out; |
1582 | return 0; | 1610 | return 0; |
1583 | 1611 | ||
1584 | bad_seb: | 1612 | bad_aeb: |
1585 | ubi_err("bad scanning information about LEB %d", seb->lnum); | 1613 | ubi_err("bad attaching information about LEB %d", aeb->lnum); |
1586 | ubi_dbg_dump_seb(seb, 0); | 1614 | ubi_dump_aeb(aeb, 0); |
1587 | ubi_dbg_dump_sv(sv); | 1615 | ubi_dump_av(av); |
1588 | goto out; | 1616 | goto out; |
1589 | 1617 | ||
1590 | bad_sv: | 1618 | bad_av: |
1591 | ubi_err("bad scanning information about volume %d", sv->vol_id); | 1619 | ubi_err("bad attaching information about volume %d", av->vol_id); |
1592 | ubi_dbg_dump_sv(sv); | 1620 | ubi_dump_av(av); |
1593 | goto out; | 1621 | goto out; |
1594 | 1622 | ||
1595 | bad_vid_hdr: | 1623 | bad_vid_hdr: |
1596 | ubi_err("bad scanning information about volume %d", sv->vol_id); | 1624 | ubi_err("bad attaching information about volume %d", av->vol_id); |
1597 | ubi_dbg_dump_sv(sv); | 1625 | ubi_dump_av(av); |
1598 | ubi_dbg_dump_vid_hdr(vidh); | 1626 | ubi_dump_vid_hdr(vidh); |
1599 | 1627 | ||
1600 | out: | 1628 | out: |
1601 | ubi_dbg_dump_stack(); | 1629 | dump_stack(); |
1602 | return -EINVAL; | 1630 | return -EINVAL; |
1603 | } | 1631 | } |
1604 | |||
1605 | #endif /* CONFIG_MTD_UBI_DEBUG */ | ||
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 0fde9fc7d2e5..2c5ed5ca9c33 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c | |||
@@ -27,10 +27,6 @@ | |||
27 | * module load parameters or the kernel boot parameters. If MTD devices were | 27 | * module load parameters or the kernel boot parameters. If MTD devices were |
28 | * specified, UBI does not attach any MTD device, but it is possible to do | 28 | * specified, UBI does not attach any MTD device, but it is possible to do |
29 | * later using the "UBI control device". | 29 | * later using the "UBI control device". |
30 | * | ||
31 | * At the moment we only attach UBI devices by scanning, which will become a | ||
32 | * bottleneck when flashes reach certain large size. Then one may improve UBI | ||
33 | * and add other methods, although it does not seem to be easy to do. | ||
34 | */ | 30 | */ |
35 | 31 | ||
36 | #include <linux/err.h> | 32 | #include <linux/err.h> |
@@ -554,10 +550,10 @@ static void uif_close(struct ubi_device *ubi) | |||
554 | } | 550 | } |
555 | 551 | ||
556 | /** | 552 | /** |
557 | * free_internal_volumes - free internal volumes. | 553 | * ubi_free_internal_volumes - free internal volumes. |
558 | * @ubi: UBI device description object | 554 | * @ubi: UBI device description object |
559 | */ | 555 | */ |
560 | static void free_internal_volumes(struct ubi_device *ubi) | 556 | void ubi_free_internal_volumes(struct ubi_device *ubi) |
561 | { | 557 | { |
562 | int i; | 558 | int i; |
563 | 559 | ||
@@ -569,59 +565,6 @@ static void free_internal_volumes(struct ubi_device *ubi) | |||
569 | } | 565 | } |
570 | 566 | ||
571 | /** | 567 | /** |
572 | * attach_by_scanning - attach an MTD device using scanning method. | ||
573 | * @ubi: UBI device descriptor | ||
574 | * | ||
575 | * This function returns zero in case of success and a negative error code in | ||
576 | * case of failure. | ||
577 | * | ||
578 | * Note, currently this is the only method to attach UBI devices. Hopefully in | ||
579 | * the future we'll have more scalable attaching methods and avoid full media | ||
580 | * scanning. But even in this case scanning will be needed as a fall-back | ||
581 | * attaching method if there are some on-flash table corruptions. | ||
582 | */ | ||
583 | static int attach_by_scanning(struct ubi_device *ubi) | ||
584 | { | ||
585 | int err; | ||
586 | struct ubi_scan_info *si; | ||
587 | |||
588 | si = ubi_scan(ubi); | ||
589 | if (IS_ERR(si)) | ||
590 | return PTR_ERR(si); | ||
591 | |||
592 | ubi->bad_peb_count = si->bad_peb_count; | ||
593 | ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count; | ||
594 | ubi->corr_peb_count = si->corr_peb_count; | ||
595 | ubi->max_ec = si->max_ec; | ||
596 | ubi->mean_ec = si->mean_ec; | ||
597 | ubi_msg("max. sequence number: %llu", si->max_sqnum); | ||
598 | |||
599 | err = ubi_read_volume_table(ubi, si); | ||
600 | if (err) | ||
601 | goto out_si; | ||
602 | |||
603 | err = ubi_wl_init_scan(ubi, si); | ||
604 | if (err) | ||
605 | goto out_vtbl; | ||
606 | |||
607 | err = ubi_eba_init_scan(ubi, si); | ||
608 | if (err) | ||
609 | goto out_wl; | ||
610 | |||
611 | ubi_scan_destroy_si(si); | ||
612 | return 0; | ||
613 | |||
614 | out_wl: | ||
615 | ubi_wl_close(ubi); | ||
616 | out_vtbl: | ||
617 | free_internal_volumes(ubi); | ||
618 | vfree(ubi->vtbl); | ||
619 | out_si: | ||
620 | ubi_scan_destroy_si(si); | ||
621 | return err; | ||
622 | } | ||
623 | |||
624 | /** | ||
625 | * 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. |
626 | * @ubi: UBI device description object | 569 | * @ubi: UBI device description object |
627 | * | 570 | * |
@@ -790,11 +733,11 @@ static int io_init(struct ubi_device *ubi) | |||
790 | ubi_msg("data offset: %d", ubi->leb_start); | 733 | ubi_msg("data offset: %d", ubi->leb_start); |
791 | 734 | ||
792 | /* | 735 | /* |
793 | * Note, ideally, we have to initialize ubi->bad_peb_count here. But | 736 | * Note, ideally, we have to initialize @ubi->bad_peb_count here. But |
794 | * unfortunately, MTD does not provide this information. We should loop | 737 | * unfortunately, MTD does not provide this information. We should loop |
795 | * over all physical eraseblocks and invoke mtd->block_is_bad() for | 738 | * over all physical eraseblocks and invoke mtd->block_is_bad() for |
796 | * each physical eraseblock. So, we skip ubi->bad_peb_count | 739 | * each physical eraseblock. So, we leave @ubi->bad_peb_count |
797 | * uninitialized and initialize it after scanning. | 740 | * uninitialized so far. |
798 | */ | 741 | */ |
799 | 742 | ||
800 | return 0; | 743 | return 0; |
@@ -805,7 +748,7 @@ static int io_init(struct ubi_device *ubi) | |||
805 | * @ubi: UBI device description object | 748 | * @ubi: UBI device description object |
806 | * @vol_id: ID of the volume to re-size | 749 | * @vol_id: ID of the volume to re-size |
807 | * | 750 | * |
808 | * This function re-sizes the volume marked by the @UBI_VTBL_AUTORESIZE_FLG in | 751 | * This function re-sizes the volume marked by the %UBI_VTBL_AUTORESIZE_FLG in |
809 | * the volume table to the largest possible size. See comments in ubi-header.h | 752 | * the volume table to the largest possible size. See comments in ubi-header.h |
810 | * for more description of the flag. Returns zero in case of success and a | 753 | * for more description of the flag. Returns zero in case of success and a |
811 | * negative error code in case of failure. | 754 | * negative error code in case of failure. |
@@ -881,7 +824,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
881 | for (i = 0; i < UBI_MAX_DEVICES; i++) { | 824 | for (i = 0; i < UBI_MAX_DEVICES; i++) { |
882 | ubi = ubi_devices[i]; | 825 | ubi = ubi_devices[i]; |
883 | if (ubi && mtd->index == ubi->mtd->index) { | 826 | if (ubi && mtd->index == ubi->mtd->index) { |
884 | dbg_err("mtd%d is already attached to ubi%d", | 827 | ubi_err("mtd%d is already attached to ubi%d", |
885 | mtd->index, i); | 828 | mtd->index, i); |
886 | return -EEXIST; | 829 | return -EEXIST; |
887 | } | 830 | } |
@@ -907,7 +850,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
907 | if (!ubi_devices[ubi_num]) | 850 | if (!ubi_devices[ubi_num]) |
908 | break; | 851 | break; |
909 | if (ubi_num == UBI_MAX_DEVICES) { | 852 | if (ubi_num == UBI_MAX_DEVICES) { |
910 | dbg_err("only %d UBI devices may be created", | 853 | ubi_err("only %d UBI devices may be created", |
911 | UBI_MAX_DEVICES); | 854 | UBI_MAX_DEVICES); |
912 | return -ENFILE; | 855 | return -ENFILE; |
913 | } | 856 | } |
@@ -917,7 +860,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
917 | 860 | ||
918 | /* Make sure ubi_num is not busy */ | 861 | /* Make sure ubi_num is not busy */ |
919 | if (ubi_devices[ubi_num]) { | 862 | if (ubi_devices[ubi_num]) { |
920 | dbg_err("ubi%d already exists", ubi_num); | 863 | ubi_err("ubi%d already exists", ubi_num); |
921 | return -EEXIST; | 864 | return -EEXIST; |
922 | } | 865 | } |
923 | } | 866 | } |
@@ -937,7 +880,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
937 | spin_lock_init(&ubi->volumes_lock); | 880 | spin_lock_init(&ubi->volumes_lock); |
938 | 881 | ||
939 | ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num); | 882 | ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num); |
940 | dbg_msg("sizeof(struct ubi_scan_leb) %zu", sizeof(struct ubi_scan_leb)); | 883 | dbg_msg("sizeof(struct ubi_ainf_peb) %zu", sizeof(struct ubi_ainf_peb)); |
941 | dbg_msg("sizeof(struct ubi_wl_entry) %zu", sizeof(struct ubi_wl_entry)); | 884 | dbg_msg("sizeof(struct ubi_wl_entry) %zu", sizeof(struct ubi_wl_entry)); |
942 | 885 | ||
943 | err = io_init(ubi); | 886 | err = io_init(ubi); |
@@ -953,9 +896,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
953 | if (err) | 896 | if (err) |
954 | goto out_free; | 897 | goto out_free; |
955 | 898 | ||
956 | err = attach_by_scanning(ubi); | 899 | err = ubi_attach(ubi); |
957 | if (err) { | 900 | if (err) { |
958 | dbg_err("failed to attach by scanning, error %d", err); | 901 | ubi_err("failed to attach mtd%d, error %d", mtd->index, err); |
959 | goto out_debugging; | 902 | goto out_debugging; |
960 | } | 903 | } |
961 | 904 | ||
@@ -1020,7 +963,7 @@ out_uif: | |||
1020 | uif_close(ubi); | 963 | uif_close(ubi); |
1021 | out_detach: | 964 | out_detach: |
1022 | ubi_wl_close(ubi); | 965 | ubi_wl_close(ubi); |
1023 | free_internal_volumes(ubi); | 966 | ubi_free_internal_volumes(ubi); |
1024 | vfree(ubi->vtbl); | 967 | vfree(ubi->vtbl); |
1025 | out_debugging: | 968 | out_debugging: |
1026 | ubi_debugging_exit_dev(ubi); | 969 | ubi_debugging_exit_dev(ubi); |
@@ -1092,7 +1035,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway) | |||
1092 | ubi_debugfs_exit_dev(ubi); | 1035 | ubi_debugfs_exit_dev(ubi); |
1093 | uif_close(ubi); | 1036 | uif_close(ubi); |
1094 | ubi_wl_close(ubi); | 1037 | ubi_wl_close(ubi); |
1095 | free_internal_volumes(ubi); | 1038 | ubi_free_internal_volumes(ubi); |
1096 | vfree(ubi->vtbl); | 1039 | vfree(ubi->vtbl); |
1097 | put_mtd_device(ubi->mtd); | 1040 | put_mtd_device(ubi->mtd); |
1098 | ubi_debugging_exit_dev(ubi); | 1041 | ubi_debugging_exit_dev(ubi); |
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index ad76592fb2f4..acec85deb6af 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c | |||
@@ -63,7 +63,7 @@ static int get_exclusive(struct ubi_volume_desc *desc) | |||
63 | users = vol->readers + vol->writers + vol->exclusive; | 63 | users = vol->readers + vol->writers + vol->exclusive; |
64 | ubi_assert(users > 0); | 64 | ubi_assert(users > 0); |
65 | if (users > 1) { | 65 | if (users > 1) { |
66 | dbg_err("%d users for volume %d", users, vol->vol_id); | 66 | ubi_err("%d users for volume %d", users, vol->vol_id); |
67 | err = -EBUSY; | 67 | err = -EBUSY; |
68 | } else { | 68 | } else { |
69 | vol->readers = vol->writers = 0; | 69 | vol->readers = vol->writers = 0; |
@@ -159,7 +159,7 @@ static loff_t vol_cdev_llseek(struct file *file, loff_t offset, int origin) | |||
159 | 159 | ||
160 | if (vol->updating) { | 160 | if (vol->updating) { |
161 | /* Update is in progress, seeking is prohibited */ | 161 | /* Update is in progress, seeking is prohibited */ |
162 | dbg_err("updating"); | 162 | ubi_err("updating"); |
163 | return -EBUSY; | 163 | return -EBUSY; |
164 | } | 164 | } |
165 | 165 | ||
@@ -178,7 +178,7 @@ static loff_t vol_cdev_llseek(struct file *file, loff_t offset, int origin) | |||
178 | } | 178 | } |
179 | 179 | ||
180 | if (new_offset < 0 || new_offset > vol->used_bytes) { | 180 | if (new_offset < 0 || new_offset > vol->used_bytes) { |
181 | dbg_err("bad seek %lld", new_offset); | 181 | ubi_err("bad seek %lld", new_offset); |
182 | return -EINVAL; | 182 | return -EINVAL; |
183 | } | 183 | } |
184 | 184 | ||
@@ -216,11 +216,11 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count, | |||
216 | count, *offp, vol->vol_id); | 216 | count, *offp, vol->vol_id); |
217 | 217 | ||
218 | if (vol->updating) { | 218 | if (vol->updating) { |
219 | dbg_err("updating"); | 219 | ubi_err("updating"); |
220 | return -EBUSY; | 220 | return -EBUSY; |
221 | } | 221 | } |
222 | if (vol->upd_marker) { | 222 | if (vol->upd_marker) { |
223 | dbg_err("damaged volume, update marker is set"); | 223 | ubi_err("damaged volume, update marker is set"); |
224 | return -EBADF; | 224 | return -EBADF; |
225 | } | 225 | } |
226 | if (*offp == vol->used_bytes || count == 0) | 226 | if (*offp == vol->used_bytes || count == 0) |
@@ -300,7 +300,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf, | |||
300 | 300 | ||
301 | lnum = div_u64_rem(*offp, vol->usable_leb_size, &off); | 301 | lnum = div_u64_rem(*offp, vol->usable_leb_size, &off); |
302 | if (off & (ubi->min_io_size - 1)) { | 302 | if (off & (ubi->min_io_size - 1)) { |
303 | dbg_err("unaligned position"); | 303 | ubi_err("unaligned position"); |
304 | return -EINVAL; | 304 | return -EINVAL; |
305 | } | 305 | } |
306 | 306 | ||
@@ -309,7 +309,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf, | |||
309 | 309 | ||
310 | /* We can write only in fractions of the minimum I/O unit */ | 310 | /* We can write only in fractions of the minimum I/O unit */ |
311 | if (count & (ubi->min_io_size - 1)) { | 311 | if (count & (ubi->min_io_size - 1)) { |
312 | dbg_err("unaligned write length"); | 312 | ubi_err("unaligned write length"); |
313 | return -EINVAL; | 313 | return -EINVAL; |
314 | } | 314 | } |
315 | 315 | ||
@@ -334,8 +334,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf, | |||
334 | break; | 334 | break; |
335 | } | 335 | } |
336 | 336 | ||
337 | err = ubi_eba_write_leb(ubi, vol, lnum, tbuf, off, len, | 337 | err = ubi_eba_write_leb(ubi, vol, lnum, tbuf, off, len); |
338 | UBI_UNKNOWN); | ||
339 | if (err) | 338 | if (err) |
340 | break; | 339 | break; |
341 | 340 | ||
@@ -477,9 +476,6 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd, | |||
477 | if (req.lnum < 0 || req.lnum >= vol->reserved_pebs || | 476 | if (req.lnum < 0 || req.lnum >= vol->reserved_pebs || |
478 | req.bytes < 0 || req.lnum >= vol->usable_leb_size) | 477 | req.bytes < 0 || req.lnum >= vol->usable_leb_size) |
479 | break; | 478 | break; |
480 | if (req.dtype != UBI_LONGTERM && req.dtype != UBI_SHORTTERM && | ||
481 | req.dtype != UBI_UNKNOWN) | ||
482 | break; | ||
483 | 479 | ||
484 | err = get_exclusive(desc); | 480 | err = get_exclusive(desc); |
485 | if (err < 0) | 481 | if (err < 0) |
@@ -518,7 +514,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd, | |||
518 | if (err) | 514 | if (err) |
519 | break; | 515 | break; |
520 | 516 | ||
521 | err = ubi_wl_flush(ubi); | 517 | err = ubi_wl_flush(ubi, UBI_ALL, UBI_ALL); |
522 | break; | 518 | break; |
523 | } | 519 | } |
524 | 520 | ||
@@ -532,7 +528,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd, | |||
532 | err = -EFAULT; | 528 | err = -EFAULT; |
533 | break; | 529 | break; |
534 | } | 530 | } |
535 | err = ubi_leb_map(desc, req.lnum, req.dtype); | 531 | err = ubi_leb_map(desc, req.lnum); |
536 | break; | 532 | break; |
537 | } | 533 | } |
538 | 534 | ||
@@ -647,8 +643,8 @@ static int verify_mkvol_req(const struct ubi_device *ubi, | |||
647 | return 0; | 643 | return 0; |
648 | 644 | ||
649 | bad: | 645 | bad: |
650 | dbg_err("bad volume creation request"); | 646 | ubi_err("bad volume creation request"); |
651 | ubi_dbg_dump_mkvol_req(req); | 647 | ubi_dump_mkvol_req(req); |
652 | return err; | 648 | return err; |
653 | } | 649 | } |
654 | 650 | ||
@@ -713,12 +709,12 @@ static int rename_volumes(struct ubi_device *ubi, | |||
713 | for (i = 0; i < req->count - 1; i++) { | 709 | for (i = 0; i < req->count - 1; i++) { |
714 | for (n = i + 1; n < req->count; n++) { | 710 | for (n = i + 1; n < req->count; n++) { |
715 | if (req->ents[i].vol_id == req->ents[n].vol_id) { | 711 | if (req->ents[i].vol_id == req->ents[n].vol_id) { |
716 | dbg_err("duplicated volume id %d", | 712 | ubi_err("duplicated volume id %d", |
717 | req->ents[i].vol_id); | 713 | req->ents[i].vol_id); |
718 | return -EINVAL; | 714 | return -EINVAL; |
719 | } | 715 | } |
720 | if (!strcmp(req->ents[i].name, req->ents[n].name)) { | 716 | if (!strcmp(req->ents[i].name, req->ents[n].name)) { |
721 | dbg_err("duplicated volume name \"%s\"", | 717 | ubi_err("duplicated volume name \"%s\"", |
722 | req->ents[i].name); | 718 | req->ents[i].name); |
723 | return -EINVAL; | 719 | return -EINVAL; |
724 | } | 720 | } |
@@ -741,7 +737,7 @@ static int rename_volumes(struct ubi_device *ubi, | |||
741 | re->desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_EXCLUSIVE); | 737 | re->desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_EXCLUSIVE); |
742 | if (IS_ERR(re->desc)) { | 738 | if (IS_ERR(re->desc)) { |
743 | err = PTR_ERR(re->desc); | 739 | err = PTR_ERR(re->desc); |
744 | dbg_err("cannot open volume %d, error %d", vol_id, err); | 740 | ubi_err("cannot open volume %d, error %d", vol_id, err); |
745 | kfree(re); | 741 | kfree(re); |
746 | goto out_free; | 742 | goto out_free; |
747 | } | 743 | } |
@@ -800,7 +796,7 @@ static int rename_volumes(struct ubi_device *ubi, | |||
800 | continue; | 796 | continue; |
801 | 797 | ||
802 | /* The volume exists but busy, or an error occurred */ | 798 | /* The volume exists but busy, or an error occurred */ |
803 | dbg_err("cannot open volume \"%s\", error %d", | 799 | ubi_err("cannot open volume \"%s\", error %d", |
804 | re->new_name, err); | 800 | re->new_name, err); |
805 | goto out_free; | 801 | goto out_free; |
806 | } | 802 | } |
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c index 61af9bb560ab..9f957c2d48e9 100644 --- a/drivers/mtd/ubi/debug.c +++ b/drivers/mtd/ubi/debug.c | |||
@@ -18,24 +18,49 @@ | |||
18 | * Author: Artem Bityutskiy (Битюцкий Артём) | 18 | * Author: Artem Bityutskiy (Битюцкий Артём) |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | ||
22 | * Here we keep all the UBI debugging stuff which should normally be disabled | ||
23 | * and compiled-out, but it is extremely helpful when hunting bugs or doing big | ||
24 | * changes. | ||
25 | */ | ||
26 | |||
27 | #ifdef CONFIG_MTD_UBI_DEBUG | ||
28 | |||
29 | #include "ubi.h" | 21 | #include "ubi.h" |
30 | #include <linux/debugfs.h> | 22 | #include <linux/debugfs.h> |
31 | #include <linux/uaccess.h> | 23 | #include <linux/uaccess.h> |
32 | #include <linux/module.h> | 24 | #include <linux/module.h> |
33 | 25 | ||
26 | |||
27 | /** | ||
28 | * ubi_dump_flash - dump a region of flash. | ||
29 | * @ubi: UBI device description object | ||
30 | * @pnum: the physical eraseblock number to dump | ||
31 | * @offset: the starting offset within the physical eraseblock to dump | ||
32 | * @len: the length of the region to dump | ||
33 | */ | ||
34 | void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len) | ||
35 | { | ||
36 | int err; | ||
37 | size_t read; | ||
38 | void *buf; | ||
39 | loff_t addr = (loff_t)pnum * ubi->peb_size + offset; | ||
40 | |||
41 | buf = vmalloc(len); | ||
42 | if (!buf) | ||
43 | return; | ||
44 | err = mtd_read(ubi->mtd, addr, len, &read, buf); | ||
45 | if (err && err != -EUCLEAN) { | ||
46 | ubi_err("error %d while reading %d bytes from PEB %d:%d, " | ||
47 | "read %zd bytes", err, len, pnum, offset, read); | ||
48 | goto out; | ||
49 | } | ||
50 | |||
51 | ubi_msg("dumping %d bytes of data from PEB %d, offset %d", | ||
52 | len, pnum, offset); | ||
53 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1); | ||
54 | out: | ||
55 | vfree(buf); | ||
56 | return; | ||
57 | } | ||
58 | |||
34 | /** | 59 | /** |
35 | * ubi_dbg_dump_ec_hdr - dump an erase counter header. | 60 | * ubi_dump_ec_hdr - dump an erase counter header. |
36 | * @ec_hdr: the erase counter header to dump | 61 | * @ec_hdr: the erase counter header to dump |
37 | */ | 62 | */ |
38 | void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) | 63 | void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) |
39 | { | 64 | { |
40 | printk(KERN_DEBUG "Erase counter header dump:\n"); | 65 | printk(KERN_DEBUG "Erase counter header dump:\n"); |
41 | printk(KERN_DEBUG "\tmagic %#08x\n", | 66 | printk(KERN_DEBUG "\tmagic %#08x\n", |
@@ -57,10 +82,10 @@ void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) | |||
57 | } | 82 | } |
58 | 83 | ||
59 | /** | 84 | /** |
60 | * ubi_dbg_dump_vid_hdr - dump a volume identifier header. | 85 | * ubi_dump_vid_hdr - dump a volume identifier header. |
61 | * @vid_hdr: the volume identifier header to dump | 86 | * @vid_hdr: the volume identifier header to dump |
62 | */ | 87 | */ |
63 | void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) | 88 | void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) |
64 | { | 89 | { |
65 | printk(KERN_DEBUG "Volume identifier header dump:\n"); | 90 | printk(KERN_DEBUG "Volume identifier header dump:\n"); |
66 | printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic)); | 91 | printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic)); |
@@ -82,10 +107,10 @@ void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) | |||
82 | } | 107 | } |
83 | 108 | ||
84 | /** | 109 | /** |
85 | * ubi_dbg_dump_vol_info- dump volume information. | 110 | * ubi_dump_vol_info - dump volume information. |
86 | * @vol: UBI volume description object | 111 | * @vol: UBI volume description object |
87 | */ | 112 | */ |
88 | void ubi_dbg_dump_vol_info(const struct ubi_volume *vol) | 113 | void ubi_dump_vol_info(const struct ubi_volume *vol) |
89 | { | 114 | { |
90 | printk(KERN_DEBUG "Volume information dump:\n"); | 115 | printk(KERN_DEBUG "Volume information dump:\n"); |
91 | printk(KERN_DEBUG "\tvol_id %d\n", vol->vol_id); | 116 | printk(KERN_DEBUG "\tvol_id %d\n", vol->vol_id); |
@@ -112,11 +137,11 @@ void ubi_dbg_dump_vol_info(const struct ubi_volume *vol) | |||
112 | } | 137 | } |
113 | 138 | ||
114 | /** | 139 | /** |
115 | * ubi_dbg_dump_vtbl_record - dump a &struct ubi_vtbl_record object. | 140 | * ubi_dump_vtbl_record - dump a &struct ubi_vtbl_record object. |
116 | * @r: the object to dump | 141 | * @r: the object to dump |
117 | * @idx: volume table index | 142 | * @idx: volume table index |
118 | */ | 143 | */ |
119 | void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) | 144 | void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) |
120 | { | 145 | { |
121 | int name_len = be16_to_cpu(r->name_len); | 146 | int name_len = be16_to_cpu(r->name_len); |
122 | 147 | ||
@@ -146,44 +171,44 @@ void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) | |||
146 | } | 171 | } |
147 | 172 | ||
148 | /** | 173 | /** |
149 | * ubi_dbg_dump_sv - dump a &struct ubi_scan_volume object. | 174 | * ubi_dump_av - dump a &struct ubi_ainf_volume object. |
150 | * @sv: the object to dump | 175 | * @av: the object to dump |
151 | */ | 176 | */ |
152 | void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv) | 177 | void ubi_dump_av(const struct ubi_ainf_volume *av) |
153 | { | 178 | { |
154 | printk(KERN_DEBUG "Volume scanning information dump:\n"); | 179 | printk(KERN_DEBUG "Volume attaching information dump:\n"); |
155 | printk(KERN_DEBUG "\tvol_id %d\n", sv->vol_id); | 180 | printk(KERN_DEBUG "\tvol_id %d\n", av->vol_id); |
156 | printk(KERN_DEBUG "\thighest_lnum %d\n", sv->highest_lnum); | 181 | printk(KERN_DEBUG "\thighest_lnum %d\n", av->highest_lnum); |
157 | printk(KERN_DEBUG "\tleb_count %d\n", sv->leb_count); | 182 | printk(KERN_DEBUG "\tleb_count %d\n", av->leb_count); |
158 | printk(KERN_DEBUG "\tcompat %d\n", sv->compat); | 183 | printk(KERN_DEBUG "\tcompat %d\n", av->compat); |
159 | printk(KERN_DEBUG "\tvol_type %d\n", sv->vol_type); | 184 | printk(KERN_DEBUG "\tvol_type %d\n", av->vol_type); |
160 | printk(KERN_DEBUG "\tused_ebs %d\n", sv->used_ebs); | 185 | printk(KERN_DEBUG "\tused_ebs %d\n", av->used_ebs); |
161 | printk(KERN_DEBUG "\tlast_data_size %d\n", sv->last_data_size); | 186 | printk(KERN_DEBUG "\tlast_data_size %d\n", av->last_data_size); |
162 | printk(KERN_DEBUG "\tdata_pad %d\n", sv->data_pad); | 187 | printk(KERN_DEBUG "\tdata_pad %d\n", av->data_pad); |
163 | } | 188 | } |
164 | 189 | ||
165 | /** | 190 | /** |
166 | * ubi_dbg_dump_seb - dump a &struct ubi_scan_leb object. | 191 | * ubi_dump_aeb - dump a &struct ubi_ainf_peb object. |
167 | * @seb: the object to dump | 192 | * @aeb: the object to dump |
168 | * @type: object type: 0 - not corrupted, 1 - corrupted | 193 | * @type: object type: 0 - not corrupted, 1 - corrupted |
169 | */ | 194 | */ |
170 | void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type) | 195 | void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type) |
171 | { | 196 | { |
172 | printk(KERN_DEBUG "eraseblock scanning information dump:\n"); | 197 | printk(KERN_DEBUG "eraseblock attaching information dump:\n"); |
173 | printk(KERN_DEBUG "\tec %d\n", seb->ec); | 198 | printk(KERN_DEBUG "\tec %d\n", aeb->ec); |
174 | printk(KERN_DEBUG "\tpnum %d\n", seb->pnum); | 199 | printk(KERN_DEBUG "\tpnum %d\n", aeb->pnum); |
175 | if (type == 0) { | 200 | if (type == 0) { |
176 | printk(KERN_DEBUG "\tlnum %d\n", seb->lnum); | 201 | printk(KERN_DEBUG "\tlnum %d\n", aeb->lnum); |
177 | printk(KERN_DEBUG "\tscrub %d\n", seb->scrub); | 202 | printk(KERN_DEBUG "\tscrub %d\n", aeb->scrub); |
178 | printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum); | 203 | printk(KERN_DEBUG "\tsqnum %llu\n", aeb->sqnum); |
179 | } | 204 | } |
180 | } | 205 | } |
181 | 206 | ||
182 | /** | 207 | /** |
183 | * ubi_dbg_dump_mkvol_req - dump a &struct ubi_mkvol_req object. | 208 | * ubi_dump_mkvol_req - dump a &struct ubi_mkvol_req object. |
184 | * @req: the object to dump | 209 | * @req: the object to dump |
185 | */ | 210 | */ |
186 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) | 211 | void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req) |
187 | { | 212 | { |
188 | char nm[17]; | 213 | char nm[17]; |
189 | 214 | ||
@@ -200,38 +225,6 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) | |||
200 | } | 225 | } |
201 | 226 | ||
202 | /** | 227 | /** |
203 | * ubi_dbg_dump_flash - dump a region of flash. | ||
204 | * @ubi: UBI device description object | ||
205 | * @pnum: the physical eraseblock number to dump | ||
206 | * @offset: the starting offset within the physical eraseblock to dump | ||
207 | * @len: the length of the region to dump | ||
208 | */ | ||
209 | void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len) | ||
210 | { | ||
211 | int err; | ||
212 | size_t read; | ||
213 | void *buf; | ||
214 | loff_t addr = (loff_t)pnum * ubi->peb_size + offset; | ||
215 | |||
216 | buf = vmalloc(len); | ||
217 | if (!buf) | ||
218 | return; | ||
219 | err = mtd_read(ubi->mtd, addr, len, &read, buf); | ||
220 | if (err && err != -EUCLEAN) { | ||
221 | ubi_err("error %d while reading %d bytes from PEB %d:%d, " | ||
222 | "read %zd bytes", err, len, pnum, offset, read); | ||
223 | goto out; | ||
224 | } | ||
225 | |||
226 | dbg_msg("dumping %d bytes of data from PEB %d, offset %d", | ||
227 | len, pnum, offset); | ||
228 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1); | ||
229 | out: | ||
230 | vfree(buf); | ||
231 | return; | ||
232 | } | ||
233 | |||
234 | /** | ||
235 | * ubi_debugging_init_dev - initialize debugging for an UBI device. | 228 | * ubi_debugging_init_dev - initialize debugging for an UBI device. |
236 | * @ubi: UBI device description object | 229 | * @ubi: UBI device description object |
237 | * | 230 | * |
@@ -479,5 +472,3 @@ void ubi_debugfs_exit_dev(struct ubi_device *ubi) | |||
479 | { | 472 | { |
480 | debugfs_remove_recursive(ubi->dbg->dfs_dir); | 473 | debugfs_remove_recursive(ubi->dbg->dfs_dir); |
481 | } | 474 | } |
482 | |||
483 | #endif /* CONFIG_MTD_UBI_DEBUG */ | ||
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h index ead2cd16ba75..d5d2645b51a7 100644 --- a/drivers/mtd/ubi/debug.h +++ b/drivers/mtd/ubi/debug.h | |||
@@ -21,21 +21,20 @@ | |||
21 | #ifndef __UBI_DEBUG_H__ | 21 | #ifndef __UBI_DEBUG_H__ |
22 | #define __UBI_DEBUG_H__ | 22 | #define __UBI_DEBUG_H__ |
23 | 23 | ||
24 | #ifdef CONFIG_MTD_UBI_DEBUG | 24 | void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); |
25 | void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr); | ||
26 | void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr); | ||
27 | |||
25 | #include <linux/random.h> | 28 | #include <linux/random.h> |
26 | 29 | ||
27 | #define ubi_assert(expr) do { \ | 30 | #define ubi_assert(expr) do { \ |
28 | if (unlikely(!(expr))) { \ | 31 | if (unlikely(!(expr))) { \ |
29 | printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \ | 32 | printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \ |
30 | __func__, __LINE__, current->pid); \ | 33 | __func__, __LINE__, current->pid); \ |
31 | ubi_dbg_dump_stack(); \ | 34 | dump_stack(); \ |
32 | } \ | 35 | } \ |
33 | } while (0) | 36 | } while (0) |
34 | 37 | ||
35 | #define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__) | ||
36 | |||
37 | #define ubi_dbg_dump_stack() dump_stack() | ||
38 | |||
39 | #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \ | 38 | #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \ |
40 | print_hex_dump(l, ps, pt, r, g, b, len, a) | 39 | print_hex_dump(l, ps, pt, r, g, b, len, a) |
41 | 40 | ||
@@ -58,17 +57,13 @@ | |||
58 | /* Initialization and build messages */ | 57 | /* Initialization and build messages */ |
59 | #define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__) | 58 | #define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__) |
60 | 59 | ||
61 | void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr); | 60 | void ubi_dump_vol_info(const struct ubi_volume *vol); |
62 | void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr); | 61 | void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx); |
63 | void ubi_dbg_dump_vol_info(const struct ubi_volume *vol); | 62 | void ubi_dump_av(const struct ubi_ainf_volume *av); |
64 | void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx); | 63 | void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type); |
65 | void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv); | 64 | void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req); |
66 | void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); | 65 | int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, |
67 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); | 66 | int len); |
68 | void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); | ||
69 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); | ||
70 | int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, | ||
71 | int offset, int len); | ||
72 | int ubi_debugging_init_dev(struct ubi_device *ubi); | 67 | int ubi_debugging_init_dev(struct ubi_device *ubi); |
73 | void ubi_debugging_exit_dev(struct ubi_device *ubi); | 68 | void ubi_debugging_exit_dev(struct ubi_device *ubi); |
74 | int ubi_debugfs_init(void); | 69 | int ubi_debugfs_init(void); |
@@ -167,73 +162,4 @@ static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi) | |||
167 | return 0; | 162 | return 0; |
168 | } | 163 | } |
169 | 164 | ||
170 | #else | ||
171 | |||
172 | /* Use "if (0)" to make compiler check arguments even if debugging is off */ | ||
173 | #define ubi_assert(expr) do { \ | ||
174 | if (0) { \ | ||
175 | printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \ | ||
176 | __func__, __LINE__, current->pid); \ | ||
177 | } \ | ||
178 | } while (0) | ||
179 | |||
180 | #define dbg_err(fmt, ...) do { \ | ||
181 | if (0) \ | ||
182 | ubi_err(fmt, ##__VA_ARGS__); \ | ||
183 | } while (0) | ||
184 | |||
185 | #define ubi_dbg_msg(fmt, ...) do { \ | ||
186 | if (0) \ | ||
187 | printk(KERN_DEBUG fmt "\n", ##__VA_ARGS__); \ | ||
188 | } while (0) | ||
189 | |||
190 | #define dbg_msg(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__) | ||
191 | #define dbg_gen(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__) | ||
192 | #define dbg_eba(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__) | ||
193 | #define dbg_wl(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__) | ||
194 | #define dbg_io(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__) | ||
195 | #define dbg_bld(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__) | ||
196 | |||
197 | static inline void ubi_dbg_dump_stack(void) { return; } | ||
198 | static inline void | ||
199 | ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) { return; } | ||
200 | static inline void | ||
201 | ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) { return; } | ||
202 | static inline void | ||
203 | ubi_dbg_dump_vol_info(const struct ubi_volume *vol) { return; } | ||
204 | static inline void | ||
205 | ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) { return; } | ||
206 | static inline void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv) { return; } | ||
207 | static inline void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, | ||
208 | int type) { return; } | ||
209 | static inline void | ||
210 | ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) { return; } | ||
211 | static inline void ubi_dbg_dump_flash(struct ubi_device *ubi, | ||
212 | int pnum, int offset, int len) { return; } | ||
213 | static inline void | ||
214 | ubi_dbg_print_hex_dump(const char *l, const char *ps, int pt, int r, | ||
215 | int g, const void *b, size_t len, bool a) { return; } | ||
216 | static inline int ubi_dbg_check_all_ff(struct ubi_device *ubi, | ||
217 | int pnum, int offset, | ||
218 | int len) { return 0; } | ||
219 | static inline int ubi_dbg_check_write(struct ubi_device *ubi, | ||
220 | const void *buf, int pnum, | ||
221 | int offset, int len) { return 0; } | ||
222 | |||
223 | static inline int ubi_debugging_init_dev(struct ubi_device *ubi) { return 0; } | ||
224 | static inline void ubi_debugging_exit_dev(struct ubi_device *ubi) { return; } | ||
225 | static inline int ubi_debugfs_init(void) { return 0; } | ||
226 | static inline void ubi_debugfs_exit(void) { return; } | ||
227 | static inline int ubi_debugfs_init_dev(struct ubi_device *ubi) { return 0; } | ||
228 | static inline void ubi_debugfs_exit_dev(struct ubi_device *ubi) { return; } | ||
229 | |||
230 | static inline int | ||
231 | ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi) { return 0; } | ||
232 | static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) { return 0; } | ||
233 | static inline int | ||
234 | ubi_dbg_is_write_failure(const struct ubi_device *ubi) { return 0; } | ||
235 | static inline int | ||
236 | ubi_dbg_is_erase_failure(const struct ubi_device *ubi) { return 0; } | ||
237 | |||
238 | #endif /* !CONFIG_MTD_UBI_DEBUG */ | ||
239 | #endif /* !__UBI_DEBUG_H__ */ | 165 | #endif /* !__UBI_DEBUG_H__ */ |
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c index 2455d620d96b..b703ac7729cf 100644 --- a/drivers/mtd/ubi/eba.c +++ b/drivers/mtd/ubi/eba.c | |||
@@ -341,7 +341,7 @@ int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol, | |||
341 | dbg_eba("erase LEB %d:%d, PEB %d", vol_id, lnum, pnum); | 341 | dbg_eba("erase LEB %d:%d, PEB %d", vol_id, lnum, pnum); |
342 | 342 | ||
343 | vol->eba_tbl[lnum] = UBI_LEB_UNMAPPED; | 343 | vol->eba_tbl[lnum] = UBI_LEB_UNMAPPED; |
344 | err = ubi_wl_put_peb(ubi, pnum, 0); | 344 | err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 0); |
345 | 345 | ||
346 | out_unlock: | 346 | out_unlock: |
347 | leb_write_unlock(ubi, vol_id, lnum); | 347 | leb_write_unlock(ubi, vol_id, lnum); |
@@ -507,7 +507,7 @@ static int recover_peb(struct ubi_device *ubi, int pnum, int vol_id, int lnum, | |||
507 | return -ENOMEM; | 507 | return -ENOMEM; |
508 | 508 | ||
509 | retry: | 509 | retry: |
510 | new_pnum = ubi_wl_get_peb(ubi, UBI_UNKNOWN); | 510 | new_pnum = ubi_wl_get_peb(ubi); |
511 | if (new_pnum < 0) { | 511 | if (new_pnum < 0) { |
512 | ubi_free_vid_hdr(ubi, vid_hdr); | 512 | ubi_free_vid_hdr(ubi, vid_hdr); |
513 | return new_pnum; | 513 | return new_pnum; |
@@ -550,7 +550,7 @@ retry: | |||
550 | ubi_free_vid_hdr(ubi, vid_hdr); | 550 | ubi_free_vid_hdr(ubi, vid_hdr); |
551 | 551 | ||
552 | vol->eba_tbl[lnum] = new_pnum; | 552 | vol->eba_tbl[lnum] = new_pnum; |
553 | ubi_wl_put_peb(ubi, pnum, 1); | 553 | ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1); |
554 | 554 | ||
555 | ubi_msg("data was successfully recovered"); | 555 | ubi_msg("data was successfully recovered"); |
556 | return 0; | 556 | return 0; |
@@ -558,7 +558,7 @@ retry: | |||
558 | out_unlock: | 558 | out_unlock: |
559 | mutex_unlock(&ubi->buf_mutex); | 559 | mutex_unlock(&ubi->buf_mutex); |
560 | out_put: | 560 | out_put: |
561 | ubi_wl_put_peb(ubi, new_pnum, 1); | 561 | ubi_wl_put_peb(ubi, vol_id, lnum, new_pnum, 1); |
562 | ubi_free_vid_hdr(ubi, vid_hdr); | 562 | ubi_free_vid_hdr(ubi, vid_hdr); |
563 | return err; | 563 | return err; |
564 | 564 | ||
@@ -568,7 +568,7 @@ write_error: | |||
568 | * get another one. | 568 | * get another one. |
569 | */ | 569 | */ |
570 | ubi_warn("failed to write to PEB %d", new_pnum); | 570 | ubi_warn("failed to write to PEB %d", new_pnum); |
571 | ubi_wl_put_peb(ubi, new_pnum, 1); | 571 | ubi_wl_put_peb(ubi, vol_id, lnum, new_pnum, 1); |
572 | if (++tries > UBI_IO_RETRIES) { | 572 | if (++tries > UBI_IO_RETRIES) { |
573 | ubi_free_vid_hdr(ubi, vid_hdr); | 573 | ubi_free_vid_hdr(ubi, vid_hdr); |
574 | return err; | 574 | return err; |
@@ -585,7 +585,6 @@ write_error: | |||
585 | * @buf: the data to write | 585 | * @buf: the data to write |
586 | * @offset: offset within the logical eraseblock where to write | 586 | * @offset: offset within the logical eraseblock where to write |
587 | * @len: how many bytes to write | 587 | * @len: how many bytes to write |
588 | * @dtype: data type | ||
589 | * | 588 | * |
590 | * This function writes data to logical eraseblock @lnum of a dynamic volume | 589 | * This function writes data to logical eraseblock @lnum of a dynamic volume |
591 | * @vol. Returns zero in case of success and a negative error code in case | 590 | * @vol. Returns zero in case of success and a negative error code in case |
@@ -593,7 +592,7 @@ write_error: | |||
593 | * written to the flash media, but may be some garbage. | 592 | * written to the flash media, but may be some garbage. |
594 | */ | 593 | */ |
595 | int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, | 594 | int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, |
596 | const void *buf, int offset, int len, int dtype) | 595 | const void *buf, int offset, int len) |
597 | { | 596 | { |
598 | int err, pnum, tries = 0, vol_id = vol->vol_id; | 597 | int err, pnum, tries = 0, vol_id = vol->vol_id; |
599 | struct ubi_vid_hdr *vid_hdr; | 598 | struct ubi_vid_hdr *vid_hdr; |
@@ -641,7 +640,7 @@ int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, | |||
641 | vid_hdr->data_pad = cpu_to_be32(vol->data_pad); | 640 | vid_hdr->data_pad = cpu_to_be32(vol->data_pad); |
642 | 641 | ||
643 | retry: | 642 | retry: |
644 | pnum = ubi_wl_get_peb(ubi, dtype); | 643 | pnum = ubi_wl_get_peb(ubi); |
645 | if (pnum < 0) { | 644 | if (pnum < 0) { |
646 | ubi_free_vid_hdr(ubi, vid_hdr); | 645 | ubi_free_vid_hdr(ubi, vid_hdr); |
647 | leb_write_unlock(ubi, vol_id, lnum); | 646 | leb_write_unlock(ubi, vol_id, lnum); |
@@ -687,7 +686,7 @@ write_error: | |||
687 | * eraseblock, so just put it and request a new one. We assume that if | 686 | * eraseblock, so just put it and request a new one. We assume that if |
688 | * this physical eraseblock went bad, the erase code will handle that. | 687 | * this physical eraseblock went bad, the erase code will handle that. |
689 | */ | 688 | */ |
690 | err = ubi_wl_put_peb(ubi, pnum, 1); | 689 | err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1); |
691 | if (err || ++tries > UBI_IO_RETRIES) { | 690 | if (err || ++tries > UBI_IO_RETRIES) { |
692 | ubi_ro_mode(ubi); | 691 | ubi_ro_mode(ubi); |
693 | leb_write_unlock(ubi, vol_id, lnum); | 692 | leb_write_unlock(ubi, vol_id, lnum); |
@@ -707,7 +706,6 @@ write_error: | |||
707 | * @lnum: logical eraseblock number | 706 | * @lnum: logical eraseblock number |
708 | * @buf: data to write | 707 | * @buf: data to write |
709 | * @len: how many bytes to write | 708 | * @len: how many bytes to write |
710 | * @dtype: data type | ||
711 | * @used_ebs: how many logical eraseblocks will this volume contain | 709 | * @used_ebs: how many logical eraseblocks will this volume contain |
712 | * | 710 | * |
713 | * This function writes data to logical eraseblock @lnum of static volume | 711 | * This function writes data to logical eraseblock @lnum of static volume |
@@ -724,8 +722,7 @@ write_error: | |||
724 | * code in case of failure. | 722 | * code in case of failure. |
725 | */ | 723 | */ |
726 | int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol, | 724 | int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol, |
727 | int lnum, const void *buf, int len, int dtype, | 725 | int lnum, const void *buf, int len, int used_ebs) |
728 | int used_ebs) | ||
729 | { | 726 | { |
730 | int err, pnum, tries = 0, data_size = len, vol_id = vol->vol_id; | 727 | int err, pnum, tries = 0, data_size = len, vol_id = vol->vol_id; |
731 | struct ubi_vid_hdr *vid_hdr; | 728 | struct ubi_vid_hdr *vid_hdr; |
@@ -763,7 +760,7 @@ int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol, | |||
763 | vid_hdr->data_crc = cpu_to_be32(crc); | 760 | vid_hdr->data_crc = cpu_to_be32(crc); |
764 | 761 | ||
765 | retry: | 762 | retry: |
766 | pnum = ubi_wl_get_peb(ubi, dtype); | 763 | pnum = ubi_wl_get_peb(ubi); |
767 | if (pnum < 0) { | 764 | if (pnum < 0) { |
768 | ubi_free_vid_hdr(ubi, vid_hdr); | 765 | ubi_free_vid_hdr(ubi, vid_hdr); |
769 | leb_write_unlock(ubi, vol_id, lnum); | 766 | leb_write_unlock(ubi, vol_id, lnum); |
@@ -807,7 +804,7 @@ write_error: | |||
807 | return err; | 804 | return err; |
808 | } | 805 | } |
809 | 806 | ||
810 | err = ubi_wl_put_peb(ubi, pnum, 1); | 807 | err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1); |
811 | if (err || ++tries > UBI_IO_RETRIES) { | 808 | if (err || ++tries > UBI_IO_RETRIES) { |
812 | ubi_ro_mode(ubi); | 809 | ubi_ro_mode(ubi); |
813 | leb_write_unlock(ubi, vol_id, lnum); | 810 | leb_write_unlock(ubi, vol_id, lnum); |
@@ -827,7 +824,6 @@ write_error: | |||
827 | * @lnum: logical eraseblock number | 824 | * @lnum: logical eraseblock number |
828 | * @buf: data to write | 825 | * @buf: data to write |
829 | * @len: how many bytes to write | 826 | * @len: how many bytes to write |
830 | * @dtype: data type | ||
831 | * | 827 | * |
832 | * This function changes the contents of a logical eraseblock atomically. @buf | 828 | * This function changes the contents of a logical eraseblock atomically. @buf |
833 | * has to contain new logical eraseblock data, and @len - the length of the | 829 | * has to contain new logical eraseblock data, and @len - the length of the |
@@ -839,7 +835,7 @@ write_error: | |||
839 | * LEB change may be done at a time. This is ensured by @ubi->alc_mutex. | 835 | * LEB change may be done at a time. This is ensured by @ubi->alc_mutex. |
840 | */ | 836 | */ |
841 | int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, | 837 | int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, |
842 | int lnum, const void *buf, int len, int dtype) | 838 | int lnum, const void *buf, int len) |
843 | { | 839 | { |
844 | int err, pnum, tries = 0, vol_id = vol->vol_id; | 840 | int err, pnum, tries = 0, vol_id = vol->vol_id; |
845 | struct ubi_vid_hdr *vid_hdr; | 841 | struct ubi_vid_hdr *vid_hdr; |
@@ -856,7 +852,7 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, | |||
856 | err = ubi_eba_unmap_leb(ubi, vol, lnum); | 852 | err = ubi_eba_unmap_leb(ubi, vol, lnum); |
857 | if (err) | 853 | if (err) |
858 | return err; | 854 | return err; |
859 | return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0, dtype); | 855 | return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0); |
860 | } | 856 | } |
861 | 857 | ||
862 | vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); | 858 | vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); |
@@ -881,7 +877,7 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, | |||
881 | vid_hdr->data_crc = cpu_to_be32(crc); | 877 | vid_hdr->data_crc = cpu_to_be32(crc); |
882 | 878 | ||
883 | retry: | 879 | retry: |
884 | pnum = ubi_wl_get_peb(ubi, dtype); | 880 | pnum = ubi_wl_get_peb(ubi); |
885 | if (pnum < 0) { | 881 | if (pnum < 0) { |
886 | err = pnum; | 882 | err = pnum; |
887 | goto out_leb_unlock; | 883 | goto out_leb_unlock; |
@@ -905,7 +901,7 @@ retry: | |||
905 | } | 901 | } |
906 | 902 | ||
907 | if (vol->eba_tbl[lnum] >= 0) { | 903 | if (vol->eba_tbl[lnum] >= 0) { |
908 | err = ubi_wl_put_peb(ubi, vol->eba_tbl[lnum], 0); | 904 | err = ubi_wl_put_peb(ubi, vol_id, lnum, vol->eba_tbl[lnum], 0); |
909 | if (err) | 905 | if (err) |
910 | goto out_leb_unlock; | 906 | goto out_leb_unlock; |
911 | } | 907 | } |
@@ -930,7 +926,7 @@ write_error: | |||
930 | goto out_leb_unlock; | 926 | goto out_leb_unlock; |
931 | } | 927 | } |
932 | 928 | ||
933 | err = ubi_wl_put_peb(ubi, pnum, 1); | 929 | err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1); |
934 | if (err || ++tries > UBI_IO_RETRIES) { | 930 | if (err || ++tries > UBI_IO_RETRIES) { |
935 | ubi_ro_mode(ubi); | 931 | ubi_ro_mode(ubi); |
936 | goto out_leb_unlock; | 932 | goto out_leb_unlock; |
@@ -1171,7 +1167,7 @@ out_unlock_leb: | |||
1171 | * print_rsvd_warning - warn about not having enough reserved PEBs. | 1167 | * print_rsvd_warning - warn about not having enough reserved PEBs. |
1172 | * @ubi: UBI device description object | 1168 | * @ubi: UBI device description object |
1173 | * | 1169 | * |
1174 | * This is a helper function for 'ubi_eba_init_scan()' which is called when UBI | 1170 | * This is a helper function for 'ubi_eba_init()' which is called when UBI |
1175 | * cannot reserve enough PEBs for bad block handling. This function makes a | 1171 | * cannot reserve enough PEBs for bad block handling. This function makes a |
1176 | * decision whether we have to print a warning or not. The algorithm is as | 1172 | * decision whether we have to print a warning or not. The algorithm is as |
1177 | * follows: | 1173 | * follows: |
@@ -1186,13 +1182,13 @@ out_unlock_leb: | |||
1186 | * reported by real users. | 1182 | * reported by real users. |
1187 | */ | 1183 | */ |
1188 | static void print_rsvd_warning(struct ubi_device *ubi, | 1184 | static void print_rsvd_warning(struct ubi_device *ubi, |
1189 | struct ubi_scan_info *si) | 1185 | struct ubi_attach_info *ai) |
1190 | { | 1186 | { |
1191 | /* | 1187 | /* |
1192 | * The 1 << 18 (256KiB) number is picked randomly, just a reasonably | 1188 | * The 1 << 18 (256KiB) number is picked randomly, just a reasonably |
1193 | * large number to distinguish between newly flashed and used images. | 1189 | * large number to distinguish between newly flashed and used images. |
1194 | */ | 1190 | */ |
1195 | if (si->max_sqnum > (1 << 18)) { | 1191 | if (ai->max_sqnum > (1 << 18)) { |
1196 | int min = ubi->beb_rsvd_level / 10; | 1192 | int min = ubi->beb_rsvd_level / 10; |
1197 | 1193 | ||
1198 | if (!min) | 1194 | if (!min) |
@@ -1209,19 +1205,19 @@ static void print_rsvd_warning(struct ubi_device *ubi, | |||
1209 | } | 1205 | } |
1210 | 1206 | ||
1211 | /** | 1207 | /** |
1212 | * ubi_eba_init_scan - initialize the EBA sub-system using scanning information. | 1208 | * ubi_eba_init - initialize the EBA sub-system using attaching information. |
1213 | * @ubi: UBI device description object | 1209 | * @ubi: UBI device description object |
1214 | * @si: scanning information | 1210 | * @ai: attaching information |
1215 | * | 1211 | * |
1216 | * This function returns zero in case of success and a negative error code in | 1212 | * This function returns zero in case of success and a negative error code in |
1217 | * case of failure. | 1213 | * case of failure. |
1218 | */ | 1214 | */ |
1219 | int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | 1215 | int ubi_eba_init(struct ubi_device *ubi, struct ubi_attach_info *ai) |
1220 | { | 1216 | { |
1221 | int i, j, err, num_volumes; | 1217 | int i, j, err, num_volumes; |
1222 | struct ubi_scan_volume *sv; | 1218 | struct ubi_ainf_volume *av; |
1223 | struct ubi_volume *vol; | 1219 | struct ubi_volume *vol; |
1224 | struct ubi_scan_leb *seb; | 1220 | struct ubi_ainf_peb *aeb; |
1225 | struct rb_node *rb; | 1221 | struct rb_node *rb; |
1226 | 1222 | ||
1227 | dbg_eba("initialize EBA sub-system"); | 1223 | dbg_eba("initialize EBA sub-system"); |
@@ -1230,7 +1226,7 @@ int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1230 | mutex_init(&ubi->alc_mutex); | 1226 | mutex_init(&ubi->alc_mutex); |
1231 | ubi->ltree = RB_ROOT; | 1227 | ubi->ltree = RB_ROOT; |
1232 | 1228 | ||
1233 | ubi->global_sqnum = si->max_sqnum + 1; | 1229 | ubi->global_sqnum = ai->max_sqnum + 1; |
1234 | num_volumes = ubi->vtbl_slots + UBI_INT_VOL_COUNT; | 1230 | num_volumes = ubi->vtbl_slots + UBI_INT_VOL_COUNT; |
1235 | 1231 | ||
1236 | for (i = 0; i < num_volumes; i++) { | 1232 | for (i = 0; i < num_volumes; i++) { |
@@ -1250,18 +1246,18 @@ int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1250 | for (j = 0; j < vol->reserved_pebs; j++) | 1246 | for (j = 0; j < vol->reserved_pebs; j++) |
1251 | vol->eba_tbl[j] = UBI_LEB_UNMAPPED; | 1247 | vol->eba_tbl[j] = UBI_LEB_UNMAPPED; |
1252 | 1248 | ||
1253 | sv = ubi_scan_find_sv(si, idx2vol_id(ubi, i)); | 1249 | av = ubi_find_av(ai, idx2vol_id(ubi, i)); |
1254 | if (!sv) | 1250 | if (!av) |
1255 | continue; | 1251 | continue; |
1256 | 1252 | ||
1257 | ubi_rb_for_each_entry(rb, seb, &sv->root, u.rb) { | 1253 | ubi_rb_for_each_entry(rb, aeb, &av->root, u.rb) { |
1258 | if (seb->lnum >= vol->reserved_pebs) | 1254 | if (aeb->lnum >= vol->reserved_pebs) |
1259 | /* | 1255 | /* |
1260 | * This may happen in case of an unclean reboot | 1256 | * This may happen in case of an unclean reboot |
1261 | * during re-size. | 1257 | * during re-size. |
1262 | */ | 1258 | */ |
1263 | ubi_scan_move_to_list(sv, seb, &si->erase); | 1259 | ubi_move_aeb_to_list(av, aeb, &ai->erase); |
1264 | vol->eba_tbl[seb->lnum] = seb->pnum; | 1260 | vol->eba_tbl[aeb->lnum] = aeb->pnum; |
1265 | } | 1261 | } |
1266 | } | 1262 | } |
1267 | 1263 | ||
@@ -1283,7 +1279,7 @@ int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1283 | if (ubi->avail_pebs < ubi->beb_rsvd_level) { | 1279 | if (ubi->avail_pebs < ubi->beb_rsvd_level) { |
1284 | /* No enough free physical eraseblocks */ | 1280 | /* No enough free physical eraseblocks */ |
1285 | ubi->beb_rsvd_pebs = ubi->avail_pebs; | 1281 | ubi->beb_rsvd_pebs = ubi->avail_pebs; |
1286 | print_rsvd_warning(ubi, si); | 1282 | print_rsvd_warning(ubi, ai); |
1287 | } else | 1283 | } else |
1288 | ubi->beb_rsvd_pebs = ubi->beb_rsvd_level; | 1284 | ubi->beb_rsvd_pebs = ubi->beb_rsvd_level; |
1289 | 1285 | ||
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c index 90b98822d9a4..4e44bee4c564 100644 --- a/drivers/mtd/ubi/gluebi.c +++ b/drivers/mtd/ubi/gluebi.c | |||
@@ -227,7 +227,7 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
227 | if (to_write > total_written) | 227 | if (to_write > total_written) |
228 | to_write = total_written; | 228 | to_write = total_written; |
229 | 229 | ||
230 | err = ubi_write(gluebi->desc, lnum, buf, offs, to_write); | 230 | err = ubi_leb_write(gluebi->desc, lnum, buf, offs, to_write); |
231 | if (err) | 231 | if (err) |
232 | break; | 232 | break; |
233 | 233 | ||
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 43f1a0011a55..a8d523794b52 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
@@ -91,21 +91,15 @@ | |||
91 | #include <linux/slab.h> | 91 | #include <linux/slab.h> |
92 | #include "ubi.h" | 92 | #include "ubi.h" |
93 | 93 | ||
94 | #ifdef CONFIG_MTD_UBI_DEBUG | 94 | static int self_check_not_bad(const struct ubi_device *ubi, int pnum); |
95 | static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum); | 95 | static int self_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum); |
96 | static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum); | 96 | static int self_check_ec_hdr(const struct ubi_device *ubi, int pnum, |
97 | static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, | 97 | const struct ubi_ec_hdr *ec_hdr); |
98 | const struct ubi_ec_hdr *ec_hdr); | 98 | static int self_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum); |
99 | static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum); | 99 | static int self_check_vid_hdr(const struct ubi_device *ubi, int pnum, |
100 | static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, | 100 | const struct ubi_vid_hdr *vid_hdr); |
101 | const struct ubi_vid_hdr *vid_hdr); | 101 | static int self_check_write(struct ubi_device *ubi, const void *buf, int pnum, |
102 | #else | 102 | int offset, int len); |
103 | #define paranoid_check_not_bad(ubi, pnum) 0 | ||
104 | #define paranoid_check_peb_ec_hdr(ubi, pnum) 0 | ||
105 | #define paranoid_check_ec_hdr(ubi, pnum, ec_hdr) 0 | ||
106 | #define paranoid_check_peb_vid_hdr(ubi, pnum) 0 | ||
107 | #define paranoid_check_vid_hdr(ubi, pnum, vid_hdr) 0 | ||
108 | #endif | ||
109 | 103 | ||
110 | /** | 104 | /** |
111 | * ubi_io_read - read data from a physical eraseblock. | 105 | * ubi_io_read - read data from a physical eraseblock. |
@@ -142,7 +136,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset, | |||
142 | ubi_assert(offset >= 0 && offset + len <= ubi->peb_size); | 136 | ubi_assert(offset >= 0 && offset + len <= ubi->peb_size); |
143 | ubi_assert(len > 0); | 137 | ubi_assert(len > 0); |
144 | 138 | ||
145 | err = paranoid_check_not_bad(ubi, pnum); | 139 | err = self_check_not_bad(ubi, pnum); |
146 | if (err) | 140 | if (err) |
147 | return err; | 141 | return err; |
148 | 142 | ||
@@ -189,16 +183,16 @@ retry: | |||
189 | } | 183 | } |
190 | 184 | ||
191 | if (retries++ < UBI_IO_RETRIES) { | 185 | if (retries++ < UBI_IO_RETRIES) { |
192 | dbg_io("error %d%s while reading %d bytes from PEB " | 186 | ubi_warn("error %d%s while reading %d bytes from PEB " |
193 | "%d:%d, read only %zd bytes, retry", | 187 | "%d:%d, read only %zd bytes, retry", |
194 | err, errstr, len, pnum, offset, read); | 188 | err, errstr, len, pnum, offset, read); |
195 | yield(); | 189 | yield(); |
196 | goto retry; | 190 | goto retry; |
197 | } | 191 | } |
198 | 192 | ||
199 | ubi_err("error %d%s while reading %d bytes from PEB %d:%d, " | 193 | ubi_err("error %d%s while reading %d bytes from PEB %d:%d, " |
200 | "read %zd bytes", err, errstr, len, pnum, offset, read); | 194 | "read %zd bytes", err, errstr, len, pnum, offset, read); |
201 | ubi_dbg_dump_stack(); | 195 | dump_stack(); |
202 | 196 | ||
203 | /* | 197 | /* |
204 | * The driver should never return -EBADMSG if it failed to read | 198 | * The driver should never return -EBADMSG if it failed to read |
@@ -257,14 +251,12 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
257 | return -EROFS; | 251 | return -EROFS; |
258 | } | 252 | } |
259 | 253 | ||
260 | /* The below has to be compiled out if paranoid checks are disabled */ | 254 | err = self_check_not_bad(ubi, pnum); |
261 | |||
262 | err = paranoid_check_not_bad(ubi, pnum); | ||
263 | if (err) | 255 | if (err) |
264 | return err; | 256 | return err; |
265 | 257 | ||
266 | /* The area we are writing to has to contain all 0xFF bytes */ | 258 | /* The area we are writing to has to contain all 0xFF bytes */ |
267 | err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); | 259 | err = ubi_self_check_all_ff(ubi, pnum, offset, len); |
268 | if (err) | 260 | if (err) |
269 | return err; | 261 | return err; |
270 | 262 | ||
@@ -273,18 +265,18 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
273 | * We write to the data area of the physical eraseblock. Make | 265 | * We write to the data area of the physical eraseblock. Make |
274 | * sure it has valid EC and VID headers. | 266 | * sure it has valid EC and VID headers. |
275 | */ | 267 | */ |
276 | err = paranoid_check_peb_ec_hdr(ubi, pnum); | 268 | err = self_check_peb_ec_hdr(ubi, pnum); |
277 | if (err) | 269 | if (err) |
278 | return err; | 270 | return err; |
279 | err = paranoid_check_peb_vid_hdr(ubi, pnum); | 271 | err = self_check_peb_vid_hdr(ubi, pnum); |
280 | if (err) | 272 | if (err) |
281 | return err; | 273 | return err; |
282 | } | 274 | } |
283 | 275 | ||
284 | if (ubi_dbg_is_write_failure(ubi)) { | 276 | if (ubi_dbg_is_write_failure(ubi)) { |
285 | dbg_err("cannot write %d bytes to PEB %d:%d " | 277 | ubi_err("cannot write %d bytes to PEB %d:%d " |
286 | "(emulated)", len, pnum, offset); | 278 | "(emulated)", len, pnum, offset); |
287 | ubi_dbg_dump_stack(); | 279 | dump_stack(); |
288 | return -EIO; | 280 | return -EIO; |
289 | } | 281 | } |
290 | 282 | ||
@@ -293,13 +285,13 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
293 | if (err) { | 285 | if (err) { |
294 | ubi_err("error %d while writing %d bytes to PEB %d:%d, written " | 286 | ubi_err("error %d while writing %d bytes to PEB %d:%d, written " |
295 | "%zd bytes", err, len, pnum, offset, written); | 287 | "%zd bytes", err, len, pnum, offset, written); |
296 | ubi_dbg_dump_stack(); | 288 | dump_stack(); |
297 | ubi_dbg_dump_flash(ubi, pnum, offset, len); | 289 | ubi_dump_flash(ubi, pnum, offset, len); |
298 | } else | 290 | } else |
299 | ubi_assert(written == len); | 291 | ubi_assert(written == len); |
300 | 292 | ||
301 | if (!err) { | 293 | if (!err) { |
302 | err = ubi_dbg_check_write(ubi, buf, pnum, offset, len); | 294 | err = self_check_write(ubi, buf, pnum, offset, len); |
303 | if (err) | 295 | if (err) |
304 | return err; | 296 | return err; |
305 | 297 | ||
@@ -310,7 +302,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
310 | offset += len; | 302 | offset += len; |
311 | len = ubi->peb_size - offset; | 303 | len = ubi->peb_size - offset; |
312 | if (len) | 304 | if (len) |
313 | err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); | 305 | err = ubi_self_check_all_ff(ubi, pnum, offset, len); |
314 | } | 306 | } |
315 | 307 | ||
316 | return err; | 308 | return err; |
@@ -364,13 +356,13 @@ retry: | |||
364 | err = mtd_erase(ubi->mtd, &ei); | 356 | err = mtd_erase(ubi->mtd, &ei); |
365 | if (err) { | 357 | if (err) { |
366 | if (retries++ < UBI_IO_RETRIES) { | 358 | if (retries++ < UBI_IO_RETRIES) { |
367 | dbg_io("error %d while erasing PEB %d, retry", | 359 | ubi_warn("error %d while erasing PEB %d, retry", |
368 | err, pnum); | 360 | err, pnum); |
369 | yield(); | 361 | yield(); |
370 | goto retry; | 362 | goto retry; |
371 | } | 363 | } |
372 | ubi_err("cannot erase PEB %d, error %d", pnum, err); | 364 | ubi_err("cannot erase PEB %d, error %d", pnum, err); |
373 | ubi_dbg_dump_stack(); | 365 | dump_stack(); |
374 | return err; | 366 | return err; |
375 | } | 367 | } |
376 | 368 | ||
@@ -383,21 +375,21 @@ retry: | |||
383 | 375 | ||
384 | if (ei.state == MTD_ERASE_FAILED) { | 376 | if (ei.state == MTD_ERASE_FAILED) { |
385 | if (retries++ < UBI_IO_RETRIES) { | 377 | if (retries++ < UBI_IO_RETRIES) { |
386 | dbg_io("error while erasing PEB %d, retry", pnum); | 378 | ubi_warn("error while erasing PEB %d, retry", pnum); |
387 | yield(); | 379 | yield(); |
388 | goto retry; | 380 | goto retry; |
389 | } | 381 | } |
390 | ubi_err("cannot erase PEB %d", pnum); | 382 | ubi_err("cannot erase PEB %d", pnum); |
391 | ubi_dbg_dump_stack(); | 383 | dump_stack(); |
392 | return -EIO; | 384 | return -EIO; |
393 | } | 385 | } |
394 | 386 | ||
395 | err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size); | 387 | err = ubi_self_check_all_ff(ubi, pnum, 0, ubi->peb_size); |
396 | if (err) | 388 | if (err) |
397 | return err; | 389 | return err; |
398 | 390 | ||
399 | if (ubi_dbg_is_erase_failure(ubi)) { | 391 | if (ubi_dbg_is_erase_failure(ubi)) { |
400 | dbg_err("cannot erase PEB %d (emulated)", pnum); | 392 | ubi_err("cannot erase PEB %d (emulated)", pnum); |
401 | return -EIO; | 393 | return -EIO; |
402 | } | 394 | } |
403 | 395 | ||
@@ -521,8 +513,7 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum) | |||
521 | * It is important to first invalidate the EC header, and then the VID | 513 | * It is important to first invalidate the EC header, and then the VID |
522 | * header. Otherwise a power cut may lead to valid EC header and | 514 | * header. Otherwise a power cut may lead to valid EC header and |
523 | * invalid VID header, in which case UBI will treat this PEB as | 515 | * invalid VID header, in which case UBI will treat this PEB as |
524 | * corrupted and will try to preserve it, and print scary warnings (see | 516 | * corrupted and will try to preserve it, and print scary warnings. |
525 | * the header comment in scan.c for more information). | ||
526 | */ | 517 | */ |
527 | addr = (loff_t)pnum * ubi->peb_size; | 518 | addr = (loff_t)pnum * ubi->peb_size; |
528 | err = mtd_write(ubi->mtd, addr, 4, &written, (void *)&data); | 519 | err = mtd_write(ubi->mtd, addr, 4, &written, (void *)&data); |
@@ -563,7 +554,7 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum) | |||
563 | */ | 554 | */ |
564 | ubi_err("cannot invalidate PEB %d, write returned %d read returned %d", | 555 | ubi_err("cannot invalidate PEB %d, write returned %d read returned %d", |
565 | pnum, err, err1); | 556 | pnum, err, err1); |
566 | ubi_dbg_dump_flash(ubi, pnum, 0, ubi->peb_size); | 557 | ubi_dump_flash(ubi, pnum, 0, ubi->peb_size); |
567 | return -EIO; | 558 | return -EIO; |
568 | } | 559 | } |
569 | 560 | ||
@@ -589,7 +580,7 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture) | |||
589 | 580 | ||
590 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); | 581 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); |
591 | 582 | ||
592 | err = paranoid_check_not_bad(ubi, pnum); | 583 | err = self_check_not_bad(ubi, pnum); |
593 | if (err != 0) | 584 | if (err != 0) |
594 | return err; | 585 | return err; |
595 | 586 | ||
@@ -721,8 +712,8 @@ static int validate_ec_hdr(const struct ubi_device *ubi, | |||
721 | 712 | ||
722 | bad: | 713 | bad: |
723 | ubi_err("bad EC header"); | 714 | ubi_err("bad EC header"); |
724 | ubi_dbg_dump_ec_hdr(ec_hdr); | 715 | ubi_dump_ec_hdr(ec_hdr); |
725 | ubi_dbg_dump_stack(); | 716 | dump_stack(); |
726 | return 1; | 717 | return 1; |
727 | } | 718 | } |
728 | 719 | ||
@@ -803,7 +794,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, | |||
803 | if (verbose) { | 794 | if (verbose) { |
804 | ubi_warn("bad magic number at PEB %d: %08x instead of " | 795 | ubi_warn("bad magic number at PEB %d: %08x instead of " |
805 | "%08x", pnum, magic, UBI_EC_HDR_MAGIC); | 796 | "%08x", pnum, magic, UBI_EC_HDR_MAGIC); |
806 | ubi_dbg_dump_ec_hdr(ec_hdr); | 797 | ubi_dump_ec_hdr(ec_hdr); |
807 | } | 798 | } |
808 | dbg_bld("bad magic number at PEB %d: %08x instead of " | 799 | dbg_bld("bad magic number at PEB %d: %08x instead of " |
809 | "%08x", pnum, magic, UBI_EC_HDR_MAGIC); | 800 | "%08x", pnum, magic, UBI_EC_HDR_MAGIC); |
@@ -817,7 +808,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, | |||
817 | if (verbose) { | 808 | if (verbose) { |
818 | ubi_warn("bad EC header CRC at PEB %d, calculated " | 809 | ubi_warn("bad EC header CRC at PEB %d, calculated " |
819 | "%#08x, read %#08x", pnum, crc, hdr_crc); | 810 | "%#08x, read %#08x", pnum, crc, hdr_crc); |
820 | ubi_dbg_dump_ec_hdr(ec_hdr); | 811 | ubi_dump_ec_hdr(ec_hdr); |
821 | } | 812 | } |
822 | dbg_bld("bad EC header CRC at PEB %d, calculated " | 813 | dbg_bld("bad EC header CRC at PEB %d, calculated " |
823 | "%#08x, read %#08x", pnum, crc, hdr_crc); | 814 | "%#08x, read %#08x", pnum, crc, hdr_crc); |
@@ -874,7 +865,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum, | |||
874 | crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); | 865 | crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); |
875 | ec_hdr->hdr_crc = cpu_to_be32(crc); | 866 | ec_hdr->hdr_crc = cpu_to_be32(crc); |
876 | 867 | ||
877 | err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); | 868 | err = self_check_ec_hdr(ubi, pnum, ec_hdr); |
878 | if (err) | 869 | if (err) |
879 | return err; | 870 | return err; |
880 | 871 | ||
@@ -905,40 +896,40 @@ static int validate_vid_hdr(const struct ubi_device *ubi, | |||
905 | int usable_leb_size = ubi->leb_size - data_pad; | 896 | int usable_leb_size = ubi->leb_size - data_pad; |
906 | 897 | ||
907 | if (copy_flag != 0 && copy_flag != 1) { | 898 | if (copy_flag != 0 && copy_flag != 1) { |
908 | dbg_err("bad copy_flag"); | 899 | ubi_err("bad copy_flag"); |
909 | goto bad; | 900 | goto bad; |
910 | } | 901 | } |
911 | 902 | ||
912 | if (vol_id < 0 || lnum < 0 || data_size < 0 || used_ebs < 0 || | 903 | if (vol_id < 0 || lnum < 0 || data_size < 0 || used_ebs < 0 || |
913 | data_pad < 0) { | 904 | data_pad < 0) { |
914 | dbg_err("negative values"); | 905 | ubi_err("negative values"); |
915 | goto bad; | 906 | goto bad; |
916 | } | 907 | } |
917 | 908 | ||
918 | if (vol_id >= UBI_MAX_VOLUMES && vol_id < UBI_INTERNAL_VOL_START) { | 909 | if (vol_id >= UBI_MAX_VOLUMES && vol_id < UBI_INTERNAL_VOL_START) { |
919 | dbg_err("bad vol_id"); | 910 | ubi_err("bad vol_id"); |
920 | goto bad; | 911 | goto bad; |
921 | } | 912 | } |
922 | 913 | ||
923 | if (vol_id < UBI_INTERNAL_VOL_START && compat != 0) { | 914 | if (vol_id < UBI_INTERNAL_VOL_START && compat != 0) { |
924 | dbg_err("bad compat"); | 915 | ubi_err("bad compat"); |
925 | goto bad; | 916 | goto bad; |
926 | } | 917 | } |
927 | 918 | ||
928 | if (vol_id >= UBI_INTERNAL_VOL_START && compat != UBI_COMPAT_DELETE && | 919 | if (vol_id >= UBI_INTERNAL_VOL_START && compat != UBI_COMPAT_DELETE && |
929 | compat != UBI_COMPAT_RO && compat != UBI_COMPAT_PRESERVE && | 920 | compat != UBI_COMPAT_RO && compat != UBI_COMPAT_PRESERVE && |
930 | compat != UBI_COMPAT_REJECT) { | 921 | compat != UBI_COMPAT_REJECT) { |
931 | dbg_err("bad compat"); | 922 | ubi_err("bad compat"); |
932 | goto bad; | 923 | goto bad; |
933 | } | 924 | } |
934 | 925 | ||
935 | if (vol_type != UBI_VID_DYNAMIC && vol_type != UBI_VID_STATIC) { | 926 | if (vol_type != UBI_VID_DYNAMIC && vol_type != UBI_VID_STATIC) { |
936 | dbg_err("bad vol_type"); | 927 | ubi_err("bad vol_type"); |
937 | goto bad; | 928 | goto bad; |
938 | } | 929 | } |
939 | 930 | ||
940 | if (data_pad >= ubi->leb_size / 2) { | 931 | if (data_pad >= ubi->leb_size / 2) { |
941 | dbg_err("bad data_pad"); | 932 | ubi_err("bad data_pad"); |
942 | goto bad; | 933 | goto bad; |
943 | } | 934 | } |
944 | 935 | ||
@@ -950,45 +941,45 @@ static int validate_vid_hdr(const struct ubi_device *ubi, | |||
950 | * mapped logical eraseblocks. | 941 | * mapped logical eraseblocks. |
951 | */ | 942 | */ |
952 | if (used_ebs == 0) { | 943 | if (used_ebs == 0) { |
953 | dbg_err("zero used_ebs"); | 944 | ubi_err("zero used_ebs"); |
954 | goto bad; | 945 | goto bad; |
955 | } | 946 | } |
956 | if (data_size == 0) { | 947 | if (data_size == 0) { |
957 | dbg_err("zero data_size"); | 948 | ubi_err("zero data_size"); |
958 | goto bad; | 949 | goto bad; |
959 | } | 950 | } |
960 | if (lnum < used_ebs - 1) { | 951 | if (lnum < used_ebs - 1) { |
961 | if (data_size != usable_leb_size) { | 952 | if (data_size != usable_leb_size) { |
962 | dbg_err("bad data_size"); | 953 | ubi_err("bad data_size"); |
963 | goto bad; | 954 | goto bad; |
964 | } | 955 | } |
965 | } else if (lnum == used_ebs - 1) { | 956 | } else if (lnum == used_ebs - 1) { |
966 | if (data_size == 0) { | 957 | if (data_size == 0) { |
967 | dbg_err("bad data_size at last LEB"); | 958 | ubi_err("bad data_size at last LEB"); |
968 | goto bad; | 959 | goto bad; |
969 | } | 960 | } |
970 | } else { | 961 | } else { |
971 | dbg_err("too high lnum"); | 962 | ubi_err("too high lnum"); |
972 | goto bad; | 963 | goto bad; |
973 | } | 964 | } |
974 | } else { | 965 | } else { |
975 | if (copy_flag == 0) { | 966 | if (copy_flag == 0) { |
976 | if (data_crc != 0) { | 967 | if (data_crc != 0) { |
977 | dbg_err("non-zero data CRC"); | 968 | ubi_err("non-zero data CRC"); |
978 | goto bad; | 969 | goto bad; |
979 | } | 970 | } |
980 | if (data_size != 0) { | 971 | if (data_size != 0) { |
981 | dbg_err("non-zero data_size"); | 972 | ubi_err("non-zero data_size"); |
982 | goto bad; | 973 | goto bad; |
983 | } | 974 | } |
984 | } else { | 975 | } else { |
985 | if (data_size == 0) { | 976 | if (data_size == 0) { |
986 | dbg_err("zero data_size of copy"); | 977 | ubi_err("zero data_size of copy"); |
987 | goto bad; | 978 | goto bad; |
988 | } | 979 | } |
989 | } | 980 | } |
990 | if (used_ebs != 0) { | 981 | if (used_ebs != 0) { |
991 | dbg_err("bad used_ebs"); | 982 | ubi_err("bad used_ebs"); |
992 | goto bad; | 983 | goto bad; |
993 | } | 984 | } |
994 | } | 985 | } |
@@ -997,8 +988,8 @@ static int validate_vid_hdr(const struct ubi_device *ubi, | |||
997 | 988 | ||
998 | bad: | 989 | bad: |
999 | ubi_err("bad VID header"); | 990 | ubi_err("bad VID header"); |
1000 | ubi_dbg_dump_vid_hdr(vid_hdr); | 991 | ubi_dump_vid_hdr(vid_hdr); |
1001 | ubi_dbg_dump_stack(); | 992 | dump_stack(); |
1002 | return 1; | 993 | return 1; |
1003 | } | 994 | } |
1004 | 995 | ||
@@ -1054,7 +1045,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1054 | if (verbose) { | 1045 | if (verbose) { |
1055 | ubi_warn("bad magic number at PEB %d: %08x instead of " | 1046 | ubi_warn("bad magic number at PEB %d: %08x instead of " |
1056 | "%08x", pnum, magic, UBI_VID_HDR_MAGIC); | 1047 | "%08x", pnum, magic, UBI_VID_HDR_MAGIC); |
1057 | ubi_dbg_dump_vid_hdr(vid_hdr); | 1048 | ubi_dump_vid_hdr(vid_hdr); |
1058 | } | 1049 | } |
1059 | dbg_bld("bad magic number at PEB %d: %08x instead of " | 1050 | dbg_bld("bad magic number at PEB %d: %08x instead of " |
1060 | "%08x", pnum, magic, UBI_VID_HDR_MAGIC); | 1051 | "%08x", pnum, magic, UBI_VID_HDR_MAGIC); |
@@ -1068,7 +1059,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1068 | if (verbose) { | 1059 | if (verbose) { |
1069 | ubi_warn("bad CRC at PEB %d, calculated %#08x, " | 1060 | ubi_warn("bad CRC at PEB %d, calculated %#08x, " |
1070 | "read %#08x", pnum, crc, hdr_crc); | 1061 | "read %#08x", pnum, crc, hdr_crc); |
1071 | ubi_dbg_dump_vid_hdr(vid_hdr); | 1062 | ubi_dump_vid_hdr(vid_hdr); |
1072 | } | 1063 | } |
1073 | dbg_bld("bad CRC at PEB %d, calculated %#08x, " | 1064 | dbg_bld("bad CRC at PEB %d, calculated %#08x, " |
1074 | "read %#08x", pnum, crc, hdr_crc); | 1065 | "read %#08x", pnum, crc, hdr_crc); |
@@ -1112,7 +1103,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1112 | dbg_io("write VID header to PEB %d", pnum); | 1103 | dbg_io("write VID header to PEB %d", pnum); |
1113 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); | 1104 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); |
1114 | 1105 | ||
1115 | err = paranoid_check_peb_ec_hdr(ubi, pnum); | 1106 | err = self_check_peb_ec_hdr(ubi, pnum); |
1116 | if (err) | 1107 | if (err) |
1117 | return err; | 1108 | return err; |
1118 | 1109 | ||
@@ -1121,7 +1112,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1121 | crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); | 1112 | crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); |
1122 | vid_hdr->hdr_crc = cpu_to_be32(crc); | 1113 | vid_hdr->hdr_crc = cpu_to_be32(crc); |
1123 | 1114 | ||
1124 | err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); | 1115 | err = self_check_vid_hdr(ubi, pnum, vid_hdr); |
1125 | if (err) | 1116 | if (err) |
1126 | return err; | 1117 | return err; |
1127 | 1118 | ||
@@ -1131,17 +1122,15 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1131 | return err; | 1122 | return err; |
1132 | } | 1123 | } |
1133 | 1124 | ||
1134 | #ifdef CONFIG_MTD_UBI_DEBUG | ||
1135 | |||
1136 | /** | 1125 | /** |
1137 | * paranoid_check_not_bad - ensure that a physical eraseblock is not bad. | 1126 | * self_check_not_bad - ensure that a physical eraseblock is not bad. |
1138 | * @ubi: UBI device description object | 1127 | * @ubi: UBI device description object |
1139 | * @pnum: physical eraseblock number to check | 1128 | * @pnum: physical eraseblock number to check |
1140 | * | 1129 | * |
1141 | * This function returns zero if the physical eraseblock is good, %-EINVAL if | 1130 | * This function returns zero if the physical eraseblock is good, %-EINVAL if |
1142 | * it is bad and a negative error code if an error occurred. | 1131 | * it is bad and a negative error code if an error occurred. |
1143 | */ | 1132 | */ |
1144 | static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | 1133 | static int self_check_not_bad(const struct ubi_device *ubi, int pnum) |
1145 | { | 1134 | { |
1146 | int err; | 1135 | int err; |
1147 | 1136 | ||
@@ -1152,13 +1141,13 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | |||
1152 | if (!err) | 1141 | if (!err) |
1153 | return err; | 1142 | return err; |
1154 | 1143 | ||
1155 | ubi_err("paranoid check failed for PEB %d", pnum); | 1144 | ubi_err("self-check failed for PEB %d", pnum); |
1156 | ubi_dbg_dump_stack(); | 1145 | dump_stack(); |
1157 | return err > 0 ? -EINVAL : err; | 1146 | return err > 0 ? -EINVAL : err; |
1158 | } | 1147 | } |
1159 | 1148 | ||
1160 | /** | 1149 | /** |
1161 | * paranoid_check_ec_hdr - check if an erase counter header is all right. | 1150 | * self_check_ec_hdr - check if an erase counter header is all right. |
1162 | * @ubi: UBI device description object | 1151 | * @ubi: UBI device description object |
1163 | * @pnum: physical eraseblock number the erase counter header belongs to | 1152 | * @pnum: physical eraseblock number the erase counter header belongs to |
1164 | * @ec_hdr: the erase counter header to check | 1153 | * @ec_hdr: the erase counter header to check |
@@ -1166,8 +1155,8 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | |||
1166 | * This function returns zero if the erase counter header contains valid | 1155 | * This function returns zero if the erase counter header contains valid |
1167 | * values, and %-EINVAL if not. | 1156 | * values, and %-EINVAL if not. |
1168 | */ | 1157 | */ |
1169 | static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, | 1158 | static int self_check_ec_hdr(const struct ubi_device *ubi, int pnum, |
1170 | const struct ubi_ec_hdr *ec_hdr) | 1159 | const struct ubi_ec_hdr *ec_hdr) |
1171 | { | 1160 | { |
1172 | int err; | 1161 | int err; |
1173 | uint32_t magic; | 1162 | uint32_t magic; |
@@ -1184,27 +1173,27 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, | |||
1184 | 1173 | ||
1185 | err = validate_ec_hdr(ubi, ec_hdr); | 1174 | err = validate_ec_hdr(ubi, ec_hdr); |
1186 | if (err) { | 1175 | if (err) { |
1187 | ubi_err("paranoid check failed for PEB %d", pnum); | 1176 | ubi_err("self-check failed for PEB %d", pnum); |
1188 | goto fail; | 1177 | goto fail; |
1189 | } | 1178 | } |
1190 | 1179 | ||
1191 | return 0; | 1180 | return 0; |
1192 | 1181 | ||
1193 | fail: | 1182 | fail: |
1194 | ubi_dbg_dump_ec_hdr(ec_hdr); | 1183 | ubi_dump_ec_hdr(ec_hdr); |
1195 | ubi_dbg_dump_stack(); | 1184 | dump_stack(); |
1196 | return -EINVAL; | 1185 | return -EINVAL; |
1197 | } | 1186 | } |
1198 | 1187 | ||
1199 | /** | 1188 | /** |
1200 | * paranoid_check_peb_ec_hdr - check erase counter header. | 1189 | * self_check_peb_ec_hdr - check erase counter header. |
1201 | * @ubi: UBI device description object | 1190 | * @ubi: UBI device description object |
1202 | * @pnum: the physical eraseblock number to check | 1191 | * @pnum: the physical eraseblock number to check |
1203 | * | 1192 | * |
1204 | * This function returns zero if the erase counter header is all right and and | 1193 | * This function returns zero if the erase counter header is all right and and |
1205 | * a negative error code if not or if an error occurred. | 1194 | * a negative error code if not or if an error occurred. |
1206 | */ | 1195 | */ |
1207 | static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) | 1196 | static int self_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) |
1208 | { | 1197 | { |
1209 | int err; | 1198 | int err; |
1210 | uint32_t crc, hdr_crc; | 1199 | uint32_t crc, hdr_crc; |
@@ -1225,14 +1214,14 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) | |||
1225 | hdr_crc = be32_to_cpu(ec_hdr->hdr_crc); | 1214 | hdr_crc = be32_to_cpu(ec_hdr->hdr_crc); |
1226 | if (hdr_crc != crc) { | 1215 | if (hdr_crc != crc) { |
1227 | ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc); | 1216 | ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc); |
1228 | ubi_err("paranoid check failed for PEB %d", pnum); | 1217 | ubi_err("self-check failed for PEB %d", pnum); |
1229 | ubi_dbg_dump_ec_hdr(ec_hdr); | 1218 | ubi_dump_ec_hdr(ec_hdr); |
1230 | ubi_dbg_dump_stack(); | 1219 | dump_stack(); |
1231 | err = -EINVAL; | 1220 | err = -EINVAL; |
1232 | goto exit; | 1221 | goto exit; |
1233 | } | 1222 | } |
1234 | 1223 | ||
1235 | err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); | 1224 | err = self_check_ec_hdr(ubi, pnum, ec_hdr); |
1236 | 1225 | ||
1237 | exit: | 1226 | exit: |
1238 | kfree(ec_hdr); | 1227 | kfree(ec_hdr); |
@@ -1240,7 +1229,7 @@ exit: | |||
1240 | } | 1229 | } |
1241 | 1230 | ||
1242 | /** | 1231 | /** |
1243 | * paranoid_check_vid_hdr - check that a volume identifier header is all right. | 1232 | * self_check_vid_hdr - check that a volume identifier header is all right. |
1244 | * @ubi: UBI device description object | 1233 | * @ubi: UBI device description object |
1245 | * @pnum: physical eraseblock number the volume identifier header belongs to | 1234 | * @pnum: physical eraseblock number the volume identifier header belongs to |
1246 | * @vid_hdr: the volume identifier header to check | 1235 | * @vid_hdr: the volume identifier header to check |
@@ -1248,8 +1237,8 @@ exit: | |||
1248 | * This function returns zero if the volume identifier header is all right, and | 1237 | * This function returns zero if the volume identifier header is all right, and |
1249 | * %-EINVAL if not. | 1238 | * %-EINVAL if not. |
1250 | */ | 1239 | */ |
1251 | static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, | 1240 | static int self_check_vid_hdr(const struct ubi_device *ubi, int pnum, |
1252 | const struct ubi_vid_hdr *vid_hdr) | 1241 | const struct ubi_vid_hdr *vid_hdr) |
1253 | { | 1242 | { |
1254 | int err; | 1243 | int err; |
1255 | uint32_t magic; | 1244 | uint32_t magic; |
@@ -1266,29 +1255,29 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, | |||
1266 | 1255 | ||
1267 | err = validate_vid_hdr(ubi, vid_hdr); | 1256 | err = validate_vid_hdr(ubi, vid_hdr); |
1268 | if (err) { | 1257 | if (err) { |
1269 | ubi_err("paranoid check failed for PEB %d", pnum); | 1258 | ubi_err("self-check failed for PEB %d", pnum); |
1270 | goto fail; | 1259 | goto fail; |
1271 | } | 1260 | } |
1272 | 1261 | ||
1273 | return err; | 1262 | return err; |
1274 | 1263 | ||
1275 | fail: | 1264 | fail: |
1276 | ubi_err("paranoid check failed for PEB %d", pnum); | 1265 | ubi_err("self-check failed for PEB %d", pnum); |
1277 | ubi_dbg_dump_vid_hdr(vid_hdr); | 1266 | ubi_dump_vid_hdr(vid_hdr); |
1278 | ubi_dbg_dump_stack(); | 1267 | dump_stack(); |
1279 | return -EINVAL; | 1268 | return -EINVAL; |
1280 | 1269 | ||
1281 | } | 1270 | } |
1282 | 1271 | ||
1283 | /** | 1272 | /** |
1284 | * paranoid_check_peb_vid_hdr - check volume identifier header. | 1273 | * self_check_peb_vid_hdr - check volume identifier header. |
1285 | * @ubi: UBI device description object | 1274 | * @ubi: UBI device description object |
1286 | * @pnum: the physical eraseblock number to check | 1275 | * @pnum: the physical eraseblock number to check |
1287 | * | 1276 | * |
1288 | * This function returns zero if the volume identifier header is all right, | 1277 | * This function returns zero if the volume identifier header is all right, |
1289 | * and a negative error code if not or if an error occurred. | 1278 | * and a negative error code if not or if an error occurred. |
1290 | */ | 1279 | */ |
1291 | static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) | 1280 | static int self_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) |
1292 | { | 1281 | { |
1293 | int err; | 1282 | int err; |
1294 | uint32_t crc, hdr_crc; | 1283 | uint32_t crc, hdr_crc; |
@@ -1313,14 +1302,14 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) | |||
1313 | if (hdr_crc != crc) { | 1302 | if (hdr_crc != crc) { |
1314 | ubi_err("bad VID header CRC at PEB %d, calculated %#08x, " | 1303 | ubi_err("bad VID header CRC at PEB %d, calculated %#08x, " |
1315 | "read %#08x", pnum, crc, hdr_crc); | 1304 | "read %#08x", pnum, crc, hdr_crc); |
1316 | ubi_err("paranoid check failed for PEB %d", pnum); | 1305 | ubi_err("self-check failed for PEB %d", pnum); |
1317 | ubi_dbg_dump_vid_hdr(vid_hdr); | 1306 | ubi_dump_vid_hdr(vid_hdr); |
1318 | ubi_dbg_dump_stack(); | 1307 | dump_stack(); |
1319 | err = -EINVAL; | 1308 | err = -EINVAL; |
1320 | goto exit; | 1309 | goto exit; |
1321 | } | 1310 | } |
1322 | 1311 | ||
1323 | err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); | 1312 | err = self_check_vid_hdr(ubi, pnum, vid_hdr); |
1324 | 1313 | ||
1325 | exit: | 1314 | exit: |
1326 | ubi_free_vid_hdr(ubi, vid_hdr); | 1315 | ubi_free_vid_hdr(ubi, vid_hdr); |
@@ -1328,7 +1317,7 @@ exit: | |||
1328 | } | 1317 | } |
1329 | 1318 | ||
1330 | /** | 1319 | /** |
1331 | * ubi_dbg_check_write - make sure write succeeded. | 1320 | * self_check_write - make sure write succeeded. |
1332 | * @ubi: UBI device description object | 1321 | * @ubi: UBI device description object |
1333 | * @buf: buffer with data which were written | 1322 | * @buf: buffer with data which were written |
1334 | * @pnum: physical eraseblock number the data were written to | 1323 | * @pnum: physical eraseblock number the data were written to |
@@ -1339,8 +1328,8 @@ exit: | |||
1339 | * the original data buffer - the data have to match. Returns zero if the data | 1328 | * the original data buffer - the data have to match. Returns zero if the data |
1340 | * match and a negative error code if not or in case of failure. | 1329 | * match and a negative error code if not or in case of failure. |
1341 | */ | 1330 | */ |
1342 | int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, | 1331 | static int self_check_write(struct ubi_device *ubi, const void *buf, int pnum, |
1343 | int offset, int len) | 1332 | int offset, int len) |
1344 | { | 1333 | { |
1345 | int err, i; | 1334 | int err, i; |
1346 | size_t read; | 1335 | size_t read; |
@@ -1368,7 +1357,7 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, | |||
1368 | if (c == c1) | 1357 | if (c == c1) |
1369 | continue; | 1358 | continue; |
1370 | 1359 | ||
1371 | ubi_err("paranoid check failed for PEB %d:%d, len %d", | 1360 | ubi_err("self-check failed for PEB %d:%d, len %d", |
1372 | pnum, offset, len); | 1361 | pnum, offset, len); |
1373 | ubi_msg("data differ at position %d", i); | 1362 | ubi_msg("data differ at position %d", i); |
1374 | dump_len = max_t(int, 128, len - i); | 1363 | dump_len = max_t(int, 128, len - i); |
@@ -1380,7 +1369,7 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, | |||
1380 | i, i + dump_len); | 1369 | i, i + dump_len); |
1381 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | 1370 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, |
1382 | buf1 + i, dump_len, 1); | 1371 | buf1 + i, dump_len, 1); |
1383 | ubi_dbg_dump_stack(); | 1372 | dump_stack(); |
1384 | err = -EINVAL; | 1373 | err = -EINVAL; |
1385 | goto out_free; | 1374 | goto out_free; |
1386 | } | 1375 | } |
@@ -1394,7 +1383,7 @@ out_free: | |||
1394 | } | 1383 | } |
1395 | 1384 | ||
1396 | /** | 1385 | /** |
1397 | * ubi_dbg_check_all_ff - check that a region of flash is empty. | 1386 | * ubi_self_check_all_ff - check that a region of flash is empty. |
1398 | * @ubi: UBI device description object | 1387 | * @ubi: UBI device description object |
1399 | * @pnum: the physical eraseblock number to check | 1388 | * @pnum: the physical eraseblock number to check |
1400 | * @offset: the starting offset within the physical eraseblock to check | 1389 | * @offset: the starting offset within the physical eraseblock to check |
@@ -1404,7 +1393,7 @@ out_free: | |||
1404 | * @offset of the physical eraseblock @pnum, and a negative error code if not | 1393 | * @offset of the physical eraseblock @pnum, and a negative error code if not |
1405 | * or if an error occurred. | 1394 | * or if an error occurred. |
1406 | */ | 1395 | */ |
1407 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) | 1396 | int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) |
1408 | { | 1397 | { |
1409 | size_t read; | 1398 | size_t read; |
1410 | int err; | 1399 | int err; |
@@ -1438,14 +1427,12 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) | |||
1438 | return 0; | 1427 | return 0; |
1439 | 1428 | ||
1440 | fail: | 1429 | fail: |
1441 | ubi_err("paranoid check failed for PEB %d", pnum); | 1430 | ubi_err("self-check failed for PEB %d", pnum); |
1442 | ubi_msg("hex dump of the %d-%d region", offset, offset + len); | 1431 | ubi_msg("hex dump of the %d-%d region", offset, offset + len); |
1443 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1); | 1432 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1); |
1444 | err = -EINVAL; | 1433 | err = -EINVAL; |
1445 | error: | 1434 | error: |
1446 | ubi_dbg_dump_stack(); | 1435 | dump_stack(); |
1447 | vfree(buf); | 1436 | vfree(buf); |
1448 | return err; | 1437 | return err; |
1449 | } | 1438 | } |
1450 | |||
1451 | #endif /* CONFIG_MTD_UBI_DEBUG */ | ||
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c index 9fdb35367fe0..3aac1acceeb4 100644 --- a/drivers/mtd/ubi/kapi.c +++ b/drivers/mtd/ubi/kapi.c | |||
@@ -221,7 +221,7 @@ out_free: | |||
221 | kfree(desc); | 221 | kfree(desc); |
222 | out_put_ubi: | 222 | out_put_ubi: |
223 | ubi_put_device(ubi); | 223 | ubi_put_device(ubi); |
224 | dbg_err("cannot open device %d, volume %d, error %d", | 224 | ubi_err("cannot open device %d, volume %d, error %d", |
225 | ubi_num, vol_id, err); | 225 | ubi_num, vol_id, err); |
226 | return ERR_PTR(err); | 226 | return ERR_PTR(err); |
227 | } | 227 | } |
@@ -426,11 +426,9 @@ EXPORT_SYMBOL_GPL(ubi_leb_read); | |||
426 | * @buf: data to write | 426 | * @buf: data to write |
427 | * @offset: offset within the logical eraseblock where to write | 427 | * @offset: offset within the logical eraseblock where to write |
428 | * @len: how many bytes to write | 428 | * @len: how many bytes to write |
429 | * @dtype: expected data type | ||
430 | * | 429 | * |
431 | * This function writes @len bytes of data from @buf to offset @offset of | 430 | * This function writes @len bytes of data from @buf to offset @offset of |
432 | * logical eraseblock @lnum. The @dtype argument describes expected lifetime of | 431 | * logical eraseblock @lnum. |
433 | * the data. | ||
434 | * | 432 | * |
435 | * This function takes care of physical eraseblock write failures. If write to | 433 | * This function takes care of physical eraseblock write failures. If write to |
436 | * the physical eraseblock write operation fails, the logical eraseblock is | 434 | * the physical eraseblock write operation fails, the logical eraseblock is |
@@ -447,7 +445,7 @@ EXPORT_SYMBOL_GPL(ubi_leb_read); | |||
447 | * returns immediately with %-EBADF code. | 445 | * returns immediately with %-EBADF code. |
448 | */ | 446 | */ |
449 | int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, | 447 | int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, |
450 | int offset, int len, int dtype) | 448 | int offset, int len) |
451 | { | 449 | { |
452 | struct ubi_volume *vol = desc->vol; | 450 | struct ubi_volume *vol = desc->vol; |
453 | struct ubi_device *ubi = vol->ubi; | 451 | struct ubi_device *ubi = vol->ubi; |
@@ -466,17 +464,13 @@ int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, | |||
466 | offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1)) | 464 | offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1)) |
467 | return -EINVAL; | 465 | return -EINVAL; |
468 | 466 | ||
469 | if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM && | ||
470 | dtype != UBI_UNKNOWN) | ||
471 | return -EINVAL; | ||
472 | |||
473 | if (vol->upd_marker) | 467 | if (vol->upd_marker) |
474 | return -EBADF; | 468 | return -EBADF; |
475 | 469 | ||
476 | if (len == 0) | 470 | if (len == 0) |
477 | return 0; | 471 | return 0; |
478 | 472 | ||
479 | return ubi_eba_write_leb(ubi, vol, lnum, buf, offset, len, dtype); | 473 | return ubi_eba_write_leb(ubi, vol, lnum, buf, offset, len); |
480 | } | 474 | } |
481 | EXPORT_SYMBOL_GPL(ubi_leb_write); | 475 | EXPORT_SYMBOL_GPL(ubi_leb_write); |
482 | 476 | ||
@@ -486,7 +480,6 @@ EXPORT_SYMBOL_GPL(ubi_leb_write); | |||
486 | * @lnum: logical eraseblock number to change | 480 | * @lnum: logical eraseblock number to change |
487 | * @buf: data to write | 481 | * @buf: data to write |
488 | * @len: how many bytes to write | 482 | * @len: how many bytes to write |
489 | * @dtype: expected data type | ||
490 | * | 483 | * |
491 | * This function changes the contents of a logical eraseblock atomically. @buf | 484 | * This function changes the contents of a logical eraseblock atomically. @buf |
492 | * has to contain new logical eraseblock data, and @len - the length of the | 485 | * has to contain new logical eraseblock data, and @len - the length of the |
@@ -497,7 +490,7 @@ EXPORT_SYMBOL_GPL(ubi_leb_write); | |||
497 | * code in case of failure. | 490 | * code in case of failure. |
498 | */ | 491 | */ |
499 | int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, | 492 | int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, |
500 | int len, int dtype) | 493 | int len) |
501 | { | 494 | { |
502 | struct ubi_volume *vol = desc->vol; | 495 | struct ubi_volume *vol = desc->vol; |
503 | struct ubi_device *ubi = vol->ubi; | 496 | struct ubi_device *ubi = vol->ubi; |
@@ -515,17 +508,13 @@ int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, | |||
515 | len > vol->usable_leb_size || len & (ubi->min_io_size - 1)) | 508 | len > vol->usable_leb_size || len & (ubi->min_io_size - 1)) |
516 | return -EINVAL; | 509 | return -EINVAL; |
517 | 510 | ||
518 | if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM && | ||
519 | dtype != UBI_UNKNOWN) | ||
520 | return -EINVAL; | ||
521 | |||
522 | if (vol->upd_marker) | 511 | if (vol->upd_marker) |
523 | return -EBADF; | 512 | return -EBADF; |
524 | 513 | ||
525 | if (len == 0) | 514 | if (len == 0) |
526 | return 0; | 515 | return 0; |
527 | 516 | ||
528 | return ubi_eba_atomic_leb_change(ubi, vol, lnum, buf, len, dtype); | 517 | return ubi_eba_atomic_leb_change(ubi, vol, lnum, buf, len); |
529 | } | 518 | } |
530 | EXPORT_SYMBOL_GPL(ubi_leb_change); | 519 | EXPORT_SYMBOL_GPL(ubi_leb_change); |
531 | 520 | ||
@@ -562,7 +551,7 @@ int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum) | |||
562 | if (err) | 551 | if (err) |
563 | return err; | 552 | return err; |
564 | 553 | ||
565 | return ubi_wl_flush(ubi); | 554 | return ubi_wl_flush(ubi, vol->vol_id, lnum); |
566 | } | 555 | } |
567 | EXPORT_SYMBOL_GPL(ubi_leb_erase); | 556 | EXPORT_SYMBOL_GPL(ubi_leb_erase); |
568 | 557 | ||
@@ -626,7 +615,6 @@ EXPORT_SYMBOL_GPL(ubi_leb_unmap); | |||
626 | * ubi_leb_map - map logical eraseblock to a physical eraseblock. | 615 | * ubi_leb_map - map logical eraseblock to a physical eraseblock. |
627 | * @desc: volume descriptor | 616 | * @desc: volume descriptor |
628 | * @lnum: logical eraseblock number | 617 | * @lnum: logical eraseblock number |
629 | * @dtype: expected data type | ||
630 | * | 618 | * |
631 | * This function maps an un-mapped logical eraseblock @lnum to a physical | 619 | * This function maps an un-mapped logical eraseblock @lnum to a physical |
632 | * eraseblock. This means, that after a successful invocation of this | 620 | * eraseblock. This means, that after a successful invocation of this |
@@ -639,7 +627,7 @@ EXPORT_SYMBOL_GPL(ubi_leb_unmap); | |||
639 | * eraseblock is already mapped, and other negative error codes in case of | 627 | * eraseblock is already mapped, and other negative error codes in case of |
640 | * other failures. | 628 | * other failures. |
641 | */ | 629 | */ |
642 | int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype) | 630 | int ubi_leb_map(struct ubi_volume_desc *desc, int lnum) |
643 | { | 631 | { |
644 | struct ubi_volume *vol = desc->vol; | 632 | struct ubi_volume *vol = desc->vol; |
645 | struct ubi_device *ubi = vol->ubi; | 633 | struct ubi_device *ubi = vol->ubi; |
@@ -652,17 +640,13 @@ int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype) | |||
652 | if (lnum < 0 || lnum >= vol->reserved_pebs) | 640 | if (lnum < 0 || lnum >= vol->reserved_pebs) |
653 | return -EINVAL; | 641 | return -EINVAL; |
654 | 642 | ||
655 | if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM && | ||
656 | dtype != UBI_UNKNOWN) | ||
657 | return -EINVAL; | ||
658 | |||
659 | if (vol->upd_marker) | 643 | if (vol->upd_marker) |
660 | return -EBADF; | 644 | return -EBADF; |
661 | 645 | ||
662 | if (vol->eba_tbl[lnum] >= 0) | 646 | if (vol->eba_tbl[lnum] >= 0) |
663 | return -EBADMSG; | 647 | return -EBADMSG; |
664 | 648 | ||
665 | return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0, dtype); | 649 | return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0); |
666 | } | 650 | } |
667 | EXPORT_SYMBOL_GPL(ubi_leb_map); | 651 | EXPORT_SYMBOL_GPL(ubi_leb_map); |
668 | 652 | ||
@@ -720,6 +704,33 @@ int ubi_sync(int ubi_num) | |||
720 | } | 704 | } |
721 | EXPORT_SYMBOL_GPL(ubi_sync); | 705 | EXPORT_SYMBOL_GPL(ubi_sync); |
722 | 706 | ||
707 | /** | ||
708 | * ubi_flush - flush UBI work queue. | ||
709 | * @ubi_num: UBI device to flush work queue | ||
710 | * @vol_id: volume id to flush for | ||
711 | * @lnum: logical eraseblock number to flush for | ||
712 | * | ||
713 | * This function executes all pending works for a particular volume id / logical | ||
714 | * eraseblock number pair. If either value is set to %UBI_ALL, then it acts as | ||
715 | * a wildcard for all of the corresponding volume numbers or logical | ||
716 | * eraseblock numbers. It returns zero in case of success and a negative error | ||
717 | * code in case of failure. | ||
718 | */ | ||
719 | int ubi_flush(int ubi_num, int vol_id, int lnum) | ||
720 | { | ||
721 | struct ubi_device *ubi; | ||
722 | int err = 0; | ||
723 | |||
724 | ubi = ubi_get_device(ubi_num); | ||
725 | if (!ubi) | ||
726 | return -ENODEV; | ||
727 | |||
728 | err = ubi_wl_flush(ubi, vol_id, lnum); | ||
729 | ubi_put_device(ubi); | ||
730 | return err; | ||
731 | } | ||
732 | EXPORT_SYMBOL_GPL(ubi_flush); | ||
733 | |||
723 | BLOCKING_NOTIFIER_HEAD(ubi_notifiers); | 734 | BLOCKING_NOTIFIER_HEAD(ubi_notifiers); |
724 | 735 | ||
725 | /** | 736 | /** |
diff --git a/drivers/mtd/ubi/scan.h b/drivers/mtd/ubi/scan.h deleted file mode 100644 index d48aef15ab5d..000000000000 --- a/drivers/mtd/ubi/scan.h +++ /dev/null | |||
@@ -1,174 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) International Business Machines Corp., 2006 | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
12 | * the GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
17 | * | ||
18 | * Author: Artem Bityutskiy (Битюцкий Артём) | ||
19 | */ | ||
20 | |||
21 | #ifndef __UBI_SCAN_H__ | ||
22 | #define __UBI_SCAN_H__ | ||
23 | |||
24 | /* The erase counter value for this physical eraseblock is unknown */ | ||
25 | #define UBI_SCAN_UNKNOWN_EC (-1) | ||
26 | |||
27 | /** | ||
28 | * struct ubi_scan_leb - scanning information about a physical eraseblock. | ||
29 | * @ec: erase counter (%UBI_SCAN_UNKNOWN_EC if it is unknown) | ||
30 | * @pnum: physical eraseblock number | ||
31 | * @lnum: logical eraseblock number | ||
32 | * @scrub: if this physical eraseblock needs scrubbing | ||
33 | * @copy_flag: this LEB is a copy (@copy_flag is set in VID header of this LEB) | ||
34 | * @sqnum: sequence number | ||
35 | * @u: unions RB-tree or @list links | ||
36 | * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects | ||
37 | * @u.list: link in one of the eraseblock lists | ||
38 | * | ||
39 | * One object of this type is allocated for each physical eraseblock during | ||
40 | * scanning. | ||
41 | */ | ||
42 | struct ubi_scan_leb { | ||
43 | int ec; | ||
44 | int pnum; | ||
45 | int lnum; | ||
46 | unsigned int scrub:1; | ||
47 | unsigned int copy_flag:1; | ||
48 | unsigned long long sqnum; | ||
49 | union { | ||
50 | struct rb_node rb; | ||
51 | struct list_head list; | ||
52 | } u; | ||
53 | }; | ||
54 | |||
55 | /** | ||
56 | * struct ubi_scan_volume - scanning information about a volume. | ||
57 | * @vol_id: volume ID | ||
58 | * @highest_lnum: highest logical eraseblock number in this volume | ||
59 | * @leb_count: number of logical eraseblocks in this volume | ||
60 | * @vol_type: volume type | ||
61 | * @used_ebs: number of used logical eraseblocks in this volume (only for | ||
62 | * static volumes) | ||
63 | * @last_data_size: amount of data in the last logical eraseblock of this | ||
64 | * volume (always equivalent to the usable logical eraseblock | ||
65 | * size in case of dynamic volumes) | ||
66 | * @data_pad: how many bytes at the end of logical eraseblocks of this volume | ||
67 | * are not used (due to volume alignment) | ||
68 | * @compat: compatibility flags of this volume | ||
69 | * @rb: link in the volume RB-tree | ||
70 | * @root: root of the RB-tree containing all the eraseblock belonging to this | ||
71 | * volume (&struct ubi_scan_leb objects) | ||
72 | * | ||
73 | * One object of this type is allocated for each volume during scanning. | ||
74 | */ | ||
75 | struct ubi_scan_volume { | ||
76 | int vol_id; | ||
77 | int highest_lnum; | ||
78 | int leb_count; | ||
79 | int vol_type; | ||
80 | int used_ebs; | ||
81 | int last_data_size; | ||
82 | int data_pad; | ||
83 | int compat; | ||
84 | struct rb_node rb; | ||
85 | struct rb_root root; | ||
86 | }; | ||
87 | |||
88 | /** | ||
89 | * struct ubi_scan_info - UBI scanning information. | ||
90 | * @volumes: root of the volume RB-tree | ||
91 | * @corr: list of corrupted physical eraseblocks | ||
92 | * @free: list of free physical eraseblocks | ||
93 | * @erase: list of physical eraseblocks which have to be erased | ||
94 | * @alien: list of physical eraseblocks which should not be used by UBI (e.g., | ||
95 | * those belonging to "preserve"-compatible internal volumes) | ||
96 | * @corr_peb_count: count of PEBs in the @corr list | ||
97 | * @empty_peb_count: count of PEBs which are presumably empty (contain only | ||
98 | * 0xFF bytes) | ||
99 | * @alien_peb_count: count of PEBs in the @alien list | ||
100 | * @bad_peb_count: count of bad physical eraseblocks | ||
101 | * @maybe_bad_peb_count: count of bad physical eraseblocks which are not marked | ||
102 | * as bad yet, but which look like bad | ||
103 | * @vols_found: number of volumes found during scanning | ||
104 | * @highest_vol_id: highest volume ID | ||
105 | * @is_empty: flag indicating whether the MTD device is empty or not | ||
106 | * @min_ec: lowest erase counter value | ||
107 | * @max_ec: highest erase counter value | ||
108 | * @max_sqnum: highest sequence number value | ||
109 | * @mean_ec: mean erase counter value | ||
110 | * @ec_sum: a temporary variable used when calculating @mean_ec | ||
111 | * @ec_count: a temporary variable used when calculating @mean_ec | ||
112 | * @scan_leb_slab: slab cache for &struct ubi_scan_leb objects | ||
113 | * | ||
114 | * This data structure contains the result of scanning and may be used by other | ||
115 | * UBI sub-systems to build final UBI data structures, further error-recovery | ||
116 | * and so on. | ||
117 | */ | ||
118 | struct ubi_scan_info { | ||
119 | struct rb_root volumes; | ||
120 | struct list_head corr; | ||
121 | struct list_head free; | ||
122 | struct list_head erase; | ||
123 | struct list_head alien; | ||
124 | int corr_peb_count; | ||
125 | int empty_peb_count; | ||
126 | int alien_peb_count; | ||
127 | int bad_peb_count; | ||
128 | int maybe_bad_peb_count; | ||
129 | int vols_found; | ||
130 | int highest_vol_id; | ||
131 | int is_empty; | ||
132 | int min_ec; | ||
133 | int max_ec; | ||
134 | unsigned long long max_sqnum; | ||
135 | int mean_ec; | ||
136 | uint64_t ec_sum; | ||
137 | int ec_count; | ||
138 | struct kmem_cache *scan_leb_slab; | ||
139 | }; | ||
140 | |||
141 | struct ubi_device; | ||
142 | struct ubi_vid_hdr; | ||
143 | |||
144 | /* | ||
145 | * ubi_scan_move_to_list - move a PEB from the volume tree to a list. | ||
146 | * | ||
147 | * @sv: volume scanning information | ||
148 | * @seb: scanning eraseblock information | ||
149 | * @list: the list to move to | ||
150 | */ | ||
151 | static inline void ubi_scan_move_to_list(struct ubi_scan_volume *sv, | ||
152 | struct ubi_scan_leb *seb, | ||
153 | struct list_head *list) | ||
154 | { | ||
155 | rb_erase(&seb->u.rb, &sv->root); | ||
156 | list_add_tail(&seb->u.list, list); | ||
157 | } | ||
158 | |||
159 | int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | ||
160 | int pnum, int ec, const struct ubi_vid_hdr *vid_hdr, | ||
161 | int bitflips); | ||
162 | struct ubi_scan_volume *ubi_scan_find_sv(const struct ubi_scan_info *si, | ||
163 | int vol_id); | ||
164 | struct ubi_scan_leb *ubi_scan_find_seb(const struct ubi_scan_volume *sv, | ||
165 | int lnum); | ||
166 | void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv); | ||
167 | struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi, | ||
168 | struct ubi_scan_info *si); | ||
169 | int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si, | ||
170 | int pnum, int ec); | ||
171 | struct ubi_scan_info *ubi_scan(struct ubi_device *ubi); | ||
172 | void ubi_scan_destroy_si(struct ubi_scan_info *si); | ||
173 | |||
174 | #endif /* !__UBI_SCAN_H__ */ | ||
diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h index 6fb8ec2174a5..468ffbc0eabd 100644 --- a/drivers/mtd/ubi/ubi-media.h +++ b/drivers/mtd/ubi/ubi-media.h | |||
@@ -149,10 +149,10 @@ enum { | |||
149 | * The @image_seq field is used to validate a UBI image that has been prepared | 149 | * The @image_seq field is used to validate a UBI image that has been prepared |
150 | * for a UBI device. The @image_seq value can be any value, but it must be the | 150 | * for a UBI device. The @image_seq value can be any value, but it must be the |
151 | * same on all eraseblocks. UBI will ensure that all new erase counter headers | 151 | * same on all eraseblocks. UBI will ensure that all new erase counter headers |
152 | * also contain this value, and will check the value when scanning at start-up. | 152 | * also contain this value, and will check the value when attaching the flash. |
153 | * One way to make use of @image_seq is to increase its value by one every time | 153 | * One way to make use of @image_seq is to increase its value by one every time |
154 | * an image is flashed over an existing image, then, if the flashing does not | 154 | * an image is flashed over an existing image, then, if the flashing does not |
155 | * complete, UBI will detect the error when scanning. | 155 | * complete, UBI will detect the error when attaching the media. |
156 | */ | 156 | */ |
157 | struct ubi_ec_hdr { | 157 | struct ubi_ec_hdr { |
158 | __be32 magic; | 158 | __be32 magic; |
@@ -298,8 +298,8 @@ struct ubi_vid_hdr { | |||
298 | #define UBI_INT_VOL_COUNT 1 | 298 | #define UBI_INT_VOL_COUNT 1 |
299 | 299 | ||
300 | /* | 300 | /* |
301 | * Starting ID of internal volumes. There is reserved room for 4096 internal | 301 | * Starting ID of internal volumes: 0x7fffefff. |
302 | * volumes. | 302 | * There is reserved room for 4096 internal volumes. |
303 | */ | 303 | */ |
304 | #define UBI_INTERNAL_VOL_START (0x7FFFFFFF - 4096) | 304 | #define UBI_INTERNAL_VOL_START (0x7FFFFFFF - 4096) |
305 | 305 | ||
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index b162790790a9..a1a81c9ea8ce 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h | |||
@@ -43,7 +43,6 @@ | |||
43 | #include <asm/pgtable.h> | 43 | #include <asm/pgtable.h> |
44 | 44 | ||
45 | #include "ubi-media.h" | 45 | #include "ubi-media.h" |
46 | #include "scan.h" | ||
47 | 46 | ||
48 | /* Maximum number of supported UBI devices */ | 47 | /* Maximum number of supported UBI devices */ |
49 | #define UBI_MAX_DEVICES 32 | 48 | #define UBI_MAX_DEVICES 32 |
@@ -66,7 +65,10 @@ | |||
66 | /* Background thread name pattern */ | 65 | /* Background thread name pattern */ |
67 | #define UBI_BGT_NAME_PATTERN "ubi_bgt%dd" | 66 | #define UBI_BGT_NAME_PATTERN "ubi_bgt%dd" |
68 | 67 | ||
69 | /* This marker in the EBA table means that the LEB is um-mapped */ | 68 | /* |
69 | * This marker in the EBA table means that the LEB is um-mapped. | ||
70 | * NOTE! It has to have the same value as %UBI_ALL. | ||
71 | */ | ||
70 | #define UBI_LEB_UNMAPPED -1 | 72 | #define UBI_LEB_UNMAPPED -1 |
71 | 73 | ||
72 | /* | 74 | /* |
@@ -82,6 +84,9 @@ | |||
82 | */ | 84 | */ |
83 | #define UBI_PROT_QUEUE_LEN 10 | 85 | #define UBI_PROT_QUEUE_LEN 10 |
84 | 86 | ||
87 | /* The volume ID/LEB number/erase counter is unknown */ | ||
88 | #define UBI_UNKNOWN -1 | ||
89 | |||
85 | /* | 90 | /* |
86 | * Error codes returned by the I/O sub-system. | 91 | * Error codes returned by the I/O sub-system. |
87 | * | 92 | * |
@@ -222,8 +227,6 @@ struct ubi_volume_desc; | |||
222 | * @upd_ebs: how many eraseblocks are expected to be updated | 227 | * @upd_ebs: how many eraseblocks are expected to be updated |
223 | * @ch_lnum: LEB number which is being changing by the atomic LEB change | 228 | * @ch_lnum: LEB number which is being changing by the atomic LEB change |
224 | * operation | 229 | * operation |
225 | * @ch_dtype: data persistency type which is being changing by the atomic LEB | ||
226 | * change operation | ||
227 | * @upd_bytes: how many bytes are expected to be received for volume update or | 230 | * @upd_bytes: how many bytes are expected to be received for volume update or |
228 | * atomic LEB change | 231 | * atomic LEB change |
229 | * @upd_received: how many bytes were already received for volume update or | 232 | * @upd_received: how many bytes were already received for volume update or |
@@ -270,7 +273,6 @@ struct ubi_volume { | |||
270 | 273 | ||
271 | int upd_ebs; | 274 | int upd_ebs; |
272 | int ch_lnum; | 275 | int ch_lnum; |
273 | int ch_dtype; | ||
274 | long long upd_bytes; | 276 | long long upd_bytes; |
275 | long long upd_received; | 277 | long long upd_received; |
276 | void *upd_buf; | 278 | void *upd_buf; |
@@ -477,6 +479,124 @@ struct ubi_device { | |||
477 | struct ubi_debug_info *dbg; | 479 | struct ubi_debug_info *dbg; |
478 | }; | 480 | }; |
479 | 481 | ||
482 | /** | ||
483 | * struct ubi_ainf_peb - attach information about a physical eraseblock. | ||
484 | * @ec: erase counter (%UBI_UNKNOWN if it is unknown) | ||
485 | * @pnum: physical eraseblock number | ||
486 | * @vol_id: ID of the volume this LEB belongs to | ||
487 | * @lnum: logical eraseblock number | ||
488 | * @scrub: if this physical eraseblock needs scrubbing | ||
489 | * @copy_flag: this LEB is a copy (@copy_flag is set in VID header of this LEB) | ||
490 | * @sqnum: sequence number | ||
491 | * @u: unions RB-tree or @list links | ||
492 | * @u.rb: link in the per-volume RB-tree of &struct ubi_ainf_peb objects | ||
493 | * @u.list: link in one of the eraseblock lists | ||
494 | * | ||
495 | * One object of this type is allocated for each physical eraseblock when | ||
496 | * attaching an MTD device. Note, if this PEB does not belong to any LEB / | ||
497 | * volume, the @vol_id and @lnum fields are initialized to %UBI_UNKNOWN. | ||
498 | */ | ||
499 | struct ubi_ainf_peb { | ||
500 | int ec; | ||
501 | int pnum; | ||
502 | int vol_id; | ||
503 | int lnum; | ||
504 | unsigned int scrub:1; | ||
505 | unsigned int copy_flag:1; | ||
506 | unsigned long long sqnum; | ||
507 | union { | ||
508 | struct rb_node rb; | ||
509 | struct list_head list; | ||
510 | } u; | ||
511 | }; | ||
512 | |||
513 | /** | ||
514 | * struct ubi_ainf_volume - attaching information about a volume. | ||
515 | * @vol_id: volume ID | ||
516 | * @highest_lnum: highest logical eraseblock number in this volume | ||
517 | * @leb_count: number of logical eraseblocks in this volume | ||
518 | * @vol_type: volume type | ||
519 | * @used_ebs: number of used logical eraseblocks in this volume (only for | ||
520 | * static volumes) | ||
521 | * @last_data_size: amount of data in the last logical eraseblock of this | ||
522 | * volume (always equivalent to the usable logical eraseblock | ||
523 | * size in case of dynamic volumes) | ||
524 | * @data_pad: how many bytes at the end of logical eraseblocks of this volume | ||
525 | * are not used (due to volume alignment) | ||
526 | * @compat: compatibility flags of this volume | ||
527 | * @rb: link in the volume RB-tree | ||
528 | * @root: root of the RB-tree containing all the eraseblock belonging to this | ||
529 | * volume (&struct ubi_ainf_peb objects) | ||
530 | * | ||
531 | * One object of this type is allocated for each volume when attaching an MTD | ||
532 | * device. | ||
533 | */ | ||
534 | struct ubi_ainf_volume { | ||
535 | int vol_id; | ||
536 | int highest_lnum; | ||
537 | int leb_count; | ||
538 | int vol_type; | ||
539 | int used_ebs; | ||
540 | int last_data_size; | ||
541 | int data_pad; | ||
542 | int compat; | ||
543 | struct rb_node rb; | ||
544 | struct rb_root root; | ||
545 | }; | ||
546 | |||
547 | /** | ||
548 | * struct ubi_attach_info - MTD device attaching information. | ||
549 | * @volumes: root of the volume RB-tree | ||
550 | * @corr: list of corrupted physical eraseblocks | ||
551 | * @free: list of free physical eraseblocks | ||
552 | * @erase: list of physical eraseblocks which have to be erased | ||
553 | * @alien: list of physical eraseblocks which should not be used by UBI (e.g., | ||
554 | * those belonging to "preserve"-compatible internal volumes) | ||
555 | * @corr_peb_count: count of PEBs in the @corr list | ||
556 | * @empty_peb_count: count of PEBs which are presumably empty (contain only | ||
557 | * 0xFF bytes) | ||
558 | * @alien_peb_count: count of PEBs in the @alien list | ||
559 | * @bad_peb_count: count of bad physical eraseblocks | ||
560 | * @maybe_bad_peb_count: count of bad physical eraseblocks which are not marked | ||
561 | * as bad yet, but which look like bad | ||
562 | * @vols_found: number of volumes found | ||
563 | * @highest_vol_id: highest volume ID | ||
564 | * @is_empty: flag indicating whether the MTD device is empty or not | ||
565 | * @min_ec: lowest erase counter value | ||
566 | * @max_ec: highest erase counter value | ||
567 | * @max_sqnum: highest sequence number value | ||
568 | * @mean_ec: mean erase counter value | ||
569 | * @ec_sum: a temporary variable used when calculating @mean_ec | ||
570 | * @ec_count: a temporary variable used when calculating @mean_ec | ||
571 | * @aeb_slab_cache: slab cache for &struct ubi_ainf_peb objects | ||
572 | * | ||
573 | * This data structure contains the result of attaching an MTD device and may | ||
574 | * be used by other UBI sub-systems to build final UBI data structures, further | ||
575 | * error-recovery and so on. | ||
576 | */ | ||
577 | struct ubi_attach_info { | ||
578 | struct rb_root volumes; | ||
579 | struct list_head corr; | ||
580 | struct list_head free; | ||
581 | struct list_head erase; | ||
582 | struct list_head alien; | ||
583 | int corr_peb_count; | ||
584 | int empty_peb_count; | ||
585 | int alien_peb_count; | ||
586 | int bad_peb_count; | ||
587 | int maybe_bad_peb_count; | ||
588 | int vols_found; | ||
589 | int highest_vol_id; | ||
590 | int is_empty; | ||
591 | int min_ec; | ||
592 | int max_ec; | ||
593 | unsigned long long max_sqnum; | ||
594 | int mean_ec; | ||
595 | uint64_t ec_sum; | ||
596 | int ec_count; | ||
597 | struct kmem_cache *aeb_slab_cache; | ||
598 | }; | ||
599 | |||
480 | #include "debug.h" | 600 | #include "debug.h" |
481 | 601 | ||
482 | extern struct kmem_cache *ubi_wl_entry_slab; | 602 | extern struct kmem_cache *ubi_wl_entry_slab; |
@@ -487,12 +607,23 @@ extern struct class *ubi_class; | |||
487 | extern struct mutex ubi_devices_mutex; | 607 | extern struct mutex ubi_devices_mutex; |
488 | extern struct blocking_notifier_head ubi_notifiers; | 608 | extern struct blocking_notifier_head ubi_notifiers; |
489 | 609 | ||
610 | /* scan.c */ | ||
611 | int ubi_add_to_av(struct ubi_device *ubi, struct ubi_attach_info *ai, int pnum, | ||
612 | int ec, const struct ubi_vid_hdr *vid_hdr, int bitflips); | ||
613 | struct ubi_ainf_volume *ubi_find_av(const struct ubi_attach_info *ai, | ||
614 | int vol_id); | ||
615 | void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av); | ||
616 | struct ubi_ainf_peb *ubi_early_get_peb(struct ubi_device *ubi, | ||
617 | struct ubi_attach_info *ai); | ||
618 | int ubi_attach(struct ubi_device *ubi); | ||
619 | void ubi_destroy_ai(struct ubi_attach_info *ai); | ||
620 | |||
490 | /* vtbl.c */ | 621 | /* vtbl.c */ |
491 | int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, | 622 | int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, |
492 | struct ubi_vtbl_record *vtbl_rec); | 623 | struct ubi_vtbl_record *vtbl_rec); |
493 | int ubi_vtbl_rename_volumes(struct ubi_device *ubi, | 624 | int ubi_vtbl_rename_volumes(struct ubi_device *ubi, |
494 | struct list_head *rename_list); | 625 | struct list_head *rename_list); |
495 | int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si); | 626 | int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai); |
496 | 627 | ||
497 | /* vmt.c */ | 628 | /* vmt.c */ |
498 | int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req); | 629 | int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req); |
@@ -525,22 +656,22 @@ int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol, | |||
525 | int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, | 656 | int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, |
526 | void *buf, int offset, int len, int check); | 657 | void *buf, int offset, int len, int check); |
527 | int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, | 658 | int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, |
528 | const void *buf, int offset, int len, int dtype); | 659 | const void *buf, int offset, int len); |
529 | int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol, | 660 | int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol, |
530 | int lnum, const void *buf, int len, int dtype, | 661 | int lnum, const void *buf, int len, int used_ebs); |
531 | int used_ebs); | ||
532 | int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, | 662 | int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, |
533 | int lnum, const void *buf, int len, int dtype); | 663 | int lnum, const void *buf, int len); |
534 | int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, | 664 | int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, |
535 | struct ubi_vid_hdr *vid_hdr); | 665 | struct ubi_vid_hdr *vid_hdr); |
536 | int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si); | 666 | int ubi_eba_init(struct ubi_device *ubi, struct ubi_attach_info *ai); |
537 | 667 | ||
538 | /* wl.c */ | 668 | /* wl.c */ |
539 | int ubi_wl_get_peb(struct ubi_device *ubi, int dtype); | 669 | int ubi_wl_get_peb(struct ubi_device *ubi); |
540 | int ubi_wl_put_peb(struct ubi_device *ubi, int pnum, int torture); | 670 | int ubi_wl_put_peb(struct ubi_device *ubi, int vol_id, int lnum, |
541 | int ubi_wl_flush(struct ubi_device *ubi); | 671 | int pnum, int torture); |
672 | int ubi_wl_flush(struct ubi_device *ubi, int vol_id, int lnum); | ||
542 | int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum); | 673 | int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum); |
543 | int ubi_wl_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si); | 674 | int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai); |
544 | void ubi_wl_close(struct ubi_device *ubi); | 675 | void ubi_wl_close(struct ubi_device *ubi); |
545 | int ubi_thread(void *u); | 676 | int ubi_thread(void *u); |
546 | 677 | ||
@@ -573,6 +704,7 @@ int ubi_volume_notify(struct ubi_device *ubi, struct ubi_volume *vol, | |||
573 | int ubi_notify_all(struct ubi_device *ubi, int ntype, | 704 | int ubi_notify_all(struct ubi_device *ubi, int ntype, |
574 | struct notifier_block *nb); | 705 | struct notifier_block *nb); |
575 | int ubi_enumerate_volumes(struct notifier_block *nb); | 706 | int ubi_enumerate_volumes(struct notifier_block *nb); |
707 | void ubi_free_internal_volumes(struct ubi_device *ubi); | ||
576 | 708 | ||
577 | /* kapi.c */ | 709 | /* kapi.c */ |
578 | void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di); | 710 | void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di); |
@@ -593,6 +725,21 @@ void ubi_do_get_volume_info(struct ubi_device *ubi, struct ubi_volume *vol, | |||
593 | rb = rb_next(rb), \ | 725 | rb = rb_next(rb), \ |
594 | pos = (rb ? container_of(rb, typeof(*pos), member) : NULL)) | 726 | pos = (rb ? container_of(rb, typeof(*pos), member) : NULL)) |
595 | 727 | ||
728 | /* | ||
729 | * ubi_move_aeb_to_list - move a PEB from the volume tree to a list. | ||
730 | * | ||
731 | * @av: volume attaching information | ||
732 | * @aeb: attaching eraseblock information | ||
733 | * @list: the list to move to | ||
734 | */ | ||
735 | static inline void ubi_move_aeb_to_list(struct ubi_ainf_volume *av, | ||
736 | struct ubi_ainf_peb *aeb, | ||
737 | struct list_head *list) | ||
738 | { | ||
739 | rb_erase(&aeb->u.rb, &av->root); | ||
740 | list_add_tail(&aeb->u.list, list); | ||
741 | } | ||
742 | |||
596 | /** | 743 | /** |
597 | * ubi_zalloc_vid_hdr - allocate a volume identifier header object. | 744 | * ubi_zalloc_vid_hdr - allocate a volume identifier header object. |
598 | * @ubi: UBI device description object | 745 | * @ubi: UBI device description object |
@@ -667,7 +814,7 @@ static inline void ubi_ro_mode(struct ubi_device *ubi) | |||
667 | if (!ubi->ro_mode) { | 814 | if (!ubi->ro_mode) { |
668 | ubi->ro_mode = 1; | 815 | ubi->ro_mode = 1; |
669 | ubi_warn("switch to read-only mode"); | 816 | ubi_warn("switch to read-only mode"); |
670 | ubi_dbg_dump_stack(); | 817 | dump_stack(); |
671 | } | 818 | } |
672 | } | 819 | } |
673 | 820 | ||
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c index 425bf5a3edd4..9f2ebd8750e7 100644 --- a/drivers/mtd/ubi/upd.c +++ b/drivers/mtd/ubi/upd.c | |||
@@ -147,7 +147,7 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol, | |||
147 | } | 147 | } |
148 | 148 | ||
149 | if (bytes == 0) { | 149 | if (bytes == 0) { |
150 | err = ubi_wl_flush(ubi); | 150 | err = ubi_wl_flush(ubi, UBI_ALL, UBI_ALL); |
151 | if (err) | 151 | if (err) |
152 | return err; | 152 | return err; |
153 | 153 | ||
@@ -186,14 +186,12 @@ int ubi_start_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, | |||
186 | dbg_gen("start changing LEB %d:%d, %u bytes", | 186 | dbg_gen("start changing LEB %d:%d, %u bytes", |
187 | vol->vol_id, req->lnum, req->bytes); | 187 | vol->vol_id, req->lnum, req->bytes); |
188 | if (req->bytes == 0) | 188 | if (req->bytes == 0) |
189 | return ubi_eba_atomic_leb_change(ubi, vol, req->lnum, NULL, 0, | 189 | return ubi_eba_atomic_leb_change(ubi, vol, req->lnum, NULL, 0); |
190 | req->dtype); | ||
191 | 190 | ||
192 | vol->upd_bytes = req->bytes; | 191 | vol->upd_bytes = req->bytes; |
193 | vol->upd_received = 0; | 192 | vol->upd_received = 0; |
194 | vol->changing_leb = 1; | 193 | vol->changing_leb = 1; |
195 | vol->ch_lnum = req->lnum; | 194 | vol->ch_lnum = req->lnum; |
196 | vol->ch_dtype = req->dtype; | ||
197 | 195 | ||
198 | vol->upd_buf = vmalloc(req->bytes); | 196 | vol->upd_buf = vmalloc(req->bytes); |
199 | if (!vol->upd_buf) | 197 | if (!vol->upd_buf) |
@@ -246,8 +244,7 @@ static int write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, | |||
246 | return 0; | 244 | return 0; |
247 | } | 245 | } |
248 | 246 | ||
249 | err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len, | 247 | err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len); |
250 | UBI_UNKNOWN); | ||
251 | } else { | 248 | } else { |
252 | /* | 249 | /* |
253 | * When writing static volume, and this is the last logical | 250 | * When writing static volume, and this is the last logical |
@@ -259,8 +256,7 @@ static int write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, | |||
259 | * contain zeros, not random trash. | 256 | * contain zeros, not random trash. |
260 | */ | 257 | */ |
261 | memset(buf + len, 0, vol->usable_leb_size - len); | 258 | memset(buf + len, 0, vol->usable_leb_size - len); |
262 | err = ubi_eba_write_leb_st(ubi, vol, lnum, buf, len, | 259 | err = ubi_eba_write_leb_st(ubi, vol, lnum, buf, len, used_ebs); |
263 | UBI_UNKNOWN, used_ebs); | ||
264 | } | 260 | } |
265 | 261 | ||
266 | return err; | 262 | return err; |
@@ -365,7 +361,7 @@ int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol, | |||
365 | 361 | ||
366 | ubi_assert(vol->upd_received <= vol->upd_bytes); | 362 | ubi_assert(vol->upd_received <= vol->upd_bytes); |
367 | if (vol->upd_received == vol->upd_bytes) { | 363 | if (vol->upd_received == vol->upd_bytes) { |
368 | err = ubi_wl_flush(ubi); | 364 | err = ubi_wl_flush(ubi, UBI_ALL, UBI_ALL); |
369 | if (err) | 365 | if (err) |
370 | return err; | 366 | return err; |
371 | /* The update is finished, clear the update marker */ | 367 | /* The update is finished, clear the update marker */ |
@@ -421,7 +417,7 @@ int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vol, | |||
421 | len - vol->upd_bytes); | 417 | len - vol->upd_bytes); |
422 | len = ubi_calc_data_len(ubi, vol->upd_buf, len); | 418 | len = ubi_calc_data_len(ubi, vol->upd_buf, len); |
423 | err = ubi_eba_atomic_leb_change(ubi, vol, vol->ch_lnum, | 419 | err = ubi_eba_atomic_leb_change(ubi, vol, vol->ch_lnum, |
424 | vol->upd_buf, len, UBI_UNKNOWN); | 420 | vol->upd_buf, len); |
425 | if (err) | 421 | if (err) |
426 | return err; | 422 | return err; |
427 | } | 423 | } |
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index 863835f4aefe..0669cff8ac3c 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c | |||
@@ -29,11 +29,7 @@ | |||
29 | #include <linux/export.h> | 29 | #include <linux/export.h> |
30 | #include "ubi.h" | 30 | #include "ubi.h" |
31 | 31 | ||
32 | #ifdef CONFIG_MTD_UBI_DEBUG | 32 | static int self_check_volumes(struct ubi_device *ubi); |
33 | static int paranoid_check_volumes(struct ubi_device *ubi); | ||
34 | #else | ||
35 | #define paranoid_check_volumes(ubi) 0 | ||
36 | #endif | ||
37 | 33 | ||
38 | static ssize_t vol_attribute_show(struct device *dev, | 34 | static ssize_t vol_attribute_show(struct device *dev, |
39 | struct device_attribute *attr, char *buf); | 35 | struct device_attribute *attr, char *buf); |
@@ -227,7 +223,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) | |||
227 | } | 223 | } |
228 | 224 | ||
229 | if (vol_id == UBI_VOL_NUM_AUTO) { | 225 | if (vol_id == UBI_VOL_NUM_AUTO) { |
230 | dbg_err("out of volume IDs"); | 226 | ubi_err("out of volume IDs"); |
231 | err = -ENFILE; | 227 | err = -ENFILE; |
232 | goto out_unlock; | 228 | goto out_unlock; |
233 | } | 229 | } |
@@ -241,7 +237,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) | |||
241 | /* Ensure that this volume does not exist */ | 237 | /* Ensure that this volume does not exist */ |
242 | err = -EEXIST; | 238 | err = -EEXIST; |
243 | if (ubi->volumes[vol_id]) { | 239 | if (ubi->volumes[vol_id]) { |
244 | dbg_err("volume %d already exists", vol_id); | 240 | ubi_err("volume %d already exists", vol_id); |
245 | goto out_unlock; | 241 | goto out_unlock; |
246 | } | 242 | } |
247 | 243 | ||
@@ -250,7 +246,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) | |||
250 | if (ubi->volumes[i] && | 246 | if (ubi->volumes[i] && |
251 | ubi->volumes[i]->name_len == req->name_len && | 247 | ubi->volumes[i]->name_len == req->name_len && |
252 | !strcmp(ubi->volumes[i]->name, req->name)) { | 248 | !strcmp(ubi->volumes[i]->name, req->name)) { |
253 | dbg_err("volume \"%s\" exists (ID %d)", req->name, i); | 249 | ubi_err("volume \"%s\" exists (ID %d)", req->name, i); |
254 | goto out_unlock; | 250 | goto out_unlock; |
255 | } | 251 | } |
256 | 252 | ||
@@ -261,9 +257,9 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) | |||
261 | 257 | ||
262 | /* Reserve physical eraseblocks */ | 258 | /* Reserve physical eraseblocks */ |
263 | if (vol->reserved_pebs > ubi->avail_pebs) { | 259 | if (vol->reserved_pebs > ubi->avail_pebs) { |
264 | dbg_err("not enough PEBs, only %d available", ubi->avail_pebs); | 260 | ubi_err("not enough PEBs, only %d available", ubi->avail_pebs); |
265 | if (ubi->corr_peb_count) | 261 | if (ubi->corr_peb_count) |
266 | dbg_err("%d PEBs are corrupted and not used", | 262 | ubi_err("%d PEBs are corrupted and not used", |
267 | ubi->corr_peb_count); | 263 | ubi->corr_peb_count); |
268 | err = -ENOSPC; | 264 | err = -ENOSPC; |
269 | goto out_unlock; | 265 | goto out_unlock; |
@@ -284,7 +280,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) | |||
284 | * Finish all pending erases because there may be some LEBs belonging | 280 | * Finish all pending erases because there may be some LEBs belonging |
285 | * to the same volume ID. | 281 | * to the same volume ID. |
286 | */ | 282 | */ |
287 | err = ubi_wl_flush(ubi); | 283 | err = ubi_wl_flush(ubi, vol_id, UBI_ALL); |
288 | if (err) | 284 | if (err) |
289 | goto out_acc; | 285 | goto out_acc; |
290 | 286 | ||
@@ -360,8 +356,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) | |||
360 | spin_unlock(&ubi->volumes_lock); | 356 | spin_unlock(&ubi->volumes_lock); |
361 | 357 | ||
362 | ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); | 358 | ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); |
363 | if (paranoid_check_volumes(ubi)) | 359 | self_check_volumes(ubi); |
364 | dbg_err("check failed while creating volume %d", vol_id); | ||
365 | return err; | 360 | return err; |
366 | 361 | ||
367 | out_sysfs: | 362 | out_sysfs: |
@@ -461,8 +456,8 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl) | |||
461 | spin_unlock(&ubi->volumes_lock); | 456 | spin_unlock(&ubi->volumes_lock); |
462 | 457 | ||
463 | ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED); | 458 | ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED); |
464 | if (!no_vtbl && paranoid_check_volumes(ubi)) | 459 | if (!no_vtbl) |
465 | dbg_err("check failed while removing volume %d", vol_id); | 460 | self_check_volumes(ubi); |
466 | 461 | ||
467 | return err; | 462 | return err; |
468 | 463 | ||
@@ -500,7 +495,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs) | |||
500 | 495 | ||
501 | if (vol->vol_type == UBI_STATIC_VOLUME && | 496 | if (vol->vol_type == UBI_STATIC_VOLUME && |
502 | reserved_pebs < vol->used_ebs) { | 497 | reserved_pebs < vol->used_ebs) { |
503 | dbg_err("too small size %d, %d LEBs contain data", | 498 | ubi_err("too small size %d, %d LEBs contain data", |
504 | reserved_pebs, vol->used_ebs); | 499 | reserved_pebs, vol->used_ebs); |
505 | return -EINVAL; | 500 | return -EINVAL; |
506 | } | 501 | } |
@@ -529,10 +524,10 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs) | |||
529 | if (pebs > 0) { | 524 | if (pebs > 0) { |
530 | spin_lock(&ubi->volumes_lock); | 525 | spin_lock(&ubi->volumes_lock); |
531 | if (pebs > ubi->avail_pebs) { | 526 | if (pebs > ubi->avail_pebs) { |
532 | dbg_err("not enough PEBs: requested %d, available %d", | 527 | ubi_err("not enough PEBs: requested %d, available %d", |
533 | pebs, ubi->avail_pebs); | 528 | pebs, ubi->avail_pebs); |
534 | if (ubi->corr_peb_count) | 529 | if (ubi->corr_peb_count) |
535 | dbg_err("%d PEBs are corrupted and not used", | 530 | ubi_err("%d PEBs are corrupted and not used", |
536 | ubi->corr_peb_count); | 531 | ubi->corr_peb_count); |
537 | spin_unlock(&ubi->volumes_lock); | 532 | spin_unlock(&ubi->volumes_lock); |
538 | err = -ENOSPC; | 533 | err = -ENOSPC; |
@@ -588,8 +583,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs) | |||
588 | } | 583 | } |
589 | 584 | ||
590 | ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED); | 585 | ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED); |
591 | if (paranoid_check_volumes(ubi)) | 586 | self_check_volumes(ubi); |
592 | dbg_err("check failed while re-sizing volume %d", vol_id); | ||
593 | return err; | 587 | return err; |
594 | 588 | ||
595 | out_acc: | 589 | out_acc: |
@@ -638,8 +632,8 @@ int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list) | |||
638 | } | 632 | } |
639 | } | 633 | } |
640 | 634 | ||
641 | if (!err && paranoid_check_volumes(ubi)) | 635 | if (!err) |
642 | ; | 636 | self_check_volumes(ubi); |
643 | return err; | 637 | return err; |
644 | } | 638 | } |
645 | 639 | ||
@@ -686,8 +680,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) | |||
686 | return err; | 680 | return err; |
687 | } | 681 | } |
688 | 682 | ||
689 | if (paranoid_check_volumes(ubi)) | 683 | self_check_volumes(ubi); |
690 | dbg_err("check failed while adding volume %d", vol_id); | ||
691 | return err; | 684 | return err; |
692 | 685 | ||
693 | out_cdev: | 686 | out_cdev: |
@@ -712,16 +705,14 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) | |||
712 | volume_sysfs_close(vol); | 705 | volume_sysfs_close(vol); |
713 | } | 706 | } |
714 | 707 | ||
715 | #ifdef CONFIG_MTD_UBI_DEBUG | ||
716 | |||
717 | /** | 708 | /** |
718 | * paranoid_check_volume - check volume information. | 709 | * self_check_volume - check volume information. |
719 | * @ubi: UBI device description object | 710 | * @ubi: UBI device description object |
720 | * @vol_id: volume ID | 711 | * @vol_id: volume ID |
721 | * | 712 | * |
722 | * Returns zero if volume is all right and a a negative error code if not. | 713 | * Returns zero if volume is all right and a a negative error code if not. |
723 | */ | 714 | */ |
724 | static int paranoid_check_volume(struct ubi_device *ubi, int vol_id) | 715 | static int self_check_volume(struct ubi_device *ubi, int vol_id) |
725 | { | 716 | { |
726 | int idx = vol_id2idx(ubi, vol_id); | 717 | int idx = vol_id2idx(ubi, vol_id); |
727 | int reserved_pebs, alignment, data_pad, vol_type, name_len, upd_marker; | 718 | int reserved_pebs, alignment, data_pad, vol_type, name_len, upd_marker; |
@@ -771,7 +762,7 @@ static int paranoid_check_volume(struct ubi_device *ubi, int vol_id) | |||
771 | } | 762 | } |
772 | 763 | ||
773 | if (vol->upd_marker && vol->corrupted) { | 764 | if (vol->upd_marker && vol->corrupted) { |
774 | dbg_err("update marker and corrupted simultaneously"); | 765 | ubi_err("update marker and corrupted simultaneously"); |
775 | goto fail; | 766 | goto fail; |
776 | } | 767 | } |
777 | 768 | ||
@@ -853,22 +844,22 @@ static int paranoid_check_volume(struct ubi_device *ubi, int vol_id) | |||
853 | return 0; | 844 | return 0; |
854 | 845 | ||
855 | fail: | 846 | fail: |
856 | ubi_err("paranoid check failed for volume %d", vol_id); | 847 | ubi_err("self-check failed for volume %d", vol_id); |
857 | if (vol) | 848 | if (vol) |
858 | ubi_dbg_dump_vol_info(vol); | 849 | ubi_dump_vol_info(vol); |
859 | ubi_dbg_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id); | 850 | ubi_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id); |
860 | dump_stack(); | 851 | dump_stack(); |
861 | spin_unlock(&ubi->volumes_lock); | 852 | spin_unlock(&ubi->volumes_lock); |
862 | return -EINVAL; | 853 | return -EINVAL; |
863 | } | 854 | } |
864 | 855 | ||
865 | /** | 856 | /** |
866 | * paranoid_check_volumes - check information about all volumes. | 857 | * self_check_volumes - check information about all volumes. |
867 | * @ubi: UBI device description object | 858 | * @ubi: UBI device description object |
868 | * | 859 | * |
869 | * Returns zero if volumes are all right and a a negative error code if not. | 860 | * Returns zero if volumes are all right and a a negative error code if not. |
870 | */ | 861 | */ |
871 | static int paranoid_check_volumes(struct ubi_device *ubi) | 862 | static int self_check_volumes(struct ubi_device *ubi) |
872 | { | 863 | { |
873 | int i, err = 0; | 864 | int i, err = 0; |
874 | 865 | ||
@@ -876,11 +867,10 @@ static int paranoid_check_volumes(struct ubi_device *ubi) | |||
876 | return 0; | 867 | return 0; |
877 | 868 | ||
878 | for (i = 0; i < ubi->vtbl_slots; i++) { | 869 | for (i = 0; i < ubi->vtbl_slots; i++) { |
879 | err = paranoid_check_volume(ubi, i); | 870 | err = self_check_volume(ubi, i); |
880 | if (err) | 871 | if (err) |
881 | break; | 872 | break; |
882 | } | 873 | } |
883 | 874 | ||
884 | return err; | 875 | return err; |
885 | } | 876 | } |
886 | #endif | ||
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c index 17cec0c01544..437bc193e170 100644 --- a/drivers/mtd/ubi/vtbl.c +++ b/drivers/mtd/ubi/vtbl.c | |||
@@ -37,16 +37,15 @@ | |||
37 | * LEB 1. This scheme guarantees recoverability from unclean reboots. | 37 | * LEB 1. This scheme guarantees recoverability from unclean reboots. |
38 | * | 38 | * |
39 | * In this UBI implementation the on-flash volume table does not contain any | 39 | * In this UBI implementation the on-flash volume table does not contain any |
40 | * information about how many data static volumes contain. This information may | 40 | * information about how much data static volumes contain. |
41 | * be found from the scanning data. | ||
42 | * | 41 | * |
43 | * But it would still be beneficial to store this information in the volume | 42 | * But it would still be beneficial to store this information in the volume |
44 | * table. For example, suppose we have a static volume X, and all its physical | 43 | * table. For example, suppose we have a static volume X, and all its physical |
45 | * eraseblocks became bad for some reasons. Suppose we are attaching the | 44 | * eraseblocks became bad for some reasons. Suppose we are attaching the |
46 | * corresponding MTD device, the scanning has found no logical eraseblocks | 45 | * corresponding MTD device, for some reason we find no logical eraseblocks |
47 | * corresponding to the volume X. According to the volume table volume X does | 46 | * corresponding to the volume X. According to the volume table volume X does |
48 | * exist. So we don't know whether it is just empty or all its physical | 47 | * exist. So we don't know whether it is just empty or all its physical |
49 | * eraseblocks went bad. So we cannot alarm the user about this corruption. | 48 | * eraseblocks went bad. So we cannot alarm the user properly. |
50 | * | 49 | * |
51 | * The volume table also stores so-called "update marker", which is used for | 50 | * The volume table also stores so-called "update marker", which is used for |
52 | * volume updates. Before updating the volume, the update marker is set, and | 51 | * volume updates. Before updating the volume, the update marker is set, and |
@@ -62,11 +61,7 @@ | |||
62 | #include <asm/div64.h> | 61 | #include <asm/div64.h> |
63 | #include "ubi.h" | 62 | #include "ubi.h" |
64 | 63 | ||
65 | #ifdef CONFIG_MTD_UBI_DEBUG | 64 | static void self_vtbl_check(const struct ubi_device *ubi); |
66 | static void paranoid_vtbl_check(const struct ubi_device *ubi); | ||
67 | #else | ||
68 | #define paranoid_vtbl_check(ubi) | ||
69 | #endif | ||
70 | 65 | ||
71 | /* Empty volume table record */ | 66 | /* Empty volume table record */ |
72 | static struct ubi_vtbl_record empty_vtbl_record; | 67 | static struct ubi_vtbl_record empty_vtbl_record; |
@@ -106,12 +101,12 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, | |||
106 | return err; | 101 | return err; |
107 | 102 | ||
108 | err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0, | 103 | err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0, |
109 | ubi->vtbl_size, UBI_LONGTERM); | 104 | ubi->vtbl_size); |
110 | if (err) | 105 | if (err) |
111 | return err; | 106 | return err; |
112 | } | 107 | } |
113 | 108 | ||
114 | paranoid_vtbl_check(ubi); | 109 | self_vtbl_check(ubi); |
115 | return 0; | 110 | return 0; |
116 | } | 111 | } |
117 | 112 | ||
@@ -158,7 +153,7 @@ int ubi_vtbl_rename_volumes(struct ubi_device *ubi, | |||
158 | return err; | 153 | return err; |
159 | 154 | ||
160 | err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0, | 155 | err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0, |
161 | ubi->vtbl_size, UBI_LONGTERM); | 156 | ubi->vtbl_size); |
162 | if (err) | 157 | if (err) |
163 | return err; | 158 | return err; |
164 | } | 159 | } |
@@ -197,7 +192,7 @@ static int vtbl_check(const struct ubi_device *ubi, | |||
197 | if (be32_to_cpu(vtbl[i].crc) != crc) { | 192 | if (be32_to_cpu(vtbl[i].crc) != crc) { |
198 | ubi_err("bad CRC at record %u: %#08x, not %#08x", | 193 | ubi_err("bad CRC at record %u: %#08x, not %#08x", |
199 | i, crc, be32_to_cpu(vtbl[i].crc)); | 194 | i, crc, be32_to_cpu(vtbl[i].crc)); |
200 | ubi_dbg_dump_vtbl_record(&vtbl[i], i); | 195 | ubi_dump_vtbl_record(&vtbl[i], i); |
201 | return 1; | 196 | return 1; |
202 | } | 197 | } |
203 | 198 | ||
@@ -229,7 +224,7 @@ static int vtbl_check(const struct ubi_device *ubi, | |||
229 | 224 | ||
230 | n = ubi->leb_size % alignment; | 225 | n = ubi->leb_size % alignment; |
231 | if (data_pad != n) { | 226 | if (data_pad != n) { |
232 | dbg_err("bad data_pad, has to be %d", n); | 227 | ubi_err("bad data_pad, has to be %d", n); |
233 | err = 6; | 228 | err = 6; |
234 | goto bad; | 229 | goto bad; |
235 | } | 230 | } |
@@ -245,7 +240,7 @@ static int vtbl_check(const struct ubi_device *ubi, | |||
245 | } | 240 | } |
246 | 241 | ||
247 | if (reserved_pebs > ubi->good_peb_count) { | 242 | if (reserved_pebs > ubi->good_peb_count) { |
248 | dbg_err("too large reserved_pebs %d, good PEBs %d", | 243 | ubi_err("too large reserved_pebs %d, good PEBs %d", |
249 | reserved_pebs, ubi->good_peb_count); | 244 | reserved_pebs, ubi->good_peb_count); |
250 | err = 9; | 245 | err = 9; |
251 | goto bad; | 246 | goto bad; |
@@ -277,8 +272,8 @@ static int vtbl_check(const struct ubi_device *ubi, | |||
277 | !strncmp(vtbl[i].name, vtbl[n].name, len1)) { | 272 | !strncmp(vtbl[i].name, vtbl[n].name, len1)) { |
278 | ubi_err("volumes %d and %d have the same name" | 273 | ubi_err("volumes %d and %d have the same name" |
279 | " \"%s\"", i, n, vtbl[i].name); | 274 | " \"%s\"", i, n, vtbl[i].name); |
280 | ubi_dbg_dump_vtbl_record(&vtbl[i], i); | 275 | ubi_dump_vtbl_record(&vtbl[i], i); |
281 | ubi_dbg_dump_vtbl_record(&vtbl[n], n); | 276 | ubi_dump_vtbl_record(&vtbl[n], n); |
282 | return -EINVAL; | 277 | return -EINVAL; |
283 | } | 278 | } |
284 | } | 279 | } |
@@ -288,26 +283,26 @@ static int vtbl_check(const struct ubi_device *ubi, | |||
288 | 283 | ||
289 | bad: | 284 | bad: |
290 | ubi_err("volume table check failed: record %d, error %d", i, err); | 285 | ubi_err("volume table check failed: record %d, error %d", i, err); |
291 | ubi_dbg_dump_vtbl_record(&vtbl[i], i); | 286 | ubi_dump_vtbl_record(&vtbl[i], i); |
292 | return -EINVAL; | 287 | return -EINVAL; |
293 | } | 288 | } |
294 | 289 | ||
295 | /** | 290 | /** |
296 | * create_vtbl - create a copy of volume table. | 291 | * create_vtbl - create a copy of volume table. |
297 | * @ubi: UBI device description object | 292 | * @ubi: UBI device description object |
298 | * @si: scanning information | 293 | * @ai: attaching information |
299 | * @copy: number of the volume table copy | 294 | * @copy: number of the volume table copy |
300 | * @vtbl: contents of the volume table | 295 | * @vtbl: contents of the volume table |
301 | * | 296 | * |
302 | * This function returns zero in case of success and a negative error code in | 297 | * This function returns zero in case of success and a negative error code in |
303 | * case of failure. | 298 | * case of failure. |
304 | */ | 299 | */ |
305 | static int create_vtbl(struct ubi_device *ubi, struct ubi_scan_info *si, | 300 | static int create_vtbl(struct ubi_device *ubi, struct ubi_attach_info *ai, |
306 | int copy, void *vtbl) | 301 | int copy, void *vtbl) |
307 | { | 302 | { |
308 | int err, tries = 0; | 303 | int err, tries = 0; |
309 | struct ubi_vid_hdr *vid_hdr; | 304 | struct ubi_vid_hdr *vid_hdr; |
310 | struct ubi_scan_leb *new_seb; | 305 | struct ubi_ainf_peb *new_aeb; |
311 | 306 | ||
312 | ubi_msg("create volume table (copy #%d)", copy + 1); | 307 | ubi_msg("create volume table (copy #%d)", copy + 1); |
313 | 308 | ||
@@ -316,9 +311,9 @@ static int create_vtbl(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
316 | return -ENOMEM; | 311 | return -ENOMEM; |
317 | 312 | ||
318 | retry: | 313 | retry: |
319 | new_seb = ubi_scan_get_free_peb(ubi, si); | 314 | new_aeb = ubi_early_get_peb(ubi, ai); |
320 | if (IS_ERR(new_seb)) { | 315 | if (IS_ERR(new_aeb)) { |
321 | err = PTR_ERR(new_seb); | 316 | err = PTR_ERR(new_aeb); |
322 | goto out_free; | 317 | goto out_free; |
323 | } | 318 | } |
324 | 319 | ||
@@ -328,25 +323,24 @@ retry: | |||
328 | vid_hdr->data_size = vid_hdr->used_ebs = | 323 | vid_hdr->data_size = vid_hdr->used_ebs = |
329 | vid_hdr->data_pad = cpu_to_be32(0); | 324 | vid_hdr->data_pad = cpu_to_be32(0); |
330 | vid_hdr->lnum = cpu_to_be32(copy); | 325 | vid_hdr->lnum = cpu_to_be32(copy); |
331 | vid_hdr->sqnum = cpu_to_be64(++si->max_sqnum); | 326 | vid_hdr->sqnum = cpu_to_be64(++ai->max_sqnum); |
332 | 327 | ||
333 | /* The EC header is already there, write the VID header */ | 328 | /* The EC header is already there, write the VID header */ |
334 | err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr); | 329 | err = ubi_io_write_vid_hdr(ubi, new_aeb->pnum, vid_hdr); |
335 | if (err) | 330 | if (err) |
336 | goto write_error; | 331 | goto write_error; |
337 | 332 | ||
338 | /* Write the layout volume contents */ | 333 | /* Write the layout volume contents */ |
339 | err = ubi_io_write_data(ubi, vtbl, new_seb->pnum, 0, ubi->vtbl_size); | 334 | err = ubi_io_write_data(ubi, vtbl, new_aeb->pnum, 0, ubi->vtbl_size); |
340 | if (err) | 335 | if (err) |
341 | goto write_error; | 336 | goto write_error; |
342 | 337 | ||
343 | /* | 338 | /* |
344 | * And add it to the scanning information. Don't delete the old version | 339 | * And add it to the attaching information. Don't delete the old version |
345 | * of this LEB as it will be deleted and freed in 'ubi_scan_add_used()'. | 340 | * of this LEB as it will be deleted and freed in 'ubi_add_to_av()'. |
346 | */ | 341 | */ |
347 | err = ubi_scan_add_used(ubi, si, new_seb->pnum, new_seb->ec, | 342 | err = ubi_add_to_av(ubi, ai, new_aeb->pnum, new_aeb->ec, vid_hdr, 0); |
348 | vid_hdr, 0); | 343 | kfree(new_aeb); |
349 | kfree(new_seb); | ||
350 | ubi_free_vid_hdr(ubi, vid_hdr); | 344 | ubi_free_vid_hdr(ubi, vid_hdr); |
351 | return err; | 345 | return err; |
352 | 346 | ||
@@ -356,10 +350,10 @@ write_error: | |||
356 | * Probably this physical eraseblock went bad, try to pick | 350 | * Probably this physical eraseblock went bad, try to pick |
357 | * another one. | 351 | * another one. |
358 | */ | 352 | */ |
359 | list_add(&new_seb->u.list, &si->erase); | 353 | list_add(&new_aeb->u.list, &ai->erase); |
360 | goto retry; | 354 | goto retry; |
361 | } | 355 | } |
362 | kfree(new_seb); | 356 | kfree(new_aeb); |
363 | out_free: | 357 | out_free: |
364 | ubi_free_vid_hdr(ubi, vid_hdr); | 358 | ubi_free_vid_hdr(ubi, vid_hdr); |
365 | return err; | 359 | return err; |
@@ -369,20 +363,20 @@ out_free: | |||
369 | /** | 363 | /** |
370 | * process_lvol - process the layout volume. | 364 | * process_lvol - process the layout volume. |
371 | * @ubi: UBI device description object | 365 | * @ubi: UBI device description object |
372 | * @si: scanning information | 366 | * @ai: attaching information |
373 | * @sv: layout volume scanning information | 367 | * @av: layout volume attaching information |
374 | * | 368 | * |
375 | * This function is responsible for reading the layout volume, ensuring it is | 369 | * This function is responsible for reading the layout volume, ensuring it is |
376 | * not corrupted, and recovering from corruptions if needed. Returns volume | 370 | * not corrupted, and recovering from corruptions if needed. Returns volume |
377 | * table in case of success and a negative error code in case of failure. | 371 | * table in case of success and a negative error code in case of failure. |
378 | */ | 372 | */ |
379 | static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi, | 373 | static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi, |
380 | struct ubi_scan_info *si, | 374 | struct ubi_attach_info *ai, |
381 | struct ubi_scan_volume *sv) | 375 | struct ubi_ainf_volume *av) |
382 | { | 376 | { |
383 | int err; | 377 | int err; |
384 | struct rb_node *rb; | 378 | struct rb_node *rb; |
385 | struct ubi_scan_leb *seb; | 379 | struct ubi_ainf_peb *aeb; |
386 | struct ubi_vtbl_record *leb[UBI_LAYOUT_VOLUME_EBS] = { NULL, NULL }; | 380 | struct ubi_vtbl_record *leb[UBI_LAYOUT_VOLUME_EBS] = { NULL, NULL }; |
387 | int leb_corrupted[UBI_LAYOUT_VOLUME_EBS] = {1, 1}; | 381 | int leb_corrupted[UBI_LAYOUT_VOLUME_EBS] = {1, 1}; |
388 | 382 | ||
@@ -414,14 +408,14 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi, | |||
414 | dbg_gen("check layout volume"); | 408 | dbg_gen("check layout volume"); |
415 | 409 | ||
416 | /* Read both LEB 0 and LEB 1 into memory */ | 410 | /* Read both LEB 0 and LEB 1 into memory */ |
417 | ubi_rb_for_each_entry(rb, seb, &sv->root, u.rb) { | 411 | ubi_rb_for_each_entry(rb, aeb, &av->root, u.rb) { |
418 | leb[seb->lnum] = vzalloc(ubi->vtbl_size); | 412 | leb[aeb->lnum] = vzalloc(ubi->vtbl_size); |
419 | if (!leb[seb->lnum]) { | 413 | if (!leb[aeb->lnum]) { |
420 | err = -ENOMEM; | 414 | err = -ENOMEM; |
421 | goto out_free; | 415 | goto out_free; |
422 | } | 416 | } |
423 | 417 | ||
424 | err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0, | 418 | err = ubi_io_read_data(ubi, leb[aeb->lnum], aeb->pnum, 0, |
425 | ubi->vtbl_size); | 419 | ubi->vtbl_size); |
426 | if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err)) | 420 | if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err)) |
427 | /* | 421 | /* |
@@ -429,12 +423,12 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi, | |||
429 | * uncorrectable ECC error, but we have our own CRC and | 423 | * uncorrectable ECC error, but we have our own CRC and |
430 | * the data will be checked later. If the data is OK, | 424 | * the data will be checked later. If the data is OK, |
431 | * the PEB will be scrubbed (because we set | 425 | * the PEB will be scrubbed (because we set |
432 | * seb->scrub). If the data is not OK, the contents of | 426 | * aeb->scrub). If the data is not OK, the contents of |
433 | * the PEB will be recovered from the second copy, and | 427 | * the PEB will be recovered from the second copy, and |
434 | * seb->scrub will be cleared in | 428 | * aeb->scrub will be cleared in |
435 | * 'ubi_scan_add_used()'. | 429 | * 'ubi_add_to_av()'. |
436 | */ | 430 | */ |
437 | seb->scrub = 1; | 431 | aeb->scrub = 1; |
438 | else if (err) | 432 | else if (err) |
439 | goto out_free; | 433 | goto out_free; |
440 | } | 434 | } |
@@ -453,7 +447,7 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi, | |||
453 | ubi->vtbl_size); | 447 | ubi->vtbl_size); |
454 | if (leb_corrupted[1]) { | 448 | if (leb_corrupted[1]) { |
455 | ubi_warn("volume table copy #2 is corrupted"); | 449 | ubi_warn("volume table copy #2 is corrupted"); |
456 | err = create_vtbl(ubi, si, 1, leb[0]); | 450 | err = create_vtbl(ubi, ai, 1, leb[0]); |
457 | if (err) | 451 | if (err) |
458 | goto out_free; | 452 | goto out_free; |
459 | ubi_msg("volume table was restored"); | 453 | ubi_msg("volume table was restored"); |
@@ -476,7 +470,7 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi, | |||
476 | } | 470 | } |
477 | 471 | ||
478 | ubi_warn("volume table copy #1 is corrupted"); | 472 | ubi_warn("volume table copy #1 is corrupted"); |
479 | err = create_vtbl(ubi, si, 0, leb[1]); | 473 | err = create_vtbl(ubi, ai, 0, leb[1]); |
480 | if (err) | 474 | if (err) |
481 | goto out_free; | 475 | goto out_free; |
482 | ubi_msg("volume table was restored"); | 476 | ubi_msg("volume table was restored"); |
@@ -494,13 +488,13 @@ out_free: | |||
494 | /** | 488 | /** |
495 | * create_empty_lvol - create empty layout volume. | 489 | * create_empty_lvol - create empty layout volume. |
496 | * @ubi: UBI device description object | 490 | * @ubi: UBI device description object |
497 | * @si: scanning information | 491 | * @ai: attaching information |
498 | * | 492 | * |
499 | * This function returns volume table contents in case of success and a | 493 | * This function returns volume table contents in case of success and a |
500 | * negative error code in case of failure. | 494 | * negative error code in case of failure. |
501 | */ | 495 | */ |
502 | static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi, | 496 | static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi, |
503 | struct ubi_scan_info *si) | 497 | struct ubi_attach_info *ai) |
504 | { | 498 | { |
505 | int i; | 499 | int i; |
506 | struct ubi_vtbl_record *vtbl; | 500 | struct ubi_vtbl_record *vtbl; |
@@ -515,7 +509,7 @@ static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi, | |||
515 | for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) { | 509 | for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) { |
516 | int err; | 510 | int err; |
517 | 511 | ||
518 | err = create_vtbl(ubi, si, i, vtbl); | 512 | err = create_vtbl(ubi, ai, i, vtbl); |
519 | if (err) { | 513 | if (err) { |
520 | vfree(vtbl); | 514 | vfree(vtbl); |
521 | return ERR_PTR(err); | 515 | return ERR_PTR(err); |
@@ -528,18 +522,19 @@ static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi, | |||
528 | /** | 522 | /** |
529 | * init_volumes - initialize volume information for existing volumes. | 523 | * init_volumes - initialize volume information for existing volumes. |
530 | * @ubi: UBI device description object | 524 | * @ubi: UBI device description object |
531 | * @si: scanning information | 525 | * @ai: scanning information |
532 | * @vtbl: volume table | 526 | * @vtbl: volume table |
533 | * | 527 | * |
534 | * This function allocates volume description objects for existing volumes. | 528 | * This function allocates volume description objects for existing volumes. |
535 | * Returns zero in case of success and a negative error code in case of | 529 | * Returns zero in case of success and a negative error code in case of |
536 | * failure. | 530 | * failure. |
537 | */ | 531 | */ |
538 | static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si, | 532 | static int init_volumes(struct ubi_device *ubi, |
533 | const struct ubi_attach_info *ai, | ||
539 | const struct ubi_vtbl_record *vtbl) | 534 | const struct ubi_vtbl_record *vtbl) |
540 | { | 535 | { |
541 | int i, reserved_pebs = 0; | 536 | int i, reserved_pebs = 0; |
542 | struct ubi_scan_volume *sv; | 537 | struct ubi_ainf_volume *av; |
543 | struct ubi_volume *vol; | 538 | struct ubi_volume *vol; |
544 | 539 | ||
545 | for (i = 0; i < ubi->vtbl_slots; i++) { | 540 | for (i = 0; i < ubi->vtbl_slots; i++) { |
@@ -595,8 +590,8 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si, | |||
595 | } | 590 | } |
596 | 591 | ||
597 | /* Static volumes only */ | 592 | /* Static volumes only */ |
598 | sv = ubi_scan_find_sv(si, i); | 593 | av = ubi_find_av(ai, i); |
599 | if (!sv) { | 594 | if (!av) { |
600 | /* | 595 | /* |
601 | * No eraseblocks belonging to this volume found. We | 596 | * No eraseblocks belonging to this volume found. We |
602 | * don't actually know whether this static volume is | 597 | * don't actually know whether this static volume is |
@@ -608,22 +603,22 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si, | |||
608 | continue; | 603 | continue; |
609 | } | 604 | } |
610 | 605 | ||
611 | if (sv->leb_count != sv->used_ebs) { | 606 | if (av->leb_count != av->used_ebs) { |
612 | /* | 607 | /* |
613 | * We found a static volume which misses several | 608 | * We found a static volume which misses several |
614 | * eraseblocks. Treat it as corrupted. | 609 | * eraseblocks. Treat it as corrupted. |
615 | */ | 610 | */ |
616 | ubi_warn("static volume %d misses %d LEBs - corrupted", | 611 | ubi_warn("static volume %d misses %d LEBs - corrupted", |
617 | sv->vol_id, sv->used_ebs - sv->leb_count); | 612 | av->vol_id, av->used_ebs - av->leb_count); |
618 | vol->corrupted = 1; | 613 | vol->corrupted = 1; |
619 | continue; | 614 | continue; |
620 | } | 615 | } |
621 | 616 | ||
622 | vol->used_ebs = sv->used_ebs; | 617 | vol->used_ebs = av->used_ebs; |
623 | vol->used_bytes = | 618 | vol->used_bytes = |
624 | (long long)(vol->used_ebs - 1) * vol->usable_leb_size; | 619 | (long long)(vol->used_ebs - 1) * vol->usable_leb_size; |
625 | vol->used_bytes += sv->last_data_size; | 620 | vol->used_bytes += av->last_data_size; |
626 | vol->last_eb_bytes = sv->last_data_size; | 621 | vol->last_eb_bytes = av->last_data_size; |
627 | } | 622 | } |
628 | 623 | ||
629 | /* And add the layout volume */ | 624 | /* And add the layout volume */ |
@@ -664,105 +659,104 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si, | |||
664 | } | 659 | } |
665 | 660 | ||
666 | /** | 661 | /** |
667 | * check_sv - check volume scanning information. | 662 | * check_av - check volume attaching information. |
668 | * @vol: UBI volume description object | 663 | * @vol: UBI volume description object |
669 | * @sv: volume scanning information | 664 | * @av: volume attaching information |
670 | * | 665 | * |
671 | * This function returns zero if the volume scanning information is consistent | 666 | * This function returns zero if the volume attaching information is consistent |
672 | * to the data read from the volume tabla, and %-EINVAL if not. | 667 | * to the data read from the volume tabla, and %-EINVAL if not. |
673 | */ | 668 | */ |
674 | static int check_sv(const struct ubi_volume *vol, | 669 | static int check_av(const struct ubi_volume *vol, |
675 | const struct ubi_scan_volume *sv) | 670 | const struct ubi_ainf_volume *av) |
676 | { | 671 | { |
677 | int err; | 672 | int err; |
678 | 673 | ||
679 | if (sv->highest_lnum >= vol->reserved_pebs) { | 674 | if (av->highest_lnum >= vol->reserved_pebs) { |
680 | err = 1; | 675 | err = 1; |
681 | goto bad; | 676 | goto bad; |
682 | } | 677 | } |
683 | if (sv->leb_count > vol->reserved_pebs) { | 678 | if (av->leb_count > vol->reserved_pebs) { |
684 | err = 2; | 679 | err = 2; |
685 | goto bad; | 680 | goto bad; |
686 | } | 681 | } |
687 | if (sv->vol_type != vol->vol_type) { | 682 | if (av->vol_type != vol->vol_type) { |
688 | err = 3; | 683 | err = 3; |
689 | goto bad; | 684 | goto bad; |
690 | } | 685 | } |
691 | if (sv->used_ebs > vol->reserved_pebs) { | 686 | if (av->used_ebs > vol->reserved_pebs) { |
692 | err = 4; | 687 | err = 4; |
693 | goto bad; | 688 | goto bad; |
694 | } | 689 | } |
695 | if (sv->data_pad != vol->data_pad) { | 690 | if (av->data_pad != vol->data_pad) { |
696 | err = 5; | 691 | err = 5; |
697 | goto bad; | 692 | goto bad; |
698 | } | 693 | } |
699 | return 0; | 694 | return 0; |
700 | 695 | ||
701 | bad: | 696 | bad: |
702 | ubi_err("bad scanning information, error %d", err); | 697 | ubi_err("bad attaching information, error %d", err); |
703 | ubi_dbg_dump_sv(sv); | 698 | ubi_dump_av(av); |
704 | ubi_dbg_dump_vol_info(vol); | 699 | ubi_dump_vol_info(vol); |
705 | return -EINVAL; | 700 | return -EINVAL; |
706 | } | 701 | } |
707 | 702 | ||
708 | /** | 703 | /** |
709 | * check_scanning_info - check that scanning information. | 704 | * check_attaching_info - check that attaching information. |
710 | * @ubi: UBI device description object | 705 | * @ubi: UBI device description object |
711 | * @si: scanning information | 706 | * @ai: attaching information |
712 | * | 707 | * |
713 | * Even though we protect on-flash data by CRC checksums, we still don't trust | 708 | * Even though we protect on-flash data by CRC checksums, we still don't trust |
714 | * the media. This function ensures that scanning information is consistent to | 709 | * the media. This function ensures that attaching information is consistent to |
715 | * the information read from the volume table. Returns zero if the scanning | 710 | * the information read from the volume table. Returns zero if the attaching |
716 | * information is OK and %-EINVAL if it is not. | 711 | * information is OK and %-EINVAL if it is not. |
717 | */ | 712 | */ |
718 | static int check_scanning_info(const struct ubi_device *ubi, | 713 | static int check_attaching_info(const struct ubi_device *ubi, |
719 | struct ubi_scan_info *si) | 714 | struct ubi_attach_info *ai) |
720 | { | 715 | { |
721 | int err, i; | 716 | int err, i; |
722 | struct ubi_scan_volume *sv; | 717 | struct ubi_ainf_volume *av; |
723 | struct ubi_volume *vol; | 718 | struct ubi_volume *vol; |
724 | 719 | ||
725 | if (si->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) { | 720 | if (ai->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) { |
726 | ubi_err("scanning found %d volumes, maximum is %d + %d", | 721 | ubi_err("found %d volumes while attaching, maximum is %d + %d", |
727 | si->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots); | 722 | ai->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots); |
728 | return -EINVAL; | 723 | return -EINVAL; |
729 | } | 724 | } |
730 | 725 | ||
731 | if (si->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT && | 726 | if (ai->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT && |
732 | si->highest_vol_id < UBI_INTERNAL_VOL_START) { | 727 | ai->highest_vol_id < UBI_INTERNAL_VOL_START) { |
733 | ubi_err("too large volume ID %d found by scanning", | 728 | ubi_err("too large volume ID %d found", ai->highest_vol_id); |
734 | si->highest_vol_id); | ||
735 | return -EINVAL; | 729 | return -EINVAL; |
736 | } | 730 | } |
737 | 731 | ||
738 | for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { | 732 | for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { |
739 | cond_resched(); | 733 | cond_resched(); |
740 | 734 | ||
741 | sv = ubi_scan_find_sv(si, i); | 735 | av = ubi_find_av(ai, i); |
742 | vol = ubi->volumes[i]; | 736 | vol = ubi->volumes[i]; |
743 | if (!vol) { | 737 | if (!vol) { |
744 | if (sv) | 738 | if (av) |
745 | ubi_scan_rm_volume(si, sv); | 739 | ubi_remove_av(ai, av); |
746 | continue; | 740 | continue; |
747 | } | 741 | } |
748 | 742 | ||
749 | if (vol->reserved_pebs == 0) { | 743 | if (vol->reserved_pebs == 0) { |
750 | ubi_assert(i < ubi->vtbl_slots); | 744 | ubi_assert(i < ubi->vtbl_slots); |
751 | 745 | ||
752 | if (!sv) | 746 | if (!av) |
753 | continue; | 747 | continue; |
754 | 748 | ||
755 | /* | 749 | /* |
756 | * During scanning we found a volume which does not | 750 | * During attaching we found a volume which does not |
757 | * exist according to the information in the volume | 751 | * exist according to the information in the volume |
758 | * table. This must have happened due to an unclean | 752 | * table. This must have happened due to an unclean |
759 | * reboot while the volume was being removed. Discard | 753 | * reboot while the volume was being removed. Discard |
760 | * these eraseblocks. | 754 | * these eraseblocks. |
761 | */ | 755 | */ |
762 | ubi_msg("finish volume %d removal", sv->vol_id); | 756 | ubi_msg("finish volume %d removal", av->vol_id); |
763 | ubi_scan_rm_volume(si, sv); | 757 | ubi_remove_av(ai, av); |
764 | } else if (sv) { | 758 | } else if (av) { |
765 | err = check_sv(vol, sv); | 759 | err = check_av(vol, av); |
766 | if (err) | 760 | if (err) |
767 | return err; | 761 | return err; |
768 | } | 762 | } |
@@ -774,16 +768,16 @@ static int check_scanning_info(const struct ubi_device *ubi, | |||
774 | /** | 768 | /** |
775 | * ubi_read_volume_table - read the volume table. | 769 | * ubi_read_volume_table - read the volume table. |
776 | * @ubi: UBI device description object | 770 | * @ubi: UBI device description object |
777 | * @si: scanning information | 771 | * @ai: attaching information |
778 | * | 772 | * |
779 | * This function reads volume table, checks it, recover from errors if needed, | 773 | * This function reads volume table, checks it, recover from errors if needed, |
780 | * or creates it if needed. Returns zero in case of success and a negative | 774 | * or creates it if needed. Returns zero in case of success and a negative |
781 | * error code in case of failure. | 775 | * error code in case of failure. |
782 | */ | 776 | */ |
783 | int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si) | 777 | int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai) |
784 | { | 778 | { |
785 | int i, err; | 779 | int i, err; |
786 | struct ubi_scan_volume *sv; | 780 | struct ubi_ainf_volume *av; |
787 | 781 | ||
788 | empty_vtbl_record.crc = cpu_to_be32(0xf116c36b); | 782 | empty_vtbl_record.crc = cpu_to_be32(0xf116c36b); |
789 | 783 | ||
@@ -798,8 +792,8 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
798 | ubi->vtbl_size = ubi->vtbl_slots * UBI_VTBL_RECORD_SIZE; | 792 | ubi->vtbl_size = ubi->vtbl_slots * UBI_VTBL_RECORD_SIZE; |
799 | ubi->vtbl_size = ALIGN(ubi->vtbl_size, ubi->min_io_size); | 793 | ubi->vtbl_size = ALIGN(ubi->vtbl_size, ubi->min_io_size); |
800 | 794 | ||
801 | sv = ubi_scan_find_sv(si, UBI_LAYOUT_VOLUME_ID); | 795 | av = ubi_find_av(ai, UBI_LAYOUT_VOLUME_ID); |
802 | if (!sv) { | 796 | if (!av) { |
803 | /* | 797 | /* |
804 | * No logical eraseblocks belonging to the layout volume were | 798 | * No logical eraseblocks belonging to the layout volume were |
805 | * found. This could mean that the flash is just empty. In | 799 | * found. This could mean that the flash is just empty. In |
@@ -808,8 +802,8 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
808 | * But if flash is not empty this must be a corruption or the | 802 | * But if flash is not empty this must be a corruption or the |
809 | * MTD device just contains garbage. | 803 | * MTD device just contains garbage. |
810 | */ | 804 | */ |
811 | if (si->is_empty) { | 805 | if (ai->is_empty) { |
812 | ubi->vtbl = create_empty_lvol(ubi, si); | 806 | ubi->vtbl = create_empty_lvol(ubi, ai); |
813 | if (IS_ERR(ubi->vtbl)) | 807 | if (IS_ERR(ubi->vtbl)) |
814 | return PTR_ERR(ubi->vtbl); | 808 | return PTR_ERR(ubi->vtbl); |
815 | } else { | 809 | } else { |
@@ -817,14 +811,14 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
817 | return -EINVAL; | 811 | return -EINVAL; |
818 | } | 812 | } |
819 | } else { | 813 | } else { |
820 | if (sv->leb_count > UBI_LAYOUT_VOLUME_EBS) { | 814 | if (av->leb_count > UBI_LAYOUT_VOLUME_EBS) { |
821 | /* This must not happen with proper UBI images */ | 815 | /* This must not happen with proper UBI images */ |
822 | dbg_err("too many LEBs (%d) in layout volume", | 816 | ubi_err("too many LEBs (%d) in layout volume", |
823 | sv->leb_count); | 817 | av->leb_count); |
824 | return -EINVAL; | 818 | return -EINVAL; |
825 | } | 819 | } |
826 | 820 | ||
827 | ubi->vtbl = process_lvol(ubi, si, sv); | 821 | ubi->vtbl = process_lvol(ubi, ai, av); |
828 | if (IS_ERR(ubi->vtbl)) | 822 | if (IS_ERR(ubi->vtbl)) |
829 | return PTR_ERR(ubi->vtbl); | 823 | return PTR_ERR(ubi->vtbl); |
830 | } | 824 | } |
@@ -835,15 +829,15 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
835 | * The layout volume is OK, initialize the corresponding in-RAM data | 829 | * The layout volume is OK, initialize the corresponding in-RAM data |
836 | * structures. | 830 | * structures. |
837 | */ | 831 | */ |
838 | err = init_volumes(ubi, si, ubi->vtbl); | 832 | err = init_volumes(ubi, ai, ubi->vtbl); |
839 | if (err) | 833 | if (err) |
840 | goto out_free; | 834 | goto out_free; |
841 | 835 | ||
842 | /* | 836 | /* |
843 | * Make sure that the scanning information is consistent to the | 837 | * Make sure that the attaching information is consistent to the |
844 | * information stored in the volume table. | 838 | * information stored in the volume table. |
845 | */ | 839 | */ |
846 | err = check_scanning_info(ubi, si); | 840 | err = check_attaching_info(ubi, ai); |
847 | if (err) | 841 | if (err) |
848 | goto out_free; | 842 | goto out_free; |
849 | 843 | ||
@@ -858,21 +852,17 @@ out_free: | |||
858 | return err; | 852 | return err; |
859 | } | 853 | } |
860 | 854 | ||
861 | #ifdef CONFIG_MTD_UBI_DEBUG | ||
862 | |||
863 | /** | 855 | /** |
864 | * paranoid_vtbl_check - check volume table. | 856 | * self_vtbl_check - check volume table. |
865 | * @ubi: UBI device description object | 857 | * @ubi: UBI device description object |
866 | */ | 858 | */ |
867 | static void paranoid_vtbl_check(const struct ubi_device *ubi) | 859 | static void self_vtbl_check(const struct ubi_device *ubi) |
868 | { | 860 | { |
869 | if (!ubi->dbg->chk_gen) | 861 | if (!ubi->dbg->chk_gen) |
870 | return; | 862 | return; |
871 | 863 | ||
872 | if (vtbl_check(ubi, ubi->vtbl)) { | 864 | if (vtbl_check(ubi, ubi->vtbl)) { |
873 | ubi_err("paranoid check failed"); | 865 | ubi_err("self-check failed"); |
874 | BUG(); | 866 | BUG(); |
875 | } | 867 | } |
876 | } | 868 | } |
877 | |||
878 | #endif /* CONFIG_MTD_UBI_DEBUG */ | ||
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index 7c1a9bf8ac86..9df100a4ec38 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c | |||
@@ -41,12 +41,6 @@ | |||
41 | * physical eraseblocks with low erase counter to free physical eraseblocks | 41 | * physical eraseblocks with low erase counter to free physical eraseblocks |
42 | * with high erase counter. | 42 | * with high erase counter. |
43 | * | 43 | * |
44 | * The 'ubi_wl_get_peb()' function accepts data type hints which help to pick | ||
45 | * an "optimal" physical eraseblock. For example, when it is known that the | ||
46 | * physical eraseblock will be "put" soon because it contains short-term data, | ||
47 | * the WL sub-system may pick a free physical eraseblock with low erase | ||
48 | * counter, and so forth. | ||
49 | * | ||
50 | * If the WL sub-system fails to erase a physical eraseblock, it marks it as | 44 | * If the WL sub-system fails to erase a physical eraseblock, it marks it as |
51 | * bad. | 45 | * bad. |
52 | * | 46 | * |
@@ -70,8 +64,7 @@ | |||
70 | * to the user; instead, we first want to let users fill them up with data; | 64 | * to the user; instead, we first want to let users fill them up with data; |
71 | * | 65 | * |
72 | * o there is a chance that the user will put the physical eraseblock very | 66 | * o there is a chance that the user will put the physical eraseblock very |
73 | * soon, so it makes sense not to move it for some time, but wait; this is | 67 | * soon, so it makes sense not to move it for some time, but wait. |
74 | * especially important in case of "short term" physical eraseblocks. | ||
75 | * | 68 | * |
76 | * Physical eraseblocks stay protected only for limited time. But the "time" is | 69 | * Physical eraseblocks stay protected only for limited time. But the "time" is |
77 | * measured in erase cycles in this case. This is implemented with help of the | 70 | * measured in erase cycles in this case. This is implemented with help of the |
@@ -147,6 +140,8 @@ | |||
147 | * @list: a link in the list of pending works | 140 | * @list: a link in the list of pending works |
148 | * @func: worker function | 141 | * @func: worker function |
149 | * @e: physical eraseblock to erase | 142 | * @e: physical eraseblock to erase |
143 | * @vol_id: the volume ID on which this erasure is being performed | ||
144 | * @lnum: the logical eraseblock number | ||
150 | * @torture: if the physical eraseblock has to be tortured | 145 | * @torture: if the physical eraseblock has to be tortured |
151 | * | 146 | * |
152 | * The @func pointer points to the worker function. If the @cancel argument is | 147 | * The @func pointer points to the worker function. If the @cancel argument is |
@@ -159,21 +154,16 @@ struct ubi_work { | |||
159 | int (*func)(struct ubi_device *ubi, struct ubi_work *wrk, int cancel); | 154 | int (*func)(struct ubi_device *ubi, struct ubi_work *wrk, int cancel); |
160 | /* The below fields are only relevant to erasure works */ | 155 | /* The below fields are only relevant to erasure works */ |
161 | struct ubi_wl_entry *e; | 156 | struct ubi_wl_entry *e; |
157 | int vol_id; | ||
158 | int lnum; | ||
162 | int torture; | 159 | int torture; |
163 | }; | 160 | }; |
164 | 161 | ||
165 | #ifdef CONFIG_MTD_UBI_DEBUG | 162 | static int self_check_ec(struct ubi_device *ubi, int pnum, int ec); |
166 | static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec); | 163 | static int self_check_in_wl_tree(const struct ubi_device *ubi, |
167 | static int paranoid_check_in_wl_tree(const struct ubi_device *ubi, | 164 | struct ubi_wl_entry *e, struct rb_root *root); |
168 | struct ubi_wl_entry *e, | 165 | static int self_check_in_pq(const struct ubi_device *ubi, |
169 | struct rb_root *root); | 166 | struct ubi_wl_entry *e); |
170 | static int paranoid_check_in_pq(const struct ubi_device *ubi, | ||
171 | struct ubi_wl_entry *e); | ||
172 | #else | ||
173 | #define paranoid_check_ec(ubi, pnum, ec) 0 | ||
174 | #define paranoid_check_in_wl_tree(ubi, e, root) | ||
175 | #define paranoid_check_in_pq(ubi, e) 0 | ||
176 | #endif | ||
177 | 167 | ||
178 | /** | 168 | /** |
179 | * wl_tree_add - add a wear-leveling entry to a WL RB-tree. | 169 | * wl_tree_add - add a wear-leveling entry to a WL RB-tree. |
@@ -383,19 +373,15 @@ static struct ubi_wl_entry *find_wl_entry(struct rb_root *root, int diff) | |||
383 | /** | 373 | /** |
384 | * ubi_wl_get_peb - get a physical eraseblock. | 374 | * ubi_wl_get_peb - get a physical eraseblock. |
385 | * @ubi: UBI device description object | 375 | * @ubi: UBI device description object |
386 | * @dtype: type of data which will be stored in this physical eraseblock | ||
387 | * | 376 | * |
388 | * This function returns a physical eraseblock in case of success and a | 377 | * This function returns a physical eraseblock in case of success and a |
389 | * negative error code in case of failure. Might sleep. | 378 | * negative error code in case of failure. Might sleep. |
390 | */ | 379 | */ |
391 | int ubi_wl_get_peb(struct ubi_device *ubi, int dtype) | 380 | int ubi_wl_get_peb(struct ubi_device *ubi) |
392 | { | 381 | { |
393 | int err; | 382 | int err; |
394 | struct ubi_wl_entry *e, *first, *last; | 383 | struct ubi_wl_entry *e, *first, *last; |
395 | 384 | ||
396 | ubi_assert(dtype == UBI_LONGTERM || dtype == UBI_SHORTTERM || | ||
397 | dtype == UBI_UNKNOWN); | ||
398 | |||
399 | retry: | 385 | retry: |
400 | spin_lock(&ubi->wl_lock); | 386 | spin_lock(&ubi->wl_lock); |
401 | if (!ubi->free.rb_node) { | 387 | if (!ubi->free.rb_node) { |
@@ -413,45 +399,15 @@ retry: | |||
413 | goto retry; | 399 | goto retry; |
414 | } | 400 | } |
415 | 401 | ||
416 | switch (dtype) { | 402 | first = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, u.rb); |
417 | case UBI_LONGTERM: | 403 | last = rb_entry(rb_last(&ubi->free), struct ubi_wl_entry, u.rb); |
418 | /* | 404 | |
419 | * For long term data we pick a physical eraseblock with high | 405 | if (last->ec - first->ec < WL_FREE_MAX_DIFF) |
420 | * erase counter. But the highest erase counter we can pick is | 406 | e = rb_entry(ubi->free.rb_node, struct ubi_wl_entry, u.rb); |
421 | * bounded by the the lowest erase counter plus | 407 | else |
422 | * %WL_FREE_MAX_DIFF. | 408 | e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF/2); |
423 | */ | ||
424 | e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF); | ||
425 | break; | ||
426 | case UBI_UNKNOWN: | ||
427 | /* | ||
428 | * For unknown data we pick a physical eraseblock with medium | ||
429 | * erase counter. But we by no means can pick a physical | ||
430 | * eraseblock with erase counter greater or equivalent than the | ||
431 | * lowest erase counter plus %WL_FREE_MAX_DIFF/2. | ||
432 | */ | ||
433 | first = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, | ||
434 | u.rb); | ||
435 | last = rb_entry(rb_last(&ubi->free), struct ubi_wl_entry, u.rb); | ||
436 | |||
437 | if (last->ec - first->ec < WL_FREE_MAX_DIFF) | ||
438 | e = rb_entry(ubi->free.rb_node, | ||
439 | struct ubi_wl_entry, u.rb); | ||
440 | else | ||
441 | e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF/2); | ||
442 | break; | ||
443 | case UBI_SHORTTERM: | ||
444 | /* | ||
445 | * For short term data we pick a physical eraseblock with the | ||
446 | * lowest erase counter as we expect it will be erased soon. | ||
447 | */ | ||
448 | e = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, u.rb); | ||
449 | break; | ||
450 | default: | ||
451 | BUG(); | ||
452 | } | ||
453 | 409 | ||
454 | paranoid_check_in_wl_tree(ubi, e, &ubi->free); | 410 | self_check_in_wl_tree(ubi, e, &ubi->free); |
455 | 411 | ||
456 | /* | 412 | /* |
457 | * Move the physical eraseblock to the protection queue where it will | 413 | * Move the physical eraseblock to the protection queue where it will |
@@ -462,8 +418,8 @@ retry: | |||
462 | prot_queue_add(ubi, e); | 418 | prot_queue_add(ubi, e); |
463 | spin_unlock(&ubi->wl_lock); | 419 | spin_unlock(&ubi->wl_lock); |
464 | 420 | ||
465 | err = ubi_dbg_check_all_ff(ubi, e->pnum, ubi->vid_hdr_aloffset, | 421 | err = ubi_self_check_all_ff(ubi, e->pnum, ubi->vid_hdr_aloffset, |
466 | ubi->peb_size - ubi->vid_hdr_aloffset); | 422 | ubi->peb_size - ubi->vid_hdr_aloffset); |
467 | if (err) { | 423 | if (err) { |
468 | ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum); | 424 | ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum); |
469 | return err; | 425 | return err; |
@@ -488,7 +444,7 @@ static int prot_queue_del(struct ubi_device *ubi, int pnum) | |||
488 | if (!e) | 444 | if (!e) |
489 | return -ENODEV; | 445 | return -ENODEV; |
490 | 446 | ||
491 | if (paranoid_check_in_pq(ubi, e)) | 447 | if (self_check_in_pq(ubi, e)) |
492 | return -ENODEV; | 448 | return -ENODEV; |
493 | 449 | ||
494 | list_del(&e->u.list); | 450 | list_del(&e->u.list); |
@@ -514,7 +470,7 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, | |||
514 | 470 | ||
515 | dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec); | 471 | dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec); |
516 | 472 | ||
517 | err = paranoid_check_ec(ubi, e->pnum, e->ec); | 473 | err = self_check_ec(ubi, e->pnum, e->ec); |
518 | if (err) | 474 | if (err) |
519 | return -EINVAL; | 475 | return -EINVAL; |
520 | 476 | ||
@@ -627,13 +583,15 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk, | |||
627 | * schedule_erase - schedule an erase work. | 583 | * schedule_erase - schedule an erase work. |
628 | * @ubi: UBI device description object | 584 | * @ubi: UBI device description object |
629 | * @e: the WL entry of the physical eraseblock to erase | 585 | * @e: the WL entry of the physical eraseblock to erase |
586 | * @vol_id: the volume ID that last used this PEB | ||
587 | * @lnum: the last used logical eraseblock number for the PEB | ||
630 | * @torture: if the physical eraseblock has to be tortured | 588 | * @torture: if the physical eraseblock has to be tortured |
631 | * | 589 | * |
632 | * This function returns zero in case of success and a %-ENOMEM in case of | 590 | * This function returns zero in case of success and a %-ENOMEM in case of |
633 | * failure. | 591 | * failure. |
634 | */ | 592 | */ |
635 | static int schedule_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, | 593 | static int schedule_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, |
636 | int torture) | 594 | int vol_id, int lnum, int torture) |
637 | { | 595 | { |
638 | struct ubi_work *wl_wrk; | 596 | struct ubi_work *wl_wrk; |
639 | 597 | ||
@@ -646,6 +604,8 @@ static int schedule_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, | |||
646 | 604 | ||
647 | wl_wrk->func = &erase_worker; | 605 | wl_wrk->func = &erase_worker; |
648 | wl_wrk->e = e; | 606 | wl_wrk->e = e; |
607 | wl_wrk->vol_id = vol_id; | ||
608 | wl_wrk->lnum = lnum; | ||
649 | wl_wrk->torture = torture; | 609 | wl_wrk->torture = torture; |
650 | 610 | ||
651 | schedule_ubi_work(ubi, wl_wrk); | 611 | schedule_ubi_work(ubi, wl_wrk); |
@@ -714,7 +674,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, | |||
714 | e1->ec, e2->ec); | 674 | e1->ec, e2->ec); |
715 | goto out_cancel; | 675 | goto out_cancel; |
716 | } | 676 | } |
717 | paranoid_check_in_wl_tree(ubi, e1, &ubi->used); | 677 | self_check_in_wl_tree(ubi, e1, &ubi->used); |
718 | rb_erase(&e1->u.rb, &ubi->used); | 678 | rb_erase(&e1->u.rb, &ubi->used); |
719 | dbg_wl("move PEB %d EC %d to PEB %d EC %d", | 679 | dbg_wl("move PEB %d EC %d to PEB %d EC %d", |
720 | e1->pnum, e1->ec, e2->pnum, e2->ec); | 680 | e1->pnum, e1->ec, e2->pnum, e2->ec); |
@@ -723,12 +683,12 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, | |||
723 | scrubbing = 1; | 683 | scrubbing = 1; |
724 | e1 = rb_entry(rb_first(&ubi->scrub), struct ubi_wl_entry, u.rb); | 684 | e1 = rb_entry(rb_first(&ubi->scrub), struct ubi_wl_entry, u.rb); |
725 | e2 = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF); | 685 | e2 = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF); |
726 | paranoid_check_in_wl_tree(ubi, e1, &ubi->scrub); | 686 | self_check_in_wl_tree(ubi, e1, &ubi->scrub); |
727 | rb_erase(&e1->u.rb, &ubi->scrub); | 687 | rb_erase(&e1->u.rb, &ubi->scrub); |
728 | dbg_wl("scrub PEB %d to PEB %d", e1->pnum, e2->pnum); | 688 | dbg_wl("scrub PEB %d to PEB %d", e1->pnum, e2->pnum); |
729 | } | 689 | } |
730 | 690 | ||
731 | paranoid_check_in_wl_tree(ubi, e2, &ubi->free); | 691 | self_check_in_wl_tree(ubi, e2, &ubi->free); |
732 | rb_erase(&e2->u.rb, &ubi->free); | 692 | rb_erase(&e2->u.rb, &ubi->free); |
733 | ubi->move_from = e1; | 693 | ubi->move_from = e1; |
734 | ubi->move_to = e2; | 694 | ubi->move_to = e2; |
@@ -846,7 +806,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, | |||
846 | ubi->move_to_put = ubi->wl_scheduled = 0; | 806 | ubi->move_to_put = ubi->wl_scheduled = 0; |
847 | spin_unlock(&ubi->wl_lock); | 807 | spin_unlock(&ubi->wl_lock); |
848 | 808 | ||
849 | err = schedule_erase(ubi, e1, 0); | 809 | err = schedule_erase(ubi, e1, vol_id, lnum, 0); |
850 | if (err) { | 810 | if (err) { |
851 | kmem_cache_free(ubi_wl_entry_slab, e1); | 811 | kmem_cache_free(ubi_wl_entry_slab, e1); |
852 | if (e2) | 812 | if (e2) |
@@ -861,7 +821,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, | |||
861 | */ | 821 | */ |
862 | dbg_wl("PEB %d (LEB %d:%d) was put meanwhile, erase", | 822 | dbg_wl("PEB %d (LEB %d:%d) was put meanwhile, erase", |
863 | e2->pnum, vol_id, lnum); | 823 | e2->pnum, vol_id, lnum); |
864 | err = schedule_erase(ubi, e2, 0); | 824 | err = schedule_erase(ubi, e2, vol_id, lnum, 0); |
865 | if (err) { | 825 | if (err) { |
866 | kmem_cache_free(ubi_wl_entry_slab, e2); | 826 | kmem_cache_free(ubi_wl_entry_slab, e2); |
867 | goto out_ro; | 827 | goto out_ro; |
@@ -900,7 +860,7 @@ out_not_moved: | |||
900 | spin_unlock(&ubi->wl_lock); | 860 | spin_unlock(&ubi->wl_lock); |
901 | 861 | ||
902 | ubi_free_vid_hdr(ubi, vid_hdr); | 862 | ubi_free_vid_hdr(ubi, vid_hdr); |
903 | err = schedule_erase(ubi, e2, torture); | 863 | err = schedule_erase(ubi, e2, vol_id, lnum, torture); |
904 | if (err) { | 864 | if (err) { |
905 | kmem_cache_free(ubi_wl_entry_slab, e2); | 865 | kmem_cache_free(ubi_wl_entry_slab, e2); |
906 | goto out_ro; | 866 | goto out_ro; |
@@ -1019,6 +979,8 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk, | |||
1019 | { | 979 | { |
1020 | struct ubi_wl_entry *e = wl_wrk->e; | 980 | struct ubi_wl_entry *e = wl_wrk->e; |
1021 | int pnum = e->pnum, err, need; | 981 | int pnum = e->pnum, err, need; |
982 | int vol_id = wl_wrk->vol_id; | ||
983 | int lnum = wl_wrk->lnum; | ||
1022 | 984 | ||
1023 | if (cancel) { | 985 | if (cancel) { |
1024 | dbg_wl("cancel erasure of PEB %d EC %d", pnum, e->ec); | 986 | dbg_wl("cancel erasure of PEB %d EC %d", pnum, e->ec); |
@@ -1027,7 +989,8 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk, | |||
1027 | return 0; | 989 | return 0; |
1028 | } | 990 | } |
1029 | 991 | ||
1030 | dbg_wl("erase PEB %d EC %d", pnum, e->ec); | 992 | dbg_wl("erase PEB %d EC %d LEB %d:%d", |
993 | pnum, e->ec, wl_wrk->vol_id, wl_wrk->lnum); | ||
1031 | 994 | ||
1032 | err = sync_erase(ubi, e, wl_wrk->torture); | 995 | err = sync_erase(ubi, e, wl_wrk->torture); |
1033 | if (!err) { | 996 | if (!err) { |
@@ -1057,7 +1020,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk, | |||
1057 | int err1; | 1020 | int err1; |
1058 | 1021 | ||
1059 | /* Re-schedule the LEB for erasure */ | 1022 | /* Re-schedule the LEB for erasure */ |
1060 | err1 = schedule_erase(ubi, e, 0); | 1023 | err1 = schedule_erase(ubi, e, vol_id, lnum, 0); |
1061 | if (err1) { | 1024 | if (err1) { |
1062 | err = err1; | 1025 | err = err1; |
1063 | goto out_ro; | 1026 | goto out_ro; |
@@ -1125,6 +1088,8 @@ out_ro: | |||
1125 | /** | 1088 | /** |
1126 | * ubi_wl_put_peb - return a PEB to the wear-leveling sub-system. | 1089 | * ubi_wl_put_peb - return a PEB to the wear-leveling sub-system. |
1127 | * @ubi: UBI device description object | 1090 | * @ubi: UBI device description object |
1091 | * @vol_id: the volume ID that last used this PEB | ||
1092 | * @lnum: the last used logical eraseblock number for the PEB | ||
1128 | * @pnum: physical eraseblock to return | 1093 | * @pnum: physical eraseblock to return |
1129 | * @torture: if this physical eraseblock has to be tortured | 1094 | * @torture: if this physical eraseblock has to be tortured |
1130 | * | 1095 | * |
@@ -1133,7 +1098,8 @@ out_ro: | |||
1133 | * occurred to this @pnum and it has to be tested. This function returns zero | 1098 | * occurred to this @pnum and it has to be tested. This function returns zero |
1134 | * in case of success, and a negative error code in case of failure. | 1099 | * in case of success, and a negative error code in case of failure. |
1135 | */ | 1100 | */ |
1136 | int ubi_wl_put_peb(struct ubi_device *ubi, int pnum, int torture) | 1101 | int ubi_wl_put_peb(struct ubi_device *ubi, int vol_id, int lnum, |
1102 | int pnum, int torture) | ||
1137 | { | 1103 | { |
1138 | int err; | 1104 | int err; |
1139 | struct ubi_wl_entry *e; | 1105 | struct ubi_wl_entry *e; |
@@ -1175,13 +1141,13 @@ retry: | |||
1175 | return 0; | 1141 | return 0; |
1176 | } else { | 1142 | } else { |
1177 | if (in_wl_tree(e, &ubi->used)) { | 1143 | if (in_wl_tree(e, &ubi->used)) { |
1178 | paranoid_check_in_wl_tree(ubi, e, &ubi->used); | 1144 | self_check_in_wl_tree(ubi, e, &ubi->used); |
1179 | rb_erase(&e->u.rb, &ubi->used); | 1145 | rb_erase(&e->u.rb, &ubi->used); |
1180 | } else if (in_wl_tree(e, &ubi->scrub)) { | 1146 | } else if (in_wl_tree(e, &ubi->scrub)) { |
1181 | paranoid_check_in_wl_tree(ubi, e, &ubi->scrub); | 1147 | self_check_in_wl_tree(ubi, e, &ubi->scrub); |
1182 | rb_erase(&e->u.rb, &ubi->scrub); | 1148 | rb_erase(&e->u.rb, &ubi->scrub); |
1183 | } else if (in_wl_tree(e, &ubi->erroneous)) { | 1149 | } else if (in_wl_tree(e, &ubi->erroneous)) { |
1184 | paranoid_check_in_wl_tree(ubi, e, &ubi->erroneous); | 1150 | self_check_in_wl_tree(ubi, e, &ubi->erroneous); |
1185 | rb_erase(&e->u.rb, &ubi->erroneous); | 1151 | rb_erase(&e->u.rb, &ubi->erroneous); |
1186 | ubi->erroneous_peb_count -= 1; | 1152 | ubi->erroneous_peb_count -= 1; |
1187 | ubi_assert(ubi->erroneous_peb_count >= 0); | 1153 | ubi_assert(ubi->erroneous_peb_count >= 0); |
@@ -1199,7 +1165,7 @@ retry: | |||
1199 | } | 1165 | } |
1200 | spin_unlock(&ubi->wl_lock); | 1166 | spin_unlock(&ubi->wl_lock); |
1201 | 1167 | ||
1202 | err = schedule_erase(ubi, e, torture); | 1168 | err = schedule_erase(ubi, e, vol_id, lnum, torture); |
1203 | if (err) { | 1169 | if (err) { |
1204 | spin_lock(&ubi->wl_lock); | 1170 | spin_lock(&ubi->wl_lock); |
1205 | wl_tree_add(e, &ubi->used); | 1171 | wl_tree_add(e, &ubi->used); |
@@ -1248,7 +1214,7 @@ retry: | |||
1248 | } | 1214 | } |
1249 | 1215 | ||
1250 | if (in_wl_tree(e, &ubi->used)) { | 1216 | if (in_wl_tree(e, &ubi->used)) { |
1251 | paranoid_check_in_wl_tree(ubi, e, &ubi->used); | 1217 | self_check_in_wl_tree(ubi, e, &ubi->used); |
1252 | rb_erase(&e->u.rb, &ubi->used); | 1218 | rb_erase(&e->u.rb, &ubi->used); |
1253 | } else { | 1219 | } else { |
1254 | int err; | 1220 | int err; |
@@ -1275,44 +1241,55 @@ retry: | |||
1275 | /** | 1241 | /** |
1276 | * ubi_wl_flush - flush all pending works. | 1242 | * ubi_wl_flush - flush all pending works. |
1277 | * @ubi: UBI device description object | 1243 | * @ubi: UBI device description object |
1244 | * @vol_id: the volume id to flush for | ||
1245 | * @lnum: the logical eraseblock number to flush for | ||
1278 | * | 1246 | * |
1279 | * This function returns zero in case of success and a negative error code in | 1247 | * This function executes all pending works for a particular volume id / |
1280 | * case of failure. | 1248 | * logical eraseblock number pair. If either value is set to %UBI_ALL, then it |
1249 | * acts as a wildcard for all of the corresponding volume numbers or logical | ||
1250 | * eraseblock numbers. It returns zero in case of success and a negative error | ||
1251 | * code in case of failure. | ||
1281 | */ | 1252 | */ |
1282 | int ubi_wl_flush(struct ubi_device *ubi) | 1253 | int ubi_wl_flush(struct ubi_device *ubi, int vol_id, int lnum) |
1283 | { | 1254 | { |
1284 | int err; | 1255 | int err = 0; |
1256 | int found = 1; | ||
1285 | 1257 | ||
1286 | /* | 1258 | /* |
1287 | * Erase while the pending works queue is not empty, but not more than | 1259 | * Erase while the pending works queue is not empty, but not more than |
1288 | * the number of currently pending works. | 1260 | * the number of currently pending works. |
1289 | */ | 1261 | */ |
1290 | dbg_wl("flush (%d pending works)", ubi->works_count); | 1262 | dbg_wl("flush pending work for LEB %d:%d (%d pending works)", |
1291 | while (ubi->works_count) { | 1263 | vol_id, lnum, ubi->works_count); |
1292 | err = do_work(ubi); | ||
1293 | if (err) | ||
1294 | return err; | ||
1295 | } | ||
1296 | 1264 | ||
1297 | /* | ||
1298 | * Make sure all the works which have been done in parallel are | ||
1299 | * finished. | ||
1300 | */ | ||
1301 | down_write(&ubi->work_sem); | 1265 | down_write(&ubi->work_sem); |
1302 | up_write(&ubi->work_sem); | 1266 | while (found) { |
1267 | struct ubi_work *wrk; | ||
1268 | found = 0; | ||
1303 | 1269 | ||
1304 | /* | 1270 | spin_lock(&ubi->wl_lock); |
1305 | * And in case last was the WL worker and it canceled the LEB | 1271 | list_for_each_entry(wrk, &ubi->works, list) { |
1306 | * movement, flush again. | 1272 | if ((vol_id == UBI_ALL || wrk->vol_id == vol_id) && |
1307 | */ | 1273 | (lnum == UBI_ALL || wrk->lnum == lnum)) { |
1308 | while (ubi->works_count) { | 1274 | list_del(&wrk->list); |
1309 | dbg_wl("flush more (%d pending works)", ubi->works_count); | 1275 | ubi->works_count -= 1; |
1310 | err = do_work(ubi); | 1276 | ubi_assert(ubi->works_count >= 0); |
1311 | if (err) | 1277 | spin_unlock(&ubi->wl_lock); |
1312 | return err; | 1278 | |
1279 | err = wrk->func(ubi, wrk, 0); | ||
1280 | if (err) | ||
1281 | goto out; | ||
1282 | spin_lock(&ubi->wl_lock); | ||
1283 | found = 1; | ||
1284 | break; | ||
1285 | } | ||
1286 | } | ||
1287 | spin_unlock(&ubi->wl_lock); | ||
1313 | } | 1288 | } |
1314 | 1289 | ||
1315 | return 0; | 1290 | out: |
1291 | up_write(&ubi->work_sem); | ||
1292 | return err; | ||
1316 | } | 1293 | } |
1317 | 1294 | ||
1318 | /** | 1295 | /** |
@@ -1421,26 +1398,26 @@ static void cancel_pending(struct ubi_device *ubi) | |||
1421 | } | 1398 | } |
1422 | 1399 | ||
1423 | /** | 1400 | /** |
1424 | * ubi_wl_init_scan - initialize the WL sub-system using scanning information. | 1401 | * ubi_wl_init - initialize the WL sub-system using attaching information. |
1425 | * @ubi: UBI device description object | 1402 | * @ubi: UBI device description object |
1426 | * @si: scanning information | 1403 | * @ai: attaching information |
1427 | * | 1404 | * |
1428 | * This function returns zero in case of success, and a negative error code in | 1405 | * This function returns zero in case of success, and a negative error code in |
1429 | * case of failure. | 1406 | * case of failure. |
1430 | */ | 1407 | */ |
1431 | int ubi_wl_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | 1408 | int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai) |
1432 | { | 1409 | { |
1433 | int err, i; | 1410 | int err, i; |
1434 | struct rb_node *rb1, *rb2; | 1411 | struct rb_node *rb1, *rb2; |
1435 | struct ubi_scan_volume *sv; | 1412 | struct ubi_ainf_volume *av; |
1436 | struct ubi_scan_leb *seb, *tmp; | 1413 | struct ubi_ainf_peb *aeb, *tmp; |
1437 | struct ubi_wl_entry *e; | 1414 | struct ubi_wl_entry *e; |
1438 | 1415 | ||
1439 | ubi->used = ubi->erroneous = ubi->free = ubi->scrub = RB_ROOT; | 1416 | ubi->used = ubi->erroneous = ubi->free = ubi->scrub = RB_ROOT; |
1440 | spin_lock_init(&ubi->wl_lock); | 1417 | spin_lock_init(&ubi->wl_lock); |
1441 | mutex_init(&ubi->move_mutex); | 1418 | mutex_init(&ubi->move_mutex); |
1442 | init_rwsem(&ubi->work_sem); | 1419 | init_rwsem(&ubi->work_sem); |
1443 | ubi->max_ec = si->max_ec; | 1420 | ubi->max_ec = ai->max_ec; |
1444 | INIT_LIST_HEAD(&ubi->works); | 1421 | INIT_LIST_HEAD(&ubi->works); |
1445 | 1422 | ||
1446 | sprintf(ubi->bgt_name, UBI_BGT_NAME_PATTERN, ubi->ubi_num); | 1423 | sprintf(ubi->bgt_name, UBI_BGT_NAME_PATTERN, ubi->ubi_num); |
@@ -1454,48 +1431,48 @@ int ubi_wl_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1454 | INIT_LIST_HEAD(&ubi->pq[i]); | 1431 | INIT_LIST_HEAD(&ubi->pq[i]); |
1455 | ubi->pq_head = 0; | 1432 | ubi->pq_head = 0; |
1456 | 1433 | ||
1457 | list_for_each_entry_safe(seb, tmp, &si->erase, u.list) { | 1434 | list_for_each_entry_safe(aeb, tmp, &ai->erase, u.list) { |
1458 | cond_resched(); | 1435 | cond_resched(); |
1459 | 1436 | ||
1460 | e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL); | 1437 | e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL); |
1461 | if (!e) | 1438 | if (!e) |
1462 | goto out_free; | 1439 | goto out_free; |
1463 | 1440 | ||
1464 | e->pnum = seb->pnum; | 1441 | e->pnum = aeb->pnum; |
1465 | e->ec = seb->ec; | 1442 | e->ec = aeb->ec; |
1466 | ubi->lookuptbl[e->pnum] = e; | 1443 | ubi->lookuptbl[e->pnum] = e; |
1467 | if (schedule_erase(ubi, e, 0)) { | 1444 | if (schedule_erase(ubi, e, aeb->vol_id, aeb->lnum, 0)) { |
1468 | kmem_cache_free(ubi_wl_entry_slab, e); | 1445 | kmem_cache_free(ubi_wl_entry_slab, e); |
1469 | goto out_free; | 1446 | goto out_free; |
1470 | } | 1447 | } |
1471 | } | 1448 | } |
1472 | 1449 | ||
1473 | list_for_each_entry(seb, &si->free, u.list) { | 1450 | list_for_each_entry(aeb, &ai->free, u.list) { |
1474 | cond_resched(); | 1451 | cond_resched(); |
1475 | 1452 | ||
1476 | e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL); | 1453 | e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL); |
1477 | if (!e) | 1454 | if (!e) |
1478 | goto out_free; | 1455 | goto out_free; |
1479 | 1456 | ||
1480 | e->pnum = seb->pnum; | 1457 | e->pnum = aeb->pnum; |
1481 | e->ec = seb->ec; | 1458 | e->ec = aeb->ec; |
1482 | ubi_assert(e->ec >= 0); | 1459 | ubi_assert(e->ec >= 0); |
1483 | wl_tree_add(e, &ubi->free); | 1460 | wl_tree_add(e, &ubi->free); |
1484 | ubi->lookuptbl[e->pnum] = e; | 1461 | ubi->lookuptbl[e->pnum] = e; |
1485 | } | 1462 | } |
1486 | 1463 | ||
1487 | ubi_rb_for_each_entry(rb1, sv, &si->volumes, rb) { | 1464 | ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) { |
1488 | ubi_rb_for_each_entry(rb2, seb, &sv->root, u.rb) { | 1465 | ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) { |
1489 | cond_resched(); | 1466 | cond_resched(); |
1490 | 1467 | ||
1491 | e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL); | 1468 | e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL); |
1492 | if (!e) | 1469 | if (!e) |
1493 | goto out_free; | 1470 | goto out_free; |
1494 | 1471 | ||
1495 | e->pnum = seb->pnum; | 1472 | e->pnum = aeb->pnum; |
1496 | e->ec = seb->ec; | 1473 | e->ec = aeb->ec; |
1497 | ubi->lookuptbl[e->pnum] = e; | 1474 | ubi->lookuptbl[e->pnum] = e; |
1498 | if (!seb->scrub) { | 1475 | if (!aeb->scrub) { |
1499 | dbg_wl("add PEB %d EC %d to the used tree", | 1476 | dbg_wl("add PEB %d EC %d to the used tree", |
1500 | e->pnum, e->ec); | 1477 | e->pnum, e->ec); |
1501 | wl_tree_add(e, &ubi->used); | 1478 | wl_tree_add(e, &ubi->used); |
@@ -1567,10 +1544,8 @@ void ubi_wl_close(struct ubi_device *ubi) | |||
1567 | kfree(ubi->lookuptbl); | 1544 | kfree(ubi->lookuptbl); |
1568 | } | 1545 | } |
1569 | 1546 | ||
1570 | #ifdef CONFIG_MTD_UBI_DEBUG | ||
1571 | |||
1572 | /** | 1547 | /** |
1573 | * paranoid_check_ec - make sure that the erase counter of a PEB is correct. | 1548 | * self_check_ec - make sure that the erase counter of a PEB is correct. |
1574 | * @ubi: UBI device description object | 1549 | * @ubi: UBI device description object |
1575 | * @pnum: the physical eraseblock number to check | 1550 | * @pnum: the physical eraseblock number to check |
1576 | * @ec: the erase counter to check | 1551 | * @ec: the erase counter to check |
@@ -1579,7 +1554,7 @@ void ubi_wl_close(struct ubi_device *ubi) | |||
1579 | * is equivalent to @ec, and a negative error code if not or if an error | 1554 | * is equivalent to @ec, and a negative error code if not or if an error |
1580 | * occurred. | 1555 | * occurred. |
1581 | */ | 1556 | */ |
1582 | static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec) | 1557 | static int self_check_ec(struct ubi_device *ubi, int pnum, int ec) |
1583 | { | 1558 | { |
1584 | int err; | 1559 | int err; |
1585 | long long read_ec; | 1560 | long long read_ec; |
@@ -1601,9 +1576,9 @@ static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec) | |||
1601 | 1576 | ||
1602 | read_ec = be64_to_cpu(ec_hdr->ec); | 1577 | read_ec = be64_to_cpu(ec_hdr->ec); |
1603 | if (ec != read_ec) { | 1578 | if (ec != read_ec) { |
1604 | ubi_err("paranoid check failed for PEB %d", pnum); | 1579 | ubi_err("self-check failed for PEB %d", pnum); |
1605 | ubi_err("read EC is %lld, should be %d", read_ec, ec); | 1580 | ubi_err("read EC is %lld, should be %d", read_ec, ec); |
1606 | ubi_dbg_dump_stack(); | 1581 | dump_stack(); |
1607 | err = 1; | 1582 | err = 1; |
1608 | } else | 1583 | } else |
1609 | err = 0; | 1584 | err = 0; |
@@ -1614,7 +1589,7 @@ out_free: | |||
1614 | } | 1589 | } |
1615 | 1590 | ||
1616 | /** | 1591 | /** |
1617 | * paranoid_check_in_wl_tree - check that wear-leveling entry is in WL RB-tree. | 1592 | * self_check_in_wl_tree - check that wear-leveling entry is in WL RB-tree. |
1618 | * @ubi: UBI device description object | 1593 | * @ubi: UBI device description object |
1619 | * @e: the wear-leveling entry to check | 1594 | * @e: the wear-leveling entry to check |
1620 | * @root: the root of the tree | 1595 | * @root: the root of the tree |
@@ -1622,9 +1597,8 @@ out_free: | |||
1622 | * This function returns zero if @e is in the @root RB-tree and %-EINVAL if it | 1597 | * This function returns zero if @e is in the @root RB-tree and %-EINVAL if it |
1623 | * is not. | 1598 | * is not. |
1624 | */ | 1599 | */ |
1625 | static int paranoid_check_in_wl_tree(const struct ubi_device *ubi, | 1600 | static int self_check_in_wl_tree(const struct ubi_device *ubi, |
1626 | struct ubi_wl_entry *e, | 1601 | struct ubi_wl_entry *e, struct rb_root *root) |
1627 | struct rb_root *root) | ||
1628 | { | 1602 | { |
1629 | if (!ubi->dbg->chk_gen) | 1603 | if (!ubi->dbg->chk_gen) |
1630 | return 0; | 1604 | return 0; |
@@ -1632,22 +1606,22 @@ static int paranoid_check_in_wl_tree(const struct ubi_device *ubi, | |||
1632 | if (in_wl_tree(e, root)) | 1606 | if (in_wl_tree(e, root)) |
1633 | return 0; | 1607 | return 0; |
1634 | 1608 | ||
1635 | ubi_err("paranoid check failed for PEB %d, EC %d, RB-tree %p ", | 1609 | ubi_err("self-check failed for PEB %d, EC %d, RB-tree %p ", |
1636 | e->pnum, e->ec, root); | 1610 | e->pnum, e->ec, root); |
1637 | ubi_dbg_dump_stack(); | 1611 | dump_stack(); |
1638 | return -EINVAL; | 1612 | return -EINVAL; |
1639 | } | 1613 | } |
1640 | 1614 | ||
1641 | /** | 1615 | /** |
1642 | * paranoid_check_in_pq - check if wear-leveling entry is in the protection | 1616 | * self_check_in_pq - check if wear-leveling entry is in the protection |
1643 | * queue. | 1617 | * queue. |
1644 | * @ubi: UBI device description object | 1618 | * @ubi: UBI device description object |
1645 | * @e: the wear-leveling entry to check | 1619 | * @e: the wear-leveling entry to check |
1646 | * | 1620 | * |
1647 | * This function returns zero if @e is in @ubi->pq and %-EINVAL if it is not. | 1621 | * This function returns zero if @e is in @ubi->pq and %-EINVAL if it is not. |
1648 | */ | 1622 | */ |
1649 | static int paranoid_check_in_pq(const struct ubi_device *ubi, | 1623 | static int self_check_in_pq(const struct ubi_device *ubi, |
1650 | struct ubi_wl_entry *e) | 1624 | struct ubi_wl_entry *e) |
1651 | { | 1625 | { |
1652 | struct ubi_wl_entry *p; | 1626 | struct ubi_wl_entry *p; |
1653 | int i; | 1627 | int i; |
@@ -1660,10 +1634,8 @@ static int paranoid_check_in_pq(const struct ubi_device *ubi, | |||
1660 | if (p == e) | 1634 | if (p == e) |
1661 | return 0; | 1635 | return 0; |
1662 | 1636 | ||
1663 | ubi_err("paranoid check failed for PEB %d, EC %d, Protect queue", | 1637 | ubi_err("self-check failed for PEB %d, EC %d, Protect queue", |
1664 | e->pnum, e->ec); | 1638 | e->pnum, e->ec); |
1665 | ubi_dbg_dump_stack(); | 1639 | dump_stack(); |
1666 | return -EINVAL; | 1640 | return -EINVAL; |
1667 | } | 1641 | } |
1668 | |||
1669 | #endif /* CONFIG_MTD_UBI_DEBUG */ | ||
diff --git a/fs/ubifs/Kconfig b/fs/ubifs/Kconfig index f8b0160da2da..ba66d508006a 100644 --- a/fs/ubifs/Kconfig +++ b/fs/ubifs/Kconfig | |||
@@ -11,12 +11,6 @@ config UBIFS_FS | |||
11 | help | 11 | help |
12 | UBIFS is a file system for flash devices which works on top of UBI. | 12 | UBIFS is a file system for flash devices which works on top of UBI. |
13 | 13 | ||
14 | config UBIFS_FS_XATTR | ||
15 | bool "Extended attributes support" | ||
16 | depends on UBIFS_FS | ||
17 | help | ||
18 | This option enables support of extended attributes. | ||
19 | |||
20 | config UBIFS_FS_ADVANCED_COMPR | 14 | config UBIFS_FS_ADVANCED_COMPR |
21 | bool "Advanced compression options" | 15 | bool "Advanced compression options" |
22 | depends on UBIFS_FS | 16 | depends on UBIFS_FS |
@@ -41,20 +35,3 @@ config UBIFS_FS_ZLIB | |||
41 | default y | 35 | default y |
42 | help | 36 | help |
43 | Zlib compresses better than LZO but it is slower. Say 'Y' if unsure. | 37 | Zlib compresses better than LZO but it is slower. Say 'Y' if unsure. |
44 | |||
45 | # Debugging-related stuff | ||
46 | config UBIFS_FS_DEBUG | ||
47 | bool "Enable debugging support" | ||
48 | depends on UBIFS_FS | ||
49 | select DEBUG_FS | ||
50 | select KALLSYMS | ||
51 | help | ||
52 | This option enables UBIFS debugging support. It makes sure various | ||
53 | assertions, self-checks, debugging messages and test modes are compiled | ||
54 | in (this all is compiled out otherwise). Assertions are light-weight | ||
55 | and this option also enables them. Self-checks, debugging messages and | ||
56 | test modes are switched off by default. Thus, it is safe and actually | ||
57 | recommended to have debugging support enabled, and it should not slow | ||
58 | down UBIFS. You can then further enable / disable individual debugging | ||
59 | features using UBIFS module parameters and the corresponding sysfs | ||
60 | interfaces. | ||
diff --git a/fs/ubifs/Makefile b/fs/ubifs/Makefile index 80e93c35e496..2c6f0cb816b4 100644 --- a/fs/ubifs/Makefile +++ b/fs/ubifs/Makefile | |||
@@ -3,7 +3,4 @@ obj-$(CONFIG_UBIFS_FS) += ubifs.o | |||
3 | ubifs-y += shrinker.o journal.o file.o dir.o super.o sb.o io.o | 3 | ubifs-y += shrinker.o journal.o file.o dir.o super.o sb.o io.o |
4 | ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o | 4 | ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o |
5 | ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o | 5 | ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o |
6 | ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o | 6 | ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o xattr.o debug.o |
7 | |||
8 | ubifs-$(CONFIG_UBIFS_FS_DEBUG) += debug.o | ||
9 | ubifs-$(CONFIG_UBIFS_FS_XATTR) += xattr.o | ||
diff --git a/fs/ubifs/commit.c b/fs/ubifs/commit.c index fb3b5c813a30..8eda717cb99b 100644 --- a/fs/ubifs/commit.c +++ b/fs/ubifs/commit.c | |||
@@ -496,7 +496,9 @@ int ubifs_gc_should_commit(struct ubifs_info *c) | |||
496 | return ret; | 496 | return ret; |
497 | } | 497 | } |
498 | 498 | ||
499 | #ifdef CONFIG_UBIFS_FS_DEBUG | 499 | /* |
500 | * Everything below is related to debugging. | ||
501 | */ | ||
500 | 502 | ||
501 | /** | 503 | /** |
502 | * struct idx_node - hold index nodes during index tree traversal. | 504 | * struct idx_node - hold index nodes during index tree traversal. |
@@ -714,14 +716,14 @@ out: | |||
714 | return 0; | 716 | return 0; |
715 | 717 | ||
716 | out_dump: | 718 | out_dump: |
717 | dbg_err("dumping index node (iip=%d)", i->iip); | 719 | ubifs_err("dumping index node (iip=%d)", i->iip); |
718 | dbg_dump_node(c, idx); | 720 | ubifs_dump_node(c, idx); |
719 | list_del(&i->list); | 721 | list_del(&i->list); |
720 | kfree(i); | 722 | kfree(i); |
721 | if (!list_empty(&list)) { | 723 | if (!list_empty(&list)) { |
722 | i = list_entry(list.prev, struct idx_node, list); | 724 | i = list_entry(list.prev, struct idx_node, list); |
723 | dbg_err("dumping parent index node"); | 725 | ubifs_err("dumping parent index node"); |
724 | dbg_dump_node(c, &i->idx); | 726 | ubifs_dump_node(c, &i->idx); |
725 | } | 727 | } |
726 | out_free: | 728 | out_free: |
727 | while (!list_empty(&list)) { | 729 | while (!list_empty(&list)) { |
@@ -734,5 +736,3 @@ out_free: | |||
734 | err = -EINVAL; | 736 | err = -EINVAL; |
735 | return err; | 737 | return err; |
736 | } | 738 | } |
737 | |||
738 | #endif /* CONFIG_UBIFS_FS_DEBUG */ | ||
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index 1934084e2088..685a83756b2b 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c | |||
@@ -34,8 +34,6 @@ | |||
34 | #include <linux/random.h> | 34 | #include <linux/random.h> |
35 | #include "ubifs.h" | 35 | #include "ubifs.h" |
36 | 36 | ||
37 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
38 | |||
39 | static DEFINE_SPINLOCK(dbg_lock); | 37 | static DEFINE_SPINLOCK(dbg_lock); |
40 | 38 | ||
41 | static const char *get_key_fmt(int fmt) | 39 | static const char *get_key_fmt(int fmt) |
@@ -232,7 +230,7 @@ static void dump_ch(const struct ubifs_ch *ch) | |||
232 | printk(KERN_ERR "\tlen %u\n", le32_to_cpu(ch->len)); | 230 | printk(KERN_ERR "\tlen %u\n", le32_to_cpu(ch->len)); |
233 | } | 231 | } |
234 | 232 | ||
235 | void dbg_dump_inode(struct ubifs_info *c, const struct inode *inode) | 233 | void ubifs_dump_inode(struct ubifs_info *c, const struct inode *inode) |
236 | { | 234 | { |
237 | const struct ubifs_inode *ui = ubifs_inode(inode); | 235 | const struct ubifs_inode *ui = ubifs_inode(inode); |
238 | struct qstr nm = { .name = NULL }; | 236 | struct qstr nm = { .name = NULL }; |
@@ -300,7 +298,7 @@ void dbg_dump_inode(struct ubifs_info *c, const struct inode *inode) | |||
300 | kfree(pdent); | 298 | kfree(pdent); |
301 | } | 299 | } |
302 | 300 | ||
303 | void dbg_dump_node(const struct ubifs_info *c, const void *node) | 301 | void ubifs_dump_node(const struct ubifs_info *c, const void *node) |
304 | { | 302 | { |
305 | int i, n; | 303 | int i, n; |
306 | union ubifs_key key; | 304 | union ubifs_key key; |
@@ -603,7 +601,7 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node) | |||
603 | spin_unlock(&dbg_lock); | 601 | spin_unlock(&dbg_lock); |
604 | } | 602 | } |
605 | 603 | ||
606 | void dbg_dump_budget_req(const struct ubifs_budget_req *req) | 604 | void ubifs_dump_budget_req(const struct ubifs_budget_req *req) |
607 | { | 605 | { |
608 | spin_lock(&dbg_lock); | 606 | spin_lock(&dbg_lock); |
609 | printk(KERN_ERR "Budgeting request: new_ino %d, dirtied_ino %d\n", | 607 | printk(KERN_ERR "Budgeting request: new_ino %d, dirtied_ino %d\n", |
@@ -620,7 +618,7 @@ void dbg_dump_budget_req(const struct ubifs_budget_req *req) | |||
620 | spin_unlock(&dbg_lock); | 618 | spin_unlock(&dbg_lock); |
621 | } | 619 | } |
622 | 620 | ||
623 | void dbg_dump_lstats(const struct ubifs_lp_stats *lst) | 621 | void ubifs_dump_lstats(const struct ubifs_lp_stats *lst) |
624 | { | 622 | { |
625 | spin_lock(&dbg_lock); | 623 | spin_lock(&dbg_lock); |
626 | printk(KERN_ERR "(pid %d) Lprops statistics: empty_lebs %d, " | 624 | printk(KERN_ERR "(pid %d) Lprops statistics: empty_lebs %d, " |
@@ -634,7 +632,7 @@ void dbg_dump_lstats(const struct ubifs_lp_stats *lst) | |||
634 | spin_unlock(&dbg_lock); | 632 | spin_unlock(&dbg_lock); |
635 | } | 633 | } |
636 | 634 | ||
637 | void dbg_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi) | 635 | void ubifs_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi) |
638 | { | 636 | { |
639 | int i; | 637 | int i; |
640 | struct rb_node *rb; | 638 | struct rb_node *rb; |
@@ -707,7 +705,7 @@ out_unlock: | |||
707 | spin_unlock(&c->space_lock); | 705 | spin_unlock(&c->space_lock); |
708 | } | 706 | } |
709 | 707 | ||
710 | void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp) | 708 | void ubifs_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp) |
711 | { | 709 | { |
712 | int i, spc, dark = 0, dead = 0; | 710 | int i, spc, dark = 0, dead = 0; |
713 | struct rb_node *rb; | 711 | struct rb_node *rb; |
@@ -801,7 +799,7 @@ void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp) | |||
801 | printk(KERN_CONT ")\n"); | 799 | printk(KERN_CONT ")\n"); |
802 | } | 800 | } |
803 | 801 | ||
804 | void dbg_dump_lprops(struct ubifs_info *c) | 802 | void ubifs_dump_lprops(struct ubifs_info *c) |
805 | { | 803 | { |
806 | int lnum, err; | 804 | int lnum, err; |
807 | struct ubifs_lprops lp; | 805 | struct ubifs_lprops lp; |
@@ -810,20 +808,20 @@ void dbg_dump_lprops(struct ubifs_info *c) | |||
810 | printk(KERN_ERR "(pid %d) start dumping LEB properties\n", | 808 | printk(KERN_ERR "(pid %d) start dumping LEB properties\n", |
811 | current->pid); | 809 | current->pid); |
812 | ubifs_get_lp_stats(c, &lst); | 810 | ubifs_get_lp_stats(c, &lst); |
813 | dbg_dump_lstats(&lst); | 811 | ubifs_dump_lstats(&lst); |
814 | 812 | ||
815 | for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) { | 813 | for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) { |
816 | err = ubifs_read_one_lp(c, lnum, &lp); | 814 | err = ubifs_read_one_lp(c, lnum, &lp); |
817 | if (err) | 815 | if (err) |
818 | ubifs_err("cannot read lprops for LEB %d", lnum); | 816 | ubifs_err("cannot read lprops for LEB %d", lnum); |
819 | 817 | ||
820 | dbg_dump_lprop(c, &lp); | 818 | ubifs_dump_lprop(c, &lp); |
821 | } | 819 | } |
822 | printk(KERN_ERR "(pid %d) finish dumping LEB properties\n", | 820 | printk(KERN_ERR "(pid %d) finish dumping LEB properties\n", |
823 | current->pid); | 821 | current->pid); |
824 | } | 822 | } |
825 | 823 | ||
826 | void dbg_dump_lpt_info(struct ubifs_info *c) | 824 | void ubifs_dump_lpt_info(struct ubifs_info *c) |
827 | { | 825 | { |
828 | int i; | 826 | int i; |
829 | 827 | ||
@@ -862,8 +860,8 @@ void dbg_dump_lpt_info(struct ubifs_info *c) | |||
862 | spin_unlock(&dbg_lock); | 860 | spin_unlock(&dbg_lock); |
863 | } | 861 | } |
864 | 862 | ||
865 | void dbg_dump_sleb(const struct ubifs_info *c, | 863 | void ubifs_dump_sleb(const struct ubifs_info *c, |
866 | const struct ubifs_scan_leb *sleb, int offs) | 864 | const struct ubifs_scan_leb *sleb, int offs) |
867 | { | 865 | { |
868 | struct ubifs_scan_node *snod; | 866 | struct ubifs_scan_node *snod; |
869 | 867 | ||
@@ -874,11 +872,11 @@ void dbg_dump_sleb(const struct ubifs_info *c, | |||
874 | cond_resched(); | 872 | cond_resched(); |
875 | printk(KERN_ERR "Dumping node at LEB %d:%d len %d\n", sleb->lnum, | 873 | printk(KERN_ERR "Dumping node at LEB %d:%d len %d\n", sleb->lnum, |
876 | snod->offs, snod->len); | 874 | snod->offs, snod->len); |
877 | dbg_dump_node(c, snod->node); | 875 | ubifs_dump_node(c, snod->node); |
878 | } | 876 | } |
879 | } | 877 | } |
880 | 878 | ||
881 | void dbg_dump_leb(const struct ubifs_info *c, int lnum) | 879 | void ubifs_dump_leb(const struct ubifs_info *c, int lnum) |
882 | { | 880 | { |
883 | struct ubifs_scan_leb *sleb; | 881 | struct ubifs_scan_leb *sleb; |
884 | struct ubifs_scan_node *snod; | 882 | struct ubifs_scan_node *snod; |
@@ -909,7 +907,7 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum) | |||
909 | cond_resched(); | 907 | cond_resched(); |
910 | printk(KERN_ERR "Dumping node at LEB %d:%d len %d\n", lnum, | 908 | printk(KERN_ERR "Dumping node at LEB %d:%d len %d\n", lnum, |
911 | snod->offs, snod->len); | 909 | snod->offs, snod->len); |
912 | dbg_dump_node(c, snod->node); | 910 | ubifs_dump_node(c, snod->node); |
913 | } | 911 | } |
914 | 912 | ||
915 | printk(KERN_ERR "(pid %d) finish dumping LEB %d\n", | 913 | printk(KERN_ERR "(pid %d) finish dumping LEB %d\n", |
@@ -921,8 +919,8 @@ out: | |||
921 | return; | 919 | return; |
922 | } | 920 | } |
923 | 921 | ||
924 | void dbg_dump_znode(const struct ubifs_info *c, | 922 | void ubifs_dump_znode(const struct ubifs_info *c, |
925 | const struct ubifs_znode *znode) | 923 | const struct ubifs_znode *znode) |
926 | { | 924 | { |
927 | int n; | 925 | int n; |
928 | const struct ubifs_zbranch *zbr; | 926 | const struct ubifs_zbranch *zbr; |
@@ -965,7 +963,7 @@ void dbg_dump_znode(const struct ubifs_info *c, | |||
965 | spin_unlock(&dbg_lock); | 963 | spin_unlock(&dbg_lock); |
966 | } | 964 | } |
967 | 965 | ||
968 | void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat) | 966 | void ubifs_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat) |
969 | { | 967 | { |
970 | int i; | 968 | int i; |
971 | 969 | ||
@@ -981,8 +979,8 @@ void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat) | |||
981 | printk(KERN_ERR "(pid %d) finish dumping heap\n", current->pid); | 979 | printk(KERN_ERR "(pid %d) finish dumping heap\n", current->pid); |
982 | } | 980 | } |
983 | 981 | ||
984 | void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, | 982 | void ubifs_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, |
985 | struct ubifs_nnode *parent, int iip) | 983 | struct ubifs_nnode *parent, int iip) |
986 | { | 984 | { |
987 | int i; | 985 | int i; |
988 | 986 | ||
@@ -999,7 +997,7 @@ void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, | |||
999 | } | 997 | } |
1000 | } | 998 | } |
1001 | 999 | ||
1002 | void dbg_dump_tnc(struct ubifs_info *c) | 1000 | void ubifs_dump_tnc(struct ubifs_info *c) |
1003 | { | 1001 | { |
1004 | struct ubifs_znode *znode; | 1002 | struct ubifs_znode *znode; |
1005 | int level; | 1003 | int level; |
@@ -1014,7 +1012,7 @@ void dbg_dump_tnc(struct ubifs_info *c) | |||
1014 | level = znode->level; | 1012 | level = znode->level; |
1015 | printk(KERN_ERR "== Level %d ==\n", level); | 1013 | printk(KERN_ERR "== Level %d ==\n", level); |
1016 | } | 1014 | } |
1017 | dbg_dump_znode(c, znode); | 1015 | ubifs_dump_znode(c, znode); |
1018 | znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode); | 1016 | znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode); |
1019 | } | 1017 | } |
1020 | printk(KERN_ERR "(pid %d) finish dumping TNC tree\n", current->pid); | 1018 | printk(KERN_ERR "(pid %d) finish dumping TNC tree\n", current->pid); |
@@ -1023,18 +1021,18 @@ void dbg_dump_tnc(struct ubifs_info *c) | |||
1023 | static int dump_znode(struct ubifs_info *c, struct ubifs_znode *znode, | 1021 | static int dump_znode(struct ubifs_info *c, struct ubifs_znode *znode, |
1024 | void *priv) | 1022 | void *priv) |
1025 | { | 1023 | { |
1026 | dbg_dump_znode(c, znode); | 1024 | ubifs_dump_znode(c, znode); |
1027 | return 0; | 1025 | return 0; |
1028 | } | 1026 | } |
1029 | 1027 | ||
1030 | /** | 1028 | /** |
1031 | * dbg_dump_index - dump the on-flash index. | 1029 | * ubifs_dump_index - dump the on-flash index. |
1032 | * @c: UBIFS file-system description object | 1030 | * @c: UBIFS file-system description object |
1033 | * | 1031 | * |
1034 | * This function dumps whole UBIFS indexing B-tree, unlike 'dbg_dump_tnc()' | 1032 | * This function dumps whole UBIFS indexing B-tree, unlike 'ubifs_dump_tnc()' |
1035 | * which dumps only in-memory znodes and does not read znodes which from flash. | 1033 | * which dumps only in-memory znodes and does not read znodes which from flash. |
1036 | */ | 1034 | */ |
1037 | void dbg_dump_index(struct ubifs_info *c) | 1035 | void ubifs_dump_index(struct ubifs_info *c) |
1038 | { | 1036 | { |
1039 | dbg_walk_index(c, NULL, dump_znode, NULL); | 1037 | dbg_walk_index(c, NULL, dump_znode, NULL); |
1040 | } | 1038 | } |
@@ -1120,15 +1118,15 @@ int dbg_check_space_info(struct ubifs_info *c) | |||
1120 | 1118 | ||
1121 | out: | 1119 | out: |
1122 | ubifs_msg("saved lprops statistics dump"); | 1120 | ubifs_msg("saved lprops statistics dump"); |
1123 | dbg_dump_lstats(&d->saved_lst); | 1121 | ubifs_dump_lstats(&d->saved_lst); |
1124 | ubifs_msg("saved budgeting info dump"); | 1122 | ubifs_msg("saved budgeting info dump"); |
1125 | dbg_dump_budg(c, &d->saved_bi); | 1123 | ubifs_dump_budg(c, &d->saved_bi); |
1126 | ubifs_msg("saved idx_gc_cnt %d", d->saved_idx_gc_cnt); | 1124 | ubifs_msg("saved idx_gc_cnt %d", d->saved_idx_gc_cnt); |
1127 | ubifs_msg("current lprops statistics dump"); | 1125 | ubifs_msg("current lprops statistics dump"); |
1128 | ubifs_get_lp_stats(c, &lst); | 1126 | ubifs_get_lp_stats(c, &lst); |
1129 | dbg_dump_lstats(&lst); | 1127 | ubifs_dump_lstats(&lst); |
1130 | ubifs_msg("current budgeting info dump"); | 1128 | ubifs_msg("current budgeting info dump"); |
1131 | dbg_dump_budg(c, &c->bi); | 1129 | ubifs_dump_budg(c, &c->bi); |
1132 | dump_stack(); | 1130 | dump_stack(); |
1133 | return -EINVAL; | 1131 | return -EINVAL; |
1134 | } | 1132 | } |
@@ -1160,7 +1158,7 @@ int dbg_check_synced_i_size(const struct ubifs_info *c, struct inode *inode) | |||
1160 | "is clean", ui->ui_size, ui->synced_i_size); | 1158 | "is clean", ui->ui_size, ui->synced_i_size); |
1161 | ubifs_err("i_ino %lu, i_mode %#x, i_size %lld", inode->i_ino, | 1159 | ubifs_err("i_ino %lu, i_mode %#x, i_size %lld", inode->i_ino, |
1162 | inode->i_mode, i_size_read(inode)); | 1160 | inode->i_mode, i_size_read(inode)); |
1163 | dbg_dump_stack(); | 1161 | dump_stack(); |
1164 | err = -EINVAL; | 1162 | err = -EINVAL; |
1165 | } | 1163 | } |
1166 | spin_unlock(&ui->ui_lock); | 1164 | spin_unlock(&ui->ui_lock); |
@@ -1223,14 +1221,14 @@ int dbg_check_dir(struct ubifs_info *c, const struct inode *dir) | |||
1223 | "but calculated size is %llu", dir->i_ino, | 1221 | "but calculated size is %llu", dir->i_ino, |
1224 | (unsigned long long)i_size_read(dir), | 1222 | (unsigned long long)i_size_read(dir), |
1225 | (unsigned long long)size); | 1223 | (unsigned long long)size); |
1226 | dbg_dump_inode(c, dir); | 1224 | ubifs_dump_inode(c, dir); |
1227 | dump_stack(); | 1225 | dump_stack(); |
1228 | return -EINVAL; | 1226 | return -EINVAL; |
1229 | } | 1227 | } |
1230 | if (dir->i_nlink != nlink) { | 1228 | if (dir->i_nlink != nlink) { |
1231 | ubifs_err("directory inode %lu has nlink %u, but calculated " | 1229 | ubifs_err("directory inode %lu has nlink %u, but calculated " |
1232 | "nlink is %u", dir->i_ino, dir->i_nlink, nlink); | 1230 | "nlink is %u", dir->i_ino, dir->i_nlink, nlink); |
1233 | dbg_dump_inode(c, dir); | 1231 | ubifs_dump_inode(c, dir); |
1234 | dump_stack(); | 1232 | dump_stack(); |
1235 | return -EINVAL; | 1233 | return -EINVAL; |
1236 | } | 1234 | } |
@@ -1287,25 +1285,25 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1, | |||
1287 | err = 1; | 1285 | err = 1; |
1288 | key_read(c, &dent1->key, &key); | 1286 | key_read(c, &dent1->key, &key); |
1289 | if (keys_cmp(c, &zbr1->key, &key)) { | 1287 | if (keys_cmp(c, &zbr1->key, &key)) { |
1290 | dbg_err("1st entry at %d:%d has key %s", zbr1->lnum, | 1288 | ubifs_err("1st entry at %d:%d has key %s", zbr1->lnum, |
1291 | zbr1->offs, dbg_snprintf_key(c, &key, key_buf, | 1289 | zbr1->offs, dbg_snprintf_key(c, &key, key_buf, |
1292 | DBG_KEY_BUF_LEN)); | 1290 | DBG_KEY_BUF_LEN)); |
1293 | dbg_err("but it should have key %s according to tnc", | 1291 | ubifs_err("but it should have key %s according to tnc", |
1294 | dbg_snprintf_key(c, &zbr1->key, key_buf, | 1292 | dbg_snprintf_key(c, &zbr1->key, key_buf, |
1295 | DBG_KEY_BUF_LEN)); | 1293 | DBG_KEY_BUF_LEN)); |
1296 | dbg_dump_node(c, dent1); | 1294 | ubifs_dump_node(c, dent1); |
1297 | goto out_free; | 1295 | goto out_free; |
1298 | } | 1296 | } |
1299 | 1297 | ||
1300 | key_read(c, &dent2->key, &key); | 1298 | key_read(c, &dent2->key, &key); |
1301 | if (keys_cmp(c, &zbr2->key, &key)) { | 1299 | if (keys_cmp(c, &zbr2->key, &key)) { |
1302 | dbg_err("2nd entry at %d:%d has key %s", zbr1->lnum, | 1300 | ubifs_err("2nd entry at %d:%d has key %s", zbr1->lnum, |
1303 | zbr1->offs, dbg_snprintf_key(c, &key, key_buf, | 1301 | zbr1->offs, dbg_snprintf_key(c, &key, key_buf, |
1304 | DBG_KEY_BUF_LEN)); | 1302 | DBG_KEY_BUF_LEN)); |
1305 | dbg_err("but it should have key %s according to tnc", | 1303 | ubifs_err("but it should have key %s according to tnc", |
1306 | dbg_snprintf_key(c, &zbr2->key, key_buf, | 1304 | dbg_snprintf_key(c, &zbr2->key, key_buf, |
1307 | DBG_KEY_BUF_LEN)); | 1305 | DBG_KEY_BUF_LEN)); |
1308 | dbg_dump_node(c, dent2); | 1306 | ubifs_dump_node(c, dent2); |
1309 | goto out_free; | 1307 | goto out_free; |
1310 | } | 1308 | } |
1311 | 1309 | ||
@@ -1318,15 +1316,15 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1, | |||
1318 | goto out_free; | 1316 | goto out_free; |
1319 | } | 1317 | } |
1320 | if (cmp == 0 && nlen1 == nlen2) | 1318 | if (cmp == 0 && nlen1 == nlen2) |
1321 | dbg_err("2 xent/dent nodes with the same name"); | 1319 | ubifs_err("2 xent/dent nodes with the same name"); |
1322 | else | 1320 | else |
1323 | dbg_err("bad order of colliding key %s", | 1321 | ubifs_err("bad order of colliding key %s", |
1324 | dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN)); | 1322 | dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN)); |
1325 | 1323 | ||
1326 | ubifs_msg("first node at %d:%d\n", zbr1->lnum, zbr1->offs); | 1324 | ubifs_msg("first node at %d:%d\n", zbr1->lnum, zbr1->offs); |
1327 | dbg_dump_node(c, dent1); | 1325 | ubifs_dump_node(c, dent1); |
1328 | ubifs_msg("second node at %d:%d\n", zbr2->lnum, zbr2->offs); | 1326 | ubifs_msg("second node at %d:%d\n", zbr2->lnum, zbr2->offs); |
1329 | dbg_dump_node(c, dent2); | 1327 | ubifs_dump_node(c, dent2); |
1330 | 1328 | ||
1331 | out_free: | 1329 | out_free: |
1332 | kfree(dent2); | 1330 | kfree(dent2); |
@@ -1529,10 +1527,10 @@ static int dbg_check_znode(struct ubifs_info *c, struct ubifs_zbranch *zbr) | |||
1529 | out: | 1527 | out: |
1530 | ubifs_err("failed, error %d", err); | 1528 | ubifs_err("failed, error %d", err); |
1531 | ubifs_msg("dump of the znode"); | 1529 | ubifs_msg("dump of the znode"); |
1532 | dbg_dump_znode(c, znode); | 1530 | ubifs_dump_znode(c, znode); |
1533 | if (zp) { | 1531 | if (zp) { |
1534 | ubifs_msg("dump of the parent znode"); | 1532 | ubifs_msg("dump of the parent znode"); |
1535 | dbg_dump_znode(c, zp); | 1533 | ubifs_dump_znode(c, zp); |
1536 | } | 1534 | } |
1537 | dump_stack(); | 1535 | dump_stack(); |
1538 | return -EINVAL; | 1536 | return -EINVAL; |
@@ -1599,9 +1597,9 @@ int dbg_check_tnc(struct ubifs_info *c, int extra) | |||
1599 | return err; | 1597 | return err; |
1600 | if (err) { | 1598 | if (err) { |
1601 | ubifs_msg("first znode"); | 1599 | ubifs_msg("first znode"); |
1602 | dbg_dump_znode(c, prev); | 1600 | ubifs_dump_znode(c, prev); |
1603 | ubifs_msg("second znode"); | 1601 | ubifs_msg("second znode"); |
1604 | dbg_dump_znode(c, znode); | 1602 | ubifs_dump_znode(c, znode); |
1605 | return -EINVAL; | 1603 | return -EINVAL; |
1606 | } | 1604 | } |
1607 | } | 1605 | } |
@@ -1690,7 +1688,7 @@ int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, | |||
1690 | if (err) { | 1688 | if (err) { |
1691 | ubifs_err("znode checking function returned " | 1689 | ubifs_err("znode checking function returned " |
1692 | "error %d", err); | 1690 | "error %d", err); |
1693 | dbg_dump_znode(c, znode); | 1691 | ubifs_dump_znode(c, znode); |
1694 | goto out_dump; | 1692 | goto out_dump; |
1695 | } | 1693 | } |
1696 | } | 1694 | } |
@@ -1758,7 +1756,7 @@ out_dump: | |||
1758 | else | 1756 | else |
1759 | zbr = &c->zroot; | 1757 | zbr = &c->zroot; |
1760 | ubifs_msg("dump of znode at LEB %d:%d", zbr->lnum, zbr->offs); | 1758 | ubifs_msg("dump of znode at LEB %d:%d", zbr->lnum, zbr->offs); |
1761 | dbg_dump_znode(c, znode); | 1759 | ubifs_dump_znode(c, znode); |
1762 | out_unlock: | 1760 | out_unlock: |
1763 | mutex_unlock(&c->tnc_mutex); | 1761 | mutex_unlock(&c->tnc_mutex); |
1764 | return err; | 1762 | return err; |
@@ -2194,7 +2192,7 @@ out: | |||
2194 | 2192 | ||
2195 | out_dump: | 2193 | out_dump: |
2196 | ubifs_msg("dump of node at LEB %d:%d", zbr->lnum, zbr->offs); | 2194 | ubifs_msg("dump of node at LEB %d:%d", zbr->lnum, zbr->offs); |
2197 | dbg_dump_node(c, node); | 2195 | ubifs_dump_node(c, node); |
2198 | out_free: | 2196 | out_free: |
2199 | kfree(node); | 2197 | kfree(node); |
2200 | return err; | 2198 | return err; |
@@ -2352,7 +2350,7 @@ out_dump: | |||
2352 | 2350 | ||
2353 | ubifs_msg("dump of the inode %lu sitting in LEB %d:%d", | 2351 | ubifs_msg("dump of the inode %lu sitting in LEB %d:%d", |
2354 | (unsigned long)fscki->inum, zbr->lnum, zbr->offs); | 2352 | (unsigned long)fscki->inum, zbr->lnum, zbr->offs); |
2355 | dbg_dump_node(c, ino); | 2353 | ubifs_dump_node(c, ino); |
2356 | kfree(ino); | 2354 | kfree(ino); |
2357 | return -EINVAL; | 2355 | return -EINVAL; |
2358 | } | 2356 | } |
@@ -2423,12 +2421,12 @@ int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head) | |||
2423 | 2421 | ||
2424 | if (sa->type != UBIFS_DATA_NODE) { | 2422 | if (sa->type != UBIFS_DATA_NODE) { |
2425 | ubifs_err("bad node type %d", sa->type); | 2423 | ubifs_err("bad node type %d", sa->type); |
2426 | dbg_dump_node(c, sa->node); | 2424 | ubifs_dump_node(c, sa->node); |
2427 | return -EINVAL; | 2425 | return -EINVAL; |
2428 | } | 2426 | } |
2429 | if (sb->type != UBIFS_DATA_NODE) { | 2427 | if (sb->type != UBIFS_DATA_NODE) { |
2430 | ubifs_err("bad node type %d", sb->type); | 2428 | ubifs_err("bad node type %d", sb->type); |
2431 | dbg_dump_node(c, sb->node); | 2429 | ubifs_dump_node(c, sb->node); |
2432 | return -EINVAL; | 2430 | return -EINVAL; |
2433 | } | 2431 | } |
2434 | 2432 | ||
@@ -2459,8 +2457,8 @@ int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head) | |||
2459 | return 0; | 2457 | return 0; |
2460 | 2458 | ||
2461 | error_dump: | 2459 | error_dump: |
2462 | dbg_dump_node(c, sa->node); | 2460 | ubifs_dump_node(c, sa->node); |
2463 | dbg_dump_node(c, sb->node); | 2461 | ubifs_dump_node(c, sb->node); |
2464 | return -EINVAL; | 2462 | return -EINVAL; |
2465 | } | 2463 | } |
2466 | 2464 | ||
@@ -2491,13 +2489,13 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head) | |||
2491 | if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && | 2489 | if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && |
2492 | sa->type != UBIFS_XENT_NODE) { | 2490 | sa->type != UBIFS_XENT_NODE) { |
2493 | ubifs_err("bad node type %d", sa->type); | 2491 | ubifs_err("bad node type %d", sa->type); |
2494 | dbg_dump_node(c, sa->node); | 2492 | ubifs_dump_node(c, sa->node); |
2495 | return -EINVAL; | 2493 | return -EINVAL; |
2496 | } | 2494 | } |
2497 | if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && | 2495 | if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && |
2498 | sa->type != UBIFS_XENT_NODE) { | 2496 | sa->type != UBIFS_XENT_NODE) { |
2499 | ubifs_err("bad node type %d", sb->type); | 2497 | ubifs_err("bad node type %d", sb->type); |
2500 | dbg_dump_node(c, sb->node); | 2498 | ubifs_dump_node(c, sb->node); |
2501 | return -EINVAL; | 2499 | return -EINVAL; |
2502 | } | 2500 | } |
2503 | 2501 | ||
@@ -2547,9 +2545,9 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head) | |||
2547 | 2545 | ||
2548 | error_dump: | 2546 | error_dump: |
2549 | ubifs_msg("dumping first node"); | 2547 | ubifs_msg("dumping first node"); |
2550 | dbg_dump_node(c, sa->node); | 2548 | ubifs_dump_node(c, sa->node); |
2551 | ubifs_msg("dumping second node"); | 2549 | ubifs_msg("dumping second node"); |
2552 | dbg_dump_node(c, sb->node); | 2550 | ubifs_dump_node(c, sb->node); |
2553 | return -EINVAL; | 2551 | return -EINVAL; |
2554 | return 0; | 2552 | return 0; |
2555 | } | 2553 | } |
@@ -2678,7 +2676,7 @@ static void cut_data(const void *buf, unsigned int len) | |||
2678 | } | 2676 | } |
2679 | 2677 | ||
2680 | int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf, | 2678 | int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf, |
2681 | int offs, int len, int dtype) | 2679 | int offs, int len) |
2682 | { | 2680 | { |
2683 | int err, failing; | 2681 | int err, failing; |
2684 | 2682 | ||
@@ -2688,7 +2686,7 @@ int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf, | |||
2688 | failing = power_cut_emulated(c, lnum, 1); | 2686 | failing = power_cut_emulated(c, lnum, 1); |
2689 | if (failing) | 2687 | if (failing) |
2690 | cut_data(buf, len); | 2688 | cut_data(buf, len); |
2691 | err = ubi_leb_write(c->ubi, lnum, buf, offs, len, dtype); | 2689 | err = ubi_leb_write(c->ubi, lnum, buf, offs, len); |
2692 | if (err) | 2690 | if (err) |
2693 | return err; | 2691 | return err; |
2694 | if (failing) | 2692 | if (failing) |
@@ -2697,7 +2695,7 @@ int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf, | |||
2697 | } | 2695 | } |
2698 | 2696 | ||
2699 | int dbg_leb_change(struct ubifs_info *c, int lnum, const void *buf, | 2697 | int dbg_leb_change(struct ubifs_info *c, int lnum, const void *buf, |
2700 | int len, int dtype) | 2698 | int len) |
2701 | { | 2699 | { |
2702 | int err; | 2700 | int err; |
2703 | 2701 | ||
@@ -2705,7 +2703,7 @@ int dbg_leb_change(struct ubifs_info *c, int lnum, const void *buf, | |||
2705 | return -EROFS; | 2703 | return -EROFS; |
2706 | if (power_cut_emulated(c, lnum, 1)) | 2704 | if (power_cut_emulated(c, lnum, 1)) |
2707 | return -EROFS; | 2705 | return -EROFS; |
2708 | err = ubi_leb_change(c->ubi, lnum, buf, len, dtype); | 2706 | err = ubi_leb_change(c->ubi, lnum, buf, len); |
2709 | if (err) | 2707 | if (err) |
2710 | return err; | 2708 | return err; |
2711 | if (power_cut_emulated(c, lnum, 1)) | 2709 | if (power_cut_emulated(c, lnum, 1)) |
@@ -2729,7 +2727,7 @@ int dbg_leb_unmap(struct ubifs_info *c, int lnum) | |||
2729 | return 0; | 2727 | return 0; |
2730 | } | 2728 | } |
2731 | 2729 | ||
2732 | int dbg_leb_map(struct ubifs_info *c, int lnum, int dtype) | 2730 | int dbg_leb_map(struct ubifs_info *c, int lnum) |
2733 | { | 2731 | { |
2734 | int err; | 2732 | int err; |
2735 | 2733 | ||
@@ -2737,7 +2735,7 @@ int dbg_leb_map(struct ubifs_info *c, int lnum, int dtype) | |||
2737 | return -EROFS; | 2735 | return -EROFS; |
2738 | if (power_cut_emulated(c, lnum, 0)) | 2736 | if (power_cut_emulated(c, lnum, 0)) |
2739 | return -EROFS; | 2737 | return -EROFS; |
2740 | err = ubi_leb_map(c->ubi, lnum, dtype); | 2738 | err = ubi_leb_map(c->ubi, lnum); |
2741 | if (err) | 2739 | if (err) |
2742 | return err; | 2740 | return err; |
2743 | if (power_cut_emulated(c, lnum, 0)) | 2741 | if (power_cut_emulated(c, lnum, 0)) |
@@ -2857,16 +2855,16 @@ static ssize_t dfs_file_write(struct file *file, const char __user *u, | |||
2857 | * 'ubifs-debug' file-system instead. | 2855 | * 'ubifs-debug' file-system instead. |
2858 | */ | 2856 | */ |
2859 | if (file->f_path.dentry == d->dfs_dump_lprops) { | 2857 | if (file->f_path.dentry == d->dfs_dump_lprops) { |
2860 | dbg_dump_lprops(c); | 2858 | ubifs_dump_lprops(c); |
2861 | return count; | 2859 | return count; |
2862 | } | 2860 | } |
2863 | if (file->f_path.dentry == d->dfs_dump_budg) { | 2861 | if (file->f_path.dentry == d->dfs_dump_budg) { |
2864 | dbg_dump_budg(c, &c->bi); | 2862 | ubifs_dump_budg(c, &c->bi); |
2865 | return count; | 2863 | return count; |
2866 | } | 2864 | } |
2867 | if (file->f_path.dentry == d->dfs_dump_tnc) { | 2865 | if (file->f_path.dentry == d->dfs_dump_tnc) { |
2868 | mutex_lock(&c->tnc_mutex); | 2866 | mutex_lock(&c->tnc_mutex); |
2869 | dbg_dump_tnc(c); | 2867 | ubifs_dump_tnc(c); |
2870 | mutex_unlock(&c->tnc_mutex); | 2868 | mutex_unlock(&c->tnc_mutex); |
2871 | return count; | 2869 | return count; |
2872 | } | 2870 | } |
@@ -3189,5 +3187,3 @@ void ubifs_debugging_exit(struct ubifs_info *c) | |||
3189 | { | 3187 | { |
3190 | kfree(c->dbg); | 3188 | kfree(c->dbg); |
3191 | } | 3189 | } |
3192 | |||
3193 | #endif /* CONFIG_UBIFS_FS_DEBUG */ | ||
diff --git a/fs/ubifs/debug.h b/fs/ubifs/debug.h index 9f717655df18..486a8e024fb6 100644 --- a/fs/ubifs/debug.h +++ b/fs/ubifs/debug.h | |||
@@ -29,8 +29,6 @@ typedef int (*dbg_leaf_callback)(struct ubifs_info *c, | |||
29 | typedef int (*dbg_znode_callback)(struct ubifs_info *c, | 29 | typedef int (*dbg_znode_callback)(struct ubifs_info *c, |
30 | struct ubifs_znode *znode, void *priv); | 30 | struct ubifs_znode *znode, void *priv); |
31 | 31 | ||
32 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
33 | |||
34 | /* | 32 | /* |
35 | * The UBIFS debugfs directory name pattern and maximum name length (3 for "ubi" | 33 | * The UBIFS debugfs directory name pattern and maximum name length (3 for "ubi" |
36 | * + 1 for "_" and plus 2x2 for 2 UBI numbers and 1 for the trailing zero byte. | 34 | * + 1 for "_" and plus 2x2 for 2 UBI numbers and 1 for the trailing zero byte. |
@@ -149,7 +147,7 @@ struct ubifs_global_debug_info { | |||
149 | if (unlikely(!(expr))) { \ | 147 | if (unlikely(!(expr))) { \ |
150 | printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \ | 148 | printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \ |
151 | __func__, __LINE__, current->pid); \ | 149 | __func__, __LINE__, current->pid); \ |
152 | dbg_dump_stack(); \ | 150 | dump_stack(); \ |
153 | } \ | 151 | } \ |
154 | } while (0) | 152 | } while (0) |
155 | 153 | ||
@@ -161,12 +159,6 @@ struct ubifs_global_debug_info { | |||
161 | } \ | 159 | } \ |
162 | } while (0) | 160 | } while (0) |
163 | 161 | ||
164 | #define dbg_dump_stack() dump_stack() | ||
165 | |||
166 | #define dbg_err(fmt, ...) do { \ | ||
167 | ubifs_err(fmt, ##__VA_ARGS__); \ | ||
168 | } while (0) | ||
169 | |||
170 | #define ubifs_dbg_msg(type, fmt, ...) \ | 162 | #define ubifs_dbg_msg(type, fmt, ...) \ |
171 | pr_debug("UBIFS DBG " type ": " fmt "\n", ##__VA_ARGS__) | 163 | pr_debug("UBIFS DBG " type ": " fmt "\n", ##__VA_ARGS__) |
172 | 164 | ||
@@ -257,27 +249,27 @@ const char *dbg_get_key_dump(const struct ubifs_info *c, | |||
257 | const union ubifs_key *key); | 249 | const union ubifs_key *key); |
258 | const char *dbg_snprintf_key(const struct ubifs_info *c, | 250 | const char *dbg_snprintf_key(const struct ubifs_info *c, |
259 | const union ubifs_key *key, char *buffer, int len); | 251 | const union ubifs_key *key, char *buffer, int len); |
260 | void dbg_dump_inode(struct ubifs_info *c, const struct inode *inode); | 252 | void ubifs_dump_inode(struct ubifs_info *c, const struct inode *inode); |
261 | void dbg_dump_node(const struct ubifs_info *c, const void *node); | 253 | void ubifs_dump_node(const struct ubifs_info *c, const void *node); |
262 | void dbg_dump_lpt_node(const struct ubifs_info *c, void *node, int lnum, | 254 | void ubifs_dump_budget_req(const struct ubifs_budget_req *req); |
263 | int offs); | 255 | void ubifs_dump_lstats(const struct ubifs_lp_stats *lst); |
264 | void dbg_dump_budget_req(const struct ubifs_budget_req *req); | 256 | void ubifs_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi); |
265 | void dbg_dump_lstats(const struct ubifs_lp_stats *lst); | 257 | void ubifs_dump_lprop(const struct ubifs_info *c, |
266 | void dbg_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi); | 258 | const struct ubifs_lprops *lp); |
267 | void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp); | 259 | void ubifs_dump_lprops(struct ubifs_info *c); |
268 | void dbg_dump_lprops(struct ubifs_info *c); | 260 | void ubifs_dump_lpt_info(struct ubifs_info *c); |
269 | void dbg_dump_lpt_info(struct ubifs_info *c); | 261 | void ubifs_dump_leb(const struct ubifs_info *c, int lnum); |
270 | void dbg_dump_leb(const struct ubifs_info *c, int lnum); | 262 | void ubifs_dump_sleb(const struct ubifs_info *c, |
271 | void dbg_dump_sleb(const struct ubifs_info *c, | 263 | const struct ubifs_scan_leb *sleb, int offs); |
272 | const struct ubifs_scan_leb *sleb, int offs); | 264 | void ubifs_dump_znode(const struct ubifs_info *c, |
273 | void dbg_dump_znode(const struct ubifs_info *c, | 265 | const struct ubifs_znode *znode); |
274 | const struct ubifs_znode *znode); | 266 | void ubifs_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, |
275 | void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat); | 267 | int cat); |
276 | void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, | 268 | void ubifs_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, |
277 | struct ubifs_nnode *parent, int iip); | 269 | struct ubifs_nnode *parent, int iip); |
278 | void dbg_dump_tnc(struct ubifs_info *c); | 270 | void ubifs_dump_tnc(struct ubifs_info *c); |
279 | void dbg_dump_index(struct ubifs_info *c); | 271 | void ubifs_dump_index(struct ubifs_info *c); |
280 | void dbg_dump_lpt_lebs(const struct ubifs_info *c); | 272 | void ubifs_dump_lpt_lebs(const struct ubifs_info *c); |
281 | 273 | ||
282 | int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, | 274 | int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, |
283 | dbg_znode_callback znode_cb, void *priv); | 275 | dbg_znode_callback znode_cb, void *priv); |
@@ -307,11 +299,10 @@ int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head); | |||
307 | int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head); | 299 | int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head); |
308 | 300 | ||
309 | int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs, | 301 | int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs, |
310 | int len, int dtype); | 302 | int len); |
311 | int dbg_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len, | 303 | int dbg_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len); |
312 | int dtype); | ||
313 | int dbg_leb_unmap(struct ubifs_info *c, int lnum); | 304 | int dbg_leb_unmap(struct ubifs_info *c, int lnum); |
314 | int dbg_leb_map(struct ubifs_info *c, int lnum, int dtype); | 305 | int dbg_leb_map(struct ubifs_info *c, int lnum); |
315 | 306 | ||
316 | /* Debugfs-related stuff */ | 307 | /* Debugfs-related stuff */ |
317 | int dbg_debugfs_init(void); | 308 | int dbg_debugfs_init(void); |
@@ -319,162 +310,4 @@ void dbg_debugfs_exit(void); | |||
319 | int dbg_debugfs_init_fs(struct ubifs_info *c); | 310 | int dbg_debugfs_init_fs(struct ubifs_info *c); |
320 | void dbg_debugfs_exit_fs(struct ubifs_info *c); | 311 | void dbg_debugfs_exit_fs(struct ubifs_info *c); |
321 | 312 | ||
322 | #else /* !CONFIG_UBIFS_FS_DEBUG */ | ||
323 | |||
324 | /* Use "if (0)" to make compiler check arguments even if debugging is off */ | ||
325 | #define ubifs_assert(expr) do { \ | ||
326 | if (0) \ | ||
327 | printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \ | ||
328 | __func__, __LINE__, current->pid); \ | ||
329 | } while (0) | ||
330 | |||
331 | #define dbg_err(fmt, ...) do { \ | ||
332 | if (0) \ | ||
333 | ubifs_err(fmt, ##__VA_ARGS__); \ | ||
334 | } while (0) | ||
335 | |||
336 | #define DBGKEY(key) ((char *)(key)) | ||
337 | #define DBGKEY1(key) ((char *)(key)) | ||
338 | |||
339 | #define ubifs_dbg_msg(fmt, ...) do { \ | ||
340 | if (0) \ | ||
341 | printk(KERN_DEBUG fmt "\n", ##__VA_ARGS__); \ | ||
342 | } while (0) | ||
343 | |||
344 | #define dbg_dump_stack() | ||
345 | #define ubifs_assert_cmt_locked(c) | ||
346 | |||
347 | #define dbg_msg(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
348 | #define dbg_gen(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
349 | #define dbg_jnl(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
350 | #define dbg_jnlk(key, fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
351 | #define dbg_tnc(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
352 | #define dbg_tnck(key, fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
353 | #define dbg_lp(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
354 | #define dbg_find(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
355 | #define dbg_mnt(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
356 | #define dbg_mntk(key, fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
357 | #define dbg_io(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
358 | #define dbg_cmt(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
359 | #define dbg_budg(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
360 | #define dbg_log(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
361 | #define dbg_gc(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
362 | #define dbg_scan(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
363 | #define dbg_rcvry(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) | ||
364 | |||
365 | static inline int ubifs_debugging_init(struct ubifs_info *c) { return 0; } | ||
366 | static inline void ubifs_debugging_exit(struct ubifs_info *c) { return; } | ||
367 | static inline const char *dbg_ntype(int type) { return ""; } | ||
368 | static inline const char *dbg_cstate(int cmt_state) { return ""; } | ||
369 | static inline const char *dbg_jhead(int jhead) { return ""; } | ||
370 | static inline const char * | ||
371 | dbg_get_key_dump(const struct ubifs_info *c, | ||
372 | const union ubifs_key *key) { return ""; } | ||
373 | static inline const char * | ||
374 | dbg_snprintf_key(const struct ubifs_info *c, | ||
375 | const union ubifs_key *key, char *buffer, | ||
376 | int len) { return ""; } | ||
377 | static inline void dbg_dump_inode(struct ubifs_info *c, | ||
378 | const struct inode *inode) { return; } | ||
379 | static inline void dbg_dump_node(const struct ubifs_info *c, | ||
380 | const void *node) { return; } | ||
381 | static inline void dbg_dump_lpt_node(const struct ubifs_info *c, | ||
382 | void *node, int lnum, | ||
383 | int offs) { return; } | ||
384 | static inline void | ||
385 | dbg_dump_budget_req(const struct ubifs_budget_req *req) { return; } | ||
386 | static inline void | ||
387 | dbg_dump_lstats(const struct ubifs_lp_stats *lst) { return; } | ||
388 | static inline void | ||
389 | dbg_dump_budg(struct ubifs_info *c, | ||
390 | const struct ubifs_budg_info *bi) { return; } | ||
391 | static inline void dbg_dump_lprop(const struct ubifs_info *c, | ||
392 | const struct ubifs_lprops *lp) { return; } | ||
393 | static inline void dbg_dump_lprops(struct ubifs_info *c) { return; } | ||
394 | static inline void dbg_dump_lpt_info(struct ubifs_info *c) { return; } | ||
395 | static inline void dbg_dump_leb(const struct ubifs_info *c, | ||
396 | int lnum) { return; } | ||
397 | static inline void | ||
398 | dbg_dump_sleb(const struct ubifs_info *c, | ||
399 | const struct ubifs_scan_leb *sleb, int offs) { return; } | ||
400 | static inline void | ||
401 | dbg_dump_znode(const struct ubifs_info *c, | ||
402 | const struct ubifs_znode *znode) { return; } | ||
403 | static inline void dbg_dump_heap(struct ubifs_info *c, | ||
404 | struct ubifs_lpt_heap *heap, | ||
405 | int cat) { return; } | ||
406 | static inline void dbg_dump_pnode(struct ubifs_info *c, | ||
407 | struct ubifs_pnode *pnode, | ||
408 | struct ubifs_nnode *parent, | ||
409 | int iip) { return; } | ||
410 | static inline void dbg_dump_tnc(struct ubifs_info *c) { return; } | ||
411 | static inline void dbg_dump_index(struct ubifs_info *c) { return; } | ||
412 | static inline void dbg_dump_lpt_lebs(const struct ubifs_info *c) { return; } | ||
413 | |||
414 | static inline int dbg_walk_index(struct ubifs_info *c, | ||
415 | dbg_leaf_callback leaf_cb, | ||
416 | dbg_znode_callback znode_cb, | ||
417 | void *priv) { return 0; } | ||
418 | static inline void dbg_save_space_info(struct ubifs_info *c) { return; } | ||
419 | static inline int dbg_check_space_info(struct ubifs_info *c) { return 0; } | ||
420 | static inline int dbg_check_lprops(struct ubifs_info *c) { return 0; } | ||
421 | static inline int | ||
422 | dbg_old_index_check_init(struct ubifs_info *c, | ||
423 | struct ubifs_zbranch *zroot) { return 0; } | ||
424 | static inline int | ||
425 | dbg_check_old_index(struct ubifs_info *c, | ||
426 | struct ubifs_zbranch *zroot) { return 0; } | ||
427 | static inline int dbg_check_cats(struct ubifs_info *c) { return 0; } | ||
428 | static inline int dbg_check_ltab(struct ubifs_info *c) { return 0; } | ||
429 | static inline int dbg_chk_lpt_free_spc(struct ubifs_info *c) { return 0; } | ||
430 | static inline int dbg_chk_lpt_sz(struct ubifs_info *c, | ||
431 | int action, int len) { return 0; } | ||
432 | static inline int | ||
433 | dbg_check_synced_i_size(const struct ubifs_info *c, | ||
434 | struct inode *inode) { return 0; } | ||
435 | static inline int dbg_check_dir(struct ubifs_info *c, | ||
436 | const struct inode *dir) { return 0; } | ||
437 | static inline int dbg_check_tnc(struct ubifs_info *c, int extra) { return 0; } | ||
438 | static inline int dbg_check_idx_size(struct ubifs_info *c, | ||
439 | long long idx_size) { return 0; } | ||
440 | static inline int dbg_check_filesystem(struct ubifs_info *c) { return 0; } | ||
441 | static inline void dbg_check_heap(struct ubifs_info *c, | ||
442 | struct ubifs_lpt_heap *heap, | ||
443 | int cat, int add_pos) { return; } | ||
444 | static inline int dbg_check_lpt_nodes(struct ubifs_info *c, | ||
445 | struct ubifs_cnode *cnode, int row, int col) { return 0; } | ||
446 | static inline int dbg_check_inode_size(struct ubifs_info *c, | ||
447 | const struct inode *inode, | ||
448 | loff_t size) { return 0; } | ||
449 | static inline int | ||
450 | dbg_check_data_nodes_order(struct ubifs_info *c, | ||
451 | struct list_head *head) { return 0; } | ||
452 | static inline int | ||
453 | dbg_check_nondata_nodes_order(struct ubifs_info *c, | ||
454 | struct list_head *head) { return 0; } | ||
455 | |||
456 | static inline int dbg_leb_write(struct ubifs_info *c, int lnum, | ||
457 | const void *buf, int offset, | ||
458 | int len, int dtype) { return 0; } | ||
459 | static inline int dbg_leb_change(struct ubifs_info *c, int lnum, | ||
460 | const void *buf, int len, | ||
461 | int dtype) { return 0; } | ||
462 | static inline int dbg_leb_unmap(struct ubifs_info *c, int lnum) { return 0; } | ||
463 | static inline int dbg_leb_map(struct ubifs_info *c, int lnum, | ||
464 | int dtype) { return 0; } | ||
465 | |||
466 | static inline int dbg_is_chk_gen(const struct ubifs_info *c) { return 0; } | ||
467 | static inline int dbg_is_chk_index(const struct ubifs_info *c) { return 0; } | ||
468 | static inline int dbg_is_chk_orph(const struct ubifs_info *c) { return 0; } | ||
469 | static inline int dbg_is_chk_lprops(const struct ubifs_info *c) { return 0; } | ||
470 | static inline int dbg_is_chk_fs(const struct ubifs_info *c) { return 0; } | ||
471 | static inline int dbg_is_tst_rcvry(const struct ubifs_info *c) { return 0; } | ||
472 | static inline int dbg_is_power_cut(const struct ubifs_info *c) { return 0; } | ||
473 | |||
474 | static inline int dbg_debugfs_init(void) { return 0; } | ||
475 | static inline void dbg_debugfs_exit(void) { return; } | ||
476 | static inline int dbg_debugfs_init_fs(struct ubifs_info *c) { return 0; } | ||
477 | static inline int dbg_debugfs_exit_fs(struct ubifs_info *c) { return 0; } | ||
478 | |||
479 | #endif /* !CONFIG_UBIFS_FS_DEBUG */ | ||
480 | #endif /* !__UBIFS_DEBUG_H__ */ | 313 | #endif /* !__UBIFS_DEBUG_H__ */ |
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index ec9f1870ab7f..62a2727f4ecf 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c | |||
@@ -170,8 +170,6 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, const struct inode *dir, | |||
170 | return inode; | 170 | return inode; |
171 | } | 171 | } |
172 | 172 | ||
173 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
174 | |||
175 | static int dbg_check_name(const struct ubifs_info *c, | 173 | static int dbg_check_name(const struct ubifs_info *c, |
176 | const struct ubifs_dent_node *dent, | 174 | const struct ubifs_dent_node *dent, |
177 | const struct qstr *nm) | 175 | const struct qstr *nm) |
@@ -185,12 +183,6 @@ static int dbg_check_name(const struct ubifs_info *c, | |||
185 | return 0; | 183 | return 0; |
186 | } | 184 | } |
187 | 185 | ||
188 | #else | ||
189 | |||
190 | #define dbg_check_name(c, dent, nm) 0 | ||
191 | |||
192 | #endif | ||
193 | |||
194 | static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry, | 186 | static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry, |
195 | struct nameidata *nd) | 187 | struct nameidata *nd) |
196 | { | 188 | { |
@@ -1187,12 +1179,10 @@ const struct inode_operations ubifs_dir_inode_operations = { | |||
1187 | .rename = ubifs_rename, | 1179 | .rename = ubifs_rename, |
1188 | .setattr = ubifs_setattr, | 1180 | .setattr = ubifs_setattr, |
1189 | .getattr = ubifs_getattr, | 1181 | .getattr = ubifs_getattr, |
1190 | #ifdef CONFIG_UBIFS_FS_XATTR | ||
1191 | .setxattr = ubifs_setxattr, | 1182 | .setxattr = ubifs_setxattr, |
1192 | .getxattr = ubifs_getxattr, | 1183 | .getxattr = ubifs_getxattr, |
1193 | .listxattr = ubifs_listxattr, | 1184 | .listxattr = ubifs_listxattr, |
1194 | .removexattr = ubifs_removexattr, | 1185 | .removexattr = ubifs_removexattr, |
1195 | #endif | ||
1196 | }; | 1186 | }; |
1197 | 1187 | ||
1198 | const struct file_operations ubifs_dir_operations = { | 1188 | const struct file_operations ubifs_dir_operations = { |
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 5c8f6dc1d28b..35389ca2d267 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c | |||
@@ -97,7 +97,7 @@ static int read_block(struct inode *inode, void *addr, unsigned int block, | |||
97 | dump: | 97 | dump: |
98 | ubifs_err("bad data node (block %u, inode %lu)", | 98 | ubifs_err("bad data node (block %u, inode %lu)", |
99 | block, inode->i_ino); | 99 | block, inode->i_ino); |
100 | dbg_dump_node(c, dn); | 100 | ubifs_dump_node(c, dn); |
101 | return -EINVAL; | 101 | return -EINVAL; |
102 | } | 102 | } |
103 | 103 | ||
@@ -1562,12 +1562,10 @@ const struct address_space_operations ubifs_file_address_operations = { | |||
1562 | const struct inode_operations ubifs_file_inode_operations = { | 1562 | const struct inode_operations ubifs_file_inode_operations = { |
1563 | .setattr = ubifs_setattr, | 1563 | .setattr = ubifs_setattr, |
1564 | .getattr = ubifs_getattr, | 1564 | .getattr = ubifs_getattr, |
1565 | #ifdef CONFIG_UBIFS_FS_XATTR | ||
1566 | .setxattr = ubifs_setxattr, | 1565 | .setxattr = ubifs_setxattr, |
1567 | .getxattr = ubifs_getxattr, | 1566 | .getxattr = ubifs_getxattr, |
1568 | .listxattr = ubifs_listxattr, | 1567 | .listxattr = ubifs_listxattr, |
1569 | .removexattr = ubifs_removexattr, | 1568 | .removexattr = ubifs_removexattr, |
1570 | #endif | ||
1571 | }; | 1569 | }; |
1572 | 1570 | ||
1573 | const struct inode_operations ubifs_symlink_inode_operations = { | 1571 | const struct inode_operations ubifs_symlink_inode_operations = { |
diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c index ded29f6224c2..04dd6f47635e 100644 --- a/fs/ubifs/gc.c +++ b/fs/ubifs/gc.c | |||
@@ -109,7 +109,7 @@ static int switch_gc_head(struct ubifs_info *c) | |||
109 | return err; | 109 | return err; |
110 | 110 | ||
111 | c->gc_lnum = -1; | 111 | c->gc_lnum = -1; |
112 | err = ubifs_wbuf_seek_nolock(wbuf, gc_lnum, 0, UBI_LONGTERM); | 112 | err = ubifs_wbuf_seek_nolock(wbuf, gc_lnum, 0); |
113 | return err; | 113 | return err; |
114 | } | 114 | } |
115 | 115 | ||
diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c index 9228950a658f..e18b9889a51b 100644 --- a/fs/ubifs/io.c +++ b/fs/ubifs/io.c | |||
@@ -109,13 +109,13 @@ int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs, | |||
109 | if (err && (err != -EBADMSG || even_ebadmsg)) { | 109 | if (err && (err != -EBADMSG || even_ebadmsg)) { |
110 | ubifs_err("reading %d bytes from LEB %d:%d failed, error %d", | 110 | ubifs_err("reading %d bytes from LEB %d:%d failed, error %d", |
111 | len, lnum, offs, err); | 111 | len, lnum, offs, err); |
112 | dbg_dump_stack(); | 112 | dump_stack(); |
113 | } | 113 | } |
114 | return err; | 114 | return err; |
115 | } | 115 | } |
116 | 116 | ||
117 | int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs, | 117 | int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs, |
118 | int len, int dtype) | 118 | int len) |
119 | { | 119 | { |
120 | int err; | 120 | int err; |
121 | 121 | ||
@@ -123,20 +123,19 @@ int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs, | |||
123 | if (c->ro_error) | 123 | if (c->ro_error) |
124 | return -EROFS; | 124 | return -EROFS; |
125 | if (!dbg_is_tst_rcvry(c)) | 125 | if (!dbg_is_tst_rcvry(c)) |
126 | err = ubi_leb_write(c->ubi, lnum, buf, offs, len, dtype); | 126 | err = ubi_leb_write(c->ubi, lnum, buf, offs, len); |
127 | else | 127 | else |
128 | err = dbg_leb_write(c, lnum, buf, offs, len, dtype); | 128 | err = dbg_leb_write(c, lnum, buf, offs, len); |
129 | if (err) { | 129 | if (err) { |
130 | ubifs_err("writing %d bytes to LEB %d:%d failed, error %d", | 130 | ubifs_err("writing %d bytes to LEB %d:%d failed, error %d", |
131 | len, lnum, offs, err); | 131 | len, lnum, offs, err); |
132 | ubifs_ro_mode(c, err); | 132 | ubifs_ro_mode(c, err); |
133 | dbg_dump_stack(); | 133 | dump_stack(); |
134 | } | 134 | } |
135 | return err; | 135 | return err; |
136 | } | 136 | } |
137 | 137 | ||
138 | int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len, | 138 | int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len) |
139 | int dtype) | ||
140 | { | 139 | { |
141 | int err; | 140 | int err; |
142 | 141 | ||
@@ -144,14 +143,14 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len, | |||
144 | if (c->ro_error) | 143 | if (c->ro_error) |
145 | return -EROFS; | 144 | return -EROFS; |
146 | if (!dbg_is_tst_rcvry(c)) | 145 | if (!dbg_is_tst_rcvry(c)) |
147 | err = ubi_leb_change(c->ubi, lnum, buf, len, dtype); | 146 | err = ubi_leb_change(c->ubi, lnum, buf, len); |
148 | else | 147 | else |
149 | err = dbg_leb_change(c, lnum, buf, len, dtype); | 148 | err = dbg_leb_change(c, lnum, buf, len); |
150 | if (err) { | 149 | if (err) { |
151 | ubifs_err("changing %d bytes in LEB %d failed, error %d", | 150 | ubifs_err("changing %d bytes in LEB %d failed, error %d", |
152 | len, lnum, err); | 151 | len, lnum, err); |
153 | ubifs_ro_mode(c, err); | 152 | ubifs_ro_mode(c, err); |
154 | dbg_dump_stack(); | 153 | dump_stack(); |
155 | } | 154 | } |
156 | return err; | 155 | return err; |
157 | } | 156 | } |
@@ -170,12 +169,12 @@ int ubifs_leb_unmap(struct ubifs_info *c, int lnum) | |||
170 | if (err) { | 169 | if (err) { |
171 | ubifs_err("unmap LEB %d failed, error %d", lnum, err); | 170 | ubifs_err("unmap LEB %d failed, error %d", lnum, err); |
172 | ubifs_ro_mode(c, err); | 171 | ubifs_ro_mode(c, err); |
173 | dbg_dump_stack(); | 172 | dump_stack(); |
174 | } | 173 | } |
175 | return err; | 174 | return err; |
176 | } | 175 | } |
177 | 176 | ||
178 | int ubifs_leb_map(struct ubifs_info *c, int lnum, int dtype) | 177 | int ubifs_leb_map(struct ubifs_info *c, int lnum) |
179 | { | 178 | { |
180 | int err; | 179 | int err; |
181 | 180 | ||
@@ -183,13 +182,13 @@ int ubifs_leb_map(struct ubifs_info *c, int lnum, int dtype) | |||
183 | if (c->ro_error) | 182 | if (c->ro_error) |
184 | return -EROFS; | 183 | return -EROFS; |
185 | if (!dbg_is_tst_rcvry(c)) | 184 | if (!dbg_is_tst_rcvry(c)) |
186 | err = ubi_leb_map(c->ubi, lnum, dtype); | 185 | err = ubi_leb_map(c->ubi, lnum); |
187 | else | 186 | else |
188 | err = dbg_leb_map(c, lnum, dtype); | 187 | err = dbg_leb_map(c, lnum); |
189 | if (err) { | 188 | if (err) { |
190 | ubifs_err("mapping LEB %d failed, error %d", lnum, err); | 189 | ubifs_err("mapping LEB %d failed, error %d", lnum, err); |
191 | ubifs_ro_mode(c, err); | 190 | ubifs_ro_mode(c, err); |
192 | dbg_dump_stack(); | 191 | dump_stack(); |
193 | } | 192 | } |
194 | return err; | 193 | return err; |
195 | } | 194 | } |
@@ -202,7 +201,7 @@ int ubifs_is_mapped(const struct ubifs_info *c, int lnum) | |||
202 | if (err < 0) { | 201 | if (err < 0) { |
203 | ubifs_err("ubi_is_mapped failed for LEB %d, error %d", | 202 | ubifs_err("ubi_is_mapped failed for LEB %d, error %d", |
204 | lnum, err); | 203 | lnum, err); |
205 | dbg_dump_stack(); | 204 | dump_stack(); |
206 | } | 205 | } |
207 | return err; | 206 | return err; |
208 | } | 207 | } |
@@ -294,8 +293,8 @@ out_len: | |||
294 | out: | 293 | out: |
295 | if (!quiet) { | 294 | if (!quiet) { |
296 | ubifs_err("bad node at LEB %d:%d", lnum, offs); | 295 | ubifs_err("bad node at LEB %d:%d", lnum, offs); |
297 | dbg_dump_node(c, buf); | 296 | ubifs_dump_node(c, buf); |
298 | dbg_dump_stack(); | 297 | dump_stack(); |
299 | } | 298 | } |
300 | return err; | 299 | return err; |
301 | } | 300 | } |
@@ -523,8 +522,7 @@ int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf) | |||
523 | dirt = sync_len - wbuf->used; | 522 | dirt = sync_len - wbuf->used; |
524 | if (dirt) | 523 | if (dirt) |
525 | ubifs_pad(c, wbuf->buf + wbuf->used, dirt); | 524 | ubifs_pad(c, wbuf->buf + wbuf->used, dirt); |
526 | err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, wbuf->offs, sync_len, | 525 | err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, wbuf->offs, sync_len); |
527 | wbuf->dtype); | ||
528 | if (err) | 526 | if (err) |
529 | return err; | 527 | return err; |
530 | 528 | ||
@@ -562,14 +560,12 @@ int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf) | |||
562 | * @wbuf: write-buffer | 560 | * @wbuf: write-buffer |
563 | * @lnum: logical eraseblock number to seek to | 561 | * @lnum: logical eraseblock number to seek to |
564 | * @offs: logical eraseblock offset to seek to | 562 | * @offs: logical eraseblock offset to seek to |
565 | * @dtype: data type | ||
566 | * | 563 | * |
567 | * This function targets the write-buffer to logical eraseblock @lnum:@offs. | 564 | * This function targets the write-buffer to logical eraseblock @lnum:@offs. |
568 | * The write-buffer has to be empty. Returns zero in case of success and a | 565 | * The write-buffer has to be empty. Returns zero in case of success and a |
569 | * negative error code in case of failure. | 566 | * negative error code in case of failure. |
570 | */ | 567 | */ |
571 | int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs, | 568 | int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs) |
572 | int dtype) | ||
573 | { | 569 | { |
574 | const struct ubifs_info *c = wbuf->c; | 570 | const struct ubifs_info *c = wbuf->c; |
575 | 571 | ||
@@ -592,7 +588,6 @@ int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs, | |||
592 | wbuf->avail = wbuf->size; | 588 | wbuf->avail = wbuf->size; |
593 | wbuf->used = 0; | 589 | wbuf->used = 0; |
594 | spin_unlock(&wbuf->lock); | 590 | spin_unlock(&wbuf->lock); |
595 | wbuf->dtype = dtype; | ||
596 | 591 | ||
597 | return 0; | 592 | return 0; |
598 | } | 593 | } |
@@ -719,8 +714,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) | |||
719 | dbg_io("flush jhead %s wbuf to LEB %d:%d", | 714 | dbg_io("flush jhead %s wbuf to LEB %d:%d", |
720 | dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs); | 715 | dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs); |
721 | err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, | 716 | err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, |
722 | wbuf->offs, wbuf->size, | 717 | wbuf->offs, wbuf->size); |
723 | wbuf->dtype); | ||
724 | if (err) | 718 | if (err) |
725 | goto out; | 719 | goto out; |
726 | 720 | ||
@@ -756,7 +750,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) | |||
756 | dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs); | 750 | dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs); |
757 | memcpy(wbuf->buf + wbuf->used, buf, wbuf->avail); | 751 | memcpy(wbuf->buf + wbuf->used, buf, wbuf->avail); |
758 | err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, wbuf->offs, | 752 | err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, wbuf->offs, |
759 | wbuf->size, wbuf->dtype); | 753 | wbuf->size); |
760 | if (err) | 754 | if (err) |
761 | goto out; | 755 | goto out; |
762 | 756 | ||
@@ -775,7 +769,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) | |||
775 | dbg_io("write %d bytes to LEB %d:%d", | 769 | dbg_io("write %d bytes to LEB %d:%d", |
776 | wbuf->size, wbuf->lnum, wbuf->offs); | 770 | wbuf->size, wbuf->lnum, wbuf->offs); |
777 | err = ubifs_leb_write(c, wbuf->lnum, buf, wbuf->offs, | 771 | err = ubifs_leb_write(c, wbuf->lnum, buf, wbuf->offs, |
778 | wbuf->size, wbuf->dtype); | 772 | wbuf->size); |
779 | if (err) | 773 | if (err) |
780 | goto out; | 774 | goto out; |
781 | 775 | ||
@@ -797,7 +791,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) | |||
797 | dbg_io("write %d bytes to LEB %d:%d", n, wbuf->lnum, | 791 | dbg_io("write %d bytes to LEB %d:%d", n, wbuf->lnum, |
798 | wbuf->offs); | 792 | wbuf->offs); |
799 | err = ubifs_leb_write(c, wbuf->lnum, buf + written, | 793 | err = ubifs_leb_write(c, wbuf->lnum, buf + written, |
800 | wbuf->offs, n, wbuf->dtype); | 794 | wbuf->offs, n); |
801 | if (err) | 795 | if (err) |
802 | goto out; | 796 | goto out; |
803 | wbuf->offs += n; | 797 | wbuf->offs += n; |
@@ -841,9 +835,9 @@ exit: | |||
841 | out: | 835 | out: |
842 | ubifs_err("cannot write %d bytes to LEB %d:%d, error %d", | 836 | ubifs_err("cannot write %d bytes to LEB %d:%d, error %d", |
843 | len, wbuf->lnum, wbuf->offs, err); | 837 | len, wbuf->lnum, wbuf->offs, err); |
844 | dbg_dump_node(c, buf); | 838 | ubifs_dump_node(c, buf); |
845 | dbg_dump_stack(); | 839 | dump_stack(); |
846 | dbg_dump_leb(c, wbuf->lnum); | 840 | ubifs_dump_leb(c, wbuf->lnum); |
847 | return err; | 841 | return err; |
848 | } | 842 | } |
849 | 843 | ||
@@ -854,7 +848,6 @@ out: | |||
854 | * @len: node length | 848 | * @len: node length |
855 | * @lnum: logical eraseblock number | 849 | * @lnum: logical eraseblock number |
856 | * @offs: offset within the logical eraseblock | 850 | * @offs: offset within the logical eraseblock |
857 | * @dtype: node life-time hint (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN) | ||
858 | * | 851 | * |
859 | * This function automatically fills node magic number, assigns sequence | 852 | * This function automatically fills node magic number, assigns sequence |
860 | * number, and calculates node CRC checksum. The length of the @buf buffer has | 853 | * number, and calculates node CRC checksum. The length of the @buf buffer has |
@@ -863,7 +856,7 @@ out: | |||
863 | * success and a negative error code in case of failure. | 856 | * success and a negative error code in case of failure. |
864 | */ | 857 | */ |
865 | int ubifs_write_node(struct ubifs_info *c, void *buf, int len, int lnum, | 858 | int ubifs_write_node(struct ubifs_info *c, void *buf, int len, int lnum, |
866 | int offs, int dtype) | 859 | int offs) |
867 | { | 860 | { |
868 | int err, buf_len = ALIGN(len, c->min_io_size); | 861 | int err, buf_len = ALIGN(len, c->min_io_size); |
869 | 862 | ||
@@ -879,9 +872,9 @@ int ubifs_write_node(struct ubifs_info *c, void *buf, int len, int lnum, | |||
879 | return -EROFS; | 872 | return -EROFS; |
880 | 873 | ||
881 | ubifs_prepare_node(c, buf, len, 1); | 874 | ubifs_prepare_node(c, buf, len, 1); |
882 | err = ubifs_leb_write(c, lnum, buf, offs, buf_len, dtype); | 875 | err = ubifs_leb_write(c, lnum, buf, offs, buf_len); |
883 | if (err) | 876 | if (err) |
884 | dbg_dump_node(c, buf); | 877 | ubifs_dump_node(c, buf); |
885 | 878 | ||
886 | return err; | 879 | return err; |
887 | } | 880 | } |
@@ -960,8 +953,8 @@ int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len, | |||
960 | 953 | ||
961 | out: | 954 | out: |
962 | ubifs_err("bad node at LEB %d:%d", lnum, offs); | 955 | ubifs_err("bad node at LEB %d:%d", lnum, offs); |
963 | dbg_dump_node(c, buf); | 956 | ubifs_dump_node(c, buf); |
964 | dbg_dump_stack(); | 957 | dump_stack(); |
965 | return -EINVAL; | 958 | return -EINVAL; |
966 | } | 959 | } |
967 | 960 | ||
@@ -1017,8 +1010,8 @@ int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len, | |||
1017 | out: | 1010 | out: |
1018 | ubifs_err("bad node at LEB %d:%d, LEB mapping status %d", lnum, offs, | 1011 | ubifs_err("bad node at LEB %d:%d, LEB mapping status %d", lnum, offs, |
1019 | ubi_is_mapped(c->ubi, lnum)); | 1012 | ubi_is_mapped(c->ubi, lnum)); |
1020 | dbg_dump_node(c, buf); | 1013 | ubifs_dump_node(c, buf); |
1021 | dbg_dump_stack(); | 1014 | dump_stack(); |
1022 | return -EINVAL; | 1015 | return -EINVAL; |
1023 | } | 1016 | } |
1024 | 1017 | ||
@@ -1056,7 +1049,6 @@ int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf) | |||
1056 | */ | 1049 | */ |
1057 | size = c->max_write_size - (c->leb_start % c->max_write_size); | 1050 | size = c->max_write_size - (c->leb_start % c->max_write_size); |
1058 | wbuf->avail = wbuf->size = size; | 1051 | wbuf->avail = wbuf->size = size; |
1059 | wbuf->dtype = UBI_UNKNOWN; | ||
1060 | wbuf->sync_callback = NULL; | 1052 | wbuf->sync_callback = NULL; |
1061 | mutex_init(&wbuf->io_mutex); | 1053 | mutex_init(&wbuf->io_mutex); |
1062 | spin_lock_init(&wbuf->lock); | 1054 | spin_lock_init(&wbuf->lock); |
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c index 2f438ab2e7a2..12c0f154ca83 100644 --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c | |||
@@ -214,7 +214,7 @@ out: | |||
214 | err = ubifs_add_bud_to_log(c, jhead, lnum, offs); | 214 | err = ubifs_add_bud_to_log(c, jhead, lnum, offs); |
215 | if (err) | 215 | if (err) |
216 | goto out_return; | 216 | goto out_return; |
217 | err = ubifs_wbuf_seek_nolock(wbuf, lnum, offs, wbuf->dtype); | 217 | err = ubifs_wbuf_seek_nolock(wbuf, lnum, offs); |
218 | if (err) | 218 | if (err) |
219 | goto out_unlock; | 219 | goto out_unlock; |
220 | 220 | ||
@@ -385,9 +385,9 @@ out: | |||
385 | if (err == -ENOSPC) { | 385 | if (err == -ENOSPC) { |
386 | /* This are some budgeting problems, print useful information */ | 386 | /* This are some budgeting problems, print useful information */ |
387 | down_write(&c->commit_sem); | 387 | down_write(&c->commit_sem); |
388 | dbg_dump_stack(); | 388 | dump_stack(); |
389 | dbg_dump_budg(c, &c->bi); | 389 | ubifs_dump_budg(c, &c->bi); |
390 | dbg_dump_lprops(c); | 390 | ubifs_dump_lprops(c); |
391 | cmt_retries = dbg_check_lprops(c); | 391 | cmt_retries = dbg_check_lprops(c); |
392 | up_write(&c->commit_sem); | 392 | up_write(&c->commit_sem); |
393 | } | 393 | } |
@@ -1267,7 +1267,6 @@ out_free: | |||
1267 | return err; | 1267 | return err; |
1268 | } | 1268 | } |
1269 | 1269 | ||
1270 | #ifdef CONFIG_UBIFS_FS_XATTR | ||
1271 | 1270 | ||
1272 | /** | 1271 | /** |
1273 | * ubifs_jnl_delete_xattr - delete an extended attribute. | 1272 | * ubifs_jnl_delete_xattr - delete an extended attribute. |
@@ -1462,4 +1461,3 @@ out_free: | |||
1462 | return err; | 1461 | return err; |
1463 | } | 1462 | } |
1464 | 1463 | ||
1465 | #endif /* CONFIG_UBIFS_FS_XATTR */ | ||
diff --git a/fs/ubifs/log.c b/fs/ubifs/log.c index f9fd068d1ae0..c80b15d6c8de 100644 --- a/fs/ubifs/log.c +++ b/fs/ubifs/log.c | |||
@@ -29,11 +29,7 @@ | |||
29 | 29 | ||
30 | #include "ubifs.h" | 30 | #include "ubifs.h" |
31 | 31 | ||
32 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
33 | static int dbg_check_bud_bytes(struct ubifs_info *c); | 32 | static int dbg_check_bud_bytes(struct ubifs_info *c); |
34 | #else | ||
35 | #define dbg_check_bud_bytes(c) 0 | ||
36 | #endif | ||
37 | 33 | ||
38 | /** | 34 | /** |
39 | * ubifs_search_bud - search bud LEB. | 35 | * ubifs_search_bud - search bud LEB. |
@@ -262,7 +258,7 @@ int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs) | |||
262 | * an unclean reboot, because the target LEB might have been | 258 | * an unclean reboot, because the target LEB might have been |
263 | * unmapped, but not yet physically erased. | 259 | * unmapped, but not yet physically erased. |
264 | */ | 260 | */ |
265 | err = ubifs_leb_map(c, bud->lnum, UBI_SHORTTERM); | 261 | err = ubifs_leb_map(c, bud->lnum); |
266 | if (err) | 262 | if (err) |
267 | goto out_unlock; | 263 | goto out_unlock; |
268 | } | 264 | } |
@@ -270,7 +266,7 @@ int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs) | |||
270 | dbg_log("write ref LEB %d:%d", | 266 | dbg_log("write ref LEB %d:%d", |
271 | c->lhead_lnum, c->lhead_offs); | 267 | c->lhead_lnum, c->lhead_offs); |
272 | err = ubifs_write_node(c, ref, UBIFS_REF_NODE_SZ, c->lhead_lnum, | 268 | err = ubifs_write_node(c, ref, UBIFS_REF_NODE_SZ, c->lhead_lnum, |
273 | c->lhead_offs, UBI_SHORTTERM); | 269 | c->lhead_offs); |
274 | if (err) | 270 | if (err) |
275 | goto out_unlock; | 271 | goto out_unlock; |
276 | 272 | ||
@@ -422,7 +418,7 @@ int ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum) | |||
422 | 418 | ||
423 | len = ALIGN(len, c->min_io_size); | 419 | len = ALIGN(len, c->min_io_size); |
424 | dbg_log("writing commit start at LEB %d:0, len %d", c->lhead_lnum, len); | 420 | dbg_log("writing commit start at LEB %d:0, len %d", c->lhead_lnum, len); |
425 | err = ubifs_leb_write(c, c->lhead_lnum, cs, 0, len, UBI_SHORTTERM); | 421 | err = ubifs_leb_write(c, c->lhead_lnum, cs, 0, len); |
426 | if (err) | 422 | if (err) |
427 | goto out; | 423 | goto out; |
428 | 424 | ||
@@ -623,7 +619,7 @@ static int add_node(struct ubifs_info *c, void *buf, int *lnum, int *offs, | |||
623 | int sz = ALIGN(*offs, c->min_io_size), err; | 619 | int sz = ALIGN(*offs, c->min_io_size), err; |
624 | 620 | ||
625 | ubifs_pad(c, buf + *offs, sz - *offs); | 621 | ubifs_pad(c, buf + *offs, sz - *offs); |
626 | err = ubifs_leb_change(c, *lnum, buf, sz, UBI_SHORTTERM); | 622 | err = ubifs_leb_change(c, *lnum, buf, sz); |
627 | if (err) | 623 | if (err) |
628 | return err; | 624 | return err; |
629 | *lnum = ubifs_next_log_lnum(c, *lnum); | 625 | *lnum = ubifs_next_log_lnum(c, *lnum); |
@@ -702,7 +698,7 @@ int ubifs_consolidate_log(struct ubifs_info *c) | |||
702 | int sz = ALIGN(offs, c->min_io_size); | 698 | int sz = ALIGN(offs, c->min_io_size); |
703 | 699 | ||
704 | ubifs_pad(c, buf + offs, sz - offs); | 700 | ubifs_pad(c, buf + offs, sz - offs); |
705 | err = ubifs_leb_change(c, write_lnum, buf, sz, UBI_SHORTTERM); | 701 | err = ubifs_leb_change(c, write_lnum, buf, sz); |
706 | if (err) | 702 | if (err) |
707 | goto out_free; | 703 | goto out_free; |
708 | offs = ALIGN(offs, c->min_io_size); | 704 | offs = ALIGN(offs, c->min_io_size); |
@@ -734,8 +730,6 @@ out_free: | |||
734 | return err; | 730 | return err; |
735 | } | 731 | } |
736 | 732 | ||
737 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
738 | |||
739 | /** | 733 | /** |
740 | * dbg_check_bud_bytes - make sure bud bytes calculation are all right. | 734 | * dbg_check_bud_bytes - make sure bud bytes calculation are all right. |
741 | * @c: UBIFS file-system description object | 735 | * @c: UBIFS file-system description object |
@@ -767,5 +761,3 @@ static int dbg_check_bud_bytes(struct ubifs_info *c) | |||
767 | 761 | ||
768 | return err; | 762 | return err; |
769 | } | 763 | } |
770 | |||
771 | #endif /* CONFIG_UBIFS_FS_DEBUG */ | ||
diff --git a/fs/ubifs/lprops.c b/fs/ubifs/lprops.c index f8a181e647cc..86eb8e533249 100644 --- a/fs/ubifs/lprops.c +++ b/fs/ubifs/lprops.c | |||
@@ -447,7 +447,7 @@ static void change_category(struct ubifs_info *c, struct ubifs_lprops *lprops) | |||
447 | int new_cat = ubifs_categorize_lprops(c, lprops); | 447 | int new_cat = ubifs_categorize_lprops(c, lprops); |
448 | 448 | ||
449 | if (old_cat == new_cat) { | 449 | if (old_cat == new_cat) { |
450 | struct ubifs_lpt_heap *heap = &c->lpt_heap[new_cat - 1]; | 450 | struct ubifs_lpt_heap *heap; |
451 | 451 | ||
452 | /* lprops on a heap now must be moved up or down */ | 452 | /* lprops on a heap now must be moved up or down */ |
453 | if (new_cat < 1 || new_cat > LPROPS_HEAP_CNT) | 453 | if (new_cat < 1 || new_cat > LPROPS_HEAP_CNT) |
@@ -846,7 +846,9 @@ const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c) | |||
846 | return lprops; | 846 | return lprops; |
847 | } | 847 | } |
848 | 848 | ||
849 | #ifdef CONFIG_UBIFS_FS_DEBUG | 849 | /* |
850 | * Everything below is related to debugging. | ||
851 | */ | ||
850 | 852 | ||
851 | /** | 853 | /** |
852 | * dbg_check_cats - check category heaps and lists. | 854 | * dbg_check_cats - check category heaps and lists. |
@@ -1001,8 +1003,8 @@ void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat, | |||
1001 | out: | 1003 | out: |
1002 | if (err) { | 1004 | if (err) { |
1003 | dbg_msg("failed cat %d hpos %d err %d", cat, i, err); | 1005 | dbg_msg("failed cat %d hpos %d err %d", cat, i, err); |
1004 | dbg_dump_stack(); | 1006 | dump_stack(); |
1005 | dbg_dump_heap(c, heap, cat); | 1007 | ubifs_dump_heap(c, heap, cat); |
1006 | } | 1008 | } |
1007 | } | 1009 | } |
1008 | 1010 | ||
@@ -1109,8 +1111,8 @@ static int scan_check_cb(struct ubifs_info *c, | |||
1109 | if (IS_ERR(sleb)) { | 1111 | if (IS_ERR(sleb)) { |
1110 | ret = PTR_ERR(sleb); | 1112 | ret = PTR_ERR(sleb); |
1111 | if (ret == -EUCLEAN) { | 1113 | if (ret == -EUCLEAN) { |
1112 | dbg_dump_lprops(c); | 1114 | ubifs_dump_lprops(c); |
1113 | dbg_dump_budg(c, &c->bi); | 1115 | ubifs_dump_budg(c, &c->bi); |
1114 | } | 1116 | } |
1115 | goto out; | 1117 | goto out; |
1116 | } | 1118 | } |
@@ -1237,7 +1239,7 @@ out_print: | |||
1237 | ubifs_err("bad accounting of LEB %d: free %d, dirty %d flags %#x, " | 1239 | ubifs_err("bad accounting of LEB %d: free %d, dirty %d flags %#x, " |
1238 | "should be free %d, dirty %d", | 1240 | "should be free %d, dirty %d", |
1239 | lnum, lp->free, lp->dirty, lp->flags, free, dirty); | 1241 | lnum, lp->free, lp->dirty, lp->flags, free, dirty); |
1240 | dbg_dump_leb(c, lnum); | 1242 | ubifs_dump_leb(c, lnum); |
1241 | out_destroy: | 1243 | out_destroy: |
1242 | ubifs_scan_destroy(sleb); | 1244 | ubifs_scan_destroy(sleb); |
1243 | ret = -EINVAL; | 1245 | ret = -EINVAL; |
@@ -1315,5 +1317,3 @@ int dbg_check_lprops(struct ubifs_info *c) | |||
1315 | out: | 1317 | out: |
1316 | return err; | 1318 | return err; |
1317 | } | 1319 | } |
1318 | |||
1319 | #endif /* CONFIG_UBIFS_FS_DEBUG */ | ||
diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c index 66d59d0a1402..ce33b2beb151 100644 --- a/fs/ubifs/lpt.c +++ b/fs/ubifs/lpt.c | |||
@@ -701,8 +701,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first, | |||
701 | alen = ALIGN(len, c->min_io_size); | 701 | alen = ALIGN(len, c->min_io_size); |
702 | set_ltab(c, lnum, c->leb_size - alen, alen - len); | 702 | set_ltab(c, lnum, c->leb_size - alen, alen - len); |
703 | memset(p, 0xff, alen - len); | 703 | memset(p, 0xff, alen - len); |
704 | err = ubifs_leb_change(c, lnum++, buf, alen, | 704 | err = ubifs_leb_change(c, lnum++, buf, alen); |
705 | UBI_SHORTTERM); | ||
706 | if (err) | 705 | if (err) |
707 | goto out; | 706 | goto out; |
708 | p = buf; | 707 | p = buf; |
@@ -732,8 +731,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first, | |||
732 | set_ltab(c, lnum, c->leb_size - alen, | 731 | set_ltab(c, lnum, c->leb_size - alen, |
733 | alen - len); | 732 | alen - len); |
734 | memset(p, 0xff, alen - len); | 733 | memset(p, 0xff, alen - len); |
735 | err = ubifs_leb_change(c, lnum++, buf, alen, | 734 | err = ubifs_leb_change(c, lnum++, buf, alen); |
736 | UBI_SHORTTERM); | ||
737 | if (err) | 735 | if (err) |
738 | goto out; | 736 | goto out; |
739 | p = buf; | 737 | p = buf; |
@@ -780,8 +778,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first, | |||
780 | alen = ALIGN(len, c->min_io_size); | 778 | alen = ALIGN(len, c->min_io_size); |
781 | set_ltab(c, lnum, c->leb_size - alen, alen - len); | 779 | set_ltab(c, lnum, c->leb_size - alen, alen - len); |
782 | memset(p, 0xff, alen - len); | 780 | memset(p, 0xff, alen - len); |
783 | err = ubifs_leb_change(c, lnum++, buf, alen, | 781 | err = ubifs_leb_change(c, lnum++, buf, alen); |
784 | UBI_SHORTTERM); | ||
785 | if (err) | 782 | if (err) |
786 | goto out; | 783 | goto out; |
787 | p = buf; | 784 | p = buf; |
@@ -806,7 +803,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first, | |||
806 | alen = ALIGN(len, c->min_io_size); | 803 | alen = ALIGN(len, c->min_io_size); |
807 | set_ltab(c, lnum, c->leb_size - alen, alen - len); | 804 | set_ltab(c, lnum, c->leb_size - alen, alen - len); |
808 | memset(p, 0xff, alen - len); | 805 | memset(p, 0xff, alen - len); |
809 | err = ubifs_leb_change(c, lnum++, buf, alen, UBI_SHORTTERM); | 806 | err = ubifs_leb_change(c, lnum++, buf, alen); |
810 | if (err) | 807 | if (err) |
811 | goto out; | 808 | goto out; |
812 | p = buf; | 809 | p = buf; |
@@ -826,7 +823,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first, | |||
826 | 823 | ||
827 | /* Write remaining buffer */ | 824 | /* Write remaining buffer */ |
828 | memset(p, 0xff, alen - len); | 825 | memset(p, 0xff, alen - len); |
829 | err = ubifs_leb_change(c, lnum, buf, alen, UBI_SHORTTERM); | 826 | err = ubifs_leb_change(c, lnum, buf, alen); |
830 | if (err) | 827 | if (err) |
831 | goto out; | 828 | goto out; |
832 | 829 | ||
@@ -926,7 +923,7 @@ static int check_lpt_crc(void *buf, int len) | |||
926 | if (crc != calc_crc) { | 923 | if (crc != calc_crc) { |
927 | ubifs_err("invalid crc in LPT node: crc %hx calc %hx", crc, | 924 | ubifs_err("invalid crc in LPT node: crc %hx calc %hx", crc, |
928 | calc_crc); | 925 | calc_crc); |
929 | dbg_dump_stack(); | 926 | dump_stack(); |
930 | return -EINVAL; | 927 | return -EINVAL; |
931 | } | 928 | } |
932 | return 0; | 929 | return 0; |
@@ -949,7 +946,7 @@ static int check_lpt_type(uint8_t **addr, int *pos, int type) | |||
949 | if (node_type != type) { | 946 | if (node_type != type) { |
950 | ubifs_err("invalid type (%d) in LPT node type %d", node_type, | 947 | ubifs_err("invalid type (%d) in LPT node type %d", node_type, |
951 | type); | 948 | type); |
952 | dbg_dump_stack(); | 949 | dump_stack(); |
953 | return -EINVAL; | 950 | return -EINVAL; |
954 | } | 951 | } |
955 | return 0; | 952 | return 0; |
@@ -1247,7 +1244,7 @@ int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip) | |||
1247 | 1244 | ||
1248 | out: | 1245 | out: |
1249 | ubifs_err("error %d reading nnode at %d:%d", err, lnum, offs); | 1246 | ubifs_err("error %d reading nnode at %d:%d", err, lnum, offs); |
1250 | dbg_dump_stack(); | 1247 | dump_stack(); |
1251 | kfree(nnode); | 1248 | kfree(nnode); |
1252 | return err; | 1249 | return err; |
1253 | } | 1250 | } |
@@ -1312,8 +1309,8 @@ static int read_pnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip) | |||
1312 | 1309 | ||
1313 | out: | 1310 | out: |
1314 | ubifs_err("error %d reading pnode at %d:%d", err, lnum, offs); | 1311 | ubifs_err("error %d reading pnode at %d:%d", err, lnum, offs); |
1315 | dbg_dump_pnode(c, pnode, parent, iip); | 1312 | ubifs_dump_pnode(c, pnode, parent, iip); |
1316 | dbg_dump_stack(); | 1313 | dump_stack(); |
1317 | dbg_msg("calc num: %d", calc_pnode_num_from_parent(c, parent, iip)); | 1314 | dbg_msg("calc num: %d", calc_pnode_num_from_parent(c, parent, iip)); |
1318 | kfree(pnode); | 1315 | kfree(pnode); |
1319 | return err; | 1316 | return err; |
@@ -1740,16 +1737,20 @@ int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr) | |||
1740 | if (rd) { | 1737 | if (rd) { |
1741 | err = lpt_init_rd(c); | 1738 | err = lpt_init_rd(c); |
1742 | if (err) | 1739 | if (err) |
1743 | return err; | 1740 | goto out_err; |
1744 | } | 1741 | } |
1745 | 1742 | ||
1746 | if (wr) { | 1743 | if (wr) { |
1747 | err = lpt_init_wr(c); | 1744 | err = lpt_init_wr(c); |
1748 | if (err) | 1745 | if (err) |
1749 | return err; | 1746 | goto out_err; |
1750 | } | 1747 | } |
1751 | 1748 | ||
1752 | return 0; | 1749 | return 0; |
1750 | |||
1751 | out_err: | ||
1752 | ubifs_lpt_free(c, 0); | ||
1753 | return err; | ||
1753 | } | 1754 | } |
1754 | 1755 | ||
1755 | /** | 1756 | /** |
@@ -2080,8 +2081,6 @@ out: | |||
2080 | return err; | 2081 | return err; |
2081 | } | 2082 | } |
2082 | 2083 | ||
2083 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
2084 | |||
2085 | /** | 2084 | /** |
2086 | * dbg_chk_pnode - check a pnode. | 2085 | * dbg_chk_pnode - check a pnode. |
2087 | * @c: the UBIFS file-system description object | 2086 | * @c: the UBIFS file-system description object |
@@ -2096,8 +2095,8 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, | |||
2096 | int i; | 2095 | int i; |
2097 | 2096 | ||
2098 | if (pnode->num != col) { | 2097 | if (pnode->num != col) { |
2099 | dbg_err("pnode num %d expected %d parent num %d iip %d", | 2098 | ubifs_err("pnode num %d expected %d parent num %d iip %d", |
2100 | pnode->num, col, pnode->parent->num, pnode->iip); | 2099 | pnode->num, col, pnode->parent->num, pnode->iip); |
2101 | return -EINVAL; | 2100 | return -EINVAL; |
2102 | } | 2101 | } |
2103 | for (i = 0; i < UBIFS_LPT_FANOUT; i++) { | 2102 | for (i = 0; i < UBIFS_LPT_FANOUT; i++) { |
@@ -2111,14 +2110,14 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, | |||
2111 | if (lnum >= c->leb_cnt) | 2110 | if (lnum >= c->leb_cnt) |
2112 | continue; | 2111 | continue; |
2113 | if (lprops->lnum != lnum) { | 2112 | if (lprops->lnum != lnum) { |
2114 | dbg_err("bad LEB number %d expected %d", | 2113 | ubifs_err("bad LEB number %d expected %d", |
2115 | lprops->lnum, lnum); | 2114 | lprops->lnum, lnum); |
2116 | return -EINVAL; | 2115 | return -EINVAL; |
2117 | } | 2116 | } |
2118 | if (lprops->flags & LPROPS_TAKEN) { | 2117 | if (lprops->flags & LPROPS_TAKEN) { |
2119 | if (cat != LPROPS_UNCAT) { | 2118 | if (cat != LPROPS_UNCAT) { |
2120 | dbg_err("LEB %d taken but not uncat %d", | 2119 | ubifs_err("LEB %d taken but not uncat %d", |
2121 | lprops->lnum, cat); | 2120 | lprops->lnum, cat); |
2122 | return -EINVAL; | 2121 | return -EINVAL; |
2123 | } | 2122 | } |
2124 | continue; | 2123 | continue; |
@@ -2130,8 +2129,8 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, | |||
2130 | case LPROPS_FRDI_IDX: | 2129 | case LPROPS_FRDI_IDX: |
2131 | break; | 2130 | break; |
2132 | default: | 2131 | default: |
2133 | dbg_err("LEB %d index but cat %d", | 2132 | ubifs_err("LEB %d index but cat %d", |
2134 | lprops->lnum, cat); | 2133 | lprops->lnum, cat); |
2135 | return -EINVAL; | 2134 | return -EINVAL; |
2136 | } | 2135 | } |
2137 | } else { | 2136 | } else { |
@@ -2143,8 +2142,8 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, | |||
2143 | case LPROPS_FREEABLE: | 2142 | case LPROPS_FREEABLE: |
2144 | break; | 2143 | break; |
2145 | default: | 2144 | default: |
2146 | dbg_err("LEB %d not index but cat %d", | 2145 | ubifs_err("LEB %d not index but cat %d", |
2147 | lprops->lnum, cat); | 2146 | lprops->lnum, cat); |
2148 | return -EINVAL; | 2147 | return -EINVAL; |
2149 | } | 2148 | } |
2150 | } | 2149 | } |
@@ -2184,24 +2183,24 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, | |||
2184 | break; | 2183 | break; |
2185 | } | 2184 | } |
2186 | if (!found) { | 2185 | if (!found) { |
2187 | dbg_err("LEB %d cat %d not found in cat heap/list", | 2186 | ubifs_err("LEB %d cat %d not found in cat heap/list", |
2188 | lprops->lnum, cat); | 2187 | lprops->lnum, cat); |
2189 | return -EINVAL; | 2188 | return -EINVAL; |
2190 | } | 2189 | } |
2191 | switch (cat) { | 2190 | switch (cat) { |
2192 | case LPROPS_EMPTY: | 2191 | case LPROPS_EMPTY: |
2193 | if (lprops->free != c->leb_size) { | 2192 | if (lprops->free != c->leb_size) { |
2194 | dbg_err("LEB %d cat %d free %d dirty %d", | 2193 | ubifs_err("LEB %d cat %d free %d dirty %d", |
2195 | lprops->lnum, cat, lprops->free, | 2194 | lprops->lnum, cat, lprops->free, |
2196 | lprops->dirty); | 2195 | lprops->dirty); |
2197 | return -EINVAL; | 2196 | return -EINVAL; |
2198 | } | 2197 | } |
2199 | case LPROPS_FREEABLE: | 2198 | case LPROPS_FREEABLE: |
2200 | case LPROPS_FRDI_IDX: | 2199 | case LPROPS_FRDI_IDX: |
2201 | if (lprops->free + lprops->dirty != c->leb_size) { | 2200 | if (lprops->free + lprops->dirty != c->leb_size) { |
2202 | dbg_err("LEB %d cat %d free %d dirty %d", | 2201 | ubifs_err("LEB %d cat %d free %d dirty %d", |
2203 | lprops->lnum, cat, lprops->free, | 2202 | lprops->lnum, cat, lprops->free, |
2204 | lprops->dirty); | 2203 | lprops->dirty); |
2205 | return -EINVAL; | 2204 | return -EINVAL; |
2206 | } | 2205 | } |
2207 | } | 2206 | } |
@@ -2235,9 +2234,10 @@ int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode, | |||
2235 | /* cnode is a nnode */ | 2234 | /* cnode is a nnode */ |
2236 | num = calc_nnode_num(row, col); | 2235 | num = calc_nnode_num(row, col); |
2237 | if (cnode->num != num) { | 2236 | if (cnode->num != num) { |
2238 | dbg_err("nnode num %d expected %d " | 2237 | ubifs_err("nnode num %d expected %d " |
2239 | "parent num %d iip %d", cnode->num, num, | 2238 | "parent num %d iip %d", |
2240 | (nnode ? nnode->num : 0), cnode->iip); | 2239 | cnode->num, num, |
2240 | (nnode ? nnode->num : 0), cnode->iip); | ||
2241 | return -EINVAL; | 2241 | return -EINVAL; |
2242 | } | 2242 | } |
2243 | nn = (struct ubifs_nnode *)cnode; | 2243 | nn = (struct ubifs_nnode *)cnode; |
@@ -2274,5 +2274,3 @@ int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode, | |||
2274 | } | 2274 | } |
2275 | return 0; | 2275 | return 0; |
2276 | } | 2276 | } |
2277 | |||
2278 | #endif /* CONFIG_UBIFS_FS_DEBUG */ | ||
diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c index cddd6bd214f4..4fa70734e6e7 100644 --- a/fs/ubifs/lpt_commit.c +++ b/fs/ubifs/lpt_commit.c | |||
@@ -30,11 +30,7 @@ | |||
30 | #include <linux/random.h> | 30 | #include <linux/random.h> |
31 | #include "ubifs.h" | 31 | #include "ubifs.h" |
32 | 32 | ||
33 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
34 | static int dbg_populate_lsave(struct ubifs_info *c); | 33 | static int dbg_populate_lsave(struct ubifs_info *c); |
35 | #else | ||
36 | #define dbg_populate_lsave(c) 0 | ||
37 | #endif | ||
38 | 34 | ||
39 | /** | 35 | /** |
40 | * first_dirty_cnode - find first dirty cnode. | 36 | * first_dirty_cnode - find first dirty cnode. |
@@ -324,11 +320,10 @@ static int layout_cnodes(struct ubifs_info *c) | |||
324 | return 0; | 320 | return 0; |
325 | 321 | ||
326 | no_space: | 322 | no_space: |
327 | ubifs_err("LPT out of space"); | 323 | ubifs_err("LPT out of space at LEB %d:%d needing %d, done_ltab %d, " |
328 | dbg_err("LPT out of space at LEB %d:%d needing %d, done_ltab %d, " | 324 | "done_lsave %d", lnum, offs, len, done_ltab, done_lsave); |
329 | "done_lsave %d", lnum, offs, len, done_ltab, done_lsave); | 325 | ubifs_dump_lpt_info(c); |
330 | dbg_dump_lpt_info(c); | 326 | ubifs_dump_lpt_lebs(c); |
331 | dbg_dump_lpt_lebs(c); | ||
332 | dump_stack(); | 327 | dump_stack(); |
333 | return err; | 328 | return err; |
334 | } | 329 | } |
@@ -421,7 +416,7 @@ static int write_cnodes(struct ubifs_info *c) | |||
421 | alen = ALIGN(wlen, c->min_io_size); | 416 | alen = ALIGN(wlen, c->min_io_size); |
422 | memset(buf + offs, 0xff, alen - wlen); | 417 | memset(buf + offs, 0xff, alen - wlen); |
423 | err = ubifs_leb_write(c, lnum, buf + from, from, | 418 | err = ubifs_leb_write(c, lnum, buf + from, from, |
424 | alen, UBI_SHORTTERM); | 419 | alen); |
425 | if (err) | 420 | if (err) |
426 | return err; | 421 | return err; |
427 | } | 422 | } |
@@ -479,8 +474,7 @@ static int write_cnodes(struct ubifs_info *c) | |||
479 | wlen = offs - from; | 474 | wlen = offs - from; |
480 | alen = ALIGN(wlen, c->min_io_size); | 475 | alen = ALIGN(wlen, c->min_io_size); |
481 | memset(buf + offs, 0xff, alen - wlen); | 476 | memset(buf + offs, 0xff, alen - wlen); |
482 | err = ubifs_leb_write(c, lnum, buf + from, from, alen, | 477 | err = ubifs_leb_write(c, lnum, buf + from, from, alen); |
483 | UBI_SHORTTERM); | ||
484 | if (err) | 478 | if (err) |
485 | return err; | 479 | return err; |
486 | dbg_chk_lpt_sz(c, 2, c->leb_size - offs); | 480 | dbg_chk_lpt_sz(c, 2, c->leb_size - offs); |
@@ -506,8 +500,7 @@ static int write_cnodes(struct ubifs_info *c) | |||
506 | wlen = offs - from; | 500 | wlen = offs - from; |
507 | alen = ALIGN(wlen, c->min_io_size); | 501 | alen = ALIGN(wlen, c->min_io_size); |
508 | memset(buf + offs, 0xff, alen - wlen); | 502 | memset(buf + offs, 0xff, alen - wlen); |
509 | err = ubifs_leb_write(c, lnum, buf + from, from, alen, | 503 | err = ubifs_leb_write(c, lnum, buf + from, from, alen); |
510 | UBI_SHORTTERM); | ||
511 | if (err) | 504 | if (err) |
512 | return err; | 505 | return err; |
513 | dbg_chk_lpt_sz(c, 2, c->leb_size - offs); | 506 | dbg_chk_lpt_sz(c, 2, c->leb_size - offs); |
@@ -531,7 +524,7 @@ static int write_cnodes(struct ubifs_info *c) | |||
531 | wlen = offs - from; | 524 | wlen = offs - from; |
532 | alen = ALIGN(wlen, c->min_io_size); | 525 | alen = ALIGN(wlen, c->min_io_size); |
533 | memset(buf + offs, 0xff, alen - wlen); | 526 | memset(buf + offs, 0xff, alen - wlen); |
534 | err = ubifs_leb_write(c, lnum, buf + from, from, alen, UBI_SHORTTERM); | 527 | err = ubifs_leb_write(c, lnum, buf + from, from, alen); |
535 | if (err) | 528 | if (err) |
536 | return err; | 529 | return err; |
537 | 530 | ||
@@ -552,11 +545,10 @@ static int write_cnodes(struct ubifs_info *c) | |||
552 | return 0; | 545 | return 0; |
553 | 546 | ||
554 | no_space: | 547 | no_space: |
555 | ubifs_err("LPT out of space mismatch"); | 548 | ubifs_err("LPT out of space mismatch at LEB %d:%d needing %d, done_ltab " |
556 | dbg_err("LPT out of space mismatch at LEB %d:%d needing %d, done_ltab " | 549 | "%d, done_lsave %d", lnum, offs, len, done_ltab, done_lsave); |
557 | "%d, done_lsave %d", lnum, offs, len, done_ltab, done_lsave); | 550 | ubifs_dump_lpt_info(c); |
558 | dbg_dump_lpt_info(c); | 551 | ubifs_dump_lpt_lebs(c); |
559 | dbg_dump_lpt_lebs(c); | ||
560 | dump_stack(); | 552 | dump_stack(); |
561 | return err; | 553 | return err; |
562 | } | 554 | } |
@@ -1497,7 +1489,9 @@ void ubifs_lpt_free(struct ubifs_info *c, int wr_only) | |||
1497 | kfree(c->lpt_nod_buf); | 1489 | kfree(c->lpt_nod_buf); |
1498 | } | 1490 | } |
1499 | 1491 | ||
1500 | #ifdef CONFIG_UBIFS_FS_DEBUG | 1492 | /* |
1493 | * Everything below is related to debugging. | ||
1494 | */ | ||
1501 | 1495 | ||
1502 | /** | 1496 | /** |
1503 | * dbg_is_all_ff - determine if a buffer contains only 0xFF bytes. | 1497 | * dbg_is_all_ff - determine if a buffer contains only 0xFF bytes. |
@@ -1735,7 +1729,7 @@ int dbg_check_ltab(struct ubifs_info *c) | |||
1735 | for (lnum = c->lpt_first; lnum <= c->lpt_last; lnum++) { | 1729 | for (lnum = c->lpt_first; lnum <= c->lpt_last; lnum++) { |
1736 | err = dbg_check_ltab_lnum(c, lnum); | 1730 | err = dbg_check_ltab_lnum(c, lnum); |
1737 | if (err) { | 1731 | if (err) { |
1738 | dbg_err("failed at LEB %d", lnum); | 1732 | ubifs_err("failed at LEB %d", lnum); |
1739 | return err; | 1733 | return err; |
1740 | } | 1734 | } |
1741 | } | 1735 | } |
@@ -1767,10 +1761,10 @@ int dbg_chk_lpt_free_spc(struct ubifs_info *c) | |||
1767 | free += c->leb_size; | 1761 | free += c->leb_size; |
1768 | } | 1762 | } |
1769 | if (free < c->lpt_sz) { | 1763 | if (free < c->lpt_sz) { |
1770 | dbg_err("LPT space error: free %lld lpt_sz %lld", | 1764 | ubifs_err("LPT space error: free %lld lpt_sz %lld", |
1771 | free, c->lpt_sz); | 1765 | free, c->lpt_sz); |
1772 | dbg_dump_lpt_info(c); | 1766 | ubifs_dump_lpt_info(c); |
1773 | dbg_dump_lpt_lebs(c); | 1767 | ubifs_dump_lpt_lebs(c); |
1774 | dump_stack(); | 1768 | dump_stack(); |
1775 | return -EINVAL; | 1769 | return -EINVAL; |
1776 | } | 1770 | } |
@@ -1807,13 +1801,13 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len) | |||
1807 | d->chk_lpt_lebs = 0; | 1801 | d->chk_lpt_lebs = 0; |
1808 | d->chk_lpt_wastage = 0; | 1802 | d->chk_lpt_wastage = 0; |
1809 | if (c->dirty_pn_cnt > c->pnode_cnt) { | 1803 | if (c->dirty_pn_cnt > c->pnode_cnt) { |
1810 | dbg_err("dirty pnodes %d exceed max %d", | 1804 | ubifs_err("dirty pnodes %d exceed max %d", |
1811 | c->dirty_pn_cnt, c->pnode_cnt); | 1805 | c->dirty_pn_cnt, c->pnode_cnt); |
1812 | err = -EINVAL; | 1806 | err = -EINVAL; |
1813 | } | 1807 | } |
1814 | if (c->dirty_nn_cnt > c->nnode_cnt) { | 1808 | if (c->dirty_nn_cnt > c->nnode_cnt) { |
1815 | dbg_err("dirty nnodes %d exceed max %d", | 1809 | ubifs_err("dirty nnodes %d exceed max %d", |
1816 | c->dirty_nn_cnt, c->nnode_cnt); | 1810 | c->dirty_nn_cnt, c->nnode_cnt); |
1817 | err = -EINVAL; | 1811 | err = -EINVAL; |
1818 | } | 1812 | } |
1819 | return err; | 1813 | return err; |
@@ -1830,23 +1824,23 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len) | |||
1830 | chk_lpt_sz *= d->chk_lpt_lebs; | 1824 | chk_lpt_sz *= d->chk_lpt_lebs; |
1831 | chk_lpt_sz += len - c->nhead_offs; | 1825 | chk_lpt_sz += len - c->nhead_offs; |
1832 | if (d->chk_lpt_sz != chk_lpt_sz) { | 1826 | if (d->chk_lpt_sz != chk_lpt_sz) { |
1833 | dbg_err("LPT wrote %lld but space used was %lld", | 1827 | ubifs_err("LPT wrote %lld but space used was %lld", |
1834 | d->chk_lpt_sz, chk_lpt_sz); | 1828 | d->chk_lpt_sz, chk_lpt_sz); |
1835 | err = -EINVAL; | 1829 | err = -EINVAL; |
1836 | } | 1830 | } |
1837 | if (d->chk_lpt_sz > c->lpt_sz) { | 1831 | if (d->chk_lpt_sz > c->lpt_sz) { |
1838 | dbg_err("LPT wrote %lld but lpt_sz is %lld", | 1832 | ubifs_err("LPT wrote %lld but lpt_sz is %lld", |
1839 | d->chk_lpt_sz, c->lpt_sz); | 1833 | d->chk_lpt_sz, c->lpt_sz); |
1840 | err = -EINVAL; | 1834 | err = -EINVAL; |
1841 | } | 1835 | } |
1842 | if (d->chk_lpt_sz2 && d->chk_lpt_sz != d->chk_lpt_sz2) { | 1836 | if (d->chk_lpt_sz2 && d->chk_lpt_sz != d->chk_lpt_sz2) { |
1843 | dbg_err("LPT layout size %lld but wrote %lld", | 1837 | ubifs_err("LPT layout size %lld but wrote %lld", |
1844 | d->chk_lpt_sz, d->chk_lpt_sz2); | 1838 | d->chk_lpt_sz, d->chk_lpt_sz2); |
1845 | err = -EINVAL; | 1839 | err = -EINVAL; |
1846 | } | 1840 | } |
1847 | if (d->chk_lpt_sz2 && d->new_nhead_offs != len) { | 1841 | if (d->chk_lpt_sz2 && d->new_nhead_offs != len) { |
1848 | dbg_err("LPT new nhead offs: expected %d was %d", | 1842 | ubifs_err("LPT new nhead offs: expected %d was %d", |
1849 | d->new_nhead_offs, len); | 1843 | d->new_nhead_offs, len); |
1850 | err = -EINVAL; | 1844 | err = -EINVAL; |
1851 | } | 1845 | } |
1852 | lpt_sz = (long long)c->pnode_cnt * c->pnode_sz; | 1846 | lpt_sz = (long long)c->pnode_cnt * c->pnode_sz; |
@@ -1855,13 +1849,13 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len) | |||
1855 | if (c->big_lpt) | 1849 | if (c->big_lpt) |
1856 | lpt_sz += c->lsave_sz; | 1850 | lpt_sz += c->lsave_sz; |
1857 | if (d->chk_lpt_sz - d->chk_lpt_wastage > lpt_sz) { | 1851 | if (d->chk_lpt_sz - d->chk_lpt_wastage > lpt_sz) { |
1858 | dbg_err("LPT chk_lpt_sz %lld + waste %lld exceeds %lld", | 1852 | ubifs_err("LPT chk_lpt_sz %lld + waste %lld exceeds %lld", |
1859 | d->chk_lpt_sz, d->chk_lpt_wastage, lpt_sz); | 1853 | d->chk_lpt_sz, d->chk_lpt_wastage, lpt_sz); |
1860 | err = -EINVAL; | 1854 | err = -EINVAL; |
1861 | } | 1855 | } |
1862 | if (err) { | 1856 | if (err) { |
1863 | dbg_dump_lpt_info(c); | 1857 | ubifs_dump_lpt_info(c); |
1864 | dbg_dump_lpt_lebs(c); | 1858 | ubifs_dump_lpt_lebs(c); |
1865 | dump_stack(); | 1859 | dump_stack(); |
1866 | } | 1860 | } |
1867 | d->chk_lpt_sz2 = d->chk_lpt_sz; | 1861 | d->chk_lpt_sz2 = d->chk_lpt_sz; |
@@ -1880,7 +1874,7 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len) | |||
1880 | } | 1874 | } |
1881 | 1875 | ||
1882 | /** | 1876 | /** |
1883 | * dbg_dump_lpt_leb - dump an LPT LEB. | 1877 | * ubifs_dump_lpt_leb - dump an LPT LEB. |
1884 | * @c: UBIFS file-system description object | 1878 | * @c: UBIFS file-system description object |
1885 | * @lnum: LEB number to dump | 1879 | * @lnum: LEB number to dump |
1886 | * | 1880 | * |
@@ -1986,13 +1980,13 @@ out: | |||
1986 | } | 1980 | } |
1987 | 1981 | ||
1988 | /** | 1982 | /** |
1989 | * dbg_dump_lpt_lebs - dump LPT lebs. | 1983 | * ubifs_dump_lpt_lebs - dump LPT lebs. |
1990 | * @c: UBIFS file-system description object | 1984 | * @c: UBIFS file-system description object |
1991 | * | 1985 | * |
1992 | * This function dumps all LPT LEBs. The caller has to make sure the LPT is | 1986 | * This function dumps all LPT LEBs. The caller has to make sure the LPT is |
1993 | * locked. | 1987 | * locked. |
1994 | */ | 1988 | */ |
1995 | void dbg_dump_lpt_lebs(const struct ubifs_info *c) | 1989 | void ubifs_dump_lpt_lebs(const struct ubifs_info *c) |
1996 | { | 1990 | { |
1997 | int i; | 1991 | int i; |
1998 | 1992 | ||
@@ -2046,5 +2040,3 @@ static int dbg_populate_lsave(struct ubifs_info *c) | |||
2046 | 2040 | ||
2047 | return 1; | 2041 | return 1; |
2048 | } | 2042 | } |
2049 | |||
2050 | #endif /* CONFIG_UBIFS_FS_DEBUG */ | ||
diff --git a/fs/ubifs/master.c b/fs/ubifs/master.c index 278c2382e8c2..ab83ace9910a 100644 --- a/fs/ubifs/master.c +++ b/fs/ubifs/master.c | |||
@@ -241,7 +241,7 @@ static int validate_master(const struct ubifs_info *c) | |||
241 | 241 | ||
242 | out: | 242 | out: |
243 | ubifs_err("bad master node at offset %d error %d", c->mst_offs, err); | 243 | ubifs_err("bad master node at offset %d error %d", c->mst_offs, err); |
244 | dbg_dump_node(c, c->mst_node); | 244 | ubifs_dump_node(c, c->mst_node); |
245 | return -EINVAL; | 245 | return -EINVAL; |
246 | } | 246 | } |
247 | 247 | ||
@@ -317,7 +317,7 @@ int ubifs_read_master(struct ubifs_info *c) | |||
317 | if (c->leb_cnt < old_leb_cnt || | 317 | if (c->leb_cnt < old_leb_cnt || |
318 | c->leb_cnt < UBIFS_MIN_LEB_CNT) { | 318 | c->leb_cnt < UBIFS_MIN_LEB_CNT) { |
319 | ubifs_err("bad leb_cnt on master node"); | 319 | ubifs_err("bad leb_cnt on master node"); |
320 | dbg_dump_node(c, c->mst_node); | 320 | ubifs_dump_node(c, c->mst_node); |
321 | return -EINVAL; | 321 | return -EINVAL; |
322 | } | 322 | } |
323 | 323 | ||
@@ -379,7 +379,7 @@ int ubifs_write_master(struct ubifs_info *c) | |||
379 | c->mst_offs = offs; | 379 | c->mst_offs = offs; |
380 | c->mst_node->highest_inum = cpu_to_le64(c->highest_inum); | 380 | c->mst_node->highest_inum = cpu_to_le64(c->highest_inum); |
381 | 381 | ||
382 | err = ubifs_write_node(c, c->mst_node, len, lnum, offs, UBI_SHORTTERM); | 382 | err = ubifs_write_node(c, c->mst_node, len, lnum, offs); |
383 | if (err) | 383 | if (err) |
384 | return err; | 384 | return err; |
385 | 385 | ||
@@ -390,7 +390,7 @@ int ubifs_write_master(struct ubifs_info *c) | |||
390 | if (err) | 390 | if (err) |
391 | return err; | 391 | return err; |
392 | } | 392 | } |
393 | err = ubifs_write_node(c, c->mst_node, len, lnum, offs, UBI_SHORTTERM); | 393 | err = ubifs_write_node(c, c->mst_node, len, lnum, offs); |
394 | 394 | ||
395 | return err; | 395 | return err; |
396 | } | 396 | } |
diff --git a/fs/ubifs/orphan.c b/fs/ubifs/orphan.c index c542c73cfa3c..b02734db187c 100644 --- a/fs/ubifs/orphan.c +++ b/fs/ubifs/orphan.c | |||
@@ -52,11 +52,7 @@ | |||
52 | * than the maximum number of orphans allowed. | 52 | * than the maximum number of orphans allowed. |
53 | */ | 53 | */ |
54 | 54 | ||
55 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
56 | static int dbg_check_orphans(struct ubifs_info *c); | 55 | static int dbg_check_orphans(struct ubifs_info *c); |
57 | #else | ||
58 | #define dbg_check_orphans(c) 0 | ||
59 | #endif | ||
60 | 56 | ||
61 | /** | 57 | /** |
62 | * ubifs_add_orphan - add an orphan. | 58 | * ubifs_add_orphan - add an orphan. |
@@ -92,7 +88,7 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum) | |||
92 | else if (inum > o->inum) | 88 | else if (inum > o->inum) |
93 | p = &(*p)->rb_right; | 89 | p = &(*p)->rb_right; |
94 | else { | 90 | else { |
95 | dbg_err("orphaned twice"); | 91 | ubifs_err("orphaned twice"); |
96 | spin_unlock(&c->orphan_lock); | 92 | spin_unlock(&c->orphan_lock); |
97 | kfree(orphan); | 93 | kfree(orphan); |
98 | return 0; | 94 | return 0; |
@@ -158,8 +154,8 @@ void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum) | |||
158 | } | 154 | } |
159 | } | 155 | } |
160 | spin_unlock(&c->orphan_lock); | 156 | spin_unlock(&c->orphan_lock); |
161 | dbg_err("missing orphan ino %lu", (unsigned long)inum); | 157 | ubifs_err("missing orphan ino %lu", (unsigned long)inum); |
162 | dbg_dump_stack(); | 158 | dump_stack(); |
163 | } | 159 | } |
164 | 160 | ||
165 | /** | 161 | /** |
@@ -248,8 +244,7 @@ static int do_write_orph_node(struct ubifs_info *c, int len, int atomic) | |||
248 | ubifs_assert(c->ohead_offs == 0); | 244 | ubifs_assert(c->ohead_offs == 0); |
249 | ubifs_prepare_node(c, c->orph_buf, len, 1); | 245 | ubifs_prepare_node(c, c->orph_buf, len, 1); |
250 | len = ALIGN(len, c->min_io_size); | 246 | len = ALIGN(len, c->min_io_size); |
251 | err = ubifs_leb_change(c, c->ohead_lnum, c->orph_buf, len, | 247 | err = ubifs_leb_change(c, c->ohead_lnum, c->orph_buf, len); |
252 | UBI_SHORTTERM); | ||
253 | } else { | 248 | } else { |
254 | if (c->ohead_offs == 0) { | 249 | if (c->ohead_offs == 0) { |
255 | /* Ensure LEB has been unmapped */ | 250 | /* Ensure LEB has been unmapped */ |
@@ -258,7 +253,7 @@ static int do_write_orph_node(struct ubifs_info *c, int len, int atomic) | |||
258 | return err; | 253 | return err; |
259 | } | 254 | } |
260 | err = ubifs_write_node(c, c->orph_buf, len, c->ohead_lnum, | 255 | err = ubifs_write_node(c, c->orph_buf, len, c->ohead_lnum, |
261 | c->ohead_offs, UBI_SHORTTERM); | 256 | c->ohead_offs); |
262 | } | 257 | } |
263 | return err; | 258 | return err; |
264 | } | 259 | } |
@@ -569,7 +564,7 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb, | |||
569 | if (snod->type != UBIFS_ORPH_NODE) { | 564 | if (snod->type != UBIFS_ORPH_NODE) { |
570 | ubifs_err("invalid node type %d in orphan area at " | 565 | ubifs_err("invalid node type %d in orphan area at " |
571 | "%d:%d", snod->type, sleb->lnum, snod->offs); | 566 | "%d:%d", snod->type, sleb->lnum, snod->offs); |
572 | dbg_dump_node(c, snod->node); | 567 | ubifs_dump_node(c, snod->node); |
573 | return -EINVAL; | 568 | return -EINVAL; |
574 | } | 569 | } |
575 | 570 | ||
@@ -597,7 +592,7 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb, | |||
597 | ubifs_err("out of order commit number %llu in " | 592 | ubifs_err("out of order commit number %llu in " |
598 | "orphan node at %d:%d", | 593 | "orphan node at %d:%d", |
599 | cmt_no, sleb->lnum, snod->offs); | 594 | cmt_no, sleb->lnum, snod->offs); |
600 | dbg_dump_node(c, snod->node); | 595 | ubifs_dump_node(c, snod->node); |
601 | return -EINVAL; | 596 | return -EINVAL; |
602 | } | 597 | } |
603 | dbg_rcvry("out of date LEB %d", sleb->lnum); | 598 | dbg_rcvry("out of date LEB %d", sleb->lnum); |
@@ -725,7 +720,9 @@ int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only) | |||
725 | return err; | 720 | return err; |
726 | } | 721 | } |
727 | 722 | ||
728 | #ifdef CONFIG_UBIFS_FS_DEBUG | 723 | /* |
724 | * Everything below is related to debugging. | ||
725 | */ | ||
729 | 726 | ||
730 | struct check_orphan { | 727 | struct check_orphan { |
731 | struct rb_node rb; | 728 | struct rb_node rb; |
@@ -968,5 +965,3 @@ out: | |||
968 | kfree(ci.node); | 965 | kfree(ci.node); |
969 | return err; | 966 | return err; |
970 | } | 967 | } |
971 | |||
972 | #endif /* CONFIG_UBIFS_FS_DEBUG */ | ||
diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c index 2a935b317232..c30d976b4be8 100644 --- a/fs/ubifs/recovery.c +++ b/fs/ubifs/recovery.c | |||
@@ -213,10 +213,10 @@ static int write_rcvrd_mst_node(struct ubifs_info *c, | |||
213 | mst->flags |= cpu_to_le32(UBIFS_MST_RCVRY); | 213 | mst->flags |= cpu_to_le32(UBIFS_MST_RCVRY); |
214 | 214 | ||
215 | ubifs_prepare_node(c, mst, UBIFS_MST_NODE_SZ, 1); | 215 | ubifs_prepare_node(c, mst, UBIFS_MST_NODE_SZ, 1); |
216 | err = ubifs_leb_change(c, lnum, mst, sz, UBI_SHORTTERM); | 216 | err = ubifs_leb_change(c, lnum, mst, sz); |
217 | if (err) | 217 | if (err) |
218 | goto out; | 218 | goto out; |
219 | err = ubifs_leb_change(c, lnum + 1, mst, sz, UBI_SHORTTERM); | 219 | err = ubifs_leb_change(c, lnum + 1, mst, sz); |
220 | if (err) | 220 | if (err) |
221 | goto out; | 221 | goto out; |
222 | out: | 222 | out: |
@@ -362,12 +362,12 @@ out_err: | |||
362 | out_free: | 362 | out_free: |
363 | ubifs_err("failed to recover master node"); | 363 | ubifs_err("failed to recover master node"); |
364 | if (mst1) { | 364 | if (mst1) { |
365 | dbg_err("dumping first master node"); | 365 | ubifs_err("dumping first master node"); |
366 | dbg_dump_node(c, mst1); | 366 | ubifs_dump_node(c, mst1); |
367 | } | 367 | } |
368 | if (mst2) { | 368 | if (mst2) { |
369 | dbg_err("dumping second master node"); | 369 | ubifs_err("dumping second master node"); |
370 | dbg_dump_node(c, mst2); | 370 | ubifs_dump_node(c, mst2); |
371 | } | 371 | } |
372 | vfree(buf2); | 372 | vfree(buf2); |
373 | vfree(buf1); | 373 | vfree(buf1); |
@@ -555,8 +555,7 @@ static int fix_unclean_leb(struct ubifs_info *c, struct ubifs_scan_leb *sleb, | |||
555 | ubifs_pad(c, buf, pad_len); | 555 | ubifs_pad(c, buf, pad_len); |
556 | } | 556 | } |
557 | } | 557 | } |
558 | err = ubifs_leb_change(c, lnum, sleb->buf, len, | 558 | err = ubifs_leb_change(c, lnum, sleb->buf, len); |
559 | UBI_UNKNOWN); | ||
560 | if (err) | 559 | if (err) |
561 | return err; | 560 | return err; |
562 | } | 561 | } |
@@ -683,7 +682,7 @@ struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum, | |||
683 | ret, lnum, offs); | 682 | ret, lnum, offs); |
684 | break; | 683 | break; |
685 | } else { | 684 | } else { |
686 | dbg_err("unexpected return value %d", ret); | 685 | ubifs_err("unexpected return value %d", ret); |
687 | err = -EINVAL; | 686 | err = -EINVAL; |
688 | goto error; | 687 | goto error; |
689 | } | 688 | } |
@@ -789,7 +788,7 @@ struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum, | |||
789 | 788 | ||
790 | corrupted_rescan: | 789 | corrupted_rescan: |
791 | /* Re-scan the corrupted data with verbose messages */ | 790 | /* Re-scan the corrupted data with verbose messages */ |
792 | dbg_err("corruptio %d", ret); | 791 | ubifs_err("corruptio %d", ret); |
793 | ubifs_scan_a_node(c, buf, len, lnum, offs, 1); | 792 | ubifs_scan_a_node(c, buf, len, lnum, offs, 1); |
794 | corrupted: | 793 | corrupted: |
795 | ubifs_scanned_corruption(c, lnum, offs, buf); | 794 | ubifs_scanned_corruption(c, lnum, offs, buf); |
@@ -827,17 +826,17 @@ static int get_cs_sqnum(struct ubifs_info *c, int lnum, int offs, | |||
827 | goto out_free; | 826 | goto out_free; |
828 | ret = ubifs_scan_a_node(c, cs_node, UBIFS_CS_NODE_SZ, lnum, offs, 0); | 827 | ret = ubifs_scan_a_node(c, cs_node, UBIFS_CS_NODE_SZ, lnum, offs, 0); |
829 | if (ret != SCANNED_A_NODE) { | 828 | if (ret != SCANNED_A_NODE) { |
830 | dbg_err("Not a valid node"); | 829 | ubifs_err("Not a valid node"); |
831 | goto out_err; | 830 | goto out_err; |
832 | } | 831 | } |
833 | if (cs_node->ch.node_type != UBIFS_CS_NODE) { | 832 | if (cs_node->ch.node_type != UBIFS_CS_NODE) { |
834 | dbg_err("Node a CS node, type is %d", cs_node->ch.node_type); | 833 | ubifs_err("Node a CS node, type is %d", cs_node->ch.node_type); |
835 | goto out_err; | 834 | goto out_err; |
836 | } | 835 | } |
837 | if (le64_to_cpu(cs_node->cmt_no) != c->cmt_no) { | 836 | if (le64_to_cpu(cs_node->cmt_no) != c->cmt_no) { |
838 | dbg_err("CS node cmt_no %llu != current cmt_no %llu", | 837 | ubifs_err("CS node cmt_no %llu != current cmt_no %llu", |
839 | (unsigned long long)le64_to_cpu(cs_node->cmt_no), | 838 | (unsigned long long)le64_to_cpu(cs_node->cmt_no), |
840 | c->cmt_no); | 839 | c->cmt_no); |
841 | goto out_err; | 840 | goto out_err; |
842 | } | 841 | } |
843 | *cs_sqnum = le64_to_cpu(cs_node->ch.sqnum); | 842 | *cs_sqnum = le64_to_cpu(cs_node->ch.sqnum); |
@@ -941,7 +940,7 @@ static int recover_head(struct ubifs_info *c, int lnum, int offs, void *sbuf) | |||
941 | err = ubifs_leb_read(c, lnum, sbuf, 0, offs, 1); | 940 | err = ubifs_leb_read(c, lnum, sbuf, 0, offs, 1); |
942 | if (err) | 941 | if (err) |
943 | return err; | 942 | return err; |
944 | return ubifs_leb_change(c, lnum, sbuf, offs, UBI_UNKNOWN); | 943 | return ubifs_leb_change(c, lnum, sbuf, offs); |
945 | } | 944 | } |
946 | 945 | ||
947 | return 0; | 946 | return 0; |
@@ -1071,7 +1070,7 @@ static int clean_an_unclean_leb(struct ubifs_info *c, | |||
1071 | } | 1070 | } |
1072 | 1071 | ||
1073 | /* Write back the LEB atomically */ | 1072 | /* Write back the LEB atomically */ |
1074 | err = ubifs_leb_change(c, lnum, sbuf, len, UBI_UNKNOWN); | 1073 | err = ubifs_leb_change(c, lnum, sbuf, len); |
1075 | if (err) | 1074 | if (err) |
1076 | return err; | 1075 | return err; |
1077 | 1076 | ||
@@ -1138,9 +1137,9 @@ static int grab_empty_leb(struct ubifs_info *c) | |||
1138 | */ | 1137 | */ |
1139 | lnum = ubifs_find_free_leb_for_idx(c); | 1138 | lnum = ubifs_find_free_leb_for_idx(c); |
1140 | if (lnum < 0) { | 1139 | if (lnum < 0) { |
1141 | dbg_err("could not find an empty LEB"); | 1140 | ubifs_err("could not find an empty LEB"); |
1142 | dbg_dump_lprops(c); | 1141 | ubifs_dump_lprops(c); |
1143 | dbg_dump_budg(c, &c->bi); | 1142 | ubifs_dump_budg(c, &c->bi); |
1144 | return lnum; | 1143 | return lnum; |
1145 | } | 1144 | } |
1146 | 1145 | ||
@@ -1218,7 +1217,7 @@ int ubifs_rcvry_gc_commit(struct ubifs_info *c) | |||
1218 | } | 1217 | } |
1219 | mutex_unlock(&wbuf->io_mutex); | 1218 | mutex_unlock(&wbuf->io_mutex); |
1220 | if (err < 0) { | 1219 | if (err < 0) { |
1221 | dbg_err("GC failed, error %d", err); | 1220 | ubifs_err("GC failed, error %d", err); |
1222 | if (err == -EAGAIN) | 1221 | if (err == -EAGAIN) |
1223 | err = -EINVAL; | 1222 | err = -EINVAL; |
1224 | return err; | 1223 | return err; |
@@ -1472,7 +1471,7 @@ static int fix_size_in_place(struct ubifs_info *c, struct size_entry *e) | |||
1472 | len -= 1; | 1471 | len -= 1; |
1473 | len = ALIGN(len + 1, c->min_io_size); | 1472 | len = ALIGN(len + 1, c->min_io_size); |
1474 | /* Atomically write the fixed LEB back again */ | 1473 | /* Atomically write the fixed LEB back again */ |
1475 | err = ubifs_leb_change(c, lnum, c->sbuf, len, UBI_UNKNOWN); | 1474 | err = ubifs_leb_change(c, lnum, c->sbuf, len); |
1476 | if (err) | 1475 | if (err) |
1477 | goto out; | 1476 | goto out; |
1478 | dbg_rcvry("inode %lu at %d:%d size %lld -> %lld", | 1477 | dbg_rcvry("inode %lu at %d:%d size %lld -> %lld", |
diff --git a/fs/ubifs/replay.c b/fs/ubifs/replay.c index b007637f0406..3a2da7e476e5 100644 --- a/fs/ubifs/replay.c +++ b/fs/ubifs/replay.c | |||
@@ -154,8 +154,7 @@ static int set_bud_lprops(struct ubifs_info *c, struct bud_entry *b) | |||
154 | 154 | ||
155 | /* Make sure the journal head points to the latest bud */ | 155 | /* Make sure the journal head points to the latest bud */ |
156 | err = ubifs_wbuf_seek_nolock(&c->jheads[b->bud->jhead].wbuf, | 156 | err = ubifs_wbuf_seek_nolock(&c->jheads[b->bud->jhead].wbuf, |
157 | b->bud->lnum, c->leb_size - b->free, | 157 | b->bud->lnum, c->leb_size - b->free); |
158 | UBI_SHORTTERM); | ||
159 | 158 | ||
160 | out: | 159 | out: |
161 | ubifs_release_lprops(c); | 160 | ubifs_release_lprops(c); |
@@ -686,7 +685,7 @@ out: | |||
686 | 685 | ||
687 | out_dump: | 686 | out_dump: |
688 | ubifs_err("bad node is at LEB %d:%d", lnum, snod->offs); | 687 | ubifs_err("bad node is at LEB %d:%d", lnum, snod->offs); |
689 | dbg_dump_node(c, snod->node); | 688 | ubifs_dump_node(c, snod->node); |
690 | ubifs_scan_destroy(sleb); | 689 | ubifs_scan_destroy(sleb); |
691 | return -EINVAL; | 690 | return -EINVAL; |
692 | } | 691 | } |
@@ -861,16 +860,16 @@ static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf) | |||
861 | * numbers. | 860 | * numbers. |
862 | */ | 861 | */ |
863 | if (snod->type != UBIFS_CS_NODE) { | 862 | if (snod->type != UBIFS_CS_NODE) { |
864 | dbg_err("first log node at LEB %d:%d is not CS node", | 863 | ubifs_err("first log node at LEB %d:%d is not CS node", |
865 | lnum, offs); | 864 | lnum, offs); |
866 | goto out_dump; | 865 | goto out_dump; |
867 | } | 866 | } |
868 | if (le64_to_cpu(node->cmt_no) != c->cmt_no) { | 867 | if (le64_to_cpu(node->cmt_no) != c->cmt_no) { |
869 | dbg_err("first CS node at LEB %d:%d has wrong " | 868 | ubifs_err("first CS node at LEB %d:%d has wrong " |
870 | "commit number %llu expected %llu", | 869 | "commit number %llu expected %llu", |
871 | lnum, offs, | 870 | lnum, offs, |
872 | (unsigned long long)le64_to_cpu(node->cmt_no), | 871 | (unsigned long long)le64_to_cpu(node->cmt_no), |
873 | c->cmt_no); | 872 | c->cmt_no); |
874 | goto out_dump; | 873 | goto out_dump; |
875 | } | 874 | } |
876 | 875 | ||
@@ -892,7 +891,7 @@ static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf) | |||
892 | 891 | ||
893 | /* Make sure the first node sits at offset zero of the LEB */ | 892 | /* Make sure the first node sits at offset zero of the LEB */ |
894 | if (snod->offs != 0) { | 893 | if (snod->offs != 0) { |
895 | dbg_err("first node is not at zero offset"); | 894 | ubifs_err("first node is not at zero offset"); |
896 | goto out_dump; | 895 | goto out_dump; |
897 | } | 896 | } |
898 | 897 | ||
@@ -905,8 +904,8 @@ static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf) | |||
905 | } | 904 | } |
906 | 905 | ||
907 | if (snod->sqnum < c->cs_sqnum) { | 906 | if (snod->sqnum < c->cs_sqnum) { |
908 | dbg_err("bad sqnum %llu, commit sqnum %llu", | 907 | ubifs_err("bad sqnum %llu, commit sqnum %llu", |
909 | snod->sqnum, c->cs_sqnum); | 908 | snod->sqnum, c->cs_sqnum); |
910 | goto out_dump; | 909 | goto out_dump; |
911 | } | 910 | } |
912 | 911 | ||
@@ -958,7 +957,7 @@ out: | |||
958 | out_dump: | 957 | out_dump: |
959 | ubifs_err("log error detected while replaying the log at LEB %d:%d", | 958 | ubifs_err("log error detected while replaying the log at LEB %d:%d", |
960 | lnum, offs + snod->offs); | 959 | lnum, offs + snod->offs); |
961 | dbg_dump_node(c, snod->node); | 960 | ubifs_dump_node(c, snod->node); |
962 | ubifs_scan_destroy(sleb); | 961 | ubifs_scan_destroy(sleb); |
963 | return -EINVAL; | 962 | return -EINVAL; |
964 | } | 963 | } |
diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c index 771f7fb6ce92..ef3d1ba6d992 100644 --- a/fs/ubifs/sb.c +++ b/fs/ubifs/sb.c | |||
@@ -130,7 +130,6 @@ static int create_default_filesystem(struct ubifs_info *c) | |||
130 | * orphan node. | 130 | * orphan node. |
131 | */ | 131 | */ |
132 | orph_lebs = UBIFS_MIN_ORPH_LEBS; | 132 | orph_lebs = UBIFS_MIN_ORPH_LEBS; |
133 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
134 | if (c->leb_cnt - min_leb_cnt > 1) | 133 | if (c->leb_cnt - min_leb_cnt > 1) |
135 | /* | 134 | /* |
136 | * For debugging purposes it is better to have at least 2 | 135 | * For debugging purposes it is better to have at least 2 |
@@ -138,7 +137,6 @@ static int create_default_filesystem(struct ubifs_info *c) | |||
138 | * consolidations and would be stressed more. | 137 | * consolidations and would be stressed more. |
139 | */ | 138 | */ |
140 | orph_lebs += 1; | 139 | orph_lebs += 1; |
141 | #endif | ||
142 | 140 | ||
143 | main_lebs = c->leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS - log_lebs; | 141 | main_lebs = c->leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS - log_lebs; |
144 | main_lebs -= orph_lebs; | 142 | main_lebs -= orph_lebs; |
@@ -196,7 +194,7 @@ static int create_default_filesystem(struct ubifs_info *c) | |||
196 | sup->rp_size = cpu_to_le64(tmp64); | 194 | sup->rp_size = cpu_to_le64(tmp64); |
197 | sup->ro_compat_version = cpu_to_le32(UBIFS_RO_COMPAT_VERSION); | 195 | sup->ro_compat_version = cpu_to_le32(UBIFS_RO_COMPAT_VERSION); |
198 | 196 | ||
199 | err = ubifs_write_node(c, sup, UBIFS_SB_NODE_SZ, 0, 0, UBI_LONGTERM); | 197 | err = ubifs_write_node(c, sup, UBIFS_SB_NODE_SZ, 0, 0); |
200 | kfree(sup); | 198 | kfree(sup); |
201 | if (err) | 199 | if (err) |
202 | return err; | 200 | return err; |
@@ -252,14 +250,13 @@ static int create_default_filesystem(struct ubifs_info *c) | |||
252 | 250 | ||
253 | mst->total_used = cpu_to_le64(UBIFS_INO_NODE_SZ); | 251 | mst->total_used = cpu_to_le64(UBIFS_INO_NODE_SZ); |
254 | 252 | ||
255 | err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0, | 253 | err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0); |
256 | UBI_UNKNOWN); | ||
257 | if (err) { | 254 | if (err) { |
258 | kfree(mst); | 255 | kfree(mst); |
259 | return err; | 256 | return err; |
260 | } | 257 | } |
261 | err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1, 0, | 258 | err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1, |
262 | UBI_UNKNOWN); | 259 | 0); |
263 | kfree(mst); | 260 | kfree(mst); |
264 | if (err) | 261 | if (err) |
265 | return err; | 262 | return err; |
@@ -282,8 +279,7 @@ static int create_default_filesystem(struct ubifs_info *c) | |||
282 | key_write_idx(c, &key, &br->key); | 279 | key_write_idx(c, &key, &br->key); |
283 | br->lnum = cpu_to_le32(main_first + DEFAULT_DATA_LEB); | 280 | br->lnum = cpu_to_le32(main_first + DEFAULT_DATA_LEB); |
284 | br->len = cpu_to_le32(UBIFS_INO_NODE_SZ); | 281 | br->len = cpu_to_le32(UBIFS_INO_NODE_SZ); |
285 | err = ubifs_write_node(c, idx, tmp, main_first + DEFAULT_IDX_LEB, 0, | 282 | err = ubifs_write_node(c, idx, tmp, main_first + DEFAULT_IDX_LEB, 0); |
286 | UBI_UNKNOWN); | ||
287 | kfree(idx); | 283 | kfree(idx); |
288 | if (err) | 284 | if (err) |
289 | return err; | 285 | return err; |
@@ -315,8 +311,7 @@ static int create_default_filesystem(struct ubifs_info *c) | |||
315 | ino->flags = cpu_to_le32(UBIFS_COMPR_FL); | 311 | ino->flags = cpu_to_le32(UBIFS_COMPR_FL); |
316 | 312 | ||
317 | err = ubifs_write_node(c, ino, UBIFS_INO_NODE_SZ, | 313 | err = ubifs_write_node(c, ino, UBIFS_INO_NODE_SZ, |
318 | main_first + DEFAULT_DATA_LEB, 0, | 314 | main_first + DEFAULT_DATA_LEB, 0); |
319 | UBI_UNKNOWN); | ||
320 | kfree(ino); | 315 | kfree(ino); |
321 | if (err) | 316 | if (err) |
322 | return err; | 317 | return err; |
@@ -335,8 +330,7 @@ static int create_default_filesystem(struct ubifs_info *c) | |||
335 | return -ENOMEM; | 330 | return -ENOMEM; |
336 | 331 | ||
337 | cs->ch.node_type = UBIFS_CS_NODE; | 332 | cs->ch.node_type = UBIFS_CS_NODE; |
338 | err = ubifs_write_node(c, cs, UBIFS_CS_NODE_SZ, UBIFS_LOG_LNUM, | 333 | err = ubifs_write_node(c, cs, UBIFS_CS_NODE_SZ, UBIFS_LOG_LNUM, 0); |
339 | 0, UBI_UNKNOWN); | ||
340 | kfree(cs); | 334 | kfree(cs); |
341 | 335 | ||
342 | ubifs_msg("default file-system created"); | 336 | ubifs_msg("default file-system created"); |
@@ -475,7 +469,7 @@ static int validate_sb(struct ubifs_info *c, struct ubifs_sb_node *sup) | |||
475 | 469 | ||
476 | failed: | 470 | failed: |
477 | ubifs_err("bad superblock, error %d", err); | 471 | ubifs_err("bad superblock, error %d", err); |
478 | dbg_dump_node(c, sup); | 472 | ubifs_dump_node(c, sup); |
479 | return -EINVAL; | 473 | return -EINVAL; |
480 | } | 474 | } |
481 | 475 | ||
@@ -518,7 +512,7 @@ int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup) | |||
518 | int len = ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size); | 512 | int len = ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size); |
519 | 513 | ||
520 | ubifs_prepare_node(c, sup, UBIFS_SB_NODE_SZ, 1); | 514 | ubifs_prepare_node(c, sup, UBIFS_SB_NODE_SZ, 1); |
521 | return ubifs_leb_change(c, UBIFS_SB_LNUM, sup, len, UBI_LONGTERM); | 515 | return ubifs_leb_change(c, UBIFS_SB_LNUM, sup, len); |
522 | } | 516 | } |
523 | 517 | ||
524 | /** | 518 | /** |
@@ -691,7 +685,7 @@ static int fixup_leb(struct ubifs_info *c, int lnum, int len) | |||
691 | if (err) | 685 | if (err) |
692 | return err; | 686 | return err; |
693 | 687 | ||
694 | return ubifs_leb_change(c, lnum, c->sbuf, len, UBI_UNKNOWN); | 688 | return ubifs_leb_change(c, lnum, c->sbuf, len); |
695 | } | 689 | } |
696 | 690 | ||
697 | /** | 691 | /** |
diff --git a/fs/ubifs/scan.c b/fs/ubifs/scan.c index 37383e8011b1..7c40e6025fd6 100644 --- a/fs/ubifs/scan.c +++ b/fs/ubifs/scan.c | |||
@@ -101,7 +101,7 @@ int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum, | |||
101 | if (!quiet) { | 101 | if (!quiet) { |
102 | ubifs_err("bad pad node at LEB %d:%d", | 102 | ubifs_err("bad pad node at LEB %d:%d", |
103 | lnum, offs); | 103 | lnum, offs); |
104 | dbg_dump_node(c, pad); | 104 | ubifs_dump_node(c, pad); |
105 | } | 105 | } |
106 | return SCANNED_A_BAD_PAD_NODE; | 106 | return SCANNED_A_BAD_PAD_NODE; |
107 | } | 107 | } |
@@ -109,8 +109,8 @@ int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum, | |||
109 | /* Make the node pads to 8-byte boundary */ | 109 | /* Make the node pads to 8-byte boundary */ |
110 | if ((node_len + pad_len) & 7) { | 110 | if ((node_len + pad_len) & 7) { |
111 | if (!quiet) | 111 | if (!quiet) |
112 | dbg_err("bad padding length %d - %d", | 112 | ubifs_err("bad padding length %d - %d", |
113 | offs, offs + node_len + pad_len); | 113 | offs, offs + node_len + pad_len); |
114 | return SCANNED_A_BAD_PAD_NODE; | 114 | return SCANNED_A_BAD_PAD_NODE; |
115 | } | 115 | } |
116 | 116 | ||
@@ -245,7 +245,7 @@ void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs, | |||
245 | len = c->leb_size - offs; | 245 | len = c->leb_size - offs; |
246 | if (len > 8192) | 246 | if (len > 8192) |
247 | len = 8192; | 247 | len = 8192; |
248 | dbg_err("first %d bytes from LEB %d:%d", len, lnum, offs); | 248 | ubifs_err("first %d bytes from LEB %d:%d", len, lnum, offs); |
249 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 4, buf, len, 1); | 249 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 4, buf, len, 1); |
250 | } | 250 | } |
251 | 251 | ||
@@ -300,16 +300,16 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum, | |||
300 | 300 | ||
301 | switch (ret) { | 301 | switch (ret) { |
302 | case SCANNED_GARBAGE: | 302 | case SCANNED_GARBAGE: |
303 | dbg_err("garbage"); | 303 | ubifs_err("garbage"); |
304 | goto corrupted; | 304 | goto corrupted; |
305 | case SCANNED_A_NODE: | 305 | case SCANNED_A_NODE: |
306 | break; | 306 | break; |
307 | case SCANNED_A_CORRUPT_NODE: | 307 | case SCANNED_A_CORRUPT_NODE: |
308 | case SCANNED_A_BAD_PAD_NODE: | 308 | case SCANNED_A_BAD_PAD_NODE: |
309 | dbg_err("bad node"); | 309 | ubifs_err("bad node"); |
310 | goto corrupted; | 310 | goto corrupted; |
311 | default: | 311 | default: |
312 | dbg_err("unknown"); | 312 | ubifs_err("unknown"); |
313 | err = -EINVAL; | 313 | err = -EINVAL; |
314 | goto error; | 314 | goto error; |
315 | } | 315 | } |
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index 76e4e0566ad6..001acccac0d6 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c | |||
@@ -246,8 +246,8 @@ struct inode *ubifs_iget(struct super_block *sb, unsigned long inum) | |||
246 | 246 | ||
247 | out_invalid: | 247 | out_invalid: |
248 | ubifs_err("inode %lu validation failed, error %d", inode->i_ino, err); | 248 | ubifs_err("inode %lu validation failed, error %d", inode->i_ino, err); |
249 | dbg_dump_node(c, ino); | 249 | ubifs_dump_node(c, ino); |
250 | dbg_dump_inode(c, inode); | 250 | ubifs_dump_inode(c, inode); |
251 | err = -EINVAL; | 251 | err = -EINVAL; |
252 | out_ino: | 252 | out_ino: |
253 | kfree(ino); | 253 | kfree(ino); |
@@ -668,8 +668,8 @@ static int init_constants_sb(struct ubifs_info *c) | |||
668 | tmp = UBIFS_CS_NODE_SZ + UBIFS_REF_NODE_SZ * c->jhead_cnt; | 668 | tmp = UBIFS_CS_NODE_SZ + UBIFS_REF_NODE_SZ * c->jhead_cnt; |
669 | tmp = ALIGN(tmp, c->min_io_size); | 669 | tmp = ALIGN(tmp, c->min_io_size); |
670 | if (tmp > c->leb_size) { | 670 | if (tmp > c->leb_size) { |
671 | dbg_err("too small LEB size %d, at least %d needed", | 671 | ubifs_err("too small LEB size %d, at least %d needed", |
672 | c->leb_size, tmp); | 672 | c->leb_size, tmp); |
673 | return -EINVAL; | 673 | return -EINVAL; |
674 | } | 674 | } |
675 | 675 | ||
@@ -683,8 +683,8 @@ static int init_constants_sb(struct ubifs_info *c) | |||
683 | tmp /= c->leb_size; | 683 | tmp /= c->leb_size; |
684 | tmp += 1; | 684 | tmp += 1; |
685 | if (c->log_lebs < tmp) { | 685 | if (c->log_lebs < tmp) { |
686 | dbg_err("too small log %d LEBs, required min. %d LEBs", | 686 | ubifs_err("too small log %d LEBs, required min. %d LEBs", |
687 | c->log_lebs, tmp); | 687 | c->log_lebs, tmp); |
688 | return -EINVAL; | 688 | return -EINVAL; |
689 | } | 689 | } |
690 | 690 | ||
@@ -813,13 +813,10 @@ static int alloc_wbufs(struct ubifs_info *c) | |||
813 | c->jheads[i].grouped = 1; | 813 | c->jheads[i].grouped = 1; |
814 | } | 814 | } |
815 | 815 | ||
816 | c->jheads[BASEHD].wbuf.dtype = UBI_SHORTTERM; | ||
817 | /* | 816 | /* |
818 | * Garbage Collector head likely contains long-term data and | 817 | * Garbage Collector head does not need to be synchronized by timer. |
819 | * does not need to be synchronized by timer. Also GC head nodes are | 818 | * Also GC head nodes are not grouped. |
820 | * not grouped. | ||
821 | */ | 819 | */ |
822 | c->jheads[GCHD].wbuf.dtype = UBI_LONGTERM; | ||
823 | c->jheads[GCHD].wbuf.no_timer = 1; | 820 | c->jheads[GCHD].wbuf.no_timer = 1; |
824 | c->jheads[GCHD].grouped = 0; | 821 | c->jheads[GCHD].grouped = 0; |
825 | 822 | ||
@@ -863,7 +860,7 @@ static void free_orphans(struct ubifs_info *c) | |||
863 | orph = list_entry(c->orph_list.next, struct ubifs_orphan, list); | 860 | orph = list_entry(c->orph_list.next, struct ubifs_orphan, list); |
864 | list_del(&orph->list); | 861 | list_del(&orph->list); |
865 | kfree(orph); | 862 | kfree(orph); |
866 | dbg_err("orphan list not empty at unmount"); | 863 | ubifs_err("orphan list not empty at unmount"); |
867 | } | 864 | } |
868 | 865 | ||
869 | vfree(c->orph_buf); | 866 | vfree(c->orph_buf); |
@@ -1147,8 +1144,8 @@ static int check_free_space(struct ubifs_info *c) | |||
1147 | ubifs_assert(c->dark_wm > 0); | 1144 | ubifs_assert(c->dark_wm > 0); |
1148 | if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) { | 1145 | if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) { |
1149 | ubifs_err("insufficient free space to mount in R/W mode"); | 1146 | ubifs_err("insufficient free space to mount in R/W mode"); |
1150 | dbg_dump_budg(c, &c->bi); | 1147 | ubifs_dump_budg(c, &c->bi); |
1151 | dbg_dump_lprops(c); | 1148 | ubifs_dump_lprops(c); |
1152 | return -ENOSPC; | 1149 | return -ENOSPC; |
1153 | } | 1150 | } |
1154 | return 0; | 1151 | return 0; |
@@ -1301,7 +1298,7 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1301 | if (!c->ro_mount && c->space_fixup) { | 1298 | if (!c->ro_mount && c->space_fixup) { |
1302 | err = ubifs_fixup_free_space(c); | 1299 | err = ubifs_fixup_free_space(c); |
1303 | if (err) | 1300 | if (err) |
1304 | goto out_master; | 1301 | goto out_lpt; |
1305 | } | 1302 | } |
1306 | 1303 | ||
1307 | if (!c->ro_mount) { | 1304 | if (!c->ro_mount) { |
@@ -2126,8 +2123,8 @@ static struct dentry *ubifs_mount(struct file_system_type *fs_type, int flags, | |||
2126 | */ | 2123 | */ |
2127 | ubi = open_ubi(name, UBI_READONLY); | 2124 | ubi = open_ubi(name, UBI_READONLY); |
2128 | if (IS_ERR(ubi)) { | 2125 | if (IS_ERR(ubi)) { |
2129 | dbg_err("cannot open \"%s\", error %d", | 2126 | ubifs_err("cannot open \"%s\", error %d", |
2130 | name, (int)PTR_ERR(ubi)); | 2127 | name, (int)PTR_ERR(ubi)); |
2131 | return ERR_CAST(ubi); | 2128 | return ERR_CAST(ubi); |
2132 | } | 2129 | } |
2133 | 2130 | ||
diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c index abd51331345e..349f31a30f40 100644 --- a/fs/ubifs/tnc.c +++ b/fs/ubifs/tnc.c | |||
@@ -339,8 +339,8 @@ static int lnc_add(struct ubifs_info *c, struct ubifs_zbranch *zbr, | |||
339 | 339 | ||
340 | err = ubifs_validate_entry(c, dent); | 340 | err = ubifs_validate_entry(c, dent); |
341 | if (err) { | 341 | if (err) { |
342 | dbg_dump_stack(); | 342 | dump_stack(); |
343 | dbg_dump_node(c, dent); | 343 | ubifs_dump_node(c, dent); |
344 | return err; | 344 | return err; |
345 | } | 345 | } |
346 | 346 | ||
@@ -372,8 +372,8 @@ static int lnc_add_directly(struct ubifs_info *c, struct ubifs_zbranch *zbr, | |||
372 | 372 | ||
373 | err = ubifs_validate_entry(c, node); | 373 | err = ubifs_validate_entry(c, node); |
374 | if (err) { | 374 | if (err) { |
375 | dbg_dump_stack(); | 375 | dump_stack(); |
376 | dbg_dump_node(c, node); | 376 | ubifs_dump_node(c, node); |
377 | return err; | 377 | return err; |
378 | } | 378 | } |
379 | 379 | ||
@@ -1733,8 +1733,8 @@ out_err: | |||
1733 | err = -EINVAL; | 1733 | err = -EINVAL; |
1734 | out: | 1734 | out: |
1735 | ubifs_err("bad node at LEB %d:%d", zbr->lnum, zbr->offs); | 1735 | ubifs_err("bad node at LEB %d:%d", zbr->lnum, zbr->offs); |
1736 | dbg_dump_node(c, buf); | 1736 | ubifs_dump_node(c, buf); |
1737 | dbg_dump_stack(); | 1737 | dump_stack(); |
1738 | return err; | 1738 | return err; |
1739 | } | 1739 | } |
1740 | 1740 | ||
@@ -1775,7 +1775,7 @@ int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu) | |||
1775 | if (err && err != -EBADMSG) { | 1775 | if (err && err != -EBADMSG) { |
1776 | ubifs_err("failed to read from LEB %d:%d, error %d", | 1776 | ubifs_err("failed to read from LEB %d:%d, error %d", |
1777 | lnum, offs, err); | 1777 | lnum, offs, err); |
1778 | dbg_dump_stack(); | 1778 | dump_stack(); |
1779 | dbg_tnck(&bu->key, "key "); | 1779 | dbg_tnck(&bu->key, "key "); |
1780 | return err; | 1780 | return err; |
1781 | } | 1781 | } |
@@ -2403,7 +2403,7 @@ static int tnc_delete(struct ubifs_info *c, struct ubifs_znode *znode, int n) | |||
2403 | 2403 | ||
2404 | err = ubifs_add_dirt(c, zbr->lnum, zbr->len); | 2404 | err = ubifs_add_dirt(c, zbr->lnum, zbr->len); |
2405 | if (err) { | 2405 | if (err) { |
2406 | dbg_dump_znode(c, znode); | 2406 | ubifs_dump_znode(c, znode); |
2407 | return err; | 2407 | return err; |
2408 | } | 2408 | } |
2409 | 2409 | ||
@@ -2649,7 +2649,7 @@ int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key, | |||
2649 | err = ubifs_add_dirt(c, znode->zbranch[i].lnum, | 2649 | err = ubifs_add_dirt(c, znode->zbranch[i].lnum, |
2650 | znode->zbranch[i].len); | 2650 | znode->zbranch[i].len); |
2651 | if (err) { | 2651 | if (err) { |
2652 | dbg_dump_znode(c, znode); | 2652 | ubifs_dump_znode(c, znode); |
2653 | goto out_unlock; | 2653 | goto out_unlock; |
2654 | } | 2654 | } |
2655 | dbg_tnck(key, "removing key "); | 2655 | dbg_tnck(key, "removing key "); |
@@ -3275,8 +3275,6 @@ out_unlock: | |||
3275 | return err; | 3275 | return err; |
3276 | } | 3276 | } |
3277 | 3277 | ||
3278 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
3279 | |||
3280 | /** | 3278 | /** |
3281 | * dbg_check_inode_size - check if inode size is correct. | 3279 | * dbg_check_inode_size - check if inode size is correct. |
3282 | * @c: UBIFS file-system description object | 3280 | * @c: UBIFS file-system description object |
@@ -3335,13 +3333,11 @@ out_dump: | |||
3335 | (unsigned long)inode->i_ino, size, | 3333 | (unsigned long)inode->i_ino, size, |
3336 | ((loff_t)block) << UBIFS_BLOCK_SHIFT); | 3334 | ((loff_t)block) << UBIFS_BLOCK_SHIFT); |
3337 | mutex_unlock(&c->tnc_mutex); | 3335 | mutex_unlock(&c->tnc_mutex); |
3338 | dbg_dump_inode(c, inode); | 3336 | ubifs_dump_inode(c, inode); |
3339 | dbg_dump_stack(); | 3337 | dump_stack(); |
3340 | return -EINVAL; | 3338 | return -EINVAL; |
3341 | 3339 | ||
3342 | out_unlock: | 3340 | out_unlock: |
3343 | mutex_unlock(&c->tnc_mutex); | 3341 | mutex_unlock(&c->tnc_mutex); |
3344 | return err; | 3342 | return err; |
3345 | } | 3343 | } |
3346 | |||
3347 | #endif /* CONFIG_UBIFS_FS_DEBUG */ | ||
diff --git a/fs/ubifs/tnc_commit.c b/fs/ubifs/tnc_commit.c index 4c15f07a8bb2..523bbad69c0c 100644 --- a/fs/ubifs/tnc_commit.c +++ b/fs/ubifs/tnc_commit.c | |||
@@ -54,18 +54,16 @@ static int make_idx_node(struct ubifs_info *c, struct ubifs_idx_node *idx, | |||
54 | br->len = cpu_to_le32(zbr->len); | 54 | br->len = cpu_to_le32(zbr->len); |
55 | if (!zbr->lnum || !zbr->len) { | 55 | if (!zbr->lnum || !zbr->len) { |
56 | ubifs_err("bad ref in znode"); | 56 | ubifs_err("bad ref in znode"); |
57 | dbg_dump_znode(c, znode); | 57 | ubifs_dump_znode(c, znode); |
58 | if (zbr->znode) | 58 | if (zbr->znode) |
59 | dbg_dump_znode(c, zbr->znode); | 59 | ubifs_dump_znode(c, zbr->znode); |
60 | } | 60 | } |
61 | } | 61 | } |
62 | ubifs_prepare_node(c, idx, len, 0); | 62 | ubifs_prepare_node(c, idx, len, 0); |
63 | 63 | ||
64 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
65 | znode->lnum = lnum; | 64 | znode->lnum = lnum; |
66 | znode->offs = offs; | 65 | znode->offs = offs; |
67 | znode->len = len; | 66 | znode->len = len; |
68 | #endif | ||
69 | 67 | ||
70 | err = insert_old_idx_znode(c, znode); | 68 | err = insert_old_idx_znode(c, znode); |
71 | 69 | ||
@@ -322,8 +320,7 @@ static int layout_leb_in_gaps(struct ubifs_info *c, int *p) | |||
322 | 0, 0, 0); | 320 | 0, 0, 0); |
323 | if (err) | 321 | if (err) |
324 | return err; | 322 | return err; |
325 | err = ubifs_leb_change(c, lnum, c->ileb_buf, c->ileb_len, | 323 | err = ubifs_leb_change(c, lnum, c->ileb_buf, c->ileb_len); |
326 | UBI_SHORTTERM); | ||
327 | if (err) | 324 | if (err) |
328 | return err; | 325 | return err; |
329 | dbg_gc("LEB %d wrote %d index nodes", lnum, tot_written); | 326 | dbg_gc("LEB %d wrote %d index nodes", lnum, tot_written); |
@@ -388,8 +385,8 @@ static int layout_in_gaps(struct ubifs_info *c, int cnt) | |||
388 | * option which forces in-the-gaps is enabled. | 385 | * option which forces in-the-gaps is enabled. |
389 | */ | 386 | */ |
390 | ubifs_warn("out of space"); | 387 | ubifs_warn("out of space"); |
391 | dbg_dump_budg(c, &c->bi); | 388 | ubifs_dump_budg(c, &c->bi); |
392 | dbg_dump_lprops(c); | 389 | ubifs_dump_lprops(c); |
393 | } | 390 | } |
394 | /* Try to commit anyway */ | 391 | /* Try to commit anyway */ |
395 | err = 0; | 392 | err = 0; |
@@ -456,11 +453,9 @@ static int layout_in_empty_space(struct ubifs_info *c) | |||
456 | 453 | ||
457 | offs = buf_offs + used; | 454 | offs = buf_offs + used; |
458 | 455 | ||
459 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
460 | znode->lnum = lnum; | 456 | znode->lnum = lnum; |
461 | znode->offs = offs; | 457 | znode->offs = offs; |
462 | znode->len = len; | 458 | znode->len = len; |
463 | #endif | ||
464 | 459 | ||
465 | /* Update the parent */ | 460 | /* Update the parent */ |
466 | zp = znode->parent; | 461 | zp = znode->parent; |
@@ -536,10 +531,8 @@ static int layout_in_empty_space(struct ubifs_info *c) | |||
536 | break; | 531 | break; |
537 | } | 532 | } |
538 | 533 | ||
539 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
540 | c->dbg->new_ihead_lnum = lnum; | 534 | c->dbg->new_ihead_lnum = lnum; |
541 | c->dbg->new_ihead_offs = buf_offs; | 535 | c->dbg->new_ihead_offs = buf_offs; |
542 | #endif | ||
543 | 536 | ||
544 | return 0; | 537 | return 0; |
545 | } | 538 | } |
@@ -864,9 +857,9 @@ static int write_index(struct ubifs_info *c) | |||
864 | br->len = cpu_to_le32(zbr->len); | 857 | br->len = cpu_to_le32(zbr->len); |
865 | if (!zbr->lnum || !zbr->len) { | 858 | if (!zbr->lnum || !zbr->len) { |
866 | ubifs_err("bad ref in znode"); | 859 | ubifs_err("bad ref in znode"); |
867 | dbg_dump_znode(c, znode); | 860 | ubifs_dump_znode(c, znode); |
868 | if (zbr->znode) | 861 | if (zbr->znode) |
869 | dbg_dump_znode(c, zbr->znode); | 862 | ubifs_dump_znode(c, zbr->znode); |
870 | } | 863 | } |
871 | } | 864 | } |
872 | len = ubifs_idx_node_sz(c, znode->child_cnt); | 865 | len = ubifs_idx_node_sz(c, znode->child_cnt); |
@@ -881,13 +874,11 @@ static int write_index(struct ubifs_info *c) | |||
881 | } | 874 | } |
882 | offs = buf_offs + used; | 875 | offs = buf_offs + used; |
883 | 876 | ||
884 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
885 | if (lnum != znode->lnum || offs != znode->offs || | 877 | if (lnum != znode->lnum || offs != znode->offs || |
886 | len != znode->len) { | 878 | len != znode->len) { |
887 | ubifs_err("inconsistent znode posn"); | 879 | ubifs_err("inconsistent znode posn"); |
888 | return -EINVAL; | 880 | return -EINVAL; |
889 | } | 881 | } |
890 | #endif | ||
891 | 882 | ||
892 | /* Grab some stuff from znode while we still can */ | 883 | /* Grab some stuff from znode while we still can */ |
893 | cnext = znode->cnext; | 884 | cnext = znode->cnext; |
@@ -959,8 +950,7 @@ static int write_index(struct ubifs_info *c) | |||
959 | } | 950 | } |
960 | 951 | ||
961 | /* The buffer is full or there are no more znodes to do */ | 952 | /* The buffer is full or there are no more znodes to do */ |
962 | err = ubifs_leb_write(c, lnum, c->cbuf, buf_offs, blen, | 953 | err = ubifs_leb_write(c, lnum, c->cbuf, buf_offs, blen); |
963 | UBI_SHORTTERM); | ||
964 | if (err) | 954 | if (err) |
965 | return err; | 955 | return err; |
966 | buf_offs += blen; | 956 | buf_offs += blen; |
@@ -982,13 +972,11 @@ static int write_index(struct ubifs_info *c) | |||
982 | break; | 972 | break; |
983 | } | 973 | } |
984 | 974 | ||
985 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
986 | if (lnum != c->dbg->new_ihead_lnum || | 975 | if (lnum != c->dbg->new_ihead_lnum || |
987 | buf_offs != c->dbg->new_ihead_offs) { | 976 | buf_offs != c->dbg->new_ihead_offs) { |
988 | ubifs_err("inconsistent ihead"); | 977 | ubifs_err("inconsistent ihead"); |
989 | return -EINVAL; | 978 | return -EINVAL; |
990 | } | 979 | } |
991 | #endif | ||
992 | 980 | ||
993 | c->ihead_lnum = lnum; | 981 | c->ihead_lnum = lnum; |
994 | c->ihead_offs = buf_offs; | 982 | c->ihead_offs = buf_offs; |
diff --git a/fs/ubifs/tnc_misc.c b/fs/ubifs/tnc_misc.c index dc28fe6ec07a..d38ac7f9654b 100644 --- a/fs/ubifs/tnc_misc.c +++ b/fs/ubifs/tnc_misc.c | |||
@@ -293,10 +293,10 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len, | |||
293 | lnum, offs, znode->level, znode->child_cnt); | 293 | lnum, offs, znode->level, znode->child_cnt); |
294 | 294 | ||
295 | if (znode->child_cnt > c->fanout || znode->level > UBIFS_MAX_LEVELS) { | 295 | if (znode->child_cnt > c->fanout || znode->level > UBIFS_MAX_LEVELS) { |
296 | dbg_err("current fanout %d, branch count %d", | 296 | ubifs_err("current fanout %d, branch count %d", |
297 | c->fanout, znode->child_cnt); | 297 | c->fanout, znode->child_cnt); |
298 | dbg_err("max levels %d, znode level %d", | 298 | ubifs_err("max levels %d, znode level %d", |
299 | UBIFS_MAX_LEVELS, znode->level); | 299 | UBIFS_MAX_LEVELS, znode->level); |
300 | err = 1; | 300 | err = 1; |
301 | goto out_dump; | 301 | goto out_dump; |
302 | } | 302 | } |
@@ -316,7 +316,7 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len, | |||
316 | if (zbr->lnum < c->main_first || | 316 | if (zbr->lnum < c->main_first || |
317 | zbr->lnum >= c->leb_cnt || zbr->offs < 0 || | 317 | zbr->lnum >= c->leb_cnt || zbr->offs < 0 || |
318 | zbr->offs + zbr->len > c->leb_size || zbr->offs & 7) { | 318 | zbr->offs + zbr->len > c->leb_size || zbr->offs & 7) { |
319 | dbg_err("bad branch %d", i); | 319 | ubifs_err("bad branch %d", i); |
320 | err = 2; | 320 | err = 2; |
321 | goto out_dump; | 321 | goto out_dump; |
322 | } | 322 | } |
@@ -340,19 +340,19 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len, | |||
340 | type = key_type(c, &zbr->key); | 340 | type = key_type(c, &zbr->key); |
341 | if (c->ranges[type].max_len == 0) { | 341 | if (c->ranges[type].max_len == 0) { |
342 | if (zbr->len != c->ranges[type].len) { | 342 | if (zbr->len != c->ranges[type].len) { |
343 | dbg_err("bad target node (type %d) length (%d)", | 343 | ubifs_err("bad target node (type %d) length (%d)", |
344 | type, zbr->len); | 344 | type, zbr->len); |
345 | dbg_err("have to be %d", c->ranges[type].len); | 345 | ubifs_err("have to be %d", c->ranges[type].len); |
346 | err = 4; | 346 | err = 4; |
347 | goto out_dump; | 347 | goto out_dump; |
348 | } | 348 | } |
349 | } else if (zbr->len < c->ranges[type].min_len || | 349 | } else if (zbr->len < c->ranges[type].min_len || |
350 | zbr->len > c->ranges[type].max_len) { | 350 | zbr->len > c->ranges[type].max_len) { |
351 | dbg_err("bad target node (type %d) length (%d)", | 351 | ubifs_err("bad target node (type %d) length (%d)", |
352 | type, zbr->len); | 352 | type, zbr->len); |
353 | dbg_err("have to be in range of %d-%d", | 353 | ubifs_err("have to be in range of %d-%d", |
354 | c->ranges[type].min_len, | 354 | c->ranges[type].min_len, |
355 | c->ranges[type].max_len); | 355 | c->ranges[type].max_len); |
356 | err = 5; | 356 | err = 5; |
357 | goto out_dump; | 357 | goto out_dump; |
358 | } | 358 | } |
@@ -370,13 +370,13 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len, | |||
370 | 370 | ||
371 | cmp = keys_cmp(c, key1, key2); | 371 | cmp = keys_cmp(c, key1, key2); |
372 | if (cmp > 0) { | 372 | if (cmp > 0) { |
373 | dbg_err("bad key order (keys %d and %d)", i, i + 1); | 373 | ubifs_err("bad key order (keys %d and %d)", i, i + 1); |
374 | err = 6; | 374 | err = 6; |
375 | goto out_dump; | 375 | goto out_dump; |
376 | } else if (cmp == 0 && !is_hash_key(c, key1)) { | 376 | } else if (cmp == 0 && !is_hash_key(c, key1)) { |
377 | /* These can only be keys with colliding hash */ | 377 | /* These can only be keys with colliding hash */ |
378 | dbg_err("keys %d and %d are not hashed but equivalent", | 378 | ubifs_err("keys %d and %d are not hashed but equivalent", |
379 | i, i + 1); | 379 | i, i + 1); |
380 | err = 7; | 380 | err = 7; |
381 | goto out_dump; | 381 | goto out_dump; |
382 | } | 382 | } |
@@ -387,7 +387,7 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len, | |||
387 | 387 | ||
388 | out_dump: | 388 | out_dump: |
389 | ubifs_err("bad indexing node at LEB %d:%d, error %d", lnum, offs, err); | 389 | ubifs_err("bad indexing node at LEB %d:%d, error %d", lnum, offs, err); |
390 | dbg_dump_node(c, idx); | 390 | ubifs_dump_node(c, idx); |
391 | kfree(idx); | 391 | kfree(idx); |
392 | return -EINVAL; | 392 | return -EINVAL; |
393 | } | 393 | } |
@@ -486,7 +486,7 @@ int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr, | |||
486 | zbr->lnum, zbr->offs); | 486 | zbr->lnum, zbr->offs); |
487 | dbg_tnck(key, "looked for key "); | 487 | dbg_tnck(key, "looked for key "); |
488 | dbg_tnck(&key1, "but found node's key "); | 488 | dbg_tnck(&key1, "but found node's key "); |
489 | dbg_dump_node(c, node); | 489 | ubifs_dump_node(c, node); |
490 | return -EINVAL; | 490 | return -EINVAL; |
491 | } | 491 | } |
492 | 492 | ||
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 93d59aceaaef..1e5a08623d11 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h | |||
@@ -650,8 +650,6 @@ typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c, | |||
650 | * @avail: number of bytes available in the write-buffer | 650 | * @avail: number of bytes available in the write-buffer |
651 | * @used: number of used bytes in the write-buffer | 651 | * @used: number of used bytes in the write-buffer |
652 | * @size: write-buffer size (in [@c->min_io_size, @c->max_write_size] range) | 652 | * @size: write-buffer size (in [@c->min_io_size, @c->max_write_size] range) |
653 | * @dtype: type of data stored in this LEB (%UBI_LONGTERM, %UBI_SHORTTERM, | ||
654 | * %UBI_UNKNOWN) | ||
655 | * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep | 653 | * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep |
656 | * up by 'mutex_lock_nested()). | 654 | * up by 'mutex_lock_nested()). |
657 | * @sync_callback: write-buffer synchronization callback | 655 | * @sync_callback: write-buffer synchronization callback |
@@ -685,7 +683,6 @@ struct ubifs_wbuf { | |||
685 | int avail; | 683 | int avail; |
686 | int used; | 684 | int used; |
687 | int size; | 685 | int size; |
688 | int dtype; | ||
689 | int jhead; | 686 | int jhead; |
690 | int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad); | 687 | int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad); |
691 | struct mutex io_mutex; | 688 | struct mutex io_mutex; |
@@ -762,6 +759,9 @@ struct ubifs_zbranch { | |||
762 | * @offs: offset of the corresponding indexing node | 759 | * @offs: offset of the corresponding indexing node |
763 | * @len: length of the corresponding indexing node | 760 | * @len: length of the corresponding indexing node |
764 | * @zbranch: array of znode branches (@c->fanout elements) | 761 | * @zbranch: array of znode branches (@c->fanout elements) |
762 | * | ||
763 | * Note! The @lnum, @offs, and @len fields are not really needed - we have them | ||
764 | * only for internal consistency check. They could be removed to save some RAM. | ||
765 | */ | 765 | */ |
766 | struct ubifs_znode { | 766 | struct ubifs_znode { |
767 | struct ubifs_znode *parent; | 767 | struct ubifs_znode *parent; |
@@ -772,9 +772,9 @@ struct ubifs_znode { | |||
772 | int child_cnt; | 772 | int child_cnt; |
773 | int iip; | 773 | int iip; |
774 | int alt; | 774 | int alt; |
775 | #ifdef CONFIG_UBIFS_FS_DEBUG | 775 | int lnum; |
776 | int lnum, offs, len; | 776 | int offs; |
777 | #endif | 777 | int len; |
778 | struct ubifs_zbranch zbranch[]; | 778 | struct ubifs_zbranch zbranch[]; |
779 | }; | 779 | }; |
780 | 780 | ||
@@ -1444,9 +1444,7 @@ struct ubifs_info { | |||
1444 | struct rb_root size_tree; | 1444 | struct rb_root size_tree; |
1445 | struct ubifs_mount_opts mount_opts; | 1445 | struct ubifs_mount_opts mount_opts; |
1446 | 1446 | ||
1447 | #ifdef CONFIG_UBIFS_FS_DEBUG | ||
1448 | struct ubifs_debug_info *dbg; | 1447 | struct ubifs_debug_info *dbg; |
1449 | #endif | ||
1450 | }; | 1448 | }; |
1451 | 1449 | ||
1452 | extern struct list_head ubifs_infos; | 1450 | extern struct list_head ubifs_infos; |
@@ -1468,22 +1466,20 @@ void ubifs_ro_mode(struct ubifs_info *c, int err); | |||
1468 | int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs, | 1466 | int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs, |
1469 | int len, int even_ebadmsg); | 1467 | int len, int even_ebadmsg); |
1470 | int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs, | 1468 | int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs, |
1471 | int len, int dtype); | 1469 | int len); |
1472 | int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len, | 1470 | int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len); |
1473 | int dtype); | ||
1474 | int ubifs_leb_unmap(struct ubifs_info *c, int lnum); | 1471 | int ubifs_leb_unmap(struct ubifs_info *c, int lnum); |
1475 | int ubifs_leb_map(struct ubifs_info *c, int lnum, int dtype); | 1472 | int ubifs_leb_map(struct ubifs_info *c, int lnum); |
1476 | int ubifs_is_mapped(const struct ubifs_info *c, int lnum); | 1473 | int ubifs_is_mapped(const struct ubifs_info *c, int lnum); |
1477 | int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len); | 1474 | int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len); |
1478 | int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs, | 1475 | int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs); |
1479 | int dtype); | ||
1480 | int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf); | 1476 | int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf); |
1481 | int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len, | 1477 | int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len, |
1482 | int lnum, int offs); | 1478 | int lnum, int offs); |
1483 | int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len, | 1479 | int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len, |
1484 | int lnum, int offs); | 1480 | int lnum, int offs); |
1485 | int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum, | 1481 | int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum, |
1486 | int offs, int dtype); | 1482 | int offs); |
1487 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, | 1483 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, |
1488 | int offs, int quiet, int must_chk_crc); | 1484 | int offs, int quiet, int must_chk_crc); |
1489 | void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); | 1485 | void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); |
diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c index 7a8bafa19c9f..0f7139bdb2c2 100644 --- a/fs/ubifs/xattr.c +++ b/fs/ubifs/xattr.c | |||
@@ -399,8 +399,8 @@ ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf, | |||
399 | if (buf) { | 399 | if (buf) { |
400 | /* If @buf is %NULL we are supposed to return the length */ | 400 | /* If @buf is %NULL we are supposed to return the length */ |
401 | if (ui->data_len > size) { | 401 | if (ui->data_len > size) { |
402 | dbg_err("buffer size %zd, xattr len %d", | 402 | ubifs_err("buffer size %zd, xattr len %d", |
403 | size, ui->data_len); | 403 | size, ui->data_len); |
404 | err = -ERANGE; | 404 | err = -ERANGE; |
405 | goto out_iput; | 405 | goto out_iput; |
406 | } | 406 | } |
diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h index db4836bed514..c3918a0684fe 100644 --- a/include/linux/mtd/ubi.h +++ b/include/linux/mtd/ubi.h | |||
@@ -25,6 +25,9 @@ | |||
25 | #include <linux/types.h> | 25 | #include <linux/types.h> |
26 | #include <mtd/ubi-user.h> | 26 | #include <mtd/ubi-user.h> |
27 | 27 | ||
28 | /* All voumes/LEBs */ | ||
29 | #define UBI_ALL -1 | ||
30 | |||
28 | /* | 31 | /* |
29 | * enum ubi_open_mode - UBI volume open mode constants. | 32 | * enum ubi_open_mode - UBI volume open mode constants. |
30 | * | 33 | * |
@@ -208,14 +211,15 @@ void ubi_close_volume(struct ubi_volume_desc *desc); | |||
208 | int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset, | 211 | int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset, |
209 | int len, int check); | 212 | int len, int check); |
210 | int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, | 213 | int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, |
211 | int offset, int len, int dtype); | 214 | int offset, int len); |
212 | int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, | 215 | int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, |
213 | int len, int dtype); | 216 | int len); |
214 | int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum); | 217 | int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum); |
215 | int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum); | 218 | int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum); |
216 | int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype); | 219 | int ubi_leb_map(struct ubi_volume_desc *desc, int lnum); |
217 | int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum); | 220 | int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum); |
218 | int ubi_sync(int ubi_num); | 221 | int ubi_sync(int ubi_num); |
222 | int ubi_flush(int ubi_num, int vol_id, int lnum); | ||
219 | 223 | ||
220 | /* | 224 | /* |
221 | * This function is the same as the 'ubi_leb_read()' function, but it does not | 225 | * This function is the same as the 'ubi_leb_read()' function, but it does not |
@@ -226,25 +230,4 @@ static inline int ubi_read(struct ubi_volume_desc *desc, int lnum, char *buf, | |||
226 | { | 230 | { |
227 | return ubi_leb_read(desc, lnum, buf, offset, len, 0); | 231 | return ubi_leb_read(desc, lnum, buf, offset, len, 0); |
228 | } | 232 | } |
229 | |||
230 | /* | ||
231 | * This function is the same as the 'ubi_leb_write()' functions, but it does | ||
232 | * not have the data type argument. | ||
233 | */ | ||
234 | static inline int ubi_write(struct ubi_volume_desc *desc, int lnum, | ||
235 | const void *buf, int offset, int len) | ||
236 | { | ||
237 | return ubi_leb_write(desc, lnum, buf, offset, len, UBI_UNKNOWN); | ||
238 | } | ||
239 | |||
240 | /* | ||
241 | * This function is the same as the 'ubi_leb_change()' functions, but it does | ||
242 | * not have the data type argument. | ||
243 | */ | ||
244 | static inline int ubi_change(struct ubi_volume_desc *desc, int lnum, | ||
245 | const void *buf, int len) | ||
246 | { | ||
247 | return ubi_leb_change(desc, lnum, buf, len, UBI_UNKNOWN); | ||
248 | } | ||
249 | |||
250 | #endif /* !__LINUX_UBI_H__ */ | 233 | #endif /* !__LINUX_UBI_H__ */ |
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h index 3c4109777aff..8787349fbafe 100644 --- a/include/mtd/ubi-user.h +++ b/include/mtd/ubi-user.h | |||
@@ -196,23 +196,6 @@ | |||
196 | #define UBI_MAX_RNVOL 32 | 196 | #define UBI_MAX_RNVOL 32 |
197 | 197 | ||
198 | /* | 198 | /* |
199 | * UBI data type hint constants. | ||
200 | * | ||
201 | * UBI_LONGTERM: long-term data | ||
202 | * UBI_SHORTTERM: short-term data | ||
203 | * UBI_UNKNOWN: data persistence is unknown | ||
204 | * | ||
205 | * These constants are used when data is written to UBI volumes in order to | ||
206 | * help the UBI wear-leveling unit to find more appropriate physical | ||
207 | * eraseblocks. | ||
208 | */ | ||
209 | enum { | ||
210 | UBI_LONGTERM = 1, | ||
211 | UBI_SHORTTERM = 2, | ||
212 | UBI_UNKNOWN = 3, | ||
213 | }; | ||
214 | |||
215 | /* | ||
216 | * UBI volume type constants. | 199 | * UBI volume type constants. |
217 | * | 200 | * |
218 | * @UBI_DYNAMIC_VOLUME: dynamic volume | 201 | * @UBI_DYNAMIC_VOLUME: dynamic volume |
@@ -375,25 +358,34 @@ struct ubi_rnvol_req { | |||
375 | * requests. | 358 | * requests. |
376 | * @lnum: logical eraseblock number to change | 359 | * @lnum: logical eraseblock number to change |
377 | * @bytes: how many bytes will be written to the logical eraseblock | 360 | * @bytes: how many bytes will be written to the logical eraseblock |
378 | * @dtype: data type (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN) | 361 | * @dtype: pass "3" for better compatibility with old kernels |
379 | * @padding: reserved for future, not used, has to be zeroed | 362 | * @padding: reserved for future, not used, has to be zeroed |
363 | * | ||
364 | * The @dtype field used to inform UBI about what kind of data will be written | ||
365 | * to the LEB: long term (value 1), short term (value 2), unknown (value 3). | ||
366 | * UBI tried to pick a PEB with lower erase counter for short term data and a | ||
367 | * PEB with higher erase counter for long term data. But this was not really | ||
368 | * used because users usually do not know this and could easily mislead UBI. We | ||
369 | * removed this feature in May 2012. UBI currently just ignores the @dtype | ||
370 | * field. But for better compatibility with older kernels it is recommended to | ||
371 | * set @dtype to 3 (unknown). | ||
380 | */ | 372 | */ |
381 | struct ubi_leb_change_req { | 373 | struct ubi_leb_change_req { |
382 | __s32 lnum; | 374 | __s32 lnum; |
383 | __s32 bytes; | 375 | __s32 bytes; |
384 | __s8 dtype; | 376 | __s8 dtype; /* obsolete, do not use! */ |
385 | __s8 padding[7]; | 377 | __s8 padding[7]; |
386 | } __packed; | 378 | } __packed; |
387 | 379 | ||
388 | /** | 380 | /** |
389 | * struct ubi_map_req - a data structure used in map LEB requests. | 381 | * struct ubi_map_req - a data structure used in map LEB requests. |
382 | * @dtype: pass "3" for better compatibility with old kernels | ||
390 | * @lnum: logical eraseblock number to unmap | 383 | * @lnum: logical eraseblock number to unmap |
391 | * @dtype: data type (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN) | ||
392 | * @padding: reserved for future, not used, has to be zeroed | 384 | * @padding: reserved for future, not used, has to be zeroed |
393 | */ | 385 | */ |
394 | struct ubi_map_req { | 386 | struct ubi_map_req { |
395 | __s32 lnum; | 387 | __s32 lnum; |
396 | __s8 dtype; | 388 | __s8 dtype; /* obsolete, do not use! */ |
397 | __s8 padding[3]; | 389 | __s8 padding[3]; |
398 | } __packed; | 390 | } __packed; |
399 | 391 | ||