[dm-devel] [PATCH 26/26] block: unexport blk_alloc_queue

2021-05-20 Thread Christoph Hellwig
blk_alloc_queue is just an internal helper now, unexport it and remove
it from the public header.

Signed-off-by: Christoph Hellwig 
---
 block/blk-core.c   | 1 -
 block/blk.h| 2 ++
 include/linux/blkdev.h | 1 -
 3 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 689aac2625d2..3515a66022d7 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -599,7 +599,6 @@ struct request_queue *blk_alloc_queue(int node_id)
kmem_cache_free(blk_requestq_cachep, q);
return NULL;
 }
-EXPORT_SYMBOL(blk_alloc_queue);
 
 /**
  * blk_get_queue - increment the request_queue refcount
diff --git a/block/blk.h b/block/blk.h
index cba3a94aabfa..3440142f029b 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -359,4 +359,6 @@ int bio_add_hw_page(struct request_queue *q, struct bio 
*bio,
struct page *page, unsigned int len, unsigned int offset,
unsigned int max_sectors, bool *same_page);
 
+struct request_queue *blk_alloc_queue(int node_id);
+
 #endif /* BLK_INTERNAL_H */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 2c28577b50f4..d66d0da72529 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1213,7 +1213,6 @@ static inline int blk_rq_map_sg(struct request_queue *q, 
struct request *rq,
 extern void blk_dump_rq_flags(struct request *, char *);
 
 bool __must_check blk_get_queue(struct request_queue *);
-struct request_queue *blk_alloc_queue(int node_id);
 extern void blk_put_queue(struct request_queue *);
 extern void blk_set_queue_dying(struct request_queue *);
 
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH 24/26] xpram: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-20 Thread Christoph Hellwig
Convert the xpram driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.

Signed-off-by: Christoph Hellwig 
---
 drivers/s390/block/xpram.c | 26 +-
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/s390/block/xpram.c b/drivers/s390/block/xpram.c
index d1ed39162943..91ef710edfd2 100644
--- a/drivers/s390/block/xpram.c
+++ b/drivers/s390/block/xpram.c
@@ -56,7 +56,6 @@ typedef struct {
 static xpram_device_t xpram_devices[XPRAM_MAX_DEVS];
 static unsigned int xpram_sizes[XPRAM_MAX_DEVS];
 static struct gendisk *xpram_disks[XPRAM_MAX_DEVS];
-static struct request_queue *xpram_queues[XPRAM_MAX_DEVS];
 static unsigned int xpram_pages;
 static int xpram_devs;
 
@@ -341,17 +340,13 @@ static int __init xpram_setup_blkdev(void)
int i, rc = -ENOMEM;
 
for (i = 0; i < xpram_devs; i++) {
-   xpram_disks[i] = alloc_disk(1);
+   xpram_disks[i] = blk_alloc_disk(NUMA_NO_NODE);
if (!xpram_disks[i])
goto out;
-   xpram_queues[i] = blk_alloc_queue(NUMA_NO_NODE);
-   if (!xpram_queues[i]) {
-   put_disk(xpram_disks[i]);
-   goto out;
-   }
-   blk_queue_flag_set(QUEUE_FLAG_NONROT, xpram_queues[i]);
-   blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, xpram_queues[i]);
-   blk_queue_logical_block_size(xpram_queues[i], 4096);
+   blk_queue_flag_set(QUEUE_FLAG_NONROT, xpram_disks[i]->queue);
+   blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM,
+   xpram_disks[i]->queue);
+   blk_queue_logical_block_size(xpram_disks[i]->queue, 4096);
}
 
/*
@@ -373,9 +368,9 @@ static int __init xpram_setup_blkdev(void)
offset += xpram_devices[i].size;
disk->major = XPRAM_MAJOR;
disk->first_minor = i;
+   disk->minors = 1;
disk->fops = _devops;
disk->private_data = _devices[i];
-   disk->queue = xpram_queues[i];
sprintf(disk->disk_name, "slram%d", i);
set_capacity(disk, xpram_sizes[i] << 1);
add_disk(disk);
@@ -383,10 +378,8 @@ static int __init xpram_setup_blkdev(void)
 
return 0;
 out:
-   while (i--) {
-   blk_cleanup_queue(xpram_queues[i]);
-   put_disk(xpram_disks[i]);
-   }
+   while (i--)
+   blk_cleanup_disk(xpram_disks[i]);
return rc;
 }
 
@@ -434,8 +427,7 @@ static void __exit xpram_exit(void)
int i;
for (i = 0; i < xpram_devs; i++) {
del_gendisk(xpram_disks[i]);
-   blk_cleanup_queue(xpram_queues[i]);
-   put_disk(xpram_disks[i]);
+   blk_cleanup_disk(xpram_disks[i]);
}
unregister_blkdev(XPRAM_MAJOR, XPRAM_NAME);
platform_device_unregister(xpram_pdev);
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH 25/26] null_blk: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-20 Thread Christoph Hellwig
Convert the null_blk driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.  Note that the
blk-mq mode is left with its own allocations scheme, to be handled later.

Signed-off-by: Christoph Hellwig 
---
 drivers/block/null_blk/main.c | 38 +--
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 5f006d9e1472..d8e098f1e5b5 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1597,11 +1597,10 @@ static void null_del_dev(struct nullb *nullb)
null_restart_queue_async(nullb);
}
 
-   blk_cleanup_queue(nullb->q);
+   blk_cleanup_disk(nullb->disk);
if (dev->queue_mode == NULL_Q_MQ &&
nullb->tag_set == >__tag_set)
blk_mq_free_tag_set(nullb->tag_set);
-   put_disk(nullb->disk);
cleanup_queues(nullb);
if (null_cache_active(nullb))
null_free_device_storage(nullb->dev, true);
@@ -1700,22 +1699,19 @@ static int init_driver_queues(struct nullb *nullb)
 static int null_gendisk_register(struct nullb *nullb)
 {
sector_t size = ((sector_t)nullb->dev->size * SZ_1M) >> SECTOR_SHIFT;
-   struct gendisk *disk;
+   struct gendisk *disk = nullb->disk;
 
-   disk = nullb->disk = alloc_disk_node(1, nullb->dev->home_node);
-   if (!disk)
-   return -ENOMEM;
set_capacity(disk, size);
 
disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO;
disk->major = null_major;
disk->first_minor   = nullb->index;
+   disk->minors= 1;
if (queue_is_mq(nullb->q))
disk->fops  = _rq_ops;
else
disk->fops  = _bio_ops;
disk->private_data  = nullb;
-   disk->queue = nullb->q;
strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
 
if (nullb->dev->zoned) {
@@ -1851,23 +1847,27 @@ static int null_add_dev(struct nullb_device *dev)
goto out_cleanup_queues;
 
if (!null_setup_fault())
-   goto out_cleanup_queues;
+   goto out_cleanup_tags;
 
+   rv = -ENOMEM;
nullb->tag_set->timeout = 5 * HZ;
nullb->q = blk_mq_init_queue_data(nullb->tag_set, nullb);
-   if (IS_ERR(nullb->q)) {
-   rv = -ENOMEM;
+   if (IS_ERR(nullb->q))
goto out_cleanup_tags;
-   }
+   nullb->disk = alloc_disk_node(1, nullb->dev->home_node);
+   if (!nullb->disk)
+   goto out_cleanup_disk;
+   nullb->disk->queue = nullb->q;
} else if (dev->queue_mode == NULL_Q_BIO) {
-   nullb->q = blk_alloc_queue(dev->home_node);
-   if (!nullb->q) {
-   rv = -ENOMEM;
+   rv = -ENOMEM;
+   nullb->disk = blk_alloc_disk(nullb->dev->home_node);
+   if (!nullb->disk)
goto out_cleanup_queues;
-   }
+
+   nullb->q = nullb->disk->queue;
rv = init_driver_queues(nullb);
if (rv)
-   goto out_cleanup_blk_queue;
+   goto out_cleanup_disk;
}
 
if (dev->mbps) {
@@ -1883,7 +1883,7 @@ static int null_add_dev(struct nullb_device *dev)
if (dev->zoned) {
rv = null_init_zoned_dev(dev, nullb->q);
if (rv)
-   goto out_cleanup_blk_queue;
+   goto out_cleanup_disk;
}
 
nullb->q->queuedata = nullb;
@@ -1921,8 +1921,8 @@ static int null_add_dev(struct nullb_device *dev)
return 0;
 out_cleanup_zone:
null_free_zoned_dev(dev);
-out_cleanup_blk_queue:
-   blk_cleanup_queue(nullb->q);
+out_cleanup_disk:
+   blk_cleanup_disk(nullb->disk);
 out_cleanup_tags:
if (dev->queue_mode == NULL_Q_MQ && nullb->tag_set == >__tag_set)
blk_mq_free_tag_set(nullb->tag_set);
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH 23/26] dcssblk: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-20 Thread Christoph Hellwig
Convert the dcssblk driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.

Signed-off-by: Christoph Hellwig 
---
 drivers/s390/block/dcssblk.c | 26 --
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index da33cb4cba28..7faa5639 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -90,7 +90,6 @@ struct dcssblk_dev_info {
int segment_type;
unsigned char save_pending;
unsigned char is_shared;
-   struct request_queue *dcssblk_queue;
int num_of_segments;
struct list_head seg_list;
struct dax_device *dax_dev;
@@ -429,9 +428,7 @@ dcssblk_shared_store(struct device *dev, struct 
device_attribute *attr, const ch
kill_dax(dev_info->dax_dev);
put_dax(dev_info->dax_dev);
del_gendisk(dev_info->gd);
-   blk_cleanup_queue(dev_info->dcssblk_queue);
-   dev_info->gd->queue = NULL;
-   put_disk(dev_info->gd);
+   blk_cleanup_disk(dev_info->gd);
up_write(_devices_sem);
 
if (device_remove_file_self(dev, attr)) {
@@ -644,18 +641,17 @@ dcssblk_add_store(struct device *dev, struct 
device_attribute *attr, const char
dev_info->dev.release = dcssblk_release_segment;
dev_info->dev.groups = dcssblk_dev_attr_groups;
INIT_LIST_HEAD(_info->lh);
-   dev_info->gd = alloc_disk(DCSSBLK_MINORS_PER_DISK);
+   dev_info->gd = blk_alloc_disk(NUMA_NO_NODE);
if (dev_info->gd == NULL) {
rc = -ENOMEM;
goto seg_list_del;
}
dev_info->gd->major = dcssblk_major;
+   dev_info->gd->minors = DCSSBLK_MINORS_PER_DISK;
dev_info->gd->fops = _devops;
-   dev_info->dcssblk_queue = blk_alloc_queue(NUMA_NO_NODE);
-   dev_info->gd->queue = dev_info->dcssblk_queue;
dev_info->gd->private_data = dev_info;
-   blk_queue_logical_block_size(dev_info->dcssblk_queue, 4096);
-   blk_queue_flag_set(QUEUE_FLAG_DAX, dev_info->dcssblk_queue);
+   blk_queue_logical_block_size(dev_info->gd->queue, 4096);
+   blk_queue_flag_set(QUEUE_FLAG_DAX, dev_info->gd->queue);
 
seg_byte_size = (dev_info->end - dev_info->start + 1);
set_capacity(dev_info->gd, seg_byte_size >> 9); // size in sectors
@@ -719,9 +715,7 @@ dcssblk_add_store(struct device *dev, struct 
device_attribute *attr, const char
 
 put_dev:
list_del(_info->lh);
-   blk_cleanup_queue(dev_info->dcssblk_queue);
-   dev_info->gd->queue = NULL;
-   put_disk(dev_info->gd);
+   blk_cleanup_disk(dev_info->gd);
list_for_each_entry(seg_info, _info->seg_list, lh) {
segment_unload(seg_info->segment_name);
}
@@ -731,9 +725,7 @@ dcssblk_add_store(struct device *dev, struct 
device_attribute *attr, const char
 dev_list_del:
list_del(_info->lh);
 release_gd:
-   blk_cleanup_queue(dev_info->dcssblk_queue);
-   dev_info->gd->queue = NULL;
-   put_disk(dev_info->gd);
+   blk_cleanup_disk(dev_info->gd);
up_write(_devices_sem);
 seg_list_del:
if (dev_info == NULL)
@@ -801,9 +793,7 @@ dcssblk_remove_store(struct device *dev, struct 
device_attribute *attr, const ch
kill_dax(dev_info->dax_dev);
put_dax(dev_info->dax_dev);
del_gendisk(dev_info->gd);
-   blk_cleanup_queue(dev_info->dcssblk_queue);
-   dev_info->gd->queue = NULL;
-   put_disk(dev_info->gd);
+   blk_cleanup_disk(dev_info->gd);
 
/* unload all related segments */
list_for_each_entry(entry, _info->seg_list, lh)
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH 21/26] n64cart: convert to blk_alloc_disk

2021-05-20 Thread Christoph Hellwig
Convert the n64cart driver to use the blk_alloc_disk helper to simplify
gendisk and request_queue allocation.

Signed-off-by: Christoph Hellwig 
---
 drivers/block/n64cart.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/block/n64cart.c b/drivers/block/n64cart.c
index 3dae4b631dea..7b4dd10af9ec 100644
--- a/drivers/block/n64cart.c
+++ b/drivers/block/n64cart.c
@@ -132,14 +132,10 @@ static int __init n64cart_probe(struct platform_device 
*pdev)
if (!reg_base)
return -EINVAL;
 
-   disk = alloc_disk(0);
+   disk = blk_alloc_disk(NUMA_NO_NODE);
if (!disk)
return -ENOMEM;
 
-   disk->queue = blk_alloc_queue(NUMA_NO_NODE);
-   if (!disk->queue)
-   return -ENOMEM;
-
disk->first_minor = 0;
disk->flags = GENHD_FL_NO_PART_SCAN;
disk->fops = _fops;
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH 18/26] nvme-multipath: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-20 Thread Christoph Hellwig
Convert the nvme-multipath driver to use the blk_alloc_disk and
blk_cleanup_disk helpers to simplify gendisk and request_queue
allocation.

Signed-off-by: Christoph Hellwig 
---
 drivers/nvdimm/pmem.c |  1 -
 drivers/nvme/host/multipath.c | 45 ++-
 2 files changed, 13 insertions(+), 33 deletions(-)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 9fcd05084564..31f3c4bd6f72 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -472,7 +472,6 @@ static int pmem_attach_disk(struct device *dev,
blk_queue_flag_set(QUEUE_FLAG_DAX, q);
 
disk->fops  = _fops;
-   disk->queue = q;
disk->private_data  = pmem;
nvdimm_namespace_disk_name(ndns, disk->disk_name);
set_capacity(disk, (pmem->size - pmem->pfn_pad - pmem->data_offset)
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index a5d02f236cca..b5fbdb416022 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -427,7 +427,6 @@ static void nvme_requeue_work(struct work_struct *work)
 
 int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
 {
-   struct request_queue *q;
bool vwc = false;
 
mutex_init(>lock);
@@ -443,33 +442,24 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct 
nvme_ns_head *head)
if (!(ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) || !multipath)
return 0;
 
-   q = blk_alloc_queue(ctrl->numa_node);
-   if (!q)
-   goto out;
-   blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
-   /* set to a default value for 512 until disk is validated */
-   blk_queue_logical_block_size(q, 512);
-   blk_set_stacking_limits(>limits);
-
-   /* we need to propagate up the VMC settings */
-   if (ctrl->vwc & NVME_CTRL_VWC_PRESENT)
-   vwc = true;
-   blk_queue_write_cache(q, vwc, vwc);
-
-   head->disk = alloc_disk(0);
+   head->disk = blk_alloc_disk(ctrl->numa_node);
if (!head->disk)
-   goto out_cleanup_queue;
+   return -ENOMEM;
head->disk->fops = _ns_head_ops;
head->disk->private_data = head;
-   head->disk->queue = q;
sprintf(head->disk->disk_name, "nvme%dn%d",
ctrl->subsys->instance, head->instance);
-   return 0;
 
-out_cleanup_queue:
-   blk_cleanup_queue(q);
-out:
-   return -ENOMEM;
+   blk_queue_flag_set(QUEUE_FLAG_NONROT, head->disk->queue);
+   /* set to a default value of 512 until the disk is validated */
+   blk_queue_logical_block_size(head->disk->queue, 512);
+   blk_set_stacking_limits(>disk->queue->limits);
+
+   /* we need to propagate up the VMC settings */
+   if (ctrl->vwc & NVME_CTRL_VWC_PRESENT)
+   vwc = true;
+   blk_queue_write_cache(head->disk->queue, vwc, vwc);
+   return 0;
 }
 
 static void nvme_mpath_set_live(struct nvme_ns *ns)
@@ -768,16 +758,7 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)
/* make sure all pending bios are cleaned up */
kblockd_schedule_work(>requeue_work);
flush_work(>requeue_work);
-   blk_cleanup_queue(head->disk->queue);
-   if (!test_bit(NVME_NSHEAD_DISK_LIVE, >flags)) {
-   /*
-* if device_add_disk wasn't called, prevent
-* disk release to put a bogus reference on the
-* request queue
-*/
-   head->disk->queue = NULL;
-   }
-   put_disk(head->disk);
+   blk_cleanup_disk(head->disk);
 }
 
 void nvme_mpath_init_ctrl(struct nvme_ctrl *ctrl)
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH 20/26] simdisk: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-20 Thread Christoph Hellwig
Convert the simdisk driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.

