Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab4d8f7e authored by Ryusuke Konishi's avatar Ryusuke Konishi
Browse files

nilfs2: split out nilfs_attach_snapshot



This splits the code to attach snapshots into a separate routine for
convenience sake.

Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
parent 367ea334
Loading
Loading
Loading
Loading
+45 −28
Original line number Original line Diff line number Diff line
@@ -783,6 +783,40 @@ static int nilfs_get_root_dentry(struct super_block *sb,
	return ret;
	return ret;
}
}


static int nilfs_attach_snapshot(struct super_block *s, __u64 cno,
				 struct dentry **root_dentry)
{
	struct the_nilfs *nilfs = NILFS_SB(s)->s_nilfs;
	struct nilfs_root *root;
	int ret;

	down_read(&nilfs->ns_segctor_sem);
	ret = nilfs_cpfile_is_snapshot(nilfs->ns_cpfile, cno);
	up_read(&nilfs->ns_segctor_sem);
	if (ret < 0) {
		ret = (ret == -ENOENT) ? -EINVAL : ret;
		goto out;
	} else if (!ret) {
		printk(KERN_ERR "NILFS: The specified checkpoint is "
		       "not a snapshot (checkpoint number=%llu).\n",
		       (unsigned long long)cno);
		ret = -EINVAL;
		goto out;
	}

	ret = nilfs_attach_checkpoint(NILFS_SB(s), cno, false, &root);
	if (ret) {
		printk(KERN_ERR "NILFS: error loading snapshot "
		       "(checkpoint number=%llu).\n",
	       (unsigned long long)cno);
		goto out;
	}
	ret = nilfs_get_root_dentry(s, root, root_dentry);
	nilfs_put_root(root);
 out:
	return ret;
}

/**
/**
 * nilfs_fill_super() - initialize a super block instance
 * nilfs_fill_super() - initialize a super block instance
 * @sb: super_block
 * @sb: super_block
@@ -800,7 +834,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
	struct nilfs_sb_info *sbi;
	struct nilfs_sb_info *sbi;
	struct nilfs_root *fsroot;
	struct nilfs_root *fsroot;
	__u64 cno;
	__u64 cno;
	int err, curr_mnt;
	int err;


	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
	if (!sbi)
	if (!sbi)
@@ -841,35 +875,17 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
	if (err)
	if (err)
		goto failed_sbi;
		goto failed_sbi;


	cno = nilfs_last_cno(nilfs);
	curr_mnt = true;

	if (sb->s_flags & MS_RDONLY) {
	if (nilfs_test_opt(sbi, SNAPSHOT)) {
	if (nilfs_test_opt(sbi, SNAPSHOT)) {
			down_read(&nilfs->ns_segctor_sem);
		err = nilfs_attach_snapshot(sb, sbi->s_snapshot_cno,
			err = nilfs_cpfile_is_snapshot(nilfs->ns_cpfile,
					    &sb->s_root);
						       sbi->s_snapshot_cno);
		if (err)
			up_read(&nilfs->ns_segctor_sem);
			if (err < 0) {
				if (err == -ENOENT)
					err = -EINVAL;
				goto failed_sbi;
			}
			if (!err) {
				printk(KERN_ERR
				       "NILFS: The specified checkpoint is "
				       "not a snapshot "
				       "(checkpoint number=%llu).\n",
				       (unsigned long long)sbi->s_snapshot_cno);
				err = -EINVAL;
			goto failed_sbi;
			goto failed_sbi;
			}

			cno = sbi->s_snapshot_cno;
		goto add_to_supers;
			curr_mnt = false;
		}
	}
	}


	err = nilfs_attach_checkpoint(sbi, cno, curr_mnt, &fsroot);
	cno = nilfs_last_cno(nilfs);
	err = nilfs_attach_checkpoint(sbi, cno, true, &fsroot);
	if (err) {
	if (err) {
		printk(KERN_ERR "NILFS: error loading a checkpoint"
		printk(KERN_ERR "NILFS: error loading a checkpoint"
		       " (checkpoint number=%llu).\n", (unsigned long long)cno);
		       " (checkpoint number=%llu).\n", (unsigned long long)cno);
@@ -894,6 +910,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
		up_write(&nilfs->ns_sem);
		up_write(&nilfs->ns_sem);
	}
	}


 add_to_supers:
	down_write(&nilfs->ns_super_sem);
	down_write(&nilfs->ns_super_sem);
	list_add(&sbi->s_list, &nilfs->ns_supers);
	list_add(&sbi->s_list, &nilfs->ns_supers);
	if (!nilfs_test_opt(sbi, SNAPSHOT))
	if (!nilfs_test_opt(sbi, SNAPSHOT))