1a38a9eacSBryan Schumaker /* 2a38a9eacSBryan Schumaker * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. 3a38a9eacSBryan Schumaker * Written by David Howells (dhowells@redhat.com) 4a38a9eacSBryan Schumaker */ 5a38a9eacSBryan Schumaker 6a38a9eacSBryan Schumaker #include <linux/nfs_fs.h> 7a38a9eacSBryan Schumaker #include "nfs4_fs.h" 8d6aa6a81STrond Myklebust #include "internal.h" 9a38a9eacSBryan Schumaker 10a38a9eacSBryan Schumaker #define NFSDBG_FACILITY NFSDBG_CLIENT 11a38a9eacSBryan Schumaker 125e6b1990STrond Myklebust int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool auth_probe) 13a38a9eacSBryan Schumaker { 14a38a9eacSBryan Schumaker struct nfs_fsinfo fsinfo; 15a38a9eacSBryan Schumaker int ret = -ENOMEM; 16a38a9eacSBryan Schumaker 17a38a9eacSBryan Schumaker dprintk("--> nfs4_get_rootfh()\n"); 18a38a9eacSBryan Schumaker 19a38a9eacSBryan Schumaker fsinfo.fattr = nfs_alloc_fattr(); 20a38a9eacSBryan Schumaker if (fsinfo.fattr == NULL) 21a38a9eacSBryan Schumaker goto out; 22a38a9eacSBryan Schumaker 23a38a9eacSBryan Schumaker /* Start by getting the root filehandle from the server */ 245e6b1990STrond Myklebust ret = nfs4_proc_get_rootfh(server, mntfh, &fsinfo, auth_probe); 25a38a9eacSBryan Schumaker if (ret < 0) { 26a38a9eacSBryan Schumaker dprintk("nfs4_get_rootfh: getroot error = %d\n", -ret); 27a38a9eacSBryan Schumaker goto out; 28a38a9eacSBryan Schumaker } 29a38a9eacSBryan Schumaker 30a38a9eacSBryan Schumaker if (!(fsinfo.fattr->valid & NFS_ATTR_FATTR_TYPE) 31a38a9eacSBryan Schumaker || !S_ISDIR(fsinfo.fattr->mode)) { 32a38a9eacSBryan Schumaker printk(KERN_ERR "nfs4_get_rootfh:" 33a38a9eacSBryan Schumaker " getroot encountered non-directory\n"); 34a38a9eacSBryan Schumaker ret = -ENOTDIR; 35a38a9eacSBryan Schumaker goto out; 36a38a9eacSBryan Schumaker } 37a38a9eacSBryan Schumaker 38a38a9eacSBryan Schumaker if (fsinfo.fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) { 39a38a9eacSBryan Schumaker printk(KERN_ERR "nfs4_get_rootfh:" 40a38a9eacSBryan Schumaker " getroot obtained referral\n"); 41a38a9eacSBryan Schumaker ret = -EREMOTE; 42a38a9eacSBryan Schumaker goto out; 43a38a9eacSBryan Schumaker } 44a38a9eacSBryan Schumaker 45a38a9eacSBryan Schumaker memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server->fsid)); 46a38a9eacSBryan Schumaker out: 47a38a9eacSBryan Schumaker nfs_free_fattr(fsinfo.fattr); 48a38a9eacSBryan Schumaker dprintk("<-- nfs4_get_rootfh() = %d\n", ret); 49a38a9eacSBryan Schumaker return ret; 50a38a9eacSBryan Schumaker } 51