diff options
author | Raghavendra G <raghavendra@gluster.com> | 2009-11-13 16:04:47 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-11-19 02:52:05 -0800 |
commit | 877522adb8a30de0023464cba0e597104e93cccc (patch) | |
tree | facc6f5f361c94898ca532d496a4372ac35c4dff /transport | |
parent | f88cd26064d7aa306720d4e4d48af9086d97fb13 (diff) |
transport/ib-verbs: synchronize ib_verbs_recv_completion_proc with ib_verbs_receive so that the former doesn't overwrite the pointer from which latter reads.
- There can be a condition wherein,
1. the thread executing ib_verbs_recv_completion_proc (thr 1) stores the
buffer pointer and notifies the upper translators about a POLLIN event.
2. the thread waiting for events on socket (thr 2) calls transport_receive,
but in ib_verbs_receive it has not still read the data.
3. thr 1 receives work completion event for another work request and
overwrites the buffer pointer.
4. thr 2 reads from the new pointer there by missing the data stored in
buffer pointed by pointer which got overwritten.
Signed-off-by: Raghavendra G <raghavendra@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 382 (Data can be lost before it is read in ib_verbs_receive.)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=382
Diffstat (limited to 'transport')
-rw-r--r-- | transport/ib-verbs/src/ib-verbs.c | 10 | ||||
-rw-r--r-- | transport/ib-verbs/src/ib-verbs.h | 1 |
2 files changed, 6 insertions, 5 deletions
diff --git a/transport/ib-verbs/src/ib-verbs.c b/transport/ib-verbs/src/ib-verbs.c index 8338587a5d2..d89a6892878 100644 --- a/transport/ib-verbs/src/ib-verbs.c +++ b/transport/ib-verbs/src/ib-verbs.c @@ -497,7 +497,7 @@ ib_verbs_receive (transport_t *this, char **hdr_p, size_t *hdrlen_p, priv->data_ptr = NULL; data_len = priv->data_len; - /* pthread_cond_broadcast (&priv->recv_cond); */ + pthread_cond_broadcast (&priv->recv_cond); } pthread_mutex_unlock (&priv->recv_mutex); @@ -1137,9 +1137,9 @@ ib_verbs_recv_completion_proc (void *data) pthread_mutex_lock (&priv->recv_mutex); { -/* while (priv->data_ptr) - pthread_cond_wait (&priv->recv_cond, &priv->recv_mutex); -*/ + while (priv->data_ptr) + pthread_cond_wait (&priv->recv_cond, + &priv->recv_mutex); priv->data_ptr = post->buf; priv->data_offset = 0; @@ -1567,7 +1567,7 @@ ib_verbs_init (transport_t *this) pthread_mutex_init (&priv->read_mutex, NULL); pthread_mutex_init (&priv->write_mutex, NULL); pthread_mutex_init (&priv->recv_mutex, NULL); - /* pthread_cond_init (&priv->recv_cond, NULL); */ + pthread_cond_init (&priv->recv_cond, NULL); return 0; } diff --git a/transport/ib-verbs/src/ib-verbs.h b/transport/ib-verbs/src/ib-verbs.h index 0b61a2a60e7..2e38c009dba 100644 --- a/transport/ib-verbs/src/ib-verbs.h +++ b/transport/ib-verbs/src/ib-verbs.h @@ -209,6 +209,7 @@ struct _ib_verbs_private { char handshake_ret; pthread_mutex_t recv_mutex; + pthread_cond_t recv_cond; /* used during ib_verbs_handshake */ struct { |