Lines Matching +full:super +full:- +full:set
1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
14 #include <linux/backing-dev.h>
31 spin_lock(&nilfs->ns_last_segment_lock); in nilfs_set_last_segment()
32 nilfs->ns_last_pseg = start_blocknr; in nilfs_set_last_segment()
33 nilfs->ns_last_seq = seq; in nilfs_set_last_segment()
34 nilfs->ns_last_cno = cno; in nilfs_set_last_segment()
37 if (nilfs->ns_prev_seq == nilfs->ns_last_seq) in nilfs_set_last_segment()
42 nilfs->ns_prev_seq = nilfs->ns_last_seq; in nilfs_set_last_segment()
45 spin_unlock(&nilfs->ns_last_segment_lock); in nilfs_set_last_segment()
49 * alloc_nilfs - allocate a nilfs object
50 * @sb: super block instance
63 nilfs->ns_sb = sb; in alloc_nilfs()
64 nilfs->ns_bdev = sb->s_bdev; in alloc_nilfs()
65 atomic_set(&nilfs->ns_ndirtyblks, 0); in alloc_nilfs()
66 init_rwsem(&nilfs->ns_sem); in alloc_nilfs()
67 mutex_init(&nilfs->ns_snapshot_mount_mutex); in alloc_nilfs()
68 INIT_LIST_HEAD(&nilfs->ns_dirty_files); in alloc_nilfs()
69 INIT_LIST_HEAD(&nilfs->ns_gc_inodes); in alloc_nilfs()
70 spin_lock_init(&nilfs->ns_inode_lock); in alloc_nilfs()
71 spin_lock_init(&nilfs->ns_last_segment_lock); in alloc_nilfs()
72 nilfs->ns_cptree = RB_ROOT; in alloc_nilfs()
73 spin_lock_init(&nilfs->ns_cptree_lock); in alloc_nilfs()
74 init_rwsem(&nilfs->ns_segctor_sem); in alloc_nilfs()
75 nilfs->ns_sb_update_freq = NILFS_SB_FREQ; in alloc_nilfs()
81 * destroy_nilfs - destroy nilfs object
88 brelse(nilfs->ns_sbh[0]); in destroy_nilfs()
89 brelse(nilfs->ns_sbh[1]); in destroy_nilfs()
99 struct nilfs_super_block **sbp = nilfs->ns_sbp; in nilfs_load_super_root()
109 down_read(&nilfs->ns_sem); in nilfs_load_super_root()
110 dat_entry_size = le16_to_cpu(sbp[0]->s_dat_entry_size); in nilfs_load_super_root()
111 checkpoint_size = le16_to_cpu(sbp[0]->s_checkpoint_size); in nilfs_load_super_root()
112 segment_usage_size = le16_to_cpu(sbp[0]->s_segment_usage_size); in nilfs_load_super_root()
113 up_read(&nilfs->ns_sem); in nilfs_load_super_root()
115 inode_size = nilfs->ns_inode_size; in nilfs_load_super_root()
117 rawi = (void *)bh_sr->b_data + NILFS_SR_DAT_OFFSET(inode_size); in nilfs_load_super_root()
118 err = nilfs_dat_read(sb, dat_entry_size, rawi, &nilfs->ns_dat); in nilfs_load_super_root()
122 rawi = (void *)bh_sr->b_data + NILFS_SR_CPFILE_OFFSET(inode_size); in nilfs_load_super_root()
123 err = nilfs_cpfile_read(sb, checkpoint_size, rawi, &nilfs->ns_cpfile); in nilfs_load_super_root()
127 rawi = (void *)bh_sr->b_data + NILFS_SR_SUFILE_OFFSET(inode_size); in nilfs_load_super_root()
129 &nilfs->ns_sufile); in nilfs_load_super_root()
133 raw_sr = (struct nilfs_super_root *)bh_sr->b_data; in nilfs_load_super_root()
134 nilfs->ns_nongc_ctime = le64_to_cpu(raw_sr->sr_nongc_ctime); in nilfs_load_super_root()
141 iput(nilfs->ns_cpfile); in nilfs_load_super_root()
144 iput(nilfs->ns_dat); in nilfs_load_super_root()
151 INIT_LIST_HEAD(&ri->ri_used_segments); in nilfs_init_recovery_info()
156 nilfs_dispose_segment_list(&ri->ri_used_segments); in nilfs_clear_recovery_info()
160 * nilfs_store_log_cursor - load log cursor from a super block
162 * @sbp: buffer storing super block to be read
165 * containing a super root from a given super block, and initializes
174 nilfs->ns_last_pseg = le64_to_cpu(sbp->s_last_pseg); in nilfs_store_log_cursor()
175 nilfs->ns_last_cno = le64_to_cpu(sbp->s_last_cno); in nilfs_store_log_cursor()
176 nilfs->ns_last_seq = le64_to_cpu(sbp->s_last_seq); in nilfs_store_log_cursor()
178 nilfs->ns_prev_seq = nilfs->ns_last_seq; in nilfs_store_log_cursor()
179 nilfs->ns_seg_seq = nilfs->ns_last_seq; in nilfs_store_log_cursor()
180 nilfs->ns_segnum = in nilfs_store_log_cursor()
181 nilfs_get_segnum_of_block(nilfs, nilfs->ns_last_pseg); in nilfs_store_log_cursor()
182 nilfs->ns_cno = nilfs->ns_last_cno + 1; in nilfs_store_log_cursor()
183 if (nilfs->ns_segnum >= nilfs->ns_nsegments) { in nilfs_store_log_cursor()
184 nilfs_err(nilfs->ns_sb, in nilfs_store_log_cursor()
186 (unsigned long long)nilfs->ns_segnum, in nilfs_store_log_cursor()
187 nilfs->ns_nsegments); in nilfs_store_log_cursor()
188 ret = -EINVAL; in nilfs_store_log_cursor()
194 * nilfs_get_blocksize - get block size from raw superblock data
195 * @sb: super block instance
204 * large, -EINVAL is returned.
209 unsigned int shift_bits = le32_to_cpu(sbp->s_log_block_size); in nilfs_get_blocksize()
212 ilog2(NILFS_MAX_BLOCK_SIZE) - BLOCK_SIZE_BITS)) { in nilfs_get_blocksize()
215 return -EINVAL; in nilfs_get_blocksize()
222 * load_nilfs - load and recover the nilfs
224 * @sb: super block instance used to recover past segment
226 * load_nilfs() searches and load the latest super root,
233 unsigned int s_flags = sb->s_flags; in load_nilfs()
234 int really_read_only = bdev_read_only(nilfs->ns_bdev); in load_nilfs()
252 struct nilfs_super_block **sbp = nilfs->ns_sbp; in load_nilfs()
255 if (err != -EINVAL) in load_nilfs()
260 "unable to fall back to spare super block"); in load_nilfs()
266 * restore super block with its spare and reconfigure in load_nilfs()
269 memcpy(sbp[0], sbp[1], nilfs->ns_sbsize); in load_nilfs()
270 nilfs->ns_crc_seed = le32_to_cpu(sbp[0]->s_crc_seed); in load_nilfs()
271 nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime); in load_nilfs()
273 /* verify consistency between two super blocks */ in load_nilfs()
278 if (blocksize != nilfs->ns_blocksize) { in load_nilfs()
280 "blocksize differs between two super blocks (%d != %d)", in load_nilfs()
281 blocksize, nilfs->ns_blocksize); in load_nilfs()
282 err = -EINVAL; in load_nilfs()
290 /* drop clean flag to allow roll-forward and recovery */ in load_nilfs()
291 nilfs->ns_mount_state &= ~NILFS_VALID_FS; in load_nilfs()
301 nilfs_err(sb, "error %d while loading super root", err); in load_nilfs()
317 "norecovery option specified, skipping roll-forward recovery"); in load_nilfs()
320 features = le64_to_cpu(nilfs->ns_sbp[0]->s_feature_compat_ro) & in load_nilfs()
326 err = -EROFS; in load_nilfs()
332 err = -EROFS; in load_nilfs()
335 sb->s_flags &= ~SB_RDONLY; in load_nilfs()
339 err = -EINVAL; in load_nilfs()
347 down_write(&nilfs->ns_sem); in load_nilfs()
348 nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */ in load_nilfs()
350 up_write(&nilfs->ns_sem); in load_nilfs()
354 "error %d updating super block. recovery unfinished.", in load_nilfs()
362 sb->s_flags = s_flags; in load_nilfs()
366 nilfs_err(sb, "error %d while searching super root", err); in load_nilfs()
373 iput(nilfs->ns_cpfile); in load_nilfs()
374 iput(nilfs->ns_sufile); in load_nilfs()
375 iput(nilfs->ns_dat); in load_nilfs()
379 sb->s_flags = s_flags; in load_nilfs()
390 res = min_t(unsigned long long, res, (1ULL << max_bits) - 1); in nilfs_max_size()
395 * nilfs_nrsvsegs - calculate the number of reserved segments
402 DIV_ROUND_UP(nsegs * nilfs->ns_r_segments_percentage, in nilfs_nrsvsegs()
407 * nilfs_max_segment_count - calculate the maximum number of segments
414 max_count = div64_ul(max_count, nilfs->ns_blocks_per_segment); in nilfs_max_segment_count()
420 nilfs->ns_nsegments = nsegs; in nilfs_set_nsegments()
421 nilfs->ns_nrsvsegs = nilfs_nrsvsegs(nilfs, nsegs); in nilfs_set_nsegments()
429 if (le32_to_cpu(sbp->s_rev_level) < NILFS_MIN_SUPP_REV) { in nilfs_store_disk_layout()
430 nilfs_err(nilfs->ns_sb, in nilfs_store_disk_layout()
432 le32_to_cpu(sbp->s_rev_level), in nilfs_store_disk_layout()
433 le16_to_cpu(sbp->s_minor_rev_level), in nilfs_store_disk_layout()
435 return -EINVAL; in nilfs_store_disk_layout()
437 nilfs->ns_sbsize = le16_to_cpu(sbp->s_bytes); in nilfs_store_disk_layout()
438 if (nilfs->ns_sbsize > BLOCK_SIZE) in nilfs_store_disk_layout()
439 return -EINVAL; in nilfs_store_disk_layout()
441 nilfs->ns_inode_size = le16_to_cpu(sbp->s_inode_size); in nilfs_store_disk_layout()
442 if (nilfs->ns_inode_size > nilfs->ns_blocksize) { in nilfs_store_disk_layout()
443 nilfs_err(nilfs->ns_sb, "too large inode size: %d bytes", in nilfs_store_disk_layout()
444 nilfs->ns_inode_size); in nilfs_store_disk_layout()
445 return -EINVAL; in nilfs_store_disk_layout()
446 } else if (nilfs->ns_inode_size < NILFS_MIN_INODE_SIZE) { in nilfs_store_disk_layout()
447 nilfs_err(nilfs->ns_sb, "too small inode size: %d bytes", in nilfs_store_disk_layout()
448 nilfs->ns_inode_size); in nilfs_store_disk_layout()
449 return -EINVAL; in nilfs_store_disk_layout()
452 nilfs->ns_first_ino = le32_to_cpu(sbp->s_first_ino); in nilfs_store_disk_layout()
453 if (nilfs->ns_first_ino < NILFS_USER_INO) { in nilfs_store_disk_layout()
454 nilfs_err(nilfs->ns_sb, in nilfs_store_disk_layout()
455 "too small lower limit for non-reserved inode numbers: %u", in nilfs_store_disk_layout()
456 nilfs->ns_first_ino); in nilfs_store_disk_layout()
457 return -EINVAL; in nilfs_store_disk_layout()
460 nilfs->ns_blocks_per_segment = le32_to_cpu(sbp->s_blocks_per_segment); in nilfs_store_disk_layout()
461 if (nilfs->ns_blocks_per_segment < NILFS_SEG_MIN_BLOCKS) { in nilfs_store_disk_layout()
462 nilfs_err(nilfs->ns_sb, "too short segment: %lu blocks", in nilfs_store_disk_layout()
463 nilfs->ns_blocks_per_segment); in nilfs_store_disk_layout()
464 return -EINVAL; in nilfs_store_disk_layout()
467 nilfs->ns_first_data_block = le64_to_cpu(sbp->s_first_data_block); in nilfs_store_disk_layout()
468 nilfs->ns_r_segments_percentage = in nilfs_store_disk_layout()
469 le32_to_cpu(sbp->s_r_segments_percentage); in nilfs_store_disk_layout()
470 if (nilfs->ns_r_segments_percentage < 1 || in nilfs_store_disk_layout()
471 nilfs->ns_r_segments_percentage > 99) { in nilfs_store_disk_layout()
472 nilfs_err(nilfs->ns_sb, in nilfs_store_disk_layout()
474 nilfs->ns_r_segments_percentage); in nilfs_store_disk_layout()
475 return -EINVAL; in nilfs_store_disk_layout()
478 nsegments = le64_to_cpu(sbp->s_nsegments); in nilfs_store_disk_layout()
480 nilfs_err(nilfs->ns_sb, in nilfs_store_disk_layout()
484 return -EINVAL; in nilfs_store_disk_layout()
487 nblocks = sb_bdev_nr_blocks(nilfs->ns_sb); in nilfs_store_disk_layout()
489 u64 min_block_count = nsegments * nilfs->ns_blocks_per_segment; in nilfs_store_disk_layout()
497 nilfs_err(nilfs->ns_sb, in nilfs_store_disk_layout()
501 return -EINVAL; in nilfs_store_disk_layout()
506 nilfs->ns_crc_seed = le32_to_cpu(sbp->s_crc_seed); in nilfs_store_disk_layout()
517 if (!sbp || le16_to_cpu(sbp->s_magic) != NILFS_SUPER_MAGIC) in nilfs_valid_sb()
519 bytes = le16_to_cpu(sbp->s_bytes); in nilfs_valid_sb()
522 crc = crc32_le(le32_to_cpu(sbp->s_crc_seed), (unsigned char *)sbp, in nilfs_valid_sb()
526 bytes - sumoff - 4); in nilfs_valid_sb()
527 return crc == le32_to_cpu(sbp->s_sum); in nilfs_valid_sb()
531 * nilfs_sb2_bad_offset - check the location of the second superblock
545 unsigned int shift_bits = le32_to_cpu(sbp->s_log_block_size); in nilfs_sb2_bad_offset()
546 u32 blocks_per_segment = le32_to_cpu(sbp->s_blocks_per_segment); in nilfs_sb2_bad_offset()
547 u64 nsegments = le64_to_cpu(sbp->s_nsegments); in nilfs_sb2_bad_offset()
551 shift_bits > ilog2(NILFS_MAX_BLOCK_SIZE) - BLOCK_SIZE_BITS) in nilfs_sb2_bad_offset()
564 if (nilfs->ns_sbp[i]) { in nilfs_release_super_block()
565 brelse(nilfs->ns_sbh[i]); in nilfs_release_super_block()
566 nilfs->ns_sbh[i] = NULL; in nilfs_release_super_block()
567 nilfs->ns_sbp[i] = NULL; in nilfs_release_super_block()
574 brelse(nilfs->ns_sbh[0]); in nilfs_fall_back_super_block()
575 nilfs->ns_sbh[0] = nilfs->ns_sbh[1]; in nilfs_fall_back_super_block()
576 nilfs->ns_sbp[0] = nilfs->ns_sbp[1]; in nilfs_fall_back_super_block()
577 nilfs->ns_sbh[1] = NULL; in nilfs_fall_back_super_block()
578 nilfs->ns_sbp[1] = NULL; in nilfs_fall_back_super_block()
583 struct buffer_head *tsbh = nilfs->ns_sbh[0]; in nilfs_swap_super_block()
584 struct nilfs_super_block *tsbp = nilfs->ns_sbp[0]; in nilfs_swap_super_block()
586 nilfs->ns_sbh[0] = nilfs->ns_sbh[1]; in nilfs_swap_super_block()
587 nilfs->ns_sbp[0] = nilfs->ns_sbp[1]; in nilfs_swap_super_block()
588 nilfs->ns_sbh[1] = tsbh; in nilfs_swap_super_block()
589 nilfs->ns_sbp[1] = tsbp; in nilfs_swap_super_block()
596 struct nilfs_super_block **sbp = nilfs->ns_sbp; in nilfs_load_super_block()
597 struct buffer_head **sbh = nilfs->ns_sbh; in nilfs_load_super_block()
598 u64 sb2off, devsize = bdev_nr_bytes(nilfs->ns_bdev); in nilfs_load_super_block()
603 return -EINVAL; in nilfs_load_super_block()
614 return -EIO; in nilfs_load_super_block()
626 * Compare two super blocks and set 1 in swp if the secondary in nilfs_load_super_block()
627 * super block is valid and newer. Otherwise, set 0 in swp. in nilfs_load_super_block()
632 le64_to_cpu(sbp[1]->s_last_cno) > in nilfs_load_super_block()
633 le64_to_cpu(sbp[0]->s_last_cno)); in nilfs_load_super_block()
645 return -EINVAL; in nilfs_load_super_block()
657 * If one has been dropped, set index 0 pointing to the remaining one, in nilfs_load_super_block()
658 * otherwise set index 1 pointing to the old one (including if both in nilfs_load_super_block()
661 * Divided case valid[0] valid[1] swp -> older in nilfs_load_super_block()
662 * ------------------------------------------------------------- in nilfs_load_super_block()
671 nilfs->ns_sbwcount = 0; in nilfs_load_super_block()
672 nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime); in nilfs_load_super_block()
673 nilfs->ns_prot_seq = le64_to_cpu(sbp[older]->s_last_seq); in nilfs_load_super_block()
679 * init_nilfs - initialize a NILFS instance.
681 * @sb: super block
684 * reading the super block, getting disk layout information, initializing
696 down_write(&nilfs->ns_sem); in init_nilfs()
700 nilfs_err(sb, "unable to set blocksize"); in init_nilfs()
701 err = -EINVAL; in init_nilfs()
724 err = -EINVAL; in init_nilfs()
727 if (sb->s_blocksize != blocksize) { in init_nilfs()
728 int hw_blocksize = bdev_logical_block_size(sb->s_bdev); in init_nilfs()
732 "blocksize %d too small for device (sector-size = %d)", in init_nilfs()
734 err = -EINVAL; in init_nilfs()
740 err = -EINVAL; in init_nilfs()
752 nilfs->ns_blocksize_bits = sb->s_blocksize_bits; in init_nilfs()
753 nilfs->ns_blocksize = blocksize; in init_nilfs()
759 sb->s_maxbytes = nilfs_max_size(sb->s_blocksize_bits); in init_nilfs()
761 nilfs->ns_mount_state = le16_to_cpu(sbp->s_state); in init_nilfs()
770 up_write(&nilfs->ns_sem); in init_nilfs()
787 sects_per_block = (1 << nilfs->ns_blocksize_bits) / in nilfs_discard_segments()
788 bdev_logical_block_size(nilfs->ns_bdev); in nilfs_discard_segments()
794 nblocks = seg_end - seg_start + 1; in nilfs_discard_segments()
796 nblocks += seg_end - seg_start + 1; in nilfs_discard_segments()
798 ret = blkdev_issue_discard(nilfs->ns_bdev, in nilfs_discard_segments()
808 ret = blkdev_issue_discard(nilfs->ns_bdev, in nilfs_discard_segments()
819 ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile); in nilfs_count_free_blocks()
820 *nblocks = (sector_t)ncleansegs * nilfs->ns_blocks_per_segment; in nilfs_count_free_blocks()
828 ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile); in nilfs_near_disk_full()
829 nincsegs = atomic_read(&nilfs->ns_ndirtyblks) / in nilfs_near_disk_full()
830 nilfs->ns_blocks_per_segment + 1; in nilfs_near_disk_full()
832 return ncleansegs <= nilfs->ns_nrsvsegs + nincsegs; in nilfs_near_disk_full()
840 spin_lock(&nilfs->ns_cptree_lock); in nilfs_lookup_root()
841 n = nilfs->ns_cptree.rb_node; in nilfs_lookup_root()
845 if (cno < root->cno) { in nilfs_lookup_root()
846 n = n->rb_left; in nilfs_lookup_root()
847 } else if (cno > root->cno) { in nilfs_lookup_root()
848 n = n->rb_right; in nilfs_lookup_root()
850 refcount_inc(&root->count); in nilfs_lookup_root()
851 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_lookup_root()
855 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_lookup_root()
875 spin_lock(&nilfs->ns_cptree_lock); in nilfs_find_or_create_root()
877 p = &nilfs->ns_cptree.rb_node; in nilfs_find_or_create_root()
884 if (cno < root->cno) { in nilfs_find_or_create_root()
885 p = &(*p)->rb_left; in nilfs_find_or_create_root()
886 } else if (cno > root->cno) { in nilfs_find_or_create_root()
887 p = &(*p)->rb_right; in nilfs_find_or_create_root()
889 refcount_inc(&root->count); in nilfs_find_or_create_root()
890 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_find_or_create_root()
896 new->cno = cno; in nilfs_find_or_create_root()
897 new->ifile = NULL; in nilfs_find_or_create_root()
898 new->nilfs = nilfs; in nilfs_find_or_create_root()
899 refcount_set(&new->count, 1); in nilfs_find_or_create_root()
900 atomic64_set(&new->inodes_count, 0); in nilfs_find_or_create_root()
901 atomic64_set(&new->blocks_count, 0); in nilfs_find_or_create_root()
903 rb_link_node(&new->rb_node, parent, p); in nilfs_find_or_create_root()
904 rb_insert_color(&new->rb_node, &nilfs->ns_cptree); in nilfs_find_or_create_root()
906 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_find_or_create_root()
919 struct the_nilfs *nilfs = root->nilfs; in nilfs_put_root()
921 if (refcount_dec_and_lock(&root->count, &nilfs->ns_cptree_lock)) { in nilfs_put_root()
922 rb_erase(&root->rb_node, &nilfs->ns_cptree); in nilfs_put_root()
923 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_put_root()
926 iput(root->ifile); in nilfs_put_root()