From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: axboe@kernel.dk, martin.petersen@oracle.com,
darrick.wong@oracle.com, JBottomley@parallels.com,
bcrl@kvack.org, viro@zeniv.linux.org.uk
Cc: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org,
Gu Zheng <guz.fnst@cn.fujitsu.com>,
linux-scsi@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 1/5] fs/bio-integrity: remove duplicate code
Date: Thu, 20 Mar 2014 21:30:48 -0700 [thread overview]
Message-ID: <20140321043048.8428.52698.stgit@birch.djwong.org> (raw)
In-Reply-To: <20140321043041.8428.79003.stgit@birch.djwong.org>
Frøm: Gu Zheng <guz.fnst@cn.fujitsu.com>
Most code of function bio_integrity_verify and bio_integrity_generate
is the same, so introduce a help function bio_integrity_generate_verify()
to remove the duplicate code.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
---
fs/bio-integrity.c | 83 +++++++++++++++++++++++-----------------------------
1 file changed, 37 insertions(+), 46 deletions(-)
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
index 4f70f38..413312f 100644
--- a/fs/bio-integrity.c
+++ b/fs/bio-integrity.c
@@ -301,25 +301,26 @@ int bio_integrity_get_tag(struct bio *bio, void *tag_buf, unsigned int len)
EXPORT_SYMBOL(bio_integrity_get_tag);
/**
- * bio_integrity_generate - Generate integrity metadata for a bio
- * @bio: bio to generate integrity metadata for
- *
- * Description: Generates integrity metadata for a bio by calling the
- * block device's generation callback function. The bio must have a
- * bip attached with enough room to accommodate the generated
- * integrity metadata.
+ * bio_integrity_generate_verify - Generate/verify integrity metadata for a bio
+ * @bio: bio to generate/verify integrity metadata for
+ * @operate: operate number, 1 for generate, 0 for verify
*/
-static void bio_integrity_generate(struct bio *bio)
+static int bio_integrity_generate_verify(struct bio *bio, int operate)
{
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 = bio->bi_iter.bi_sector;
- unsigned int sectors, total;
+ sector_t sector;
+ unsigned int sectors, total, ret;
void *prot_buf = bio->bi_integrity->bip_buf;
- total = 0;
+ 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;
@@ -330,7 +331,15 @@ static void bio_integrity_generate(struct bio *bio)
bix.prot_buf = prot_buf;
bix.sector = sector;
- bi->generate_fn(&bix);
+ 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;
@@ -340,6 +349,21 @@ static void bio_integrity_generate(struct bio *bio)
kunmap_atomic(kaddr);
}
+ return ret;
+}
+
+/**
+ * bio_integrity_generate - Generate integrity metadata for a bio
+ * @bio: bio to generate integrity metadata for
+ *
+ * Description: Generates integrity metadata for a bio by calling the
+ * block device's generation callback function. The bio must have a
+ * bip attached with enough room to accommodate the generated
+ * integrity metadata.
+ */
+static void bio_integrity_generate(struct bio *bio)
+{
+ bio_integrity_generate_verify(bio, 1);
}
static inline unsigned short blk_integrity_tuple_size(struct blk_integrity *bi)
@@ -454,40 +478,7 @@ EXPORT_SYMBOL(bio_integrity_prep);
*/
static int bio_integrity_verify(struct bio *bio)
{
- struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
- struct blk_integrity_exchg bix;
- struct bio_vec *bv;
- sector_t sector = bio->bi_integrity->bip_iter.bi_sector;
- unsigned int sectors, ret = 0;
- void *prot_buf = bio->bi_integrity->bip_buf;
- int i;
-
- bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
- bix.sector_size = bi->sector_size;
-
- bio_for_each_segment_all(bv, bio, i) {
- 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;
-
- 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;
-
- kunmap_atomic(kaddr);
- }
-
- return ret;
+ return bio_integrity_generate_verify(bio, 0);
}
/**
--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to majordomo@kvack.org. For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>
next prev parent reply other threads:[~2014-03-21 4:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-21 4:30 [RFC PATCH 0/5] userspace PI passthrough via AIO/DIO Darrick J. Wong
2014-03-21 4:30 ` Darrick J. Wong [this message]
2014-03-21 4:30 ` [PATCH 2/5] aio/dio: enable DIX passthrough Darrick J. Wong
2014-03-21 4:31 ` [PATCH 3/5] aio/dio: allow user to ask kernel to fill in parts of the protection info Darrick J. Wong
2014-03-21 4:31 ` [PATCH 4/5] aio/dio: advertise possible userspace flags Darrick J. Wong
2014-03-21 4:31 ` [PATCH 5/5] blk-integrity: refactor various routines Darrick J. Wong
2014-03-21 14:57 ` [RFC PATCH 0/5] userspace PI passthrough via AIO/DIO Jeff Moyer
2014-03-21 21:39 ` Darrick J. Wong
2014-03-21 23:48 ` Zach Brown
2014-03-21 18:23 ` Zach Brown
2014-03-21 21:44 ` Benjamin LaHaise
2014-03-21 22:54 ` Darrick J. Wong
2014-03-22 0:29 ` Zach Brown
2014-03-22 2:32 ` Darrick J. Wong
2014-03-22 9:43 ` Darrick J. Wong
2014-03-23 14:02 ` Jan Kara
2014-03-23 17:07 ` Darrick J. Wong
2014-03-21 22:20 ` Darrick J. Wong
2014-03-22 0:00 ` 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=20140321043048.8428.52698.stgit@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=JBottomley@parallels.com \
--cc=axboe@kernel.dk \
--cc=bcrl@kvack.org \
--cc=guz.fnst@cn.fujitsu.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 \
/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).