Skip to content

Commit 4d8d929

Browse files
committed
nilfs2: set pointer to root object in inodes
This puts a pointer to nilfs_root object in the private part of on-memory inode, and makes nilfs_iget function pick up the inode with the same root object. Non-root inodes inherit its nilfs_root object from parent inode. That of the root inode is allocated through nilfs_attach_checkpoint() function. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
1 parent ba65ae4 commit 4d8d929

5 files changed

Lines changed: 68 additions & 20 deletions

File tree

‎fs/nilfs2/inode.c‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
struct nilfs_iget_args {
3838
u64 ino;
3939
__u64 cno;
40+
struct nilfs_root *root;
4041
int for_gc;
4142
};
4243

@@ -284,6 +285,7 @@ struct inode *nilfs_new_inode(struct inode *dir, int mode)
284285
struct nilfs_sb_info *sbi = NILFS_SB(sb);
285286
struct inode *inode;
286287
struct nilfs_inode_info *ii;
288+
struct nilfs_root *root;
287289
int err = -ENOMEM;
288290
ino_t ino;
289291

@@ -294,8 +296,10 @@ struct inode *nilfs_new_inode(struct inode *dir, int mode)
294296
mapping_set_gfp_mask(inode->i_mapping,
295297
mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
296298

299+
root = NILFS_I(dir)->i_root;
297300
ii = NILFS_I(inode);
298301
ii->i_state = 1 << NILFS_I_NEW;
302+
ii->i_root = root;
299303

300304
err = nilfs_ifile_create_inode(sbi->s_ifile, &ino, &ii->i_bh);
301305
if (unlikely(err))
@@ -484,7 +488,7 @@ static int nilfs_iget_test(struct inode *inode, void *opaque)
484488
struct nilfs_iget_args *args = opaque;
485489
struct nilfs_inode_info *ii;
486490

487-
if (args->ino != inode->i_ino)
491+
if (args->ino != inode->i_ino || args->root != NILFS_I(inode)->i_root)
488492
return 0;
489493

490494
ii = NILFS_I(inode);
@@ -502,13 +506,21 @@ static int nilfs_iget_set(struct inode *inode, void *opaque)
502506
if (args->for_gc) {
503507
NILFS_I(inode)->i_state = 1 << NILFS_I_GCINODE;
504508
NILFS_I(inode)->i_cno = args->cno;
509+
NILFS_I(inode)->i_root = NULL;
510+
} else {
511+
if (args->root && args->ino == NILFS_ROOT_INO)
512+
nilfs_get_root(args->root);
513+
NILFS_I(inode)->i_root = args->root;
505514
}
506515
return 0;
507516
}
508517

509-
struct inode *nilfs_iget(struct super_block *sb, unsigned long ino)
518+
struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root,
519+
unsigned long ino)
510520
{
511-
struct nilfs_iget_args args = { .ino = ino, .cno = 0, .for_gc = 0 };
521+
struct nilfs_iget_args args = {
522+
.ino = ino, .root = root, .cno = 0, .for_gc = 0
523+
};
512524
struct inode *inode;
513525
int err;
514526

@@ -530,7 +542,9 @@ struct inode *nilfs_iget(struct super_block *sb, unsigned long ino)
530542
struct inode *nilfs_iget_for_gc(struct super_block *sb, unsigned long ino,
531543
__u64 cno)
532544
{
533-
struct nilfs_iget_args args = { .ino = ino, .cno = cno, .for_gc = 1 };
545+
struct nilfs_iget_args args = {
546+
.ino = ino, .root = NULL, .cno = cno, .for_gc = 1
547+
};
534548
struct inode *inode;
535549
int err;
536550

@@ -682,6 +696,9 @@ static void nilfs_clear_inode(struct inode *inode)
682696
nilfs_bmap_clear(ii->i_bmap);
683697

684698
nilfs_btnode_cache_clear(&ii->i_btnode_cache);
699+
700+
if (ii->i_root && inode->i_ino == NILFS_ROOT_INO)
701+
nilfs_put_root(ii->i_root);
685702
}
686703

687704
void nilfs_evict_inode(struct inode *inode)
@@ -690,7 +707,7 @@ void nilfs_evict_inode(struct inode *inode)
690707
struct super_block *sb = inode->i_sb;
691708
struct nilfs_inode_info *ii = NILFS_I(inode);
692709

693-
if (inode->i_nlink || unlikely(is_bad_inode(inode))) {
710+
if (inode->i_nlink || !ii->i_root || unlikely(is_bad_inode(inode))) {
694711
if (inode->i_data.nrpages)
695712
truncate_inode_pages(&inode->i_data, 0);
696713
end_writeback(inode);

‎fs/nilfs2/namei.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ nilfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
7070
ino = nilfs_inode_by_name(dir, &dentry->d_name);
7171
inode = NULL;
7272
if (ino) {
73-
inode = nilfs_iget(dir->i_sb, ino);
73+
inode = nilfs_iget(dir->i_sb, NILFS_I(dir)->i_root, ino);
7474
if (IS_ERR(inode))
7575
return ERR_CAST(inode);
7676
}
@@ -87,7 +87,8 @@ struct dentry *nilfs_get_parent(struct dentry *child)
8787
if (!ino)
8888
return ERR_PTR(-ENOENT);
8989

90-
inode = nilfs_iget(child->d_inode->i_sb, ino);
90+
inode = nilfs_iget(child->d_inode->i_sb,
91+
NILFS_I(child->d_inode)->i_root, ino);
9192
if (IS_ERR(inode))
9293
return ERR_CAST(inode);
9394
return d_obtain_alias(inode);

‎fs/nilfs2/nilfs.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct nilfs_inode_info {
5959
#endif
6060
struct buffer_head *i_bh; /* i_bh contains a new or dirty
6161
disk inode */
62+
struct nilfs_root *i_root;
6263
struct inode vfs_inode;
6364
};
6465

@@ -247,7 +248,8 @@ extern int nilfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
247248
extern void nilfs_set_inode_flags(struct inode *);
248249
extern int nilfs_read_inode_common(struct inode *, struct nilfs_inode *);
249250
extern void nilfs_write_inode_common(struct inode *, struct nilfs_inode *, int);
250-
extern struct inode *nilfs_iget(struct super_block *, unsigned long);
251+
struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root,
252+
unsigned long ino);
251253
extern struct inode *nilfs_iget_for_gc(struct super_block *sb,
252254
unsigned long ino, __u64 cno);
253255
extern void nilfs_update_inode(struct inode *, struct buffer_head *);
@@ -285,7 +287,8 @@ extern struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *,
285287
int flip);
286288
extern int nilfs_commit_super(struct nilfs_sb_info *, int);
287289
extern int nilfs_cleanup_super(struct nilfs_sb_info *);
288-
extern int nilfs_attach_checkpoint(struct nilfs_sb_info *, __u64);
290+
int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt,
291+
struct nilfs_root **root);
289292
extern void nilfs_detach_checkpoint(struct nilfs_sb_info *);
290293

