Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b40ccdd57cc0d57a…
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);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c0629c13fe2dfa8d…
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 {