]> sourceware.org Git - lvm2.git/commitdiff
cachevol: rename converted LV to _cvol
authorZdenek Kabelac <zkabelac@redhat.com>
Sat, 12 Oct 2019 21:37:17 +0000 (23:37 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Mon, 14 Oct 2019 13:15:12 +0000 (15:15 +0200)
When converting existing public LV to internally used
'CacheVol' LV - rename LV to LV_cvol.

When splitting CacheVol, remove _cvol suffix.

WHATS_NEW
tools/lvconvert.c

index 6405686eb9b76d011dfb2b4ac1b5e78aefd6ff29..6d1700a21560e5b8151c071fdd586674e233722c 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.03.06 - 
 ================================
+  Rename LV converted to cachevol to use _cvol suffix.
   Use normal LVs for wiping of cachevols.
   Reload cleanered cache DM only with cleaner policy.
   Fix cmd return when zering of cachevol fails.
index 885380cf841485309af9d1ebeaf1856a46948d96..14663e8df3a1bce629741d3a35ac8d8de96e57e7 100644 (file)
@@ -1840,6 +1840,8 @@ static int _lvconvert_split_and_keep_cachevol(struct cmd_context *cmd,
                                   struct logical_volume *lv,
                                   struct logical_volume *lv_fast)
 {
+       char cvol_name[NAME_LEN];
+       char *c;
        struct lv_segment *cache_seg = first_seg(lv);
        int cache_mode = cache_seg->cache_mode;
        int noflush = 0;
@@ -1879,6 +1881,25 @@ static int _lvconvert_split_and_keep_cachevol(struct cmd_context *cmd,
        if (!lv_detach_cache_vol(lv, noflush))
                return_0;
 
+       /* Cut off suffix _cvol */
+       if (!dm_strncpy(cvol_name, lv_fast->name, sizeof(cvol_name)) ||
+           !(c = strstr(cvol_name, "_cvol"))) {
+               /* likely older instance of metadata */
+               log_debug("LV %s has no suffix for cachevol (skipping rename).",
+                         display_lvname(lv_fast));
+       } else {
+               *c = 0;
+               /* If the name is in use, generate new lvol%d */
+               if (lv_name_is_used_in_vg(lv->vg, cvol_name, NULL) &&
+                   !generate_lv_name(lv->vg, "lvol%d", cvol_name, sizeof(cvol_name))) {
+                       log_error("Failed to generate unique name for unused logical volume.");
+                       return 0;
+               }
+
+               if (!lv_rename_update(cmd, lv_fast, cvol_name, 0))
+                       return_0;
+       }
+
        if (!vg_write(lv->vg) || !vg_commit(lv->vg))
                return_0;
 
@@ -4193,6 +4214,7 @@ static int _lvconvert_cachevol_attach_single(struct cmd_context *cmd,
        struct volume_group *vg = lv->vg;
        struct logical_volume *cachevol_lv;
        const char *cachevol_name;
+       char cvol_name[NAME_LEN];
 
        if (!(cachevol_name = arg_str_value(cmd, cachevol_ARG, NULL)))
                goto_out;
@@ -4238,6 +4260,13 @@ static int _lvconvert_cachevol_attach_single(struct cmd_context *cmd,
                goto_out;
 
        /* Attach the cache to the main LV. */
+       if (dm_snprintf(cvol_name, sizeof(cvol_name), "%s_cvol", cachevol_lv->name) < 0) {
+               log_error("Can't prepare new metadata name for %s.", display_lvname(cachevol_lv));
+               return 0;
+       }
+       if (!lv_rename_update(cmd, cachevol_lv, cvol_name, 0))
+               return_0;
+
        cachevol_lv->status |= LV_CACHE_VOL;
        if (!_cache_vol_attach(cmd, lv, cachevol_lv))
                goto_out;
This page took 0.054298 seconds and 5 git commands to generate.