Skip to contentSkip to conversation

dm mpath: Minor multipath related cleanup

PATCH In review Benjamin Marzinski 3 participants 7 messages Jan 28 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

cover dm mpath: Minor multipath related cleanup

This patchset fixes two minor bugs in creating multipath devices, and removes some dm locking that is no longer necessary after a change in the multipath code.

Benjamin Marzinski (3):
dm mpath: Add missing dm_put_device when failing to get scsi dh name Revert "dm: fix a race condition in retrieve_deps"
dm mpath: make pg_init_delay_msecs settable

 drivers/md/dm-core.h  |  1 -
 drivers/md/dm-ioctl.c |  7 +------
 drivers/md/dm-mpath.c | 22 +++++++++++-----------
 drivers/md/dm-table.c | 32 ++++++++------------------------
 4 files changed, 20 insertions(+), 42 deletions(-)
Signature · 1 line
2.50.1
author maintainer
#1 lore raw

PATCH 1/3 dm mpath: Add missing dm_put_device when failing to get scsi dh name

When commit fd81bc5cca8f ("scsi: device_handler: Return error pointer in scsi_dh_attached_handler_name()") added code to fail parsing the path if scsi_dh_attached_handler_name() failed with -ENOMEM, it didn't clean up the reference to the path device that had just been taken. Fix this, and steamline the error paths of parse_path() a little.

Fixes fd81bc5cca8f ("scsi: device_handler: Return error pointer in scsi_dh_attached_handler_name()")
---
 drivers/md/dm-mpath.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/md/dm-mpath.c +10 -10
index c748e7f952c4..6f9d86f4b912 100644
@@ -960,27 +960,27 @@ static struct pgpath *parse_path(struct dm_arg_set *as, struct path_selector *ps
 			attached_handler_name = NULL;
 		} else {
 			r = PTR_ERR(attached_handler_name);
-			goto bad;
+			ti->error = "error allocating handler name";
+			goto bad_put_device;
 		}
 	}
 	if (attached_handler_name || m->hw_handler_name) {
 		INIT_DELAYED_WORK(&p->activate_path, activate_path_work);
 		r = setup_scsi_dh(p->path.dev->bdev, m, &attached_handler_name, &ti->error);
 		kfree(attached_handler_name);
-		if (r) {
-			dm_put_device(ti, p->path.dev);
-			goto bad;
-		}
+		if (r)
+			goto bad_put_device;
 	}
 
 	r = ps->type->add_path(ps, &p->path, as->argc, as->argv, &ti->error);
-	if (r) {
-		dm_put_device(ti, p->path.dev);
-		goto bad;
-	}
+	if (r)
+		goto bad_put_device;
 
 	return p;
- bad:
+
+bad_put_device:
+	dm_put_device(ti, p->path.dev);
+bad:
 	free_pgpath(p);
 	return ERR_PTR(r);
 }
Signature · 1 line
2.50.1
author maintainer
#2 lore raw

PATCH 2/3 Revert "dm: fix a race condition in retrieve_deps"

In reply to Benjamin Marzinski

This reverts commit f6007dce0cd35d634d9be91ef3515a6385dcee16.

Commit f6007dce0cd3 ("dm: fix a race condition in retrieve_deps") was added to fix a race between retrieving the list of dm table devices and multipath_message() modifying the list of table devices. But Commit a48f6b82c5c4 ("dm mpath: don't call dm_get_device in multipath_message") removed the call to dm_get_device() from multipath_message(). After that commit, the only calls to dm_get_device() and dm_put_device() are in target constructors and destructors, so the race with retrieve_deps() is no longer possible.

---
 drivers/md/dm-core.h  |  1 -
 drivers/md/dm-ioctl.c |  7 +------
 drivers/md/dm-table.c | 32 ++++++++------------------------
 3 files changed, 9 insertions(+), 31 deletions(-)