Signed-off-by: Christoph Hellwig 
---
 arch/xtensa/platforms/iss/simdisk.c | 29 +++--
 1 file changed, 7 insertions(+), 22 deletions(-)

diff --git a/arch/xtensa/platforms/iss/simdisk.c 
b/arch/xtensa/platforms/iss/simdisk.c
index fc09be7b1347..3cdfa00738e0 100644
--- a/arch/xtensa/platforms/iss/simdisk.c
+++ b/arch/xtensa/platforms/iss/simdisk.c
@@ -27,7 +27,6 @@
 struct simdisk {
const char *filename;
spinlock_t lock;
-   struct request_queue *queue;
struct gendisk *gd;
struct proc_dir_entry *procfile;
int users;
@@ -266,21 +265,13 @@ static int __init simdisk_setup(struct simdisk *dev, int 
which,
spin_lock_init(>lock);
dev->users = 0;
 
-   dev->queue = blk_alloc_queue(NUMA_NO_NODE);
-   if (dev->queue == NULL) {
-   pr_err("blk_alloc_queue failed\n");
-   goto out_alloc_queue;
-   }
-
-   dev->gd = alloc_disk(SIMDISK_MINORS);
-   if (dev->gd == NULL) {
-   pr_err("alloc_disk failed\n");
-   goto out_alloc_disk;
-   }
+   dev->gd = blk_alloc_disk(NUMA_NO_NODE);
+   if (!dev->gd)
+   return -ENOMEM;
dev->gd->major = simdisk_major;
dev->gd->first_minor = which;
+   dev->gd->minors = SIMDISK_MINORS;
dev->gd->fops = _ops;
-   dev->gd->queue = dev->queue;
dev->gd->private_data = dev;
snprintf(dev->gd->disk_name, 32, "simdisk%d", which);
set_capacity(dev->gd, 0);
@@ -288,12 +279,6 @@ static int __init simdisk_setup(struct simdisk *dev, int 
which,
 
dev->procfile = proc_create_data(tmp, 0644, procdir, _proc_ops, 
dev);
return 0;
-
-out_alloc_disk:
-   blk_cleanup_queue(dev->queue);
-   dev->queue = NULL;
-out_alloc_queue:
-   return -ENOMEM;
 }
 
 static int __init simdisk_init(void)
@@ -343,10 +328,10 @@ static void simdisk_teardown(struct simdisk *dev, int 
which,
char tmp[2] = { '0' + which, 0 };
 
simdisk_detach(dev);
-   if (dev->gd)
+   if (dev->gd) {
del_gendisk(dev->gd);
-   if (dev->queue)
-   blk_cleanup_queue(dev->queue);
+   blk_cleanup_disk(dev->gd);
+   }
remove_proc_entry(tmp, procdir);
 }
 
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH 22/26] ps3vram: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-20 Thread Christoph Hellwig
Convert the ps3vram driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.

Signed-off-by: Christoph Hellwig 
---
 drivers/block/ps3vram.c | 31 ---
 1 file changed, 8 insertions(+), 23 deletions(-)

diff --git a/drivers/block/ps3vram.c b/drivers/block/ps3vram.c
index 1d738999fb69..7fbf469651c4 100644
--- a/drivers/block/ps3vram.c
+++ b/drivers/block/ps3vram.c
@@ -67,7 +67,6 @@ struct ps3vram_cache {
 };
 
 struct ps3vram_priv {
-   struct request_queue *queue;
struct gendisk *gendisk;
 
u64 size;
@@ -613,7 +612,6 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev)
 {
struct ps3vram_priv *priv;
int error, status;
-   struct request_queue *queue;
struct gendisk *gendisk;
u64 ddr_size, ddr_lpar, ctrl_lpar, info_lpar, reports_lpar,
reports_size, xdr_lpar;
@@ -736,33 +734,23 @@ static int ps3vram_probe(struct ps3_system_bus_device 
*dev)
 
ps3vram_proc_init(dev);
 
-   queue = blk_alloc_queue(NUMA_NO_NODE);
-   if (!queue) {
-   dev_err(>core, "blk_alloc_queue failed\n");
-   error = -ENOMEM;
-   goto out_cache_cleanup;
-   }
-
-   priv->queue = queue;
-   blk_queue_max_segments(queue, BLK_MAX_SEGMENTS);
-   blk_queue_max_segment_size(queue, BLK_MAX_SEGMENT_SIZE);
-   blk_queue_max_hw_sectors(queue, BLK_SAFE_MAX_SECTORS);
-
-   gendisk = alloc_disk(1);
+   gendisk = blk_alloc_disk(NUMA_NO_NODE);
if (!gendisk) {
-   dev_err(>core, "alloc_disk failed\n");
+   dev_err(>core, "blk_alloc_disk failed\n");
error = -ENOMEM;
-   goto fail_cleanup_queue;
+   goto out_cache_cleanup;
}
 
priv->gendisk = gendisk;
gendisk->major = ps3vram_major;
-   gendisk->first_minor = 0;
+   gendisk->minors = 1;
gendisk->fops = _fops;
-   gendisk->queue = queue;
gendisk->private_data = dev;
strlcpy(gendisk->disk_name, DEVICE_NAME, sizeof(gendisk->disk_name));
set_capacity(gendisk, priv->size >> 9);
+   blk_queue_max_segments(gendisk->queue, BLK_MAX_SEGMENTS);
+   blk_queue_max_segment_size(gendisk->queue, BLK_MAX_SEGMENT_SIZE);
+   blk_queue_max_hw_sectors(gendisk->queue, BLK_SAFE_MAX_SECTORS);
 
dev_info(>core, "%s: Using %llu MiB of GPU memory\n",
 gendisk->disk_name, get_capacity(gendisk) >> 11);
@@ -770,8 +758,6 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev)
device_add_disk(>core, gendisk, NULL);
return 0;
 
-fail_cleanup_queue:
-   blk_cleanup_queue(queue);
 out_cache_cleanup:
remove_proc_entry(DEVICE_NAME, NULL);
ps3vram_cache_cleanup(dev);
@@ -802,8 +788,7 @@ static void ps3vram_remove(struct ps3_system_bus_device 
*dev)
struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
 
del_gendisk(priv->gendisk);
-   put_disk(priv->gendisk);
-   blk_cleanup_queue(priv->queue);
+   blk_cleanup_disk(priv->gendisk);
remove_proc_entry(DEVICE_NAME, NULL);
ps3vram_cache_cleanup(dev);
iounmap(priv->reports);
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH 17/26] nvdimm-pmem: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-20 Thread Christoph Hellwig
Convert the nvdimm-pmem driver to use the blk_alloc_disk and
blk_cleanup_disk helpers to simplify gendisk and request_queue
allocation.

Signed-off-by: Christoph Hellwig 
---
 drivers/nvdimm/pmem.c | 15 +--
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 968b8483c763..9fcd05084564 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -338,7 +338,7 @@ static void pmem_pagemap_cleanup(struct dev_pagemap *pgmap)
struct request_queue *q =
container_of(pgmap->ref, struct request_queue, q_usage_counter);
 
-   blk_cleanup_queue(q);
+   blk_cleanup_disk(queue_to_disk(q));
 }
 
 static void pmem_release_queue(void *pgmap)
