nfs: store devname at disconnected NFS roots

part 2: make sure that disconnected roots have corresponding mnt_devname
values stashed into them.

Have nfs*_get_root() stuff a copy of devname into ->d_fsdata of the
found root, provided that it is disconnected.

Have ->d_release() free it when dentry goes away.

Have the places where NFS uses ->d_fsdata for sillyrename (and that
can *never* happen to a disconnected root - dentry will be attached
to its parent) free old devname copies if they find those.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2011-03-16 05:44:14 -04:00
parent 0d5839ad05
commit b1942c5f8c
3 changed files with 65 additions and 4 deletions

View File

@ -1169,11 +1169,23 @@ static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode)
iput(inode); iput(inode);
} }
static void nfs_d_release(struct dentry *dentry)
{
/* free cached devname value, if it survived that far */
if (unlikely(dentry->d_fsdata)) {
if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
WARN_ON(1);
else
kfree(dentry->d_fsdata);
}
}
const struct dentry_operations nfs_dentry_operations = { 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, .d_automount = nfs_d_automount,
.d_release = nfs_d_release,
}; };
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)
@ -1248,6 +1260,7 @@ const struct dentry_operations nfs4_dentry_operations = {
.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, .d_automount = nfs_d_automount,
.d_release = nfs_d_release,
}; };
/* /*

View File

@ -82,12 +82,18 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh,
struct nfs_fsinfo fsinfo; struct nfs_fsinfo fsinfo;
struct dentry *ret; struct dentry *ret;
struct inode *inode; struct inode *inode;
void *name = kstrdup(devname, GFP_KERNEL);
int error; int error;
if (!name)
return ERR_PTR(-ENOMEM);
/* get the actual root for this mount */ /* get the actual root for this mount */
fsinfo.fattr = nfs_alloc_fattr(); fsinfo.fattr = nfs_alloc_fattr();
if (fsinfo.fattr == NULL) if (fsinfo.fattr == NULL) {
kfree(name);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
}
error = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo); error = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo);
if (error < 0) { if (error < 0) {
@ -120,7 +126,15 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh,
} }
security_d_instantiate(ret, inode); security_d_instantiate(ret, inode);
spin_lock(&ret->d_lock);
if (IS_ROOT(ret) && !(ret->d_flags & DCACHE_NFSFS_RENAMED)) {
ret->d_fsdata = name;
name = NULL;
}
spin_unlock(&ret->d_lock);
out: out:
if (name)
kfree(name);
nfs_free_fattr(fsinfo.fattr); nfs_free_fattr(fsinfo.fattr);
return ret; return ret;
} }
@ -177,21 +191,28 @@ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh,
struct nfs_fattr *fattr = NULL; struct nfs_fattr *fattr = NULL;
struct dentry *ret; struct dentry *ret;
struct inode *inode; struct inode *inode;
void *name = kstrdup(devname, GFP_KERNEL);
int error; int error;
dprintk("--> nfs4_get_root()\n"); dprintk("--> nfs4_get_root()\n");
if (!name)
return ERR_PTR(-ENOMEM);
/* get the info about the server and filesystem */ /* get the info about the server and filesystem */
error = nfs4_server_capabilities(server, mntfh); error = nfs4_server_capabilities(server, mntfh);
if (error < 0) { if (error < 0) {
dprintk("nfs_get_root: getcaps error = %d\n", dprintk("nfs_get_root: getcaps error = %d\n",
-error); -error);
kfree(name);
return ERR_PTR(error); return ERR_PTR(error);
} }
fattr = nfs_alloc_fattr(); fattr = nfs_alloc_fattr();
if (fattr == NULL) if (fattr == NULL) {
return ERR_PTR(-ENOMEM);; kfree(name);
return ERR_PTR(-ENOMEM);
}
/* get the actual root for this mount */ /* get the actual root for this mount */
error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr); error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr);
@ -225,8 +246,15 @@ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh,
} }
security_d_instantiate(ret, inode); security_d_instantiate(ret, inode);
spin_lock(&ret->d_lock);
if (IS_ROOT(ret) && !(ret->d_flags & DCACHE_NFSFS_RENAMED)) {
ret->d_fsdata = name;
name = NULL;
}
spin_unlock(&ret->d_lock);
out: out:
if (name)
kfree(name);
nfs_free_fattr(fattr); nfs_free_fattr(fattr);
dprintk("<-- nfs4_get_root()\n"); dprintk("<-- nfs4_get_root()\n");
return ret; return ret;

