From patchwork Mon Jan 21 08:17:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10773191 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 484441390 for ; Mon, 21 Jan 2019 08:20:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3930B29EE6 for ; Mon, 21 Jan 2019 08:20:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D5D429EEA; Mon, 21 Jan 2019 08:20:40 +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 C50E229EE6 for ; Mon, 21 Jan 2019 08:20:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D9E2D8E0032; Mon, 21 Jan 2019 03:20:38 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D4EE58E0025; Mon, 21 Jan 2019 03:20:38 -0500 (EST) 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 C17458E0032; Mon, 21 Jan 2019 03:20:38 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 969458E0025 for ; Mon, 21 Jan 2019 03:20:38 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id t18so20379706qtj.3 for ; Mon, 21 Jan 2019 00:20:38 -0800 (PST) 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=UPqY5b1JqVkM1npPaeOz/GFx2XqKiaYkjhq3oYeVa/0=; b=HUrAcMnGlIBk+Z6wSD5zDlLX8CNEVFkr2J6GFwrgBHb5k6RCYZKjkLVBDjMKQGeJ/r 2xG/uFN95rdpFVO1KhZwzxZ6tEJgioKlNic4dixeu/iDIhuxTpHPO61LyaUfMH9D7kmw nDV9wYO1ySmi2eH6Sliy1bm5mrEnB+08VgeX52qAwj6/lqFJNI1Jvxtx/hwFPU6Ln+NX 6ircLl0OBhwG9NBGLw4G4Y6rcgCA9NPtWPruYszbM3OT20g4MJp3LJoVcDP3Ql5zt8yQ Xz58LOyaPOwEgPfjOa6Lp3gAMxramDrQBAe8icyzEND8dAW3TUxGPHw2mfHaYmauMBH7 Tz5w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 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: AJcUuke/jIcxlQA3leeJM80Z4qoYkZGsEzqFiqGP45/1hRAhMqESAeu9 cl4bZZOWjaxSPZRLfW61HMDxLJEUvGN89ApWv1couOHwa9fr5DZyQYd+bjwUFrevLrJXKiVEY9E /IXdtrLapqYyu5g9YEIavri1DuQbPO5+5f2sbmePTmbZl9417RgubDiW54JzWh180eA== X-Received: by 2002:a37:6bc1:: with SMTP id g184mr23505366qkc.236.1548058838403; Mon, 21 Jan 2019 00:20:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN4FTlKrgVCXKIBBZCrAhsGfgFwVchxgAzkIit4Buw1XR1AdGE7Y9WZ15BazE2qlKOBcDNA3 X-Received: by 2002:a37:6bc1:: with SMTP id g184mr23505353qkc.236.1548058837693; Mon, 21 Jan 2019 00:20:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548058837; cv=none; d=google.com; s=arc-20160816; b=cgM8c1pk9A+JqjAhKBM5ihCVNi7URH6cZVZ976TM/7flKjKymM2pZIQWqOiKIVO4YX 6L4G2TKbKcg2jaoUYypqP9vnFaHGQph26FNtUmhtGZYaqlmyE0ZMPD/eEFIyIC+YK69u EKtVhnDr3HDoicitKUIaBbjvyS0fHN/i0IIq9znSzXlyDjwUsLqFzmj7snQHIgnPB/UK V8I6nLn8bH7wGhtoKwAfKngZb30eOxB3D2SsiUve1N14poeSjqWNpjGAyic+OEfBX7Y2 oxK9KK0idRJMf6xPJU444oW9ir1NVtaG78D/nBxTtYR9WBQ6+OvLdh7BQccPO4TV7wlu 7e8Q== 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; bh=UPqY5b1JqVkM1npPaeOz/GFx2XqKiaYkjhq3oYeVa/0=; b=Ehb08wVx5My7FiHSIZ1J1bKY1f/lJpq0kvENDLhvOysBLJPIrH9NnvW7nY3fkVw6gQ UUZhBSF3O6/ln5ayDyGGN6GGx0wod52woTqFN0rPrqY7Ln5G11EVEjU9bXJl4pXE49Z4 eIidF1t6lbjXjjpPLg3i/tGnzVzJFRwDCe/KRmOZcd1DkYmm92i+fZRnMMhrXxwEf3BB jR0WJAreHLsUIuHz+it2k4YrnnJinr8OnQP+2AdsFEqJuXqjps/kDXvVf8H5Jv4ltYnk NDwktOaJr2jEdaxhPf4mR5B37ic6+MEbvji9LtYxWa6NPgUptdi0FebgYUAEvyW4FJUw sm5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 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 (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id i13si1831724qtm.380.2019.01.21.00.20.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 00:20:37 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 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-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADB8C1640; Mon, 21 Jan 2019 08:20:36 +0000 (UTC) Received: from localhost (ovpn-8-22.pek2.redhat.com [10.72.8.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5444D19741; Mon, 21 Jan 2019 08:20:33 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V14 08/18] block: introduce mp_bvec_last_segment() Date: Mon, 21 Jan 2019 16:17:55 +0800 Message-Id: <20190121081805.32727-9-ming.lei@redhat.com> In-Reply-To: <20190121081805.32727-1-ming.lei@redhat.com> References: <20190121081805.32727-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 21 Jan 2019 08:20:37 +0000 (UTC) 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. Reviewed-by: Omar Sandoval Signed-off-by: Ming Lei --- include/linux/bvec.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 0ae729b1c9fe..21f76bad7be2 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -131,4 +131,26 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, .bi_bvec_done = 0, \ } +/* + * Get the last single-page segment from the multi-page bvec and store it + * in @seg + */ +static inline void mp_bvec_last_segment(const struct bio_vec *bvec, + struct bio_vec *seg) +{ + unsigned total = bvec->bv_offset + bvec->bv_len; + unsigned last_page = (total - 1) / PAGE_SIZE; + + 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 */