1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00
Commit Graph

1291 Commits

Author SHA1 Message Date
Zdenek Kabelac
b1215b7f8c lvmlockd: enforce 64bit arithmetic
Coverity suggest to stay on the 'safe' side and widen operators early
so 64bit offset is made from 64bit arithmentic.
2015-11-09 17:04:10 +01:00
Zdenek Kabelac
d6767d753f lvmlockd: add missing error checks
Detect error from function and report them.
2015-11-09 17:04:10 +01:00
Zdenek Kabelac
c2d5cfbdb8 cleanup: use _ for local function 2015-11-09 17:04:10 +01:00
Zdenek Kabelac
3db5ba08b1 cleanup: drop unneded headers
Coverity notices they are not really needed.
2015-11-09 17:04:10 +01:00
Zdenek Kabelac
32762e2a9c libdaemon: fix passing 32bit values for %d
Since %d is now prohibited for its great confusion,
replace it with  FMTd64 and correctly converted int64_t
parameter.
2015-11-09 17:04:10 +01:00
David Teigland
e207ededd6 lvmlockd: shut up warnings 2015-11-09 10:00:04 -06:00
Zdenek Kabelac
0b5a75c9af lvmetad: restore use of FMTd64
daemon_reply_simple() eats just 64bit numbers - so make it explicit.
2015-11-09 14:02:27 +01:00
Zdenek Kabelac
5aae8de776 lvmetad: maintain seqno as int
Keep seqno as 32bit value.
Also use '_' prefix for local _update_metadata.
2015-11-09 12:21:17 +01:00
Zdenek Kabelac
b1dab26be0 cleanup: coverity quiet
While through all codepaths we never 'read' lock_id unless LCKF_CONVERT,
coverity cannot decrypt this.

As since it's usually better to pass in 'well-defined' data structures
preset lock_id to 0.
2015-11-09 10:22:52 +01:00
Zdenek Kabelac
11151121aa cleanup: use fputs for plain strings
Use fputs() when printing plain string,
easier then fprintf which needs to parse it.

Also check fd before close is >= 0 -
it is - but coverity fail to see it, so eliminate
this false-positive warning.
2015-11-09 10:22:52 +01:00
Zdenek Kabelac
c4c5635870 cleanup: drop unneeded assign
prio is always assigned later.
2015-11-09 10:22:52 +01:00
Zdenek Kabelac
99def8f439 lvmetad: check for pointers not NULL
Check for  arg_vgid_lookup and arg_name_lookup not being NULL.
Drop checking arg_vgid and arg_name for NULL since they
are already dereference earlier - thus mostly must be NOT NULL.

(If that would be possible larger rework of this function would be
required).
2015-11-09 10:19:19 +01:00
Zdenek Kabelac
f66fe2c444 lvmetad: require meta_lookup
Coverity: do not call update_pvid_to_vgid() with
meta_lookup == NULL since it is dereferencing it.
2015-11-09 10:19:19 +01:00
Zdenek Kabelac
91bde0f4a1 lvmetad: check for allocation fail
Coverity: missing check for root != NULL as this pointer is
later dereferenced in add_last_node().
2015-11-09 10:19:19 +01:00
Zdenek Kabelac
9df3069083 clvmd: check for pthread_create status
Coverity: likes to see checked function result.
2015-11-09 10:19:18 +01:00
Zdenek Kabelac
2c8d6f5c90 dmeventd: open fifo in one function
Put calls related to fifo opening into a single function.

Fix  Time-Of-Check-Time-Of-Use and use fstat()
and fchmod() on already opened fd instead of
checking first path and then risking to open something
different.
2015-11-09 10:18:53 +01:00
Zdenek Kabelac
e1b111b02a dmeventd: reorder tou 2015-11-09 10:00:33 +01:00
Zdenek Kabelac
8b857bfdc6 libdevmapper-event: fix fifo leak on error path
Coverity: when _init_client() fails, client fifo could have
been already openned and needs to be closed on error path.
2015-11-09 10:00:13 +01:00
David Teigland
4e6377f5ba lvmetad: refactor and document
update_metadata and pv_found update the cached metadata;
these are both reworked to improve the code, organize it
by each possible state and transition, make it much more
clear what's changing, add more error checking and
handling, and add comments.

