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

Commit 36d43a43 authored by David Howells's avatar David Howells Committed by Al Viro
Browse files

NFS: Use d_automount() rather than abusing follow_link()



Make NFS use the new d_automount() dentry operation rather than abusing
follow_link() on directories.

Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Acked-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
Acked-by: default avatarIan Kent <raven@themaw.net>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent d18610b0
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -970,7 +970,7 @@ int nfs_lookup_verify_inode(struct inode *inode, struct nameidata *nd)
{
{
	struct nfs_server *server = NFS_SERVER(inode);
	struct nfs_server *server = NFS_SERVER(inode);


	if (test_bit(NFS_INO_MOUNTPOINT, &NFS_I(inode)->flags))
	if (IS_AUTOMOUNT(inode))
		return 0;
		return 0;
	if (nd != NULL) {
	if (nd != NULL) {
		/* VFS wants an on-the-wire revalidation */
		/* VFS wants an on-the-wire revalidation */
@@ -1173,6 +1173,7 @@ const struct dentry_operations nfs_dentry_operations = {
	.d_revalidate	= nfs_lookup_revalidate,
	.d_revalidate	= nfs_lookup_revalidate,
	.d_delete	= nfs_dentry_delete,
	.d_delete	= nfs_dentry_delete,
	.d_iput		= nfs_dentry_iput,
	.d_iput		= nfs_dentry_iput,
	.d_automount	= nfs_d_automount,
};
};


static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
@@ -1246,6 +1247,7 @@ const struct dentry_operations nfs4_dentry_operations = {
	.d_revalidate	= nfs_open_revalidate,
	.d_revalidate	= nfs_open_revalidate,
	.d_delete	= nfs_dentry_delete,
	.d_delete	= nfs_dentry_delete,
	.d_iput		= nfs_dentry_iput,
	.d_iput		= nfs_dentry_iput,
	.d_automount	= nfs_d_automount,
};
};


/*
/*
+2 −2
Original line number Original line Diff line number Diff line
@@ -300,7 +300,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
				else
				else
					inode->i_op = &nfs_mountpoint_inode_operations;
					inode->i_op = &nfs_mountpoint_inode_operations;
				inode->i_fop = NULL;
				inode->i_fop = NULL;
				set_bit(NFS_INO_MOUNTPOINT, &nfsi->flags);
				inode->i_flags |= S_AUTOMOUNT;
			}
			}
		} else if (S_ISLNK(inode->i_mode))
		} else if (S_ISLNK(inode->i_mode))
			inode->i_op = &nfs_symlink_inode_operations;
			inode->i_op = &nfs_symlink_inode_operations;
@@ -1208,7 +1208,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
	/* Update the fsid? */
	/* Update the fsid? */
	if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) &&
	if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) &&
			!nfs_fsid_equal(&server->fsid, &fattr->fsid) &&
			!nfs_fsid_equal(&server->fsid, &fattr->fsid) &&
			!test_bit(NFS_INO_MOUNTPOINT, &nfsi->flags))
			!IS_AUTOMOUNT(inode))
		server->fsid = fattr->fsid;
		server->fsid = fattr->fsid;


	/*
	/*
+1 −0
Original line number Original line Diff line number Diff line
@@ -252,6 +252,7 @@ extern char *nfs_path(const char *base,
		      const struct dentry *droot,
		      const struct dentry *droot,
		      const struct dentry *dentry,
		      const struct dentry *dentry,
		      char *buffer, ssize_t buflen);
		      char *buffer, ssize_t buflen);
extern struct vfsmount *nfs_d_automount(struct path *path);


/* getroot.c */
/* getroot.c */
extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
+40 −44
Original line number Original line Diff line number Diff line
@@ -97,9 +97,8 @@ char *nfs_path(const char *base,
}
}


/*
/*
 * nfs_follow_mountpoint - handle crossing a mountpoint on the server
 * nfs_d_automount - Handle crossing a mountpoint on the server
 * @dentry - dentry of mountpoint
 * @path - The mountpoint
 * @nd - nameidata info
 *
 *
 * When we encounter a mountpoint on the server, we want to set up
 * When we encounter a mountpoint on the server, we want to set up
 * a mountpoint on the client too, to prevent inode numbers from
 * a mountpoint on the client too, to prevent inode numbers from
@@ -109,84 +108,81 @@ char *nfs_path(const char *base,
 * situation, and that different filesystems may want to use
 * situation, and that different filesystems may want to use
 * different security flavours.
 * different security flavours.
 */
 */
