Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm: introduce dm_remap_zone_report()

A target driver support zoned block devices and exposing it as such may
receive REQ_OP_ZONE_REPORT request for the user to determine the mapped
device zone configuration. To process properly such request, the target
driver may need to remap the zone descriptors provided in the report
reply. The helper function dm_remap_zone_report() does this generically
using only the target start offset and length and the start offset
within the target device.

dm_remap_zone_report() will remap the start sector of all zones
reported. If the report includes sequential zones, the write pointer
position of these zones will also be remapped.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

authored by

Damien Le Moal and committed by
Mike Snitzer
10999307 264c869d

+81
+79
drivers/md/dm.c
··· 1013 1013 EXPORT_SYMBOL_GPL(dm_accept_partial_bio); 1014 1014 1015 1015 /* 1016 + * The zone descriptors obtained with a zone report indicate 1017 + * zone positions within the target device. The zone descriptors 1018 + * must be remapped to match their position within the dm device. 1019 + * A target may call dm_remap_zone_report after completion of a 1020 + * REQ_OP_ZONE_REPORT bio to remap the zone descriptors obtained 1021 + * from the target device mapping to the dm device. 1022 + */ 1023 + void dm_remap_zone_report(struct dm_target *ti, struct bio *bio, sector_t start) 1024 + { 1025 + #ifdef CONFIG_BLK_DEV_ZONED 1026 + struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone); 1027 + struct bio *report_bio = tio->io->bio; 1028 + struct blk_zone_report_hdr *hdr = NULL; 1029 + struct blk_zone *zone; 1030 + unsigned int nr_rep = 0; 1031 + unsigned int ofst; 1032 + struct bio_vec bvec; 1033 + struct bvec_iter iter; 1034 + void *addr; 1035 + 1036 + if (bio->bi_status) 1037 + return; 1038 + 1039 + /* 1040 + * Remap the start sector of the reported zones. For sequential zones, 1041 + * also remap the write pointer position. 1042 + */ 1043 + bio_for_each_segment(bvec, report_bio, iter) { 1044 + addr = kmap_atomic(bvec.bv_page); 1045 + 1046 + /* Remember the report header in the first page */ 1047 + if (!hdr) { 1048 + hdr = addr; 1049 + ofst = sizeof(struct blk_zone_report_hdr); 1050 + } else 1051 + ofst = 0; 1052 + 1053 + /* Set zones start sector */ 1054 + while (hdr->nr_zones && ofst < bvec.bv_len) { 1055 + zone = addr + ofst; 1056 + if (zone->start >= start + ti->len) { 1057 + hdr->nr_zones = 0; 1058 + break; 1059 + } 1060 + zone->start = zone->start + ti->begin - start; 1061 + if (zone->type != BLK_ZONE_TYPE_CONVENTIONAL) { 1062 + if (zone->cond == BLK_ZONE_COND_FULL) 1063 + zone->wp = zone->start + zone->len; 1064 + else if (zone->cond == BLK_ZONE_COND_EMPTY) 1065 + zone->wp = zone->start; 1066 + else 1067 + zone->wp = zone->wp + ti->begin - start; 1068 + } 1069 + ofst += sizeof(struct blk_zone); 1070 + hdr->nr_zones--; 1071 + nr_rep++; 1072 + } 1073 + 1074 + if (addr != hdr) 1075 + kunmap_atomic(addr); 1076 + 1077 + if (!hdr->nr_zones) 1078 + break; 1079 + } 1080 + 1081 + if (hdr) { 1082 + hdr->nr_zones = nr_rep; 1083 + kunmap_atomic(hdr); 1084 + } 1085 + 1086 + bio_advance(report_bio, report_bio->bi_iter.bi_size); 1087 + 1088 + #else /* !CONFIG_BLK_DEV_ZONED */ 1089 + bio->bi_status = BLK_STS_NOTSUPP; 1090 + #endif 1091 + } 1092 + EXPORT_SYMBOL_GPL(dm_remap_zone_report); 1093 + 1094 + /* 1016 1095 * Flush current->bio_list when the target map method blocks. 1017 1096 * This fixes deadlocks in snapshot and possibly in other targets. 1018 1097 */
+2
include/linux/device-mapper.h
··· 450 450 int dm_suspended(struct dm_target *ti); 451 451 int dm_noflush_suspending(struct dm_target *ti); 452 452 void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors); 453 + void dm_remap_zone_report(struct dm_target *ti, struct bio *bio, 454 + sector_t start); 453 455 union map_info *dm_get_rq_mapinfo(struct request *rq); 454 456 455 457 struct queue_limits *dm_get_queue_limits(struct mapped_device *md);