Lines Matching refs:c
24 static int jffs2_rp_can_write(struct jffs2_sb_info *c) in jffs2_rp_can_write() argument
27 struct jffs2_mount_opts *opts = &c->mount_opts; in jffs2_rp_can_write()
29 avail = c->dirty_size + c->free_size + c->unchecked_size + in jffs2_rp_can_write()
30 c->erasing_size - c->resv_blocks_write * c->sector_size in jffs2_rp_can_write()
31 - c->nospc_dirty_size; in jffs2_rp_can_write()
37 opts->rp_size, c->dirty_size, c->free_size, in jffs2_rp_can_write()
38 c->erasing_size, c->unchecked_size, in jffs2_rp_can_write()
39 c->nr_erasing_blocks, avail, c->nospc_dirty_size); in jffs2_rp_can_write()
71 static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
74 int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, in jffs2_reserve_space() argument
78 int blocksneeded = c->resv_blocks_write; in jffs2_reserve_space()
83 mutex_lock(&c->alloc_sem); in jffs2_reserve_space()
87 spin_lock(&c->erase_completion_lock); in jffs2_reserve_space()
93 if (prio != ALLOC_DELETION && !jffs2_rp_can_write(c)) { in jffs2_reserve_space()
100 while(c->nr_free_blocks + c->nr_erasing_blocks < blocksneeded) { in jffs2_reserve_space()
115 …dirty = c->dirty_size + c->erasing_size - c->nr_erasing_blocks * c->sector_size + c->unchecked_siz… in jffs2_reserve_space()
116 if (dirty < c->nospc_dirty_size) { in jffs2_reserve_space()
117 …if (prio == ALLOC_DELETION && c->nr_free_blocks + c->nr_erasing_blocks >= c->resv_blocks_deletion)… in jffs2_reserve_space()
123 dirty, c->unchecked_size, in jffs2_reserve_space()
124 c->sector_size); in jffs2_reserve_space()
126 spin_unlock(&c->erase_completion_lock); in jffs2_reserve_space()
127 mutex_unlock(&c->alloc_sem); in jffs2_reserve_space()
140 avail = c->free_size + c->dirty_size + c->erasing_size + c->unchecked_size; in jffs2_reserve_space()
141 if ( (avail / c->sector_size) <= blocksneeded) { in jffs2_reserve_space()
142 …if (prio == ALLOC_DELETION && c->nr_free_blocks + c->nr_erasing_blocks >= c->resv_blocks_deletion)… in jffs2_reserve_space()
149 avail, blocksneeded * c->sector_size); in jffs2_reserve_space()
150 spin_unlock(&c->erase_completion_lock); in jffs2_reserve_space()
151 mutex_unlock(&c->alloc_sem); in jffs2_reserve_space()
155 mutex_unlock(&c->alloc_sem); in jffs2_reserve_space()
158 c->nr_free_blocks, c->nr_erasing_blocks, in jffs2_reserve_space()
159 c->free_size, c->dirty_size, c->wasted_size, in jffs2_reserve_space()
160 c->used_size, c->erasing_size, c->bad_size, in jffs2_reserve_space()
161 c->free_size + c->dirty_size + in jffs2_reserve_space()
162 c->wasted_size + c->used_size + in jffs2_reserve_space()
163 c->erasing_size + c->bad_size, in jffs2_reserve_space()
164 c->flash_size); in jffs2_reserve_space()
165 spin_unlock(&c->erase_completion_lock); in jffs2_reserve_space()
167 ret = jffs2_garbage_collect_pass(c); in jffs2_reserve_space()
170 spin_lock(&c->erase_completion_lock); in jffs2_reserve_space()
171 if (c->nr_erasing_blocks && in jffs2_reserve_space()
172 list_empty(&c->erase_pending_list) && in jffs2_reserve_space()
173 list_empty(&c->erase_complete_list)) { in jffs2_reserve_space()
176 add_wait_queue(&c->erase_wait, &wait); in jffs2_reserve_space()
179 spin_unlock(&c->erase_completion_lock); in jffs2_reserve_space()
182 remove_wait_queue(&c->erase_wait, &wait); in jffs2_reserve_space()
184 spin_unlock(&c->erase_completion_lock); in jffs2_reserve_space()
193 mutex_lock(&c->alloc_sem); in jffs2_reserve_space()
194 spin_lock(&c->erase_completion_lock); in jffs2_reserve_space()
197 ret = jffs2_do_reserve_space(c, minsize, len, sumsize); in jffs2_reserve_space()
204 spin_unlock(&c->erase_completion_lock); in jffs2_reserve_space()
206 ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1); in jffs2_reserve_space()
208 mutex_unlock(&c->alloc_sem); in jffs2_reserve_space()
212 int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, in jffs2_reserve_space_gc() argument
221 spin_lock(&c->erase_completion_lock); in jffs2_reserve_space_gc()
222 ret = jffs2_do_reserve_space(c, minsize, len, sumsize); in jffs2_reserve_space_gc()
227 spin_unlock(&c->erase_completion_lock); in jffs2_reserve_space_gc()
235 ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1); in jffs2_reserve_space_gc()
243 static void jffs2_close_nextblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) in jffs2_close_nextblock() argument
246 if (c->nextblock == NULL) { in jffs2_close_nextblock()
253 c->dirty_size += jeb->wasted_size; in jffs2_close_nextblock()
254 c->wasted_size -= jeb->wasted_size; in jffs2_close_nextblock()
257 if (VERYDIRTY(c, jeb->dirty_size)) { in jffs2_close_nextblock()
261 list_add_tail(&jeb->list, &c->very_dirty_list); in jffs2_close_nextblock()
266 list_add_tail(&jeb->list, &c->dirty_list); in jffs2_close_nextblock()
272 list_add_tail(&jeb->list, &c->clean_list); in jffs2_close_nextblock()
274 c->nextblock = NULL; in jffs2_close_nextblock()
280 static int jffs2_find_nextblock(struct jffs2_sb_info *c) in jffs2_find_nextblock() argument
286 if (list_empty(&c->free_list)) { in jffs2_find_nextblock()
288 if (!c->nr_erasing_blocks && in jffs2_find_nextblock()
289 !list_empty(&c->erasable_list)) { in jffs2_find_nextblock()
292 ejeb = list_entry(c->erasable_list.next, struct jffs2_eraseblock, list); in jffs2_find_nextblock()
293 list_move_tail(&ejeb->list, &c->erase_pending_list); in jffs2_find_nextblock()
294 c->nr_erasing_blocks++; in jffs2_find_nextblock()
295 jffs2_garbage_collect_trigger(c); in jffs2_find_nextblock()
300 if (!c->nr_erasing_blocks && in jffs2_find_nextblock()
301 !list_empty(&c->erasable_pending_wbuf_list)) { in jffs2_find_nextblock()
305 spin_unlock(&c->erase_completion_lock); in jffs2_find_nextblock()
306 jffs2_flush_wbuf_pad(c); in jffs2_find_nextblock()
307 spin_lock(&c->erase_completion_lock); in jffs2_find_nextblock()
312 if (!c->nr_erasing_blocks) { in jffs2_find_nextblock()
316 c->nr_erasing_blocks, c->nr_free_blocks, in jffs2_find_nextblock()
317 list_empty(&c->erasable_list) ? "yes" : "no", in jffs2_find_nextblock()
318 list_empty(&c->erasing_list) ? "yes" : "no", in jffs2_find_nextblock()
319 list_empty(&c->erase_pending_list) ? "yes" : "no"); in jffs2_find_nextblock()
323 spin_unlock(&c->erase_completion_lock); in jffs2_find_nextblock()
325 jffs2_erase_pending_blocks(c, 1); in jffs2_find_nextblock()
326 spin_lock(&c->erase_completion_lock); in jffs2_find_nextblock()
334 next = c->free_list.next; in jffs2_find_nextblock()
336 c->nextblock = list_entry(next, struct jffs2_eraseblock, list); in jffs2_find_nextblock()
337 c->nr_free_blocks--; in jffs2_find_nextblock()
339 jffs2_sum_reset_collected(c->summary); /* reset collected summary */ in jffs2_find_nextblock()
343 if (!(c->wbuf_ofs % c->sector_size) && !c->wbuf_len) in jffs2_find_nextblock()
344 c->wbuf_ofs = 0xffffffff; in jffs2_find_nextblock()
348 __func__, c->nextblock->offset); in jffs2_find_nextblock()
354 static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, in jffs2_do_reserve_space() argument
357 struct jffs2_eraseblock *jeb = c->nextblock; in jffs2_do_reserve_space()
368 reserved_size = PAD(sumsize + c->summary->sum_size + JFFS2_SUMMARY_FRAME_SIZE); in jffs2_do_reserve_space()
372 c->summary->sum_size, sumsize); in jffs2_do_reserve_space()
377 if (jeb && (PAD(minsize) + PAD(c->summary->sum_size + sumsize + in jffs2_do_reserve_space()
381 if (jffs2_sum_is_disabled(c->summary)) { in jffs2_do_reserve_space()
388 ret = jffs2_sum_write_sumnode(c); in jffs2_do_reserve_space()
393 if (jffs2_sum_is_disabled(c->summary)) { in jffs2_do_reserve_space()
401 jffs2_close_nextblock(c, jeb); in jffs2_do_reserve_space()
404 reserved_size = PAD(sumsize + c->summary->sum_size + JFFS2_SUMMARY_FRAME_SIZE); in jffs2_do_reserve_space()
413 if (jffs2_wbuf_dirty(c)) { in jffs2_do_reserve_space()
414 spin_unlock(&c->erase_completion_lock); in jffs2_do_reserve_space()
417 jffs2_flush_wbuf_pad(c); in jffs2_do_reserve_space()
418 spin_lock(&c->erase_completion_lock); in jffs2_do_reserve_space()
419 jeb = c->nextblock; in jffs2_do_reserve_space()
423 spin_unlock(&c->erase_completion_lock); in jffs2_do_reserve_space()
425 ret = jffs2_prealloc_raw_node_refs(c, jeb, 1); in jffs2_do_reserve_space()
431 spin_lock(&c->erase_completion_lock); in jffs2_do_reserve_space()
437 jffs2_link_node_ref(c, jeb, in jffs2_do_reserve_space()
438 (jeb->offset + c->sector_size - waste) | REF_OBSOLETE, in jffs2_do_reserve_space()
442 c->dirty_size -= waste; in jffs2_do_reserve_space()
444 c->wasted_size += waste; in jffs2_do_reserve_space()
446 jffs2_close_nextblock(c, jeb); in jffs2_do_reserve_space()
453 ret = jffs2_find_nextblock(c); in jffs2_do_reserve_space()
457 jeb = c->nextblock; in jffs2_do_reserve_space()
459 if (jeb->free_size != c->sector_size - c->cleanmarker_size) { in jffs2_do_reserve_space()
469 if (c->cleanmarker_size && jeb->used_size == c->cleanmarker_size && in jffs2_do_reserve_space()
477 spin_unlock(&c->erase_completion_lock); in jffs2_do_reserve_space()
478 jffs2_mark_node_obsolete(c, jeb->first_node); in jffs2_do_reserve_space()
479 spin_lock(&c->erase_completion_lock); in jffs2_do_reserve_space()
484 *len, jeb->offset + (c->sector_size - jeb->free_size)); in jffs2_do_reserve_space()
500 struct jffs2_raw_node_ref *jffs2_add_physical_node_ref(struct jffs2_sb_info *c, in jffs2_add_physical_node_ref() argument
507 jeb = &c->blocks[ofs / c->sector_size]; in jffs2_add_physical_node_ref()
515 if ((c->nextblock || ((ofs & 3) != REF_OBSOLETE)) in jffs2_add_physical_node_ref()
516 && (jeb != c->nextblock || (ofs & ~3) != jeb->offset + (c->sector_size - jeb->free_size))) { in jffs2_add_physical_node_ref()
519 if (c->nextblock) in jffs2_add_physical_node_ref()
520 pr_warn("nextblock 0x%08x", c->nextblock->offset); in jffs2_add_physical_node_ref()
524 jeb->offset + (c->sector_size - jeb->free_size)); in jffs2_add_physical_node_ref()
528 spin_lock(&c->erase_completion_lock); in jffs2_add_physical_node_ref()
530 new = jffs2_link_node_ref(c, jeb, ofs, len, ic); in jffs2_add_physical_node_ref()
537 if (jffs2_wbuf_dirty(c)) { in jffs2_add_physical_node_ref()
539 spin_unlock(&c->erase_completion_lock); in jffs2_add_physical_node_ref()
540 jffs2_flush_wbuf_pad(c); in jffs2_add_physical_node_ref()
541 spin_lock(&c->erase_completion_lock); in jffs2_add_physical_node_ref()
544 list_add_tail(&jeb->list, &c->clean_list); in jffs2_add_physical_node_ref()
545 c->nextblock = NULL; in jffs2_add_physical_node_ref()
547 jffs2_dbg_acct_sanity_check_nolock(c,jeb); in jffs2_add_physical_node_ref()
548 jffs2_dbg_acct_paranoia_check_nolock(c, jeb); in jffs2_add_physical_node_ref()
550 spin_unlock(&c->erase_completion_lock); in jffs2_add_physical_node_ref()
556 void jffs2_complete_reservation(struct jffs2_sb_info *c) in jffs2_complete_reservation() argument
559 spin_lock(&c->erase_completion_lock); in jffs2_complete_reservation()
560 jffs2_garbage_collect_trigger(c); in jffs2_complete_reservation()
561 spin_unlock(&c->erase_completion_lock); in jffs2_complete_reservation()
562 mutex_unlock(&c->alloc_sem); in jffs2_complete_reservation()
579 void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref) in jffs2_mark_node_obsolete() argument
597 blocknr = ref->flash_offset / c->sector_size; in jffs2_mark_node_obsolete()
598 if (blocknr >= c->nr_blocks) { in jffs2_mark_node_obsolete()
603 jeb = &c->blocks[blocknr]; in jffs2_mark_node_obsolete()
605 if (jffs2_can_mark_obsolete(c) && !jffs2_is_readonly(c) && in jffs2_mark_node_obsolete()
606 !(c->flags & (JFFS2_SB_FLAG_SCANNING | JFFS2_SB_FLAG_BUILDING))) { in jffs2_mark_node_obsolete()
613 mutex_lock(&c->erase_free_sem); in jffs2_mark_node_obsolete()
616 spin_lock(&c->erase_completion_lock); in jffs2_mark_node_obsolete()
618 freed_len = ref_totlen(c, jeb, ref); in jffs2_mark_node_obsolete()
630 c->unchecked_size -= freed_len; in jffs2_mark_node_obsolete()
641 c->used_size -= freed_len; in jffs2_mark_node_obsolete()
645 if ((jeb->dirty_size || ISDIRTY(jeb->wasted_size + freed_len)) && jeb != c->nextblock) { in jffs2_mark_node_obsolete()
649 c->dirty_size += freed_len; in jffs2_mark_node_obsolete()
653 if (on_list(&jeb->list, &c->bad_used_list)) { in jffs2_mark_node_obsolete()
662 c->dirty_size += jeb->wasted_size; in jffs2_mark_node_obsolete()
663 c->wasted_size -= jeb->wasted_size; in jffs2_mark_node_obsolete()
671 c->wasted_size += freed_len; in jffs2_mark_node_obsolete()
675 jffs2_dbg_acct_sanity_check_nolock(c, jeb); in jffs2_mark_node_obsolete()
676 jffs2_dbg_acct_paranoia_check_nolock(c, jeb); in jffs2_mark_node_obsolete()
678 if (c->flags & JFFS2_SB_FLAG_SCANNING) { in jffs2_mark_node_obsolete()
684 spin_unlock(&c->erase_completion_lock); in jffs2_mark_node_obsolete()
689 if (jeb == c->nextblock) { in jffs2_mark_node_obsolete()
693 if (jeb == c->gcblock) { in jffs2_mark_node_obsolete()
696 c->gcblock = NULL; in jffs2_mark_node_obsolete()
702 if (jffs2_wbuf_dirty(c)) { in jffs2_mark_node_obsolete()
704 list_add_tail(&jeb->list, &c->erasable_pending_wbuf_list); in jffs2_mark_node_obsolete()
710 list_add_tail(&jeb->list, &c->erase_pending_list); in jffs2_mark_node_obsolete()
711 c->nr_erasing_blocks++; in jffs2_mark_node_obsolete()
712 jffs2_garbage_collect_trigger(c); in jffs2_mark_node_obsolete()
717 list_add_tail(&jeb->list, &c->erasable_list); in jffs2_mark_node_obsolete()
721 } else if (jeb == c->gcblock) { in jffs2_mark_node_obsolete()
729 list_add_tail(&jeb->list, &c->dirty_list); in jffs2_mark_node_obsolete()
730 } else if (VERYDIRTY(c, jeb->dirty_size) && in jffs2_mark_node_obsolete()
731 !VERYDIRTY(c, jeb->dirty_size - addedsize)) { in jffs2_mark_node_obsolete()
736 list_add_tail(&jeb->list, &c->very_dirty_list); in jffs2_mark_node_obsolete()
743 spin_unlock(&c->erase_completion_lock); in jffs2_mark_node_obsolete()
745 if (!jffs2_can_mark_obsolete(c) || jffs2_is_readonly(c) || in jffs2_mark_node_obsolete()
746 (c->flags & JFFS2_SB_FLAG_BUILDING)) { in jffs2_mark_node_obsolete()
758 ret = jffs2_flash_read(c, ref_offset(ref), sizeof(n), &retlen, (char *)&n); in jffs2_mark_node_obsolete()
781 ret = jffs2_flash_write(c, ref_offset(ref), sizeof(n), &retlen, (char *)&n); in jffs2_mark_node_obsolete()
807 spin_lock(&c->erase_completion_lock); in jffs2_mark_node_obsolete()
819 jffs2_release_xattr_datum(c, (struct jffs2_xattr_datum *)ic); in jffs2_mark_node_obsolete()
822 jffs2_release_xattr_ref(c, (struct jffs2_xattr_ref *)ic); in jffs2_mark_node_obsolete()
827 jffs2_del_ino_cache(c, ic); in jffs2_mark_node_obsolete()
830 spin_unlock(&c->erase_completion_lock); in jffs2_mark_node_obsolete()
834 mutex_unlock(&c->erase_free_sem); in jffs2_mark_node_obsolete()
837 int jffs2_thread_should_wake(struct jffs2_sb_info *c) in jffs2_thread_should_wake() argument
844 if (!list_empty(&c->erase_complete_list) || in jffs2_thread_should_wake()
845 !list_empty(&c->erase_pending_list)) in jffs2_thread_should_wake()
848 if (c->unchecked_size) { in jffs2_thread_should_wake()
850 c->unchecked_size, c->check_ino); in jffs2_thread_should_wake()
862 dirty = c->dirty_size + c->erasing_size - c->nr_erasing_blocks * c->sector_size; in jffs2_thread_should_wake()
864 if (c->nr_free_blocks + c->nr_erasing_blocks < c->resv_blocks_gctrigger && in jffs2_thread_should_wake()
865 (dirty > c->nospc_dirty_size)) in jffs2_thread_should_wake()
868 list_for_each_entry(jeb, &c->very_dirty_list, list) { in jffs2_thread_should_wake()
870 if (nr_very_dirty == c->vdirty_blocks_gctrigger) { in jffs2_thread_should_wake()
879 __func__, c->nr_free_blocks, c->nr_erasing_blocks, in jffs2_thread_should_wake()
880 c->dirty_size, nr_very_dirty, ret ? "yes" : "no"); in jffs2_thread_should_wake()