report: adjust lv_active_remotely for shared VGs
PATCH v2 1/3 report: adjust lv_active_remotely for shared VGs
Add a note to the manpage that lvmlockd is unable to determine accurately and without side-effects whether a LV is remotely active. Also change the value of the lv_active_remotely option from false to undefined for shared VGs to distinctly communicate that inability to users. Only for local VGs it can be definitely stated that they are not remotely active.
---
v2: No change, the same as v1.
lib/report/report.c | 3 ++- man/lvmlockd.8_main | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-)
lib/report/report.c +2 -1
@@ -3838,9 +3838,10 @@ static int _lvactiveremotely_disp(struct dm_report *rh, struct dm_pool *mem,struct dm_report_field *field, const void *data, void *private) { + const struct logical_volume *lv = (const struct logical_volume *) data;int active_remotely; -if (!activation ()) +if (!activation () ||vg_is_shared (lv->vg))return _binary_undef_disp (rh, mem, field, private); active_remotely =0 ;
man/lvmlockd.8_main +4 -0
@@ -878,6 +878,10 @@ If lvmlockd fails or is killed while in use, locks it held remain but are orphaned in the lock manager. lvmlockd can be restarted with an option to adopt the orphan locks from the previous instance of lvmlockd. . +.IP \[bu] +The 'lvs' command does not report any remote state, because lvmlockd is +unable to passively check the remote active or lock state of an LV. +. .SH SEE ALSO . .BR lvm (8),
--
2.38.1
PATCH v2 2/3 report: query lvmlockd for lv_active_exclusively
Adjusted the lv_active_exclusively option to account for shared VGs.
A LV is definitely not exclusively active if:
- it is not (locally) active, regardless of whether it is in a local or shared VG.
- it is in a shared VG, locally active, and lvmlockd reports a non-exclusive lock (e.g. shared lock or no lock at all).
A LV is definitely exclusively active if:
- it is in a local VG, and (locally) active.
- it is in a shared VG, locally active, and lvmlockd reports a exclusive lock.
The "exclusively active" state of a LV is undefined if:
- it is in a shared VG, locally active, and lvmlockd can't be reached or responds with an error.
For the sanlock lvmlock LV, lvmlockd reports no lock and it is thus shown as not exclusively active.
---
v2: Rename and use the existing _query_lock_lv(...) function instead of
reimplementing the whole lvmlockd communication.
lib/locking/lvmlockd.c | 7 +++---- lib/locking/lvmlockd.h | 9 +++++++++ lib/report/report.c | 10 +++++++++- 3 files changed, 21 insertions(+), 5 deletions(-)
lib/locking/lvmlockd.c +3 -4
@@ -2298,9 +2298,8 @@ int lockd_vg_update(struct volume_group *vg)return ret; } -static int _query_lock_lv (struct cmd_context *cmd,struct volume_group *vg, -const char *lv_name,char *lv_uuid, -const char *lock_args,int *ex,int *sh) +int lockd_query_lv (struct volume_group *vg,const char *lv_name,char *lv_uuid, +const char *lock_args,int *ex,int *sh) {daemon_reply reply;const char *opts =NULL ;
@@ -2386,7 +2385,7 @@ int lockd_lv_name(struct cmd_context *cmd, struct volume_group *vg, !strcmp(cmd->name, "lvchange") || !strcmp(cmd->name, "lvconvert")) {int ex =0 , sh =0 ; -if (!_query_lock_lv (cmd, vg, lv_name, lv_uuid, lock_args, &ex, &sh)) +if (!lockd_query_lv (vg, lv_name, lv_uuid, lock_args, &ex, &sh))return 1 ;if (sh) {log_warn ("WARNING: shared LV may require refresh on other hosts where it is active." );
lib/locking/lvmlockd.h +9 -0
@@ -103,6 +103,9 @@ int lockd_lv_uses_lock(struct logical_volume *lv);int lockd_lv_refresh (struct cmd_context *cmd,struct lvresize_params *lp); +int lockd_query_lv (struct volume_group *vg,const char *lv_name,char *lv_uuid, +const char *lock_args,int *ex,int *sh); +#else /* LVMLOCKD_SUPPORT */ static inline void lvmlockd_set_socket (const char *sock)
@@ -258,6 +261,12 @@ static inline int lockd_lv_refresh(struct cmd_context *cmd, struct lvresize_parareturn 0 ; } +static inline int lockd_query_lv (struct volume_group *vg,const char *lv_name, +char *lv_uuid,const char *lock_args,int *ex,int *sh) +{ +return 0 ; +} +#endif /* LVMLOCKD_SUPPORT */ #endif /* _LVMLOCKD_H */
lib/report/report.c +9 -1
@@ -24,6 +24,7 @@#include "lib/cache/lvmcache.h" #include "lib/device/device-types.h" #include "lib/datastruct/str_list.h" +#include "lib/locking/lvmlockd.h" #include <stddef.h> /* offsetof() */ #include <float.h> /* DBL_MAX */
@@ -3854,13 +3855,20 @@ static int _lvactiveexclusively_disp(struct dm_report *rh, struct dm_pool *mem, const void *data, void *private) { const struct logical_volume *lv = (const struct logical_volume *) data; -int active_exclusively; +int active_exclusively, _sh =0 ;if (!activation ())return _binary_undef_disp (rh, mem, field, private); active_exclusively =lv_is_active (lv); +if (active_exclusively &&vg_is_shared (lv->vg)) { + active_exclusively =0 ; +if (!lockd_query_lv (lv->vg, lv->name,lv_uuid_dup (NULL , lv), + lv->lock_args, &active_exclusively, &_sh)) +return _binary_undef_disp (rh, mem, field, private); + } +return _binary_disp (rh, mem, field, active_exclusively,GET_FIRST_RESERVED_NAME (lv_active_exclusively_y), private); }
--
2.38.1
PATCH v2 3/3 lvmlockd: Improve error handling
In certain error cases the request to lvmlockd is send using a uninitialized lvmlockd handle and its socket_fd 0, resulting in the request payload being printed to stdout and then blocking the process waiting to read the response from stdout. This is fixed by setting the socket_fd and error members to values that trigger existing guards.
To prevent redundant and unnecessary error output, a short-circuit is added to the send function.
---
v2: New commit, not part of v1.
lib/locking/lvmlockd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
lib/locking/lvmlockd.c +7 -1
@@ -88,8 +88,11 @@ void lvmlockd_connect(void)log_error ("lvmlockd is already connected." ); } -if (_lvmlockd_init_failed) +if (_lvmlockd_init_failed) { + _lvmlockd.socket_fd =-1 ; + _lvmlockd.error =-1 ;return ; + } _lvmlockd =lvmlockd_open (_lvmlockd_socket);
@@ -195,6 +198,9 @@ static daemon_reply _lockd_send_with_pvs(const char *req_name, req =daemon_request_make (req_name); +if (!_lvmlockd_connected) + goto bad; +va_start (ap, lock_pvs);daemon_request_extend_v (req, ap);va_end (ap);
--
2.38.1