nfsd: just keep single lockd reference for nfsd (try #2)
Subsystems (2)
(Re-adding linux-nfs cc):
Quoted 10 lines · Jeff Layton
This patch should replace the other patches that I proposed to make sure that each
sv_permsockentry holds a lockd refrence.Right now, nfsd keeps a lockd reference for each socket that it has open. This is unnecessary and complicates the error handling on startup and shutdown. Change it to just do a
lockd_upwhen starting the first nfsd thread just do a singlelockd_downwhen taking down the last nfsd thread. Because of the strange way thesv_countis handled this requires an extra flag to tell whether thenfsd_servholds a reference for lockd or not.
OK, thanks. This doesn't fix everything, but it looks like an improvement. Applying for 2.6.36.
Quoted 11 lines
This patch also changes the error handling in
nfsd_create_serva bit too. There doesn't seem to be any need to reset thenfssvc_boottime if the nfsd startup failed.Note though that this does change the user-visible behavior slightly. Today when someone writes a text socktype and port to the portlist file prior to starting nfsd, lockd is not started when nfsd threads are brought up. With this change, it will be started any time that the
nfsd_servis created. I'm making the assumption that that's not a problem. If it is then we'll need to take a different approach to fixing this.
(But with this last paragraph deleted, since it no longer applies?)
--b.
Quoted 120 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfsctl.c | 10 ---------- fs/nfsd/nfssvc.c | 27 ++++++++++++++------------- 2 files changed, 14 insertions(+), 23 deletions(-)fs/nfsd/nfsctl.c +0
-10@@ -949,15 +949,8 @@ static ssize_t __write_ports_addfd(char *buf)if (err !=0 )return err; - err =lockd_up (); -if (err !=0 ) { -svc_destroy (nfsd_serv); -return err; - } - err =svc_addsock (nfsd_serv, fd, buf,SIMPLE_TRANSACTION_LIMIT );if (err <0 ) { -lockd_down ();svc_destroy (nfsd_serv);return err; }@@ -982,9 +975,6 @@ static ssize_t __write_ports_delfd(char *buf)if (nfsd_serv !=NULL ) len =svc_sock_names (nfsd_serv, buf,SIMPLE_TRANSACTION_LIMIT , toclose); -if (len >=0 ) -lockd_down (); -kfree (toclose);return len; }fs/nfsd/nfssvc.c +14
-13@@ -25,6 +25,7 @@extern struct svc_program nfsd_program;static int nfsd (void *vrqstp);struct timeval nfssvc_boot; +static bool nfsd_lockd_up;/* * nfsd_mutex protects nfsd_serv -- both the pointer itself and the members @@ -183,9 +184,10 @@ int nfsd_nrthreads(void)static void nfsd_last_thread (struct svc_serv *serv) {/* When last nfsd thread exits we need to do some clean-up */ -struct svc_xprt *xprt; -list_for_each_entry (xprt, &serv->sv_permsocks, xpt_list) +if (nfsd_lockd_up) {lockd_down (); + nfsd_lockd_up = false; + } nfsd_serv =NULL ;nfsd_racache_shutdown ();nfs4_state_shutdown ();@@ -267,10 +269,9 @@ int nfsd_create_serv(void) nfsd_serv =svc_create_pooled (&nfsd_program, nfsd_max_blksize, nfsd_last_thread, nfsd,THIS_MODULE );if (nfsd_serv ==NULL ) - err = -ENOMEM ; -else -set_max_drc (); +return -ENOMEM ; +set_max_drc ();do_gettimeofday (&nfssvc_boot);/* record boot time */ return err; }@@ -286,19 +287,11 @@ static int nfsd_init_socks(int port)if (error <0 )return error; - error =lockd_up (); -if (error <0 ) -return error; - error =svc_create_xprt (nfsd_serv,"tcp" ,PF_INET , port,SVC_SOCK_DEFAULTS );if (error <0 )return error; - error =lockd_up (); -if (error <0 ) -return error; -return 0 ; }@@ -395,6 +388,12 @@ nfsd_svc(unsigned short port, int nrservs) error =nfsd_racache_init (2 *nrservs);if (error<0 ) goto out; + + error =lockd_up (); +if (error !=0 ) + goto out; + nfsd_lockd_up = true; + error =nfs4_state_start ();if (error) goto out;@@ -422,6 +421,8 @@ shutdown_state:if (error <0 )nfs4_state_shutdown (); out: +if (nfsd_lockd_up && error <0 ) +lockd_down ();mutex_unlock (&nfsd_mutex);return error; }Signature · 1 line
1.5.5.6
Quoted 29 lines · On Tue, 20 Jul 2010 18:06:06 -0400 "J. Bruce Fields" <[email protected]>…
(Re-adding linux-nfs cc):
Quoted 10 lines · Jeff Layton
This patch should replace the other patches that I proposed to make sure that each
sv_permsockentry holds a lockd refrence.Right now, nfsd keeps a lockd reference for each socket that it has open. This is unnecessary and complicates the error handling on startup and shutdown. Change it to just do a
lockd_upwhen starting the first nfsd thread just do a singlelockd_downwhen taking down the last nfsd thread. Because of the strange way thesv_countis handled this requires an extra flag to tell whether thenfsd_servholds a reference for lockd or not.OK, thanks. This doesn't fix everything, but it looks like an improvement. Applying for 2.6.36.
Quoted 11 lines
This patch also changes the error handling in
nfsd_create_serva bit too. There doesn't seem to be any need to reset thenfssvc_boottime if the nfsd startup failed.Note though that this does change the user-visible behavior slightly. Today when someone writes a text socktype and port to the portlist file prior to starting nfsd, lockd is not started when nfsd threads are brought up. With this change, it will be started any time that the
nfsd_servis created. I'm making the assumption that that's not a problem. If it is then we'll need to take a different approach to fixing this.
Quoted 4 lines
(But with this last paragraph deleted, since it no longer applies?)
--b.
Ahh yeah, my bad. This patch was intended as more of an RFC than a "please apply" :). I just spun it up this earlier today.
You'll probably want "try #3" too which fixes a bug with the nfsd_lockd_up flag handling. If it's ok with you, I'll resend tomorrow, cc linux-nfs with a fixed description.
Quoted 106 lines
Quoted 106 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfsctl.c | 10 ---------- fs/nfsd/nfssvc.c | 27 ++++++++++++++------------- 2 files changed, 14 insertions(+), 23 deletions(-)fs/nfsd/nfsctl.c +0
-10@@ -949,15 +949,8 @@ static ssize_t __write_ports_addfd(char *buf)if (err !=0 )return err; - err =lockd_up (); -if (err !=0 ) { -svc_destroy (nfsd_serv); -return err; - } - err =svc_addsock (nfsd_serv, fd, buf,SIMPLE_TRANSACTION_LIMIT );if (err <0 ) { -lockd_down ();svc_destroy (nfsd_serv);return err; }@@ -982,9 +975,6 @@ static ssize_t __write_ports_delfd(char *buf)if (nfsd_serv !=NULL ) len =svc_sock_names (nfsd_serv, buf,SIMPLE_TRANSACTION_LIMIT , toclose); -if (len >=0 ) -lockd_down (); -kfree (toclose);return len; }fs/nfsd/nfssvc.c +12
-13@@ -25,6 +25,7 @@extern struct svc_program nfsd_program;static int nfsd (void *vrqstp);struct timeval nfssvc_boot; +static bool nfsd_lockd_up;/* * nfsd_mutex protects nfsd_serv -- both the pointer itself and the members @@ -183,9 +184,10 @@ int nfsd_nrthreads(void)static void nfsd_last_thread (struct svc_serv *serv) {/* When last nfsd thread exits we need to do some clean-up */ -struct svc_xprt *xprt; -list_for_each_entry (xprt, &serv->sv_permsocks, xpt_list) +if (nfsd_lockd_up) {lockd_down (); + nfsd_lockd_up = false; + } nfsd_serv =NULL ;nfsd_racache_shutdown ();nfs4_state_shutdown ();@@ -267,10 +269,9 @@ int nfsd_create_serv(void) nfsd_serv =svc_create_pooled (&nfsd_program, nfsd_max_blksize, nfsd_last_thread, nfsd,THIS_MODULE );if (nfsd_serv ==NULL ) - err = -ENOMEM ; -else -set_max_drc (); +return -ENOMEM ; +set_max_drc ();do_gettimeofday (&nfssvc_boot);/* record boot time */ return err; }@@ -286,19 +287,11 @@ static int nfsd_init_socks(int port)if (error <0 )return error; - error =lockd_up (); -if (error <0 ) -return error; - error =svc_create_xprt (nfsd_serv,"tcp" ,PF_INET , port,SVC_SOCK_DEFAULTS );if (error <0 )return error; - error =lockd_up (); -if (error <0 ) -return error; -return 0 ; }@@ -395,6 +388,12 @@ nfsd_svc(unsigned short port, int nrservs) error =nfsd_racache_init (2 *nrservs);if (error<0 ) goto out; + + error =lockd_up (); +if (error !=0 ) + goto out; + nfsd_lockd_up = true; + error =nfs4_state_start ();
Quoted 8 lines
fs/nfsd/nfssvc.c shutdown_state: · line 425
Quoted 8 lines
fs/nfsd/nfssvc.c +2
-0if (error) goto out;@@ -422,6 +421,8 @@ shutdown_state:if (error <0 )nfs4_state_shutdown (); out: +if (nfsd_lockd_up && error <0 ) +lockd_down ();
^^^^^^^
This is the bug -- nfsd_lockd_up needs to be set to "false" here.
Quoted 6 lines
Quoted 6 lines
fs/nfsd/nfssvc.c +0
-0mutex_unlock (&nfsd_mutex);return error; }Signature · 1 line
1.5.5.6
Thanks,
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 37 lines · Jeff Layton
Quoted 29 lines · On Tue, 20 Jul 2010 18:06:06 -0400 "J. Bruce Fields" <[email protected]>…
(Re-adding linux-nfs cc):
Quoted 10 lines · Jeff Layton
This patch should replace the other patches that I proposed to make sure that each
sv_permsockentry holds a lockd refrence.Right now, nfsd keeps a lockd reference for each socket that it has open. This is unnecessary and complicates the error handling on startup and shutdown. Change it to just do a
lockd_upwhen starting the first nfsd thread just do a singlelockd_downwhen taking down the last nfsd thread. Because of the strange way thesv_countis handled this requires an extra flag to tell whether thenfsd_servholds a reference for lockd or not.OK, thanks. This doesn't fix everything, but it looks like an improvement. Applying for 2.6.36.
Quoted 11 lines
This patch also changes the error handling in
nfsd_create_serva bit too. There doesn't seem to be any need to reset thenfssvc_boottime if the nfsd startup failed.Note though that this does change the user-visible behavior slightly. Today when someone writes a text socktype and port to the portlist file prior to starting nfsd, lockd is not started when nfsd threads are brought up. With this change, it will be started any time that the
nfsd_servis created. I'm making the assumption that that's not a problem. If it is then we'll need to take a different approach to fixing this.Quoted 4 lines
(But with this last paragraph deleted, since it no longer applies?)
--b.
Quoted 6 lines
Ahh yeah, my bad. This patch was intended as more of an RFC than a "please apply" :). I just spun it up this earlier today.
You'll probably want "try #3" too which fixes a bug with the
nfsd_lockd_upflag handling. If it's ok with you, I'll resend tomorrow, cc linux-nfs with a fixed description.
Erp, OK. I haven't pushed that out yet, so OK.
--b.
Quoted 128 lines
Quoted 107 lines
Quoted 107 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfsctl.c | 10 ---------- fs/nfsd/nfssvc.c | 27 ++++++++++++++------------- 2 files changed, 14 insertions(+), 23 deletions(-)fs/nfsd/nfsctl.c +0
-10@@ -949,15 +949,8 @@ static ssize_t __write_ports_addfd(char *buf)if (err !=0 )return err; - err =lockd_up (); -if (err !=0 ) { -svc_destroy (nfsd_serv); -return err; - } - err =svc_addsock (nfsd_serv, fd, buf,SIMPLE_TRANSACTION_LIMIT );if (err <0 ) { -lockd_down ();svc_destroy (nfsd_serv);return err; }@@ -982,9 +975,6 @@ static ssize_t __write_ports_delfd(char *buf)if (nfsd_serv !=NULL ) len =svc_sock_names (nfsd_serv, buf,SIMPLE_TRANSACTION_LIMIT , toclose); -if (len >=0 ) -lockd_down (); -kfree (toclose);return len; }fs/nfsd/nfssvc.c +12
-13@@ -25,6 +25,7 @@extern struct svc_program nfsd_program;static int nfsd (void *vrqstp);struct timeval nfssvc_boot; +static bool nfsd_lockd_up;/* * nfsd_mutex protects nfsd_serv -- both the pointer itself and the members @@ -183,9 +184,10 @@ int nfsd_nrthreads(void)static void nfsd_last_thread (struct svc_serv *serv) {/* When last nfsd thread exits we need to do some clean-up */ -struct svc_xprt *xprt; -list_for_each_entry (xprt, &serv->sv_permsocks, xpt_list) +if (nfsd_lockd_up) {lockd_down (); + nfsd_lockd_up = false; + } nfsd_serv =NULL ;nfsd_racache_shutdown ();nfs4_state_shutdown ();@@ -267,10 +269,9 @@ int nfsd_create_serv(void) nfsd_serv =svc_create_pooled (&nfsd_program, nfsd_max_blksize, nfsd_last_thread, nfsd,THIS_MODULE );if (nfsd_serv ==NULL ) - err = -ENOMEM ; -else -set_max_drc (); +return -ENOMEM ; +set_max_drc ();do_gettimeofday (&nfssvc_boot);/* record boot time */ return err; }@@ -286,19 +287,11 @@ static int nfsd_init_socks(int port)if (error <0 )return error; - error =lockd_up (); -if (error <0 ) -return error; - error =svc_create_xprt (nfsd_serv,"tcp" ,PF_INET , port,SVC_SOCK_DEFAULTS );if (error <0 )return error; - error =lockd_up (); -if (error <0 ) -return error; -return 0 ; }@@ -395,6 +388,12 @@ nfsd_svc(unsigned short port, int nrservs) error =nfsd_racache_init (2 *nrservs);if (error<0 ) goto out; + + error =lockd_up (); +if (error !=0 ) + goto out; + nfsd_lockd_up = true; + error =nfs4_state_start ();Quoted 8 lines
fs/nfsd/nfssvc.c shutdown_state: · line 425
Quoted 8 lines
fs/nfsd/nfssvc.c +2
-0if (error) goto out;@@ -422,6 +421,8 @@ shutdown_state:if (error <0 )nfs4_state_shutdown (); out: +if (nfsd_lockd_up && error <0 ) +lockd_down ();^^^^^^^This is the bug --
nfsd_lockd_upneeds to be set to "false" here.Quoted 6 lines
Quoted 6 lines
fs/nfsd/nfssvc.c +0
-0mutex_unlock (&nfsd_mutex);return error; }Signature · 1 line
1.5.5.6Thanks,
Signature · 1 line
Jeff Layton <[email protected]>