View File

@ -148,6 +148,7 @@ static int nfs_do_call_unlink(struct dentry *parent, struct inode *dir, struct n
alias = d_lookup(parent, &data->args.name); alias = d_lookup(parent, &data->args.name);
if (alias != NULL) { if (alias != NULL) {
int ret = 0; int ret = 0;
void *devname_garbage = NULL;
/* /*
* Hey, we raced with lookup... See if we need to transfer * Hey, we raced with lookup... See if we need to transfer
@ -157,6 +158,7 @@ static int nfs_do_call_unlink(struct dentry *parent, struct inode *dir, struct n
spin_lock(&alias->d_lock); spin_lock(&alias->d_lock);
if (alias->d_inode != NULL && if (alias->d_inode != NULL &&
!(alias->d_flags & DCACHE_NFSFS_RENAMED)) { !(alias->d_flags & DCACHE_NFSFS_RENAMED)) {
devname_garbage = alias->d_fsdata;
alias->d_fsdata = data; alias->d_fsdata = data;
alias->d_flags |= DCACHE_NFSFS_RENAMED; alias->d_flags |= DCACHE_NFSFS_RENAMED;
ret = 1; ret = 1;
@ -164,6 +166,13 @@ static int nfs_do_call_unlink(struct dentry *parent, struct inode *dir, struct n
spin_unlock(&alias->d_lock); spin_unlock(&alias->d_lock);
nfs_dec_sillycount(dir); nfs_dec_sillycount(dir);
dput(alias); dput(alias);
/*
* If we'd displaced old cached devname, free it. At that
* point dentry is definitely not a root, so we won't need
* that anymore.
*/
if (devname_garbage)
kfree(devname_garbage);
return ret; return ret;
} }
data->dir = igrab(dir); data->dir = igrab(dir);
@ -252,6 +261,7 @@ nfs_async_unlink(struct inode *dir, struct dentry *dentry)
{ {
struct nfs_unlinkdata *data; struct nfs_unlinkdata *data;
int status = -ENOMEM; int status = -ENOMEM;
void *devname_garbage = NULL;
data = kzalloc(sizeof(*data), GFP_KERNEL); data = kzalloc(sizeof(*data), GFP_KERNEL);
if (data == NULL) if (data == NULL)
@ -269,8 +279,16 @@ nfs_async_unlink(struct inode *dir, struct dentry *dentry)
if (dentry->d_flags & DCACHE_NFSFS_RENAMED) if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
goto out_unlock; goto out_unlock;
dentry->d_flags |= DCACHE_NFSFS_RENAMED; dentry->d_flags |= DCACHE_NFSFS_RENAMED;
devname_garbage = dentry->d_fsdata;
dentry->d_fsdata = data; dentry->d_fsdata = data;
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
/*
* If we'd displaced old cached devname, free it. At that
* point dentry is definitely not a root, so we won't need
* that anymore.
*/
if (devname_garbage)
kfree(devname_garbage);
return 0; return 0;
out_unlock: out_unlock:
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
@ -299,6 +317,7 @@ nfs_complete_unlink(struct dentry *dentry, struct inode *inode)
if (dentry->d_flags & DCACHE_NFSFS_RENAMED) { if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
dentry->d_flags &= ~DCACHE_NFSFS_RENAMED; dentry->d_flags &= ~DCACHE_NFSFS_RENAMED;
data = dentry->d_fsdata; data = dentry->d_fsdata;
dentry->d_fsdata = NULL;
} }
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
@ -315,6 +334,7 @@ nfs_cancel_async_unlink(struct dentry *dentry)
struct nfs_unlinkdata *data = dentry->d_fsdata; struct nfs_unlinkdata *data = dentry->d_fsdata;
dentry->d_flags &= ~DCACHE_NFSFS_RENAMED; dentry->d_flags &= ~DCACHE_NFSFS_RENAMED;
dentry->d_fsdata = NULL;
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
nfs_free_unlinkdata(data); nfs_free_unlinkdata(data);
return; return;