Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp33053pxv; Wed, 14 Jul 2021 22:15:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhCBhehSlQ5Sht2SRuZF0LyP7pa+BZOTx5w/NiuTo13X1a3i1B7/Ov3VoaB+1gxB4/eHUg X-Received: by 2002:a17:906:388b:: with SMTP id q11mr2979664ejd.43.1626326110778; Wed, 14 Jul 2021 22:15:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626326110; cv=none; d=google.com; s=arc-20160816; b=yYq9gYpUcBJgwq56A5Eam5rjy+77zkyecBzgnqNpWFakfmBrqQ3k6U3BDUba0MqmHN w8N+v601bYcBPf45yLBz88aTBDVpaJpbao0Jx1T5hnvrHfoVhZ5fLXxdiayY23mUMzRH HLxHN9OnroXEiaPK5MB1fuRxUNhIR//r+AqNx8foeqk4fYrWKGFRc9+zB98ApuWt9e5o zizz3gSMVdBHYraVvgJRMRU+CNx2n8So1YEx86iy145jWJpAW0QasjaUeKDAUov3k5mP JGC6Q0v282YYD9ijOuhIZZ+/tubPk19VPrq6rnCPC/ZvY/mG0pjF79UdlIvX7DSRchOB PmHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nR2oa5e93nFAI2YDNXg5bh3xw6tIvBeN/m4O0bgKbkg=; b=1FpF0HCmit3Ubhv1Sw2v+MqFW9lrfz3kul6LqAUSs14d+2lD/sbwyRYudBx/9sXP+P U4P8YPyhd18nYwc/RR1G6QSgQKVdqp2Oy9gipsZ1Z2USAs78VmXHMtlAGAvNMQIVM6ub eURfULwYsrjjunDR5lET+tCxDNKPkpwHtquDqlwwy30h7LDFPCbw11JtxvOflWS9geS+ OSK/1n1A3O6dOJduFG+uEsZxy8QezH3FpM/Oi5AjcPDF0aZx9V352v2LVIcQY2pgNnGW qCGPdFzgj6FY92ndfR00YSUlLreTLD2UUgLhW7ADYFfFaS6ohCGRMV6odPXMmU1ITZQa vMJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Jw7RSMUH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bl4si6159254ejb.689.2021.07.14.22.14.48; Wed, 14 Jul 2021 22:15:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Jw7RSMUH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238238AbhGOEw6 (ORCPT + 99 others); Thu, 15 Jul 2021 00:52:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230260AbhGOEw5 (ORCPT ); Thu, 15 Jul 2021 00:52:57 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C7B4C06175F; Wed, 14 Jul 2021 21:50:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=nR2oa5e93nFAI2YDNXg5bh3xw6tIvBeN/m4O0bgKbkg=; b=Jw7RSMUHmstQ0QgkqASbq5J0yi jjJWrPgUdm4Ls0Qw3rWSdBATQyFfZy1twlES6IgCkYfga9AsDpdum2+4FFRDeSEtrl1/udjOpR+Vs gPKfe/ddO56BwwWwxXpYy/TROoslQgTIwXioHWsCZW2Jk1Jk3L9tFJekJGQxy2UySBg/qdJkhsH8L poHi/vo9fjXxeehKZphi1dS8tQ+gt8to8vSUK/jLqcy9/NVcM+Sl0M3NQvk1nKnplMO/XVtiFUZ7E QZghEvsPdF7yoKCLDlGs5qP0bjk1qxl/tTzCnQq+za+x97/aZVlqFd4lLG1ghbujhEF6zrMZCaYqR 7xZfWZ+w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3tIj-002yn6-2I; Thu, 15 Jul 2021 04:49:00 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v14 091/138] block: Add bio_for_each_folio_all() Date: Thu, 15 Jul 2021 04:36:17 +0100 Message-Id: <20210715033704.692967-92-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715033704.692967-1-willy@infradead.org> References: <20210715033704.692967-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow callers to iterate over each folio instead of each page. The bio need not have been constructed using folios originally. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/bio.h | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/include/linux/bio.h b/include/linux/bio.h index ade93e2de6a1..d462bbc95c4b 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -189,7 +189,7 @@ static inline void bio_advance_iter_single(const struct bio *bio, */ #define bio_for_each_bvec_all(bvl, bio, i) \ for (i = 0, bvl = bio_first_bvec_all(bio); \ - i < (bio)->bi_vcnt; i++, bvl++) \ + i < (bio)->bi_vcnt; i++, bvl++) #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len) @@ -314,6 +314,47 @@ static inline struct bio_vec *bio_last_bvec_all(struct bio *bio) return &bio->bi_io_vec[bio->bi_vcnt - 1]; } +struct folio_iter { + struct folio *folio; + size_t offset; + size_t length; + size_t _seg_count; + int _i; +}; + +static inline +void bio_first_folio(struct folio_iter *fi, struct bio *bio, int i) +{ + struct bio_vec *bvec = bio_first_bvec_all(bio) + i; + + fi->folio = page_folio(bvec->bv_page); + fi->offset = bvec->bv_offset + + PAGE_SIZE * (bvec->bv_page - &fi->folio->page); + fi->_seg_count = bvec->bv_len; + fi->length = min(folio_size(fi->folio) - fi->offset, fi->_seg_count); + fi->_i = i; +} + +static inline void bio_next_folio(struct folio_iter *fi, struct bio *bio) +{ + fi->_seg_count -= fi->length; + if (fi->_seg_count) { + fi->folio = folio_next(fi->folio); + fi->offset = 0; + fi->length = min(folio_size(fi->folio), fi->_seg_count); + } else if (fi->_i + 1 < bio->bi_vcnt) { + bio_first_folio(fi, bio, fi->_i + 1); + } else { + fi->folio = NULL; + } +} + +/* + * Iterate over each folio in a bio. + */ +#define bio_for_each_folio_all(fi, bio) \ + for (bio_first_folio(&fi, bio, 0); fi.folio; bio_next_folio(&fi, bio)) + enum bip_flags { BIP_BLOCK_INTEGRITY = 1 << 0, /* block layer owns integrity data */ BIP_MAPPED_INTEGRITY = 1 << 1, /* ref tag has been remapped */ -- 2.30.2