report: improve lv_active_remotely and lv_active_exclusively for shared VGs
cover report: improve lv_active_remotely and lv_active_exclusively for shared VGs
Hello,
following a recent conversation [0] on the linux-lvm mailing list, this patchset aims to improve the lv_active_remotely and lv_active_exclusively report options so they accurately represent the actual state for LVs in shared VGs using lvmlockd.
I implemented the proposed changes using lvmlockd-client.h, and peeked at _query_lv_lock(...) and lvmlockctl.c to get an idea how to query lvmlockd for lock modes of specific LVs. I also tested them to the best of my abilities, and are quiet satisfied with the end-result as seen below.
``` root at node1:~# vgchange --lock-start root at node1:~# lvchange -ay 'my-local-vg/used-lv' root at node1:~# lvchange -aey 'my-shared-vg/node1-exclusive-lv' root at node1:~# lvchange -asy 'my-shared-vg/shared-but-only-node1-lv' root at node1:~# lvchange -asy 'my-shared-vg/shared-on-both-lv' root at node1:~# lvs -a -o 'vg_name,vg_shared,vg_lock_type,vg_lock_args,lv_name,lv_uuid,lv_active,lv_active_locally,lv_active_remotely,lv_active_exclusively,lv_lockargs' VG Shared LockType VLockArgs LV LV UUID Active ActLocal ActRemote ActExcl LLockArgs my-local-vg used-lv bPQnVM-5tvh-zXm2-1SV3-sqSb-FqTN-pk0g6q active active locally active exclusively my-local-vg unused-lv B9zzl2-k2PV-P1tR-WStf-nfme-gvIi-ij5Jzg my-shared-vg shared sanlock 1.0.0:lvmlock [lvmlock] 2Iuwpm-TA9H-0JSA-EmeS-PaZX-oCzU-jo3X7h active active locally unknown my-shared-vg shared sanlock 1.0.0:lvmlock node1-exclusive-lv TDFv2h-gYnZ-dkj4-kAVx-tkCR-gCvf-fXgDK7 active active locally unknown active exclusively 1.0.0:70254592 my-shared-vg shared sanlock 1.0.0:lvmlock node2-exclusive-lv Pjhy72-Ah71-lPac-mC1f-FH4h-yXYx-JoplUH unknown 1.0.0:71303168 my-shared-vg shared sanlock 1.0.0:lvmlock shared-but-only-node1-lv qPVTYt-YGP0-X7kr-afGJ-8PyG-vS1p-FGWQLf active active locally unknown 1.0.0:72351744 my-shared-vg shared sanlock 1.0.0:lvmlock shared-but-only-node2-lv 0mfufn-JJDI-IoVm-dyUf-soWa-Wy4G-TcGnbe unknown 1.0.0:73400320 my-shared-vg shared sanlock 1.0.0:lvmlock shared-on-both-lv DPsQl2-6pqd-ZUTM-plv6-qR4w-VSZv-6mRwBr active active locally unknown 1.0.0:74448896 my-shared-vg shared sanlock 1.0.0:lvmlock unused-lv 96X21r-Zm2Z-O2gp-hWVw-ryCb-y6JV-QYQOBk unknown 1.0.0:75497472 root at node1:~# lvmlockctl --info --dump | grep 'type=lv' info=r name=TDFv2h-gYnZ-dkj4-kAVx-tkCR-gCvf-fXgDK7 type=lv mode=ex sh_count=0 version=0 info=r name=Pjhy72-Ah71-lPac-mC1f-FH4h-yXYx-JoplUH type=lv mode=un sh_count=0 version=0 info=r name=qPVTYt-YGP0-X7kr-afGJ-8PyG-vS1p-FGWQLf type=lv mode=sh sh_count=1 version=0 info=r name=0mfufn-JJDI-IoVm-dyUf-soWa-Wy4G-TcGnbe type=lv mode=un sh_count=0 version=0 info=r name=DPsQl2-6pqd-ZUTM-plv6-qR4w-VSZv-6mRwBr type=lv mode=sh sh_count=1 version=0 info=r name=96X21r-Zm2Z-O2gp-hWVw-ryCb-y6JV-QYQOBk type=lv mode=un sh_count=0 version=0 info=r name=2Iuwpm-TA9H-0JSA-EmeS-PaZX-oCzU-jo3X7h type=lv mode=un sh_count=0 version=0 ```
One thing I noticed is that lvmlockctl --info now shows a row for the sanlock lvmlock LV with no lock, which it didn't before. I assume this is created/triggered by the query for that LV.
Thanks to David Teigland for his guidance.
[0] https://listman.redhat.com/archives/linux-lvm/2022-October/026293.html
----
Greetings
Corubba
PATCH 1/2 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.
--- 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 2/2 report: query lvmlockd for lv_active_exclusively
In reply to corubbaAdjusted 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.
The lvmlockd socket is opened and closed for every query. This may pose a performance bottleneck, and could be optimised by lazy-opening it once when needed for the first time, and closing it once after all LVs are done.
--- lib/report/report.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
lib/report/report.c +56 -0
@@ -25,6 +25,8 @@#include "lib/device/device-types.h" #include "lib/datastruct/str_list.h" +#include "daemons/lvmlockd/lvmlockd-client.h" +#include <stddef.h> /* offsetof() */ #include <float.h> /* DBL_MAX */ #include <time.h>
@@ -3849,6 +3851,55 @@ static int _lvactiveremotely_disp(struct dm_report *rh, struct dm_pool *mem,return _binary_disp (rh, mem, field, active_remotely,GET_FIRST_RESERVED_NAME (lv_active_remotely_y), private); } +/* Returns 0 on success, 1 on error. */ +static int _lvactiveexclusively_lvmlockd (const struct logical_volume *lv,int *active_exclusively) +{ +int ret =0 ; +daemon_handle lvmlockd; +daemon_reply reply; +const char *reply_str =NULL ; + +log_debug ("lvmlockd query_lock_lv %s/%s" , lv->vg->name, lv->name); + + lvmlockd =lvmlockd_open (NULL ); +if (lvmlockd.socket_fd <0 || lvmlockd.error) { +log_error ("Cannot connect to lvmlockd." ); +return 1 ; + } + + reply =daemon_send_simple (lvmlockd, +"query_lock_lv" , +"pid = " FMTd64, (int64_t )getpid (), +"opts = %s" ,"none" , +"vg_name = %s" , lv->vg->name, +"lv_name = %s" , lv->name, +"lv_uuid = %s" ,lv_uuid_dup (NULL , lv), +"vg_lock_type = %s" , lv->vg->lock_type, +"vg_lock_args = %s" , lv->vg->lock_args, +"lv_lock_args = %s" , lv->lock_args, +NULL ); + +if (reply.error) { +log_error ("reply error %d" , reply.error); + ret =1 ; + } + +if (!ret) + reply_str =daemon_reply_str (reply,"mode" ,NULL ); +if (!ret && !reply_str) { +log_error ("query_lock_lv mode not returned" ); + ret =1 ; + }else if (!ret) { +log_debug ("query_lock_lv result mode %s" , reply_str); + *active_exclusively =strcmp (reply_str,"ex" ) ?0 :1 ; + } + +daemon_reply_destroy (reply); +lvmlockd_close (lvmlockd); + +return ret; +} +static int _lvactiveexclusively_disp (struct dm_report *rh,struct dm_pool *mem,struct dm_report_field *field,const void *data,void *private)
@@ -3861,6 +3912,11 @@ static int _lvactiveexclusively_disp(struct dm_report *rh, struct dm_pool *mem, active_exclusively =lv_is_active (lv); +if (active_exclusively &&vg_is_shared (lv->vg)) { +if (_lvactiveexclusively_lvmlockd (lv, &active_exclusively)) +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