diff options
Diffstat (limited to 'fs/jffs2/nodemgmt.c')
-rw-r--r-- | fs/jffs2/nodemgmt.c | 214 |
1 files changed, 130 insertions, 84 deletions
diff --git a/fs/jffs2/nodemgmt.c b/fs/jffs2/nodemgmt.c index 694aa5b0350..6784d1e7a7e 100644 --- a/fs/jffs2/nodemgmt.c +++ b/fs/jffs2/nodemgmt.c | |||
@@ -9,6 +9,8 @@ | |||
9 | * | 9 | * |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
13 | |||
12 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
13 | #include <linux/mtd/mtd.h> | 15 | #include <linux/mtd/mtd.h> |
14 | #include <linux/compiler.h> | 16 | #include <linux/compiler.h> |
@@ -46,10 +48,10 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, | |||
46 | /* align it */ | 48 | /* align it */ |
47 | minsize = PAD(minsize); | 49 | minsize = PAD(minsize); |
48 | 50 | ||
49 | D1(printk(KERN_DEBUG "jffs2_reserve_space(): Requested 0x%x bytes\n", minsize)); | 51 | jffs2_dbg(1, "%s(): Requested 0x%x bytes\n", __func__, minsize); |
50 | mutex_lock(&c->alloc_sem); | 52 | mutex_lock(&c->alloc_sem); |
51 | 53 | ||
52 | D1(printk(KERN_DEBUG "jffs2_reserve_space(): alloc sem got\n")); | 54 | jffs2_dbg(1, "%s(): alloc sem got\n", __func__); |
53 | 55 | ||
54 | spin_lock(&c->erase_completion_lock); | 56 | spin_lock(&c->erase_completion_lock); |
55 | 57 | ||
@@ -73,11 +75,13 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, | |||
73 | dirty = c->dirty_size + c->erasing_size - c->nr_erasing_blocks * c->sector_size + c->unchecked_size; | 75 | dirty = c->dirty_size + c->erasing_size - c->nr_erasing_blocks * c->sector_size + c->unchecked_size; |
74 | if (dirty < c->nospc_dirty_size) { | 76 | if (dirty < c->nospc_dirty_size) { |
75 | if (prio == ALLOC_DELETION && c->nr_free_blocks + c->nr_erasing_blocks >= c->resv_blocks_deletion) { | 77 | if (prio == ALLOC_DELETION && c->nr_free_blocks + c->nr_erasing_blocks >= c->resv_blocks_deletion) { |
76 | D1(printk(KERN_NOTICE "jffs2_reserve_space(): Low on dirty space to GC, but it's a deletion. Allowing...\n")); | 78 | jffs2_dbg(1, "%s(): Low on dirty space to GC, but it's a deletion. Allowing...\n", |
79 | __func__); | ||
77 | break; | 80 | break; |
78 | } | 81 | } |
79 | D1(printk(KERN_DEBUG "dirty size 0x%08x + unchecked_size 0x%08x < nospc_dirty_size 0x%08x, returning -ENOSPC\n", | 82 | jffs2_dbg(1, "dirty size 0x%08x + unchecked_size 0x%08x < nospc_dirty_size 0x%08x, returning -ENOSPC\n", |
80 | dirty, c->unchecked_size, c->sector_size)); | 83 | dirty, c->unchecked_size, |
84 | c->sector_size); | ||
81 | 85 | ||
82 | spin_unlock(&c->erase_completion_lock); | 86 | spin_unlock(&c->erase_completion_lock); |
83 | mutex_unlock(&c->alloc_sem); | 87 | mutex_unlock(&c->alloc_sem); |
@@ -96,12 +100,13 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, | |||
96 | avail = c->free_size + c->dirty_size + c->erasing_size + c->unchecked_size; | 100 | avail = c->free_size + c->dirty_size + c->erasing_size + c->unchecked_size; |
97 | if ( (avail / c->sector_size) <= blocksneeded) { | 101 | if ( (avail / c->sector_size) <= blocksneeded) { |
98 | if (prio == ALLOC_DELETION && c->nr_free_blocks + c->nr_erasing_blocks >= c->resv_blocks_deletion) { | 102 | if (prio == ALLOC_DELETION && c->nr_free_blocks + c->nr_erasing_blocks >= c->resv_blocks_deletion) { |
99 | D1(printk(KERN_NOTICE "jffs2_reserve_space(): Low on possibly available space, but it's a deletion. Allowing...\n")); | 103 | jffs2_dbg(1, "%s(): Low on possibly available space, but it's a deletion. Allowing...\n", |
104 | __func__); | ||
100 | break; | 105 | break; |
101 | } | 106 | } |
102 | 107 | ||
103 | D1(printk(KERN_DEBUG "max. available size 0x%08x < blocksneeded * sector_size 0x%08x, returning -ENOSPC\n", | 108 | jffs2_dbg(1, "max. available size 0x%08x < blocksneeded * sector_size 0x%08x, returning -ENOSPC\n", |
104 | avail, blocksneeded * c->sector_size)); | 109 | avail, blocksneeded * c->sector_size); |
105 | spin_unlock(&c->erase_completion_lock); | 110 | spin_unlock(&c->erase_completion_lock); |
106 | mutex_unlock(&c->alloc_sem); | 111 | mutex_unlock(&c->alloc_sem); |
107 | return -ENOSPC; | 112 | return -ENOSPC; |
@@ -109,9 +114,14 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, | |||
109 | 114 | ||
110 | mutex_unlock(&c->alloc_sem); | 115 | mutex_unlock(&c->alloc_sem); |
111 | 116 | ||
112 | D1(printk(KERN_DEBUG "Triggering GC pass. nr_free_blocks %d, nr_erasing_blocks %d, free_size 0x%08x, dirty_size 0x%08x, wasted_size 0x%08x, used_size 0x%08x, erasing_size 0x%08x, bad_size 0x%08x (total 0x%08x of 0x%08x)\n", | 117 | jffs2_dbg(1, "Triggering GC pass. nr_free_blocks %d, nr_erasing_blocks %d, free_size 0x%08x, dirty_size 0x%08x, wasted_size 0x%08x, used_size 0x%08x, erasing_size 0x%08x, bad_size 0x%08x (total 0x%08x of 0x%08x)\n", |
113 | c->nr_free_blocks, c->nr_erasing_blocks, c->free_size, c->dirty_size, c->wasted_size, c->used_size, c->erasing_size, c->bad_size, | 118 | c->nr_free_blocks, c->nr_erasing_blocks, |
114 | c->free_size + c->dirty_size + c->wasted_size + c->used_size + c->erasing_size + c->bad_size, c->flash_size)); | 119 | c->free_size, c->dirty_size, c->wasted_size, |
120 | c->used_size, c->erasing_size, c->bad_size, | ||
121 | c->free_size + c->dirty_size + | ||
122 | c->wasted_size + c->used_size + | ||
123 | c->erasing_size + c->bad_size, | ||
124 | c->flash_size); | ||
115 | spin_unlock(&c->erase_completion_lock); | 125 | spin_unlock(&c->erase_completion_lock); |
116 | 126 | ||
117 | ret = jffs2_garbage_collect_pass(c); | 127 | ret = jffs2_garbage_collect_pass(c); |
@@ -124,7 +134,8 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, | |||
124 | DECLARE_WAITQUEUE(wait, current); | 134 | DECLARE_WAITQUEUE(wait, current); |
125 | set_current_state(TASK_UNINTERRUPTIBLE); | 135 | set_current_state(TASK_UNINTERRUPTIBLE); |
126 | add_wait_queue(&c->erase_wait, &wait); | 136 | add_wait_queue(&c->erase_wait, &wait); |
127 | D1(printk(KERN_DEBUG "%s waiting for erase to complete\n", __func__)); | 137 | jffs2_dbg(1, "%s waiting for erase to complete\n", |
138 | __func__); | ||
128 | spin_unlock(&c->erase_completion_lock); | 139 | spin_unlock(&c->erase_completion_lock); |
129 | 140 | ||
130 | schedule(); | 141 | schedule(); |
@@ -144,7 +155,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, | |||
144 | 155 | ||
145 | ret = jffs2_do_reserve_space(c, minsize, len, sumsize); | 156 | ret = jffs2_do_reserve_space(c, minsize, len, sumsize); |
146 | if (ret) { | 157 | if (ret) { |
147 | D1(printk(KERN_DEBUG "jffs2_reserve_space: ret is %d\n", ret)); | 158 | jffs2_dbg(1, "%s(): ret is %d\n", __func__, ret); |
148 | } | 159 | } |
149 | } | 160 | } |
150 | spin_unlock(&c->erase_completion_lock); | 161 | spin_unlock(&c->erase_completion_lock); |
@@ -161,13 +172,14 @@ int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, | |||
161 | int ret = -EAGAIN; | 172 | int ret = -EAGAIN; |
162 | minsize = PAD(minsize); | 173 | minsize = PAD(minsize); |
163 | 174 | ||
164 | D1(printk(KERN_DEBUG "jffs2_reserve_space_gc(): Requested 0x%x bytes\n", minsize)); | 175 | jffs2_dbg(1, "%s(): Requested 0x%x bytes\n", __func__, minsize); |
165 | 176 | ||
166 | spin_lock(&c->erase_completion_lock); | 177 | spin_lock(&c->erase_completion_lock); |
167 | while(ret == -EAGAIN) { | 178 | while(ret == -EAGAIN) { |
168 | ret = jffs2_do_reserve_space(c, minsize, len, sumsize); | 179 | ret = jffs2_do_reserve_space(c, minsize, len, sumsize); |
169 | if (ret) { | 180 | if (ret) { |
170 | D1(printk(KERN_DEBUG "jffs2_reserve_space_gc: looping, ret is %d\n", ret)); | 181 | jffs2_dbg(1, "%s(): looping, ret is %d\n", |
182 | __func__, ret); | ||
171 | } | 183 | } |
172 | } | 184 | } |
173 | spin_unlock(&c->erase_completion_lock); | 185 | spin_unlock(&c->erase_completion_lock); |
@@ -184,8 +196,8 @@ static void jffs2_close_nextblock(struct jffs2_sb_info *c, struct jffs2_eraseblo | |||
184 | { | 196 | { |
185 | 197 | ||
186 | if (c->nextblock == NULL) { | 198 | if (c->nextblock == NULL) { |
187 | D1(printk(KERN_DEBUG "jffs2_close_nextblock: Erase block at 0x%08x has already been placed in a list\n", | 199 | jffs2_dbg(1, "%s(): Erase block at 0x%08x has already been placed in a list\n", |
188 | jeb->offset)); | 200 | __func__, jeb->offset); |
189 | return; | 201 | return; |
190 | } | 202 | } |
191 | /* Check, if we have a dirty block now, or if it was dirty already */ | 203 | /* Check, if we have a dirty block now, or if it was dirty already */ |
@@ -195,17 +207,20 @@ static void jffs2_close_nextblock(struct jffs2_sb_info *c, struct jffs2_eraseblo | |||
195 | jeb->dirty_size += jeb->wasted_size; | 207 | jeb->dirty_size += jeb->wasted_size; |
196 | jeb->wasted_size = 0; | 208 | jeb->wasted_size = 0; |
197 | if (VERYDIRTY(c, jeb->dirty_size)) { | 209 | if (VERYDIRTY(c, jeb->dirty_size)) { |
198 | D1(printk(KERN_DEBUG "Adding full erase block at 0x%08x to very_dirty_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n", | 210 | jffs2_dbg(1, "Adding full erase block at 0x%08x to very_dirty_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n", |
199 | jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size)); | 211 | jeb->offset, jeb->free_size, jeb->dirty_size, |
212 | jeb->used_size); | ||
200 | list_add_tail(&jeb->list, &c->very_dirty_list); | 213 | list_add_tail(&jeb->list, &c->very_dirty_list); |
201 | } else { | 214 | } else { |
202 | D1(printk(KERN_DEBUG "Adding full erase block at 0x%08x to dirty_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n", | 215 | jffs2_dbg(1, "Adding full erase block at 0x%08x to dirty_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n", |
203 | jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size)); | 216 | jeb->offset, jeb->free_size, jeb->dirty_size, |
217 | jeb->used_size); | ||
204 | list_add_tail(&jeb->list, &c->dirty_list); | 218 | list_add_tail(&jeb->list, &c->dirty_list); |
205 | } | 219 | } |
206 | } else { | 220 | } else { |
207 | D1(printk(KERN_DEBUG "Adding full erase block at 0x%08x to clean_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n", | 221 | jffs2_dbg(1, "Adding full erase block at 0x%08x to clean_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n", |
208 | jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size)); | 222 | jeb->offset, jeb->free_size, jeb->dirty_size, |
223 | jeb->used_size); | ||
209 | list_add_tail(&jeb->list, &c->clean_list); | 224 | list_add_tail(&jeb->list, &c->clean_list); |
210 | } | 225 | } |
211 | c->nextblock = NULL; | 226 | c->nextblock = NULL; |
@@ -230,13 +245,14 @@ static int jffs2_find_nextblock(struct jffs2_sb_info *c) | |||
230 | list_move_tail(&ejeb->list, &c->erase_pending_list); | 245 | list_move_tail(&ejeb->list, &c->erase_pending_list); |
231 | c->nr_erasing_blocks++; | 246 | c->nr_erasing_blocks++; |
232 | jffs2_garbage_collect_trigger(c); | 247 | jffs2_garbage_collect_trigger(c); |
233 | D1(printk(KERN_DEBUG "jffs2_find_nextblock: Triggering erase of erasable block at 0x%08x\n", | 248 | jffs2_dbg(1, "%s(): Triggering erase of erasable block at 0x%08x\n", |
234 | ejeb->offset)); | 249 | __func__, ejeb->offset); |
235 | } | 250 | } |
236 | 251 | ||
237 | if (!c->nr_erasing_blocks && | 252 | if (!c->nr_erasing_blocks && |
238 | !list_empty(&c->erasable_pending_wbuf_list)) { | 253 | !list_empty(&c->erasable_pending_wbuf_list)) { |
239 | D1(printk(KERN_DEBUG "jffs2_find_nextblock: Flushing write buffer\n")); | 254 | jffs2_dbg(1, "%s(): Flushing write buffer\n", |
255 | __func__); | ||
240 | /* c->nextblock is NULL, no update to c->nextblock allowed */ | 256 | /* c->nextblock is NULL, no update to c->nextblock allowed */ |
241 | spin_unlock(&c->erase_completion_lock); | 257 | spin_unlock(&c->erase_completion_lock); |
242 | jffs2_flush_wbuf_pad(c); | 258 | jffs2_flush_wbuf_pad(c); |
@@ -248,9 +264,11 @@ static int jffs2_find_nextblock(struct jffs2_sb_info *c) | |||
248 | if (!c->nr_erasing_blocks) { | 264 | if (!c->nr_erasing_blocks) { |
249 | /* Ouch. We're in GC, or we wouldn't have got here. | 265 | /* Ouch. We're in GC, or we wouldn't have got here. |
250 | And there's no space left. At all. */ | 266 | And there's no space left. At all. */ |
251 | printk(KERN_CRIT "Argh. No free space left for GC. nr_erasing_blocks is %d. nr_free_blocks is %d. (erasableempty: %s, erasingempty: %s, erasependingempty: %s)\n", | 267 | pr_crit("Argh. No free space left for GC. nr_erasing_blocks is %d. nr_free_blocks is %d. (erasableempty: %s, erasingempty: %s, erasependingempty: %s)\n", |
252 | c->nr_erasing_blocks, c->nr_free_blocks, list_empty(&c->erasable_list)?"yes":"no", | 268 | c->nr_erasing_blocks, c->nr_free_blocks, |
253 | list_empty(&c->erasing_list)?"yes":"no", list_empty(&c->erase_pending_list)?"yes":"no"); | 269 | list_empty(&c->erasable_list) ? "yes" : "no", |
270 | list_empty(&c->erasing_list) ? "yes" : "no", | ||
271 | list_empty(&c->erase_pending_list) ? "yes" : "no"); | ||
254 | return -ENOSPC; | 272 | return -ENOSPC; |
255 | } | 273 | } |
256 | 274 | ||
@@ -278,7 +296,8 @@ static int jffs2_find_nextblock(struct jffs2_sb_info *c) | |||
278 | c->wbuf_ofs = 0xffffffff; | 296 | c->wbuf_ofs = 0xffffffff; |
279 | #endif | 297 | #endif |
280 | 298 | ||
281 | D1(printk(KERN_DEBUG "jffs2_find_nextblock(): new nextblock = 0x%08x\n", c->nextblock->offset)); | 299 | jffs2_dbg(1, "%s(): new nextblock = 0x%08x\n", |
300 | __func__, c->nextblock->offset); | ||
282 | 301 | ||
283 | return 0; | 302 | return 0; |
284 | } | 303 | } |
@@ -345,7 +364,8 @@ static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, | |||
345 | 364 | ||
346 | if (jffs2_wbuf_dirty(c)) { | 365 | if (jffs2_wbuf_dirty(c)) { |
347 | spin_unlock(&c->erase_completion_lock); | 366 | spin_unlock(&c->erase_completion_lock); |
348 | D1(printk(KERN_DEBUG "jffs2_do_reserve_space: Flushing write buffer\n")); | 367 | jffs2_dbg(1, "%s(): Flushing write buffer\n", |
368 | __func__); | ||
349 | jffs2_flush_wbuf_pad(c); | 369 | jffs2_flush_wbuf_pad(c); |
350 | spin_lock(&c->erase_completion_lock); | 370 | spin_lock(&c->erase_completion_lock); |
351 | jeb = c->nextblock; | 371 | jeb = c->nextblock; |
@@ -387,7 +407,8 @@ static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, | |||
387 | jeb = c->nextblock; | 407 | jeb = c->nextblock; |
388 | 408 | ||
389 | if (jeb->free_size != c->sector_size - c->cleanmarker_size) { | 409 | if (jeb->free_size != c->sector_size - c->cleanmarker_size) { |
390 | printk(KERN_WARNING "Eep. Block 0x%08x taken from free_list had free_size of 0x%08x!!\n", jeb->offset, jeb->free_size); | 410 | pr_warn("Eep. Block 0x%08x taken from free_list had free_size of 0x%08x!!\n", |
411 | jeb->offset, jeb->free_size); | ||
391 | goto restart; | 412 | goto restart; |
392 | } | 413 | } |
393 | } | 414 | } |
@@ -408,8 +429,9 @@ static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, | |||
408 | spin_lock(&c->erase_completion_lock); | 429 | spin_lock(&c->erase_completion_lock); |
409 | } | 430 | } |
410 | 431 | ||
411 | D1(printk(KERN_DEBUG "jffs2_do_reserve_space(): Giving 0x%x bytes at 0x%x\n", | 432 | jffs2_dbg(1, "%s(): Giving 0x%x bytes at 0x%x\n", |
412 | *len, jeb->offset + (c->sector_size - jeb->free_size))); | 433 | __func__, |
434 | *len, jeb->offset + (c->sector_size - jeb->free_size)); | ||
413 | return 0; | 435 | return 0; |
414 | } | 436 | } |
415 | 437 | ||
@@ -434,20 +456,22 @@ struct jffs2_raw_node_ref *jffs2_add_physical_node_ref(struct jffs2_sb_info *c, | |||
434 | 456 | ||
435 | jeb = &c->blocks[ofs / c->sector_size]; | 457 | jeb = &c->blocks[ofs / c->sector_size]; |
436 | 458 | ||
437 | D1(printk(KERN_DEBUG "jffs2_add_physical_node_ref(): Node at 0x%x(%d), size 0x%x\n", | 459 | jffs2_dbg(1, "%s(): Node at 0x%x(%d), size 0x%x\n", |
438 | ofs & ~3, ofs & 3, len)); | 460 | __func__, ofs & ~3, ofs & 3, len); |
439 | #if 1 | 461 | #if 1 |
440 | /* Allow non-obsolete nodes only to be added at the end of c->nextblock, | 462 | /* Allow non-obsolete nodes only to be added at the end of c->nextblock, |
441 | if c->nextblock is set. Note that wbuf.c will file obsolete nodes | 463 | if c->nextblock is set. Note that wbuf.c will file obsolete nodes |
442 | even after refiling c->nextblock */ | 464 | even after refiling c->nextblock */ |
443 | if ((c->nextblock || ((ofs & 3) != REF_OBSOLETE)) | 465 | if ((c->nextblock || ((ofs & 3) != REF_OBSOLETE)) |
444 | && (jeb != c->nextblock || (ofs & ~3) != jeb->offset + (c->sector_size - jeb->free_size))) { | 466 | && (jeb != c->nextblock || (ofs & ~3) != jeb->offset + (c->sector_size - jeb->free_size))) { |
445 | printk(KERN_WARNING "argh. node added in wrong place at 0x%08x(%d)\n", ofs & ~3, ofs & 3); | 467 | pr_warn("argh. node added in wrong place at 0x%08x(%d)\n", |
468 | ofs & ~3, ofs & 3); | ||
446 | if (c->nextblock) | 469 | if (c->nextblock) |
447 | printk(KERN_WARNING "nextblock 0x%08x", c->nextblock->offset); | 470 | pr_warn("nextblock 0x%08x", c->nextblock->offset); |
448 | else | 471 | else |
449 | printk(KERN_WARNING "No nextblock"); | 472 | pr_warn("No nextblock"); |
450 | printk(", expected at %08x\n", jeb->offset + (c->sector_size - jeb->free_size)); | 473 | pr_cont(", expected at %08x\n", |
474 | jeb->offset + (c->sector_size - jeb->free_size)); | ||
451 | return ERR_PTR(-EINVAL); | 475 | return ERR_PTR(-EINVAL); |
452 | } | 476 | } |
453 | #endif | 477 | #endif |
@@ -457,8 +481,9 @@ struct jffs2_raw_node_ref *jffs2_add_physical_node_ref(struct jffs2_sb_info *c, | |||
457 | 481 | ||
458 | if (!jeb->free_size && !jeb->dirty_size && !ISDIRTY(jeb->wasted_size)) { | 482 | if (!jeb->free_size && !jeb->dirty_size && !ISDIRTY(jeb->wasted_size)) { |
459 | /* If it lives on the dirty_list, jffs2_reserve_space will put it there */ | 483 | /* If it lives on the dirty_list, jffs2_reserve_space will put it there */ |
460 | D1(printk(KERN_DEBUG "Adding full erase block at 0x%08x to clean_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n", | 484 | jffs2_dbg(1, "Adding full erase block at 0x%08x to clean_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n", |
461 | jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size)); | 485 | jeb->offset, jeb->free_size, jeb->dirty_size, |
486 | jeb->used_size); | ||
462 | if (jffs2_wbuf_dirty(c)) { | 487 | if (jffs2_wbuf_dirty(c)) { |
463 | /* Flush the last write in the block if it's outstanding */ | 488 | /* Flush the last write in the block if it's outstanding */ |
464 | spin_unlock(&c->erase_completion_lock); | 489 | spin_unlock(&c->erase_completion_lock); |
@@ -480,7 +505,7 @@ struct jffs2_raw_node_ref *jffs2_add_physical_node_ref(struct jffs2_sb_info *c, | |||
480 | 505 | ||
481 | void jffs2_complete_reservation(struct jffs2_sb_info *c) | 506 | void jffs2_complete_reservation(struct jffs2_sb_info *c) |
482 | { | 507 | { |
483 | D1(printk(KERN_DEBUG "jffs2_complete_reservation()\n")); | 508 | jffs2_dbg(1, "jffs2_complete_reservation()\n"); |
484 | spin_lock(&c->erase_completion_lock); | 509 | spin_lock(&c->erase_completion_lock); |
485 | jffs2_garbage_collect_trigger(c); | 510 | jffs2_garbage_collect_trigger(c); |
486 | spin_unlock(&c->erase_completion_lock); | 511 | spin_unlock(&c->erase_completion_lock); |
@@ -493,7 +518,7 @@ static inline int on_list(struct list_head *obj, struct list_head *head) | |||
493 | 518 | ||
494 | list_for_each(this, head) { | 519 | list_for_each(this, head) { |
495 | if (this == obj) { | 520 | if (this == obj) { |
496 | D1(printk("%p is on list at %p\n", obj, head)); | 521 | jffs2_dbg(1, "%p is on list at %p\n", obj, head); |
497 | return 1; | 522 | return 1; |
498 | 523 | ||
499 | } | 524 | } |
@@ -511,16 +536,18 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref | |||
511 | uint32_t freed_len; | 536 | uint32_t freed_len; |
512 | 537 | ||
513 | if(unlikely(!ref)) { | 538 | if(unlikely(!ref)) { |
514 | printk(KERN_NOTICE "EEEEEK. jffs2_mark_node_obsolete called with NULL node\n"); | 539 | pr_notice("EEEEEK. jffs2_mark_node_obsolete called with NULL node\n"); |
515 | return; | 540 | return; |
516 | } | 541 | } |
517 | if (ref_obsolete(ref)) { | 542 | if (ref_obsolete(ref)) { |
518 | D1(printk(KERN_DEBUG "jffs2_mark_node_obsolete called with already obsolete node at 0x%08x\n", ref_offset(ref))); | 543 | jffs2_dbg(1, "%s(): called with already obsolete node at 0x%08x\n", |
544 | __func__, ref_offset(ref)); | ||
519 | return; | 545 | return; |
520 | } | 546 | } |
521 | blocknr = ref->flash_offset / c->sector_size; | 547 | blocknr = ref->flash_offset / c->sector_size; |
522 | if (blocknr >= c->nr_blocks) { | 548 | if (blocknr >= c->nr_blocks) { |
523 | printk(KERN_NOTICE "raw node at 0x%08x is off the end of device!\n", ref->flash_offset); | 549 | pr_notice("raw node at 0x%08x is off the end of device!\n", |
550 | ref->flash_offset); | ||
524 | BUG(); | 551 | BUG(); |
525 | } | 552 | } |
526 | jeb = &c->blocks[blocknr]; | 553 | jeb = &c->blocks[blocknr]; |
@@ -542,27 +569,31 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref | |||
542 | 569 | ||
543 | if (ref_flags(ref) == REF_UNCHECKED) { | 570 | if (ref_flags(ref) == REF_UNCHECKED) { |
544 | D1(if (unlikely(jeb->unchecked_size < freed_len)) { | 571 | D1(if (unlikely(jeb->unchecked_size < freed_len)) { |
545 | printk(KERN_NOTICE "raw unchecked node of size 0x%08x freed from erase block %d at 0x%08x, but unchecked_size was already 0x%08x\n", | 572 | pr_notice("raw unchecked node of size 0x%08x freed from erase block %d at 0x%08x, but unchecked_size was already 0x%08x\n", |
546 | freed_len, blocknr, ref->flash_offset, jeb->used_size); | 573 | freed_len, blocknr, |
574 | ref->flash_offset, jeb->used_size); | ||
547 | BUG(); | 575 | BUG(); |
548 | }) | 576 | }) |
549 | D1(printk(KERN_DEBUG "Obsoleting previously unchecked node at 0x%08x of len %x: ", ref_offset(ref), freed_len)); | 577 | jffs2_dbg(1, "Obsoleting previously unchecked node at 0x%08x of len %x\n", |
578 | ref_offset(ref), freed_len); | ||
550 | jeb->unchecked_size -= freed_len; | 579 | jeb->unchecked_size -= freed_len; |
551 | c->unchecked_size -= freed_len; | 580 | c->unchecked_size -= freed_len; |
552 | } else { | 581 | } else { |
553 | D1(if (unlikely(jeb->used_size < freed_len)) { | 582 | D1(if (unlikely(jeb->used_size < freed_len)) { |
554 | printk(KERN_NOTICE "raw node of size 0x%08x freed from erase block %d at 0x%08x, but used_size was already 0x%08x\n", | 583 | pr_notice("raw node of size 0x%08x freed from erase block %d at 0x%08x, but used_size was already 0x%08x\n", |
555 | freed_len, blocknr, ref->flash_offset, jeb->used_size); | 584 | freed_len, blocknr, |
585 | ref->flash_offset, jeb->used_size); | ||
556 | BUG(); | 586 | BUG(); |
557 | }) | 587 | }) |
558 | D1(printk(KERN_DEBUG "Obsoleting node at 0x%08x of len %#x: ", ref_offset(ref), freed_len)); | 588 | jffs2_dbg(1, "Obsoleting node at 0x%08x of len %#x: ", |
589 | ref_offset(ref), freed_len); | ||
559 | jeb->used_size -= freed_len; | 590 | jeb->used_size -= freed_len; |
560 | c->used_size -= freed_len; | 591 | c->used_size -= freed_len; |
561 | } | 592 | } |
562 | 593 | ||
563 | // Take care, that wasted size is taken into concern | 594 | // Take care, that wasted size is taken into concern |
564 | if ((jeb->dirty_size || ISDIRTY(jeb->wasted_size + freed_len)) && jeb != c->nextblock) { | 595 | if ((jeb->dirty_size || ISDIRTY(jeb->wasted_size + freed_len)) && jeb != c->nextblock) { |
565 | D1(printk("Dirtying\n")); | 596 | jffs2_dbg(1, "Dirtying\n"); |
566 | addedsize = freed_len; | 597 | addedsize = freed_len; |
567 | jeb->dirty_size += freed_len; | 598 | jeb->dirty_size += freed_len; |
568 | c->dirty_size += freed_len; | 599 | c->dirty_size += freed_len; |
@@ -570,12 +601,12 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref | |||
570 | /* Convert wasted space to dirty, if not a bad block */ | 601 | /* Convert wasted space to dirty, if not a bad block */ |
571 | if (jeb->wasted_size) { | 602 | if (jeb->wasted_size) { |
572 | if (on_list(&jeb->list, &c->bad_used_list)) { | 603 | if (on_list(&jeb->list, &c->bad_used_list)) { |
573 | D1(printk(KERN_DEBUG "Leaving block at %08x on the bad_used_list\n", | 604 | jffs2_dbg(1, "Leaving block at %08x on the bad_used_list\n", |
574 | jeb->offset)); | 605 | jeb->offset); |
575 | addedsize = 0; /* To fool the refiling code later */ | 606 | addedsize = 0; /* To fool the refiling code later */ |
576 | } else { | 607 | } else { |
577 | D1(printk(KERN_DEBUG "Converting %d bytes of wasted space to dirty in block at %08x\n", | 608 | jffs2_dbg(1, "Converting %d bytes of wasted space to dirty in block at %08x\n", |
578 | jeb->wasted_size, jeb->offset)); | 609 | jeb->wasted_size, jeb->offset); |
579 | addedsize += jeb->wasted_size; | 610 | addedsize += jeb->wasted_size; |
580 | jeb->dirty_size += jeb->wasted_size; | 611 | jeb->dirty_size += jeb->wasted_size; |
581 | c->dirty_size += jeb->wasted_size; | 612 | c->dirty_size += jeb->wasted_size; |
@@ -584,7 +615,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref | |||
584 | } | 615 | } |
585 | } | 616 | } |
586 | } else { | 617 | } else { |
587 | D1(printk("Wasting\n")); | 618 | jffs2_dbg(1, "Wasting\n"); |
588 | addedsize = 0; | 619 | addedsize = 0; |
589 | jeb->wasted_size += freed_len; | 620 | jeb->wasted_size += freed_len; |
590 | c->wasted_size += freed_len; | 621 | c->wasted_size += freed_len; |
@@ -606,50 +637,57 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref | |||
606 | } | 637 | } |
607 | 638 | ||
608 | if (jeb == c->nextblock) { | 639 | if (jeb == c->nextblock) { |
609 | D2(printk(KERN_DEBUG "Not moving nextblock 0x%08x to dirty/erase_pending list\n", jeb->offset)); | 640 | jffs2_dbg(2, "Not moving nextblock 0x%08x to dirty/erase_pending list\n", |
641 | jeb->offset); | ||
610 | } else if (!jeb->used_size && !jeb->unchecked_size) { | 642 | } else if (!jeb->used_size && !jeb->unchecked_size) { |
611 | if (jeb == c->gcblock) { | 643 | if (jeb == c->gcblock) { |
612 | D1(printk(KERN_DEBUG "gcblock at 0x%08x completely dirtied. Clearing gcblock...\n", jeb->offset)); | 644 | jffs2_dbg(1, "gcblock at 0x%08x completely dirtied. Clearing gcblock...\n", |
645 | jeb->offset); | ||
613 | c->gcblock = NULL; | 646 | c->gcblock = NULL; |
614 | } else { | 647 | } else { |
615 | D1(printk(KERN_DEBUG "Eraseblock at 0x%08x completely dirtied. Removing from (dirty?) list...\n", jeb->offset)); | 648 | jffs2_dbg(1, "Eraseblock at 0x%08x completely dirtied. Removing from (dirty?) list...\n", |
649 | jeb->offset); | ||
616 | list_del(&jeb->list); | 650 | list_del(&jeb->list); |
617 | } | 651 | } |
618 | if (jffs2_wbuf_dirty(c)) { | 652 | if (jffs2_wbuf_dirty(c)) { |
619 | D1(printk(KERN_DEBUG "...and adding to erasable_pending_wbuf_list\n")); | 653 | jffs2_dbg(1, "...and adding to erasable_pending_wbuf_list\n"); |
620 | list_add_tail(&jeb->list, &c->erasable_pending_wbuf_list); | 654 | list_add_tail(&jeb->list, &c->erasable_pending_wbuf_list); |
621 | } else { | 655 | } else { |
622 | if (jiffies & 127) { | 656 | if (jiffies & 127) { |
623 | /* Most of the time, we just erase it immediately. Otherwise we | 657 | /* Most of the time, we just erase it immediately. Otherwise we |
624 | spend ages scanning it on mount, etc. */ | 658 | spend ages scanning it on mount, etc. */ |
625 | D1(printk(KERN_DEBUG "...and adding to erase_pending_list\n")); | 659 | jffs2_dbg(1, "...and adding to erase_pending_list\n"); |
626 | list_add_tail(&jeb->list, &c->erase_pending_list); | 660 | list_add_tail(&jeb->list, &c->erase_pending_list); |
627 | c->nr_erasing_blocks++; | 661 | c->nr_erasing_blocks++; |
628 | jffs2_garbage_collect_trigger(c); | 662 | jffs2_garbage_collect_trigger(c); |
629 | } else { | 663 | } else { |
630 | /* Sometimes, however, we leave it elsewhere so it doesn't get | 664 | /* Sometimes, however, we leave it elsewhere so it doesn't get |
631 | immediately reused, and we spread the load a bit. */ | 665 | immediately reused, and we spread the load a bit. */ |
632 | D1(printk(KERN_DEBUG "...and adding to erasable_list\n")); | 666 | jffs2_dbg(1, "...and adding to erasable_list\n"); |
633 | list_add_tail(&jeb->list, &c->erasable_list); | 667 | list_add_tail(&jeb->list, &c->erasable_list); |
634 | } | 668 | } |
635 | } | 669 | } |
636 | D1(printk(KERN_DEBUG "Done OK\n")); | 670 | jffs2_dbg(1, "Done OK\n"); |
637 | } else if (jeb == c->gcblock) { | 671 | } else if (jeb == c->gcblock) { |
638 | D2(printk(KERN_DEBUG "Not moving gcblock 0x%08x to dirty_list\n", jeb->offset)); | 672 | jffs2_dbg(2, "Not moving gcblock 0x%08x to dirty_list\n", |
673 | jeb->offset); | ||
639 | } else if (ISDIRTY(jeb->dirty_size) && !ISDIRTY(jeb->dirty_size - addedsize)) { | 674 | } else if (ISDIRTY(jeb->dirty_size) && !ISDIRTY(jeb->dirty_size - addedsize)) { |
640 | D1(printk(KERN_DEBUG "Eraseblock at 0x%08x is freshly dirtied. Removing from clean list...\n", jeb->offset)); | 675 | jffs2_dbg(1, "Eraseblock at 0x%08x is freshly dirtied. Removing from clean list...\n", |
676 | jeb->offset); | ||
641 | list_del(&jeb->list); | 677 | list_del(&jeb->list); |
642 | D1(printk(KERN_DEBUG "...and adding to dirty_list\n")); | 678 | jffs2_dbg(1, "...and adding to dirty_list\n"); |
643 | list_add_tail(&jeb->list, &c->dirty_list); | 679 | list_add_tail(&jeb->list, &c->dirty_list); |
644 | } else if (VERYDIRTY(c, jeb->dirty_size) && | 680 | } else if (VERYDIRTY(c, jeb->dirty_size) && |
645 | !VERYDIRTY(c, jeb->dirty_size - addedsize)) { | 681 | !VERYDIRTY(c, jeb->dirty_size - addedsize)) { |
646 | D1(printk(KERN_DEBUG "Eraseblock at 0x%08x is now very dirty. Removing from dirty list...\n", jeb->offset)); | 682 | jffs2_dbg(1, "Eraseblock at 0x%08x is now very dirty. Removing from dirty list...\n", |
683 | jeb->offset); | ||
647 | list_del(&jeb->list); | 684 | list_del(&jeb->list); |
648 | D1(printk(KERN_DEBUG "...and adding to very_dirty_list\n")); | 685 | jffs2_dbg(1, "...and adding to very_dirty_list\n"); |
649 | list_add_tail(&jeb->list, &c->very_dirty_list); | 686 | list_add_tail(&jeb->list, &c->very_dirty_list); |
650 | } else { | 687 | } else { |
651 | D1(printk(KERN_DEBUG "Eraseblock at 0x%08x not moved anywhere. (free 0x%08x, dirty 0x%08x, used 0x%08x)\n", | 688 | jffs2_dbg(1, "Eraseblock at 0x%08x not moved anywhere. (free 0x%08x, dirty 0x%08x, used 0x%08x)\n", |
652 | jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size)); | 689 | jeb->offset, jeb->free_size, jeb->dirty_size, |
690 | jeb->used_size); | ||
653 | } | 691 | } |
654 | 692 | ||
655 | spin_unlock(&c->erase_completion_lock); | 693 | spin_unlock(&c->erase_completion_lock); |
@@ -665,33 +703,40 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref | |||
665 | the block hasn't _already_ been erased, and that 'ref' itself hasn't been freed yet | 703 | the block hasn't _already_ been erased, and that 'ref' itself hasn't been freed yet |
666 | by jffs2_free_jeb_node_refs() in erase.c. Which is nice. */ | 704 | by jffs2_free_jeb_node_refs() in erase.c. Which is nice. */ |
667 | 705 | ||
668 | D1(printk(KERN_DEBUG "obliterating obsoleted node at 0x%08x\n", ref_offset(ref))); | 706 | jffs2_dbg(1, "obliterating obsoleted node at 0x%08x\n", |
707 | ref_offset(ref)); | ||
669 | ret = jffs2_flash_read(c, ref_offset(ref), sizeof(n), &retlen, (char *)&n); | 708 | ret = jffs2_flash_read(c, ref_offset(ref), sizeof(n), &retlen, (char *)&n); |
670 | if (ret) { | 709 | if (ret) { |
671 | printk(KERN_WARNING "Read error reading from obsoleted node at 0x%08x: %d\n", ref_offset(ref), ret); | 710 | pr_warn("Read error reading from obsoleted node at 0x%08x: %d\n", |
711 | ref_offset(ref), ret); | ||
672 | goto out_erase_sem; | 712 | goto out_erase_sem; |
673 | } | 713 | } |
674 | if (retlen != sizeof(n)) { | 714 | if (retlen != sizeof(n)) { |
675 | printk(KERN_WARNING "Short read from obsoleted node at 0x%08x: %zd\n", ref_offset(ref), retlen); | 715 | pr_warn("Short read from obsoleted node at 0x%08x: %zd\n", |
716 | ref_offset(ref), retlen); | ||
676 | goto out_erase_sem; | 717 | goto out_erase_sem; |
677 | } | 718 | } |
678 | if (PAD(je32_to_cpu(n.totlen)) != PAD(freed_len)) { | 719 | if (PAD(je32_to_cpu(n.totlen)) != PAD(freed_len)) { |
679 | printk(KERN_WARNING "Node totlen on flash (0x%08x) != totlen from node ref (0x%08x)\n", je32_to_cpu(n.totlen), freed_len); | 720 | pr_warn("Node totlen on flash (0x%08x) != totlen from node ref (0x%08x)\n", |
721 | je32_to_cpu(n.totlen), freed_len); | ||
680 | goto out_erase_sem; | 722 | goto out_erase_sem; |
681 | } | 723 | } |
682 | if (!(je16_to_cpu(n.nodetype) & JFFS2_NODE_ACCURATE)) { | 724 | if (!(je16_to_cpu(n.nodetype) & JFFS2_NODE_ACCURATE)) { |
683 | D1(printk(KERN_DEBUG "Node at 0x%08x was already marked obsolete (nodetype 0x%04x)\n", ref_offset(ref), je16_to_cpu(n.nodetype))); | 725 | jffs2_dbg(1, "Node at 0x%08x was already marked obsolete (nodetype 0x%04x)\n", |
726 | ref_offset(ref), je16_to_cpu(n.nodetype)); | ||
684 | goto out_erase_sem; | 727 | goto out_erase_sem; |
685 | } | 728 | } |
686 | /* XXX FIXME: This is ugly now */ | 729 | /* XXX FIXME: This is ugly now */ |
687 | n.nodetype = cpu_to_je16(je16_to_cpu(n.nodetype) & ~JFFS2_NODE_ACCURATE); | 730 | n.nodetype = cpu_to_je16(je16_to_cpu(n.nodetype) & ~JFFS2_NODE_ACCURATE); |
688 | ret = jffs2_flash_write(c, ref_offset(ref), sizeof(n), &retlen, (char *)&n); | 731 | ret = jffs2_flash_write(c, ref_offset(ref), sizeof(n), &retlen, (char *)&n); |
689 | if (ret) { | 732 | if (ret) { |
690 | printk(KERN_WARNING "Write error in obliterating obsoleted node at 0x%08x: %d\n", ref_offset(ref), ret); | 733 | pr_warn("Write error in obliterating obsoleted node at 0x%08x: %d\n", |
734 | ref_offset(ref), ret); | ||
691 | goto out_erase_sem; | 735 | goto out_erase_sem; |
692 | } | 736 | } |
693 | if (retlen != sizeof(n)) { | 737 | if (retlen != sizeof(n)) { |
694 | printk(KERN_WARNING "Short write in obliterating obsoleted node at 0x%08x: %zd\n", ref_offset(ref), retlen); | 738 | pr_warn("Short write in obliterating obsoleted node at 0x%08x: %zd\n", |
739 | ref_offset(ref), retlen); | ||
695 | goto out_erase_sem; | 740 | goto out_erase_sem; |
696 | } | 741 | } |
697 | 742 | ||
@@ -751,8 +796,8 @@ int jffs2_thread_should_wake(struct jffs2_sb_info *c) | |||
751 | return 1; | 796 | return 1; |
752 | 797 | ||
753 | if (c->unchecked_size) { | 798 | if (c->unchecked_size) { |
754 | D1(printk(KERN_DEBUG "jffs2_thread_should_wake(): unchecked_size %d, checked_ino #%d\n", | 799 | jffs2_dbg(1, "jffs2_thread_should_wake(): unchecked_size %d, checked_ino #%d\n", |
755 | c->unchecked_size, c->checked_ino)); | 800 | c->unchecked_size, c->checked_ino); |
756 | return 1; | 801 | return 1; |
757 | } | 802 | } |
758 | 803 | ||
@@ -780,8 +825,9 @@ int jffs2_thread_should_wake(struct jffs2_sb_info *c) | |||
780 | } | 825 | } |
781 | } | 826 | } |
782 | 827 | ||
783 | D1(printk(KERN_DEBUG "jffs2_thread_should_wake(): nr_free_blocks %d, nr_erasing_blocks %d, dirty_size 0x%x, vdirty_blocks %d: %s\n", | 828 | jffs2_dbg(1, "%s(): nr_free_blocks %d, nr_erasing_blocks %d, dirty_size 0x%x, vdirty_blocks %d: %s\n", |
784 | c->nr_free_blocks, c->nr_erasing_blocks, c->dirty_size, nr_very_dirty, ret?"yes":"no")); | 829 | __func__, c->nr_free_blocks, c->nr_erasing_blocks, |
830 | c->dirty_size, nr_very_dirty, ret ? "yes" : "no"); | ||
785 | 831 | ||
786 | return ret; | 832 | return ret; |
787 | } | 833 | } |