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