dm: add support for secure erase forwarding
authorDenis Semakin <d.semakin@omprussia.ru>
Tue, 13 Mar 2018 09:23:45 +0000 (13:23 +0400)
committerMike Snitzer <snitzer@redhat.com>
Tue, 3 Apr 2018 19:04:21 +0000 (15:04 -0400)
Set QUEUE_FLAG_SECERASE in DM device's queue_flags if a DM table's
data devices support secure erase.

Also, add support for secure erase to both the linear and striped
targets.

Signed-off-by: Denis Semakin <d.semakin@omprussia.ru>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-linear.c
drivers/md/dm-stripe.c
drivers/md/dm-table.c
drivers/md/dm.c
include/linux/device-mapper.h

index d5f8eff7c11d88a066d1dd83fe4707b33264cfae..ff751b00aacd3eb6b874dea8ea47b7ca3f0c675a 100644 (file)
@@ -59,6 +59,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 
        ti->num_flush_bios = 1;
        ti->num_discard_bios = 1;
+       ti->num_secure_erase_bios = 1;
        ti->num_write_same_bios = 1;
        ti->num_write_zeroes_bios = 1;
        ti->private = lc;
index cd209e8902a62ebeb3eb5f851ae7154933137936..bb907cb3e60dfc90203585d7e5abfd4ff0d93a66 100644 (file)
@@ -169,6 +169,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 
        ti->num_flush_bios = stripes;
        ti->num_discard_bios = stripes;
+       ti->num_secure_erase_bios = stripes;
        ti->num_write_same_bios = stripes;
        ti->num_write_zeroes_bios = stripes;
 
@@ -295,6 +296,7 @@ static int stripe_map(struct dm_target *ti, struct bio *bio)
                return DM_MAPIO_REMAPPED;
        }
        if (unlikely(bio_op(bio) == REQ_OP_DISCARD) ||
+           unlikely(bio_op(bio) == REQ_OP_SECURE_ERASE) ||
            unlikely(bio_op(bio) == REQ_OP_WRITE_ZEROES) ||
            unlikely(bio_op(bio) == REQ_OP_WRITE_SAME)) {
                target_bio_nr = dm_bio_get_target_bio_nr(bio);
index 7eb3e2a3c07d5a607669d36aa0a462bfd175d9b3..f20fbc96a805e435f150208ca34fcb0370ff8c2e 100644 (file)
@@ -1846,6 +1846,34 @@ static bool dm_table_supports_discards(struct dm_table *t)
        return true;
 }
 
+static int device_not_secure_erase_capable(struct dm_target *ti,
+                                          struct dm_dev *dev, sector_t start,
+                                          sector_t len, void *data)
+{
+       struct request_queue *q = bdev_get_queue(dev->bdev);
+
+       return q && !blk_queue_secure_erase(q);
+}
+
+static bool dm_table_supports_secure_erase(struct dm_table *t)
+{
+       struct dm_target *ti;
+       unsigned int i;
+
+       for (i = 0; i < dm_table_get_num_targets(t); i++) {
+               ti = dm_table_get_target(t, i);
+
+               if (!ti->num_secure_erase_bios)
+                       return false;
+
+               if (!ti->type->iterate_devices ||
+                   ti->type->iterate_devices(ti, device_not_secure_erase_capable, NULL))
+                       return false;
+       }
+
+       return true;
+}
+
 void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
                               struct queue_limits *limits)
 {
@@ -1867,6 +1895,9 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
        } else
                queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
 
+       if (dm_table_supports_secure_erase(t))
+               queue_flag_set_unlocked(QUEUE_FLAG_SECERASE, q);
+
        if (dm_table_supports_flush(t, (1UL << QUEUE_FLAG_WC))) {
                wc = true;
                if (dm_table_supports_flush(t, (1UL << QUEUE_FLAG_FUA)))
index 038c7572fdd46e186b572c5edb3bc1266408f4fa..3b3cbd1a165920380bd0c86b6be7e4561370a088 100644 (file)
@@ -1414,6 +1414,11 @@ static unsigned get_num_discard_bios(struct dm_target *ti)
        return ti->num_discard_bios;
 }
 
+static unsigned get_num_secure_erase_bios(struct dm_target *ti)
+{
+       return ti->num_secure_erase_bios;
+}
+
 static unsigned get_num_write_same_bios(struct dm_target *ti)
 {
        return ti->num_write_same_bios;
@@ -1467,6 +1472,11 @@ static int __send_discard(struct clone_info *ci, struct dm_target *ti)
                                           is_split_required_for_discard);
 }
 
+static int __send_secure_erase(struct clone_info *ci, struct dm_target *ti)
+{
+       return __send_changing_extent_only(ci, ti, get_num_secure_erase_bios, NULL);
+}
+
 static int __send_write_same(struct clone_info *ci, struct dm_target *ti)
 {
        return __send_changing_extent_only(ci, ti, get_num_write_same_bios, NULL);
@@ -1484,6 +1494,8 @@ static bool __process_abnormal_io(struct clone_info *ci, struct dm_target *ti,
 
        if (bio_op(bio) == REQ_OP_DISCARD)
                *result = __send_discard(ci, ti);
+       else if (bio_op(bio) == REQ_OP_SECURE_ERASE)
+               *result = __send_secure_erase(ci, ti);
        else if (bio_op(bio) == REQ_OP_WRITE_SAME)
                *result = __send_write_same(ci, ti);
        else if (bio_op(bio) == REQ_OP_WRITE_ZEROES)
index 1e2426c18eb4b3c81677981e4b26dce7f7d25ab4..019e2efc6c25d6b6bfd6bf97a9db86b9ff32723c 100644 (file)
@@ -267,6 +267,12 @@ struct dm_target {
         */
        unsigned num_discard_bios;
 
+       /*
+        * The number of secure erase bios that will be submitted to the target.
+        * The bio number can be accessed with dm_bio_get_target_bio_nr.
+        */
+       unsigned num_secure_erase_bios;
+
        /*
         * The number of WRITE SAME bios that will be submitted to the target.
         * The bio number can be accessed with dm_bio_get_target_bio_nr.