[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <523C030E.3040408@cn.fujitsu.com>
Date: Fri, 20 Sep 2013 16:10:54 +0800
From: Gu Zheng <guz.fnst@...fujitsu.com>
To: Al Viro <viro@...iv.linux.org.uk>
CC: Jens <axboe@...nel.dk>, fsdevel <linux-fsdevel@...r.kernel.org>,
linux-kernel <linux-kernel@...r.kernel.org>
Subject: [PATCH] fs/bio-integrity: remove duplicate code
Most code of function bio_integrity_verify and bio_integrity_generate
is the same, so introduce a common function bio_integrity_generate_verity()
to remove the duplicate code.
Signed-off-by: Gu Zheng <guz.fnst@...fujitsu.com>
---
fs/bio-integrity.c | 84 ++++++++++++++++++++++-----------------------------
1 files changed, 36 insertions(+), 48 deletions(-)
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
index 6025084..f096aec 100644
--- a/fs/bio-integrity.c
+++ b/fs/bio-integrity.c
@@ -287,24 +287,25 @@ 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;
- sector_t sector = bio->bi_sector;
- unsigned int i, sectors, total;
+ sector_t sector;
+ unsigned int i, sectors, total, ret;
void *prot_buf = bio->bi_integrity->bip_buf;
- total = 0;
+ if (operate)
+ sector = bio->bi_sector;
+ else
+ sector = bio->bi_integrity->bip_sector;
+
+ ret = total = 0;
bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
bix.sector_size = bi->sector_size;
@@ -314,8 +315,13 @@ static void bio_integrity_generate(struct bio *bio)
bix.data_size = bv->bv_len;
bix.prot_buf = prot_buf;
bix.sector = sector;
-
- bi->generate_fn(&bix);
+ if (operate) {
+ bi->generate_fn(&bix);
+ } else {
+ ret = bi->verify_fn(&bix);
+ kunmap_atomic(kaddr);
+ return ret;
+ }
sectors = bv->bv_len / bi->sector_size;
sector += sectors;
@@ -325,6 +331,22 @@ 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)
@@ -439,41 +461,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_sector;
- unsigned int i, sectors, total, ret;
- void *prot_buf = bio->bi_integrity->bip_buf;
-
- ret = total = 0;
- bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
- bix.sector_size = bi->sector_size;
-
- bio_for_each_segment(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;
- total += sectors * bi->tuple_size;
- BUG_ON(total > bio->bi_integrity->bip_size);
-
- kunmap_atomic(kaddr);
- }
-
- return ret;
+ return bio_integrity_generate_verify(bio, 0);
}
/**
--
1.7.7
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists