diff options
Diffstat (limited to 'lib/format_text/export.c')
-rw-r--r-- | lib/format_text/export.c | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/lib/format_text/export.c b/lib/format_text/export.c index 8ddfa85..70c1aa6 100644 --- a/lib/format_text/export.c +++ b/lib/format_text/export.c @@ -27,6 +27,7 @@ #include <sys/utsname.h> struct formatter; +__attribute__((format(printf, 3, 0))) typedef int (*out_with_comment_fn) (struct formatter * f, const char *comment, const char *fmt, va_list ap); typedef int (*nl_fn) (struct formatter * f); @@ -147,6 +148,7 @@ static int _nl_raw(struct formatter *f) } #define COMMENT_TAB 6 +__attribute__((format(printf, 3, 0))) static int _out_with_comment_file(struct formatter *f, const char *comment, const char *fmt, va_list ap) { @@ -182,6 +184,7 @@ static int _out_with_comment_file(struct formatter *f, const char *comment, return 1; } +__attribute__((format(printf, 3, 0))) static int _out_with_comment_raw(struct formatter *f, const char *comment __attribute__((unused)), const char *fmt, va_list ap) @@ -316,9 +319,9 @@ static int _out_line(const char *line, void *_f) { return out_text(f, "%s", line); } -int out_config_node(struct formatter *f, const struct config_node *cn) +int out_config_node(struct formatter *f, const struct dm_config_node *cn) { - return write_config_node(cn, _out_line, f); + return dm_config_write_node(cn, _out_line, f); } static int _print_header(struct formatter *f, @@ -334,12 +337,12 @@ static int _print_header(struct formatter *f, outf(f, FORMAT_VERSION_FIELD " = %d", FORMAT_VERSION_VALUE); outnl(f); - if (!(buf = alloca(escaped_len(desc)))) { + if (!(buf = alloca(dm_escaped_len(desc)))) { log_error("temporary stack allocation for description" "string failed"); return 0; } - outf(f, "description = \"%s\"", escape_double_quotes(buf, desc)); + outf(f, "description = \"%s\"", dm_escape_double_quotes(buf, desc)); outnl(f); outf(f, "creation_host = \"%s\"\t# %s %s %s %s %s", _utsname.nodename, _utsname.sysname, _utsname.nodename, _utsname.release, @@ -392,6 +395,9 @@ static int _print_vg(struct formatter *f, struct volume_group *vg) outf(f, "seqno = %u", vg->seqno); + if (vg->fid && vg->fid->fmt) + outf(f, "format = \"%s\" # informational", vg->fid->fmt->name); + if (!_print_flag_config(f, vg->status, VG_FLAGS)) return_0; @@ -462,14 +468,14 @@ static int _print_pvs(struct formatter *f, struct volume_group *vg) outf(f, "id = \"%s\"", buffer); - if (!(buf = alloca(escaped_len(pv_dev_name(pv))))) { + if (!(buf = alloca(dm_escaped_len(pv_dev_name(pv))))) { log_error("temporary stack allocation for device name" "string failed"); return 0; } outhint(f, "device = \"%s\"", - escape_double_quotes(buf, pv_dev_name(pv))); + dm_escape_double_quotes(buf, pv_dev_name(pv))); outnl(f); if (!_print_flag_config(f, pv->status, PV_FLAGS)) @@ -541,10 +547,25 @@ int out_areas(struct formatter *f, const struct lv_segment *seg, (s == seg->area_count - 1) ? "" : ","); break; case AREA_LV: - outf(f, "\"%s\", %u%s", - seg_lv(seg, s)->name, - seg_le(seg, s), + if (!(seg->status & RAID)) { + outf(f, "\"%s\", %u%s", + seg_lv(seg, s)->name, + seg_le(seg, s), + (s == seg->area_count - 1) ? "" : ","); + continue; + } + + /* RAID devices are laid-out in metadata/data pairs */ + if (!(seg_lv(seg, s)->status & RAID_IMAGE) || + !(seg_metalv(seg, s)->status & RAID_META)) { + log_error("RAID segment has non-RAID areas"); + return 0; + } + + outf(f, "\"%s\", \"%s\"%s", + seg_metalv(seg, s)->name, seg_lv(seg, s)->name, (s == seg->area_count - 1) ? "" : ","); + break; case AREA_UNASSIGNED: return 0; @@ -561,6 +582,8 @@ static int _print_lv(struct formatter *f, struct logical_volume *lv) struct lv_segment *seg; char buffer[4096]; int seg_count; + struct tm *local_tm; + time_t ts; outnl(f); outf(f, "%s {", lv->name); @@ -578,6 +601,19 @@ static int _print_lv(struct formatter *f, struct logical_volume *lv) if (!_out_tags(f, &lv->tags)) return_0; + if (lv->timestamp) { + ts = (time_t)lv->timestamp; + strncpy(buffer, "# ", sizeof(buffer)); + if (!(local_tm = localtime(&ts)) || + !strftime(buffer + 2, sizeof(buffer) - 2, + "%Y-%m-%d %T %z", local_tm)) + buffer[0] = 0; + + outf(f, "creation_host = \"%s\"", lv->hostname); + outfc(f, buffer, "creation_time = %" PRIu64, + lv->timestamp); + } + if (lv->alloc != ALLOC_INHERIT) outf(f, "allocation_policy = \"%s\"", get_alloc_string(lv->alloc)); @@ -724,11 +760,15 @@ static int _text_vg_export(struct formatter *f, r = 1; out: - if (f->mem) + if (f->mem) { dm_pool_destroy(f->mem); + f->mem = NULL; + } - if (f->pv_names) + if (f->pv_names) { dm_hash_destroy(f->pv_names); + f->pv_names = NULL; + } return r; } @@ -757,10 +797,10 @@ int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp) } /* Returns amount of buffer used incl. terminating NUL */ -int text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf) +size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf) { struct formatter *f; - int r = 0; + size_t r = 0; _init(); @@ -791,7 +831,7 @@ int text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf) return r; } -int export_vg_to_buffer(struct volume_group *vg, char **buf) +size_t export_vg_to_buffer(struct volume_group *vg, char **buf) { return text_vg_export_raw(vg, "", buf); } |