From patchwork Sat Mar 9 16:43:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2241931 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 B4E4E3FCF6 for ; Sat, 9 Mar 2013 16:43:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932860Ab3CIQne (ORCPT ); Sat, 9 Mar 2013 11:43:34 -0500 Received: from mail-ie0-f170.google.com ([209.85.223.170]:44557 "EHLO mail-ie0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932846Ab3CIQnd (ORCPT ); Sat, 9 Mar 2013 11:43:33 -0500 Received: by mail-ie0-f170.google.com with SMTP id c11so3269254ieb.15 for ; Sat, 09 Mar 2013 08:43:33 -0800 (PST) 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=PmvhFhlJzEtM1XbFrJ3xBNd5x6QbX6nLB8nDh1oNq7w=; b=ArTMhwrJSdVoB3zDO0Eygcnl4pbCOYU8rnsWST9GTakcIXHF21DDE9xeRIC/gVRADR lZBp3z+j7101kuSJxLVdtj99+WeJVeQ2Y1TC1dmzaGTP8jfVYK0l54rCIYENsnetAxmk pAHzYf1xkZHcgHJQJczSUUNmie1UZd/9aXuHp9P6kS59KoZRPp3YkNmUphNqRgDLp4z5 m2Hq8oAXcB341VA7bjbIugdS4wYfYTTErMTHPmzcAInGwnNm1SAcNcs+/4xtxV8asDhM YeEJkbc2Xz1HqdEA66Bb++e5f/D0r30H2czTz992n3/5mr93Akj9+cly8ng4h56yG4c9 QR0A== X-Received: by 10.50.140.73 with SMTP id re9mr2775692igb.59.1362847413062; Sat, 09 Mar 2013 08:43:33 -0800 (PST) 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 wx2sm4842975igb.4.2013.03.09.08.43.31 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 09 Mar 2013 08:43:32 -0800 (PST) Message-ID: <513B66B3.3090704@inktank.com> Date: Sat, 09 Mar 2013 10:43:31 -0600 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] libceph: encapsulate reading message data References: <513B661F.4050203@inktank.com> In-Reply-To: <513B661F.4050203@inktank.com> X-Gm-Message-State: ALoCoQkqvieiHLqmHWroHUSRWEt/xOKj31ImW44qeTZg+5y9N11BH97Y92QqTqRRh/19Zi4RhbKZ Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org 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 --- net/ceph/messenger.c | 68 +++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 26 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,45 @@ 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 = 0; + + BUG_ON(!msg); + + data_len = le32_to_cpu(con->in_hdr.data_len); + prepare_message_data(msg, msg_pos); + 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 ret; +} + /* * 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; @@ -1956,10 +1988,6 @@ static int read_partial_message(struct ceph_connection *con) if (m->middle) m->middle->vec.iov_len = 0; - /* prepare for data payload, if any */ - - if (data_len) - prepare_message_data(con->in_msg, &con->in_msg_pos); } /* front */ @@ -1978,22 +2006,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 (m->hdr.data_len) { + ret = read_partial_msg_data(con); + if (ret <= 0) + return ret; } /* footer */ @@ -2119,13 +2135,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..91f577a 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;