All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@redhat.com>
To: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: device-mapper development <dm-devel@redhat.com>
Subject: Re: [PATCH 7/7] dm-mpath: Fix a race condition in __multipath_map()
Date: Tue, 15 Nov 2016 19:37:20 -0500	[thread overview]
Message-ID: <20161116003720.GA19059@redhat.com> (raw)
In-Reply-To: <81bc399e-df90-099d-1b25-bdb0fda3f27c@sandisk.com>

On Tue, Nov 15 2016 at  6:35pm -0500,
Bart Van Assche <bart.vanassche@sandisk.com> wrote:

> If a single-queue dm device is stacked on top of multi-queue block
> devices and map_tio_request() is called while there are no paths then
> the request will be prepared for a single-queue path. If a path is
> added after a request was prepared and before __multipath_map() is
> called return DM_MAPIO_REQUEUE such that it gets unprepared and
> reprepared as a blk-mq request.

This patch makes little sense to me.  There isn't a scenario that I'm
aware of that would allow the request_queue to transition between old
.request_fn and new blk-mq.

The dm-table code should prevent this.

Mike

> diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
> index 7559537..6b20349 100644
> --- a/drivers/md/dm-mpath.c
> +++ b/drivers/md/dm-mpath.c
> @@ -541,6 +541,7 @@ static int __multipath_map(struct dm_target *ti, struct request *clone,
>  	size_t nr_bytes = clone ? blk_rq_bytes(clone) : blk_rq_bytes(rq);
>  	struct pgpath *pgpath;
>  	struct block_device *bdev;
> +	struct request_queue *q;
>  	struct dm_mpath_io *mpio;
>  
>  	/* Do we need to select a new pgpath? */
> @@ -558,6 +559,18 @@ static int __multipath_map(struct dm_target *ti, struct request *clone,
>  		return r;
>  	}
>  
> +	bdev = pgpath->path.dev->bdev;
> +	q = bdev_get_queue(bdev);
> +
> +	/*
> +	 * When a request is prepared if there are no paths it may happen that
> +	 * the request was prepared for a single-queue path and that a
> +	 * multiqueue path is added before __multipath_map() is called. If
> +	 * that happens requeue to trigger unprepare and reprepare.
> +	 */
> +	if ((clone && q->mq_ops) || (!clone && !q->mq_ops))
> +		return r;
> +
>  	mpio = set_mpio(m, map_context);
>  	if (!mpio)
>  		/* ENOMEM, requeue */
> @@ -566,22 +579,20 @@ static int __multipath_map(struct dm_target *ti, struct request *clone,
>  	mpio->pgpath = pgpath;
>  	mpio->nr_bytes = nr_bytes;
>  
> -	bdev = pgpath->path.dev->bdev;
> -
>  	if (clone) {
>  		/*
>  		 * Old request-based interface: allocated clone is passed in.
>  		 * Used by: .request_fn stacked on .request_fn path(s).
>  		 */
> -		clone->q = bdev_get_queue(bdev);
> +		clone->q = q;
>  	} else {
>  		/*
>  		 * blk-mq request-based interface; used by both:
>  		 * .request_fn stacked on blk-mq path(s) and
>  		 * blk-mq stacked on blk-mq path(s).
>  		 */
> -		clone = blk_mq_alloc_request(bdev_get_queue(bdev),
> -					rq_data_dir(rq), BLK_MQ_REQ_NOWAIT);
> +		clone = blk_mq_alloc_request(q, rq_data_dir(rq),
> +					     BLK_MQ_REQ_NOWAIT);
>  		if (IS_ERR(clone)) {
>  			/* EBUSY, ENODEV or EWOULDBLOCK; requeue */
>  			clear_request_fn_mpio(m, map_context);
> -- 
> 2.10.1
> 
> --
> dm-devel mailing list
> dm-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/dm-devel

  reply	other threads:[~2016-11-16  0:37 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-15 23:31 [PATCH 0/7] dm-mpath: Fix a race condition in the blk-mq path Bart Van Assche
2016-11-15 23:32 ` [PATCH 1/7] dm: Fix a (theoretical?) race condition in rq_completed() Bart Van Assche
2016-11-16  0:46   ` Mike Snitzer
2016-11-15 23:33 ` [PATCH 2/7] dm: Simplify dm_table_determine_type() Bart Van Assche
2016-11-16 14:54   ` Mike Snitzer
2016-11-16 20:14     ` Bart Van Assche
2016-11-16 21:11       ` Mike Snitzer
2016-11-16 21:53         ` Bart Van Assche
2016-11-16 23:09           ` Mike Snitzer
2016-11-15 23:33 ` [PATCH 3/7] dm-mpath: Document a locking assumption Bart Van Assche
2016-11-18  0:07   ` Mike Snitzer
2016-11-15 23:34 ` [PATCH 4/7] dm-mpath: Change return type of pg_init_all_paths() from int into void Bart Van Assche
2016-11-15 23:34 ` [PATCH 5/7] dm-mpath: Do not touch *__clone if request allocation fails Bart Van Assche
2016-11-15 23:34 ` [PATCH 6/7] dm-mpath: Avoid code duplication in __multipath_map() Bart Van Assche
2016-11-16  0:39   ` Mike Snitzer
2016-11-15 23:35 ` [PATCH 7/7] dm-mpath: Fix a race condition " Bart Van Assche
2016-11-16  0:37   ` Mike Snitzer [this message]
2016-11-16  0:40     ` Bart Van Assche
2016-11-16  1:01       ` Mike Snitzer
2016-11-16  1:08         ` Bart Van Assche
2016-11-16  1:50           ` Mike Snitzer
2016-11-21 21:44     ` Bart Van Assche
2016-11-21 23:43       ` Mike Snitzer
2016-11-21 23:57         ` Bart Van Assche
2016-11-22  0:34           ` Mike Snitzer
2016-11-22 23:47             ` Bart Van Assche
2016-11-23  0:48               ` Mike Snitzer
2016-11-23  3:16                 ` Mike Snitzer
2016-11-23 18:28                   ` Bart Van Assche
2016-11-23 18:50                     ` Mike Snitzer
2016-11-16  0:47 ` [PATCH 0/7] dm-mpath: Fix a race condition in the blk-mq path Mike Snitzer
2016-11-16  0:57   ` Bart Van Assche
2016-11-16  1:08     ` Mike Snitzer
2016-11-16  1:10       ` Bart Van Assche
2016-11-16  1:53         ` Mike Snitzer
2016-11-16  7:39 ` Hannes Reinecke
2016-11-16 14:56   ` Mike Snitzer
2016-11-16 18:22     ` Bart Van Assche
2016-11-16 19:32       ` Mike Snitzer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161116003720.GA19059@redhat.com \
    --to=snitzer@redhat.com \
    --cc=bart.vanassche@sandisk.com \
    --cc=dm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.