All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sage Weil <sage@inktank.com>
To: ceph-devel@vger.kernel.org
Cc: Sage Weil <sage@inktank.com>
Subject: [PATCH 8/8] libceph: recheck con state after allocating incoming message
Date: Mon, 30 Jul 2012 08:59:31 -0700	[thread overview]
Message-ID: <1343663971-3221-9-git-send-email-sage@inktank.com> (raw)
In-Reply-To: <1343663971-3221-1-git-send-email-sage@inktank.com>

We drop the lock when calling the ->alloc_msg() con op, which means
we need to (a) not clobber con->in_msg without the mutex held, and (b)
we need to verify that we are still in the OPEN state when we retake
it to avoid causing any mayhem.  If the state does change, -EAGAIN
will get us back to con_work() and loop.

Signed-off-by: Sage Weil <sage@inktank.com>
---
 net/ceph/messenger.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 5177af0..91ad692 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -2735,9 +2735,16 @@ static int ceph_con_in_msg_alloc(struct ceph_connection *con, int *skip)
 	BUG_ON(con->in_msg != NULL);
 
 	if (con->ops->alloc_msg) {
+		struct ceph_msg *msg;
+
 		mutex_unlock(&con->mutex);
-		con->in_msg = con->ops->alloc_msg(con, hdr, skip);
+		msg = con->ops->alloc_msg(con, hdr, skip);
 		mutex_lock(&con->mutex);
+		if (con->state != CON_STATE_OPEN) {
+			ceph_msg_put(msg);
+			return -EAGAIN;
+		}
+		con->in_msg = msg;
 		if (con->in_msg) {
 			con->in_msg->con = con->ops->get(con);
 			BUG_ON(con->in_msg->con == NULL);
-- 
1.7.9.5


      parent reply	other threads:[~2012-07-30 15:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-30 15:59 [PATCH 0/8] Last batch of messenger fixes, misc Sage Weil
2012-07-30 15:59 ` [PATCH 1/8] libceph: be less chatty about stray replies Sage Weil
2012-07-30 23:00   ` Alex Elder
2012-07-30 15:59 ` [PATCH 2/8] ceph: update MAINTAINERS file Sage Weil
2012-07-30 23:09   ` Alex Elder
2012-07-30 15:59 ` [PATCH 3/8] libceph: fix handling of immediate socket connect failure Sage Weil
2012-07-31  0:08   ` Alex Elder
2012-07-30 15:59 ` [PATCH 4/8] libceph: revoke mon_client messages on session restart Sage Weil
2012-07-31  0:09   ` Alex Elder
2012-07-30 15:59 ` [PATCH 5/8] libceph: verify state after retaking con lock after dispatch Sage Weil
2012-07-31  0:11   ` Alex Elder
2012-07-30 15:59 ` [PATCH 6/8] libceph: avoid dropping con mutex before fault Sage Weil
2012-07-31  0:12   ` Alex Elder
2012-07-30 15:59 ` [PATCH 7/8] libceph: change ceph_con_in_msg_alloc convention to be less weird Sage Weil
2012-07-31  0:25   ` Alex Elder
2012-07-31  1:09     ` Sage Weil
2012-07-30 15:59 ` Sage Weil [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1343663971-3221-9-git-send-email-sage@inktank.com \
    --to=sage@inktank.com \
    --cc=ceph-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.