From patchwork Mon Dec 3 12:50:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongsheng Yang X-Patchwork-Id: 10709507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4DB9016B1 for ; Mon, 3 Dec 2018 12:56:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F00A2B415 for ; Mon, 3 Dec 2018 12:56:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 331E42B54C; Mon, 3 Dec 2018 12:56:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0A7E2B415 for ; Mon, 3 Dec 2018 12:56:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726594AbeLCM52 (ORCPT ); Mon, 3 Dec 2018 07:57:28 -0500 Received: from m50211.mail.qiye.163.com ([123.125.50.211]:22276 "EHLO m50211.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726490AbeLCM52 (ORCPT ); Mon, 3 Dec 2018 07:57:28 -0500 Received: from atest-guest.localdomain (unknown [218.94.118.90]) by smtp3 (Coremail) with SMTP id PdOowEDpa0CfJgVcOwAAAA--.14S3; Mon, 03 Dec 2018 20:50:39 +0800 (CST) From: Dongsheng Yang To: idryomov@gmail.com, sage@redhat.com, elder@kernel.org, jdillama@redhat.com Cc: dongsheng.yang@easystack.cn, ceph-devel@vger.kernel.org Subject: [PATCH 01/11] libceph: support prefix and suffix in bio_iter Date: Mon, 3 Dec 2018 07:50:25 -0500 Message-Id: <1543841435-13652-2-git-send-email-dongsheng.yang@easystack.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1543841435-13652-1-git-send-email-dongsheng.yang@easystack.cn> References: <1543841435-13652-1-git-send-email-dongsheng.yang@easystack.cn> X-CM-TRANSID: PdOowEDpa0CfJgVcOwAAAA--.14S3 X-Coremail-Antispam: 1Uf129KBjvJXoW3Jr4DZr17JF1fKrW8WFW8Crg_yoW7Xw4kpF sIga1kGa4fGan7JFW3tF1xAF4fJr93WrW0grZ8Jay5Gw17Jry5JFyIkr9YgF4xKr4kWF1a yrs8AayUCryrJaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JbiOJrUUUUU= X-Originating-IP: [218.94.118.90] X-CM-SenderInfo: 5grqw2pkhqwhp1dqwq5hdv52pwdfyhdfq/1tbiGwASelpcgQPvqAAAsw Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When we want to add some prefix to the bio data, such as journal header, we don't want to copy it from bio into a new larger memory. Instead, we need a prefix page and suffix page to store the header and footer in bio_iter. Signed-off-by: Dongsheng Yang --- include/linux/ceph/messenger.h | 9 ++++ net/ceph/messenger.c | 96 ++++++++++++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 22 deletions(-) diff --git a/include/linux/ceph/messenger.h b/include/linux/ceph/messenger.h index 800a212..0da6a4b 100644 --- a/include/linux/ceph/messenger.h +++ b/include/linux/ceph/messenger.h @@ -87,6 +87,15 @@ enum ceph_msg_data_type { struct ceph_bio_iter { struct bio *bio; struct bvec_iter iter; + size_t bio_len; + + struct page *prefix_page; + unsigned int prefix_offset; + unsigned int prefix_len; + + struct page *suffix_page; + unsigned int suffix_offset; + unsigned int suffix_len; }; #define __ceph_bio_iter_advance_step(it, n, STEP) do { \ diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 57fcc6b..64c70c5 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -828,23 +828,46 @@ static void ceph_msg_data_bio_cursor_init(struct ceph_msg_data_cursor *cursor, cursor->resid = min_t(size_t, length, data->bio_length); *it = data->bio_pos; - if (cursor->resid < it->iter.bi_size) - it->iter.bi_size = cursor->resid; - BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter)); - cursor->last_piece = cursor->resid == bio_iter_len(it->bio, it->iter); + if (cursor->resid < it->iter.bi_size + it->prefix_len + it->suffix_len) + it->iter.bi_size = cursor->resid - it->prefix_len - it->suffix_len; + + it->bio_len = cursor->resid - it->prefix_len - it->suffix_len; + if (it->suffix_len) { + cursor->last_piece = cursor->resid == it->suffix_len; + } else if (it->bio_len) { + cursor->last_piece = cursor->resid == bio_iter_len(it->bio, it->iter); + } else if (it->prefix_len) { + cursor->last_piece = cursor->resid == it->prefix_len; + } else { + BUG(); + } } static struct page *ceph_msg_data_bio_next(struct ceph_msg_data_cursor *cursor, size_t *page_offset, size_t *length) { - struct bio_vec bv = bio_iter_iovec(cursor->bio_iter.bio, - cursor->bio_iter.iter); + struct ceph_bio_iter *it = &cursor->bio_iter; - *page_offset = bv.bv_offset; - *length = bv.bv_len; - return bv.bv_page; + if (it->prefix_len) { + *page_offset = it->prefix_offset; + *length = it->prefix_len; + return it->prefix_page; + } else if (it->bio_len) { + struct bio_vec bv = bio_iter_iovec(cursor->bio_iter.bio, + cursor->bio_iter.iter); + + *page_offset = bv.bv_offset; + *length = bv.bv_len; + return bv.bv_page; + } else { + BUG_ON(!it->suffix_len); + + *page_offset = it->suffix_offset; + *length = it->suffix_len; + return it->suffix_page; + } } static bool ceph_msg_data_bio_advance(struct ceph_msg_data_cursor *cursor, @@ -852,29 +875,58 @@ static bool ceph_msg_data_bio_advance(struct ceph_msg_data_cursor *cursor, { struct ceph_bio_iter *it = &cursor->bio_iter; + if (!bytes) + return false; + BUG_ON(bytes > cursor->resid); - BUG_ON(bytes > bio_iter_len(it->bio, it->iter)); cursor->resid -= bytes; - bio_advance_iter(it->bio, &it->iter, bytes); + if (it->prefix_len) { + BUG_ON(bytes > it->prefix_len); + it->prefix_offset += bytes; + it->prefix_len -= bytes; + if (it->prefix_len) + return false; + } else if (it->bio_len) { + BUG_ON(bytes > bio_iter_len(it->bio, it->iter)); + bio_advance_iter(it->bio, &it->iter, bytes); + it->bio_len -= bytes; + if (!cursor->resid) { + BUG_ON(!cursor->last_piece); + return false; /* no more data */ + } + if (it->iter.bi_size && it->iter.bi_bvec_done) + return false; /* more bytes to process in this segment */ + + if (it->bio_len && !it->iter.bi_size) { + it->bio = it->bio->bi_next; + it->iter = it->bio->bi_iter; + if (cursor->resid < it->iter.bi_size) + it->iter.bi_size = cursor->resid; + } + } else { + BUG_ON(!it->suffix_len); + it->suffix_offset += bytes; + it->suffix_len -= bytes; + if (it->suffix_len) + return false; + } if (!cursor->resid) { BUG_ON(!cursor->last_piece); return false; /* no more data */ } - if (!bytes || (it->iter.bi_size && it->iter.bi_bvec_done)) - return false; /* more bytes to process in this segment */ - - if (!it->iter.bi_size) { - it->bio = it->bio->bi_next; - it->iter = it->bio->bi_iter; - if (cursor->resid < it->iter.bi_size) - it->iter.bi_size = cursor->resid; + BUG_ON(cursor->last_piece); + if (it->suffix_len) { + cursor->last_piece = cursor->resid == it->suffix_len; + } else if (it->bio_len) { + cursor->last_piece = cursor->resid == bio_iter_len(it->bio, it->iter); + } else if (it->prefix_len) { + cursor->last_piece = cursor->resid == it->prefix_len; + } else { + BUG(); } - BUG_ON(cursor->last_piece); - BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter)); - cursor->last_piece = cursor->resid == bio_iter_len(it->bio, it->iter); return true; } #endif /* CONFIG_BLOCK */