提交 286d7d6a 编写于 作者: T Trond Myklebust

NFSv4: Remove requirement for machine creds for the "setclientid" operation

 Use a cred from the nfs4_client->cl_state_owners list.
Signed-off-by: NTrond Myklebust <Trond.Myklebust@netapp.com>
上级 b4454fe1
...@@ -1822,23 +1822,9 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, ...@@ -1822,23 +1822,9 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
clnt->cl_softrtry = 1; clnt->cl_softrtry = 1;
clnt->cl_chatty = 1; clnt->cl_chatty = 1;
clp->cl_rpcclient = clnt; clp->cl_rpcclient = clnt;
clp->cl_cred = rpcauth_lookupcred(clnt->cl_auth, 0);
if (IS_ERR(clp->cl_cred)) {
up_write(&clp->cl_sem);
err = PTR_ERR(clp->cl_cred);
clp->cl_cred = NULL;
goto out_fail;
}
memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr)); memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
nfs_idmap_new(clp); nfs_idmap_new(clp);
} }
if (list_empty(&clp->cl_superblocks)) {
err = nfs4_init_client(clp);
if (err != 0) {
up_write(&clp->cl_sem);
goto out_fail;
}
}
list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks); list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
clnt = rpc_clone_client(clp->cl_rpcclient); clnt = rpc_clone_client(clp->cl_rpcclient);
if (!IS_ERR(clnt)) if (!IS_ERR(clnt))
......
...@@ -68,7 +68,6 @@ struct nfs4_client { ...@@ -68,7 +68,6 @@ struct nfs4_client {
atomic_t cl_count; atomic_t cl_count;
struct rpc_clnt * cl_rpcclient; struct rpc_clnt * cl_rpcclient;
struct rpc_cred * cl_cred;
struct list_head cl_superblocks; /* List of nfs_server structs */ struct list_head cl_superblocks; /* List of nfs_server structs */
...@@ -211,8 +210,8 @@ extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t); ...@@ -211,8 +210,8 @@ extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t);
/* nfs4proc.c */ /* nfs4proc.c */
extern int nfs4_map_errors(int err); extern int nfs4_map_errors(int err);
extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short); extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short, struct rpc_cred *);
extern int nfs4_proc_setclientid_confirm(struct nfs4_client *); extern int nfs4_proc_setclientid_confirm(struct nfs4_client *, struct rpc_cred *);
extern int nfs4_proc_async_renew(struct nfs4_client *, struct rpc_cred *); extern int nfs4_proc_async_renew(struct nfs4_client *, struct rpc_cred *);
extern int nfs4_proc_renew(struct nfs4_client *, struct rpc_cred *); extern int nfs4_proc_renew(struct nfs4_client *, struct rpc_cred *);
extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state); extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state);
...@@ -238,7 +237,6 @@ extern void init_nfsv4_state(struct nfs_server *); ...@@ -238,7 +237,6 @@ extern void init_nfsv4_state(struct nfs_server *);
extern void destroy_nfsv4_state(struct nfs_server *); extern void destroy_nfsv4_state(struct nfs_server *);
extern struct nfs4_client *nfs4_get_client(struct in_addr *); extern struct nfs4_client *nfs4_get_client(struct in_addr *);
extern void nfs4_put_client(struct nfs4_client *clp); extern void nfs4_put_client(struct nfs4_client *clp);
extern int nfs4_init_client(struct nfs4_client *clp);
extern struct nfs4_client *nfs4_find_client(struct in_addr *); extern struct nfs4_client *nfs4_find_client(struct in_addr *);
struct rpc_cred *nfs4_get_renew_cred(struct nfs4_client *clp); struct rpc_cred *nfs4_get_renew_cred(struct nfs4_client *clp);
extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *); extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *);
......
...@@ -2846,7 +2846,7 @@ int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct ...@@ -2846,7 +2846,7 @@ int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct
return nfs4_map_errors(ret); return nfs4_map_errors(ret);
} }
int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short port) int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short port, struct rpc_cred *cred)
{ {
nfs4_verifier sc_verifier; nfs4_verifier sc_verifier;
struct nfs4_setclientid setclientid = { struct nfs4_setclientid setclientid = {
...@@ -2857,7 +2857,7 @@ int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short p ...@@ -2857,7 +2857,7 @@ int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short p
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
.rpc_argp = &setclientid, .rpc_argp = &setclientid,
.rpc_resp = clp, .rpc_resp = clp,
.rpc_cred = clp->cl_cred, .rpc_cred = cred,
}; };
u32 *p; u32 *p;
int loop = 0; int loop = 0;
...@@ -2871,7 +2871,7 @@ int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short p ...@@ -2871,7 +2871,7 @@ int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short p
setclientid.sc_name_len = scnprintf(setclientid.sc_name, setclientid.sc_name_len = scnprintf(setclientid.sc_name,
sizeof(setclientid.sc_name), "%s/%u.%u.%u.%u %s %u", sizeof(setclientid.sc_name), "%s/%u.%u.%u.%u %s %u",
clp->cl_ipaddr, NIPQUAD(clp->cl_addr.s_addr), clp->cl_ipaddr, NIPQUAD(clp->cl_addr.s_addr),
clp->cl_cred->cr_ops->cr_name, cred->cr_ops->cr_name,
clp->cl_id_uniquifier); clp->cl_id_uniquifier);
setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
sizeof(setclientid.sc_netid), "tcp"); sizeof(setclientid.sc_netid), "tcp");
...@@ -2894,14 +2894,14 @@ int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short p ...@@ -2894,14 +2894,14 @@ int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short p
} }
int int
nfs4_proc_setclientid_confirm(struct nfs4_client *clp) nfs4_proc_setclientid_confirm(struct nfs4_client *clp, struct rpc_cred *cred)
{ {
struct nfs_fsinfo fsinfo; struct nfs_fsinfo fsinfo;
struct rpc_message msg = { struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
.rpc_argp = clp, .rpc_argp = clp,
.rpc_resp = &fsinfo, .rpc_resp = &fsinfo,
.rpc_cred = clp->cl_cred, .rpc_cred = cred,
}; };
unsigned long now; unsigned long now;
int status; int status;
......
...@@ -91,11 +91,10 @@ nfs4_alloc_client(struct in_addr *addr) ...@@ -91,11 +91,10 @@ nfs4_alloc_client(struct in_addr *addr)
if (nfs_callback_up() < 0) if (nfs_callback_up() < 0)
return NULL; return NULL;
if ((clp = kmalloc(sizeof(*clp), GFP_KERNEL)) == NULL) { if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL) {
nfs_callback_down(); nfs_callback_down();
return NULL; return NULL;
} }
memset(clp, 0, sizeof(*clp));
memcpy(&clp->cl_addr, addr, sizeof(clp->cl_addr)); memcpy(&clp->cl_addr, addr, sizeof(clp->cl_addr));
init_rwsem(&clp->cl_sem); init_rwsem(&clp->cl_sem);
INIT_LIST_HEAD(&clp->cl_delegations); INIT_LIST_HEAD(&clp->cl_delegations);
...@@ -108,7 +107,7 @@ nfs4_alloc_client(struct in_addr *addr) ...@@ -108,7 +107,7 @@ nfs4_alloc_client(struct in_addr *addr)
rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS4 client"); rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS4 client");
clp->cl_rpcclient = ERR_PTR(-EINVAL); clp->cl_rpcclient = ERR_PTR(-EINVAL);
clp->cl_boot_time = CURRENT_TIME; clp->cl_boot_time = CURRENT_TIME;
clp->cl_state = 0; clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
return clp; return clp;
} }
...@@ -125,8 +124,6 @@ nfs4_free_client(struct nfs4_client *clp) ...@@ -125,8 +124,6 @@ nfs4_free_client(struct nfs4_client *clp)
kfree(sp); kfree(sp);
} }
BUG_ON(!list_empty(&clp->cl_state_owners)); BUG_ON(!list_empty(&clp->cl_state_owners));
if (clp->cl_cred)
put_rpccred(clp->cl_cred);
nfs_idmap_delete(clp); nfs_idmap_delete(clp);
if (!IS_ERR(clp->cl_rpcclient)) if (!IS_ERR(clp->cl_rpcclient))
rpc_shutdown_client(clp->cl_rpcclient); rpc_shutdown_client(clp->cl_rpcclient);
...@@ -196,21 +193,17 @@ nfs4_put_client(struct nfs4_client *clp) ...@@ -196,21 +193,17 @@ nfs4_put_client(struct nfs4_client *clp)
nfs4_free_client(clp); nfs4_free_client(clp);
} }
static int __nfs4_init_client(struct nfs4_client *clp) static int nfs4_init_client(struct nfs4_client *clp, struct rpc_cred *cred)
{ {
int status = nfs4_proc_setclientid(clp, NFS4_CALLBACK, nfs_callback_tcpport); int status = nfs4_proc_setclientid(clp, NFS4_CALLBACK,
nfs_callback_tcpport, cred);
if (status == 0) if (status == 0)
status = nfs4_proc_setclientid_confirm(clp); status = nfs4_proc_setclientid_confirm(clp, cred);
if (status == 0) if (status == 0)
nfs4_schedule_state_renewal(clp); nfs4_schedule_state_renewal(clp);
return status; return status;
} }
int nfs4_init_client(struct nfs4_client *clp)
{
return nfs4_map_errors(__nfs4_init_client(clp));
}
u32 u32
nfs4_alloc_lockowner_id(struct nfs4_client *clp) nfs4_alloc_lockowner_id(struct nfs4_client *clp)
{ {
...@@ -246,6 +239,18 @@ struct rpc_cred *nfs4_get_renew_cred(struct nfs4_client *clp) ...@@ -246,6 +239,18 @@ struct rpc_cred *nfs4_get_renew_cred(struct nfs4_client *clp)
return cred; return cred;
} }
struct rpc_cred *nfs4_get_setclientid_cred(struct nfs4_client *clp)
{
struct nfs4_state_owner *sp;
if (!list_empty(&clp->cl_state_owners)) {
sp = list_entry(clp->cl_state_owners.next,
struct nfs4_state_owner, so_list);
return get_rpccred(sp->so_cred);
}
return NULL;
}
static struct nfs4_state_owner * static struct nfs4_state_owner *
nfs4_find_state_owner(struct nfs4_client *clp, struct rpc_cred *cred) nfs4_find_state_owner(struct nfs4_client *clp, struct rpc_cred *cred)
{ {
...@@ -902,6 +907,7 @@ static int reclaimer(void *ptr) ...@@ -902,6 +907,7 @@ static int reclaimer(void *ptr)
struct nfs4_client *clp = ptr; struct nfs4_client *clp = ptr;
struct nfs4_state_owner *sp; struct nfs4_state_owner *sp;
struct nfs4_state_recovery_ops *ops; struct nfs4_state_recovery_ops *ops;
struct rpc_cred *cred;
int status = 0; int status = 0;
allow_signal(SIGKILL); allow_signal(SIGKILL);
...@@ -913,20 +919,33 @@ static int reclaimer(void *ptr) ...@@ -913,20 +919,33 @@ static int reclaimer(void *ptr)
if (list_empty(&clp->cl_superblocks)) if (list_empty(&clp->cl_superblocks))
goto out; goto out;
restart_loop: restart_loop:
status = nfs4_proc_renew(clp, clp->cl_cred); ops = &nfs4_network_partition_recovery_ops;
switch (status) { /* Are there any open files on this volume? */
case 0: cred = nfs4_get_renew_cred(clp);
case -NFS4ERR_CB_PATH_DOWN: if (cred != NULL) {
goto out; /* Yes there are: try to renew the old lease */
case -NFS4ERR_STALE_CLIENTID: status = nfs4_proc_renew(clp, cred);
case -NFS4ERR_LEASE_MOVED: switch (status) {
ops = &nfs4_reboot_recovery_ops; case 0:
break; case -NFS4ERR_CB_PATH_DOWN:
default: put_rpccred(cred);
ops = &nfs4_network_partition_recovery_ops; goto out;
}; case -NFS4ERR_STALE_CLIENTID:
case -NFS4ERR_LEASE_MOVED:
ops = &nfs4_reboot_recovery_ops;
}
} else {
/* "reboot" to ensure we clear all state on the server */
clp->cl_boot_time = CURRENT_TIME;
cred = nfs4_get_setclientid_cred(clp);
}
/* We're going to have to re-establish a clientid */
nfs4_state_mark_reclaim(clp); nfs4_state_mark_reclaim(clp);
status = __nfs4_init_client(clp); status = -ENOENT;
if (cred != NULL) {
status = nfs4_init_client(clp, cred);
put_rpccred(cred);
}
if (status) if (status)
goto out_error; goto out_error;
/* Mark all delegations for reclaim */ /* Mark all delegations for reclaim */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册