From patchwork Mon Apr 27 17:13:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 6281971 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AA5EF9F1C2 for ; Mon, 27 Apr 2015 17:13:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD636203C1 for ; Mon, 27 Apr 2015 17:13:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D474A203C3 for ; Mon, 27 Apr 2015 17:13:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964954AbbD0RNb (ORCPT ); Mon, 27 Apr 2015 13:13:31 -0400 Received: from mail-pd0-f169.google.com ([209.85.192.169]:35474 "EHLO mail-pd0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964825AbbD0RNZ (ORCPT ); Mon, 27 Apr 2015 13:13:25 -0400 Received: by pdbqd1 with SMTP id qd1so134963626pdb.2 for ; Mon, 27 Apr 2015 10:13:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=cajw+BT0hGdFB91B1wuepDN1ytAOKsYAlxmILt2Q6sM=; b=ICvpDQx+2hpTTuqANFFDtWrieQQ1JSwQukrXvbd+Hk38at5aNmDZD6PaM5fR5zHb3A CHIkU12qQpuFPRAwS4sqwjL0GvykHgbHLaB4s28dpxVuXJS5Cc77NaaC7Bu7Ui3kz23b shIWHK7IYM+wfBod9etoFIekFXa6nCEBHJN3WKwvEMOJILgpghWNlFNaBotovExplASD YimsJtazUpIkRlWkvtK/BHt2rCNwIi3QiNfyyEEynq93VDXJ05l53Zzz8/Da8t8Poy3F eeycUP4hx4g6i+YiX3ujd1R//ml7xEfxu7YyQDWY1I48VZw1uGyyeAVYEQhK06G4scyu B5Xw== X-Gm-Message-State: ALoCoQmP66KNSsw9eaDJgHbjiMj6uv2Wh+iOMQoD6YMpUBElzvGJKrukrpghs5YECVwWdWF6deM4 X-Received: by 10.70.131.193 with SMTP id oo1mr24186923pdb.63.1430154805191; Mon, 27 Apr 2015 10:13:25 -0700 (PDT) Received: from shibby.corp.google.com ([104.135.1.105]) by mx.google.com with ESMTPSA id ff10sm12124675pab.13.2015.04.27.10.13.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Apr 2015 10:13:24 -0700 (PDT) From: Alex Elder To: ceph-devel@vger.kernel.org Subject: [PATCH 7/7] messenger: con_work() is not really a loop Date: Mon, 27 Apr 2015 12:13:15 -0500 Message-Id: <1430154795-17123-8-git-send-email-elder@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1430154795-17123-1-git-send-email-elder@linaro.org> References: <1430154795-17123-1-git-send-email-elder@linaro.org> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In con_work(), a while(true) loop is used to contain a block of code. The normal path through that code does *not* actually loop. The only time it loops is if a socket read or write operation returns -EAGAIN. So the use of the loop control structure is a little misleading. Restructure that block so it's *not* a loop, and use "goto" calls rather than a loop to implement the control flow. Signed-off-by: Alex Elder --- net/ceph/messenger.c | 84 +++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index ec60c23..053c5f3 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -2845,54 +2845,52 @@ static void con_work(struct work_struct *work) struct ceph_connection *con = container_of(work, struct ceph_connection, work.work); bool fault; + int ret; mutex_lock(&con->mutex); - while (true) { - int ret; - - if ((fault = con_sock_closed(con))) { - dout("%s: con %p SOCK_CLOSED\n", __func__, con); - break; - } - if (con_backoff(con)) { - dout("%s: con %p BACKOFF\n", __func__, con); - break; - } - if (con->state == CON_STATE_STANDBY) { - dout("%s: con %p STANDBY\n", __func__, con); - break; - } - if (con->state == CON_STATE_CLOSED) { - dout("%s: con %p CLOSED\n", __func__, con); - BUG_ON(con->sock); - break; - } - if (con->state == CON_STATE_PREOPEN) { - dout("%s: con %p PREOPEN\n", __func__, con); - BUG_ON(con->sock); - } - - ret = try_read(con); - if (ret < 0) { - if (ret == -EAGAIN) - continue; - if (!con->error_msg) - con->error_msg = "socket error on read"; - fault = true; - break; - } +again: + fault = con_sock_closed(con); + if (fault) { + dout("%s: con %p SOCK_CLOSED\n", __func__, con); + goto done; + } + if (con_backoff(con)) { + dout("%s: con %p BACKOFF\n", __func__, con); + goto done; + } + if (con->state == CON_STATE_STANDBY) { + dout("%s: con %p STANDBY\n", __func__, con); + goto done; + } + if (con->state == CON_STATE_CLOSED) { + dout("%s: con %p CLOSED\n", __func__, con); + BUG_ON(con->sock); + goto done; + } + if (con->state == CON_STATE_PREOPEN) { + dout("%s: con %p PREOPEN\n", __func__, con); + BUG_ON(con->sock); + } - ret = try_write(con); - if (ret < 0) { - if (ret == -EAGAIN) - continue; - if (!con->error_msg) - con->error_msg = "socket error on write"; - fault = true; - } + ret = try_read(con); + if (ret < 0) { + if (ret == -EAGAIN) + goto again; + if (!con->error_msg) + con->error_msg = "socket error on read"; + fault = true; + goto done; + } - break; /* If we make it to here, we're done */ + ret = try_write(con); + if (ret < 0) { + if (ret == -EAGAIN) + goto again; + if (!con->error_msg) + con->error_msg = "socket error on write"; + fault = true; } +done: if (fault) con_fault(con); mutex_unlock(&con->mutex);