Lines Matching refs:nilfs

29 void nilfs_set_last_segment(struct the_nilfs *nilfs,  in nilfs_set_last_segment()  argument
32 spin_lock(&nilfs->ns_last_segment_lock); in nilfs_set_last_segment()
33 nilfs->ns_last_pseg = start_blocknr; in nilfs_set_last_segment()
34 nilfs->ns_last_seq = seq; in nilfs_set_last_segment()
35 nilfs->ns_last_cno = cno; in nilfs_set_last_segment()
37 if (!nilfs_sb_dirty(nilfs)) { in nilfs_set_last_segment()
38 if (nilfs->ns_prev_seq == nilfs->ns_last_seq) in nilfs_set_last_segment()
41 set_nilfs_sb_dirty(nilfs); in nilfs_set_last_segment()
43 nilfs->ns_prev_seq = nilfs->ns_last_seq; in nilfs_set_last_segment()
46 spin_unlock(&nilfs->ns_last_segment_lock); in nilfs_set_last_segment()
58 struct the_nilfs *nilfs; in alloc_nilfs() local
60 nilfs = kzalloc(sizeof(*nilfs), GFP_KERNEL); in alloc_nilfs()
61 if (!nilfs) in alloc_nilfs()
64 nilfs->ns_sb = sb; in alloc_nilfs()
65 nilfs->ns_bdev = sb->s_bdev; in alloc_nilfs()
66 atomic_set(&nilfs->ns_ndirtyblks, 0); in alloc_nilfs()
67 init_rwsem(&nilfs->ns_sem); in alloc_nilfs()
68 mutex_init(&nilfs->ns_snapshot_mount_mutex); in alloc_nilfs()
69 INIT_LIST_HEAD(&nilfs->ns_dirty_files); in alloc_nilfs()
70 INIT_LIST_HEAD(&nilfs->ns_gc_inodes); in alloc_nilfs()
71 spin_lock_init(&nilfs->ns_inode_lock); in alloc_nilfs()
72 spin_lock_init(&nilfs->ns_next_gen_lock); in alloc_nilfs()
73 spin_lock_init(&nilfs->ns_last_segment_lock); in alloc_nilfs()
74 nilfs->ns_cptree = RB_ROOT; in alloc_nilfs()
75 spin_lock_init(&nilfs->ns_cptree_lock); in alloc_nilfs()
76 init_rwsem(&nilfs->ns_segctor_sem); in alloc_nilfs()
77 nilfs->ns_sb_update_freq = NILFS_SB_FREQ; in alloc_nilfs()
79 return nilfs; in alloc_nilfs()
86 void destroy_nilfs(struct the_nilfs *nilfs) in destroy_nilfs() argument
89 if (nilfs_init(nilfs)) { in destroy_nilfs()
90 brelse(nilfs->ns_sbh[0]); in destroy_nilfs()
91 brelse(nilfs->ns_sbh[1]); in destroy_nilfs()
93 kfree(nilfs); in destroy_nilfs()
96 static int nilfs_load_super_root(struct the_nilfs *nilfs, in nilfs_load_super_root() argument
101 struct nilfs_super_block **sbp = nilfs->ns_sbp; in nilfs_load_super_root()
107 err = nilfs_read_super_root_block(nilfs, sr_block, &bh_sr, 1); in nilfs_load_super_root()
111 down_read(&nilfs->ns_sem); in nilfs_load_super_root()
115 up_read(&nilfs->ns_sem); in nilfs_load_super_root()
117 inode_size = nilfs->ns_inode_size; in nilfs_load_super_root()
120 err = nilfs_dat_read(sb, dat_entry_size, rawi, &nilfs->ns_dat); in nilfs_load_super_root()
125 err = nilfs_cpfile_read(sb, checkpoint_size, rawi, &nilfs->ns_cpfile); in nilfs_load_super_root()
131 &nilfs->ns_sufile); in nilfs_load_super_root()
136 nilfs->ns_nongc_ctime = le64_to_cpu(raw_sr->sr_nongc_ctime); in nilfs_load_super_root()
143 iput(nilfs->ns_cpfile); in nilfs_load_super_root()
146 iput(nilfs->ns_dat); in nilfs_load_super_root()
171 static int nilfs_store_log_cursor(struct the_nilfs *nilfs, in nilfs_store_log_cursor() argument
176 nilfs->ns_last_pseg = le64_to_cpu(sbp->s_last_pseg); in nilfs_store_log_cursor()
177 nilfs->ns_last_cno = le64_to_cpu(sbp->s_last_cno); in nilfs_store_log_cursor()
178 nilfs->ns_last_seq = le64_to_cpu(sbp->s_last_seq); in nilfs_store_log_cursor()
180 nilfs->ns_prev_seq = nilfs->ns_last_seq; in nilfs_store_log_cursor()
181 nilfs->ns_seg_seq = nilfs->ns_last_seq; in nilfs_store_log_cursor()
182 nilfs->ns_segnum = in nilfs_store_log_cursor()
183 nilfs_get_segnum_of_block(nilfs, nilfs->ns_last_pseg); in nilfs_store_log_cursor()
184 nilfs->ns_cno = nilfs->ns_last_cno + 1; in nilfs_store_log_cursor()
185 if (nilfs->ns_segnum >= nilfs->ns_nsegments) { in nilfs_store_log_cursor()
186 nilfs_err(nilfs->ns_sb, in nilfs_store_log_cursor()
188 (unsigned long long)nilfs->ns_segnum, in nilfs_store_log_cursor()
189 nilfs->ns_nsegments); in nilfs_store_log_cursor()
232 int load_nilfs(struct the_nilfs *nilfs, struct super_block *sb) in load_nilfs() argument
236 int really_read_only = bdev_read_only(nilfs->ns_bdev); in load_nilfs()
237 int valid_fs = nilfs_valid_fs(nilfs); in load_nilfs()
252 err = nilfs_search_super_root(nilfs, &ri); in load_nilfs()
254 struct nilfs_super_block **sbp = nilfs->ns_sbp; in load_nilfs()
271 memcpy(sbp[0], sbp[1], nilfs->ns_sbsize); in load_nilfs()
272 nilfs->ns_crc_seed = le32_to_cpu(sbp[0]->s_crc_seed); in load_nilfs()
273 nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime); in load_nilfs()
280 if (blocksize != nilfs->ns_blocksize) { in load_nilfs()
283 blocksize, nilfs->ns_blocksize); in load_nilfs()
288 err = nilfs_store_log_cursor(nilfs, sbp[0]); in load_nilfs()
293 nilfs->ns_mount_state &= ~NILFS_VALID_FS; in load_nilfs()
296 err = nilfs_search_super_root(nilfs, &ri); in load_nilfs()
301 err = nilfs_load_super_root(nilfs, sb, ri.ri_super_root); in load_nilfs()
317 if (nilfs_test_opt(nilfs, NORECOVERY)) { in load_nilfs()
322 features = le64_to_cpu(nilfs->ns_sbp[0]->s_feature_compat_ro) & in load_nilfs()
338 } else if (nilfs_test_opt(nilfs, NORECOVERY)) { in load_nilfs()
345 err = nilfs_salvage_orphan_logs(nilfs, sb, &ri); in load_nilfs()
349 down_write(&nilfs->ns_sem); in load_nilfs()
350 nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */ in load_nilfs()
352 up_write(&nilfs->ns_sem); in load_nilfs()
372 nilfs_sysfs_delete_device_group(nilfs); in load_nilfs()
375 iput(nilfs->ns_cpfile); in load_nilfs()
376 iput(nilfs->ns_sufile); in load_nilfs()
377 iput(nilfs->ns_dat); in load_nilfs()
401 unsigned long nilfs_nrsvsegs(struct the_nilfs *nilfs, unsigned long nsegs) in nilfs_nrsvsegs() argument
404 DIV_ROUND_UP(nsegs * nilfs->ns_r_segments_percentage, in nilfs_nrsvsegs()
412 static u64 nilfs_max_segment_count(struct the_nilfs *nilfs) in nilfs_max_segment_count() argument
416 do_div(max_count, nilfs->ns_blocks_per_segment); in nilfs_max_segment_count()
420 void nilfs_set_nsegments(struct the_nilfs *nilfs, unsigned long nsegs) in nilfs_set_nsegments() argument
422 nilfs->ns_nsegments = nsegs; in nilfs_set_nsegments()
423 nilfs->ns_nrsvsegs = nilfs_nrsvsegs(nilfs, nsegs); in nilfs_set_nsegments()
426 static int nilfs_store_disk_layout(struct the_nilfs *nilfs, in nilfs_store_disk_layout() argument
432 nilfs_err(nilfs->ns_sb, in nilfs_store_disk_layout()
439 nilfs->ns_sbsize = le16_to_cpu(sbp->s_bytes); in nilfs_store_disk_layout()
440 if (nilfs->ns_sbsize > BLOCK_SIZE) in nilfs_store_disk_layout()
443 nilfs->ns_inode_size = le16_to_cpu(sbp->s_inode_size); in nilfs_store_disk_layout()
444 if (nilfs->ns_inode_size > nilfs->ns_blocksize) { in nilfs_store_disk_layout()
445 nilfs_err(nilfs->ns_sb, "too large inode size: %d bytes", in nilfs_store_disk_layout()
446 nilfs->ns_inode_size); in nilfs_store_disk_layout()
448 } else if (nilfs->ns_inode_size < NILFS_MIN_INODE_SIZE) { in nilfs_store_disk_layout()
449 nilfs_err(nilfs->ns_sb, "too small inode size: %d bytes", in nilfs_store_disk_layout()
450 nilfs->ns_inode_size); in nilfs_store_disk_layout()
454 nilfs->ns_first_ino = le32_to_cpu(sbp->s_first_ino); in nilfs_store_disk_layout()
456 nilfs->ns_blocks_per_segment = le32_to_cpu(sbp->s_blocks_per_segment); in nilfs_store_disk_layout()
457 if (nilfs->ns_blocks_per_segment < NILFS_SEG_MIN_BLOCKS) { in nilfs_store_disk_layout()
458 nilfs_err(nilfs->ns_sb, "too short segment: %lu blocks", in nilfs_store_disk_layout()
459 nilfs->ns_blocks_per_segment); in nilfs_store_disk_layout()
463 nilfs->ns_first_data_block = le64_to_cpu(sbp->s_first_data_block); in nilfs_store_disk_layout()
464 nilfs->ns_r_segments_percentage = in nilfs_store_disk_layout()
466 if (nilfs->ns_r_segments_percentage < 1 || in nilfs_store_disk_layout()
467 nilfs->ns_r_segments_percentage > 99) { in nilfs_store_disk_layout()
468 nilfs_err(nilfs->ns_sb, in nilfs_store_disk_layout()
470 nilfs->ns_r_segments_percentage); in nilfs_store_disk_layout()
475 if (nsegments > nilfs_max_segment_count(nilfs)) { in nilfs_store_disk_layout()
476 nilfs_err(nilfs->ns_sb, in nilfs_store_disk_layout()
479 (unsigned long long)nilfs_max_segment_count(nilfs)); in nilfs_store_disk_layout()
483 nblocks = sb_bdev_nr_blocks(nilfs->ns_sb); in nilfs_store_disk_layout()
485 u64 min_block_count = nsegments * nilfs->ns_blocks_per_segment; in nilfs_store_disk_layout()
493 nilfs_err(nilfs->ns_sb, in nilfs_store_disk_layout()
501 nilfs_set_nsegments(nilfs, nsegments); in nilfs_store_disk_layout()
502 nilfs->ns_crc_seed = le32_to_cpu(sbp->s_crc_seed); in nilfs_store_disk_layout()
555 static void nilfs_release_super_block(struct the_nilfs *nilfs) in nilfs_release_super_block() argument
560 if (nilfs->ns_sbp[i]) { in nilfs_release_super_block()
561 brelse(nilfs->ns_sbh[i]); in nilfs_release_super_block()
562 nilfs->ns_sbh[i] = NULL; in nilfs_release_super_block()
563 nilfs->ns_sbp[i] = NULL; in nilfs_release_super_block()
568 void nilfs_fall_back_super_block(struct the_nilfs *nilfs) in nilfs_fall_back_super_block() argument
570 brelse(nilfs->ns_sbh[0]); in nilfs_fall_back_super_block()
571 nilfs->ns_sbh[0] = nilfs->ns_sbh[1]; in nilfs_fall_back_super_block()
572 nilfs->ns_sbp[0] = nilfs->ns_sbp[1]; in nilfs_fall_back_super_block()
573 nilfs->ns_sbh[1] = NULL; in nilfs_fall_back_super_block()
574 nilfs->ns_sbp[1] = NULL; in nilfs_fall_back_super_block()
577 void nilfs_swap_super_block(struct the_nilfs *nilfs) in nilfs_swap_super_block() argument
579 struct buffer_head *tsbh = nilfs->ns_sbh[0]; in nilfs_swap_super_block()
580 struct nilfs_super_block *tsbp = nilfs->ns_sbp[0]; in nilfs_swap_super_block()
582 nilfs->ns_sbh[0] = nilfs->ns_sbh[1]; in nilfs_swap_super_block()
583 nilfs->ns_sbp[0] = nilfs->ns_sbp[1]; in nilfs_swap_super_block()
584 nilfs->ns_sbh[1] = tsbh; in nilfs_swap_super_block()
585 nilfs->ns_sbp[1] = tsbp; in nilfs_swap_super_block()
588 static int nilfs_load_super_block(struct the_nilfs *nilfs, in nilfs_load_super_block() argument
592 struct nilfs_super_block **sbp = nilfs->ns_sbp; in nilfs_load_super_block()
593 struct buffer_head **sbh = nilfs->ns_sbh; in nilfs_load_super_block()
594 u64 sb2off, devsize = bdev_nr_bytes(nilfs->ns_bdev); in nilfs_load_super_block()
639 nilfs_release_super_block(nilfs); in nilfs_load_super_block()
649 nilfs_swap_super_block(nilfs); in nilfs_load_super_block()
651 nilfs->ns_sbwcount = 0; in nilfs_load_super_block()
652 nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime); in nilfs_load_super_block()
653 nilfs->ns_prot_seq = le64_to_cpu(sbp[valid[1] & !swp]->s_last_seq); in nilfs_load_super_block()
671 int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb, char *data) in init_nilfs() argument
677 down_write(&nilfs->ns_sem); in init_nilfs()
685 err = nilfs_load_super_block(nilfs, sb, blocksize, &sbp); in init_nilfs()
718 nilfs_release_super_block(nilfs); in init_nilfs()
725 err = nilfs_load_super_block(nilfs, sb, blocksize, &sbp); in init_nilfs()
733 nilfs->ns_blocksize_bits = sb->s_blocksize_bits; in init_nilfs()
734 nilfs->ns_blocksize = blocksize; in init_nilfs()
736 get_random_bytes(&nilfs->ns_next_generation, in init_nilfs()
737 sizeof(nilfs->ns_next_generation)); in init_nilfs()
739 err = nilfs_store_disk_layout(nilfs, sbp); in init_nilfs()
745 nilfs->ns_mount_state = le16_to_cpu(sbp->s_state); in init_nilfs()
747 err = nilfs_store_log_cursor(nilfs, sbp); in init_nilfs()
751 set_nilfs_init(nilfs); in init_nilfs()
754 up_write(&nilfs->ns_sem); in init_nilfs()
758 nilfs_release_super_block(nilfs); in init_nilfs()
762 int nilfs_discard_segments(struct the_nilfs *nilfs, __u64 *segnump, in nilfs_discard_segments() argument
771 sects_per_block = (1 << nilfs->ns_blocksize_bits) / in nilfs_discard_segments()
772 bdev_logical_block_size(nilfs->ns_bdev); in nilfs_discard_segments()
774 nilfs_get_segment_range(nilfs, *sn, &seg_start, &seg_end); in nilfs_discard_segments()
782 ret = blkdev_issue_discard(nilfs->ns_bdev, in nilfs_discard_segments()
792 ret = blkdev_issue_discard(nilfs->ns_bdev, in nilfs_discard_segments()
799 int nilfs_count_free_blocks(struct the_nilfs *nilfs, sector_t *nblocks) in nilfs_count_free_blocks() argument
803 ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile); in nilfs_count_free_blocks()
804 *nblocks = (sector_t)ncleansegs * nilfs->ns_blocks_per_segment; in nilfs_count_free_blocks()
808 int nilfs_near_disk_full(struct the_nilfs *nilfs) in nilfs_near_disk_full() argument
812 ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile); in nilfs_near_disk_full()
813 nincsegs = atomic_read(&nilfs->ns_ndirtyblks) / in nilfs_near_disk_full()
814 nilfs->ns_blocks_per_segment + 1; in nilfs_near_disk_full()
816 return ncleansegs <= nilfs->ns_nrsvsegs + nincsegs; in nilfs_near_disk_full()
819 struct nilfs_root *nilfs_lookup_root(struct the_nilfs *nilfs, __u64 cno) in nilfs_lookup_root() argument
824 spin_lock(&nilfs->ns_cptree_lock); in nilfs_lookup_root()
825 n = nilfs->ns_cptree.rb_node; in nilfs_lookup_root()
835 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_lookup_root()
839 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_lookup_root()
845 nilfs_find_or_create_root(struct the_nilfs *nilfs, __u64 cno) in nilfs_find_or_create_root() argument
851 root = nilfs_lookup_root(nilfs, cno); in nilfs_find_or_create_root()
859 spin_lock(&nilfs->ns_cptree_lock); in nilfs_find_or_create_root()
861 p = &nilfs->ns_cptree.rb_node; in nilfs_find_or_create_root()
874 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_find_or_create_root()
882 new->nilfs = nilfs; in nilfs_find_or_create_root()
888 rb_insert_color(&new->rb_node, &nilfs->ns_cptree); in nilfs_find_or_create_root()
890 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_find_or_create_root()
903 struct the_nilfs *nilfs = root->nilfs; in nilfs_put_root() local
905 if (refcount_dec_and_lock(&root->count, &nilfs->ns_cptree_lock)) { in nilfs_put_root()
906 rb_erase(&root->rb_node, &nilfs->ns_cptree); in nilfs_put_root()
907 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_put_root()