Lines Matching refs:c
66 static int validate_inode(struct ubifs_info *c, const struct inode *inode) in validate_inode() argument
71 if (inode->i_size > c->max_inode_sz) { in validate_inode()
97 err = dbg_check_dir_size(c, inode); in validate_inode()
106 struct ubifs_info *c = sb->s_fs_info; in ubifs_iget() local
125 ino_key_init(c, &key, inode->i_ino); in ubifs_iget()
127 err = ubifs_tnc_lookup(c, &key, ino); in ubifs_iget()
155 err = validate_inode(c, inode); in ubifs_iget()
160 inode->i_mapping->backing_dev_info = &c->bdi; in ubifs_iget()
249 dbg_dump_node(c, ino); in ubifs_iget()
250 dbg_dump_inode(c, inode); in ubifs_iget()
289 struct ubifs_info *c = inode->i_sb->s_fs_info; in ubifs_write_inode() local
316 err = ubifs_jnl_write_inode(c, inode); in ubifs_write_inode()
324 ubifs_release_dirty_inode_budget(c, ui); in ubifs_write_inode()
331 struct ubifs_info *c = inode->i_sb->s_fs_info; in ubifs_delete_inode() local
351 err = ubifs_jnl_delete_inode(c, inode); in ubifs_delete_inode()
362 ubifs_release_dirty_inode_budget(c, ui); in ubifs_delete_inode()
379 struct ubifs_info *c = dentry->d_sb->s_fs_info; in ubifs_statfs() local
381 __le32 *uuid = (__le32 *)c->uuid; in ubifs_statfs()
383 free = ubifs_get_free_space(c); in ubifs_statfs()
389 buf->f_blocks = c->block_cnt; in ubifs_statfs()
391 if (free > c->report_rp_size) in ubifs_statfs()
392 buf->f_bavail = (free - c->report_rp_size) >> UBIFS_BLOCK_SHIFT; in ubifs_statfs()
400 ubifs_assert(buf->f_bfree <= c->block_cnt); in ubifs_statfs()
406 struct ubifs_info *c = mnt->mnt_sb->s_fs_info; in ubifs_show_options() local
408 if (c->mount_opts.unmount_mode == 2) in ubifs_show_options()
410 else if (c->mount_opts.unmount_mode == 1) in ubifs_show_options()
413 if (c->mount_opts.bulk_read == 2) in ubifs_show_options()
415 else if (c->mount_opts.bulk_read == 1) in ubifs_show_options()
418 if (c->mount_opts.chk_data_crc == 2) in ubifs_show_options()
420 else if (c->mount_opts.chk_data_crc == 1) in ubifs_show_options()
423 if (c->mount_opts.override_compr) { in ubifs_show_options()
425 seq_printf(s, ubifs_compr_name(c->mount_opts.compr_type)); in ubifs_show_options()
434 struct ubifs_info *c = sb->s_fs_info; in ubifs_sync_fs() local
468 for (i = 0; i < c->jhead_cnt; i++) { in ubifs_sync_fs()
469 err = ubifs_wbuf_sync(&c->jheads[i].wbuf); in ubifs_sync_fs()
474 err = ubifs_run_commit(c); in ubifs_sync_fs()
478 return ubi_sync(c->vi.ubi_num); in ubifs_sync_fs()
490 static int init_constants_early(struct ubifs_info *c) in init_constants_early() argument
492 if (c->vi.corrupted) { in init_constants_early()
494 c->ro_media = 1; in init_constants_early()
497 if (c->di.ro_mode) { in init_constants_early()
499 c->ro_media = 1; in init_constants_early()
502 if (c->vi.vol_type == UBI_STATIC_VOLUME) { in init_constants_early()
504 c->ro_media = 1; in init_constants_early()
507 c->leb_cnt = c->vi.size; in init_constants_early()
508 c->leb_size = c->vi.usable_leb_size; in init_constants_early()
509 c->half_leb_size = c->leb_size / 2; in init_constants_early()
510 c->min_io_size = c->di.min_io_size; in init_constants_early()
511 c->min_io_shift = fls(c->min_io_size) - 1; in init_constants_early()
513 if (c->leb_size < UBIFS_MIN_LEB_SZ) { in init_constants_early()
515 c->leb_size, UBIFS_MIN_LEB_SZ); in init_constants_early()
519 if (c->leb_cnt < UBIFS_MIN_LEB_CNT) { in init_constants_early()
521 c->leb_cnt, UBIFS_MIN_LEB_CNT); in init_constants_early()
525 if (!is_power_of_2(c->min_io_size)) { in init_constants_early()
526 ubifs_err("bad min. I/O size %d", c->min_io_size); in init_constants_early()
535 if (c->min_io_size < 8) { in init_constants_early()
536 c->min_io_size = 8; in init_constants_early()
537 c->min_io_shift = 3; in init_constants_early()
540 c->ref_node_alsz = ALIGN(UBIFS_REF_NODE_SZ, c->min_io_size); in init_constants_early()
541 c->mst_node_alsz = ALIGN(UBIFS_MST_NODE_SZ, c->min_io_size); in init_constants_early()
547 c->ranges[UBIFS_PAD_NODE].len = UBIFS_PAD_NODE_SZ; in init_constants_early()
548 c->ranges[UBIFS_SB_NODE].len = UBIFS_SB_NODE_SZ; in init_constants_early()
549 c->ranges[UBIFS_MST_NODE].len = UBIFS_MST_NODE_SZ; in init_constants_early()
550 c->ranges[UBIFS_REF_NODE].len = UBIFS_REF_NODE_SZ; in init_constants_early()
551 c->ranges[UBIFS_TRUN_NODE].len = UBIFS_TRUN_NODE_SZ; in init_constants_early()
552 c->ranges[UBIFS_CS_NODE].len = UBIFS_CS_NODE_SZ; in init_constants_early()
554 c->ranges[UBIFS_INO_NODE].min_len = UBIFS_INO_NODE_SZ; in init_constants_early()
555 c->ranges[UBIFS_INO_NODE].max_len = UBIFS_MAX_INO_NODE_SZ; in init_constants_early()
556 c->ranges[UBIFS_ORPH_NODE].min_len = in init_constants_early()
558 c->ranges[UBIFS_ORPH_NODE].max_len = c->leb_size; in init_constants_early()
559 c->ranges[UBIFS_DENT_NODE].min_len = UBIFS_DENT_NODE_SZ; in init_constants_early()
560 c->ranges[UBIFS_DENT_NODE].max_len = UBIFS_MAX_DENT_NODE_SZ; in init_constants_early()
561 c->ranges[UBIFS_XENT_NODE].min_len = UBIFS_XENT_NODE_SZ; in init_constants_early()
562 c->ranges[UBIFS_XENT_NODE].max_len = UBIFS_MAX_XENT_NODE_SZ; in init_constants_early()
563 c->ranges[UBIFS_DATA_NODE].min_len = UBIFS_DATA_NODE_SZ; in init_constants_early()
564 c->ranges[UBIFS_DATA_NODE].max_len = UBIFS_MAX_DATA_NODE_SZ; in init_constants_early()
569 c->ranges[UBIFS_IDX_NODE].min_len = UBIFS_IDX_NODE_SZ + UBIFS_BRANCH_SZ; in init_constants_early()
574 c->ranges[UBIFS_IDX_NODE].max_len = INT_MAX; in init_constants_early()
580 c->dead_wm = ALIGN(MIN_WRITE_SZ, c->min_io_size); in init_constants_early()
581 c->dark_wm = ALIGN(UBIFS_MAX_NODE_SZ, c->min_io_size); in init_constants_early()
588 c->leb_overhead = c->leb_size % UBIFS_MAX_DATA_NODE_SZ; in init_constants_early()
591 c->max_bu_buf_len = UBIFS_MAX_BULK_READ * UBIFS_MAX_DATA_NODE_SZ; in init_constants_early()
592 if (c->max_bu_buf_len > c->leb_size) in init_constants_early()
593 c->max_bu_buf_len = c->leb_size; in init_constants_early()
612 static int bud_wbuf_callback(struct ubifs_info *c, int lnum, int free, int pad) in bud_wbuf_callback() argument
614 return ubifs_update_one_lp(c, lnum, free, pad, 0, 0); in bud_wbuf_callback()
626 static int init_constants_sb(struct ubifs_info *c) in init_constants_sb() argument
631 c->main_bytes = (long long)c->main_lebs * c->leb_size; in init_constants_sb()
632 c->max_znode_sz = sizeof(struct ubifs_znode) + in init_constants_sb()
633 c->fanout * sizeof(struct ubifs_zbranch); in init_constants_sb()
635 tmp = ubifs_idx_node_sz(c, 1); in init_constants_sb()
636 c->ranges[UBIFS_IDX_NODE].min_len = tmp; in init_constants_sb()
637 c->min_idx_node_sz = ALIGN(tmp, 8); in init_constants_sb()
639 tmp = ubifs_idx_node_sz(c, c->fanout); in init_constants_sb()
640 c->ranges[UBIFS_IDX_NODE].max_len = tmp; in init_constants_sb()
641 c->max_idx_node_sz = ALIGN(tmp, 8); in init_constants_sb()
644 tmp = UBIFS_CS_NODE_SZ + UBIFS_REF_NODE_SZ * c->jhead_cnt; in init_constants_sb()
645 tmp = ALIGN(tmp, c->min_io_size); in init_constants_sb()
646 if (tmp > c->leb_size) { in init_constants_sb()
648 c->leb_size, tmp); in init_constants_sb()
656 tmp64 = c->max_bud_bytes + c->leb_size - 1; in init_constants_sb()
657 c->max_bud_cnt = div_u64(tmp64, c->leb_size); in init_constants_sb()
658 tmp = (c->ref_node_alsz * c->max_bud_cnt + c->leb_size - 1); in init_constants_sb()
659 tmp /= c->leb_size; in init_constants_sb()
661 if (c->log_lebs < tmp) { in init_constants_sb()
663 c->log_lebs, tmp); in init_constants_sb()
674 c->page_budget = UBIFS_MAX_DATA_NODE_SZ * UBIFS_BLOCKS_PER_PAGE; in init_constants_sb()
675 c->inode_budget = UBIFS_INO_NODE_SZ; in init_constants_sb()
676 c->dent_budget = UBIFS_MAX_DENT_NODE_SZ; in init_constants_sb()
685 c->bg_bud_bytes = (c->max_bud_bytes * 13) >> 4; in init_constants_sb()
693 tmp64 = (long long)(c->jhead_cnt + 1) * c->leb_size + 1; in init_constants_sb()
694 if (c->bg_bud_bytes < tmp64) in init_constants_sb()
695 c->bg_bud_bytes = tmp64; in init_constants_sb()
696 if (c->max_bud_bytes < tmp64 + c->leb_size) in init_constants_sb()
697 c->max_bud_bytes = tmp64 + c->leb_size; in init_constants_sb()
699 err = ubifs_calc_lpt_geom(c); in init_constants_sb()
714 static void init_constants_master(struct ubifs_info *c) in init_constants_master() argument
718 c->min_idx_lebs = ubifs_calc_min_idx_lebs(c); in init_constants_master()
729 tmp64 = c->main_lebs - 1 - 1 - MIN_INDEX_LEBS - c->jhead_cnt + 1; in init_constants_master()
730 tmp64 *= (long long)c->leb_size - c->leb_overhead; in init_constants_master()
731 tmp64 = ubifs_reported_space(c, tmp64); in init_constants_master()
732 c->block_cnt = tmp64 >> UBIFS_BLOCK_SHIFT; in init_constants_master()
746 static int take_gc_lnum(struct ubifs_info *c) in take_gc_lnum() argument
750 if (c->gc_lnum == -1) { in take_gc_lnum()
756 err = ubifs_change_one_lp(c, c->gc_lnum, c->leb_size, 0, in take_gc_lnum()
768 static int alloc_wbufs(struct ubifs_info *c) in alloc_wbufs() argument
772 c->jheads = kzalloc(c->jhead_cnt * sizeof(struct ubifs_jhead), in alloc_wbufs()
774 if (!c->jheads) in alloc_wbufs()
778 for (i = 0; i < c->jhead_cnt; i++) { in alloc_wbufs()
779 INIT_LIST_HEAD(&c->jheads[i].buds_list); in alloc_wbufs()
780 err = ubifs_wbuf_init(c, &c->jheads[i].wbuf); in alloc_wbufs()
784 c->jheads[i].wbuf.sync_callback = &bud_wbuf_callback; in alloc_wbufs()
785 c->jheads[i].wbuf.jhead = i; in alloc_wbufs()
788 c->jheads[BASEHD].wbuf.dtype = UBI_SHORTTERM; in alloc_wbufs()
793 c->jheads[GCHD].wbuf.dtype = UBI_LONGTERM; in alloc_wbufs()
794 c->jheads[GCHD].wbuf.timeout = 0; in alloc_wbufs()
803 static void free_wbufs(struct ubifs_info *c) in free_wbufs() argument
807 if (c->jheads) { in free_wbufs()
808 for (i = 0; i < c->jhead_cnt; i++) { in free_wbufs()
809 kfree(c->jheads[i].wbuf.buf); in free_wbufs()
810 kfree(c->jheads[i].wbuf.inodes); in free_wbufs()
812 kfree(c->jheads); in free_wbufs()
813 c->jheads = NULL; in free_wbufs()
821 static void free_orphans(struct ubifs_info *c) in free_orphans() argument
825 while (c->orph_dnext) { in free_orphans()
826 orph = c->orph_dnext; in free_orphans()
827 c->orph_dnext = orph->dnext; in free_orphans()
832 while (!list_empty(&c->orph_list)) { in free_orphans()
833 orph = list_entry(c->orph_list.next, struct ubifs_orphan, list); in free_orphans()
839 vfree(c->orph_buf); in free_orphans()
840 c->orph_buf = NULL; in free_orphans()
847 static void free_buds(struct ubifs_info *c) in free_buds() argument
849 struct rb_node *this = c->buds.rb_node; in free_buds()
880 static int check_volume_empty(struct ubifs_info *c) in check_volume_empty() argument
884 c->empty = 1; in check_volume_empty()
885 for (lnum = 0; lnum < c->leb_cnt; lnum++) { in check_volume_empty()
886 err = ubi_is_mapped(c->ubi, lnum); in check_volume_empty()
890 c->empty = 0; in check_volume_empty()
943 static int ubifs_parse_options(struct ubifs_info *c, char *options, in ubifs_parse_options() argument
966 c->mount_opts.unmount_mode = 2; in ubifs_parse_options()
969 c->mount_opts.unmount_mode = 1; in ubifs_parse_options()
972 c->mount_opts.bulk_read = 2; in ubifs_parse_options()
973 c->bulk_read = 1; in ubifs_parse_options()
976 c->mount_opts.bulk_read = 1; in ubifs_parse_options()
977 c->bulk_read = 0; in ubifs_parse_options()
980 c->mount_opts.chk_data_crc = 2; in ubifs_parse_options()
981 c->no_chk_data_crc = 0; in ubifs_parse_options()
984 c->mount_opts.chk_data_crc = 1; in ubifs_parse_options()
985 c->no_chk_data_crc = 1; in ubifs_parse_options()
994 c->mount_opts.compr_type = UBIFS_COMPR_NONE; in ubifs_parse_options()
996 c->mount_opts.compr_type = UBIFS_COMPR_LZO; in ubifs_parse_options()
998 c->mount_opts.compr_type = UBIFS_COMPR_ZLIB; in ubifs_parse_options()
1005 c->mount_opts.override_compr = 1; in ubifs_parse_options()
1006 c->default_compr = c->mount_opts.compr_type; in ubifs_parse_options()
1026 static void destroy_journal(struct ubifs_info *c) in destroy_journal() argument
1028 while (!list_empty(&c->unclean_leb_list)) { in destroy_journal()
1031 ucleb = list_entry(c->unclean_leb_list.next, in destroy_journal()
1036 while (!list_empty(&c->old_buds)) { in destroy_journal()
1039 bud = list_entry(c->old_buds.next, struct ubifs_bud, list); in destroy_journal()
1043 ubifs_destroy_idx_gc(c); in destroy_journal()
1044 ubifs_destroy_size_tree(c); in destroy_journal()
1045 ubifs_tnc_close(c); in destroy_journal()
1046 free_buds(c); in destroy_journal()
1053 static void bu_init(struct ubifs_info *c) in bu_init() argument
1055 ubifs_assert(c->bulk_read == 1); in bu_init()
1057 if (c->bu.buf) in bu_init()
1061 c->bu.buf = kmalloc(c->max_bu_buf_len, GFP_KERNEL | __GFP_NOWARN); in bu_init()
1062 if (!c->bu.buf) { in bu_init()
1063 if (c->max_bu_buf_len > UBIFS_KMALLOC_OK) { in bu_init()
1064 c->max_bu_buf_len = UBIFS_KMALLOC_OK; in bu_init()
1070 "disabling it", c->max_bu_buf_len); in bu_init()
1071 c->mount_opts.bulk_read = 1; in bu_init()
1072 c->bulk_read = 0; in bu_init()
1084 static int check_free_space(struct ubifs_info *c) in check_free_space() argument
1086 ubifs_assert(c->dark_wm > 0); in check_free_space()
1087 if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) { in check_free_space()
1089 dbg_dump_budg(c); in check_free_space()
1090 dbg_dump_lprops(c); in check_free_space()
1106 static int mount_ubifs(struct ubifs_info *c) in mount_ubifs() argument
1108 struct super_block *sb = c->vfs_sb; in mount_ubifs()
1113 err = init_constants_early(c); in mount_ubifs()
1117 err = ubifs_debugging_init(c); in mount_ubifs()
1121 err = check_volume_empty(c); in mount_ubifs()
1125 if (c->empty && (mounted_read_only || c->ro_media)) { in mount_ubifs()
1131 c->ro_media ? "UBI volume" : "mount"); in mount_ubifs()
1136 if (c->ro_media && !mounted_read_only) { in mount_ubifs()
1148 c->bottom_up_buf = kmalloc(BOTTOM_UP_HEIGHT * sizeof(int), GFP_KERNEL); in mount_ubifs()
1149 if (!c->bottom_up_buf) in mount_ubifs()
1152 c->sbuf = vmalloc(c->leb_size); in mount_ubifs()
1153 if (!c->sbuf) in mount_ubifs()
1157 c->ileb_buf = vmalloc(c->leb_size); in mount_ubifs()
1158 if (!c->ileb_buf) in mount_ubifs()
1162 if (c->bulk_read == 1) in mount_ubifs()
1163 bu_init(c); in mount_ubifs()
1169 c->always_chk_crc = 1; in mount_ubifs()
1171 err = ubifs_read_superblock(c); in mount_ubifs()
1179 if (!ubifs_compr_present(c->default_compr)) { in mount_ubifs()
1181 ubifs_compr_name(c->default_compr)); in mount_ubifs()
1185 err = init_constants_sb(c); in mount_ubifs()
1189 sz = ALIGN(c->max_idx_node_sz, c->min_io_size); in mount_ubifs()
1190 sz = ALIGN(sz + c->max_idx_node_sz, c->min_io_size); in mount_ubifs()
1191 c->cbuf = kmalloc(sz, GFP_NOFS); in mount_ubifs()
1192 if (!c->cbuf) { in mount_ubifs()
1197 sprintf(c->bgt_name, BGT_NAME_PATTERN, c->vi.ubi_num, c->vi.vol_id); in mount_ubifs()
1199 err = alloc_wbufs(c); in mount_ubifs()
1204 c->bgt = kthread_create(ubifs_bg_thread, c, c->bgt_name); in mount_ubifs()
1205 if (IS_ERR(c->bgt)) { in mount_ubifs()
1206 err = PTR_ERR(c->bgt); in mount_ubifs()
1207 c->bgt = NULL; in mount_ubifs()
1209 c->bgt_name, err); in mount_ubifs()
1212 wake_up_process(c->bgt); in mount_ubifs()
1215 err = ubifs_read_master(c); in mount_ubifs()
1219 init_constants_master(c); in mount_ubifs()
1221 if ((c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY)) != 0) { in mount_ubifs()
1223 c->need_recovery = 1; in mount_ubifs()
1225 err = ubifs_recover_inl_heads(c, c->sbuf); in mount_ubifs()
1234 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY); in mount_ubifs()
1235 err = ubifs_write_master(c); in mount_ubifs()
1240 err = ubifs_lpt_init(c, 1, !mounted_read_only); in mount_ubifs()
1244 err = dbg_check_idx_size(c, c->old_idx_sz); in mount_ubifs()
1248 err = ubifs_replay_journal(c); in mount_ubifs()
1252 err = ubifs_mount_orphans(c, c->need_recovery, mounted_read_only); in mount_ubifs()
1259 err = check_free_space(c); in mount_ubifs()
1264 lnum = c->lhead_lnum + 1; in mount_ubifs()
1265 if (lnum >= UBIFS_LOG_LNUM + c->log_lebs) in mount_ubifs()
1267 if (lnum == c->ltail_lnum) { in mount_ubifs()
1268 err = ubifs_consolidate_log(c); in mount_ubifs()
1273 if (c->need_recovery) { in mount_ubifs()
1274 err = ubifs_recover_size(c); in mount_ubifs()
1277 err = ubifs_rcvry_gc_commit(c); in mount_ubifs()
1279 err = take_gc_lnum(c); in mount_ubifs()
1287 err = ubifs_leb_unmap(c, c->gc_lnum); in mount_ubifs()
1292 err = dbg_check_lprops(c); in mount_ubifs()
1295 } else if (c->need_recovery) { in mount_ubifs()
1296 err = ubifs_recover_size(c); in mount_ubifs()
1306 err = take_gc_lnum(c); in mount_ubifs()
1312 list_add_tail(&c->infos_list, &ubifs_infos); in mount_ubifs()
1315 if (c->need_recovery) { in mount_ubifs()
1319 c->need_recovery = 0; in mount_ubifs()
1322 ubifs_assert(c->lst.taken_empty_lebs == 1); in mount_ubifs()
1325 ubifs_assert(c->lst.taken_empty_lebs == 1); in mount_ubifs()
1327 err = dbg_check_filesystem(c); in mount_ubifs()
1331 err = dbg_debugfs_init_fs(c); in mount_ubifs()
1335 c->always_chk_crc = 0; in mount_ubifs()
1338 c->vi.ubi_num, c->vi.vol_id, c->vi.name); in mount_ubifs()
1341 x = (long long)c->main_lebs * c->leb_size; in mount_ubifs()
1343 "LEBs)", x, x >> 10, x >> 20, c->main_lebs); in mount_ubifs()
1344 x = (long long)c->log_lebs * c->leb_size + c->max_bud_bytes; in mount_ubifs()
1346 "LEBs)", x, x >> 10, x >> 20, c->log_lebs + c->max_bud_cnt); in mount_ubifs()
1348 c->fmt_version, UBIFS_FORMAT_VERSION); in mount_ubifs()
1349 ubifs_msg("default compressor: %s", ubifs_compr_name(c->default_compr)); in mount_ubifs()
1351 c->report_rp_size, c->report_rp_size >> 10); in mount_ubifs()
1354 dbg_msg("min. I/O unit size: %d bytes", c->min_io_size); in mount_ubifs()
1356 c->leb_size, c->leb_size >> 10); in mount_ubifs()
1358 c->jhead_cnt - NONDATA_JHEADS_CNT); in mount_ubifs()
1361 c->uuid[0], c->uuid[1], c->uuid[2], c->uuid[3], in mount_ubifs()
1362 c->uuid[4], c->uuid[5], c->uuid[6], c->uuid[7], in mount_ubifs()
1363 c->uuid[8], c->uuid[9], c->uuid[10], c->uuid[11], in mount_ubifs()
1364 c->uuid[12], c->uuid[13], c->uuid[14], c->uuid[15]); in mount_ubifs()
1365 dbg_msg("big_lpt %d", c->big_lpt); in mount_ubifs()
1367 c->log_lebs, UBIFS_LOG_LNUM, c->log_last); in mount_ubifs()
1369 c->lpt_lebs, c->lpt_first, c->lpt_last); in mount_ubifs()
1371 c->orph_lebs, c->orph_first, c->orph_last); in mount_ubifs()
1373 c->main_lebs, c->main_first, c->leb_cnt - 1); in mount_ubifs()
1374 dbg_msg("index LEBs: %d", c->lst.idx_lebs); in mount_ubifs()
1376 c->old_idx_sz, c->old_idx_sz >> 10, c->old_idx_sz >> 20); in mount_ubifs()
1377 dbg_msg("key hash type: %d", c->key_hash_type); in mount_ubifs()
1378 dbg_msg("tree fanout: %d", c->fanout); in mount_ubifs()
1379 dbg_msg("reserved GC LEB: %d", c->gc_lnum); in mount_ubifs()
1380 dbg_msg("first main LEB: %d", c->main_first); in mount_ubifs()
1381 dbg_msg("max. znode size %d", c->max_znode_sz); in mount_ubifs()
1382 dbg_msg("max. index node size %d", c->max_idx_node_sz); in mount_ubifs()
1392 dbg_msg("dead watermark: %d", c->dead_wm); in mount_ubifs()
1393 dbg_msg("dark watermark: %d", c->dark_wm); in mount_ubifs()
1394 dbg_msg("LEB overhead: %d", c->leb_overhead); in mount_ubifs()
1395 x = (long long)c->main_lebs * c->dark_wm; in mount_ubifs()
1399 c->max_bud_bytes, c->max_bud_bytes >> 10, in mount_ubifs()
1400 c->max_bud_bytes >> 20); in mount_ubifs()
1402 c->bg_bud_bytes, c->bg_bud_bytes >> 10, in mount_ubifs()
1403 c->bg_bud_bytes >> 20); in mount_ubifs()
1405 c->bud_bytes, c->bud_bytes >> 10, c->bud_bytes >> 20); in mount_ubifs()
1406 dbg_msg("max. seq. number: %llu", c->max_sqnum); in mount_ubifs()
1407 dbg_msg("commit number: %llu", c->cmt_no); in mount_ubifs()
1413 list_del(&c->infos_list); in mount_ubifs()
1416 free_orphans(c); in mount_ubifs()
1418 destroy_journal(c); in mount_ubifs()
1420 ubifs_lpt_free(c, 0); in mount_ubifs()
1422 kfree(c->mst_node); in mount_ubifs()
1423 kfree(c->rcvrd_mst_node); in mount_ubifs()
1424 if (c->bgt) in mount_ubifs()
1425 kthread_stop(c->bgt); in mount_ubifs()
1427 free_wbufs(c); in mount_ubifs()
1429 kfree(c->cbuf); in mount_ubifs()
1431 kfree(c->bu.buf); in mount_ubifs()
1432 vfree(c->ileb_buf); in mount_ubifs()
1433 vfree(c->sbuf); in mount_ubifs()
1434 kfree(c->bottom_up_buf); in mount_ubifs()
1435 ubifs_debugging_exit(c); in mount_ubifs()
1448 static void ubifs_umount(struct ubifs_info *c) in ubifs_umount() argument
1450 dbg_gen("un-mounting UBI device %d, volume %d", c->vi.ubi_num, in ubifs_umount()
1451 c->vi.vol_id); in ubifs_umount()
1453 dbg_debugfs_exit_fs(c); in ubifs_umount()
1455 list_del(&c->infos_list); in ubifs_umount()
1458 if (c->bgt) in ubifs_umount()
1459 kthread_stop(c->bgt); in ubifs_umount()
1461 destroy_journal(c); in ubifs_umount()
1462 free_wbufs(c); in ubifs_umount()
1463 free_orphans(c); in ubifs_umount()
1464 ubifs_lpt_free(c, 0); in ubifs_umount()
1466 kfree(c->cbuf); in ubifs_umount()
1467 kfree(c->rcvrd_mst_node); in ubifs_umount()
1468 kfree(c->mst_node); in ubifs_umount()
1469 kfree(c->bu.buf); in ubifs_umount()
1470 vfree(c->ileb_buf); in ubifs_umount()
1471 vfree(c->sbuf); in ubifs_umount()
1472 kfree(c->bottom_up_buf); in ubifs_umount()
1473 ubifs_debugging_exit(c); in ubifs_umount()
1484 static int ubifs_remount_rw(struct ubifs_info *c) in ubifs_remount_rw() argument
1488 mutex_lock(&c->umount_mutex); in ubifs_remount_rw()
1489 dbg_save_space_info(c); in ubifs_remount_rw()
1490 c->remounting_rw = 1; in ubifs_remount_rw()
1491 c->always_chk_crc = 1; in ubifs_remount_rw()
1493 err = check_free_space(c); in ubifs_remount_rw()
1497 if (c->old_leb_cnt != c->leb_cnt) { in ubifs_remount_rw()
1500 sup = ubifs_read_sb_node(c); in ubifs_remount_rw()
1505 sup->leb_cnt = cpu_to_le32(c->leb_cnt); in ubifs_remount_rw()
1506 err = ubifs_write_sb_node(c, sup); in ubifs_remount_rw()
1511 if (c->need_recovery) { in ubifs_remount_rw()
1513 err = ubifs_write_rcvrd_mst_node(c); in ubifs_remount_rw()
1516 err = ubifs_recover_size(c); in ubifs_remount_rw()
1519 err = ubifs_clean_lebs(c, c->sbuf); in ubifs_remount_rw()
1522 err = ubifs_recover_inl_heads(c, c->sbuf); in ubifs_remount_rw()
1527 ubifs_assert(c->tot_orphans == 0); in ubifs_remount_rw()
1528 err = ubifs_clear_orphans(c); in ubifs_remount_rw()
1533 if (!(c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY))) { in ubifs_remount_rw()
1534 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY); in ubifs_remount_rw()
1535 err = ubifs_write_master(c); in ubifs_remount_rw()
1540 c->ileb_buf = vmalloc(c->leb_size); in ubifs_remount_rw()
1541 if (!c->ileb_buf) { in ubifs_remount_rw()
1546 err = ubifs_lpt_init(c, 0, 1); in ubifs_remount_rw()
1550 err = alloc_wbufs(c); in ubifs_remount_rw()
1554 ubifs_create_buds_lists(c); in ubifs_remount_rw()
1557 c->bgt = kthread_create(ubifs_bg_thread, c, c->bgt_name); in ubifs_remount_rw()
1558 if (IS_ERR(c->bgt)) { in ubifs_remount_rw()
1559 err = PTR_ERR(c->bgt); in ubifs_remount_rw()
1560 c->bgt = NULL; in ubifs_remount_rw()
1562 c->bgt_name, err); in ubifs_remount_rw()
1565 wake_up_process(c->bgt); in ubifs_remount_rw()
1567 c->orph_buf = vmalloc(c->leb_size); in ubifs_remount_rw()
1568 if (!c->orph_buf) { in ubifs_remount_rw()
1574 lnum = c->lhead_lnum + 1; in ubifs_remount_rw()
1575 if (lnum >= UBIFS_LOG_LNUM + c->log_lebs) in ubifs_remount_rw()
1577 if (lnum == c->ltail_lnum) { in ubifs_remount_rw()
1578 err = ubifs_consolidate_log(c); in ubifs_remount_rw()
1583 if (c->need_recovery) in ubifs_remount_rw()
1584 err = ubifs_rcvry_gc_commit(c); in ubifs_remount_rw()
1586 err = ubifs_leb_unmap(c, c->gc_lnum); in ubifs_remount_rw()
1590 if (c->need_recovery) { in ubifs_remount_rw()
1591 c->need_recovery = 0; in ubifs_remount_rw()
1596 c->vfs_sb->s_flags &= ~MS_RDONLY; in ubifs_remount_rw()
1597 c->remounting_rw = 0; in ubifs_remount_rw()
1598 c->always_chk_crc = 0; in ubifs_remount_rw()
1599 err = dbg_check_space_info(c); in ubifs_remount_rw()
1600 mutex_unlock(&c->umount_mutex); in ubifs_remount_rw()
1604 vfree(c->orph_buf); in ubifs_remount_rw()
1605 c->orph_buf = NULL; in ubifs_remount_rw()
1606 if (c->bgt) { in ubifs_remount_rw()
1607 kthread_stop(c->bgt); in ubifs_remount_rw()
1608 c->bgt = NULL; in ubifs_remount_rw()
1610 free_wbufs(c); in ubifs_remount_rw()
1611 vfree(c->ileb_buf); in ubifs_remount_rw()
1612 c->ileb_buf = NULL; in ubifs_remount_rw()
1613 ubifs_lpt_free(c, 1); in ubifs_remount_rw()
1614 c->remounting_rw = 0; in ubifs_remount_rw()
1615 c->always_chk_crc = 0; in ubifs_remount_rw()
1616 mutex_unlock(&c->umount_mutex); in ubifs_remount_rw()
1627 static void ubifs_remount_ro(struct ubifs_info *c) in ubifs_remount_ro() argument
1631 ubifs_assert(!c->need_recovery); in ubifs_remount_ro()
1632 ubifs_assert(!(c->vfs_sb->s_flags & MS_RDONLY)); in ubifs_remount_ro()
1634 mutex_lock(&c->umount_mutex); in ubifs_remount_ro()
1635 if (c->bgt) { in ubifs_remount_ro()
1636 kthread_stop(c->bgt); in ubifs_remount_ro()
1637 c->bgt = NULL; in ubifs_remount_ro()
1640 dbg_save_space_info(c); in ubifs_remount_ro()
1642 for (i = 0; i < c->jhead_cnt; i++) { in ubifs_remount_ro()
1643 ubifs_wbuf_sync(&c->jheads[i].wbuf); in ubifs_remount_ro()
1644 del_timer_sync(&c->jheads[i].wbuf.timer); in ubifs_remount_ro()
1647 c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); in ubifs_remount_ro()
1648 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); in ubifs_remount_ro()
1649 c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum); in ubifs_remount_ro()
1650 err = ubifs_write_master(c); in ubifs_remount_ro()
1652 ubifs_ro_mode(c, err); in ubifs_remount_ro()
1654 free_wbufs(c); in ubifs_remount_ro()
1655 vfree(c->orph_buf); in ubifs_remount_ro()
1656 c->orph_buf = NULL; in ubifs_remount_ro()
1657 vfree(c->ileb_buf); in ubifs_remount_ro()
1658 c->ileb_buf = NULL; in ubifs_remount_ro()
1659 ubifs_lpt_free(c, 1); in ubifs_remount_ro()
1660 err = dbg_check_space_info(c); in ubifs_remount_ro()
1662 ubifs_ro_mode(c, err); in ubifs_remount_ro()
1663 mutex_unlock(&c->umount_mutex); in ubifs_remount_ro()
1669 struct ubifs_info *c = sb->s_fs_info; in ubifs_put_super() local
1671 ubifs_msg("un-mount UBI device %d, volume %d", c->vi.ubi_num, in ubifs_put_super()
1672 c->vi.vol_id); in ubifs_put_super()
1678 ubifs_assert(atomic_long_read(&c->dirty_pg_cnt) == 0); in ubifs_put_super()
1679 ubifs_assert(c->budg_idx_growth == 0); in ubifs_put_super()
1680 ubifs_assert(c->budg_dd_growth == 0); in ubifs_put_super()
1681 ubifs_assert(c->budg_data_growth == 0); in ubifs_put_super()
1689 mutex_lock(&c->umount_mutex); in ubifs_put_super()
1690 if (!(c->vfs_sb->s_flags & MS_RDONLY)) { in ubifs_put_super()
1695 if (c->bgt) { in ubifs_put_super()
1696 kthread_stop(c->bgt); in ubifs_put_super()
1697 c->bgt = NULL; in ubifs_put_super()
1701 if (c->jheads) in ubifs_put_super()
1702 for (i = 0; i < c->jhead_cnt; i++) { in ubifs_put_super()
1703 ubifs_wbuf_sync(&c->jheads[i].wbuf); in ubifs_put_super()
1704 del_timer_sync(&c->jheads[i].wbuf.timer); in ubifs_put_super()
1711 if (!c->ro_media) { in ubifs_put_super()
1719 c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); in ubifs_put_super()
1720 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); in ubifs_put_super()
1721 c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum); in ubifs_put_super()
1722 err = ubifs_write_master(c); in ubifs_put_super()
1734 ubifs_umount(c); in ubifs_put_super()
1735 bdi_destroy(&c->bdi); in ubifs_put_super()
1736 ubi_close_volume(c->ubi); in ubifs_put_super()
1737 mutex_unlock(&c->umount_mutex); in ubifs_put_super()
1738 kfree(c); in ubifs_put_super()
1744 struct ubifs_info *c = sb->s_fs_info; in ubifs_remount_fs() local
1748 err = ubifs_parse_options(c, data, 1); in ubifs_remount_fs()
1755 if (c->ro_media) { in ubifs_remount_fs()
1759 err = ubifs_remount_rw(c); in ubifs_remount_fs()
1763 if (c->ro_media) { in ubifs_remount_fs()
1767 ubifs_remount_ro(c); in ubifs_remount_fs()
1770 if (c->bulk_read == 1) in ubifs_remount_fs()
1771 bu_init(c); in ubifs_remount_fs()
1774 kfree(c->bu.buf); in ubifs_remount_fs()
1775 c->bu.buf = NULL; in ubifs_remount_fs()
1778 ubifs_assert(c->lst.taken_empty_lebs == 1); in ubifs_remount_fs()
1850 struct ubifs_info *c; in ubifs_fill_super() local
1854 c = kzalloc(sizeof(struct ubifs_info), GFP_KERNEL); in ubifs_fill_super()
1855 if (!c) in ubifs_fill_super()
1858 spin_lock_init(&c->cnt_lock); in ubifs_fill_super()
1859 spin_lock_init(&c->cs_lock); in ubifs_fill_super()
1860 spin_lock_init(&c->buds_lock); in ubifs_fill_super()
1861 spin_lock_init(&c->space_lock); in ubifs_fill_super()
1862 spin_lock_init(&c->orphan_lock); in ubifs_fill_super()
1863 init_rwsem(&c->commit_sem); in ubifs_fill_super()
1864 mutex_init(&c->lp_mutex); in ubifs_fill_super()
1865 mutex_init(&c->tnc_mutex); in ubifs_fill_super()
1866 mutex_init(&c->log_mutex); in ubifs_fill_super()
1867 mutex_init(&c->mst_mutex); in ubifs_fill_super()
1868 mutex_init(&c->umount_mutex); in ubifs_fill_super()
1869 mutex_init(&c->bu_mutex); in ubifs_fill_super()
1870 init_waitqueue_head(&c->cmt_wq); in ubifs_fill_super()
1871 c->buds = RB_ROOT; in ubifs_fill_super()
1872 c->old_idx = RB_ROOT; in ubifs_fill_super()
1873 c->size_tree = RB_ROOT; in ubifs_fill_super()
1874 c->orph_tree = RB_ROOT; in ubifs_fill_super()
1875 INIT_LIST_HEAD(&c->infos_list); in ubifs_fill_super()
1876 INIT_LIST_HEAD(&c->idx_gc); in ubifs_fill_super()
1877 INIT_LIST_HEAD(&c->replay_list); in ubifs_fill_super()
1878 INIT_LIST_HEAD(&c->replay_buds); in ubifs_fill_super()
1879 INIT_LIST_HEAD(&c->uncat_list); in ubifs_fill_super()
1880 INIT_LIST_HEAD(&c->empty_list); in ubifs_fill_super()
1881 INIT_LIST_HEAD(&c->freeable_list); in ubifs_fill_super()
1882 INIT_LIST_HEAD(&c->frdi_idx_list); in ubifs_fill_super()
1883 INIT_LIST_HEAD(&c->unclean_leb_list); in ubifs_fill_super()
1884 INIT_LIST_HEAD(&c->old_buds); in ubifs_fill_super()
1885 INIT_LIST_HEAD(&c->orph_list); in ubifs_fill_super()
1886 INIT_LIST_HEAD(&c->orph_new); in ubifs_fill_super()
1888 c->highest_inum = UBIFS_FIRST_INO; in ubifs_fill_super()
1889 c->lhead_lnum = c->ltail_lnum = UBIFS_LOG_LNUM; in ubifs_fill_super()
1891 ubi_get_volume_info(ubi, &c->vi); in ubifs_fill_super()
1892 ubi_get_device_info(c->vi.ubi_num, &c->di); in ubifs_fill_super()
1895 c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READWRITE); in ubifs_fill_super()
1896 if (IS_ERR(c->ubi)) { in ubifs_fill_super()
1897 err = PTR_ERR(c->ubi); in ubifs_fill_super()
1909 c->bdi.capabilities = BDI_CAP_MAP_COPY; in ubifs_fill_super()
1910 c->bdi.unplug_io_fn = default_unplug_io_fn; in ubifs_fill_super()
1911 err = bdi_init(&c->bdi); in ubifs_fill_super()
1915 err = ubifs_parse_options(c, data, 0); in ubifs_fill_super()
1919 c->vfs_sb = sb; in ubifs_fill_super()
1921 sb->s_fs_info = c; in ubifs_fill_super()
1925 sb->s_dev = c->vi.cdev; in ubifs_fill_super()
1926 sb->s_maxbytes = c->max_inode_sz = key_max_inode_size(c); in ubifs_fill_super()
1927 if (c->max_inode_sz > MAX_LFS_FILESIZE) in ubifs_fill_super()
1928 sb->s_maxbytes = c->max_inode_sz = MAX_LFS_FILESIZE; in ubifs_fill_super()
1931 mutex_lock(&c->umount_mutex); in ubifs_fill_super()
1932 err = mount_ubifs(c); in ubifs_fill_super()
1949 mutex_unlock(&c->umount_mutex); in ubifs_fill_super()
1955 ubifs_umount(c); in ubifs_fill_super()
1957 mutex_unlock(&c->umount_mutex); in ubifs_fill_super()
1959 bdi_destroy(&c->bdi); in ubifs_fill_super()
1961 ubi_close_volume(c->ubi); in ubifs_fill_super()
1963 kfree(c); in ubifs_fill_super()