Lines Matching refs:c
58 static int do_commit(struct ubifs_info *c) in do_commit() argument
65 if (c->ro_media) { in do_commit()
71 for (i = 0; i < c->jhead_cnt; i++) { in do_commit()
72 err = ubifs_wbuf_sync(&c->jheads[i].wbuf); in do_commit()
77 c->cmt_no += 1; in do_commit()
78 err = ubifs_gc_start_commit(c); in do_commit()
81 err = dbg_check_lprops(c); in do_commit()
84 err = ubifs_log_start_commit(c, &new_ltail_lnum); in do_commit()
87 err = ubifs_tnc_start_commit(c, &zroot); in do_commit()
90 err = ubifs_lpt_start_commit(c); in do_commit()
93 err = ubifs_orphan_start_commit(c); in do_commit()
97 ubifs_get_lp_stats(c, &lst); in do_commit()
99 up_write(&c->commit_sem); in do_commit()
101 err = ubifs_tnc_end_commit(c); in do_commit()
104 err = ubifs_lpt_end_commit(c); in do_commit()
107 err = ubifs_orphan_end_commit(c); in do_commit()
110 old_ltail_lnum = c->ltail_lnum; in do_commit()
111 err = ubifs_log_end_commit(c, new_ltail_lnum); in do_commit()
114 err = dbg_check_old_index(c, &zroot); in do_commit()
118 mutex_lock(&c->mst_mutex); in do_commit()
119 c->mst_node->cmt_no = cpu_to_le64(c->cmt_no); in do_commit()
120 c->mst_node->log_lnum = cpu_to_le32(new_ltail_lnum); in do_commit()
121 c->mst_node->root_lnum = cpu_to_le32(zroot.lnum); in do_commit()
122 c->mst_node->root_offs = cpu_to_le32(zroot.offs); in do_commit()
123 c->mst_node->root_len = cpu_to_le32(zroot.len); in do_commit()
124 c->mst_node->ihead_lnum = cpu_to_le32(c->ihead_lnum); in do_commit()
125 c->mst_node->ihead_offs = cpu_to_le32(c->ihead_offs); in do_commit()
126 c->mst_node->index_size = cpu_to_le64(c->old_idx_sz); in do_commit()
127 c->mst_node->lpt_lnum = cpu_to_le32(c->lpt_lnum); in do_commit()
128 c->mst_node->lpt_offs = cpu_to_le32(c->lpt_offs); in do_commit()
129 c->mst_node->nhead_lnum = cpu_to_le32(c->nhead_lnum); in do_commit()
130 c->mst_node->nhead_offs = cpu_to_le32(c->nhead_offs); in do_commit()
131 c->mst_node->ltab_lnum = cpu_to_le32(c->ltab_lnum); in do_commit()
132 c->mst_node->ltab_offs = cpu_to_le32(c->ltab_offs); in do_commit()
133 c->mst_node->lsave_lnum = cpu_to_le32(c->lsave_lnum); in do_commit()
134 c->mst_node->lsave_offs = cpu_to_le32(c->lsave_offs); in do_commit()
135 c->mst_node->lscan_lnum = cpu_to_le32(c->lscan_lnum); in do_commit()
136 c->mst_node->empty_lebs = cpu_to_le32(lst.empty_lebs); in do_commit()
137 c->mst_node->idx_lebs = cpu_to_le32(lst.idx_lebs); in do_commit()
138 c->mst_node->total_free = cpu_to_le64(lst.total_free); in do_commit()
139 c->mst_node->total_dirty = cpu_to_le64(lst.total_dirty); in do_commit()
140 c->mst_node->total_used = cpu_to_le64(lst.total_used); in do_commit()
141 c->mst_node->total_dead = cpu_to_le64(lst.total_dead); in do_commit()
142 c->mst_node->total_dark = cpu_to_le64(lst.total_dark); in do_commit()
143 if (c->no_orphs) in do_commit()
144 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); in do_commit()
146 c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_NO_ORPHS); in do_commit()
147 err = ubifs_write_master(c); in do_commit()
148 mutex_unlock(&c->mst_mutex); in do_commit()
152 err = ubifs_log_post_commit(c, old_ltail_lnum); in do_commit()
155 err = ubifs_gc_end_commit(c); in do_commit()
158 err = ubifs_lpt_post_commit(c); in do_commit()
162 spin_lock(&c->cs_lock); in do_commit()
163 c->cmt_state = COMMIT_RESTING; in do_commit()
164 wake_up(&c->cmt_wq); in do_commit()
166 spin_unlock(&c->cs_lock); in do_commit()
171 up_write(&c->commit_sem); in do_commit()
174 spin_lock(&c->cs_lock); in do_commit()
175 c->cmt_state = COMMIT_BROKEN; in do_commit()
176 wake_up(&c->cmt_wq); in do_commit()
177 spin_unlock(&c->cs_lock); in do_commit()
178 ubifs_ro_mode(c, err); in do_commit()
189 static int run_bg_commit(struct ubifs_info *c) in run_bg_commit() argument
191 spin_lock(&c->cs_lock); in run_bg_commit()
196 if (c->cmt_state != COMMIT_BACKGROUND && in run_bg_commit()
197 c->cmt_state != COMMIT_REQUIRED) in run_bg_commit()
199 spin_unlock(&c->cs_lock); in run_bg_commit()
201 down_write(&c->commit_sem); in run_bg_commit()
202 spin_lock(&c->cs_lock); in run_bg_commit()
203 if (c->cmt_state == COMMIT_REQUIRED) in run_bg_commit()
204 c->cmt_state = COMMIT_RUNNING_REQUIRED; in run_bg_commit()
205 else if (c->cmt_state == COMMIT_BACKGROUND) in run_bg_commit()
206 c->cmt_state = COMMIT_RUNNING_BACKGROUND; in run_bg_commit()
209 spin_unlock(&c->cs_lock); in run_bg_commit()
211 return do_commit(c); in run_bg_commit()
214 up_write(&c->commit_sem); in run_bg_commit()
216 spin_unlock(&c->cs_lock); in run_bg_commit()
235 struct ubifs_info *c = info; in ubifs_bg_thread() local
238 c->bgt_name, current->pid); in ubifs_bg_thread()
250 if (!c->need_bgt) { in ubifs_bg_thread()
263 c->need_bgt = 0; in ubifs_bg_thread()
264 err = ubifs_bg_wbufs_sync(c); in ubifs_bg_thread()
266 ubifs_ro_mode(c, err); in ubifs_bg_thread()
268 run_bg_commit(c); in ubifs_bg_thread()
272 dbg_msg("background thread \"%s\" stops", c->bgt_name); in ubifs_bg_thread()
283 void ubifs_commit_required(struct ubifs_info *c) in ubifs_commit_required() argument
285 spin_lock(&c->cs_lock); in ubifs_commit_required()
286 switch (c->cmt_state) { in ubifs_commit_required()
289 dbg_cmt("old: %s, new: %s", dbg_cstate(c->cmt_state), in ubifs_commit_required()
291 c->cmt_state = COMMIT_REQUIRED; in ubifs_commit_required()
294 dbg_cmt("old: %s, new: %s", dbg_cstate(c->cmt_state), in ubifs_commit_required()
296 c->cmt_state = COMMIT_RUNNING_REQUIRED; in ubifs_commit_required()
303 spin_unlock(&c->cs_lock); in ubifs_commit_required()
313 void ubifs_request_bg_commit(struct ubifs_info *c) in ubifs_request_bg_commit() argument
315 spin_lock(&c->cs_lock); in ubifs_request_bg_commit()
316 if (c->cmt_state == COMMIT_RESTING) { in ubifs_request_bg_commit()
317 dbg_cmt("old: %s, new: %s", dbg_cstate(c->cmt_state), in ubifs_request_bg_commit()
319 c->cmt_state = COMMIT_BACKGROUND; in ubifs_request_bg_commit()
320 spin_unlock(&c->cs_lock); in ubifs_request_bg_commit()
321 ubifs_wake_up_bgt(c); in ubifs_request_bg_commit()
323 spin_unlock(&c->cs_lock); in ubifs_request_bg_commit()
332 static int wait_for_commit(struct ubifs_info *c) in wait_for_commit() argument
343 wait_event(c->cmt_wq, c->cmt_state != COMMIT_RUNNING_BACKGROUND && in wait_for_commit()
344 c->cmt_state != COMMIT_RUNNING_REQUIRED); in wait_for_commit()
356 int ubifs_run_commit(struct ubifs_info *c) in ubifs_run_commit() argument
360 spin_lock(&c->cs_lock); in ubifs_run_commit()
361 if (c->cmt_state == COMMIT_BROKEN) { in ubifs_run_commit()
366 if (c->cmt_state == COMMIT_RUNNING_BACKGROUND) in ubifs_run_commit()
371 c->cmt_state = COMMIT_RUNNING_REQUIRED; in ubifs_run_commit()
373 if (c->cmt_state == COMMIT_RUNNING_REQUIRED) { in ubifs_run_commit()
374 spin_unlock(&c->cs_lock); in ubifs_run_commit()
375 return wait_for_commit(c); in ubifs_run_commit()
377 spin_unlock(&c->cs_lock); in ubifs_run_commit()
381 down_write(&c->commit_sem); in ubifs_run_commit()
382 spin_lock(&c->cs_lock); in ubifs_run_commit()
387 if (c->cmt_state == COMMIT_BROKEN) { in ubifs_run_commit()
392 if (c->cmt_state == COMMIT_RUNNING_BACKGROUND) in ubifs_run_commit()
393 c->cmt_state = COMMIT_RUNNING_REQUIRED; in ubifs_run_commit()
395 if (c->cmt_state == COMMIT_RUNNING_REQUIRED) { in ubifs_run_commit()
396 up_write(&c->commit_sem); in ubifs_run_commit()
397 spin_unlock(&c->cs_lock); in ubifs_run_commit()
398 return wait_for_commit(c); in ubifs_run_commit()
400 c->cmt_state = COMMIT_RUNNING_REQUIRED; in ubifs_run_commit()
401 spin_unlock(&c->cs_lock); in ubifs_run_commit()
403 err = do_commit(c); in ubifs_run_commit()
407 up_write(&c->commit_sem); in ubifs_run_commit()
409 spin_unlock(&c->cs_lock); in ubifs_run_commit()
424 int ubifs_gc_should_commit(struct ubifs_info *c) in ubifs_gc_should_commit() argument
428 spin_lock(&c->cs_lock); in ubifs_gc_should_commit()
429 if (c->cmt_state == COMMIT_BACKGROUND) { in ubifs_gc_should_commit()
431 c->cmt_state = COMMIT_REQUIRED; in ubifs_gc_should_commit()
434 if (c->cmt_state == COMMIT_REQUIRED) in ubifs_gc_should_commit()
436 spin_unlock(&c->cs_lock); in ubifs_gc_should_commit()
469 int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot) in dbg_old_index_check_init() argument
473 struct ubifs_debug_info *d = c->dbg; in dbg_old_index_check_init()
480 idx = kmalloc(c->max_idx_node_sz, GFP_NOFS); in dbg_old_index_check_init()
484 err = ubifs_read_node(c, idx, UBIFS_IDX_NODE, len, lnum, offs); in dbg_old_index_check_init()
508 int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot) in dbg_check_old_index() argument
512 struct ubifs_debug_info *d = c->dbg; in dbg_check_old_index()
525 sz = sizeof(struct idx_node) + ubifs_idx_node_sz(c, c->fanout) - in dbg_check_old_index()
552 err = ubifs_read_node(c, idx, UBIFS_IDX_NODE, len, lnum, offs); in dbg_check_old_index()
557 if (child_cnt < 1 || child_cnt > c->fanout) { in dbg_check_old_index()
575 key_read(c, ubifs_idx_key(c, idx), &lower_key); in dbg_check_old_index()
576 highest_ino_key(c, &upper_key, INUM_WATERMARK); in dbg_check_old_index()
578 key_copy(c, &upper_key, &i->upper_key); in dbg_check_old_index()
592 key_read(c, ubifs_idx_key(c, idx), &l_key); in dbg_check_old_index()
593 br = ubifs_idx_branch(c, idx, child_cnt - 1); in dbg_check_old_index()
594 key_read(c, &br->key, &u_key); in dbg_check_old_index()
595 if (keys_cmp(c, &lower_key, &l_key) > 0) { in dbg_check_old_index()
599 if (keys_cmp(c, &upper_key, &u_key) < 0) { in dbg_check_old_index()
603 if (keys_cmp(c, &upper_key, &u_key) == 0) in dbg_check_old_index()
604 if (!is_hash_key(c, &u_key)) { in dbg_check_old_index()
639 br = ubifs_idx_branch(c, idx, iip); in dbg_check_old_index()
643 key_read(c, &br->key, &lower_key); in dbg_check_old_index()
645 br = ubifs_idx_branch(c, idx, iip + 1); in dbg_check_old_index()
646 key_read(c, &br->key, &upper_key); in dbg_check_old_index()
648 key_copy(c, &i->upper_key, &upper_key); in dbg_check_old_index()
651 err = dbg_old_index_check_init(c, zroot); in dbg_check_old_index()
659 dbg_dump_node(c, idx); in dbg_check_old_index()
665 dbg_dump_node(c, &i->idx); in dbg_check_old_index()