提交 01c64fea 编写于 作者: D David Howells 提交者: Al Viro

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

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

[NOTE: THIS IS UNTESTED!]
Signed-off-by: NDavid Howells <dhowells@redhat.com>
Cc: Steve French <sfrench@samba.org>
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
上级 36d43a43
...@@ -255,32 +255,6 @@ static struct vfsmount *cifs_dfs_do_refmount(struct cifs_sb_info *cifs_sb, ...@@ -255,32 +255,6 @@ static struct vfsmount *cifs_dfs_do_refmount(struct cifs_sb_info *cifs_sb,
} }
static int add_mount_helper(struct vfsmount *newmnt, struct nameidata *nd,
struct list_head *mntlist)
{
/* stolen from afs code */
int err;
mntget(newmnt);
err = do_add_mount(newmnt, &nd->path, nd->path.mnt->mnt_flags | MNT_SHRINKABLE, mntlist);
switch (err) {
case 0:
path_put(&nd->path);
nd->path.mnt = newmnt;
nd->path.dentry = dget(newmnt->mnt_root);
schedule_delayed_work(&cifs_dfs_automount_task,
cifs_dfs_mountpoint_expiry_timeout);
break;
case -EBUSY:
/* someone else made a mount here whilst we were busy */
err = follow_down(&nd->path, false);
default:
mntput(newmnt);
break;
}
return err;
}
static void dump_referral(const struct dfs_info3_param *ref) static void dump_referral(const struct dfs_info3_param *ref)
{ {
cFYI(1, "DFS: ref path: %s", ref->path_name); cFYI(1, "DFS: ref path: %s", ref->path_name);
...@@ -290,45 +264,43 @@ static void dump_referral(const struct dfs_info3_param *ref) ...@@ -290,45 +264,43 @@ static void dump_referral(const struct dfs_info3_param *ref)
ref->path_consumed); ref->path_consumed);
} }
/*
static void* * Create a vfsmount that we can automount
cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd) */
static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)
{ {
struct dfs_info3_param *referrals = NULL; struct dfs_info3_param *referrals = NULL;
unsigned int num_referrals = 0; unsigned int num_referrals = 0;
struct cifs_sb_info *cifs_sb; struct cifs_sb_info *cifs_sb;
struct cifsSesInfo *ses; struct cifsSesInfo *ses;
char *full_path = NULL; char *full_path;
int xid, i; int xid, i;
int rc = 0; int rc;
struct vfsmount *mnt = ERR_PTR(-ENOENT); struct vfsmount *mnt;
struct tcon_link *tlink; struct tcon_link *tlink;
cFYI(1, "in %s", __func__); cFYI(1, "in %s", __func__);
BUG_ON(IS_ROOT(dentry)); BUG_ON(IS_ROOT(mntpt));
xid = GetXid(); xid = GetXid();
dput(nd->path.dentry);
nd->path.dentry = dget(dentry);
/* /*
* The MSDFS spec states that paths in DFS referral requests and * The MSDFS spec states that paths in DFS referral requests and
* responses must be prefixed by a single '\' character instead of * responses must be prefixed by a single '\' character instead of
* the double backslashes usually used in the UNC. This function * the double backslashes usually used in the UNC. This function
* gives us the latter, so we must adjust the result. * gives us the latter, so we must adjust the result.
*/ */
full_path = build_path_from_dentry(dentry); mnt = ERR_PTR(-ENOMEM);
if (full_path == NULL) { full_path = build_path_from_dentry(mntpt);
rc = -ENOMEM; if (full_path == NULL)
goto out_err; goto free_xid;
}
cifs_sb = CIFS_SB(dentry->d_inode->i_sb); cifs_sb = CIFS_SB(mntpt->d_inode->i_sb);
tlink = cifs_sb_tlink(cifs_sb); tlink = cifs_sb_tlink(cifs_sb);
mnt = ERR_PTR(-EINVAL);
if (IS_ERR(tlink)) { if (IS_ERR(tlink)) {
rc = PTR_ERR(tlink); mnt = ERR_CAST(tlink);
goto out_err; goto free_full_path;
} }
ses = tlink_tcon(tlink)->ses; ses = tlink_tcon(tlink)->ses;
...@@ -338,46 +310,77 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd) ...@@ -338,46 +310,77 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
cifs_put_tlink(tlink); cifs_put_tlink(tlink);
mnt = ERR_PTR(-ENOENT);
for (i = 0; i < num_referrals; i++) { for (i = 0; i < num_referrals; i++) {
int len; int len;
dump_referral(referrals+i); dump_referral(referrals + i);
/* connect to a node */ /* connect to a node */
len = strlen(referrals[i].node_name); len = strlen(referrals[i].node_name);
if (len < 2) { if (len < 2) {
cERROR(1, "%s: Net Address path too short: %s", cERROR(1, "%s: Net Address path too short: %s",
__func__, referrals[i].node_name); __func__, referrals[i].node_name);
rc = -EINVAL; mnt = ERR_PTR(-EINVAL);
goto out_err; break;
} }
mnt = cifs_dfs_do_refmount(cifs_sb, mnt = cifs_dfs_do_refmount(cifs_sb,
full_path, referrals + i); full_path, referrals + i);
cFYI(1, "%s: cifs_dfs_do_refmount:%s , mnt:%p", __func__, cFYI(1, "%s: cifs_dfs_do_refmount:%s , mnt:%p", __func__,
referrals[i].node_name, mnt); referrals[i].node_name, mnt);
/* complete mount procedure if we accured submount */
if (!IS_ERR(mnt)) if (!IS_ERR(mnt))
break; goto success;
} }
/* we need it cause for() above could exit without valid submount */ /* no valid submounts were found; return error from get_dfs_path() by
rc = PTR_ERR(mnt); * preference */
if (IS_ERR(mnt)) if (rc != 0)
goto out_err; mnt = ERR_PTR(rc);
rc = add_mount_helper(mnt, nd, &cifs_dfs_automount_list);
out: success:
FreeXid(xid);
free_dfs_info_array(referrals, num_referrals); free_dfs_info_array(referrals, num_referrals);
free_full_path:
kfree(full_path); kfree(full_path);
free_xid:
FreeXid(xid);
cFYI(1, "leaving %s" , __func__); cFYI(1, "leaving %s" , __func__);
return ERR_PTR(rc); return mnt;
out_err: }
path_put(&nd->path);
goto out; /*
* Attempt to automount the referral
*/
struct vfsmount *cifs_dfs_d_automount(struct path *path)
{
struct vfsmount *newmnt;
int err;
cFYI(1, "in %s", __func__);
newmnt = cifs_dfs_do_automount(path->dentry);
if (IS_ERR(newmnt)) {
cFYI(1, "leaving %s [automount failed]" , __func__);
return newmnt;
}
mntget(newmnt);
err = do_add_mount(newmnt, path, path->mnt->mnt_flags | MNT_SHRINKABLE,
&cifs_dfs_automount_list);
switch (err) {
case 0:
schedule_delayed_work(&cifs_dfs_automount_task,
cifs_dfs_mountpoint_expiry_timeout);
cFYI(1, "leaving %s [ok]" , __func__);
return newmnt;
case -EBUSY:
/* someone else made a mount here whilst we were busy */
mntput(newmnt);
cFYI(1, "leaving %s [EBUSY]" , __func__);
return NULL;
default:
mntput(newmnt);
cFYI(1, "leaving %s [error %d]" , __func__, err);
return ERR_PTR(err);
}
} }
const struct inode_operations cifs_dfs_referral_inode_operations = { const struct inode_operations cifs_dfs_referral_inode_operations = {
.follow_link = cifs_dfs_follow_mountpoint,
}; };
...@@ -93,6 +93,12 @@ extern int cifs_readdir(struct file *file, void *direntry, filldir_t filldir); ...@@ -93,6 +93,12 @@ extern int cifs_readdir(struct file *file, void *direntry, filldir_t filldir);
extern const struct dentry_operations cifs_dentry_ops; extern const struct dentry_operations cifs_dentry_ops;
extern const struct dentry_operations cifs_ci_dentry_ops; extern const struct dentry_operations cifs_ci_dentry_ops;
#ifdef CONFIG_CIFS_DFS_UPCALL
extern struct vfsmount *cifs_dfs_d_automount(struct path *path);
#else
#define cifs_dfs_d_automount NULL
#endif
/* Functions related to symlinks */ /* Functions related to symlinks */
extern void *cifs_follow_link(struct dentry *direntry, struct nameidata *nd); extern void *cifs_follow_link(struct dentry *direntry, struct nameidata *nd);
extern void cifs_put_link(struct dentry *direntry, extern void cifs_put_link(struct dentry *direntry,
......
...@@ -675,6 +675,7 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd) ...@@ -675,6 +675,7 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
const struct dentry_operations cifs_dentry_ops = { const struct dentry_operations cifs_dentry_ops = {
.d_revalidate = cifs_d_revalidate, .d_revalidate = cifs_d_revalidate,
.d_automount = cifs_dfs_d_automount,
/* d_delete: cifs_d_delete, */ /* not needed except for debugging */ /* d_delete: cifs_d_delete, */ /* not needed except for debugging */
}; };
...@@ -711,4 +712,5 @@ const struct dentry_operations cifs_ci_dentry_ops = { ...@@ -711,4 +712,5 @@ const struct dentry_operations cifs_ci_dentry_ops = {
.d_revalidate = cifs_d_revalidate, .d_revalidate = cifs_d_revalidate,
.d_hash = cifs_ci_hash, .d_hash = cifs_ci_hash,
.d_compare = cifs_ci_compare, .d_compare = cifs_ci_compare,
.d_automount = cifs_dfs_d_automount,
}; };
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "fscache.h" #include "fscache.h"
static void cifs_set_ops(struct inode *inode, const bool is_dfs_referral) static void cifs_set_ops(struct inode *inode)
{ {
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
...@@ -60,7 +60,7 @@ static void cifs_set_ops(struct inode *inode, const bool is_dfs_referral) ...@@ -60,7 +60,7 @@ static void cifs_set_ops(struct inode *inode, const bool is_dfs_referral)
break; break;
case S_IFDIR: case S_IFDIR:
#ifdef CONFIG_CIFS_DFS_UPCALL #ifdef CONFIG_CIFS_DFS_UPCALL
if (is_dfs_referral) { if (IS_AUTOMOUNT(inode)) {
inode->i_op = &cifs_dfs_referral_inode_operations; inode->i_op = &cifs_dfs_referral_inode_operations;
} else { } else {
#else /* NO DFS support, treat as a directory */ #else /* NO DFS support, treat as a directory */
...@@ -167,7 +167,9 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr) ...@@ -167,7 +167,9 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
} }
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
cifs_set_ops(inode, fattr->cf_flags & CIFS_FATTR_DFS_REFERRAL); if (fattr->cf_flags & CIFS_FATTR_DFS_REFERRAL)
inode->i_flags |= S_AUTOMOUNT;
cifs_set_ops(inode);
} }
void void
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册