/* * get an NFS4 root dentry from the root filehandle */ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh) { struct nfs_server *server = NFS_SB(sb); struct nfs_fattr fattr; struct dentry *mntroot; struct inode *inode; int error; dprintk("--> nfs4_get_root()\n"); /* 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); return ERR_PTR(error); } /* get the actual root for this mount */ error = server->nfs_client->rpc_ops->getattr(server, mntfh, &fattr); if (error < 0) { dprintk("nfs_get_root: getattr error = %d\n", -error); return ERR_PTR(error); } inode = nfs_fhget(sb, mntfh, &fattr); if (IS_ERR(inode)) { dprintk("nfs_get_root: get root inode failed\n"); return ERR_CAST(inode); } error = nfs_superblock_set_dummy_root(sb, inode); if (error != 0) return ERR_PTR(error); /* root dentries normally start off anonymous and get spliced in later * if the dentry tree reaches them; however if the dentry already * exists, we'll pick it up at this point and use it as the root */ mntroot = d_obtain_alias(inode); if (IS_ERR(mntroot)) { dprintk("nfs_get_root: get root dentry failed\n"); return mntroot; } security_d_instantiate(mntroot, inode); if (!mntroot->d_op) mntroot->d_op = server->nfs_client->rpc_ops->dentry_ops; dprintk("<-- nfs4_get_root()\n"); return mntroot; }
/* * get an NFS2/NFS3 root dentry from the root filehandle */ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh) { struct nfs_server *server = NFS_SB(sb); struct nfs_fsinfo fsinfo; struct dentry *ret; struct inode *inode; int error; /* get the actual root for this mount */ fsinfo.fattr = nfs_alloc_fattr(); if (fsinfo.fattr == NULL) return ERR_PTR(-ENOMEM); error = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo); if (error < 0) { dprintk("nfs_get_root: getattr error = %d\n", -error); ret = ERR_PTR(error); goto out; } inode = nfs_fhget(sb, mntfh, fsinfo.fattr); if (IS_ERR(inode)) { dprintk("nfs_get_root: get root inode failed\n"); ret = ERR_CAST(inode); goto out; } error = nfs_superblock_set_dummy_root(sb, inode); if (error != 0) { ret = ERR_PTR(error); goto out; } /* root dentries normally start off anonymous and get spliced in later * if the dentry tree reaches them; however if the dentry already * exists, we'll pick it up at this point and use it as the root */ ret = d_obtain_alias(inode); if (IS_ERR(ret)) { dprintk("nfs_get_root: get root dentry failed\n"); goto out; } security_d_instantiate(ret, inode); if (ret->d_op == NULL) ret->d_op = server->nfs_client->rpc_ops->dentry_ops; out: nfs_free_fattr(fsinfo.fattr); return ret; }
/* * get an NFS2/NFS3 root dentry from the root filehandle */ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh, const char *devname) { struct nfs_server *server = NFS_SB(sb); 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) { kfree(name); return ERR_PTR(-ENOMEM); } error = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo); if (error < 0) { dprintk("nfs_get_root: getattr error = %d\n", -error); ret = ERR_PTR(error); goto out; } inode = nfs_fhget(sb, mntfh, fsinfo.fattr); if (IS_ERR(inode)) { dprintk("nfs_get_root: get root inode failed\n"); ret = ERR_CAST(inode); goto out; } error = nfs_superblock_set_dummy_root(sb, inode); if (error != 0) { ret = ERR_PTR(error); goto out; } /* root dentries normally start off anonymous and get spliced in later * if the dentry tree reaches them; however if the dentry already * exists, we'll pick it up at this point and use it as the root */ ret = d_obtain_alias(inode); if (IS_ERR(ret)) { dprintk("nfs_get_root: get root dentry failed\n"); goto out; } 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; }