From patchwork Wed Jun 27 12:45:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10491411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 477D460325 for ; Wed, 27 Jun 2018 12:48:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3730028D80 for ; Wed, 27 Jun 2018 12:48:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AC8B28D84; Wed, 27 Jun 2018 12:48:48 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0B7228D80 for ; Wed, 27 Jun 2018 12:48:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1B6B6B0283; Wed, 27 Jun 2018 08:48:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CCA1D6B0284; Wed, 27 Jun 2018 08:48:46 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDFF66B0285; Wed, 27 Jun 2018 08:48:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f199.google.com (mail-qt0-f199.google.com [209.85.216.199]) by kanga.kvack.org (Postfix) with ESMTP id 91D8C6B0283 for ; Wed, 27 Jun 2018 08:48:46 -0400 (EDT) Received: by mail-qt0-f199.google.com with SMTP id k8-v6so1766303qtj.18 for ; Wed, 27 Jun 2018 05:48:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=rStqc6ZYuBxwnhHNibknb5sxMcxqSod0DzPk49ANLc8=; b=I2ezJ0bS+X4BKk7lVzw8Or4Uh5dObFhq7l4pRmCMZWD5qUjzz4K60Ku2Hzq6e1pkfq xU8PWbaX6KiWoy7oJ0go3WKVP5l6SAjb40tPcJ6qNv0yURt1QaRnZar3wKHCo6ppbV4P apOV2j2M1yXJ2HHt0VromjGlkTiMEwDyMsPF0sXJjfWuvJxNo+oB15xyAZNEpfAw4fwv kc0fn5y3OSpZWj9hT+Tzj0BR4GM+ibhCR3qdXP6WEtt+3mTyya6PcFNFmqQhP83rit76 X1jzie+QuTPsP1zKcWkrlRTHFFY+Ov40bRpWjNSObZ8v7strX4PeuRUr0uPX1RHjgyAx DRwA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APt69E3KDLPPGgsT+Vf9UkD0vSAcPed+pJB6A+CrEBUAFVDlEazFONk8 XcopecOM5lmAtDjowTZc9wNOI5ZubtNnn0NocWOHm1FC9LC6RGIOi4fBQezCetV8HNUHGcaG0Yi Rzn/q5LOqNMitlZzTk2n/PsZa8FaJVgaoyh+eOKQnQyBVrWWg2TqJ8d4SlLAxrHV1tg== X-Received: by 2002:a37:d683:: with SMTP id p3-v6mr5140670qkl.424.1530103726406; Wed, 27 Jun 2018 05:48:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpekAWdMErjrspti4CN2rKNubHKpNYMcGT8AwdIf2CgBJToxgIWAUkKSx8RbsqM+qcSPe5R5 X-Received: by 2002:a37:d683:: with SMTP id p3-v6mr5140650qkl.424.1530103725916; Wed, 27 Jun 2018 05:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530103725; cv=none; d=google.com; s=arc-20160816; b=gkKQyUFJ77w2tdSkCheP/vR1vccl558DuNEVtq/r+zuNreJy5OlCfAJfeZuUOZDAO/ a0Kt6gReucyXYZK87r3djKaUPlT+4zxaQfiB5OhcRgzC0NrTUyDnRzm2WgIk9HCBa5T8 +H9F2g1u7SJxNBrm/Yhqfu2Wu4kjgqnWq4z9ZwWJbmUfyaQM7TUaDO/XWcyxKVgkTvlQ F8udcV38/AJGndVKqDCcRuTh929/lplsa+2excAZpTgeVEVjg2rxDV77CiTeVLbA3vga HEWN91C7ubPro7iXriAULsYhC8Bcb/8v44Ks5tKNgK5CaJcNwSyK+vFtO7y5YmmLoL0d yWuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rStqc6ZYuBxwnhHNibknb5sxMcxqSod0DzPk49ANLc8=; b=ST97Fqt3kAcBMBXA3Y0vtM3wI6gyPI43aFSjE0vdnwU+9htgcvrEnRoLf7IJTc0AuQ H2vxp8u/yoFh1j7t+6rbyrQo7m14MHktFJJ2oJzXHd3zY5RJfjN0um6TnI1/h960cemU erwM5UcA2gXbGwjKiRMfl+6GzSm6BPn0/O0BJLCKjEzQ97ePXPUdbCtpQqoRTRxm1p53 /lxKFjhiT5uvN3cQB9C3FhL4KdE3iE9kEymc17zJ1gFsluJWJfEHNC3yla0lBY5R9YoL QfJbqtPVCH7epD2jxVKU7DBHzdLaYNDooCLStEJMkgIoG3VEATdZ/Iwv7tSXDfDiCNro qDNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id e49-v6si2163769qta.144.2018.06.27.05.48.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 05:48:45 -0700 (PDT) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92AB181A4EBC; Wed, 27 Jun 2018 12:48:45 +0000 (UTC) Received: from localhost (ovpn-12-44.pek2.redhat.com [10.72.12.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76A372026D5B; Wed, 27 Jun 2018 12:48:37 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Kent Overstreet Cc: David Sterba , Huang Ying , Mike Snitzer , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , "Darrick J . Wong" , Coly Li , Filipe Manana , Randy Dunlap , Ming Lei Subject: [PATCH V7 14/24] block: introduce bvec_last_segment() Date: Wed, 27 Jun 2018 20:45:38 +0800 Message-Id: <20180627124548.3456-15-ming.lei@redhat.com> In-Reply-To: <20180627124548.3456-1-ming.lei@redhat.com> References: <20180627124548.3456-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 27 Jun 2018 12:48:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 27 Jun 2018 12:48:45 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP BTRFS and guard_bio_eod() need to get the last singlepage segment from one multipage bvec, so introduce this helper to make them happy. Signed-off-by: Ming Lei --- include/linux/bvec.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 417d44cf1e82..2269c7608a3e 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -219,4 +219,29 @@ static inline bool mp_bvec_iter_advance(const struct bio_vec *bv, .bi_bvec_done = 0, \ } +/* + * Get the last singlepage segment from the multipage bvec and store it + * in @seg + */ +static inline void bvec_last_segment(const struct bio_vec *bvec, + struct bio_vec *seg) +{ + unsigned total = bvec->bv_offset + bvec->bv_len; + unsigned last_page = total / PAGE_SIZE; + + if (last_page * PAGE_SIZE == total) + last_page--; + + seg->bv_page = nth_page(bvec->bv_page, last_page); + + /* the whole segment is inside the last page */ + if (bvec->bv_offset >= last_page * PAGE_SIZE) { + seg->bv_offset = bvec->bv_offset % PAGE_SIZE; + seg->bv_len = bvec->bv_len; + } else { + seg->bv_offset = 0; + seg->bv_len = total - last_page * PAGE_SIZE; + } +} + #endif /* __LINUX_BVEC_ITER_H */