master - liblvm: Save off and restore umask values
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=eaeb33abd4887c...
Commit: eaeb33abd4887c668aa88703b6e8981da6f44791
Parent: f270bbd442b3c36115ea490ec838cf29277a46d2
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Dec 17 16:51:11 2013 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Dec 20 13:36:22 2013 -0600
liblvm: Save off and restore umask values
lvm has a default umask value in the config file that defaults
to 0077 which lvm changes to during normal operation. This
causes a problem when the code is used as a library with
liblvm as it is changing the umask for the process. This
patch saves off the current umask, sets to what is specified
in the config file and restores it what it was on library
function call exit.
The user is now free to change the umask in their application at
anytime including between library calls.
This fix address BZ:
https://bugzilla.redhat.com/show_bug.cgi?id=1012113
Tested by setting umask to 0777 and running the python unit
test and verifying that umask is still same value as expected
at the test completion and with a successful run.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
liblvm/lvm_base.c | 68 +++++++++++--
liblvm/lvm_lv.c | 246 ++++++++++++++++++++++++++++++++++++++-------
liblvm/lvm_misc.c | 25 +++++
liblvm/lvm_misc.h | 12 ++
liblvm/lvm_pv.c | 150 +++++++++++++++++++++++-----
liblvm/lvm_vg.c | 292 +++++++++++++++++++++++++++++++++++++++--------------
6 files changed, 647 insertions(+), 146 deletions(-)
diff --git a/liblvm/lvm_base.c b/liblvm/lvm_base.c
index 80a4894..2a373ba 100644
--- a/liblvm/lvm_base.c
+++ b/liblvm/lvm_base.c
@@ -18,13 +18,14 @@
#include "lvm-version.h"
#include "metadata-exported.h"
#include "lvm2app.h"
+#include "lvm_misc.h"
const char *lvm_library_get_version(void)
{
return LVM_VERSION;
}
-lvm_t lvm_init(const char *system_dir)
+static lvm_t _lvm_init(const char *system_dir)
{
struct cmd_context *cmd;
@@ -75,18 +76,34 @@ lvm_t lvm_init(const char *system_dir)
return (lvm_t) cmd;
}
+
+lvm_t lvm_init(const char *system_dir)
+{
+ lvm_t h = NULL;
+ struct saved_env e = store_user_env(NULL);
+ h = _lvm_init(system_dir);
+ restore_user_env(&e);
+ return h;
+}
+
void lvm_quit(lvm_t libh)
{
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
destroy_toolcontext((struct cmd_context *)libh);
udev_fin_library_context();
+ restore_user_env(&e);
}
int lvm_config_reload(lvm_t libh)
{
+ int rc = 0;
+
/* FIXME: re-init locking needed here? */
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
if (!refresh_toolcontext((struct cmd_context *)libh))
- return -1;
- return 0;
+ rc = -1;
+ restore_user_env(&e);
+ return rc;
}
/*
@@ -94,54 +111,83 @@ int lvm_config_reload(lvm_t libh)
*/
int lvm_config_override(lvm_t libh, const char *config_settings)
{
+ int rc = 0;
struct cmd_context *cmd = (struct cmd_context *)libh;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
+
if (!override_config_tree_from_string(cmd, config_settings))
- return -1;
- return 0;
+ rc = -1;
+ restore_user_env(&e);
+ return rc;
}
int lvm_config_find_bool(lvm_t libh, const char *config_path, int fail)
{
+ int rc = 0;
struct cmd_context *cmd = (struct cmd_context *)libh;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
- return dm_config_tree_find_bool(cmd->cft, config_path, fail);
+ rc = dm_config_tree_find_bool(cmd->cft, config_path, fail);
+ restore_user_env(&e);
+ return rc;
}
int lvm_errno(lvm_t libh)
{
- return stored_errno();
+ int rc;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
+ rc = stored_errno();
+ restore_user_env(&e);
+ return rc;
}
const char *lvm_errmsg(lvm_t libh)
{
const char *rc = NULL;
struct cmd_context *cmd = (struct cmd_context *)libh;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
+
const char *msg = stored_errmsg_with_clear();
if (msg) {
rc = dm_pool_strdup(cmd->mem, msg);
free((void *)msg);
}
+
+ restore_user_env(&e);
return rc;
}
const char *lvm_vgname_from_pvid(lvm_t libh, const char *pvid)
{
+ const char *rc = NULL;
struct cmd_context *cmd = (struct cmd_context *)libh;
struct id id;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
- if (!id_read_format(&id, pvid)) {
+ if (id_read_format(&id, pvid)) {
+ rc = find_vgname_from_pvid(cmd, (char *)id.uuid);
+ } else {
log_error(INTERNAL_ERROR "Unable to convert uuid");
- return NULL;
}
- return find_vgname_from_pvid(cmd, (char *)id.uuid);
+
+ restore_user_env(&e);
+ return rc;
}
const char *lvm_vgname_from_device(lvm_t libh, const char *device)
{
+ const char *rc = NULL;
struct cmd_context *cmd = (struct cmd_context *)libh;
- return find_vgname_from_pvname(cmd, device);
+ struct saved_env e = store_user_env(cmd);
+ rc = find_vgname_from_pvname(cmd, device);
+ restore_user_env(&e);
+ return rc;
}
+/*
+ * No context to work with, so no ability to save off and restore env is not
+ * available and is not needed.
+ */
float lvm_percent_to_float(percent_t v)
{
return percent_to_float(v);
diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c
index b451c83..3b0e18d 100644
--- a/liblvm/lvm_lv.c
+++ b/liblvm/lvm_lv.c
@@ -45,60 +45,99 @@ static int _lv_check_handle(const lv_t lv, const int vg_writeable)
/* FIXME: have lib/report/report.c _disp function call lv_size()? */
uint64_t lvm_lv_get_size(const lv_t lv)
{
- return SECTOR_SIZE * lv_size(lv);
+ uint64_t rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = SECTOR_SIZE * lv_size(lv);
+ restore_user_env(&e);
+ return rc;
}
const char *lvm_lv_get_uuid(const lv_t lv)
{
- return lv_uuid_dup(lv);
+ const char *rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = lv_uuid_dup(lv);
+ restore_user_env(&e);
+ return rc;
}
const char *lvm_lv_get_name(const lv_t lv)
{
- return dm_pool_strndup(lv->vg->vgmem, (const char *)lv->name,
+ const char *rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = dm_pool_strndup(lv->vg->vgmem, (const char *)lv->name,
NAME_LEN+1);
+ restore_user_env(&e);
+ return rc;
}
const char *lvm_lv_get_attr(const lv_t lv)
{
- return lv_attr_dup(lv->vg->vgmem, lv);
+ const char *rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = lv_attr_dup(lv->vg->vgmem, lv);
+ restore_user_env(&e);
+ return rc;
}
const char *lvm_lv_get_origin(const lv_t lv)
{
- return lv_origin_dup(lv->vg->vgmem, lv);
+ const char *rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = lv_origin_dup(lv->vg->vgmem, lv);
+ restore_user_env(&e);
+ return rc;
}
struct lvm_property_value lvm_lv_get_property(const lv_t lv, const char *name)
{
- return get_property(NULL, NULL, lv, NULL, NULL, NULL, NULL, name);
+ struct lvm_property_value rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = get_property(NULL, NULL, lv, NULL, NULL, NULL, NULL, name);
+ restore_user_env(&e);
+ return rc;
}
struct lvm_property_value lvm_lvseg_get_property(const lvseg_t lvseg,
const char *name)
{
- return get_property(NULL, NULL, NULL, lvseg, NULL, NULL, NULL, name);
+ struct lvm_property_value rc;
+ struct saved_env e = store_user_env(lvseg->lv->vg->cmd);
+ rc = get_property(NULL, NULL, NULL, lvseg, NULL, NULL, NULL, name);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_lv_is_active(const lv_t lv)
{
+ uint64_t rc = 0;
struct lvinfo info;
+
+ struct saved_env e = store_user_env(lv->vg->cmd);
+
if (lv_info(lv->vg->cmd, lv, 0, &info, 0, 0) &&
info.exists && info.live_table)
- return 1;
- return 0;
+ rc = 1;
+
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_lv_is_suspended(const lv_t lv)
{
+ uint64_t rc = 0;
struct lvinfo info;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+
if (lv_info(lv->vg->cmd, lv, 0, &info, 0, 0) &&
info.exists && info.suspended)
- return 1;
- return 0;
+ rc = 1;
+
+ restore_user_env(&e);
+ return rc;
}
-int lvm_lv_add_tag(lv_t lv, const char *tag)
+static int _lvm_lv_add_tag(lv_t lv, const char *tag)
{
if (_lv_check_handle(lv, 1))
return -1;
@@ -107,8 +146,17 @@ int lvm_lv_add_tag(lv_t lv, const char *tag)
return 0;
}
+int lvm_lv_add_tag(lv_t lv, const char *tag)
+{
+ int rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = _lvm_lv_add_tag(lv, tag);
+ restore_user_env(&e);
+ return rc;
+}
+
-int lvm_lv_remove_tag(lv_t lv, const char *tag)
+static int _lvm_lv_remove_tag(lv_t lv, const char *tag)
{
if (_lv_check_handle(lv, 1))
return -1;
@@ -117,10 +165,23 @@ int lvm_lv_remove_tag(lv_t lv, const char *tag)
return 0;
}
+int lvm_lv_remove_tag(lv_t lv, const char *tag)
+{
+ int rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = _lvm_lv_remove_tag(lv, tag);
+ restore_user_env(&e);
+ return rc;
+}
+
struct dm_list *lvm_lv_get_tags(const lv_t lv)
{
- return tag_list_copy(lv->vg->vgmem, &lv->tags);
+ struct dm_list *rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = tag_list_copy(lv->vg->vgmem, &lv->tags);
+ restore_user_env(&e);
+ return rc;
}
/* Set defaults for non-segment specific LV parameters */
@@ -171,7 +232,7 @@ static int _lv_set_default_linear_params(struct cmd_context *cmd,
* lvm_vg_write. However, this appears to be non-trivial change until
* lv_create_single is refactored by segtype.
*/
-lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size)
+static lv_t _lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size)
{
struct lvcreate_params lp = { 0 };
uint64_t extents;
@@ -196,11 +257,20 @@ lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size)
return (lv_t) lv;
}
+lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size)
+{
+ lv_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = _lvm_vg_create_lv_linear(vg, name, size);
+ restore_user_env(&e);
+ return rc;
+}
+
/*
* FIXME: This function should probably not commit to disk but require calling
* lvm_vg_write.
*/
-int lvm_vg_remove_lv(lv_t lv)
+static int _lvm_vg_remove_lv(lv_t lv)
{
if (!lv || !lv->vg || vg_read_error(lv->vg))
return -1;
@@ -211,7 +281,16 @@ int lvm_vg_remove_lv(lv_t lv)
return 0;
}
-int lvm_lv_activate(lv_t lv)
+int lvm_vg_remove_lv(lv_t lv)
+{
+ int rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = _lvm_vg_remove_lv(lv);
+ restore_user_env(&e);
+ return rc;
+}
+
+static int _lvm_lv_activate(lv_t lv)
{
if (!lv || !lv->vg || vg_read_error(lv->vg) || !lv->vg->cmd)
return -1;
@@ -248,7 +327,16 @@ int lvm_lv_activate(lv_t lv)
return 0;
}
-int lvm_lv_deactivate(lv_t lv)
+int lvm_lv_activate(lv_t lv)
+{
+ int rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = _lvm_lv_activate(lv);
+ restore_user_env(&e);
+ return rc;
+}
+
+static int _lvm_lv_deactivate(lv_t lv)
{
if (!lv || !lv->vg || vg_read_error(lv->vg) || !lv->vg->cmd)
return -1;
@@ -261,7 +349,16 @@ int lvm_lv_deactivate(lv_t lv)
return 0;
}
-struct dm_list *lvm_lv_list_lvsegs(lv_t lv)
+int lvm_lv_deactivate(lv_t lv)
+{
+ int rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = _lvm_lv_deactivate(lv);
+ restore_user_env(&e);
+ return rc;
+}
+
+static struct dm_list *_lvm_lv_list_lvsegs(lv_t lv)
{
struct dm_list *list;
lvseg_list_t *lvseg;
@@ -288,18 +385,32 @@ struct dm_list *lvm_lv_list_lvsegs(lv_t lv)
return list;
}
+struct dm_list *lvm_lv_list_lvsegs(lv_t lv)
+{
+ struct dm_list *rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = _lvm_lv_list_lvsegs(lv);
+ restore_user_env(&e);
+ return rc;
+}
+
lv_t lvm_lv_from_name(vg_t vg, const char *name)
{
+ lv_t rc = NULL;
struct lv_list *lvl;
+ struct saved_env e = store_user_env(vg->cmd);
dm_list_iterate_items(lvl, &vg->lvs) {
- if (!strcmp(name, lvl->lv->name))
- return lvl->lv;
+ if (!strcmp(name, lvl->lv->name)) {
+ rc = lvl->lv;
+ break;
+ }
}
- return NULL;
+ restore_user_env(&e);
+ return rc;
}
-lv_t lvm_lv_from_uuid(vg_t vg, const char *uuid)
+static lv_t _lvm_lv_from_uuid(vg_t vg, const char *uuid)
{
struct lv_list *lvl;
struct id id;
@@ -322,19 +433,33 @@ lv_t lvm_lv_from_uuid(vg_t vg, const char *uuid)
return NULL;
}
+lv_t lvm_lv_from_uuid(vg_t vg, const char *uuid)
+{
+ lv_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = _lvm_lv_from_uuid(vg, uuid);
+ restore_user_env(&e);
+ return rc;
+}
+
int lvm_lv_rename(lv_t lv, const char *new_name)
{
+ int rc = 0;
+ struct saved_env e = store_user_env(lv->vg->cmd);
if (!lv_rename(lv->vg->cmd, lv, new_name)) {
/* FIXME Improve msg */
log_error("LV rename failed.");
- return -1;
+ rc = -1;
}
- return 0;
+ restore_user_env(&e);
+ return rc;
}
int lvm_lv_resize(const lv_t lv, uint64_t new_size)
{
+ int rc = 0;
struct lvresize_params lp = { 0 };
+ struct saved_env e = { 0 };
lp.vg_name = lv->vg->name;
lp.lv_name = lv->name;
@@ -345,27 +470,32 @@ int lvm_lv_resize(const lv_t lv, uint64_t new_size)
lp.ac_force = 1; /* Assume the user has a good backup? */
lp.sizeargs = 1;
+ e = store_user_env(lv->vg->cmd);
+
if (!lv_resize_prepare(lv->vg->cmd, lv, &lp, &lv->vg->pvs) ||
!lv_resize(lv->vg->cmd, lv, &lp, &lv->vg->pvs)) {
/* FIXME Improve msg */
log_error("LV resize failed.");
/* FIXME Define consistent symbolic return codes */
- return -1;
+ rc = -1;
}
-
- return 0;
+ restore_user_env(&e);
+ return rc;
}
lv_t lvm_lv_snapshot(const lv_t lv, const char *snap_name,
uint64_t max_snap_size)
{
+ lv_t rc = NULL;
struct lvm_lv_create_params *lvcp = NULL;
+ struct saved_env e = store_user_env(lv->vg->cmd);
lvcp = lvm_lv_params_create_snapshot(lv, snap_name, max_snap_size);
if (lvcp) {
- return lvm_lv_create(lvcp);
+ rc = lvm_lv_create(lvcp);
}
- return NULL;
+ restore_user_env(&e);
+ return rc;
}
/* Set defaults for thin pool specific LV parameters */
@@ -405,7 +535,7 @@ static int _lv_set_pool_params(struct lvcreate_params *lp,
return 1;
}
-lv_create_params_t lvm_lv_params_create_thin_pool(vg_t vg,
+static lv_create_params_t _lvm_lv_params_create_thin_pool(vg_t vg,
const char *pool_name, uint64_t size, uint32_t chunk_size,
uint64_t meta_size, lvm_thin_discards_t discard)
{
@@ -465,6 +595,18 @@ lv_create_params_t lvm_lv_params_create_thin_pool(vg_t vg,
return lvcp;
}
+lv_create_params_t lvm_lv_params_create_thin_pool(vg_t vg,
+ const char *pool_name, uint64_t size, uint32_t chunk_size,
+ uint64_t meta_size, lvm_thin_discards_t discard)
+{
+ lv_create_params_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = _lvm_lv_params_create_thin_pool(vg, pool_name, size, chunk_size,
+ meta_size, discard);
+ restore_user_env(&e);
+ return rc;
+}
+
/* Set defaults for thin LV specific parameters */
static int _lv_set_thin_params(struct lvcreate_params *lp,
vg_t vg, const char *pool,
@@ -487,7 +629,7 @@ static int _lv_set_thin_params(struct lvcreate_params *lp,
return 1;
}
-lv_create_params_t lvm_lv_params_create_snapshot(const lv_t lv,
+static lv_create_params_t _lvm_lv_params_create_snapshot(const lv_t lv,
const char *snap_name,
uint64_t max_snap_size)
{
@@ -548,8 +690,19 @@ lv_create_params_t lvm_lv_params_create_snapshot(const lv_t lv,
return lvcp;
}
+lv_create_params_t lvm_lv_params_create_snapshot(const lv_t lv,
+ const char *snap_name,
+ uint64_t max_snap_size)
+{
+ lv_create_params_t rc;
+ struct saved_env e = store_user_env(lv->vg->cmd);
+ rc = _lvm_lv_params_create_snapshot(lv, snap_name, max_snap_size);
+ restore_user_env(&e);
+ return rc;
+}
-lv_create_params_t lvm_lv_params_create_thin(const vg_t vg, const char *pool_name,
+static lv_create_params_t _lvm_lv_params_create_thin(const vg_t vg,
+ const char *pool_name,
const char *lvname, uint64_t size)
{
struct lvm_lv_create_params *lvcp = NULL;
@@ -590,6 +743,16 @@ lv_create_params_t lvm_lv_params_create_thin(const vg_t vg, const char *pool_nam
return lvcp;
}
+lv_create_params_t lvm_lv_params_create_thin(const vg_t vg, const char *pool_name,
+ const char *lvname, uint64_t size)
+{
+ lv_create_params_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = _lvm_lv_params_create_thin(vg, pool_name, lvname, size);
+ restore_user_env(&e);
+ return rc;
+}
+
struct lvm_property_value lvm_lv_params_get_property(
const lv_create_params_t params,
const char *name)
@@ -597,13 +760,14 @@ struct lvm_property_value lvm_lv_params_get_property(
struct lvm_property_value rc = {
.is_valid = 0
};
+ struct saved_env e = store_user_env(params->vg->cmd);
if (params && params->magic == LV_CREATE_PARAMS_MAGIC) {
rc = get_property(NULL, NULL, NULL, NULL, NULL, ¶ms->lvp, NULL, name);
} else {
log_error("Invalid lv_create_params parameter");
}
-
+ restore_user_env(&e);
return rc;
}
@@ -611,16 +775,19 @@ int lvm_lv_params_set_property(lv_create_params_t params, const char *name,
struct lvm_property_value *prop)
{
int rc = -1;
+ struct saved_env e = store_user_env(params->vg->cmd);
if (params && params->magic == LV_CREATE_PARAMS_MAGIC) {
rc = set_property(NULL, NULL, NULL, ¶ms->lvp, NULL, name, prop);
} else {
log_error("Invalid lv_create_params parameter");
}
+
+ restore_user_env(&e);
return rc;
}
-lv_t lvm_lv_create(lv_create_params_t params)
+static lv_t _lvm_lv_create(lv_create_params_t params)
{
struct lv_list *lvl = NULL;
@@ -644,3 +811,12 @@ lv_t lvm_lv_create(lv_create_params_t params)
log_error("Invalid lv_create_params parameter");
return NULL;
}
+
+lv_t lvm_lv_create(lv_create_params_t params)
+{
+ lv_t rc;
+ struct saved_env e = store_user_env(params->vg->cmd);
+ rc = _lvm_lv_create(params);
+ restore_user_env(&e);
+ return rc;
+}
diff --git a/liblvm/lvm_misc.c b/liblvm/lvm_misc.c
index ba77010..d9b4323 100644
--- a/liblvm/lvm_misc.c
+++ b/liblvm/lvm_misc.c
@@ -140,3 +140,28 @@ int set_property(const pv_t pv, const vg_t vg, const lv_t lv,
}
return 0;
}
+
+/*
+ * Store anything that may need to be restored back to the user on library
+ * call exit. Currently the only thing we are preserving is the users umask.
+ */
+struct saved_env store_user_env(struct cmd_context *cmd)
+{
+ struct saved_env env = {0};
+
+ if (cmd) {
+ env.user_umask = umask(cmd->default_settings.umask);
+ } else {
+ env.user_umask = umask(0);
+ umask(env.user_umask);
+ }
+
+ return env;
+}
+
+void restore_user_env(const struct saved_env *env)
+{
+ if (env) {
+ umask(env->user_umask);
+ }
+}
diff --git a/liblvm/lvm_misc.h b/liblvm/lvm_misc.h
index b187021..4678338 100644
--- a/liblvm/lvm_misc.h
+++ b/liblvm/lvm_misc.h
@@ -17,6 +17,18 @@
#include "libdevmapper.h"
#include "lvm2app.h"
#include "metadata-exported.h"
+#include "toolcontext.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+struct saved_env
+{
+ mode_t user_umask;
+};
+
+struct saved_env store_user_env(struct cmd_context *cmd);
+void restore_user_env(const struct saved_env *env);
struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list);
struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
index d540a6c..163ea4f 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -20,6 +20,7 @@
#include "lvm2app.h"
#include "locking.h"
#include "toolcontext.h"
+#include "lvm_misc.h"
struct lvm_pv_create_params
{
@@ -33,43 +34,75 @@ struct lvm_pv_create_params
const char *lvm_pv_get_uuid(const pv_t pv)
{
- return pv_uuid_dup(pv);
+ const char *rc;
+ struct saved_env e = store_user_env(pv->vg->cmd);
+ rc = pv_uuid_dup(pv);
+ restore_user_env(&e);
+ return rc;
}
const char *lvm_pv_get_name(const pv_t pv)
{
- return dm_pool_strndup(pv->vg->vgmem, pv_dev_name(pv), NAME_LEN);
+ const char *rc;
+ struct saved_env e = store_user_env(pv->vg->cmd);
+ rc = dm_pool_strndup(pv->vg->vgmem, pv_dev_name(pv), NAME_LEN);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_pv_get_mda_count(const pv_t pv)
{
- return (uint64_t) pv_mda_count(pv);
+ uint64_t rc;
+ struct saved_env e = store_user_env(pv->vg->cmd);
+ rc = (uint64_t) pv_mda_count(pv);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_pv_get_dev_size(const pv_t pv)
{
- return SECTOR_SIZE * pv_dev_size(pv);
+ uint64_t rc;
+ struct saved_env e = store_user_env(pv->vg->cmd);
+ rc = SECTOR_SIZE * pv_dev_size(pv);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_pv_get_size(const pv_t pv)
{
- return SECTOR_SIZE * pv_size_field(pv);
+ uint64_t rc;
+ struct saved_env e = store_user_env(pv->vg->cmd);
+ rc = SECTOR_SIZE * pv_size_field(pv);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_pv_get_free(const pv_t pv)
{
- return SECTOR_SIZE * pv_free(pv);
+ uint64_t rc;
+ struct saved_env e = store_user_env(pv->vg->cmd);
+ rc = SECTOR_SIZE * pv_free(pv);
+ restore_user_env(&e);
+ return rc;
}
struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name)
{
- return get_property(pv, NULL, NULL, NULL, NULL, NULL, NULL, name);
+ struct lvm_property_value rc;
+ struct saved_env e = store_user_env(pv->vg->cmd);
+ rc = get_property(pv, NULL, NULL, NULL, NULL, NULL, NULL, name);
+ restore_user_env(&e);
+ return rc;
}
struct lvm_property_value lvm_pvseg_get_property(const pvseg_t pvseg,
const char *name)
{
- return get_property(NULL, NULL, NULL, NULL, pvseg, NULL, NULL, name);
+ struct lvm_property_value rc;
+ struct saved_env e = store_user_env(pvseg->pv->vg->cmd);
+ rc = get_property(NULL, NULL, NULL, NULL, pvseg, NULL, NULL, name);
+ restore_user_env(&e);
+ return rc;
}
struct lvm_list_wrapper
@@ -82,17 +115,20 @@ struct lvm_list_wrapper
int lvm_pv_remove(lvm_t libh, const char *pv_name)
{
+ int rc = 0;
struct cmd_context *cmd = (struct cmd_context *)libh;
+ struct saved_env e = store_user_env(cmd);
if (!pvremove_single(cmd, pv_name, NULL, 0, 0))
- return -1;
+ rc = -1;
- return 0;
+ restore_user_env(&e);
+ return rc;
}
-#define PV_LIST_MAGIC 0xF005BA11
+#define PV_LIST_MAGIC 4026907153
-struct dm_list *lvm_list_pvs(lvm_t libh)
+static struct dm_list *_lvm_list_pvs(lvm_t libh)
{
struct lvm_list_wrapper *rc = NULL;
struct cmd_context *cmd = (struct cmd_context *)libh;
@@ -127,11 +163,21 @@ struct dm_list *lvm_list_pvs(lvm_t libh)
return &rc->pvslist;
}
+struct dm_list *lvm_list_pvs(lvm_t libh)
+{
+ struct dm_list *rc;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
+ rc = _lvm_list_pvs(libh);
+ restore_user_env(&e);
+ return rc;
+}
+
int lvm_list_pvs_free(struct dm_list *pvlist)
{
struct lvm_list_wrapper *to_delete;
struct vg_list *vgl;
struct pv_list *pvl;
+ struct saved_env e;
if (pvlist) {
to_delete = dm_list_struct_base(pvlist, struct lvm_list_wrapper, pvslist);
@@ -140,6 +186,12 @@ int lvm_list_pvs_free(struct dm_list *pvlist)
return -1;
}
+ /*
+ * Need to ensure that pointer is valid before we can use reference to
+ * cmd.
+ */
+ e = store_user_env(to_delete->cmd);
+
dm_list_iterate_items(vgl, &to_delete->vgslist) {
release_vg(vgl->vg);
}
@@ -149,12 +201,14 @@ int lvm_list_pvs_free(struct dm_list *pvlist)
unlock_vg(to_delete->cmd, VG_GLOBAL);
to_delete->magic = 0xA5A5A5A5;
+
+ restore_user_env(&e);
}
return 0;
}
-struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
+static struct dm_list *_lvm_pv_list_pvsegs(pv_t pv)
{
struct dm_list *list;
pvseg_list_t *pvseg;
@@ -183,18 +237,32 @@ struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
return list;
}
+struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
+{
+ struct dm_list *rc;
+ struct saved_env e = store_user_env(pv->vg->cmd);
+ rc = _lvm_pv_list_pvsegs(pv);
+ restore_user_env(&e);
+ return rc;
+}
+
pv_t lvm_pv_from_name(vg_t vg, const char *name)
{
+ pv_t rc = NULL;
struct pv_list *pvl;
+ struct saved_env e = store_user_env(vg->cmd);
dm_list_iterate_items(pvl, &vg->pvs)
- if (!strcmp(name, pv_dev_name(pvl->pv)))
- return pvl->pv;
+ if (!strcmp(name, pv_dev_name(pvl->pv))) {
+ rc = pvl->pv;
+ break;
+ }
- return NULL;
+ restore_user_env(&e);
+ return rc;
}
-pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid)
+static pv_t _lvm_pv_from_uuid(vg_t vg, const char *uuid)
{
struct pv_list *pvl;
struct id id;
@@ -216,7 +284,16 @@ pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid)
return NULL;
}
-int lvm_pv_resize(const pv_t pv, uint64_t new_size)
+pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid)
+{
+ pv_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = _lvm_pv_from_uuid(vg, uuid);
+ restore_user_env(&e);
+ return rc;
+}
+
+static int _lvm_pv_resize(const pv_t pv, uint64_t new_size)
{
uint64_t size = new_size >> SECTOR_SHIFT;
@@ -236,6 +313,15 @@ int lvm_pv_resize(const pv_t pv, uint64_t new_size)
return 0;
}
+int lvm_pv_resize(const pv_t pv, uint64_t new_size)
+{
+ int rc;
+ struct saved_env e = store_user_env(pv->vg->cmd);
+ rc = _lvm_pv_resize(pv, new_size);
+ restore_user_env(&e);
+ return rc;
+}
+
/*
* Common internal code to create a parameter passing object
*/
@@ -280,7 +366,11 @@ static struct lvm_pv_create_params *_lvm_pv_params_create(
pv_create_params_t lvm_pv_params_create(lvm_t libh, const char *pv_name)
{
- return _lvm_pv_params_create(libh, pv_name, NULL);
+ pv_create_params_t rc;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
+ rc = _lvm_pv_params_create(libh, pv_name, NULL);
+ restore_user_env(&e);
+ return rc;
}
struct lvm_property_value lvm_pv_params_get_property(
@@ -290,10 +380,13 @@ struct lvm_property_value lvm_pv_params_get_property(
struct lvm_property_value rc = {
.is_valid = 0
};
+ struct saved_env e;
if (params && params->magic == PV_CREATE_PARAMS_MAGIC) {
+ e = store_user_env((struct cmd_context *)(params->libh));
rc = get_property(NULL, NULL, NULL, NULL, NULL, NULL, ¶ms->pv_p,
name);
+ restore_user_env(&e);
} else {
log_error("Invalid pv_create_params parameter");
}
@@ -305,9 +398,12 @@ int lvm_pv_params_set_property(pv_create_params_t params, const char *name,
struct lvm_property_value *prop)
{
int rc = -1;
+ struct saved_env e;
if (params && params->magic == PV_CREATE_PARAMS_MAGIC) {
+ e = store_user_env((struct cmd_context *)(params->libh));
rc = set_property(NULL, NULL, NULL, NULL, ¶ms->pv_p, name, prop);
+ restore_user_env(&e);
} else {
log_error("Invalid pv_create_params parameter");
}
@@ -334,21 +430,27 @@ static int _pv_create(pv_create_params_t params)
int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size)
{
struct lvm_pv_create_params pp;
+ int rc = -1;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
- if (!_lvm_pv_params_create(libh, pv_name, &pp))
- return -1;
-
- pp.pv_p.size = size;
+ if (_lvm_pv_params_create(libh, pv_name, &pp)) {
+ pp.pv_p.size = size;
+ rc = _pv_create(&pp);
+ }
- return _pv_create(&pp);
+ restore_user_env(&e);
+ return rc;
}
int lvm_pv_create_adv(pv_create_params_t params)
{
int rc = -1;
+ struct saved_env e;
if (params && params->magic == PV_CREATE_PARAMS_MAGIC) {
+ e = store_user_env((struct cmd_context *)(params->libh));
rc = _pv_create(params);
+ restore_user_env(&e);
} else {
log_error("Invalid pv_create_params parameter");
}
diff --git a/liblvm/lvm_vg.c b/liblvm/lvm_vg.c
index d3c8ae2..76c5c63 100644
--- a/liblvm/lvm_vg.c
+++ b/liblvm/lvm_vg.c
@@ -25,47 +25,49 @@
int lvm_vg_add_tag(vg_t vg, const char *tag)
{
- if (vg_read_error(vg))
- return -1;
-
- if (!vg_check_write_mode(vg))
- return -1;
+ int rc = -1;
+ struct saved_env e = store_user_env(vg->cmd);
- if (!vg_change_tag(vg, tag, 1))
- return -1;
- return 0;
+ if (!vg_read_error(vg) && vg_check_write_mode(vg) &&
+ vg_change_tag(vg, tag, 1))
+ rc = 0;
+ restore_user_env(&e);
+ return rc;
}
int lvm_vg_remove_tag(vg_t vg, const char *tag)
{
- if (vg_read_error(vg))
- return -1;
-
- if (!vg_check_write_mode(vg))
- return -1;
+ int rc = -1;
+ struct saved_env e = store_user_env(vg->cmd);
- if (!vg_change_tag(vg, tag, 0))
- return -1;
- return 0;
+ if (!vg_read_error(vg) && vg_check_write_mode(vg) &&
+ vg_change_tag(vg, tag, 0))
+ rc = 0;
+ restore_user_env(&e);
+ return rc;
}
vg_t lvm_vg_create(lvm_t libh, const char *vg_name)
{
- struct volume_group *vg;
+ struct volume_group *vg = NULL;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
vg = vg_create((struct cmd_context *)libh, vg_name);
/* FIXME: error handling is still TBD */
if (vg_read_error(vg)) {
release_vg(vg);
- return NULL;
+ vg = NULL;
+ } else {
+ vg->open_mode = 'w';
}
- vg->open_mode = 'w';
+
+ restore_user_env(&e);
return (vg_t) vg;
}
-int lvm_vg_extend(vg_t vg, const char *device)
+static int _lvm_vg_extend(vg_t vg, const char *device)
{
struct pvcreate_params pp;
@@ -93,31 +95,41 @@ int lvm_vg_extend(vg_t vg, const char *device)
return 0;
}
+int lvm_vg_extend(vg_t vg, const char *device)
+{
+ int rc = 0;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = _lvm_vg_extend(vg, device);
+ restore_user_env(&e);
+ return rc;
+}
+
int lvm_vg_reduce(vg_t vg, const char *device)
{
- if (vg_read_error(vg))
- return -1;
- if (!vg_check_write_mode(vg))
- return -1;
+ int rc = -1;
+ struct saved_env e = store_user_env(vg->cmd);
- if (!vg_reduce(vg, device))
- return -1;
- return 0;
+ if (!vg_read_error(vg) && vg_check_write_mode(vg) && vg_reduce(vg, device))
+ rc = 0;
+
+ restore_user_env(&e);
+ return rc;
}
int lvm_vg_set_extent_size(vg_t vg, uint32_t new_size)
{
- if (vg_read_error(vg))
- return -1;
- if (!vg_check_write_mode(vg))
- return -1;
+ int rc = -1;
+ struct saved_env e = store_user_env(vg->cmd);
- if (!vg_set_extent_size(vg, new_size / SECTOR_SIZE))
- return -1;
- return 0;
+ if (!vg_read_error(vg) && vg_check_write_mode(vg) &&
+ vg_set_extent_size(vg, new_size / SECTOR_SIZE))
+ rc = 0;
+
+ restore_user_env(&e);
+ return rc;
}
-int lvm_vg_write(vg_t vg)
+static int _lvm_vg_write(vg_t vg)
{
struct pv_list *pvl;
@@ -159,31 +171,41 @@ int lvm_vg_write(vg_t vg)
return 0;
}
+int lvm_vg_write(vg_t vg)
+{
+ int rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = _lvm_vg_write(vg);
+ restore_user_env(&e);
+ return rc;
+}
+
int lvm_vg_close(vg_t vg)
{
+ struct saved_env e = store_user_env(vg->cmd);
if (vg_read_error(vg) == FAILED_LOCKING)
release_vg(vg);
else
unlock_and_release_vg(vg->cmd, vg, vg->name);
+ restore_user_env(&e);
return 0;
}
int lvm_vg_remove(vg_t vg)
{
- if (vg_read_error(vg))
- return -1;
- if (!vg_check_write_mode(vg))
- return -1;
+ int rc = -1;
+ struct saved_env e = store_user_env(vg->cmd);
- if (!vg_remove_check(vg))
- return -1;
-
- vg_remove_pvs(vg);
+ if (!vg_read_error(vg) && vg_check_write_mode(vg) && vg_remove_check(vg)) {
+ vg_remove_pvs(vg);
+ rc = 0;
+ }
- return 0;
+ restore_user_env(&e);
+ return rc;
}
-vg_t lvm_vg_open(lvm_t libh, const char *vgname, const char *mode,
+static vg_t _lvm_vg_open(lvm_t libh, const char *vgname, const char *mode,
uint32_t flags)
{
uint32_t internal_flags = 0;
@@ -208,7 +230,17 @@ vg_t lvm_vg_open(lvm_t libh, const char *vgname, const char *mode,
return (vg_t) vg;
}
-struct dm_list *lvm_vg_list_pvs(vg_t vg)
+vg_t lvm_vg_open(lvm_t libh, const char *vgname, const char *mode,
+ uint32_t flags)
+{
+ vg_t rc;
+ struct saved_env e = store_user_env((struct cmd_context*)libh);
+ rc = _lvm_vg_open(libh, vgname, mode, flags);
+ restore_user_env(&e);
+ return rc;
+}
+
+static struct dm_list *_lvm_vg_list_pvs(vg_t vg)
{
struct dm_list *list;
pv_list_t *pvs;
@@ -235,7 +267,16 @@ struct dm_list *lvm_vg_list_pvs(vg_t vg)
return list;
}
-struct dm_list *lvm_vg_list_lvs(vg_t vg)
+struct dm_list *lvm_vg_list_pvs(vg_t vg)
+{
+ struct dm_list *rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = _lvm_vg_list_pvs(vg);
+ restore_user_env(&e);
+ return rc;
+}
+
+static struct dm_list *_lvm_vg_list_lvs(vg_t vg)
{
struct dm_list *list;
lv_list_t *lvs;
@@ -262,86 +303,159 @@ struct dm_list *lvm_vg_list_lvs(vg_t vg)
return list;
}
+struct dm_list *lvm_vg_list_lvs(vg_t vg)
+{
+ struct dm_list *rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = _lvm_vg_list_lvs(vg);
+ restore_user_env(&e);
+ return rc;
+}
+
struct dm_list *lvm_vg_get_tags(const vg_t vg)
{
- return tag_list_copy(vg->vgmem, &vg->tags);
+ struct dm_list *rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = tag_list_copy(vg->vgmem, &vg->tags);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_vg_get_seqno(const vg_t vg)
{
- return vg_seqno(vg);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = vg_seqno(vg);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_vg_is_clustered(const vg_t vg)
{
- return vg_is_clustered(vg);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = vg_is_clustered(vg);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_vg_is_exported(const vg_t vg)
{
- return vg_is_exported(vg);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = vg_is_exported(vg);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_vg_is_partial(const vg_t vg)
{
- return (vg_missing_pv_count(vg) != 0);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = (vg_missing_pv_count(vg) != 0);
+ restore_user_env(&e);
+ return rc;
}
/* FIXME: invalid handle? return INTMAX? */
uint64_t lvm_vg_get_size(const vg_t vg)
{
- return SECTOR_SIZE * vg_size(vg);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = SECTOR_SIZE * vg_size(vg);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_vg_get_free_size(const vg_t vg)
{
- return SECTOR_SIZE * vg_free(vg);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = SECTOR_SIZE * vg_free(vg);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_vg_get_extent_size(const vg_t vg)
{
- return SECTOR_SIZE * vg_extent_size(vg);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = SECTOR_SIZE * vg_extent_size(vg);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_vg_get_extent_count(const vg_t vg)
{
- return vg_extent_count(vg);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = vg_extent_count(vg);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_vg_get_free_extent_count(const vg_t vg)
{
- return vg_free_count(vg);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = vg_free_count(vg);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_vg_get_pv_count(const vg_t vg)
{
- return vg_pv_count(vg);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = vg_pv_count(vg);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_vg_get_max_pv(const vg_t vg)
{
- return vg_max_pv(vg);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = vg_max_pv(vg);
+ restore_user_env(&e);
+ return rc;
}
uint64_t lvm_vg_get_max_lv(const vg_t vg)
{
- return vg_max_lv(vg);
+ uint64_t rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = vg_max_lv(vg);
+ restore_user_env(&e);
+ return rc;
}
const char *lvm_vg_get_uuid(const vg_t vg)
{
- return vg_uuid_dup(vg);
+ const char *rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = vg_uuid_dup(vg);
+ restore_user_env(&e);
+ return rc;
}
const char *lvm_vg_get_name(const vg_t vg)
{
- return dm_pool_strndup(vg->vgmem, (const char *)vg->name, NAME_LEN+1);
+ const char *rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = dm_pool_strndup(vg->vgmem, (const char *)vg->name, NAME_LEN+1);
+ restore_user_env(&e);
+ return rc;
}
struct lvm_property_value lvm_vg_get_property(const vg_t vg, const char *name)
{
- return get_property(NULL, vg, NULL, NULL, NULL, NULL, NULL, name);
+ struct lvm_property_value rc;
+ struct saved_env e = store_user_env(vg->cmd);
+ rc = get_property(NULL, vg, NULL, NULL, NULL, NULL, NULL, name);
+ restore_user_env(&e);
+ return rc;
}
int lvm_vg_set_property(const vg_t vg, const char *name,
@@ -352,29 +466,41 @@ int lvm_vg_set_property(const vg_t vg, const char *name,
* that worst case we have two copies which will get freed when the vg gets
* released.
*/
+ int rc;
+ struct saved_env e = store_user_env(vg->cmd);
if (value->is_valid && value->is_string && value->value.string) {
value->value.string = dm_pool_strndup(vg->vgmem, value->value.string,
strlen(value->value.string) + 1);
}
- return set_property(NULL, vg, NULL, NULL, NULL, name, value);
+ rc = set_property(NULL, vg, NULL, NULL, NULL, name, value);
+ restore_user_env(&e);
+ return rc;
}
struct dm_list *lvm_list_vg_names(lvm_t libh)
{
- if (!lvmetad_vg_list_to_lvmcache((struct cmd_context *)libh))
- return NULL;
+ struct dm_list *rc = NULL;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
- return get_vgnames((struct cmd_context *)libh, 0);
+ if (lvmetad_vg_list_to_lvmcache((struct cmd_context *)libh)) {
+ rc = get_vgnames((struct cmd_context *)libh, 0);
+ }
+ restore_user_env(&e);
+ return rc;
}
struct dm_list *lvm_list_vg_uuids(lvm_t libh)
{
- if (!lvmetad_vg_list_to_lvmcache((struct cmd_context *)libh))
- return NULL;
+ struct dm_list *rc = NULL;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
- return get_vgids((struct cmd_context *)libh, 0);
+ if (lvmetad_vg_list_to_lvmcache((struct cmd_context *)libh)) {
+ rc = get_vgids((struct cmd_context *)libh, 0);
+ }
+ restore_user_env(&e);
+ return rc;
}
/*
@@ -382,21 +508,29 @@ struct dm_list *lvm_list_vg_uuids(lvm_t libh)
*/
int lvm_scan(lvm_t libh)
{
+ int rc = 0;
+ struct saved_env e = store_user_env((struct cmd_context *)libh);
+
if (!lvmcache_label_scan((struct cmd_context *)libh, 2))
- return -1;
- return 0;
+ rc = -1;
+
+ restore_user_env(&e);
+ return rc;
}
int lvm_lv_name_validate(const vg_t vg, const char *name)
{
+ int rc = -1;
name_error_t name_error;
+ struct saved_env e = store_user_env(vg->cmd);
+
name_error = validate_name_detailed(name);
if (NAME_VALID == name_error) {
if (apply_lvname_restrictions(name)) {
if (!find_lv_in_vg(vg, name)) {
- return 0;
+ rc = 0;
} else {
log_errno(EINVAL, "LV name exists in VG");
}
@@ -404,14 +538,20 @@ int lvm_lv_name_validate(const vg_t vg, const char *name)
} else {
display_name_error(name_error);
}
- return -1;
+
+ restore_user_env(&e);
+ return rc;
}
int lvm_vg_name_validate(lvm_t libh, const char *name)
{
+ int rc = -1;
struct cmd_context *cmd = (struct cmd_context *)libh;
+ struct saved_env e = store_user_env(cmd);
if (validate_new_vg_name(cmd, name))
- return 0;
- return -1;
+ rc = 0;
+
+ restore_user_env(&e);
+ return rc;
}
9 years, 9 months
master - device: if BLKPBSZGET is unavailable, try to use BLKSSZGET with fallback to 512b
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f270bbd442b3c3...
Commit: f270bbd442b3c36115ea490ec838cf29277a46d2
Parent: 359291b41cdeb1ca886e018aa44c67882da10252
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Dec 18 13:52:01 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Dec 18 13:52:01 2013 +0100
device: if BLKPBSZGET is unavailable, try to use BLKSSZGET with fallback to 512b
---
lib/device/dev-io.c | 23 ++++++++++++++++++-----
1 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 1bfac1d..82cc2fc 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -155,13 +155,26 @@ int dev_get_block_size(struct device *dev, unsigned int *physical_block_size, un
}
log_debug_devs("%s: physical block size is %u bytes", name, dev->phys_block_size);
}
-#else
+#elif BLKSSZGET
/* if we can't get physical block size, just use logical block size instead */
- // FIXME block_size is typically 4096b while phys_block_size is 512b
- dev->phys_block_size = 512;// dev->block_size;
- log_debug_devs("%s: physical block size can't be determined, using logical "
- "block size of %u bytes instead", name, dev->phys_block_size);
+ if (dev->phys_block_size == -1) {
+ if (ioctl(dev_fd(dev), BLKSSZGET, &dev->phys_block_size) < 0) {
+ log_sys_error("ioctl BLKSSZGET", name);
+ r = 0;
+ goto out;
+ }
+ log_debug_devs("%s: physical block size can't be determined, using logical "
+ "block size of %u bytes", name, dev->phys_block_size);
+ }
+#else
+ /* if even BLKSSZGET is not available, use default 512b */
+ if (dev->phys_block_size == -1) {
+ dev->phys_block_size = 512;
+ log_debug_devs("%s: physical block size can't be determined, using block "
+ "size of %u bytes instead", name, dev->phys_block_size);
+ }
#endif
+
*physical_block_size = (unsigned int) dev->phys_block_size;
*block_size = (unsigned int) dev->block_size;
out:
9 years, 9 months
master - systemd: use only major:minor for pvscan in lvm2-pvscan@.service
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=359291b41cdeb1...
Commit: 359291b41cdeb1ca886e018aa44c67882da10252
Parent: 3c818c89467f9b54bc94d9919a127dd912d96c24
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Dec 18 12:00:02 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Dec 18 12:23:59 2013 +0100
systemd: use only major:minor for pvscan in lvm2-pvscan@.service
When using filters for the pvscan --cache (the global_filter),
there's a difference between:
pvscan --cache -aay /dev/block/<major>:<minor>
and
pvscan --cache -aay <major>:<minor> (or --major <major> --minor <minor>)
In the first case, we need to be sure to have an exact matching line
in the filter for the device to be used, no aliases are considered
So for example even if we have accept rule for "/dev/sda" present,
this won't apply for "/dev/block/8:0" even though it's the same device!
This is because we're comparing the path used on command line directly
with the path written in the rule.
For the second one, any alias mentioned in the filter will apply
as we're comparing the major and minor pair, not looking at actual
device names - so any alias mentioned in the rules will suffice for
the filtering rule to apply.
For the global_filter to be properly used, we need to call the
second one in the lvm2-pvscan@.service - nobody is able to tell
what value of major:minor the kernel assignes next time, hence
this bug makes the use of global_filter quite unusable!
---
WHATS_NEW | 1 +
scripts/lvm2_pvscan_systemd_red_hat@.service.in | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index fe8f1ea..1dac25e 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Use major:minor in lvm2-pvscan@.service for proper global_filter application.
Syntax and spelling fixes in some man pages.
Dependency scan counts with snapshots and external origins.
Make sure VG extent size is always greater or equal to PV phys. block size.
diff --git a/scripts/lvm2_pvscan_systemd_red_hat@.service.in b/scripts/lvm2_pvscan_systemd_red_hat@.service.in
index 6b21c75..cdbbe40 100644
--- a/scripts/lvm2_pvscan_systemd_red_hat@.service.in
+++ b/scripts/lvm2_pvscan_systemd_red_hat@.service.in
@@ -11,5 +11,5 @@ Conflicts=shutdown.target
[Service]
Type=oneshot
RemainAfterExit=yes
-ExecStart=@sbindir@/pvscan --cache --activate ay /dev/block/%i
+ExecStart=@sbindir@/pvscan --cache --activate ay %i
ExecStop=@sbindir@/pvscan --cache %i
9 years, 9 months
master - device: if BLKPBSZGET is unavailable, enforce 512
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3c818c89467f9b...
Commit: 3c818c89467f9b54bc94d9919a127dd912d96c24
Parent: 434d95cef31c4d95b6468e02397e1fedbdca9928
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Dec 18 10:52:09 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Dec 18 10:52:09 2013 +0100
device: if BLKPBSZGET is unavailable, enforce 512
If there is no define for BLKPBSZGET - we have hard time how to
decrypt physical block size - we can't use here block_size,
since this is usually 4k while we need to use 512b.
FIXME: find some better way, until that enforce value 512.
Eventually we could also try to put in:
+#ifndef BLKPBSZGET
+# define BLKPBSZGET _IO(0x12,123)
+#endif
but this will still not work well on old kernels.
---
lib/device/dev-io.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 766d9af..1bfac1d 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -157,7 +157,8 @@ int dev_get_block_size(struct device *dev, unsigned int *physical_block_size, un
}
#else
/* if we can't get physical block size, just use logical block size instead */
- dev->phys_block_size = dev->block_size;
+ // FIXME block_size is typically 4096b while phys_block_size is 512b
+ dev->phys_block_size = 512;// dev->block_size;
log_debug_devs("%s: physical block size can't be determined, using logical "
"block size of %u bytes instead", name, dev->phys_block_size);
#endif
9 years, 9 months
master - tests: clear inactive table before resuming in teardown
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=434d95cef31c4d...
Commit: 434d95cef31c4d95b6468e02397e1fedbdca9928
Parent: 3776832499862ce6896b598487e79b02e7432326
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Dec 18 10:40:36 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Dec 18 10:40:36 2013 +0100
tests: clear inactive table before resuming in teardown
---
test/lib/aux.sh | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 92385c8..ac6e111 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -98,6 +98,7 @@ teardown_devs_prefixed() {
# Resume suspended devices first
for dm in $(dm_info suspended,name | grep "^Suspended:.*$prefix"); do
echo "dmsetup resume \"${dm#Suspended:}\""
+ dmsetup clear "${dm#Suspended:}"
dmsetup resume "${dm#Suspended:}" &
done
9 years, 9 months
master - man: syntax and spelling fixes.
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3776832499862c...
Commit: 3776832499862ce6896b598487e79b02e7432326
Parent: c3d82d717ccd4d4801f5d84787bb12e0189eb1af
Author: Ville Skyttä <ville.skytta(a)iki.fi>
AuthorDate: Tue Dec 17 20:26:10 2013 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Dec 18 09:03:42 2013 +0100
man: syntax and spelling fixes.
---
WHATS_NEW | 1 +
man/dmsetup.8.in | 2 +-
man/lvconvert.8.in | 2 +-
man/lvm.8.in | 4 ++--
man/lvreduce.8.in | 2 +-
man/lvresize.8.in | 2 +-
man/pvmove.8.in | 2 +-
7 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index a7522f9..fe8f1ea 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Syntax and spelling fixes in some man pages.
Dependency scan counts with snapshots and external origins.
Make sure VG extent size is always greater or equal to PV phys. block size.
Optimize double call of stat() for cached devices.
diff --git a/man/dmsetup.8.in b/man/dmsetup.8.in
index 93621a5..599c843 100644
--- a/man/dmsetup.8.in
+++ b/man/dmsetup.8.in
@@ -484,7 +484,7 @@ Default subsystem is LVM.
.B status
.RB [ \-\-target
.IR target_type ]
-.RB [ \-\-\noflush ]
+.RB [ \-\-noflush ]
.RI [ device_name ]
.br
Outputs status information for each of the device's targets.
diff --git a/man/lvconvert.8.in b/man/lvconvert.8.in
index 44b89af..c8cb2dc 100644
--- a/man/lvconvert.8.in
+++ b/man/lvconvert.8.in
@@ -203,7 +203,7 @@ a mirror logical volume.
.B \-\-trackchanges
Used with \fB\-\-splitmirrors\fP on a raid1 device, this tracks changes so
that the read-only detached image can be merged efficiently back into
-the mirror later. Only the regions of the detatched device where
+the mirror later. Only the regions of the detached device where
the data changed get resynchronized.
Please note that this feature is only supported with the new md-based mirror
diff --git a/man/lvm.8.in b/man/lvm.8.in
index 13e66d0..d78281a 100644
--- a/man/lvm.8.in
+++ b/man/lvm.8.in
@@ -21,7 +21,7 @@ that command.
On invocation, \fBlvm\fP requires that only the standard file descriptors
stdin, stdout and stderr are available. If others are found, they
get closed and messages are issued warning about the leak.
-This warning can be suppressed by setting enviromental variable
+This warning can be suppressed by setting the environment variable
.B LVM_SUPPRESS_FD_WARNINGS\fP.
.LP
Where commands take VG or LV names as arguments, the full path name is
@@ -46,7 +46,7 @@ being created in the filesystem for them.
\fBdumpconfig\fP \(em Display the configuration information after
loading \fBlvm.conf\fP(5) and any other configuration files.
.TP
-\fBdevtypes\fP \(dm Display the recognised built-in block device types.
+\fBdevtypes\fP \(em Display the recognised built-in block device types.
.TP
\fBformats\fP \(em Display recognised metadata formats.
.TP
diff --git a/man/lvreduce.8.in b/man/lvreduce.8.in
index dabdc88..2c38f5b 100644
--- a/man/lvreduce.8.in
+++ b/man/lvreduce.8.in
@@ -57,7 +57,7 @@ size of the Logical Volume with the suffix \fI%LV\fP, as a percentage of the
remaining free space in the Volume Group with the suffix \fI%FREE\fP, or (for
a snapshot) as a percentage of the total space in the Origin Logical
Volume with the suffix \fI%ORIGIN\fP.
-The resulting value for the substraction is rounded downward, for the absolute
+The resulting value for the subtraction is rounded downward, for the absolute
size it is rounded upward.
.TP
.IR \fB\-L ", " \fB\-\-size " [" \- ] LogicalVolumeSize [ bBsSkKmMgGtTpPeE ]
diff --git a/man/lvresize.8.in b/man/lvresize.8.in
index e04869d..3606762 100644
--- a/man/lvresize.8.in
+++ b/man/lvresize.8.in
@@ -56,7 +56,7 @@ the remaining free space of the PhysicalVolumes on the command line with the
suffix \fI%PVS\fP, as a percentage of the remaining free space in the
Volume Group with the suffix \fI%FREE\fP, or (for a snapshot) as a percentage
of the total space in the Origin Logical Volume with the suffix \fI%ORIGIN\fP.
-The resulting value is rounded downward for the substraction otherwise
+The resulting value is rounded downward for the subtraction otherwise
it is rounded upward.
.TP
.IR \fB\-L ", " \fB\-\-size " [" + | - ] LogicalVolumeSize [ bBsSkKmMgGtTpPeE ]
diff --git a/man/pvmove.8.in b/man/pvmove.8.in
index c77dcbc..bb69547 100644
--- a/man/pvmove.8.in
+++ b/man/pvmove.8.in
@@ -131,7 +131,7 @@ also refers to 1000 Physical Extents starting from Physical Extent number 1000.
(Counting starts from 0, so this refers to the 1001st to the 2000th inclusive.)
.P
To move a range of Physical Extents to a specific location (which must have
-sufficent free extents) use the form:
+sufficient free extents) use the form:
.sp
.B pvmove /dev/sdb1:1000-1999 /dev/sdc1
.sp
9 years, 9 months
master - Revert "tree_action: destroy devices from failing activation"
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c3d82d717ccd4d...
Commit: c3d82d717ccd4d4801f5d84787bb12e0189eb1af
Parent: 3652083f38ca21276c8467f54eeaa8f1365ec6fe
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Dec 17 15:17:44 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 17 15:21:28 2013 +0100
Revert "tree_action: destroy devices from failing activation"
This reverts commit 24639be558a9d4561a34f2b76485b227aed8e9c3.
Ok - seems we could be here a bit too active - and we
may remove devices which are unsuable for reasons we are not
aware of - thus taking down whole device could be way to big hammer.
So we still need some solution to recover from failing preload
and activation - but it needs more tunning.
---
WHATS_NEW | 1 -
lib/activate/dev_manager.c | 10 ++--------
2 files changed, 2 insertions(+), 9 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 59820b2..a7522f9 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,6 +1,5 @@
Version 2.02.105 -
=====================================
- Try to remove any unusable devices from dm table when activation fails.
Dependency scan counts with snapshots and external origins.
Make sure VG extent size is always greater or equal to PV phys. block size.
Optimize double call of stat() for cached devices.
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index a4147d3..7b0b6e2 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -2754,21 +2754,15 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv,
goto_out;
/* Preload any devices required before any suspensions */
- if (!dm_tree_preload_children(root, dlid, DLID_SIZE)) {
- bad:
- if (!dm_tree_deactivate_children(root, dlid, DLID_SIZE))
- stack;
- if (!_remove_lv_symlinks(dm, root))
- log_warn("Failed to remove all device symlinks associated with %s.", lv->name);
+ if (!dm_tree_preload_children(root, dlid, DLID_SIZE))
goto_out;
- }
if (dm_tree_node_size_changed(root))
dm->flush_required = 1;
if (action == ACTIVATE) {
if (!dm_tree_activate_children(root, dlid, DLID_SIZE))
- goto_bad;
+ goto_out;
if (!_create_lv_symlinks(dm, root))
log_warn("Failed to create symlinks for %s.", lv->name);
}
9 years, 9 months
master - device: use BLKPBSZGET for physical block size only if the op is available, otherwise use logical block size
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3652083f38ca21...
Commit: 3652083f38ca21276c8467f54eeaa8f1365ec6fe
Parent: 24639be558a9d4561a34f2b76485b227aed8e9c3
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Dec 17 15:16:25 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Dec 17 15:17:28 2013 +0100
device: use BLKPBSZGET for physical block size only if the op is available, otherwise use logical block size
Older kernels < 2.6.32 don't have BLKPBSZGET defined.
---
lib/device/dev-io.c | 25 ++++++++++++++++---------
1 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 45700e5..766d9af 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -136,15 +136,6 @@ int dev_get_block_size(struct device *dev, unsigned int *physical_block_size, un
if (needs_open && !dev_open_readonly(dev))
return_0;
- if (dev->phys_block_size == -1) {
- if (ioctl(dev_fd(dev), BLKPBSZGET, &dev->phys_block_size) < 0) {
- log_sys_error("ioctl BLKPBSZGET", name);
- r = 0;
- goto out;
- }
- log_debug_devs("%s: physical block size is %u bytes", name, dev->phys_block_size);
- }
-
if (dev->block_size == -1) {
if (ioctl(dev_fd(dev), BLKBSZGET, &dev->block_size) < 0) {
log_sys_error("ioctl BLKBSZGET", name);
@@ -154,6 +145,22 @@ int dev_get_block_size(struct device *dev, unsigned int *physical_block_size, un
log_debug_devs("%s: block size is %u bytes", name, dev->block_size);
}
+#ifdef BLKPBSZGET
+ /* BLKPBSZGET is available in kernel >= 2.6.32 only */
+ if (dev->phys_block_size == -1) {
+ if (ioctl(dev_fd(dev), BLKPBSZGET, &dev->phys_block_size) < 0) {
+ log_sys_error("ioctl BLKPBSZGET", name);
+ r = 0;
+ goto out;
+ }
+ log_debug_devs("%s: physical block size is %u bytes", name, dev->phys_block_size);
+ }
+#else
+ /* if we can't get physical block size, just use logical block size instead */
+ dev->phys_block_size = dev->block_size;
+ log_debug_devs("%s: physical block size can't be determined, using logical "
+ "block size of %u bytes instead", name, dev->phys_block_size);
+#endif
*physical_block_size = (unsigned int) dev->phys_block_size;
*block_size = (unsigned int) dev->block_size;
out:
9 years, 9 months
master - tree_action: destroy devices from failing activation
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=24639be558a9d4...
Commit: 24639be558a9d4561a34f2b76485b227aed8e9c3
Parent: 94137b72edf232a0e82758c1669f1f60f2df3c50
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Dec 17 13:49:03 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 17 14:08:54 2013 +0100
tree_action: destroy devices from failing activation
When activation fails - we may leak large tree of partially loaded
devices in the dm table (i.e. failure in snapshot activation)
The best we can do here is try to deactivate whole device and
remove as much inactive table entries as we can.
---
WHATS_NEW | 1 +
lib/activate/dev_manager.c | 10 ++++++++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index a7522f9..59820b2 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Try to remove any unusable devices from dm table when activation fails.
Dependency scan counts with snapshots and external origins.
Make sure VG extent size is always greater or equal to PV phys. block size.
Optimize double call of stat() for cached devices.
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 7b0b6e2..a4147d3 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -2754,15 +2754,21 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv,
goto_out;
/* Preload any devices required before any suspensions */
- if (!dm_tree_preload_children(root, dlid, DLID_SIZE))
+ if (!dm_tree_preload_children(root, dlid, DLID_SIZE)) {
+ bad:
+ if (!dm_tree_deactivate_children(root, dlid, DLID_SIZE))
+ stack;
+ if (!_remove_lv_symlinks(dm, root))
+ log_warn("Failed to remove all device symlinks associated with %s.", lv->name);
goto_out;
+ }
if (dm_tree_node_size_changed(root))
dm->flush_required = 1;
if (action == ACTIVATE) {
if (!dm_tree_activate_children(root, dlid, DLID_SIZE))
- goto_out;
+ goto_bad;
if (!_create_lv_symlinks(dm, root))
log_warn("Failed to create symlinks for %s.", lv->name);
}
9 years, 9 months
master - lv_dependency: scan also snapshots and extorigins
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=94137b72edf232...
Commit: 94137b72edf232a0e82758c1669f1f60f2df3c50
Parent: 760714829bfd6f3cc6e0f23f029baf4cc9ed441d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Dec 17 13:53:15 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 17 14:08:54 2013 +0100
lv_dependency: scan also snapshots and extorigins
When LV is scanned for its dependencies - scan also origin's snapshots,
and thin external origins.
So if any PV from snapshot or external origin device is missing - lvm2 will
avoid trying to activate such device.
---
WHATS_NEW | 1 +
lib/metadata/metadata.c | 9 +++++++++
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 1679131..a7522f9 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Dependency scan counts with snapshots and external origins.
Make sure VG extent size is always greater or equal to PV phys. block size.
Optimize double call of stat() for cached devices.
Enable support for thin provisioning for default configuration.
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 84d3200..4d4778b 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -2019,6 +2019,7 @@ static int _lv_each_dependency(struct logical_volume *lv,
{
unsigned i, s;
struct lv_segment *lvseg;
+ struct dm_list *snh;
struct logical_volume *deps[] = {
(lv->rdevice && lv != lv->rdevice->lv) ? lv->rdevice->lv : 0,
@@ -2031,6 +2032,8 @@ static int _lv_each_dependency(struct logical_volume *lv,
}
dm_list_iterate_items(lvseg, &lv->segments) {
+ if (lvseg->external_lv && !fn(lvseg->external_lv, data))
+ return_0;
if (lvseg->log_lv && !fn(lvseg->log_lv, data))
return_0;
if (lvseg->rlog_lv && !fn(lvseg->rlog_lv, data))
@@ -2044,6 +2047,12 @@ static int _lv_each_dependency(struct logical_volume *lv,
return_0;
}
}
+
+ if (lv_is_origin(lv))
+ dm_list_iterate(snh, &lv->snapshot_segs)
+ if (!fn(dm_list_struct_base(snh, struct lv_segment, origin_list)->cow, data))
+ return_0;
+
return 1;
}
9 years, 9 months