The state and content of the cache (hash tables) does not
change (apart from some things that didn't work before),
and the communication to/from commands does not change.
The implementation and organization of the code making
the state changes does change significantly.

One detail related to the content of the cache does change:
different hash tables do not reference the same memory any more;
the target values in each hash table are allocated and freed
individually.
2015-11-03 13:18:27 -06:00
Zdenek Kabelac
099466939e thin: dmeventd plugin check number of failures
If plugin's lvm command execution fails too often (>10 times),
there is no point to torture system more then necessary, just log
and drop monitoring in this case.
2015-10-29 12:14:20 +01:00
Zdenek Kabelac
5d76bdcdbd dmeventd: event string parser handles empty field
Improve event string parser to avoid unneeded alloc+free.

Daemon talk function uses '-' to mark NULL/missing field.
So restore the NULL pointer back on parser.

This should have made old tools like 'dmevent_tool' work again.
As now 'uuid' or 'dso' could become NULL and then be
properly used in _want_registered_device() function.

Since lvm2 always fill these parameters, this change should
have no effect on lvm2.
2015-10-27 11:42:40 +01:00
Zdenek Kabelac
b702d67747 dmevent: fix referencing
Plugin increments DSO refcounter in _alloc_thread_status().
2015-10-26 23:31:23 +01:00
Zdenek Kabelac
1a7bea0f0f cleanup: drop debug 2015-10-23 10:54:13 +02:00
Zdenek Kabelac
b5b2a54834 cleanup: fix gcc compile with older pthread
Older pthread library was missing 'trick'
in pthread_cleanup_pop() which lead to
compilation error:

error: label at end of compound statement

Use explicit ';' to fix it.
2015-10-23 10:54:13 +02:00
Zdenek Kabelac
87a39d8bac dmeventd: ensure filter is empty
On some error path we could have left filter set to some value.
Not a big issue - but lets make reporting correct as soon
as we can.
2015-10-23 10:54:13 +02:00
Zdenek Kabelac
cff1c728d8 dmeventd: debug error paths 2015-10-23 10:54:13 +02:00
Zdenek Kabelac
1a2d0a0c72 cleanup: indents 2015-10-22 22:46:10 +02:00
Zdenek Kabelac
8be60e6a65 cleanup: easier to read code
Avoid using #ifdef code and use 'cmd' instead of 'die'.
2015-10-22 22:46:10 +02:00
Zdenek Kabelac
2af696c32f dmeventd: exit on idle
Implementing exit when 'dmeventd' is idle.
Default idle timeout set to 1 hour - after this time period
dmeventd will cleanly exit.

On systems with 'systemd' - service is automatically started with
next contact on dmeventd communication socket/fifo.

On other systems - new dmeventd starts again when lvm2 command detects
its missing and monitoring is needed.
2015-10-22 22:43:03 +02:00
Zdenek Kabelac
4284ba65eb dmeventd: debug signals 2015-10-22 22:41:12 +02:00
Zdenek Kabelac
aeec62ad19 dmeventd: snapshot plugin unmonitor
Send signal to itself to mark plugin as 'finished' as
the watching rule is no longer usable.
2015-10-22 22:41:12 +02:00
Zdenek Kabelac
12aa56d298 dmeventd: handle signal from plugin
Add support to unmonitor device when monitor recognizes there is
nothing to monitor anymore.

TODO: possibly API change with return value could be also used.
2015-10-22 22:40:07 +02:00
Zdenek Kabelac
9156c5d088 dmeventd: rework locking code
Redesign threading code:

- plugin registration runs within its new created thread for
  improved parallel usage.

- wait task is created just once and used during whole plugin lifetime.

- event thread is based over  'events' filter being set - when
  filter is 0, such thread is 'unused'.

- event loop is  simplified.

- timeout thread is never signaling 'processing' thread.

- pending of events filter cnange is properly reported and
  running event thread is signalled when possible.

- helgrind is not reporting problems.
2015-10-22 22:39:24 +02:00
Zdenek Kabelac
466a1c72b7 cleanup: use enums 2015-10-22 22:36:00 +02:00
Zdenek Kabelac
81e9ab3156 dmeventd: code mode _get_device_status
Move _get_device_status() in code.
Use dm_task_no_flush() function when reading status.
(e.g. none blocking for thins pool)
2015-10-22 22:35:25 +02:00
Zdenek Kabelac
15dbd4b56a dmeventd: minimize locking time for get_imeout
Don't hold lock when creating message (allocating memory).
Thread cannot dissapear as it's only the same thread which
may clean it.
2015-10-22 22:34:30 +02:00
Zdenek Kabelac
e2ea2a8147 dmeventd: drop unneded test
Function is never called without device.uuid.
2015-10-22 22:34:29 +02:00
Zdenek Kabelac
941c6354db dmeventd: wake up timer when setting new timeout 2015-10-22 22:34:29 +02:00
Zdenek Kabelac
02eb000f51 dmeventd: use dm_hold_control_dev
Need here to keep  control device opened while there is 'any' dso
plugin loaded - otherwise there would a race closing controlfd
inside lvm2 plugin while some other monitoring thread would
tried to execute another WAITEVENT task.
2015-10-22 22:34:27 +02:00
Zdenek Kabelac
efc76ca33d dmeventd: move dso handling into single code section
Move all DSO related function in front, so they could be easily
referenced from rest of code.

Add proper error paths with logging and error reporting.

Drop mutex locking when releasing DSO - since DSO is always
allocated and released in main 'event' processing thread.
2015-10-22 22:33:19 +02:00
Zdenek Kabelac
590091a4fa dmeventd: using warning level
When dmevend notices problems, but continues to operate normally
change log level to warning.
2015-10-22 22:33:19 +02:00
Zdenek Kabelac
9488cbdd0b dmeventd: no registering of 0 event mask
Whenever user tries to register 0 mask report this as EINVAL.
2015-10-22 22:33:19 +02:00
Zdenek Kabelac
fa9e41d2e3 dmeventd: thin plugin update
Use  dm_make_percent for percentage calculation like lvm2 command.

Use a single call for resize.
2015-10-22 22:33:07 +02:00
Zdenek Kabelac
6b0bc5b2d9 dmeventd: snapshot plugin device removal
Add #ifdef-ed code to have ability to even remove unusable device.
For now purely experimental.
2015-10-22 22:29:53 +02:00
Zdenek Kabelac
7ff5b03e5e dmeventd: snapshot plugin updates
Improve test for invalid snapshot.

Use dm_make_percent() to manipulate with exactly same percentage
as lvm2 command is using.
2015-10-22 22:29:50 +02:00
Zdenek Kabelac
91350f5c6a dmeventd: mirror plugin update
Don't use  --config  - this requires reload of lvm.conf
2015-10-22 22:28:37 +02:00
Zdenek Kabelac
9c5c9e2355 dmeventd: raid plugin reporting
Fix raid logging introduced with last updating commit.
2015-10-22 22:28:37 +02:00
Zdenek Kabelac
cde12cbe9e dmeventd: lvm2 plugin correctly debug
Fix debug message and report exit when really doing it.
Also add missing '_' to static function.
2015-10-22 22:28:37 +02:00
Zdenek Kabelac
ab6d16a8a5 dmeventd: check for malloc return 2015-10-22 22:28:37 +02:00
David Teigland
73e679f33f man: document possible lvmetad -l values
In the man page and the lvmetad help output.
2015-10-21 13:36:57 -05:00
Ondrej Kozina
f67a52677b lvmetad: add optional timeout option 2015-10-20 15:45:14 +02:00
David Teigland
df34fcdafd lvmlockd: use flag to avoid blocking in sanlock_acquire
If a host failed while holding a sanlock lease,
sanlock_acquire will by default block and wait
for the lease to expire before returning.  We
want it to return with an error so we can retry
instead of blocking, which allows us to process
other lock operations.

(Enclose this in an ifdef until the new flag
appears in a sanlock release.)
2015-10-14 14:39:29 -05:00
Zdenek Kabelac
a6d1c8ac65 dmeventd: use matching function
Respect lvm2_log_fn prototype. The idea of 'reusing' print_log with
plain cast is causing very strange crashes with some older 'gcc'  compilers.
So just do it cleanly...
2015-10-14 14:25:27 +02:00
Zdenek Kabelac
3f1a3b7090 dmeventd: fix missing '!'
During recent code changes '!' was badly converted.
2015-10-13 22:10:47 +02:00
Zdenek Kabelac
ccc39be053 dmeventd: compilable without DEBUG CFLAG
Missed compilability without DEBUG.
2015-10-13 20:59:35 +02:00
Zdenek Kabelac
4b586ad3c2 dmeventd: rework raid plugin
Switch to per-thread mem-pool and lock only for lvm2 calls.
Use libdm parser for raid status line.
2015-10-13 16:02:19 +02:00
Zdenek Kabelac
256e432e78 dmeventd: less locking mirror
Rework mirror plugin to use per-thread mem-pool.
This allows to use locking only for lvm2 library calls.
2015-10-13 16:02:18 +02:00
Zdenek Kabelac
51ff7d5ed8 dmeventd: less locking for snapshot and thin
Use lvm lock for lvm library calls.

dm functions in-use are 'thread-safe' since we use
local per-thread mem pool.
2015-10-13 16:01:41 +02:00
Zdenek Kabelac
49e11102c7 dmeventd: add local mempool for raid and mirror
Using local mempools allows to drop locks when such memory is needed.
2015-10-13 15:56:23 +02:00
Zdenek Kabelac
a11cd2ca2d dmeventd: use new macros to init mempool
For thin and snapshot use new macros
to simplify mempool init and destroy
2015-10-13 15:56:03 +02:00
Zdenek Kabelac
f9926e7e6c dmeventd: introduce macro for init
Simplify commonly used pool creation.
2015-10-13 15:56:03 +02:00
Zdenek Kabelac
76ea01dd20 dmeventd: new initialization of plugin threads
Rework thread creation code to better use resources.

New code will not leak 'timeout' registered thread on error path.

Also if the thread already exist - avoid creation of thread
object and it's later destruction.

If the race is noticed during adding new monitoring thread,
such thread is put on cleanup list and -EEXIST is reported.
2015-10-13 15:55:05 +02:00
Zdenek Kabelac
09a8479cb7 cleanup: move system defines before structs 2015-10-13 15:22:58 +02:00
Zdenek Kabelac
0a633750f1 cleanup: avoid using private
Switch private to user.
2015-10-13 15:22:58 +02:00
Zdenek Kabelac
0e2261dbd1 cleanup: remove multilog 2015-10-13 15:22:57 +02:00
Zdenek Kabelac
842a7a17e3 cleanup: always set nsec 2015-10-13 15:22:57 +02:00
Zdenek Kabelac
8b9533f38f dmeventd: support logging on stdout
Add new supported option '-l' log to stdout/stderr.

It has to be paired with '-f' (foreground run).
2015-10-13 15:22:57 +02:00
Zdenek Kabelac
903e9af1b2 cleanup: static with _
Document ? is printing to stderr.
2015-10-13 15:16:56 +02:00
Zdenek Kabelac
e261af52eb dmeventd: handle snapshot overflow
When snapshot reports overflow, handle it in the same way as Invalid.
Until better ideas are implemented.
2015-10-13 15:15:44 +02:00
Zdenek Kabelac
0e27210308 dmeventd: add more debug messages 2015-10-13 15:15:43 +02:00
Zdenek Kabelac
13086c2523 dmeventd: drop changing logging
As we now use 'unified' logging macro system - we no longer need
to protect from change of logging function pointer - it's set
once at the start of dmeventd and not change anymore
(as lvm2 library no longer interferers here).
2015-10-13 15:15:43 +02:00
Zdenek Kabelac
42a9c8b4a6 dmeventd: enable new logging 2015-10-13 15:13:28 +02:00
Zdenek Kabelac
e50583d721 dmeventd: enable new logging 2015-10-13 15:09:35 +02:00
Zdenek Kabelac
c90363b585 dmeventd: use log_ macros in plugins
Convert from syslog to standard log_() macros in plugins.
2015-10-13 15:09:03 +02:00
Zdenek Kabelac
915f0faac1 dmeventd: syslog -> log_xxxxx
Convert logging of dmeventd to libdm logging macros.
2015-10-13 14:43:30 +02:00
Zdenek Kabelac
0641e3a5fd libdmevent: add dm_event_log
Add dm_event_log() logging function.
Controled by dm_event_log_set().
2015-10-13 14:40:46 +02:00
Zdenek Kabelac
11a084cf42 dmeventd: log all commands with CMD: prefix
For easier grep of all processed command - add CMD: prefix to them.

Use  >>>  for entring command processing
and  <<<  when command is processed.
2015-10-13 14:40:46 +02:00
Zdenek Kabelac
d60794c3a3 dmeventd: fix loging report
msg.cmd holds return value from processing after _do_process_request,
so save it before call.
2015-10-13 14:40:46 +02:00
Zdenek Kabelac
7e1c08bb6a dmeventd: correct ret code for fail
As  _do_register_device() calls  register_device() function that returns
1 success & 0 fail -  ret = -ENOMEM for fail case instead of 0.
2015-10-13 14:38:49 +02:00
Zdenek Kabelac
a61f3c5316 clvmd: update help test
Use <n> for <input> value.
2015-09-22 00:08:44 +02:00
David Teigland
b7410c95cf lvmlockd: unlock lv if command fails before lock completes
If lvmlockd acquires an lv lock for a command, but the
command exits before the reply, then the command has
not activated the lv and lvmlockd should unlock it.
This only applies when the lv was not already locked.

(There will always be a chance that the lv lock is held
while the lv is not active, i.e. if the command fails in
the small window between getting the lv lock and before
doing the activation.  In that case, rerunning the
activation command corrects the inconsistency.)

This commit helps by automatically clearing the
inconsistency (lv locked by not activated) in the most
common case when the lv lock operation is slow to
complete and the command is canceled by the user.

This commit also adds and cleans up references to the
client id in a bunch of log messages, which is useful
to follow processing on each independent lock request.
2015-09-16 15:56:54 -05:00
Zdenek Kabelac
fd3d795b93 makefiles: distclean missing files 2015-09-11 21:52:27 +02:00
David Teigland
6bc3d72a65 lvmlockd: prevent vgremove of dlm VG while lockspace is used
This applies the same rule/logic to dlm VGs that has always
existed for sanlock VGs.  Allowing a dlm VG to be removed
while its lockspace was still running on other hosts largely
worked, but there were difficult problems if another VG with
the same name was recreated.  Forcing the VG lockspace to
be stopped, gives both sanlock and dlm VGs the same behavior.
2015-09-11 14:12:13 -05:00
David Teigland
854a559a49 lvmlockd: remove shortcut for lockspace thread cleanup
This shortcut was added for an odd case that I do not
believe is relevant any more.  Having an alternate
path for lockspace thread cleanup is a complication
that could lead to problems.
2015-09-11 13:20:20 -05:00
David Teigland
18dfbbb150 lvmlockd: optimize dlm global lockspace creation
Set a flag indicating that the dlm global lockspace
exists to avoid going through the entire process of
trying to add it before finding it exists.
2015-09-11 13:20:01 -05:00
David Teigland
3670f095c7 lvmlockd: check all variations of lvb values
The dlm will often lose the lvb content, so we need to
check quite a few possibilities for lvb values that
were not being checked before.

Refactoring was required to pass the entire lvb value
back to the core code instead of the single value.

The only functional change should be detecting new
lvb states where metadata is now invalidated where
it wasn't before.
2015-09-10 09:47:26 -05:00
David Teigland
f11d690967 lvmlockd: flag for internal actions
When an action is created by lvmlockd for itself,
there is no client to send the result to.  Add
the NO_CLIENT flag to the action to skip sending
the result to a client.
2015-09-10 09:47:26 -05:00
David Teigland
15ae237d2c lvmlockd: rename ADOPT_CLIENT_ID
to INTERNAL_CLIENT_ID since it will be
used for more than adopting locks.
2015-09-10 09:47:26 -05:00
Alasdair G Kergon
fb12308416 style: Standardise some error paths. 2015-09-05 23:56:30 +01:00
David Teigland
10ccbc5efa lvmlockd: don't stop lockspace for EREMOVED
Undo the part of the recent EREMOVED change which
automatically stopped the lockspace for a remotely
removed VG.  It didn't always work (would not work
when lvb content was rebuilt in the dlm).  This will
be handled better when the lvb content is controlled
more strictly.
2015-09-04 13:41:38 -05:00
David Teigland
c71af0895d lvmlockctl: update command descriptions and add logging
The one line descriptions will match the man page.