@@ -361,7 +361,6 @@ static void pmem_release_disk(void *__pmem)
kill_dax(pmem->dax_dev);
put_dax(pmem->dax_dev);
del_gendisk(pmem->disk);
-   put_disk(pmem->disk);
 }
 
 static const struct dev_pagemap_ops fsdax_pagemap_ops = {
@@ -422,10 +421,12 @@ static int pmem_attach_disk(struct device *dev,
return -EBUSY;
}
 
-   q = blk_alloc_queue(dev_to_node(dev));
-   if (!q)
+   disk = blk_alloc_disk(nid);
+   if (!disk)
return -ENOMEM;
+   q = disk->queue;
 
+   pmem->disk = disk;
pmem->pfn_flags = PFN_DEV;
pmem->pgmap.ref = >q_usage_counter;
if (is_nd_pfn(dev)) {
@@ -470,11 +471,6 @@ static int pmem_attach_disk(struct device *dev,
if (pmem->pfn_flags & PFN_MAP)
blk_queue_flag_set(QUEUE_FLAG_DAX, q);
 
-   disk = alloc_disk_node(0, nid);
-   if (!disk)
-   return -ENOMEM;
-   pmem->disk = disk;
-
disk->fops  = _fops;
disk->queue = q;
disk->private_data  = pmem;
@@ -490,7 +486,6 @@ static int pmem_attach_disk(struct device *dev,
flags = DAXDEV_F_SYNC;
dax_dev = alloc_dax(pmem, disk->disk_name, _dax_ops, flags);
if (IS_ERR(dax_dev)) {
-   put_disk(disk);
return PTR_ERR(dax_dev);
}
dax_write_cache(dax_dev, nvdimm_has_cache(nd_region));
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH 19/26] nfblock: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-20 Thread Christoph Hellwig
Convert the nfblock driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.

Signed-off-by: Christoph Hellwig 
---
 arch/m68k/emu/nfblock.c | 20 +---
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/arch/m68k/emu/nfblock.c b/arch/m68k/emu/nfblock.c
index ba808543161a..9a8394e96388 100644
--- a/arch/m68k/emu/nfblock.c
+++ b/arch/m68k/emu/nfblock.c
@@ -55,7 +55,6 @@ struct nfhd_device {
int id;
u32 blocks, bsize;
int bshift;
-   struct request_queue *queue;
struct gendisk *disk;
 };
 
@@ -119,32 +118,24 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 
bsize)
dev->bsize = bsize;
dev->bshift = ffs(bsize) - 10;
 
-   dev->queue = blk_alloc_queue(NUMA_NO_NODE);
-   if (dev->queue == NULL)
-   goto free_dev;
-
-   blk_queue_logical_block_size(dev->queue, bsize);
-
-   dev->disk = alloc_disk(16);
+   dev->disk = blk_alloc_disk(NUMA_NO_NODE);
if (!dev->disk)
-   goto free_queue;
+   goto free_dev;
 
dev->disk->major = major_num;
dev->disk->first_minor = dev_id * 16;
+   dev->disk->minors = 16;
dev->disk->fops = _ops;
dev->disk->private_data = dev;
sprintf(dev->disk->disk_name, "nfhd%u", dev_id);
set_capacity(dev->disk, (sector_t)blocks * (bsize / 512));
-   dev->disk->queue = dev->queue;
-
+   blk_queue_logical_block_size(dev->disk->queue, bsize);
add_disk(dev->disk);
 
list_add_tail(>list, _list);
 
return 0;
 
-free_queue:
-   blk_cleanup_queue(dev->queue);
 free_dev:
kfree(dev);
 out:
@@ -186,8 +177,7 @@ static void __exit nfhd_exit(void)
list_for_each_entry_safe(dev, next, _list, list) {
list_del(>list);
del_gendisk(dev->disk);
-   put_disk(dev->disk);
-   blk_cleanup_queue(dev->queue);
+   blk_cleanup_disk(dev->disk);
kfree(dev);
}
unregister_blkdev(major_num, "nfhd");
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [PATCH v3 01/11] block: improve handling of all zones reset operation

2021-05-20 Thread Johannes Thumshirn
Looks good,
Reviewed-by: Johannes Thumshirn 



--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [PATCH v3 08/11] dm: Forbid requeue of writes to zones

2021-05-20 Thread Johannes Thumshirn
Reviewed-by: Johannes Thumshirn 



--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [PATCH v3 09/11] dm: rearrange core declarations

2021-05-20 Thread Johannes Thumshirn
Reviewed-by: Johannes Thumshirn 



--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [PATCH v3 11/11] dm crypt: Fix zoned block device support

2021-05-20 Thread Johannes Thumshirn
Looks good,
Reviewed-by: Johannes Thumshirn 



--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [PATCH v3 02/11] block: introduce bio zone helpers

2021-05-20 Thread Johannes Thumshirn
Looks good,
Reviewed-by: Johannes Thumshirn 



--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH v3 04/11] dm: Fix dm_accept_partial_bio()

2021-05-20 Thread Damien Le Moal
Fix dm_accept_partial_bio() to actually check that zone management
commands are not passed as explained in the function documentation
comment. Also, since a zone append operation cannot be split, add
REQ_OP_ZONE_APPEND as a forbidden command.

White lines are added around the group of BUG_ON() calls to make the
code more legible.

Signed-off-by: Damien Le Moal 
Reviewed-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/md/dm.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index ca2aedd8ee7d..a9211575bfed 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1237,8 +1237,9 @@ static int dm_dax_zero_page_range(struct dax_device 
*dax_dev, pgoff_t pgoff,
 
 /*
  * A target may call dm_accept_partial_bio only from the map routine.  It is
- * allowed for all bio types except REQ_PREFLUSH, REQ_OP_ZONE_RESET,
- * REQ_OP_ZONE_OPEN, REQ_OP_ZONE_CLOSE and REQ_OP_ZONE_FINISH.
+ * allowed for all bio types except REQ_PREFLUSH, zone management operations
+ * (REQ_OP_ZONE_RESET, REQ_OP_ZONE_OPEN, REQ_OP_ZONE_CLOSE and
+ * REQ_OP_ZONE_FINISH) and zone append writes.
  *
  * dm_accept_partial_bio informs the dm that the target only wants to process
  * additional n_sectors sectors of the bio and the rest of the data should be
@@ -1268,9 +1269,13 @@ void dm_accept_partial_bio(struct bio *bio, unsigned 
n_sectors)
 {
struct dm_target_io *tio = container_of(bio, struct dm_target_io, 
clone);
unsigned bi_size = bio->bi_iter.bi_size >> SECTOR_SHIFT;
+
BUG_ON(bio->bi_opf & REQ_PREFLUSH);
+   BUG_ON(op_is_zone_mgmt(bio_op(bio)));
+   BUG_ON(bio_op(bio) == REQ_OP_ZONE_APPEND);
BUG_ON(bi_size > *tio->len_ptr);
BUG_ON(n_sectors > bi_size);
+
*tio->len_ptr -= bi_size - n_sectors;
bio->bi_iter.bi_size = n_sectors << SECTOR_SHIFT;
 }
-- 
2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH v3 05/11] dm: cleanup device_area_is_invalid()

2021-05-20 Thread Damien Le Moal
In device_area_is_invalid(), use bdev_is_zoned() instead of open
coding the test on the zoned model returned by bdev_zoned_model().

Signed-off-by: Damien Le Moal 
Reviewed-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/md/dm-table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index ee47a332b462..21fd9cd4da32 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -249,7 +249,7 @@ static int device_area_is_invalid(struct dm_target *ti, 
struct dm_dev *dev,
 * If the target is mapped to zoned block device(s), check
 * that the zones are not partially mapped.
 */
-   if (bdev_zoned_model(bdev) != BLK_ZONED_NONE) {
+   if (bdev_is_zoned(bdev)) {
unsigned int zone_sectors = bdev_zone_sectors(bdev);
 
if (start & (zone_sectors - 1)) {
-- 
2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH v3 11/11] dm crypt: Fix zoned block device support

2021-05-20 Thread Damien Le Moal
Zone append BIOs (REQ_OP_ZONE_APPEND) always specify the start sector
of the zone to be written instead of the actual sector location to
write. The write location is determined by the device and returned to
the host upon completion of the operation. This interface, while simple
and efficient for writing into sequential zones of a zoned block
device, is incompatible with the use of sector values to calculate a
cypher block IV. All data written in a zone end up using the same IV
values corresponding to the first sectors of the zone, but read
operation will specify any sector within the zone resulting in an IV
mismatch between encryption and decryption.

To solve this problem, report to DM core that zone append operations are
not supported. This result in the zone append operations being emulated
using regular write operations.

Reported-by: Shin'ichiro Kawasaki 
Signed-off-by: Damien Le Moal 
Reviewed-by: Hannes Reinecke 
---
 drivers/md/dm-crypt.c | 24 +++-
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index f410ceee51d7..50f4cbd600d5 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -3280,14 +3280,28 @@ static int crypt_ctr(struct dm_target *ti, unsigned int 
argc, char **argv)
}
cc->start = tmpll;
 
-   /*
-* For zoned block devices, we need to preserve the issuer write
-* ordering. To do so, disable write workqueues and force inline
-* encryption completion.
-*/
if (bdev_is_zoned(cc->dev->bdev)) {
+   /*
+* For zoned block devices, we need to preserve the issuer write
+* ordering. To do so, disable write workqueues and force inline
+* encryption completion.
+*/
set_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, >flags);
set_bit(DM_CRYPT_WRITE_INLINE, >flags);
+
+   /*
+* All zone append writes to a zone of a zoned block device will
+* have the same BIO sector, the start of the zone. When the
+* cypher IV mode uses sector values, all data targeting a
+* zone will be encrypted using the first sector numbers of the
+* zone. This will not result in write errors but will
+* cause most reads to fail as reads will use the sector values
+* for the actual data locations, resulting in IV mismatch.
+* To avoid this problem, ask DM core to emulate zone append
+* operations with regular writes.
+*/
+   DMDEBUG("Zone append operations will be emulated");
+   ti->emulate_zone_append = true;
}
 
if (crypt_integrity_aead(cc) || cc->integrity_iv_size) {
-- 
2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH v3 09/11] dm: rearrange core declarations

2021-05-20 Thread Damien Le Moal
Move the definitions of struct dm_target_io, struct dm_io and of the
bits of the flags field of struct mapped_device from dm.c to dm-core.h
to make them usable from dm-zone.c.
For the same reason, declare dec_pending() in dm-core.h after renaming
it to dm_io_dec_pending(). And for symmetry of the function names,
introduce the inline helper dm_io_inc_pending() instead of directly
using atomic_inc() calls.

Signed-off-by: Damien Le Moal 
Reviewed-by: Hannes Reinecke 
---
 drivers/md/dm-core.h | 52 ++
 drivers/md/dm.c  | 59 ++--
 2 files changed, 59 insertions(+), 52 deletions(-)

diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h
index 5953ff2bd260..cfabc1c91f9f 100644
--- a/drivers/md/dm-core.h
+++ b/drivers/md/dm-core.h
@@ -116,6 +116,19 @@ struct mapped_device {
struct srcu_struct io_barrier;
 };
 
+/*
+ * Bits for the flags field of struct mapped_device.
+ */
+#define DMF_BLOCK_IO_FOR_SUSPEND 0
+#define DMF_SUSPENDED 1
+#define DMF_FROZEN 2
+#define DMF_FREEING 3
+#define DMF_DELETING 4
+#define DMF_NOFLUSH_SUSPENDING 5
+#define DMF_DEFERRED_REMOVE 6
+#define DMF_SUSPENDED_INTERNALLY 7
+#define DMF_POST_SUSPENDING 8
+
 void disable_discard(struct mapped_device *md);
 void disable_write_same(struct mapped_device *md);
 void disable_write_zeroes(struct mapped_device *md);
@@ -173,6 +186,45 @@ struct dm_table {
 #endif
 };
 
+/*
+ * One of these is allocated per clone bio.
+ */
+#define DM_TIO_MAGIC 7282014
+struct dm_target_io {
+   unsigned int magic;
+   struct dm_io *io;
+   struct dm_target *ti;
+   unsigned int target_bio_nr;
+   unsigned int *len_ptr;
+   bool inside_dm_io;
+   struct bio clone;
+};
+
+/*
+ * One of these is allocated per original bio.
+ * It contains the first clone used for that original.
+ */
+#define DM_IO_MAGIC 5191977
+struct dm_io {
+   unsigned int magic;
+   struct mapped_device *md;
+   blk_status_t status;
+   atomic_t io_count;
+   struct bio *orig_bio;
+   unsigned long start_time;
+   spinlock_t endio_lock;
+   struct dm_stats_aux stats_aux;
+   /* last member of dm_target_io is 'struct bio' */
+   struct dm_target_io tio;
+};
+
+static inline void dm_io_inc_pending(struct dm_io *io)
+{
+   atomic_inc(>io_count);
+}
+
+void dm_io_dec_pending(struct dm_io *io, blk_status_t error);
+
 static inline struct completion *dm_get_completion_from_kobject(struct kobject 
*kobj)
 {
return _of(kobj, struct dm_kobject_holder, kobj)->completion;
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 4426019a89cc..563504163b74 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -74,38 +74,6 @@ struct clone_info {
unsigned sector_count;
 };
 
-/*
- * One of these is allocated per clone bio.
- */
-#define DM_TIO_MAGIC 7282014
-struct dm_target_io {
-   unsigned magic;
-   struct dm_io *io;
-   struct dm_target *ti;
-   unsigned target_bio_nr;
-   unsigned *len_ptr;
-   bool inside_dm_io;
-   struct bio clone;
-};
-
-/*
- * One of these is allocated per original bio.
- * It contains the first clone used for that original.
- */
-#define DM_IO_MAGIC 5191977
-struct dm_io {
-   unsigned magic;
-   struct mapped_device *md;
-   blk_status_t status;
-   atomic_t io_count;
-   struct bio *orig_bio;
-   unsigned long start_time;
-   spinlock_t endio_lock;
-   struct dm_stats_aux stats_aux;
-   /* last member of dm_target_io is 'struct bio' */
-   struct dm_target_io tio;
-};
-
 #define DM_TARGET_IO_BIO_OFFSET (offsetof(struct dm_target_io, clone))
 #define DM_IO_BIO_OFFSET \
(offsetof(struct dm_target_io, clone) + offsetof(struct dm_io, tio))
@@ -137,19 +105,6 @@ EXPORT_SYMBOL_GPL(dm_bio_get_target_bio_nr);
 
 #define MINOR_ALLOCED ((void *)-1)
 
-/*
- * Bits for the md->flags field.
- */
-#define DMF_BLOCK_IO_FOR_SUSPEND 0
-#define DMF_SUSPENDED 1
-#define DMF_FROZEN 2
-#define DMF_FREEING 3
-#define DMF_DELETING 4
-#define DMF_NOFLUSH_SUSPENDING 5
-#define DMF_DEFERRED_REMOVE 6
-#define DMF_SUSPENDED_INTERNALLY 7
-#define DMF_POST_SUSPENDING 8
-
 #define DM_NUMA_NODE NUMA_NO_NODE
 static int dm_numa_node = DM_NUMA_NODE;
 
@@ -825,7 +780,7 @@ static int __noflush_suspending(struct mapped_device *md)
  * Decrements the number of outstanding ios that a bio has been
  * cloned into, completing the original io if necc.
  */
-static void dec_pending(struct dm_io *io, blk_status_t error)
+void dm_io_dec_pending(struct dm_io *io, blk_status_t error)
 {
unsigned long flags;
blk_status_t io_error;
@@ -978,7 +933,7 @@ static void clone_endio(struct bio *bio)
}
 
free_tio(tio);
-   dec_pending(io, error);
+   dm_io_dec_pending(io, error);
 }
 
 /*
@@ -1247,7 +1202,7 @@ static blk_qc_t __map_bio(struct dm_target_io *tio)
 * anything, the target has assumed ownership of
 * this io.
 */
-   

[dm-devel] [PATCH v3 10/11] dm: introduce zone append emulation

2021-05-20 Thread Damien Le Moal
For zoned targets that cannot support zone append operations, implement
an emulation using regular write operations. If the original BIO
submitted by the user is a zone append operation, change its clone into
a regular write operation directed at the target zone write pointer
position.

To do so, an array of write pointer offsets (write pointer position
relative to the start of a zone) is added to struct mapped_device. All
operations that modify a sequential zone write pointer (writes, zone
reset, zone finish and zone append) are intersepted in __map_bio() and
processed using the new functions dm_zone_map_bio().

Detection of the target ability to natively support zone append
operations is done from dm_table_set_restrictions() by calling the
function dm_set_zones_restrictions(). A target that does not support
zone append operation, either by explicitly declaring it using the new
struct dm_target field zone_append_not_supported, or because the device
table contains a non-zoned device, has its mapped device marked with the
new flag DMF_ZONE_APPEND_EMULATED. The helper function
dm_emulate_zone_append() is introduced to test a mapped device for this
new flag.

Atomicity of the zones write pointer tracking and updates is done using
a zone write locking mechanism based on a bitmap. This is similar to
the block layer method but based on BIOs rather than struct request.
A zone write lock is taken in dm_zone_map_bio() for any clone BIO with
an operation type that changes the BIO target zone write pointer
position. The zone write lock is released if the clone BIO is failed
before submission or when dm_zone_endio() is called when the clone BIO
completes.

The zone write lock bitmap of the mapped device, together with a bitmap
indicating zone types (conv_zones_bitmap) and the write pointer offset
array (zwp_offset) are allocated and initialized with a full device zone
report in dm_set_zones_restrictions() using the function
dm_revalidate_zones().

For failed operations that may have modified a zone write pointer, the
zone write pointer offset is marked as invalid in dm_zone_endio().
Zones with an invalid write pointer offset are checked and the write
pointer updated using an internal report zone operation when the
faulty zone is accessed again by the user.

All functions added for this emulation have a minimal overhead for
zoned targets natively supporting zone append operations. Regular
device targets are also not affected. The added code also does not
impact builds with CONFIG_BLK_DEV_ZONED disabled by stubbing out all
dm zone related functions.

Signed-off-by: Damien Le Moal 
---
 drivers/md/dm-core.h  |  13 +
 drivers/md/dm-table.c |  19 +-
 drivers/md/dm-zone.c  | 580 --
 drivers/md/dm.c   |  38 ++-
 drivers/md/dm.h   |  16 +-
 include/linux/device-mapper.h |   6 +
 6 files changed, 618 insertions(+), 54 deletions(-)

diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h
index cfabc1c91f9f..edc1553c4eea 100644
--- a/drivers/md/dm-core.h
+++ b/drivers/md/dm-core.h
@@ -114,6 +114,11 @@ struct mapped_device {
bool init_tio_pdu:1;
 
struct srcu_struct io_barrier;
+
+#ifdef CONFIG_BLK_DEV_ZONED
+   unsigned int nr_zones;
+   unsigned int *zwp_offset;
+#endif
 };
 
 /*
@@ -128,6 +133,7 @@ struct mapped_device {
 #define DMF_DEFERRED_REMOVE 6
 #define DMF_SUSPENDED_INTERNALLY 7
 #define DMF_POST_SUSPENDING 8
+#define DMF_EMULATE_ZONE_APPEND 9
 
 void disable_discard(struct mapped_device *md);
 void disable_write_same(struct mapped_device *md);
@@ -143,6 +149,13 @@ static inline struct dm_stats *dm_get_stats(struct 
mapped_device *md)
return >stats;
 }
 
+static inline bool dm_emulate_zone_append(struct mapped_device *md)
+{
+   if (blk_queue_is_zoned(md->queue))
+   return test_bit(DMF_EMULATE_ZONE_APPEND, >flags);
+   return false;
+}
+
 #define DM_TABLE_MAX_DEPTH 16
 
 struct dm_table {
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index dd9f648ab598..21fdccfb16cf 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -1981,11 +1981,12 @@ static int device_requires_stable_pages(struct 
dm_target *ti,
return blk_queue_stable_writes(q);
 }
 
-void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
-  struct queue_limits *limits)
+int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
+ struct queue_limits *limits)
 {
bool wc = false, fua = false;
int page_size = PAGE_SIZE;
+   int r;
 
/*
 * Copy table's limits to the DM device's request_queue
@@ -2064,12 +2065,20 @@ void dm_table_set_restrictions(struct dm_table *t, 
struct request_queue *q,
dm_table_any_dev_attr(t, device_is_not_random, NULL))
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
 
-   /* For a zoned target, setup the zones related 

[dm-devel] [PATCH v3 01/11] block: improve handling of all zones reset operation

2021-05-20 Thread Damien Le Moal
SCSI, ZNS and null_blk zoned devices support resetting all zones using
a single command (REQ_OP_ZONE_RESET_ALL), as indicated using the device
request queue flag QUEUE_FLAG_ZONE_RESETALL. This flag is not set for
device mapper targets creating zoned devices. In this case, a user
request for resetting all zones of a device is processed in
blkdev_zone_mgmt() by issuing a REQ_OP_ZONE_RESET operation for each
zone of the device. This leads to different behaviors of the
BLKRESETZONE ioctl() depending on the target device support for the
reset all operation. E.g.

blkzone reset /dev/sdX

will reset all zones of a SCSI device using a single command that will
ignore conventional, read-only or offline zones.

But a dm-linear device including conventional, read-only or offline
zones cannot be reset in the same manner as some of the single zone
reset operations issued by blkdev_zone_mgmt() will fail. E.g.:

blkzone reset /dev/dm-Y
blkzone: /dev/dm-0: BLKRESETZONE ioctl failed: Remote I/O error

To simplify applications and tools development, unify the behavior of
the all-zone reset operation by modifying blkdev_zone_mgmt() to not
issue a zone reset operation for conventional, read-only and offline
zones, thus mimicking what an actual reset-all device command does on a
device supporting REQ_OP_ZONE_RESET_ALL. This emulation is done using
the new function blkdev_zone_reset_all_emulated(). The zones needing a
reset are identified using a bitmap that is initialized using a zone
report. Since empty zones do not need a reset, also ignore these zones.
The function blkdev_zone_reset_all() is introduced for block devices
natively supporting reset all operations. blkdev_zone_mgmt() is modified
to call either function to execute an all zone reset request.

Signed-off-by: Damien Le Moal 
[hch: split into multiple functions]
Signed-off-by: Christoph Hellwig 
Reviewed-by: Hannes Reinecke 
---
 block/blk-zoned.c | 117 +++---
 1 file changed, 90 insertions(+), 27 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 250cb76ee615..0ded16b0f713 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -161,18 +161,87 @@ int blkdev_report_zones(struct block_device *bdev, 
sector_t sector,
 }
 EXPORT_SYMBOL_GPL(blkdev_report_zones);
 
-static inline bool blkdev_allow_reset_all_zones(struct block_device *bdev,
-   sector_t sector,
-   sector_t nr_sectors)
+static inline unsigned long *blk_alloc_zone_bitmap(int node,
+  unsigned int nr_zones)
 {
-   if (!blk_queue_zone_resetall(bdev_get_queue(bdev)))
-   return false;
+   return kcalloc_node(BITS_TO_LONGS(nr_zones), sizeof(unsigned long),
+   GFP_NOIO, node);
+}
 
+static int blk_zone_need_reset_cb(struct blk_zone *zone, unsigned int idx,
+ void *data)
+{
/*
-* REQ_OP_ZONE_RESET_ALL can be executed only if the number of sectors
-* of the applicable zone range is the entire disk.
+* For an all-zones reset, ignore conventional, empty, read-only
+* and offline zones.
 */
-   return !sector && nr_sectors == get_capacity(bdev->bd_disk);
+   switch (zone->cond) {
+   case BLK_ZONE_COND_NOT_WP:
+   case BLK_ZONE_COND_EMPTY:
+   case BLK_ZONE_COND_READONLY:
+   case BLK_ZONE_COND_OFFLINE:
+   return 0;
+   default:
+   set_bit(idx, (unsigned long *)data);
+   return 0;
+   }
+}
+
+static int blkdev_zone_reset_all_emulated(struct block_device *bdev,
+ gfp_t gfp_mask)
+{
+   struct request_queue *q = bdev_get_queue(bdev);
+   sector_t capacity = get_capacity(bdev->bd_disk);
+   sector_t zone_sectors = blk_queue_zone_sectors(q);
+   unsigned long *need_reset;
+   struct bio *bio = NULL;
+   sector_t sector;
+   int ret;
+
+   need_reset = blk_alloc_zone_bitmap(q->node, q->nr_zones);
+   if (!need_reset)
+   return -ENOMEM;
+
+   ret = bdev->bd_disk->fops->report_zones(bdev->bd_disk, 0,
+   q->nr_zones, blk_zone_need_reset_cb,
+   need_reset);
+   if (ret < 0)
+   goto out_free_need_reset;
+
+   ret = 0;
+   while (sector < capacity) {
+   if (!test_bit(blk_queue_zone_no(q, sector), need_reset)) {
+   sector += zone_sectors;
+   continue;
+   }
+   bio = blk_next_bio(bio, 0, gfp_mask);
+   bio_set_dev(bio, bdev);
+   bio->bi_opf = REQ_OP_ZONE_RESET | REQ_SYNC;
+   bio->bi_iter.bi_sector = sector;
+   sector += zone_sectors;
+
+   /* This may take a while, so be nice to others */
+   cond_resched();
+   }

[dm-devel] [PATCH v3 02/11] block: introduce bio zone helpers

2021-05-20 Thread Damien Le Moal
Introduce the helper functions bio_zone_no() and bio_zone_is_seq().
Both are the BIO counterparts of the request helpers blk_rq_zone_no()
and blk_rq_zone_is_seq(), respectively returning the number of the
target zone of a bio and true if the BIO target zone is sequential.

Signed-off-by: Damien Le Moal 
Reviewed-by: Hannes Reinecke 
---
 include/linux/blkdev.h | 12 
 1 file changed, 12 insertions(+)

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index f69c75bd6d27..2db0f376f5d9 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1008,6 +1008,18 @@ static inline unsigned int blk_rq_stats_sectors(const 
struct request *rq)
 /* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
 const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
 
+static inline unsigned int bio_zone_no(struct bio *bio)
+{
+   return blk_queue_zone_no(bdev_get_queue(bio->bi_bdev),
+bio->bi_iter.bi_sector);
+}
+
+static inline unsigned int bio_zone_is_seq(struct bio *bio)
+{
+   return blk_queue_zone_is_seq(bdev_get_queue(bio->bi_bdev),
+bio->bi_iter.bi_sector);
+}
+
 static inline unsigned int blk_rq_zone_no(struct request *rq)
 {
return blk_queue_zone_no(rq->q, blk_rq_pos(rq));
-- 
2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH v3 07/11] dm: Introduce dm_report_zones()

2021-05-20 Thread Damien Le Moal
To simplify the implementation of the report_zones operation of a zoned
target, introduce the function dm_report_zones() to set a target
mapping start sector in struct dm_report_zones_args and call
blkdev_report_zones(). This new function is exported and the report
zones callback function dm_report_zones_cb() is not.

dm-linear, dm-flakey and dm-crypt are modified to use dm_report_zones().

Signed-off-by: Damien Le Moal 
Reviewed-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/md/dm-crypt.c |  7 +++
 drivers/md/dm-flakey.c|  7 +++
 drivers/md/dm-linear.c|  7 +++
 drivers/md/dm-zone.c  | 23 ---
 include/linux/device-mapper.h |  3 ++-
 5 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index b0ab080f2567..f410ceee51d7 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -3138,11 +3138,10 @@ static int crypt_report_zones(struct dm_target *ti,
struct dm_report_zones_args *args, unsigned int nr_zones)
 {
struct crypt_config *cc = ti->private;
-   sector_t sector = cc->start + dm_target_offset(ti, args->next_sector);
 
-   args->start = cc->start;
-   return blkdev_report_zones(cc->dev->bdev, sector, nr_zones,
-  dm_report_zones_cb, args);
+   return dm_report_zones(cc->dev->bdev, cc->start,
+   cc->start + dm_target_offset(ti, args->next_sector),
+   args, nr_zones);
 }
 #else
 #define crypt_report_zones NULL
diff --git a/drivers/md/dm-flakey.c b/drivers/md/dm-flakey.c
index b7fee9936f05..5877220c01ed 100644
--- a/drivers/md/dm-flakey.c
+++ b/drivers/md/dm-flakey.c
@@ -463,11 +463,10 @@ static int flakey_report_zones(struct dm_target *ti,
struct dm_report_zones_args *args, unsigned int nr_zones)
 {
struct flakey_c *fc = ti->private;
-   sector_t sector = flakey_map_sector(ti, args->next_sector);
 
-   args->start = fc->start;
-   return blkdev_report_zones(fc->dev->bdev, sector, nr_zones,
-  dm_report_zones_cb, args);
+   return dm_report_zones(fc->dev->bdev, fc->start,
+  flakey_map_sector(ti, args->next_sector),
+  args, nr_zones);
 }
 #else
 #define flakey_report_zones NULL
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 92db0f5e7f28..c91f1e2e2f65 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -140,11 +140,10 @@ static int linear_report_zones(struct dm_target *ti,
struct dm_report_zones_args *args, unsigned int nr_zones)
 {
struct linear_c *lc = ti->private;
-   sector_t sector = linear_map_sector(ti, args->next_sector);
 
-   args->start = lc->start;
-   return blkdev_report_zones(lc->dev->bdev, sector, nr_zones,
-  dm_report_zones_cb, args);
+   return dm_report_zones(lc->dev->bdev, lc->start,
+  linear_map_sector(ti, args->next_sector),
+  args, nr_zones);
 }
 #else
 #define linear_report_zones NULL
diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c
index 3243c42b7951..b42474043249 100644
--- a/drivers/md/dm-zone.c
+++ b/drivers/md/dm-zone.c
@@ -56,7 +56,8 @@ int dm_blk_report_zones(struct gendisk *disk, sector_t sector,
return ret;
 }
 
-int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data)
+static int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx,
+ void *data)
 {
struct dm_report_zones_args *args = data;
sector_t sector_diff = args->tgt->begin - args->start;
@@ -84,7 +85,24 @@ int dm_report_zones_cb(struct blk_zone *zone, unsigned int 
idx, void *data)
args->next_sector = zone->start + zone->len;
return args->orig_cb(zone, args->zone_idx++, args->orig_data);
 }
-EXPORT_SYMBOL_GPL(dm_report_zones_cb);
+
+/*
+ * Helper for drivers of zoned targets to implement struct target_type
+ * report_zones operation.
+ */
+int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector,
+   struct dm_report_zones_args *args, unsigned int nr_zones)
+{
+   /*
+* Set the target mapping start sector first so that
+* dm_report_zones_cb() can correctly remap zone information.
+*/
+   args->start = start;
+
+   return blkdev_report_zones(bdev, sector, nr_zones,
+  dm_report_zones_cb, args);
+}
+EXPORT_SYMBOL_GPL(dm_report_zones);
 
 void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q)
 {
@@ -99,4 +117,3 @@ void dm_set_zones_restrictions(struct dm_table *t, struct 
request_queue *q)
WARN_ON_ONCE(queue_is_mq(q));
q->nr_zones = blkdev_nr_zones(t->md->disk);
 }
