xref: /linux/fs/nfs/nfs4getroot.c (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2a38a9eacSBryan Schumaker /*
3a38a9eacSBryan Schumaker * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
4a38a9eacSBryan Schumaker * Written by David Howells (dhowells@redhat.com)
5a38a9eacSBryan Schumaker */
6a38a9eacSBryan Schumaker 
7a38a9eacSBryan Schumaker #include <linux/nfs_fs.h>
8a38a9eacSBryan Schumaker #include "nfs4_fs.h"
9d6aa6a81STrond Myklebust #include "internal.h"
10a38a9eacSBryan Schumaker 
11a38a9eacSBryan Schumaker #define NFSDBG_FACILITY		NFSDBG_CLIENT
12a38a9eacSBryan Schumaker 
nfs4_get_rootfh(struct nfs_server * server,struct nfs_fh * mntfh,bool auth_probe)135e6b1990STrond Myklebust int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool auth_probe)
14a38a9eacSBryan Schumaker {
15a38a9eacSBryan Schumaker 	struct nfs_fsinfo fsinfo;
16a38a9eacSBryan Schumaker 	int ret = -ENOMEM;
17a38a9eacSBryan Schumaker 
18a38a9eacSBryan Schumaker 	fsinfo.fattr = nfs_alloc_fattr();
19a38a9eacSBryan Schumaker 	if (fsinfo.fattr == NULL)
20a38a9eacSBryan Schumaker 		goto out;
21a38a9eacSBryan Schumaker 
22a38a9eacSBryan Schumaker 	/* Start by getting the root filehandle from the server */
235e6b1990STrond Myklebust 	ret = nfs4_proc_get_rootfh(server, mntfh, &fsinfo, auth_probe);
24a38a9eacSBryan Schumaker 	if (ret < 0) {
25a38a9eacSBryan Schumaker 		dprintk("nfs4_get_rootfh: getroot error = %d\n", -ret);
26a38a9eacSBryan Schumaker 		goto out;
27a38a9eacSBryan Schumaker 	}
28a38a9eacSBryan Schumaker 
29a38a9eacSBryan Schumaker 	if (!(fsinfo.fattr->valid & NFS_ATTR_FATTR_TYPE)
30a38a9eacSBryan Schumaker 			|| !S_ISDIR(fsinfo.fattr->mode)) {
31a38a9eacSBryan Schumaker 		printk(KERN_ERR "nfs4_get_rootfh:"
32a38a9eacSBryan Schumaker 		       " getroot encountered non-directory\n");
33a38a9eacSBryan Schumaker 		ret = -ENOTDIR;
34a38a9eacSBryan Schumaker 		goto out;
35a38a9eacSBryan Schumaker 	}
36a38a9eacSBryan Schumaker 
37a38a9eacSBryan Schumaker 	memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server->fsid));
38a38a9eacSBryan Schumaker out:
39a38a9eacSBryan Schumaker 	nfs_free_fattr(fsinfo.fattr);
40a38a9eacSBryan Schumaker 	return ret;
41a38a9eacSBryan Schumaker }
42