From patchwork Sun Mar 10 19:16:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2245751 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 59E9EDF24C for ; Sun, 10 Mar 2013 19:16:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753171Ab3CJTQ4 (ORCPT ); Sun, 10 Mar 2013 15:16:56 -0400 Received: from mail-ia0-f172.google.com ([209.85.210.172]:62750 "EHLO mail-ia0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751619Ab3CJTQ4 (ORCPT ); Sun, 10 Mar 2013 15:16:56 -0400 Received: by mail-ia0-f172.google.com with SMTP id l29so2939494iag.17 for ; Sun, 10 Mar 2013 12:16:55 -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=oRBCtyPuhjk5kzrEPt6yRBPjQ0eRljvpHRDV7JSAMW4=; b=bGDq2PllJ+3gytMGhdCZHrSwXlMZ3LA7MSnwbYINUmrB1KPkzgEg3yhuvJVm0iZJjM 7+uU2cNzW3QsTuSJqSCZTwCUWCNlojohFhQ+Qoo8HziJkeIY9LmHvFYHTaIVW6SAS4T2 yjNMHhBWeWKfeKjg8P9iLFVrctBTKTD5Bi8wcFK0pBow1Rf3SFSkWX1RelyUpwo7sQog P83d9gOtxZy2i4jo7tG2ukI2X9gszUOiO4wQgywjGsD2feYJOdB34aiN0D2k0SSV/xIE A2YYmVCc7RwtrqiPblfJ1ypU9ng3Ee1W/5rr5HYX6G/tT5KZ3P+GDje/J+qD3OpFZtO2 v1uQ== X-Received: by 10.50.13.71 with SMTP id f7mr5066712igc.32.1362943015824; Sun, 10 Mar 2013 12:16:55 -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 vb15sm9662493igb.9.2013.03.10.12.16.54 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 10 Mar 2013 12:16:54 -0700 (PDT) Message-ID: <513CDC25.4050600@inktank.com> Date: Sun, 10 Mar 2013 14:16:53 -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 5/8] libceph: prepare for other message data item types References: <513CD9BE.1070505@inktank.com> In-Reply-To: <513CD9BE.1070505@inktank.com> X-Gm-Message-State: ALoCoQlpbHPFTsdBdRqTjXgqMzuQwuVSnHQPs8RpzT5sFOL7Xk7jVAxgpqTwQFAOy86POeFSh/wn Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org This just inserts some infrastructure in preparation for handling other types of ceph message data items. No functional changes, just trying to simplify review by separating out some noise. I will fold this into the previous patch before committing. Signed-off-by: Alex Elder --- include/linux/ceph/messenger.h | 8 +++- net/ceph/messenger.c | 99 ++++++++++++++++++++++++++++++++-------- 2 files changed, 85 insertions(+), 22 deletions(-) BUG_ON(!pagelist); @@ -771,12 +766,7 @@ static void ceph_msg_data_cursor_init(struct ceph_msg_data *data) cursor->last_piece = pagelist->length <= PAGE_SIZE; } -/* - * Return the page containing the next piece to process for a given - * data item, and supply the page offset and length of that piece. - * Indicate whether this is the last piece in this data item. - */ -static struct page *ceph_msg_data_next(struct ceph_msg_data *data, +static struct page *ceph_msg_data_pagelist_next(struct ceph_msg_data *data, size_t *page_offset, size_t *length, bool *last_piece) @@ -808,11 +798,8 @@ static struct page *ceph_msg_data_next(struct ceph_msg_data *data, return data->cursor.page; } -/* - * Returns true if the result moves the cursor on to the next piece - * (the next page) of the pagelist. - */ -static bool ceph_msg_data_advance(struct ceph_msg_data *data, size_t bytes) +static bool ceph_msg_data_pagelist_advance(struct ceph_msg_data *data, + size_t bytes) { struct ceph_msg_data_cursor *cursor = &data->cursor; struct ceph_pagelist *pagelist; @@ -844,6 +831,78 @@ static bool ceph_msg_data_advance(struct ceph_msg_data *data, size_t bytes) return true; } +/* + * Message data is handled (sent or received) in pieces, where each + * piece resides on a single page. The network layer might not + * consume an entire piece at once. A data item's cursor keeps + * track of which piece is next to process and how much remains to + * be processed in that piece. It also tracks whether the current + * piece is the last one in the data item. + */ +static void ceph_msg_data_cursor_init(struct ceph_msg_data *data) +{ + switch (data->type) { + case CEPH_MSG_DATA_NONE: + case CEPH_MSG_DATA_PAGES: + break; + case CEPH_MSG_DATA_PAGELIST: + ceph_msg_data_pagelist_cursor_init(data); + break; +#ifdef CONFIG_BLOCK + case CEPH_MSG_DATA_BIO: +#endif /* CONFIG_BLOCK */ + default: + break; + } +} + +/* + * Return the page containing the next piece to process for a given + * data item, and supply the page offset and length of that piece. + * Indicate whether this is the last piece in this data item. + */ +static struct page *ceph_msg_data_next(struct ceph_msg_data *data, + size_t *page_offset, + size_t *length, + bool *last_piece) +{ + switch (data->type) { + case CEPH_MSG_DATA_NONE: + case CEPH_MSG_DATA_PAGES: + break; + case CEPH_MSG_DATA_PAGELIST: + return ceph_msg_data_pagelist_next(data, page_offset, length, + last_piece); +#ifdef CONFIG_BLOCK + case CEPH_MSG_DATA_BIO: + break; +#endif /* CONFIG_BLOCK */ + } + BUG(); + return NULL; +} + +/* + * Returns true if the result moves the cursor on to the next piece + * of the data item. + */ +static bool ceph_msg_data_advance(struct ceph_msg_data *data, size_t bytes) +{ + switch (data->type) { + case CEPH_MSG_DATA_NONE: + case CEPH_MSG_DATA_PAGES: + break; + case CEPH_MSG_DATA_PAGELIST: + return ceph_msg_data_pagelist_advance(data, bytes); +#ifdef CONFIG_BLOCK + case CEPH_MSG_DATA_BIO: + break; +#endif /* CONFIG_BLOCK */ + } + BUG(); + return false; +} + static void prepare_message_data(struct ceph_msg *msg, struct ceph_msg_pos *msg_pos) { diff --git a/include/linux/ceph/messenger.h b/include/linux/ceph/messenger.h index 1486243..716c3fd 100644 --- a/include/linux/ceph/messenger.h +++ b/include/linux/ceph/messenger.h @@ -97,8 +97,12 @@ static __inline__ bool ceph_msg_data_type_valid(enum ceph_msg_data_type type) struct ceph_msg_data_cursor { bool last_piece; /* now at last piece of data item */ - struct page *page; /* current page in pagelist */ - size_t offset; /* pagelist bytes consumed */ + union { + struct { /* pagelist */ + struct page *page; /* page from list */ + size_t offset; /* bytes from list */ + }; + }; }; struct ceph_msg_data { diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index b978cf8..ce81164 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -742,21 +742,16 @@ static void iter_bio_next(struct bio **bio_iter, unsigned int *seg) #endif /* - * Message data is handled (sent or received) in pieces, where each - * piece resides on a single page. The network layer might not - * consume an entire piece at once. A data item's cursor keeps - * track of which piece is next to process and how much remains to - * be processed in that piece. It also tracks whether the current - * piece is the last one in the data item. + * For a pagelist, a piece is whatever remains to be consumed in the + * first page in the list, or the front of the next page. */ -static void ceph_msg_data_cursor_init(struct ceph_msg_data *data) +static void ceph_msg_data_pagelist_cursor_init(struct ceph_msg_data *data) { struct ceph_msg_data_cursor *cursor = &data->cursor; struct ceph_pagelist *pagelist; struct page *page; - if (data->type != CEPH_MSG_DATA_PAGELIST) - return; + BUG_ON(data->type != CEPH_MSG_DATA_PAGELIST); pagelist = data->pagelist;