Refactor data structures to support NFSv4 migration
Subsystems (2)
cover Refactor data structures to support NFSv4 migration
Trond-
Here are four patches that move fields related to NFSv4 state from the nfs_client struct to the nfs_server struct, in order to facilitate the eventual implementation of NFSv4 migration.
This series should address all recent review comments. It passes my simple tests here: Full cthon suite passes over NFSv4 against an OpenSolaris 2009.6 NFS server, and a full -j3 kernel build on NFSv4 completes without hangs or lockdep splats on a two-way client. The kernel build usually generates some delegation activity with this Solaris server.
---
Chuck Lever (4):
NFS: Move cl_delegations to the nfs_server struct
NFS: Introduce nfs_detach_delegations()
NFS: Move cl_state_owners and related fields to the nfs_server struct
NFS: Allow walking nfs_client.cl_superblocks list outside client.c
fs/nfs/client.c | 48 +++--- fs/nfs/delegation.c | 362 ++++++++++++++++++++++++++++++++------------- fs/nfs/delegation.h | 1 fs/nfs/nfs4_fs.h | 2 fs/nfs/nfs4renewd.c | 11 + fs/nfs/nfs4state.c | 239 +++++++++++++++++++++--------- include/linux/nfs_fs_sb.h | 11 + 7 files changed, 474 insertions(+), 200 deletions(-)
Signature · 1 line
Chuck Lever
PATCH 1/4 NFS: Allow walking nfs_client.cl_superblocks list outside client.c
We're about to move some fields from struct nfs_client to struct nfs_server. There is a many-to-one relationship between nfs_servers and nfs_clients. After these fields are moved to the nfs_server struct, to visit all of the data in these fields that is owned by one nfs_client, code will need to visit each nfs_server on the cl_superblocks list for that nfs_client.
To serialize changes to the cl_superblocks list during these little expeditions, protect the list with RCU.
---
fs/nfs/client.c | 44 +++++++++++++++++++++++++------------------- fs/nfs/nfs4renewd.c | 9 +++++++-- 2 files changed, 32 insertions(+), 21 deletions(-)
fs/nfs/client.c +25 -19
@@ -988,6 +988,27 @@ static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_serve target->options = source->options; } +static void nfs_server_insert_lists (struct nfs_server *server) +{ +struct nfs_client *clp = server->nfs_client; + +spin_lock (&nfs_client_lock); +list_add_tail_rcu (&server->client_link, &clp->cl_superblocks); +list_add_tail (&server->master_link, &nfs_volume_list); +spin_unlock (&nfs_client_lock); + +} + +static void nfs_server_remove_lists (struct nfs_server *server) +{ +spin_lock (&nfs_client_lock); +list_del_rcu (&server->client_link); +list_del (&server->master_link); +spin_unlock (&nfs_client_lock); + +synchronize_rcu (); +} +/* * Allocate and initialise a server record */
@@ -1029,11 +1050,8 @@ void nfs_free_server(struct nfs_server *server) {dprintk ("--> nfs_free_server()\n" ); +nfs_server_remove_lists (server);unset_pnfs_layoutdriver (server); -spin_lock (&nfs_client_lock); -list_del (&server->client_link); -list_del (&server->master_link); -spin_unlock (&nfs_client_lock);if (server->destroy !=NULL ) server->destroy (server);
@@ -1108,11 +1126,7 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data, (unsigned long long ) server->fsid.major, (unsigned long long) server->fsid.minor); -spin_lock (&nfs_client_lock); -list_add_tail (&server->client_link, &server->nfs_client->cl_superblocks); -list_add_tail (&server->master_link, &nfs_volume_list); -spin_unlock (&nfs_client_lock); - +nfs_server_insert_lists (server); server->mount_time = jiffies;nfs_free_fattr (fattr);return server;
@@ -1342,11 +1356,7 @@ static int nfs4_server_common_setup(struct nfs_server *server,if (server->namelen ==0 || server->namelen >NFS4_MAXNAMLEN ) server->namelen =NFS4_MAXNAMLEN ; -spin_lock (&nfs_client_lock); -list_add_tail (&server->client_link, &server->nfs_client->cl_superblocks); -list_add_tail (&server->master_link, &nfs_volume_list); -spin_unlock (&nfs_client_lock); - +nfs_server_insert_lists (server); server->mount_time = jiffies; out:nfs_free_fattr (fattr);
@@ -1551,11 +1561,7 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,if (error <0 ) goto out_free_server; -spin_lock (&nfs_client_lock); -list_add_tail (&server->client_link, &server->nfs_client->cl_superblocks); -list_add_tail (&server->master_link, &nfs_volume_list); -spin_unlock (&nfs_client_lock); - +nfs_server_insert_lists (server); server->mount_time = jiffies;nfs_free_fattr (fattr_fsinfo);
fs/nfs/nfs4renewd.c +7 -2
@@ -63,9 +63,14 @@ nfs4_renew_state(struct work_struct *work) ops = clp->cl_mvops->state_renewal_ops;dprintk ("%s: start\n" , __func__); -/* Are there any active superblocks? */ -if (list_empty (&clp->cl_superblocks)) + +rcu_read_lock (); +if (list_empty (&clp->cl_superblocks)) { +rcu_read_unlock (); goto out; + } +rcu_read_unlock (); +spin_lock (&clp->cl_lock); lease = clp->cl_lease_time; last = clp->cl_last_renewal;
PATCH 2/4 NFS: Move cl_state_owners and related fields to the nfs_server struct
In reply to Chuck LeverNFSv4 migration needs to reassociate state owners from the source to the destination nfs_server data structures. To make that easier, move the cl_state_owners field to the nfs_server struct. cl_openowner_id and cl_lockowner_id accompany this move, as they are used in conjunction with cl_state_owners.
The cl_lock field in the parent nfs_client continues to protect all three of these fields.
---
fs/nfs/nfs4_fs.h | 2 fs/nfs/nfs4state.c | 239 ++++++++++++++++++++++++++++++++------------- include/linux/nfs_fs_sb.h | 9 +- 3 files changed, 177 insertions(+), 73 deletions(-)
fs/nfs/nfs4_fs.h +1 -1
@@ -109,7 +109,7 @@ struct nfs_unique_id {struct nfs4_state_owner {struct nfs_unique_id so_owner_id;struct nfs_server *so_server; -struct rb_node so_client_node; +struct rb_node so_server_node;struct rpc_cred *so_cred;/* Associated cred */
fs/nfs/nfs4state.c +171 -68
414 lines not on this page · raw message
include/linux/nfs_fs_sb.h +5 -4
@@ -47,11 +47,7 @@ struct nfs_client {u64 cl_clientid;/* constant */ unsigned long cl_state; -struct rb_root cl_openowner_id; -struct rb_root cl_lockowner_id; -struct list_head cl_delegations; -struct rb_root cl_state_owners;spinlock_t cl_lock;unsigned long cl_lease_time;
@@ -148,6 +144,11 @@ struct nfs_server {that are supported on this filesystem */ struct pnfs_layoutdriver_type *pnfs_curr_ld;/* Active layout driver */ + +/* the following fields are protected by nfs_client->cl_lock */ +struct rb_root state_owners; +struct rb_root openowner_id; +struct rb_root lockowner_id;#endif void (*destroy)(struct nfs_server *);
Re: [PATCH 2/4] NFS: Move cl_state_owners and related fields to the nfs_server struct
Quoted 116 lines · Chuck Lever
NFSv4 migration needs to reassociate state owners from the source to the destination
nfs_serverdata structures. To make that easier, move thecl_state_ownersfield to thenfs_serverstruct.cl_openowner_idandcl_lockowner_idaccompany this move, as they are used in conjunction withcl_state_owners.The
cl_lockfield in the parentnfs_clientcontinues to protect all three of these fields.Signed-off-by Chuck Lever <[email protected]>---
fs/nfs/nfs4_fs.h | 2 fs/nfs/nfs4state.c | 239 ++++++++++++++++++++++++++++++++------------- include/linux/nfs_fs_sb.h | 9 +- 3 files changed, 177 insertions(+), 73 deletions(-)fs/nfs/nfs4_fs.h +1
-1@@ -109,7 +109,7 @@ struct nfs_unique_id {struct nfs4_state_owner {struct nfs_unique_id so_owner_id;struct nfs_server *so_server; -struct rb_node so_client_node; +struct rb_node so_server_node;struct rpc_cred *so_cred;/* Associated cred */ fs/nfs/nfs4state.c +50
-5@@ -105,14 +105,17 @@ static void nfs4_clear_machine_cred(struct nfs_client *clp)put_rpccred (cred); } -struct rpc_cred *nfs4_get_renew_cred_locked (struct nfs_client *clp) +static struct rpc_cred * +nfs4_get_renew_cred_server_locked (struct nfs_server *server) { +struct rpc_cred *cred =NULL ;struct nfs4_state_owner *sp;struct rb_node *pos; -struct rpc_cred *cred =NULL ; -for (pos =rb_first (&clp->cl_state_owners); pos !=NULL ; pos =rb_next (pos)) { - sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); +for (pos =rb_first (&server->state_owners); + pos !=NULL ; + pos =rb_next (pos)) { + sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);if (list_empty (&sp->so_states))continue ; cred =get_rpccred (sp->so_cred);@@ -121,6 +124,28 @@ struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)return cred; } +/** +* nfs4_get_renew_cred_locked - Acquire credential for a renew operation +* @clp: client state handle +* +* Returns an rpc_cred with reference count bumped, or NULL. +* Caller must hold clp->cl_lock. +*/ +struct rpc_cred *nfs4_get_renew_cred_locked (struct nfs_client *clp) +{ +struct rpc_cred *cred =NULL ; +struct nfs_server *server; + +rcu_read_lock (); +list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) { + cred =nfs4_get_renew_cred_server_locked (server); +if (cred !=NULL ) +break ; + } +rcu_read_unlock (); +return cred; +} +#if defined(CONFIG_NFS_V4_1 )static int nfs41_setup_state_renewal (struct nfs_client *clp)@@ -210,21 +235,45 @@ struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp)#endif /* CONFIG_NFS_V4_1 */ -struct rpc_cred *nfs4_get_setclientid_cred (struct nfs_client *clp) +static struct rpc_cred * +nfs4_get_setclientid_cred_server_locked (struct nfs_server *server) { +struct rpc_cred *cred =NULL ;struct nfs4_state_owner *sp;struct rb_node *pos; + + pos =rb_first (&server->state_owners); +if (pos !=NULL ) { + sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); + cred =get_rpccred (sp->so_cred); + } +return cred; +} + +/** +* nfs4_get_setclientid_cred - Acquire credential for a setclientid operation +* @clp: client state handle +* +* Returns an rpc_cred with reference count bumped, or NULL. +*/ +struct rpc_cred *nfs4_get_setclientid_cred (struct nfs_client *clp) +{ +struct nfs_server *server;struct rpc_cred *cred;
fs/nfs/nfs4state.c struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp) · line 269
Quoted 10 lines
fs/nfs/nfs4state.c +2
-4spin_lock (&clp->cl_lock); cred =nfs4_get_machine_cred_locked (clp);if (cred !=NULL ) goto out; - pos =rb_first (&clp->cl_state_owners); -if (pos !=NULL ) { - sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); - cred =get_rpccred (sp->so_cred); + +rcu_read_lock ();
Here's another rcu_read_lock() nested inside a spin locked section.
Quoted 216 lines
fs/nfs/nfs4state.c +57
-39+list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) { + cred =nfs4_get_setclientid_cred_server_locked (server); +if (cred !=NULL ) +break ; } +rcu_read_unlock (); + out:spin_unlock (&clp->cl_lock);return cred;@@ -286,16 +335,15 @@ static void nfs_free_unique_id(struct rb_root *root, struct nfs_unique_id *id) }static struct nfs4_state_owner * -nfs4_find_state_owner (struct nfs_server *server,struct rpc_cred *cred) +nfs4_find_state_owner_locked (struct nfs_server *server,struct rpc_cred *cred) { -struct nfs_client *clp = server->nfs_client; -struct rb_node **p = &clp->cl_state_owners.rb_node, +struct rb_node **p = &server->state_owners.rb_node, *parent =NULL ;struct nfs4_state_owner *sp, *res =NULL ;while (*p !=NULL ) { parent = *p; - sp = rb_entry(parent, struct nfs4_state_owner, so_client_node); + sp = rb_entry(parent, struct nfs4_state_owner, so_server_node);if (server < sp->so_server) { p = &parent->rb_left;@@ -319,24 +367,17 @@ nfs4_find_state_owner(struct nfs_server *server, struct rpc_cred *cred) }static struct nfs4_state_owner * -nfs4_insert_state_owner (struct nfs_client *clp,struct nfs4_state_owner *new) +nfs4_insert_state_owner_locked (struct nfs4_state_owner *new) { -struct rb_node **p = &clp->cl_state_owners.rb_node, +struct nfs_server *server = new->so_server; +struct rb_node **p = &server->state_owners.rb_node, *parent =NULL ;struct nfs4_state_owner *sp;while (*p !=NULL ) { parent = *p; - sp = rb_entry(parent, struct nfs4_state_owner, so_client_node); + sp = rb_entry(parent, struct nfs4_state_owner, so_server_node); -if (new->so_server < sp->so_server) { - p = &parent->rb_left; -continue ; - } -if (new->so_server > sp->so_server) { - p = &parent->rb_right; -continue ; - }if (new->so_cred < sp->so_cred) p = &parent->rb_left;else if (new->so_cred > sp->so_cred)@@ -346,18 +387,20 @@ nfs4_insert_state_owner(struct nfs_client *clp, struct nfs4_state_owner *new)return sp; } } -nfs_alloc_unique_id (&clp->cl_openowner_id, &new->so_owner_id,1 ,64 ); -rb_link_node (&new->so_client_node, parent, p); -rb_insert_color (&new->so_client_node, &clp->cl_state_owners); +nfs_alloc_unique_id (&server->openowner_id, &new->so_owner_id,1 ,64 ); +rb_link_node (&new->so_server_node, parent, p); +rb_insert_color (&new->so_server_node, &server->state_owners);return new; }static void -nfs4_remove_state_owner (struct nfs_client *clp,struct nfs4_state_owner *sp) +nfs4_remove_state_owner_locked (struct nfs4_state_owner *sp) { -if (!RB_EMPTY_NODE (&sp->so_client_node)) -rb_erase (&sp->so_client_node, &clp->cl_state_owners); -nfs_free_unique_id (&clp->cl_openowner_id, &sp->so_owner_id); +struct nfs_server *server = sp->so_server; + +if (!RB_EMPTY_NODE (&sp->so_server_node)) +rb_erase (&sp->so_server_node, &server->state_owners); +nfs_free_unique_id (&server->openowner_id, &sp->so_owner_id); }/* @@ -386,23 +429,32 @@ nfs4_alloc_state_owner(void)static void nfs4_drop_state_owner (struct nfs4_state_owner *sp) { -if (!RB_EMPTY_NODE (&sp->so_client_node)) { -struct nfs_client *clp = sp->so_server->nfs_client; +if (!RB_EMPTY_NODE (&sp->so_server_node)) { +struct nfs_server *server = sp->so_server; +struct nfs_client *clp = server->nfs_client;spin_lock (&clp->cl_lock); -rb_erase (&sp->so_client_node, &clp->cl_state_owners); -RB_CLEAR_NODE (&sp->so_client_node); +rb_erase (&sp->so_server_node, &server->state_owners); +RB_CLEAR_NODE (&sp->so_server_node);spin_unlock (&clp->cl_lock); } } -struct nfs4_state_owner *nfs4_get_state_owner (struct nfs_server *server,struct rpc_cred *cred) +/** +* nfs4_get_state_owner - Look up a state owner given a credential +* @server: nfs_server to search +* @cred: RPC credential to match +* +* Returns a pointer to an instantiated nfs4_state_owner struct, or NULL. +*/ +struct nfs4_state_owner *nfs4_get_state_owner (struct nfs_server *server, +struct rpc_cred *cred) {struct nfs_client *clp = server->nfs_client;struct nfs4_state_owner *sp, *new;spin_lock (&clp->cl_lock); - sp =nfs4_find_state_owner (server, cred); + sp =nfs4_find_state_owner_locked (server, cred);spin_unlock (&clp->cl_lock);if (sp !=NULL )return sp;@@ -412,7 +464,7 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct new->so_server = server; new->so_cred = cred;spin_lock (&clp->cl_lock); - sp =nfs4_insert_state_owner (clp, new); + sp =nfs4_insert_state_owner_locked (new);spin_unlock (&clp->cl_lock);if (sp == new)get_rpccred (cred);@@ -423,6 +475,11 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, structreturn sp; } +/** +* nfs4_put_state_owner - Release a nfs4_state_owner +* @sp: state owner data to release +* +*/ void nfs4_put_state_owner (struct nfs4_state_owner *sp) {struct nfs_client *clp = sp->so_server->nfs_client;@@ -430,7 +487,7 @@ void nfs4_put_state_owner(struct nfs4_state_owner *sp)if (!atomic_dec_and_lock (&sp->so_count, &clp->cl_lock))return ; -nfs4_remove_state_owner (clp, sp); +nfs4_remove_state_owner_locked (sp);spin_unlock (&clp->cl_lock);rpc_destroy_wait_queue (&sp->so_sequence.wait);put_rpccred (cred);@@ -633,7 +690,8 @@ __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pstatic struct nfs4_lock_state *nfs4_alloc_lock_state (struct nfs4_state *state,fl_owner_t fl_owner,pid_t fl_pid,unsigned int type) {struct nfs4_lock_state *lsp; -struct nfs_client *clp = state->owner->so_server->nfs_client; +struct nfs_server *server = state->owner->so_server; +struct nfs_client *clp = server->nfs_client; lsp =kzalloc (sizeof (*lsp),GFP_NOFS );if (lsp ==NULL )@@ -657,7 +715,7 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, freturn NULL ; }spin_lock (&clp->cl_lock); -nfs_alloc_unique_id (&clp->cl_lockowner_id, &lsp->ls_id,1 ,64 ); +nfs_alloc_unique_id (&server->lockowner_id, &lsp->ls_id,1 ,64 );spin_unlock (&clp->cl_lock);INIT_LIST_HEAD (&lsp->ls_locks);return lsp;@@ -665,10 +723,11 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fstatic void nfs4_free_lock_state (struct nfs4_lock_state *lsp) { -struct nfs_client *clp = lsp->ls_state->owner->so_server->nfs_client; +struct nfs_server *server = lsp->ls_state->owner->so_server; +struct nfs_client *clp = server->nfs_client;spin_lock (&clp->cl_lock); -nfs_free_unique_id (&clp->cl_lockowner_id, &lsp->ls_id); +nfs_free_unique_id (&server->lockowner_id, &lsp->ls_id);spin_unlock (&clp->cl_lock);rpc_destroy_wait_queue (&lsp->ls_sequence.wait);kfree (lsp);@@ -1114,25 +1173,40 @@ static void nfs4_clear_open_state(struct nfs4_state *state) } } -static void nfs4_state_mark_reclaim_helper (struct nfs_client *clp,int (*mark_reclaim)(struct nfs_client *clp,struct nfs4_state *state)) +static void nfs4_reset_seqids_locked (struct nfs_server *server, +int (*mark_reclaim)(struct nfs_client *clp,struct nfs4_state *state)) {struct nfs4_state_owner *sp;struct rb_node *pos;struct nfs4_state *state; -/* Reset all sequence ids to zero */ -for (pos =rb_first (&clp->cl_state_owners); pos !=NULL ; pos =rb_next (pos)) { - sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); +for (pos =rb_first (&server->state_owners); + pos !=NULL ; + pos =rb_next (pos)) { + sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); sp->so_seqid.flags =0 ;spin_lock (&sp->so_lock);list_for_each_entry (state, &sp->so_states, open_states) { -if (mark_reclaim (clp, state)) +if (mark_reclaim (server->nfs_client, state))nfs4_clear_open_state (state); }spin_unlock (&sp->so_lock);
fs/nfs/nfs4state.c static void nfs4_clear_open_state(struct nfs4_state *state) · line 1203
Quoted 10 lines
fs/nfs/nfs4state.c +7
-0} } +static void nfs4_state_mark_reclaim_helper (struct nfs_client *clp, +int (*mark_reclaim)(struct nfs_client *clp,struct nfs4_state *state)) +{ +struct nfs_server *server; + +spin_lock (&clp->cl_lock); +rcu_read_lock ();
Ditto.
Quoted 46 lines
fs/nfs/nfs4state.c +19
-8+list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) +nfs4_reset_seqids_locked (server, mark_reclaim); +rcu_read_unlock (); +spin_unlock (&clp->cl_lock); +} +static void nfs4_state_start_reclaim_reboot (struct nfs_client *clp) {/* Mark all delegations for reclaim */ @@ -1148,26 +1222,42 @@ static void nfs4_reclaim_complete(struct nfs_client *clp, (void )ops->reclaim_complete (clp); } -static int nfs4_state_clear_reclaim_reboot (struct nfs_client *clp) +static void nfs4_clear_reclaim_server_locked (struct nfs_server *server) {struct nfs4_state_owner *sp;struct rb_node *pos;struct nfs4_state *state; -if (!test_and_clear_bit (NFS4CLNT_RECLAIM_REBOOT , &clp->cl_state)) -return 0 ; - -for (pos =rb_first (&clp->cl_state_owners); pos !=NULL ; pos =rb_next (pos)) { - sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); +for (pos =rb_first (&server->state_owners); + pos !=NULL ; + pos =rb_next (pos)) { + sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);spin_lock (&sp->so_lock);list_for_each_entry (state, &sp->so_states, open_states) { -if (!test_and_clear_bit (NFS_STATE_RECLAIM_REBOOT , &state->flags)) +if (!test_and_clear_bit (NFS_STATE_RECLAIM_REBOOT , + &state->flags))continue ; -nfs4_state_mark_reclaim_nograce (clp, state); +nfs4_state_mark_reclaim_nograce (server->nfs_client, + state); }spin_unlock (&sp->so_lock); } +} + +static int nfs4_state_clear_reclaim_reboot (struct nfs_client *clp) +{
fs/nfs/nfs4state.c static void nfs4_reclaim_complete(struct nfs_client *clp, · line 1259
Quoted 10 lines
fs/nfs/nfs4state.c +10
-0+struct nfs_server *server; + +if (!test_and_clear_bit (NFS4CLNT_RECLAIM_REBOOT , &clp->cl_state)) +return 0 ; + +spin_lock (&clp->cl_lock); +rcu_read_lock (); +list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) +nfs4_clear_reclaim_server_locked (server); +rcu_read_unlock ();
Ditto
Quoted 15 lines
fs/nfs/nfs4state.c +3
-0+spin_unlock (&clp->cl_lock);nfs_delegation_reap_unclaimed (clp);return 1 ; }@@ -1238,26 +1328,39 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)static int nfs4_do_reclaim (struct nfs_client *clp,const struct nfs4_state_recovery_ops *ops) { +struct nfs4_state_owner *sp; +struct nfs_server *server;struct rb_node *pos;int status =0 ; restart:spin_lock (&clp->cl_lock);
fs/nfs/nfs4state.c static int nfs4_recovery_handle_error(struct nfs_client *clp, int error) · line 1338
Quoted 10 lines
fs/nfs/nfs4state.c +1
-9-for (pos =rb_first (&clp->cl_state_owners); pos !=NULL ; pos =rb_next (pos)) { - struct nfs4_state_owner *sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); -if (!test_and_clear_bit (ops->owner_flag_bit, &sp->so_flags)) -continue ; -atomic_inc (&sp->so_count); -spin_unlock (&clp->cl_lock); - status =nfs4_reclaim_open_state (sp, ops); -if (status <0 ) { -set_bit (ops->owner_flag_bit, &sp->so_flags); +rcu_read_lock ();
Ditto.
Quoted 60 lines
fs/nfs/nfs4state.c +22
-3+list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) { +for (pos =rb_first (&server->state_owners); + pos !=NULL ; + pos =rb_next (pos)) { + sp =rb_entry (pos, + struct nfs4_state_owner, so_server_node); +if (!test_and_clear_bit (ops->owner_flag_bit, + &sp->so_flags)) +continue ; +atomic_inc (&sp->so_count); +rcu_read_unlock (); +spin_unlock (&clp->cl_lock); + + status =nfs4_reclaim_open_state (sp, ops); +if (status <0 ) { +set_bit (ops->owner_flag_bit, &sp->so_flags); +nfs4_put_state_owner (sp); +return nfs4_recovery_handle_error (clp, status); + } +nfs4_put_state_owner (sp); -return nfs4_recovery_handle_error (clp, status); + goto restart; } -nfs4_put_state_owner (sp); - goto restart; } +rcu_read_unlock ();spin_unlock (&clp->cl_lock);return status; }include/linux/nfs_fs_sb.h +5
-4@@ -47,11 +47,7 @@ struct nfs_client {u64 cl_clientid;/* constant */ unsigned long cl_state; -struct rb_root cl_openowner_id; -struct rb_root cl_lockowner_id; -struct list_head cl_delegations; -struct rb_root cl_state_owners;spinlock_t cl_lock;unsigned long cl_lease_time;@@ -148,6 +144,11 @@ struct nfs_server {that are supported on this filesystem */ struct pnfs_layoutdriver_type *pnfs_curr_ld;/* Active layout driver */ + +/* the following fields are protected by nfs_client->cl_lock */ +struct rb_root state_owners; +struct rb_root openowner_id; +struct rb_root lockowner_id;#endif void (*destroy)(struct nfs_server *);
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Re: [PATCH 2/4] NFS: Move cl_state_owners and related fields to the nfs_server struct
Quoted 61 lines · Trond Myklebust
Quoted 60 lines · Chuck Lever
NFSv4 migration needs to reassociate state owners from the source to the destination
nfs_serverdata structures. To make that easier, move thecl_state_ownersfield to thenfs_serverstruct.cl_openowner_idandcl_lockowner_idaccompany this move, as they are used in conjunction withcl_state_owners.The
cl_lockfield in the parentnfs_clientcontinues to protect all three of these fields.Signed-off-by Chuck Lever <[email protected]>---
fs/nfs/nfs4_fs.h | 2 fs/nfs/nfs4state.c | 239 ++++++++++++++++++++++++++++++++------------- include/linux/nfs_fs_sb.h | 9 +- 3 files changed, 177 insertions(+), 73 deletions(-)fs/nfs/nfs4_fs.h +1
-1@@ -109,7 +109,7 @@ struct nfs_unique_id {struct nfs4_state_owner {struct nfs_unique_id so_owner_id;struct nfs_server *so_server; -struct rb_node so_client_node; +struct rb_node so_server_node;struct rpc_cred *so_cred;/* Associated cred */ fs/nfs/nfs4state.c +7
-4@@ -105,14 +105,17 @@ static void nfs4_clear_machine_cred(struct nfs_client *clp)put_rpccred (cred); } -struct rpc_cred *nfs4_get_renew_cred_locked (struct nfs_client *clp) +static struct rpc_cred * +nfs4_get_renew_cred_server_locked (struct nfs_server *server) { +struct rpc_cred *cred =NULL ;struct nfs4_state_owner *sp;struct rb_node *pos; -struct rpc_cred *cred =NULL ; -for (pos =rb_first (&clp->cl_state_owners); pos !=NULL ; pos =rb_next (pos)) { - sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); +for (pos =rb_first (&server->state_owners); + pos !=NULL ; + pos =rb_next (pos)) { + sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);if (list_empty (&sp->so_states))continue ; cred =get_rpccred (sp->so_cred);@@ -121,6 +124,28 @@ struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)return cred; }
Quoted 6 lines
fs/nfs/nfs4state.c struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp) · line 132
Quoted 6 lines
fs/nfs/nfs4state.c +6
-0+/** +* nfs4_get_renew_cred_locked - Acquire credential for a renew operation +* @clp: client state handle +* +* Returns an rpc_cred with reference count bumped, or NULL. +* Caller must hold clp->cl_lock.
Here's a case where clp->cl_lock will always be held before we invoke rcu_read_lock(). This is why I tried to take cl_lock first, then invoke rcu_read_lock(). I guess that's not a valid concern.
Quoted 50 lines
Quoted 50 lines
fs/nfs/nfs4state.c +37
-1+*/ +struct rpc_cred *nfs4_get_renew_cred_locked (struct nfs_client *clp) +{ +struct rpc_cred *cred =NULL ; +struct nfs_server *server; + +rcu_read_lock (); +list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) { + cred =nfs4_get_renew_cred_server_locked (server); +if (cred !=NULL ) +break ; + } +rcu_read_unlock (); +return cred; +} +#if defined(CONFIG_NFS_V4_1 )static int nfs41_setup_state_renewal (struct nfs_client *clp)@@ -210,21 +235,45 @@ struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp)#endif /* CONFIG_NFS_V4_1 */ -struct rpc_cred *nfs4_get_setclientid_cred (struct nfs_client *clp) +static struct rpc_cred * +nfs4_get_setclientid_cred_server_locked (struct nfs_server *server) { +struct rpc_cred *cred =NULL ;struct nfs4_state_owner *sp;struct rb_node *pos; + + pos =rb_first (&server->state_owners); +if (pos !=NULL ) { + sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); + cred =get_rpccred (sp->so_cred); + } +return cred; +} + +/** +* nfs4_get_setclientid_cred - Acquire credential for a setclientid operation +* @clp: client state handle +* +* Returns an rpc_cred with reference count bumped, or NULL. +*/ +struct rpc_cred *nfs4_get_setclientid_cred (struct nfs_client *clp) +{ +struct nfs_server *server;struct rpc_cred *cred;
Quoted 12 lines
fs/nfs/nfs4state.c struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp) · line 269
Quoted 10 lines
fs/nfs/nfs4state.c +2
-4spin_lock (&clp->cl_lock); cred =nfs4_get_machine_cred_locked (clp);if (cred !=NULL ) goto out; - pos =rb_first (&clp->cl_state_owners); -if (pos !=NULL ) { - sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); - cred =get_rpccred (sp->so_cred); + +rcu_read_lock ();Here's another
rcu_read_lock()nested inside a spin locked section.
In this case, we're already holding cl_lock in order to call nfs4_get_machine_cred_locked(). Is it worth the extra logic to release the lock and then grab it repeatedly in the loop?
Quoted 220 lines
Quoted 220 lines
fs/nfs/nfs4state.c +6
-0+list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) { + cred =nfs4_get_setclientid_cred_server_locked (server); +if (cred !=NULL ) +break ; } +rcu_read_unlock (); +out:
spin_unlock(&clp->cl_lock); return cred;fs/nfs/nfs4state.c +0
-0@@ -286,16 +335,15 @@ static void nfs_free_unique_id(struct rb_root *root, struct nfs_unique_id *id) }static struct
nfs4_state_owner*fs/nfs/nfs4state.c +1
-1-nfs4_find_state_owner(struct nfs_server *server, struct rpc_cred *cred) +nfs4_find_state_owner_locked(struct nfs_server *server, struct rpc_cred *cred){
fs/nfs/nfs4state.c +1
-2-struct nfs_client *clp = server->nfs_client; - struct rb_node **p = &clp->cl_state_owners.rb_node, + struct rb_node **p = &server->state_owners.rb_node,*parent = NULL; struct nfs4_state_owner *sp, *res = NULL; while (*p != NULL) { parent = *p;fs/nfs/nfs4state.c +1
-1- sp = rb_entry(parent, struct nfs4_state_owner, so_client_node); + sp = rb_entry(parent, struct nfs4_state_owner, so_server_node);if (server < sp->so_server) { p = &parent->rb_left;fs/nfs/nfs4state.c +0
-0@@ -319,24 +367,17 @@ nfs4_find_state_owner(struct nfs_server *server, struct rpc_cred *cred) }static struct
nfs4_state_owner*fs/nfs/nfs4state.c +1
-1-nfs4_insert_state_owner(struct nfs_client *clp, struct nfs4_state_owner *new) +nfs4_insert_state_owner_locked(struct nfs4_state_owner *new){
fs/nfs/nfs4state.c +2
-1- struct rb_node **p = &clp->cl_state_owners.rb_node, +struct nfs_server *server = new->so_server; + struct rb_node **p = &server->state_owners.rb_node,*parent = NULL; struct nfs4_state_owner *sp; while (*p != NULL) { parent = *p;fs/nfs/nfs4state.c +1
-9- sp = rb_entry(parent, struct nfs4_state_owner, so_client_node); + sp = rb_entry(parent, struct nfs4_state_owner, so_server_node); -if (new->so_server < sp->so_server) { - p = &parent->rb_left; -continue ; - } -if (new->so_server > sp->so_server) { - p = &parent->rb_right; -continue ; - }if (new->so_cred < sp->so_cred) p = &parent->rb_left; else if (new->so_cred > sp->so_cred)fs/nfs/nfs4state.c +3
-3@@ -346,18 +387,20 @@ nfs4_insert_state_owner(struct nfs_client *clp, struct nfs4_state_owner *new)return sp; } } -nfs_alloc_unique_id (&clp->cl_openowner_id, &new->so_owner_id,1 ,64 ); -rb_link_node (&new->so_client_node, parent, p); -rb_insert_color (&new->so_client_node, &clp->cl_state_owners); +nfs_alloc_unique_id (&server->openowner_id, &new->so_owner_id,1 ,64 ); +rb_link_node (&new->so_server_node, parent, p); +rb_insert_color (&new->so_server_node, &server->state_owners);return new; }static void
fs/nfs/nfs4state.c +1
-1-nfs4_remove_state_owner(struct nfs_client *clp, struct nfs4_state_owner *sp) +nfs4_remove_state_owner_locked(struct nfs4_state_owner *sp){
fs/nfs/nfs4state.c +5
-3-if (!RB_EMPTY_NODE (&sp->so_client_node)) -rb_erase (&sp->so_client_node, &clp->cl_state_owners); -nfs_free_unique_id (&clp->cl_openowner_id, &sp->so_owner_id); +struct nfs_server *server = sp->so_server; + +if (!RB_EMPTY_NODE (&sp->so_server_node)) +rb_erase (&sp->so_server_node, &server->state_owners); +nfs_free_unique_id (&server->openowner_id, &sp->so_owner_id);}
/*
fs/nfs/nfs4state.c +0
-0@@ -386,23 +429,32 @@ nfs4_alloc_state_owner(void)static void
nfs4_drop_state_owner(struct nfs4_state_owner *sp){fs/nfs/nfs4state.c +3
-2-if (!RB_EMPTY_NODE (&sp->so_client_node)) { -struct nfs_client *clp = sp->so_server->nfs_client; +if (!RB_EMPTY_NODE (&sp->so_server_node)) { +struct nfs_server *server = sp->so_server; +struct nfs_client *clp = server->nfs_client;spin_lock(&clp->cl_lock);fs/nfs/nfs4state.c +2
-2-rb_erase (&sp->so_client_node, &clp->cl_state_owners); -RB_CLEAR_NODE (&sp->so_client_node); +rb_erase (&sp->so_server_node, &server->state_owners); +RB_CLEAR_NODE (&sp->so_server_node);spin_unlock(&clp->cl_lock); } }fs/nfs/nfs4state.c +9
-1-struct nfs4_state_owner *nfs4_get_state_owner (struct nfs_server *server,struct rpc_cred *cred) +/** +* nfs4_get_state_owner - Look up a state owner given a credential +* @server: nfs_server to search +* @cred: RPC credential to match +* +* Returns a pointer to an instantiated nfs4_state_owner struct, or NULL. +*/ +struct nfs4_state_owner *nfs4_get_state_owner (struct nfs_server *server, +struct rpc_cred *cred){ struct nfs_client *clp = server->nfs_client; struct nfs4_state_owner *sp, *new; spin_lock(&clp->cl_lock);fs/nfs/nfs4state.c +1
-1- sp =nfs4_find_state_owner (server, cred); + sp =nfs4_find_state_owner_locked (server, cred);spin_unlock(&clp->cl_lock); if (sp != NULL) return sp;fs/nfs/nfs4state.c +20
-11@@ -412,7 +464,7 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct new->so_server = server; new->so_cred = cred;spin_lock (&clp->cl_lock); - sp =nfs4_insert_state_owner (clp, new); + sp =nfs4_insert_state_owner_locked (new);spin_unlock (&clp->cl_lock);if (sp == new)get_rpccred (cred);@@ -423,6 +475,11 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, structreturn sp; } +/** +* nfs4_put_state_owner - Release a nfs4_state_owner +* @sp: state owner data to release +* +*/ void nfs4_put_state_owner (struct nfs4_state_owner *sp) {struct nfs_client *clp = sp->so_server->nfs_client;@@ -430,7 +487,7 @@ void nfs4_put_state_owner(struct nfs4_state_owner *sp)if (!atomic_dec_and_lock (&sp->so_count, &clp->cl_lock))return ; -nfs4_remove_state_owner (clp, sp); +nfs4_remove_state_owner_locked (sp);spin_unlock (&clp->cl_lock);rpc_destroy_wait_queue (&sp->so_sequence.wait);put_rpccred (cred);@@ -633,7 +690,8 @@ __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pstatic struct nfs4_lock_state *nfs4_alloc_lock_state (struct nfs4_state *state,fl_owner_t fl_owner,pid_t fl_pid,unsigned int type) {struct nfs4_lock_state *lsp; -struct nfs_client *clp = state->owner->so_server->nfs_client; +struct nfs_server *server = state->owner->so_server; +struct nfs_client *clp = server->nfs_client; lsp =kzalloc (sizeof (*lsp),GFP_NOFS );if (lsp ==NULL )@@ -657,7 +715,7 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, freturn NULL ; }spin_lock (&clp->cl_lock); -nfs_alloc_unique_id (&clp->cl_lockowner_id, &lsp->ls_id,1 ,64 ); +nfs_alloc_unique_id (&server->lockowner_id, &lsp->ls_id,1 ,64 );spin_unlock (&clp->cl_lock);INIT_LIST_HEAD (&lsp->ls_locks);return lsp;@@ -665,10 +723,11 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fstatic void nfs4_free_lock_state (struct nfs4_lock_state *lsp) { -struct nfs_client *clp = lsp->ls_state->owner->so_server->nfs_client; +struct nfs_server *server = lsp->ls_state->owner->so_server; +struct nfs_client *clp = server->nfs_client;spin_lock (&clp->cl_lock); -nfs_free_unique_id (&clp->cl_lockowner_id, &lsp->ls_id); +nfs_free_unique_id (&server->lockowner_id, &lsp->ls_id);spin_unlock (&clp->cl_lock);rpc_destroy_wait_queue (&lsp->ls_sequence.wait);kfree (lsp);@@ -1114,25 +1173,40 @@ static void nfs4_clear_open_state(struct nfs4_state *state) } } -static void nfs4_state_mark_reclaim_helper (struct nfs_client *clp,int (*mark_reclaim)(struct nfs_client *clp,struct nfs4_state *state)) +static void nfs4_reset_seqids_locked (struct nfs_server *server, +int (*mark_reclaim)(struct nfs_client *clp,struct nfs4_state *state)) {struct nfs4_state_owner *sp;struct rb_node *pos;struct nfs4_state *state; -/* Reset all sequence ids to zero */ -for (pos =rb_first (&clp->cl_state_owners); pos !=NULL ; pos =rb_next (pos)) { - sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); +for (pos =rb_first (&server->state_owners); + pos !=NULL ; + pos =rb_next (pos)) { + sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); sp->so_seqid.flags =0 ;spin_lock (&sp->so_lock);list_for_each_entry (state, &sp->so_states, open_states) { -if (mark_reclaim (clp, state)) +if (mark_reclaim (server->nfs_client, state))nfs4_clear_open_state (state); }spin_unlock (&sp->so_lock); } }
Quoted 9 lines
fs/nfs/nfs4state.c static void nfs4_clear_open_state(struct nfs4_state *state) · line 1203
Quoted 7 lines
fs/nfs/nfs4state.c +7
-0+static void nfs4_state_mark_reclaim_helper (struct nfs_client *clp, +int (*mark_reclaim)(struct nfs_client *clp,struct nfs4_state *state)) +{ +struct nfs_server *server; + +spin_lock (&clp->cl_lock); +rcu_read_lock ();Ditto.
One begins to wonder if we should have a per-nfs_server lock for the state_owners fields, instead of re-using cl_lock. Such a lock would probably have to protect sp->so_cred as well.
Quoted 156 lines
Quoted 47 lines
fs/nfs/nfs4state.c +19
-8+list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) +nfs4_reset_seqids_locked (server, mark_reclaim); +rcu_read_unlock (); +spin_unlock (&clp->cl_lock); +} +static void nfs4_state_start_reclaim_reboot (struct nfs_client *clp) {/* Mark all delegations for reclaim */ @@ -1148,26 +1222,42 @@ static void nfs4_reclaim_complete(struct nfs_client *clp, (void )ops->reclaim_complete (clp); } -static int nfs4_state_clear_reclaim_reboot (struct nfs_client *clp) +static void nfs4_clear_reclaim_server_locked (struct nfs_server *server) {struct nfs4_state_owner *sp;struct rb_node *pos;struct nfs4_state *state; -if (!test_and_clear_bit (NFS4CLNT_RECLAIM_REBOOT , &clp->cl_state)) -return 0 ; - -for (pos =rb_first (&clp->cl_state_owners); pos !=NULL ; pos =rb_next (pos)) { - sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); +for (pos =rb_first (&server->state_owners); + pos !=NULL ; + pos =rb_next (pos)) { + sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);spin_lock (&sp->so_lock);list_for_each_entry (state, &sp->so_states, open_states) { -if (!test_and_clear_bit (NFS_STATE_RECLAIM_REBOOT , &state->flags)) +if (!test_and_clear_bit (NFS_STATE_RECLAIM_REBOOT , + &state->flags))continue ; -nfs4_state_mark_reclaim_nograce (clp, state); +nfs4_state_mark_reclaim_nograce (server->nfs_client, + state); }spin_unlock (&sp->so_lock); } +} + +static int nfs4_state_clear_reclaim_reboot (struct nfs_client *clp) +{fs/nfs/nfs4state.c static void nfs4_reclaim_complete(struct nfs_client *clp, · line 1259
Quoted 10 lines
fs/nfs/nfs4state.c +10
-0+struct nfs_server *server; + +if (!test_and_clear_bit (NFS4CLNT_RECLAIM_REBOOT , &clp->cl_state)) +return 0 ; + +spin_lock (&clp->cl_lock); +rcu_read_lock (); +list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) +nfs4_clear_reclaim_server_locked (server); +rcu_read_unlock ();Ditto
Quoted 15 lines
fs/nfs/nfs4state.c +3
-0+spin_unlock (&clp->cl_lock);nfs_delegation_reap_unclaimed (clp);return 1 ; }@@ -1238,26 +1328,39 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)static int nfs4_do_reclaim (struct nfs_client *clp,const struct nfs4_state_recovery_ops *ops) { +struct nfs4_state_owner *sp; +struct nfs_server *server;struct rb_node *pos;int status =0 ;restart:
spin_lock(&clp->cl_lock);fs/nfs/nfs4state.c static int nfs4_recovery_handle_error(struct nfs_client *clp, int error) · line 1338
Quoted 10 lines
fs/nfs/nfs4state.c +1
-9-for (pos =rb_first (&clp->cl_state_owners); pos !=NULL ; pos =rb_next (pos)) { - struct nfs4_state_owner *sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); -if (!test_and_clear_bit (ops->owner_flag_bit, &sp->so_flags)) -continue ; -atomic_inc (&sp->so_count); -spin_unlock (&clp->cl_lock); - status =nfs4_reclaim_open_state (sp, ops); -if (status <0 ) { -set_bit (ops->owner_flag_bit, &sp->so_flags); +rcu_read_lock ();Ditto.
Quoted 60 lines
fs/nfs/nfs4state.c +20
-0+list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) { +for (pos =rb_first (&server->state_owners); + pos !=NULL ; + pos =rb_next (pos)) { + sp =rb_entry (pos, + struct nfs4_state_owner, so_server_node); +if (!test_and_clear_bit (ops->owner_flag_bit, + &sp->so_flags)) +continue ; +atomic_inc (&sp->so_count); +rcu_read_unlock (); +spin_unlock (&clp->cl_lock); + + status =nfs4_reclaim_open_state (sp, ops); +if (status <0 ) { +set_bit (ops->owner_flag_bit, &sp->so_flags); +nfs4_put_state_owner (sp); +return nfs4_recovery_handle_error (clp, status); + } +nfs4_put_state_owner(sp);fs/nfs/nfs4state.c +1
-1-return nfs4_recovery_handle_error (clp, status); + goto restart;}fs/nfs/nfs4state.c +0
-2-nfs4_put_state_owner (sp); - goto restart;}fs/nfs/nfs4state.c +1
-0+rcu_read_unlock ();spin_unlock(&clp->cl_lock); return status; }include/linux/nfs_fs_sb.h +5
-4@@ -47,11 +47,7 @@ struct nfs_client {u64 cl_clientid;/* constant */ unsigned long cl_state; -struct rb_root cl_openowner_id; -struct rb_root cl_lockowner_id; -struct list_head cl_delegations; -struct rb_root cl_state_owners;spinlock_t cl_lock;unsigned long cl_lease_time;@@ -148,6 +144,11 @@ struct nfs_server {that are supported on this filesystem */ struct pnfs_layoutdriver_type *pnfs_curr_ld;/* Active layout driver */ + +/* the following fields are protected by nfs_client->cl_lock */ +struct rb_root state_owners; +struct rb_root openowner_id; +struct rb_root lockowner_id;#endif void (*destroy)(struct nfs_server *);Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
Re: [PATCH 2/4] NFS: Move cl_state_owners and related fields to the nfs_server struct
Quoted 135 lines · Chuck Lever
Quoted 61 lines · Trond Myklebust
Quoted 60 lines · Chuck Lever
NFSv4 migration needs to reassociate state owners from the source to the destination
nfs_serverdata structures. To make that easier, move thecl_state_ownersfield to thenfs_serverstruct.cl_openowner_idandcl_lockowner_idaccompany this move, as they are used in conjunction withcl_state_owners.The
cl_lockfield in the parentnfs_clientcontinues to protect all three of these fields.Signed-off-by Chuck Lever <[email protected]>---
fs/nfs/nfs4_fs.h | 2 fs/nfs/nfs4state.c | 239 ++++++++++++++++++++++++++++++++------------- include/linux/nfs_fs_sb.h | 9 +- 3 files changed, 177 insertions(+), 73 deletions(-)fs/nfs/nfs4_fs.h +1
-1@@ -109,7 +109,7 @@ struct nfs_unique_id {struct nfs4_state_owner {struct nfs_unique_id so_owner_id;struct nfs_server *so_server; -struct rb_node so_client_node; +struct rb_node so_server_node;struct rpc_cred *so_cred;/* Associated cred */ fs/nfs/nfs4state.c +7
-4@@ -105,14 +105,17 @@ static void nfs4_clear_machine_cred(struct nfs_client *clp)put_rpccred (cred); } -struct rpc_cred *nfs4_get_renew_cred_locked (struct nfs_client *clp) +static struct rpc_cred * +nfs4_get_renew_cred_server_locked (struct nfs_server *server) { +struct rpc_cred *cred =NULL ;struct nfs4_state_owner *sp;struct rb_node *pos; -struct rpc_cred *cred =NULL ; -for (pos =rb_first (&clp->cl_state_owners); pos !=NULL ; pos =rb_next (pos)) { - sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); +for (pos =rb_first (&server->state_owners); + pos !=NULL ; + pos =rb_next (pos)) { + sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);if (list_empty (&sp->so_states))continue ; cred =get_rpccred (sp->so_cred);@@ -121,6 +124,28 @@ struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)return cred; }Quoted 6 lines
fs/nfs/nfs4state.c struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp) · line 132
Quoted 6 lines
fs/nfs/nfs4state.c +6
-0+/** +* nfs4_get_renew_cred_locked - Acquire credential for a renew operation +* @clp: client state handle +* +* Returns an rpc_cred with reference count bumped, or NULL. +* Caller must hold clp->cl_lock. Here's a case where
clp->cl_lockwill always be held before we invokercu_read_lock(). This is why I tried to takecl_lockfirst, then invokercu_read_lock(). I guess that's not a valid concern.Quoted 50 lines
Quoted 50 lines
fs/nfs/nfs4state.c +37
-1+*/ +struct rpc_cred *nfs4_get_renew_cred_locked (struct nfs_client *clp) +{ +struct rpc_cred *cred =NULL ; +struct nfs_server *server; + +rcu_read_lock (); +list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) { + cred =nfs4_get_renew_cred_server_locked (server); +if (cred !=NULL ) +break ; + } +rcu_read_unlock (); +return cred; +} +#if defined(CONFIG_NFS_V4_1 )static int nfs41_setup_state_renewal (struct nfs_client *clp)@@ -210,21 +235,45 @@ struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp)#endif /* CONFIG_NFS_V4_1 */ -struct rpc_cred *nfs4_get_setclientid_cred (struct nfs_client *clp) +static struct rpc_cred * +nfs4_get_setclientid_cred_server_locked (struct nfs_server *server) { +struct rpc_cred *cred =NULL ;struct nfs4_state_owner *sp;struct rb_node *pos; + + pos =rb_first (&server->state_owners); +if (pos !=NULL ) { + sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); + cred =get_rpccred (sp->so_cred); + } +return cred; +} + +/** +* nfs4_get_setclientid_cred - Acquire credential for a setclientid operation +* @clp: client state handle +* +* Returns an rpc_cred with reference count bumped, or NULL. +*/ +struct rpc_cred *nfs4_get_setclientid_cred (struct nfs_client *clp) +{ +struct nfs_server *server;struct rpc_cred *cred;Quoted 12 lines
fs/nfs/nfs4state.c struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp) · line 269
Quoted 10 lines
fs/nfs/nfs4state.c +2
-4spin_lock (&clp->cl_lock); cred =nfs4_get_machine_cred_locked (clp);if (cred !=NULL ) goto out; - pos =rb_first (&clp->cl_state_owners); -if (pos !=NULL ) { - sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); - cred =get_rpccred (sp->so_cred); + +rcu_read_lock ();Here's another
rcu_read_lock()nested inside a spin locked section.
Quoted 1 line
In this case, we're already holding
cl_lockin order to callnfs4_get_machine_cred_locked(). Is it worth the extra logic to release the lock and then grab it repeatedly in the loop?
I'd prefer to just see the rcu_read_lock() moved outside the spin lock in situations like this. Doing so shouldn't make a difference to the performance, but it looks neater.
There are a couple of comments in code elsewhere that say that you shouldn't rely on rcu_read_lock() being the same as preempt_disable(), so I suppose we shouldn't get rid of it altogether.
Cheers
Trond
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
PATCH 3/4 NFS: Introduce nfs_detach_delegations()
In reply to Chuck LeverClean up: Refactor code that takes clp->cl_lock and calls nfs_detach_delegations_locked() into its own function.
While we're changing the call sites, get rid of the second parameter and the logic in nfs_detach_delegations_locked() that uses it, since callers always set that parameter of nfs_detach_delegations_locked() to NULL.
---
fs/nfs/delegation.c | 41 ++++++++++++++++++++--------------------- 1 files changed, 20 insertions(+), 21 deletions(-)
fs/nfs/delegation.c +20 -21
@@ -175,9 +175,9 @@ static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegationreturn inode; } -static struct nfs_delegation *nfs_detach_delegation_locked (struct nfs_inode *nfsi, -const nfs4_stateid *stateid, -struct nfs_client *clp) +static struct nfs_delegation * +nfs_detach_delegation_locked (struct nfs_inode *nfsi, +struct nfs_client *clp) {struct nfs_delegation *delegation = rcu_dereference_protected(nfsi->delegation,
@@ -185,22 +185,29 @@ static struct nfs_delegation *nfs_detach_delegation_locked(struct nfs_inode *nfsif (delegation ==NULL ) goto nomatch; +spin_lock (&delegation->lock); -if (stateid !=NULL &&memcmp (delegation->stateid.data, stateid->data, -sizeof (delegation->stateid.data)) !=0 ) - goto nomatch_unlock;list_del_rcu (&delegation->super_list); delegation->inode =NULL ; nfsi->delegation_state =0 ;rcu_assign_pointer (nfsi->delegation,NULL );spin_unlock (&delegation->lock);return delegation; -nomatch_unlock: -spin_unlock (&delegation->lock); nomatch:return NULL ; } +static struct nfs_delegation *nfs_detach_delegation (struct nfs_inode *nfsi, +struct nfs_client *clp) +{ +struct nfs_delegation *delegation; + +spin_lock (&clp->cl_lock); + delegation =nfs_detach_delegation_locked (nfsi, clp); +spin_unlock (&clp->cl_lock); +return delegation; +} +/* * Set up a delegation on an inode */
@@ -246,7 +253,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct delegation =NULL ; goto out; } - freeme =nfs_detach_delegation_locked (nfsi,NULL , clp); + freeme =nfs_detach_delegation_locked (nfsi, clp); }list_add_rcu (&delegation->super_list, &clp->cl_delegations); nfsi->delegation_state = delegation->type;
@@ -307,9 +314,7 @@ restart: inode =nfs_delegation_grab_inode (delegation);if (inode ==NULL )continue ; -spin_lock (&clp->cl_lock); - delegation =nfs_detach_delegation_locked (NFS_I (inode),NULL , clp); -spin_unlock (&clp->cl_lock); + delegation =nfs_detach_delegation (NFS_I (inode), clp);rcu_read_unlock ();if (delegation !=NULL ) {filemap_flush (inode->i_mapping);
@@ -338,9 +343,7 @@ void nfs_inode_return_delegation_noreclaim(struct inode *inode)struct nfs_delegation *delegation;if (rcu_access_pointer (nfsi->delegation) !=NULL ) { -spin_lock (&clp->cl_lock); - delegation =nfs_detach_delegation_locked (nfsi,NULL , clp); -spin_unlock (&clp->cl_lock); + delegation =nfs_detach_delegation (nfsi, clp);if (delegation !=NULL )nfs_do_return_delegation (inode, delegation,0 ); }
@@ -354,9 +357,7 @@ int nfs_inode_return_delegation(struct inode *inode)int err =0 ;if (rcu_access_pointer (nfsi->delegation) !=NULL ) { -spin_lock (&clp->cl_lock); - delegation =nfs_detach_delegation_locked (nfsi,NULL , clp); -spin_unlock (&clp->cl_lock); + delegation =nfs_detach_delegation (nfsi, clp);if (delegation !=NULL ) {nfs_wb_all (inode); err =__nfs_inode_return_delegation (inode, delegation,1 );
@@ -530,9 +531,7 @@ restart: inode =nfs_delegation_grab_inode (delegation);if (inode ==NULL )continue ; -spin_lock (&clp->cl_lock); - delegation =nfs_detach_delegation_locked (NFS_I (inode),NULL , clp); -spin_unlock (&clp->cl_lock); + delegation =nfs_detach_delegation (NFS_I (inode), clp);rcu_read_unlock ();if (delegation !=NULL )nfs_free_delegation (delegation);
PATCH 4/4 NFS: Move cl_delegations to the nfs_server struct
In reply to Chuck LeverDelegations are per-inode, not per-nfs_client. When a server file system is migrated, delegations on the client must be moved from the source to the destination nfs_server. Make it easier to manage a mount point's delegation list across a migration event by moving the list to the nfs_server struct.
Clean up: I added documenting comments to public functions I changed in this patch. For consistency I added comments to all the other public functions in fs/nfs/delegation.c.
---
fs/nfs/client.c | 4 - fs/nfs/delegation.c | 337 +++++++++++++++++++++++++++++++++------------ fs/nfs/delegation.h | 1 fs/nfs/nfs4renewd.c | 2 include/linux/nfs_fs_sb.h | 2 5 files changed, 253 insertions(+), 93 deletions(-)
fs/nfs/client.c +3 -1
@@ -144,7 +144,6 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_ clp->cl_proto = cl_init->proto;#ifdef CONFIG_NFS_V4 -INIT_LIST_HEAD (&clp->cl_delegations);spin_lock_init (&clp->cl_lock);INIT_DELAYED_WORK (&clp->cl_renewd, nfs4_renew_state);rpc_init_wait_queue (&clp->cl_rpcwaitq,"NFS client" );
@@ -1025,6 +1024,9 @@ static struct nfs_server *nfs_alloc_server(void)/* Zero out the NFS state stuff */ INIT_LIST_HEAD (&server->client_link);INIT_LIST_HEAD (&server->master_link); +#ifdef CONFIG_NFS_V4 +INIT_LIST_HEAD (&server->delegations); +#endif atomic_set (&server->active,0 );
fs/nfs/delegation.c +247 -90
547 lines not on this page · raw message
fs/nfs/delegation.h +1 -0
@@ -44,6 +44,7 @@ void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags);void nfs_expire_unreferenced_delegations (struct nfs_client *clp);void nfs_handle_cb_pathdown (struct nfs_client *clp);int nfs_client_return_marked_delegations (struct nfs_client *clp); +int nfs_delegations_present (struct nfs_client *clp);void nfs_delegation_mark_reclaim (struct nfs_client *clp);void nfs_delegation_reap_unclaimed (struct nfs_client *clp);
fs/nfs/nfs4renewd.c +1 -1
@@ -80,7 +80,7 @@ nfs4_renew_state(struct work_struct *work) cred = ops->get_state_renewal_cred_locked (clp);spin_unlock (&clp->cl_lock);if (cred ==NULL ) { -if (list_empty (&clp->cl_delegations)) { +if (!nfs_delegations_present (clp)) {set_bit (NFS4CLNT_LEASE_EXPIRED , &clp->cl_state); goto out; }
include/linux/nfs_fs_sb.h +1 -1
@@ -47,7 +47,6 @@ struct nfs_client {u64 cl_clientid;/* constant */ unsigned long cl_state; -struct list_head cl_delegations;spinlock_t cl_lock;unsigned long cl_lease_time;
@@ -149,6 +148,7 @@ struct nfs_server {struct rb_root state_owners;struct rb_root openowner_id;struct rb_root lockowner_id; +struct list_head delegations;#endif void (*destroy)(struct nfs_server *);
Re: [PATCH 4/4] NFS: Move cl_delegations to the nfs_server struct
Quoted 33 lines · Chuck Lever
Delegations are per-inode, not per-nfs_client. When a server file system is migrated, delegations on the client must be moved from the source to the destination
nfs_server. Make it easier to manage a mount point's delegation list across a migration event by moving the list to thenfs_serverstruct.Clean up: I added documenting comments to public functions I changed in this patch. For consistency I added comments to all the other public functions in
fs/nfs/delegation.c.Signed-off-by Chuck Lever <[email protected]>---
fs/nfs/client.c | 4 - fs/nfs/delegation.c | 337 +++++++++++++++++++++++++++++++++------------ fs/nfs/delegation.h | 1 fs/nfs/nfs4renewd.c | 2 include/linux/nfs_fs_sb.h | 2 5 files changed, 253 insertions(+), 93 deletions(-)fs/nfs/client.c +0
-1@@ -144,7 +144,6 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_ clp->cl_proto = cl_init->proto;#ifdef CONFIG_NFS_V4 -INIT_LIST_HEAD (&clp->cl_delegations);spin_lock_init (&clp->cl_lock);INIT_DELAYED_WORK (&clp->cl_renewd, nfs4_renew_state);rpc_init_wait_queue (&clp->cl_rpcwaitq,"NFS client" );
fs/nfs/client.c static struct nfs_server *nfs_alloc_server(void) · line 1029
Quoted 6 lines
fs/nfs/client.c +3
-0@@ -1025,6 +1024,9 @@ static struct nfs_server *nfs_alloc_server(void)/* Zero out the NFS state stuff */ INIT_LIST_HEAD (&server->client_link);INIT_LIST_HEAD (&server->master_link); +#ifdef CONFIG_NFS_V4 +INIT_LIST_HEAD (&server->delegations); +#endif
As I said earlier, can we please avoid this? Just define the 'delegations' field unconditionally in struct nfs_server, and get rid of the CONFIG_NFS_V4 above.
Cheers
Trond
Quoted 25 lines
fs/nfs/client.c +0
-0atomic_set (&server->active,0 );include/linux/nfs_fs_sb.h +1
-1@@ -47,7 +47,6 @@ struct nfs_client {u64 cl_clientid;/* constant */ unsigned long cl_state; -struct list_head cl_delegations;spinlock_t cl_lock;unsigned long cl_lease_time;@@ -149,6 +148,7 @@ struct nfs_server {struct rb_root state_owners;struct rb_root openowner_id;struct rb_root lockowner_id; +struct list_head delegations;#endif void (*destroy)(struct nfs_server *);
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
A message that is not in the archive (sent off-list or not yet received): 1293142182.9718.3.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org
Re: [PATCH 4/4] NFS: Move cl_delegations to the nfs_server struct
Quoted 28 lines · Trond Myklebust
Quoted 27 lines · Chuck Lever
Delegations are per-inode, not per-nfs_client. When a server file system is migrated, delegations on the client must be moved from the source to the destination
nfs_server. Make it easier to manage a mount point's delegation list across a migration event by moving the list to thenfs_serverstruct.Clean up: I added documenting comments to public functions I changed in this patch. For consistency I added comments to all the other public functions in
fs/nfs/delegation.c.Signed-off-by Chuck Lever <[email protected]>---
fs/nfs/client.c | 4 - fs/nfs/delegation.c | 337 +++++++++++++++++++++++++++++++++------------ fs/nfs/delegation.h | 1 fs/nfs/nfs4renewd.c | 2 include/linux/nfs_fs_sb.h | 2 5 files changed, 253 insertions(+), 93 deletions(-)fs/nfs/client.c +0
-0@@ -144,7 +144,6 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_ clp->cl_proto = cl_init->proto;
Quoted 16 lines
fs/nfs/client.c static struct nfs_server *nfs_alloc_server(void) · line 1029
Quoted 12 lines
fs/nfs/client.c +3
-1#ifdef CONFIG_NFS_V4 -INIT_LIST_HEAD (&clp->cl_delegations);spin_lock_init (&clp->cl_lock);INIT_DELAYED_WORK (&clp->cl_renewd, nfs4_renew_state);rpc_init_wait_queue (&clp->cl_rpcwaitq,"NFS client" );@@ -1025,6 +1024,9 @@ static struct nfs_server *nfs_alloc_server(void)/* Zero out the NFS state stuff */ INIT_LIST_HEAD (&server->client_link);INIT_LIST_HEAD (&server->master_link); +#ifdef CONFIG_NFS_V4 +INIT_LIST_HEAD (&server->delegations); +#endif As I said earlier, can we please avoid this? Just define the 'delegations' field unconditionally in struct
nfs_server, and get rid of theCONFIG_NFS_V4above.
Sorry, dude. I forgot that one.
Quoted 38 lines
Cheers
TrondQuoted 25 lines
fs/nfs/client.c +0
-0atomic_set (&server->active,0 );include/linux/nfs_fs_sb.h +1
-1@@ -47,7 +47,6 @@ struct nfs_client {u64 cl_clientid;/* constant */ unsigned long cl_state; -struct list_head cl_delegations;spinlock_t cl_lock;unsigned long cl_lease_time;@@ -149,6 +148,7 @@ struct nfs_server {struct rb_root state_owners;struct rb_root openowner_id;struct rb_root lockowner_id; +struct list_head delegations;#endif void (*destroy)(struct nfs_server *);Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com