Skip to content

Commit 5e8eed2

Browse files
committed
Merge tag 'for-5.8/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper fixes from Mike Snitzer: - Quite a few DM zoned target fixes and a Zone append fix in DM core. Considering the amount of dm-zoned changes that went in during the 5.8 merge window these fixes are not that surprising. - A few DM writecache target fixes. - A fix to Documentation index to include DM ebs target docs. - Small cleanup to use struct_size() in DM core's retrieve_deps(). * tag 'for-5.8/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm writecache: add cond_resched to loop in persistent_memory_claim() dm zoned: Fix reclaim zone selection dm zoned: Fix random zone reclaim selection dm: update original bio sector on Zone Append dm zoned: Fix metadata zone size check docs: device-mapper: add dm-ebs.rst to an index file dm ioctl: use struct_size() helper in retrieve_deps() dm writecache: skip writecache_wait when using pmem mode dm writecache: correct uncommitted_block when discarding uncommitted entry dm zoned: assign max_io_len correctly dm zoned: fix uninitialized pointer dereference
2 parents 6116dea + d35bd76 commit 5e8eed2

File tree

7 files changed

+56
-18
lines changed

7 files changed

+56
-18
lines changed

Documentation/admin-guide/device-mapper/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Device Mapper
1111
dm-clone
1212
dm-crypt
1313
dm-dust
14+
dm-ebs
1415
dm-flakey
1516
dm-init
1617
dm-integrity

