master - cache: rename variable in _cache_add_target_line
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5ee1727f808e76f5963...
Commit: 5ee1727f808e76f59637d78f2691aadc25d49b17
Parent: 7541e002b21260c558059c3c3c9739d05f37d4b3
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 5 16:05:28 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Nov 6 11:36:28 2018 -0600
cache: rename variable in _cache_add_target_line
so it is not specific to lv/seg type
---
lib/cache_segtype/cache.c | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/lib/cache_segtype/cache.c b/lib/cache_segtype/cache.c
index a9be51d..17f94d1 100644
--- a/lib/cache_segtype/cache.c
+++ b/lib/cache_segtype/cache.c
@@ -543,6 +543,7 @@ static int _cache_add_target_line(struct dev_manager *dm,
uint32_t *pvmove_mirror_count __attribute__((unused)))
{
struct lv_segment *cache_pool_seg;
+ struct lv_segment *setting_seg;
char *metadata_uuid, *data_uuid, *origin_uuid;
uint64_t feature_flags = 0;
unsigned attr;
@@ -552,15 +553,20 @@ static int _cache_add_target_line(struct dev_manager *dm,
return 0;
}
+ log_debug("cache_add_target_line lv %s pool %s", seg->lv->name, seg->pool_lv->name);
+
cache_pool_seg = first_seg(seg->pool_lv);
+
+ setting_seg = cache_pool_seg;
+
if (seg->cleaner_policy)
/* With cleaner policy always pass writethrough */
feature_flags |= DM_CACHE_FEATURE_WRITETHROUGH;
else
- switch (cache_pool_seg->cache_mode) {
+ switch (setting_seg->cache_mode) {
default:
log_error(INTERNAL_ERROR "LV %s has unknown cache mode %d.",
- display_lvname(seg->lv), cache_pool_seg->cache_mode);
+ display_lvname(seg->lv), setting_seg->cache_mode);
/* Fall through */
case CACHE_MODE_WRITETHROUGH:
feature_flags |= DM_CACHE_FEATURE_WRITETHROUGH;
@@ -573,7 +579,7 @@ static int _cache_add_target_line(struct dev_manager *dm,
break;
}
- switch (cache_pool_seg->cache_metadata_format) {
+ switch (setting_seg->cache_metadata_format) {
case CACHE_METADATA_FORMAT_1: break;
case CACHE_METADATA_FORMAT_2:
if (!_target_present(cmd, NULL, &attr))
@@ -581,7 +587,7 @@ static int _cache_add_target_line(struct dev_manager *dm,
if (!(attr & CACHE_FEATURE_METADATA2)) {
log_error("LV %s has metadata format %u unsuported by kernel.",
- display_lvname(seg->lv), cache_pool_seg->cache_metadata_format);
+ display_lvname(seg->lv), setting_seg->cache_metadata_format);
return 0;
}
feature_flags |= DM_CACHE_FEATURE_METADATA2;
@@ -589,7 +595,7 @@ static int _cache_add_target_line(struct dev_manager *dm,
break;
default:
log_error(INTERNAL_ERROR "LV %s has unknown metadata format %u.",
- display_lvname(seg->lv), cache_pool_seg->cache_metadata_format);
+ display_lvname(seg->lv), setting_seg->cache_metadata_format);
return 0;
}
5 years, 5 months
master - cache: rename variable in _cache_display
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7541e002b21260c5580...
Commit: 7541e002b21260c558059c3c3c9739d05f37d4b3
Parent: 85b4b2f92490a7e12d3aaf67df1db7a0bcc6937e
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 5 15:56:28 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Nov 6 11:36:28 2018 -0600
cache: rename variable in _cache_display
so it is not specific to lv/seg type
---
lib/cache_segtype/cache.c | 29 ++++++++++++++++++-----------
1 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/lib/cache_segtype/cache.c b/lib/cache_segtype/cache.c
index cb86212..a9be51d 100644
--- a/lib/cache_segtype/cache.c
+++ b/lib/cache_segtype/cache.c
@@ -47,23 +47,30 @@ static int _cache_out_line(const char *line, void *_f)
static void _cache_display(const struct lv_segment *seg)
{
const struct dm_config_node *n;
- const struct lv_segment *pool_seg =
- seg_is_cache_pool(seg) ? seg : first_seg(seg->pool_lv);
+ const struct lv_segment *setting_seg = NULL;
+
+ if (seg_is_cache_pool(seg))
+ setting_seg = seg;
+
+ else if (seg_is_cache(seg))
+ setting_seg = first_seg(seg->pool_lv);
+ else
+ return;
log_print(" Chunk size\t\t%s",
- display_size(seg->lv->vg->cmd, pool_seg->chunk_size));
+ display_size(seg->lv->vg->cmd, setting_seg->chunk_size));
- if (pool_seg->cache_metadata_format != CACHE_METADATA_FORMAT_UNSELECTED)
- log_print(" Metadata format\t%u", pool_seg->cache_metadata_format);
+ if (setting_seg->cache_metadata_format != CACHE_METADATA_FORMAT_UNSELECTED)
+ log_print(" Metadata format\t%u", setting_seg->cache_metadata_format);
- if (pool_seg->cache_mode != CACHE_MODE_UNSELECTED)
- log_print(" Mode\t\t%s", get_cache_mode_name(pool_seg));
+ if (setting_seg->cache_mode != CACHE_MODE_UNSELECTED)
+ log_print(" Mode\t\t%s", get_cache_mode_name(setting_seg));
- if (pool_seg->policy_name)
- log_print(" Policy\t\t%s", pool_seg->policy_name);
+ if (setting_seg->policy_name)
+ log_print(" Policy\t\t%s", setting_seg->policy_name);
- if (pool_seg->policy_settings &&
- (n = pool_seg->policy_settings->child))
+ if (setting_seg->policy_settings &&
+ (n = setting_seg->policy_settings->child))
dm_config_write_node(n, _cache_out_line, NULL);
log_print(" ");
5 years, 5 months
master - cache: clean up segment line creation
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=85b4b2f92490a7e12d3...
Commit: 85b4b2f92490a7e12d3aaf67df1db7a0bcc6937e
Parent: e26dacf30a656276afdc36516cb7b330da4ff705
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 5 15:50:37 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Nov 6 11:36:28 2018 -0600
cache: clean up segment line creation
---
device_mapper/libdm-deptree.c | 22 +++++++++++++---------
1 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/device_mapper/libdm-deptree.c b/device_mapper/libdm-deptree.c
index 16858b4..5d03545 100644
--- a/device_mapper/libdm-deptree.c
+++ b/device_mapper/libdm-deptree.c
@@ -2544,7 +2544,7 @@ static int _cache_emit_segment_line(struct dm_task *dmt,
char *params, size_t paramsize)
{
int pos = 0;
- /* unsigned feature_count; */
+ unsigned feature_count;
char data[DM_FORMAT_DEV_BUFSIZE];
char metadata[DM_FORMAT_DEV_BUFSIZE];
char origin[DM_FORMAT_DEV_BUFSIZE];
@@ -2569,19 +2569,23 @@ static int _cache_emit_segment_line(struct dm_task *dmt,
EMIT_PARAMS(pos, " %u", seg->data_block_size);
/* Features */
- /* feature_count = hweight32(seg->flags); */
- /* EMIT_PARAMS(pos, " %u", feature_count); */
+
+ feature_count = 1; /* One of passthrough|writeback|writethrough is always set. */
+
if (seg->flags & DM_CACHE_FEATURE_METADATA2)
- EMIT_PARAMS(pos, " 2 metadata2 ");
- else
- EMIT_PARAMS(pos, " 1 ");
+ feature_count++;
+
+ EMIT_PARAMS(pos, " %u", feature_count);
+
+ if (seg->flags & DM_CACHE_FEATURE_METADATA2)
+ EMIT_PARAMS(pos, " metadata2");
if (seg->flags & DM_CACHE_FEATURE_PASSTHROUGH)
- EMIT_PARAMS(pos, "passthrough");
+ EMIT_PARAMS(pos, " passthrough");
else if (seg->flags & DM_CACHE_FEATURE_WRITEBACK)
- EMIT_PARAMS(pos, "writeback");
+ EMIT_PARAMS(pos, " writeback");
else
- EMIT_PARAMS(pos, "writethrough");
+ EMIT_PARAMS(pos, " writethrough");
/* Cache Policy */
name = seg->policy_name ? : "default";
5 years, 5 months
master - cache: factor getting cache mode
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e26dacf30a656276afd...
Commit: e26dacf30a656276afdc36516cb7b330da4ff705
Parent: f3f3d6066b82523867a7e7cdaa3d64ae73a44b2e
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 5 15:46:07 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Nov 6 11:36:28 2018 -0600
cache: factor getting cache mode
so part can be called separately
---
lib/metadata/cache_manip.c | 67 ++++++++++++++++++++++++++++---------------
1 files changed, 43 insertions(+), 24 deletions(-)
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index 0cf94ae..b4d269d 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -95,32 +95,14 @@ int set_cache_mode(cache_mode_t *mode, const char *cache_mode)
return 1;
}
-int cache_set_cache_mode(struct lv_segment *seg, cache_mode_t mode)
+static cache_mode_t _get_cache_mode_from_config(struct cmd_context *cmd,
+ struct profile *profile,
+ struct logical_volume *lv)
{
- struct cmd_context *cmd = seg->lv->vg->cmd;
- struct profile *profile = seg->lv->profile;
+ cache_mode_t mode;
const char *str;
int id;
- if (seg_is_cache(seg))
- seg = first_seg(seg->pool_lv);
- else if (seg_is_cache_pool(seg)) {
- if (mode == CACHE_MODE_UNSELECTED)
- return 1; /* Defaults only for cache */
- } else {
- log_error(INTERNAL_ERROR "Cannot set cache mode for non cache volume %s.",
- display_lvname(seg->lv));
- return 0;
- }
-
- if (mode != CACHE_MODE_UNSELECTED) {
- seg->cache_mode = mode;
- return 1;
- }
-
- if (seg->cache_mode != CACHE_MODE_UNSELECTED)
- return 1; /* Default already set in cache pool */
-
/* Figure default settings from config/profiles */
id = allocation_cache_mode_CFG;
@@ -131,11 +113,48 @@ int cache_set_cache_mode(struct lv_segment *seg, cache_mode_t mode)
if (!(str = find_config_tree_str(cmd, id, profile))) {
log_error(INTERNAL_ERROR "Cache mode is not determined.");
+ return CACHE_MODE_WRITETHROUGH;
+ }
+
+ if (!(set_cache_mode(&mode, str)))
+ return CACHE_MODE_WRITETHROUGH;
+
+ return mode;
+}
+
+int cache_set_cache_mode(struct lv_segment *seg, cache_mode_t mode)
+{
+ struct cmd_context *cmd = seg->lv->vg->cmd;
+ struct lv_segment *setting_seg;
+
+ /*
+ * Don't set a cache mode on an unused cache pool, the
+ * cache mode will be set when it's attached.
+ */
+ if (seg_is_cache_pool(seg) && (mode == CACHE_MODE_UNSELECTED))
+ return 1;
+
+ if (seg_is_cache_pool(seg))
+ setting_seg = seg;
+
+ else if (seg_is_cache(seg))
+ setting_seg = first_seg(seg->pool_lv);
+
+ else {
+ log_error(INTERNAL_ERROR "Cannot set cache mode for non cache volume %s.",
+ display_lvname(seg->lv));
return 0;
}
- if (!(set_cache_mode(&seg->cache_mode, str)))
- return_0;
+ if (mode != CACHE_MODE_UNSELECTED) {
+ setting_seg->cache_mode = mode;
+ return 1;
+ }
+
+ if (setting_seg->cache_mode != CACHE_MODE_UNSELECTED)
+ return 1;
+
+ setting_seg->cache_mode = _get_cache_mode_from_config(cmd, seg->lv->profile, seg->lv);
return 1;
}
5 years, 5 months
master - cache: factor settings text import export
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f3f3d6066b82523867a...
Commit: f3f3d6066b82523867a7e7cdaa3d64ae73a44b2e
Parent: 8d7075528f0c6e3a0ddeb737c25540683a1946a2
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 5 15:23:23 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Nov 6 11:36:28 2018 -0600
cache: factor settings text import export
Pull out the export/import of settings text so
it can be used later from elsewhere.
---
lib/cache_segtype/cache.c | 130 ++++++++++++++++++++++++++------------------
1 files changed, 77 insertions(+), 53 deletions(-)
diff --git a/lib/cache_segtype/cache.c b/lib/cache_segtype/cache.c
index ab9f942..cb86212 100644
--- a/lib/cache_segtype/cache.c
+++ b/lib/cache_segtype/cache.c
@@ -99,32 +99,16 @@ static void _fix_missing_defaults(struct lv_segment *cpool_seg)
}
}
-static int _cache_pool_text_import(struct lv_segment *seg,
- const struct dm_config_node *sn,
- struct dm_hash_table *pv_hash __attribute__((unused)))
+static int _settings_text_import(struct lv_segment *seg,
+ const struct dm_config_node *sn)
{
- struct logical_volume *data_lv, *meta_lv;
const char *str = NULL;
struct dm_pool *mem = seg->lv->vg->vgmem;
- if (!dm_config_has_node(sn, "data"))
- return SEG_LOG_ERROR("Cache data not specified in");
- if (!(str = dm_config_find_str(sn, "data", NULL)))
- return SEG_LOG_ERROR("Cache data must be a string in");
- if (!(data_lv = find_lv(seg->lv->vg, str)))
- return SEG_LOG_ERROR("Unknown logical volume %s specified for "
- "cache data in", str);
-
- if (!dm_config_has_node(sn, "metadata"))
- return SEG_LOG_ERROR("Cache metadata not specified in");
- if (!(str = dm_config_find_str(sn, "metadata", NULL)))
- return SEG_LOG_ERROR("Cache metadata must be a string in");
- if (!(meta_lv = find_lv(seg->lv->vg, str)))
- return SEG_LOG_ERROR("Unknown logical volume %s specified for "
- "cache metadata in", str);
-
- if (!dm_config_get_uint32(sn, "chunk_size", &seg->chunk_size))
- return SEG_LOG_ERROR("Couldn't read cache chunk_size in");
+ if (dm_config_has_node(sn, "chunk_size")) {
+ if (!dm_config_get_uint32(sn, "chunk_size", &seg->chunk_size))
+ return SEG_LOG_ERROR("Couldn't read cache chunk_size in");
+ }
/*
* Read in features:
@@ -146,16 +130,6 @@ static int _cache_pool_text_import(struct lv_segment *seg,
return SEG_LOG_ERROR("Failed to duplicate policy in");
}
- if (dm_config_has_node(sn, "metadata_format")) {
- if (!dm_config_get_uint32(sn, "metadata_format", &seg->cache_metadata_format) ||
- ((seg->cache_metadata_format != CACHE_METADATA_FORMAT_1) &&
- (seg->cache_metadata_format != CACHE_METADATA_FORMAT_2)))
- return SEG_LOG_ERROR("Unknown cache metadata format %u number in",
- seg->cache_metadata_format);
- if (seg->cache_metadata_format == CACHE_METADATA_FORMAT_2)
- seg->lv->status |= LV_METADATA_FORMAT;
- }
-
/*
* Read in policy args:
* policy_settings {
@@ -184,6 +158,75 @@ static int _cache_pool_text_import(struct lv_segment *seg,
return_0;
}
+ return 1;
+}
+
+static int _settings_text_export(const struct lv_segment *seg,
+ struct formatter *f)
+{
+ if (seg->chunk_size)
+ outf(f, "chunk_size = %" PRIu32, seg->chunk_size);
+
+ if (seg->cache_mode != CACHE_MODE_UNSELECTED) {
+ const char *cache_mode;
+ if (!(cache_mode = cache_mode_num_to_str(seg->cache_mode)))
+ return_0;
+ outf(f, "cache_mode = \"%s\"", cache_mode);
+ }
+
+ if (seg->policy_name) {
+ outf(f, "policy = \"%s\"", seg->policy_name);
+
+ if (seg->policy_settings) {
+ if (strcmp(seg->policy_settings->key, "policy_settings")) {
+ log_error(INTERNAL_ERROR "Incorrect policy_settings tree, %s.",
+ seg->policy_settings->key);
+ return 0;
+ }
+ if (seg->policy_settings->child)
+ out_config_node(f, seg->policy_settings);
+ }
+ }
+
+ return 1;
+}
+
+static int _cache_pool_text_import(struct lv_segment *seg,
+ const struct dm_config_node *sn,
+ struct dm_hash_table *pv_hash __attribute__((unused)))
+{
+ struct logical_volume *data_lv, *meta_lv;
+ const char *str = NULL;
+
+ if (!dm_config_has_node(sn, "data"))
+ return SEG_LOG_ERROR("Cache data not specified in");
+ if (!(str = dm_config_find_str(sn, "data", NULL)))
+ return SEG_LOG_ERROR("Cache data must be a string in");
+ if (!(data_lv = find_lv(seg->lv->vg, str)))
+ return SEG_LOG_ERROR("Unknown logical volume %s specified for "
+ "cache data in", str);
+
+ if (!dm_config_has_node(sn, "metadata"))
+ return SEG_LOG_ERROR("Cache metadata not specified in");
+ if (!(str = dm_config_find_str(sn, "metadata", NULL)))
+ return SEG_LOG_ERROR("Cache metadata must be a string in");
+ if (!(meta_lv = find_lv(seg->lv->vg, str)))
+ return SEG_LOG_ERROR("Unknown logical volume %s specified for "
+ "cache metadata in", str);
+
+ if (dm_config_has_node(sn, "metadata_format")) {
+ if (!dm_config_get_uint32(sn, "metadata_format", &seg->cache_metadata_format) ||
+ ((seg->cache_metadata_format != CACHE_METADATA_FORMAT_1) &&
+ (seg->cache_metadata_format != CACHE_METADATA_FORMAT_2)))
+ return SEG_LOG_ERROR("Unknown cache metadata format %u number in",
+ seg->cache_metadata_format);
+ if (seg->cache_metadata_format == CACHE_METADATA_FORMAT_2)
+ seg->lv->status |= LV_METADATA_FORMAT;
+ }
+
+ if (!_settings_text_import(seg, sn))
+ return_0;
+
if (!attach_pool_data_lv(seg, data_lv))
return_0;
if (!attach_pool_metadata_lv(seg, meta_lv))
@@ -207,11 +250,8 @@ static int _cache_pool_text_import_area_count(const struct dm_config_node *sn,
static int _cache_pool_text_export(const struct lv_segment *seg,
struct formatter *f)
{
- const char *cache_mode;
-
outf(f, "data = \"%s\"", seg_lv(seg, 0)->name);
outf(f, "metadata = \"%s\"", seg->metadata_lv->name);
- outf(f, "chunk_size = %" PRIu32, seg->chunk_size);
switch (seg->cache_metadata_format) {
case CACHE_METADATA_FORMAT_UNSELECTED:
@@ -237,25 +277,9 @@ static int _cache_pool_text_export(const struct lv_segment *seg,
* but not worth to break backward compatibility, by shifting
* content to cache segment
*/
- if (seg->cache_mode != CACHE_MODE_UNSELECTED) {
- if (!(cache_mode = get_cache_mode_name(seg)))
- return_0;
- outf(f, "cache_mode = \"%s\"", cache_mode);
- }
- if (seg->policy_name) {
- outf(f, "policy = \"%s\"", seg->policy_name);
-
- if (seg->policy_settings) {
- if (strcmp(seg->policy_settings->key, "policy_settings")) {
- log_error(INTERNAL_ERROR "Incorrect policy_settings tree, %s.",
- seg->policy_settings->key);
- return 0;
- }
- if (seg->policy_settings->child)
- out_config_node(f, seg->policy_settings);
- }
- }
+ if (!_settings_text_export(seg, f))
+ return_0;
return 1;
}
5 years, 5 months
master - cache: add cache_mode_num_to_str
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8d7075528f0c6e3a0dd...
Commit: 8d7075528f0c6e3a0ddeb737c25540683a1946a2
Parent: a427a935493aa2d92c85f1765aaf714e073d88bc
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 5 14:53:52 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Nov 6 11:36:28 2018 -0600
cache: add cache_mode_num_to_str
Requires only string and number, no specific lv/seg type.
---
lib/metadata/cache_manip.c | 50 ++++++++++++++++++++++++++-----------
lib/metadata/metadata-exported.h | 1 +
2 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index 5ba353c..0cf94ae 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -30,33 +30,53 @@
#define DM_HINT_OVERHEAD_PER_BLOCK 8 /* bytes */
#define DM_MAX_HINT_WIDTH (4+16) /* bytes. FIXME Configurable? */
+const char *cache_mode_num_to_str(cache_mode_t mode)
+{
+ switch (mode) {
+ case CACHE_MODE_WRITETHROUGH:
+ return "writethrough";
+ case CACHE_MODE_WRITEBACK:
+ return "writeback";
+ case CACHE_MODE_PASSTHROUGH:
+ return "passthrough";
+ default:
+ return NULL;
+ }
+}
+
const char *display_cache_mode(const struct lv_segment *seg)
{
- if (seg_is_cache(seg))
- seg = first_seg(seg->pool_lv);
+ const struct lv_segment *setting_seg = NULL;
+ const char *str;
- if (!seg_is_cache_pool(seg) ||
- (seg->cache_mode == CACHE_MODE_UNSELECTED))
+ if (seg_is_cache_pool(seg))
+ setting_seg = seg;
+
+ else if (seg_is_cache(seg))
+ setting_seg = first_seg(seg->pool_lv);
+
+ if (!setting_seg || (setting_seg->cache_mode == CACHE_MODE_UNSELECTED))
return "";
- return get_cache_mode_name(seg);
-}
+ if (!(str = cache_mode_num_to_str(setting_seg->cache_mode))) {
+ log_error(INTERNAL_ERROR "Cache pool %s has undefined cache mode, using writethrough instead.",
+ display_lvname(seg->lv));
+ str = "writethrough";
+ }
+ return str;
+}
const char *get_cache_mode_name(const struct lv_segment *pool_seg)
{
- switch (pool_seg->cache_mode) {
- default:
+ const char *str;
+
+ if (!(str = cache_mode_num_to_str(pool_seg->cache_mode))) {
log_error(INTERNAL_ERROR "Cache pool %s has undefined cache mode, using writethrough instead.",
display_lvname(pool_seg->lv));
- /* Fall through */
- case CACHE_MODE_WRITETHROUGH:
- return "writethrough";
- case CACHE_MODE_WRITEBACK:
- return "writeback";
- case CACHE_MODE_PASSTHROUGH:
- return "passthrough";
+ str = "writethrough";
}
+ return str;
}
int set_cache_mode(cache_mode_t *mode, const char *cache_mode)
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 840f623..76c164b 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -1216,6 +1216,7 @@ struct lv_status_cache {
dm_percent_t dirty_usage;
};
+const char *cache_mode_num_to_str(cache_mode_t mode);
const char *display_cache_mode(const struct lv_segment *seg);
const char *get_cache_mode_name(const struct lv_segment *pool_seg);
int set_cache_mode(cache_mode_t *mode, const char *cache_mode);
5 years, 5 months
master - tests: fix shell quoting
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a427a935493aa2d92c8...
Commit: a427a935493aa2d92c85f1765aaf714e073d88bc
Parent: ad0268e239a2d8445813733b70ea54a546f8b627
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Nov 6 17:26:15 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Nov 6 17:26:15 2018 +0100
tests: fix shell quoting
---
test/shell/pvscan-autoactivate.sh | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/test/shell/pvscan-autoactivate.sh b/test/shell/pvscan-autoactivate.sh
index b6db47a..c2fc36a 100644
--- a/test/shell/pvscan-autoactivate.sh
+++ b/test/shell/pvscan-autoactivate.sh
@@ -20,7 +20,7 @@ ONLINEDIR="$RUNDIR/lvm/pvs_online"
_clear_online() {
# wait till udev is finished
aux udev_wait
- rm -f "$ONLINEDIR/*"
+ rm -f "$ONLINEDIR"/*
test -n "${1+varset}" || touch "$ONLINEDIR/foo"
}
@@ -62,9 +62,9 @@ lvchange -an $vg1
_clear_online
-pvscan -vvvv --cache -aay "$dev1"
+pvscan --cache -aay "$dev1"
check lv_field $vg1/$lv1 lv_active ""
-pvscan -vvvv --cache -aay "$dev2"
+pvscan --cache -aay "$dev2"
check lv_field $vg1/$lv1 lv_active "active"
lvchange -an $vg1
5 years, 5 months
master - tests: add wait for udev
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ad0268e239a2d844581...
Commit: ad0268e239a2d8445813733b70ea54a546f8b627
Parent: a1b1b3dbb620dd51123387828b4b936a47814853
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Nov 6 15:01:52 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Nov 6 15:05:44 2018 +0100
tests: add wait for udev
Since the test is currently directly working with live directory,
which can be getting updates from system's udev - add wait
for settling so removal of all known PVs happens after that.
But still this has major influce on behavior of running system,
so the test should never be executed on a user used box.
---
test/shell/pvscan-autoactivate.sh | 59 +++++++++++++++---------------------
1 files changed, 25 insertions(+), 34 deletions(-)
diff --git a/test/shell/pvscan-autoactivate.sh b/test/shell/pvscan-autoactivate.sh
index 5c5a3c6..b6db47a 100644
--- a/test/shell/pvscan-autoactivate.sh
+++ b/test/shell/pvscan-autoactivate.sh
@@ -12,6 +12,18 @@
SKIP_WITH_LVMPOLLD=1
+RUNDIR="/run"
+test -d "$RUNDIR" || RUNDIR="/var/run"
+ONLINEDIR="$RUNDIR/lvm/pvs_online"
+
+# FIXME: kills logic for running system
+_clear_online() {
+ # wait till udev is finished
+ aux udev_wait
+ rm -f "$ONLINEDIR/*"
+ test -n "${1+varset}" || touch "$ONLINEDIR/foo"
+}
+
. lib/inittest
aux prepare_pvs 2
@@ -19,13 +31,9 @@ aux prepare_pvs 2
vgcreate $vg1 "$dev1" "$dev2"
lvcreate -n $lv1 -l 4 -a n $vg1
-RUNDIR="/run"
-test -d "$RUNDIR" || RUNDIR="/var/run"
-
# the first pvscan scans all devs
-# FIXME: kills logic for running system
-rm -rf "$RUNDIR/lvm/pvs_online"
-mkdir "$RUNDIR/lvm/pvs_online" || true
+test -d "$ONLINEDIR" || mkdir "$ONLINEDIR"
+_clear_online nofoo
pvscan --cache -aay
check lv_field $vg1/$lv1 lv_active "active"
@@ -34,8 +42,7 @@ lvchange -an $vg1
# the first pvscan scans all devs even when
# only one device is specified
-# FIXME: kills logic for running system
-rm "$RUNDIR/lvm/pvs_online/*"
+_clear_online nofoo
pvscan --cache -aay "$dev1"
check lv_field $vg1/$lv1 lv_active "active"
@@ -43,10 +50,7 @@ lvchange -an $vg1
# touch foo to disable first-pvscan case,
# then check pvscan with no args scans all
-
-# FIXME: kills logic for running system
-rm "$RUNDIR/lvm/pvs_online/*"
-touch "$RUNDIR/lvm/pvs_online/foo"
+_clear_online
pvscan --cache -aay
check lv_field $vg1/$lv1 lv_active "active"
@@ -56,13 +60,11 @@ lvchange -an $vg1
# then check that vg is activated only after
# both devs appear separately
-# FIXME: kills logic for running system
-rm "$RUNDIR/lvm/pvs_online/*"
-touch "$RUNDIR/lvm/pvs_online/foo"
+_clear_online
-pvscan --cache -aay "$dev1"
+pvscan -vvvv --cache -aay "$dev1"
check lv_field $vg1/$lv1 lv_active ""
-pvscan --cache -aay "$dev2"
+pvscan -vvvv --cache -aay "$dev2"
check lv_field $vg1/$lv1 lv_active "active"
lvchange -an $vg1
@@ -70,9 +72,7 @@ lvchange -an $vg1
# then check that vg is activated when both
# devs appear together
-# FIXME: kills logic for running system
-rm "$RUNDIR/lvm/pvs_online/*"
-touch "$RUNDIR/lvm/pvs_online/foo"
+_clear_online
pvscan --cache -aay "$dev1" "$dev2"
check lv_field $vg1/$lv1 lv_active "active"
@@ -92,9 +92,7 @@ lvcreate -n $lv1 -l 4 -a n $vg1
# touch foo to disable first-pvscan case,
# test case where dev with metadata appears first
-# FIXME: kills logic for running system
-rm "$RUNDIR/lvm/pvs_online/*"
-touch "$RUNDIR/lvm/pvs_online/foo"
+_clear_online
pvscan --cache -aay "$dev2"
check lv_field $vg1/$lv1 lv_active ""
@@ -106,9 +104,7 @@ lvchange -an $vg1
# test case where dev without metadata
# appears first which triggers scanning all
-# FIXME: kills logic for running system
-rm "$RUNDIR/lvm/pvs_online/*"
-touch "$RUNDIR/lvm/pvs_online/foo"
+_clear_online
pvscan --cache -aay "$dev1"
check lv_field $vg1/$lv1 lv_active "active"
@@ -119,8 +115,7 @@ lvchange -an $vg1
# dev without metadata is scanned, but
# first-pvscan case scans all devs
-# FIXME: kills logic for running system
-rm "$RUNDIR/lvm/pvs_online/*"
+_clear_online nofoo
pvscan --cache -aay "$dev1"
check lv_field $vg1/$lv1 lv_active "active"
@@ -130,9 +125,7 @@ lvchange -an $vg1
# is online without the -aay option to
# activate until after they are online
-# FIXME: kills logic for running system
-rm "$RUNDIR/lvm/pvs_online/*"
-touch "$RUNDIR/lvm/pvs_online/foo"
+_clear_online
pvscan --cache "$dev1"
check lv_field $vg1/$lv1 lv_active ""
@@ -144,9 +137,7 @@ lvchange -an $vg1
# like previous
-# FIXME: kills logic for running system
-rm "$RUNDIR/lvm/pvs_online/*"
-touch "$RUNDIR/lvm/pvs_online/foo"
+_clear_online
pvscan --cache "$dev1"
check lv_field $vg1/$lv1 lv_active ""
5 years, 5 months
master - pvscan: add error checking for write of online files
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a1b1b3dbb620dd51123...
Commit: a1b1b3dbb620dd51123387828b4b936a47814853
Parent: 9a6f0e64f92bfb9f8c7fd4e5692a8107eba50034
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Nov 6 15:04:35 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Nov 6 15:05:44 2018 +0100
pvscan: add error checking for write of online files
When there is any write failure during writting file,
report this upward as error and fail command instead
of continuing futher.
---
tools/pvscan.c | 37 +++++++++++++++++++++++++------------
1 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 85b0e04..0f7603e 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -256,40 +256,52 @@ static void _online_pvid_files_remove(void)
log_sys_debug("closedir", _pvs_online_dir);
}
-static void _online_pvid_file_create(struct device *dev)
+static int _online_pvid_file_create(struct device *dev)
{
char path[PATH_MAX];
char buf[32];
int major, minor;
int fd;
int rv;
-
- memset(path, 0, sizeof(path));
+ int len;
major = (int)MAJOR(dev->dev);
minor = (int)MINOR(dev->dev);
- snprintf(path, sizeof(path), "%s/%s", _pvs_online_dir, dev->pvid);
+ if (dm_snprintf(path, sizeof(path), "%s/%s", _pvs_online_dir, dev->pvid) < 0) {
+ log_error("Path %s/%s is too long.", _pvs_online_dir, dev->pvid);
+ return 0;
+ }
- snprintf(buf, sizeof(buf), "%d:%d\n", major, minor);
+ if ((len = dm_snprintf(buf, sizeof(buf), "%d:%d\n", major, minor)) < 0) {
+ log_error("Device %d:%d is too long.", major, minor);
+ return 0;
+ }
log_debug("Create pv online: %s %d:%d %s", path, major, minor, dev_name(dev));
fd = open(path, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
if (fd < 0) {
- log_warn("Failed to open %s: %d", path, errno);
- return;
+ log_error("Failed to open %s: %d", path, errno);
+ return 0;
}
- rv = write(fd, buf, strlen(buf));
- if (!rv || rv < 0)
- log_warn("Failed to write fd %d buf %s dev %s to %s: %d",
- fd, buf, dev_name(dev), path, errno);
+ while (len > 0) {
+ rv = write(fd, buf, len);
+ if (rv < 0) {
+ log_error("Failed to write fd %d buf %s dev %s to %s: %d",
+ fd, buf, dev_name(dev), path, errno);
+ return 0;
+ }
+ len -= rv;
+ }
/* We don't care about syncing, these files are not even persistent. */
if (close(fd))
log_sys_debug("close", path);
+
+ return 1;
}
static int _online_pvid_file_exists(const char *pvid)
@@ -364,7 +376,8 @@ static int _online_pv_found(struct cmd_context *cmd,
* Create file named for pvid to record this PV is online.
*/
- _online_pvid_file_create(dev);
+ if (!_online_pvid_file_create(dev))
+ return_0;
if (!vg || !found_vgnames)
return 1;
5 years, 5 months
master - debug: missing backtrace
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9a6f0e64f92bfb9f8c7...
Commit: 9a6f0e64f92bfb9f8c7fd4e5692a8107eba50034
Parent: 9d9979963ffa5ec72a188e123a89eeea8ea666c5
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 2 22:19:26 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 5 17:25:11 2018 +0100
debug: missing backtrace
---
lib/cache/lvmcache.c | 3 ++-
lib/device/bcache.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index e681ed8..d35b366 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -1848,7 +1848,8 @@ void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset)
if (retain_orphans) {
struct format_type *fmt;
- lvmcache_init(cmd);
+ if (!lvmcache_init(cmd))
+ stack;
dm_list_iterate_items(fmt, &cmd->formats) {
if (!lvmcache_add_orphan_vginfo(fmt->orphan_vg_name, fmt))
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index 0183079..62970ef 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -1004,7 +1004,8 @@ void bcache_destroy(struct bcache *cache)
if (cache->nr_locked)
log_warn("some blocks are still locked");
- bcache_flush(cache);
+ if (!bcache_flush(cache))
+ stack;
_wait_all(cache);
_exit_free_list(cache);
radix_tree_destroy(cache->rtree);
5 years, 5 months