master - thin: validate unused thin pool
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6116b1d6e30209...
Commit: 6116b1d6e302097086c9dcd418e4404ddd337939
Parent: ee627884de95ae5a40f0fc2534dcd60e63e2a58d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Nov 4 15:06:55 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Nov 4 15:28:00 2014 +0100
thin: validate unused thin pool
Function tests, that given new thin pool is still unused.
---
lib/metadata/metadata.h | 3 ++
lib/metadata/thin_manip.c | 52 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
index 1dd8867..48c1b3c 100644
--- a/lib/metadata/metadata.h
+++ b/lib/metadata/metadata.h
@@ -389,6 +389,9 @@ struct lv_segment *find_pool_seg(const struct lv_segment *seg);
/* Find some unused device_id for thin pool LV segment. */
uint32_t get_free_pool_device_id(struct lv_segment *thin_pool_seg);
+/* Check if the new thin-pool could be used for lvm2 thin volumes */
+int check_new_thin_pool(const struct logical_volume *pool_lv);
+
/*
* Remove a dev_dir if present.
*/
diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c
index 8569ac1..50354cc 100644
--- a/lib/metadata/thin_manip.c
+++ b/lib/metadata/thin_manip.c
@@ -569,3 +569,55 @@ int lv_is_thin_origin(const struct logical_volume *lv, unsigned int *snap_count)
return r;
}
+
+/*
+ * Explict check of new thin pool for usability
+ *
+ * Allow use of thin pools by external apps. When lvm2 metadata has
+ * transaction_id == 0 for a new thin pool, it will explicitely validate
+ * the pool is still unused.
+ *
+ * To prevent lvm2 to create thin volumes in externally used thin pools
+ * simply increment its transaction_id.
+ */
+int check_new_thin_pool(const struct logical_volume *pool_lv)
+{
+ struct cmd_context *cmd = pool_lv->vg->cmd;
+ uint64_t transaction_id;
+
+ /* For transaction_id check LOCAL activation is required */
+ if (!activate_lv_excl_local(cmd, pool_lv)) {
+ log_error("Aborting. Failed to locally activate thin pool %s.",
+ display_lvname(pool_lv));
+ return 0;
+ }
+
+ /* With volume lists, check pool really is locally active */
+ if (!lv_thin_pool_transaction_id(pool_lv, &transaction_id)) {
+ log_error("Cannot read thin pool %s transaction id locally, perhaps skipped in lvm.conf volume_list?",
+ display_lvname(pool_lv));
+ return 0;
+ }
+
+ /* Require pool to have same transaction_id as new */
+ if (first_seg(pool_lv)->transaction_id != transaction_id) {
+ log_error("Cannot use thin pool %s with transaction id "
+ "%" PRIu64 " for thin volumes. "
+ "Expected transaction id %" PRIu64 ".",
+ display_lvname(pool_lv), transaction_id,
+ first_seg(pool_lv)->transaction_id);
+ return 0;
+ }
+
+ log_verbose("Deactivating public thin pool %s",
+ display_lvname(pool_lv));
+
+ /* Prevent any 'race' with in-use thin pool and always deactivate */
+ if (!deactivate_lv(pool_lv->vg->cmd, pool_lv)) {
+ log_error("Aborting. Could not deactivate thin pool %s.",
+ display_lvname(pool_lv));
+ return 0;
+ }
+
+ return 1;
+}
9 years, 5 months
master - thin: no validation skip of new thin pools
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ee627884de95ae...
Commit: ee627884de95ae5a40f0fc2534dcd60e63e2a58d
Parent: 26aa912b4663633c6e094bad85393601903bcaac
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Nov 4 09:51:58 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Nov 4 15:28:00 2014 +0100
thin: no validation skip of new thin pools
Allowing 'external' use of thin-pools requires to validate even
so far 'unused' new thin pools.
Later we may have 'smarter' way to resolve which thin-pools are
owned by lvm2 and which are external.
---
lib/activate/dev_manager.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 266c80a..41911c1 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -1815,12 +1815,15 @@ static int _pool_register_callback(struct dev_manager *dm,
{
struct pool_cb_data *data;
+ /* Do not skip metadata of testing even for unused thin pools */
+#if 0
/* Skip metadata testing for unused thin pool. */
if (lv_is_thin_pool(lv) &&
(!first_seg(lv)->transaction_id ||
((first_seg(lv)->transaction_id == 1) &&
pool_has_message(first_seg(lv), NULL, 0))))
return 1;
+#endif
if (!(data = dm_pool_zalloc(dm->mem, sizeof(*data)))) {
log_error("Failed to allocated path for callback.");
9 years, 5 months
master - thin: add lv_is_new_thin_pool
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=26aa912b466363...
Commit: 26aa912b4663633c6e094bad85393601903bcaac
Parent: 89233544e00a0acfad82055b737ebcce41919d58
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Nov 4 10:31:28 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Nov 4 15:28:00 2014 +0100
thin: add lv_is_new_thin_pool
Recognize 'new' (and never used) lvm2 thin pool - it has 'transaction_id' == 0
(lv_is_used_thin_pool() has slightly different meaning).
---
lib/metadata/metadata-exported.h | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 736b0b5..713b3b6 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -175,6 +175,7 @@
#define lv_is_thin_volume(lv) (((lv)->status & THIN_VOLUME) ? 1 : 0)
#define lv_is_thin_pool(lv) (((lv)->status & THIN_POOL) ? 1 : 0)
+#define lv_is_new_thin_pool(lv) (lv_is_thin_pool(lv) && !first_seg(lv)->transaction_id)
#define lv_is_used_thin_pool(lv) (lv_is_thin_pool(lv) && !dm_list_empty(&(lv)->segs_using_this_lv))
#define lv_is_thin_pool_data(lv) (((lv)->status & THIN_POOL_DATA) ? 1 : 0)
#define lv_is_thin_pool_metadata(lv) (((lv)->status & THIN_POOL_METADATA) ? 1 : 0)
9 years, 5 months
master - libdm: allow to activate any pool with tid == 0
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=89233544e00a0a...
Commit: 89233544e00a0acfad82055b737ebcce41919d58
Parent: 7092b47ec90571668c30ef38a9ec251adcff2c82
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Nov 4 09:42:15 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Nov 4 15:28:00 2014 +0100
libdm: allow to activate any pool with tid == 0
When transaction_id is set 0 for thin-pool, libdm avoids validation
of thin-pool, unless there are real messages to be send to thin-pool.
This relaxes strict policy which always required to know
in front transaction_id for the kernel target.
It now allows to activate thin-pool with any transaction_id
(when transaction_id is passed in)
It is now upto application to validate transaction_id from life
thin-pool volume with transaction_id within it's own metadata.
---
WHATS_NEW_DM | 1 +
libdm/libdm-deptree.c | 4 +++-
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 6b5ee3a..0305077 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.91 -
====================================
+ Allow activation of any thin-pool with passed transaction_id == 0.
Don't print uninitialized stack bytes when non-root uses dm_check_version().
Fix selection criteria to not match reserved values when using >, <, >=, <.
Add DM_LIST_HEAD_INIT macro to libdevmapper.h
diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c
index 0048b1c..d120bf5 100644
--- a/libdm/libdm-deptree.c
+++ b/libdm/libdm-deptree.c
@@ -3757,7 +3757,8 @@ int dm_tree_node_add_thin_pool_target(struct dm_tree_node *node,
seg->metadata->props.delay_resume_if_new = 0;
seg->pool->props.delay_resume_if_new = 0;
- node->props.send_messages = 1;
+ /* Validate only transaction_id > 0 when activating thin-pool */
+ node->props.send_messages = transaction_id ? 1 : 0;
seg->transaction_id = transaction_id;
seg->low_water_mark = low_water_mark;
seg->data_block_size = data_block_size;
@@ -3826,6 +3827,7 @@ int dm_tree_node_add_thin_pool_message(struct dm_tree_node *node,
tm->message.type = type;
dm_list_add(&seg->thin_messages, &tm->list);
+ node->props.send_messages = 1;
return 1;
}
9 years, 5 months
master - lvconvert: convert missing sizes to extents
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7092b47ec90571...
Commit: 7092b47ec90571668c30ef38a9ec251adcff2c82
Parent: 847b2aa5b418c80d4fe2fb68dec32e7992416ba0
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Nov 4 14:14:52 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Nov 4 15:25:47 2014 +0100
lvconvert: convert missing sizes to extents
After initial 'size' usage converted to extents, continue to use
only extents.
(in-release fix).
---
tools/lvconvert.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 22058ea..fcec8e1 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -2842,7 +2842,7 @@ static int _lvconvert_pool(struct cmd_context *cmd,
log_error("Unknown pool metadata LV %s.", lp->pool_metadata_name);
return 0;
}
- lp->pool_metadata_size = lp->pool_metadata_lv->size;
+ lp->pool_metadata_extents = lp->pool_metadata_lv->le_count;
metadata_lv = lp->pool_metadata_lv;
if (metadata_lv == pool_lv) {
@@ -2885,7 +2885,7 @@ static int _lvconvert_pool(struct cmd_context *cmd,
if (!_lvconvert_update_pool_params(pool_lv, lp))
return_0;
- if (lp->pool_metadata_size > metadata_lv->size) {
+ if (lp->pool_metadata_extents > metadata_lv->le_count) {
log_error("Logical volume %s is too small for metadata.",
display_lvname(metadata_lv));
return 0;
@@ -2953,7 +2953,7 @@ static int _lvconvert_pool(struct cmd_context *cmd,
if (!_lvconvert_update_pool_params(pool_lv, lp))
return_0;
- if (metadata_lv->size < lp->pool_metadata_size)
+ if (metadata_lv->le_count < lp->pool_metadata_extents)
log_print_unless_silent("Continuing with swap...");
if (!arg_count(cmd, discards_ARG))
9 years, 5 months
master - tests: thin
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=847b2aa5b418c8...
Commit: 847b2aa5b418c80d4fe2fb68dec32e7992416ba0
Parent: e4e96f6b19e2ae7ba8841c1e93ba385cc18ca3c9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 30 23:18:40 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 3 14:19:34 2014 +0100
tests: thin
---
test/shell/lvcreate-thin.sh | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/test/shell/lvcreate-thin.sh b/test/shell/lvcreate-thin.sh
index 733888e..0433ac8 100644
--- a/test/shell/lvcreate-thin.sh
+++ b/test/shell/lvcreate-thin.sh
@@ -239,7 +239,9 @@ aux teardown_devs
aux prepare_pvs 10 16500
vgcreate $vg -s 64K $(cat DEVICES)
-lvcreate -L4M --chunksize 128 --poolmetadatasize 0 -T $vg/pool1 2>out
+# Size 0 is not valid
+invalid lvcreate -L4M --chunksize 128 --poolmetadatasize 0 -T $vg/pool1 2>out
+lvcreate -L4M --chunksize 128 --poolmetadatasize 16k -T $vg/pool1 2>out
grep "WARNING: Minimum" out
# FIXME: metadata allocation fails, if PV doesn't have at least 16GB
# i.e. pool metadata device cannot be multisegment
9 years, 5 months
master - tests: usage of -m0 -Mn
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e4e96f6b19e2ae...
Commit: e4e96f6b19e2ae7ba8841c1e93ba385cc18ca3c9
Parent: 6c32ced6572b857ca954601757268dc4bb688b2f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Oct 31 23:18:31 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 3 14:19:34 2014 +0100
tests: usage of -m0 -Mn
Test -m0 passed with types.
Check --readahead and thins.
---
test/shell/lvcreate-thin.sh | 17 +++++++++++++++++
test/shell/lvcreate-usage.sh | 2 +-
2 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/test/shell/lvcreate-thin.sh b/test/shell/lvcreate-thin.sh
index 619a40c..733888e 100644
--- a/test/shell/lvcreate-thin.sh
+++ b/test/shell/lvcreate-thin.sh
@@ -200,6 +200,23 @@ not lvcreate --chunksize 256 -l1 -T $vg/pool1
not lvcreate --chunksize 32 -l1 -T $vg/pool1
# Too large chunk size (max is 1GB)
not lvcreate -L4M --chunksize 2G -T $vg/pool1
+# Cannot specify --minor with pool
+fail lvcreate -L10M --minor 100 -T $vg/pool_minor
+
+# FIXME: Currently ambigous - is it for thin, thin-pool, both ?
+fail lvcreate -L4M -Mn -m0 -T --readahead 32 -V20 -n $lv $vg/pool_normal
+
+# Check read-ahead setting will also pass with -Mn -m0
+lvcreate -L4M -Mn -m0 -T --readahead 64k $vg/pool_readahead
+lvcreate -V20M -Mn -m0 -T --readahead 128k -n thin_readahead $vg/pool_readahead
+check lv_field $vg/pool_readahead lv_read_ahead "64.00k"
+check lv_field $vg/thin_readahead lv_read_ahead "128.00k"
+
+if test ! -d /sys/block/dm-2345; then
+# Check some unused minor and support for --minor with thins
+ lvcreate --minor 2345 -T -V20M -n thin_minor $vg/pool_readahead
+ check lv_field $vg/thin_minor lv_minor "2345"
+fi
# Test creation of inactive pool
lvcreate -an -L4M -T $vg/pool1
diff --git a/test/shell/lvcreate-usage.sh b/test/shell/lvcreate-usage.sh
index 5d37d9c..fe82005 100644
--- a/test/shell/lvcreate-usage.sh
+++ b/test/shell/lvcreate-usage.sh
@@ -22,7 +22,7 @@ grep "Invalid argument for --type" err
invalid lvcreate --type $RANDOM -l1 -n $lv1 $vg
invalid lvcreate --type unknown -l1 -n $lv1 $vg
-lvcreate --type linear -aey -l1 -n $lv1 $vg
+lvcreate --type linear -aey -m0 -l1 -n $lv1 $vg
lvcreate --type snapshot -l1 -n $lv2 $vg/$lv1
# Reject repeated invocation (run 2 times) (bz178216)
9 years, 5 months
master - cleanup: use lv_is_pool
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6c32ced6572b85...
Commit: 6c32ced6572b857ca954601757268dc4bb688b2f
Parent: 0ba5571bab4ea0d9e1f30bd35033033bdb477417
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Nov 2 19:43:35 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 3 14:19:34 2014 +0100
cleanup: use lv_is_pool
Use lv_is_pool() to detect both pool versions.
---
lib/report/report.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index c74bbfa..4f505e7 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -447,7 +447,7 @@ static int _datalv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(
const void *data, void *private __attribute__((unused)))
{
const struct logical_volume *lv = (const struct logical_volume *) data;
- const struct lv_segment *seg = (lv_is_thin_pool(lv) || lv_is_cache_pool(lv)) ? first_seg(lv) : NULL;
+ const struct lv_segment *seg = (lv_is_pool(lv)) ? first_seg(lv) : NULL;
if (seg)
return _lvname_disp(rh, mem, field, seg_lv(seg, 0), private);
@@ -460,7 +460,7 @@ static int _metadatalv_disp(struct dm_report *rh, struct dm_pool *mem __attribut
const void *data, void *private __attribute__((unused)))
{
const struct logical_volume *lv = (const struct logical_volume *) data;
- const struct lv_segment *seg = (lv_is_thin_pool(lv) || lv_is_cache_pool(lv)) ? first_seg(lv) : NULL;
+ const struct lv_segment *seg = (lv_is_pool(lv)) ? first_seg(lv) : NULL;
if (seg)
return _lvname_disp(rh, mem, field, seg->metadata_lv, private);
9 years, 5 months
master - cleanup: use logical_volume* directly
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0ba5571bab4ea0...
Commit: 0ba5571bab4ea0d9e1f30bd35033033bdb477417
Parent: fdc252ec35c8c08ef4674bb1656bf4bfed641add
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Oct 31 10:15:00 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 3 14:19:34 2014 +0100
cleanup: use logical_volume* directly
---
tools/lvresize.c | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/tools/lvresize.c b/tools/lvresize.c
index 133cc6f..08248bb 100644
--- a/tools/lvresize.c
+++ b/tools/lvresize.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2013 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2014 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -168,7 +168,7 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
struct lvresize_params lp = { 0 };
struct volume_group *vg;
struct dm_list *pvh = NULL;
- struct lv_list *lvl;
+ struct logical_volume *lv;
int r = ECMD_FAILED;
if (!_lvresize_params(cmd, argc, argv, &lp))
@@ -181,23 +181,23 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
return_ECMD_FAILED;
}
- /* Does LV exist? */
- if (!(lvl = find_lv_in_vg(vg, lp.lv_name))) {
- log_error("Logical volume %s not found in volume group %s",
- lp.lv_name, lp.vg_name);
+ /* Does LV exist? */
+ if (!(lv = find_lv(vg, lp.lv_name))) {
+ log_error("Logical volume %s not found in volume group %s",
+ lp.lv_name, lp.vg_name);
goto out;
- }
+ }
if (!(pvh = lp.argc ? create_pv_list(cmd->mem, vg, lp.argc,
lp.argv, 1) : &vg->pvs))
goto_out;
- if (!lv_resize_prepare(cmd, lvl->lv, &lp, pvh)) {
+ if (!lv_resize_prepare(cmd, lv, &lp, pvh)) {
r = EINVALID_CMD_LINE;
goto_out;
}
- if (!lv_resize(cmd, lvl->lv, &lp, pvh))
+ if (!lv_resize(cmd, lv, &lp, pvh))
goto_out;
r = ECMD_PROCESSED;
9 years, 5 months
master - cleanup: consistent name
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fdc252ec35c8c0...
Commit: fdc252ec35c8c08ef4674bb1656bf4bfed641add
Parent: ce7f06cf4e62147293678c0baf0c86c45e8b4549
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Oct 31 11:52:30 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 3 14:19:34 2014 +0100
cleanup: consistent name
---
tools/toollib.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/toollib.h b/tools/toollib.h
index 50cc26c..e0e1e66 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -115,7 +115,7 @@ int get_pool_params(struct cmd_context *cmd,
const struct segment_type *segtype,
int *passed_args,
uint64_t *pool_metadata_size,
- int *pool_metadataspare,
+ int *pool_metadata_spare,
uint32_t *chunk_size,
thin_discards_t *discards,
int *zero);
9 years, 5 months