summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2014-11-02 18:36:41 +0100
committerZdenek Kabelac <zkabelac@redhat.com>2014-11-03 14:19:33 +0100
commitd2e9802ba7eb48af8d78cee2420897201d57c406 (patch)
treed723b91cb6c29f89e181f4d754b1dc621f6a4e6f
parent0b7335f84717743bf9c3f9ea9cafff279dff8672 (diff)
downloadlvm2-d2e9802ba7eb48af8d78cee2420897201d57c406.tar.gz
cache: add wipe_cache_pool
Add function for wiping cache pool volume. Only unused cache-pool could be wiped.
-rw-r--r--lib/metadata/cache_manip.c41
-rw-r--r--lib/metadata/metadata-exported.h1
2 files changed, 42 insertions, 0 deletions
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index e59a32f5e..bff64a378 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -369,3 +369,44 @@ int lv_is_cache_origin(const struct logical_volume *lv)
seg = get_only_segment_using_this_lv(lv);
return seg && lv_is_cache(seg->lv) && (seg_lv(seg, 0) == lv);
}
+
+/*
+ * Wipe cache pool metadata area before use.
+ *
+ * Activates metadata volume as 'cache-pool' so regular wiping
+ * of existing visible volume may proceed.
+ */
+int wipe_cache_pool(struct logical_volume *cache_pool_lv)
+{
+ int r;
+
+ /* Only unused cache-pool could be activated and wiped */
+ if (!lv_is_cache_pool(cache_pool_lv) ||
+ !dm_list_empty(&cache_pool_lv->segs_using_this_lv)) {
+ log_error(INTERNAL_ERROR "Failed to wipe cache pool for volume %s.",
+ display_lvname(cache_pool_lv));
+ return 0;
+ }
+
+ cache_pool_lv->status |= LV_TEMPORARY;
+ if (!activate_lv_local(cache_pool_lv->vg->cmd, cache_pool_lv)) {
+ log_error("Aborting. Failed to activate cache pool %s.",
+ display_lvname(cache_pool_lv));
+ return 0;
+ }
+ cache_pool_lv->status &= ~LV_TEMPORARY;
+ if (!(r = wipe_lv(cache_pool_lv, (struct wipe_params) { .do_zero = 1 }))) {
+ log_error("Aborting. Failed to wipe cache pool %s.",
+ display_lvname(cache_pool_lv));
+ /* Delay return of error after deactivation */
+ }
+
+ /* Deactivate cleared cache-pool metadata */
+ if (!deactivate_lv(cache_pool_lv->vg->cmd, cache_pool_lv)) {
+ log_error("Aborting. Could not deactivate cache pool %s.",
+ display_lvname(cache_pool_lv));
+ r = 0;
+ }
+
+ return r;
+}
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 013da1653..723a9c13f 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -1099,6 +1099,7 @@ struct logical_volume *lv_cache_create(struct logical_volume *pool,
struct logical_volume *origin);
int lv_cache_remove(struct logical_volume *cache_lv);
int get_cache_mode(const char *str, uint32_t *flags);
+int wipe_cache_pool(struct logical_volume *cache_pool_lv);
/* -- metadata/cache_manip.c */
struct cmd_vg *cmd_vg_add(struct dm_pool *mem, struct dm_list *cmd_vgs,