master - test: Update Makefiles
by Marian Csontos
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0dae377fbf1e0b...
Commit: 0dae377fbf1e0b3e1484984602cbaf73487efa47
Parent: 8bc90a25c26baa3d31f46415b3bb61e46f0477c1
Author: Marian Csontos <mcsontos(a)redhat.com>
AuthorDate: Thu Jul 30 20:23:14 2015 +0200
Committer: Marian Csontos <mcsontos(a)redhat.com>
CommitterDate: Thu Jul 30 20:39:38 2015 +0200
test: Update Makefiles
- Add missing check_lvmpolld to toplevel Makefile
- Document check_system
---
Makefile.in | 2 +-
test/Makefile.in | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/Makefile.in b/Makefile.in
index 1eb026b..35e5d8f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -95,7 +95,7 @@ endif
DISTCLEAN_TARGETS += cscope.out
CLEAN_DIRS += autom4te.cache
-check check_system check_cluster check_local check_lvmetad unit: all
+check check_system check_cluster check_local check_lvmetad check_lvmpolld unit: all
$(MAKE) -C test $(@)
conf.generate: tools
diff --git a/test/Makefile.in b/test/Makefile.in
index 72eb4e6..65ba294 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -66,6 +66,7 @@ help:
@echo -e "\nAvailable targets:"
@echo " all Default target, run check."
@echo " check Run all tests."
+ @echo " check_system Run all tests using udev."
@echo " check_local Run tests without clvmd and lvmetad."
@echo " check_cluster Run tests with cluster daemon."
@echo " check_lvmetad Run tests with lvmetad daemon."
8 years, 8 months
master - spec: lockd_dlm requires dlm-lib instead of dlm
by Marian Csontos
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=8bc90a25c26baa...
Commit: 8bc90a25c26baa3d31f46415b3bb61e46f0477c1
Parent: b40ccdd57cc0d57a71e584600c1025e649dc6d8a
Author: Marian Csontos <mcsontos(a)redhat.com>
AuthorDate: Thu Jul 30 20:19:35 2015 +0200
Committer: Marian Csontos <mcsontos(a)redhat.com>
CommitterDate: Thu Jul 30 20:39:38 2015 +0200
spec: lockd_dlm requires dlm-lib instead of dlm
---
spec/packages.inc | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/spec/packages.inc b/spec/packages.inc
index 33dda2e..2c0caa8 100644
--- a/spec/packages.inc
+++ b/spec/packages.inc
@@ -257,7 +257,7 @@ Summary: LVM locking daemon
Group: System Environment/Base
Requires: lvm2 = %{version}-%{release}
%if %{enable_lockd_dlm}
-Requires: dlm >= %{dlm_version}
+Requires: dlm-lib >= %{dlm_version}
%endif
%if %{enable_lockd_sanlock}
Requires: sanlock-lib >= %{sanlock_version}
8 years, 8 months
master - lvmlockd: create sanlock lv large enough for existing lvs
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b40ccdd57cc0d5...
Commit: b40ccdd57cc0d57a71e584600c1025e649dc6d8a
Parent: 78135c24b419d070a238f1660408c843707c7cbb
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Jul 30 12:04:31 2015 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Jul 30 12:04:31 2015 -0500
lvmlockd: create sanlock lv large enough for existing lvs
When changing an existing VG to lock_type sanlock,
make the sanlock lv large enough to hold all the
locks needed for existing LVs.
---
lib/locking/lvmlockd.c | 20 ++++++++++++++------
lib/locking/lvmlockd.h | 4 ++--
tools/vgchange.c | 17 ++++++++++++-----
tools/vgcreate.c | 2 +-
4 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c
index 66c6615..15abd54 100644
--- a/lib/locking/lvmlockd.c
+++ b/lib/locking/lvmlockd.c
@@ -320,9 +320,6 @@ static int _lockd_request(struct cmd_context *cmd,
/*
* Eventually add an option to specify which pv the lvmlock lv should be placed on.
- * FIXME: when converting a VG from lock_type none to sanlock, we need to count
- * the number of existing LVs to ensure that the new sanlock_lv is large enough
- * for all of them that need locks.
*/
static int _create_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg,
@@ -559,7 +556,7 @@ out:
return ret;
}
-static int _init_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg)
+static int _init_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg, int lv_lock_count)
{
daemon_reply reply;
const char *reply_str;
@@ -588,7 +585,18 @@ static int _init_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg)
* LV, then activates the lvmlock LV. The lvmlock LV must be active
* before we ask lvmlockd to initialize the VG because sanlock needs
* to initialize leases on the lvmlock LV.
+ *
+ * When converting an existing VG to sanlock, the sanlock lv needs to
+ * be large enough to hold leases for all existing lvs needing locks.
+ * One sanlock lease uses 1MB/8MB for 512/4K sector size devices, so
+ * increase the initial size by 1MB/8MB for each existing lv.
+ * FIXME: we don't know what sector size the pv will have, so we
+ * multiply by 8 (MB) unnecessarily when the sector size is 512.
*/
+
+ if (lv_lock_count)
+ extend_mb += (lv_lock_count * 8);
+
if (!_create_sanlock_lv(cmd, vg, LOCKD_SANLOCK_LV_NAME, extend_mb)) {
log_error("Failed to create internal lv.");
return 0;
@@ -816,7 +824,7 @@ static void _forget_vg_name(struct cmd_context *cmd, struct volume_group *vg)
/* vgcreate */
int lockd_init_vg(struct cmd_context *cmd, struct volume_group *vg,
- const char *lock_type)
+ const char *lock_type, int lv_lock_count)
{
switch (get_lock_type_from_string(lock_type)) {
case LOCK_TYPE_NONE:
@@ -827,7 +835,7 @@ int lockd_init_vg(struct cmd_context *cmd, struct volume_group *vg,
case LOCK_TYPE_DLM:
return _init_vg_dlm(cmd, vg);
case LOCK_TYPE_SANLOCK:
- return _init_vg_sanlock(cmd, vg);
+ return _init_vg_sanlock(cmd, vg, lv_lock_count);
default:
log_error("Unknown lock_type.");
return 0;
diff --git a/lib/locking/lvmlockd.h b/lib/locking/lvmlockd.h
index f141635..b0edeae 100644
--- a/lib/locking/lvmlockd.h
+++ b/lib/locking/lvmlockd.h
@@ -54,7 +54,7 @@ void lvmlockd_disconnect(void);
/* vgcreate/vgremove use init/free */
-int lockd_init_vg(struct cmd_context *cmd, struct volume_group *vg, const char *lock_type);
+int lockd_init_vg(struct cmd_context *cmd, struct volume_group *vg, const char *lock_type, int lv_lock_count);
int lockd_free_vg_before(struct cmd_context *cmd, struct volume_group *vg);
void lockd_free_vg_final(struct cmd_context *cmd, struct volume_group *vg);
@@ -125,7 +125,7 @@ static inline int lvmlockd_use(void)
return 0;
}
-static inline int lockd_init_vg(struct cmd_context *cmd, struct volume_group *vg, const char *lock_type)
+static inline int lockd_init_vg(struct cmd_context *cmd, struct volume_group *vg, const char *lock_type, int lv_lock_count)
{
return 1;
}
diff --git a/tools/vgchange.c b/tools/vgchange.c
index 824fd91..a163cf5 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -526,6 +526,7 @@ static int _vgchange_locktype(struct cmd_context *cmd,
const char *lock_type = arg_str_value(cmd, locktype_ARG, NULL);
struct lv_list *lvl;
struct logical_volume *lv;
+ int lv_lock_count = 0;
/*
* This is a special/forced exception to change the lock type to none.
@@ -654,11 +655,17 @@ static int _vgchange_locktype(struct cmd_context *cmd,
* For lock_type dlm, lockd_init_vg() will do a single
* vg_write() that sets lock_type, sets lock_args, clears
* system_id, and sets all LV lock_args to dlm.
+ * For lock_type sanlock, lockd_init_vg() needs to know
+ * how many LV locks are needed so that it can make the
+ * sanlock lv large enough.
*/
- if (!strcmp(lock_type, "dlm")) {
- dm_list_iterate_items(lvl, &vg->lvs) {
- lv = lvl->lv;
- if (lockd_lv_uses_lock(lv))
+ dm_list_iterate_items(lvl, &vg->lvs) {
+ lv = lvl->lv;
+
+ if (lockd_lv_uses_lock(lv)) {
+ lv_lock_count++;
+
+ if (!strcmp(lock_type, "dlm"))
lv->lock_args = "dlm";
}
}
@@ -673,7 +680,7 @@ static int _vgchange_locktype(struct cmd_context *cmd,
vg->system_id = NULL;
- if (!lockd_init_vg(cmd, vg, lock_type)) {
+ if (!lockd_init_vg(cmd, vg, lock_type, lv_lock_count)) {
log_error("Failed to initialize lock args for lock type %s", lock_type);
return 0;
}
diff --git a/tools/vgcreate.c b/tools/vgcreate.c
index 20ba4aa..67b593d 100644
--- a/tools/vgcreate.c
+++ b/tools/vgcreate.c
@@ -131,7 +131,7 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
* a local VG. lockd_init_vg() then writes the VG a second time with
* both lock_type and lock_args set.
*/
- if (!lockd_init_vg(cmd, vg, vp_new.lock_type)) {
+ if (!lockd_init_vg(cmd, vg, vp_new.lock_type, 0)) {
log_error("Failed to initialize lock args for lock type %s",
vp_new.lock_type);
vg_remove_pvs(vg);
8 years, 8 months
master - lvmlockd: small fixes and cleanup for lvmlockctl
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=78135c24b419d0...
Commit: 78135c24b419d070a238f1660408c843707c7cbb
Parent: d9c67a9b21583e6665ba7c13a3fa2d0151082f5b
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Jul 30 10:47:41 2015 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Jul 30 10:50:22 2015 -0500
lvmlockd: small fixes and cleanup for lvmlockctl
. clean up the info output for readability
. remove some internal debug output
. fix the daemon quit option
---
daemons/lvmlockd/lvmlockctl.c | 35 +++++++++++++----------------------
daemons/lvmlockd/lvmlockd-core.c | 9 ++++-----
2 files changed, 17 insertions(+), 27 deletions(-)
diff --git a/daemons/lvmlockd/lvmlockctl.c b/daemons/lvmlockd/lvmlockctl.c
index 4b27a57..cb67296 100644
--- a/daemons/lvmlockd/lvmlockctl.c
+++ b/daemons/lvmlockd/lvmlockctl.c
@@ -40,11 +40,6 @@ static socklen_t dump_addrlen;
daemon_handle _lvmlockd;
-#define log_debug(fmt, args...) \
-do { \
- printf(fmt "\n", ##args); \
-} while (0)
-
#define log_error(fmt, args...) \
do { \
printf(fmt "\n", ##args); \
@@ -102,6 +97,8 @@ static void find_client_info(uint32_t client_id, uint32_t *pid, char *cl_name)
}
}
+static int first_ls = 1;
+
static void format_info_ls(char *line)
{
char ls_name[MAX_NAME+1] = { 0 };
@@ -114,7 +111,9 @@ static void format_info_ls(char *line)
sscanf(line, "info=ls ls_name=%s vg_name=%s vg_uuid=%s vg_sysid=%s vg_args=%s lm_type=%s",
ls_name, vg_name, vg_uuid, vg_sysid, lock_args, lock_type);
- printf("\n");
+ if (!first_ls)
+ printf("\n");
+ first_ls = 0;
printf("VG %s lock_type=%s %s\n", vg_name, lock_type, vg_uuid);
@@ -160,10 +159,10 @@ static void format_info_r(char *line, char *r_name_out, char *r_type_out)
/* when mode is un, there will be no lk lines, so print now */
if (!strcmp(r_type, "gl")) {
- printf("LK GL un ver %4u\n", ver);
+ printf("LK GL un ver %u\n", ver);
} else if (!strcmp(r_type, "vg")) {
- printf("LK VG un ver %4u\n", ver);
+ printf("LK VG un ver %u\n", ver);
} else if (!strcmp(r_type, "lv")) {
printf("LK LV un %s\n", r_name);
@@ -191,10 +190,10 @@ static void format_info_lk(char *line, char *r_name, char *r_type)
find_client_info(client_id, &pid, cl_name);
if (!strcmp(r_type, "gl")) {
- printf("LK GL %s ver %4u pid %u (%s)\n", mode, ver, pid, cl_name);
+ printf("LK GL %s ver %u pid %u (%s)\n", mode, ver, pid, cl_name);
} else if (!strcmp(r_type, "vg")) {
- printf("LK VG %s ver %4u pid %u (%s)\n", mode, ver, pid, cl_name);
+ printf("LK VG %s ver %u pid %u (%s)\n", mode, ver, pid, cl_name);
} else if (!strcmp(r_type, "lv")) {
printf("LK LV %s %s\n", mode, r_name);
@@ -232,10 +231,10 @@ static void format_info_r_action(char *line, char *r_name, char *r_type)
}
if (!strcmp(r_type, "gl")) {
- printf("LW GL %s ver %4u pid %u (%s)\n", mode, 0, pid, cl_name);
+ printf("LW GL %s ver %u pid %u (%s)\n", mode, 0, pid, cl_name);
} else if (!strcmp(r_type, "vg")) {
- printf("LW VG %s ver %4u pid %u (%s)\n", mode, 0, pid, cl_name);
+ printf("LW VG %s ver %u pid %u (%s)\n", mode, 0, pid, cl_name);
} else if (!strcmp(r_type, "lv")) {
printf("LW LV %s %s\n", mode, r_name);
@@ -245,7 +244,7 @@ static void format_info_r_action(char *line, char *r_name, char *r_type)
static void format_info_line(char *line, char *r_name, char *r_type)
{
if (!strncmp(line, "info=structs ", strlen("info=structs "))) {
- printf("%s", line);
+ /* only print this in the raw info dump */
} else if (!strncmp(line, "info=client ", strlen("info=client "))) {
save_client_info(line);
@@ -325,8 +324,6 @@ static daemon_reply _lvmlockd_send(const char *req_name, ...)
static int _lvmlockd_result(daemon_reply reply, int *result)
{
int reply_result;
- const char *reply_flags;
- const char *lock_type;
if (reply.error) {
log_error("lvmlockd_result reply error %d", reply.error);
@@ -344,14 +341,8 @@ static int _lvmlockd_result(daemon_reply reply, int *result)
return 0;
}
- /* The lock_type that lvmlockd used for locking. */
- lock_type = daemon_reply_str(reply, "lock_type", "none");
-
*result = reply_result;
- reply_flags = daemon_reply_str(reply, "result_flags", NULL);
-
- log_debug("lvmlockd_result %d %s lm %s", reply_result, reply_flags, lock_type);
return 1;
}
@@ -606,7 +597,7 @@ int main(int argc, char **argv)
_lvmlockd = lvmlockd_open(NULL);
if (_lvmlockd.socket_fd < 0 || _lvmlockd.error) {
- log_error("lvmlockd open error %d", _lvmlockd.error);
+ log_error("Cannot connect to lvmlockd.");
return -1;
}
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index dc0d3e7..b299050 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -3886,7 +3886,7 @@ static int print_lockspace(struct lockspace *ls, const char *prefix, int pos, in
"thread_work=%d "
"thread_stop=%d "
"thread_done=%d "
- "sanlock_gl_enabled=%d",
+ "sanlock_gl_enabled=%d\n",
prefix,
ls->name,
ls->vg_name,
@@ -4127,11 +4127,10 @@ static void client_recv_action(struct client *cl)
if (op == LD_OP_QUIT) {
log_debug("op quit");
pthread_mutex_lock(&lockspaces_mutex);
- if (list_empty(&lockspaces)) {
+ if (list_empty(&lockspaces))
daemon_quit = 1;
- } else {
+ else
result = -EBUSY;
- }
pthread_mutex_unlock(&lockspaces_mutex);
}
@@ -5511,7 +5510,7 @@ static int main_loop(daemon_state *ds_arg)
while (1) {
rv = poll(pollfd, pollfd_maxi + 1, -1);
- if (rv == -1 && errno == EINTR) {
+ if ((rv == -1 && errno == EINTR) || daemon_quit) {
if (daemon_quit) {
int count;
/* first sigterm would trigger stops, and
8 years, 8 months
master - cleanup: toolcontext: move report_list_item_separator into its group
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d9c67a9b21583e...
Commit: d9c67a9b21583e6665ba7c13a3fa2d0151082f5b
Parent: e6834b3237e2d523430a8b8a3ff24b0b27f7cb2f
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Jul 30 16:14:10 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Jul 30 16:14:10 2015 +0200
cleanup: toolcontext: move report_list_item_separator into its group
---
lib/commands/toolcontext.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index d2fd8a2..ec2242d 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -165,7 +165,6 @@ struct cmd_context {
* Host tags.
*/
struct dm_list tags; /* list of defined tags */
- const char *report_list_item_separator;
int hosttags;
/*
@@ -186,6 +185,7 @@ struct cmd_context {
/*
* Others - unsorted.
*/
+ const char *report_list_item_separator;
const char *time_format;
unsigned rand_seed;
};
8 years, 8 months
master - cleanup: toolcontext: make cmd_context more readable
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e6834b3237e2d5...
Commit: e6834b3237e2d523430a8b8a3ff24b0b27f7cb2f
Parent: c0629c13fe2dfa8d6aaace242209f4bf7675345f
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Jul 30 16:01:02 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Jul 30 16:01:02 2015 +0200
cleanup: toolcontext: make cmd_context more readable
Just shuffle the items and put them into logical groups so it's
visible at first sight what each group contains - it makes it a bit
easier to make heads and tails of the whole cmd_context monster.
---
lib/commands/toolcontext.h | 134 ++++++++++++++++++++++++++------------------
1 files changed, 79 insertions(+), 55 deletions(-)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 57feb01..d2fd8a2 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -69,29 +69,50 @@ struct cmd_context_initialized_parts {
/* FIXME Split into tool & library contexts */
/* command-instance-related variables needed by library */
struct cmd_context {
- struct dm_pool *libmem; /* For permanent config data */
- struct dm_pool *mem; /* Transient: Cleared between each command */
-
- const struct format_type *fmt; /* Current format to use by default */
- struct format_type *fmt_backup; /* Format to use for backups */
-
- struct dm_list formats; /* Available formats */
- struct dm_list segtypes; /* Available segment types */
- const char *system_id;
- const char *hostname;
- const char *kernel_vsn;
+ /*
+ * Memory handlers.
+ */
+ struct dm_pool *libmem; /* for permanent config data */
+ struct dm_pool *mem; /* transient: cleared between each command */
- unsigned rand_seed;
- char *linebuffer;
+ /*
+ * Command line and arguments.
+ */
const char *cmd_line;
struct command *command;
char **argv;
struct arg_values *arg_values;
struct dm_list arg_value_groups;
+ /*
+ * Format handlers.
+ */
+ const struct format_type *fmt; /* current format to use by default */
+ struct format_type *fmt_backup; /* format to use for backups */
+ struct dm_list formats; /* available formats */
+ struct dm_list segtypes; /* available segment types */
+
+ /*
+ * Machine and system identification.
+ */
+ const char *system_id;
+ const char *hostname;
+ const char *kernel_vsn;
+
+ /*
+ * Device identification.
+ */
+ struct dev_types *dev_types; /* recognized extra device types. */
+
+ /*
+ * Initialization state.
+ */
struct cmd_context_initialized_parts initialized;
- unsigned is_long_lived:1; /* Optimises persistent_filter handling */
+ /*
+ * Switches.
+ */
+ unsigned is_long_lived:1; /* optimises persistent_filter handling */
unsigned handles_missing_pvs:1;
unsigned handles_unknown_segments:1;
unsigned use_linear_target:1;
@@ -102,68 +123,71 @@ struct cmd_context {
unsigned report_binary_values_as_numeric:1;
unsigned metadata_read_only:1;
unsigned ignore_clustered_vgs:1;
- unsigned threaded:1; /* Set if running within a thread e.g. clvmd */
-
- const char *time_format;
-
- unsigned independent_metadata_areas:1; /* Active formats have MDAs outside PVs */
+ unsigned threaded:1; /* set if running within a thread e.g. clvmd */
+ unsigned independent_metadata_areas:1; /* active formats have MDAs outside PVs */
unsigned unknown_system_id:1;
- unsigned include_foreign_vgs:1; /* report/display cmds can reveal foreign VGs */
- unsigned include_shared_vgs:1; /* report/display cmds can reveal lockd VGs */
- unsigned include_active_foreign_vgs:1; /* cmd should process foreign VGs with active LVs */
- unsigned vg_read_print_access_error:1; /* print access errors from vg_read */
+ unsigned include_foreign_vgs:1; /* report/display cmds can reveal foreign VGs */
+ unsigned include_shared_vgs:1; /* report/display cmds can reveal lockd VGs */
+ unsigned include_active_foreign_vgs:1; /* cmd should process foreign VGs with active LVs */
+ unsigned vg_read_print_access_error:1; /* print access errors from vg_read */
unsigned lockd_gl_disable:1;
unsigned lockd_vg_disable:1;
unsigned lockd_lv_disable:1;
unsigned lockd_vg_default_sh:1;
unsigned lockd_vg_enforce_sh:1;
- struct dev_types *dev_types;
-
/*
- * Use of filters depends on whether lvmetad is used or not:
- *
- * - if lvmetad is used:
- * - cmd->lvmetad_filter used when scanning devices for lvmetad
- * - cmd->filter used when processing lvmetad responses
- * - cmd->full_filter used for remaining situations
- *
- * - if lvmetad is not used:
- * - cmd->lvmetad_filter is NULL
- * - cmd->filter == cmd->full_filter used for all situations
- *
+ * Filtering.
*/
- struct dev_filter *lvmetad_filter;
- struct dev_filter *filter;
- struct dev_filter *full_filter;
- int dump_filter; /* Dump filter when exiting? */
-
- struct dm_list config_files; /* master lvm config + any existing tag configs */
- struct profile_params *profile_params; /* profile handling params including loaded profile configs */
- struct dm_config_tree *cft; /* the whole cascade: CONFIG_STRING -> CONFIG_PROFILE -> CONFIG_FILE/CONFIG_MERGED_FILES */
+ struct dev_filter *lvmetad_filter; /* pre-lvmetad filter chain */
+ struct dev_filter *filter; /* post-lvmetad filter chain */
+ struct dev_filter *full_filter; /* lvmetad_filter + filter */
+ int dump_filter; /* Dump filter when exiting? */
- struct dm_hash_table *cft_def_hash; /* config definition hash used for validity check (item type + item recognized) */
-
- /* selected settings with original default/configured value which can be changed during cmd processing */
- struct config_info default_settings;
- /* may contain changed values compared to default_settings */
- struct config_info current_settings;
+ /*
+ * Configuration.
+ */
+ struct dm_list config_files; /* master lvm config + any existing tag configs */
+ struct profile_params *profile_params; /* profile handling params including loaded profile configs */
+ struct dm_config_tree *cft; /* the whole cascade: CONFIG_STRING -> CONFIG_PROFILE -> CONFIG_FILE/CONFIG_MERGED_FILES */
+ struct dm_hash_table *cft_def_hash; /* config definition hash used for validity check (item type + item recognized) */
+ struct config_info default_settings; /* selected settings with original default/configured value which can be changed during cmd processing */
+ struct config_info current_settings; /* may contain changed values compared to default_settings */
+ /*
+ * Archives and backups.
+ */
struct archive_params *archive_params;
struct backup_params *backup_params;
const char *stripe_filler;
- /* List of defined tags */
- struct dm_list tags;
+ /*
+ * Host tags.
+ */
+ struct dm_list tags; /* list of defined tags */
const char *report_list_item_separator;
int hosttags;
- const char *lib_dir; /* Cache value global/library_dir */
+ /*
+ * Paths.
+ */
+ const char *lib_dir; /* cache value global/library_dir */
char system_dir[PATH_MAX];
char dev_dir[PATH_MAX];
char proc_dir[PATH_MAX];
- char display_buffer[NAME_LEN * 10]; /* Ring buffer for upto 10 longest vg/lv names */
- unsigned display_lvname_idx; /* Index to ring buffer */
+
+ /*
+ * Buffers.
+ */
+ char display_buffer[NAME_LEN * 10]; /* ring buffer for upto 10 longest vg/lv names */
+ unsigned display_lvname_idx; /* index to ring buffer */
+ char *linebuffer;
+
+ /*
+ * Others - unsorted.
+ */
+ const char *time_format;
+ unsigned rand_seed;
};
/*
8 years, 8 months
master - commands: add new NO_METADATA_PROCESSING flag to selected commands
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c0629c13fe2dfa...
Commit: c0629c13fe2dfa8d6aaace242209f4bf7675345f
Parent: f6473baffc2d0b486b2aa941cf2681683026b3a5
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Jul 30 10:48:28 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Jul 30 13:56:13 2015 +0200
commands: add new NO_METADATA_PROCESSING flag to selected commands
When a command is flagged with NO_METADATA_PROCESSING flag, it means
such command does not process any metadata and hence it doens't require
lvmetad, lvmpolld and it can get away with no locking too. These are
mostly simple commands (like lvmconfig/dumpconfig, version, types,
segtypes and other builtin commands that do not process metadata
in any way).
At first, when lvm command is executed, create toolcontext without
initializing connections (lvmetad,lvmpolld) and without initializing
filters (which depend on connections init). Instead, delay this
initialization until we know we need this. That is, until the
lvm_run_command fn is called in which we know what the actual
command to run is and hence we can avoid any connection, filter
or locking initiliazation for commands that would not make use
of it anyway.
For all the other create_toolcontext calls, we keep the original
behaviour - the filters and connections are initialized together
with the toolcontext.
---
WHATS_NEW | 1 +
lib/locking/locking.c | 5 +++--
tools/commands.h | 20 ++++++++++----------
tools/lvmcmdline.c | 21 +++++++++++++++++----
tools/tools.h | 2 ++
5 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 1d8f472..1e04acb 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.127 -
=================================
+ Do not init filters, locking, lvmetad, lvmpolld if command doesn't use it.
Recognise vg/lv name format in dmsetup.
Fix regression in cache causing some PVs to bypass filters (2.02.105).
diff --git a/lib/locking/locking.c b/lib/locking/locking.c
index c88a85b..22e83d2 100644
--- a/lib/locking/locking.c
+++ b/lib/locking/locking.c
@@ -119,8 +119,9 @@ int init_locking(int type, struct cmd_context *cmd, int suppress_messages)
switch (type) {
case 0:
init_no_locking(&_locking, cmd, suppress_messages);
- log_warn("WARNING: Locking disabled. Be careful! "
- "This could corrupt your metadata.");
+ log_warn_suppress(suppress_messages,
+ "WARNING: Locking disabled. Be careful! "
+ "This could corrupt your metadata.");
return 1;
case 1:
diff --git a/tools/commands.h b/tools/commands.h
index 7f4b4e2..0ab578d 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -30,7 +30,7 @@ xx(e2fsadm,
xx(config,
"Display and manipulate configuration information",
- PERMITTED_READ_ONLY,
+ PERMITTED_READ_ONLY | NO_METADATA_PROCESSING,
"config\n"
"\t[-f|--file filename]\n"
"\t[--type {current|default|diff|full|list|missing|new|profilable|profilable-command|profilable-metadata}\n"
@@ -60,7 +60,7 @@ xx(config,
xx(devtypes,
"Display recognised built-in block device types",
- PERMITTED_READ_ONLY,
+ PERMITTED_READ_ONLY | NO_METADATA_PROCESSING,
"devtypes\n"
"\t[--aligned]\n"
"\t[--binary]\n"
@@ -86,7 +86,7 @@ xx(devtypes,
xx(dumpconfig,
"Display and manipulate configuration information",
- PERMITTED_READ_ONLY,
+ PERMITTED_READ_ONLY | NO_METADATA_PROCESSING,
"dumpconfig\n"
"\t[-f|--file filename]\n"
"\t[--type {current|default|diff|full|list|missing|new|profilable|profilable-command|profilable-metadata}\n"
@@ -116,12 +116,12 @@ xx(dumpconfig,
xx(formats,
"List available metadata formats",
- PERMITTED_READ_ONLY,
+ PERMITTED_READ_ONLY | NO_METADATA_PROCESSING,
"formats\n")
xx(help,
"Display help for commands",
- PERMITTED_READ_ONLY,
+ PERMITTED_READ_ONLY | NO_METADATA_PROCESSING,
"help <command>\n")
/*********
@@ -491,7 +491,7 @@ xx(lvmchange,
xx(lvmconfig,
"Display and manipulate configuration information",
- PERMITTED_READ_ONLY,
+ PERMITTED_READ_ONLY | NO_METADATA_PROCESSING,
"lvmconfig\n"
"\t[-f|--file filename]\n"
"\t[--type {current|default|diff|full|list|missing|new|profilable|profilable-command|profilable-metadata}\n"
@@ -979,17 +979,17 @@ xx(pvscan,
xx(segtypes,
"List available segment types",
- PERMITTED_READ_ONLY,
+ PERMITTED_READ_ONLY | NO_METADATA_PROCESSING,
"segtypes\n")
xx(systemid,
"Display the system ID, if any, currently set on this host",
- PERMITTED_READ_ONLY,
+ PERMITTED_READ_ONLY | NO_METADATA_PROCESSING,
"systemid\n")
xx(tags,
"List tags defined on this host",
- PERMITTED_READ_ONLY,
+ PERMITTED_READ_ONLY | NO_METADATA_PROCESSING,
"tags\n")
xx(vgcfgbackup,
@@ -1409,5 +1409,5 @@ xx(vgsplit,
xx(version,
"Display software and driver version information",
- PERMITTED_READ_ONLY,
+ PERMITTED_READ_ONLY | NO_METADATA_PROCESSING,
"version\n")
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 0c88164..b7809c7 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1463,6 +1463,11 @@ static int _init_lvmlockd(struct cmd_context *cmd)
return 1;
}
+static int _cmd_no_meta_proc(struct cmd_context *cmd)
+{
+ return cmd->command->flags & NO_METADATA_PROCESSING;
+}
+
int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
{
struct dm_config_tree *config_string_cft;
@@ -1554,6 +1559,12 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
if (!_prepare_profiles(cmd))
return_ECMD_FAILED;
+ if (!cmd->initialized.connections && !_cmd_no_meta_proc(cmd) && !init_connections(cmd))
+ return_ECMD_FAILED;
+
+ if (!cmd->initialized.filters && !_cmd_no_meta_proc(cmd) && !init_filters(cmd, 1))
+ return_ECMD_FAILED;
+
if (arg_count(cmd, readonly_ARG))
cmd->metadata_read_only = 1;
@@ -1587,7 +1598,9 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
goto out;
}
- if (arg_count(cmd, readonly_ARG)) {
+ if (_cmd_no_meta_proc(cmd))
+ locking_type = 0;
+ else if (arg_count(cmd, readonly_ARG)) {
if (find_config_tree_bool(cmd, global_use_lvmlockd_CFG, NULL)) {
/*
* FIXME: we could use locking_type 5 here if that didn't
@@ -1610,12 +1623,12 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
else
locking_type = -1;
- if (!init_locking(locking_type, cmd, arg_count(cmd, sysinit_ARG))) {
+ if (!init_locking(locking_type, cmd, _cmd_no_meta_proc(cmd) || arg_count(cmd, sysinit_ARG))) {
ret = ECMD_FAILED;
goto_out;
}
- if (!_init_lvmlockd(cmd)) {
+ if (!_cmd_no_meta_proc(cmd) && !_init_lvmlockd(cmd)) {
ret = ECMD_FAILED;
goto_out;
}
@@ -2056,7 +2069,7 @@ int lvm2_main(int argc, char **argv)
if (!alias && argc > 1 && !strcmp(argv[1], "version"))
return lvm_return_code(version(NULL, argc, argv));
- if (!(cmd = init_lvm(1, 1)))
+ if (!(cmd = init_lvm(0, 0)))
return -1;
cmd->argv = argv;
diff --git a/tools/tools.h b/tools/tools.h
index 5ee5786..4ed893f 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -103,6 +103,8 @@ struct arg_value_group_list {
#define ONE_VGNAME_ARG 0x00000010
/* Command needs a shared lock on a VG; it only reads the VG. */
#define LOCKD_VG_SH 0x00000020
+/* Command does not process any metadata. */
+#define NO_METADATA_PROCESSING 0x00000040
/* a register of the lvm commands */
struct command {
8 years, 8 months
master - toolcontext: add switches to create_toolcontext for connections and filters init
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f6473baffc2d0b...
Commit: f6473baffc2d0b486b2aa941cf2681683026b3a5
Parent: 3e343ba5ef02d8ae3e87eadc80cf69fc34c65622
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Jul 30 10:34:10 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Jul 30 13:54:09 2015 +0200
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.)
---
daemons/clvmd/lvm-functions.c | 2 +-
daemons/lvmetad/testclient.c | 2 +-
lib/commands/toolcontext.c | 54 ++++++++++++++++++++++++++++------------
lib/commands/toolcontext.h | 8 +++++-
liblvm/lvm_base.c | 2 +-
tools/lvm2cmdline.h | 2 +-
tools/lvmcmdlib.c | 2 +-
tools/lvmcmdline.c | 7 +++--
8 files changed, 54 insertions(+), 25 deletions(-)
diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c
index e7dbfde..99e7317 100644
--- a/daemons/clvmd/lvm-functions.c
+++ b/daemons/clvmd/lvm-functions.c
@@ -899,7 +899,7 @@ int init_clvm(struct dm_hash_table *excl_uuid)
if (!get_initial_state(excl_uuid))
log_error("Cannot load initial lock states.");
- if (!(cmd = create_toolcontext(1, NULL, 0, 1))) {
+ if (!(cmd = create_toolcontext(1, NULL, 0, 1, 1, 1))) {
log_error("Failed to allocate command context");
return 0;
}
diff --git a/daemons/lvmetad/testclient.c b/daemons/lvmetad/testclient.c
index fbf7b65..59aedc6 100644
--- a/daemons/lvmetad/testclient.c
+++ b/daemons/lvmetad/testclient.c
@@ -124,7 +124,7 @@ int main(int argc, char **argv) {
if (argc > 1) {
int i;
- struct cmd_context *cmd = create_toolcontext(0, NULL, 0, 0);
+ struct cmd_context *cmd = create_toolcontext(0, NULL, 0, 0, 1, 1);
for (i = 1; i < argc; ++i) {
const char *uuid = NULL;
scan(h, argv[i]);
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index dadb3c5..c087820 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -55,7 +55,6 @@
#endif
static const size_t linebuffer_size = 4096;
-static int _init_connections(struct cmd_context *cmd);
/*
* Copy the input string, removing invalid characters.
@@ -675,9 +674,6 @@ 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));
- if (!_init_connections(cmd))
- return_0;
-
if (!_init_system_id(cmd))
return_0;
@@ -1165,7 +1161,7 @@ bad:
* md component filter -> fw raid filter
*
*/
-static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
+int init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
{
const char *dev_cache;
struct dev_filter *filter = NULL, *filter_components[2] = {0};
@@ -1173,6 +1169,11 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
const struct dm_config_node *cn;
struct timespec ts, cts;
+ if (!cmd->initialized.connections) {
+ log_error(INTERNAL_ERROR "connections must be initialized before filters");
+ return 0;
+ }
+
cmd->dump_filter = 0;
cmd->lvmetad_filter = _init_lvmetad_filter_chain(cmd);
@@ -1253,6 +1254,7 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
dev_cache);
}
+ cmd->initialized.filters = 1;
return 1;
bad:
if (!filter) {
@@ -1276,6 +1278,7 @@ bad:
if (cmd->lvmetad_filter)
cmd->lvmetad_filter->destroy(cmd->lvmetad_filter);
+ cmd->initialized.filters = 0;
return 0;
}
@@ -1696,26 +1699,33 @@ static int _init_lvmpolld(struct cmd_context *cmd)
return 1;
}
-static int _init_connections(struct cmd_context *cmd)
+int init_connections(struct cmd_context *cmd)
{
+
if (!_init_lvmetad(cmd)) {
log_error("Failed to initialize lvmetad connection.");
- return 0;
+ goto bad;
}
if (!_init_lvmpolld(cmd)) {
log_error("Failed to initialize lvmpolld connection.");
- return 0;
+ goto bad;
}
+ cmd->initialized.connections = 1;
return 1;
+bad:
+ cmd->initialized.connections = 0;
+ return 0;
}
/* Entry point */
struct cmd_context *create_toolcontext(unsigned is_long_lived,
const char *system_dir,
unsigned set_buffering,
- unsigned threaded)
+ unsigned threaded,
+ unsigned set_connections,
+ unsigned set_filters)
{
struct cmd_context *cmd;
FILE *new_stream;
@@ -1859,9 +1869,6 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
if (!_init_dev_cache(cmd))
goto_out;
- if (!_init_filters(cmd, 1))
- goto_out;
-
memlock_init(cmd);
if (!_init_formats(cmd))
@@ -1880,6 +1887,12 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
_init_globals(cmd);
+ if (set_connections && !init_connections(cmd))
+ return_0;
+
+ if (set_filters && !init_filters(cmd, 1))
+ goto_out;
+
cmd->default_settings.cache_vgmetadata = 1;
cmd->current_settings = cmd->default_settings;
@@ -1957,14 +1970,19 @@ static void _destroy_filters(struct cmd_context *cmd)
cmd->full_filter->destroy(cmd->full_filter);
cmd->lvmetad_filter = cmd->filter = cmd->full_filter = NULL;
}
+ cmd->initialized.filters = 0;
}
int refresh_filters(struct cmd_context *cmd)
{
int r, saved_ignore_suspended_devices = ignore_suspended_devices();
+ if (!cmd->initialized.filters)
+ /* if filters not initialized, there's nothing to refresh */
+ return 1;
+
_destroy_filters(cmd);
- if (!(r = _init_filters(cmd, 0)))
+ if (!(r = init_filters(cmd, 0)))
stack;
/*
@@ -2074,9 +2092,6 @@ int refresh_toolcontext(struct cmd_context *cmd)
if (!_init_dev_cache(cmd))
return_0;
- if (!_init_filters(cmd, 0))
- return_0;
-
if (!_init_formats(cmd))
return_0;
@@ -2091,6 +2106,12 @@ int refresh_toolcontext(struct cmd_context *cmd)
cmd->initialized.config = 1;
+ if (cmd->initialized.connections && !init_connections(cmd))
+ return_0;
+
+ if (cmd->initialized.filters && !init_filters(cmd, 0))
+ return_0;
+
reset_lvm_errno(1);
return 1;
}
@@ -2159,6 +2180,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
lvmetad_release_token();
lvmetad_disconnect();
lvmpolld_disconnect();
+ cmd->initialized.connections = 0;
release_log_memory();
activation_exit();
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index c59024b..57feb01 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -62,6 +62,8 @@ struct config_tree_list {
struct cmd_context_initialized_parts {
unsigned config:1; /* used to reinitialize config if previous init was not successful */
+ unsigned filters:1;
+ unsigned connections:1;
};
/* FIXME Split into tool & library contexts */
@@ -171,13 +173,17 @@ struct cmd_context {
struct cmd_context *create_toolcontext(unsigned is_long_lived,
const char *system_dir,
unsigned set_buffering,
- unsigned threaded);
+ unsigned threaded,
+ unsigned set_connections,
+ unsigned set_filters);
void destroy_toolcontext(struct cmd_context *cmd);
int refresh_toolcontext(struct cmd_context *cmd);
int refresh_filters(struct cmd_context *cmd);
int process_profilable_config(struct cmd_context *cmd);
int config_files_changed(struct cmd_context *cmd);
int init_lvmcache_orphans(struct cmd_context *cmd);
+int init_filters(struct cmd_context *cmd, unsigned load_persistent_cache);
+int init_connections(struct cmd_context *cmd);
struct format_type *get_format_by_name(struct cmd_context *cmd, const char *format);
diff --git a/liblvm/lvm_base.c b/liblvm/lvm_base.c
index c1954d1..5b14c3b 100644
--- a/liblvm/lvm_base.c
+++ b/liblvm/lvm_base.c
@@ -45,7 +45,7 @@ static lvm_t _lvm_init(const char *system_dir)
/* create context */
/* FIXME: split create_toolcontext */
/* FIXME: make all globals configurable */
- cmd = create_toolcontext(0, system_dir, 0, 0);
+ cmd = create_toolcontext(0, system_dir, 0, 0, 1, 1);
if (!cmd)
return NULL;
diff --git a/tools/lvm2cmdline.h b/tools/lvm2cmdline.h
index 5c4889e..fe77d56 100644
--- a/tools/lvm2cmdline.h
+++ b/tools/lvm2cmdline.h
@@ -31,7 +31,7 @@ int lvm2_main(int argc, char **argv);
void *cmdlib_lvm2_init(unsigned static_compile);
void lvm_fin(struct cmd_context *cmd);
-struct cmd_context *init_lvm(void);
+struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters);
void lvm_register_commands(void);
int lvm_split(char *str, int *argc, char **argv, int max);
int lvm_run_command(struct cmd_context *cmd, int argc, char **argv);
diff --git a/tools/lvmcmdlib.c b/tools/lvmcmdlib.c
index 76576c2..26f160f 100644
--- a/tools/lvmcmdlib.c
+++ b/tools/lvmcmdlib.c
@@ -33,7 +33,7 @@ void *cmdlib_lvm2_init(unsigned static_compile)
lvm_register_commands();
init_is_static(static_compile);
- if (!(cmd = init_lvm()))
+ if (!(cmd = init_lvm(1, 1)))
return NULL;
return (void *) cmd;
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 98a2c30..0c88164 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1873,7 +1873,7 @@ static int _close_stray_fds(const char *command)
return 1;
}
-struct cmd_context *init_lvm(void)
+struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters)
{
struct cmd_context *cmd;
@@ -1887,7 +1887,8 @@ struct cmd_context *init_lvm(void)
*/
dm_set_name_mangling_mode(DM_STRING_MANGLING_NONE);
- if (!(cmd = create_toolcontext(0, NULL, 1, 0))) {
+ if (!(cmd = create_toolcontext(0, NULL, 1, 0,
+ set_connections, set_filters))) {
udev_fin_library_context();
return_NULL;
}
@@ -2055,7 +2056,7 @@ int lvm2_main(int argc, char **argv)
if (!alias && argc > 1 && !strcmp(argv[1], "version"))
return lvm_return_code(version(NULL, argc, argv));
- if (!(cmd = init_lvm()))
+ if (!(cmd = init_lvm(1, 1)))
return -1;
cmd->argv = argv;
8 years, 8 months
master - refactor: toolcontext: move lvmetad and lvmpolld init into separate function
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3e343ba5ef02d8...
Commit: 3e343ba5ef02d8ae3e87eadc80cf69fc34c65622
Parent: 6b0c464a3462c568931c22fe71cc4f80b7ead508
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Jul 30 10:13:45 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Jul 30 13:54:09 2015 +0200
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).
---
lib/commands/toolcontext.c | 98 +++++++++++++++++++++++++++++---------------
1 files changed, 65 insertions(+), 33 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index da0ca22..dadb3c5 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -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,
8 years, 8 months
master - refactor: toolcontext: add struct cmd_context_initialized_parts
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6b0c464a3462c5...
Commit: 6b0c464a3462c568931c22fe71cc4f80b7ead508
Parent: 9aabf441bdb8480f2e99722955fedcb4a19d760d
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Jul 30 09:59:39 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Jul 30 13:54:05 2015 +0200
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...
---
daemons/clvmd/lvm-functions.c | 2 +-
lib/commands/toolcontext.c | 8 ++++----
lib/commands/toolcontext.h | 8 +++++++-
tools/lvmcmdline.c | 2 +-
4 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c
index dafffcc..e7dbfde 100644
--- a/daemons/clvmd/lvm-functions.c
+++ b/daemons/clvmd/lvm-functions.c
@@ -510,7 +510,7 @@ int do_lock_lv(unsigned char command, unsigned char lock_flags, char *resource)
DEBUGLOG("do_lock_lv: resource '%s', cmd = %s, flags = %s, critical_section = %d\n",
resource, decode_locking_cmd(command), decode_flags(lock_flags), critical_section());
- if (!cmd->config_initialized || config_files_changed(cmd)) {
+ if (!cmd->initialized.config || config_files_changed(cmd)) {
/* Reinitialise various settings inc. logging, filters */
if (do_refresh_cache()) {
log_error("Updated config file invalid. Aborting.");
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 3fe2bb2..da0ca22 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1851,9 +1851,9 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
cmd->default_settings.cache_vgmetadata = 1;
cmd->current_settings = cmd->default_settings;
- cmd->config_initialized = 1;
+ cmd->initialized.config = 1;
out:
- if (!cmd->config_initialized) {
+ if (!cmd->initialized.config) {
destroy_toolcontext(cmd);
cmd = NULL;
}
@@ -1979,7 +1979,7 @@ int refresh_toolcontext(struct cmd_context *cmd)
_destroy_config(cmd);
- cmd->config_initialized = 0;
+ cmd->initialized.config = 0;
cmd->hosttags = 0;
@@ -2057,7 +2057,7 @@ int refresh_toolcontext(struct cmd_context *cmd)
if (!_init_backup(cmd))
return_0;
- cmd->config_initialized = 1;
+ cmd->initialized.config = 1;
reset_lvm_errno(1);
return 1;
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 4e8998d..c59024b 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -60,6 +60,10 @@ struct config_tree_list {
struct dm_config_tree *cft;
};
+struct cmd_context_initialized_parts {
+ unsigned config:1; /* used to reinitialize config if previous init was not successful */
+};
+
/* FIXME Split into tool & library contexts */
/* command-instance-related variables needed by library */
struct cmd_context {
@@ -82,6 +86,9 @@ struct cmd_context {
char **argv;
struct arg_values *arg_values;
struct dm_list arg_value_groups;
+
+ struct cmd_context_initialized_parts initialized;
+
unsigned is_long_lived:1; /* Optimises persistent_filter handling */
unsigned handles_missing_pvs:1;
unsigned handles_unknown_segments:1;
@@ -132,7 +139,6 @@ struct cmd_context {
struct dm_list config_files; /* master lvm config + any existing tag configs */
struct profile_params *profile_params; /* profile handling params including loaded profile configs */
struct dm_config_tree *cft; /* the whole cascade: CONFIG_STRING -> CONFIG_PROFILE -> CONFIG_FILE/CONFIG_MERGED_FILES */
- int config_initialized; /* used to reinitialize config if previous init was not successful */
struct dm_hash_table *cft_def_hash; /* config definition hash used for validity check (item type + item recognized) */
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 9e0d029..98a2c30 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1541,7 +1541,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
goto_out;
}
- if (arg_count(cmd, config_ARG) || !cmd->config_initialized || config_files_changed(cmd)) {
+ if (arg_count(cmd, config_ARG) || !cmd->initialized.config || config_files_changed(cmd)) {
/* Reinitialise various settings inc. logging, filters */
if (!refresh_toolcontext(cmd)) {
if ((config_string_cft = remove_config_tree_by_source(cmd, CONFIG_STRING)))
8 years, 8 months