From patchwork Sun Mar 10 16:33:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2245071 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 4E7484020C for ; Sun, 10 Mar 2013 16:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752609Ab3CJQd5 (ORCPT ); Sun, 10 Mar 2013 12:33:57 -0400 Received: from mail-qe0-f41.google.com ([209.85.128.41]:37424 "EHLO mail-qe0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751657Ab3CJQdz (ORCPT ); Sun, 10 Mar 2013 12:33:55 -0400 Received: by mail-qe0-f41.google.com with SMTP id 6so1901724qeb.28 for ; Sun, 10 Mar 2013 09:33:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=VkLOSqstwUC0NQdnVPeJ1mXVtB0prJrf0zFwF1Nfg7E=; b=JrsfXkWb8j2IAgkZOiD/UdI6AdhxqEhWmRTpxoKIroiWIig4t9QkScGWGE7ZORWUCz XIY7dmj9DnybRWUbjpm/5yNgP8pVDAvnuPn9OjvyFWRxAdSeIpf8tj4hXxGovxLTd0MK IQYQtOSfk5HRs6aLO23PeE7nmeykWp5koCA7WJHhS+JfK78MPPaXOafniz13Tbsyx2Wf wNy8lv2U+9i+/jqhU1lVDoYxAnYhK0Hszxl3t2ibyszVlxfi9yhvoiqYW9ieeSPANfFc jhl55FroIiPhf+ojisnOpcdiYeS+OJZm1dZJ/Yr8ag+8DKPhMa93R11jbGVditJ8Jue8 nzgA== X-Received: by 10.224.39.146 with SMTP id g18mr13777692qae.2.1362933234088; Sun, 10 Mar 2013 09:33:54 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id dt10sm20595131qab.0.2013.03.10.09.33.51 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 10 Mar 2013 09:33:52 -0700 (PDT) Message-ID: <513CB5EE.2070903@inktank.com> Date: Sun, 10 Mar 2013 11:33:50 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 4/6, v3] libceph: encapsulate reading message data References: <513B661F.4050203@inktank.com> <513B66B3.3090704@inktank.com> In-Reply-To: <513B66B3.3090704@inktank.com> X-Gm-Message-State: ALoCoQnD0fKhyIVEqy/TKyRhHb+6pyNYhxW4XuSg/EwgGcaSgsHqrEIfNRRtDuuHahXXJ+go4uW4 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Found another problem with this one. In order to indicate that the it is successful, read_partial_msg_data() needs to return a positive value (even if no bytes were read because the entire data portion of a message has been read). So this latest version has it return 1 in that case rather than zero. The last update--initializing the message position information--is still in place here. I think this will be the last one (though I probably just jinxed that.) Pull the code that reads the data portion into a message into a separate function read_partial_msg_data(). Rename write_partial_msg_pages() to be write_partial_message_data() to match its read counterpart, and to reflect its more generic purpose. Signed-off-by: Alex Elder --- v3: read_partial_msg_data() returns positive for success v2: do not move the call to prepare_message_data() net/ceph/messenger.c | 63 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 22 deletions(-) struct ceph_msg_pos *msg_pos = &con->out_msg_pos; @@ -1088,7 +1088,7 @@ static int write_partial_msg_pages(struct ceph_connection *con) const size_t trail_len = (msg->trail ? msg->trail->length : 0); const size_t trail_off = data_len - trail_len; - dout("write_partial_msg_pages %p msg %p page %d offset %d\n", + dout("%s %p msg %p page %d offset %d\n", __func__, con, msg, msg_pos->page, msg_pos->page_pos); /* @@ -1157,7 +1157,7 @@ static int write_partial_msg_pages(struct ceph_connection *con) out_msg_pos_next(con, page, length, (size_t) ret, in_trail); } - dout("write_partial_msg_pages %p msg %p done\n", con, msg); + dout("%s %p msg %p done\n", __func__, con, msg); /* prepare and queue up footer, too */ if (!do_datacrc) @@ -1869,13 +1869,44 @@ static int read_partial_message_bio(struct ceph_connection *con, } #endif +static int read_partial_msg_data(struct ceph_connection *con) +{ + struct ceph_msg *msg = con->in_msg; + struct ceph_msg_pos *msg_pos = &con->in_msg_pos; + const bool do_datacrc = !con->msgr->nocrc; + unsigned int data_len; + int ret; + + BUG_ON(!msg); + + data_len = le32_to_cpu(con->in_hdr.data_len); + while (msg_pos->data_pos < data_len) { + if (msg->pages) { + ret = read_partial_message_pages(con, msg->pages, + data_len, do_datacrc); + if (ret <= 0) + return ret; +#ifdef CONFIG_BLOCK + } else if (msg->bio) { + ret = read_partial_message_bio(con, + data_len, do_datacrc); + if (ret <= 0) + return ret; +#endif + } else { + BUG_ON(1); + } + } + + return 1; /* must return > 0 to indicate success */ +} + /* * read (part of) a message. */ static int read_partial_message(struct ceph_connection *con) { struct ceph_msg *m = con->in_msg; - struct ceph_msg_pos *msg_pos = &con->in_msg_pos; int size; int end; int ret; @@ -1978,22 +2009,10 @@ static int read_partial_message(struct ceph_connection *con) } /* (page) data */ - while (msg_pos->data_pos < data_len) { - if (m->pages) { - ret = read_partial_message_pages(con, m->pages, - data_len, do_datacrc); - if (ret <= 0) - return ret; -#ifdef CONFIG_BLOCK - } else if (m->bio) { - ret = read_partial_message_bio(con, - data_len, do_datacrc); - if (ret <= 0) - return ret; -#endif - } else { - BUG_ON(1); - } + if (data_len) { + ret = read_partial_msg_data(con); + if (ret <= 0) + return ret; } /* footer */ @@ -2119,13 +2138,13 @@ more_kvec: goto do_next; } - ret = write_partial_msg_pages(con); + ret = write_partial_message_data(con); if (ret == 1) goto more_kvec; /* we need to send the footer, too! */ if (ret == 0) goto out; if (ret < 0) { - dout("try_write write_partial_msg_pages err %d\n", + dout("try_write write_partial_message_data err %d\n", ret); goto out; } diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 813c299..6e0bd36 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -1076,7 +1076,7 @@ static void in_msg_pos_next(struct ceph_connection *con, size_t len, * 0 -> socket full, but more to do * <0 -> error */ -static int write_partial_msg_pages(struct ceph_connection *con) +static int write_partial_message_data(struct ceph_connection *con) { struct ceph_msg *msg = con->out_msg;