@@ -391,18 +391,24 @@ static int nilfs_sync_fs(struct super_block *sb, int wait)
391391 return err ;
392392}
393393
394- int nilfs_attach_checkpoint (struct nilfs_sb_info * sbi , __u64 cno )
394+ int nilfs_attach_checkpoint (struct nilfs_sb_info * sbi , __u64 cno , int curr_mnt ,
395+ struct nilfs_root * * rootp )
395396{
396397 struct the_nilfs * nilfs = sbi -> s_nilfs ;
398+ struct nilfs_root * root ;
397399 struct nilfs_checkpoint * raw_cp ;
398400 struct buffer_head * bh_cp ;
399- int err ;
401+ int err = - ENOMEM ;
402+
403+ root = nilfs_find_or_create_root (
404+ nilfs , curr_mnt ? NILFS_CPTREE_CURRENT_CNO : cno );
405+ if (!root )
406+ return err ;
400407
401408 down_write (& nilfs -> ns_super_sem );
402409 list_add (& sbi -> s_list , & nilfs -> ns_supers );
403410 up_write (& nilfs -> ns_super_sem );
404411
405- err = - ENOMEM ;
406412 sbi -> s_ifile = nilfs_ifile_new (sbi , nilfs -> ns_inode_size );
407413 if (!sbi -> s_ifile )
408414 goto delist ;
@@ -428,6 +434,8 @@ int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno)
428434 atomic_set (& sbi -> s_blocks_count , le64_to_cpu (raw_cp -> cp_blocks_count ));
429435
430436 nilfs_cpfile_put_checkpoint (nilfs -> ns_cpfile , cno , bh_cp );
437+
438+ * rootp = root ;
431439 return 0 ;
432440
433441 failed_bh :
@@ -440,6 +448,7 @@ int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno)
440448 down_write (& nilfs -> ns_super_sem );
441449 list_del_init (& sbi -> s_list );
442450 up_write (& nilfs -> ns_super_sem );
451+ nilfs_put_root (root );
443452
444453 return err ;
445454}
@@ -551,12 +560,20 @@ static struct inode *
551560nilfs_nfs_get_inode (struct super_block * sb , u64 ino , u32 generation )
552561{
553562 struct inode * inode ;
563+ struct nilfs_root * root ;
554564
555565 if (ino < NILFS_FIRST_INO (sb ) && ino != NILFS_ROOT_INO &&
556566 ino != NILFS_SKETCH_INO )
557567 return ERR_PTR (- ESTALE );
558568
559- inode = nilfs_iget (sb , ino );
569+ root = nilfs_lookup_root (NILFS_SB (sb )-> s_nilfs ,
570+ NILFS_CPTREE_CURRENT_CNO );
571+ if (!root )
572+ return ERR_PTR (- ESTALE );
573+
574+ /* new file handle type is required to export snapshots */
575+ inode = nilfs_iget (sb , root , ino );
576+ nilfs_put_root (root );
560577 if (IS_ERR (inode ))
561578 return ERR_CAST (inode );
562579 if (generation && inode -> i_generation != generation ) {
@@ -815,9 +832,10 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
815832 struct the_nilfs * nilfs )
816833{
817834 struct nilfs_sb_info * sbi ;
835+ struct nilfs_root * fsroot ;
818836 struct inode * root ;
819837 __u64 cno ;
820- int err ;
838+ int err , curr_mnt ;
821839
822840 sbi = kzalloc (sizeof (* sbi ), GFP_KERNEL );
823841 if (!sbi )
@@ -859,6 +877,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
859877 goto failed_sbi ;
860878
861879 cno = nilfs_last_cno (nilfs );
880+ curr_mnt = true;
862881
863882 if (sb -> s_flags & MS_RDONLY ) {
864883 if (nilfs_test_opt (sbi , SNAPSHOT )) {
@@ -881,10 +900,11 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
881900 goto failed_sbi ;
882901 }
883902 cno = sbi -> s_snapshot_cno ;
903+ curr_mnt = false;
884904 }
885905 }
886906
887- err = nilfs_attach_checkpoint (sbi , cno );
907+ err = nilfs_attach_checkpoint (sbi , cno , curr_mnt , & fsroot );
888908 if (err ) {
889909 printk (KERN_ERR "NILFS: error loading a checkpoint"
890910 " (checkpoint number=%llu).\n" , (unsigned long long )cno );
@@ -897,7 +917,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
897917 goto failed_checkpoint ;
898918 }
899919
900- root = nilfs_iget (sb , NILFS_ROOT_INO );
920+ root = nilfs_iget (sb , fsroot , NILFS_ROOT_INO );
901921 if (IS_ERR (root )) {
902922 printk (KERN_ERR "NILFS: get root inode failed\n" );
903923 err = PTR_ERR (root );
@@ -917,6 +937,8 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
917937 goto failed_segctor ;
918938 }
919939
940+ nilfs_put_root (fsroot );
941+
920942 if (!(sb -> s_flags & MS_RDONLY )) {
921943 down_write (& nilfs -> ns_sem );
922944 nilfs_setup_super (sbi );
@@ -935,6 +957,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
935957
936958 failed_checkpoint :
937959 nilfs_detach_checkpoint (sbi );
960+ nilfs_put_root (fsroot );
938961
939962 failed_sbi :
940963 put_nilfs (nilfs );
0 commit comments