Add a syslog entry when enabling/disabling the global lock
to help debugging.
2015-09-04 11:05:13 -05:00
David Teigland
6240a7639d lvmlockd: fixes for starting dlm global lockspace
Remove the optimization/shortcut for starting the dlm global
lockspace when it was already running.

Reenable automatically starting the dlm global lockspace
when a command attempts to use it and it's not yet started.
This had become disabled at some point.
2015-09-03 16:47:54 -05:00
David Teigland
c27015368b lvmlockd: improve log messages for adding dlm global lockspace 2015-09-03 16:47:54 -05:00
Zdenek Kabelac
2b9843c20b dmeventd: reorder mempool allocation
Since lvm2_init() effectively detects memory leaks
allocate mempool after this initialization
(so it's not reported as leak).
2015-09-03 23:34:36 +02:00
Ondrej Kozina
7bbc128c3d lvmpolld: make lvpoll error messages visible
Previously all stderr messages issued by spawned lvpoll command were reported
as INFO only. This made all such messages invisible in syslog or lvmpolld log
while running default configuration.

All lvpoll stderr messages are loged with WARN priority now and lvpoll
command exiting with retcode != 0 is logged with ERROR priority in
syslog and lvmpolld log
2015-09-02 17:24:26 +02:00
David Teigland
8b6226997e lvmlockd: also use vg name in set_vg_info
Include both the VG uuid and name in the lvmetad
set_vg_info message.  This works around an obscure
problem where the VG uuid in lvmlockd is wrong
when one host removes a dlm VG, then creates a new
VG with the same name.  If the dlm lockspace for
the initial VG was never stopped on another host,
that other host will be using the old uuid in its
lvmetad set_vg_info message.  (That can be
corrected with a larger change, but this is an
effective workaround.)
2015-08-28 14:43:58 -05:00
David Teigland
f0b3e05add lvmetad: also accept vg name for set_vg_info
set_vg_info previously accepted only vg uuid,
now accept both vg uuid and vg name.  If the
uuid is provided, it's used just as before,
but if the uuid is not provided, or if it's
not found, then fall back to using the vg
name if that is provided.
2015-08-28 14:36:48 -05:00
David Teigland
3c1924c9c0 lvmlockd: fix starting dlm global lockspace
lvmlockd would fail to recognize that the global lockspace
failed to start if the dlm wasn't running, so future attempts
to start the dlm global lockspace would do nothing, thinking
it was already running.
2015-08-27 16:00:24 -05:00
David Teigland
e4d5d05119 lvmlockd: remove list of inactive lockspaces
This was only used to return two flags indicating specific
reasons for a lock failure so that a more specific error
message could be printed by the command (lockspace had been
stopped, or lockspace had an error starting.)

Remove the list, given its limited usefulness, the fact it
would easily become inaccurate, and the fact it was causing
misleading error messages.  The error conditions it was meant
to help could be reported differently.
2015-08-27 15:23:14 -05:00
David Teigland
58713d34dd lvmlockd: detect when dlm lvb is invalidated
The lvb content can be lost during dlm recovery,
and we need to detect when this happens to revalidate.
2015-08-27 10:27:24 -05:00
David Teigland
231b7df6cc lvmlockd: improve VG removal for lock_type dlm
This makes lvmlockd removal steps for dlm VGs closely match
sanlock VGs.  Because dlm lockspaces are not required to be
stopped on all hosts before vgremove, there is an extra bit
for dlm lockspaces, where a flag is set in the VG lock lvb
indicating that the VG was removed.  If other hosts happen
to use the VG lock they will see this flag and stop their
lockspace.
2015-08-27 10:27:24 -05:00
David Teigland
521136181b lvmlockd: fix to work around dlm lvb bug
Work around a dlm bug that fails to copy lvb
on a NL->EX conversion.
2015-08-27 10:27:24 -05:00
David Teigland
fda19b55b1 lvmlockd: fix dlm EAGAIN checks
libdlm returns EAGAIN in errno
2015-08-27 10:27:24 -05:00
David Teigland
1fae121b22 lvmlockd: fix sending debug info to lvmlockctl
Single messages sent over unix sockets are limited in
size to /proc/sys/net/core/wmem_max, so send the 1MB
debug buffer in smaller chunks to avoid EMSGSIZE.

Also look for EAGAIN and retry sending for a limited
time when the reader is slower than the writer.

Also shift the location of that code so it's the same
as other requests.
2015-08-20 14:07:11 -05:00
Ferenc Wágner
5476ee8655 cmirrord: avoid resync buffer overflow in LOG_SPRINT
Use snprintf() instead of sprintf() to exclude the possibility of
overflowing the resync history buffers.
2015-08-20 19:06:47 +02:00
Ferenc Wágner
3c396cf1e1 cmirrord: avoid debugging buffer overflow in LOG_SPRINT
Use snprintf() instead of sprintf() to exclude the possibility of
overflowing the debugging history buffers.
2015-08-20 19:06:47 +02:00
Ferenc Wágner
1ea1cb6dc9 cmirrord: fix stack smashing
With clusters larger than 3 nodes, the 32-byte debug buffer in
cpg_join_callback() is too small to contain all the node IDs, because
32-bit identifiers are generally rendered in 10 decimal digits.  No fixed
size is good in all cases, but this is conditionally logged debug info,
so we can simply truncate it.  Double the size, nevertheless.
2015-08-20 19:06:47 +02:00
Ferenc Wágner
92a4b5cc3c cmirrord: add --foreground and --help options. 2015-08-20 19:06:47 +02:00
Ferenc Wágner
c0d6056870 cmirrord: move generic setup from daemonize() to init_all()
Apply pidfile creation, removal and signal setup to foreground processes too.
2015-08-20 19:06:47 +02:00
David Teigland
62a87c84ed lvmlockd: ignore cmd close if no locks were taken
When a command closes its connection, don't waste
time looking for locks to purge if it did not make
any lock requests.
2015-08-19 12:16:04 -05:00
David Teigland
ce2e60ab45 lvmlockd: change log_error to log_debug for non error
It's not uncommon for a command like vgchange -an to
deactivate and unlock LVs that were not active, so
don't lock that as an error.
2015-08-19 11:43:39 -05:00
David Teigland
9c5a85ce24 lvmlockctl: fix debug output 2015-08-18 16:49:33 -05:00
Zdenek Kabelac
abb24370e9 cleanup: move var declaration 2015-08-18 16:05:04 +02:00
Zdenek Kabelac
3a3e17d603 cleanup: check pthread result codes 2015-08-18 15:00:08 +02:00
David Teigland
597de9d586 lvmlockd: add LV name to some debug logging
The LV uuid is used as the lock name, and including
the LV name in some log messages makes it easier to
follow log messages.
2015-08-10 15:07:10 -05:00
David Teigland
6bd5bf3cb5 lvmlockd: fix check for other sanlock lockspaces
The check for other sanlock lockspaces was not checking
that the lockspace type was sanlock, so if dlm lockspaces
were visible, they were wrongly included.
2015-08-10 13:16:04 -05:00
David Teigland
fd1782b5fc lvmlockd: handle loss of sanlock lease storage
This adds the infrastructure, code paths, error reporting,
etc. to handle storage errors, or storage loss, under the
sanlock leases in a VG that is being used.  The loss of
storage means sanlock cannot renew its leases, which means
that the host needs to stop using the shared VG before its
leases expire.

This still requires manually shutting down a VG that has
lost lease storage, e.g. unmounting file systems,
deactivating LVs in the VG.  The next step is to
automatically use a command like blkdeactivate to do that.
2015-08-05 10:21:45 -05:00
Peter Rajnoha
c78033233a coverity: return value check in lvmlockd-dlm
daemons/lvmlockd/lvmlockd-dlm.c:647: check_return: Calling "closedir" without checking return value (as is done elsewhere 13 out of 14 times).
2015-08-04 09:49:29 +02:00
Peter Rajnoha
83541123c8 coverity: fix cppcheck warnings
/lib/log/log.c:88: warning[invalidScanfArgType_int]: %llu in format string (no. 2) requires 'unsigned long long *' but the argument type is 'long long *'.
daemons/lvmlockd/lvmlockd-core.c:791: error[uninitstring]: Dangerous usage of 'version' (strncpy doesn't always null-terminate it).
2015-08-04 09:33:55 +02:00
Peter Rajnoha
46e6b2b86e coverity: fix possible resource leak in lvmpolld-core
/daemons/lvmpolld/lvmpolld-core.c:573: leaked_storage: Variable "cmdargv" going out of scope leaks the storage it points to.
2015-08-04 09:25:47 +02:00
David Teigland
d11f8d4228 lvmlockd: automatically remove the dlm global lockspace
The dlm global lockspace is automatically added when the
first dlm VG lockspace is added.  Reverse this by removing
the dlm global lockspace after the last dlm VG lockspace
is removed.  (Remove old non-working code that did this
based on an old command that could explicitly add/remove
the dlm global lockspace.)
2015-08-03 10:23:01 -05:00
David Teigland
78135c24b4 lvmlockd: small fixes and cleanup for lvmlockctl
. clean up the info output for readability
. remove some internal debug output
. fix the daemon quit option
2015-07-30 10:50:22 -05:00
Peter Rajnoha
f6473baffc toolcontext: add switches to create_toolcontext for connections and filters init
Make it possible to decide whether we want to initialize connections and
filters together with toolcontext creation.

Add "filters" and "connections" fields to struct
cmd_context_initialized_parts and set these in cmd_context.initialized
instance accordingly.

(For now, all create_toolcontext calls do initialize connections and
filters, we'll change that in subsequent patch appropriately.)
2015-07-30 13:54:09 +02:00
Peter Rajnoha
6b0c464a34 refactor: toolcontext: add struct cmd_context_initialized_parts
Add struct cmd_context_initialized_parts to wrap up information
about which cmd context pieces are initialized and add variable
of this struct type into struct cmd_context.

Also, move existing "config_initialized" variable that was directly
part of cmd_context into the new cmd_context.initialized wrapper.

We'll be adding more items into the struct cmd_context_initialized_parts
with subsequent patches...
2015-07-30 13:54:05 +02:00
David Teigland
9aabf441bd vgremove: warn when removing sanlock global lock
When the sanlock VG holding the global lock is removed,
print a warning indicating that the global needs to be
enabled in another sanlock VG.
2015-07-29 14:27:32 -05:00
David Teigland
772b54a08b vgcreate: improve checks for existing global lock
This tries harder to avoid creating duplicate global locks in
sanlock VGs by refusing to create a new sanlock VG with a
global lock if other sanlock VGs exist that may have a gl.
2015-07-29 14:27:32 -05:00
Alasdair G Kergon
fa11ddd7df lvmlockd: Drop -lrt now handled by configure. 2015-07-27 14:53:08 +01:00
Alasdair G Kergon
3934ade5a2 gitignore: Update for in-place build. 2015-07-27 13:18:35 +01:00
Alasdair G Kergon
be66243933 clvmd: Fix freeze if client dies holding locks.
Simply running concurrent copies of 'pvscan | true' is enough to make
clvmd freeze: pvscan exits on the EPIPE without first releasing the
global lock.

clvmd notices the client disappear but because the cleanup code that
releases the locks is triggered from within some processing after the
next select() returns, and that processing can 'break' after doing just
one action, it sometimes never releases the locks to other clients.

Move the cleanup code before the select.
Check all fds after select().
Improve some debug messages and warn in the unlikely event that
select() capacity could soon be exceeded.
2015-07-23 23:10:16 +01:00
David Teigland
57534733b7 lvmlockd: improve check for duplicate global locks
When there are duplicate global locks, check if the gl
is still enabled each time a gl or vg lock is acquired
in the lockspace.  Once one of the duplicates is disabled,
then other hosts will recognize that the issue is resolved
without needing to restart the lockspaces.
2015-07-23 10:39:11 -05:00
David Teigland
85b42d7c95 lvmlockd: improve errors when lvm is built without a lock manager
When lvmlockd is compiled without support for one of the
lock managers (sanlock or dlm), and a command tries to use
one of them, explain that in the error message.
2015-07-17 11:16:18 -05:00
Marian Csontos
738ae4a77f lvmpolld: Fix segfault on 32 bit architectures
Explicit conversions are needed to align writes and reads on the stack.
int64_t is popped from stack while int was pushed.
2015-07-10 16:16:57 +02:00
David Teigland
6294509cc6 coverity: cleanup related to lvmlockd
A couple missing mutex unlock on error bugs.
A bunch of buffer size/termination warnings.
2015-07-09 11:29:28 -05:00
Peter Rajnoha
10d27998b3 coverity: missing return value checks 2015-07-09 15:15:15 +02:00
Peter Rajnoha
a9a7c297ae coverity: missing return value for dm_split_lvm_name pass proper DM name instead of NULL value 2015-07-09 13:11:57 +02:00
Peter Rajnoha
023cf21848 coverity: fix possible invalid dereferences
lib/format1/import-export.c:167: var_deref_op: Dereferencing null pointer "vg->lvm1_system_id"
lib/cache/lvmetad.c:1023: var_deref_op: Dereferencing null pointer "this"
daemons/lvmlockd/lvmlockd-core.c:2659: check_after_deref: Null-checking "act" suggests that it may be null, but it has already been dereferenced on all paths leading to the check
/daemons/lvmetad/lvmetad-core.c:1024: check_after_deref: Null-checking "pvmeta" suggests that it may be null, but it has already been dereferenced on all paths leading to the check
2015-07-09 12:07:41 +02:00
David Teigland
903569d533 lvmlockd: remove log_error instances for normal conditions
There are a number of log_error instances that are replaced
by log_debug because they are not errors.
2015-07-08 15:25:14 -05:00
David Teigland
de13abdfdf lvmlockd: fix unreachable code 2015-07-08 11:02:11 -05:00
David Teigland
2566bdfbc3 lvmlockctl: fix uninitialized names
When formatting and printing info from lvmlockd.
Also fix some new line problems.
2015-07-08 10:58:56 -05:00
Peter Rajnoha
3ec4813ba2 coverity: fix missing initialization
... Using uninitialized value "lockd_state" when calling "lockd_vg"
(even though lockd_vg assigns 0 to the lockd_state, but it looks at
previous state of lockd_state just before that so we need to have
that properly initialized!)

libdm/libdm-report.c:2934: uninit_use_in_call: Using uninitialized value "tm". Field "tm.tm_gmtoff" is uninitialized when calling "_get_final_time".

daemons/lvmlockd/lvmlockctl.c:273: uninit_use_in_call: Using uninitialized element of array "r_name" when calling "format_info_r_action". (just added FIXME as this looks unfinished?)
2015-07-08 14:53:30 +02:00
Peter Rajnoha
71f4fbfbde coverity: fix uninitialized values and other reported problems
daemons/lvmlockd/lvmlockd-core.c:5709: error[uninitStructMember]: Uninitialized struct member: ds.....
daemons/lvmlockd/lvmlockd-core.c:799: error[uninitstring]: Dangerous usage of 'version' (strncpy doesn't always null-terminate it)
daemons/lvmlockd/lvmlockd-core.c:646: error[memleakOnRealloc]: Common realloc mistake: 'pollfd' nulled but not freed upon failure
2015-07-08 14:19:51 +02:00
Peter Rajnoha
16e9b32c2f coverity: fix resource leaks
lib/log/log.c:115: leaked_storage: Variable "st" going out of scope leaks the storage it points to
daemons/lvmpolld/lvmpolld-core.c:573: leaked_storage: Variable "cmdargv" going out of scope leaks the storage it points to
daemons/lvmlockd/lvmlockd-core.c:5341: leaked_handle: Handle variable "fd" going out of scope leaks the handle
daemons/lvmlockd/lvmlockctl.c:575: overwrite_var: Overwriting "able_vg_name" in "able_vg_name = strdup(optarg)" leaks the storage that "able_vg_name" points to
daemons/lvmlockd/lvmlockctl.c:571: overwrite_var: Overwriting "able_vg_name" in "able_vg_name = strdup(optarg)" leaks the storage that "able_vg_name" points to
daemons/lvmlockd/lvmlockctl.c:385: leaked_handle: Handle variable "s" going out of scope leaks the handle
2015-07-08 13:56:06 +02:00
Ondrej Kozina
088ee7618d lvmpolld: fix possible memory corruption with mem debug
if lvm2 is built with debug memory options dm_free() is not
mapped directly to std library's free(). This may cause memory corruption
as a line buffer may get reallocated in getline with realloc.

This is a temporary hotfix. Other debug memory failure needs to
be investigated and explained.
2015-07-07 14:49:53 +02:00
David Teigland
d16332be72 lvmetactl: program to interact with lvmetad
This is not installed; it's only a developer utility
at this point.
2015-07-06 15:54:22 -05:00
Alasdair G Kergon
dfe3eb12d0 include: Standardise around new tool.h. 2015-07-06 17:30:18 +01:00
David Teigland
d3605b81f3 configure: enable building lvmlockd without sanlock or dlm 2015-07-06 11:09:58 -05:00
Alasdair G Kergon
810ab095e6 macros: Wrap PRI with FMT.
Create a set of wrappers with embedded % such as
  #define FMTu64 "%" PRIu64
2015-07-06 15:09:17 +01:00
Alasdair G Kergon
36ce97c625 pre-release 2015-07-03 16:34:40 +01:00
David Teigland
fe70b03de2 Add lvmlockd 2015-07-02 15:42:26 -05:00
David Teigland
bf77f71711 lvmetad: add invalidation method
Add the ability to invalidate global or individual VG metadata.
The invalid state is returned to lvm commands along with the metadata.
This allows lvm commands to detect stale metadata from the cache and
reread the latest metadata from disk (in a subsequent patch.)

These changes do not change the protocol or compatibility between
lvm commands and lvmetad.

Global information
------------------

Global information refers to metadata that is not isolated
to a single VG , e.g. the list of vg names, or the list of pvs.

When an external system, e.g. a locking system, detects that global
information has been changed from another host (e.g. a new vg has been
created) it sends lvmetad the message: set_global_info: global_invalid=1.
lvmetad sets the global invalid flag to indicate that its cached data is
stale.

When lvm commands request information from lvmetad, lvmetad returns the
cached information, along with an additional top-level config node called
"global_invalid".  This new info tells the lvm command that the cached
information is stale.

When an lvm command sees global_invalid from lvmated, it knows it should
rescan devices and update lvmetad with the latest information.  When this
is complete, it sends lvmetad the message: set_global_info:
global_invalid=0, and lvmetad clears the global invalid flag.  Further lvm
commands will use the lvmetad cache until it is invalidated again.

The most common commands that cause global invalidation are vgcreate and
vgextend.  These are uncommon compared to commands that report global
information, e.g. vgs.  So, the percentage of lvmetad replies containing
global_invalid should be very small.

VG information
--------------

VG information refers to metadata that is isolated to a single VG,
e.g. an LV or the size of an LV.

When an external system determines that VG information has been changed
from another host (e.g. an lvcreate or lvresize), it sends lvmetad the
message: set_vg_info: uuid=X version=N.  X is the VG uuid, and N is the
latest VG seqno that was written.  lvmetad checks the seqno of its cached
VG, and if the version from the message is newer, it sets an invalid flag
for the cached VG.  The invalid flag, along with the newer seqno are saved
in a new vg_info struct.

When lvm commands request VG metadata from lvmetad, lvmetad includes the
invalid flag along with the VG metadata.  The lvm command checks for this
flag, and rereads the VG from disk if set.  The VG read from disk is sent
to lvmetad.  lvmetad sees that the seqno in the new version matches the
seqno from the last set_vg_info message, and clears the vg invalid flag.
Further lvm commands will use the VG metadata from lvmetad until it is
next invalidated.
2015-06-23 16:36:33 -05:00