mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
refactor: toolcontext: move lvmetad and lvmpolld init into separate function
Move original lvmetad and lvmpolld initialization code from _process_config fn to their own functions _init_lvmetad and _init_lvmpolld (both covered with single _init_connections fn).
This commit is contained in:
parent
6b0c464a34
commit
3e343ba5ef
@ -55,6 +55,7 @@
|
||||
#endif
|
||||
|
||||
static const size_t linebuffer_size = 4096;
|
||||
static int _init_connections(struct cmd_context *cmd);
|
||||
|
||||
/*
|
||||
* Copy the input string, removing invalid characters.
|
||||
@ -532,8 +533,6 @@ static int _process_config(struct cmd_context *cmd)
|
||||
const struct dm_config_node *cn;
|
||||
const struct dm_config_value *cv;
|
||||
int64_t pv_min_kb;
|
||||
const char *lvmetad_socket;
|
||||
const char *lvmpolld_socket;
|
||||
int udev_disabled = 0;
|
||||
char sysfs_dir[PATH_MAX];
|
||||
|
||||
@ -676,41 +675,12 @@ static int _process_config(struct cmd_context *cmd)
|
||||
init_detect_internal_vg_cache_corruption
|
||||
(find_config_tree_bool(cmd, global_detect_internal_vg_cache_corruption_CFG, NULL));
|
||||
|
||||
lvmetad_disconnect();
|
||||
lvmpolld_disconnect();
|
||||
|
||||
lvmetad_socket = getenv("LVM_LVMETAD_SOCKET");
|
||||
if (!lvmetad_socket)
|
||||
lvmetad_socket = DEFAULT_RUN_DIR "/lvmetad.socket";
|
||||
|
||||
/* TODO?
|
||||
lvmetad_socket = find_config_tree_str(cmd, "lvmetad/socket_path",
|
||||
DEFAULT_RUN_DIR "/lvmetad.socket");
|
||||
*/
|
||||
lvmetad_set_socket(lvmetad_socket);
|
||||
cn = find_config_tree_array(cmd, devices_global_filter_CFG, NULL);
|
||||
lvmetad_set_token(cn ? cn->v : NULL);
|
||||
|
||||
if (find_config_tree_int(cmd, global_locking_type_CFG, NULL) == 3 &&
|
||||
find_config_tree_bool(cmd, global_use_lvmetad_CFG, NULL)) {
|
||||
log_warn("WARNING: configuration setting use_lvmetad overridden to 0 due to locking_type 3. "
|
||||
"Clustered environment not supported by lvmetad yet.");
|
||||
lvmetad_set_active(NULL, 0);
|
||||
} else
|
||||
lvmetad_set_active(NULL, find_config_tree_bool(cmd, global_use_lvmetad_CFG, NULL));
|
||||
|
||||
lvmetad_init(cmd);
|
||||
if (!_init_connections(cmd))
|
||||
return_0;
|
||||
|
||||
if (!_init_system_id(cmd))
|
||||
return_0;
|
||||
|
||||
lvmpolld_socket = getenv("LVM_LVMPOLLD_SOCKET");
|
||||
if (!lvmpolld_socket)
|
||||
lvmpolld_socket = DEFAULT_RUN_DIR "/lvmpolld.socket";
|
||||
lvmpolld_set_socket(lvmpolld_socket);
|
||||
|
||||
lvmpolld_set_active(find_config_tree_bool(cmd, global_use_lvmpolld_CFG, NULL));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1679,6 +1649,68 @@ static int _reopen_stream(FILE *stream, int fd, const char *mode, const char *na
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _init_lvmetad(struct cmd_context *cmd)
|
||||
{
|
||||
const struct dm_config_node *cn;
|
||||
const char *lvmetad_socket;
|
||||
|
||||
lvmetad_disconnect();
|
||||
|
||||
lvmetad_socket = getenv("LVM_LVMETAD_SOCKET");
|
||||
if (!lvmetad_socket)
|
||||
lvmetad_socket = DEFAULT_RUN_DIR "/lvmetad.socket";
|
||||
|
||||
/* TODO?
|
||||
lvmetad_socket = find_config_tree_str(cmd, "lvmetad/socket_path",
|
||||
DEFAULT_RUN_DIR "/lvmetad.socket");
|
||||
*/
|
||||
|
||||
lvmetad_set_socket(lvmetad_socket);
|
||||
cn = find_config_tree_array(cmd, devices_global_filter_CFG, NULL);
|
||||
lvmetad_set_token(cn ? cn->v : NULL);
|
||||
|
||||
if (find_config_tree_int(cmd, global_locking_type_CFG, NULL) == 3 &&
|
||||
find_config_tree_bool(cmd, global_use_lvmetad_CFG, NULL)) {
|
||||
log_warn("WARNING: configuration setting use_lvmetad overridden to 0 due to locking_type 3. "
|
||||
"Clustered environment not supported by lvmetad yet.");
|
||||
lvmetad_set_active(NULL, 0);
|
||||
} else
|
||||
lvmetad_set_active(NULL, find_config_tree_bool(cmd, global_use_lvmetad_CFG, NULL));
|
||||
|
||||
lvmetad_init(cmd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _init_lvmpolld(struct cmd_context *cmd)
|
||||
{
|
||||
const char *lvmpolld_socket;
|
||||
|
||||
lvmpolld_disconnect();
|
||||
|
||||
lvmpolld_socket = getenv("LVM_LVMPOLLD_SOCKET");
|
||||
if (!lvmpolld_socket)
|
||||
lvmpolld_socket = DEFAULT_RUN_DIR "/lvmpolld.socket";
|
||||
lvmpolld_set_socket(lvmpolld_socket);
|
||||
|
||||
lvmpolld_set_active(find_config_tree_bool(cmd, global_use_lvmpolld_CFG, NULL));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _init_connections(struct cmd_context *cmd)
|
||||
{
|
||||
if (!_init_lvmetad(cmd)) {
|
||||
log_error("Failed to initialize lvmetad connection.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_init_lvmpolld(cmd)) {
|
||||
log_error("Failed to initialize lvmpolld connection.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Entry point */
|
||||
struct cmd_context *create_toolcontext(unsigned is_long_lived,
|
||||
const char *system_dir,
|
||||
|
Loading…
Reference in New Issue
Block a user