Thread (76 messages) 76 messages, 5 authors, 2012-09-21

Re: [PATCH v2 02/26] block: Add bio_advance()

From: Kent Overstreet <hidden>
Date: 2012-09-20 23:13:13
Also in: dm-devel, lkml

On Thu, Sep 20, 2012 at 02:58:27PM -0700, Tejun Heo wrote:
On Mon, Sep 10, 2012 at 05:22:13PM -0700, Kent Overstreet wrote:
quoted
+/**
+ * bio_advance - increment/complete a bio by some number of bytes
+ * @bio:	bio to advance
+ * @bytes:	number of bytes to complete
+ *
+ * This updates bi_sector, bi_size and bi_idx; if the number of bytes to
+ * complete doesn't align with a bvec boundary, then bv_len and bv_offset will
+ * be updated on the last bvec as well.
+ *
+ * @bio will then represent the remaining, uncompleted portion of the io.
+ */
+void bio_advance(struct bio *bio, unsigned bytes)
+{
+	if (bio_integrity(bio))
+		bio_integrity_advance(bio, bytes);
+
+	bio->bi_sector += bytes >> 0;
Hmmm.... bytes >> 0?
Whoops...
quoted
+	bio->bi_size -= bytes;
+
+	if (!bio->bi_size)
+		return;
+
+	while (bytes) {
+		if (unlikely(bio->bi_idx >= bio->bi_vcnt)) {
+			printk(KERN_ERR "%s: bio idx %d >= vcnt %d\n",
pr_err() is preferred but maybe WARN_ON_ONCE() is better fit here?
This happening would be a bug, right?
I just cut and pasted that from blk_update_request(), which is what the
next patch refactors...

But yes it would be a bug. It gets converted to a BUG_ON() in a later
patch (not in this series), as this gets further abstracted into a
wrapper around bvec_advance_iter() which doesn't know about struct bio
(as bio integrity gets its own iterator).

Might drop it entirely, depending on what exactly I end up doing with
bi_vcnt...
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help