Commit 25520d55 authored by Martin K. Petersen's avatar Martin K. Petersen Committed by Jens Axboe

block: Inline blk_integrity in struct gendisk

Up until now the_integrity profile has been dynamically allocated and
attached to struct gendisk after the disk has been made active.

This causes problems because NVMe devices need to register the profile
prior to the partition table being read due to a mandatory metadata
buffer requirement. In addition, DM goes through hoops to deal with
preallocating, but not initializing integrity profiles.

Since the integrity profile is small (4 bytes + a pointer), Christoph
suggested moving it to struct gendisk proper. This requires several
changes:

 - Moving the blk_integrity definition to genhd.h.

 - Inlining blk_integrity in struct gendisk.

 - Removing the dynamic allocation code.

 - Adding helper functions which allow gendisk to set up and tear down
   the integrity sysfs dir when a disk is added/deleted.

 - Adding a blk_integrity_revalidate() callback for updating the stable
   pages bdi setting.

 - The calls that depend on whether a device has an integrity profile or
   not now key off of the bi->profile pointer.

 - Simplifying the integrity support routines in DM (Mike Snitzer).
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Reported-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarSagi Grimberg <sagig@mellanox.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 4c241d08
...@@ -30,10 +30,6 @@ ...@@ -30,10 +30,6 @@
#include "blk.h" #include "blk.h"
static struct kmem_cache *integrity_cachep;
static const char *bi_unsupported_name = "unsupported";
/** /**
* blk_rq_count_integrity_sg - Count number of integrity scatterlist elements * blk_rq_count_integrity_sg - Count number of integrity scatterlist elements
* @q: request queue * @q: request queue
...@@ -146,13 +142,13 @@ EXPORT_SYMBOL(blk_rq_map_integrity_sg); ...@@ -146,13 +142,13 @@ EXPORT_SYMBOL(blk_rq_map_integrity_sg);
*/ */
int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2) int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2)
{ {
struct blk_integrity *b1 = gd1->integrity; struct blk_integrity *b1 = &gd1->integrity;
struct blk_integrity *b2 = gd2->integrity; struct blk_integrity *b2 = &gd2->integrity;
if (!b1 && !b2) if (!b1->profile && !b2->profile)
return 0; return 0;
if (!b1 || !b2) if (!b1->profile || !b2->profile)
return -1; return -1;
if (b1->interval_exp != b2->interval_exp) { if (b1->interval_exp != b2->interval_exp) {
...@@ -163,21 +159,21 @@ int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2) ...@@ -163,21 +159,21 @@ int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2)
} }
if (b1->tuple_size != b2->tuple_size) { if (b1->tuple_size != b2->tuple_size) {
printk(KERN_ERR "%s: %s/%s tuple sz %u != %u\n", __func__, pr_err("%s: %s/%s tuple sz %u != %u\n", __func__,
gd1->disk_name, gd2->disk_name, gd1->disk_name, gd2->disk_name,
b1->tuple_size, b2->tuple_size); b1->tuple_size, b2->tuple_size);
return -1; return -1;
} }
if (b1->tag_size && b2->tag_size && (b1->tag_size != b2->tag_size)) { if (b1->tag_size && b2->tag_size && (b1->tag_size != b2->tag_size)) {
printk(KERN_ERR "%s: %s/%s tag sz %u != %u\n", __func__, pr_err("%s: %s/%s tag sz %u != %u\n", __func__,
gd1->disk_name, gd2->disk_name, gd1->disk_name, gd2->disk_name,
b1->tag_size, b2->tag_size); b1->tag_size, b2->tag_size);
return -1; return -1;
} }
if (b1->profile != b2->profile) { if (b1->profile != b2->profile) {
printk(KERN_ERR "%s: %s/%s type %s != %s\n", __func__, pr_err("%s: %s/%s type %s != %s\n", __func__,
gd1->disk_name, gd2->disk_name, gd1->disk_name, gd2->disk_name,
b1->profile->name, b2->profile->name); b1->profile->name, b2->profile->name);
return -1; return -1;
...@@ -250,7 +246,7 @@ static ssize_t integrity_attr_show(struct kobject *kobj, struct attribute *attr, ...@@ -250,7 +246,7 @@ static ssize_t integrity_attr_show(struct kobject *kobj, struct attribute *attr,
char *page) char *page)
{ {
struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj); struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj);
struct blk_integrity *bi = blk_get_integrity(disk); struct blk_integrity *bi = &disk->integrity;
struct integrity_sysfs_entry *entry = struct integrity_sysfs_entry *entry =
container_of(attr, struct integrity_sysfs_entry, attr); container_of(attr, struct integrity_sysfs_entry, attr);
...@@ -262,7 +258,7 @@ static ssize_t integrity_attr_store(struct kobject *kobj, ...@@ -262,7 +258,7 @@ static ssize_t integrity_attr_store(struct kobject *kobj,
size_t count) size_t count)
{ {
struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj); struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj);
struct blk_integrity *bi = blk_get_integrity(disk); struct blk_integrity *bi = &disk->integrity;
struct integrity_sysfs_entry *entry = struct integrity_sysfs_entry *entry =
container_of(attr, struct integrity_sysfs_entry, attr); container_of(attr, struct integrity_sysfs_entry, attr);
ssize_t ret = 0; ssize_t ret = 0;
...@@ -275,7 +271,7 @@ static ssize_t integrity_attr_store(struct kobject *kobj, ...@@ -275,7 +271,7 @@ static ssize_t integrity_attr_store(struct kobject *kobj,
static ssize_t integrity_format_show(struct blk_integrity *bi, char *page) static ssize_t integrity_format_show(struct blk_integrity *bi, char *page)
{ {
if (bi != NULL && bi->profile->name != NULL) if (bi->profile && bi->profile->name)
return sprintf(page, "%s\n", bi->profile->name); return sprintf(page, "%s\n", bi->profile->name);
else else
return sprintf(page, "none\n"); return sprintf(page, "none\n");
...@@ -283,18 +279,13 @@ static ssize_t integrity_format_show(struct blk_integrity *bi, char *page) ...@@ -283,18 +279,13 @@ static ssize_t integrity_format_show(struct blk_integrity *bi, char *page)
static ssize_t integrity_tag_size_show(struct blk_integrity *bi, char *page) static ssize_t integrity_tag_size_show(struct blk_integrity *bi, char *page)
{ {
if (bi != NULL)
return sprintf(page, "%u\n", bi->tag_size); return sprintf(page, "%u\n", bi->tag_size);
else
return sprintf(page, "0\n");
} }
static ssize_t integrity_interval_show(struct blk_integrity *bi, char *page) static ssize_t integrity_interval_show(struct blk_integrity *bi, char *page)
{ {
if (bi != NULL) return sprintf(page, "%u\n",
return sprintf(page, "%u\n", 1 << bi->interval_exp); bi->interval_exp ? 1 << bi->interval_exp : 0);
else
return sprintf(page, "0\n");
} }
static ssize_t integrity_verify_store(struct blk_integrity *bi, static ssize_t integrity_verify_store(struct blk_integrity *bi,
...@@ -388,113 +379,78 @@ static const struct sysfs_ops integrity_ops = { ...@@ -388,113 +379,78 @@ static const struct sysfs_ops integrity_ops = {
.store = &integrity_attr_store, .store = &integrity_attr_store,
}; };
static int __init blk_dev_integrity_init(void)
{
integrity_cachep = kmem_cache_create("blkdev_integrity",
sizeof(struct blk_integrity),
0, SLAB_PANIC, NULL);
return 0;
}
subsys_initcall(blk_dev_integrity_init);
static void blk_integrity_release(struct kobject *kobj)
{
struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj);
struct blk_integrity *bi = blk_get_integrity(disk);
kmem_cache_free(integrity_cachep, bi);
}
static struct kobj_type integrity_ktype = { static struct kobj_type integrity_ktype = {
.default_attrs = integrity_attrs, .default_attrs = integrity_attrs,
.sysfs_ops = &integrity_ops, .sysfs_ops = &integrity_ops,
.release = blk_integrity_release,
}; };
bool blk_integrity_is_initialized(struct gendisk *disk)
{
struct blk_integrity *bi = blk_get_integrity(disk);
return (bi && bi->profile->name && strcmp(bi->profile->name,
bi_unsupported_name) != 0);
}
EXPORT_SYMBOL(blk_integrity_is_initialized);
/** /**
* blk_integrity_register - Register a gendisk as being integrity-capable * blk_integrity_register - Register a gendisk as being integrity-capable
* @disk: struct gendisk pointer to make integrity-aware * @disk: struct gendisk pointer to make integrity-aware
* @template: optional integrity profile to register * @template: block integrity profile to register
* *
* Description: When a device needs to advertise itself as being able * Description: When a device needs to advertise itself as being able to
* to send/receive integrity metadata it must use this function to * send/receive integrity metadata it must use this function to register
* register the capability with the block layer. The template is a * the capability with the block layer. The template is a blk_integrity
* blk_integrity struct with values appropriate for the underlying * struct with values appropriate for the underlying hardware. See
* hardware. If template is NULL the new profile is allocated but * Documentation/block/data-integrity.txt.
* not filled out. See Documentation/block/data-integrity.txt.
*/ */
int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template) void blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
{ {
struct blk_integrity *bi; struct blk_integrity *bi = &disk->integrity;
BUG_ON(disk == NULL);
if (disk->integrity == NULL) {
bi = kmem_cache_alloc(integrity_cachep,
GFP_KERNEL | __GFP_ZERO);
if (!bi)
return -1;
if (kobject_init_and_add(&disk->integrity_kobj, &integrity_ktype,
&disk_to_dev(disk)->kobj,
"%s", "integrity")) {
kmem_cache_free(integrity_cachep, bi);
return -1;
}
kobject_uevent(&disk->integrity_kobj, KOBJ_ADD); bi->flags = BLK_INTEGRITY_VERIFY | BLK_INTEGRITY_GENERATE |
template->flags;
bi->flags |= BLK_INTEGRITY_VERIFY | BLK_INTEGRITY_GENERATE;
bi->interval_exp = ilog2(queue_logical_block_size(disk->queue)); bi->interval_exp = ilog2(queue_logical_block_size(disk->queue));
disk->integrity = bi;
} else
bi = disk->integrity;
/* Use the provided profile as template */
if (template != NULL) {
bi->profile = template->profile; bi->profile = template->profile;
bi->tuple_size = template->tuple_size; bi->tuple_size = template->tuple_size;
bi->tag_size = template->tag_size; bi->tag_size = template->tag_size;
bi->flags |= template->flags;
} else
bi->profile->name = bi_unsupported_name;
disk->queue->backing_dev_info.capabilities |= BDI_CAP_STABLE_WRITES; blk_integrity_revalidate(disk);
return 0;
} }
EXPORT_SYMBOL(blk_integrity_register); EXPORT_SYMBOL(blk_integrity_register);
/** /**
* blk_integrity_unregister - Remove block integrity profile * blk_integrity_unregister - Unregister block integrity profile
* @disk: disk whose integrity profile to deallocate * @disk: disk whose integrity profile to unregister
* *
* Description: This function frees all memory used by the block * Description: This function unregisters the integrity capability from
* integrity profile. To be called at device teardown. * a block device.
*/ */
void blk_integrity_unregister(struct gendisk *disk) void blk_integrity_unregister(struct gendisk *disk)
{ {
struct blk_integrity *bi; blk_integrity_revalidate(disk);
memset(&disk->integrity, 0, sizeof(struct blk_integrity));
}
EXPORT_SYMBOL(blk_integrity_unregister);
void blk_integrity_revalidate(struct gendisk *disk)
{
struct blk_integrity *bi = &disk->integrity;
if (!disk || !disk->integrity) if (!(disk->flags & GENHD_FL_UP))
return; return;
disk->queue->backing_dev_info.capabilities &= ~BDI_CAP_STABLE_WRITES; if (bi->profile)
disk->queue->backing_dev_info.capabilities |=
BDI_CAP_STABLE_WRITES;
else
disk->queue->backing_dev_info.capabilities &=
~BDI_CAP_STABLE_WRITES;
}
bi = disk->integrity; void blk_integrity_add(struct gendisk *disk)
{
if (kobject_init_and_add(&disk->integrity_kobj, &integrity_ktype,
&disk_to_dev(disk)->kobj, "%s", "integrity"))
return;
kobject_uevent(&disk->integrity_kobj, KOBJ_ADD);
}
void blk_integrity_del(struct gendisk *disk)
{
kobject_uevent(&disk->integrity_kobj, KOBJ_REMOVE); kobject_uevent(&disk->integrity_kobj, KOBJ_REMOVE);
kobject_del(&disk->integrity_kobj); kobject_del(&disk->integrity_kobj);
kobject_put(&disk->integrity_kobj); kobject_put(&disk->integrity_kobj);
disk->integrity = NULL;
} }
EXPORT_SYMBOL(blk_integrity_unregister);
...@@ -630,6 +630,7 @@ void add_disk(struct gendisk *disk) ...@@ -630,6 +630,7 @@ void add_disk(struct gendisk *disk)
WARN_ON(retval); WARN_ON(retval);
disk_add_events(disk); disk_add_events(disk);
blk_integrity_add(disk);
} }
EXPORT_SYMBOL(add_disk); EXPORT_SYMBOL(add_disk);
...@@ -638,6 +639,7 @@ void del_gendisk(struct gendisk *disk) ...@@ -638,6 +639,7 @@ void del_gendisk(struct gendisk *disk)
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct hd_struct *part;
blk_integrity_del(disk);
disk_del_events(disk); disk_del_events(disk);
/* invalidate stuff */ /* invalidate stuff */
......
...@@ -428,6 +428,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) ...@@ -428,6 +428,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
if (disk->fops->revalidate_disk) if (disk->fops->revalidate_disk)
disk->fops->revalidate_disk(disk); disk->fops->revalidate_disk(disk);
blk_integrity_revalidate(disk);
check_disk_size_change(disk, bdev); check_disk_size_change(disk, bdev);
bdev->bd_invalidated = 0; bdev->bd_invalidated = 0;
if (!get_capacity(disk) || !(state = check_partition(disk, bdev))) if (!get_capacity(disk) || !(state = check_partition(disk, bdev)))
......
...@@ -1014,15 +1014,16 @@ static int dm_table_build_index(struct dm_table *t) ...@@ -1014,15 +1014,16 @@ static int dm_table_build_index(struct dm_table *t)
return r; return r;
} }
static bool integrity_profile_exists(struct gendisk *disk)
{
return !!blk_get_integrity(disk);
}
/* /*
* Get a disk whose integrity profile reflects the table's profile. * Get a disk whose integrity profile reflects the table's profile.
* If %match_all is true, all devices' profiles must match.
* If %match_all is false, all devices must at least have an
* allocated integrity profile; but uninitialized is ok.
* Returns NULL if integrity support was inconsistent or unavailable. * Returns NULL if integrity support was inconsistent or unavailable.
*/ */
static struct gendisk * dm_table_get_integrity_disk(struct dm_table *t, static struct gendisk * dm_table_get_integrity_disk(struct dm_table *t)
bool match_all)
{ {
struct list_head *devices = dm_table_get_devices(t); struct list_head *devices = dm_table_get_devices(t);
struct dm_dev_internal *dd = NULL; struct dm_dev_internal *dd = NULL;
...@@ -1030,10 +1031,8 @@ static struct gendisk * dm_table_get_integrity_disk(struct dm_table *t, ...@@ -1030,10 +1031,8 @@ static struct gendisk * dm_table_get_integrity_disk(struct dm_table *t,
list_for_each_entry(dd, devices, list) { list_for_each_entry(dd, devices, list) {
template_disk = dd->dm_dev->bdev->bd_disk; template_disk = dd->dm_dev->bdev->bd_disk;
if (!blk_get_integrity(template_disk)) if (!integrity_profile_exists(template_disk))
goto no_integrity; goto no_integrity;
if (!match_all && !blk_integrity_is_initialized(template_disk))
continue; /* skip uninitialized profiles */
else if (prev_disk && else if (prev_disk &&
blk_integrity_compare(prev_disk, template_disk) < 0) blk_integrity_compare(prev_disk, template_disk) < 0)
goto no_integrity; goto no_integrity;
...@@ -1052,34 +1051,40 @@ static struct gendisk * dm_table_get_integrity_disk(struct dm_table *t, ...@@ -1052,34 +1051,40 @@ static struct gendisk * dm_table_get_integrity_disk(struct dm_table *t,
} }
/* /*
* Register the mapped device for blk_integrity support if * Register the mapped device for blk_integrity support if the
* the underlying devices have an integrity profile. But all devices * underlying devices have an integrity profile. But all devices may
* may not have matching profiles (checking all devices isn't reliable * not have matching profiles (checking all devices isn't reliable
* during table load because this table may use other DM device(s) which * during table load because this table may use other DM device(s) which
* must be resumed before they will have an initialized integity profile). * must be resumed before they will have an initialized integity
* Stacked DM devices force a 2 stage integrity profile validation: * profile). Consequently, stacked DM devices force a 2 stage integrity
* 1 - during load, validate all initialized integrity profiles match * profile validation: First pass during table load, final pass during
* 2 - during resume, validate all integrity profiles match * resume.
*/ */
static int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device *md) static int dm_table_register_integrity(struct dm_table *t)
{ {
struct mapped_device *md = t->md;
struct gendisk *template_disk = NULL; struct gendisk *template_disk = NULL;
template_disk = dm_table_get_integrity_disk(t, false); template_disk = dm_table_get_integrity_disk(t);
if (!template_disk) if (!template_disk)
return 0; return 0;
if (!blk_integrity_is_initialized(dm_disk(md))) { if (!integrity_profile_exists(dm_disk(md))) {
t->integrity_supported = 1; t->integrity_supported = 1;
return blk_integrity_register(dm_disk(md), NULL); /*
* Register integrity profile during table load; we can do
* this because the final profile must match during resume.
*/
blk_integrity_register(dm_disk(md),
blk_get_integrity(template_disk));
return 0;
} }
/* /*
* If DM device already has an initalized integrity * If DM device already has an initialized integrity
* profile the new profile should not conflict. * profile the new profile should not conflict.
*/ */
if (blk_integrity_is_initialized(template_disk) && if (blk_integrity_compare(dm_disk(md), template_disk) < 0) {
blk_integrity_compare(dm_disk(md), template_disk) < 0) {
DMWARN("%s: conflict with existing integrity profile: " DMWARN("%s: conflict with existing integrity profile: "
"%s profile mismatch", "%s profile mismatch",
dm_device_name(t->md), dm_device_name(t->md),
...@@ -1087,7 +1092,7 @@ static int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device ...@@ -1087,7 +1092,7 @@ static int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device
return 1; return 1;
} }
/* Preserve existing initialized integrity profile */ /* Preserve existing integrity profile */
t->integrity_supported = 1; t->integrity_supported = 1;
return 0; return 0;
} }
...@@ -1112,7 +1117,7 @@ int dm_table_complete(struct dm_table *t) ...@@ -1112,7 +1117,7 @@ int dm_table_complete(struct dm_table *t)
return r; return r;
} }
r = dm_table_prealloc_integrity(t, t->md); r = dm_table_register_integrity(t);
if (r) { if (r) {
DMERR("could not register integrity profile."); DMERR("could not register integrity profile.");
return r; return r;
...@@ -1278,29 +1283,30 @@ int dm_calculate_queue_limits(struct dm_table *table, ...@@ -1278,29 +1283,30 @@ int dm_calculate_queue_limits(struct dm_table *table,
} }
/* /*
* Set the integrity profile for this device if all devices used have * Verify that all devices have an integrity profile that matches the
* matching profiles. We're quite deep in the resume path but still * DM device's registered integrity profile. If the profiles don't
* don't know if all devices (particularly DM devices this device * match then unregister the DM device's integrity profile.
* may be stacked on) have matching profiles. Even if the profiles
* don't match we have no way to fail (to resume) at this point.
*/ */
static void dm_table_set_integrity(struct dm_table *t) static void dm_table_verify_integrity(struct dm_table *t)
{ {
struct gendisk *template_disk = NULL; struct gendisk *template_disk = NULL;
if (!blk_get_integrity(dm_disk(t->md))) if (t->integrity_supported) {
/*
* Verify that the original integrity profile
* matches all the devices in this table.
*/
template_disk = dm_table_get_integrity_disk(t);
if (template_disk &&
blk_integrity_compare(dm_disk(t->md), template_disk) >= 0)
return; return;
}
template_disk = dm_table_get_integrity_disk(t, true); if (integrity_profile_exists(dm_disk(t->md))) {
if (template_disk)
blk_integrity_register(dm_disk(t->md),
blk_get_integrity(template_disk));
else if (blk_integrity_is_initialized(dm_disk(t->md)))
DMWARN("%s: device no longer has a valid integrity profile",
dm_device_name(t->md));
else
DMWARN("%s: unable to establish an integrity profile", DMWARN("%s: unable to establish an integrity profile",
dm_device_name(t->md)); dm_device_name(t->md));
blk_integrity_unregister(dm_disk(t->md));
}
} }
static int device_flush_capable(struct dm_target *ti, struct dm_dev *dev, static int device_flush_capable(struct dm_target *ti, struct dm_dev *dev,
...@@ -1500,7 +1506,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, ...@@ -1500,7 +1506,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
else else
queue_flag_set_unlocked(QUEUE_FLAG_NO_SG_MERGE, q); queue_flag_set_unlocked(QUEUE_FLAG_NO_SG_MERGE, q);
dm_table_set_integrity(t); dm_table_verify_integrity(t);
/* /*
* Determine whether or not this queue's I/O timings contribute * Determine whether or not this queue's I/O timings contribute
......
...@@ -1962,12 +1962,9 @@ int md_integrity_register(struct mddev *mddev) ...@@ -1962,12 +1962,9 @@ int md_integrity_register(struct mddev *mddev)
* All component devices are integrity capable and have matching * All component devices are integrity capable and have matching
* profiles, register the common profile for the md device. * profiles, register the common profile for the md device.
*/ */
if (blk_integrity_register(mddev->gendisk, blk_integrity_register(mddev->gendisk,
bdev_get_integrity(reference->bdev)) != 0) { bdev_get_integrity(reference->bdev));
printk(KERN_ERR "md: failed to register integrity for %s\n",
mdname(mddev));
return -EINVAL;
}
printk(KERN_NOTICE "md: data integrity enabled on %s\n", mdname(mddev)); printk(KERN_NOTICE "md: data integrity enabled on %s\n", mdname(mddev));
if (bioset_integrity_create(mddev->bio_set, BIO_POOL_SIZE)) { if (bioset_integrity_create(mddev->bio_set, BIO_POOL_SIZE)) {
printk(KERN_ERR "md: failed to create integrity pool for %s\n", printk(KERN_ERR "md: failed to create integrity pool for %s\n",
......
...@@ -405,7 +405,6 @@ int nd_integrity_init(struct gendisk *disk, unsigned long meta_size) ...@@ -405,7 +405,6 @@ int nd_integrity_init(struct gendisk *disk, unsigned long meta_size)
.generate_fn = nd_pi_nop_generate_verify, .generate_fn = nd_pi_nop_generate_verify,
.verify_fn = nd_pi_nop_generate_verify, .verify_fn = nd_pi_nop_generate_verify,
}; };
int ret;
if (meta_size == 0) if (meta_size == 0)
return 0; return 0;
...@@ -414,10 +413,7 @@ int nd_integrity_init(struct gendisk *disk, unsigned long meta_size) ...@@ -414,10 +413,7 @@ int nd_integrity_init(struct gendisk *disk, unsigned long meta_size)
bi.tuple_size = meta_size; bi.tuple_size = meta_size;
bi.tag_size = meta_size; bi.tag_size = meta_size;
ret = blk_integrity_register(disk, &bi); blk_integrity_register(disk, &bi);
if (ret)
return ret;
blk_queue_max_integrity_segments(disk->queue, 1); blk_queue_max_integrity_segments(disk->queue, 1);
return 0; return 0;
......
...@@ -538,7 +538,7 @@ static void nvme_dif_remap(struct request *req, ...@@ -538,7 +538,7 @@ static void nvme_dif_remap(struct request *req,
virt = bip_get_seed(bip); virt = bip_get_seed(bip);
phys = nvme_block_nr(ns, blk_rq_pos(req)); phys = nvme_block_nr(ns, blk_rq_pos(req));
nlb = (blk_rq_bytes(req) >> ns->lba_shift); nlb = (blk_rq_bytes(req) >> ns->lba_shift);
ts = ns->disk->integrity->tuple_size; ts = ns->disk->integrity.tuple_size;
for (i = 0; i < nlb; i++, virt++, phys++) { for (i = 0; i < nlb; i++, virt++, phys++) {
pi = (struct t10_pi_tuple *)p; pi = (struct t10_pi_tuple *)p;
...@@ -2044,8 +2044,7 @@ static int nvme_revalidate_disk(struct gendisk *disk) ...@@ -2044,8 +2044,7 @@ static int nvme_revalidate_disk(struct gendisk *disk)
ns->pi_type = pi_type; ns->pi_type = pi_type;
blk_queue_logical_block_size(ns->queue, bs); blk_queue_logical_block_size(ns->queue, bs);
if (ns->ms && !blk_get_integrity(disk) && (disk->flags & GENHD_FL_UP) && if (ns->ms && !ns->ext)
!ns->ext)
nvme_init_integrity(ns); nvme_init_integrity(ns);
if (ns->ms && !(ns->ms == 8 && ns->pi_type) && !blk_get_integrity(disk)) if (ns->ms && !(ns->ms == 8 && ns->pi_type) && !blk_get_integrity(disk))
......
...@@ -1075,7 +1075,7 @@ int revalidate_disk(struct gendisk *disk) ...@@ -1075,7 +1075,7 @@ int revalidate_disk(struct gendisk *disk)
if (disk->fops->revalidate_disk) if (disk->fops->revalidate_disk)
ret = disk->fops->revalidate_disk(disk); ret = disk->fops->revalidate_disk(disk);
blk_integrity_revalidate(disk);
bdev = bdget_disk(disk, 0); bdev = bdget_disk(disk, 0);
if (!bdev) if (!bdev)
return ret; return ret;
......
...@@ -1468,16 +1468,7 @@ struct blk_integrity_profile { ...@@ -1468,16 +1468,7 @@ struct blk_integrity_profile {
const char *name; const char *name;
}; };
struct blk_integrity { extern void blk_integrity_register(struct gendisk *, struct blk_integrity *);
struct blk_integrity_profile *profile;
unsigned char flags;
unsigned char tuple_size;
unsigned char interval_exp;
unsigned char tag_size;
};
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 void blk_integrity_unregister(struct gendisk *);
extern int blk_integrity_compare(struct gendisk *, struct gendisk *); extern int blk_integrity_compare(struct gendisk *, struct gendisk *);
extern int blk_rq_map_integrity_sg(struct request_queue *, struct bio *, extern int blk_rq_map_integrity_sg(struct request_queue *, struct bio *,
...@@ -1488,15 +1479,20 @@ extern bool blk_integrity_merge_rq(struct request_queue *, struct request *, ...@@ -1488,15 +1479,20 @@ extern bool blk_integrity_merge_rq(struct request_queue *, struct request *,
extern bool blk_integrity_merge_bio(struct request_queue *, struct request *, extern bool blk_integrity_merge_bio(struct request_queue *, struct request *,
struct bio *); struct bio *);
static inline static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk)
struct blk_integrity *bdev_get_integrity(struct block_device *bdev)
{ {
return bdev->bd_disk->integrity; struct blk_integrity *bi = &disk->integrity;
if (!bi->profile)
return NULL;
return bi;
} }
static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) static inline
struct blk_integrity *bdev_get_integrity(struct block_device *bdev)
{ {
return disk->integrity; return blk_get_integrity(bdev->bd_disk);
} }
static inline bool blk_integrity_rq(struct request *rq) static inline bool blk_integrity_rq(struct request *rq)
...@@ -1570,10 +1566,9 @@ static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b) ...@@ -1570,10 +1566,9 @@ static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b)
{ {
return 0; return 0;
} }
static inline int blk_integrity_register(struct gendisk *d, static inline void blk_integrity_register(struct gendisk *d,
struct blk_integrity *b) struct blk_integrity *b)
{ {
return 0;
} }
static inline void blk_integrity_unregister(struct gendisk *d) static inline void blk_integrity_unregister(struct gendisk *d)
{ {
...@@ -1598,10 +1593,7 @@ static inline bool blk_integrity_merge_bio(struct request_queue *rq, ...@@ -1598,10 +1593,7 @@ static inline bool blk_integrity_merge_bio(struct request_queue *rq,
{ {
return true; return true;
} }
static inline bool blk_integrity_is_initialized(struct gendisk *g)
{
return 0;
}
static inline bool integrity_req_gap_back_merge(struct request *req, static inline bool integrity_req_gap_back_merge(struct request *req,
struct bio *next) struct bio *next)
{ {
......
...@@ -163,6 +163,18 @@ struct disk_part_tbl { ...@@ -163,6 +163,18 @@ struct disk_part_tbl {
struct disk_events; struct disk_events;
#if defined(CONFIG_BLK_DEV_INTEGRITY)
struct blk_integrity {
struct blk_integrity_profile *profile;
unsigned char flags;
unsigned char tuple_size;
unsigned char interval_exp;
unsigned char tag_size;
};
#endif /* CONFIG_BLK_DEV_INTEGRITY */
struct gendisk { struct gendisk {
/* major, first_minor and minors are input parameters only, /* major, first_minor and minors are input parameters only,
* don't use directly. Use disk_devt() and disk_max_parts(). * don't use directly. Use disk_devt() and disk_max_parts().
...@@ -198,9 +210,9 @@ struct gendisk { ...@@ -198,9 +210,9 @@ struct gendisk {
atomic_t sync_io; /* RAID */ atomic_t sync_io; /* RAID */
struct disk_events *ev; struct disk_events *ev;
#ifdef CONFIG_BLK_DEV_INTEGRITY #ifdef CONFIG_BLK_DEV_INTEGRITY
struct blk_integrity *integrity; struct blk_integrity integrity;
struct kobject integrity_kobj; struct kobject integrity_kobj;
#endif #endif /* CONFIG_BLK_DEV_INTEGRITY */
int node_id; int node_id;
}; };
...@@ -728,6 +740,16 @@ static inline void part_nr_sects_write(struct hd_struct *part, sector_t size) ...@@ -728,6 +740,16 @@ static inline void part_nr_sects_write(struct hd_struct *part, sector_t size)
#endif #endif
} }
#if defined(CONFIG_BLK_DEV_INTEGRITY)
extern void blk_integrity_add(struct gendisk *);
extern void blk_integrity_del(struct gendisk *);
extern void blk_integrity_revalidate(struct gendisk *);
#else /* CONFIG_BLK_DEV_INTEGRITY */
static inline void blk_integrity_add(struct gendisk *disk) { }
static inline void blk_integrity_del(struct gendisk *disk) { }
static inline void blk_integrity_revalidate(struct gendisk *disk) { }
#endif /* CONFIG_BLK_DEV_INTEGRITY */
#else /* CONFIG_BLOCK */ #else /* CONFIG_BLOCK */
static inline void printk_all_partitions(void) { } static inline void printk_all_partitions(void) { }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment