mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
lvmetad: improve client logging when connecting
Rename lvmetad_warning() to lvmetad_connect_or_warn(). Log all connection attempts on the client side, whether successful or not. Reduce some nesting and remove a redundant assertion.
This commit is contained in:
parent
a527a3b8c2
commit
6d760b2c63
27
lib/cache/lvmetad.c
vendored
27
lib/cache/lvmetad.c
vendored
@ -20,7 +20,6 @@
|
||||
#include "lvmcache.h"
|
||||
#include "lvmetad-client.h"
|
||||
#include "format-text.h" // TODO for disk_locn, used as a DA representation
|
||||
#include "assert.h"
|
||||
#include "crc.h"
|
||||
|
||||
static daemon_handle _lvmetad;
|
||||
@ -49,19 +48,26 @@ void lvmetad_init(struct cmd_context *cmd)
|
||||
|
||||
static void _lvmetad_connect()
|
||||
{
|
||||
if (_lvmetad_use && _lvmetad_socket && !_lvmetad_connected) {
|
||||
assert(_lvmetad_socket);
|
||||
_lvmetad = lvmetad_open(_lvmetad_socket);
|
||||
if (_lvmetad.socket_fd >= 0 && !_lvmetad.error)
|
||||
_lvmetad_connected = 1;
|
||||
if (!_lvmetad_use || !_lvmetad_socket || _lvmetad_connected)
|
||||
return;
|
||||
|
||||
_lvmetad = lvmetad_open(_lvmetad_socket);
|
||||
if (_lvmetad.socket_fd >= 0 && !_lvmetad.error) {
|
||||
log_debug("Successfully connected to lvmetad on fd %d.",
|
||||
_lvmetad.socket_fd);
|
||||
_lvmetad_connected = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void lvmetad_warning(void)
|
||||
void lvmetad_connect_or_warn(void)
|
||||
{
|
||||
if (!_lvmetad_use)
|
||||
return;
|
||||
|
||||
if (!_lvmetad_connected)
|
||||
_lvmetad_connect();
|
||||
if (_lvmetad_use && (_lvmetad.socket_fd < 0 || _lvmetad.error))
|
||||
|
||||
if ((_lvmetad.socket_fd < 0 || _lvmetad.error))
|
||||
log_warn("WARNING: Failed to connect to lvmetad: %s. Falling back to internal scanning.",
|
||||
strerror(_lvmetad.error));
|
||||
}
|
||||
@ -70,8 +76,13 @@ int lvmetad_active(void)
|
||||
{
|
||||
if (!_lvmetad_use)
|
||||
return 0;
|
||||
|
||||
if (!_lvmetad_connected)
|
||||
_lvmetad_connect();
|
||||
|
||||
if ((_lvmetad.socket_fd < 0 || _lvmetad.error))
|
||||
log_debug("Failed to connect to lvmetad: %s.", strerror(_lvmetad.error));
|
||||
|
||||
return _lvmetad_connected;
|
||||
}
|
||||
|
||||
|
9
lib/cache/lvmetad.h
vendored
9
lib/cache/lvmetad.h
vendored
@ -49,8 +49,11 @@ void lvmetad_set_socket(const char *);
|
||||
*/
|
||||
int lvmetad_active(void);
|
||||
|
||||
/* Print a warning if lvmetad is enabled but we failed to connect. */
|
||||
void lvmetad_warning(void);
|
||||
/*
|
||||
* Connect to lvmetad unless the connection is already open or lvmetad is
|
||||
* not configured to be used. If we fail to connect, print a warning.
|
||||
*/
|
||||
void lvmetad_connect_or_warn(void);
|
||||
|
||||
/*
|
||||
* Drop connection to lvmetad. A subsequent lvmetad_init() will re-establish
|
||||
@ -146,7 +149,7 @@ int lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler handler)
|
||||
# define lvmetad_set_active(a) do { } while (0)
|
||||
# define lvmetad_set_socket(a) do { } while (0)
|
||||
# define lvmetad_active() (0)
|
||||
# define lvmetad_warning() do { } while (0)
|
||||
# define lvmetad_connect_or_warn() do { } while (0)
|
||||
# define lvmetad_set_token(a) do { } while (0)
|
||||
# define lvmetad_release_token() do { } while (0)
|
||||
# define lvmetad_vg_update(vg) (1)
|
||||
|
@ -877,7 +877,7 @@ static int _get_settings(struct cmd_context *cmd)
|
||||
init_ignorelockingfailure(0);
|
||||
|
||||
if (!arg_count(cmd, sysinit_ARG))
|
||||
lvmetad_warning();
|
||||
lvmetad_connect_or_warn();
|
||||
|
||||
if (arg_count(cmd, nosuffix_ARG))
|
||||
cmd->current_settings.suffix = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user