Lockd: grace period containerization
Subsystems (3)
cover Lockd: grace period containerization
This patch set is marked with RFC, because I'm still not quite sure, that this implementation will satisfy other interested people.
So, would be appreciated for any comments.
This patch set makes grace period and hosts reclaiming network namespace aware.
Main ideas:
1) moving of
unsigned long next_gc; unsigned long nrhosts; struct delayed_work grace_period_end; struct lock_manager lockd_manager; struct list_head grace_list;
to per-net Lockd data.
2) moving of
struct lock_manager nfsd4_manager;
to per-net NFSd data.
3) shutdown + gc of NLM hosts done now network namespace aware.
4) restart_grace() now works only for init_net.
The following series implements...
---
Stanislav Kinsbursky (13):
LockD: mark host per network namespace on garbage collect
LockD: make garbage collector network namespace aware.
LockD: manage garbage collection timeout per networks namespace
LockD: manage used host count per networks namespace
Lockd: host complaining function introduced
Lockd: add more debug to host shutdown functions
LockD: manage grace period per network namespace
LockD: make lockd manager allocated per network namespace
NFSd: make nfsd4_manager allocated per network namespace context.
SUNRPC: service request network namespace helper introduced
LockD: manage grace list per network namespace
LockD: pass actual network namespace to grace period management functions
Lockd: move grace period management from lockd() to per-net functions
fs/lockd/grace.c | 16 +++++-- fs/lockd/host.c | 92 +++++++++++++++++++++++++++++-------------- fs/lockd/netns.h | 7 +++ fs/lockd/svc.c | 43 ++++++++++++-------- fs/lockd/svc4proc.c | 13 +++--- fs/lockd/svclock.c | 16 ++++--- fs/lockd/svcproc.c | 15 ++++--- fs/lockd/svcsubs.c | 19 ++++++--- fs/nfs/callback_xdr.c | 4 +- fs/nfsd/export.c | 4 +- fs/nfsd/netns.h | 2 + fs/nfsd/nfs4idmap.c | 4 +- fs/nfsd/nfs4proc.c | 18 +++++--- fs/nfsd/nfs4state.c | 60 ++++++++++++++++------------ fs/nfsd/state.h | 3 + include/linux/fs.h | 5 +- include/linux/lockd/lockd.h | 6 +-- include/linux/sunrpc/svc.h | 2 + 18 files changed, 204 insertions(+), 125 deletions(-)
RFC PATCH 1/13 LockD: mark host per network namespace on garbage collect
This is required for per-network NLM shutdown and cleanup. This patch passes init_net for a while.
--- fs/lockd/host.c | 3 ++- fs/lockd/svcsubs.c | 19 +++++++++++++------ include/linux/lockd/lockd.h | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-)
fs/lockd/host.c +2 -1
@@ -628,13 +628,14 @@ nlm_gc_hosts(void)struct hlist_head *chain;struct hlist_node *pos, *next;struct nlm_host *host; +struct net *net = &init_net;dprintk ("lockd: host garbage collection\n" );for_each_host (host, pos, chain, nlm_server_hosts) host->h_inuse =0 ;/* Mark all hosts that hold locks, blocks or shares */ -nlmsvc_mark_resources (); +nlmsvc_mark_resources (net);for_each_host_safe (host, pos, next, chain, nlm_server_hosts) { if (atomic_read(&host->h_count) || host->h_inuse
fs/lockd/svcsubs.c +13 -6
@@ -309,7 +309,8 @@ nlm_release_file(struct nlm_file *file)* Helpers function for resource traversal * * nlmsvc_mark_host: -* used by the garbage collector; simply sets h_inuse. +* used by the garbage collector; simply sets h_inuse only for those +* hosts, which passed network check. * Always returns 0. * * nlmsvc_same_host:
@@ -320,12 +321,15 @@ nlm_release_file(struct nlm_file *file)* returns 1 iff the host is a client. * Used by nlmsvc_invalidate_all */ +static int -nlmsvc_mark_host (void *data,struct nlm_host *dummy) +nlmsvc_mark_host (void *data,struct nlm_host *hint) {struct nlm_host *host = data; - host->h_inuse =1 ; +if ((hint->net ==NULL ) || + (host->net == hint->net)) + host->h_inuse =1 ;return 0 ; }
@@ -358,10 +362,13 @@ nlmsvc_is_client(void *data, struct nlm_host *dummy)* Mark all hosts that still hold resources */ void -nlmsvc_mark_resources (void ) +nlmsvc_mark_resources (struct net *net) { -dprintk ("lockd: nlmsvc_mark_resources\n" ); -nlm_traverse_files (NULL , nlmsvc_mark_host,NULL ); +struct nlm_host hint; + +dprintk ("lockd: nlmsvc_mark_resources for net %p\n" , net); + hint.net = net; +nlm_traverse_files (&hint, nlmsvc_mark_host,NULL ); }/*
include/linux/lockd/lockd.h +1 -1
@@ -279,7 +279,7 @@ void nlmsvc_release_call(struct nlm_rqst *);__be32 nlm_lookup_file (struct svc_rqst *,struct nlm_file **,struct nfs_fh *);void nlm_release_file (struct nlm_file *); -void nlmsvc_mark_resources (void ); +void nlmsvc_mark_resources (struct net *);void nlmsvc_free_host_resources (struct nlm_host *);void nlmsvc_invalidate_all (void );
RFC PATCH 2/13 LockD: make garbage collector network namespace aware.
In reply to Stanislav KinsburskyRefresh of diff-lockd-make-hosts-garbage-collect-check-per-net
--- fs/lockd/host.c | 22 +++++++++++++--------- 1 files changed, 13 insertions(+), 9 deletions(-)
fs/lockd/host.c +13 -9
@@ -45,7 +45,7 @@ static unsigned long next_gc;static unsigned long nrhosts;static DEFINE_MUTEX (nlm_host_mutex); -static void nlm_gc_hosts (void ); +static void nlm_gc_hosts (struct net *net);struct nlm_lookup_host_info {const int server;/* search for server|client */
@@ -345,7 +345,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,mutex_lock (&nlm_host_mutex);if (time_after_eq (jiffies, next_gc)) -nlm_gc_hosts (); +nlm_gc_hosts (net); chain = &nlm_server_hosts[nlm_hash_address (ni.sap)];hlist_for_each_entry (host, pos, chain, h_hash) {
@@ -588,7 +588,7 @@ nlm_shutdown_hosts_net(struct net *net) }/* Then, perform a garbage collection pass */ -nlm_gc_hosts (); +nlm_gc_hosts (net);mutex_unlock (&nlm_host_mutex); }
@@ -623,27 +623,31 @@ nlm_shutdown_hosts(void)* mark & sweep for resources held by remote clients. */ static void -nlm_gc_hosts (void ) +nlm_gc_hosts (struct net *net) {struct hlist_head *chain;struct hlist_node *pos, *next;struct nlm_host *host; -struct net *net = &init_net; -dprintk ("lockd: host garbage collection\n" ); -for_each_host (host, pos, chain, nlm_server_hosts) +dprintk ("lockd: host garbage collection for net %p\n" , net); +for_each_host (host, pos, chain, nlm_server_hosts) { +if (net && host->net != net) +continue ; host->h_inuse =0 ; + }/* Mark all hosts that hold locks, blocks or shares */ nlmsvc_mark_resources (net);for_each_host_safe (host, pos, next, chain, nlm_server_hosts) { +if (net && host->net != net) +continue ;if (atomic_read (&host->h_count) || host->h_inuse ||time_before (jiffies, host->h_expires)) {dprintk ("nlm_gc_hosts skipping %s " -"(cnt %d use %d exp %ld)\n" , +"(cnt %d use %d exp %ld net %p)\n" , host->h_name,atomic_read (&host->h_count), - host->h_inuse, host->h_expires); + host->h_inuse, host->h_expires, host->net);continue ; }nlm_destroy_host_locked (host);
RFC PATCH 3/13 LockD: manage garbage collection timeout per networks namespace
In reply to Stanislav KinsburskyThis patch moves next_gc to per-net data.
Note: passed network can be NULL (when Lockd kthread is exiting of Lockd module is removing).
--- fs/lockd/host.c | 12 +++++++++--- fs/lockd/netns.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-)
fs/lockd/host.c +9 -3
@@ -21,6 +21,8 @@#include <net/ipv6.h> +#include "netns.h" +#define NLMDBG_FACILITY NLMDBG_HOSTCACHE#define NLM_HOST_NRHASH 32#define NLM_HOST_REBIND (60 * HZ)
@@ -41,7 +43,6 @@ static struct hlist_head nlm_client_hosts[NLM_HOST_NRHASH];hlist_for_each_entry_safe ((host), (pos), (next), \ (chain), h_hash) -static unsigned long next_gc;static unsigned long nrhosts;static DEFINE_MUTEX (nlm_host_mutex);
@@ -337,6 +338,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp, .hostname_len = hostname_len, .net = net, }; +struct lockd_net *ln =net_generic (net, lockd_net_id); dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__, (int)hostname_len, hostname, rqstp->rq_vers,
@@ -344,7 +346,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,mutex_lock (&nlm_host_mutex); -if (time_after_eq (jiffies, next_gc)) +if (time_after_eq (jiffies, ln->next_gc))nlm_gc_hosts (net); chain = &nlm_server_hosts[nlm_hash_address (ni.sap)];
@@ -653,5 +655,9 @@ nlm_gc_hosts(struct net *net)nlm_destroy_host_locked (host); } - next_gc = jiffies +NLM_HOST_COLLECT ; +if (net) { +struct lockd_net *ln =net_generic (net, lockd_net_id); + + ln->next_gc = jiffies +NLM_HOST_COLLECT ; + } }
fs/lockd/netns.h +1 -0
@@ -5,6 +5,7 @@struct lockd_net {unsigned int nlmsvc_users; +unsigned long next_gc; };extern int lockd_net_id;
RFC PATCH 4/13 LockD: manage used host count per networks namespace
In reply to Stanislav KinsburskyThis patch introduces moves nrhosts in per-net data.
It also adds kernel warning to nlm_shutdown_hosts_net() about remaining hosts in specified network namespace context.
--- fs/lockd/host.c | 18 ++++++++++++++++++ fs/lockd/netns.h | 1 + 2 files changed, 19 insertions(+), 0 deletions(-)
fs/lockd/host.c +18 -0
@@ -173,6 +173,7 @@ out:static void nlm_destroy_host_locked (struct nlm_host *host) {struct rpc_clnt *clnt; +struct lockd_net *ln =net_generic (host->net, lockd_net_id);dprintk ("lockd: destroy host %s\n" , host->h_name);
@@ -189,6 +190,7 @@ static void nlm_destroy_host_locked(struct nlm_host *host)rpc_shutdown_client (clnt);kfree (host); + ln->nrhosts--; nrhosts--; }
@@ -229,6 +231,7 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,struct hlist_node *pos;struct nlm_host *host;struct nsm_handle *nsm =NULL ; +struct lockd_net *ln =net_generic (net, lockd_net_id); dprintk("lockd: %s(host='%s', vers=%u, proto=%s)\n", __func__, (hostname ? hostname : "<none>"), version,
@@ -263,6 +266,7 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, goto out;hlist_add_head (&host->h_hash, chain); + ln->nrhosts++; nrhosts++; dprintk("lockd: %s created host %s (%s)\n", __func__,
@@ -384,6 +388,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,memcpy (nlm_srcaddr (host), src_sap, src_len); host->h_srcaddrlen = src_len;hlist_add_head (&host->h_hash, chain); + ln->nrhosts++; nrhosts++; dprintk("lockd: %s created host %s (%s)\n",
@@ -592,6 +597,19 @@ nlm_shutdown_hosts_net(struct net *net)/* Then, perform a garbage collection pass */ nlm_gc_hosts (net);mutex_unlock (&nlm_host_mutex); + +/* complain if any hosts are left */ +if (net) { +struct lockd_net *ln =net_generic (net, lockd_net_id); + +printk (KERN_WARNING "lockd: couldn't shutdown host module for net %p!\n" , net); +dprintk ("lockd: %lu hosts left in net %p:\n" , ln->nrhosts, net); +for_each_host (host, pos, chain, nlm_server_hosts) { +dprintk (" %s (cnt %d use %d exp %ld net %p)\n" , + host->h_name,atomic_read (&host->h_count), + host->h_inuse, host->h_expires, host->net); + } + } }/*
fs/lockd/netns.h +1 -0
@@ -6,6 +6,7 @@struct lockd_net {unsigned int nlmsvc_users;unsigned long next_gc; +unsigned long nrhosts; };extern int lockd_net_id;
RFC PATCH 5/13 Lockd: host complaining function introduced
In reply to Stanislav KinsburskyJust a small cleanup.
--- fs/lockd/host.c | 57 +++++++++++++++++++++++++++++-------------------------- 1 files changed, 30 insertions(+), 27 deletions(-)
fs/lockd/host.c +30 -27
@@ -572,6 +572,35 @@ void nlm_host_rebooted(const struct nlm_reboot *info)nsm_release (nsm); } +static void nlm_complain_hosts (struct net *net) +{ +struct hlist_head *chain; +struct hlist_node *pos; +struct nlm_host *host; + +if (net) { +struct lockd_net *ln =net_generic (net, lockd_net_id); + +if (ln->nrhosts ==0 ) +return ; +printk (KERN_WARNING "lockd: couldn't shutdown host module for net %p!\n" , net); +dprintk ("lockd: %lu hosts left in net %p:\n" , ln->nrhosts, net); + }else { +if (nrhosts ==0 ) +return ; +printk (KERN_WARNING "lockd: couldn't shutdown host module!\n" ); +dprintk ("lockd: %lu hosts left:\n" , nrhosts); + } + +for_each_host (host, pos, chain, nlm_server_hosts) { +if (net && host->net != net) +continue ; +dprintk (" %s (cnt %d use %d exp %ld net %p)\n" , + host->h_name,atomic_read (&host->h_count), + host->h_inuse, host->h_expires, host->net); + } +} +void nlm_shutdown_hosts_net (struct net *net) {
@@ -598,18 +627,7 @@ nlm_shutdown_hosts_net(struct net *net)nlm_gc_hosts (net);mutex_unlock (&nlm_host_mutex); -/* complain if any hosts are left */ -if (net) { -struct lockd_net *ln =net_generic (net, lockd_net_id); - -printk (KERN_WARNING "lockd: couldn't shutdown host module for net %p!\n" , net); -dprintk ("lockd: %lu hosts left in net %p:\n" , ln->nrhosts, net); -for_each_host (host, pos, chain, nlm_server_hosts) { -dprintk (" %s (cnt %d use %d exp %ld net %p)\n" , - host->h_name,atomic_read (&host->h_count), - host->h_inuse, host->h_expires, host->net); - } - } +nlm_complain_hosts (net); }/*
@@ -619,22 +637,7 @@ nlm_shutdown_hosts_net(struct net *net)void nlm_shutdown_hosts (void ) { -struct hlist_head *chain; -struct hlist_node *pos; -struct nlm_host *host; -nlm_shutdown_hosts_net (NULL ); - -/* complain if any hosts are left */ -if (nrhosts !=0 ) { -printk (KERN_WARNING "lockd: couldn't shutdown host module!\n" ); -dprintk ("lockd: %lu hosts left:\n" , nrhosts); -for_each_host (host, pos, chain, nlm_server_hosts) { -dprintk (" %s (cnt %d use %d exp %ld net %p)\n" , - host->h_name,atomic_read (&host->h_count), - host->h_inuse, host->h_expires, host->net); - } - } }/*
RFC PATCH 6/13 Lockd: add more debug to host shutdown functions
In reply to Stanislav Kinsbursky--- fs/lockd/host.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/lockd/host.c +2 -2
@@ -608,11 +608,10 @@ nlm_shutdown_hosts_net(struct net *net)struct hlist_node *pos;struct nlm_host *host; -dprintk ("lockd: shutting down host module\n" );mutex_lock (&nlm_host_mutex);/* First, make all hosts eligible for gc */ -dprintk ("lockd: nuking all hosts...\n" ); +dprintk ("lockd: nuking all hosts in net %p...\n" , net);for_each_host (host, pos, chain, nlm_server_hosts) {if (net && host->net != net)continue ;
@@ -637,6 +636,7 @@ nlm_shutdown_hosts_net(struct net *net)void nlm_shutdown_hosts (void ) { +dprintk ("lockd: shutting down host module\n" );nlm_shutdown_hosts_net (NULL ); }
RFC PATCH 7/13 LockD: manage grace period per network namespace
In reply to Stanislav Kinsbursky--- fs/lockd/netns.h | 2 ++ fs/lockd/svc.c | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-)
fs/lockd/netns.h +2 -0
@@ -7,6 +7,8 @@ struct lockd_net {unsigned int nlmsvc_users;unsigned long next_gc;unsigned long nrhosts; + +struct delayed_work grace_period_end; };extern int lockd_net_id;
fs/lockd/svc.c +11 -6
@@ -95,21 +95,22 @@ static void grace_ender(struct work_struct *not_used)locks_end_grace (&lockd_manager); } -static DECLARE_DELAYED_WORK(grace_period_end, grace_ender); -static void set_grace_period (void ) {unsigned long grace_period =get_lockd_grace_period (); +struct lockd_net *ln =net_generic (&init_net, lockd_net_id);locks_start_grace (&lockd_manager); -cancel_delayed_work_sync (&grace_period_end); -schedule_delayed_work (&grace_period_end, grace_period); +cancel_delayed_work_sync (&ln->grace_period_end); +schedule_delayed_work (&ln->grace_period_end, grace_period); }static void restart_grace (void ) {if (nlmsvc_ops) { -cancel_delayed_work_sync (&grace_period_end); +struct lockd_net *ln =net_generic (&init_net, lockd_net_id); + +cancel_delayed_work_sync (&ln->grace_period_end);locks_end_grace (&lockd_manager);nlmsvc_invalidate_all ();set_grace_period ();
@@ -124,6 +125,7 @@ lockd(void *vrqstp) {int err =0 , preverr =0 ;struct svc_rqst *rqstp = vrqstp; +struct lockd_net *ln =net_generic (&init_net, lockd_net_id);/* try_to_freeze() is called from svc_recv() */ set_freezable ();
@@ -184,7 +186,7 @@ lockd(void *vrqstp)svc_process (rqstp); }flush_signals (current); -cancel_delayed_work_sync (&grace_period_end); +cancel_delayed_work_sync (&ln->grace_period_end);locks_end_grace (&lockd_manager);if (nlmsvc_ops)nlmsvc_invalidate_all ();
@@ -589,6 +591,9 @@ module_param(nlm_max_connections, uint, 0644);static int lockd_init_net (struct net *net) { +struct lockd_net *ln =net_generic (net, lockd_net_id); + +INIT_DELAYED_WORK (&ln->grace_period_end, grace_ender);return 0 ; }
RFC PATCH 8/13 LockD: make lockd manager allocated per network namespace
In reply to Stanislav Kinsbursky--- fs/lockd/netns.h | 2 ++ fs/lockd/svc.c | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-)
fs/lockd/netns.h +2 -0
@@ -1,6 +1,7 @@#ifndef __LOCKD_NETNS_H__#define __LOCKD_NETNS_H__ +#include <linux/fs.h> #include <net/netns/generic.h> struct lockd_net {
@@ -9,6 +10,7 @@ struct lockd_net {unsigned long nrhosts;struct delayed_work grace_period_end; +struct lock_manager lockd_manager; };extern int lockd_net_id;
fs/lockd/svc.c +10 -8
@@ -87,12 +87,14 @@ static unsigned long get_lockd_grace_period(void)return nlm_timeout *5 *HZ ; } -static struct lock_manager lockd_manager = { -}; - -static void grace_ender (struct work_struct *not_used) +static void grace_ender (struct work_struct *grace) { -locks_end_grace (&lockd_manager); + struct delayed_work *dwork = container_of(grace, struct delayed_work, + work); + struct lockd_net *ln = container_of(dwork, struct lockd_net, + grace_period_end); + +locks_end_grace (&ln->lockd_manager); }static void set_grace_period (void )
@@ -100,7 +102,7 @@ static void set_grace_period(void)unsigned long grace_period =get_lockd_grace_period ();struct lockd_net *ln =net_generic (&init_net, lockd_net_id); -locks_start_grace (&lockd_manager); +locks_start_grace (&ln->lockd_manager);cancel_delayed_work_sync (&ln->grace_period_end);schedule_delayed_work (&ln->grace_period_end, grace_period); }
@@ -111,7 +113,7 @@ static void restart_grace(void)struct lockd_net *ln =net_generic (&init_net, lockd_net_id);cancel_delayed_work_sync (&ln->grace_period_end); -locks_end_grace (&lockd_manager); +locks_end_grace (&ln->lockd_manager);nlmsvc_invalidate_all ();set_grace_period (); }
@@ -187,7 +189,7 @@ lockd(void *vrqstp) }flush_signals (current);cancel_delayed_work_sync (&ln->grace_period_end); -locks_end_grace (&lockd_manager); +locks_end_grace (&ln->lockd_manager);if (nlmsvc_ops)nlmsvc_invalidate_all ();nlm_shutdown_hosts ();
RFC PATCH 9/13 NFSd: make nfsd4_manager allocated per network namespace context.
In reply to Stanislav Kinsbursky--- fs/nfsd/netns.h | 2 ++ fs/nfsd/nfs4state.c | 32 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-)
fs/nfsd/netns.h +2 -0
@@ -34,6 +34,8 @@ struct nfsd_net {struct cache_detail *idtoname_cache;struct cache_detail *nametoid_cache; + +struct lock_manager nfsd4_manager; };extern int nfsd_net_id;
fs/nfsd/nfs4state.c +19 -13
@@ -44,6 +44,8 @@#include "vfs.h" #include "current_stateid.h" +#include "netns.h" +#define NFSDDBG_FACILITY NFSDDBG_PROC/* Globals */
@@ -3184,22 +3186,21 @@ out:return status; } -static struct lock_manager nfsd4_manager = { -}; -static bool grace_ended;static void -nfsd4_end_grace (void ) +nfsd4_end_grace (struct net *net) { +struct nfsd_net *nn =net_generic (net, nfsd_net_id); +/* do nothing if grace period already ended */ if (grace_ended)return ;dprintk ("NFSD: end of grace period\n" ); grace_ended = true; -nfsd4_record_grace_done (&init_net, boot_time); -locks_end_grace (&nfsd4_manager); +nfsd4_record_grace_done (net, boot_time); +locks_end_grace (&nn->nfsd4_manager);/* * Now that every NFSv4 client has had the chance to recover and * to see the (possibly new, possibly shorter) lease time, we
@@ -3222,7 +3223,7 @@ nfs4_laundromat(void)nfs4_lock_state ();dprintk ("NFSD: laundromat service - starting\n" ); -nfsd4_end_grace (); +nfsd4_end_grace (&init_net);INIT_LIST_HEAD (&reaplist);spin_lock (&client_lock);list_for_each_safe (pos, next, &client_lru) {
@@ -4743,6 +4744,8 @@ set_max_delegations(void)int nfs4_state_start (void ) { +struct net *net = &init_net; +struct nfsd_net *nn =net_generic (net, nfsd_net_id);int ret;/*
@@ -4752,10 +4755,10 @@ nfs4_state_start(void)* to that instead and then do most of the rest of this on a per-net * basis. */ -get_net (&init_net); -nfsd4_client_tracking_init (&init_net); +get_net (net); +nfsd4_client_tracking_init (net); boot_time =get_seconds (); -locks_start_grace (&nfsd4_manager); +locks_start_grace (&nn->nfsd4_manager); grace_ended = false;printk (KERN_INFO "NFSD: starting %ld-second grace period\n" , nfsd4_grace);
@@ -4778,8 +4781,8 @@ nfs4_state_start(void) out_free_laundry:destroy_workqueue (laundry_wq); out_recovery: -nfsd4_client_tracking_exit (&init_net); -put_net (&init_net); +nfsd4_client_tracking_exit (net); +put_net (net);return ret; }
@@ -4820,9 +4823,12 @@ __nfs4_state_shutdown(void)void nfs4_state_shutdown (void ) { +struct net *net = &init_net; +struct nfsd_net *nn =net_generic (net, nfsd_net_id); +cancel_delayed_work_sync (&laundromat_work);destroy_workqueue (laundry_wq); -locks_end_grace (&nfsd4_manager); +locks_end_grace (&nn->nfsd4_manager);nfs4_lock_state ();__nfs4_state_shutdown ();nfs4_unlock_state ();
RFC PATCH 10/13 SUNRPC: service request network namespace helper introduced
In reply to Stanislav KinsburskyThis is a cleanup patch - makes code looks simplier.
It replaces widely used rqstp->rq_xprt->xpt_net by introduced SVC_NET(rqstp).
--- fs/lockd/host.c | 2 +- fs/nfs/callback_xdr.c | 4 ++-- fs/nfsd/export.c | 4 ++-- fs/nfsd/nfs4idmap.c | 4 ++-- include/linux/sunrpc/svc.h | 2 ++ 5 files changed, 9 insertions(+), 7 deletions(-)
fs/lockd/host.c +1 -1
@@ -331,7 +331,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,struct nsm_handle *nsm =NULL ;struct sockaddr *src_sap =svc_daddr (rqstp);size_t src_len = rqstp->rq_daddrlen; -struct net *net = rqstp->rq_xprt->xpt_net; +struct net *net =SVC_NET (rqstp);struct nlm_lookup_host_info ni = { .server =1 , .sap =svc_addr (rqstp),
fs/nfs/callback_xdr.c +2 -2
@@ -863,7 +863,7 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r .drc_status = 0, .clp = NULL, .slotid = NFS4_NO_SLOT, - .net = rqstp->rq_xprt->xpt_net, + .net = SVC_NET(rqstp), };unsigned int nops =0 ;
@@ -879,7 +879,7 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *rreturn rpc_garbage_args;if (hdr_arg.minorversion ==0 ) { - cps.clp =nfs4_find_client_ident (rqstp->rq_xprt->xpt_net, hdr_arg.cb_ident); + cps.clp =nfs4_find_client_ident (SVC_NET (rqstp), hdr_arg.cb_ident);if (!cps.clp || !check_gss_callback_principal (cps.clp, rqstp))return rpc_drop_reply; }
fs/nfsd/export.c +2 -2
@@ -929,7 +929,7 @@ struct svc_export * rqst_exp_get_by_name(struct svc_rqst *rqstp, struct path *path) { struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT); -struct nfsd_net *nn =net_generic (rqstp->rq_xprt->xpt_net, nfsd_net_id); +struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id);struct cache_detail *cd = nn->svc_export_cache;if (rqstp->rq_client ==NULL )
@@ -960,7 +960,7 @@ struct svc_export * rqst_exp_find(struct svc_rqst *rqstp, int fsid_type, u32 *fsidv) { struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT); -struct nfsd_net *nn =net_generic (rqstp->rq_xprt->xpt_net, nfsd_net_id); +struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id);struct cache_detail *cd = nn->svc_export_cache;if (rqstp->rq_client ==NULL )
fs/nfsd/nfs4idmap.c +2 -2
@@ -546,7 +546,7 @@ idmap_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen .type = type, };int ret; -struct nfsd_net *nn =net_generic (rqstp->rq_xprt->xpt_net, nfsd_net_id); +struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id);if (namelen +1 >sizeof (key.name))return nfserr_badowner;
@@ -571,7 +571,7 @@ idmap_id_to_name(struct svc_rqst *rqstp, int type, uid_t id, char *name) .type = type, };int ret; -struct nfsd_net *nn =net_generic (rqstp->rq_xprt->xpt_net, nfsd_net_id); +struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id);strlcpy (key.authname,rqst_authname (rqstp),sizeof (key.authname)); ret =idmap_lookup (rqstp, idtoname_lookup, &key, nn->idtoname_cache, &item);
include/linux/sunrpc/svc.h +2 -0
@@ -279,6 +279,8 @@ struct svc_rqst {struct task_struct *rq_task;/* service thread */ }; +#define SVC_NET (svc_rqst) (svc_rqst->rq_xprt->xpt_net) +/* * Rigorous type checking on sockaddr type conversions */
RFC PATCH 11/13 LockD: manage grace list per network namespace
In reply to Stanislav Kinsbursky--- fs/lockd/grace.c | 14 +++++++++++--- fs/lockd/netns.h | 1 + fs/lockd/svc.c | 1 + 3 files changed, 13 insertions(+), 3 deletions(-)
fs/lockd/grace.c +11 -3
@@ -4,8 +4,10 @@#include <linux/module.h> #include <linux/lockd/bind.h> +#include <net/net_namespace.h> + +#include "netns.h" -static LIST_HEAD (grace_list);static DEFINE_SPINLOCK (grace_lock);/**
@@ -21,8 +23,11 @@ static DEFINE_SPINLOCK(grace_lock);*/ void locks_start_grace (struct lock_manager *lm) { +struct net *net = &init_net; +struct lockd_net *ln =net_generic (net, lockd_net_id); +spin_lock (&grace_lock); -list_add (&lm->list, &grace_list); +list_add (&lm->list, &ln->grace_list);spin_unlock (&grace_lock); }EXPORT_SYMBOL_GPL (locks_start_grace);
@@ -54,6 +59,9 @@ EXPORT_SYMBOL_GPL(locks_end_grace);*/ int locks_in_grace (void ) { -return !list_empty (&grace_list); +struct net *net = &init_net; +struct lockd_net *ln =net_generic (net, lockd_net_id); + +return !list_empty (&ln->grace_list); }EXPORT_SYMBOL_GPL (locks_in_grace);
fs/lockd/netns.h +1 -0
@@ -11,6 +11,7 @@ struct lockd_net {struct delayed_work grace_period_end;struct lock_manager lockd_manager; +struct list_head grace_list; };extern int lockd_net_id;
fs/lockd/svc.c +1 -0
@@ -596,6 +596,7 @@ static int lockd_init_net(struct net *net)struct lockd_net *ln =net_generic (net, lockd_net_id);INIT_DELAYED_WORK (&ln->grace_period_end, grace_ender); +INIT_LIST_HEAD (&ln->grace_list);return 0 ; }
RFC PATCH 12/13 LockD: pass actual network namespace to grace period management functions
In reply to Stanislav KinsburskyPassed network namespace replaced hard-coded init_net
--- fs/lockd/grace.c | 6 ++---- fs/lockd/svc.c | 16 +++++++++------- fs/lockd/svc4proc.c | 13 +++++++------ fs/lockd/svclock.c | 16 ++++++++-------- fs/lockd/svcproc.c | 15 +++++++++------ fs/nfsd/nfs4proc.c | 18 ++++++++++-------- fs/nfsd/nfs4state.c | 30 ++++++++++++++++-------------- fs/nfsd/state.h | 3 ++- include/linux/fs.h | 5 +++-- include/linux/lockd/lockd.h | 4 ++-- 10 files changed, 68 insertions(+), 58 deletions(-)
fs/lockd/grace.c +2 -4
@@ -21,9 +21,8 @@ static DEFINE_SPINLOCK(grace_lock);* * This function is called to start a grace period. */ -void locks_start_grace (struct lock_manager *lm) +void locks_start_grace (struct net *net,struct lock_manager *lm) { -struct net *net = &init_net;struct lockd_net *ln =net_generic (net, lockd_net_id);spin_lock (&grace_lock);
@@ -57,9 +56,8 @@ EXPORT_SYMBOL_GPL(locks_end_grace);* to answer ordinary lock requests, and when they should accept only * lock reclaims. */ -int locks_in_grace (void ) +int locks_in_grace (struct net *net) { -struct net *net = &init_net;struct lockd_net *ln =net_generic (net, lockd_net_id);return !list_empty (&ln->grace_list);
fs/lockd/svc.c +9 -7
@@ -97,12 +97,12 @@ static void grace_ender(struct work_struct *grace)locks_end_grace (&ln->lockd_manager); } -static void set_grace_period (void ) +static void set_grace_period (struct net *net) {unsigned long grace_period =get_lockd_grace_period (); -struct lockd_net *ln =net_generic (&init_net, lockd_net_id); +struct lockd_net *ln =net_generic (net, lockd_net_id); -locks_start_grace (&ln->lockd_manager); +locks_start_grace (net, &ln->lockd_manager);cancel_delayed_work_sync (&ln->grace_period_end);schedule_delayed_work (&ln->grace_period_end, grace_period); }
@@ -110,12 +110,13 @@ static void set_grace_period(void)static void restart_grace (void ) {if (nlmsvc_ops) { -struct lockd_net *ln =net_generic (&init_net, lockd_net_id); +struct net *net = &init_net; +struct lockd_net *ln =net_generic (net, lockd_net_id);cancel_delayed_work_sync (&ln->grace_period_end);locks_end_grace (&ln->lockd_manager);nlmsvc_invalidate_all (); -set_grace_period (); +set_grace_period (net); } }
@@ -127,7 +128,8 @@ lockd(void *vrqstp) {int err =0 , preverr =0 ;struct svc_rqst *rqstp = vrqstp; -struct lockd_net *ln =net_generic (&init_net, lockd_net_id); +struct net *net = &init_net; +struct lockd_net *ln =net_generic (net, lockd_net_id);/* try_to_freeze() is called from svc_recv() */ set_freezable ();
@@ -141,7 +143,7 @@ lockd(void *vrqstp) nlm_timeout =LOCKD_DFLT_TIMEO ; nlmsvc_timeout = nlm_timeout *HZ ; -set_grace_period (); +set_grace_period (net);/* * The main request loop. We don't terminate until the last
fs/lockd/svc4proc.c +7 -6
@@ -11,6 +11,7 @@#include <linux/time.h> #include <linux/lockd/lockd.h> #include <linux/lockd/share.h> +#include <linux/sunrpc/svc_xprt.h> #define NLMDBG_FACILITY NLMDBG_CLIENT
@@ -151,7 +152,7 @@ nlm4svc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp, resp->cookie = argp->cookie;/* Don't accept requests during grace period */ -if (locks_in_grace ()) { +if (locks_in_grace (SVC_NET (rqstp))) { resp->status = nlm_lck_denied_grace_period;return rpc_success; }
@@ -161,7 +162,7 @@ nlm4svc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp,return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;/* Try to cancel request. */ - resp->status =nlmsvc_cancel_blocked (file, &argp->lock); + resp->status =nlmsvc_cancel_blocked (SVC_NET (rqstp), file, &argp->lock);dprintk ("lockd: CANCEL status %d\n" ,ntohl (resp->status));nlmsvc_release_host (host);
@@ -184,7 +185,7 @@ nlm4svc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp, resp->cookie = argp->cookie;/* Don't accept new lock requests during grace period */ -if (locks_in_grace ()) { +if (locks_in_grace (SVC_NET (rqstp))) { resp->status = nlm_lck_denied_grace_period;return rpc_success; }
@@ -194,7 +195,7 @@ nlm4svc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp,return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;/* Now try to remove the lock */ - resp->status =nlmsvc_unlock (file, &argp->lock); + resp->status =nlmsvc_unlock (SVC_NET (rqstp), file, &argp->lock);dprintk ("lockd: UNLOCK status %d\n" ,ntohl (resp->status));nlmsvc_release_host (host);
@@ -321,7 +322,7 @@ nlm4svc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp, resp->cookie = argp->cookie;/* Don't accept new lock requests during grace period */ -if (locks_in_grace () && !argp->reclaim) { +if (locks_in_grace (SVC_NET (rqstp)) && !argp->reclaim) { resp->status = nlm_lck_denied_grace_period;return rpc_success; }
@@ -354,7 +355,7 @@ nlm4svc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp, resp->cookie = argp->cookie;/* Don't accept requests during grace period */ -if (locks_in_grace ()) { +if (locks_in_grace (SVC_NET (rqstp))) { resp->status = nlm_lck_denied_grace_period;return rpc_success; }
fs/lockd/svclock.c +8 -8
@@ -26,7 +26,7 @@#include <linux/kernel.h> #include <linux/sched.h> #include <linux/sunrpc/clnt.h> -#include <linux/sunrpc/svc.h> +#include <linux/sunrpc/svc_xprt.h> #include <linux/lockd/nlm.h> #include <linux/lockd/lockd.h> #include <linux/kthread.h>
@@ -447,11 +447,11 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, goto out; } -if (locks_in_grace () && !reclaim) { +if (locks_in_grace (SVC_NET (rqstp)) && !reclaim) { ret = nlm_lck_denied_grace_period; goto out; } -if (reclaim && !locks_in_grace ()) { +if (reclaim && !locks_in_grace (SVC_NET (rqstp))) { ret = nlm_lck_denied_grace_period; goto out; }
@@ -559,7 +559,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file, goto out; } -if (locks_in_grace ()) { +if (locks_in_grace (SVC_NET (rqstp))) { ret = nlm_lck_denied_grace_period; goto out; }
@@ -603,7 +603,7 @@ out:* must be removed. */ __be32 -nlmsvc_unlock (struct nlm_file *file,struct nlm_lock *lock) +nlmsvc_unlock (struct net *net,struct nlm_file *file,struct nlm_lock *lock) {int error;
@@ -615,7 +615,7 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock) (long long)lock->fl.fl_end);/* First, cancel any lock that might be there */ -nlmsvc_cancel_blocked (file, lock); +nlmsvc_cancel_blocked (net, file, lock); lock->fl.fl_type =F_UNLCK ; error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL );
@@ -631,7 +631,7 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock)* The calling procedure must check whether the file can be closed. */ __be32 -nlmsvc_cancel_blocked (struct nlm_file *file,struct nlm_lock *lock) +nlmsvc_cancel_blocked (struct net *net,struct nlm_file *file,struct nlm_lock *lock) {struct nlm_block *block;int status =0 ;
@@ -643,7 +643,7 @@ nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock) (long long )lock->fl.fl_start, (long long)lock->fl.fl_end); -if (locks_in_grace ()) +if (locks_in_grace (net))return nlm_lck_denied_grace_period;mutex_lock (&file->f_mutex);
fs/lockd/svcproc.c +9 -6
@@ -11,6 +11,7 @@#include <linux/time.h> #include <linux/lockd/lockd.h> #include <linux/lockd/share.h> +#include <linux/sunrpc/svc_xprt.h> #define NLMDBG_FACILITY NLMDBG_CLIENT
@@ -175,13 +176,14 @@ nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp, {struct nlm_host *host;struct nlm_file *file; +struct net *net =SVC_NET (rqstp);dprintk ("lockd: CANCEL called\n" ); resp->cookie = argp->cookie;/* Don't accept requests during grace period */ -if (locks_in_grace ()) { +if (locks_in_grace (net)) { resp->status = nlm_lck_denied_grace_period;return rpc_success; }
@@ -191,7 +193,7 @@ nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp,return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;/* Try to cancel request. */ - resp->status =cast_status (nlmsvc_cancel_blocked (file, &argp->lock)); + resp->status =cast_status (nlmsvc_cancel_blocked (net, file, &argp->lock));dprintk ("lockd: CANCEL status %d\n" ,ntohl (resp->status));nlmsvc_release_host (host);
@@ -208,13 +210,14 @@ nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp, {struct nlm_host *host;struct nlm_file *file; +struct net *net =SVC_NET (rqstp);dprintk ("lockd: UNLOCK called\n" ); resp->cookie = argp->cookie;/* Don't accept new lock requests during grace period */ -if (locks_in_grace ()) { +if (locks_in_grace (net)) { resp->status = nlm_lck_denied_grace_period;return rpc_success; }
@@ -224,7 +227,7 @@ nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp,return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;/* Now try to remove the lock */ - resp->status =cast_status (nlmsvc_unlock (file, &argp->lock)); + resp->status =cast_status (nlmsvc_unlock (net, file, &argp->lock));dprintk ("lockd: UNLOCK status %d\n" ,ntohl (resp->status));nlmsvc_release_host (host);
@@ -361,7 +364,7 @@ nlmsvc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp, resp->cookie = argp->cookie;/* Don't accept new lock requests during grace period */ -if (locks_in_grace () && !argp->reclaim) { +if (locks_in_grace (SVC_NET (rqstp)) && !argp->reclaim) { resp->status = nlm_lck_denied_grace_period;return rpc_success; }
@@ -394,7 +397,7 @@ nlmsvc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp, resp->cookie = argp->cookie;/* Don't accept requests during grace period */ -if (locks_in_grace ()) { +if (locks_in_grace (SVC_NET (rqstp))) { resp->status = nlm_lck_denied_grace_period;return rpc_success; }
fs/nfsd/nfs4proc.c +10 -8
@@ -352,10 +352,10 @@ nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,/* Openowner is now set, so sequence id will get bumped. Now we need * these checks before we do any creates: */ status = nfserr_grace; -if (locks_in_grace () && open->op_claim_type !=NFS4_OPEN_CLAIM_PREVIOUS ) +if (locks_in_grace (SVC_NET (rqstp)) && open->op_claim_type !=NFS4_OPEN_CLAIM_PREVIOUS ) goto out; status = nfserr_no_grace; -if (!locks_in_grace () && open->op_claim_type ==NFS4_OPEN_CLAIM_PREVIOUS ) +if (!locks_in_grace (SVC_NET (rqstp)) && open->op_claim_type ==NFS4_OPEN_CLAIM_PREVIOUS ) goto out;switch (open->op_claim_type) {
@@ -690,7 +690,8 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,nfs4_lock_state ();/* check stateid */ -if ((status =nfs4_preprocess_stateid_op (cstate, &read->rd_stateid, +if ((status =nfs4_preprocess_stateid_op (SVC_NET (rqstp), + cstate, &read->rd_stateid,RD_STATE , &read->rd_filp))) {dprintk ("NFSD: nfsd4_read: couldn't process stateid!\n" ); goto out;
@@ -745,7 +746,7 @@ nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, {__be32 status; -if (locks_in_grace ()) +if (locks_in_grace (SVC_NET (rqstp)))return nfserr_grace; status =nfsd_unlink (rqstp, &cstate->current_fh,0 , remove->rm_name, remove->rm_namelen);
@@ -764,8 +765,8 @@ nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (!cstate->save_fh.fh_dentry)return status; -if (locks_in_grace () && !(cstate->save_fh.fh_export->ex_flags - &NFSEXP_NOSUBTREECHECK )) +if (locks_in_grace (SVC_NET (rqstp)) && + !(cstate->save_fh.fh_export->ex_flags &NFSEXP_NOSUBTREECHECK ))return nfserr_grace; status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, rename->rn_snamelen, &cstate->current_fh,
@@ -848,7 +849,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (setattr->sa_iattr.ia_valid &ATTR_SIZE ) {nfs4_lock_state (); - status =nfs4_preprocess_stateid_op (cstate, + status =nfs4_preprocess_stateid_op (SVC_NET (rqstp), cstate, &setattr->sa_stateid,WR_STATE ,NULL );nfs4_unlock_state ();if (status) {
@@ -893,7 +894,8 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,return nfserr_inval;nfs4_lock_state (); - status =nfs4_preprocess_stateid_op (cstate, stateid,WR_STATE , &filp); + status =nfs4_preprocess_stateid_op (SVC_NET (rqstp), + cstate, stateid,WR_STATE , &filp);if (filp)get_file (filp);nfs4_unlock_state ();
fs/nfsd/nfs4state.c +16 -14
@@ -2951,7 +2951,9 @@ static void nfsd4_open_deleg_none_ext(struct nfsd4_open *open, int status)* Attempt to hand out a delegation. */ static void -nfs4_open_delegation (struct svc_fh *fh,struct nfsd4_open *open,struct nfs4_ol_stateid *stp,struct svc_fh *parent) +nfs4_open_delegation (struct net *net,struct svc_fh *fh, +struct nfsd4_open *open,struct nfs4_ol_stateid *stp, +struct svc_fh *parent) {struct nfs4_delegation *dp; struct nfs4_openowner *oo = container_of(stp->st_stateowner, struct nfs4_openowner, oo_owner);
@@ -2972,7 +2974,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_ol_case NFS4_OPEN_CLAIM_NULL :/* Let's not give out any delegations till everyone's * had the chance to reclaim theirs.... */ -if (locks_in_grace ()) +if (locks_in_grace (net)) goto out;if (!cb_up || !(oo->oo_flags &NFS4_OO_CONFIRMED )) goto out;
@@ -3108,7 +3110,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf* Attempt to hand out a delegation. No error return, because the * OPEN succeeds even if we fail. */ -nfs4_open_delegation (current_fh, open, stp, parent); +nfs4_open_delegation (SVC_NET (rqstp), current_fh, open, stp, parent); nodeleg: status = nfs_ok;
@@ -3347,11 +3349,11 @@ out: }static inline __be32 -check_special_stateids (svc_fh *current_fh,stateid_t *stateid,int flags) +check_special_stateids (struct net *net,svc_fh *current_fh,stateid_t *stateid,int flags) {if (ONE_STATEID (stateid) && (flags &RD_STATE ))return nfs_ok; -else if (locks_in_grace ()) { +else if (locks_in_grace (net)) {/* Answer in remaining cases depends on existence of * conflicting state; so we must wait out the grace period. */ return nfserr_grace;
@@ -3368,9 +3370,9 @@ check_special_stateids(svc_fh *current_fh, stateid_t *stateid, int flags)* that are not able to provide mandatory locking. */ static inline int -grace_disallows_io (struct inode *inode) +grace_disallows_io (struct net *net,struct inode *inode) { -return locks_in_grace () &&mandatory_lock (inode); +return locks_in_grace (net) &&mandatory_lock (inode); }/* Returns true iff a is later than b: */
@@ -3453,7 +3455,7 @@ static __be32 nfsd4_lookup_stateid(stateid_t *stateid, unsigned char typemask, s* Checks for stateid operations */ __be32 -nfs4_preprocess_stateid_op (struct nfsd4_compound_state *cstate, +nfs4_preprocess_stateid_op (struct net *net,struct nfsd4_compound_state *cstate,stateid_t *stateid,int flags,struct file **filpp) {struct nfs4_stid *s;
@@ -3466,11 +3468,11 @@ nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,if (filpp) *filpp =NULL ; -if (grace_disallows_io (ino)) +if (grace_disallows_io (net, ino))return nfserr_grace;if (ZERO_STATEID (stateid) ||ONE_STATEID (stateid)) -return check_special_stateids (current_fh, stateid, flags); +return check_special_stateids (net, current_fh, stateid, flags); status =nfsd4_lookup_stateid (stateid,NFS4_DELEG_STID |NFS4_OPEN_STID |NFS4_LOCK_STID , &s);if (status)
@@ -4168,10 +4170,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; status = nfserr_grace; -if (locks_in_grace () && !lock->lk_reclaim) +if (locks_in_grace (SVC_NET (rqstp)) && !lock->lk_reclaim) goto out; status = nfserr_no_grace; -if (!locks_in_grace () && lock->lk_reclaim) +if (!locks_in_grace (SVC_NET (rqstp)) && lock->lk_reclaim) goto out;locks_init_lock (&file_lock);
@@ -4274,7 +4276,7 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,int error;__be32 status; -if (locks_in_grace ()) +if (locks_in_grace (SVC_NET (rqstp)))return nfserr_grace;if (check_lock_length (lockt->lt_offset, lockt->lt_length))
@@ -4758,7 +4760,7 @@ nfs4_state_start(void)get_net (net);nfsd4_client_tracking_init (net); boot_time =get_seconds (); -locks_start_grace (&nn->nfsd4_manager); +locks_start_grace (net, &nn->nfsd4_manager); grace_ended = false;printk (KERN_INFO "NFSD: starting %ld-second grace period\n" , nfsd4_grace);
fs/nfsd/state.h +2 -1
@@ -452,7 +452,8 @@ static inline struct nfs4_ol_stateid *openlockstateid(struct nfs4_stid *s)struct nfsd4_compound_state ; -extern __be32 nfs4_preprocess_stateid_op (struct nfsd4_compound_state *cstate, +extern __be32 nfs4_preprocess_stateid_op (struct net *net, +struct nfsd4_compound_state *cstate,stateid_t *stateid,int flags,struct file **filp);extern void nfs4_lock_state (void );extern void nfs4_unlock_state (void );
include/linux/fs.h +3 -2
@@ -1129,9 +1129,10 @@ struct lock_manager {struct list_head list; }; -void locks_start_grace (struct lock_manager *); +struct net ; +void locks_start_grace (struct net *,struct lock_manager *);void locks_end_grace (struct lock_manager *); -int locks_in_grace (void ); +int locks_in_grace (struct net *);/* that will die - we need it for nfs_lock_info */ #include <linux/nfs_fs_i.h>
include/linux/lockd/lockd.h +2 -2
@@ -262,11 +262,11 @@ typedef int (*nlm_host_match_fn_t)(void *cur, struct nlm_host *ref);__be32 nlmsvc_lock (struct svc_rqst *,struct nlm_file *,struct nlm_host *,struct nlm_lock *,int ,struct nlm_cookie *,int ); -__be32 nlmsvc_unlock (struct nlm_file *,struct nlm_lock *); +__be32 nlmsvc_unlock (struct net *net,struct nlm_file *,struct nlm_lock *);__be32 nlmsvc_testlock (struct svc_rqst *,struct nlm_file *,struct nlm_host *,struct nlm_lock *,struct nlm_lock *,struct nlm_cookie *); -__be32 nlmsvc_cancel_blocked (struct nlm_file *,struct nlm_lock *); +__be32 nlmsvc_cancel_blocked (struct net *net,struct nlm_file *,struct nlm_lock *);unsigned long nlmsvc_retry_blocked (void );void nlmsvc_traverse_blocks (struct nlm_host *,struct nlm_file *,nlm_host_match_fn_t match);
RFC PATCH 13/13 Lockd: move grace period management from lockd() to per-net functions
In reply to Stanislav Kinsbursky--- fs/lockd/svc.c | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-)
fs/lockd/svc.c +3 -6
@@ -128,8 +128,6 @@ lockd(void *vrqstp) {int err =0 , preverr =0 ;struct svc_rqst *rqstp = vrqstp; -struct net *net = &init_net; -struct lockd_net *ln =net_generic (net, lockd_net_id);/* try_to_freeze() is called from svc_recv() */ set_freezable ();
@@ -143,8 +141,6 @@ lockd(void *vrqstp) nlm_timeout =LOCKD_DFLT_TIMEO ; nlmsvc_timeout = nlm_timeout *HZ ; -set_grace_period (net); -/* * The main request loop. We don't terminate until the last * NFS mount or NFS daemon has gone away.
@@ -190,8 +186,6 @@ lockd(void *vrqstp)svc_process (rqstp); }flush_signals (current); -cancel_delayed_work_sync (&ln->grace_period_end); -locks_end_grace (&ln->lockd_manager);if (nlmsvc_ops)nlmsvc_invalidate_all ();nlm_shutdown_hosts ();
@@ -272,6 +266,7 @@ static int lockd_up_net(struct svc_serv *serv, struct net *net) error =make_socks (serv, net);if (error <0 ) goto err_socks; +set_grace_period (net);dprintk ("lockd_up_net: per-net data created; net=%p\n" , net);return 0 ;
@@ -289,6 +284,8 @@ static void lockd_down_net(struct svc_serv *serv, struct net *net)if (ln->nlmsvc_users) {if (--ln->nlmsvc_users ==0 ) {nlm_shutdown_hosts_net (net); +cancel_delayed_work_sync (&ln->grace_period_end); +locks_end_grace (&ln->lockd_manager);svc_shutdown_net (serv, net);dprintk ("lockd_down_net: per-net data destroyed; net=%p\n" , net); }
[RFC PATCH 14/13] NFSd: make grace end flag per network namespace
In reply to Stanislav KinsburskyNFSd's grace_ender flag is a part of grace period facility.
--- fs/nfsd/netns.h | 1 + fs/nfsd/nfs4state.c | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-)
fs/nfsd/netns.h +1 -0
@@ -36,6 +36,7 @@ struct nfsd_net {struct cache_detail *nametoid_cache;struct lock_manager nfsd4_manager; +bool grace_ended; };extern int nfsd_net_id;
fs/nfsd/nfs4state.c +3 -5
@@ -3188,19 +3188,17 @@ out:return status; } -static bool grace_ended; -static void nfsd4_end_grace (struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id);/* do nothing if grace period already ended */ -if (grace_ended) +if (nn->grace_ended)return ;dprintk ("NFSD: end of grace period\n" ); - grace_ended = true; + nn->grace_ended = true;nfsd4_record_grace_done (net, boot_time);locks_end_grace (&nn->nfsd4_manager);/*
@@ -4761,7 +4759,7 @@ nfs4_state_start(void)nfsd4_client_tracking_init (net); boot_time =get_seconds ();locks_start_grace (net, &nn->nfsd4_manager); - grace_ended = false; + nn->grace_ended = false;printk (KERN_INFO "NFSD: starting %ld-second grace period\n" , nfsd4_grace); ret =set_callback_cred ();
[RFC PATCH 15/13] NFSd: make boot_time variable per network namespace
In reply to Stanislav KinsburskyNFSd's boot_time represents grace period start point in time.
--- fs/nfsd/netns.h | 1 + fs/nfsd/nfs4state.c | 47 ++++++++++++++++++++++++++++------------------- fs/nfsd/state.h | 4 +++- 3 files changed, 32 insertions(+), 20 deletions(-)
fs/nfsd/netns.h +1 -0
@@ -37,6 +37,7 @@ struct nfsd_net {struct lock_manager nfsd4_manager;bool grace_ended; +time_t boot_time; };extern int nfsd_net_id;
fs/nfsd/nfs4state.c +28 -19
178 lines not on this page · raw message
fs/nfsd/state.h +3 -1
@@ -451,6 +451,7 @@ static inline struct nfs4_ol_stateid *openlockstateid(struct nfs4_stid *s)#define WR_STATE 0x00000020struct nfsd4_compound_state ; +struct nfsd_net ; extern __be32 nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
@@ -477,7 +478,8 @@ extern __be32 nfs4_make_rec_clidname(char *clidname, struct xdr_netobj *clname);extern int nfs4_client_to_reclaim (const char *name);extern int nfs4_has_reclaimed_state (const char *name,bool use_exchange_id);extern void release_session_client (struct nfsd4_session *); -extern __be32 nfs4_validate_stateid (struct nfs4_client *,stateid_t *); +extern __be32 nfs4_validate_stateid (struct nfs4_client *,stateid_t *, +struct nfsd_net *);extern void nfsd4_purge_closed_stateid (struct nfs4_stateowner *);/* nfs4recover operations */
Quoted 19 lines · Stanislav Kinsbursky
This patch set is marked with RFC, because I'm still not quite sure, that this implementation will satisfy other interested people.
So, would be appreciated for any comments.This patch set makes grace period and hosts reclaiming network namespace aware.
Main ideas:
1) moving ofunsigned long next_gc; unsigned long nrhosts; struct delayed_work grace_period_end; struct lock_manager lockd_manager; struct list_head grace_list;to per-net Lockd data.
Quoted 7 lines
2) moving of
struct lock_manager nfsd4_manager;to per-net NFSd data.
3) shutdown + gc of NLM hosts done now network namespace aware.
That all sounds reasonable to me.
Quoted 1 line
4)
restart_grace()now works only forinit_net.
Eventually we might just remove that. I doubt it's used anywhere.
--b.
Quoted 41 lines
The following series implements...
---
Stanislav Kinsbursky (13):
LockD: mark host per network namespace on garbage collect
LockD: make garbage collector network namespace aware.
LockD: manage garbage collection timeout per networks namespace
LockD: manage used host count per networks namespace
Lockd: host complaining function introduced
Lockd: add more debug to host shutdown functions
LockD: manage grace period per network namespace
LockD: make lockd manager allocated per network namespace
NFSd: makenfsd4_managerallocated per network namespace context.
SUNRPC: service request network namespace helper introduced
LockD: manage grace list per network namespace
LockD: pass actual network namespace to grace period management functions
Lockd: move grace period management fromlockd()to per-net functionsfs/lockd/grace.c | 16 +++++-- fs/lockd/host.c | 92 +++++++++++++++++++++++++++++-------------- fs/lockd/netns.h | 7 +++ fs/lockd/svc.c | 43 ++++++++++++-------- fs/lockd/svc4proc.c | 13 +++--- fs/lockd/svclock.c | 16 ++++--- fs/lockd/svcproc.c | 15 ++++--- fs/lockd/svcsubs.c | 19 ++++++--- fs/nfs/callback_xdr.c | 4 +- fs/nfsd/export.c | 4 +- fs/nfsd/netns.h | 2 + fs/nfsd/nfs4idmap.c | 4 +- fs/nfsd/nfs4proc.c | 18 +++++--- fs/nfsd/nfs4state.c | 60 ++++++++++++++++------------ fs/nfsd/state.h | 3 + include/linux/fs.h | 5 +- include/linux/lockd/lockd.h | 6 +-- include/linux/sunrpc/svc.h | 2 + 18 files changed, 204 insertions(+), 125 deletions(-)
Quoted 26 lines · J. Bruce Fields
Quoted 25 lines · Stanislav Kinsbursky
This patch set is marked with RFC, because I'm still not quite sure, that this implementation will satisfy other interested people.
So, would be appreciated for any comments.This patch set makes grace period and hosts reclaiming network namespace aware.
Main ideas:
1) moving ofunsigned long next_gc; unsigned long nrhosts; struct delayed_work grace_period_end; struct lock_manager lockd_manager; struct list_head grace_list;to per-net Lockd data.
2) moving of
struct lock_manager nfsd4_manager;to per-net NFSd data.
Quoted 7 lines
Quoted 1 line
3) shutdown + gc of NLM hosts done now network namespace aware.
That all sounds reasonable to me.
Quoted 1 line
4)
restart_grace()now works only forinit_net.Eventually we might just remove that. I doubt it's used anywhere.
And on a quick skim I don't see anything wrong with the patches themselves; let me know when you consider them ready.
The per-net grace period management probably isn't what we'll want eventually, but as I said on the other thread I think it's a reasonable starting point.
--b.