25 #include <linux/slab.h>
28 #include <linux/random.h>
49 if (!nilfs_sb_dirty(nilfs)) {
53 set_nilfs_sb_dirty(nilfs);
99 if (nilfs_init(nilfs)) {
106 static int nilfs_load_super_root(
struct the_nilfs *nilfs,
109 struct buffer_head *bh_sr;
113 unsigned dat_entry_size, segment_usage_size, checkpoint_size;
122 dat_entry_size =
le16_to_cpu(sbp[0]->s_dat_entry_size);
123 checkpoint_size =
le16_to_cpu(sbp[0]->s_checkpoint_size);
124 segment_usage_size =
le16_to_cpu(sbp[0]->s_segment_usage_size);
162 memset(ri, 0,
sizeof(*ri));
181 static int nilfs_store_log_cursor(
struct the_nilfs *nilfs,
216 int valid_fs = nilfs_valid_fs(nilfs);
223 "required for readonly filesystem.\n");
225 "be enabled during recovery.\n");
229 nilfs_init_recovery_info(&ri);
239 if (!nilfs_valid_sb(sbp[1])) {
241 "NILFS warning: unable to fall back to spare"
246 "NILFS: try rollback from an earlier position\n");
260 "NILFS warning: blocksize differs between "
261 "two super blocks (%d != %d)\n",
266 err = nilfs_store_log_cursor(nilfs, sbp[0]);
293 "skipping roll-forward recovery\n");
300 "recovery because of unsupported optional "
302 (
unsigned long long)features);
306 if (really_read_only) {
308 "unavailable, cannot proceed.\n");
315 "option was specified for a read/write mount\n");
331 "recovery unfinished.\n");
337 nilfs_clear_recovery_info(&ri);
351 nilfs_clear_recovery_info(&ri);
356 static unsigned long long nilfs_max_size(
unsigned int blkbits)
359 unsigned long long res = MAX_LFS_FILESIZE;
363 res =
min_t(
unsigned long long, res, (1ULL << max_bits) - 1);
385 static int nilfs_store_disk_layout(
struct the_nilfs *nilfs,
390 "(superblock rev.=%d.%d, current rev.=%d.%d). "
391 "Please check the version of mkfs.nilfs.\n",
415 printk(
KERN_ERR "NILFS: invalid reserved segments percentage.\n");
426 static unsigned char sum[4];
439 crc =
crc32_le(crc, (
unsigned char *)sbp + sumoff + 4,
451 static void nilfs_release_super_block(
struct the_nilfs *nilfs)
455 for (i = 0; i < 2; i++) {
475 struct buffer_head *tsbh = nilfs->
ns_sbh[0];
484 static int nilfs_load_super_block(
struct the_nilfs *nilfs,
489 struct buffer_head **sbh = nilfs->
ns_sbh;
491 int valid[2], swp = 0;
503 "NILFS warning: unable to read primary superblock "
504 "(blocksize = %d)\n", blocksize);
505 }
else if (!sbp[1]) {
507 "NILFS warning: unable to read secondary superblock "
508 "(blocksize = %d)\n", blocksize);
515 valid[0] = nilfs_valid_sb(sbp[0]);
516 valid[1] = nilfs_valid_sb(sbp[1]);
517 swp = valid[1] && (!valid[0] ||
521 if (valid[swp] && nilfs_sb2_bad_offset(sbp[swp], sb2off)) {
529 nilfs_release_super_block(nilfs);
537 "using spare superblock (blocksize = %d).\n", blocksize);
575 err = nilfs_load_super_block(nilfs, sb, blocksize, &sbp);
591 "filesystem blocksize %d\n", blocksize);
596 int hw_blocksize = bdev_logical_block_size(sb->
s_bdev);
598 if (blocksize < hw_blocksize) {
600 "NILFS: blocksize %d too small for device "
601 "(sector-size = %d).\n",
602 blocksize, hw_blocksize);
606 nilfs_release_super_block(nilfs);
609 err = nilfs_load_super_block(nilfs, sb, blocksize, &sbp);
621 err = nilfs_store_disk_layout(nilfs, sbp);
629 err = nilfs_store_log_cursor(nilfs, sbp);
633 set_nilfs_init(nilfs);
640 nilfs_release_super_block(nilfs);
649 unsigned int sects_per_block;
654 bdev_logical_block_size(nilfs->
ns_bdev);
655 for (sn = segnump; sn < segnump + nsegs; sn++) {
656 nilfs_get_segment_range(nilfs, *sn, &seg_start, &seg_end);
660 nblocks = seg_end - seg_start + 1;
661 }
else if (start + nblocks == seg_start) {
662 nblocks += seg_end - seg_start + 1;
665 start * sects_per_block,
666 nblocks * sects_per_block,
675 start * sects_per_block,
676 nblocks * sects_per_block,
683 unsigned long ncleansegs;
694 unsigned long ncleansegs, nincsegs;
700 return ncleansegs <= nilfs->
ns_nrsvsegs + nincsegs;
713 if (cno < root->cno) {
715 }
else if (cno > root->
cno) {
751 if (cno < root->cno) {
753 }
else if (cno > root->
cno) {
770 rb_link_node(&new->rb_node, parent, p);