drivers/md/dm-core.h +0 -1
index 1cda8618d74d..a3b8ad6e1c42 100644
@@ -215,7 +215,6 @@ struct dm_table {
 
 	/* a list of devices used by this table */
 	struct list_head devices;
-	struct rw_semaphore devices_lock;
 
 	/* events get handed up using this callback */
 	void (*event_fn)(void *data);
drivers/md/dm-ioctl.c +1 -6
index 4165fef4c170..fd4bf8e1d73e 100644
@@ -1648,8 +1648,6 @@ static void retrieve_deps(struct dm_table *table,
 	struct dm_dev_internal *dd;
 	struct dm_target_deps *deps;
 
-	down_read(&table->devices_lock);
-
 	deps = get_result_buffer(param, param_size, &len);
 
 	/*
@@ -1664,7 +1662,7 @@ static void retrieve_deps(struct dm_table *table,
 	needed = struct_size(deps, dev, count);
 	if (len < needed) {
 		param->flags |= DM_BUFFER_FULL_FLAG;
-		goto out;
+		return;
 	}
 
 	/*
@@ -1676,9 +1674,6 @@ static void retrieve_deps(struct dm_table *table,
 		deps->dev[count++] = huge_encode_dev(dd->dm_dev->bdev->bd_dev);
 
 	param->data_size = param->data_start + needed;
-
-out:
-	up_read(&table->devices_lock);
 }
 
 static int table_deps(struct file *filp, struct dm_ioctl *param, size_t param_size)
drivers/md/dm-table.c +8 -24
index 4b70872725d0..7be1d8dc8bdd 100644
@@ -139,7 +139,6 @@ int dm_table_create(struct dm_table **result, blk_mode_t mode,
 		return -ENOMEM;
 
 	INIT_LIST_HEAD(&t->devices);
-	init_rwsem(&t->devices_lock);
 
 	if (!num_targets)
 		num_targets = KEYS_PER_NODE;
@@ -380,20 +379,16 @@ int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode,
 	if (dev == disk_devt(t->md->disk))
 		return -EINVAL;
 
-	down_write(&t->devices_lock);
-
 	dd = find_device(&t->devices, dev);
 	if (!dd) {
 		dd = kmalloc(sizeof(*dd), GFP_KERNEL);
-		if (!dd) {
-			r = -ENOMEM;
-			goto unlock_ret_r;
-		}
+		if (!dd)
+			return -ENOMEM;
 
 		r = dm_get_table_device(t->md, dev, mode, &dd->dm_dev);
 		if (r) {
 			kfree(dd);
-			goto unlock_ret_r;
+			return r;
 		}
 
 		refcount_set(&dd->count, 1);
@@ -403,17 +398,12 @@ int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode,
 	} else if (dd->dm_dev->mode != (mode | dd->dm_dev->mode)) {
 		r = upgrade_mode(dd, mode, t->md);
 		if (r)
-			goto unlock_ret_r;
+			return r;
 	}
 	refcount_inc(&dd->count);
 out:
-	up_write(&t->devices_lock);
 	*result = dd->dm_dev;
 	return 0;
-
-unlock_ret_r:
-	up_write(&t->devices_lock);
-	return r;
 }
 EXPORT_SYMBOL(dm_get_device);
 
@@ -464,12 +454,9 @@ static int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
 void dm_put_device(struct dm_target *ti, struct dm_dev *d)
 {
 	int found = 0;
-	struct dm_table *t = ti->table;
-	struct list_head *devices = &t->devices;
+	struct list_head *devices = &ti->table->devices;
 	struct dm_dev_internal *dd;
 
-	down_write(&t->devices_lock);
-
 	list_for_each_entry(dd, devices, list) {
 		if (dd->dm_dev == d) {
 			found = 1;
@@ -478,17 +465,14 @@ void dm_put_device(struct dm_target *ti, struct dm_dev *d)
 	}
 	if (!found) {
 		DMERR("%s: device %s not in table devices list",
-		      dm_device_name(t->md), d->name);
-		goto unlock_ret;
+		      dm_device_name(ti->table->md), d->name);
+		return;
 	}
 	if (refcount_dec_and_test(&dd->count)) {
-		dm_put_table_device(t->md, d);
+		dm_put_table_device(ti->table->md, d);
 		list_del(&dd->list);
 		kfree(dd);
 	}
-
-unlock_ret:
-	up_write(&t->devices_lock);
 }
 EXPORT_SYMBOL(dm_put_device);
 
Signature · 1 line
2.50.1
author maintainer
#3 lore raw

PATCH 3/3 dm mpath: make pg_init_delay_msecs settable

In reply to Benjamin Marzinski

"pg_init_delay_msecs X" can be passed as a feature in the multipath table and is used to set m->pg_init_delay_msecs in parse_features(). However, alloc_multipath_stage2(), which is called after parse_features(), resets m->pg_init_delay_msecs to its default value. Instead, set m->pg_init_delay_msecs in alloc_multipath(), which is called before parse_features(), to avoid overwriting a value passed in by the table.

---
 drivers/md/dm-mpath.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-mpath.c +1 -1
index 6f9d86f4b912..de03f9b06584 100644
@@ -225,6 +225,7 @@ static struct multipath *alloc_multipath(struct dm_target *ti)
 		mutex_init(&m->work_mutex);
 
 		m->queue_mode = DM_TYPE_NONE;
+		m->pg_init_delay_msecs = DM_PG_INIT_DELAY_DEFAULT;
 
 		m->ti = ti;
 		ti->private = m;
@@ -251,7 +252,6 @@ static int alloc_multipath_stage2(struct dm_target *ti, struct multipath *m)
 	set_bit(MPATHF_QUEUE_IO, &m->flags);
 	atomic_set(&m->pg_init_in_progress, 0);
 	atomic_set(&m->pg_init_count, 0);
-	m->pg_init_delay_msecs = DM_PG_INIT_DELAY_DEFAULT;
 	init_waitqueue_head(&m->pg_init_wait);
 	init_waitqueue_head(&m->probe_wait);
 
Signature · 1 line
2.50.1
#4 lore raw

Re: [PATCH 3/3] dm mpath: make pg_init_delay_msecs settable

Quoted 10 lines · Benjamin Marzinski

"pg_init_delay_msecs X" can be passed as a feature in the multipath table and is used to set m->pg_init_delay_msecs in parse_features(). However, alloc_multipath_stage2(), which is called after parse_features(), resets m->pg_init_delay_msecs to its default value. Instead, set m->pg_init_delay_msecs in alloc_multipath(), which is called before parse_features(), to avoid overwriting a value passed in
by the table.

Fixes 848b8aefd44d ("dm mpath: optimize NVMe bio-based support")

?

Reviewed-by on the v1 series
#5 lore raw
In reply to Benjamin Marzinski
Quoted 11 lines · Benjamin Marzinski

This patchset fixes two minor bugs in creating multipath devices, and removes some dm locking that is no longer necessary after a change in the
multipath code.

Benjamin Marzinski (3):
  dm mpath: Add missing dm_put_device when failing to get scsi dh name
  Revert "dm: fix a race condition in retrieve_deps"
  dm mpath: make pg_init_delay_msecs settable

Quoted 5 lines

 drivers/md/dm-core.h  |  1 -

 drivers/md/dm-ioctl.c |  7 +------
 drivers/md/dm-mpath.c | 22 +++++++++++-----------
 drivers/md/dm-table.c | 32 ++++++++------------------------
 4 files changed, 20 insertions(+), 42 deletions(-)
maintainer
#6 lore raw
In reply to Benjamin Marzinski
Quoted 9 lines · Benjamin Marzinski

This patchset fixes two minor bugs in creating multipath devices, and removes some dm locking that is no longer necessary after a change in the multipath code.

Benjamin Marzinski (3):
dm mpath: Add missing dm_put_device when failing to get scsi dh name Revert "dm: fix a race condition in retrieve_deps"
dm mpath: make pg_init_delay_msecs settable

Quoted 8 lines
 drivers/md/dm-core.h  |  1 -
 drivers/md/dm-ioctl.c |  7 +------
 drivers/md/dm-mpath.c | 22 +++++++++++-----------
 drivers/md/dm-table.c | 32 ++++++++------------------------
 4 files changed, 20 insertions(+), 42 deletions(-)
Signature · 1 line
2.50.1

Hi

I accepted all three patches. I added Cc: [email protected] to patch 1 and 3.

Mikulas