From 2c45c9b8b20f35151659ac289c6508149b63e83e Mon Sep 17 00:00:00 2001 From: Mike Snitzer Date: Thu, 31 Mar 2011 23:37:23 -0400 Subject: [PATCH] dm integrity code cleanup --- block/blk-integrity.c | 11 +++++++++-- drivers/md/dm-table.c | 48 ++++++++++++++++++++---------------------------- include/linux/blkdev.h | 8 +------- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/block/blk-integrity.c b/block/blk-integrity.c index a36186d..129b9e2 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -30,8 +30,7 @@ static struct kmem_cache *integrity_cachep; -const char bi_unsupported_name[] = "unsupported"; -EXPORT_SYMBOL_GPL(bi_unsupported_name); +static const char *bi_unsupported_name = "unsupported"; /** * blk_rq_count_integrity_sg - Count number of integrity scatterlist elements @@ -361,6 +360,14 @@ static struct kobj_type integrity_ktype = { .release = blk_integrity_release, }; +bool blk_integrity_is_initialized(struct gendisk *disk) +{ + struct blk_integrity *bi = blk_get_integrity(disk); + + return (bi && bi->name && strcmp(bi->name, bi_unsupported_name) != 0); +} +EXPORT_SYMBOL(blk_integrity_is_initialized); + /** * blk_integrity_register - Register a gendisk as being integrity-capable * @disk: struct gendisk pointer to make integrity-aware diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 39ee315..5ec4bf5 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -938,14 +938,12 @@ static struct gendisk * dm_table_get_integrity_disk(struct dm_table *t, struct list_head *devices = dm_table_get_devices(t); struct dm_dev_internal *dd = NULL; struct gendisk *prev_disk = NULL, *template_disk = NULL; - struct blk_integrity *bi = NULL; list_for_each_entry(dd, devices, list) { template_disk = dd->dm_dev.bdev->bd_disk; - bi = blk_get_integrity(template_disk); - if (!bi) + if (!blk_get_integrity(template_disk)) goto no_integrity; - if (!match_all && !blk_integrity_is_initialized(bi)) + if (!match_all && !blk_integrity_is_initialized(template_disk)) continue; /* skip uninitialized profiles */ else if (prev_disk && blk_integrity_compare(prev_disk, template_disk) < 0) { @@ -977,37 +975,31 @@ no_integrity: static int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device *md) { struct gendisk *template_disk = NULL; - struct blk_integrity *template_bi = NULL, *dm_bi = NULL; template_disk = dm_table_get_integrity_disk(t, false); - if (template_disk) { - /* - * If DM device already has an initalized integrity - * profile the new profile should not conflict. - */ - dm_bi = blk_get_integrity(dm_disk(md)); - template_bi = blk_get_integrity(template_disk); - if (blk_integrity_is_initialized(dm_bi)) { - if (blk_integrity_is_initialized(template_bi) && - blk_integrity_compare(dm_disk(md), template_disk) < 0) { - DMWARN("%s: existing integrity conflict: " - "%s mismatch", - dm_device_name(t->md), - template_disk->disk_name); - return 1; - } - - /* - * Avoid clearing an existing integrity profile - */ - t->integrity_supported = 1; - return 0; - } + if (!template_disk) + return 0; + if (!blk_integrity_is_initialized(dm_disk(md))) { t->integrity_supported = 1; return blk_integrity_register(dm_disk(md), NULL); } + /* + * If DM device already has an initalized integrity + * profile the new profile should not conflict. + */ + if (blk_integrity_is_initialized(template_disk) && + blk_integrity_compare(dm_disk(md), template_disk) < 0) { + DMWARN("%s: existing integrity conflict: " + "%s mismatch", + dm_device_name(t->md), + template_disk->disk_name); + return 1; + } + + /* Preserve existing initialized integrity profile */ + t->integrity_supported = 1; return 0; } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 405b93b..32176cc 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1206,6 +1206,7 @@ struct blk_integrity { struct kobject kobj; }; +extern bool blk_integrity_is_initialized(struct gendisk *); extern int blk_integrity_register(struct gendisk *, struct blk_integrity *); extern void blk_integrity_unregister(struct gendisk *); extern int blk_integrity_compare(struct gendisk *, struct gendisk *); @@ -1248,13 +1249,6 @@ queue_max_integrity_segments(struct request_queue *q) return q->limits.max_integrity_segments; } -extern const char bi_unsupported_name[]; /* = "unsupported" */ - -static inline bool blk_integrity_is_initialized(struct blk_integrity *bi) -{ - return (bi && bi->name && strcmp(bi->name, bi_unsupported_name) != 0); -} - #else /* CONFIG_BLK_DEV_INTEGRITY */ #define blk_integrity_rq(rq) (0)