lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Tue, 27 Dec 2016 23:56:10 +0800
From:   Ming Lei <tom.leiming@...il.com>
To:     Jens Axboe <axboe@...com>, linux-kernel@...r.kernel.org
Cc:     linux-block@...r.kernel.org, Christoph Hellwig <hch@...radead.org>,
        Ming Lei <tom.leiming@...il.com>,
        Mike Christie <mchristi@...hat.com>,
        Hannes Reinecke <hare@...e.com>,
        Kent Overstreet <kent.overstreet@...il.com>,
        Chaitanya Kulkarni <chaitanya.kulkarni@...t.com>
Subject: [PATCH v1 21/54] block: introduce bio_can_convert_to_sp()

This patch introduces bio_can_convert_to_sp() for checking
if one multipage bio can be converted into one singlepage
bio. If not, returns how many sectors we need to split for
converting the splitted one into singlepage bio.

In the following patches, block bounce and bcache will use
the helper.

Signed-off-by: Ming Lei <tom.leiming@...il.com>
---
 include/linux/bio.h | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/include/linux/bio.h b/include/linux/bio.h
index 0f2859f96468..79079bc5a1be 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -262,6 +262,35 @@ static inline unsigned bio_segments_mp(struct bio *bio)
 }
 
 /*
+ * This helper checks @bio and see if we can convert it into one
+ * singlepage bvec based bio. Return true if yes, otherwise false
+ * is returned.
+ *
+ * @sectors returns how many sectors we need to split for converting
+ * the splitted one into a singlepage bio if the whole bio can't be
+ * converted into a singlepage bio.
+ */
+static inline bool bio_can_convert_to_sp(struct bio *bio, unsigned *sectors)
+{
+	struct bio_vec bv;
+	struct bvec_iter iter;
+	unsigned len = 0;
+	bool ret = true;
+	unsigned segs = 0;
+
+	bio_for_each_segment(bv, bio, iter) {
+		if (++segs > BIO_MAX_PAGES) {
+			ret = false;
+			*sectors = len >> 9;
+			break;
+		}
+		len += bv.bv_len;
+	}
+
+	return ret;
+}
+
+/*
  * get a reference to a bio, so it won't disappear. the intended use is
  * something like:
  *
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