static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
struct vfsmount *nfs_d_automount(struct path *path)
{
{
	struct vfsmount *mnt;
	struct vfsmount *mnt;
	struct nfs_server *server = NFS_SERVER(dentry->d_inode);
	struct nfs_server *server = NFS_SERVER(path->dentry->d_inode);
	struct dentry *parent;
	struct dentry *parent;
	struct nfs_fh *fh = NULL;
	struct nfs_fh *fh = NULL;
	struct nfs_fattr *fattr = NULL;
	struct nfs_fattr *fattr = NULL;
	int err;
	int err;


	dprintk("--> nfs_follow_mountpoint()\n");
	dprintk("--> nfs_d_automount()\n");


	err = -ESTALE;
	mnt = ERR_PTR(-ESTALE);
	if (IS_ROOT(dentry))
	if (IS_ROOT(path->dentry))
		goto out_err;
		goto out_nofree;


	err = -ENOMEM;
	mnt = ERR_PTR(-ENOMEM);
	fh = nfs_alloc_fhandle();
	fh = nfs_alloc_fhandle();
	fattr = nfs_alloc_fattr();
	fattr = nfs_alloc_fattr();
	if (fh == NULL || fattr == NULL)
	if (fh == NULL || fattr == NULL)
		goto out_err;
		goto out;


	dprintk("%s: enter\n", __func__);
	dprintk("%s: enter\n", __func__);
	dput(nd->path.dentry);
	nd->path.dentry = dget(dentry);


	/* Look it up again */
	/* Look it up again to get its attributes */
	parent = dget_parent(nd->path.dentry);
	parent = dget_parent(path->dentry);
	err = server->nfs_client->rpc_ops->lookup(parent->d_inode,
	err = server->nfs_client->rpc_ops->lookup(parent->d_inode,
						  &nd->path.dentry->d_name,
						  &path->dentry->d_name,
						  fh, fattr);
						  fh, fattr);
	dput(parent);
	dput(parent);
	if (err != 0)
	if (err != 0) {
		goto out_err;
		mnt = ERR_PTR(err);
		goto out;
	}


	if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
	if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
		mnt = nfs_do_refmount(nd->path.mnt, nd->path.dentry);
		mnt = nfs_do_refmount(path->mnt, path->dentry);
	else
	else
		mnt = nfs_do_submount(nd->path.mnt, nd->path.dentry, fh,
		mnt = nfs_do_submount(path->mnt, path->dentry, fh, fattr);
				      fattr);
	err = PTR_ERR(mnt);
	if (IS_ERR(mnt))
	if (IS_ERR(mnt))
		goto out_err;
		goto out;


	mntget(mnt);
	mntget(mnt);
	err = do_add_mount(mnt, &nd->path, nd->path.mnt->mnt_flags|MNT_SHRINKABLE,
	err = do_add_mount(mnt, path, path->mnt->mnt_flags | MNT_SHRINKABLE,
			   &nfs_automount_list);
			   &nfs_automount_list);
	if (err < 0) {
	switch (err) {
	case 0:
		dprintk("%s: done, success\n", __func__);
		schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
		break;
	case -EBUSY:
		/* someone else made a mount here whilst we were busy */
		mntput(mnt);
		dprintk("%s: done, collision\n", __func__);
		mnt = NULL;
		break;
	default:
		mntput(mnt);
		mntput(mnt);
		if (err == -EBUSY)
		dprintk("%s: done, error %d\n", __func__, err);
			goto out_follow;
		mnt = ERR_PTR(err);
		goto out_err;
		break;
	}
	}
	path_put(&nd->path);

	nd->path.mnt = mnt;
	nd->path.dentry = dget(mnt->mnt_root);
	schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
out:
out:
	nfs_free_fattr(fattr);
	nfs_free_fattr(fattr);
	nfs_free_fhandle(fh);
	nfs_free_fhandle(fh);
	dprintk("%s: done, returned %d\n", __func__, err);
out_nofree:

	dprintk("<-- nfs_follow_mountpoint() = %p\n", mnt);
	dprintk("<-- nfs_follow_mountpoint() = %d\n", err);
	return mnt;
	return ERR_PTR(err);
out_err:
	path_put(&nd->path);
	goto out;
out_follow:
	err = follow_down(&nd->path, false);
	goto out;
}
}


const struct inode_operations nfs_mountpoint_inode_operations = {
const struct inode_operations nfs_mountpoint_inode_operations = {
	.follow_link	= nfs_follow_mountpoint,
	.getattr	= nfs_getattr,
	.getattr	= nfs_getattr,
};
};


const struct inode_operations nfs_referral_inode_operations = {
const struct inode_operations nfs_referral_inode_operations = {
	.follow_link	= nfs_follow_mountpoint,
};
};


static void nfs_expire_automounts(struct work_struct *work)
static void nfs_expire_automounts(struct work_struct *work)
+0 −1
Original line number Original line Diff line number Diff line
@@ -215,7 +215,6 @@ struct nfs_inode {
#define NFS_INO_ADVISE_RDPLUS	(0)		/* advise readdirplus */
#define NFS_INO_ADVISE_RDPLUS	(0)		/* advise readdirplus */
#define NFS_INO_STALE		(1)		/* possible stale inode */
#define NFS_INO_STALE		(1)		/* possible stale inode */
#define NFS_INO_ACL_LRU_SET	(2)		/* Inode is on the LRU list */
#define NFS_INO_ACL_LRU_SET	(2)		/* Inode is on the LRU list */
#define NFS_INO_MOUNTPOINT	(3)		/* inode is remote mountpoint */
#define NFS_INO_FLUSHING	(4)		/* inode is flushing out data */
#define NFS_INO_FLUSHING	(4)		/* inode is flushing out data */
#define NFS_INO_FSCACHE		(5)		/* inode can be cached by FS-Cache */
#define NFS_INO_FSCACHE		(5)		/* inode can be cached by FS-Cache */
#define NFS_INO_FSCACHE_LOCK	(6)		/* FS-Cache cookie management lock */
#define NFS_INO_FSCACHE_LOCK	(6)		/* FS-Cache cookie management lock */