* [PATCH 1/3] Make it clear rpc_createerr is thread safe
2016-05-19 15:35 ` [PATCH v2 0/3] Do not hold clnt_fd_lock mutex during connect Paulo Andrade
@ 2016-05-19 15:35 ` Paulo Andrade
2016-05-19 23:51 ` [Libtirpc-devel] " Ian Kent
2016-06-02 14:50 ` Steve Dickson
2016-05-19 15:35 ` [PATCH 2/3] Record errno value before calling syslog Paulo Andrade
2016-05-19 15:35 ` [PATCH 3/3] Do not hold a global mutex during connect Paulo Andrade
2 siblings, 2 replies; 9+ messages in thread
From: Paulo Andrade @ 2016-05-19 15:35 UTC (permalink / raw)
To: libtirpc-devel; +Cc: linux-nfs, Paulo Andrade
Avoid hidding it under a macro, and also avoid multiple function
calls when accessing structure fields.
Signed-off-by: Paulo Andrade <pcpa@gnu.org>
---
src/clnt_vc.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/clnt_vc.c b/src/clnt_vc.c
index a72f9f7..8af7ddd 100644
--- a/src/clnt_vc.c
+++ b/src/clnt_vc.c
@@ -72,6 +72,8 @@
#define CMGROUP_MAX 16
#define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
+#undef rpc_createerr /* make it clear it is a thread safe variable */
+
/*
* Credentials structure, used to verify the identity of a peer
* process that has sent us a message. This is allocated by the
@@ -188,10 +190,11 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
cl = (CLIENT *)mem_alloc(sizeof (*cl));
ct = (struct ct_data *)mem_alloc(sizeof (*ct));
if ((cl == (CLIENT *)NULL) || (ct == (struct ct_data *)NULL)) {
+ struct rpc_createerr *ce = &get_rpc_createerr();
(void) syslog(LOG_ERR, clnt_vc_errstr,
clnt_vc_str, __no_mem_str);
- rpc_createerr.cf_stat = RPC_SYSTEMERROR;
- rpc_createerr.cf_error.re_errno = errno;
+ ce->cf_stat = RPC_SYSTEMERROR;
+ ce->cf_error.re_errno = errno;
goto err;
}
ct->ct_addr.buf = NULL;
@@ -235,15 +238,17 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
slen = sizeof ss;
if (getpeername(fd, (struct sockaddr *)&ss, &slen) < 0) {
if (errno != ENOTCONN) {
- rpc_createerr.cf_stat = RPC_SYSTEMERROR;
- rpc_createerr.cf_error.re_errno = errno;
+ struct rpc_createerr *ce = &get_rpc_createerr();
+ ce->cf_stat = RPC_SYSTEMERROR;
+ ce->cf_error.re_errno = errno;
mutex_unlock(&clnt_fd_lock);
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
goto err;
}
if (connect(fd, (struct sockaddr *)raddr->buf, raddr->len) < 0){
- rpc_createerr.cf_stat = RPC_SYSTEMERROR;
- rpc_createerr.cf_error.re_errno = errno;
+ struct rpc_createerr *ce = &get_rpc_createerr();
+ ce->cf_stat = RPC_SYSTEMERROR;
+ ce->cf_error.re_errno = errno;
mutex_unlock(&clnt_fd_lock);
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
goto err;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [Libtirpc-devel] [PATCH 1/3] Make it clear rpc_createerr is thread safe
2016-05-19 15:35 ` [PATCH 1/3] Make it clear rpc_createerr is thread safe Paulo Andrade
@ 2016-05-19 23:51 ` Ian Kent
2016-06-02 14:50 ` Steve Dickson
1 sibling, 0 replies; 9+ messages in thread
From: Ian Kent @ 2016-05-19 23:51 UTC (permalink / raw)
To: Paulo Andrade, libtirpc-devel; +Cc: linux-nfs, Paulo Andrade
On Thu, 2016-05-19 at 12:35 -0300, Paulo Andrade wrote:
> Avoid hidding it under a macro, and also avoid multiple function
> calls when accessing structure fields.
I like this approach, the use of the macro was confusing to me.
Including that define must always be the case though.
If others agree with this there probably needs to be follow up series with
similar changes for the rest of the source.
I guess the main argument against it is that library users have come to expect
using the macro and could be confused by this change, the exact opposite to the
point of the change.
Thoughts anyone?
>
> Signed-off-by: Paulo Andrade <pcpa@gnu.org>
> ---
> src/clnt_vc.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/src/clnt_vc.c b/src/clnt_vc.c
> index a72f9f7..8af7ddd 100644
> --- a/src/clnt_vc.c
> +++ b/src/clnt_vc.c
> @@ -72,6 +72,8 @@
> #define CMGROUP_MAX 16
> #define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
>
> +#undef rpc_createerr /* make it clear it is a thread safe
> variable */
> +
> /*
> * Credentials structure, used to verify the identity of a peer
> * process that has sent us a message. This is allocated by the
> @@ -188,10 +190,11 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
> cl = (CLIENT *)mem_alloc(sizeof (*cl));
> ct = (struct ct_data *)mem_alloc(sizeof (*ct));
> if ((cl == (CLIENT *)NULL) || (ct == (struct ct_data *)NULL)) {
> + struct rpc_createerr *ce = &get_rpc_createerr();
> (void) syslog(LOG_ERR, clnt_vc_errstr,
> clnt_vc_str, __no_mem_str);
> - rpc_createerr.cf_stat = RPC_SYSTEMERROR;
> - rpc_createerr.cf_error.re_errno = errno;
> + ce->cf_stat = RPC_SYSTEMERROR;
> + ce->cf_error.re_errno = errno;
> goto err;
> }
> ct->ct_addr.buf = NULL;
> @@ -235,15 +238,17 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
> slen = sizeof ss;
> if (getpeername(fd, (struct sockaddr *)&ss, &slen) < 0) {
> if (errno != ENOTCONN) {
> - rpc_createerr.cf_stat = RPC_SYSTEMERROR;
> - rpc_createerr.cf_error.re_errno = errno;
> + struct rpc_createerr *ce = &get_rpc_createerr();
> + ce->cf_stat = RPC_SYSTEMERROR;
> + ce->cf_error.re_errno = errno;
> mutex_unlock(&clnt_fd_lock);
> thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
> goto err;
> }
> if (connect(fd, (struct sockaddr *)raddr->buf, raddr->len) <
> 0){
> - rpc_createerr.cf_stat = RPC_SYSTEMERROR;
> - rpc_createerr.cf_error.re_errno = errno;
> + struct rpc_createerr *ce = &get_rpc_createerr();
> + ce->cf_stat = RPC_SYSTEMERROR;
> + ce->cf_error.re_errno = errno;
> mutex_unlock(&clnt_fd_lock);
> thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
> goto err;
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [Libtirpc-devel] [PATCH 1/3] Make it clear rpc_createerr is thread safe
2016-05-19 15:35 ` [PATCH 1/3] Make it clear rpc_createerr is thread safe Paulo Andrade
2016-05-19 23:51 ` [Libtirpc-devel] " Ian Kent
@ 2016-06-02 14:50 ` Steve Dickson
1 sibling, 0 replies; 9+ messages in thread
From: Steve Dickson @ 2016-06-02 14:50 UTC (permalink / raw)
To: Paulo Andrade, libtirpc-devel; +Cc: linux-nfs, Paulo Andrade
On 05/19/2016 11:35 AM, Paulo Andrade wrote:
> Avoid hidding it under a macro, and also avoid multiple function
> calls when accessing structure fields.
>
> Signed-off-by: Paulo Andrade <pcpa@gnu.org>
Committed...
steved.
> ---
> src/clnt_vc.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/src/clnt_vc.c b/src/clnt_vc.c
> index a72f9f7..8af7ddd 100644
> --- a/src/clnt_vc.c
> +++ b/src/clnt_vc.c
> @@ -72,6 +72,8 @@
> #define CMGROUP_MAX 16
> #define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
>
> +#undef rpc_createerr /* make it clear it is a thread safe variable */
> +
> /*
> * Credentials structure, used to verify the identity of a peer
> * process that has sent us a message. This is allocated by the
> @@ -188,10 +190,11 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
> cl = (CLIENT *)mem_alloc(sizeof (*cl));
> ct = (struct ct_data *)mem_alloc(sizeof (*ct));
> if ((cl == (CLIENT *)NULL) || (ct == (struct ct_data *)NULL)) {
> + struct rpc_createerr *ce = &get_rpc_createerr();
> (void) syslog(LOG_ERR, clnt_vc_errstr,
> clnt_vc_str, __no_mem_str);
> - rpc_createerr.cf_stat = RPC_SYSTEMERROR;
> - rpc_createerr.cf_error.re_errno = errno;
> + ce->cf_stat = RPC_SYSTEMERROR;
> + ce->cf_error.re_errno = errno;
> goto err;
> }
> ct->ct_addr.buf = NULL;
> @@ -235,15 +238,17 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
> slen = sizeof ss;
> if (getpeername(fd, (struct sockaddr *)&ss, &slen) < 0) {
> if (errno != ENOTCONN) {
> - rpc_createerr.cf_stat = RPC_SYSTEMERROR;
> - rpc_createerr.cf_error.re_errno = errno;
> + struct rpc_createerr *ce = &get_rpc_createerr();
> + ce->cf_stat = RPC_SYSTEMERROR;
> + ce->cf_error.re_errno = errno;
> mutex_unlock(&clnt_fd_lock);
> thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
> goto err;
> }
> if (connect(fd, (struct sockaddr *)raddr->buf, raddr->len) < 0){
> - rpc_createerr.cf_stat = RPC_SYSTEMERROR;
> - rpc_createerr.cf_error.re_errno = errno;
> + struct rpc_createerr *ce = &get_rpc_createerr();
> + ce->cf_stat = RPC_SYSTEMERROR;
> + ce->cf_error.re_errno = errno;
> mutex_unlock(&clnt_fd_lock);
> thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
> goto err;
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/3] Record errno value before calling syslog
2016-05-19 15:35 ` [PATCH v2 0/3] Do not hold clnt_fd_lock mutex during connect Paulo Andrade
2016-05-19 15:35 ` [PATCH 1/3] Make it clear rpc_createerr is thread safe Paulo Andrade
@ 2016-05-19 15:35 ` Paulo Andrade
2016-06-02 14:51 ` [Libtirpc-devel] " Steve Dickson
2016-05-19 15:35 ` [PATCH 3/3] Do not hold a global mutex during connect Paulo Andrade
2 siblings, 1 reply; 9+ messages in thread
From: Paulo Andrade @ 2016-05-19 15:35 UTC (permalink / raw)
To: libtirpc-devel; +Cc: linux-nfs, Paulo Andrade
Unlikely to change, but stay in the safe side.
Signed-off-by: Paulo Andrade <pcpa@gnu.org>
---
src/clnt_vc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/clnt_vc.c b/src/clnt_vc.c
index 8af7ddd..0da18ca 100644
--- a/src/clnt_vc.c
+++ b/src/clnt_vc.c
@@ -191,10 +191,10 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
ct = (struct ct_data *)mem_alloc(sizeof (*ct));
if ((cl == (CLIENT *)NULL) || (ct == (struct ct_data *)NULL)) {
struct rpc_createerr *ce = &get_rpc_createerr();
- (void) syslog(LOG_ERR, clnt_vc_errstr,
- clnt_vc_str, __no_mem_str);
ce->cf_stat = RPC_SYSTEMERROR;
ce->cf_error.re_errno = errno;
+ (void) syslog(LOG_ERR, clnt_vc_errstr,
+ clnt_vc_str, __no_mem_str);
goto err;
}
ct->ct_addr.buf = NULL;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [Libtirpc-devel] [PATCH 2/3] Record errno value before calling syslog
2016-05-19 15:35 ` [PATCH 2/3] Record errno value before calling syslog Paulo Andrade
@ 2016-06-02 14:51 ` Steve Dickson
0 siblings, 0 replies; 9+ messages in thread
From: Steve Dickson @ 2016-06-02 14:51 UTC (permalink / raw)
To: Paulo Andrade, libtirpc-devel; +Cc: linux-nfs, Paulo Andrade
On 05/19/2016 11:35 AM, Paulo Andrade wrote:
> Unlikely to change, but stay in the safe side.
>
> Signed-off-by: Paulo Andrade <pcpa@gnu.org>
Committed..
steved.
> ---
> src/clnt_vc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/clnt_vc.c b/src/clnt_vc.c
> index 8af7ddd..0da18ca 100644
> --- a/src/clnt_vc.c
> +++ b/src/clnt_vc.c
> @@ -191,10 +191,10 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
> ct = (struct ct_data *)mem_alloc(sizeof (*ct));
> if ((cl == (CLIENT *)NULL) || (ct == (struct ct_data *)NULL)) {
> struct rpc_createerr *ce = &get_rpc_createerr();
> - (void) syslog(LOG_ERR, clnt_vc_errstr,
> - clnt_vc_str, __no_mem_str);
> ce->cf_stat = RPC_SYSTEMERROR;
> ce->cf_error.re_errno = errno;
> + (void) syslog(LOG_ERR, clnt_vc_errstr,
> + clnt_vc_str, __no_mem_str);
> goto err;
> }
> ct->ct_addr.buf = NULL;
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/3] Do not hold a global mutex during connect
2016-05-19 15:35 ` [PATCH v2 0/3] Do not hold clnt_fd_lock mutex during connect Paulo Andrade
2016-05-19 15:35 ` [PATCH 1/3] Make it clear rpc_createerr is thread safe Paulo Andrade
2016-05-19 15:35 ` [PATCH 2/3] Record errno value before calling syslog Paulo Andrade
@ 2016-05-19 15:35 ` Paulo Andrade
2016-05-20 2:00 ` [Libtirpc-devel] " Ian Kent
2016-06-02 14:51 ` Steve Dickson
2 siblings, 2 replies; 9+ messages in thread
From: Paulo Andrade @ 2016-05-19 15:35 UTC (permalink / raw)
To: libtirpc-devel; +Cc: linux-nfs, Paulo Andrade
A multi-threaded application, connecting to multiple rpc servers,
may dead lock if the connect call stalls on a non responsive server.
Signed-off-by: Paulo Andrade <pcpa@gnu.org>
---
src/clnt_vc.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/clnt_vc.c b/src/clnt_vc.c
index 0da18ca..0f018d5 100644
--- a/src/clnt_vc.c
+++ b/src/clnt_vc.c
@@ -233,15 +233,16 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
assert(vc_cv != (cond_t *) NULL);
/*
- * XXX - fvdl connecting while holding a mutex?
+ * Do not hold mutex during connect
*/
+ mutex_unlock(&clnt_fd_lock);
+
slen = sizeof ss;
if (getpeername(fd, (struct sockaddr *)&ss, &slen) < 0) {
if (errno != ENOTCONN) {
struct rpc_createerr *ce = &get_rpc_createerr();
ce->cf_stat = RPC_SYSTEMERROR;
ce->cf_error.re_errno = errno;
- mutex_unlock(&clnt_fd_lock);
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
goto err;
}
@@ -249,12 +250,10 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
struct rpc_createerr *ce = &get_rpc_createerr();
ce->cf_stat = RPC_SYSTEMERROR;
ce->cf_error.re_errno = errno;
- mutex_unlock(&clnt_fd_lock);
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
goto err;
}
}
- mutex_unlock(&clnt_fd_lock);
if (!__rpc_fd2sockinfo(fd, &si))
goto err;
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [Libtirpc-devel] [PATCH 3/3] Do not hold a global mutex during connect
2016-05-19 15:35 ` [PATCH 3/3] Do not hold a global mutex during connect Paulo Andrade
@ 2016-05-20 2:00 ` Ian Kent
2016-06-02 14:51 ` Steve Dickson
1 sibling, 0 replies; 9+ messages in thread
From: Ian Kent @ 2016-05-20 2:00 UTC (permalink / raw)
To: Paulo Andrade, libtirpc-devel; +Cc: linux-nfs, Paulo Andrade
On Thu, 2016-05-19 at 12:35 -0300, Paulo Andrade wrote:
> A multi-threaded application, connecting to multiple rpc servers,
> may dead lock if the connect call stalls on a non responsive server.
It's occurred to me that the mutex may be held over the connect(2) call to
prevent concurrent calls to connect(2) using the same fd.
That's a race and is a lot harder to deal with.
Comments, thoughts anyone?
I guess it's time to have a look at the connect(2) source ....
>
> Signed-off-by: Paulo Andrade <pcpa@gnu.org>
> ---
> src/clnt_vc.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/src/clnt_vc.c b/src/clnt_vc.c
> index 0da18ca..0f018d5 100644
> --- a/src/clnt_vc.c
> +++ b/src/clnt_vc.c
> @@ -233,15 +233,16 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
> assert(vc_cv != (cond_t *) NULL);
>
> /*
> - * XXX - fvdl connecting while holding a mutex?
> + * Do not hold mutex during connect
> */
> + mutex_unlock(&clnt_fd_lock);
> +
> slen = sizeof ss;
> if (getpeername(fd, (struct sockaddr *)&ss, &slen) < 0) {
> if (errno != ENOTCONN) {
> struct rpc_createerr *ce = &get_rpc_createerr();
> ce->cf_stat = RPC_SYSTEMERROR;
> ce->cf_error.re_errno = errno;
> - mutex_unlock(&clnt_fd_lock);
> thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
> goto err;
> }
> @@ -249,12 +250,10 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
> struct rpc_createerr *ce = &get_rpc_createerr();
> ce->cf_stat = RPC_SYSTEMERROR;
> ce->cf_error.re_errno = errno;
> - mutex_unlock(&clnt_fd_lock);
> thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
> goto err;
> }
> }
> - mutex_unlock(&clnt_fd_lock);
> if (!__rpc_fd2sockinfo(fd, &si))
> goto err;
> thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [Libtirpc-devel] [PATCH 3/3] Do not hold a global mutex during connect
2016-05-19 15:35 ` [PATCH 3/3] Do not hold a global mutex during connect Paulo Andrade
2016-05-20 2:00 ` [Libtirpc-devel] " Ian Kent
@ 2016-06-02 14:51 ` Steve Dickson
1 sibling, 0 replies; 9+ messages in thread
From: Steve Dickson @ 2016-06-02 14:51 UTC (permalink / raw)
To: Paulo Andrade, libtirpc-devel; +Cc: linux-nfs, Paulo Andrade
On 05/19/2016 11:35 AM, Paulo Andrade wrote:
> A multi-threaded application, connecting to multiple rpc servers,
> may dead lock if the connect call stalls on a non responsive server.
>
> Signed-off-by: Paulo Andrade <pcpa@gnu.org>
committed...
steved.
> ---
> src/clnt_vc.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/src/clnt_vc.c b/src/clnt_vc.c
> index 0da18ca..0f018d5 100644
> --- a/src/clnt_vc.c
> +++ b/src/clnt_vc.c
> @@ -233,15 +233,16 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
> assert(vc_cv != (cond_t *) NULL);
>
> /*
> - * XXX - fvdl connecting while holding a mutex?
> + * Do not hold mutex during connect
> */
> + mutex_unlock(&clnt_fd_lock);
> +
> slen = sizeof ss;
> if (getpeername(fd, (struct sockaddr *)&ss, &slen) < 0) {
> if (errno != ENOTCONN) {
> struct rpc_createerr *ce = &get_rpc_createerr();
> ce->cf_stat = RPC_SYSTEMERROR;
> ce->cf_error.re_errno = errno;
> - mutex_unlock(&clnt_fd_lock);
> thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
> goto err;
> }
> @@ -249,12 +250,10 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
> struct rpc_createerr *ce = &get_rpc_createerr();
> ce->cf_stat = RPC_SYSTEMERROR;
> ce->cf_error.re_errno = errno;
> - mutex_unlock(&clnt_fd_lock);
> thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
> goto err;
> }
> }
> - mutex_unlock(&clnt_fd_lock);
> if (!__rpc_fd2sockinfo(fd, &si))
> goto err;
> thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
>
^ permalink raw reply [flat|nested] 9+ messages in thread