291294
/* gcinode.c */

‎fs/nilfs2/recovery.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ static int nilfs_recovery_copy_block(struct the_nilfs *nilfs,
504504

505505
static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
506506
struct nilfs_sb_info *sbi,
507+
struct nilfs_root *root,
507508
struct list_head *head,
508509
unsigned long *nr_salvaged_blocks)
509510
{
@@ -515,7 +516,7 @@ static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
515516
int err = 0, err2 = 0;
516517

517518
list_for_each_entry_safe(rb, n, head, list) {
518-
inode = nilfs_iget(sbi->s_super, rb->ino);
519+
inode = nilfs_iget(sbi->s_super, root, rb->ino);
519520
if (IS_ERR(inode)) {
520521
err = PTR_ERR(inode);
521522
inode = NULL;
@@ -578,6 +579,7 @@ static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
578579
*/
579580
static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
580581
struct nilfs_sb_info *sbi,
582+
struct nilfs_root *root,
581583
struct nilfs_recovery_info *ri)
582584
{
583585
struct buffer_head *bh_sum = NULL;
@@ -649,7 +651,7 @@ static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
649651
goto failed;
650652
if (flags & NILFS_SS_LOGEND) {
651653
err = nilfs_recover_dsync_blocks(
652-
nilfs, sbi, &dsync_blocks,
654+
nilfs, sbi, root, &dsync_blocks,
653655
&nsalvaged_blocks);
654656
if (unlikely(err))
655657
goto failed;
@@ -746,19 +748,20 @@ int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs,
746748
struct nilfs_sb_info *sbi,
747749
struct nilfs_recovery_info *ri)
748750
{
751+
struct nilfs_root *root;
749752
int err;
750753

751754
if (ri->ri_lsegs_start == 0 || ri->ri_lsegs_end == 0)
752755
return 0;
753756

754-
err = nilfs_attach_checkpoint(sbi, ri->ri_cno);
757+
err = nilfs_attach_checkpoint(sbi, ri->ri_cno, true, &root);
755758
if (unlikely(err)) {
756759
printk(KERN_ERR
757760
"NILFS: error loading the latest checkpoint.\n");
758761
return err;
759762
}
760763

761-
err = nilfs_do_roll_forward(nilfs, sbi, ri);
764+
err = nilfs_do_roll_forward(nilfs, sbi, root, ri);
762765
if (unlikely(err))
763766
goto failed;
764767

@@ -789,6 +792,7 @@ int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs,
789792

790793
failed:
791794
nilfs_detach_checkpoint(sbi);
795+
nilfs_put_root(root);
792796
return err;
793797
}
794798

‎fs/nilfs2/super.c‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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 *
551560
nilfs_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

Comments
 (0)