Commit 49659416 authored by Alex Elder's avatar Alex Elder

libceph: use a do..while loop in con_work()

This just converts a manually-implemented loop into a do..while loop
in con_work().  It also moves handling of EAGAIN inside the blocks
where it's already been determined an error code was returned.

Also update a few dout() calls near the affected code for
consistency.
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent b6e7b6a1
...@@ -2387,51 +2387,53 @@ static void con_work(struct work_struct *work) ...@@ -2387,51 +2387,53 @@ static void con_work(struct work_struct *work)
{ {
struct ceph_connection *con = container_of(work, struct ceph_connection, struct ceph_connection *con = container_of(work, struct ceph_connection,
work.work); work.work);
bool fault = false; bool fault;
int ret;
mutex_lock(&con->mutex); mutex_lock(&con->mutex);
restart: while (true) {
if (con_sock_closed(con)) { int ret;
if ((fault = con_sock_closed(con))) {
dout("%s: con %p SOCK_CLOSED\n", __func__, con); dout("%s: con %p SOCK_CLOSED\n", __func__, con);
fault = true; break;
goto done;
} }
if (con_backoff(con)) { if (con_backoff(con)) {
dout("%s: con %p BACKOFF\n", __func__, con); dout("%s: con %p BACKOFF\n", __func__, con);
goto done; break;
} }
if (con->state == CON_STATE_STANDBY) { if (con->state == CON_STATE_STANDBY) {
dout("con_work %p STANDBY\n", con); dout("%s: con %p STANDBY\n", __func__, con);
goto done; break;
} }
if (con->state == CON_STATE_CLOSED) { if (con->state == CON_STATE_CLOSED) {
dout("con_work %p CLOSED\n", con); dout("%s: con %p CLOSED\n", __func__, con);
BUG_ON(con->sock); BUG_ON(con->sock);
goto done; break;
} }
if (con->state == CON_STATE_PREOPEN) { if (con->state == CON_STATE_PREOPEN) {
dout("%s: con %p OPENING\n", __func__, con); dout("%s: con %p PREOPEN\n", __func__, con);
BUG_ON(con->sock); BUG_ON(con->sock);
} }
ret = try_read(con); ret = try_read(con);
if (ret == -EAGAIN)
goto restart;
if (ret < 0) { if (ret < 0) {
if (ret == -EAGAIN)
continue;
con->error_msg = "socket error on read"; con->error_msg = "socket error on read";
fault = true; fault = true;
goto done; break;
} }
ret = try_write(con); ret = try_write(con);
if (ret == -EAGAIN)
goto restart;
if (ret < 0) { if (ret < 0) {
if (ret == -EAGAIN)
continue;
con->error_msg = "socket error on write"; con->error_msg = "socket error on write";
fault = true; fault = true;
} }
done:
break; /* If we make it to here, we're done */
}
if (fault) if (fault)
con_fault(con); con_fault(con);
mutex_unlock(&con->mutex); mutex_unlock(&con->mutex);
...@@ -2442,7 +2444,6 @@ static void con_work(struct work_struct *work) ...@@ -2442,7 +2444,6 @@ static void con_work(struct work_struct *work)
con->ops->put(con); con->ops->put(con);
} }
/* /*
* Generic error/fault handler. A retry mechanism is used with * Generic error/fault handler. A retry mechanism is used with
* exponential backoff * exponential backoff
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment