From b1942c5f8cf3bea3a3c88a7498ae4c4361f31afe Mon Sep 17 00:00:00 2001 From: Al Viro Date: Wed, 16 Mar 2011 05:44:14 -0400 Subject: 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 --- fs/nfs/getroot.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'fs/nfs/getroot.c') diff --git a/fs/nfs/getroot.c b/fs/nfs/getroot.c index 4d6e5a3..1084792 100644 --- a/fs/nfs/getroot.c +++ b/fs/nfs/getroot.c @@ -82,12 +82,18 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh, struct nfs_fsinfo fsinfo; struct dentry *ret; struct inode *inode; + void *name = kstrdup(devname, GFP_KERNEL); int error; + if (!name) + return ERR_PTR(-ENOMEM); + /* get the actual root for this mount */ fsinfo.fattr = nfs_alloc_fattr(); - if (fsinfo.fattr == NULL) + if (fsinfo.fattr == NULL) { + kfree(name); return ERR_PTR(-ENOMEM); + } error = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo); 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); + 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: + if (name) + kfree(name); nfs_free_fattr(fsinfo.fattr); 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 dentry *ret; struct inode *inode; + void *name = kstrdup(devname, GFP_KERNEL); int error; dprintk("--> nfs4_get_root()\n"); + if (!name) + return ERR_PTR(-ENOMEM); + /* get the info about the server and filesystem */ error = nfs4_server_capabilities(server, mntfh); if (error < 0) { dprintk("nfs_get_root: getcaps error = %d\n", -error); + kfree(name); return ERR_PTR(error); } fattr = nfs_alloc_fattr(); - if (fattr == NULL) - return ERR_PTR(-ENOMEM);; + if (fattr == NULL) { + kfree(name); + return ERR_PTR(-ENOMEM); + } /* get the actual root for this mount */ 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); - + 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: + if (name) + kfree(name); nfs_free_fattr(fattr); dprintk("<-- nfs4_get_root()\n"); return ret; -- cgit v1.1