• Home
  • Raw
  • Download

Lines Matching refs:nilfs

37 void nilfs_set_last_segment(struct the_nilfs *nilfs,  in nilfs_set_last_segment()  argument
40 spin_lock(&nilfs->ns_last_segment_lock); in nilfs_set_last_segment()
41 nilfs->ns_last_pseg = start_blocknr; in nilfs_set_last_segment()
42 nilfs->ns_last_seq = seq; in nilfs_set_last_segment()
43 nilfs->ns_last_cno = cno; in nilfs_set_last_segment()
45 if (!nilfs_sb_dirty(nilfs)) { in nilfs_set_last_segment()
46 if (nilfs->ns_prev_seq == nilfs->ns_last_seq) in nilfs_set_last_segment()
49 set_nilfs_sb_dirty(nilfs); in nilfs_set_last_segment()
51 nilfs->ns_prev_seq = nilfs->ns_last_seq; in nilfs_set_last_segment()
54 spin_unlock(&nilfs->ns_last_segment_lock); in nilfs_set_last_segment()
66 struct the_nilfs *nilfs; in alloc_nilfs() local
68 nilfs = kzalloc(sizeof(*nilfs), GFP_KERNEL); in alloc_nilfs()
69 if (!nilfs) in alloc_nilfs()
72 nilfs->ns_sb = sb; in alloc_nilfs()
73 nilfs->ns_bdev = sb->s_bdev; in alloc_nilfs()
74 atomic_set(&nilfs->ns_ndirtyblks, 0); in alloc_nilfs()
75 init_rwsem(&nilfs->ns_sem); in alloc_nilfs()
76 mutex_init(&nilfs->ns_snapshot_mount_mutex); in alloc_nilfs()
77 INIT_LIST_HEAD(&nilfs->ns_dirty_files); in alloc_nilfs()
78 INIT_LIST_HEAD(&nilfs->ns_gc_inodes); in alloc_nilfs()
79 spin_lock_init(&nilfs->ns_inode_lock); in alloc_nilfs()
80 spin_lock_init(&nilfs->ns_next_gen_lock); in alloc_nilfs()
81 spin_lock_init(&nilfs->ns_last_segment_lock); in alloc_nilfs()
82 nilfs->ns_cptree = RB_ROOT; in alloc_nilfs()
83 spin_lock_init(&nilfs->ns_cptree_lock); in alloc_nilfs()
84 init_rwsem(&nilfs->ns_segctor_sem); in alloc_nilfs()
85 nilfs->ns_sb_update_freq = NILFS_SB_FREQ; in alloc_nilfs()
87 return nilfs; in alloc_nilfs()
94 void destroy_nilfs(struct the_nilfs *nilfs) in destroy_nilfs() argument
97 if (nilfs_init(nilfs)) { in destroy_nilfs()
98 nilfs_sysfs_delete_device_group(nilfs); in destroy_nilfs()
99 brelse(nilfs->ns_sbh[0]); in destroy_nilfs()
100 brelse(nilfs->ns_sbh[1]); in destroy_nilfs()
102 kfree(nilfs); in destroy_nilfs()
105 static int nilfs_load_super_root(struct the_nilfs *nilfs, in nilfs_load_super_root() argument
110 struct nilfs_super_block **sbp = nilfs->ns_sbp; in nilfs_load_super_root()
116 err = nilfs_read_super_root_block(nilfs, sr_block, &bh_sr, 1); in nilfs_load_super_root()
120 down_read(&nilfs->ns_sem); in nilfs_load_super_root()
124 up_read(&nilfs->ns_sem); in nilfs_load_super_root()
126 inode_size = nilfs->ns_inode_size; in nilfs_load_super_root()
129 err = nilfs_dat_read(sb, dat_entry_size, rawi, &nilfs->ns_dat); in nilfs_load_super_root()
134 err = nilfs_cpfile_read(sb, checkpoint_size, rawi, &nilfs->ns_cpfile); in nilfs_load_super_root()
140 &nilfs->ns_sufile); in nilfs_load_super_root()
145 nilfs->ns_nongc_ctime = le64_to_cpu(raw_sr->sr_nongc_ctime); in nilfs_load_super_root()
152 iput(nilfs->ns_cpfile); in nilfs_load_super_root()
155 iput(nilfs->ns_dat); in nilfs_load_super_root()
180 static int nilfs_store_log_cursor(struct the_nilfs *nilfs, in nilfs_store_log_cursor() argument
185 nilfs->ns_last_pseg = le64_to_cpu(sbp->s_last_pseg); in nilfs_store_log_cursor()
186 nilfs->ns_last_cno = le64_to_cpu(sbp->s_last_cno); in nilfs_store_log_cursor()
187 nilfs->ns_last_seq = le64_to_cpu(sbp->s_last_seq); in nilfs_store_log_cursor()
189 nilfs->ns_prev_seq = nilfs->ns_last_seq; in nilfs_store_log_cursor()
190 nilfs->ns_seg_seq = nilfs->ns_last_seq; in nilfs_store_log_cursor()
191 nilfs->ns_segnum = in nilfs_store_log_cursor()
192 nilfs_get_segnum_of_block(nilfs, nilfs->ns_last_pseg); in nilfs_store_log_cursor()
193 nilfs->ns_cno = nilfs->ns_last_cno + 1; in nilfs_store_log_cursor()
194 if (nilfs->ns_segnum >= nilfs->ns_nsegments) { in nilfs_store_log_cursor()
195 nilfs_msg(nilfs->ns_sb, KERN_ERR, in nilfs_store_log_cursor()
197 (unsigned long long)nilfs->ns_segnum, in nilfs_store_log_cursor()
198 nilfs->ns_nsegments); in nilfs_store_log_cursor()
213 int load_nilfs(struct the_nilfs *nilfs, struct super_block *sb) in load_nilfs() argument
217 int really_read_only = bdev_read_only(nilfs->ns_bdev); in load_nilfs()
218 int valid_fs = nilfs_valid_fs(nilfs); in load_nilfs()
233 err = nilfs_search_super_root(nilfs, &ri); in load_nilfs()
235 struct nilfs_super_block **sbp = nilfs->ns_sbp; in load_nilfs()
253 memcpy(sbp[0], sbp[1], nilfs->ns_sbsize); in load_nilfs()
254 nilfs->ns_crc_seed = le32_to_cpu(sbp[0]->s_crc_seed); in load_nilfs()
255 nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime); in load_nilfs()
259 if (blocksize != nilfs->ns_blocksize) { in load_nilfs()
262 blocksize, nilfs->ns_blocksize); in load_nilfs()
266 err = nilfs_store_log_cursor(nilfs, sbp[0]); in load_nilfs()
271 nilfs->ns_mount_state &= ~NILFS_VALID_FS; in load_nilfs()
274 err = nilfs_search_super_root(nilfs, &ri); in load_nilfs()
279 err = nilfs_load_super_root(nilfs, sb, ri.ri_super_root); in load_nilfs()
292 if (nilfs_test_opt(nilfs, NORECOVERY)) { in load_nilfs()
297 features = le64_to_cpu(nilfs->ns_sbp[0]->s_feature_compat_ro) & in load_nilfs()
313 } else if (nilfs_test_opt(nilfs, NORECOVERY)) { in load_nilfs()
320 err = nilfs_salvage_orphan_logs(nilfs, sb, &ri); in load_nilfs()
324 down_write(&nilfs->ns_sem); in load_nilfs()
325 nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */ in load_nilfs()
327 up_write(&nilfs->ns_sem); in load_nilfs()
347 iput(nilfs->ns_cpfile); in load_nilfs()
348 iput(nilfs->ns_sufile); in load_nilfs()
349 iput(nilfs->ns_dat); in load_nilfs()
373 unsigned long nilfs_nrsvsegs(struct the_nilfs *nilfs, unsigned long nsegs) in nilfs_nrsvsegs() argument
376 DIV_ROUND_UP(nsegs * nilfs->ns_r_segments_percentage, in nilfs_nrsvsegs()
380 void nilfs_set_nsegments(struct the_nilfs *nilfs, unsigned long nsegs) in nilfs_set_nsegments() argument
382 nilfs->ns_nsegments = nsegs; in nilfs_set_nsegments()
383 nilfs->ns_nrsvsegs = nilfs_nrsvsegs(nilfs, nsegs); in nilfs_set_nsegments()
386 static int nilfs_store_disk_layout(struct the_nilfs *nilfs, in nilfs_store_disk_layout() argument
390 nilfs_msg(nilfs->ns_sb, KERN_ERR, in nilfs_store_disk_layout()
397 nilfs->ns_sbsize = le16_to_cpu(sbp->s_bytes); in nilfs_store_disk_layout()
398 if (nilfs->ns_sbsize > BLOCK_SIZE) in nilfs_store_disk_layout()
401 nilfs->ns_inode_size = le16_to_cpu(sbp->s_inode_size); in nilfs_store_disk_layout()
402 if (nilfs->ns_inode_size > nilfs->ns_blocksize) { in nilfs_store_disk_layout()
403 nilfs_msg(nilfs->ns_sb, KERN_ERR, in nilfs_store_disk_layout()
405 nilfs->ns_inode_size); in nilfs_store_disk_layout()
407 } else if (nilfs->ns_inode_size < NILFS_MIN_INODE_SIZE) { in nilfs_store_disk_layout()
408 nilfs_msg(nilfs->ns_sb, KERN_ERR, in nilfs_store_disk_layout()
410 nilfs->ns_inode_size); in nilfs_store_disk_layout()
414 nilfs->ns_first_ino = le32_to_cpu(sbp->s_first_ino); in nilfs_store_disk_layout()
416 nilfs->ns_blocks_per_segment = le32_to_cpu(sbp->s_blocks_per_segment); in nilfs_store_disk_layout()
417 if (nilfs->ns_blocks_per_segment < NILFS_SEG_MIN_BLOCKS) { in nilfs_store_disk_layout()
418 nilfs_msg(nilfs->ns_sb, KERN_ERR, in nilfs_store_disk_layout()
420 nilfs->ns_blocks_per_segment); in nilfs_store_disk_layout()
424 nilfs->ns_first_data_block = le64_to_cpu(sbp->s_first_data_block); in nilfs_store_disk_layout()
425 nilfs->ns_r_segments_percentage = in nilfs_store_disk_layout()
427 if (nilfs->ns_r_segments_percentage < 1 || in nilfs_store_disk_layout()
428 nilfs->ns_r_segments_percentage > 99) { in nilfs_store_disk_layout()
429 nilfs_msg(nilfs->ns_sb, KERN_ERR, in nilfs_store_disk_layout()
431 nilfs->ns_r_segments_percentage); in nilfs_store_disk_layout()
435 nilfs_set_nsegments(nilfs, le64_to_cpu(sbp->s_nsegments)); in nilfs_store_disk_layout()
436 nilfs->ns_crc_seed = le32_to_cpu(sbp->s_crc_seed); in nilfs_store_disk_layout()
467 static void nilfs_release_super_block(struct the_nilfs *nilfs) in nilfs_release_super_block() argument
472 if (nilfs->ns_sbp[i]) { in nilfs_release_super_block()
473 brelse(nilfs->ns_sbh[i]); in nilfs_release_super_block()
474 nilfs->ns_sbh[i] = NULL; in nilfs_release_super_block()
475 nilfs->ns_sbp[i] = NULL; in nilfs_release_super_block()
480 void nilfs_fall_back_super_block(struct the_nilfs *nilfs) in nilfs_fall_back_super_block() argument
482 brelse(nilfs->ns_sbh[0]); in nilfs_fall_back_super_block()
483 nilfs->ns_sbh[0] = nilfs->ns_sbh[1]; in nilfs_fall_back_super_block()
484 nilfs->ns_sbp[0] = nilfs->ns_sbp[1]; in nilfs_fall_back_super_block()
485 nilfs->ns_sbh[1] = NULL; in nilfs_fall_back_super_block()
486 nilfs->ns_sbp[1] = NULL; in nilfs_fall_back_super_block()
489 void nilfs_swap_super_block(struct the_nilfs *nilfs) in nilfs_swap_super_block() argument
491 struct buffer_head *tsbh = nilfs->ns_sbh[0]; in nilfs_swap_super_block()
492 struct nilfs_super_block *tsbp = nilfs->ns_sbp[0]; in nilfs_swap_super_block()
494 nilfs->ns_sbh[0] = nilfs->ns_sbh[1]; in nilfs_swap_super_block()
495 nilfs->ns_sbp[0] = nilfs->ns_sbp[1]; in nilfs_swap_super_block()
496 nilfs->ns_sbh[1] = tsbh; in nilfs_swap_super_block()
497 nilfs->ns_sbp[1] = tsbp; in nilfs_swap_super_block()
500 static int nilfs_load_super_block(struct the_nilfs *nilfs, in nilfs_load_super_block() argument
504 struct nilfs_super_block **sbp = nilfs->ns_sbp; in nilfs_load_super_block()
505 struct buffer_head **sbh = nilfs->ns_sbh; in nilfs_load_super_block()
506 u64 sb2off = NILFS_SB2_OFFSET_BYTES(nilfs->ns_bdev->bd_inode->i_size); in nilfs_load_super_block()
545 nilfs_release_super_block(nilfs); in nilfs_load_super_block()
555 nilfs_swap_super_block(nilfs); in nilfs_load_super_block()
557 nilfs->ns_sbwcount = 0; in nilfs_load_super_block()
558 nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime); in nilfs_load_super_block()
559 nilfs->ns_prot_seq = le64_to_cpu(sbp[valid[1] & !swp]->s_last_seq); in nilfs_load_super_block()
577 int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb, char *data) in init_nilfs() argument
583 down_write(&nilfs->ns_sem); in init_nilfs()
591 err = nilfs_load_super_block(nilfs, sb, blocksize, &sbp); in init_nilfs()
622 nilfs_release_super_block(nilfs); in init_nilfs()
625 err = nilfs_load_super_block(nilfs, sb, blocksize, &sbp); in init_nilfs()
633 nilfs->ns_blocksize_bits = sb->s_blocksize_bits; in init_nilfs()
634 nilfs->ns_blocksize = blocksize; in init_nilfs()
636 get_random_bytes(&nilfs->ns_next_generation, in init_nilfs()
637 sizeof(nilfs->ns_next_generation)); in init_nilfs()
639 err = nilfs_store_disk_layout(nilfs, sbp); in init_nilfs()
645 nilfs->ns_mount_state = le16_to_cpu(sbp->s_state); in init_nilfs()
647 err = nilfs_store_log_cursor(nilfs, sbp); in init_nilfs()
655 set_nilfs_init(nilfs); in init_nilfs()
658 up_write(&nilfs->ns_sem); in init_nilfs()
662 nilfs_release_super_block(nilfs); in init_nilfs()
666 int nilfs_discard_segments(struct the_nilfs *nilfs, __u64 *segnump, in nilfs_discard_segments() argument
675 sects_per_block = (1 << nilfs->ns_blocksize_bits) / in nilfs_discard_segments()
676 bdev_logical_block_size(nilfs->ns_bdev); in nilfs_discard_segments()
678 nilfs_get_segment_range(nilfs, *sn, &seg_start, &seg_end); in nilfs_discard_segments()
686 ret = blkdev_issue_discard(nilfs->ns_bdev, in nilfs_discard_segments()
696 ret = blkdev_issue_discard(nilfs->ns_bdev, in nilfs_discard_segments()
703 int nilfs_count_free_blocks(struct the_nilfs *nilfs, sector_t *nblocks) in nilfs_count_free_blocks() argument
707 down_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem); in nilfs_count_free_blocks()
708 ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile); in nilfs_count_free_blocks()
709 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem); in nilfs_count_free_blocks()
710 *nblocks = (sector_t)ncleansegs * nilfs->ns_blocks_per_segment; in nilfs_count_free_blocks()
714 int nilfs_near_disk_full(struct the_nilfs *nilfs) in nilfs_near_disk_full() argument
718 ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile); in nilfs_near_disk_full()
719 nincsegs = atomic_read(&nilfs->ns_ndirtyblks) / in nilfs_near_disk_full()
720 nilfs->ns_blocks_per_segment + 1; in nilfs_near_disk_full()
722 return ncleansegs <= nilfs->ns_nrsvsegs + nincsegs; in nilfs_near_disk_full()
725 struct nilfs_root *nilfs_lookup_root(struct the_nilfs *nilfs, __u64 cno) in nilfs_lookup_root() argument
730 spin_lock(&nilfs->ns_cptree_lock); in nilfs_lookup_root()
731 n = nilfs->ns_cptree.rb_node; in nilfs_lookup_root()
741 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_lookup_root()
745 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_lookup_root()
751 nilfs_find_or_create_root(struct the_nilfs *nilfs, __u64 cno) in nilfs_find_or_create_root() argument
757 root = nilfs_lookup_root(nilfs, cno); in nilfs_find_or_create_root()
765 spin_lock(&nilfs->ns_cptree_lock); in nilfs_find_or_create_root()
767 p = &nilfs->ns_cptree.rb_node; in nilfs_find_or_create_root()
780 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_find_or_create_root()
788 new->nilfs = nilfs; in nilfs_find_or_create_root()
794 rb_insert_color(&new->rb_node, &nilfs->ns_cptree); in nilfs_find_or_create_root()
796 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_find_or_create_root()
810 struct the_nilfs *nilfs = root->nilfs; in nilfs_put_root() local
814 spin_lock(&nilfs->ns_cptree_lock); in nilfs_put_root()
815 rb_erase(&root->rb_node, &nilfs->ns_cptree); in nilfs_put_root()
816 spin_unlock(&nilfs->ns_cptree_lock); in nilfs_put_root()