From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: axboe@kernel.dk, zab@redhat.com, martin.petersen@oracle.com,
darrick.wong@oracle.com, JBottomley@parallels.com,
jmoyer@redhat.com, bcrl@kvack.org, viro@zeniv.linux.org.uk
Cc: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org,
linux-scsi@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 6/6] blk-integrity: refactor various routines
Date: Mon, 24 Mar 2014 09:23:13 -0700 [thread overview]
Message-ID: <20140324162313.10848.7587.stgit@birch.djwong.org> (raw)
In-Reply-To: <20140324162231.10848.4863.stgit@birch.djwong.org>
Refactor blk-integrity.c to avoid duplicating similar functions, and
remove all users of pi_buf, since it's really only there to handle the
(common) case where the kernel auto-generates all the PI data.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
fs/bio-integrity.c | 120 +++++++++++++++++++++------------------------------
include/linux/bio.h | 2 -
2 files changed, 49 insertions(+), 73 deletions(-)
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
index 381ee38..3ff1572 100644
--- a/fs/bio-integrity.c
+++ b/fs/bio-integrity.c
@@ -97,8 +97,7 @@ void bio_integrity_free(struct bio *bio)
struct bio_integrity_payload *bip = bio->bi_integrity;
struct bio_set *bs = bio->bi_pool;
- if (bip->bip_owns_buf)
- kfree(bip->bip_buf);
+ kfree(bip->bip_buf);
if (bs) {
if (bip->bip_slab != BIO_POOL_NONE)
@@ -239,9 +238,11 @@ static int bio_integrity_tag(struct bio *bio, void *tag_buf, unsigned int len,
{
struct bio_integrity_payload *bip = bio->bi_integrity;
struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
- unsigned int nr_sectors;
-
- BUG_ON(bip->bip_buf == NULL);
+ unsigned int nr_sectors, tag_offset, sectors;
+ void *prot_buf;
+ unsigned int prot_offset, prot_len;
+ struct bio_vec *iv;
+ void (*tag_fn)(void *buf, void *tag_buf, unsigned int);
if (bi->tag_size == 0)
return -1;
@@ -255,10 +256,30 @@ static int bio_integrity_tag(struct bio *bio, void *tag_buf, unsigned int len,
return -1;
}
- if (set)
- bi->set_tag_fn(bip->bip_buf, tag_buf, nr_sectors);
- else
- bi->get_tag_fn(bip->bip_buf, tag_buf, nr_sectors);
+ iv = bip->bip_vec;
+ prot_offset = iv->bv_offset;
+ prot_len = iv->bv_len;
+ prot_buf = kmap_atomic(iv->bv_page);
+ tag_fn = set ? bi->set_tag_fn : bi->get_tag_fn;
+ tag_offset = 0;
+
+ while (nr_sectors) {
+ if (prot_len < bi->tuple_size) {
+ kunmap_atomic(prot_buf);
+ iv++;
+ BUG_ON(iv >= bip->bip_vec + bip->bip_vcnt);
+ prot_offset = iv->bv_offset;
+ prot_len = iv->bv_len;
+ prot_buf = kmap_atomic(iv->bv_page);
+ }
+ sectors = min(prot_len / bi->tuple_size, nr_sectors);
+ tag_fn(prot_buf + prot_offset, tag_buf + tag_offset, sectors);
+ nr_sectors -= sectors;
+ tag_offset += sectors * bi->tuple_size;
+ prot_offset += sectors * bi->tuple_size;
+ prot_len -= sectors * bi->tuple_size;
+ }
+ kunmap_atomic(prot_buf);
return 0;
}
@@ -300,28 +321,24 @@ int bio_integrity_get_tag(struct bio *bio, void *tag_buf, unsigned int len)
}
EXPORT_SYMBOL(bio_integrity_get_tag);
-/**
- * bio_integrity_update_user_buffer - Update user-provided PI buffers for a bio
- * @bio: bio to generate/verify integrity metadata for
- */
-int bio_integrity_update_user_buffer(struct bio *bio)
+typedef int (walk_buf_fn)(struct blk_integrity_exchg *bi, int flags);
+
+static int bio_integrity_walk_bufs(struct bio *bio, sector_t sector,
+ walk_buf_fn *mod_fn)
{
struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
struct blk_integrity_exchg bix;
struct bio_vec bv;
struct bvec_iter iter;
- sector_t sector;
unsigned int sectors, total, ret;
void *prot_buf;
unsigned int prot_offset, prot_len, bv_offset, bv_len;
struct bio_vec *iv;
struct bio_integrity_payload *bip = bio->bi_integrity;
- if (!bi->mod_user_buf_fn)
+ if (!mod_fn)
return 0;
- sector = bio->bi_iter.bi_sector;
-
total = ret = 0;
bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
bix.sector_size = bi->sector_size;
@@ -351,7 +368,7 @@ int bio_integrity_update_user_buffer(struct bio *bio)
bix.prot_buf = prot_buf + prot_offset;
bix.sector = sector;
- ret = bi->mod_user_buf_fn(&bix, bip->bip_user_flags);
+ ret = mod_fn(&bix, bip->bip_user_flags);
if (ret) {
if (ret == -ENOTTY)
ret = 0;
@@ -374,59 +391,19 @@ int bio_integrity_update_user_buffer(struct bio *bio)
kunmap_atomic(prot_buf);
return ret;
}
-EXPORT_SYMBOL_GPL(bio_integrity_update_user_buffer);
/**
- * bio_integrity_generate_verify - Generate/verify integrity metadata for a bio
+ * bio_integrity_update_user_buffer - Update user-provided PI buffers for a bio
* @bio: bio to generate/verify integrity metadata for
- * @operate: operate number, 1 for generate, 0 for verify
+ * @sector: stratin
*/
-static int bio_integrity_generate_verify(struct bio *bio, int operate)
+int bio_integrity_update_user_buffer(struct bio *bio)
{
struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
- struct blk_integrity_exchg bix;
- struct bio_vec bv;
- struct bvec_iter iter;
- sector_t sector;
- unsigned int sectors, total, ret;
- void *prot_buf = bio->bi_integrity->bip_buf;
-
- if (operate)
- sector = bio->bi_iter.bi_sector;
- else
- sector = bio->bi_integrity->bip_iter.bi_sector;
-
- total = ret = 0;
- bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
- bix.sector_size = bi->sector_size;
-
- bio_for_each_segment(bv, bio, iter) {
- void *kaddr = kmap_atomic(bv.bv_page);
- bix.data_buf = kaddr + bv.bv_offset;
- bix.data_size = bv.bv_len;
- bix.prot_buf = prot_buf;
- bix.sector = sector;
-
- if (operate) {
- bi->generate_fn(&bix);
- } else {
- ret = bi->verify_fn(&bix);
- if (ret) {
- kunmap_atomic(kaddr);
- return ret;
- }
- }
-
- sectors = bv.bv_len / bi->sector_size;
- sector += sectors;
- prot_buf += sectors * bi->tuple_size;
- total += sectors * bi->tuple_size;
- BUG_ON(total > bio->bi_integrity->bip_iter.bi_size);
-
- kunmap_atomic(kaddr);
- }
- return ret;
+ return bio_integrity_walk_bufs(bio, bio->bi_iter.bi_sector,
+ bi->mod_user_buf_fn);
}
+EXPORT_SYMBOL_GPL(bio_integrity_update_user_buffer);
/**
* bio_integrity_generate - Generate integrity metadata for a bio
@@ -439,7 +416,9 @@ static int bio_integrity_generate_verify(struct bio *bio, int operate)
*/
static void bio_integrity_generate(struct bio *bio)
{
- bio_integrity_generate_verify(bio, 1);
+ struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
+ bio_integrity_walk_bufs(bio, bio->bi_iter.bi_sector,
+ (walk_buf_fn *)bi->generate_fn);
}
static inline unsigned short blk_integrity_tuple_size(struct blk_integrity *bi)
@@ -479,7 +458,6 @@ int bio_integrity_prep_buffer(struct bio *bio, int rw,
sectors = bio_integrity_hw_sectors(bi, bio_sectors(bio));
- /* Allocate kernel buffer for protection data */
len = sectors * blk_integrity_tuple_size(bi);
end = (pi->pi_offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
start = pi->pi_offset >> PAGE_SHIFT;
@@ -497,8 +475,6 @@ int bio_integrity_prep_buffer(struct bio *bio, int rw,
return -EIO;
}
- bip->bip_owns_buf = 0;
- bip->bip_buf = NULL;
bip->bip_iter.bi_size = len;
bip->bip_iter.bi_sector = bio->bi_iter.bi_sector;
bip->bip_user_flags = pi->pi_userflags;
@@ -591,7 +567,6 @@ int bio_integrity_prep(struct bio *bio)
return -EIO;
}
- bip->bip_owns_buf = 1;
bip->bip_buf = buf;
bip->bip_iter.bi_size = len;
bip->bip_iter.bi_sector = bio->bi_iter.bi_sector;
@@ -646,7 +621,10 @@ EXPORT_SYMBOL(bio_integrity_prep);
*/
static int bio_integrity_verify(struct bio *bio)
{
- return bio_integrity_generate_verify(bio, 0);
+ struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
+ return bio_integrity_walk_bufs(bio,
+ bio->bi_integrity->bip_iter.bi_sector,
+ (walk_buf_fn *)bi->verify_fn);
}
/**
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 5bd9618..c2ad1a8 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -292,14 +292,12 @@ struct bio_integrity_payload {
struct bvec_iter bip_iter;
- /* kill - should just use bip_vec */
void *bip_buf; /* generated integrity data */
bio_end_io_t *bip_end_io; /* saved I/O completion fn */
unsigned short bip_slab; /* slab the bip came from */
unsigned short bip_vcnt; /* # of integrity bio_vecs */
- unsigned bip_owns_buf:1; /* should free bip_buf */
struct work_struct bip_work; /* I/O completion */
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2014-03-24 16:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-24 16:22 [RFC PATCH DONOTMERGE v2 0/6] userspace PI passthrough via AIO/DIO Darrick J. Wong
2014-03-24 16:22 ` [PATCH 1/6] fs/bio-integrity: remove duplicate code Darrick J. Wong
2014-04-02 19:17 ` Zach Brown
2014-04-02 20:35 ` Darrick J. Wong
2014-03-24 16:22 ` [PATCH 2/6] io: define an interface for IO extensions Darrick J. Wong
[not found] ` <20140324162244.10848.46322.stgit-PTl6brltDGh4DFYR7WNSRA@public.gmane.org>
2014-04-02 19:22 ` Jeff Moyer
2014-04-02 22:08 ` Darrick J. Wong
2014-04-02 19:49 ` Zach Brown
2014-04-02 22:28 ` Darrick J. Wong
2014-04-02 22:53 ` Zach Brown
2014-04-02 23:06 ` Darrick J. Wong
2014-03-24 16:22 ` [PATCH 3/6] aio/dio: enable PI passthrough Darrick J. Wong
2014-04-02 20:01 ` Zach Brown
2014-04-02 20:44 ` Darrick J. Wong
2014-04-02 22:33 ` Zach Brown
2014-04-02 22:55 ` Darrick J. Wong
2014-03-24 16:22 ` [PATCH 4/6] PI IO extension: allow user to ask kernel to fill in parts of the protection info Darrick J. Wong
2014-03-24 16:23 ` [PATCH 5/6] PI IO extension: advertise possible userspace flags Darrick J. Wong
2014-03-24 16:23 ` Darrick J. Wong [this message]
2014-04-02 19:14 ` [RFC PATCH DONOTMERGE v2 0/6] userspace PI passthrough via AIO/DIO Zach Brown
2014-04-02 20:05 ` Zach Brown
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=20140324162313.10848.7587.stgit@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=JBottomley@parallels.com \
--cc=axboe@kernel.dk \
--cc=bcrl@kvack.org \
--cc=jmoyer@redhat.com \
--cc=linux-aio@kvack.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=viro@zeniv.linux.org.uk \
--cc=zab@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 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).