drivers/md/dm-ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ static void retrieve_deps(struct dm_table *table,
14711471
/*
14721472
* Check we have enough space.
14731473
*/
1474-
needed = sizeof(*deps) + (sizeof(*deps->dev) * count);
1474+
needed = struct_size(deps, dev, count);
14751475
if (len < needed) {
14761476
param->flags |= DM_BUFFER_FULL_FLAG;
14771477
return;

drivers/md/dm-writecache.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ static int persistent_memory_claim(struct dm_writecache *wc)
282282
while (daa-- && i < p) {
283283
pages[i++] = pfn_t_to_page(pfn);
284284
pfn.val++;
285+
if (!(i & 15))
286+
cond_resched();
285287
}
286288
} while (i < p);
287289
wc->memory_map = vmap(pages, p, VM_MAP, PAGE_KERNEL);
@@ -849,10 +851,14 @@ static void writecache_discard(struct dm_writecache *wc, sector_t start, sector_
849851

850852
if (likely(!e->write_in_progress)) {
851853
if (!discarded_something) {
852-
writecache_wait_for_ios(wc, READ);
853-
writecache_wait_for_ios(wc, WRITE);
854+
if (!WC_MODE_PMEM(wc)) {
855+
writecache_wait_for_ios(wc, READ);
856+
writecache_wait_for_ios(wc, WRITE);
857+
}
854858
discarded_something = true;
855859
}
860+
if (!writecache_entry_is_committed(wc, e))
861+
wc->uncommitted_blocks--;
856862
writecache_free_entry(wc, e);
857863
}
858864

drivers/md/dm-zoned-metadata.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,8 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb,
10781078
nr_meta_zones = (le32_to_cpu(sb->nr_meta_blocks) + zmd->zone_nr_blocks - 1)
10791079
>> zmd->zone_nr_blocks_shift;
10801080
if (!nr_meta_zones ||
1081-
nr_meta_zones >= zmd->nr_rnd_zones) {
1081+
(zmd->nr_devs <= 1 && nr_meta_zones >= zmd->nr_rnd_zones) ||
1082+
(zmd->nr_devs > 1 && nr_meta_zones >= zmd->nr_cache_zones)) {
10821083
dmz_dev_err(dev, "Invalid number of metadata blocks");
10831084
return -ENXIO;
10841085
}
@@ -1949,7 +1950,7 @@ static struct dm_zone *dmz_get_rnd_zone_for_reclaim(struct dmz_metadata *zmd,
19491950
unsigned int idx, bool idle)
19501951
{
19511952
struct dm_zone *dzone = NULL;
1952-
struct dm_zone *zone, *last = NULL;
1953+
struct dm_zone *zone, *maxw_z = NULL;
19531954
struct list_head *zone_list;
19541955

19551956
/* If we have cache zones select from the cache zone list */
@@ -1961,18 +1962,37 @@ static struct dm_zone *dmz_get_rnd_zone_for_reclaim(struct dmz_metadata *zmd,
19611962
} else
19621963
zone_list = &zmd->dev[idx].map_rnd_list;
19631964

1965+
/*
1966+
* Find the buffer zone with the heaviest weight or the first (oldest)
1967+
* data zone that can be reclaimed.
1968+
*/
19641969
list_for_each_entry(zone, zone_list, link) {
19651970
if (dmz_is_buf(zone)) {
19661971
dzone = zone->bzone;
1967-
if (dzone->dev->dev_idx != idx)
1968-
continue;
1969-
if (!last) {
1970-
last = dzone;
1972+
if (dmz_is_rnd(dzone) && dzone->dev->dev_idx != idx)
19711973
continue;
1972-
}
1973-
if (last->weight < dzone->weight)
1974+
if (!maxw_z || maxw_z->weight < dzone->weight)
1975+
maxw_z = dzone;
1976+
} else {
1977+
dzone = zone;
1978+
if (dmz_lock_zone_reclaim(dzone))
1979+
return dzone;
1980+
}
1981+
}
1982+
1983+
if (maxw_z && dmz_lock_zone_reclaim(maxw_z))
1984+
return maxw_z;
1985+
1986+
/*
1987+
* If we come here, none of the zones inspected could be locked for
1988+
* reclaim. Try again, being more aggressive, that is, find the
1989+
* first zone that can be reclaimed regardless of its weitght.
1990+
*/
1991+
list_for_each_entry(zone, zone_list, link) {
1992+
if (dmz_is_buf(zone)) {
1993+
dzone = zone->bzone;
1994+
if (dmz_is_rnd(dzone) && dzone->dev->dev_idx != idx)
19741995
continue;
1975-
dzone = last;
19761996
} else
19771997
dzone = zone;
19781998
if (dmz_lock_zone_reclaim(dzone))
@@ -2006,7 +2026,7 @@ static struct dm_zone *dmz_get_seq_zone_for_reclaim(struct dmz_metadata *zmd,
20062026
struct dm_zone *dmz_get_zone_for_reclaim(struct dmz_metadata *zmd,
20072027
unsigned int dev_idx, bool idle)
20082028
{
2009-
struct dm_zone *zone;
2029+
struct dm_zone *zone = NULL;
20102030

20112031
/*
20122032
* Search for a zone candidate to reclaim: 2 cases are possible.
@@ -2019,7 +2039,7 @@ struct dm_zone *dmz_get_zone_for_reclaim(struct dmz_metadata *zmd,
20192039
dmz_lock_map(zmd);
20202040
if (list_empty(&zmd->reserved_seq_zones_list))
20212041
zone = dmz_get_seq_zone_for_reclaim(zmd, dev_idx);
2022-
else
2042+
if (!zone)
20232043
zone = dmz_get_rnd_zone_for_reclaim(zmd, dev_idx, idle);
20242044
dmz_unlock_map(zmd);
20252045

drivers/md/dm-zoned-reclaim.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ static int dmz_do_reclaim(struct dmz_reclaim *zrc)
377377
dmz_metadata_label(zmd), zrc->dev_idx);
378378
return -EBUSY;
379379
}
380+
rzone = dzone;
380381

381382
start = jiffies;
382383
if (dmz_is_cache(dzone) || dmz_is_rnd(dzone)) {
@@ -391,8 +392,6 @@ static int dmz_do_reclaim(struct dmz_reclaim *zrc)
391392
*/
392393
ret = dmz_reclaim_rnd_data(zrc, dzone);
393394
}
394-
rzone = dzone;
395-
396395
} else {
397396
struct dm_zone *bzone = dzone->bzone;
398397
sector_t chunk_block = 0;
@@ -415,7 +414,6 @@ static int dmz_do_reclaim(struct dmz_reclaim *zrc)
415414
* be later reclaimed.
416415
*/
417416
ret = dmz_reclaim_seq_data(zrc, dzone);
418-
rzone = dzone;
419417
}
420418
}
421419
out:

drivers/md/dm-zoned-target.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ static int dmz_ctr(struct dm_target *ti, unsigned int argc, char **argv)
890890
}
891891

892892
/* Set target (no write same support) */
893-
ti->max_io_len = dmz_zone_nr_sectors(dmz->metadata) << 9;
893+
ti->max_io_len = dmz_zone_nr_sectors(dmz->metadata);
894894
ti->num_flush_bios = 1;
895895
ti->num_discard_bios = 1;
896896
ti->num_write_zeroes_bios = 1;

drivers/md/dm.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ static void clone_endio(struct bio *bio)
10091009
struct dm_io *io = tio->io;
10101010
struct mapped_device *md = tio->io->md;
10111011
dm_endio_fn endio = tio->ti->type->end_io;
1012+
struct bio *orig_bio = io->orig_bio;
10121013

10131014
if (unlikely(error == BLK_STS_TARGET) && md->type != DM_TYPE_NVME_BIO_BASED) {
10141015
if (bio_op(bio) == REQ_OP_DISCARD &&
@@ -1022,6 +1023,18 @@ static void clone_endio(struct bio *bio)
10221023
disable_write_zeroes(md);
10231024
}
10241025

1026+
/*
1027+
* For zone-append bios get offset in zone of the written
1028+
* sector and add that to the original bio sector pos.
1029+
*/
1030+
if (bio_op(orig_bio) == REQ_OP_ZONE_APPEND) {
1031+
sector_t written_sector = bio->bi_iter.bi_sector;
1032+
struct request_queue *q = orig_bio->bi_disk->queue;
1033+
u64 mask = (u64)blk_queue_zone_sectors(q) - 1;
1034+
1035+
orig_bio->bi_iter.bi_sector += written_sector & mask;
1036+
}
1037+
10251038
if (endio) {
10261039
int r = endio(tio->ti, bio, &error);
10271040
switch (r) {

0 commit comments

Comments
 (0)