From 85028e021c988ecbeb158c2f8a6be6b38fa2e582 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 4 Dec 2001 14:14:07 +0000 Subject: [PATCH] o sync --- lib/format_text/import-export.c | 153 +++++++++++++++++++++++++++++++- lib/format_text/sample.vg | 74 +++++++++------ 2 files changed, 197 insertions(+), 30 deletions(-) diff --git a/lib/format_text/import-export.c b/lib/format_text/import-export.c index ffeacddbb..a6082579e 100644 --- a/lib/format_text/import-export.c +++ b/lib/format_text/import-export.c @@ -5,6 +5,139 @@ */ #include "text-rep.h" +#include "metadata.h" +#include "log.h" + +#include + +struct flag { + int mask; + char *description; +}; + +static struct flag _vg_flags[] = { + {ACTIVE, "ACTIVE"}, + {EXPORTED_VG, "EXPORTED"}, + {EXTENDABLE_VG, "EXTENDABLE"}, + {CLUSTERED, "CLUSTERED"}, + {SHARED, "SHARED"}, + {0, NULL} +}; + +static struct flag _pv_flags[] = { + {ACTIVE, "ACTIVE"}, + {ALLOCATED_PV, "ALLOCATED"}, + {0, NULL} +}; + +static struct flag _lv_flags[] = { + {ACTIVE, "ACTIVE"}, + {READ, "READ"}, + {WRITE, "WRITE"}, + {ALLOC_SIMPLE, "ALLOC_SIMPLE"}, + {ALLOC_STRICT, "ALLOC_STRICT"}, + {ALLOC_CONTIGUOUS, "ALLOC_CONTIGUOUS"}, + {SNAPSHOT, "SNASHOT"}, + {SNAPSHOT_ORG, "SNAPSHOT_ORIGIN"}, + {0, NULL} +}; + +static void _print_flags(uint32_t status, struct flag *flags, FILE *fp) +{ + int f, first = 1; + + fprintf(fp, "["); + for (f = 0; flags[f].mask; f++) { + if (status & flags[f].mask) { + if (!first) + fprintf(fp, ", "); + else + first = 0; + + fprintf(fp, "\"%s\"", flags[f].name); + status &= ~flags[f].mask; + } + } + fprintf(fp, "]"); + + if (status) + /* FIXME: agk is this the correct log level ? */ + log_print("Not all flags were successfully exported, " + "possible bug."); +} + +static int _print_header(FILE *fp, struct volume_group *vg) +{ + fprintf(fp, "# This file was generated by the LVM2 library\n" + "# %s\n\n", ctime(time(NULL))); + return 1; +} + +static int _print_vg(FILE *fp, struct volume_group *vg) +{ + fprintf(fp, "volume_group {\n"); + + fprintf(fp, "\tid = "); + _print_uuid(&vg.uuid); + fprintf(fp, "\n\tname = \"%s\"\n", vg->name); + + fprintf(fp, "\tstatus = "); + _print_flags(fp, vg->status, _vg_flags); + + fprintf(fp, "\n\textent_size = %u", vg->extent_size); + _print_size_comment(fp, vg->extent_size); + + fprintf(fp, "\tmax_lv = %u\n", vg->max_lv); + fprintf(fp, "\tmax_pv = %u\n", vg->max_pv); + fprintf(fp, "}\n"); + return 1; +} + +static int _print_pvs(FILE *fp, struct volume_group *vg) +{ + struct list pvh; + struct physical_volume *pv; + int count; + + fprintf(fp, "physical_volumes {\n\n"); + + list_iterate (pvh, &vg->pvs) { + fprintf(fp, "\tpv%d {\n", count++); + pv = &list_item(pvh, struct pv_list)->pv; + fprintf(fp, "\t\tid = "); + _print_uuid(fp, &pv->uuid); + fprintf(fp, "\n\t\tdevice = %s\t# Hint only\n\n", + dev_name(pv->dev)); + + fprintf(fp, "\t\tstatus = "); + _print_flags(fp, pv->status, _pv_flags); + + fprintf(fp, "\n\n\t\tpe_start = %u\n"); + fprintf(fp, "\t\tpe_count = %u", pv->pe_count); + _print_size_comment(fp, pe_count * vg->extent_size); + _fprintf(fp, "\n\t}\n") + } + + fprintf(fp, "}\n\n"); + return 1; +} + +static int _print_lvs(FILE *fp, struct volume_group *vg) +{ + struct list *lvh; + struct logical_volume *lv; + + fprintf(fp, "logical_volumes {\n"); + + list_iterate (lvh, &vg->lvs) { + lv = &list_item(lvh, struct lv_list)->lv; + + + } + + fprintf(fp, "}\n"); + return 1; +} struct volume_group *text_vg_import(struct pool *mem, struct config_file *cf) { @@ -12,8 +145,24 @@ struct volume_group *text_vg_import(struct pool *mem, struct config_file *cf) return NULL; } -struct config_file *text_vg_export(struct pool *mem, struct volume_group *vg) +int text_vg_export(FILE *fp, struct volume_group *vg) { - +#define fail do {stack; return 0;} while(0) + + if (!_print_header(fp, vg)) + fail; + + if (!_print_vg(fp, vg)) + fail; + + if (!_print_pvs(fp, vg)) + fail; + + if (!_print_lvs(fp, vg)) + fail; + +#undef fail + + return 1; } diff --git a/lib/format_text/sample.vg b/lib/format_text/sample.vg index bba353cb6..5d3611890 100644 --- a/lib/format_text/sample.vg +++ b/lib/format_text/sample.vg @@ -1,45 +1,63 @@ # An example volume group -vg { +volume_group { id = "ksjdlfksjldskjlsk" name = "sample_volume_group" - status = [???] + status = ["ACTIVE"] - extent_size = 8192 # 4M - extent_count = 1024 + extent_size = 8192 # 4M max_lv = 99 max_pv = 255 - - physical_volumes = ["pv1", "pv2"] - logical_volumes = ["lv1", "lv2"] } -pv1 { - id = "lksjdflksdlsk" - - device = "/dev/hda1" +physical_volumes { - status = [???] + pv1 { + id = "lksjdflksdlsk" + device = "/dev/hda1" # Hint only - pe_start = 8192 - pe_count = 300 # ???M -} + status = ["ALLOCATABLE"] + pe_start = 8192 + pe_count = 2048 # 8 Gigabytes + } -lv1 { - id = "lksdflskj" - name = "music" + pv2 { + id = "lksjdflksdlsk" + device = "/dev/hda2" # Hint only - status = [???] - read_ahead = 1024 - stripes = 1 - - size = ?? - le_count = 30 + status = ["ALLOCATABLE"] + pe_start = 8192 + pe_count = 1024 # 4 Gigabytes + } +} - map = ["pv1", 0, - "pv2", 1, - ... - ] +logical_volumes { + + music { + id = "lksdflskj" + status = ["ACTIVE"] + read_ahead = 1024 + + segment_count = 2 + + segment1 { + start_extent = 0 + extent_count = 1024 # 4 Gigabytes + stripes = 1 + + areas = ["pv1", 0] + } + + segment2 { + start_extent = 1024 + extent_count = 2048 # 8 Gigabytes + stripes = 2 + stripe_size = 32 # 16k stripes + + areas = ["pv1", 1024, + "pv2", 0] + } + } } \ No newline at end of file -- 2.43.5