Skip to content

Commit 8dd87f3

Browse files
mikechristieMike Snitzer
authored andcommitted
dm: Allow dm_call_pr to be used for path searches
The specs state that if you send a reserve down a path that is already the holder success must be returned and if it goes down a path that is not the holder reservation conflict must be returned. Windows failover clustering will send a second reservation and expects that a device returns success. The problem for multipathing is that for an All Registrants reservation, we can send the reserve down any path but for all other reservation types there is one path that is the holder. To handle this we could add PR state to dm but that can get nasty. Look at target_core_pr.c for an example of the type of things we'd have to track. It will also get more complicated because other initiators can change the state so we will have to add in async event/sense handling. This commit, and the 3 commits that follow, tries to keep dm simple and keep just doing passthrough. This commit modifies dm_call_pr to be able to find the first usable path that can execute our pr_op then return. When dm_pr_reserve is converted to dm_call_pr in the next commit for the normal case we will use the same path for every reserve. Signed-off-by: Mike Christie <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent e120a5f commit 8dd87f3

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

drivers/md/dm.c

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,10 +3077,11 @@ struct dm_pr {
30773077
u64 new_key;
30783078
u32 flags;
30793079
bool fail_early;
3080+
int ret;
30803081
};
30813082

30823083
static int dm_call_pr(struct block_device *bdev, iterate_devices_callout_fn fn,
3083-
void *data)
3084+
struct dm_pr *pr)
30843085
{
30853086
struct mapped_device *md = bdev->bd_disk->private_data;
30863087
struct dm_table *table;
@@ -3105,7 +3106,8 @@ static int dm_call_pr(struct block_device *bdev, iterate_devices_callout_fn fn,
31053106
if (!ti->type->iterate_devices)
31063107
goto out;
31073108

3108-
ret = ti->type->iterate_devices(ti, fn, data);
3109+
ti->type->iterate_devices(ti, fn, pr);
3110+
ret = 0;
31093111
out:
31103112
dm_put_live_table(md, srcu_idx);
31113113
return ret;
@@ -3119,10 +3121,24 @@ static int __dm_pr_register(struct dm_target *ti, struct dm_dev *dev,
31193121
{
31203122
struct dm_pr *pr = data;
31213123
const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops;
3124+
int ret;
3125+
3126+
if (!ops || !ops->pr_register) {
3127+
pr->ret = -EOPNOTSUPP;
3128+
return -1;
3129+
}
3130+
3131+
ret = ops->pr_register(dev->bdev, pr->old_key, pr->new_key, pr->flags);
3132+
if (!ret)
3133+
return 0;
3134+
3135+
if (!pr->ret)
3136+
pr->ret = ret;
31223137

3123-
if (!ops || !ops->pr_register)
3124-
return -EOPNOTSUPP;
3125-
return ops->pr_register(dev->bdev, pr->old_key, pr->new_key, pr->flags);
3138+
if (pr->fail_early)
3139+
return -1;
3140+
3141+
return 0;
31263142
}
31273143

31283144
static int dm_pr_register(struct block_device *bdev, u64 old_key, u64 new_key,
@@ -3133,19 +3149,29 @@ static int dm_pr_register(struct block_device *bdev, u64 old_key, u64 new_key,
31333149
.new_key = new_key,
31343150
.flags = flags,
31353151
.fail_early = true,
3152+
.ret = 0,
31363153
};
31373154
int ret;
31383155

31393156
ret = dm_call_pr(bdev, __dm_pr_register, &pr);
3140-
if (ret && new_key) {
3141-
/* unregister all paths if we failed to register any path */
3142-
pr.old_key = new_key;
3143-
pr.new_key = 0;
3144-
pr.flags = 0;
3145-
pr.fail_early = false;
3146-
dm_call_pr(bdev, __dm_pr_register, &pr);
3157+
if (ret) {
3158+
/* Didn't even get to register a path */
3159+
return ret;
31473160
}
31483161

3162+
if (!pr.ret)
3163+
return 0;
3164+
ret = pr.ret;
3165+
3166+
if (!new_key)
3167+
return ret;
3168+
3169+
/* unregister all paths if we failed to register any path */
3170+
pr.old_key = new_key;
3171+
pr.new_key = 0;
3172+
pr.flags = 0;
3173+
pr.fail_early = false;
3174+
(void) dm_call_pr(bdev, __dm_pr_register, &pr);
31493175
return ret;
31503176
}
31513177

0 commit comments

Comments
 (0)