Lines Matching refs:c
56 static int nothing_to_commit(struct ubifs_info *c) in nothing_to_commit() argument
62 if (c->mounting || c->remounting_rw) in nothing_to_commit()
69 if (c->zroot.znode && ubifs_zn_dirty(c->zroot.znode)) in nothing_to_commit()
79 if (c->nroot && test_bit(DIRTY_CNODE, &c->nroot->flags)) in nothing_to_commit()
82 ubifs_assert(c, atomic_long_read(&c->dirty_zn_cnt) == 0); in nothing_to_commit()
83 ubifs_assert(c, c->dirty_pn_cnt == 0); in nothing_to_commit()
84 ubifs_assert(c, c->dirty_nn_cnt == 0); in nothing_to_commit()
97 static int do_commit(struct ubifs_info *c) in do_commit() argument
104 ubifs_assert(c, !c->ro_media && !c->ro_mount); in do_commit()
106 if (c->ro_error) { in do_commit()
111 if (nothing_to_commit(c)) { in do_commit()
112 up_write(&c->commit_sem); in do_commit()
118 for (i = 0; i < c->jhead_cnt; i++) { in do_commit()
119 err = ubifs_wbuf_sync(&c->jheads[i].wbuf); in do_commit()
124 c->cmt_no += 1; in do_commit()
125 err = ubifs_gc_start_commit(c); in do_commit()
128 err = dbg_check_lprops(c); in do_commit()
131 err = ubifs_log_start_commit(c, &new_ltail_lnum); in do_commit()
134 err = ubifs_tnc_start_commit(c, &zroot); in do_commit()
137 err = ubifs_lpt_start_commit(c); in do_commit()
140 err = ubifs_orphan_start_commit(c); in do_commit()
144 ubifs_get_lp_stats(c, &lst); in do_commit()
146 up_write(&c->commit_sem); in do_commit()
148 err = ubifs_tnc_end_commit(c); in do_commit()
151 err = ubifs_lpt_end_commit(c); in do_commit()
154 err = ubifs_orphan_end_commit(c); in do_commit()
157 err = dbg_check_old_index(c, &zroot); in do_commit()
161 c->mst_node->cmt_no = cpu_to_le64(c->cmt_no); in do_commit()
162 c->mst_node->log_lnum = cpu_to_le32(new_ltail_lnum); in do_commit()
163 c->mst_node->root_lnum = cpu_to_le32(zroot.lnum); in do_commit()
164 c->mst_node->root_offs = cpu_to_le32(zroot.offs); in do_commit()
165 c->mst_node->root_len = cpu_to_le32(zroot.len); in do_commit()
166 c->mst_node->ihead_lnum = cpu_to_le32(c->ihead_lnum); in do_commit()
167 c->mst_node->ihead_offs = cpu_to_le32(c->ihead_offs); in do_commit()
168 c->mst_node->index_size = cpu_to_le64(c->bi.old_idx_sz); in do_commit()
169 c->mst_node->lpt_lnum = cpu_to_le32(c->lpt_lnum); in do_commit()
170 c->mst_node->lpt_offs = cpu_to_le32(c->lpt_offs); in do_commit()
171 c->mst_node->nhead_lnum = cpu_to_le32(c->nhead_lnum); in do_commit()
172 c->mst_node->nhead_offs = cpu_to_le32(c->nhead_offs); in do_commit()
173 c->mst_node->ltab_lnum = cpu_to_le32(c->ltab_lnum); in do_commit()
174 c->mst_node->ltab_offs = cpu_to_le32(c->ltab_offs); in do_commit()
175 c->mst_node->lsave_lnum = cpu_to_le32(c->lsave_lnum); in do_commit()
176 c->mst_node->lsave_offs = cpu_to_le32(c->lsave_offs); in do_commit()
177 c->mst_node->lscan_lnum = cpu_to_le32(c->lscan_lnum); in do_commit()
178 c->mst_node->empty_lebs = cpu_to_le32(lst.empty_lebs); in do_commit()
179 c->mst_node->idx_lebs = cpu_to_le32(lst.idx_lebs); in do_commit()
180 c->mst_node->total_free = cpu_to_le64(lst.total_free); in do_commit()
181 c->mst_node->total_dirty = cpu_to_le64(lst.total_dirty); in do_commit()
182 c->mst_node->total_used = cpu_to_le64(lst.total_used); in do_commit()
183 c->mst_node->total_dead = cpu_to_le64(lst.total_dead); in do_commit()
184 c->mst_node->total_dark = cpu_to_le64(lst.total_dark); in do_commit()
185 if (c->no_orphs) in do_commit()
186 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); in do_commit()
188 c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_NO_ORPHS); in do_commit()
190 old_ltail_lnum = c->ltail_lnum; in do_commit()
191 err = ubifs_log_end_commit(c, new_ltail_lnum); in do_commit()
195 err = ubifs_log_post_commit(c, old_ltail_lnum); in do_commit()
198 err = ubifs_gc_end_commit(c); in do_commit()
201 err = ubifs_lpt_post_commit(c); in do_commit()
206 spin_lock(&c->cs_lock); in do_commit()
207 c->cmt_state = COMMIT_RESTING; in do_commit()
208 wake_up(&c->cmt_wq); in do_commit()
210 spin_unlock(&c->cs_lock); in do_commit()
214 up_write(&c->commit_sem); in do_commit()
216 ubifs_err(c, "commit failed, error %d", err); in do_commit()
217 spin_lock(&c->cs_lock); in do_commit()
218 c->cmt_state = COMMIT_BROKEN; in do_commit()
219 wake_up(&c->cmt_wq); in do_commit()
220 spin_unlock(&c->cs_lock); in do_commit()
221 ubifs_ro_mode(c, err); in do_commit()
232 static int run_bg_commit(struct ubifs_info *c) in run_bg_commit() argument
234 spin_lock(&c->cs_lock); in run_bg_commit()
239 if (c->cmt_state != COMMIT_BACKGROUND && in run_bg_commit()
240 c->cmt_state != COMMIT_REQUIRED) in run_bg_commit()
242 spin_unlock(&c->cs_lock); in run_bg_commit()
244 down_write(&c->commit_sem); in run_bg_commit()
245 spin_lock(&c->cs_lock); in run_bg_commit()
246 if (c->cmt_state == COMMIT_REQUIRED) in run_bg_commit()
247 c->cmt_state = COMMIT_RUNNING_REQUIRED; in run_bg_commit()
248 else if (c->cmt_state == COMMIT_BACKGROUND) in run_bg_commit()
249 c->cmt_state = COMMIT_RUNNING_BACKGROUND; in run_bg_commit()
252 spin_unlock(&c->cs_lock); in run_bg_commit()
254 return do_commit(c); in run_bg_commit()
257 up_write(&c->commit_sem); in run_bg_commit()
259 spin_unlock(&c->cs_lock); in run_bg_commit()
278 struct ubifs_info *c = info; in ubifs_bg_thread() local
280 ubifs_msg(c, "background thread \"%s\" started, PID %d", in ubifs_bg_thread()
281 c->bgt_name, current->pid); in ubifs_bg_thread()
293 if (!c->need_bgt) { in ubifs_bg_thread()
306 c->need_bgt = 0; in ubifs_bg_thread()
307 err = ubifs_bg_wbufs_sync(c); in ubifs_bg_thread()
309 ubifs_ro_mode(c, err); in ubifs_bg_thread()
311 run_bg_commit(c); in ubifs_bg_thread()
315 ubifs_msg(c, "background thread \"%s\" stops", c->bgt_name); in ubifs_bg_thread()
326 void ubifs_commit_required(struct ubifs_info *c) in ubifs_commit_required() argument
328 spin_lock(&c->cs_lock); in ubifs_commit_required()
329 switch (c->cmt_state) { in ubifs_commit_required()
332 dbg_cmt("old: %s, new: %s", dbg_cstate(c->cmt_state), in ubifs_commit_required()
334 c->cmt_state = COMMIT_REQUIRED; in ubifs_commit_required()
337 dbg_cmt("old: %s, new: %s", dbg_cstate(c->cmt_state), in ubifs_commit_required()
339 c->cmt_state = COMMIT_RUNNING_REQUIRED; in ubifs_commit_required()
346 spin_unlock(&c->cs_lock); in ubifs_commit_required()
356 void ubifs_request_bg_commit(struct ubifs_info *c) in ubifs_request_bg_commit() argument
358 spin_lock(&c->cs_lock); in ubifs_request_bg_commit()
359 if (c->cmt_state == COMMIT_RESTING) { in ubifs_request_bg_commit()
360 dbg_cmt("old: %s, new: %s", dbg_cstate(c->cmt_state), in ubifs_request_bg_commit()
362 c->cmt_state = COMMIT_BACKGROUND; in ubifs_request_bg_commit()
363 spin_unlock(&c->cs_lock); in ubifs_request_bg_commit()
364 ubifs_wake_up_bgt(c); in ubifs_request_bg_commit()
366 spin_unlock(&c->cs_lock); in ubifs_request_bg_commit()
375 static int wait_for_commit(struct ubifs_info *c) in wait_for_commit() argument
386 wait_event(c->cmt_wq, c->cmt_state != COMMIT_RUNNING_BACKGROUND && in wait_for_commit()
387 c->cmt_state != COMMIT_RUNNING_REQUIRED); in wait_for_commit()
399 int ubifs_run_commit(struct ubifs_info *c) in ubifs_run_commit() argument
403 spin_lock(&c->cs_lock); in ubifs_run_commit()
404 if (c->cmt_state == COMMIT_BROKEN) { in ubifs_run_commit()
409 if (c->cmt_state == COMMIT_RUNNING_BACKGROUND) in ubifs_run_commit()
414 c->cmt_state = COMMIT_RUNNING_REQUIRED; in ubifs_run_commit()
416 if (c->cmt_state == COMMIT_RUNNING_REQUIRED) { in ubifs_run_commit()
417 spin_unlock(&c->cs_lock); in ubifs_run_commit()
418 return wait_for_commit(c); in ubifs_run_commit()
420 spin_unlock(&c->cs_lock); in ubifs_run_commit()
424 down_write(&c->commit_sem); in ubifs_run_commit()
425 spin_lock(&c->cs_lock); in ubifs_run_commit()
430 if (c->cmt_state == COMMIT_BROKEN) { in ubifs_run_commit()
435 if (c->cmt_state == COMMIT_RUNNING_BACKGROUND) in ubifs_run_commit()
436 c->cmt_state = COMMIT_RUNNING_REQUIRED; in ubifs_run_commit()
438 if (c->cmt_state == COMMIT_RUNNING_REQUIRED) { in ubifs_run_commit()
439 up_write(&c->commit_sem); in ubifs_run_commit()
440 spin_unlock(&c->cs_lock); in ubifs_run_commit()
441 return wait_for_commit(c); in ubifs_run_commit()
443 c->cmt_state = COMMIT_RUNNING_REQUIRED; in ubifs_run_commit()
444 spin_unlock(&c->cs_lock); in ubifs_run_commit()
446 err = do_commit(c); in ubifs_run_commit()
450 up_write(&c->commit_sem); in ubifs_run_commit()
452 spin_unlock(&c->cs_lock); in ubifs_run_commit()
467 int ubifs_gc_should_commit(struct ubifs_info *c) in ubifs_gc_should_commit() argument
471 spin_lock(&c->cs_lock); in ubifs_gc_should_commit()
472 if (c->cmt_state == COMMIT_BACKGROUND) { in ubifs_gc_should_commit()
474 c->cmt_state = COMMIT_REQUIRED; in ubifs_gc_should_commit()
477 if (c->cmt_state == COMMIT_REQUIRED) in ubifs_gc_should_commit()
479 spin_unlock(&c->cs_lock); in ubifs_gc_should_commit()
514 int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot) in dbg_old_index_check_init() argument
518 struct ubifs_debug_info *d = c->dbg; in dbg_old_index_check_init()
525 idx = kmalloc(c->max_idx_node_sz, GFP_NOFS); in dbg_old_index_check_init()
529 err = ubifs_read_node(c, idx, UBIFS_IDX_NODE, len, lnum, offs); in dbg_old_index_check_init()
553 int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot) in dbg_check_old_index() argument
557 struct ubifs_debug_info *d = c->dbg; in dbg_check_old_index()
565 if (!dbg_is_chk_index(c)) in dbg_check_old_index()
570 sz = sizeof(struct idx_node) + ubifs_idx_node_sz(c, c->fanout) - in dbg_check_old_index()
597 err = ubifs_read_node(c, idx, UBIFS_IDX_NODE, len, lnum, offs); in dbg_check_old_index()
602 if (child_cnt < 1 || child_cnt > c->fanout) { in dbg_check_old_index()
620 key_read(c, ubifs_idx_key(c, idx), &lower_key); in dbg_check_old_index()
621 highest_ino_key(c, &upper_key, INUM_WATERMARK); in dbg_check_old_index()
623 key_copy(c, &upper_key, &i->upper_key); in dbg_check_old_index()
637 key_read(c, ubifs_idx_key(c, idx), &l_key); in dbg_check_old_index()
638 br = ubifs_idx_branch(c, idx, child_cnt - 1); in dbg_check_old_index()
639 key_read(c, &br->key, &u_key); in dbg_check_old_index()
640 if (keys_cmp(c, &lower_key, &l_key) > 0) { in dbg_check_old_index()
644 if (keys_cmp(c, &upper_key, &u_key) < 0) { in dbg_check_old_index()
648 if (keys_cmp(c, &upper_key, &u_key) == 0) in dbg_check_old_index()
649 if (!is_hash_key(c, &u_key)) { in dbg_check_old_index()
684 br = ubifs_idx_branch(c, idx, iip); in dbg_check_old_index()
688 key_read(c, &br->key, &lower_key); in dbg_check_old_index()
690 br = ubifs_idx_branch(c, idx, iip + 1); in dbg_check_old_index()
691 key_read(c, &br->key, &upper_key); in dbg_check_old_index()
693 key_copy(c, &i->upper_key, &upper_key); in dbg_check_old_index()
696 err = dbg_old_index_check_init(c, zroot); in dbg_check_old_index()
703 ubifs_err(c, "dumping index node (iip=%d)", i->iip); in dbg_check_old_index()
704 ubifs_dump_node(c, idx, ubifs_idx_node_sz(c, c->fanout)); in dbg_check_old_index()
709 ubifs_err(c, "dumping parent index node"); in dbg_check_old_index()
710 ubifs_dump_node(c, &i->idx, ubifs_idx_node_sz(c, c->fanout)); in dbg_check_old_index()
718 ubifs_err(c, "failed, error %d", err); in dbg_check_old_index()