Commit 9c72bad1 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Mike Snitzer
Browse files

dm: call PR reserve/unreserve on each underlying device

So far we tried to rely on the SCSI 'all target ports' bit to register
all path, but for many setups this didn't work properly as the different
paths are seen as separate initiators to the target instead of multiple
ports of the same initiator.  Because of that we'll stop setting the
'all target ports' bit in SCSI, and let device mapper handle iterating
over the device for each path and register them manually.
Signed-off-by: default avatarChristoph Hellwig <>
Reviewed-by: default avatarMike Christie <>
Signed-off-by: default avatarMike Snitzer <>
parent 01f90dd9
...@@ -2521,26 +2521,76 @@ void dm_free_md_mempools(struct dm_md_mempools *pools) ...@@ -2521,26 +2521,76 @@ void dm_free_md_mempools(struct dm_md_mempools *pools)
kfree(pools); kfree(pools);
} }
static int dm_pr_register(struct block_device *bdev, u64 old_key, u64 new_key, struct dm_pr {
u32 flags) u64 old_key;
u64 new_key;
u32 flags;
bool fail_early;
static int dm_call_pr(struct block_device *bdev, iterate_devices_callout_fn fn,
void *data)
{ {
struct mapped_device *md = bdev->bd_disk->private_data; struct mapped_device *md = bdev->bd_disk->private_data;
const struct pr_ops *ops; struct dm_table *table;
fmode_t mode; struct dm_target *ti;
int r; int ret = -ENOTTY, srcu_idx;
r = dm_grab_bdev_for_ioctl(md, &bdev, &mode); table = dm_get_live_table(md, &srcu_idx);
if (r < 0) if (!table || !dm_table_get_size(table))
return r; goto out;
ops = bdev->bd_disk->fops->pr_ops; /* We only support devices that have a single target */
if (ops && ops->pr_register) if (dm_table_get_num_targets(table) != 1)
r = ops->pr_register(bdev, old_key, new_key, flags); goto out;
else ti = dm_table_get_target(table, 0);
bdput(bdev); ret = -EINVAL;
return r; if (!ti->type->iterate_devices)
goto out;
ret = ti->type->iterate_devices(ti, fn, data);
dm_put_live_table(md, srcu_idx);
return ret;
* For register / unregister we need to manually call out to every path.
static int __dm_pr_register(struct dm_target *ti, struct dm_dev *dev,
sector_t start, sector_t len, void *data)
struct dm_pr *pr = data;
const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops;
if (!ops || !ops->pr_register)
return ops->pr_register(dev->bdev, pr->old_key, pr->new_key, pr->flags);
static int dm_pr_register(struct block_device *bdev, u64 old_key, u64 new_key,
u32 flags)
struct dm_pr pr = {
.old_key = old_key,
.new_key = new_key,
.flags = flags,
.fail_early = true,
int ret;
ret = dm_call_pr(bdev, __dm_pr_register, &pr);
if (ret && new_key) {
/* unregister all paths if we failed to register any path */
pr.old_key = new_key;
pr.new_key = 0;
pr.flags = 0;
pr.fail_early = false;
dm_call_pr(bdev, __dm_pr_register, &pr);
return ret;
} }
static int dm_pr_reserve(struct block_device *bdev, u64 key, enum pr_type type, static int dm_pr_reserve(struct block_device *bdev, u64 key, enum pr_type type,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment