]> sourceware.org Git - lvm2.git/commitdiff
cleanup: use NAME_LEN
authorZdenek Kabelac <zkabelac@redhat.com>
Thu, 5 Nov 2015 10:58:03 +0000 (11:58 +0100)
committerZdenek Kabelac <zkabelac@redhat.com>
Mon, 9 Nov 2015 09:22:51 +0000 (10:22 +0100)
Let's have instant check for max name len when creating
subLV name.

lib/metadata/lv_manip.c

index 48f470ea007a3a563db373e702df9474f2c03a49..fbb53229a858268e64d7f19e679dcf5ea4ef1192 100644 (file)
@@ -3718,8 +3718,7 @@ static int _lv_insert_empty_sublvs(struct logical_volume *lv,
        uint32_t i;
        uint64_t sub_lv_status = 0;
        const char *layer_name;
-       size_t len = strlen(lv->name) + 32;
-       char img_name[len];
+       char img_name[NAME_LEN];
        struct lv_segment *mapseg;
 
        if (lv->le_count || !dm_list_empty(&lv->segments)) {
@@ -3745,7 +3744,8 @@ static int _lv_insert_empty_sublvs(struct logical_volume *lv,
        if (!(mapseg = alloc_lv_segment(segtype, lv, 0, 0, lv->status,
                                        stripe_size, NULL,
                                        devices, 0, 0, region_size, 0, NULL))) {
-               log_error("Failed to create mapping segment for %s", lv->name);
+               log_error("Failed to create mapping segment for %s.",
+                         display_lvname(lv));
                return 0;
        }
 
@@ -3755,19 +3755,19 @@ static int _lv_insert_empty_sublvs(struct logical_volume *lv,
        for (i = 0; i < devices; i++) {
                /* Data LVs */
                if (devices > 1) {
-                       if (dm_snprintf(img_name, len, "%s_%s_%u",
+                       if (dm_snprintf(img_name, sizeof(img_name), "%s_%s_%u",
                                        lv->name, layer_name, i) < 0)
-                               return_0;
+                               goto_bad;
                } else {
-                       if (dm_snprintf(img_name, len, "%s_%s",
+                       if (dm_snprintf(img_name, sizeof(img_name), "%s_%s",
                                        lv->name, layer_name) < 0)
-                               return_0;
+                               goto_bad;
                }
 
                /* FIXME Should use ALLOC_INHERIT here and inherit from parent LV */
                if (!(sub_lv = lv_create_empty(img_name, NULL,
-                                        LVM_READ | LVM_WRITE,
-                                        lv->alloc, lv->vg)))
+                                              LVM_READ | LVM_WRITE,
+                                              lv->alloc, lv->vg)))
                        return_0;
 
                if (!set_lv_segment_area_lv(mapseg, i, sub_lv, 0, sub_lv_status))
@@ -3775,24 +3775,29 @@ static int _lv_insert_empty_sublvs(struct logical_volume *lv,
 
                /* Metadata LVs for raid */
                if (segtype_is_raid(segtype)) {
-                       if (dm_snprintf(img_name, len, "%s_rmeta_%u", lv->name, i) < 0)
+                       if (dm_snprintf(img_name, sizeof(img_name), "%s_rmeta_%u",
+                                       lv->name, i) < 0)
+                               goto_bad;
+                       /* FIXME Should use ALLOC_INHERIT here and inherit from parent LV */
+                       if (!(sub_lv = lv_create_empty(img_name, NULL,
+                                                      LVM_READ | LVM_WRITE,
+                                                      lv->alloc, lv->vg)))
                                return_0;
-               } else
-                       continue;
 
-               /* FIXME Should use ALLOC_INHERIT here and inherit from parent LV */
-               if (!(sub_lv = lv_create_empty(img_name, NULL,
-                                              LVM_READ | LVM_WRITE,
-                                              lv->alloc, lv->vg)))
-                       return_0;
-
-               if (!set_lv_segment_area_lv(mapseg, i, sub_lv, 0, RAID_META))
+                       if (!set_lv_segment_area_lv(mapseg, i, sub_lv, 0, RAID_META))
                                return_0;
+               }
        }
 
        dm_list_add(&lv->segments, &mapseg->list);
 
        return 1;
+
+bad:
+       log_error("Failed to create sub LV name for LV %s.",
+                 display_lvname(lv));
+
+       return 0;
 }
 
 static int _lv_extend_layered_lv(struct alloc_handle *ah,
@@ -3880,8 +3885,8 @@ static int _lv_extend_layered_lv(struct alloc_handle *ah,
                                return 0;
                        }
 
-                       log_verbose("Clearing metadata area of %s/%s",
-                                   meta_lv->vg->name, meta_lv->name);
+                       log_verbose("Clearing metadata area of %s",
+                                   display_lvname(meta_lv));
                        /*
                         * Rather than wiping meta_lv->size, we can simply
                         * wipe '1' to remove the superblock of any previous
This page took 0.038706 seconds and 5 git commands to generate.