diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
commit | c71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch) | |
tree | ecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /fs/ubifs/super.c | |
parent | ea53c912f8a86a8567697115b6a0d8152beee5c8 (diff) | |
parent | 6a00f206debf8a5c8899055726ad127dbeeed098 (diff) |
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts:
litmus/sched_cedf.c
Diffstat (limited to 'fs/ubifs/super.c')
-rw-r--r-- | fs/ubifs/super.c | 393 |
1 files changed, 241 insertions, 152 deletions
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index cd5900b85d38..529be0582029 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c | |||
@@ -272,12 +272,20 @@ static struct inode *ubifs_alloc_inode(struct super_block *sb) | |||
272 | return &ui->vfs_inode; | 272 | return &ui->vfs_inode; |
273 | }; | 273 | }; |
274 | 274 | ||
275 | static void ubifs_i_callback(struct rcu_head *head) | ||
276 | { | ||
277 | struct inode *inode = container_of(head, struct inode, i_rcu); | ||
278 | struct ubifs_inode *ui = ubifs_inode(inode); | ||
279 | INIT_LIST_HEAD(&inode->i_dentry); | ||
280 | kmem_cache_free(ubifs_inode_slab, ui); | ||
281 | } | ||
282 | |||
275 | static void ubifs_destroy_inode(struct inode *inode) | 283 | static void ubifs_destroy_inode(struct inode *inode) |
276 | { | 284 | { |
277 | struct ubifs_inode *ui = ubifs_inode(inode); | 285 | struct ubifs_inode *ui = ubifs_inode(inode); |
278 | 286 | ||
279 | kfree(ui->data); | 287 | kfree(ui->data); |
280 | kmem_cache_free(ubifs_inode_slab, inode); | 288 | call_rcu(&inode->i_rcu, ubifs_i_callback); |
281 | } | 289 | } |
282 | 290 | ||
283 | /* | 291 | /* |
@@ -367,14 +375,14 @@ out: | |||
367 | ubifs_release_dirty_inode_budget(c, ui); | 375 | ubifs_release_dirty_inode_budget(c, ui); |
368 | else { | 376 | else { |
369 | /* We've deleted something - clean the "no space" flags */ | 377 | /* We've deleted something - clean the "no space" flags */ |
370 | c->nospace = c->nospace_rp = 0; | 378 | c->bi.nospace = c->bi.nospace_rp = 0; |
371 | smp_wmb(); | 379 | smp_wmb(); |
372 | } | 380 | } |
373 | done: | 381 | done: |
374 | end_writeback(inode); | 382 | end_writeback(inode); |
375 | } | 383 | } |
376 | 384 | ||
377 | static void ubifs_dirty_inode(struct inode *inode) | 385 | static void ubifs_dirty_inode(struct inode *inode, int flags) |
378 | { | 386 | { |
379 | struct ubifs_inode *ui = ubifs_inode(inode); | 387 | struct ubifs_inode *ui = ubifs_inode(inode); |
380 | 388 | ||
@@ -504,9 +512,12 @@ static int init_constants_early(struct ubifs_info *c) | |||
504 | 512 | ||
505 | c->leb_cnt = c->vi.size; | 513 | c->leb_cnt = c->vi.size; |
506 | c->leb_size = c->vi.usable_leb_size; | 514 | c->leb_size = c->vi.usable_leb_size; |
515 | c->leb_start = c->di.leb_start; | ||
507 | c->half_leb_size = c->leb_size / 2; | 516 | c->half_leb_size = c->leb_size / 2; |
508 | c->min_io_size = c->di.min_io_size; | 517 | c->min_io_size = c->di.min_io_size; |
509 | c->min_io_shift = fls(c->min_io_size) - 1; | 518 | c->min_io_shift = fls(c->min_io_size) - 1; |
519 | c->max_write_size = c->di.max_write_size; | ||
520 | c->max_write_shift = fls(c->max_write_size) - 1; | ||
510 | 521 | ||
511 | if (c->leb_size < UBIFS_MIN_LEB_SZ) { | 522 | if (c->leb_size < UBIFS_MIN_LEB_SZ) { |
512 | ubifs_err("too small LEBs (%d bytes), min. is %d bytes", | 523 | ubifs_err("too small LEBs (%d bytes), min. is %d bytes", |
@@ -526,6 +537,18 @@ static int init_constants_early(struct ubifs_info *c) | |||
526 | } | 537 | } |
527 | 538 | ||
528 | /* | 539 | /* |
540 | * Maximum write size has to be greater or equivalent to min. I/O | ||
541 | * size, and be multiple of min. I/O size. | ||
542 | */ | ||
543 | if (c->max_write_size < c->min_io_size || | ||
544 | c->max_write_size % c->min_io_size || | ||
545 | !is_power_of_2(c->max_write_size)) { | ||
546 | ubifs_err("bad write buffer size %d for %d min. I/O unit", | ||
547 | c->max_write_size, c->min_io_size); | ||
548 | return -EINVAL; | ||
549 | } | ||
550 | |||
551 | /* | ||
529 | * UBIFS aligns all node to 8-byte boundary, so to make function in | 552 | * UBIFS aligns all node to 8-byte boundary, so to make function in |
530 | * io.c simpler, assume minimum I/O unit size to be 8 bytes if it is | 553 | * io.c simpler, assume minimum I/O unit size to be 8 bytes if it is |
531 | * less than 8. | 554 | * less than 8. |
@@ -533,6 +556,10 @@ static int init_constants_early(struct ubifs_info *c) | |||
533 | if (c->min_io_size < 8) { | 556 | if (c->min_io_size < 8) { |
534 | c->min_io_size = 8; | 557 | c->min_io_size = 8; |
535 | c->min_io_shift = 3; | 558 | c->min_io_shift = 3; |
559 | if (c->max_write_size < c->min_io_size) { | ||
560 | c->max_write_size = c->min_io_size; | ||
561 | c->max_write_shift = c->min_io_shift; | ||
562 | } | ||
536 | } | 563 | } |
537 | 564 | ||
538 | c->ref_node_alsz = ALIGN(UBIFS_REF_NODE_SZ, c->min_io_size); | 565 | c->ref_node_alsz = ALIGN(UBIFS_REF_NODE_SZ, c->min_io_size); |
@@ -667,11 +694,11 @@ static int init_constants_sb(struct ubifs_info *c) | |||
667 | * be compressed and direntries are of the maximum size. | 694 | * be compressed and direntries are of the maximum size. |
668 | * | 695 | * |
669 | * Note, data, which may be stored in inodes is budgeted separately, so | 696 | * Note, data, which may be stored in inodes is budgeted separately, so |
670 | * it is not included into 'c->inode_budget'. | 697 | * it is not included into 'c->bi.inode_budget'. |
671 | */ | 698 | */ |
672 | c->page_budget = UBIFS_MAX_DATA_NODE_SZ * UBIFS_BLOCKS_PER_PAGE; | 699 | c->bi.page_budget = UBIFS_MAX_DATA_NODE_SZ * UBIFS_BLOCKS_PER_PAGE; |
673 | c->inode_budget = UBIFS_INO_NODE_SZ; | 700 | c->bi.inode_budget = UBIFS_INO_NODE_SZ; |
674 | c->dent_budget = UBIFS_MAX_DENT_NODE_SZ; | 701 | c->bi.dent_budget = UBIFS_MAX_DENT_NODE_SZ; |
675 | 702 | ||
676 | /* | 703 | /* |
677 | * When the amount of flash space used by buds becomes | 704 | * When the amount of flash space used by buds becomes |
@@ -715,7 +742,7 @@ static void init_constants_master(struct ubifs_info *c) | |||
715 | { | 742 | { |
716 | long long tmp64; | 743 | long long tmp64; |
717 | 744 | ||
718 | c->min_idx_lebs = ubifs_calc_min_idx_lebs(c); | 745 | c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c); |
719 | c->report_rp_size = ubifs_reported_space(c, c->rp_size); | 746 | c->report_rp_size = ubifs_reported_space(c, c->rp_size); |
720 | 747 | ||
721 | /* | 748 | /* |
@@ -784,15 +811,18 @@ static int alloc_wbufs(struct ubifs_info *c) | |||
784 | 811 | ||
785 | c->jheads[i].wbuf.sync_callback = &bud_wbuf_callback; | 812 | c->jheads[i].wbuf.sync_callback = &bud_wbuf_callback; |
786 | c->jheads[i].wbuf.jhead = i; | 813 | c->jheads[i].wbuf.jhead = i; |
814 | c->jheads[i].grouped = 1; | ||
787 | } | 815 | } |
788 | 816 | ||
789 | c->jheads[BASEHD].wbuf.dtype = UBI_SHORTTERM; | 817 | c->jheads[BASEHD].wbuf.dtype = UBI_SHORTTERM; |
790 | /* | 818 | /* |
791 | * Garbage Collector head likely contains long-term data and | 819 | * Garbage Collector head likely contains long-term data and |
792 | * does not need to be synchronized by timer. | 820 | * does not need to be synchronized by timer. Also GC head nodes are |
821 | * not grouped. | ||
793 | */ | 822 | */ |
794 | c->jheads[GCHD].wbuf.dtype = UBI_LONGTERM; | 823 | c->jheads[GCHD].wbuf.dtype = UBI_LONGTERM; |
795 | c->jheads[GCHD].wbuf.no_timer = 1; | 824 | c->jheads[GCHD].wbuf.no_timer = 1; |
825 | c->jheads[GCHD].grouped = 0; | ||
796 | 826 | ||
797 | return 0; | 827 | return 0; |
798 | } | 828 | } |
@@ -1117,8 +1147,8 @@ static int check_free_space(struct ubifs_info *c) | |||
1117 | { | 1147 | { |
1118 | ubifs_assert(c->dark_wm > 0); | 1148 | ubifs_assert(c->dark_wm > 0); |
1119 | if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) { | 1149 | if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) { |
1120 | ubifs_err("insufficient free space to mount in read/write mode"); | 1150 | ubifs_err("insufficient free space to mount in R/W mode"); |
1121 | dbg_dump_budg(c); | 1151 | dbg_dump_budg(c, &c->bi); |
1122 | dbg_dump_lprops(c); | 1152 | dbg_dump_lprops(c); |
1123 | return -ENOSPC; | 1153 | return -ENOSPC; |
1124 | } | 1154 | } |
@@ -1137,11 +1167,11 @@ static int check_free_space(struct ubifs_info *c) | |||
1137 | */ | 1167 | */ |
1138 | static int mount_ubifs(struct ubifs_info *c) | 1168 | static int mount_ubifs(struct ubifs_info *c) |
1139 | { | 1169 | { |
1140 | struct super_block *sb = c->vfs_sb; | 1170 | int err; |
1141 | int err, mounted_read_only = (sb->s_flags & MS_RDONLY); | ||
1142 | long long x; | 1171 | long long x; |
1143 | size_t sz; | 1172 | size_t sz; |
1144 | 1173 | ||
1174 | c->ro_mount = !!(c->vfs_sb->s_flags & MS_RDONLY); | ||
1145 | err = init_constants_early(c); | 1175 | err = init_constants_early(c); |
1146 | if (err) | 1176 | if (err) |
1147 | return err; | 1177 | return err; |
@@ -1154,7 +1184,7 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1154 | if (err) | 1184 | if (err) |
1155 | goto out_free; | 1185 | goto out_free; |
1156 | 1186 | ||
1157 | if (c->empty && (mounted_read_only || c->ro_media)) { | 1187 | if (c->empty && (c->ro_mount || c->ro_media)) { |
1158 | /* | 1188 | /* |
1159 | * This UBI volume is empty, and read-only, or the file system | 1189 | * This UBI volume is empty, and read-only, or the file system |
1160 | * is mounted read-only - we cannot format it. | 1190 | * is mounted read-only - we cannot format it. |
@@ -1165,7 +1195,7 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1165 | goto out_free; | 1195 | goto out_free; |
1166 | } | 1196 | } |
1167 | 1197 | ||
1168 | if (c->ro_media && !mounted_read_only) { | 1198 | if (c->ro_media && !c->ro_mount) { |
1169 | ubifs_err("cannot mount read-write - read-only media"); | 1199 | ubifs_err("cannot mount read-write - read-only media"); |
1170 | err = -EROFS; | 1200 | err = -EROFS; |
1171 | goto out_free; | 1201 | goto out_free; |
@@ -1185,7 +1215,7 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1185 | if (!c->sbuf) | 1215 | if (!c->sbuf) |
1186 | goto out_free; | 1216 | goto out_free; |
1187 | 1217 | ||
1188 | if (!mounted_read_only) { | 1218 | if (!c->ro_mount) { |
1189 | c->ileb_buf = vmalloc(c->leb_size); | 1219 | c->ileb_buf = vmalloc(c->leb_size); |
1190 | if (!c->ileb_buf) | 1220 | if (!c->ileb_buf) |
1191 | goto out_free; | 1221 | goto out_free; |
@@ -1194,11 +1224,14 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1194 | if (c->bulk_read == 1) | 1224 | if (c->bulk_read == 1) |
1195 | bu_init(c); | 1225 | bu_init(c); |
1196 | 1226 | ||
1197 | /* | 1227 | if (!c->ro_mount) { |
1198 | * We have to check all CRCs, even for data nodes, when we mount the FS | 1228 | c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ, |
1199 | * (specifically, when we are replaying). | 1229 | GFP_KERNEL); |
1200 | */ | 1230 | if (!c->write_reserve_buf) |
1201 | c->always_chk_crc = 1; | 1231 | goto out_free; |
1232 | } | ||
1233 | |||
1234 | c->mounting = 1; | ||
1202 | 1235 | ||
1203 | err = ubifs_read_superblock(c); | 1236 | err = ubifs_read_superblock(c); |
1204 | if (err) | 1237 | if (err) |
@@ -1227,12 +1260,12 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1227 | goto out_free; | 1260 | goto out_free; |
1228 | } | 1261 | } |
1229 | 1262 | ||
1230 | sprintf(c->bgt_name, BGT_NAME_PATTERN, c->vi.ubi_num, c->vi.vol_id); | 1263 | err = alloc_wbufs(c); |
1231 | if (!mounted_read_only) { | 1264 | if (err) |
1232 | err = alloc_wbufs(c); | 1265 | goto out_cbuf; |
1233 | if (err) | ||
1234 | goto out_cbuf; | ||
1235 | 1266 | ||
1267 | sprintf(c->bgt_name, BGT_NAME_PATTERN, c->vi.ubi_num, c->vi.vol_id); | ||
1268 | if (!c->ro_mount) { | ||
1236 | /* Create background thread */ | 1269 | /* Create background thread */ |
1237 | c->bgt = kthread_create(ubifs_bg_thread, c, "%s", c->bgt_name); | 1270 | c->bgt = kthread_create(ubifs_bg_thread, c, "%s", c->bgt_name); |
1238 | if (IS_ERR(c->bgt)) { | 1271 | if (IS_ERR(c->bgt)) { |
@@ -1254,12 +1287,25 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1254 | if ((c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY)) != 0) { | 1287 | if ((c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY)) != 0) { |
1255 | ubifs_msg("recovery needed"); | 1288 | ubifs_msg("recovery needed"); |
1256 | c->need_recovery = 1; | 1289 | c->need_recovery = 1; |
1257 | if (!mounted_read_only) { | 1290 | } |
1258 | err = ubifs_recover_inl_heads(c, c->sbuf); | 1291 | |
1259 | if (err) | 1292 | if (c->need_recovery && !c->ro_mount) { |
1260 | goto out_master; | 1293 | err = ubifs_recover_inl_heads(c, c->sbuf); |
1261 | } | 1294 | if (err) |
1262 | } else if (!mounted_read_only) { | 1295 | goto out_master; |
1296 | } | ||
1297 | |||
1298 | err = ubifs_lpt_init(c, 1, !c->ro_mount); | ||
1299 | if (err) | ||
1300 | goto out_master; | ||
1301 | |||
1302 | if (!c->ro_mount && c->space_fixup) { | ||
1303 | err = ubifs_fixup_free_space(c); | ||
1304 | if (err) | ||
1305 | goto out_master; | ||
1306 | } | ||
1307 | |||
1308 | if (!c->ro_mount) { | ||
1263 | /* | 1309 | /* |
1264 | * Set the "dirty" flag so that if we reboot uncleanly we | 1310 | * Set the "dirty" flag so that if we reboot uncleanly we |
1265 | * will notice this immediately on the next mount. | 1311 | * will notice this immediately on the next mount. |
@@ -1267,14 +1313,10 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1267 | c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY); | 1313 | c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY); |
1268 | err = ubifs_write_master(c); | 1314 | err = ubifs_write_master(c); |
1269 | if (err) | 1315 | if (err) |
1270 | goto out_master; | 1316 | goto out_lpt; |
1271 | } | 1317 | } |
1272 | 1318 | ||
1273 | err = ubifs_lpt_init(c, 1, !mounted_read_only); | 1319 | err = dbg_check_idx_size(c, c->bi.old_idx_sz); |
1274 | if (err) | ||
1275 | goto out_lpt; | ||
1276 | |||
1277 | err = dbg_check_idx_size(c, c->old_idx_sz); | ||
1278 | if (err) | 1320 | if (err) |
1279 | goto out_lpt; | 1321 | goto out_lpt; |
1280 | 1322 | ||
@@ -1283,13 +1325,13 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1283 | goto out_journal; | 1325 | goto out_journal; |
1284 | 1326 | ||
1285 | /* Calculate 'min_idx_lebs' after journal replay */ | 1327 | /* Calculate 'min_idx_lebs' after journal replay */ |
1286 | c->min_idx_lebs = ubifs_calc_min_idx_lebs(c); | 1328 | c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c); |
1287 | 1329 | ||
1288 | err = ubifs_mount_orphans(c, c->need_recovery, mounted_read_only); | 1330 | err = ubifs_mount_orphans(c, c->need_recovery, c->ro_mount); |
1289 | if (err) | 1331 | if (err) |
1290 | goto out_orphans; | 1332 | goto out_orphans; |
1291 | 1333 | ||
1292 | if (!mounted_read_only) { | 1334 | if (!c->ro_mount) { |
1293 | int lnum; | 1335 | int lnum; |
1294 | 1336 | ||
1295 | err = check_free_space(c); | 1337 | err = check_free_space(c); |
@@ -1351,7 +1393,7 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1351 | spin_unlock(&ubifs_infos_lock); | 1393 | spin_unlock(&ubifs_infos_lock); |
1352 | 1394 | ||
1353 | if (c->need_recovery) { | 1395 | if (c->need_recovery) { |
1354 | if (mounted_read_only) | 1396 | if (c->ro_mount) |
1355 | ubifs_msg("recovery deferred"); | 1397 | ubifs_msg("recovery deferred"); |
1356 | else { | 1398 | else { |
1357 | c->need_recovery = 0; | 1399 | c->need_recovery = 0; |
@@ -1374,11 +1416,11 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1374 | if (err) | 1416 | if (err) |
1375 | goto out_infos; | 1417 | goto out_infos; |
1376 | 1418 | ||
1377 | c->always_chk_crc = 0; | 1419 | c->mounting = 0; |
1378 | 1420 | ||
1379 | ubifs_msg("mounted UBI device %d, volume %d, name \"%s\"", | 1421 | ubifs_msg("mounted UBI device %d, volume %d, name \"%s\"", |
1380 | c->vi.ubi_num, c->vi.vol_id, c->vi.name); | 1422 | c->vi.ubi_num, c->vi.vol_id, c->vi.name); |
1381 | if (mounted_read_only) | 1423 | if (c->ro_mount) |
1382 | ubifs_msg("mounted read-only"); | 1424 | ubifs_msg("mounted read-only"); |
1383 | x = (long long)c->main_lebs * c->leb_size; | 1425 | x = (long long)c->main_lebs * c->leb_size; |
1384 | ubifs_msg("file system size: %lld bytes (%lld KiB, %lld MiB, %d " | 1426 | ubifs_msg("file system size: %lld bytes (%lld KiB, %lld MiB, %d " |
@@ -1395,6 +1437,7 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1395 | 1437 | ||
1396 | dbg_msg("compiled on: " __DATE__ " at " __TIME__); | 1438 | dbg_msg("compiled on: " __DATE__ " at " __TIME__); |
1397 | dbg_msg("min. I/O unit size: %d bytes", c->min_io_size); | 1439 | dbg_msg("min. I/O unit size: %d bytes", c->min_io_size); |
1440 | dbg_msg("max. write size: %d bytes", c->max_write_size); | ||
1398 | dbg_msg("LEB size: %d bytes (%d KiB)", | 1441 | dbg_msg("LEB size: %d bytes (%d KiB)", |
1399 | c->leb_size, c->leb_size >> 10); | 1442 | c->leb_size, c->leb_size >> 10); |
1400 | dbg_msg("data journal heads: %d", | 1443 | dbg_msg("data journal heads: %d", |
@@ -1411,7 +1454,8 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1411 | c->main_lebs, c->main_first, c->leb_cnt - 1); | 1454 | c->main_lebs, c->main_first, c->leb_cnt - 1); |
1412 | dbg_msg("index LEBs: %d", c->lst.idx_lebs); | 1455 | dbg_msg("index LEBs: %d", c->lst.idx_lebs); |
1413 | dbg_msg("total index bytes: %lld (%lld KiB, %lld MiB)", | 1456 | dbg_msg("total index bytes: %lld (%lld KiB, %lld MiB)", |
1414 | c->old_idx_sz, c->old_idx_sz >> 10, c->old_idx_sz >> 20); | 1457 | c->bi.old_idx_sz, c->bi.old_idx_sz >> 10, |
1458 | c->bi.old_idx_sz >> 20); | ||
1415 | dbg_msg("key hash type: %d", c->key_hash_type); | 1459 | dbg_msg("key hash type: %d", c->key_hash_type); |
1416 | dbg_msg("tree fanout: %d", c->fanout); | 1460 | dbg_msg("tree fanout: %d", c->fanout); |
1417 | dbg_msg("reserved GC LEB: %d", c->gc_lnum); | 1461 | dbg_msg("reserved GC LEB: %d", c->gc_lnum); |
@@ -1424,9 +1468,9 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1424 | UBIFS_TRUN_NODE_SZ, UBIFS_SB_NODE_SZ, UBIFS_MST_NODE_SZ); | 1468 | UBIFS_TRUN_NODE_SZ, UBIFS_SB_NODE_SZ, UBIFS_MST_NODE_SZ); |
1425 | dbg_msg("node sizes: ref %zu, cmt. start %zu, orph %zu", | 1469 | dbg_msg("node sizes: ref %zu, cmt. start %zu, orph %zu", |
1426 | UBIFS_REF_NODE_SZ, UBIFS_CS_NODE_SZ, UBIFS_ORPH_NODE_SZ); | 1470 | UBIFS_REF_NODE_SZ, UBIFS_CS_NODE_SZ, UBIFS_ORPH_NODE_SZ); |
1427 | dbg_msg("max. node sizes: data %zu, inode %zu dentry %zu", | 1471 | dbg_msg("max. node sizes: data %zu, inode %zu dentry %zu, idx %d", |
1428 | UBIFS_MAX_DATA_NODE_SZ, UBIFS_MAX_INO_NODE_SZ, | 1472 | UBIFS_MAX_DATA_NODE_SZ, UBIFS_MAX_INO_NODE_SZ, |
1429 | UBIFS_MAX_DENT_NODE_SZ); | 1473 | UBIFS_MAX_DENT_NODE_SZ, ubifs_idx_node_sz(c, c->fanout)); |
1430 | dbg_msg("dead watermark: %d", c->dead_wm); | 1474 | dbg_msg("dead watermark: %d", c->dead_wm); |
1431 | dbg_msg("dark watermark: %d", c->dark_wm); | 1475 | dbg_msg("dark watermark: %d", c->dark_wm); |
1432 | dbg_msg("LEB overhead: %d", c->leb_overhead); | 1476 | dbg_msg("LEB overhead: %d", c->leb_overhead); |
@@ -1466,6 +1510,7 @@ out_wbufs: | |||
1466 | out_cbuf: | 1510 | out_cbuf: |
1467 | kfree(c->cbuf); | 1511 | kfree(c->cbuf); |
1468 | out_free: | 1512 | out_free: |
1513 | kfree(c->write_reserve_buf); | ||
1469 | kfree(c->bu.buf); | 1514 | kfree(c->bu.buf); |
1470 | vfree(c->ileb_buf); | 1515 | vfree(c->ileb_buf); |
1471 | vfree(c->sbuf); | 1516 | vfree(c->sbuf); |
@@ -1504,6 +1549,7 @@ static void ubifs_umount(struct ubifs_info *c) | |||
1504 | kfree(c->cbuf); | 1549 | kfree(c->cbuf); |
1505 | kfree(c->rcvrd_mst_node); | 1550 | kfree(c->rcvrd_mst_node); |
1506 | kfree(c->mst_node); | 1551 | kfree(c->mst_node); |
1552 | kfree(c->write_reserve_buf); | ||
1507 | kfree(c->bu.buf); | 1553 | kfree(c->bu.buf); |
1508 | vfree(c->ileb_buf); | 1554 | vfree(c->ileb_buf); |
1509 | vfree(c->sbuf); | 1555 | vfree(c->sbuf); |
@@ -1535,7 +1581,7 @@ static int ubifs_remount_rw(struct ubifs_info *c) | |||
1535 | mutex_lock(&c->umount_mutex); | 1581 | mutex_lock(&c->umount_mutex); |
1536 | dbg_save_space_info(c); | 1582 | dbg_save_space_info(c); |
1537 | c->remounting_rw = 1; | 1583 | c->remounting_rw = 1; |
1538 | c->always_chk_crc = 1; | 1584 | c->ro_mount = 0; |
1539 | 1585 | ||
1540 | err = check_free_space(c); | 1586 | err = check_free_space(c); |
1541 | if (err) | 1587 | if (err) |
@@ -1551,6 +1597,7 @@ static int ubifs_remount_rw(struct ubifs_info *c) | |||
1551 | } | 1597 | } |
1552 | sup->leb_cnt = cpu_to_le32(c->leb_cnt); | 1598 | sup->leb_cnt = cpu_to_le32(c->leb_cnt); |
1553 | err = ubifs_write_sb_node(c, sup); | 1599 | err = ubifs_write_sb_node(c, sup); |
1600 | kfree(sup); | ||
1554 | if (err) | 1601 | if (err) |
1555 | goto out; | 1602 | goto out; |
1556 | } | 1603 | } |
@@ -1590,16 +1637,14 @@ static int ubifs_remount_rw(struct ubifs_info *c) | |||
1590 | goto out; | 1637 | goto out; |
1591 | } | 1638 | } |
1592 | 1639 | ||
1593 | err = ubifs_lpt_init(c, 0, 1); | 1640 | c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ, GFP_KERNEL); |
1594 | if (err) | 1641 | if (!c->write_reserve_buf) |
1595 | goto out; | 1642 | goto out; |
1596 | 1643 | ||
1597 | err = alloc_wbufs(c); | 1644 | err = ubifs_lpt_init(c, 0, 1); |
1598 | if (err) | 1645 | if (err) |
1599 | goto out; | 1646 | goto out; |
1600 | 1647 | ||
1601 | ubifs_create_buds_lists(c); | ||
1602 | |||
1603 | /* Create background thread */ | 1648 | /* Create background thread */ |
1604 | c->bgt = kthread_create(ubifs_bg_thread, c, "%s", c->bgt_name); | 1649 | c->bgt = kthread_create(ubifs_bg_thread, c, "%s", c->bgt_name); |
1605 | if (IS_ERR(c->bgt)) { | 1650 | if (IS_ERR(c->bgt)) { |
@@ -1634,20 +1679,37 @@ static int ubifs_remount_rw(struct ubifs_info *c) | |||
1634 | if (err) | 1679 | if (err) |
1635 | goto out; | 1680 | goto out; |
1636 | 1681 | ||
1682 | dbg_gen("re-mounted read-write"); | ||
1683 | c->remounting_rw = 0; | ||
1684 | |||
1637 | if (c->need_recovery) { | 1685 | if (c->need_recovery) { |
1638 | c->need_recovery = 0; | 1686 | c->need_recovery = 0; |
1639 | ubifs_msg("deferred recovery completed"); | 1687 | ubifs_msg("deferred recovery completed"); |
1688 | } else { | ||
1689 | /* | ||
1690 | * Do not run the debugging space check if the were doing | ||
1691 | * recovery, because when we saved the information we had the | ||
1692 | * file-system in a state where the TNC and lprops has been | ||
1693 | * modified in memory, but all the I/O operations (including a | ||
1694 | * commit) were deferred. So the file-system was in | ||
1695 | * "non-committed" state. Now the file-system is in committed | ||
1696 | * state, and of course the amount of free space will change | ||
1697 | * because, for example, the old index size was imprecise. | ||
1698 | */ | ||
1699 | err = dbg_check_space_info(c); | ||
1700 | } | ||
1701 | |||
1702 | if (c->space_fixup) { | ||
1703 | err = ubifs_fixup_free_space(c); | ||
1704 | if (err) | ||
1705 | goto out; | ||
1640 | } | 1706 | } |
1641 | 1707 | ||
1642 | dbg_gen("re-mounted read-write"); | ||
1643 | c->vfs_sb->s_flags &= ~MS_RDONLY; | ||
1644 | c->remounting_rw = 0; | ||
1645 | c->always_chk_crc = 0; | ||
1646 | err = dbg_check_space_info(c); | ||
1647 | mutex_unlock(&c->umount_mutex); | 1708 | mutex_unlock(&c->umount_mutex); |
1648 | return err; | 1709 | return err; |
1649 | 1710 | ||
1650 | out: | 1711 | out: |
1712 | c->ro_mount = 1; | ||
1651 | vfree(c->orph_buf); | 1713 | vfree(c->orph_buf); |
1652 | c->orph_buf = NULL; | 1714 | c->orph_buf = NULL; |
1653 | if (c->bgt) { | 1715 | if (c->bgt) { |
@@ -1655,11 +1717,12 @@ out: | |||
1655 | c->bgt = NULL; | 1717 | c->bgt = NULL; |
1656 | } | 1718 | } |
1657 | free_wbufs(c); | 1719 | free_wbufs(c); |
1720 | kfree(c->write_reserve_buf); | ||
1721 | c->write_reserve_buf = NULL; | ||
1658 | vfree(c->ileb_buf); | 1722 | vfree(c->ileb_buf); |
1659 | c->ileb_buf = NULL; | 1723 | c->ileb_buf = NULL; |
1660 | ubifs_lpt_free(c, 1); | 1724 | ubifs_lpt_free(c, 1); |
1661 | c->remounting_rw = 0; | 1725 | c->remounting_rw = 0; |
1662 | c->always_chk_crc = 0; | ||
1663 | mutex_unlock(&c->umount_mutex); | 1726 | mutex_unlock(&c->umount_mutex); |
1664 | return err; | 1727 | return err; |
1665 | } | 1728 | } |
@@ -1676,7 +1739,7 @@ static void ubifs_remount_ro(struct ubifs_info *c) | |||
1676 | int i, err; | 1739 | int i, err; |
1677 | 1740 | ||
1678 | ubifs_assert(!c->need_recovery); | 1741 | ubifs_assert(!c->need_recovery); |
1679 | ubifs_assert(!(c->vfs_sb->s_flags & MS_RDONLY)); | 1742 | ubifs_assert(!c->ro_mount); |
1680 | 1743 | ||
1681 | mutex_lock(&c->umount_mutex); | 1744 | mutex_lock(&c->umount_mutex); |
1682 | if (c->bgt) { | 1745 | if (c->bgt) { |
@@ -1686,10 +1749,8 @@ static void ubifs_remount_ro(struct ubifs_info *c) | |||
1686 | 1749 | ||
1687 | dbg_save_space_info(c); | 1750 | dbg_save_space_info(c); |
1688 | 1751 | ||
1689 | for (i = 0; i < c->jhead_cnt; i++) { | 1752 | for (i = 0; i < c->jhead_cnt; i++) |
1690 | ubifs_wbuf_sync(&c->jheads[i].wbuf); | 1753 | ubifs_wbuf_sync(&c->jheads[i].wbuf); |
1691 | hrtimer_cancel(&c->jheads[i].wbuf.timer); | ||
1692 | } | ||
1693 | 1754 | ||
1694 | c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); | 1755 | c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); |
1695 | c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); | 1756 | c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); |
@@ -1698,12 +1759,14 @@ static void ubifs_remount_ro(struct ubifs_info *c) | |||
1698 | if (err) | 1759 | if (err) |
1699 | ubifs_ro_mode(c, err); | 1760 | ubifs_ro_mode(c, err); |
1700 | 1761 | ||
1701 | free_wbufs(c); | ||
1702 | vfree(c->orph_buf); | 1762 | vfree(c->orph_buf); |
1703 | c->orph_buf = NULL; | 1763 | c->orph_buf = NULL; |
1764 | kfree(c->write_reserve_buf); | ||
1765 | c->write_reserve_buf = NULL; | ||
1704 | vfree(c->ileb_buf); | 1766 | vfree(c->ileb_buf); |
1705 | c->ileb_buf = NULL; | 1767 | c->ileb_buf = NULL; |
1706 | ubifs_lpt_free(c, 1); | 1768 | ubifs_lpt_free(c, 1); |
1769 | c->ro_mount = 1; | ||
1707 | err = dbg_check_space_info(c); | 1770 | err = dbg_check_space_info(c); |
1708 | if (err) | 1771 | if (err) |
1709 | ubifs_ro_mode(c, err); | 1772 | ubifs_ro_mode(c, err); |
@@ -1723,10 +1786,11 @@ static void ubifs_put_super(struct super_block *sb) | |||
1723 | * of the media. For example, there will be dirty inodes if we failed | 1786 | * of the media. For example, there will be dirty inodes if we failed |
1724 | * to write them back because of I/O errors. | 1787 | * to write them back because of I/O errors. |
1725 | */ | 1788 | */ |
1726 | ubifs_assert(atomic_long_read(&c->dirty_pg_cnt) == 0); | 1789 | if (!c->ro_error) { |
1727 | ubifs_assert(c->budg_idx_growth == 0); | 1790 | ubifs_assert(c->bi.idx_growth == 0); |
1728 | ubifs_assert(c->budg_dd_growth == 0); | 1791 | ubifs_assert(c->bi.dd_growth == 0); |
1729 | ubifs_assert(c->budg_data_growth == 0); | 1792 | ubifs_assert(c->bi.data_growth == 0); |
1793 | } | ||
1730 | 1794 | ||
1731 | /* | 1795 | /* |
1732 | * The 'c->umount_lock' prevents races between UBIFS memory shrinker | 1796 | * The 'c->umount_lock' prevents races between UBIFS memory shrinker |
@@ -1735,7 +1799,7 @@ static void ubifs_put_super(struct super_block *sb) | |||
1735 | * the mutex is locked. | 1799 | * the mutex is locked. |
1736 | */ | 1800 | */ |
1737 | mutex_lock(&c->umount_mutex); | 1801 | mutex_lock(&c->umount_mutex); |
1738 | if (!(c->vfs_sb->s_flags & MS_RDONLY)) { | 1802 | if (!c->ro_mount) { |
1739 | /* | 1803 | /* |
1740 | * First of all kill the background thread to make sure it does | 1804 | * First of all kill the background thread to make sure it does |
1741 | * not interfere with un-mounting and freeing resources. | 1805 | * not interfere with un-mounting and freeing resources. |
@@ -1745,23 +1809,22 @@ static void ubifs_put_super(struct super_block *sb) | |||
1745 | c->bgt = NULL; | 1809 | c->bgt = NULL; |
1746 | } | 1810 | } |
1747 | 1811 | ||
1748 | /* Synchronize write-buffers */ | ||
1749 | if (c->jheads) | ||
1750 | for (i = 0; i < c->jhead_cnt; i++) | ||
1751 | ubifs_wbuf_sync(&c->jheads[i].wbuf); | ||
1752 | |||
1753 | /* | 1812 | /* |
1754 | * On fatal errors c->ro_media is set to 1, in which case we do | 1813 | * On fatal errors c->ro_error is set to 1, in which case we do |
1755 | * not write the master node. | 1814 | * not write the master node. |
1756 | */ | 1815 | */ |
1757 | if (!c->ro_media) { | 1816 | if (!c->ro_error) { |
1817 | int err; | ||
1818 | |||
1819 | /* Synchronize write-buffers */ | ||
1820 | for (i = 0; i < c->jhead_cnt; i++) | ||
1821 | ubifs_wbuf_sync(&c->jheads[i].wbuf); | ||
1822 | |||
1758 | /* | 1823 | /* |
1759 | * We are being cleanly unmounted which means the | 1824 | * We are being cleanly unmounted which means the |
1760 | * orphans were killed - indicate this in the master | 1825 | * orphans were killed - indicate this in the master |
1761 | * node. Also save the reserved GC LEB number. | 1826 | * node. Also save the reserved GC LEB number. |
1762 | */ | 1827 | */ |
1763 | int err; | ||
1764 | |||
1765 | c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); | 1828 | c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); |
1766 | c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); | 1829 | c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); |
1767 | c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum); | 1830 | c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum); |
@@ -1774,6 +1837,10 @@ static void ubifs_put_super(struct super_block *sb) | |||
1774 | */ | 1837 | */ |
1775 | ubifs_err("failed to write master node, " | 1838 | ubifs_err("failed to write master node, " |
1776 | "error %d", err); | 1839 | "error %d", err); |
1840 | } else { | ||
1841 | for (i = 0; i < c->jhead_cnt; i++) | ||
1842 | /* Make sure write-buffer timers are canceled */ | ||
1843 | hrtimer_cancel(&c->jheads[i].wbuf.timer); | ||
1777 | } | 1844 | } |
1778 | } | 1845 | } |
1779 | 1846 | ||
@@ -1781,7 +1848,6 @@ static void ubifs_put_super(struct super_block *sb) | |||
1781 | bdi_destroy(&c->bdi); | 1848 | bdi_destroy(&c->bdi); |
1782 | ubi_close_volume(c->ubi); | 1849 | ubi_close_volume(c->ubi); |
1783 | mutex_unlock(&c->umount_mutex); | 1850 | mutex_unlock(&c->umount_mutex); |
1784 | kfree(c); | ||
1785 | } | 1851 | } |
1786 | 1852 | ||
1787 | static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data) | 1853 | static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data) |
@@ -1797,17 +1863,21 @@ static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data) | |||
1797 | return err; | 1863 | return err; |
1798 | } | 1864 | } |
1799 | 1865 | ||
1800 | if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { | 1866 | if (c->ro_mount && !(*flags & MS_RDONLY)) { |
1867 | if (c->ro_error) { | ||
1868 | ubifs_msg("cannot re-mount R/W due to prior errors"); | ||
1869 | return -EROFS; | ||
1870 | } | ||
1801 | if (c->ro_media) { | 1871 | if (c->ro_media) { |
1802 | ubifs_msg("cannot re-mount due to prior errors"); | 1872 | ubifs_msg("cannot re-mount R/W - UBI volume is R/O"); |
1803 | return -EROFS; | 1873 | return -EROFS; |
1804 | } | 1874 | } |
1805 | err = ubifs_remount_rw(c); | 1875 | err = ubifs_remount_rw(c); |
1806 | if (err) | 1876 | if (err) |
1807 | return err; | 1877 | return err; |
1808 | } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) { | 1878 | } else if (!c->ro_mount && (*flags & MS_RDONLY)) { |
1809 | if (c->ro_media) { | 1879 | if (c->ro_error) { |
1810 | ubifs_msg("cannot re-mount due to prior errors"); | 1880 | ubifs_msg("cannot re-mount R/O due to prior errors"); |
1811 | return -EROFS; | 1881 | return -EROFS; |
1812 | } | 1882 | } |
1813 | ubifs_remount_ro(c); | 1883 | ubifs_remount_ro(c); |
@@ -1900,59 +1970,65 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode) | |||
1900 | return ERR_PTR(-EINVAL); | 1970 | return ERR_PTR(-EINVAL); |
1901 | } | 1971 | } |
1902 | 1972 | ||
1903 | static int ubifs_fill_super(struct super_block *sb, void *data, int silent) | 1973 | static struct ubifs_info *alloc_ubifs_info(struct ubi_volume_desc *ubi) |
1904 | { | 1974 | { |
1905 | struct ubi_volume_desc *ubi = sb->s_fs_info; | ||
1906 | struct ubifs_info *c; | 1975 | struct ubifs_info *c; |
1907 | struct inode *root; | ||
1908 | int err; | ||
1909 | 1976 | ||
1910 | c = kzalloc(sizeof(struct ubifs_info), GFP_KERNEL); | 1977 | c = kzalloc(sizeof(struct ubifs_info), GFP_KERNEL); |
1911 | if (!c) | 1978 | if (c) { |
1912 | return -ENOMEM; | 1979 | spin_lock_init(&c->cnt_lock); |
1980 | spin_lock_init(&c->cs_lock); | ||
1981 | spin_lock_init(&c->buds_lock); | ||
1982 | spin_lock_init(&c->space_lock); | ||
1983 | spin_lock_init(&c->orphan_lock); | ||
1984 | init_rwsem(&c->commit_sem); | ||
1985 | mutex_init(&c->lp_mutex); | ||
1986 | mutex_init(&c->tnc_mutex); | ||
1987 | mutex_init(&c->log_mutex); | ||
1988 | mutex_init(&c->mst_mutex); | ||
1989 | mutex_init(&c->umount_mutex); | ||
1990 | mutex_init(&c->bu_mutex); | ||
1991 | mutex_init(&c->write_reserve_mutex); | ||
1992 | init_waitqueue_head(&c->cmt_wq); | ||
1993 | c->buds = RB_ROOT; | ||
1994 | c->old_idx = RB_ROOT; | ||
1995 | c->size_tree = RB_ROOT; | ||
1996 | c->orph_tree = RB_ROOT; | ||
1997 | INIT_LIST_HEAD(&c->infos_list); | ||
1998 | INIT_LIST_HEAD(&c->idx_gc); | ||
1999 | INIT_LIST_HEAD(&c->replay_list); | ||
2000 | INIT_LIST_HEAD(&c->replay_buds); | ||
2001 | INIT_LIST_HEAD(&c->uncat_list); | ||
2002 | INIT_LIST_HEAD(&c->empty_list); | ||
2003 | INIT_LIST_HEAD(&c->freeable_list); | ||
2004 | INIT_LIST_HEAD(&c->frdi_idx_list); | ||
2005 | INIT_LIST_HEAD(&c->unclean_leb_list); | ||
2006 | INIT_LIST_HEAD(&c->old_buds); | ||
2007 | INIT_LIST_HEAD(&c->orph_list); | ||
2008 | INIT_LIST_HEAD(&c->orph_new); | ||
2009 | c->no_chk_data_crc = 1; | ||
2010 | |||
2011 | c->highest_inum = UBIFS_FIRST_INO; | ||
2012 | c->lhead_lnum = c->ltail_lnum = UBIFS_LOG_LNUM; | ||
2013 | |||
2014 | ubi_get_volume_info(ubi, &c->vi); | ||
2015 | ubi_get_device_info(c->vi.ubi_num, &c->di); | ||
2016 | } | ||
2017 | return c; | ||
2018 | } | ||
1913 | 2019 | ||
1914 | spin_lock_init(&c->cnt_lock); | 2020 | static int ubifs_fill_super(struct super_block *sb, void *data, int silent) |
1915 | spin_lock_init(&c->cs_lock); | 2021 | { |
1916 | spin_lock_init(&c->buds_lock); | 2022 | struct ubifs_info *c = sb->s_fs_info; |
1917 | spin_lock_init(&c->space_lock); | 2023 | struct inode *root; |
1918 | spin_lock_init(&c->orphan_lock); | 2024 | int err; |
1919 | init_rwsem(&c->commit_sem); | ||
1920 | mutex_init(&c->lp_mutex); | ||
1921 | mutex_init(&c->tnc_mutex); | ||
1922 | mutex_init(&c->log_mutex); | ||
1923 | mutex_init(&c->mst_mutex); | ||
1924 | mutex_init(&c->umount_mutex); | ||
1925 | mutex_init(&c->bu_mutex); | ||
1926 | init_waitqueue_head(&c->cmt_wq); | ||
1927 | c->buds = RB_ROOT; | ||
1928 | c->old_idx = RB_ROOT; | ||
1929 | c->size_tree = RB_ROOT; | ||
1930 | c->orph_tree = RB_ROOT; | ||
1931 | INIT_LIST_HEAD(&c->infos_list); | ||
1932 | INIT_LIST_HEAD(&c->idx_gc); | ||
1933 | INIT_LIST_HEAD(&c->replay_list); | ||
1934 | INIT_LIST_HEAD(&c->replay_buds); | ||
1935 | INIT_LIST_HEAD(&c->uncat_list); | ||
1936 | INIT_LIST_HEAD(&c->empty_list); | ||
1937 | INIT_LIST_HEAD(&c->freeable_list); | ||
1938 | INIT_LIST_HEAD(&c->frdi_idx_list); | ||
1939 | INIT_LIST_HEAD(&c->unclean_leb_list); | ||
1940 | INIT_LIST_HEAD(&c->old_buds); | ||
1941 | INIT_LIST_HEAD(&c->orph_list); | ||
1942 | INIT_LIST_HEAD(&c->orph_new); | ||
1943 | 2025 | ||
1944 | c->vfs_sb = sb; | 2026 | c->vfs_sb = sb; |
1945 | c->highest_inum = UBIFS_FIRST_INO; | ||
1946 | c->lhead_lnum = c->ltail_lnum = UBIFS_LOG_LNUM; | ||
1947 | |||
1948 | ubi_get_volume_info(ubi, &c->vi); | ||
1949 | ubi_get_device_info(c->vi.ubi_num, &c->di); | ||
1950 | |||
1951 | /* Re-open the UBI device in read-write mode */ | 2027 | /* Re-open the UBI device in read-write mode */ |
1952 | c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READWRITE); | 2028 | c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READWRITE); |
1953 | if (IS_ERR(c->ubi)) { | 2029 | if (IS_ERR(c->ubi)) { |
1954 | err = PTR_ERR(c->ubi); | 2030 | err = PTR_ERR(c->ubi); |
1955 | goto out_free; | 2031 | goto out; |
1956 | } | 2032 | } |
1957 | 2033 | ||
1958 | /* | 2034 | /* |
@@ -1965,7 +2041,6 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent) | |||
1965 | */ | 2041 | */ |
1966 | c->bdi.name = "ubifs", | 2042 | c->bdi.name = "ubifs", |
1967 | c->bdi.capabilities = BDI_CAP_MAP_COPY; | 2043 | c->bdi.capabilities = BDI_CAP_MAP_COPY; |
1968 | c->bdi.unplug_io_fn = default_unplug_io_fn; | ||
1969 | err = bdi_init(&c->bdi); | 2044 | err = bdi_init(&c->bdi); |
1970 | if (err) | 2045 | if (err) |
1971 | goto out_close; | 2046 | goto out_close; |
@@ -2019,24 +2094,29 @@ out_bdi: | |||
2019 | bdi_destroy(&c->bdi); | 2094 | bdi_destroy(&c->bdi); |
2020 | out_close: | 2095 | out_close: |
2021 | ubi_close_volume(c->ubi); | 2096 | ubi_close_volume(c->ubi); |
2022 | out_free: | 2097 | out: |
2023 | kfree(c); | ||
2024 | return err; | 2098 | return err; |
2025 | } | 2099 | } |
2026 | 2100 | ||
2027 | static int sb_test(struct super_block *sb, void *data) | 2101 | static int sb_test(struct super_block *sb, void *data) |
2028 | { | 2102 | { |
2029 | dev_t *dev = data; | 2103 | struct ubifs_info *c1 = data; |
2030 | struct ubifs_info *c = sb->s_fs_info; | 2104 | struct ubifs_info *c = sb->s_fs_info; |
2031 | 2105 | ||
2032 | return c->vi.cdev == *dev; | 2106 | return c->vi.cdev == c1->vi.cdev; |
2107 | } | ||
2108 | |||
2109 | static int sb_set(struct super_block *sb, void *data) | ||
2110 | { | ||
2111 | sb->s_fs_info = data; | ||
2112 | return set_anon_super(sb, NULL); | ||
2033 | } | 2113 | } |
2034 | 2114 | ||
2035 | static int ubifs_get_sb(struct file_system_type *fs_type, int flags, | 2115 | static struct dentry *ubifs_mount(struct file_system_type *fs_type, int flags, |
2036 | const char *name, void *data, struct vfsmount *mnt) | 2116 | const char *name, void *data) |
2037 | { | 2117 | { |
2038 | struct ubi_volume_desc *ubi; | 2118 | struct ubi_volume_desc *ubi; |
2039 | struct ubi_volume_info vi; | 2119 | struct ubifs_info *c; |
2040 | struct super_block *sb; | 2120 | struct super_block *sb; |
2041 | int err; | 2121 | int err; |
2042 | 2122 | ||
@@ -2049,34 +2129,37 @@ static int ubifs_get_sb(struct file_system_type *fs_type, int flags, | |||
2049 | */ | 2129 | */ |
2050 | ubi = open_ubi(name, UBI_READONLY); | 2130 | ubi = open_ubi(name, UBI_READONLY); |
2051 | if (IS_ERR(ubi)) { | 2131 | if (IS_ERR(ubi)) { |
2052 | ubifs_err("cannot open \"%s\", error %d", | 2132 | dbg_err("cannot open \"%s\", error %d", |
2053 | name, (int)PTR_ERR(ubi)); | 2133 | name, (int)PTR_ERR(ubi)); |
2054 | return PTR_ERR(ubi); | 2134 | return ERR_CAST(ubi); |
2055 | } | 2135 | } |
2056 | ubi_get_volume_info(ubi, &vi); | ||
2057 | 2136 | ||
2058 | dbg_gen("opened ubi%d_%d", vi.ubi_num, vi.vol_id); | 2137 | c = alloc_ubifs_info(ubi); |
2138 | if (!c) { | ||
2139 | err = -ENOMEM; | ||
2140 | goto out_close; | ||
2141 | } | ||
2059 | 2142 | ||
2060 | sb = sget(fs_type, &sb_test, &set_anon_super, &vi.cdev); | 2143 | dbg_gen("opened ubi%d_%d", c->vi.ubi_num, c->vi.vol_id); |
2144 | |||
2145 | sb = sget(fs_type, sb_test, sb_set, c); | ||
2061 | if (IS_ERR(sb)) { | 2146 | if (IS_ERR(sb)) { |
2062 | err = PTR_ERR(sb); | 2147 | err = PTR_ERR(sb); |
2148 | kfree(c); | ||
2063 | goto out_close; | 2149 | goto out_close; |
2064 | } | 2150 | } |
2065 | 2151 | ||
2066 | if (sb->s_root) { | 2152 | if (sb->s_root) { |
2153 | struct ubifs_info *c1 = sb->s_fs_info; | ||
2154 | kfree(c); | ||
2067 | /* A new mount point for already mounted UBIFS */ | 2155 | /* A new mount point for already mounted UBIFS */ |
2068 | dbg_gen("this ubi volume is already mounted"); | 2156 | dbg_gen("this ubi volume is already mounted"); |
2069 | if ((flags ^ sb->s_flags) & MS_RDONLY) { | 2157 | if (!!(flags & MS_RDONLY) != c1->ro_mount) { |
2070 | err = -EBUSY; | 2158 | err = -EBUSY; |
2071 | goto out_deact; | 2159 | goto out_deact; |
2072 | } | 2160 | } |
2073 | } else { | 2161 | } else { |
2074 | sb->s_flags = flags; | 2162 | sb->s_flags = flags; |
2075 | /* | ||
2076 | * Pass 'ubi' to 'fill_super()' in sb->s_fs_info where it is | ||
2077 | * replaced by 'c'. | ||
2078 | */ | ||
2079 | sb->s_fs_info = ubi; | ||
2080 | err = ubifs_fill_super(sb, data, flags & MS_SILENT ? 1 : 0); | 2163 | err = ubifs_fill_super(sb, data, flags & MS_SILENT ? 1 : 0); |
2081 | if (err) | 2164 | if (err) |
2082 | goto out_deact; | 2165 | goto out_deact; |
@@ -2087,21 +2170,27 @@ static int ubifs_get_sb(struct file_system_type *fs_type, int flags, | |||
2087 | /* 'fill_super()' opens ubi again so we must close it here */ | 2170 | /* 'fill_super()' opens ubi again so we must close it here */ |
2088 | ubi_close_volume(ubi); | 2171 | ubi_close_volume(ubi); |
2089 | 2172 | ||
2090 | simple_set_mnt(mnt, sb); | 2173 | return dget(sb->s_root); |
2091 | return 0; | ||
2092 | 2174 | ||
2093 | out_deact: | 2175 | out_deact: |
2094 | deactivate_locked_super(sb); | 2176 | deactivate_locked_super(sb); |
2095 | out_close: | 2177 | out_close: |
2096 | ubi_close_volume(ubi); | 2178 | ubi_close_volume(ubi); |
2097 | return err; | 2179 | return ERR_PTR(err); |
2180 | } | ||
2181 | |||
2182 | static void kill_ubifs_super(struct super_block *s) | ||
2183 | { | ||
2184 | struct ubifs_info *c = s->s_fs_info; | ||
2185 | kill_anon_super(s); | ||
2186 | kfree(c); | ||
2098 | } | 2187 | } |
2099 | 2188 | ||
2100 | static struct file_system_type ubifs_fs_type = { | 2189 | static struct file_system_type ubifs_fs_type = { |
2101 | .name = "ubifs", | 2190 | .name = "ubifs", |
2102 | .owner = THIS_MODULE, | 2191 | .owner = THIS_MODULE, |
2103 | .get_sb = ubifs_get_sb, | 2192 | .mount = ubifs_mount, |
2104 | .kill_sb = kill_anon_super, | 2193 | .kill_sb = kill_ubifs_super, |
2105 | }; | 2194 | }; |
2106 | 2195 | ||
2107 | /* | 2196 | /* |