2019-05-19 20:08:55 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-07-17 04:39:17 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
|
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*/
|
2012-07-17 04:39:18 +08:00
|
|
|
#include <linux/module.h>
|
2012-07-17 04:39:17 +08:00
|
|
|
#include <linux/nfs_fs.h>
|
2012-07-17 04:39:18 +08:00
|
|
|
#include <linux/nfs_mount.h>
|
2013-02-05 01:50:00 +08:00
|
|
|
#include <linux/sunrpc/addr.h>
|
2012-07-17 04:39:17 +08:00
|
|
|
#include <linux/sunrpc/auth.h>
|
|
|
|
#include <linux/sunrpc/xprt.h>
|
|
|
|
#include <linux/sunrpc/bc_xprt.h>
|
2013-11-14 20:25:19 +08:00
|
|
|
#include <linux/sunrpc/rpc_pipe_fs.h>
|
2012-07-17 04:39:17 +08:00
|
|
|
#include "internal.h"
|
|
|
|
#include "callback.h"
|
2012-07-17 04:39:18 +08:00
|
|
|
#include "delegation.h"
|
2012-11-27 01:49:34 +08:00
|
|
|
#include "nfs4session.h"
|
2015-04-16 01:00:05 +08:00
|
|
|
#include "nfs4idmap.h"
|
2012-07-17 04:39:18 +08:00
|
|
|
#include "pnfs.h"
|
|
|
|
#include "netns.h"
|
2012-07-17 04:39:17 +08:00
|
|
|
|
|
|
|
#define NFSDBG_FACILITY NFSDBG_CLIENT
|
|
|
|
|
2012-07-17 04:39:21 +08:00
|
|
|
/*
|
|
|
|
* Get a unique NFSv4.0 callback identifier which will be used
|
|
|
|
* by the V4.0 callback service to lookup the nfs_client struct
|
|
|
|
*/
|
|
|
|
static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
|
|
|
|
|
|
|
|
if (clp->rpc_ops->version != 4 || minorversion != 0)
|
|
|
|
return ret;
|
2013-02-28 09:05:01 +08:00
|
|
|
idr_preload(GFP_KERNEL);
|
2012-07-17 04:39:21 +08:00
|
|
|
spin_lock(&nn->nfs_client_lock);
|
2015-11-20 22:56:20 +08:00
|
|
|
ret = idr_alloc(&nn->cb_ident_idr, clp, 1, 0, GFP_NOWAIT);
|
2013-02-28 09:05:01 +08:00
|
|
|
if (ret >= 0)
|
|
|
|
clp->cl_cb_ident = ret;
|
2012-07-17 04:39:21 +08:00
|
|
|
spin_unlock(&nn->nfs_client_lock);
|
2013-02-28 09:05:01 +08:00
|
|
|
idr_preload_end();
|
|
|
|
return ret < 0 ? ret : 0;
|
2012-07-17 04:39:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_NFS_V4_1
|
2019-02-19 02:32:38 +08:00
|
|
|
/*
|
2013-09-07 02:14:00 +08:00
|
|
|
* Per auth flavor data server rpc clients
|
|
|
|
*/
|
|
|
|
struct nfs4_ds_server {
|
|
|
|
struct list_head list; /* ds_clp->cl_ds_clients */
|
|
|
|
struct rpc_clnt *rpc_clnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2019-02-19 02:32:38 +08:00
|
|
|
* nfs4_find_ds_client - Common lookup case for DS I/O
|
|
|
|
* @ds_clp: pointer to the DS's nfs_client
|
|
|
|
* @flavor: rpc auth flavour to match
|
2013-09-07 02:14:00 +08:00
|
|
|
*/
|
|
|
|
static struct nfs4_ds_server *
|
|
|
|
nfs4_find_ds_client(struct nfs_client *ds_clp, rpc_authflavor_t flavor)
|
|
|
|
{
|
|
|
|
struct nfs4_ds_server *dss;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(dss, &ds_clp->cl_ds_clients, list) {
|
|
|
|
if (dss->rpc_clnt->cl_auth->au_flavor != flavor)
|
|
|
|
continue;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
dss = NULL;
|
|
|
|
out:
|
|
|
|
rcu_read_unlock();
|
|
|
|
return dss;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct nfs4_ds_server *
|
|
|
|
nfs4_add_ds_client(struct nfs_client *ds_clp, rpc_authflavor_t flavor,
|
|
|
|
struct nfs4_ds_server *new)
|
|
|
|
{
|
|
|
|
struct nfs4_ds_server *dss;
|
|
|
|
|
|
|
|
spin_lock(&ds_clp->cl_lock);
|
|
|
|
list_for_each_entry(dss, &ds_clp->cl_ds_clients, list) {
|
|
|
|
if (dss->rpc_clnt->cl_auth->au_flavor != flavor)
|
|
|
|
continue;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (new)
|
|
|
|
list_add_rcu(&new->list, &ds_clp->cl_ds_clients);
|
|
|
|
dss = new;
|
|
|
|
out:
|
|
|
|
spin_unlock(&ds_clp->cl_lock); /* need some lock to protect list */
|
|
|
|
return dss;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct nfs4_ds_server *
|
|
|
|
nfs4_alloc_ds_server(struct nfs_client *ds_clp, rpc_authflavor_t flavor)
|
|
|
|
{
|
|
|
|
struct nfs4_ds_server *dss;
|
|
|
|
|
|
|
|
dss = kmalloc(sizeof(*dss), GFP_NOFS);
|
|
|
|
if (dss == NULL)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
dss->rpc_clnt = rpc_clone_client_set_auth(ds_clp->cl_rpcclient, flavor);
|
|
|
|
if (IS_ERR(dss->rpc_clnt)) {
|
|
|
|
int err = PTR_ERR(dss->rpc_clnt);
|
|
|
|
kfree (dss);
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
INIT_LIST_HEAD(&dss->list);
|
|
|
|
|
|
|
|
return dss;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfs4_free_ds_server(struct nfs4_ds_server *dss)
|
|
|
|
{
|
|
|
|
rpc_release_client(dss->rpc_clnt);
|
|
|
|
kfree(dss);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-19 02:32:38 +08:00
|
|
|
* nfs4_find_or_create_ds_client - Find or create a DS rpc client
|
|
|
|
* @ds_clp: pointer to the DS's nfs_client
|
|
|
|
* @inode: pointer to the inode
|
|
|
|
*
|
|
|
|
* Find or create a DS rpc client with th MDS server rpc client auth flavor
|
|
|
|
* in the nfs_client cl_ds_clients list.
|
|
|
|
*/
|
2013-09-07 02:14:00 +08:00
|
|
|
struct rpc_clnt *
|
|
|
|
nfs4_find_or_create_ds_client(struct nfs_client *ds_clp, struct inode *inode)
|
|
|
|
{
|
|
|
|
struct nfs4_ds_server *dss, *new;
|
|
|
|
rpc_authflavor_t flavor = NFS_SERVER(inode)->client->cl_auth->au_flavor;
|
|
|
|
|
|
|
|
dss = nfs4_find_ds_client(ds_clp, flavor);
|
|
|
|
if (dss != NULL)
|
|
|
|
goto out;
|
|
|
|
new = nfs4_alloc_ds_server(ds_clp, flavor);
|
|
|
|
if (IS_ERR(new))
|
|
|
|
return ERR_CAST(new);
|
|
|
|
dss = nfs4_add_ds_client(ds_clp, flavor, new);
|
|
|
|
if (dss != new)
|
|
|
|
nfs4_free_ds_server(new);
|
|
|
|
out:
|
|
|
|
return dss->rpc_clnt;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs4_find_or_create_ds_client);
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfs4_shutdown_ds_clients(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
struct nfs4_ds_server *dss;
|
|
|
|
|
|
|
|
while (!list_empty(&clp->cl_ds_clients)) {
|
|
|
|
dss = list_entry(clp->cl_ds_clients.next,
|
|
|
|
struct nfs4_ds_server, list);
|
|
|
|
list_del(&dss->list);
|
|
|
|
rpc_shutdown_client(dss->rpc_clnt);
|
|
|
|
kfree (dss);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-10 03:13:32 +08:00
|
|
|
static void
|
|
|
|
nfs4_cleanup_callback(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
struct nfs4_copy_state *cp_state;
|
|
|
|
|
|
|
|
while (!list_empty(&clp->pending_cb_stateids)) {
|
|
|
|
cp_state = list_entry(clp->pending_cb_stateids.next,
|
|
|
|
struct nfs4_copy_state, copies);
|
|
|
|
list_del(&cp_state->copies);
|
|
|
|
kfree(cp_state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-10 00:49:11 +08:00
|
|
|
void nfs41_shutdown_client(struct nfs_client *clp)
|
2012-07-17 04:39:21 +08:00
|
|
|
{
|
|
|
|
if (nfs4_has_session(clp)) {
|
2018-07-10 03:13:32 +08:00
|
|
|
nfs4_cleanup_callback(clp);
|
2013-09-07 02:14:00 +08:00
|
|
|
nfs4_shutdown_ds_clients(clp);
|
2012-07-17 04:39:21 +08:00
|
|
|
nfs4_destroy_session(clp->cl_session);
|
|
|
|
nfs4_destroy_clientid(clp);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-08-10 00:49:11 +08:00
|
|
|
#endif /* CONFIG_NFS_V4_1 */
|
|
|
|
|
|
|
|
void nfs40_shutdown_client(struct nfs_client *clp)
|
2012-07-17 04:39:21 +08:00
|
|
|
{
|
2013-08-10 00:49:11 +08:00
|
|
|
if (clp->cl_slot_tbl) {
|
2014-02-02 02:47:06 +08:00
|
|
|
nfs4_shutdown_slot_table(clp->cl_slot_tbl);
|
2013-08-10 00:49:11 +08:00
|
|
|
kfree(clp->cl_slot_tbl);
|
|
|
|
}
|
2012-07-17 04:39:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct nfs_client *clp = nfs_alloc_client(cl_init);
|
|
|
|
if (IS_ERR(clp))
|
|
|
|
return clp;
|
|
|
|
|
|
|
|
err = nfs_get_cb_ident_idr(clp, cl_init->minorversion);
|
|
|
|
if (err)
|
|
|
|
goto error;
|
|
|
|
|
2013-05-23 00:50:38 +08:00
|
|
|
if (cl_init->minorversion > NFS4_MAX_MINOR_VERSION) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2012-07-17 04:39:21 +08:00
|
|
|
spin_lock_init(&clp->cl_lock);
|
|
|
|
INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state);
|
2013-09-07 02:14:00 +08:00
|
|
|
INIT_LIST_HEAD(&clp->cl_ds_clients);
|
2012-07-17 04:39:21 +08:00
|
|
|
rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client");
|
|
|
|
clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
|
|
|
|
clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion];
|
2013-10-18 02:13:02 +08:00
|
|
|
clp->cl_mig_gen = 1;
|
2016-09-18 06:17:39 +08:00
|
|
|
#if IS_ENABLED(CONFIG_NFS_V4_1)
|
|
|
|
init_waitqueue_head(&clp->cl_lock_waitq);
|
|
|
|
#endif
|
2018-07-10 03:13:32 +08:00
|
|
|
INIT_LIST_HEAD(&clp->pending_cb_stateids);
|
2012-07-17 04:39:21 +08:00
|
|
|
return clp;
|
|
|
|
|
|
|
|
error:
|
2012-08-21 00:12:29 +08:00
|
|
|
nfs_free_client(clp);
|
2012-07-17 04:39:21 +08:00
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy the NFS4 callback service
|
|
|
|
*/
|
|
|
|
static void nfs4_destroy_callback(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
|
2012-08-20 22:00:16 +08:00
|
|
|
nfs_callback_down(clp->cl_mvops->minor_version, clp->cl_net);
|
2012-07-17 04:39:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void nfs4_shutdown_client(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state))
|
|
|
|
nfs4_kill_renewd(clp);
|
2013-08-10 00:49:11 +08:00
|
|
|
clp->cl_mvops->shutdown_client(clp);
|
2012-07-17 04:39:21 +08:00
|
|
|
nfs4_destroy_callback(clp);
|
|
|
|
if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state))
|
|
|
|
nfs_idmap_delete(clp);
|
|
|
|
|
|
|
|
rpc_destroy_wait_queue(&clp->cl_rpcwaitq);
|
|
|
|
kfree(clp->cl_serverowner);
|
|
|
|
kfree(clp->cl_serverscope);
|
|
|
|
kfree(clp->cl_implid);
|
2015-01-04 04:16:04 +08:00
|
|
|
kfree(clp->cl_owner_id);
|
2012-07-17 04:39:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void nfs4_free_client(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
nfs4_shutdown_client(clp);
|
|
|
|
nfs_free_client(clp);
|
|
|
|
}
|
|
|
|
|
2012-07-17 04:39:17 +08:00
|
|
|
/*
|
|
|
|
* Initialize the NFS4 callback service
|
|
|
|
*/
|
|
|
|
static int nfs4_init_callback(struct nfs_client *clp)
|
|
|
|
{
|
2014-11-09 09:15:26 +08:00
|
|
|
struct rpc_xprt *xprt;
|
2012-07-17 04:39:17 +08:00
|
|
|
int error;
|
|
|
|
|
2014-11-09 09:15:26 +08:00
|
|
|
xprt = rcu_dereference_raw(clp->cl_rpcclient->cl_xprt);
|
2012-07-17 04:39:17 +08:00
|
|
|
|
2014-11-09 09:15:26 +08:00
|
|
|
if (nfs4_has_session(clp)) {
|
|
|
|
error = xprt_setup_backchannel(xprt, NFS41_BC_MIN_CALLBACKS);
|
|
|
|
if (error < 0)
|
2012-07-17 04:39:17 +08:00
|
|
|
return error;
|
|
|
|
}
|
2014-11-09 09:15:26 +08:00
|
|
|
|
|
|
|
error = nfs_callback_up(clp->cl_mvops->minor_version, xprt);
|
|
|
|
if (error < 0) {
|
|
|
|
dprintk("%s: failed to start callback. Error = %d\n",
|
|
|
|
__func__, error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
__set_bit(NFS_CS_CALLBACK, &clp->cl_res_state);
|
|
|
|
|
2012-07-17 04:39:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-10 00:49:11 +08:00
|
|
|
/**
|
|
|
|
* nfs40_init_client - nfs_client initialization tasks for NFSv4.0
|
2019-02-19 02:32:38 +08:00
|
|
|
* @clp: nfs_client to initialize
|
2013-08-10 00:49:11 +08:00
|
|
|
*
|
|
|
|
* Returns zero on success, or a negative errno if some error occurred.
|
|
|
|
*/
|
|
|
|
int nfs40_init_client(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
struct nfs4_slot_table *tbl;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
tbl = kzalloc(sizeof(*tbl), GFP_NOFS);
|
|
|
|
if (tbl == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = nfs4_setup_slot_table(tbl, NFS4_MAX_SLOT_TABLE,
|
|
|
|
"NFSv4.0 transport Slot table");
|
|
|
|
if (ret) {
|
|
|
|
kfree(tbl);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
clp->cl_slot_tbl = tbl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_NFS_V4_1)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs41_init_client - nfs_client initialization tasks for NFSv4.1+
|
2019-02-19 02:32:38 +08:00
|
|
|
* @clp: nfs_client to initialize
|
2013-08-10 00:49:11 +08:00
|
|
|
*
|
|
|
|
* Returns zero on success, or a negative errno if some error occurred.
|
|
|
|
*/
|
|
|
|
int nfs41_init_client(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
struct nfs4_session *session = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the session and mark it expired.
|
|
|
|
* When a SEQUENCE operation encounters the expired session
|
|
|
|
* it will do session recovery to initialize it.
|
|
|
|
*/
|
|
|
|
session = nfs4_alloc_session(clp);
|
|
|
|
if (!session)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
clp->cl_session = session;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The create session reply races with the server back
|
|
|
|
* channel probe. Mark the client NFS_CS_SESSION_INITING
|
|
|
|
* so that the client back channel can find the
|
|
|
|
* nfs_client struct
|
|
|
|
*/
|
|
|
|
nfs_mark_client_ready(clp, NFS_CS_SESSION_INITING);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NFS_V4_1 */
|
|
|
|
|
2012-07-17 04:39:17 +08:00
|
|
|
/*
|
|
|
|
* Initialize the minor version specific parts of an NFS4 client record
|
|
|
|
*/
|
|
|
|
static int nfs4_init_client_minor_version(struct nfs_client *clp)
|
|
|
|
{
|
2013-08-10 00:49:11 +08:00
|
|
|
int ret;
|
2012-07-17 04:39:17 +08:00
|
|
|
|
2013-08-10 00:49:11 +08:00
|
|
|
ret = clp->cl_mvops->init_client(clp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2012-07-17 04:39:17 +08:00
|
|
|
return nfs4_init_callback(clp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs4_init_client - Initialise an NFS4 client record
|
|
|
|
*
|
|
|
|
* @clp: nfs_client to initialise
|
2019-02-19 02:32:38 +08:00
|
|
|
* @cl_init: pointer to nfs_client_initdata
|
2012-07-17 04:39:17 +08:00
|
|
|
*
|
|
|
|
* Returns pointer to an NFS client, or an ERR_PTR value.
|
|
|
|
*/
|
|
|
|
struct nfs_client *nfs4_init_client(struct nfs_client *clp,
|
2016-06-23 02:13:12 +08:00
|
|
|
const struct nfs_client_initdata *cl_init)
|
2012-07-17 04:39:17 +08:00
|
|
|
{
|
|
|
|
char buf[INET6_ADDRSTRLEN + 1];
|
2016-06-23 02:13:12 +08:00
|
|
|
const char *ip_addr = cl_init->ip_addr;
|
2012-09-15 05:24:32 +08:00
|
|
|
struct nfs_client *old;
|
2012-07-17 04:39:17 +08:00
|
|
|
int error;
|
|
|
|
|
2017-04-08 02:15:18 +08:00
|
|
|
if (clp->cl_cons_state == NFS_CS_READY)
|
2012-07-17 04:39:17 +08:00
|
|
|
/* the client is initialised already */
|
|
|
|
return clp;
|
|
|
|
|
|
|
|
/* Check NFS protocol revision and initialize RPC op vector */
|
|
|
|
clp->rpc_ops = &nfs_v4_clientops;
|
|
|
|
|
2013-04-14 23:49:51 +08:00
|
|
|
if (clp->cl_minorversion != 0)
|
|
|
|
__set_bit(NFS_CS_INFINITE_SLOTS, &clp->cl_flags);
|
2012-07-17 04:39:17 +08:00
|
|
|
__set_bit(NFS_CS_DISCRTRY, &clp->cl_flags);
|
2013-09-25 00:06:07 +08:00
|
|
|
__set_bit(NFS_CS_NO_RETRANS_TIMEOUT, &clp->cl_flags);
|
2013-11-14 20:25:19 +08:00
|
|
|
|
2016-06-23 02:13:12 +08:00
|
|
|
error = nfs_create_rpc_client(clp, cl_init, RPC_AUTH_GSS_KRB5I);
|
2013-04-05 04:14:11 +08:00
|
|
|
if (error == -EINVAL)
|
2016-06-23 02:13:12 +08:00
|
|
|
error = nfs_create_rpc_client(clp, cl_init, RPC_AUTH_UNIX);
|
2012-07-17 04:39:17 +08:00
|
|
|
if (error < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* If no clientaddr= option was specified, find a usable cb address */
|
|
|
|
if (ip_addr == NULL) {
|
|
|
|
struct sockaddr_storage cb_addr;
|
|
|
|
struct sockaddr *sap = (struct sockaddr *)&cb_addr;
|
|
|
|
|
|
|
|
error = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr));
|
|
|
|
if (error < 0)
|
|
|
|
goto error;
|
|
|
|
error = rpc_ntop(sap, buf, sizeof(buf));
|
|
|
|
if (error < 0)
|
|
|
|
goto error;
|
|
|
|
ip_addr = (const char *)buf;
|
|
|
|
}
|
|
|
|
strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
|
|
|
|
|
|
|
|
error = nfs_idmap_new(clp);
|
|
|
|
if (error < 0) {
|
|
|
|
dprintk("%s: failed to create idmapper. Error = %d\n",
|
|
|
|
__func__, error);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
__set_bit(NFS_CS_IDMAP, &clp->cl_res_state);
|
|
|
|
|
|
|
|
error = nfs4_init_client_minor_version(clp);
|
|
|
|
if (error < 0)
|
|
|
|
goto error;
|
|
|
|
|
2012-09-15 05:24:32 +08:00
|
|
|
error = nfs4_discover_server_trunking(clp, &old);
|
|
|
|
if (error < 0)
|
|
|
|
goto error;
|
|
|
|
|
2017-12-06 02:55:44 +08:00
|
|
|
if (clp != old) {
|
2014-01-20 11:45:36 +08:00
|
|
|
clp->cl_preserve_clid = true;
|
2017-12-06 02:55:44 +08:00
|
|
|
/*
|
|
|
|
* Mark the client as having failed initialization so other
|
|
|
|
* processes walking the nfs_client_list in nfs_match_client()
|
|
|
|
* won't try to use it.
|
|
|
|
*/
|
|
|
|
nfs_mark_client_ready(clp, -EPERM);
|
|
|
|
}
|
2014-01-20 11:45:36 +08:00
|
|
|
nfs_put_client(clp);
|
2017-06-08 23:52:44 +08:00
|
|
|
clear_bit(NFS_CS_TSM_POSSIBLE, &clp->cl_flags);
|
2014-01-20 11:45:36 +08:00
|
|
|
return old;
|
2012-07-17 04:39:17 +08:00
|
|
|
|
|
|
|
error:
|
|
|
|
nfs_mark_client_ready(clp, error);
|
|
|
|
nfs_put_client(clp);
|
|
|
|
return ERR_PTR(error);
|
|
|
|
}
|
2012-07-17 04:39:18 +08:00
|
|
|
|
2012-09-15 05:24:32 +08:00
|
|
|
/*
|
|
|
|
* SETCLIENTID just did a callback update with the callback ident in
|
|
|
|
* "drop," but server trunking discovery claims "drop" and "keep" are
|
|
|
|
* actually the same server. Swap the callback IDs so that "keep"
|
|
|
|
* will continue to use the callback ident the server now knows about,
|
|
|
|
* and so that "keep"'s original callback ident is destroyed when
|
|
|
|
* "drop" is freed.
|
|
|
|
*/
|
|
|
|
static void nfs4_swap_callback_idents(struct nfs_client *keep,
|
|
|
|
struct nfs_client *drop)
|
|
|
|
{
|
|
|
|
struct nfs_net *nn = net_generic(keep->cl_net, nfs_net_id);
|
|
|
|
unsigned int save = keep->cl_cb_ident;
|
|
|
|
|
|
|
|
if (keep->cl_cb_ident == drop->cl_cb_ident)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dprintk("%s: keeping callback ident %u and dropping ident %u\n",
|
|
|
|
__func__, keep->cl_cb_ident, drop->cl_cb_ident);
|
|
|
|
|
|
|
|
spin_lock(&nn->nfs_client_lock);
|
|
|
|
|
|
|
|
idr_replace(&nn->cb_ident_idr, keep, drop->cl_cb_ident);
|
|
|
|
keep->cl_cb_ident = drop->cl_cb_ident;
|
|
|
|
|
|
|
|
idr_replace(&nn->cb_ident_idr, drop, save);
|
|
|
|
drop->cl_cb_ident = save;
|
|
|
|
|
|
|
|
spin_unlock(&nn->nfs_client_lock);
|
|
|
|
}
|
|
|
|
|
2015-01-04 04:35:27 +08:00
|
|
|
static bool nfs4_match_client_owner_id(const struct nfs_client *clp1,
|
|
|
|
const struct nfs_client *clp2)
|
|
|
|
{
|
|
|
|
if (clp1->cl_owner_id == NULL || clp2->cl_owner_id == NULL)
|
|
|
|
return true;
|
|
|
|
return strcmp(clp1->cl_owner_id, clp2->cl_owner_id) == 0;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:02:52 +08:00
|
|
|
static bool nfs4_same_verifier(nfs4_verifier *v1, nfs4_verifier *v2)
|
|
|
|
{
|
|
|
|
return memcmp(v1->data, v2->data, sizeof(v1->data)) == 0;
|
|
|
|
}
|
|
|
|
|
2017-04-08 02:15:13 +08:00
|
|
|
static int nfs4_match_client(struct nfs_client *pos, struct nfs_client *new,
|
|
|
|
struct nfs_client **prev, struct nfs_net *nn)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (pos->rpc_ops != new->rpc_ops)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (pos->cl_minorversion != new->cl_minorversion)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* If "pos" isn't marked ready, we can't trust the
|
|
|
|
* remaining fields in "pos", especially the client
|
|
|
|
* ID and serverowner fields. Wait for CREATE_SESSION
|
|
|
|
* to finish. */
|
|
|
|
if (pos->cl_cons_state > NFS_CS_READY) {
|
2017-10-20 17:53:38 +08:00
|
|
|
refcount_inc(&pos->cl_count);
|
2017-04-08 02:15:13 +08:00
|
|
|
spin_unlock(&nn->nfs_client_lock);
|
|
|
|
|
|
|
|
nfs_put_client(*prev);
|
|
|
|
*prev = pos;
|
|
|
|
|
|
|
|
status = nfs_wait_client_init_complete(pos);
|
|
|
|
spin_lock(&nn->nfs_client_lock);
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos->cl_cons_state != NFS_CS_READY)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (pos->cl_clientid != new->cl_clientid)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* NFSv4.1 always uses the uniform string, however someone
|
|
|
|
* might switch the uniquifier string on us.
|
|
|
|
*/
|
|
|
|
if (!nfs4_match_client_owner_id(pos, new))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-15 05:24:32 +08:00
|
|
|
/**
|
|
|
|
* nfs40_walk_client_list - Find server that recognizes a client ID
|
|
|
|
*
|
|
|
|
* @new: nfs_client with client ID to test
|
|
|
|
* @result: OUT: found nfs_client, or new
|
|
|
|
* @cred: credential to use for trunking test
|
|
|
|
*
|
|
|
|
* Returns zero, a negative errno, or a negative NFS4ERR status.
|
|
|
|
* If zero is returned, an nfs_client pointer is planted in "result."
|
|
|
|
*
|
|
|
|
* NB: nfs40_walk_client_list() relies on the new nfs_client being
|
|
|
|
* the last nfs_client on the list.
|
|
|
|
*/
|
|
|
|
int nfs40_walk_client_list(struct nfs_client *new,
|
|
|
|
struct nfs_client **result,
|
2018-12-03 08:30:31 +08:00
|
|
|
const struct cred *cred)
|
2012-09-15 05:24:32 +08:00
|
|
|
{
|
|
|
|
struct nfs_net *nn = net_generic(new->cl_net, nfs_net_id);
|
2013-04-06 04:11:11 +08:00
|
|
|
struct nfs_client *pos, *prev = NULL;
|
2012-09-15 05:24:32 +08:00
|
|
|
struct nfs4_setclientid_res clid = {
|
|
|
|
.clientid = new->cl_clientid,
|
|
|
|
.confirm = new->cl_confirm,
|
|
|
|
};
|
2013-01-19 11:41:53 +08:00
|
|
|
int status = -NFS4ERR_STALE_CLIENTID;
|
2012-09-15 05:24:32 +08:00
|
|
|
|
|
|
|
spin_lock(&nn->nfs_client_lock);
|
2013-04-06 04:11:11 +08:00
|
|
|
list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) {
|
2014-09-18 21:13:17 +08:00
|
|
|
|
2017-12-06 02:55:44 +08:00
|
|
|
if (pos == new)
|
|
|
|
goto found;
|
|
|
|
|
2017-04-08 02:15:13 +08:00
|
|
|
status = nfs4_match_client(pos, new, &prev, nn);
|
|
|
|
if (status < 0)
|
|
|
|
goto out_unlock;
|
|
|
|
if (status != 0)
|
2015-01-04 04:35:27 +08:00
|
|
|
continue;
|
2016-11-28 22:02:52 +08:00
|
|
|
/*
|
|
|
|
* We just sent a new SETCLIENTID, which should have
|
|
|
|
* caused the server to return a new cl_confirm. So if
|
|
|
|
* cl_confirm is the same, then this is a different
|
|
|
|
* server that just returned the same cl_confirm by
|
|
|
|
* coincidence:
|
|
|
|
*/
|
|
|
|
if ((new != pos) && nfs4_same_verifier(&pos->cl_confirm,
|
|
|
|
&new->cl_confirm))
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* But if the cl_confirm's are different, then the only
|
|
|
|
* way that a SETCLIENTID_CONFIRM to pos can succeed is
|
|
|
|
* if new and pos point to the same server:
|
|
|
|
*/
|
2017-12-06 02:55:44 +08:00
|
|
|
found:
|
2017-10-20 17:53:38 +08:00
|
|
|
refcount_inc(&pos->cl_count);
|
2012-09-15 05:24:32 +08:00
|
|
|
spin_unlock(&nn->nfs_client_lock);
|
|
|
|
|
2014-11-18 20:23:43 +08:00
|
|
|
nfs_put_client(prev);
|
2013-01-19 11:41:53 +08:00
|
|
|
prev = pos;
|
2012-09-15 05:24:32 +08:00
|
|
|
|
|
|
|
status = nfs4_proc_setclientid_confirm(pos, &clid, cred);
|
2013-01-19 11:41:53 +08:00
|
|
|
switch (status) {
|
|
|
|
case -NFS4ERR_STALE_CLIENTID:
|
|
|
|
break;
|
|
|
|
case 0:
|
2012-09-15 05:24:32 +08:00
|
|
|
nfs4_swap_callback_idents(pos, new);
|
2016-11-28 22:02:52 +08:00
|
|
|
pos->cl_confirm = new->cl_confirm;
|
2017-12-06 02:55:44 +08:00
|
|
|
nfs_mark_client_ready(pos, NFS_CS_READY);
|
2012-09-15 05:24:32 +08:00
|
|
|
|
2013-01-19 11:41:53 +08:00
|
|
|
prev = NULL;
|
2012-09-15 05:24:32 +08:00
|
|
|
*result = pos;
|
2014-03-19 02:11:24 +08:00
|
|
|
goto out;
|
|
|
|
case -ERESTARTSYS:
|
|
|
|
case -ETIMEDOUT:
|
|
|
|
/* The callback path may have been inadvertently
|
|
|
|
* changed. Schedule recovery!
|
|
|
|
*/
|
|
|
|
nfs4_schedule_path_down_recovery(pos);
|
2013-01-19 11:41:53 +08:00
|
|
|
default:
|
|
|
|
goto out;
|
2012-09-15 05:24:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock(&nn->nfs_client_lock);
|
|
|
|
}
|
2017-04-08 02:15:13 +08:00
|
|
|
out_unlock:
|
2013-01-19 11:41:53 +08:00
|
|
|
spin_unlock(&nn->nfs_client_lock);
|
2012-09-15 05:24:32 +08:00
|
|
|
|
2013-01-19 11:56:23 +08:00
|
|
|
/* No match found. The server lost our clientid */
|
2013-01-19 11:41:53 +08:00
|
|
|
out:
|
2014-11-18 20:23:43 +08:00
|
|
|
nfs_put_client(prev);
|
2013-01-19 11:41:53 +08:00
|
|
|
return status;
|
2012-09-15 05:24:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_NFS_V4_1
|
|
|
|
/*
|
2015-01-03 05:25:08 +08:00
|
|
|
* Returns true if the server major ids match
|
2012-09-15 05:24:32 +08:00
|
|
|
*/
|
2019-06-05 04:14:30 +08:00
|
|
|
bool
|
2016-09-09 21:22:20 +08:00
|
|
|
nfs4_check_serverowner_major_id(struct nfs41_server_owner *o1,
|
|
|
|
struct nfs41_server_owner *o2)
|
2012-09-15 05:24:32 +08:00
|
|
|
{
|
|
|
|
if (o1->major_id_sz != o2->major_id_sz)
|
2017-04-08 02:15:14 +08:00
|
|
|
return false;
|
|
|
|
return memcmp(o1->major_id, o2->major_id, o1->major_id_sz) == 0;
|
2012-09-15 05:24:32 +08:00
|
|
|
}
|
|
|
|
|
2016-09-09 21:22:21 +08:00
|
|
|
/*
|
|
|
|
* Returns true if the server scopes match
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
nfs4_check_server_scope(struct nfs41_server_scope *s1,
|
|
|
|
struct nfs41_server_scope *s2)
|
|
|
|
{
|
|
|
|
if (s1->server_scope_sz != s2->server_scope_sz)
|
2017-04-08 02:15:15 +08:00
|
|
|
return false;
|
|
|
|
return memcmp(s1->server_scope, s2->server_scope,
|
|
|
|
s1->server_scope_sz) == 0;
|
2016-09-09 21:22:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-09 21:22:28 +08:00
|
|
|
* nfs4_detect_session_trunking - Checks for session trunking.
|
2016-09-09 21:22:21 +08:00
|
|
|
* @clp: original mount nfs_client
|
|
|
|
* @res: result structure from an exchange_id using the original mount
|
|
|
|
* nfs_client with a new multi_addr transport
|
2019-02-19 02:32:38 +08:00
|
|
|
* @xprt: pointer to the transport to add.
|
|
|
|
*
|
|
|
|
* Called after a successful EXCHANGE_ID on a multi-addr connection.
|
|
|
|
* Upon success, add the transport.
|
2016-09-09 21:22:21 +08:00
|
|
|
*
|
|
|
|
* Returns zero on success, otherwise -EINVAL
|
|
|
|
*
|
|
|
|
* Note: since the exchange_id for the new multi_addr transport uses the
|
|
|
|
* same nfs_client from the original mount, the cl_owner_id is reused,
|
|
|
|
* so eir_clientowner is the same.
|
|
|
|
*/
|
|
|
|
int nfs4_detect_session_trunking(struct nfs_client *clp,
|
|
|
|
struct nfs41_exchange_id_res *res,
|
|
|
|
struct rpc_xprt *xprt)
|
|
|
|
{
|
|
|
|
/* Check eir_clientid */
|
2017-04-08 02:15:11 +08:00
|
|
|
if (clp->cl_clientid != res->clientid)
|
2016-09-09 21:22:21 +08:00
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
/* Check eir_server_owner so_major_id */
|
|
|
|
if (!nfs4_check_serverowner_major_id(clp->cl_serverowner,
|
|
|
|
res->server_owner))
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
/* Check eir_server_owner so_minor_id */
|
2017-04-08 02:15:12 +08:00
|
|
|
if (clp->cl_serverowner->minor_id != res->server_owner->minor_id)
|
2016-09-09 21:22:21 +08:00
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
/* Check eir_server_scope */
|
|
|
|
if (!nfs4_check_server_scope(clp->cl_serverscope, res->server_scope))
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
pr_info("NFS: %s: Session trunking succeeded for %s\n",
|
|
|
|
clp->cl_hostname,
|
|
|
|
xprt->address_strings[RPC_DISPLAY_ADDR]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out_err:
|
|
|
|
pr_info("NFS: %s: Session trunking failed for %s\n", clp->cl_hostname,
|
|
|
|
xprt->address_strings[RPC_DISPLAY_ADDR]);
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-09-15 05:24:32 +08:00
|
|
|
/**
|
|
|
|
* nfs41_walk_client_list - Find nfs_client that matches a client/server owner
|
|
|
|
*
|
|
|
|
* @new: nfs_client with client ID to test
|
|
|
|
* @result: OUT: found nfs_client, or new
|
|
|
|
* @cred: credential to use for trunking test
|
|
|
|
*
|
|
|
|
* Returns zero, a negative errno, or a negative NFS4ERR status.
|
|
|
|
* If zero is returned, an nfs_client pointer is planted in "result."
|
|
|
|
*
|
|
|
|
* NB: nfs41_walk_client_list() relies on the new nfs_client being
|
|
|
|
* the last nfs_client on the list.
|
|
|
|
*/
|
|
|
|
int nfs41_walk_client_list(struct nfs_client *new,
|
|
|
|
struct nfs_client **result,
|
2018-12-03 08:30:31 +08:00
|
|
|
const struct cred *cred)
|
2012-09-15 05:24:32 +08:00
|
|
|
{
|
|
|
|
struct nfs_net *nn = net_generic(new->cl_net, nfs_net_id);
|
2013-04-06 04:11:11 +08:00
|
|
|
struct nfs_client *pos, *prev = NULL;
|
2013-01-19 11:56:23 +08:00
|
|
|
int status = -NFS4ERR_STALE_CLIENTID;
|
2012-09-15 05:24:32 +08:00
|
|
|
|
|
|
|
spin_lock(&nn->nfs_client_lock);
|
2013-04-06 04:11:11 +08:00
|
|
|
list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) {
|
2014-09-18 21:13:17 +08:00
|
|
|
|
2015-03-04 09:28:59 +08:00
|
|
|
if (pos == new)
|
|
|
|
goto found;
|
|
|
|
|
2017-04-08 02:15:13 +08:00
|
|
|
status = nfs4_match_client(pos, new, &prev, nn);
|
|
|
|
if (status < 0)
|
|
|
|
goto out;
|
|
|
|
if (status != 0)
|
2012-09-15 05:24:32 +08:00
|
|
|
continue;
|
|
|
|
|
2015-01-03 05:25:08 +08:00
|
|
|
/*
|
|
|
|
* Note that session trunking is just a special subcase of
|
|
|
|
* client id trunking. In either case, we want to fall back
|
|
|
|
* to using the existing nfs_client.
|
|
|
|
*/
|
2016-09-09 21:22:20 +08:00
|
|
|
if (!nfs4_check_serverowner_major_id(pos->cl_serverowner,
|
|
|
|
new->cl_serverowner))
|
2012-09-15 05:24:32 +08:00
|
|
|
continue;
|
|
|
|
|
2015-03-04 09:28:59 +08:00
|
|
|
found:
|
2017-10-20 17:53:38 +08:00
|
|
|
refcount_inc(&pos->cl_count);
|
2013-04-06 04:11:11 +08:00
|
|
|
*result = pos;
|
2013-04-11 00:44:18 +08:00
|
|
|
status = 0;
|
2013-04-06 04:11:11 +08:00
|
|
|
break;
|
2012-09-15 05:24:32 +08:00
|
|
|
}
|
|
|
|
|
2017-04-08 02:15:13 +08:00
|
|
|
out:
|
2012-09-15 05:24:32 +08:00
|
|
|
spin_unlock(&nn->nfs_client_lock);
|
2014-11-18 20:23:43 +08:00
|
|
|
nfs_put_client(prev);
|
2013-01-19 11:56:23 +08:00
|
|
|
return status;
|
2012-09-15 05:24:32 +08:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_NFS_V4_1 */
|
|
|
|
|
2012-07-17 04:39:18 +08:00
|
|
|
static void nfs4_destroy_server(struct nfs_server *server)
|
|
|
|
{
|
2019-08-03 22:11:27 +08:00
|
|
|
LIST_HEAD(freeme);
|
|
|
|
|
2012-07-17 04:39:18 +08:00
|
|
|
nfs_server_return_all_delegations(server);
|
|
|
|
unset_pnfs_layoutdriver(server);
|
2019-08-03 22:11:27 +08:00
|
|
|
nfs4_purge_state_owners(server, &freeme);
|
|
|
|
nfs4_free_state_owners(&freeme);
|
2012-07-17 04:39:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NFSv4.0 callback thread helper
|
|
|
|
*
|
|
|
|
* Find a client by callback identifier
|
|
|
|
*/
|
|
|
|
struct nfs_client *
|
|
|
|
nfs4_find_client_ident(struct net *net, int cb_ident)
|
|
|
|
{
|
|
|
|
struct nfs_client *clp;
|
|
|
|
struct nfs_net *nn = net_generic(net, nfs_net_id);
|
|
|
|
|
|
|
|
spin_lock(&nn->nfs_client_lock);
|
|
|
|
clp = idr_find(&nn->cb_ident_idr, cb_ident);
|
|
|
|
if (clp)
|
2017-10-20 17:53:38 +08:00
|
|
|
refcount_inc(&clp->cl_count);
|
2012-07-17 04:39:18 +08:00
|
|
|
spin_unlock(&nn->nfs_client_lock);
|
|
|
|
return clp;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_NFS_V4_1)
|
|
|
|
/* Common match routine for v4.0 and v4.1 callback services */
|
|
|
|
static bool nfs4_cb_match_client(const struct sockaddr *addr,
|
|
|
|
struct nfs_client *clp, u32 minorversion)
|
|
|
|
{
|
|
|
|
struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
|
|
|
|
|
|
|
|
/* Don't match clients that failed to initialise */
|
|
|
|
if (!(clp->cl_cons_state == NFS_CS_READY ||
|
|
|
|
clp->cl_cons_state == NFS_CS_SESSION_INITING))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
smp_rmb();
|
|
|
|
|
|
|
|
/* Match the version and minorversion */
|
|
|
|
if (clp->rpc_ops->version != 4 ||
|
|
|
|
clp->cl_minorversion != minorversion)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Match only the IP address, not the port number */
|
2015-07-14 02:01:28 +08:00
|
|
|
return rpc_cmp_addr(addr, clap);
|
2012-07-17 04:39:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NFSv4.1 callback thread helper
|
|
|
|
* For CB_COMPOUND calls, find a client by IP address, protocol version,
|
|
|
|
* minorversion, and sessionID
|
|
|
|
*
|
|
|
|
* Returns NULL if no such client
|
|
|
|
*/
|
|
|
|
struct nfs_client *
|
|
|
|
nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr,
|
2013-06-05 23:15:01 +08:00
|
|
|
struct nfs4_sessionid *sid, u32 minorversion)
|
2012-07-17 04:39:18 +08:00
|
|
|
{
|
|
|
|
struct nfs_client *clp;
|
|
|
|
struct nfs_net *nn = net_generic(net, nfs_net_id);
|
|
|
|
|
|
|
|
spin_lock(&nn->nfs_client_lock);
|
|
|
|
list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
|
2017-10-07 22:02:21 +08:00
|
|
|
if (!nfs4_cb_match_client(addr, clp, minorversion))
|
2012-07-17 04:39:18 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!nfs4_has_session(clp))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Match sessionid*/
|
|
|
|
if (memcmp(clp->cl_session->sess_id.data,
|
|
|
|
sid->data, NFS4_MAX_SESSIONID_LEN) != 0)
|
|
|
|
continue;
|
|
|
|
|
2017-10-20 17:53:38 +08:00
|
|
|
refcount_inc(&clp->cl_count);
|
2012-07-17 04:39:18 +08:00
|
|
|
spin_unlock(&nn->nfs_client_lock);
|
|
|
|
return clp;
|
|
|
|
}
|
|
|
|
spin_unlock(&nn->nfs_client_lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_NFS_V4_1 */
|
|
|
|
|
|
|
|
struct nfs_client *
|
|
|
|
nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr,
|
2013-06-05 23:15:01 +08:00
|
|
|
struct nfs4_sessionid *sid, u32 minorversion)
|
2012-07-17 04:39:18 +08:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NFS_V4_1 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up an NFS4 client
|
|
|
|
*/
|
|
|
|
static int nfs4_set_client(struct nfs_server *server,
|
|
|
|
const char *hostname,
|
|
|
|
const struct sockaddr *addr,
|
|
|
|
const size_t addrlen,
|
|
|
|
const char *ip_addr,
|
|
|
|
int proto, const struct rpc_timeout *timeparms,
|
2017-04-27 23:13:40 +08:00
|
|
|
u32 minorversion, unsigned int nconnect,
|
|
|
|
struct net *net)
|
2012-07-17 04:39:18 +08:00
|
|
|
{
|
|
|
|
struct nfs_client_initdata cl_init = {
|
|
|
|
.hostname = hostname,
|
|
|
|
.addr = addr,
|
|
|
|
.addrlen = addrlen,
|
2016-06-23 02:13:12 +08:00
|
|
|
.ip_addr = ip_addr,
|
2012-07-31 04:05:16 +08:00
|
|
|
.nfs_mod = &nfs_v4,
|
2012-07-17 04:39:18 +08:00
|
|
|
.proto = proto,
|
|
|
|
.minorversion = minorversion,
|
|
|
|
.net = net,
|
2016-06-23 02:13:12 +08:00
|
|
|
.timeparms = timeparms,
|
2019-04-25 05:46:43 +08:00
|
|
|
.cred = server->cred,
|
2012-07-17 04:39:18 +08:00
|
|
|
};
|
|
|
|
struct nfs_client *clp;
|
|
|
|
|
2019-10-17 23:13:54 +08:00
|
|
|
if (minorversion == 0)
|
|
|
|
__set_bit(NFS_CS_REUSEPORT, &cl_init.init_flags);
|
2020-06-23 22:35:28 +08:00
|
|
|
if (proto == XPRT_TRANSPORT_TCP)
|
2017-04-27 23:13:40 +08:00
|
|
|
cl_init.nconnect = nconnect;
|
2019-10-17 23:13:54 +08:00
|
|
|
|
2012-07-17 04:39:18 +08:00
|
|
|
if (server->flags & NFS_MOUNT_NORESVPORT)
|
2019-10-17 21:37:44 +08:00
|
|
|
__set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags);
|
2013-06-26 00:23:27 +08:00
|
|
|
if (server->options & NFS_OPTION_MIGRATION)
|
2019-10-17 21:37:44 +08:00
|
|
|
__set_bit(NFS_CS_MIGRATION, &cl_init.init_flags);
|
2017-06-08 23:52:44 +08:00
|
|
|
if (test_bit(NFS_MIG_TSM_POSSIBLE, &server->mig_status))
|
2019-10-17 21:37:44 +08:00
|
|
|
__set_bit(NFS_CS_TSM_POSSIBLE, &cl_init.init_flags);
|
2017-12-05 03:13:46 +08:00
|
|
|
server->port = rpc_get_port(addr);
|
2012-07-17 04:39:18 +08:00
|
|
|
|
|
|
|
/* Allocate or find a client reference we can use */
|
2016-11-18 04:15:55 +08:00
|
|
|
clp = nfs_get_client(&cl_init);
|
2017-04-08 02:15:16 +08:00
|
|
|
if (IS_ERR(clp))
|
|
|
|
return PTR_ERR(clp);
|
2012-07-17 04:39:18 +08:00
|
|
|
|
2018-02-22 02:46:43 +08:00
|
|
|
if (server->nfs_client == clp) {
|
|
|
|
nfs_put_client(clp);
|
2017-04-08 02:15:16 +08:00
|
|
|
return -ELOOP;
|
2018-02-22 02:46:43 +08:00
|
|
|
}
|
2016-08-30 21:20:32 +08:00
|
|
|
|
2012-07-17 04:39:18 +08:00
|
|
|
/*
|
|
|
|
* Query for the lease time on clientid setup or renewal
|
|
|
|
*
|
|
|
|
* Note that this will be set on nfs_clients that were created
|
|
|
|
* only for the DS role and did not set this bit, but now will
|
|
|
|
* serve a dual role.
|
|
|
|
*/
|
|
|
|
set_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state);
|
|
|
|
|
|
|
|
server->nfs_client = clp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a pNFS Data Server client.
|
|
|
|
*
|
|
|
|
* Return any existing nfs_client that matches server address,port,version
|
|
|
|
* and minorversion.
|
|
|
|
*
|
|
|
|
* For a new nfs_client, use a soft mount (default), a low retrans and a
|
|
|
|
* low timeout interval so that if a connection is lost, we retry through
|
|
|
|
* the MDS.
|
|
|
|
*/
|
2016-06-14 01:57:35 +08:00
|
|
|
struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv,
|
2012-07-17 04:39:18 +08:00
|
|
|
const struct sockaddr *ds_addr, int ds_addrlen,
|
2014-05-29 21:07:00 +08:00
|
|
|
int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans,
|
2016-11-18 04:15:55 +08:00
|
|
|
u32 minor_version)
|
2012-07-17 04:39:18 +08:00
|
|
|
{
|
2016-06-23 02:13:12 +08:00
|
|
|
struct rpc_timeout ds_timeout;
|
2016-06-14 01:57:35 +08:00
|
|
|
struct nfs_client *mds_clp = mds_srv->nfs_client;
|
2012-07-17 04:39:18 +08:00
|
|
|
struct nfs_client_initdata cl_init = {
|
|
|
|
.addr = ds_addr,
|
|
|
|
.addrlen = ds_addrlen,
|
2016-06-23 02:13:12 +08:00
|
|
|
.nodename = mds_clp->cl_rpcclient->cl_nodename,
|
|
|
|
.ip_addr = mds_clp->cl_ipaddr,
|
2012-07-31 04:05:16 +08:00
|
|
|
.nfs_mod = &nfs_v4,
|
2012-07-17 04:39:18 +08:00
|
|
|
.proto = ds_proto,
|
2014-05-30 18:15:58 +08:00
|
|
|
.minorversion = minor_version,
|
2012-07-17 04:39:18 +08:00
|
|
|
.net = mds_clp->cl_net,
|
2016-06-23 02:13:12 +08:00
|
|
|
.timeparms = &ds_timeout,
|
2019-04-25 05:46:43 +08:00
|
|
|
.cred = mds_srv->cred,
|
2012-07-17 04:39:18 +08:00
|
|
|
};
|
2014-07-08 11:45:47 +08:00
|
|
|
char buf[INET6_ADDRSTRLEN + 1];
|
|
|
|
|
|
|
|
if (rpc_ntop(ds_addr, buf, sizeof(buf)) <= 0)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
cl_init.hostname = buf;
|
2012-07-17 04:39:18 +08:00
|
|
|
|
2017-04-27 23:22:07 +08:00
|
|
|
if (mds_clp->cl_nconnect > 1 && ds_proto == XPRT_TRANSPORT_TCP)
|
|
|
|
cl_init.nconnect = mds_clp->cl_nconnect;
|
|
|
|
|
2016-06-14 01:57:35 +08:00
|
|
|
if (mds_srv->flags & NFS_MOUNT_NORESVPORT)
|
|
|
|
__set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags);
|
|
|
|
|
2012-07-17 04:39:18 +08:00
|
|
|
/*
|
|
|
|
* Set an authflavor equual to the MDS value. Use the MDS nfs_client
|
|
|
|
* cl_ipaddr so as to use the same EXCHANGE_ID co_ownerid as the MDS
|
|
|
|
* (section 13.1 RFC 5661).
|
|
|
|
*/
|
|
|
|
nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans);
|
2017-04-08 02:15:18 +08:00
|
|
|
return nfs_get_client(&cl_init);
|
2012-07-17 04:39:18 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs4_set_ds_client);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Session has been established, and the client marked ready.
|
2018-09-18 22:07:44 +08:00
|
|
|
* Limit the mount rsize, wsize and dtsize using negotiated fore
|
|
|
|
* channel attributes.
|
2012-07-17 04:39:18 +08:00
|
|
|
*/
|
2018-09-18 22:07:44 +08:00
|
|
|
static void nfs4_session_limit_rwsize(struct nfs_server *server)
|
2012-07-17 04:39:18 +08:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_NFS_V4_1
|
|
|
|
struct nfs4_session *sess;
|
|
|
|
u32 server_resp_sz;
|
|
|
|
u32 server_rqst_sz;
|
|
|
|
|
|
|
|
if (!nfs4_has_session(server->nfs_client))
|
|
|
|
return;
|
|
|
|
sess = server->nfs_client->cl_session;
|
|
|
|
server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead;
|
|
|
|
server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead;
|
|
|
|
|
2018-09-18 22:07:44 +08:00
|
|
|
if (server->dtsize > server_resp_sz)
|
|
|
|
server->dtsize = server_resp_sz;
|
|
|
|
if (server->rsize > server_resp_sz)
|
2012-07-17 04:39:18 +08:00
|
|
|
server->rsize = server_resp_sz;
|
2018-09-18 22:07:44 +08:00
|
|
|
if (server->wsize > server_rqst_sz)
|
2012-07-17 04:39:18 +08:00
|
|
|
server->wsize = server_rqst_sz;
|
|
|
|
#endif /* CONFIG_NFS_V4_1 */
|
|
|
|
}
|
|
|
|
|
NFSv4.2: define limits and sizes for user xattr handling
Set limits for extended attributes (attribute value size and listxattr
buffer size), based on the fs-independent limits (XATTR_*_MAX).
Define the maximum XDR sizes for the RFC 8276 XATTR operations.
In the case of operations that carry a larger payload (SETXATTR,
GETXATTR, LISTXATTR), these exclude that payload, which is added
as separate pages, like other operations do.
Define, much like for read and write operations, the maximum overhead
sizes for get/set/listxattr, and use them to limit the maximum payload
size for those operations, in combination with the channel attributes.
Signed-off-by: Frank van der Linden <fllinden@amazon.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
2020-06-24 06:38:54 +08:00
|
|
|
/*
|
|
|
|
* Limit xattr sizes using the channel attributes.
|
|
|
|
*/
|
|
|
|
static void nfs4_session_limit_xasize(struct nfs_server *server)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_NFS_V4_2
|
|
|
|
struct nfs4_session *sess;
|
|
|
|
u32 server_gxa_sz;
|
|
|
|
u32 server_sxa_sz;
|
|
|
|
u32 server_lxa_sz;
|
|
|
|
|
|
|
|
if (!nfs4_has_session(server->nfs_client))
|
|
|
|
return;
|
|
|
|
|
|
|
|
sess = server->nfs_client->cl_session;
|
|
|
|
|
|
|
|
server_gxa_sz = sess->fc_attrs.max_resp_sz - nfs42_maxgetxattr_overhead;
|
|
|
|
server_sxa_sz = sess->fc_attrs.max_rqst_sz - nfs42_maxsetxattr_overhead;
|
|
|
|
server_lxa_sz = sess->fc_attrs.max_resp_sz -
|
|
|
|
nfs42_maxlistxattrs_overhead;
|
|
|
|
|
|
|
|
if (server->gxasize > server_gxa_sz)
|
|
|
|
server->gxasize = server_gxa_sz;
|
|
|
|
if (server->sxasize > server_sxa_sz)
|
|
|
|
server->sxasize = server_sxa_sz;
|
|
|
|
if (server->lxasize > server_lxa_sz)
|
|
|
|
server->lxasize = server_lxa_sz;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-07-17 04:39:18 +08:00
|
|
|
static int nfs4_server_common_setup(struct nfs_server *server,
|
2013-09-08 00:58:57 +08:00
|
|
|
struct nfs_fh *mntfh, bool auth_probe)
|
2012-07-17 04:39:18 +08:00
|
|
|
{
|
|
|
|
struct nfs_fattr *fattr;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* data servers support only a subset of NFSv4.1 */
|
|
|
|
if (is_ds_only_client(server->nfs_client))
|
|
|
|
return -EPROTONOSUPPORT;
|
|
|
|
|
|
|
|
fattr = nfs_alloc_fattr();
|
|
|
|
if (fattr == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* We must ensure the session is initialised first */
|
2013-06-27 00:21:49 +08:00
|
|
|
error = nfs4_init_session(server->nfs_client);
|
2012-07-17 04:39:18 +08:00
|
|
|
if (error < 0)
|
|
|
|
goto out;
|
|
|
|
|
2013-03-16 04:11:57 +08:00
|
|
|
/* Set the basic capabilities */
|
|
|
|
server->caps |= server->nfs_client->cl_mvops->init_caps;
|
|
|
|
if (server->flags & NFS_MOUNT_NORDIRPLUS)
|
|
|
|
server->caps &= ~NFS_CAP_READDIRPLUS;
|
2014-05-29 01:41:22 +08:00
|
|
|
if (server->nfs_client->cl_proto == XPRT_TRANSPORT_RDMA)
|
|
|
|
server->caps &= ~NFS_CAP_READ_PLUS;
|
2013-03-16 04:11:57 +08:00
|
|
|
/*
|
|
|
|
* Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower
|
|
|
|
* authentication.
|
|
|
|
*/
|
|
|
|
if (nfs4_disable_idmapping &&
|
|
|
|
server->client->cl_auth->au_flavor == RPC_AUTH_UNIX)
|
|
|
|
server->caps |= NFS_CAP_UIDGID_NOMAP;
|
|
|
|
|
|
|
|
|
2012-07-17 04:39:18 +08:00
|
|
|
/* Probe the root fh to retrieve its FSID and filehandle */
|
2013-09-08 00:58:57 +08:00
|
|
|
error = nfs4_get_rootfh(server, mntfh, auth_probe);
|
2012-07-17 04:39:18 +08:00
|
|
|
if (error < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
dprintk("Server FSID: %llx:%llx\n",
|
|
|
|
(unsigned long long) server->fsid.major,
|
|
|
|
(unsigned long long) server->fsid.minor);
|
2013-10-18 02:12:45 +08:00
|
|
|
nfs_display_fhandle(mntfh, "Pseudo-fs root FH");
|
2012-07-17 04:39:18 +08:00
|
|
|
|
|
|
|
error = nfs_probe_fsinfo(server, mntfh, fattr);
|
|
|
|
if (error < 0)
|
|
|
|
goto out;
|
|
|
|
|
2018-09-18 22:07:44 +08:00
|
|
|
nfs4_session_limit_rwsize(server);
|
NFSv4.2: define limits and sizes for user xattr handling
Set limits for extended attributes (attribute value size and listxattr
buffer size), based on the fs-independent limits (XATTR_*_MAX).
Define the maximum XDR sizes for the RFC 8276 XATTR operations.
In the case of operations that carry a larger payload (SETXATTR,
GETXATTR, LISTXATTR), these exclude that payload, which is added
as separate pages, like other operations do.
Define, much like for read and write operations, the maximum overhead
sizes for get/set/listxattr, and use them to limit the maximum payload
size for those operations, in combination with the channel attributes.
Signed-off-by: Frank van der Linden <fllinden@amazon.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
2020-06-24 06:38:54 +08:00
|
|
|
nfs4_session_limit_xasize(server);
|
2018-09-18 22:07:44 +08:00
|
|
|
|
2012-07-17 04:39:18 +08:00
|
|
|
if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
|
|
|
|
server->namelen = NFS4_MAXNAMLEN;
|
|
|
|
|
|
|
|
nfs_server_insert_lists(server);
|
|
|
|
server->mount_time = jiffies;
|
|
|
|
server->destroy = nfs4_destroy_server;
|
|
|
|
out:
|
|
|
|
nfs_free_fattr(fattr);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a version 4 volume record
|
|
|
|
*/
|
2019-12-10 20:31:14 +08:00
|
|
|
static int nfs4_init_server(struct nfs_server *server, struct fs_context *fc)
|
2012-07-17 04:39:18 +08:00
|
|
|
{
|
2019-12-10 20:31:14 +08:00
|
|
|
struct nfs_fs_context *ctx = nfs_fc2context(fc);
|
2012-07-17 04:39:18 +08:00
|
|
|
struct rpc_timeout timeparms;
|
|
|
|
int error;
|
|
|
|
|
2019-12-10 20:31:06 +08:00
|
|
|
nfs_init_timeout_values(&timeparms, ctx->nfs_server.protocol,
|
|
|
|
ctx->timeo, ctx->retrans);
|
2012-07-17 04:39:18 +08:00
|
|
|
|
|
|
|
/* Initialise the client representation from the mount data */
|
2019-12-10 20:31:06 +08:00
|
|
|
server->flags = ctx->flags;
|
|
|
|
server->options = ctx->options;
|
|
|
|
server->auth_info = ctx->auth_info;
|
2012-07-17 04:39:18 +08:00
|
|
|
|
2013-10-19 03:15:19 +08:00
|
|
|
/* Use the first specified auth flavor. If this flavor isn't
|
|
|
|
* allowed by the server, use the SECINFO path to try the
|
|
|
|
* other specified flavors */
|
2019-12-10 20:31:06 +08:00
|
|
|
if (ctx->auth_info.flavor_len >= 1)
|
|
|
|
ctx->selected_flavor = ctx->auth_info.flavors[0];
|
2013-10-19 03:15:16 +08:00
|
|
|
else
|
2019-12-10 20:31:06 +08:00
|
|
|
ctx->selected_flavor = RPC_AUTH_UNIX;
|
2013-09-08 00:58:57 +08:00
|
|
|
|
2012-07-17 04:39:18 +08:00
|
|
|
/* Get a client record */
|
|
|
|
error = nfs4_set_client(server,
|
2019-12-10 20:31:14 +08:00
|
|
|
ctx->nfs_server.hostname,
|
|
|
|
&ctx->nfs_server.address,
|
|
|
|
ctx->nfs_server.addrlen,
|
|
|
|
ctx->client_address,
|
|
|
|
ctx->nfs_server.protocol,
|
|
|
|
&timeparms,
|
|
|
|
ctx->minorversion,
|
|
|
|
ctx->nfs_server.nconnect,
|
|
|
|
fc->net_ns);
|
2012-07-17 04:39:18 +08:00
|
|
|
if (error < 0)
|
2017-04-08 02:15:17 +08:00
|
|
|
return error;
|
2012-07-17 04:39:18 +08:00
|
|
|
|
2019-12-10 20:31:06 +08:00
|
|
|
if (ctx->rsize)
|
|
|
|
server->rsize = nfs_block_size(ctx->rsize, NULL);
|
|
|
|
if (ctx->wsize)
|
|
|
|
server->wsize = nfs_block_size(ctx->wsize, NULL);
|
2012-07-17 04:39:18 +08:00
|
|
|
|
2019-12-10 20:31:06 +08:00
|
|
|
server->acregmin = ctx->acregmin * HZ;
|
|
|
|
server->acregmax = ctx->acregmax * HZ;
|
|
|
|
server->acdirmin = ctx->acdirmin * HZ;
|
|
|
|
server->acdirmax = ctx->acdirmax * HZ;
|
|
|
|
server->port = ctx->nfs_server.port;
|
2012-07-17 04:39:18 +08:00
|
|
|
|
2017-04-08 02:15:17 +08:00
|
|
|
return nfs_init_server_rpcclient(server, &timeparms,
|
2019-12-10 20:31:06 +08:00
|
|
|
ctx->selected_flavor);
|
2012-07-17 04:39:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a version 4 volume record
|
|
|
|
* - keyed on server and FSID
|
|
|
|
*/
|
2019-12-10 20:31:14 +08:00
|
|
|
struct nfs_server *nfs4_create_server(struct fs_context *fc)
|
2012-07-17 04:39:18 +08:00
|
|
|
{
|
2019-12-10 20:31:14 +08:00
|
|
|
struct nfs_fs_context *ctx = nfs_fc2context(fc);
|
2012-07-17 04:39:18 +08:00
|
|
|
struct nfs_server *server;
|
2013-09-08 00:58:57 +08:00
|
|
|
bool auth_probe;
|
2012-07-17 04:39:18 +08:00
|
|
|
int error;
|
|
|
|
|
|
|
|
server = nfs_alloc_server();
|
|
|
|
if (!server)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2019-04-25 05:46:43 +08:00
|
|
|
server->cred = get_cred(current_cred());
|
|
|
|
|
2019-12-10 20:31:14 +08:00
|
|
|
auth_probe = ctx->auth_info.flavor_len < 1;
|
2013-09-08 00:58:57 +08:00
|
|
|
|
2012-07-17 04:39:18 +08:00
|
|
|
/* set up the general RPC client */
|
2019-12-10 20:31:14 +08:00
|
|
|
error = nfs4_init_server(server, fc);
|
2012-07-17 04:39:18 +08:00
|
|
|
if (error < 0)
|
|
|
|
goto error;
|
|
|
|
|
2019-12-10 20:31:14 +08:00
|
|
|
error = nfs4_server_common_setup(server, ctx->mntfh, auth_probe);
|
2012-07-17 04:39:18 +08:00
|
|
|
if (error < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return server;
|
|
|
|
|
|
|
|
error:
|
|
|
|
nfs_free_server(server);
|
|
|
|
return ERR_PTR(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create an NFS4 referral server record
|
|
|
|
*/
|
2019-12-10 20:31:14 +08:00
|
|
|
struct nfs_server *nfs4_create_referral_server(struct fs_context *fc)
|
2012-07-17 04:39:18 +08:00
|
|
|
{
|
2019-12-10 20:31:14 +08:00
|
|
|
struct nfs_fs_context *ctx = nfs_fc2context(fc);
|
2012-07-17 04:39:18 +08:00
|
|
|
struct nfs_client *parent_client;
|
|
|
|
struct nfs_server *server, *parent_server;
|
2013-10-19 03:15:18 +08:00
|
|
|
bool auth_probe;
|
2012-07-17 04:39:18 +08:00
|
|
|
int error;
|
|
|
|
|
|
|
|
server = nfs_alloc_server();
|
|
|
|
if (!server)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2019-12-10 20:31:14 +08:00
|
|
|
parent_server = NFS_SB(ctx->clone_data.sb);
|
2012-07-17 04:39:18 +08:00
|
|
|
parent_client = parent_server->nfs_client;
|
|
|
|
|
2019-04-25 05:46:43 +08:00
|
|
|
server->cred = get_cred(parent_server->cred);
|
|
|
|
|
2012-07-17 04:39:18 +08:00
|
|
|
/* Initialise the client representation from the parent server */
|
|
|
|
nfs_server_copy_userdata(server, parent_server);
|
|
|
|
|
2017-12-05 03:13:38 +08:00
|
|
|
/* Get a client representation */
|
2018-07-06 00:08:08 +08:00
|
|
|
#if IS_ENABLED(CONFIG_SUNRPC_XPRT_RDMA)
|
2019-12-10 20:31:14 +08:00
|
|
|
rpc_set_port(&ctx->nfs_server.address, NFS_RDMA_PORT);
|
|
|
|
error = nfs4_set_client(server,
|
|
|
|
ctx->nfs_server.hostname,
|
|
|
|
&ctx->nfs_server.address,
|
|
|
|
ctx->nfs_server.addrlen,
|
2012-07-17 04:39:18 +08:00
|
|
|
parent_client->cl_ipaddr,
|
2017-12-05 03:13:38 +08:00
|
|
|
XPRT_TRANSPORT_RDMA,
|
|
|
|
parent_server->client->cl_timeout,
|
|
|
|
parent_client->cl_mvops->minor_version,
|
2017-04-27 23:13:40 +08:00
|
|
|
parent_client->cl_nconnect,
|
2017-12-05 03:13:38 +08:00
|
|
|
parent_client->cl_net);
|
|
|
|
if (!error)
|
|
|
|
goto init_server;
|
2018-07-06 00:08:08 +08:00
|
|
|
#endif /* IS_ENABLED(CONFIG_SUNRPC_XPRT_RDMA) */
|
2017-12-05 03:13:38 +08:00
|
|
|
|
2019-12-10 20:31:14 +08:00
|
|
|
rpc_set_port(&ctx->nfs_server.address, NFS_PORT);
|
|
|
|
error = nfs4_set_client(server,
|
|
|
|
ctx->nfs_server.hostname,
|
|
|
|
&ctx->nfs_server.address,
|
|
|
|
ctx->nfs_server.addrlen,
|
2017-12-05 03:13:38 +08:00
|
|
|
parent_client->cl_ipaddr,
|
|
|
|
XPRT_TRANSPORT_TCP,
|
2012-07-17 04:39:18 +08:00
|
|
|
parent_server->client->cl_timeout,
|
|
|
|
parent_client->cl_mvops->minor_version,
|
2017-04-27 23:13:40 +08:00
|
|
|
parent_client->cl_nconnect,
|
2012-07-17 04:39:18 +08:00
|
|
|
parent_client->cl_net);
|
|
|
|
if (error < 0)
|
|
|
|
goto error;
|
|
|
|
|
2018-07-06 00:08:08 +08:00
|
|
|
#if IS_ENABLED(CONFIG_SUNRPC_XPRT_RDMA)
|
2017-12-05 03:13:38 +08:00
|
|
|
init_server:
|
|
|
|
#endif
|
2019-12-10 20:31:14 +08:00
|
|
|
error = nfs_init_server_rpcclient(server, parent_server->client->cl_timeout,
|
|
|
|
ctx->selected_flavor);
|
2012-07-17 04:39:18 +08:00
|
|
|
if (error < 0)
|
|
|
|
goto error;
|
|
|
|
|
2013-10-19 03:15:18 +08:00
|
|
|
auth_probe = parent_server->auth_info.flavor_len < 1;
|
|
|
|
|
2019-12-10 20:31:14 +08:00
|
|
|
error = nfs4_server_common_setup(server, ctx->mntfh, auth_probe);
|
2012-07-17 04:39:18 +08:00
|
|
|
if (error < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return server;
|
|
|
|
|
|
|
|
error:
|
|
|
|
nfs_free_server(server);
|
|
|
|
return ERR_PTR(error);
|
|
|
|
}
|
2013-10-18 02:12:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab the destination's particulars, including lease expiry time.
|
|
|
|
*
|
|
|
|
* Returns zero if probe succeeded and retrieved FSID matches the FSID
|
|
|
|
* we have cached.
|
|
|
|
*/
|
|
|
|
static int nfs_probe_destination(struct nfs_server *server)
|
|
|
|
{
|
2015-03-18 06:25:59 +08:00
|
|
|
struct inode *inode = d_inode(server->super->s_root);
|
2013-10-18 02:12:28 +08:00
|
|
|
struct nfs_fattr *fattr;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
fattr = nfs_alloc_fattr();
|
|
|
|
if (fattr == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Sanity: the probe won't work if the destination server
|
|
|
|
* does not recognize the migrated FH. */
|
|
|
|
error = nfs_probe_fsinfo(server, NFS_FH(inode), fattr);
|
|
|
|
|
|
|
|
nfs_free_fattr(fattr);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs4_update_server - Move an nfs_server to a different nfs_client
|
|
|
|
*
|
|
|
|
* @server: represents FSID to be moved
|
|
|
|
* @hostname: new end-point's hostname
|
|
|
|
* @sap: new end-point's socket address
|
|
|
|
* @salen: size of "sap"
|
2014-02-17 10:42:56 +08:00
|
|
|
* @net: net namespace
|
2013-10-18 02:12:28 +08:00
|
|
|
*
|
|
|
|
* The nfs_server must be quiescent before this function is invoked.
|
|
|
|
* Either its session is drained (NFSv4.1+), or its transport is
|
|
|
|
* plugged and drained (NFSv4.0).
|
|
|
|
*
|
|
|
|
* Returns zero on success, or a negative errno value.
|
|
|
|
*/
|
|
|
|
int nfs4_update_server(struct nfs_server *server, const char *hostname,
|
2014-02-17 10:42:56 +08:00
|
|
|
struct sockaddr *sap, size_t salen, struct net *net)
|
2013-10-18 02:12:28 +08:00
|
|
|
{
|
|
|
|
struct nfs_client *clp = server->nfs_client;
|
|
|
|
struct rpc_clnt *clnt = server->client;
|
|
|
|
struct xprt_create xargs = {
|
|
|
|
.ident = clp->cl_proto,
|
2014-02-17 10:42:56 +08:00
|
|
|
.net = net,
|
2013-10-18 02:12:28 +08:00
|
|
|
.dstaddr = sap,
|
|
|
|
.addrlen = salen,
|
|
|
|
.servername = hostname,
|
|
|
|
};
|
|
|
|
char buf[INET6_ADDRSTRLEN + 1];
|
|
|
|
struct sockaddr_storage address;
|
|
|
|
struct sockaddr *localaddr = (struct sockaddr *)&address;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = rpc_switch_client_transport(clnt, &xargs, clnt->cl_timeout);
|
2017-04-08 02:15:18 +08:00
|
|
|
if (error != 0)
|
|
|
|
return error;
|
2013-10-18 02:12:28 +08:00
|
|
|
|
|
|
|
error = rpc_localaddr(clnt, localaddr, sizeof(address));
|
2017-04-08 02:15:18 +08:00
|
|
|
if (error != 0)
|
|
|
|
return error;
|
2013-10-18 02:12:28 +08:00
|
|
|
|
2017-04-08 02:15:18 +08:00
|
|
|
if (rpc_ntop(localaddr, buf, sizeof(buf)) == 0)
|
|
|
|
return -EAFNOSUPPORT;
|
2013-10-18 02:12:28 +08:00
|
|
|
|
|
|
|
nfs_server_remove_lists(server);
|
2017-06-08 23:52:44 +08:00
|
|
|
set_bit(NFS_MIG_TSM_POSSIBLE, &server->mig_status);
|
2013-10-18 02:12:28 +08:00
|
|
|
error = nfs4_set_client(server, hostname, sap, salen, buf,
|
|
|
|
clp->cl_proto, clnt->cl_timeout,
|
2017-04-27 23:13:40 +08:00
|
|
|
clp->cl_minorversion,
|
|
|
|
clp->cl_nconnect, net);
|
2017-06-08 23:52:44 +08:00
|
|
|
clear_bit(NFS_MIG_TSM_POSSIBLE, &server->mig_status);
|
2013-10-18 02:12:28 +08:00
|
|
|
if (error != 0) {
|
|
|
|
nfs_server_insert_lists(server);
|
2017-04-08 02:15:18 +08:00
|
|
|
return error;
|
2013-10-18 02:12:28 +08:00
|
|
|
}
|
2018-02-22 02:46:43 +08:00
|
|
|
nfs_put_client(clp);
|
2013-10-18 02:12:28 +08:00
|
|
|
|
|
|
|
if (server->nfs_client->cl_hostname == NULL)
|
|
|
|
server->nfs_client->cl_hostname = kstrdup(hostname, GFP_KERNEL);
|
|
|
|
nfs_server_insert_lists(server);
|
|
|
|
|
2017-04-08 02:15:18 +08:00
|
|
|
return nfs_probe_destination(server);
|
2013-10-18 02:12:28 +08:00
|
|
|
}
|