stable-2.02 - activation: use cmd pending mem for pending_delete
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ad86cda4d79704dcce1...
Commit: ad86cda4d79704dcce13d98cd9579baab56b7e7b
Parent: 36523a398d50381f8355e719b98c3ce584b81a23
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Aug 27 12:18:47 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Aug 27 15:59:33 2019 +0200
activation: use cmd pending mem for pending_delete
Since we need to preserve allocated strings across 2 separate
activation calls of '_tree_action()' we need to use other mem
pool them dm->mem - but since cmd->mem is released between
individual lvm2 locking calls, we rather introduce a new separate
mem pool just for pending deletes with easy to see life-span.
(not using 'libmem' as it would basicaly keep allocations over
the whole lifetime of clvmd)
This patch is fixing previous commmit where the memory was
improperly used after pool release.
---
lib/activate/dev_manager.c | 31 ++++++++++++-------------------
lib/commands/toolcontext.c | 10 ++++++++++
lib/commands/toolcontext.h | 1 +
3 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index dd585da..dc64159 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -64,7 +64,6 @@ struct dev_manager {
int activation; /* building activation tree */
int suspend; /* building suspend tree */
unsigned track_external_lv_deps;
- struct dm_list pending_delete; /* str_list of dlid(s) with pending delete */
unsigned track_pending_delete;
unsigned track_pvmove_deps;
@@ -1251,8 +1250,6 @@ struct dev_manager *dev_manager_create(struct cmd_context *cmd,
dm_udev_set_sync_support(cmd->current_settings.udev_sync);
- dm_list_init(&dm->pending_delete);
-
return dm;
bad:
@@ -1939,7 +1936,7 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
if (!(name = dm_build_dm_name(dm->mem, lv->vg->name, lv->name, layer)))
return_0;
- if (!(dlid = build_dm_uuid(dm->mem, lv, layer)))
+ if (!(dlid = build_dm_uuid(dm->track_pending_delete ? dm->cmd->pending_delete_mem : dm->mem, lv, layer)))
return_0;
if (!_info(dm->cmd, name, dlid, 1, 0, &info, NULL, NULL))
@@ -1981,7 +1978,7 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
if (info.exists && dm->track_pending_delete) {
log_debug_activation("Tracking pending delete for %s (%s).",
display_lvname(lv), dlid);
- if (!str_list_add(dm->mem, &dm->pending_delete, dlid))
+ if (!str_list_add(dm->cmd->pending_delete_mem, &dm->cmd->pending_delete, dlid))
return_0;
}
@@ -3218,20 +3215,26 @@ static int _clean_tree(struct dev_manager *dm, struct dm_tree_node *root, const
if (non_toplevel_tree_dlid && !strcmp(non_toplevel_tree_dlid, uuid))
continue;
- if (!str_list_add(dm->mem, &dm->pending_delete, uuid))
+ if (!(uuid = dm_pool_strdup(dm->cmd->pending_delete_mem, uuid))) {
+ log_error("_clean_tree: Failed to duplicate uuid.");
+ return 0;
+ }
+
+ if (!str_list_add(dm->cmd->pending_delete_mem, &dm->cmd->pending_delete, uuid))
return_0;
}
/* Deactivate any tracked pending delete nodes */
- if (!dm_list_empty(&dm->pending_delete) && !dm_get_suspended_counter()) {
+ if (!dm_list_empty(&dm->cmd->pending_delete) && !dm_get_suspended_counter()) {
fs_unlock();
dm_tree_set_cookie(root, fs_get_cookie());
- dm_list_iterate_items(dl, &dm->pending_delete) {
+ dm_list_iterate_items(dl, &dm->cmd->pending_delete) {
log_debug_activation("Deleting tracked UUID %s.", dl->str);
if (!dm_tree_deactivate_children(root, dl->str, strlen(dl->str)))
return_0;
}
- dm_list_init(&dm->pending_delete);
+ dm_list_init(&dm->cmd->pending_delete);
+ dm_pool_empty(dm->cmd->pending_delete_mem);
}
return 1;
@@ -3358,22 +3361,12 @@ out_no_root:
int dev_manager_activate(struct dev_manager *dm, const struct logical_volume *lv,
struct lv_activate_opts *laopts)
{
- dm_list_splice(&dm->pending_delete, &lv->vg->cmd->pending_delete);
-
if (!_tree_action(dm, lv, laopts, ACTIVATE))
return_0;
if (!_tree_action(dm, lv, laopts, CLEAN))
return_0;
- if (!dm_list_empty(&dm->pending_delete)) {
- log_debug("Preserving %d device(s) for removal while being suspended.",
- dm_list_size(&dm->pending_delete));
- if (!(str_list_dup(lv->vg->cmd->mem, &lv->vg->cmd->pending_delete,
- &dm->pending_delete)))
- return_0;
- }
-
return 1;
}
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index c90cb57..95fb343 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1761,6 +1761,8 @@ void destroy_config_context(struct cmd_context *cmd)
dm_pool_destroy(cmd->mem);
if (cmd->libmem)
dm_pool_destroy(cmd->libmem);
+ if (cmd->pending_delete_mem)
+ dm_pool_destroy(cmd->pending_delete_mem);
dm_free(cmd);
}
@@ -1789,6 +1791,9 @@ struct cmd_context *create_config_context(void)
if (!(cmd->mem = dm_pool_create("command", 4 * 1024)))
goto out;
+ if (!(cmd->pending_delete_mem = dm_pool_create("pending_delete", 1024)))
+ goto_out;
+
dm_list_init(&cmd->config_files);
dm_list_init(&cmd->tags);
@@ -1937,6 +1942,9 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
goto out;
}
+ if (!(cmd->pending_delete_mem = dm_pool_create("pending_delete", 1024)))
+ goto_out;
+
if (!_init_lvm_conf(cmd))
goto_out;
@@ -2264,6 +2272,8 @@ void destroy_toolcontext(struct cmd_context *cmd)
if (cmd->libmem)
dm_pool_destroy(cmd->libmem);
+ if (cmd->pending_delete_mem)
+ dm_pool_destroy(cmd->pending_delete_mem);
#ifndef VALGRIND_POOL
if (cmd->linebuffer) {
/* Reset stream buffering to defaults */
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 9c225b8..4b2a079 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -232,6 +232,7 @@ struct cmd_context {
const char *time_format;
unsigned rand_seed;
struct dm_list pending_delete; /* list of LVs for removal */
+ struct dm_pool *pending_delete_mem; /* memory pool for pending deletes */
};
/*
4 years, 7 months
master - activation: use cmd pending mem for pending_delete
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b2885b7103049b11ca3...
Commit: b2885b7103049b11ca3e98fe0c8898df2ce5f9ac
Parent: aefd177b047eb548e63ac94c9eb442604175d3bc
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Aug 27 12:18:47 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Aug 27 15:54:42 2019 +0200
activation: use cmd pending mem for pending_delete
Since we need to preserve allocated strings across 2 separate
activation calls of '_tree_action()' we need to use other mem
pool them dm->mem - but since cmd->mem is released between
individual lvm2 locking calls, we rather introduce a new separate
mem pool just for pending deletes with easy to see life-span.
(not using 'libmem' as it would basicaly keep allocations over
the whole lifetime of clvmd)
This patch is fixing previous commmit where the memory was
improperly used after pool release.
---
lib/activate/dev_manager.c | 31 ++++++++++++-------------------
lib/commands/toolcontext.c | 10 ++++++++++
lib/commands/toolcontext.h | 1 +
3 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 74dbc60..3a6f11f 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -64,7 +64,6 @@ struct dev_manager {
int activation; /* building activation tree */
int suspend; /* building suspend tree */
unsigned track_external_lv_deps;
- struct dm_list pending_delete; /* str_list of dlid(s) with pending delete */
unsigned track_pending_delete;
unsigned track_pvmove_deps;
@@ -1387,8 +1386,6 @@ struct dev_manager *dev_manager_create(struct cmd_context *cmd,
dm_udev_set_sync_support(cmd->current_settings.udev_sync);
- dm_list_init(&dm->pending_delete);
-
return dm;
bad:
@@ -2165,7 +2162,7 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
if (!(name = dm_build_dm_name(dm->mem, lv->vg->name, lv->name, layer)))
return_0;
- if (!(dlid = build_dm_uuid(dm->mem, lv, layer)))
+ if (!(dlid = build_dm_uuid(dm->track_pending_delete ? dm->cmd->pending_delete_mem : dm->mem, lv, layer)))
return_0;
if (!_info(dm->cmd, name, dlid, 1, 0, &info, NULL, NULL))
@@ -2207,7 +2204,7 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
if (info.exists && dm->track_pending_delete) {
log_debug_activation("Tracking pending delete for %s (%s).",
display_lvname(lv), dlid);
- if (!str_list_add(dm->mem, &dm->pending_delete, dlid))
+ if (!str_list_add(dm->cmd->pending_delete_mem, &dm->cmd->pending_delete, dlid))
return_0;
}
@@ -3599,20 +3596,26 @@ static int _clean_tree(struct dev_manager *dm, struct dm_tree_node *root, const
if (non_toplevel_tree_dlid && !strcmp(non_toplevel_tree_dlid, uuid))
continue;
- if (!str_list_add(dm->mem, &dm->pending_delete, uuid))
+ if (!(uuid = dm_pool_strdup(dm->cmd->pending_delete_mem, uuid))) {
+ log_error("_clean_tree: Failed to duplicate uuid.");
+ return 0;
+ }
+
+ if (!str_list_add(dm->cmd->pending_delete_mem, &dm->cmd->pending_delete, uuid))
return_0;
}
/* Deactivate any tracked pending delete nodes */
- if (!dm_list_empty(&dm->pending_delete) && !dm_get_suspended_counter()) {
+ if (!dm_list_empty(&dm->cmd->pending_delete) && !dm_get_suspended_counter()) {
fs_unlock();
dm_tree_set_cookie(root, fs_get_cookie());
- dm_list_iterate_items(dl, &dm->pending_delete) {
+ dm_list_iterate_items(dl, &dm->cmd->pending_delete) {
log_debug_activation("Deleting tracked UUID %s.", dl->str);
if (!dm_tree_deactivate_children(root, dl->str, strlen(dl->str)))
return_0;
}
- dm_list_init(&dm->pending_delete);
+ dm_list_init(&dm->cmd->pending_delete);
+ dm_pool_empty(dm->cmd->pending_delete_mem);
}
return 1;
@@ -3739,22 +3742,12 @@ out_no_root:
int dev_manager_activate(struct dev_manager *dm, const struct logical_volume *lv,
struct lv_activate_opts *laopts)
{
- dm_list_splice(&dm->pending_delete, &lv->vg->cmd->pending_delete);
-
if (!_tree_action(dm, lv, laopts, ACTIVATE))
return_0;
if (!_tree_action(dm, lv, laopts, CLEAN))
return_0;
- if (!dm_list_empty(&dm->pending_delete)) {
- log_debug("Preserving %d device(s) for removal while being suspended.",
- dm_list_size(&dm->pending_delete));
- if (!(str_list_dup(lv->vg->cmd->mem, &lv->vg->cmd->pending_delete,
- &dm->pending_delete)))
- return_0;
- }
-
return 1;
}
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 0a93553..479d499 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1492,6 +1492,8 @@ void destroy_config_context(struct cmd_context *cmd)
dm_pool_destroy(cmd->mem);
if (cmd->libmem)
dm_pool_destroy(cmd->libmem);
+ if (cmd->pending_delete_mem)
+ dm_pool_destroy(cmd->pending_delete_mem);
free(cmd);
}
@@ -1520,6 +1522,9 @@ struct cmd_context *create_config_context(void)
if (!(cmd->mem = dm_pool_create("command", 4 * 1024)))
goto out;
+ if (!(cmd->pending_delete_mem = dm_pool_create("pending_delete", 1024)))
+ goto_out;
+
dm_list_init(&cmd->config_files);
dm_list_init(&cmd->tags);
dm_list_init(&cmd->hints);
@@ -1667,6 +1672,9 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
goto out;
}
+ if (!(cmd->pending_delete_mem = dm_pool_create("pending_delete", 1024)))
+ goto_out;
+
if (!_init_lvm_conf(cmd))
goto_out;
@@ -1970,6 +1978,8 @@ void destroy_toolcontext(struct cmd_context *cmd)
if (cmd->libmem)
dm_pool_destroy(cmd->libmem);
+ if (cmd->pending_delete_mem)
+ dm_pool_destroy(cmd->pending_delete_mem);
#ifndef VALGRIND_POOL
if (cmd->linebuffer) {
/* Reset stream buffering to defaults */
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 8a20d1f..c09558a 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -240,6 +240,7 @@ struct cmd_context {
const char *time_format;
unsigned rand_seed;
struct dm_list pending_delete; /* list of LVs for removal */
+ struct dm_pool *pending_delete_mem; /* memory pool for pending deletes */
};
/*
4 years, 7 months
stable-2.02 - cov: Fix a leak
by Marian Csontos
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=36523a398d50381f835...
Commit: 36523a398d50381f8355e719b98c3ce584b81a23
Parent: e4f72e6655ff756c886ad78abcc696d3267e6c5f
Author: Marian Csontos <mcsontos(a)redhat.com>
AuthorDate: Tue Aug 27 12:21:41 2019 +0200
Committer: Marian Csontos <mcsontos(a)redhat.com>
CommitterDate: Tue Aug 27 12:23:13 2019 +0200
cov: Fix a leak
---
lib/device/bcache.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index a250bfd..d487ca2 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -516,6 +516,7 @@ static bool _sync_issue(struct io_engine *ioe, enum dir d, int fd,
(unsigned long long)limit_nbytes,
(unsigned long long)extra_nbytes,
(unsigned long long)_last_byte_sector_size);
+ free(io);
return false;
}
}
@@ -547,8 +548,8 @@ static bool _sync_issue(struct io_engine *ioe, enum dir d, int fd,
log_debug("Device write error %d offset %llu len %llu", errno,
(unsigned long long)(where + pos),
(unsigned long long)(len - pos));
- free(io);
- return false;
+ free(io);
+ return false;
}
pos += rv;
}
4 years, 7 months
stable-2.02 - build: Fix make rpm with releases
by Marian Csontos
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e4f72e6655ff756c886...
Commit: e4f72e6655ff756c886ad78abcc696d3267e6c5f
Parent: 8bcd482cc5fc58c9d5ff5305f1f1bff5d80eaa92
Author: Marian Csontos <mcsontos(a)redhat.com>
AuthorDate: Tue Jul 2 15:18:40 2019 +0200
Committer: Marian Csontos <mcsontos(a)redhat.com>
CommitterDate: Tue Aug 27 12:23:13 2019 +0200
build: Fix make rpm with releases
- git describe returns just v2_02_182 instead of e.g.
v2_02_181-44-adf123, so cut needs -s option.
- there is no dash in VERSION_DM so we need to split on space first.
---
Makefile.in | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/Makefile.in b/Makefile.in
index e2f5a84..29d5bed 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -124,11 +124,11 @@ rpm: dist
$(LN_S) -f $(abs_top_srcdir)/spec/build.inc $(rpmbuilddir)/SOURCES
$(LN_S) -f $(abs_top_srcdir)/spec/macros.inc $(rpmbuilddir)/SOURCES
$(LN_S) -f $(abs_top_srcdir)/spec/packages.inc $(rpmbuilddir)/SOURCES
- DM_VER=$$(cut -d- -f1 $(top_srcdir)/VERSION_DM);\
- GIT_VER=$$(cd $(top_srcdir); git describe | cut -d- --output-delimiter=. -f2,3 || echo 0);\
+ DM_VER=$$(cut -d' ' -f1 $(top_srcdir)/VERSION_DM | cut -d- -f1);\
+ GIT_VER=$$(cd $(top_srcdir); git describe | cut -s -d- --output-delimiter=. -f2,3);\
sed -e "s,\(device_mapper_version\) [0-9.]*$$,\1 $$DM_VER," \
-e "s,^\(Version:[^0-9%]*\)[0-9.]*$$,\1 $(LVM_VER)," \
- -e "s,^\(Release:[^0-9%]*\)[0-9.]\+,\1 $$GIT_VER," \
+ -e "s,^\(Release:[^0-9%]*\)[0-9.]\+,\1 $${GIT_VER:-"0"}," \
$(top_srcdir)/spec/source.inc >$(rpmbuilddir)/SOURCES/source.inc
rpmbuild -v --define "_topdir $(rpmbuilddir)" -ba $(top_srcdir)/spec/lvm2.spec
4 years, 7 months
stable-2.02 - pvscan: avoid redundant activation
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8bcd482cc5fc58c9d5f...
Commit: 8bcd482cc5fc58c9d5ff5305f1f1bff5d80eaa92
Parent: 93de9b59c21e6a3b29ccaa6425fde50a9053bdc2
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Aug 19 14:22:01 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Mon Aug 26 16:25:18 2019 -0500
pvscan: avoid redundant activation
Use temp files in /run/lvm/vgs_online/ to keep track of when
a VG has been autoactivated by pvscan. When pvscan autoactivates
a VG, it creates a temp file with the VG's name. Before a
subsequent pvscan tries to autoactivate the same VG, it checks
if a temp file exists for the VG name, and if so it skips it.
This can commonly happen when many devices appear on the system
at once, which generates several concurrent pvscans. In this case
the first pvscan does initialization by scanning all devices and
activating any complete VGs. The other pvscans would attempt to
activate the same complete VGs again. This extra work could
create a bottleneck of pvscan commands.
If a VG is deactivated by vgchange, the vg online file is removed.
If PVs are then disconnected/reconnected, pvscan will again
autoactivate the VG.
Also, this patch disables the VG refresh that could be called from
pvscan --cache -aay if lvmetad detects metadata inconsistencies.
The role of pvscan should be limited to basic autoactivation, and
any refresh scenarios are special cases that are not appropriate
for automation.
The warning printed by commands retrying an lvmetad connection
has been reduced to once every 10 seconds. New output messages
have been added to pvscan to record when pvscan is falling back
to direct activation of all VGs.
---
lib/cache/lvmetad.c | 11 +++--
tools/pvscan.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++--
tools/vgchange.c | 13 ++++++
3 files changed, 123 insertions(+), 9 deletions(-)
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index 86a880a..d7e798d 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -248,7 +248,7 @@ int lvmetad_token_matches(struct cmd_context *cmd)
const char *daemon_token;
unsigned int delay_usec = 0;
unsigned int wait_sec = 0;
- uint64_t now = 0, wait_start = 0;
+ uint64_t now = 0, wait_start = 0, last_warn = 0;
int ret = 1;
wait_sec = (unsigned int)_lvmetad_update_timeout;
@@ -294,12 +294,15 @@ retry:
wait_start = now;
if (now - wait_start > wait_sec) {
- log_warn("WARNING: Not using lvmetad after %u sec lvmetad_update_wait_time.", wait_sec);
+ log_warn("pvscan[%d] WARNING: Not using lvmetad after %u sec lvmetad_update_wait_time.", getpid(), wait_sec);
goto fail;
}
- log_warn("WARNING: lvmetad is being updated, retrying (setup) for %u more seconds.",
- wait_sec - (unsigned int)(now - wait_start));
+ if (now - last_warn >= 10) {
+ last_warn = now;
+ log_warn("pvscan[%d] WARNING: lvmetad is being updated, retrying (setup) for %u more seconds.",
+ getpid(), wait_sec - (unsigned int)(now - wait_start));
+ }
/* Delay a random period between 1 and 2 seconds. */
delay_usec = 1000000 + lvm_even_rand(&_lvmetad_cmd->rand_seed, 1000000);
diff --git a/tools/pvscan.c b/tools/pvscan.c
index daac88f..c21845c 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -18,8 +18,13 @@
#include "lvmetad.h"
#include "lvmcache.h"
+#include <dirent.h>
+#include <sys/file.h>
+
extern int use_full_md_check;
+void online_vg_file_remove(const char *vgname);
+
struct pvscan_params {
int new_pvs_found;
int pvs_found;
@@ -142,6 +147,82 @@ static int _lvmetad_clear_dev(dev_t devno, int32_t major, int32_t minor)
return 1;
}
+static const char *_vgs_online_dir = DEFAULT_RUN_DIR "/vgs_online";
+
+static void _online_dir_setup(void)
+{
+ struct stat st;
+ int rv;
+
+ if (!stat(DEFAULT_RUN_DIR, &st))
+ goto do_vgs;
+
+ log_debug("Creating run_dir.");
+ dm_prepare_selinux_context(DEFAULT_RUN_DIR, S_IFDIR);
+ rv = mkdir(DEFAULT_RUN_DIR, 0755);
+ dm_prepare_selinux_context(NULL, 0);
+
+ if ((rv < 0) && stat(DEFAULT_RUN_DIR, &st))
+ log_error("Failed to create %s %d", DEFAULT_RUN_DIR, errno);
+
+do_vgs:
+ if (!stat(_vgs_online_dir, &st))
+ return;
+
+ log_debug("Creating vgs_online_dir.");
+ dm_prepare_selinux_context(_vgs_online_dir, S_IFDIR);
+ rv = mkdir(_vgs_online_dir, 0755);
+ dm_prepare_selinux_context(NULL, 0);
+
+ if ((rv < 0) && stat(_vgs_online_dir, &st))
+ log_error("Failed to create %s %d", _vgs_online_dir, errno);
+}
+
+static int _online_vg_file_create(struct cmd_context *cmd, const char *vgname)
+{
+ char path[PATH_MAX];
+ int fd;
+
+ if (dm_snprintf(path, sizeof(path), "%s/%s", _vgs_online_dir, vgname) < 0) {
+ log_error("Path %s/%s is too long.", _vgs_online_dir, vgname);
+ return 0;
+ }
+
+ log_debug("Create vg online: %s", path);
+
+ fd = open(path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
+ if (fd < 0) {
+ log_debug("Failed to create %s: %d", path, errno);
+ return 0;
+ }
+
+ /* We don't care about syncing, these files are not even persistent. */
+
+ if (close(fd))
+ log_sys_debug("close", path);
+
+ return 1;
+}
+
+void online_vg_file_remove(const char *vgname)
+{
+ char path[PATH_MAX];
+
+ if (dm_snprintf(path, sizeof(path), "%s/%s", _vgs_online_dir, vgname) < 0) {
+ log_error("Path %s/%s is too long.", _vgs_online_dir, vgname);
+ return;
+ }
+
+ log_debug("Unlink vg online: %s", path);
+
+ /*
+ * There will only be an online file for the vg if it was
+ * autoactivated, so in many cases there will not be one.
+ */
+
+ unlink(path);
+}
+
/*
* pvscan --cache does not perform any lvmlockd locking, and
* pvscan --cache -aay skips autoactivation in lockd VGs.
@@ -190,8 +271,6 @@ static int _pvscan_autoactivate_single(struct cmd_context *cmd, const char *vg_n
struct volume_group *vg, struct processing_handle *handle)
{
struct pvscan_aa_params *pp = (struct pvscan_aa_params *)handle->custom_handle;
- unsigned int refresh_retries = REFRESH_BEFORE_AUTOACTIVATION_RETRIES;
- int refresh_done = 0;
if (vg_is_clustered(vg))
return ECMD_PROCESSED;
@@ -204,6 +283,10 @@ static int _pvscan_autoactivate_single(struct cmd_context *cmd, const char *vg_n
log_debug("pvscan autoactivating VG %s.", vg_name);
+#if 0
+ unsigned int refresh_retries = REFRESH_BEFORE_AUTOACTIVATION_RETRIES;
+ int refresh_done = 0;
+
/*
* Refresh LVs in a VG that has "changed" from finding a PV.
* The meaning of "changed" is determined in lvmetad, and is
@@ -241,8 +324,14 @@ static int _pvscan_autoactivate_single(struct cmd_context *cmd, const char *vg_n
if (!refresh_done)
log_warn("%s: refresh before autoactivation failed.", vg->name);
}
+#endif
- log_debug_activation("Autoactivating VG %s.", vg_name);
+ if (!_online_vg_file_create(cmd, vg->name)) {
+ log_print("pvscan[%d] VG %s skip autoactivation.", getpid(), vg->name);
+ return ECMD_PROCESSED;
+ }
+
+ log_print("pvscan[%d] VG %s run autoactivation.", getpid(), vg->name);
if (!vgchange_activate(cmd, vg, CHANGE_AAY)) {
log_error("%s: autoactivation failed.", vg->name);
@@ -307,6 +396,7 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv)
struct dev_iter *iter;
const char *pv_name;
const char *reason = NULL;
+ const char *dev_arg = NULL;
int32_t major = -1;
int32_t minor = -1;
int devno_args = 0;
@@ -346,7 +436,12 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv)
log_error("Both --major and --minor required to identify devices.");
return EINVALID_CMD_LINE;
}
-
+
+ if (!devno_args && argc)
+ dev_arg = *argv;
+
+ _online_dir_setup();
+
if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_READ, NULL)) {
log_error("Unable to obtain global lock.");
return ECMD_FAILED;
@@ -358,7 +453,7 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv)
* still activate LVs even though it's not updating the cache.
*/
if (do_activate && !lvmetad_used()) {
- log_verbose("Activating all VGs without lvmetad.");
+ log_print("pvscan[%d] activating all directly (lvmetad unused) %s", getpid(), dev_arg ?: "");
all_vgs = 1;
devno_args = 0;
goto activate;
@@ -399,6 +494,7 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv)
log_warn("WARNING: Not using lvmetad because %s.", reason);
lvmetad_make_unused(cmd);
}
+ log_print("pvscan[%d] activating all directly (lvmetad token) %s", getpid(), dev_arg ?: "");
all_vgs = 1;
goto activate;
}
@@ -415,6 +511,7 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv)
if (lvmetad_is_disabled(cmd, &reason)) {
log_warn("WARNING: Not using lvmetad because %s.", reason);
lvmetad_make_unused(cmd);
+ log_print("pvscan[%d] activating all directly (lvmetad disabled) %s", getpid(), dev_arg ?: "");
all_vgs = 1;
goto activate;
}
@@ -610,6 +707,7 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv)
*/
if (lvmetad_used() && lvmetad_is_disabled(cmd, &reason)) {
log_warn("WARNING: Not using lvmetad because %s.", reason);
+ log_print("pvscan[%d] activating directly (lvmetad disabled in scan) %s", getpid(), dev_arg ?: "");
lvmetad_make_unused(cmd);
}
diff --git a/tools/vgchange.c b/tools/vgchange.c
index e15fca7..52abc11 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -20,6 +20,8 @@ struct vgchange_params {
unsigned int lock_start_sanlock : 1;
};
+extern void online_vg_file_remove(const char *vgname);
+
/*
* Increments *count by the number of _new_ monitored devices.
*/
@@ -259,6 +261,17 @@ int vgchange_activate(struct cmd_context *cmd, struct volume_group *vg,
r = 0;
}
+ if (!do_activate && r) {
+ /*
+ * While the VG is inactive, the PVs may go offline.
+ * If the PVs then come back online, pvscan --cache -aay
+ * which should autoactivate the VG again. We need
+ * to remove the vg online file in order for the pvscan
+ * to autoactivate the VG again.
+ */
+ online_vg_file_remove(vg->name);
+ }
+
/* Print message only if there was not found a missing VG */
log_print_unless_silent("%d logical volume(s) in volume group \"%s\" now active",
lvs_in_vg_activated(vg), vg->name);
4 years, 7 months
master - configure: continue build if prlimit is missing
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=aefd177b047eb548e63...
Commit: aefd177b047eb548e63ac94c9eb442604175d3bc
Parent: 55f1d8a2697c6641215604ee32181d7ead7b8d85
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Aug 26 17:34:45 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Aug 26 17:34:45 2019 +0200
configure: continue build if prlimit is missing
---
configure | 13 ++++++++++++-
configure.ac | 3 ++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/configure b/configure
index 7bb038a..6dd7eda 100755
--- a/configure
+++ b/configure
@@ -6647,7 +6647,7 @@ $as_echo "#define _REENTRANT 1" >>confdefs.h
################################################################################
for ac_func in ftruncate gethostname getpagesize gettimeofday localtime_r \
- memchr memset mkdir mkfifo munmap nl_langinfo prlimit pselect realpath rmdir setenv \
+ memchr memset mkdir mkfifo munmap nl_langinfo pselect realpath rmdir setenv \
setlocale strcasecmp strchr strcspn strdup strerror strncasecmp strndup \
strrchr strspn strstr strtol strtoul uname
do :
@@ -6663,6 +6663,17 @@ else
fi
done
+for ac_func in prlimit
+do :
+ ac_fn_c_check_func "$LINENO" "prlimit" "ac_cv_func_prlimit"
+if test "x$ac_cv_func_prlimit" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_PRLIMIT 1
+_ACEOF
+
+fi
+done
+
# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
# for constant arguments. Useless!
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working alloca.h" >&5
diff --git a/configure.ac b/configure.ac
index e3af0c4..74ca201 100644
--- a/configure.ac
+++ b/configure.ac
@@ -153,9 +153,10 @@ AC_DEFINE([_REENTRANT], 1, [Define to use re-entrant thread safe versions])
################################################################################
dnl -- Check for functions
AC_CHECK_FUNCS([ftruncate gethostname getpagesize gettimeofday localtime_r \
- memchr memset mkdir mkfifo munmap nl_langinfo prlimit pselect realpath rmdir setenv \
+ memchr memset mkdir mkfifo munmap nl_langinfo pselect realpath rmdir setenv \
setlocale strcasecmp strchr strcspn strdup strerror strncasecmp strndup \
strrchr strspn strstr strtol strtoul uname], , [AC_MSG_ERROR(bailing out)])
+AC_CHECK_FUNCS([prlimit])
AC_FUNC_ALLOCA
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_CHOWN
4 years, 7 months
master - configure: check for prlimit
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=55f1d8a2697c6641215...
Commit: 55f1d8a2697c6641215604ee32181d7ead7b8d85
Parent: a50c127904a99b5862c323ddc76bfcf760dd0805
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Aug 26 17:19:16 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Aug 26 17:24:37 2019 +0200
configure: check for prlimit
Update configure and make code compilable if prlimit() is not present.
Since the code is suspicious do not cope yet with it's replacement
with set/getrlimit().
---
configure | 4 ++--
configure.ac | 2 +-
include/configure.h.in | 3 +++
lib/label/label.c | 2 ++
4 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/configure b/configure
index 4c84765..7bb038a 100755
--- a/configure
+++ b/configure
@@ -1715,7 +1715,7 @@ Optional Packages:
cache_restore tool: [autodetect]
--with-vdo=TYPE vdo support: internal/none [internal]
--with-vdo-format=PATH vdoformat tool: [autodetect]
- --with-writecache=TYPE writecache support: internal/none [internal]
+ --with-writecache=TYPE writecache support: internal/none [none]
--with-ocfdir=DIR install OCF files in
[PREFIX/lib/ocf/resource.d/lvm2]
--with-default-pid-dir=PID_DIR
@@ -6647,7 +6647,7 @@ $as_echo "#define _REENTRANT 1" >>confdefs.h
################################################################################
for ac_func in ftruncate gethostname getpagesize gettimeofday localtime_r \
- memchr memset mkdir mkfifo munmap nl_langinfo pselect realpath rmdir setenv \
+ memchr memset mkdir mkfifo munmap nl_langinfo prlimit pselect realpath rmdir setenv \
setlocale strcasecmp strchr strcspn strdup strerror strncasecmp strndup \
strrchr strspn strstr strtol strtoul uname
do :
diff --git a/configure.ac b/configure.ac
index 830edb8..e3af0c4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -153,7 +153,7 @@ AC_DEFINE([_REENTRANT], 1, [Define to use re-entrant thread safe versions])
################################################################################
dnl -- Check for functions
AC_CHECK_FUNCS([ftruncate gethostname getpagesize gettimeofday localtime_r \
- memchr memset mkdir mkfifo munmap nl_langinfo pselect realpath rmdir setenv \
+ memchr memset mkdir mkfifo munmap nl_langinfo prlimit pselect realpath rmdir setenv \
setlocale strcasecmp strchr strcspn strdup strerror strncasecmp strndup \
strrchr strspn strstr strtol strtoul uname], , [AC_MSG_ERROR(bailing out)])
AC_FUNC_ALLOCA
diff --git a/include/configure.h.in b/include/configure.h.in
index a43053a..91a3a7d 100644
--- a/include/configure.h.in
+++ b/include/configure.h.in
@@ -292,6 +292,9 @@
/* Define to 1 if you have the <paths.h> header file. */
#undef HAVE_PATHS_H
+/* Define to 1 if you have the `prlimit' function. */
+#undef HAVE_PRLIMIT
+
/* Define to 1 if you have the `pselect' function. */
#undef HAVE_PSELECT
diff --git a/lib/label/label.c b/lib/label/label.c
index e786c89..dc4d32d 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -873,6 +873,7 @@ static void _free_hints(struct dm_list *hints)
static void _prepare_open_file_limit(struct cmd_context *cmd, unsigned int num_devs)
{
+#ifdef HAVE_PRLIMIT
struct rlimit old, new;
unsigned int want = num_devs + BASE_FD_COUNT;
int rv;
@@ -909,6 +910,7 @@ static void _prepare_open_file_limit(struct cmd_context *cmd, unsigned int num_d
log_warn("WARNING: cannot set open file limit for scanning %u devices.", num_devs);
return;
}
+#endif
}
/*
4 years, 7 months
master - dmsetup: missed trailing newline
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a50c127904a99b5862c...
Commit: a50c127904a99b5862c323ddc76bfcf760dd0805
Parent: 4b1dcc2eebb27cae54b4c618ab31072bdb230ea9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Aug 26 15:37:57 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Aug 26 17:22:58 2019 +0200
dmsetup: missed trailing newline
---
libdm/dm-tools/dmsetup.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/libdm/dm-tools/dmsetup.c b/libdm/dm-tools/dmsetup.c
index a38df6b..2f8a1be 100644
--- a/libdm/dm-tools/dmsetup.c
+++ b/libdm/dm-tools/dmsetup.c
@@ -1695,7 +1695,7 @@ static int _udevcomplete(CMD_ARGS)
if (!(cookie = _get_cookie_value(argv[0])))
return_0;
- printf("DM_COOKIE_COMPLETED=0x%-10x", cookie);
+ printf("DM_COOKIE_COMPLETED=0x%-10x\n", cookie);
/*
* Strip flags from the cookie and use cookie magic instead.
* If the cookie has non-zero prefix and the base is zero then
4 years, 7 months
stable-2.02 - dmsetup: missed trailing newline
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=93de9b59c21e6a3b29c...
Commit: 93de9b59c21e6a3b29ccaa6425fde50a9053bdc2
Parent: e03bdd7556289ef130c6e173e86207e2a3d765c9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Aug 26 15:37:57 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Aug 26 15:38:20 2019 +0200
dmsetup: missed trailing newline
---
tools/dmsetup.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 5b21620..60e0638 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -1694,7 +1694,7 @@ static int _udevcomplete(CMD_ARGS)
if (!(cookie = _get_cookie_value(argv[0])))
return_0;
- printf("DM_COOKIE_COMPLETED=0x%-10x", cookie);
+ printf("DM_COOKIE_COMPLETED=0x%-10x\n", cookie);
/*
* Strip flags from the cookie and use cookie magic instead.
* If the cookie has non-zero prefix and the base is zero then
4 years, 7 months
stable-2.02 - lv_manip: add synchronizations
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e03bdd7556289ef130c...
Commit: e03bdd7556289ef130c6e173e86207e2a3d765c9
Parent: c4a6b9ded02ffe682285ec4c2706114f6f2bd481
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Aug 26 13:28:17 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Aug 26 15:36:41 2019 +0200
lv_manip: add synchronizations
New udev in rawhide seems to be 'dropping' udev rule operations for devices
that are no longer existing - while this is 'probably' a bug - it's
revealing moments in lvm2 that likely should not run in a single
transaction and we should wait for a cookie before submitting more work.
TODO: it seem more 'error' paths should always include synchronization
before starting deactivating 'just activated' devices.
We should probably figure out some 'automatic' solution for this instead
of placing sync_local_dev_name() all over the place...
---
lib/metadata/lv_manip.c | 14 +++++++++++---
lib/metadata/snapshot_manip.c | 5 +++++
lib/metadata/thin_manip.c | 6 ++++++
tools/lvconvert.c | 12 ++++++++++++
4 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 87c81c3..76451ea 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -5655,9 +5655,17 @@ out:
ret = 1;
bad:
- if (activated && !deactivate_lv(cmd, lock_lv)) {
- log_error("Problem deactivating %s.", display_lvname(lock_lv));
- ret = 0;
+ if (activated) {
+ if (!sync_local_dev_names(lock_lv->vg->cmd)) {
+ log_error("Failed to sync local devices before deactivating LV %s.",
+ display_lvname(lock_lv));
+ return 0;
+ }
+
+ if (!deactivate_lv(cmd, lock_lv)) {
+ log_error("Problem deactivating %s.", display_lvname(lock_lv));
+ ret = 0;
+ }
}
return ret;
diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c
index 81e4703..aeb739c 100644
--- a/lib/metadata/snapshot_manip.c
+++ b/lib/metadata/snapshot_manip.c
@@ -292,6 +292,11 @@ int vg_remove_snapshot(struct logical_volume *cow)
if (is_origin_active &&
lv_is_virtual_origin(origin)) {
+ if (!sync_local_dev_names(origin->vg->cmd)) {
+ log_error("Failed to sync local devices before deactivating origin LV %s.",
+ display_lvname(origin));
+ return 0;
+ }
if (!deactivate_lv(origin->vg->cmd, origin)) {
log_error("Failed to deactivate logical volume \"%s\"",
origin->name);
diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c
index 2216927..3aab297 100644
--- a/lib/metadata/thin_manip.c
+++ b/lib/metadata/thin_manip.c
@@ -531,6 +531,12 @@ int update_pool_lv(struct logical_volume *lv, int activate)
}
}
+ if (!sync_local_dev_names(lv->vg->cmd)) {
+ log_error("Failed to sync local devices LV %s.",
+ display_lvname(lv));
+ return 0;
+ }
+
if (activate &&
!deactivate_lv(lv->vg->cmd, lv)) {
log_error("Failed to deactivate %s.", display_lvname(lv));
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index bc666c0..8a07a84 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -2529,6 +2529,12 @@ static int _lvconvert_cache_repair(struct cmd_context *cmd,
/* TODO: any active validation of cache-pool metadata? */
deactivate_mlv:
+ if (!sync_local_dev_names(cmd)) {
+ log_error("Failed to sync local devices before deactivating LV %s.",
+ display_lvname(mlv));
+ return 0;
+ }
+
if (!deactivate_lv(cmd, mlv)) {
log_error("Cannot deactivate pool metadata volume %s.",
display_lvname(mlv));
@@ -2536,6 +2542,12 @@ deactivate_mlv:
}
deactivate_pmslv:
+ if (!sync_local_dev_names(cmd)) {
+ log_error("Failed to sync local devices before deactivating LV %s.",
+ display_lvname(pmslv));
+ return 0;
+ }
+
if (!deactivate_lv(cmd, pmslv)) {
log_error("Cannot deactivate pool metadata spare volume %s.",
display_lvname(pmslv));
4 years, 7 months