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

2021-05-24 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 
Reviewed-by: Chaitanya Kulkarni 
---
 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



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

2021-05-24 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 v4 07/11] dm: Introduce dm_report_zones()

2021-05-24 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 v4 09/11] dm: rearrange core declarations

2021-05-24 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 v4 08/11] dm: Forbid requeue of writes to zones

2021-05-24 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 v4 10/11] dm: introduce zone append emulation

2021-05-24 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 v4 11/11] dm crypt: Fix zoned block device support

2021-05-24 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 v4 04/11] dm: Fix dm_accept_partial_bio()

2021-05-24 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 v4 06/11] dm: move zone related code to dm-zone.c

2021-05-24 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 v4 02/11] block: introduce bio zone helpers

2021-05-24 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 
Reviewed-by: Chaitanya Kulkarni 
---
 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 v4 01/11] block: improve handling of all zones reset operation

2021-05-24 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 
---
 block/blk-zoned.c | 119 +++---
 1 file changed, 92 insertions(+), 27 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 250cb76ee615..f47f688b6ea6 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -161,18 +161,89 @@ 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 =  0;
+   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();
+   }
+
+   if (bio) {
+ 

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

2021-05-24 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 v3:
* Fixed missing variable initialization in
  blkdev_zone_reset_all_emulated() in patch 1.
* Rebased on rc3
* Added reviewed-by tags

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 | 119 +--
 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, 955 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



Re: [dm-devel] [PATCH] multipath-tools: Remove trailing/leading whitespaces

2021-05-24 Thread Benjamin Marzinski
On Sat, May 22, 2021 at 09:17:36PM +0200, Xose Vazquez Perez wrote:
> Cc: Martin Wilck 
> Cc: Benjamin Marzinski 
> Cc: Christophe Varoqui 
> Cc: DM-DEVEL ML 
> Signed-off-by: Xose Vazquez Perez 

If no one objects, I'm fine with this going in. But if anyone has
objections to a whitespace only patch, I'm o.k. with this not going in
as well.

-Ben

> ---
>  Makefile.inc  | 2 +-
>  libmultipath/configure.c  | 2 +-
>  libmultipath/devmapper.c  | 4 ++--
>  libmultipath/sysfs.c  | 2 +-
>  multipath/multipath.8 | 2 +-
>  multipathd/cli_handlers.c | 2 +-
>  multipathd/main.c | 2 +-
>  7 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/Makefile.inc b/Makefile.inc
> index 91100a20..d0ec9b44 100644
> --- a/Makefile.inc
> +++ b/Makefile.inc
> @@ -101,7 +101,7 @@ OPTFLAGS  := -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
>  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 
> +CPPFLAGS := -Wp,-D_FORTIFY_SOURCE=2
>  CFLAGS   := --std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe 
> \
>  -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" 
> -DRUN_DIR=\"${RUN}\" \
>  -MMD -MP
> diff --git a/libmultipath/configure.c b/libmultipath/configure.c
> index 6ca1f4bb..a6ae3359 100644
> --- a/libmultipath/configure.c
> +++ b/libmultipath/configure.c
> @@ -397,7 +397,7 @@ int setup_map(struct multipath *mpp, char *params, int 
> params_size,
>   start_io_err_stat_thread(vecs);
>  
>   n_paths = VECTOR_SIZE(mpp->paths);
> -/*
> + /*
>* assign paths to path groups -- start with no groups and all paths
>* in mpp->paths
>*/
> diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
> index 095cbc0c..98ec2a58 100644
> --- a/libmultipath/devmapper.c
> +++ b/libmultipath/devmapper.c
> @@ -598,8 +598,8 @@ int dm_addmap_reload(struct multipath *mpp, char *params, 
> int flush)
>   return r;
>  
>   /* If the resume failed, dm will leave the device suspended, and
> -  * drop the new table, so doing a second resume will try using
> -  * the original table */
> +  * drop the new table, so doing a second resume will try using
> +  * the original table */
>   if (dm_is_suspended(mpp->alias))
>   dm_simplecmd(DM_DEVICE_RESUME, mpp->alias, !flush, 1,
>udev_flags, 0);
> diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c
> index 7a2af1ea..9ff145f2 100644
> --- a/libmultipath/sysfs.c
> +++ b/libmultipath/sysfs.c
> @@ -358,7 +358,7 @@ bool sysfs_is_multipathed(struct path *pp, bool set_wwid)
>   strchop(pp->wwid);
>   }
>   }
> -} else if (nr < 0)
> + } else if (nr < 0)
>   condlog(1, "%s: error reading from %s: %m",
>   __func__, pathbuf);
>  
> diff --git a/multipath/multipath.8 b/multipath/multipath.8
> index 5b29a5d9..17df59f5 100644
> --- a/multipath/multipath.8
> +++ b/multipath/multipath.8
> @@ -225,7 +225,7 @@ Dry run, do not create or update devmaps.
>  .TP
>  .B \-e
>  Enable all foreign libraries. This overrides the
> -.I enable_foreign 
> +.I enable_foreign
>  option from \fBmultipath.conf(5)\fR.
>  .
>  .TP
> diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
> index 59d44b45..d70e1dbc 100644
> --- a/multipathd/cli_handlers.c
> +++ b/multipathd/cli_handlers.c
> @@ -1215,7 +1215,7 @@ cli_reconfigure(void * v, char ** reply, int * len, 
> void * data)
>  
>   condlog(2, "reconfigure (operator)");
>  
> - rc = set_config_state(DAEMON_CONFIGURE); 
> + rc = set_config_state(DAEMON_CONFIGURE);
>   if (rc == ETIMEDOUT) {
>   condlog(2, "timeout starting reconfiguration");
>   return 1;
> diff --git a/multipathd/main.c b/multipathd/main.c
> index 2251e02c..bdd629e7 100644
> --- a/multipathd/main.c
> +++ b/multipathd/main.c
> @@ -2014,7 +2014,7 @@ static int check_path_reinstate_state(struct path * pp) 
> {
>  
>   /* If path became failed again or continue failed, should reset
>* path san_path_err_forget_rate and path dis_reinstate_time to
> -  * start a new stable check. 
> +  * start a new stable check.
>*/
>   if ((pp->state != PATH_UP) && (pp->state != PATH_GHOST) &&
>   (pp->state != PATH_DELAYED)) {
> -- 
> 2.31.1

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



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

2021-05-24 Thread Benjamin Marzinski
On Thu, May 20, 2021 at 09:52:08PM +0200, mwi...@suse.com wrote:
> 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 
Reviewed-by: Benjamin Marzinski 
> ---
>  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



Re: [dm-devel] [PATCH 14/26] md: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-24 Thread Hannes Reinecke

On 5/24/21 9:26 AM, Christoph Hellwig wrote:

On Sun, May 23, 2021 at 10:12:49AM +0200, Hannes Reinecke wrote:

+   blk_set_stacking_limits(>queue->limits);
blk_queue_write_cache(mddev->queue, true, true);
/* Allow extended partitions.  This makes the
 * 'mdp' device redundant, but we can't really


Wouldn't it make sense to introduce a helper 'blk_queue_from_disk()' or
somesuch to avoid having to keep an explicit 'queue' pointer?


My rought plan is that a few series from now bio based drivers will
never directly deal with the request_queue at all.


Go for it.

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 18/26] nvme-multipath: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-24 Thread Christoph Hellwig
On Sun, May 23, 2021 at 10:20:27AM +0200, Hannes Reinecke wrote:
> What about the check for GENHD_FL_UP a bit further up in line 766?
> Can this still happen with the new allocation scheme, ie is there still a 
> difference in lifetime between ->disk and ->disk->queue?

Yes, nvme_free_ns_head can still be called before device_add_disk was
called for an allocated nshead gendisk during error handling of the
setup path.  There is still a difference in the lifetime in that they
are separately refcounted, but it does not matter to the driver.

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



Re: [dm-devel] [PATCH 14/26] md: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-24 Thread Christoph Hellwig
On Sun, May 23, 2021 at 10:12:49AM +0200, Hannes Reinecke wrote:
>> +blk_set_stacking_limits(>queue->limits);
>>  blk_queue_write_cache(mddev->queue, true, true);
>>  /* Allow extended partitions.  This makes the
>>   * 'mdp' device redundant, but we can't really
>>
> Wouldn't it make sense to introduce a helper 'blk_queue_from_disk()' or 
> somesuch to avoid having to keep an explicit 'queue' pointer?

My rought plan is that a few series from now bio based drivers will
never directly deal with the request_queue at all.

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



Re: [dm-devel] [PATCH 13/26] dm: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-24 Thread Christoph Hellwig
On Sun, May 23, 2021 at 10:10:34AM +0200, Hannes Reinecke wrote:
> Can't these conditionals be merged into a single 'if (md->disk)'?
> Eg like:
>
>   if (md->disk) {
>   spin_lock(&_minor_lock);
>   md->disk->private_data = NULL;
>   spin_unlock(&_minor_lock);
>   del_gendisk(md->disk);
>   dm_queue_destroy_keyslot_manager(md->queue);
>   blk_cleanup_disk(md->queue);
>   }
>
> We're now always allocating 'md->disk' and 'md->queue' together,
> so how can we end up in a situation where one is set without the other?

I guess we could do that, not sure it is worth the churn, though.

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



Re: [dm-devel] [PATCH 06/26] brd: convert to blk_alloc_disk/blk_cleanup_disk

2021-05-24 Thread Christoph Hellwig
On Sun, May 23, 2021 at 09:58:48AM +0200, Hannes Reinecke wrote:
>> +/*
>> + * This is so fdisk will align partitions on 4k, because of
>> + * direct_access API needing 4k alignment, returning a PFN
>> + * (This is only a problem on very small devices <= 4M,
>> + *  otherwise fdisk will align on 1M. Regardless this call
>> + *  is harmless)
>> + */
>> +blk_queue_physical_block_size(disk->queue, PAGE_SIZE);
>>   
>
> Maybe converting the comment to refer to 'PAGE_SIZE' instead of 4k while 
> you're at it ...

I really do not want to touch these kinds of unrelated things here.

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



Re: [dm-devel] [PATCH 05/26] block: add blk_alloc_disk and blk_cleanup_disk APIs

2021-05-24 Thread Christoph Hellwig
On Fri, May 21, 2021 at 05:44:07PM +, Luis Chamberlain wrote:
> Its not obvious to me why using this new API requires you then to
> set minors explicitly to 1, and yet here underneath we see the minors
> argument passed is 0.
> 
> Nor is it clear from the documentation.

Basically for all new drivers no one should set minors at all, and the
dynamic dev_t mechanism does all the work.  For converted old drivers
minors is set manually instead of being passed an an argument that
should be 0 for all new drivers.

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



Re: [dm-devel] [PATCH 01/26] block: refactor device number setup in __device_add_disk

2021-05-24 Thread Christoph Hellwig
On Sun, May 23, 2021 at 09:46:01AM +0200, Hannes Reinecke wrote:
> ... and also fixes an issue with GENHD_FL_UP remained set in an error path 
> in __device_add_disk().

Well, the error path in __device_add_disk is a complete disaster right
now, but Luis is looking into it fortunately.

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



Re: [dm-devel] [PATCH 01/26] block: refactor device number setup in __device_add_disk

2021-05-24 Thread Christoph Hellwig
On Fri, May 21, 2021 at 05:16:46PM +, Luis Chamberlain wrote:
> > -   /* in consecutive minor range? */
> > -   if (bdev->bd_partno < disk->minors) {
> > -   *devt = MKDEV(disk->major, disk->first_minor + bdev->bd_partno);
> > -   return 0;
> > -   }
> > -
> 
> It is not obviously clear to me, why this was part of add_disk()
> path, and ...
> 
> > diff --git a/block/partitions/core.c b/block/partitions/core.c
> > index dc60ecf46fe6..504297bdc8bf 100644
> > --- a/block/partitions/core.c
> > +++ b/block/partitions/core.c
> > @@ -379,9 +380,15 @@ static struct block_device *add_partition(struct 
> > gendisk *disk, int partno,
> > pdev->type = _type;
> > pdev->parent = ddev;
> >  
> > -   err = blk_alloc_devt(bdev, );
> > -   if (err)
> > -   goto out_put;
> > +   /* in consecutive minor range? */
> > +   if (bdev->bd_partno < disk->minors) {
> > +   devt = MKDEV(disk->major, disk->first_minor + bdev->bd_partno);
> > +   } else {
> > +   err = blk_alloc_ext_minor();
> > +   if (err < 0)
> > +   goto out_put;
> > +   devt = MKDEV(BLOCK_EXT_MAJOR, err);
> > +   }
> > pdev->devt = devt;
> >  
> > /* delay uevent until 'holders' subdir is created */
> 
> ... and why we only add this here now.

For the genhd minors == 0 (aka GENHD_FL_EXT_DEVT) implies having to
allocate a dynamic dev_t, so it can be folded into another conditional.

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



[dm-devel] [PATCH][V2][next] dm space maps: Fix uninitialized variable r2

2021-05-24 Thread Colin King
From: Colin Ian King 

In the case where recursing(mm) is true variable r2 is not
inintialized and an uninitialized value is being used in the
call combine_errors later on. Fix this by setting r2 to zero.

Addresses-Coverity: ("Uninitialized scalar variable")
Fixes: def6a7a9a7f0 ("dm space maps: improve performance with inc/dec on ranges 
of blocks")
Signed-off-by: Colin Ian King 
---

V2: Add fix in function sm_metadata_inc_blocks

---
 drivers/md/persistent-data/dm-space-map-metadata.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c 
b/drivers/md/persistent-data/dm-space-map-metadata.c
index 3b70ee861cf5..a9a362777fad 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.c
+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
@@ -417,6 +417,7 @@ static int sm_metadata_inc_blocks(struct dm_space_map *sm, 
dm_block_t b, dm_bloc
r = add_bop(smm, BOP_INC, b, e);
if (r)
return r;
+   r2 = 0;
} else {
in(smm);
r = sm_ll_inc(>ll, b, e, _allocations);
@@ -432,9 +433,10 @@ static int sm_metadata_dec_blocks(struct dm_space_map *sm, 
dm_block_t b, dm_bloc
int32_t nr_allocations;
struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
 
-   if (recursing(smm))
+   if (recursing(smm)) {
r = add_bop(smm, BOP_DEC, b, e);
-   else {
+   r2 = 0;
+   } else {
in(smm);
r = sm_ll_dec(>ll, b, e, _allocations);
r2 = out(smm);
-- 
2.31.1

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



Re: [dm-devel] [PATCH 02/26] block: move the DISK_MAX_PARTS sanity check into __device_add_disk

2021-05-24 Thread Luis Chamberlain
On Fri, May 21, 2021 at 07:50:52AM +0200, Christoph Hellwig wrote:
> Keep this together with the first place that actually looks at
> ->minors and prepare for not passing a minors argument to
> alloc_disk.
> 
> Signed-off-by: Christoph Hellwig 

Reviewed-by: Luis Chamberlain 

  Luis

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



[dm-devel] [PATCH][next] dm space map disk: remove redundant initialization of variable index

2021-05-24 Thread Colin King
From: Colin Ian King 

The variable index is being initialized with a value that is never read,
it is being updated later on. The assignment is redundant and can be
removed.

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King 
---
 drivers/md/persistent-data/dm-space-map-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/persistent-data/dm-space-map-common.c 
b/drivers/md/persistent-data/dm-space-map-common.c
index 7e30700c8830..ad7a1b9304c7 100644
--- a/drivers/md/persistent-data/dm-space-map-common.c
+++ b/drivers/md/persistent-data/dm-space-map-common.c
@@ -577,7 +577,7 @@ static int __sm_ll_inc_overflow(struct ll_disk *ll, 
dm_block_t b, struct inc_con
 
 static int sm_ll_inc_overflow(struct ll_disk *ll, dm_block_t b, struct 
inc_context *ic)
 {
-   int index = -1;
+   int index;
struct btree_node *n;
__le32 *v_ptr;
uint32_t rc;
-- 
2.31.1

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



Re: [dm-devel] [PATCH 05/26] block: add blk_alloc_disk and blk_cleanup_disk APIs

2021-05-24 Thread Luis Chamberlain
On Fri, May 21, 2021 at 07:50:55AM +0200, Christoph Hellwig wrote:
> Add two new APIs to allocate and free a gendisk including the
> request_queue for use with BIO based drivers.  This is to avoid
> boilerplate code in drivers.
> 
> Signed-off-by: Christoph Hellwig 
> ---
>  block/genhd.c | 35 +++
>  include/linux/genhd.h | 22 ++
>  2 files changed, 57 insertions(+)
> 
> diff --git a/block/genhd.c b/block/genhd.c
> index e4974af3d729..6d4ce962866d 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -1302,6 +1302,25 @@ struct gendisk *__alloc_disk_node(int minors, int 
> node_id)
>  }
>  EXPORT_SYMBOL(__alloc_disk_node);
>  
> +struct gendisk *__blk_alloc_disk(int node)
> +{
> + struct request_queue *q;
> + struct gendisk *disk;
> +
> + q = blk_alloc_queue(node);
> + if (!q)
> + return NULL;
> +
> + disk = __alloc_disk_node(0, node);
> + if (!disk) {
> + blk_cleanup_queue(q);
> + return NULL;
> + }
> + disk->queue = q;
> + return disk;
> +}
> +EXPORT_SYMBOL(__blk_alloc_disk);

Its not obvious to me why using this new API requires you then to
set minors explicitly to 1, and yet here underneath we see the minors
argument passed is 0.

Nor is it clear from the documentation.

  Luis

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



[dm-devel] [PATCH][next] dm btree: Fix potential read of array with negative index i

2021-05-24 Thread Colin King
From: Colin Ian King 

The call to lower_bound can return -1 if the key is not found
with the bsearch, leading to a negative index access into
array node->keys[]. Ensure this cannot occur by checking for
a negative index before reading from the array.

Addresses-Coverity: ("Negative array index read")
Fixes: d69e2e7e28bd ("dm btree: improve btree residency")
Signed-off-by: Colin Ian King 
---
 drivers/md/persistent-data/dm-btree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/persistent-data/dm-btree.c 
b/drivers/md/persistent-data/dm-btree.c
index b8d21b6e2953..266deaea5eea 100644
--- a/drivers/md/persistent-data/dm-btree.c
+++ b/drivers/md/persistent-data/dm-btree.c
@@ -1048,7 +1048,7 @@ static bool contains_key(struct btree_node *node, 
uint64_t key)
 {
int i = lower_bound(node, key);
 
-   if (le64_to_cpu(node->keys[i]) == key)
+   if (i >= 0 && le64_to_cpu(node->keys[i]) == key)
return true;
 
return false;
-- 
2.31.1

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



Re: [dm-devel] [PATCH 01/26] block: refactor device number setup in __device_add_disk

2021-05-24 Thread Luis Chamberlain
On Fri, May 21, 2021 at 07:50:51AM +0200, Christoph Hellwig wrote:
> diff --git a/block/genhd.c b/block/genhd.c
> index 39ca97b0edc6..2c00bc3261d9 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -335,52 +335,22 @@ static int blk_mangle_minor(int minor)

<-- snip -->

> -int blk_alloc_devt(struct block_device *bdev, dev_t *devt)
> +int blk_alloc_ext_minor(void)
>  {
> - struct gendisk *disk = bdev->bd_disk;
>   int idx;
>  
> - /* in consecutive minor range? */
> - if (bdev->bd_partno < disk->minors) {
> - *devt = MKDEV(disk->major, disk->first_minor + bdev->bd_partno);
> - return 0;
> - }
> -

It is not obviously clear to me, why this was part of add_disk()
path, and ...

> diff --git a/block/partitions/core.c b/block/partitions/core.c
> index dc60ecf46fe6..504297bdc8bf 100644
> --- a/block/partitions/core.c
> +++ b/block/partitions/core.c
> @@ -379,9 +380,15 @@ static struct block_device *add_partition(struct gendisk 
> *disk, int partno,
>   pdev->type = _type;
>   pdev->parent = ddev;
>  
> - err = blk_alloc_devt(bdev, );
> - if (err)
> - goto out_put;
> + /* in consecutive minor range? */
> + if (bdev->bd_partno < disk->minors) {
> + devt = MKDEV(disk->major, disk->first_minor + bdev->bd_partno);
> + } else {
> + err = blk_alloc_ext_minor();
> + if (err < 0)
> + goto out_put;
> + devt = MKDEV(BLOCK_EXT_MAJOR, err);
> + }
>   pdev->devt = devt;
>  
>   /* delay uevent until 'holders' subdir is created */

... and why we only add this here now.

Other than that, this looks like a super nice cleanup!

Reviewed-by: Luis Chamberlain 

  Luis

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



Re: [dm-devel] [PATCH 04/26] block: add a flag to make put_disk on partially initalized disks safer

2021-05-24 Thread Luis Chamberlain
On Fri, May 21, 2021 at 07:50:54AM +0200, Christoph Hellwig wrote:
> Add a flag to indicate that __device_add_disk did grab a queue reference
> so that disk_release only drops it if we actually had it.  This sort
> out one of the major pitfals with partially initialized gendisk that
> a lot of drivers did get wrong or still do.
> 
> Signed-off-by: Christoph Hellwig 

Reviewed-by: Luis Chamberlain 

  Luis

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



[dm-devel] [PATCH -next] dm btree: make symbol 'shadow_child' static

2021-05-24 Thread Zou Wei
The sparse tool complains as follows:

drivers/md/persistent-data/dm-btree.c:696:5: warning:
 symbol 'shadow_child' was not declared. Should it be static?

This symbol is not used outside of dm-btree.c, so marks it static.

Reported-by: Hulk Robot 
Signed-off-by: Zou Wei 
---
 drivers/md/persistent-data/dm-btree.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/md/persistent-data/dm-btree.c 
b/drivers/md/persistent-data/dm-btree.c
index b8d21b6..a29bcb8 100644
--- a/drivers/md/persistent-data/dm-btree.c
+++ b/drivers/md/persistent-data/dm-btree.c
@@ -693,8 +693,10 @@ static int split_one_into_two(struct shadow_spine *s, 
unsigned parent_index,
  * child of the given parent node.  Making sure to update the parent to point
  * to the new shadow.
  */
-int shadow_child(struct dm_btree_info *info, struct dm_btree_value_type *vt,
-struct btree_node *parent, unsigned index, struct dm_block 
**result)
+static int shadow_child(struct dm_btree_info *info,
+   struct dm_btree_value_type *vt,
+   struct btree_node *parent,
+   unsigned index, struct dm_block **result)
 {
int r, inc;
dm_block_t root;
-- 
2.6.2

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



Re: [dm-devel] [PATCH 03/26] block: automatically enable GENHD_FL_EXT_DEVT

2021-05-24 Thread Luis Chamberlain
On Fri, May 21, 2021 at 07:50:53AM +0200, Christoph Hellwig wrote:
> Automatically set the GENHD_FL_EXT_DEVT flag for all disks allocated
> without an explicit number of minors.  This is what all new block
> drivers should do, so make sure it is the default without boilerplate
> code.
> 
> Signed-off-by: Christoph Hellwig 

Reviewed-by: Luis Chamberlain 

  Luis

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



[dm-devel] [PATCH][next] dm space maps: Fix uninitialized variable r2

2021-05-24 Thread Colin King
From: Colin Ian King 

In the case where recursing(mm) is true variable r2 is not
inintialized and an uninitialized value is being used in the
call combine_errors later on. Fix this by setting r2 to zero.

Addresses-Coverity: ("Uninitialized scalar variable")
Fixes: def6a7a9a7f0 ("dm space maps: improve performance with inc/dec on ranges 
of blocks")
Signed-off-by: Colin Ian King 
---
 drivers/md/persistent-data/dm-space-map-metadata.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c 
b/drivers/md/persistent-data/dm-space-map-metadata.c
index 3b70ee861cf5..5be5ef4c831f 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.c
+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
@@ -432,9 +432,10 @@ static int sm_metadata_dec_blocks(struct dm_space_map *sm, 
dm_block_t b, dm_bloc
int32_t nr_allocations;
struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
 
-   if (recursing(smm))
+   if (recursing(smm)) {
r = add_bop(smm, BOP_DEC, b, e);
-   else {
+   r2 = 0;
+   } else {
in(smm);
r = sm_ll_dec(>ll, b, e, _allocations);
r2 = out(smm);
-- 
2.31.1

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



[dm-devel] NAK: [PATCH][next] dm space maps: Fix uninitialized variable r2

2021-05-24 Thread Colin Ian King
On 21/05/2021 10:40, Colin King wrote:
> From: Colin Ian King 
> 
> In the case where recursing(mm) is true variable r2 is not
> inintialized and an uninitialized value is being used in the
> call combine_errors later on. Fix this by setting r2 to zero.
> 
> Addresses-Coverity: ("Uninitialized scalar variable")
> Fixes: def6a7a9a7f0 ("dm space maps: improve performance with inc/dec on 
> ranges of blocks")
> Signed-off-by: Colin Ian King 
> ---
>  drivers/md/persistent-data/dm-space-map-metadata.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c 
> b/drivers/md/persistent-data/dm-space-map-metadata.c
> index 3b70ee861cf5..5be5ef4c831f 100644
> --- a/drivers/md/persistent-data/dm-space-map-metadata.c
> +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
> @@ -432,9 +432,10 @@ static int sm_metadata_dec_blocks(struct dm_space_map 
> *sm, dm_block_t b, dm_bloc
>   int32_t nr_allocations;
>   struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
>  
> - if (recursing(smm))
> + if (recursing(smm)) {
>   r = add_bop(smm, BOP_DEC, b, e);
> - else {
> + r2 = 0;
> + } else {
>   in(smm);
>   r = sm_ll_dec(>ll, b, e, _allocations);
>   r2 = out(smm);
> 

There is a another occurrence of this, I'll send a V2 shortly

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