Commit 9c47008d authored by Martin K. Petersen's avatar Martin K. Petersen Committed by Alasdair G Kergon

dm: add integrity support

This patch provides support for data integrity passthrough in the device
mapper.

 - If one or more component devices support integrity an integrity
   profile is preallocated for the DM device.

 - If all component devices have compatible profiles the DM device is
   flagged as capable.

 - Handle integrity metadata when splitting and cloning bios.
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 577c9c45
...@@ -1047,6 +1047,19 @@ static int populate_table(struct dm_table *table, ...@@ -1047,6 +1047,19 @@ static int populate_table(struct dm_table *table,
return dm_table_complete(table); return dm_table_complete(table);
} }
static int table_prealloc_integrity(struct dm_table *t,
struct mapped_device *md)
{
struct list_head *devices = dm_table_get_devices(t);
struct dm_dev_internal *dd;
list_for_each_entry(dd, devices, list)
if (bdev_get_integrity(dd->dm_dev.bdev))
return blk_integrity_register(dm_disk(md), NULL);
return 0;
}
static int table_load(struct dm_ioctl *param, size_t param_size) static int table_load(struct dm_ioctl *param, size_t param_size)
{ {
int r; int r;
...@@ -1068,6 +1081,14 @@ static int table_load(struct dm_ioctl *param, size_t param_size) ...@@ -1068,6 +1081,14 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
goto out; goto out;
} }
r = table_prealloc_integrity(t, md);
if (r) {
DMERR("%s: could not register integrity profile.",
dm_device_name(md));
dm_table_destroy(t);
goto out;
}
down_write(&_hash_lock); down_write(&_hash_lock);
hc = dm_get_mdptr(md); hc = dm_get_mdptr(md);
if (!hc || hc->md != md) { if (!hc || hc->md != md) {
......
...@@ -879,6 +879,45 @@ struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector) ...@@ -879,6 +879,45 @@ struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector)
return &t->targets[(KEYS_PER_NODE * n) + k]; return &t->targets[(KEYS_PER_NODE * n) + k];
} }
/*
* Set the integrity profile for this device if all devices used have
* matching profiles.
*/
static void dm_table_set_integrity(struct dm_table *t)
{
struct list_head *devices = dm_table_get_devices(t);
struct dm_dev_internal *prev = NULL, *dd = NULL;
if (!blk_get_integrity(dm_disk(t->md)))
return;
list_for_each_entry(dd, devices, list) {
if (prev &&
blk_integrity_compare(prev->dm_dev.bdev->bd_disk,
dd->dm_dev.bdev->bd_disk) < 0) {
DMWARN("%s: integrity not set: %s and %s mismatch",
dm_device_name(t->md),
prev->dm_dev.bdev->bd_disk->disk_name,
dd->dm_dev.bdev->bd_disk->disk_name);
goto no_integrity;
}
prev = dd;
}
if (!prev || !bdev_get_integrity(prev->dm_dev.bdev))
goto no_integrity;
blk_integrity_register(dm_disk(t->md),
bdev_get_integrity(prev->dm_dev.bdev));
return;
no_integrity:
blk_integrity_register(dm_disk(t->md), NULL);
return;
}
void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q) void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q)
{ {
/* /*
...@@ -899,6 +938,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q) ...@@ -899,6 +938,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q)
else else
queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, q); queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, q);
dm_table_set_integrity(t);
} }
unsigned int dm_table_get_num_targets(struct dm_table *t) unsigned int dm_table_get_num_targets(struct dm_table *t)
......
...@@ -700,6 +700,12 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector, ...@@ -700,6 +700,12 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector,
clone->bi_io_vec->bv_len = clone->bi_size; clone->bi_io_vec->bv_len = clone->bi_size;
clone->bi_flags |= 1 << BIO_CLONED; clone->bi_flags |= 1 << BIO_CLONED;
if (bio_integrity(bio)) {
bio_integrity_clone(clone, bio, GFP_NOIO);
bio_integrity_trim(clone,
bio_sector_offset(bio, idx, offset), len);
}
return clone; return clone;
} }
...@@ -721,6 +727,14 @@ static struct bio *clone_bio(struct bio *bio, sector_t sector, ...@@ -721,6 +727,14 @@ static struct bio *clone_bio(struct bio *bio, sector_t sector,
clone->bi_size = to_bytes(len); clone->bi_size = to_bytes(len);
clone->bi_flags &= ~(1 << BIO_SEG_VALID); clone->bi_flags &= ~(1 << BIO_SEG_VALID);
if (bio_integrity(bio)) {
bio_integrity_clone(clone, bio, GFP_NOIO);
if (idx != bio->bi_idx || clone->bi_size < bio->bi_size)
bio_integrity_trim(clone,
bio_sector_offset(bio, idx, 0), len);
}
return clone; return clone;
} }
...@@ -1193,6 +1207,7 @@ static void free_dev(struct mapped_device *md) ...@@ -1193,6 +1207,7 @@ static void free_dev(struct mapped_device *md)
mempool_destroy(md->tio_pool); mempool_destroy(md->tio_pool);
mempool_destroy(md->io_pool); mempool_destroy(md->io_pool);
bioset_free(md->bs); bioset_free(md->bs);
blk_integrity_unregister(md->disk);
del_gendisk(md->disk); del_gendisk(md->disk);
free_minor(minor); free_minor(minor);
......
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