-
diff --git a/include/linux/device-mapper.h 

[dm-devel] [PATCH v3 08/11] dm: Forbid requeue of writes to zones

2021-05-20 Thread Damien Le Moal
A target map method requesting the requeue of a bio with
DM_MAPIO_REQUEUE or completing it with DM_ENDIO_REQUEUE can cause
unaligned write errors if the bio is a write operation targeting a
sequential zone. If a zoned target request such a requeue, warn about
it and kill the IO.

The function dm_is_zone_write() is introduced to detect write operations
to zoned targets.

This change does not affect the target drivers supporting zoned devices
and exposing a zoned device, namely dm-crypt, dm-linear and dm-flakey as
none of these targets ever request a requeue.

Signed-off-by: Damien Le Moal 
Reviewed-by: Hannes Reinecke 
---
 drivers/md/dm-zone.c | 17 +
 drivers/md/dm.c  | 18 +++---
 drivers/md/dm.h  |  5 +
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c
index b42474043249..edc3bbb45637 100644
--- a/drivers/md/dm-zone.c
+++ b/drivers/md/dm-zone.c
@@ -104,6 +104,23 @@ int dm_report_zones(struct block_device *bdev, sector_t 
start, sector_t sector,
 }
 EXPORT_SYMBOL_GPL(dm_report_zones);
 
+bool dm_is_zone_write(struct mapped_device *md, struct bio *bio)
+{
+   struct request_queue *q = md->queue;
+
+   if (!blk_queue_is_zoned(q))
+   return false;
+
+   switch (bio_op(bio)) {
+   case REQ_OP_WRITE_ZEROES:
+   case REQ_OP_WRITE_SAME:
+   case REQ_OP_WRITE:
+   return !op_is_flush(bio->bi_opf) && bio_sectors(bio);
+   default:
+   return false;
+   }
+}
+
 void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q)
 {
if (!blk_queue_is_zoned(q))
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 45d2dc2ee844..4426019a89cc 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -846,11 +846,15 @@ static void dec_pending(struct dm_io *io, blk_status_t 
error)
 * Target requested pushing back the I/O.
 */
spin_lock_irqsave(>deferred_lock, flags);
-   if (__noflush_suspending(md))
+   if (__noflush_suspending(md) &&
+   !WARN_ON_ONCE(dm_is_zone_write(md, bio)))
/* NOTE early return due to BLK_STS_DM_REQUEUE 
below */
bio_list_add_head(>deferred, io->orig_bio);
else
-   /* noflush suspend was interrupted. */
+   /*
+* noflush suspend was interrupted or this is
+* a write to a zoned target.
+*/
io->status = BLK_STS_IOERR;
spin_unlock_irqrestore(>deferred_lock, flags);
}
@@ -947,7 +951,15 @@ static void clone_endio(struct bio *bio)
int r = endio(tio->ti, bio, );
switch (r) {
case DM_ENDIO_REQUEUE:
-   error = BLK_STS_DM_REQUEUE;
+   /*
+* Requeuing writes to a sequential zone of a zoned
+* target will break the sequential write pattern:
+* fail such IO.
+*/
+   if (WARN_ON_ONCE(dm_is_zone_write(md, bio)))
+   error = BLK_STS_IOERR;
+   else
+   error = BLK_STS_DM_REQUEUE;
fallthrough;
case DM_ENDIO_DONE:
break;
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index fdf1536a4b62..39c243258e24 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -107,8 +107,13 @@ void dm_set_zones_restrictions(struct dm_table *t, struct 
request_queue *q);
 #ifdef CONFIG_BLK_DEV_ZONED
 int dm_blk_report_zones(struct gendisk *disk, sector_t sector,
unsigned int nr_zones, report_zones_cb cb, void *data);
+bool dm_is_zone_write(struct mapped_device *md, struct bio *bio);
 #else
 #define dm_blk_report_zonesNULL
+static inline bool dm_is_zone_write(struct mapped_device *md, struct bio *bio)
+{
+   return false;
+}
 #endif
 
 /*-
-- 
2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH v3 00/11] dm: Improve zoned block device support

2021-05-20 Thread Damien Le Moal
This series improve device mapper support for zoned block devices and
of targets exposing a zoned device.

The first patch improve support for user requests to reset all zones of
the target device. With the fix, such operation behave similarly to
physical block devices implementation based on the single zone reset
command with the ALL bit set.

The following 2 patches are preparatory block layer patches.

Patch 4 and 5 are 2 small fixes to DM core zoned block device support.

Patch 6 reorganizes DM core code, moving conditionally defined zoned
block device code into the new dm-zone.c file. This avoids sprinkly DM
with zone related code defined under an #ifdef CONFIG_BLK_DEV_ZONED.

Patch 7 improves DM zone report helper functions for target drivers.

Patch 8 fixes a potential problem with BIO requeue on zoned target.

Finally, patch 9 to 11 implement zone append emulation using regular
writes for target drivers that cannot natively support this BIO type.
The only target currently needing this emulation is dm-crypt. With this
change, a zoned dm-crypt device behaves exactly like a regular zoned
block device, correctly executing user zone append BIOs.

This series passes the following tests:
1) zonefs tests on top of dm-crypt with a zoned nullblk device
2) zonefs tests on top of dm-crypt+dm-linear with an SMR HDD
3) btrfs fstests on top of dm-crypt with zoned nullblk devices.

Comments are as always welcome.

Changes from v2:
* Replace use of spinlock to protect the zone write pointer offset
  array in patch 11 with READ_ONCE/WRITE_ONCE as suggested by Hannes.
* Added reviewed-by tags

Changes from v1:
* Use Christoph proposed approach for patch 1 (split reset all
  processing into different functions)
* Changed helpers introduced in patch 2 to remove the request_queue
  argument
* Improve patch 3 commit message as suggested by Christoph (explaining
  that the flag is a special case that cannot use a REQ_XXX flag)
* Changed DMWARN() into DMDEBUG in patch 11 as suggested by Milan
* Added reviewed-by tags

Damien Le Moal (11):
  block: improve handling of all zones reset operation
  block: introduce bio zone helpers
  block: introduce BIO_ZONE_WRITE_LOCKED bio flag
  dm: Fix dm_accept_partial_bio()
  dm: cleanup device_area_is_invalid()
  dm: move zone related code to dm-zone.c
  dm: Introduce dm_report_zones()
  dm: Forbid requeue of writes to zones
  dm: rearrange core declarations
  dm: introduce zone append emulation
  dm crypt: Fix zoned block device support

 block/blk-zoned.c | 117 --
 drivers/md/Makefile   |   4 +
 drivers/md/dm-core.h  |  65 
 drivers/md/dm-crypt.c |  31 +-
 drivers/md/dm-flakey.c|   7 +-
 drivers/md/dm-linear.c|   7 +-
 drivers/md/dm-table.c |  21 +-
 drivers/md/dm-zone.c  | 654 ++
 drivers/md/dm.c   | 202 +++
 drivers/md/dm.h   |  30 +-
 include/linux/blk_types.h |   1 +
 include/linux/blkdev.h|  12 +
 include/linux/device-mapper.h |   9 +-
 13 files changed, 953 insertions(+), 207 deletions(-)
 create mode 100644 drivers/md/dm-zone.c

-- 
2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH v3 06/11] dm: move zone related code to dm-zone.c

2021-05-20 Thread Damien Le Moal
Move core and table code used for zoned targets and conditionally
defined with #ifdef CONFIG_BLK_DEV_ZONED to the new file dm-zone.c.
This file is conditionally compiled depending on CONFIG_BLK_DEV_ZONED.
The small helper dm_set_zones_restrictions() is introduced to
initialize a mapped device request queue zone attributes in
dm_table_set_restrictions().

Signed-off-by: Damien Le Moal 
Reviewed-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/md/Makefile   |   4 ++
 drivers/md/dm-table.c |  14 ++
 drivers/md/dm-zone.c  | 102 ++
 drivers/md/dm.c   |  78 
 drivers/md/dm.h   |  11 +
 5 files changed, 120 insertions(+), 89 deletions(-)
 create mode 100644 drivers/md/dm-zone.c

diff --git a/drivers/md/Makefile b/drivers/md/Makefile
index ef7ddc27685c..a74aaf8b1445 100644
--- a/drivers/md/Makefile
+++ b/drivers/md/Makefile
@@ -92,6 +92,10 @@ ifeq ($(CONFIG_DM_UEVENT),y)
 dm-mod-objs+= dm-uevent.o
 endif
 
+ifeq ($(CONFIG_BLK_DEV_ZONED),y)
+dm-mod-objs+= dm-zone.o
+endif
+
 ifeq ($(CONFIG_DM_VERITY_FEC),y)
 dm-verity-objs += dm-verity-fec.o
 endif
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 21fd9cd4da32..dd9f648ab598 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -2064,17 +2064,9 @@ void dm_table_set_restrictions(struct dm_table *t, 
struct request_queue *q,
dm_table_any_dev_attr(t, device_is_not_random, NULL))
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
 
-   /*
-* For a zoned target, the number of zones should be updated for the
-* correct value to be exposed in sysfs queue/nr_zones. For a BIO based
-* target, this is all that is needed.
-*/
-#ifdef CONFIG_BLK_DEV_ZONED
-   if (blk_queue_is_zoned(q)) {
-   WARN_ON_ONCE(queue_is_mq(q));
-   q->nr_zones = blkdev_nr_zones(t->md->disk);
-   }
-#endif
+   /* For a zoned target, setup the zones related queue attributes */
+   if (blk_queue_is_zoned(q))
+   dm_set_zones_restrictions(t, q);
 
dm_update_keyslot_manager(q, t);
blk_queue_update_readahead(q);
diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c
new file mode 100644
index ..3243c42b7951
--- /dev/null
+++ b/drivers/md/dm-zone.c
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 Western Digital Corporation or its affiliates.
+ */
+
+#include 
+
+#include "dm-core.h"
+
+/*
+ * User facing dm device block device report zone operation. This calls the
+ * report_zones operation for each target of a device table. This operation is
+ * generally implemented by targets using dm_report_zones().
+ */
+int dm_blk_report_zones(struct gendisk *disk, sector_t sector,
+   unsigned int nr_zones, report_zones_cb cb, void *data)
+{
+   struct mapped_device *md = disk->private_data;
+   struct dm_table *map;
+   int srcu_idx, ret;
+   struct dm_report_zones_args args = {
+   .next_sector = sector,
+   .orig_data = data,
+   .orig_cb = cb,
+   };
+
+   if (dm_suspended_md(md))
+   return -EAGAIN;
+
+   map = dm_get_live_table(md, _idx);
+   if (!map) {
+   ret = -EIO;
+   goto out;
+   }
+
+   do {
+   struct dm_target *tgt;
+
+   tgt = dm_table_find_target(map, args.next_sector);
+   if (WARN_ON_ONCE(!tgt->type->report_zones)) {
+   ret = -EIO;
+   goto out;
+   }
+
+   args.tgt = tgt;
+   ret = tgt->type->report_zones(tgt, ,
+ nr_zones - args.zone_idx);
+   if (ret < 0)
+   goto out;
+   } while (args.zone_idx < nr_zones &&
+args.next_sector < get_capacity(disk));
+
+   ret = args.zone_idx;
+out:
+   dm_put_live_table(md, srcu_idx);
+   return ret;
+}
+
+int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data)
+{
+   struct dm_report_zones_args *args = data;
+   sector_t sector_diff = args->tgt->begin - args->start;
+
+   /*
+* Ignore zones beyond the target range.
+*/
+   if (zone->start >= args->start + args->tgt->len)
+   return 0;
+
+   /*
+* Remap the start sector and write pointer position of the zone
+* to match its position in the target range.
+*/
+   zone->start += sector_diff;
+   if (zone->type != BLK_ZONE_TYPE_CONVENTIONAL) {
+   if (zone->cond == BLK_ZONE_COND_FULL)
+   zone->wp = zone->start + zone->len;
+   else if (zone->cond == BLK_ZONE_COND_EMPTY)
+   zone->wp = zone->start;
+   else
+   

[dm-devel] [PATCH v3 03/11] block: introduce BIO_ZONE_WRITE_LOCKED bio flag

2021-05-20 Thread Damien Le Moal
Introduce the BIO flag BIO_ZONE_WRITE_LOCKED to indicate that a BIO owns
the write lock of the zone it is targeting. This is the counterpart of
the struct request flag RQF_ZONE_WRITE_LOCKED.

This new BIO flag is reserved for now for zone write locking control
for device mapper targets exposing a zoned block device. Since in this
case, the lock flag must not be propagated to the struct request that
will be used to process the BIO, a BIO private flag is used rather than
changing the RQF_ZONE_WRITE_LOCKED request flag into a common REQ_XXX
flag that could be used for both BIO and request. This avoids conflicts
down the stack with the block IO scheduler zone write locking
(in mq-deadline).

Signed-off-by: Damien Le Moal 
Reviewed-by: Christoph Hellwig 
Reviewed-by: Hannes Reinecke 
---
 include/linux/blk_types.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index db026b6ec15a..e5cf12f102a2 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -304,6 +304,7 @@ enum {
BIO_CGROUP_ACCT,/* has been accounted to a cgroup */
BIO_TRACKED,/* set if bio goes through the rq_qos path */
BIO_REMAPPED,
+   BIO_ZONE_WRITE_LOCKED,  /* Owns a zoned device zone write lock */
BIO_FLAG_LAST
 };
 
-- 
2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [git pull] device mapper fixes for 5.13-rc3

2021-05-20 Thread pr-tracker-bot
The pull request you sent on Thu, 20 May 2021 15:45:46 -0400:

> git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git 
> tags/for-5.13/dm-fixes

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/a0eb553b6ff650faa031a470d048555b0b80a309

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/prtracker.html

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH] libmultipath: fix build without LIBDM_API_DEFERRED

2021-05-20 Thread mwilck
From: Martin Wilck 

Build fails on distributions that don't support DM_DEFERRED_REMOVE
(libdevmapper < 1.02.89). Fix it.

Resolves: https://github.com/opensvc/multipath-tools/issues/7
Tested-by: Paul Menzel 
---
 libmultipath/devmapper.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 095cbc0..47a6d60 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -49,6 +49,9 @@ static int dm_conf_verbosity;
 
 #ifdef LIBDM_API_DEFERRED
 static int dm_cancel_remove_partmaps(const char * mapname);
+#define __DR_UNUSED__ /* empty */
+#else
+#define __DR_UNUSED__ __attribute__((unused))
 #endif
 
 static int do_foreach_partmaps(const char * mapname,
@@ -384,7 +387,8 @@ libmp_dm_task_create(int task)
 #define do_deferred(x) ((x) == DEFERRED_REMOVE_ON || (x) == 
DEFERRED_REMOVE_IN_PROGRESS)
 
 static int
-dm_simplecmd (int task, const char *name, int no_flush, int need_sync, 
uint16_t udev_flags, int deferred_remove) {
+dm_simplecmd (int task, const char *name, int no_flush, int need_sync,
+ uint16_t udev_flags, int deferred_remove __DR_UNUSED__) {
int r = 0;
int udev_wait_flag = ((need_sync || udev_flags) &&
  (task == DM_DEVICE_RESUME ||
@@ -1122,7 +1126,8 @@ dm_flush_map_nopaths(const char * mapname, int 
deferred_remove)
 #else
 
 int
-dm_flush_map_nopaths(const char * mapname, int deferred_remove)
+dm_flush_map_nopaths(const char * mapname,
+int deferred_remove __attribute__((unused)))
 {
return _dm_flush_map(mapname, 1, 0, 0, 0);
 }
@@ -1573,7 +1578,7 @@ dm_cancel_deferred_remove (struct multipath *mpp)
 #else
 
 int
-dm_cancel_deferred_remove (struct multipath *mpp)
+dm_cancel_deferred_remove (struct multipath *mpp __attribute__((unused)))
 {
return 0;
 }
-- 
2.31.1


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [git pull] device mapper fixes for 5.13-rc3

2021-05-20 Thread Mike Snitzer
Hi Linus,

The following changes since commit 6efb943b8616ec53a5e444193dccf1af9ad627b5:

  Linux 5.13-rc1 (2021-05-09 14:17:44 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git 
tags/for-5.13/dm-fixes

for you to fetch changes up to bc8f3d4647a99468d7733039b6bc9234b6e91df4:

  dm integrity: fix sparse warnings (2021-05-13 14:53:49 -0400)

Please pull, thanks.
Mike


- Fix a couple DM snapshot target crashes exposed by user-error.

- Fix DM integrity target to not use discard optimization, introduced
  during 5.13 merge, when recalulating.

- Fix some sparse warnings in DM integrity target.


Mikulas Patocka (4):
  dm snapshot: fix a crash when an origin has no snapshots
  dm snapshot: fix crash with transient storage and zero chunk size
  dm integrity: revert to not using discard filler when recalulating
  dm integrity: fix sparse warnings

 drivers/md/dm-integrity.c | 81 +--
 drivers/md/dm-snap.c  |  6 ++--
 2 files changed, 39 insertions(+), 48 deletions(-)

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [dm:for-next 5/8] drivers/md/persistent-data/dm-btree.c:702:5: warning: no previous prototype for function 'shadow_child'

2021-05-20 Thread kernel test robot
tree:   
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git 
for-next
head:   68040817337fda98196974401391f2d1b9f87e49
commit: d69e2e7e28bd1d13ad2ac1f2e9ea6184567d1587 [5/8] dm btree: improve btree 
residency
config: x86_64-randconfig-a013-20210520 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 
bf9ef3efaa99c02e7bfc4c57207301b8de39a278)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# 
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?id=d69e2e7e28bd1d13ad2ac1f2e9ea6184567d1587
git remote add dm 
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git
git fetch --no-tags dm for-next
git checkout d69e2e7e28bd1d13ad2ac1f2e9ea6184567d1587
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

>> drivers/md/persistent-data/dm-btree.c:702:5: warning: no previous prototype 
>> for function 'shadow_child' [-Wmissing-prototypes]
   int shadow_child(struct dm_btree_info *info, struct dm_btree_value_type *vt,
   ^
   drivers/md/persistent-data/dm-btree.c:702:1: note: declare 'static' if the 
function is not intended to be used outside of this translation unit
   int shadow_child(struct dm_btree_info *info, struct dm_btree_value_type *vt,
   ^
   static 
   1 warning generated.


vim +/shadow_child +702 drivers/md/persistent-data/dm-btree.c

   696  
   697  /*
   698   * We often need to modify a sibling node.  This function shadows a 
particular
   699   * child of the given parent node.  Making sure to update the parent to 
point
   700   * to the new shadow.
   701   */
 > 702  int shadow_child(struct dm_btree_info *info, struct dm_btree_value_type 
 > *vt,
   703   struct btree_node *parent, unsigned index, struct 
dm_block **result)
   704  {
   705  int r, inc;
   706  dm_block_t root;
   707  struct btree_node *node;
   708  
   709  root = value64(parent, index);
   710  
   711  r = dm_tm_shadow_block(info->tm, root, _node_validator,
   712 result, );
   713  if (r)
   714  return r;
   715  
   716  node = dm_block_data(*result);
   717  
   718  if (inc)
   719  inc_children(info->tm, node, vt);
   720  
   721  *((__le64 *) value_ptr(parent, index)) =
   722  cpu_to_le64(dm_block_location(*result));
   723  
   724  return 0;
   725  }
   726  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

[dm-devel] [dm:for-next 7/8] include/uapi/linux/byteorder/little_endian.h:32:42: warning: cast from pointer to integer of different size

2021-05-20 Thread kernel test robot
tree:   
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git 
for-next
head:   68040817337fda98196974401391f2d1b9f87e49
commit: def6a7a9a7f0e7e3886fb77cf45c4a48e7e71c36 [7/8] dm space maps: improve 
performance with inc/dec on ranges of blocks
config: i386-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# 
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?id=def6a7a9a7f0e7e3886fb77cf45c4a48e7e71c36
git remote add dm 
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git
git fetch --no-tags dm for-next
git checkout def6a7a9a7f0e7e3886fb77cf45c4a48e7e71c36
# save the attached .config to linux build tree
make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

   In file included from include/linux/byteorder/little_endian.h:5,
from arch/x86/include/uapi/asm/byteorder.h:5,
from include/asm-generic/bitops/le.h:7,
from arch/x86/include/asm/bitops.h:395,
from include/linux/bitops.h:32,
from include/linux/kernel.h:12,
from arch/x86/include/asm/percpu.h:27,
from arch/x86/include/asm/current.h:6,
from include/linux/sched.h:12,
from include/linux/blkdev.h:5,
from drivers/md/persistent-data/dm-block-manager.h:11,
from drivers/md/persistent-data/dm-btree.h:9,
from drivers/md/persistent-data/dm-array.h:9,
from drivers/md/persistent-data/dm-array.c:7:
   drivers/md/persistent-data/dm-array.c: In function 'block_inc':
>> include/uapi/linux/byteorder/little_endian.h:32:42: warning: cast from 
>> pointer to integer of different size [-Wpointer-to-int-cast]
  32 | #define __le64_to_cpu(x) ((__force __u64)(__le64)(x))
 |  ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro 
'__le64_to_cpu'
  87 | #define le64_to_cpu __le64_to_cpu
 | ^
   drivers/md/persistent-data/dm-array.c:578:34: note: in expansion of macro 
'le64_to_cpu'
 578 |   dm_tm_inc(info->btree_info.tm, le64_to_cpu(block_le));
 |  ^~~


vim +32 include/uapi/linux/byteorder/little_endian.h

5921e6f8809b161 David Howells 2012-10-13  14  
5921e6f8809b161 David Howells 2012-10-13  15  #define __constant_htonl(x) 
((__force __be32)___constant_swab32((x)))
5921e6f8809b161 David Howells 2012-10-13  16  #define __constant_ntohl(x) 
___constant_swab32((__force __be32)(x))
5921e6f8809b161 David Howells 2012-10-13  17  #define __constant_htons(x) 
((__force __be16)___constant_swab16((x)))
5921e6f8809b161 David Howells 2012-10-13  18  #define __constant_ntohs(x) 
___constant_swab16((__force __be16)(x))
5921e6f8809b161 David Howells 2012-10-13  19  #define __constant_cpu_to_le64(x) 
((__force __le64)(__u64)(x))
5921e6f8809b161 David Howells 2012-10-13  20  #define __constant_le64_to_cpu(x) 
((__force __u64)(__le64)(x))
5921e6f8809b161 David Howells 2012-10-13  21  #define __constant_cpu_to_le32(x) 
((__force __le32)(__u32)(x))
5921e6f8809b161 David Howells 2012-10-13  22  #define __constant_le32_to_cpu(x) 
((__force __u32)(__le32)(x))
5921e6f8809b161 David Howells 2012-10-13  23  #define __constant_cpu_to_le16(x) 
((__force __le16)(__u16)(x))
5921e6f8809b161 David Howells 2012-10-13  24  #define __constant_le16_to_cpu(x) 
((__force __u16)(__le16)(x))
5921e6f8809b161 David Howells 2012-10-13  25  #define __constant_cpu_to_be64(x) 
((__force __be64)___constant_swab64((x)))
5921e6f8809b161 David Howells 2012-10-13  26  #define __constant_be64_to_cpu(x) 
___constant_swab64((__force __u64)(__be64)(x))
5921e6f8809b161 David Howells 2012-10-13  27  #define __constant_cpu_to_be32(x) 
((__force __be32)___constant_swab32((x)))
5921e6f8809b161 David Howells 2012-10-13  28  #define __constant_be32_to_cpu(x) 
___constant_swab32((__force __u32)(__be32)(x))
5921e6f8809b161 David Howells 2012-10-13  29  #define __constant_cpu_to_be16(x) 
((__force __be16)___constant_swab16((x)))
5921e6f8809b161 David Howells 2012-10-13  30  #define __constant_be16_to_cpu(x) 
___constant_swab16((__force __u16)(__be16)(x))
5921e6f8809b161 David Howells 2012-10-13  31  #define __cpu_to_le64(x) 
((__force __le64)(__u64)(x))
5921e6f8809b161 David Howells 2012-10-13 @32  #define __le64_to_cpu(x) 
((__force __u64)(__le64)(x))
5921e6f8809b161 David Howells 2012-10-13  33  #define __cpu_to_le32(x) 
((__force __le32)(__u32)(x))
5921e6f8809b161 David Howells 2012-10-13  34  #define __le32_to_cpu(x) 
((__force __u32)(__le32)(x))
5921e6f8809b161 David Howells 2012-10-13  35  #define __cpu_to_le16(x) 
((__force 

[dm-devel] [dm:for-next 5/8] drivers/md/persistent-data/dm-btree.c:702:5: warning: no previous prototype for 'shadow_child'

2021-05-20 Thread kernel test robot
tree:   
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git 
for-next
head:   68040817337fda98196974401391f2d1b9f87e49
commit: d69e2e7e28bd1d13ad2ac1f2e9ea6184567d1587 [5/8] dm btree: improve btree 
residency
config: um-allmodconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# 
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?id=d69e2e7e28bd1d13ad2ac1f2e9ea6184567d1587
git remote add dm 
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git
git fetch --no-tags dm for-next
git checkout d69e2e7e28bd1d13ad2ac1f2e9ea6184567d1587
# save the attached .config to linux build tree
make W=1 ARCH=um 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

>> drivers/md/persistent-data/dm-btree.c:702:5: warning: no previous prototype 
>> for 'shadow_child' [-Wmissing-prototypes]
 702 | int shadow_child(struct dm_btree_info *info, struct 
dm_btree_value_type *vt,
 | ^~~~


vim +/shadow_child +702 drivers/md/persistent-data/dm-btree.c

   696  
   697  /*
   698   * We often need to modify a sibling node.  This function shadows a 
particular
   699   * child of the given parent node.  Making sure to update the parent to 
point
   700   * to the new shadow.
   701   */
 > 702  int shadow_child(struct dm_btree_info *info, struct dm_btree_value_type 
 > *vt,
   703   struct btree_node *parent, unsigned index, struct 
dm_block **result)
   704  {
   705  int r, inc;
   706  dm_block_t root;
   707  struct btree_node *node;
   708  
   709  root = value64(parent, index);
   710  
   711  r = dm_tm_shadow_block(info->tm, root, _node_validator,
   712 result, );
   713  if (r)
   714  return r;
   715  
   716  node = dm_block_data(*result);
   717  
   718  if (inc)
   719  inc_children(info->tm, node, vt);
   720  
   721  *((__le64 *) value_ptr(parent, index)) =
   722  cpu_to_le64(dm_block_location(*result));
   723  
   724  return 0;
   725  }
   726  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

[dm-devel] [dm:for-next 7/8] include/uapi/linux/byteorder/big_endian.h:32:50: warning: cast from pointer to integer of different size

2021-05-20 Thread kernel test robot
tree:   
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git 
for-next
head:   68040817337fda98196974401391f2d1b9f87e49
commit: def6a7a9a7f0e7e3886fb77cf45c4a48e7e71c36 [7/8] dm space maps: improve 
performance with inc/dec on ranges of blocks
config: mips-allyesconfig (attached as .config)
compiler: mips-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?id=def6a7a9a7f0e7e3886fb77cf45c4a48e7e71c36
git remote add dm 
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git
git fetch --no-tags dm for-next
git checkout def6a7a9a7f0e7e3886fb77cf45c4a48e7e71c36
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=mips 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

   In file included from include/linux/swab.h:5,
from include/uapi/linux/byteorder/big_endian.h:13,
from include/linux/byteorder/big_endian.h:5,
from arch/mips/include/uapi/asm/byteorder.h:13,
from arch/mips/include/asm/bitops.h:20,
from include/linux/bitops.h:32,
from include/linux/kernel.h:12,
from include/asm-generic/bug.h:20,
from arch/mips/include/asm/bug.h:42,
from include/linux/bug.h:5,
from include/linux/thread_info.h:12,
from include/asm-generic/current.h:5,
from ./arch/mips/include/generated/asm/current.h:1,
from include/linux/sched.h:12,
from include/linux/blkdev.h:5,
from drivers/md/persistent-data/dm-block-manager.h:11,
from drivers/md/persistent-data/dm-btree.h:9,
from drivers/md/persistent-data/dm-array.h:9,
from drivers/md/persistent-data/dm-array.c:7:
   drivers/md/persistent-data/dm-array.c: In function 'block_inc':
>> include/uapi/linux/byteorder/big_endian.h:32:50: warning: cast from pointer 
>> to integer of different size [-Wpointer-to-int-cast]
  32 | #define __le64_to_cpu(x) __swab64((__force __u64)(__le64)(x))
 |  ^
   include/uapi/linux/swab.h:128:54: note: in definition of macro '__swab64'
 128 | #define __swab64(x) (__u64)__builtin_bswap64((__u64)(x))
 |  ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro 
'__le64_to_cpu'
  87 | #define le64_to_cpu __le64_to_cpu
 | ^
   drivers/md/persistent-data/dm-array.c:578:34: note: in expansion of macro 
'le64_to_cpu'
 578 |   dm_tm_inc(info->btree_info.tm, le64_to_cpu(block_le));
 |  ^~~


vim +32 include/uapi/linux/byteorder/big_endian.h

5921e6f8809b161 David Howells 2012-10-13  14  
5921e6f8809b161 David Howells 2012-10-13  15  #define __constant_htonl(x) 
((__force __be32)(__u32)(x))
5921e6f8809b161 David Howells 2012-10-13  16  #define __constant_ntohl(x) 
((__force __u32)(__be32)(x))
5921e6f8809b161 David Howells 2012-10-13  17  #define __constant_htons(x) 
((__force __be16)(__u16)(x))
5921e6f8809b161 David Howells 2012-10-13  18  #define __constant_ntohs(x) 
((__force __u16)(__be16)(x))
5921e6f8809b161 David Howells 2012-10-13  19  #define __constant_cpu_to_le64(x) 
((__force __le64)___constant_swab64((x)))
5921e6f8809b161 David Howells 2012-10-13  20  #define __constant_le64_to_cpu(x) 
___constant_swab64((__force __u64)(__le64)(x))
5921e6f8809b161 David Howells 2012-10-13  21  #define __constant_cpu_to_le32(x) 
((__force __le32)___constant_swab32((x)))
5921e6f8809b161 David Howells 2012-10-13  22  #define __constant_le32_to_cpu(x) 
___constant_swab32((__force __u32)(__le32)(x))
5921e6f8809b161 David Howells 2012-10-13  23  #define __constant_cpu_to_le16(x) 
((__force __le16)___constant_swab16((x)))
5921e6f8809b161 David Howells 2012-10-13  24  #define __constant_le16_to_cpu(x) 
___constant_swab16((__force __u16)(__le16)(x))
5921e6f8809b161 David Howells 2012-10-13  25  #define __constant_cpu_to_be64(x) 
((__force __be64)(__u64)(x))
5921e6f8809b161 David Howells 2012-10-13  26  #define __constant_be64_to_cpu(x) 
((__force __u64)(__be64)(x))
5921e6f8809b161 David Howells 2012-10-13  27  #define __constant_cpu_to_be32(x) 
((__force __be32)(__u32)(x))
5921e6f8809b161 David Howells 2012-10-13  28  #define __constant_be32_to_cpu(x) 
((__force __u32)(__be32)(x))
5921e6f8809b161 David Howells 2012-10-13  29  #define 

Re: [dm-devel] [PATCH v2 4/4] libdmmp: use KBUILD_BUILD_TIMESTAMP when building man pages

2021-05-20 Thread Benjamin Marzinski
On Mon, May 17, 2021 at 11:27:27PM +0200, mwi...@suse.com wrote:
> From: Martin Wilck 
> 
> Use the latest commit timestamp of the "libdmmp.h" file as
> the timestamp for the man pages. This should avoid spurious rebuilds
> of the documentation.
> 
> Signed-off-by: Martin Wilck 
Reviewed-by: Benjamin Marzinski 
> ---
>  libdmmp/Makefile | 2 ++
>  libdmmp/docs/man/dmmp_context_free.3 | 2 +-
>  libdmmp/docs/man/dmmp_context_log_func_set.3 | 2 +-
>  libdmmp/docs/man/dmmp_context_log_priority_get.3 | 2 +-
>  libdmmp/docs/man/dmmp_context_log_priority_set.3 | 2 +-
>  libdmmp/docs/man/dmmp_context_new.3  | 2 +-
>  libdmmp/docs/man/dmmp_context_timeout_get.3  | 2 +-
>  libdmmp/docs/man/dmmp_context_timeout_set.3  | 2 +-
>  libdmmp/docs/man/dmmp_context_userdata_get.3 | 2 +-
>  libdmmp/docs/man/dmmp_context_userdata_set.3 | 2 +-
>  libdmmp/docs/man/dmmp_flush_mpath.3  | 2 +-
>  libdmmp/docs/man/dmmp_last_error_msg.3   | 2 +-
>  libdmmp/docs/man/dmmp_log_priority_str.3 | 2 +-
>  libdmmp/docs/man/dmmp_mpath_array_free.3 | 2 +-
>  libdmmp/docs/man/dmmp_mpath_array_get.3  | 2 +-
>  libdmmp/docs/man/dmmp_mpath_kdev_name_get.3  | 2 +-
>  libdmmp/docs/man/dmmp_mpath_name_get.3   | 2 +-
>  libdmmp/docs/man/dmmp_mpath_wwid_get.3   | 2 +-
>  libdmmp/docs/man/dmmp_path_array_get.3   | 2 +-
>  libdmmp/docs/man/dmmp_path_blk_name_get.3| 2 +-
>  libdmmp/docs/man/dmmp_path_group_array_get.3 | 2 +-
>  libdmmp/docs/man/dmmp_path_group_id_get.3| 2 +-
>  libdmmp/docs/man/dmmp_path_group_priority_get.3  | 2 +-
>  libdmmp/docs/man/dmmp_path_group_selector_get.3  | 2 +-
>  libdmmp/docs/man/dmmp_path_group_status_get.3| 2 +-
>  libdmmp/docs/man/dmmp_path_group_status_str.3| 2 +-
>  libdmmp/docs/man/dmmp_path_status_get.3  | 2 +-
>  libdmmp/docs/man/dmmp_path_status_str.3  | 2 +-
>  libdmmp/docs/man/dmmp_reconfig.3 | 2 +-
>  libdmmp/docs/man/dmmp_strerror.3 | 2 +-
>  30 files changed, 31 insertions(+), 29 deletions(-)
> 
> diff --git a/libdmmp/Makefile b/libdmmp/Makefile
> index 764a0bc..79b92fb 100644
> --- a/libdmmp/Makefile
> +++ b/libdmmp/Makefile
> @@ -76,6 +76,8 @@ docs/man/%.3.gz:docs/man/%.3
>  docs/man/dmmp_strerror.3:$(HEADERS)
>   TEMPFILE=$(shell mktemp); \
>   cat $^ | perl docs/doc-preclean.pl >$$TEMPFILE; \
> + LC_ALL=C \
> + KBUILD_BUILD_TIMESTAMP=`git log -n1 --pretty=%cd --date=iso -- $^` \
>   perl docs/kernel-doc -man $$TEMPFILE | \
>   perl docs/split-man.pl docs/man; \
>   rm -f $$TEMPFILE
> diff --git a/libdmmp/docs/man/dmmp_context_free.3 
> b/libdmmp/docs/man/dmmp_context_free.3
> index 0d26f42..7c109e1 100644
> --- a/libdmmp/docs/man/dmmp_context_free.3
> +++ b/libdmmp/docs/man/dmmp_context_free.3
> @@ -1,4 +1,4 @@
> -.TH "dmmp_context_free" 3 "dmmp_context_free" "March 2021" "Device Mapper 
> Multipath API - libdmmp Manual" 
> +.TH "dmmp_context_free" 3 "dmmp_context_free" "March 2018" "Device Mapper 
> Multipath API - libdmmp Manual" 
>  .SH NAME
>  dmmp_context_free \- Release the memory of struct dmmp_context.
>  .SH SYNOPSIS
> diff --git a/libdmmp/docs/man/dmmp_context_log_func_set.3 
> b/libdmmp/docs/man/dmmp_context_log_func_set.3
> index 986793d..be311ec 100644
> --- a/libdmmp/docs/man/dmmp_context_log_func_set.3
> +++ b/libdmmp/docs/man/dmmp_context_log_func_set.3
> @@ -1,4 +1,4 @@
> -.TH "dmmp_context_log_func_set" 3 "dmmp_context_log_func_set" "March 2021" 
> "Device Mapper Multipath API - libdmmp Manual" 
> +.TH "dmmp_context_log_func_set" 3 "dmmp_context_log_func_set" "March 2018" 
> "Device Mapper Multipath API - libdmmp Manual" 
>  .SH NAME
>  dmmp_context_log_func_set \- Set log handler function.
>  .SH SYNOPSIS
> diff --git a/libdmmp/docs/man/dmmp_context_log_priority_get.3 
> b/libdmmp/docs/man/dmmp_context_log_priority_get.3
> index 9a273a2..be38301 100644
> --- a/libdmmp/docs/man/dmmp_context_log_priority_get.3
> +++ b/libdmmp/docs/man/dmmp_context_log_priority_get.3
> @@ -1,4 +1,4 @@
> -.TH "dmmp_context_log_priority_get" 3 "dmmp_context_log_priority_get" "March 
> 2021" "Device Mapper Multipath API - libdmmp Manual" 
> +.TH "dmmp_context_log_priority_get" 3 "dmmp_context_log_priority_get" "March 
> 2018" "Device Mapper Multipath API - libdmmp Manual" 
>  .SH NAME
>  dmmp_context_log_priority_get \- Get log priority.
>  .SH SYNOPSIS
> diff --git a/libdmmp/docs/man/dmmp_context_log_priority_set.3 
> b/libdmmp/docs/man/dmmp_context_log_priority_set.3
> index 469c5a4..79e4d2e 100644
> --- a/libdmmp/docs/man/dmmp_context_log_priority_set.3
> +++ b/libdmmp/docs/man/dmmp_context_log_priority_set.3
> @@ -1,4 +1,4 @@
> -.TH "dmmp_context_log_priority_set" 3 "dmmp_context_log_priority_set" "March 
> 2021" "Device Mapper Multipath API - libdmmp Manual" 
> +.TH "dmmp_context_log_priority_set" 3 "dmmp_context_log_priority_set" "March 
> 2018" 

Re: [dm-devel] [PATCH v2 3/4] multipath-tools: enable -Wformat-overflow=2

2021-05-20 Thread Benjamin Marzinski
On Mon, May 17, 2021 at 11:27:26PM +0200, mwi...@suse.com wrote:
> From: Martin Wilck 
> 
> Allow the compiler to catch possible format string overflows.
> Two were found by gcc 10.
> 
> Signed-off-by: Martin Wilck 
Reviewed-by: Benjamin Marzinski 
> ---
>  Makefile.inc | 3 ++-
>  libmultipath/discovery.c | 2 +-
>  libmultipath/print.c | 4 ++--
>  3 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/Makefile.inc b/Makefile.inc
> index f1e2313..91100a2 100644
> --- a/Makefile.inc
> +++ b/Makefile.inc
> @@ -95,9 +95,10 @@ TEST_CC_OPTION = $(shell \
>  STACKPROT := $(call 
> TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
>  ERROR_DISCARDED_QUALIFIERS := $(call 
> TEST_CC_OPTION,-Werror=discarded-qualifiers,)
>  WNOCLOBBERED := $(call TEST_CC_OPTION,-Wno-clobbered -Wno-error=clobbered,)
> +WFORMATOVERFLOW := $(call TEST_CC_OPTION,-Wformat-overflow=2,)
>  
>  OPTFLAGS := -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
> -WARNFLAGS:= -Werror -Wall -Wextra -Wformat=2 -Werror=implicit-int \
> +WARNFLAGS:= -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) 
> -Werror=implicit-int \
> -Werror=implicit-function-declaration -Werror=format-security 
> \
> $(WNOCLOBBERED) -Werror=cast-qual 
> $(ERROR_DISCARDED_QUALIFIERS)
>  CPPFLAGS := -Wp,-D_FORTIFY_SOURCE=2 
> diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
> index ec99a7a..bfe2f56 100644
> --- a/libmultipath/discovery.c
> +++ b/libmultipath/discovery.c
> @@ -635,7 +635,7 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path 
> *pp)
>  {
>   struct udev_device *rport_dev = NULL;
>   char value[16], *eptr;
> - char rport_id[32];
> + char rport_id[42];
>   unsigned int tmo;
>   int ret;
>  
> diff --git a/libmultipath/print.c b/libmultipath/print.c
> index 8151e11..3c69bf4 100644
> --- a/libmultipath/print.c
> +++ b/libmultipath/print.c
> @@ -1,4 +1,4 @@
> -/*
> + /*
>   * Copyright (c) 2005 Christophe Varoqui
>   */
>  #include 
> @@ -594,7 +594,7 @@ int
>  snprint_tgt_wwpn (char * buff, size_t len, const struct path * pp)
>  {
>   struct udev_device *rport_dev = NULL;
> - char rport_id[32];
> + char rport_id[42];
>   const char *value = NULL;
>   int ret;
>  
> -- 
> 2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [PATCH v2 2/4] multipathd: cli_getprkey(): fix return value

2021-05-20 Thread Benjamin Marzinski
On Mon, May 17, 2021 at 11:27:25PM +0200, mwi...@suse.com wrote:
> From: Martin Wilck 
> 
> By setting (*reply)[19] = '\0', we always truncated a possible
> ":aptpl" suffix. Fix it, and use the return value of snprintf()
> as length.
> 
> Signed-off-by: Martin Wilck 
Reviewed-by: Benjamin Marzinski 
> ---
>  multipathd/cli_handlers.c | 17 -
>  1 file changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
> index 9606494..59d44b4 100644
> --- a/multipathd/cli_handlers.c
> +++ b/multipathd/cli_handlers.c
> @@ -1540,7 +1540,7 @@ cli_getprkey(void * v, char ** reply, int * len, void * 
> data)
>   struct multipath * mpp;
>   struct vectors * vecs = (struct vectors *)data;
>   char *mapname = get_keyparam(v, MAP);
> - char *flagstr = "";
> + uint64_t key;
>  
>   mapname = convert_dev(mapname, 0);
>   condlog(3, "%s: get persistent reservation key (operator)", mapname);
> @@ -1553,17 +1553,16 @@ cli_getprkey(void * v, char ** reply, int * len, void 
> * data)
>   if (!*reply)
>   return 1;
>  
> - if (!get_be64(mpp->reservation_key)) {
> + key = get_be64(mpp->reservation_key);
> + if (!key) {
>   sprintf(*reply, "none\n");
> - *len = strlen(*reply) + 1;
> + *len = sizeof("none\n");
>   return 0;
>   }
> - if (mpp->sa_flags & MPATH_F_APTPL_MASK)
> - flagstr = ":aptpl";
> - snprintf(*reply, 26, "0x%" PRIx64 "%s\n",
> -  get_be64(mpp->reservation_key), flagstr);
> - (*reply)[19] = '\0';
> - *len = strlen(*reply) + 1;
> +
> + /* This snprintf() can't overflow - PRIx64 needs max 16 chars */
> + *len = snprintf(*reply, 26, "0x%" PRIx64 "%s\n", key,
> + mpp->sa_flags & MPATH_F_APTPL_MASK ? ":aptpl" : "") + 1;
>   return 0;
>  }
>  
> -- 
> 2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [PATCH v2 1/4] multipathd: cli_handlers: cleanup setting reply length

2021-05-20 Thread Benjamin Marzinski
On Mon, May 17, 2021 at 11:27:24PM +0200, mwi...@suse.com wrote:
> From: Martin Wilck 
> 
> Create a macro for setting the reply length for string literals
> correctly, and use it where necessary.
> 
> In cli_del_path(), don't change the function's return code
> if just the buffer allocation for the reply failed.
> 
> Signed-off-by: Martin Wilck 
Reviewed-by: Benjamin Marzinski 
> ---
>  multipathd/cli_handlers.c | 33 -
>  1 file changed, 12 insertions(+), 21 deletions(-)
> 
> diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
> index 6765fcf..9606494 100644
> --- a/multipathd/cli_handlers.c
> +++ b/multipathd/cli_handlers.c
> @@ -32,6 +32,12 @@
>  #include "foreign.h"
>  #include "cli_handlers.h"
>  
> +#define SET_REPLY_AND_LEN(__rep, __len, string_literal)  
> \
> + do {\
> + *(__rep) = strdup(string_literal);  \
> + *(__len) = *(__rep) ? sizeof(string_literal) : 0;   \
> + } while (0)
> +
>  int
>  show_paths (char ** r, int * len, struct vectors * vecs, char * style,
>   int pretty)
> @@ -802,8 +808,7 @@ cli_add_path (void * v, char ** reply, int * len, void * 
> data)
>   }
>   return ev_add_path(pp, vecs, 1);
>  blacklisted:
> - *reply = strdup("blacklisted\n");
> - *len = strlen(*reply) + 1;
> + SET_REPLY_AND_LEN(reply, len, "blacklisted\n");
>   condlog(2, "%s: path blacklisted", param);
>   return 0;
>  }
> @@ -824,23 +829,10 @@ cli_del_path (void * v, char ** reply, int * len, void 
> * data)
>   return 1;
>   }
>   ret = ev_remove_path(pp, vecs, 1);
> - if (ret == REMOVE_PATH_DELAY) {
> - *reply = strdup("delayed\n");
> - if (*reply)
> - *len = strlen(*reply) + 1;
> - else {
> - *len = 0;
> - ret = REMOVE_PATH_FAILURE;
> - }
> - } else if (ret == REMOVE_PATH_MAP_ERROR) {
> - *reply = strdup("map reload error. removed\n");
> - if (*reply)
> - *len = strlen(*reply) + 1;
> - else {
> - *len = 0;
> - ret = REMOVE_PATH_FAILURE;
> - }
> - }
> + if (ret == REMOVE_PATH_DELAY)
> + SET_REPLY_AND_LEN(reply, len, "delayed\n");
> + else if (ret == REMOVE_PATH_MAP_ERROR)
> + SET_REPLY_AND_LEN(reply, len, "map reload error. removed\n");
>   return (ret == REMOVE_PATH_FAILURE);
>  }
>  
> @@ -865,8 +857,7 @@ cli_add_map (void * v, char ** reply, int * len, void * 
> data)
>   invalid = 1;
>   pthread_cleanup_pop(1);
>   if (invalid) {
> - *reply = strdup("blacklisted\n");
> - *len = strlen(*reply) + 1;
> + SET_REPLY_AND_LEN(reply, len, "blacklisted\n");
>   condlog(2, "%s: map blacklisted", param);
>   return 1;
>   }
> -- 
> 2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [PATCH v2 10/11] dm: introduce zone append emulation

2021-05-20 Thread Damien Le Moal
On 2021/05/20 15:47, Hannes Reinecke wrote:
> On 5/20/21 8:25 AM, Damien Le Moal wrote:
>> On 2021/05/20 15:10, Hannes Reinecke wrote:
>> [...]
 +/*
 + * First phase of BIO mapping for targets with zone append emulation:
 + * check all BIO that change a zone writer pointer and change zone
 + * append operations into regular write operations.
 + */
 +static bool dm_zone_map_bio_begin(struct mapped_device *md,
 +struct bio *orig_bio, struct bio *clone)
 +{
 +  sector_t zone_sectors = blk_queue_zone_sectors(md->queue);
 +  unsigned int zno = bio_zone_no(orig_bio);
 +  unsigned long flags;
 +  bool good_io = false;
 +
 +  spin_lock_irqsave(>zwp_offset_lock, flags);
 +
 +  /*
 +   * If the target zone is in an error state, recover by inspecting the
 +   * zone to get its current write pointer position. Note that since the
 +   * target zone is already locked, a BIO issuing context should never
 +   * see the zone write in the DM_ZONE_UPDATING_WP_OFST state.
 +   */
 +  if (md->zwp_offset[zno] == DM_ZONE_INVALID_WP_OFST) {
 +  unsigned int wp_offset;
 +  int ret;
 +
 +  md->zwp_offset[zno] = DM_ZONE_UPDATING_WP_OFST;
 +
 +  spin_unlock_irqrestore(>zwp_offset_lock, flags);
 +  ret = dm_update_zone_wp_offset(md, zno, _offset);
 +  spin_lock_irqsave(>zwp_offset_lock, flags);
 +
 +  if (ret) {
 +  md->zwp_offset[zno] = DM_ZONE_INVALID_WP_OFST;
 +  goto out;
 +  }
 +  md->zwp_offset[zno] = wp_offset;
 +  } else if (md->zwp_offset[zno] == DM_ZONE_UPDATING_WP_OFST) {
 +  DMWARN_LIMIT("Invalid DM_ZONE_UPDATING_WP_OFST state");
 +  goto out;
 +  }
 +
 +  switch (bio_op(orig_bio)) {
 +  case REQ_OP_WRITE_ZEROES:
 +  case REQ_OP_WRITE_SAME:
 +  case REQ_OP_WRITE:
 +  break;
 +  case REQ_OP_ZONE_RESET:
 +  case REQ_OP_ZONE_FINISH:
 +  goto good;
 +  case REQ_OP_ZONE_APPEND:
 +  /*
 +   * Change zone append operations into a non-mergeable regular
 +   * writes directed at the current write pointer position of the
 +   * target zone.
 +   */
 +  clone->bi_opf = REQ_OP_WRITE | REQ_NOMERGE |
 +  (orig_bio->bi_opf & (~REQ_OP_MASK));
 +  clone->bi_iter.bi_sector =
 +  orig_bio->bi_iter.bi_sector + md->zwp_offset[zno];
 +  break;
 +  default:
 +  DMWARN_LIMIT("Invalid BIO operation");
 +  goto out;
 +  }
 +
 +  /* Cannot write to a full zone */
 +  if (md->zwp_offset[zno] >= zone_sectors)
 +  goto out;
 +
 +  /* Writes must be aligned to the zone write pointer */
 +  if ((clone->bi_iter.bi_sector & (zone_sectors - 1)) != 
 md->zwp_offset[zno])
 +  goto out;
 +
 +good:
 +  good_io = true;
 +
 +out:
 +  spin_unlock_irqrestore(>zwp_offset_lock, flags);
>>>
>>> I'm not happy with the spinlock. Can't the same effect be achieved with
>>> some clever READ_ONCE()/WRITE_ONCE/cmpexch magic?
>>> Especially as you have a separate 'zone lock' mechanism ...
>>
>> hmmm... Let me see. Given that what the bio completion is relatively simple, 
>> it
>> may be possible. With more coffee, I amy be able to come up with something 
>> clever.
>>
> More coffee is always a good idea :-)
> I would look at killing the intermediate state UPDATING_WP_OFST and only 
> update the pointer on endio (or if it failed).
> That way we would need to update the pointer only once if we have a 
> final state, and don't need to do the double update you are doing now.

Good point. That should work. Definitely more coffee needed :)

> 
>>>
 +
 +  return good_io;
 +}
 +
 +/*
 + * Second phase of BIO mapping for targets with zone append emulation:
 + * update the zone write pointer offset array to account for the 
 additional
 + * data written to a zone. Note that at this point, the remapped clone BIO
 + * may already have completed, so we do not touch it.
 + */
 +static blk_status_t dm_zone_map_bio_end(struct mapped_device *md,
 +  struct bio *orig_bio,
 +  unsigned int nr_sectors)
 +{
 +  unsigned int zno = bio_zone_no(orig_bio);
 +  blk_status_t sts = BLK_STS_OK;
 +  unsigned long flags;
 +
 +  spin_lock_irqsave(>zwp_offset_lock, flags);
 +
 +  /* Update the zone wp offset */
 +  switch (bio_op(orig_bio)) {
 +  case REQ_OP_ZONE_RESET:
 +  md->zwp_offset[zno] = 0;
 +  break;
 +  case REQ_OP_ZONE_FINISH:
 +  md->zwp_offset[zno] = blk_queue_zone_sectors(md->queue);
 +  

Re: [dm-devel] [PATCH v2 10/11] dm: introduce zone append emulation

2021-05-20 Thread Hannes Reinecke

On 5/20/21 8:25 AM, Damien Le Moal wrote:

On 2021/05/20 15:10, Hannes Reinecke wrote:
[...]

+/*
+ * First phase of BIO mapping for targets with zone append emulation:
+ * check all BIO that change a zone writer pointer and change zone
+ * append operations into regular write operations.
+ */
+static bool dm_zone_map_bio_begin(struct mapped_device *md,
+ struct bio *orig_bio, struct bio *clone)
+{
+   sector_t zone_sectors = blk_queue_zone_sectors(md->queue);
+   unsigned int zno = bio_zone_no(orig_bio);
+   unsigned long flags;
+   bool good_io = false;
+
+   spin_lock_irqsave(>zwp_offset_lock, flags);
+
+   /*
+* If the target zone is in an error state, recover by inspecting the
+* zone to get its current write pointer position. Note that since the
+* target zone is already locked, a BIO issuing context should never
+* see the zone write in the DM_ZONE_UPDATING_WP_OFST state.
+*/
+   if (md->zwp_offset[zno] == DM_ZONE_INVALID_WP_OFST) {
+   unsigned int wp_offset;
+   int ret;
+
+   md->zwp_offset[zno] = DM_ZONE_UPDATING_WP_OFST;
+
+   spin_unlock_irqrestore(>zwp_offset_lock, flags);
+   ret = dm_update_zone_wp_offset(md, zno, _offset);
+   spin_lock_irqsave(>zwp_offset_lock, flags);
+
+   if (ret) {
+   md->zwp_offset[zno] = DM_ZONE_INVALID_WP_OFST;
+   goto out;
+   }
+   md->zwp_offset[zno] = wp_offset;
+   } else if (md->zwp_offset[zno] == DM_ZONE_UPDATING_WP_OFST) {
+   DMWARN_LIMIT("Invalid DM_ZONE_UPDATING_WP_OFST state");
+   goto out;
+   }
+
+   switch (bio_op(orig_bio)) {
+   case REQ_OP_WRITE_ZEROES:
+   case REQ_OP_WRITE_SAME:
+   case REQ_OP_WRITE:
+   break;
+   case REQ_OP_ZONE_RESET:
+   case REQ_OP_ZONE_FINISH:
+   goto good;
+   case REQ_OP_ZONE_APPEND:
+   /*
+* Change zone append operations into a non-mergeable regular
+* writes directed at the current write pointer position of the
+* target zone.
+*/
+   clone->bi_opf = REQ_OP_WRITE | REQ_NOMERGE |
+   (orig_bio->bi_opf & (~REQ_OP_MASK));
+   clone->bi_iter.bi_sector =
+   orig_bio->bi_iter.bi_sector + md->zwp_offset[zno];
+   break;
+   default:
+   DMWARN_LIMIT("Invalid BIO operation");
+   goto out;
+   }
+
+   /* Cannot write to a full zone */
+   if (md->zwp_offset[zno] >= zone_sectors)
+   goto out;
+
+   /* Writes must be aligned to the zone write pointer */
+   if ((clone->bi_iter.bi_sector & (zone_sectors - 1)) != 
md->zwp_offset[zno])
+   goto out;
+
+good:
+   good_io = true;
+
+out:
+   spin_unlock_irqrestore(>zwp_offset_lock, flags);


I'm not happy with the spinlock. Can't the same effect be achieved with
some clever READ_ONCE()/WRITE_ONCE/cmpexch magic?
Especially as you have a separate 'zone lock' mechanism ...


hmmm... Let me see. Given that what the bio completion is relatively simple, it
may be possible. With more coffee, I amy be able to come up with something 
clever.


More coffee is always a good idea :-)
I would look at killing the intermediate state UPDATING_WP_OFST and only 
update the pointer on endio (or if it failed).
That way we would need to update the pointer only once if we have a 
final state, and don't need to do the double update you are doing now.





+
+   return good_io;
+}
+
+/*
+ * Second phase of BIO mapping for targets with zone append emulation:
+ * update the zone write pointer offset array to account for the additional
+ * data written to a zone. Note that at this point, the remapped clone BIO
+ * may already have completed, so we do not touch it.
+ */
+static blk_status_t dm_zone_map_bio_end(struct mapped_device *md,
+   struct bio *orig_bio,
+   unsigned int nr_sectors)
+{
+   unsigned int zno = bio_zone_no(orig_bio);
+   blk_status_t sts = BLK_STS_OK;
+   unsigned long flags;
+
+   spin_lock_irqsave(>zwp_offset_lock, flags);
+
+   /* Update the zone wp offset */
+   switch (bio_op(orig_bio)) {
+   case REQ_OP_ZONE_RESET:
+   md->zwp_offset[zno] = 0;
+   break;
+   case REQ_OP_ZONE_FINISH:
+   md->zwp_offset[zno] = blk_queue_zone_sectors(md->queue);
+   break;
+   case REQ_OP_WRITE_ZEROES:
+   case REQ_OP_WRITE_SAME:
+   case REQ_OP_WRITE:
+   md->zwp_offset[zno] += nr_sectors;
+   break;
+   case REQ_OP_ZONE_APPEND:
+   /*
+* Check that the target did not truncate the write operation
+* 

Re: [dm-devel] [PATCH v2 10/11] dm: introduce zone append emulation

2021-05-20 Thread Damien Le Moal
On 2021/05/20 15:10, Hannes Reinecke wrote:
[...]
>> +/*
>> + * First phase of BIO mapping for targets with zone append emulation:
>> + * check all BIO that change a zone writer pointer and change zone
>> + * append operations into regular write operations.
>> + */
>> +static bool dm_zone_map_bio_begin(struct mapped_device *md,
>> +  struct bio *orig_bio, struct bio *clone)
>> +{
>> +sector_t zone_sectors = blk_queue_zone_sectors(md->queue);
>> +unsigned int zno = bio_zone_no(orig_bio);
>> +unsigned long flags;
>> +bool good_io = false;
>> +
>> +spin_lock_irqsave(>zwp_offset_lock, flags);
>> +
>> +/*
>> + * If the target zone is in an error state, recover by inspecting the
>> + * zone to get its current write pointer position. Note that since the
>> + * target zone is already locked, a BIO issuing context should never
>> + * see the zone write in the DM_ZONE_UPDATING_WP_OFST state.
>> + */
>> +if (md->zwp_offset[zno] == DM_ZONE_INVALID_WP_OFST) {
>> +unsigned int wp_offset;
>> +int ret;
>> +
>> +md->zwp_offset[zno] = DM_ZONE_UPDATING_WP_OFST;
>> +
>> +spin_unlock_irqrestore(>zwp_offset_lock, flags);
>> +ret = dm_update_zone_wp_offset(md, zno, _offset);
>> +spin_lock_irqsave(>zwp_offset_lock, flags);
>> +
>> +if (ret) {
>> +md->zwp_offset[zno] = DM_ZONE_INVALID_WP_OFST;
>> +goto out;
>> +}
>> +md->zwp_offset[zno] = wp_offset;
>> +} else if (md->zwp_offset[zno] == DM_ZONE_UPDATING_WP_OFST) {
>> +DMWARN_LIMIT("Invalid DM_ZONE_UPDATING_WP_OFST state");
>> +goto out;
>> +}
>> +
>> +switch (bio_op(orig_bio)) {
>> +case REQ_OP_WRITE_ZEROES:
>> +case REQ_OP_WRITE_SAME:
>> +case REQ_OP_WRITE:
>> +break;
>> +case REQ_OP_ZONE_RESET:
>> +case REQ_OP_ZONE_FINISH:
>> +goto good;
>> +case REQ_OP_ZONE_APPEND:
>> +/*
>> + * Change zone append operations into a non-mergeable regular
>> + * writes directed at the current write pointer position of the
>> + * target zone.
>> + */
>> +clone->bi_opf = REQ_OP_WRITE | REQ_NOMERGE |
>> +(orig_bio->bi_opf & (~REQ_OP_MASK));
>> +clone->bi_iter.bi_sector =
>> +orig_bio->bi_iter.bi_sector + md->zwp_offset[zno];
>> +break;
>> +default:
>> +DMWARN_LIMIT("Invalid BIO operation");
>> +goto out;
>> +}
>> +
>> +/* Cannot write to a full zone */
>> +if (md->zwp_offset[zno] >= zone_sectors)
>> +goto out;
>> +
>> +/* Writes must be aligned to the zone write pointer */
>> +if ((clone->bi_iter.bi_sector & (zone_sectors - 1)) != 
>> md->zwp_offset[zno])
>> +goto out;
>> +
>> +good:
>> +good_io = true;
>> +
>> +out:
>> +spin_unlock_irqrestore(>zwp_offset_lock, flags);
> 
> I'm not happy with the spinlock. Can't the same effect be achieved with 
> some clever READ_ONCE()/WRITE_ONCE/cmpexch magic?
> Especially as you have a separate 'zone lock' mechanism ...

hmmm... Let me see. Given that what the bio completion is relatively simple, it
may be possible. With more coffee, I amy be able to come up with something 
clever.

> 
>> +
>> +return good_io;
>> +}
>> +
>> +/*
>> + * Second phase of BIO mapping for targets with zone append emulation:
>> + * update the zone write pointer offset array to account for the additional
>> + * data written to a zone. Note that at this point, the remapped clone BIO
>> + * may already have completed, so we do not touch it.
>> + */
>> +static blk_status_t dm_zone_map_bio_end(struct mapped_device *md,
>> +struct bio *orig_bio,
>> +unsigned int nr_sectors)
>> +{
>> +unsigned int zno = bio_zone_no(orig_bio);
>> +blk_status_t sts = BLK_STS_OK;
>> +unsigned long flags;
>> +
>> +spin_lock_irqsave(>zwp_offset_lock, flags);
>> +
>> +/* Update the zone wp offset */
>> +switch (bio_op(orig_bio)) {
>> +case REQ_OP_ZONE_RESET:
>> +md->zwp_offset[zno] = 0;
>> +break;
>> +case REQ_OP_ZONE_FINISH:
>> +md->zwp_offset[zno] = blk_queue_zone_sectors(md->queue);
>> +break;
>> +case REQ_OP_WRITE_ZEROES:
>> +case REQ_OP_WRITE_SAME:
>> +case REQ_OP_WRITE:
>> +md->zwp_offset[zno] += nr_sectors;
>> +break;
>> +case REQ_OP_ZONE_APPEND:
>> +/*
>> + * Check that the target did not truncate the write operation
>> + * emulating a zone append.
>> + */
>> +if (nr_sectors != bio_sectors(orig_bio)) {
>> +DMWARN_LIMIT("Truncated write for zone append");
>> +sts = BLK_STS_IOERR;
>> +

Re: [dm-devel] [PATCH v2 11/11] dm crypt: Fix zoned block device support

2021-05-20 Thread Hannes Reinecke

On 5/20/21 6:22 AM, Damien Le Moal wrote:

Zone append BIOs (REQ_OP_ZONE_APPEND) always specify the start sector
of the zone to be written instead of the actual sector location to
write. The write location is determined by the device and returned to
the host upon completion of the operation. This interface, while simple
and efficient for writing into sequential zones of a zoned block
device, is incompatible with the use of sector values to calculate a
cypher block IV. All data written in a zone end up using the same IV
values corresponding to the first sectors of the zone, but read
operation will specify any sector within the zone resulting in an IV
mismatch between encryption and decryption.

To solve this problem, report to DM core that zone append operations are
not supported. This result in the zone append operations being emulated
using regular write operations.

Reported-by: Shin'ichiro Kawasaki 
Signed-off-by: Damien Le Moal 
---
  drivers/md/dm-crypt.c | 24 +++-
  1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index f410ceee51d7..50f4cbd600d5 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -3280,14 +3280,28 @@ static int crypt_ctr(struct dm_target *ti, unsigned int 
argc, char **argv)
}
cc->start = tmpll;
  
-	/*

-* For zoned block devices, we need to preserve the issuer write
-* ordering. To do so, disable write workqueues and force inline
-* encryption completion.
-*/
if (bdev_is_zoned(cc->dev->bdev)) {
+   /*
+* For zoned block devices, we need to preserve the issuer write
+* ordering. To do so, disable write workqueues and force inline
+* encryption completion.
+*/
set_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, >flags);
set_bit(DM_CRYPT_WRITE_INLINE, >flags);
+
+   /*
+* All zone append writes to a zone of a zoned block device will
+* have the same BIO sector, the start of the zone. When the
+* cypher IV mode uses sector values, all data targeting a
+* zone will be encrypted using the first sector numbers of the
+* zone. This will not result in write errors but will
+* cause most reads to fail as reads will use the sector values
+* for the actual data locations, resulting in IV mismatch.
+* To avoid this problem, ask DM core to emulate zone append
+* operations with regular writes.
+*/
+   DMDEBUG("Zone append operations will be emulated");
+   ti->emulate_zone_append = true;
}
  
  	if (crypt_integrity_aead(cc) || cc->integrity_iv_size) {



Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
--
Dr. Hannes ReineckeKernel Storage Architect
h...@suse.de  +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

Re: [dm-devel] [PATCH v2 10/11] dm: introduce zone append emulation

2021-05-20 Thread Hannes Reinecke

On 5/20/21 6:22 AM, Damien Le Moal wrote:

For zoned targets that cannot support zone append operations, implement
an emulation using regular write operations. If the original BIO
submitted by the user is a zone append operation, change its clone into
a regular write operation directed at the target zone write pointer
position.

To do so, an array of write pointer offsets (write pointer position
relative to the start of a zone) is added to struct mapped_device. All
operations that modify a sequential zone write pointer (writes, zone
reset, zone finish and zone append) are intersepted in __map_bio() and
processed using the new functions dm_zone_map_bio().

Detection of the target ability to natively support zone append
operations is done from dm_table_set_restrictions() by calling the
function dm_set_zones_restrictions(). A target that does not support
zone append operation, either by explicitly declaring it using the new
struct dm_target field zone_append_not_supported, or because the device
table contains a non-zoned device, has its mapped device marked with the
new flag DMF_ZONE_APPEND_EMULATED. The helper function
dm_emulate_zone_append() is introduced to test a mapped device for this
new flag.

Atomicity of the zones write pointer tracking and updates is done using
a zone write locking mechanism based on a bitmap. This is similar to
the block layer method but based on BIOs rather than struct request.
A zone write lock is taken in dm_zone_map_bio() for any clone BIO with
an operation type that changes the BIO target zone write pointer
position. The zone write lock is released if the clone BIO is failed
before submission or when dm_zone_endio() is called when the clone BIO
completes.

The zone write lock bitmap of the mapped device, together with a bitmap
indicating zone types (conv_zones_bitmap) and the write pointer offset
array (zwp_offset) are allocated and initialized with a full device zone
report in dm_set_zones_restrictions() using the function
dm_revalidate_zones().

For failed operations that may have modified a zone write pointer, the
zone write pointer offset is marked as invalid in dm_zone_endio().
Zones with an invalid write pointer offset are checked and the write
pointer updated using an internal report zone operation when the
faulty zone is accessed again by the user.

All functions added for this emulation have a minimal overhead for
zoned targets natively supporting zone append operations. Regular
device targets are also not affected. The added code also does not
impact builds with CONFIG_BLK_DEV_ZONED disabled by stubbing out all
dm zone related functions.

Signed-off-by: Damien Le Moal 
---
  drivers/md/dm-core.h  |  14 +
  drivers/md/dm-table.c |  19 +-
  drivers/md/dm-zone.c  | 615 --
  drivers/md/dm.c   |  39 ++-
  drivers/md/dm.h   |  18 +-
  include/linux/device-mapper.h |   6 +
  6 files changed, 657 insertions(+), 54 deletions(-)

diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h
index cfabc1c91f9f..2dbb0c7ff720 100644
--- a/drivers/md/dm-core.h
+++ b/drivers/md/dm-core.h
@@ -114,6 +114,12 @@ struct mapped_device {
bool init_tio_pdu:1;
  
  	struct srcu_struct io_barrier;

+
+#ifdef CONFIG_BLK_DEV_ZONED
+   unsigned int nr_zones;
+   spinlock_t zwp_offset_lock;
+   unsigned int *zwp_offset;
+#endif
  };
  
  /*

@@ -128,6 +134,7 @@ struct mapped_device {
  #define DMF_DEFERRED_REMOVE 6
  #define DMF_SUSPENDED_INTERNALLY 7
  #define DMF_POST_SUSPENDING 8
+#define DMF_EMULATE_ZONE_APPEND 9
  
  void disable_discard(struct mapped_device *md);

  void disable_write_same(struct mapped_device *md);
@@ -143,6 +150,13 @@ static inline struct dm_stats *dm_get_stats(struct 
mapped_device *md)
return >stats;
  }
  
+static inline bool dm_emulate_zone_append(struct mapped_device *md)

+{
+   if (blk_queue_is_zoned(md->queue))
+   return test_bit(DMF_EMULATE_ZONE_APPEND, >flags);
+   return false;
+}
+
  #define DM_TABLE_MAX_DEPTH 16
  
  struct dm_table {

diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index dd9f648ab598..21fdccfb16cf 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -1981,11 +1981,12 @@ static int device_requires_stable_pages(struct 
dm_target *ti,
return blk_queue_stable_writes(q);
  }
  
-void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,

-  struct queue_limits *limits)
+int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
+ struct queue_limits *limits)
  {
bool wc = false, fua = false;
int page_size = PAGE_SIZE;
+   int r;
  
  	/*

 * Copy table's limits to the DM device's request_queue
@@ -2064,12 +2065,20 @@ void dm_table_set_restrictions(struct dm_table *t, 
struct request_queue *q,
dm_table_any_dev_attr(t, device_is_not_random, NULL))

Re: [dm-devel] [PATCH v2 09/11] dm: rearrange core declarations

2021-05-20 Thread Hannes Reinecke

On 5/20/21 6:22 AM, Damien Le Moal wrote:

Move the definitions of struct dm_target_io, struct dm_io and of the
bits of the flags field of struct mapped_device from dm.c to dm-core.h
to make them usable from dm-zone.c.
For the same reason, declare dec_pending() in dm-core.h after renaming
it to dm_io_dec_pending(). And for symmetry of the function names,
introduce the inline helper dm_io_inc_pending() instead of directly
using atomic_inc() calls.

Signed-off-by: Damien Le Moal 
---
  drivers/md/dm-core.h | 52 ++
  drivers/md/dm.c  | 59 ++--
  2 files changed, 59 insertions(+), 52 deletions(-)
I've never been a fan of private structures.


Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
--
Dr. Hannes ReineckeKernel Storage Architect
h...@suse.de  +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

Re: [dm-devel] [PATCH v2 06/11] dm: move zone related code to dm-zone.c

2021-05-20 Thread Hannes Reinecke

On 5/20/21 6:22 AM, Damien Le Moal wrote:

Move core and table code used for zoned targets and conditionally
defined with #ifdef CONFIG_BLK_DEV_ZONED to the new file dm-zone.c.
This file is conditionally compiled depending on CONFIG_BLK_DEV_ZONED.
The small helper dm_set_zones_restrictions() is introduced to
initialize a mapped device request queue zone attributes in
dm_table_set_restrictions().

Signed-off-by: Damien Le Moal 
Reviewed-by: Johannes Thumshirn 
---
  drivers/md/Makefile   |   4 ++
  drivers/md/dm-table.c |  14 ++
  drivers/md/dm-zone.c  | 102 ++
  drivers/md/dm.c   |  78 
  drivers/md/dm.h   |  11 +
  5 files changed, 120 insertions(+), 89 deletions(-)
  create mode 100644 drivers/md/dm-zone.c
Reviewed-by: Hannes Reinecke 


Cheers,

Hannes
--
Dr. Hannes ReineckeKernel Storage Architect
h...@suse.de  +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

Re: [dm-devel] [PATCH v2 08/11] dm: Forbid requeue of writes to zones

2021-05-20 Thread Hannes Reinecke

On 5/20/21 6:22 AM, Damien Le Moal wrote:

A target map method requesting the requeue of a bio with
DM_MAPIO_REQUEUE or completing it with DM_ENDIO_REQUEUE can cause
unaligned write errors if the bio is a write operation targeting a
sequential zone. If a zoned target request such a requeue, warn about
it and kill the IO.

The function dm_is_zone_write() is introduced to detect write operations
to zoned targets.

This change does not affect the target drivers supporting zoned devices
and exposing a zoned device, namely dm-crypt, dm-linear and dm-flakey as
none of these targets ever request a requeue.

Signed-off-by: Damien Le Moal 
---
  drivers/md/dm-zone.c | 17 +
  drivers/md/dm.c  | 18 +++---
  drivers/md/dm.h  |  5 +
  3 files changed, 37 insertions(+), 3 deletions(-)


Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
--
Dr. Hannes ReineckeKernel Storage Architect
h...@suse.de  +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

Re: [dm-devel] [PATCH v2 07/11] dm: Introduce dm_report_zones()

2021-05-20 Thread Hannes Reinecke

On 5/20/21 6:22 AM, Damien Le Moal wrote:

To simplify the implementation of the report_zones operation of a zoned
target, introduce the function dm_report_zones() to set a target
mapping start sector in struct dm_report_zones_args and call
blkdev_report_zones(). This new function is exported and the report
zones callback function dm_report_zones_cb() is not.

dm-linear, dm-flakey and dm-crypt are modified to use dm_report_zones().

Signed-off-by: Damien Le Moal 
Reviewed-by: Johannes Thumshirn 
---
  drivers/md/dm-crypt.c |  7 +++
  drivers/md/dm-flakey.c|  7 +++
  drivers/md/dm-linear.c|  7 +++
  drivers/md/dm-zone.c  | 23 ---
  include/linux/device-mapper.h |  3 ++-
  5 files changed, 31 insertions(+), 16 deletions(-)


Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
--
Dr. Hannes ReineckeKernel Storage Architect
h...@suse.de  +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

Re: [dm-devel] [PATCH v2 05/11] dm: cleanup device_area_is_invalid()

2021-05-20 Thread Hannes Reinecke

On 5/20/21 6:22 AM, Damien Le Moal wrote:

In device_area_is_invalid(), use bdev_is_zoned() instead of open
coding the test on the zoned model returned by bdev_zoned_model().

Signed-off-by: Damien Le Moal 
Reviewed-by: Johannes Thumshirn 
---
  drivers/md/dm-table.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index ee47a332b462..21fd9cd4da32 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -249,7 +249,7 @@ static int device_area_is_invalid(struct dm_target *ti, 
struct dm_dev *dev,
 * If the target is mapped to zoned block device(s), check
 * that the zones are not partially mapped.
 */
-   if (bdev_zoned_model(bdev) != BLK_ZONED_NONE) {
+   if (bdev_is_zoned(bdev)) {
unsigned int zone_sectors = bdev_zone_sectors(bdev);
  
  		if (start & (zone_sectors - 1)) {



Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
--
Dr. Hannes ReineckeKernel Storage Architect
h...@suse.de  +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel