multipathd: Fix race while registering PR key
Benjamin Marzinski
maintainerPATCH v2 1/1 multipathd: Fix race while registering PR key
When libmpathpersist registers a key, It first checks which paths are active, then registers the key on those paths, and then tells multipathd that the key has been registered, and it should start tracking it. If a path comes up after libmpathpersist checks for active paths, but before it tells multipathd that the key has been registered, multipathd will not register a key no that path (since it hasn't been told to that the device has a registered key yet). This can leave the device with a path that is missing a key.
To solve this, when multipathd is told that a key has been registered, it checks if there are the same number of registered keys as active paths. If there aren't, it registers keys on all the paths (at least until the number of registered keys and active paths are equal). To avoid doing a bunch of unnecessary PR work, pr_register_active_paths() has a new option to track the number of active paths, and mpath_pr_event_handle() now takes the number of keys to expect. The first time it's called, when there is an unknown number of keys, if the number of keys it finds matches the number of active_paths, it and pr_register_active_paths() exit early, since there is no registering work to do.
---
Changes in v2:
- made update_map_pr() set nr_keys to 0 when it failed to get the keys or when it unset prflag (to fix a bug found by Martin Wilck)
multipathd/cli_handlers.c | 6 ++++- multipathd/main.c | 57 ++++++++++++++++++++++++++++----------- multipathd/main.h | 1 + 3 files changed, 48 insertions(+), 16 deletions(-)
multipathd/cli_handlers.c +5 -1
@@ -1291,7 +1291,11 @@ cli_setprstatus(void * v, struct strbuf *reply, void * data)if (mpp->prflag !=PR_SET ) {set_pr (mpp); -condlog (2 ,"%s: prflag set" , param); +pr_register_active_paths (mpp, true); +if (mpp->prflag ==PR_SET ) +condlog (2 ,"%s: prflag set" , param); +else +condlog (0 ,"%s: Failed to set prflag" , param); }memset (&mpp->old_pr_key,0 ,8 );
multipathd/main.c +42 -15
160 lines not on this page · raw message
multipathd/main.h +1 -0
@@ -54,4 +54,5 @@ int resize_map(struct multipath *mpp, unsigned long long size, struct vectors *vecs);void set_pr (struct multipath *mpp);void unset_pr (struct multipath *mpp); +void pr_register_active_paths (struct multipath *mpp,bool check_active_nr);#endif /* MAIN_H_INCLUDED */
Signature · 1 line
2.50.1
Quoted 29 lines · Benjamin Marzinski
When libmpathpersist registers a key, It first checks which paths are active, then registers the key on those paths, and then tells multipathd
that the key has been registered, and it should start tracking it. If a path comes up after libmpathpersist checks for active paths, but before
it tells multipathd that the key has been registered, multipathd will not
register a key no that path (since it hasn't been told to that the device
has a registered key yet). This can leave the device with a path that is
missing a key.To solve this, when multipathd is told that a key has been registered,
it checks if there are the same number of registered keys as active paths. If there aren't, it registers keys on all the paths (at least until the number of registered keys and active paths are equal). To avoid doing a bunch of unnecessary PR work,pr_register_active_paths()
has a new option to track the number of active paths, andmpath_pr_event_handle()now takes the number of keys to expect. The first time it's called, when there is an unknown number of keys, if the
number of keys it finds matches the number ofactive_paths, it andpr_register_active_paths()exit early, since there is no registering work to do.
Quoted 1 line
Signed-off-by Benjamin Marzinski <[email protected]>