Distributed Replicated Block Device (DRBD) development
 help / color / mirror / Atom feed
* [Drbd-dev] [PATCH 00/27] block: cleanup direct access on .bi_vcnt & .bi_io_vec
@ 2016-04-05 11:56 Ming Lei
  2016-04-05 11:56 ` [Drbd-dev] [PATCH 02/27] block: drbd: use bio_get_base_vec() to retrieve the 1st bvec Ming Lei
  2016-04-05 11:56 ` [Drbd-dev] [PATCH 03/27] block: drbd: remove impossible failure handling Ming Lei
  0 siblings, 2 replies; 4+ messages in thread
From: Ming Lei @ 2016-04-05 11:56 UTC (permalink / raw)
  To: Jens Axboe, linux-kernel
  Cc: Boaz Harrosh, Jan Kara, Mike Snitzer, NeilBrown, Ming Lei,
	Rasmus Villemoes, Oleg Drokin, Keith Busch, Julia Lawall,
	open list:DEVICE-MAPPER  LVM, open list:TARGET SUBSYSTEM,
	Miklos Szeredi, open list:DRBD DRIVER,
	open list:STAGING SUBSYSTEM, open list:TARGET SUBSYSTEM,
	Minchan Kim, Jarod Wilson, Christoph Hellwig, Kent Overstreet,
	Ming Lin, James Simmons, open list:SUSPEND TO RAM,
	moderated list:STAGING - LUSTRE PARALLEL FILESYSTEM, linux-block,
	Tejun Heo, open list:BCACHE BLOCK LAYER CACHE, Hannes Reinecke,
	John L. Hammond, Omar Sandoval,
	open list:SOFTWARE RAID Multiple Disks SUPPORT, Andreas Dilger,
	open list:MEMORY MANAGEMENT, Jiri Kosina, NeilBrown,
	open list:LogFS, Mike Rapoport, Greg Kroah-Hartman, Joe Perches,
	Andrew Morton, Frank Zago, Al Viro

Hi Guys,

It is always not a good practice to access bio->bi_vcnt and
bio->bi_io_vec from drivers directly. Also this kind of direct
access will cause trouble when converting to multipage bvecs.

The 1st patch introduces the following 4 bio helpers which can be
used inside drivers for avoiding direct access to .bi_vcnt and .bi_io_vec.

	bio_pages()
	bio_is_full()
	bio_get_base_vec()
	bio_set_vec_table()

Both bio_pages() and bio_is_full() can be easy to convert to
multipage bvecs.

For bio_get_base_vec() and bio_set_vec_table(), they are often used
during initializing a new bio or in case of single bvec bio. With the
two new helpers, it becomes quite easy to audit access to .bi_io_vec
and .bi_vcnt.

Most of the other patches use the 4 helpers to clean up most of direct
access to .bi_vcnt and .bi_io_vec from drivers, except for MD and btrfs,
which two subsystems will be done in the future. 

Also bio_add_page() is used in floppy, dm-crypt and fs/logfs to
avoiding direct access to .bi_vcnt & .bi_io_vec.

Thanks,
Ming

Ming Lei (27):
  block: bio: introduce 4 helpers for cleanup
  block: drbd: use bio_get_base_vec() to retrieve the 1st bvec
  block: drbd: remove impossible failure handling
  block: loop: use bio_get_base_vec() to retrive bvec table
  block: pktcdvd: use bio_get_base_vec() to retrive bvec table
  block: floppy: use bio_set_vec_table()
  block: floppy: use bio_add_page()
  staging: lustre: avoid to use bio->bi_vcnt directly
  target: use bio_is_full()
  bcache: debug: avoid to access .bi_io_vec directly
  bcache: io.c: use bio_set_vec_table
  bcache: journal.c: use bio_set_vec_table()
  bcache: movinggc: use bio_set_vec_table()
  bcache: writeback: use bio_set_vec_table()
  bcache: super: use bio_set_vec_table()
  bcache: super: use bio_get_base_vec
  dm: crypt: use bio_add_page()
  dm: dm-io.c: use bio_get_base_vec()
  dm: dm.c: replace 'bio->bi_vcnt == 1' with !bio_multiple_segments
  dm: dm-bufio.c: use bio_set_vec_table()
  fs: logfs: use bio_set_vec_table()
  fs: logfs: convert to bio_add_page() in sync_request()
  fs: logfs: use bio_add_page() in __bdev_writeseg()
  fs: logfs: use bio_add_page() in do_erase()
  fs: logfs: remove unnecesary check
  kernel/power/swap.c: use bio_get_base_vec()
  mm: page_io.c: use bio_get_base_vec()

 drivers/block/drbd/drbd_bitmap.c            |   4 +-
 drivers/block/drbd/drbd_receiver.c          |  14 +---
 drivers/block/floppy.c                      |   9 +--
 drivers/block/loop.c                        |   5 +-
 drivers/block/pktcdvd.c                     |   3 +-
 drivers/md/bcache/debug.c                   |  11 ++-
 drivers/md/bcache/io.c                      |   3 +-
 drivers/md/bcache/journal.c                 |   3 +-
 drivers/md/bcache/movinggc.c                |   6 +-
 drivers/md/bcache/super.c                   |  28 +++++---
 drivers/md/bcache/writeback.c               |   4 +-
 drivers/md/dm-bufio.c                       |   3 +-
 drivers/md/dm-crypt.c                       |   8 +--
 drivers/md/dm-io.c                          |   7 +-
 drivers/md/dm.c                             |   3 +-
 drivers/staging/lustre/lustre/llite/lloop.c |   9 +--
 drivers/target/target_core_pscsi.c          |   2 +-
 fs/logfs/dev_bdev.c                         | 107 +++++++++++-----------------
 include/linux/bio.h                         |  28 ++++++++
 kernel/power/swap.c                         |  10 ++-
 mm/page_io.c                                |  18 ++++-
 21 files changed, 156 insertions(+), 129 deletions(-)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Drbd-dev] [PATCH 02/27] block: drbd: use bio_get_base_vec() to retrieve the 1st bvec
  2016-04-05 11:56 [Drbd-dev] [PATCH 00/27] block: cleanup direct access on .bi_vcnt & .bi_io_vec Ming Lei
@ 2016-04-05 11:56 ` Ming Lei
  2016-04-05 11:56 ` [Drbd-dev] [PATCH 03/27] block: drbd: remove impossible failure handling Ming Lei
  1 sibling, 0 replies; 4+ messages in thread
From: Ming Lei @ 2016-04-05 11:56 UTC (permalink / raw)
  To: Jens Axboe, linux-kernel
  Cc: Christoph Hellwig, Boaz Harrosh, Ming Lei, Philipp Reisner,
	linux-block, Lars Ellenberg, open list:DRBD DRIVER

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/block/drbd/drbd_bitmap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
index 92d6fc0..ccbd1e0 100644
--- a/drivers/block/drbd/drbd_bitmap.c
+++ b/drivers/block/drbd/drbd_bitmap.c
@@ -938,7 +938,9 @@ static void drbd_bm_endio(struct bio *bio)
 	struct drbd_bm_aio_ctx *ctx = bio->bi_private;
 	struct drbd_device *device = ctx->device;
 	struct drbd_bitmap *b = device->bitmap;
-	unsigned int idx = bm_page_to_idx(bio->bi_io_vec[0].bv_page);
+	/* single bvec bio */
+	const struct bio_vec *bvec = bio_get_base_vec(bio);
+	unsigned int idx = bm_page_to_idx(bvec->bv_page);
 
 	if ((ctx->flags & BM_AIO_COPY_PAGES) == 0 &&
 	    !bm_test_page_unchanged(b->bm_pages[idx]))
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Drbd-dev] [PATCH 03/27] block: drbd: remove impossible failure handling
  2016-04-05 11:56 [Drbd-dev] [PATCH 00/27] block: cleanup direct access on .bi_vcnt & .bi_io_vec Ming Lei
  2016-04-05 11:56 ` [Drbd-dev] [PATCH 02/27] block: drbd: use bio_get_base_vec() to retrieve the 1st bvec Ming Lei
@ 2016-04-05 11:56 ` Ming Lei
  2016-04-05 12:42   ` Lars Ellenberg
  1 sibling, 1 reply; 4+ messages in thread
From: Ming Lei @ 2016-04-05 11:56 UTC (permalink / raw)
  To: Jens Axboe, linux-kernel
  Cc: Christoph Hellwig, Boaz Harrosh, Ming Lei, Philipp Reisner,
	linux-block, Lars Ellenberg, open list:DRBD DRIVER

For a non-cloned bio, bio_add_page() only returns failure when
the io vec table is full, but in that case, bio->bi_vcnt can't
be zero at all.

So remove the impossible failure handling.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 drivers/block/drbd/drbd_receiver.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 050aaa1..1b0ed15 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -1465,20 +1465,8 @@ next_bio:
 
 	page_chain_for_each(page) {
 		unsigned len = min_t(unsigned, data_size, PAGE_SIZE);
-		if (!bio_add_page(bio, page, len, 0)) {
-			/* A single page must always be possible!
-			 * But in case it fails anyways,
-			 * we deal with it, and complain (below). */
-			if (bio->bi_vcnt == 0) {
-				drbd_err(device,
-					"bio_add_page failed for len=%u, "
-					"bi_vcnt=0 (bi_sector=%llu)\n",
-					len, (uint64_t)bio->bi_iter.bi_sector);
-				err = -ENOSPC;
-				goto fail;
-			}
+		if (!bio_add_page(bio, page, len, 0))
 			goto next_bio;
-		}
 		data_size -= len;
 		sector += len >> 9;
 		--nr_pages;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Drbd-dev] [PATCH 03/27] block: drbd: remove impossible failure handling
  2016-04-05 11:56 ` [Drbd-dev] [PATCH 03/27] block: drbd: remove impossible failure handling Ming Lei
@ 2016-04-05 12:42   ` Lars Ellenberg
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ellenberg @ 2016-04-05 12:42 UTC (permalink / raw)
  To: Ming Lei
  Cc: linux-block, Boaz Harrosh, Philipp Reisner, linux-kernel,
	Jens Axboe, Christoph Hellwig, drbd-dev

On Tue, Apr 05, 2016 at 07:56:48PM +0800, Ming Lei wrote:
> For a non-cloned bio, bio_add_page() only returns failure when
> the io vec table is full, but in that case, bio->bi_vcnt can't
> be zero at all.
> 
> So remove the impossible failure handling.

Before the immutable bvecs,
we did in fact see this trigger in the wild.
On "strange" deployments.

But for the current implementation of bio_add_page(),
you are correct, this is impossible now.

Ack.

Thanks,

    Lars


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-05 12:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-05 11:56 [Drbd-dev] [PATCH 00/27] block: cleanup direct access on .bi_vcnt & .bi_io_vec Ming Lei
2016-04-05 11:56 ` [Drbd-dev] [PATCH 02/27] block: drbd: use bio_get_base_vec() to retrieve the 1st bvec Ming Lei
2016-04-05 11:56 ` [Drbd-dev] [PATCH 03/27] block: drbd: remove impossible failure handling Ming Lei
2016-04-05 12:42   ` Lars Ellenberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox