diff --git a/lib/format_text/import_vsn1.c b/lib/format_text/import_vsn1.c index 560ea596c..33cd74b1d 100644 --- a/lib/format_text/import_vsn1.c +++ b/lib/format_text/import_vsn1.c @@ -633,7 +633,8 @@ static int _read_lvnames(struct cmd_context *cmd, if (!link_lv_to_vg(vg, lv)) return_0; - if (!(lv->name = dm_pool_strdup(mem, lvn->key))) + if (!(str = dm_pool_strdup(mem, lvn->key)) || + !lv_set_name(lv, str)) return_0; log_debug_metadata("Importing logical volume %s.", lv->name); diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c index 6760947a6..a80934199 100644 --- a/lib/metadata/lv.c +++ b/lib/metadata/lv.c @@ -1577,6 +1577,13 @@ int lv_set_creation(struct logical_volume *lv, return 1; } +int lv_set_name(struct logical_volume *lv, const char *lv_name) +{ + lv->name = lv_name; /* NULL -> LV is removed from tree */ + + return 1; +} + static char *_time_dup(struct cmd_context *cmd, struct dm_pool *mem, time_t ts, int iso_mode) { diff --git a/lib/metadata/lv.h b/lib/metadata/lv.h index 616df1cbf..89a4a2dbd 100644 --- a/lib/metadata/lv.h +++ b/lib/metadata/lv.h @@ -153,6 +153,7 @@ char *lvseg_kernel_discards_dup(struct dm_pool *mem, const struct lv_segment *se /* LV modification functions */ int lv_set_creation(struct logical_volume *lv, const char *hostname, uint64_t timestamp); +int lv_set_name(struct logical_volume *lv, const char *lv_name); int lv_active_change(struct cmd_context *cmd, struct logical_volume *lv, enum activation_change activate); diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 8e3944871..550ec99c5 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -4654,7 +4654,8 @@ static int _rename_single_lv(struct logical_volume *lv, char *new_name) return 0; } - lv->name = new_name; + if (!lv_set_name(lv, new_name)) + return_0; return 1; } @@ -4877,7 +4878,8 @@ int lv_rename_update(struct cmd_context *cmd, struct logical_volume *lv, return_0; /* rename main LV */ - lv->name = lv_names.new; + if (!lv_set_name(lv, lv_names.new)) + return_0; if (lv_is_cow(lv)) lv = origin_from_cow(lv); @@ -7307,6 +7309,7 @@ struct logical_volume *lv_create_empty(const char *name, struct format_instance *fi = vg->fid; struct logical_volume *lv; char dname[NAME_LEN]; + const char *lv_name; int historical; if (strstr(name, "%d") && @@ -7328,7 +7331,11 @@ struct logical_volume *lv_create_empty(const char *name, if (!(lv = alloc_lv(vg->vgmem))) return_NULL; - if (!(lv->name = dm_pool_strdup(vg->vgmem, name))) + if (!link_lv_to_vg(vg, lv)) + goto_bad; + + if (!(lv_name = dm_pool_strdup(vg->vgmem, name)) || + !lv_set_name(lv, lv_name)) goto_bad; lv->status = status; @@ -7342,9 +7349,6 @@ struct logical_volume *lv_create_empty(const char *name, if (lvid) lv->lvid = *lvid; - if (!link_lv_to_vg(vg, lv)) - goto_bad; - if (!lv_set_creation(lv, NULL, 0)) goto_bad; diff --git a/lib/metadata/vdo_manip.c b/lib/metadata/vdo_manip.c index 291a96c3e..0f50b160b 100644 --- a/lib/metadata/vdo_manip.c +++ b/lib/metadata/vdo_manip.c @@ -544,8 +544,10 @@ struct logical_volume *convert_vdo_lv(struct logical_volume *lv, return_NULL; /* Also swap naming, so the passed in LV keeps the passed-in name */ - vdo_lv->name = lv->name; - lv->name = lvc.lv_name; + tmp_lv.name = lv->name; + lv_set_name(lv, NULL); + lv_set_name(vdo_lv, tmp_lv.name); + lv_set_name(lv, lvc.lv_name); /* Swap segment referencing */ if (!remove_seg_from_segs_using_this_lv(lv, first_seg(lv)))