From: Mike Snitzer <snitzer@redhat.com>
To: Sergei Shtepa <sergei.shtepa@veeam.com>
Cc: Damien.LeMoal@wdc.com, hare@suse.de, ming.lei@redhat.com,
agk@redhat.com, corbet@lwn.net, axboe@kernel.dk, jack@suse.cz,
johannes.thumshirn@wdc.com, gregkh@linuxfoundation.org,
koct9i@gmail.com, steve@sk2.org, dm-devel@redhat.com,
linux-block@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, pavgel.tide@veeam.com
Subject: Re: [PATCH v4 2/6] block: add blk_interposer
Date: Wed, 3 Feb 2021 11:18:36 -0500 [thread overview]
Message-ID: <20210203161836.GB21359@redhat.com> (raw)
In-Reply-To: <1612367638-3794-3-git-send-email-sergei.shtepa@veeam.com>
On Wed, Feb 03 2021 at 10:53am -0500,
Sergei Shtepa <sergei.shtepa@veeam.com> wrote:
> blk_interposer allows to intercept bio requests, remap bio to another devices or add new bios.
>
> Signed-off-by: Sergei Shtepa <sergei.shtepa@veeam.com>
> ---
> block/bio.c | 2 +
> block/blk-core.c | 33 ++++++++++++++++
> block/genhd.c | 82 +++++++++++++++++++++++++++++++++++++++
> include/linux/blk_types.h | 6 ++-
> include/linux/genhd.h | 18 +++++++++
> 5 files changed, 139 insertions(+), 2 deletions(-)
>
> diff --git a/block/bio.c b/block/bio.c
> index 1f2cc1fbe283..f6f135eb84b5 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -684,6 +684,8 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src)
> bio_set_flag(bio, BIO_CLONED);
> if (bio_flagged(bio_src, BIO_THROTTLED))
> bio_set_flag(bio, BIO_THROTTLED);
> + if (bio_flagged(bio_src, BIO_INTERPOSED))
> + bio_set_flag(bio, BIO_INTERPOSED);
> bio->bi_opf = bio_src->bi_opf;
> bio->bi_ioprio = bio_src->bi_ioprio;
> bio->bi_write_hint = bio_src->bi_write_hint;
> diff --git a/block/blk-core.c b/block/blk-core.c
> index 7663a9b94b80..c84bc42ba88b 100644
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -1032,6 +1032,32 @@ static blk_qc_t __submit_bio_noacct_mq(struct bio *bio)
> return ret;
> }
>
> +static blk_qc_t __submit_bio_interposed(struct bio *bio)
> +{
> + struct bio_list bio_list[2] = { };
> + blk_qc_t ret = BLK_QC_T_NONE;
> +
> + current->bio_list = bio_list;
> + if (likely(bio_queue_enter(bio) == 0)) {
> + struct gendisk *disk = bio->bi_disk;
> +
> + if (likely(blk_has_interposer(disk))) {
> + bio_set_flag(bio, BIO_INTERPOSED);
> + disk->interposer->ip_submit_bio(bio);
> + } else /* interposer was removed */
> + bio_list_add(¤t->bio_list[0], bio);
style nit:
} else {
/* interposer was removed */
bio_list_add(¤t->bio_list[0], bio);
}
> +
> + blk_queue_exit(disk->queue);
> + }
> + current->bio_list = NULL;
> +
> + /* Resubmit remaining bios */
> + while ((bio = bio_list_pop(&bio_list[0])))
> + ret = submit_bio_noacct(bio);
> +
> + return ret;
> +}
> +
> /**
> * submit_bio_noacct - re-submit a bio to the block device layer for I/O
> * @bio: The bio describing the location in memory and on the device.
> @@ -1057,6 +1083,13 @@ blk_qc_t submit_bio_noacct(struct bio *bio)
> return BLK_QC_T_NONE;
> }
>
> + /*
> + * Checking the BIO_INTERPOSED flag is necessary so that the bio
> + * created by the blk_interposer do not get to it for processing.
> + */
> + if (blk_has_interposer(bio->bi_disk) &&
> + !bio_flagged(bio, BIO_INTERPOSED))
> + return __submit_bio_interposed(bio);
> if (!bio->bi_disk->fops->submit_bio)
> return __submit_bio_noacct_mq(bio);
> return __submit_bio_noacct(bio);
> diff --git a/block/genhd.c b/block/genhd.c
> index 419548e92d82..39785a3ef703 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -30,6 +30,7 @@
> static struct kobject *block_depr;
>
> DECLARE_RWSEM(bdev_lookup_sem);
> +DEFINE_MUTEX(bdev_interposer_mutex);
Seems you're using this mutex to protect access to disk->interposer in
attach/detach. This is to prevent attach/detach races to same device?
Thankfully attach/detach isn't in the bio submission fast path but it'd
be helpful to document what this mutex is protecting).
A storm of attach or detach will all hit this global mutex though...
Mike
next prev parent reply other threads:[~2021-02-03 16:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-03 15:53 [PATCH v4 0/6] block-layer interposer Sergei Shtepa
2021-02-03 15:53 ` [PATCH v4 1/6] docs: device-mapper: add remap_and_filter Sergei Shtepa
2021-02-04 4:15 ` Randy Dunlap
2021-02-04 9:44 ` Sergei Shtepa
2021-02-03 15:53 ` [PATCH v4 2/6] block: add blk_interposer Sergei Shtepa
2021-02-03 16:18 ` Mike Snitzer [this message]
2021-02-04 10:06 ` Sergei Shtepa
2021-02-03 15:53 ` [PATCH v4 3/6] block: add blk_mq_is_queue_frozen() Sergei Shtepa
2021-02-03 16:09 ` Mike Snitzer
2021-02-03 15:53 ` [PATCH v4 4/6] dm: new ioctl DM_DEV_REMAP_CMD Sergei Shtepa
2021-02-03 16:00 ` Greg KH
2021-02-03 15:53 ` [PATCH v4 5/6] dm: add 'noexcl' option for dm-linear Sergei Shtepa
2021-02-03 15:53 ` [PATCH v4 6/6] docs: device-mapper: " Sergei Shtepa
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=20210203161836.GB21359@redhat.com \
--to=snitzer@redhat.com \
--cc=Damien.LeMoal@wdc.com \
--cc=agk@redhat.com \
--cc=axboe@kernel.dk \
--cc=corbet@lwn.net \
--cc=dm-devel@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=hare@suse.de \
--cc=jack@suse.cz \
--cc=johannes.thumshirn@wdc.com \
--cc=koct9i@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=pavgel.tide@veeam.com \
--cc=sergei.shtepa@veeam.com \
--cc=steve@sk2.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).