summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/activate/activate.c7
-rw-r--r--lib/format1/format1.c2
-rw-r--r--lib/format1/lvm1_label.c6
-rw-r--r--lib/format_text/flags.c8
-rw-r--r--lib/format_text/format-text.c49
-rw-r--r--lib/format_text/format-text.h4
-rw-r--r--lib/format_text/import-export.h4
-rw-r--r--lib/format_text/import.c128
-rw-r--r--lib/label/label.c8
-rw-r--r--lib/label/label.h2
-rw-r--r--lib/metadata/merge.c1
-rw-r--r--lib/mm/pool-debug.c7
-rw-r--r--tools/Makefile.in1
-rw-r--r--tools/archive.c6
-rw-r--r--tools/lvm.c49
-rw-r--r--tools/stub.h1
-rw-r--r--tools/tools.h1
-rw-r--r--tools/vgcfgbackup.c2
18 files changed, 199 insertions, 87 deletions
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 188c3759..b188004f 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -17,7 +17,7 @@ static void _build_lv_name(char *buffer, size_t s, const char *vg_name,
snprintf(buffer, s, "%s_%s", vg_name, lv_name);
}
-static struct dm_task *_setup_task_with_name(struct logical_volume *lv,
+static struct dm_task *_setup_task_with_name(struct logical_volume *lv,
const char *lv_name, int task)
{
char name[128];
@@ -98,7 +98,6 @@ int lv_rename(const char *old_name, struct logical_volume *lv)
end:
dm_task_destroy(dmt);
-
return r;
}
@@ -126,7 +125,7 @@ int lv_suspended(struct logical_volume *lv)
return r;
}
- log_very_verbose("%s is%s suspended", lv->name,
+ log_very_verbose("%s is%s suspended", lv->name,
info.suspended ? "":" not");
return info.suspended;
}
@@ -169,7 +168,7 @@ static int _emit_target(struct dm_task *dmt, struct stripe_segment *seg)
w = tw;
}
-
+
for (s = 0; s < stripes; s++, w += tw) {
/******
log_debug("stripes: %d", stripes);
diff --git a/lib/format1/format1.c b/lib/format1/format1.c
index 82eac7ee..891b8ce7 100644
--- a/lib/format1/format1.c
+++ b/lib/format1/format1.c
@@ -371,14 +371,12 @@ static int _pv_write(struct format_instance *fi, struct physical_volume *pv)
/* Ensure any residual PE structure is gone */
pv->pe_size = pv->pe_count = pv->pe_start = 0;
- pv->status &= ~ALLOCATABLE_PV;
if (!(mem = pool_create(1024))) {
stack;
return 0;
}
-
if (!(dl = pool_alloc(mem, sizeof(*dl)))) {
stack;
goto bad;
diff --git a/lib/format1/lvm1_label.c b/lib/format1/lvm1_label.c
index 6ae1ebaa..60766c43 100644
--- a/lib/format1/lvm1_label.c
+++ b/lib/format1/lvm1_label.c
@@ -50,7 +50,7 @@ static struct label *_to_label(struct disk_list *dl)
return NULL;
}
- if (!(info = (struct lvm_label_info *) dbg_strdup(dl->pv.vg_name))) {
+ if (!(info = (struct lvm_label_info *) dbg_strdup(dl->pvd.vg_name))) {
dbg_free(l);
return NULL;
}
@@ -89,7 +89,7 @@ static int _read(struct labeller *l,
return r;
}
-static int _destroy_label(struct labeller *l, struct label *label)
+static void _destroy_label(struct labeller *l, struct label *label)
{
dbg_free(label->extra_info);
dbg_free(label);
@@ -99,7 +99,6 @@ static void _destroy(struct labeller *l)
{
struct pool *mem = (struct pool *) l->private;
pool_destroy(mem);
- dbg_free(l->private);
}
@@ -109,6 +108,7 @@ struct label_ops _lvm1_ops = {
remove: _remove,
read: _read,
verify: _can_handle,
+ destroy_label: _destroy_label,
destroy: _destroy
};
diff --git a/lib/format_text/flags.c b/lib/format_text/flags.c
index 5be0b7ac..0c06e2b9 100644
--- a/lib/format_text/flags.c
+++ b/lib/format_text/flags.c
@@ -21,6 +21,8 @@ struct flag {
static struct flag _vg_flags[] = {
{EXPORTED_VG, "EXPORTED"},
{RESIZEABLE_VG, "RESIZEABLE"},
+ {LVM_READ, "READ"},
+ {LVM_WRITE, "WRITE"},
{CLUSTERED, "CLUSTERED"},
{SHARED, "SHARED"},
{0, NULL}
@@ -134,19 +136,19 @@ int read_flags(uint32_t *status, int type, struct config_value *cv)
}
while (cv) {
- if (cv != CFG_STRING) {
+ if (cv->type != CFG_STRING) {
log_err("Status value is not a string.");
return 0;
}
for (f = 0; flags[f].description; f++)
if (!strcmp(flags[f].description, cv->v.str)) {
- (*status) &= flags[f].mask;
+ s |= flags[f].mask;
break;
}
if (!flags[f].description) {
- log_err("Unknown status flag.");
+ log_err("Unknown status flag '%s'.", cv->v.str);
return 0;
}
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index ff3dae17..0da845f4 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -23,6 +23,11 @@
* NOTE: Currently there can be only one vg per file.
*/
+struct text_c {
+ char *path;
+ struct uuid_map *um;
+};
+
static void _not_written(const char *cmd)
{
log_err("The text format is lacking an implementation for '%s'", cmd);
@@ -69,10 +74,10 @@ static int _vg_setup(struct format_instance *fi, struct volume_group *vg)
static struct volume_group *_vg_read(struct format_instance *fi,
const char *vg_name)
{
- char *file = (char *) fi->private;
+ struct text_c *tc = (struct text_c *) fi->private;
struct volume_group *vg;
- if (!(vg = text_vg_import(fi->cmd, file))) {
+ if (!(vg = text_vg_import(fi->cmd, tc->path, tc->um))) {
stack;
return NULL;
}
@@ -85,7 +90,7 @@ static struct volume_group *_vg_read(struct format_instance *fi,
if (strcmp(vg_name, vg->name)) {
pool_free(fi->cmd->mem, vg);
log_err("'%s' does not contain volume group '%s'.",
- file, vg_name);
+ tc->path, vg_name);
return NULL;
}
@@ -94,19 +99,20 @@ static struct volume_group *_vg_read(struct format_instance *fi,
static int _vg_write(struct format_instance *fi, struct volume_group *vg)
{
+ struct text_c *tc = (struct text_c *) fi->private;
+
FILE *fp;
int fd;
char *slash;
- char *file = (char *) fi->private;
char temp_file[PATH_MAX], temp_dir[PATH_MAX];
- slash = rindex(file, '/');
+ slash = rindex(tc->path, '/');
if (slash == 0)
strcpy(temp_dir, ".");
- else if (slash - file < PATH_MAX) {
- strncpy(temp_dir, file, slash - file);
- temp_dir[slash - file] = '\0';
+ else if (slash - tc->path < PATH_MAX) {
+ strncpy(temp_dir, tc->path, slash - tc->path);
+ temp_dir[slash - tc->path] = '\0';
} else {
log_error("Text format failed to determine directory.");
@@ -131,12 +137,12 @@ static int _vg_write(struct format_instance *fi, struct volume_group *vg)
}
if (fclose(fp)) {
- log_sys_error("fclose", file);
+ log_sys_error("fclose", tc->path);
return 0;
}
- if (rename(temp_file, file)) {
- log_error("%s: rename to %s failed: %s", temp_file, file,
+ if (rename(temp_file, tc->path)) {
+ log_error("%s: rename to %s failed: %s", temp_file, tc->path,
strerror(errno));
return 0;
}
@@ -146,7 +152,10 @@ static int _vg_write(struct format_instance *fi, struct volume_group *vg)
static void _destroy(struct format_instance *fi)
{
- dbg_free(fi->private);
+ struct text_c *tc = (struct text_c *) fi->private;
+
+ dbg_free(tc->path);
+ dbg_free(tc);
dbg_free(fi);
}
@@ -163,12 +172,14 @@ static struct format_handler _text_handler = {
};
struct format_instance *text_format_create(struct cmd_context *cmd,
- const char *file)
+ const char *file,
+ struct uuid_map *um)
{
const char *no_alloc = "Couldn't allocate text format object.";
struct format_instance *fi;
char *path;
+ struct text_c *tc;
if (!(fi = dbg_malloc(sizeof(*fi)))) {
log_err(no_alloc);
@@ -181,9 +192,19 @@ struct format_instance *text_format_create(struct cmd_context *cmd,
return NULL;
}
+ if (!(tc = dbg_malloc(sizeof(*tc)))) {
+ dbg_free(fi);
+ dbg_free(path);
+ log_err(no_alloc);
+ return NULL;
+ }
+
+ tc->path = path;
+ tc->um = um;
+
fi->cmd = cmd;
fi->ops = &_text_handler;
- fi->private = path;
+ fi->private = tc;
return fi;
}
diff --git a/lib/format_text/format-text.h b/lib/format_text/format-text.h
index d6338b22..1deca461 100644
--- a/lib/format_text/format-text.h
+++ b/lib/format_text/format-text.h
@@ -9,6 +9,7 @@
#include "lvm-types.h"
#include "metadata.h"
+#include "uuid-map.h"
/*
* The archive format is used to maintain a set of metadata backup files
@@ -30,6 +31,7 @@ void backup_expire(struct format_instance *fi);
* The text format can read and write a volume_group to a file.
*/
struct format_instance *text_format_create(struct cmd_context *cmd,
- const char *file);
+ const char *file,
+ struct uuid_map *um);
#endif
diff --git a/lib/format_text/import-export.h b/lib/format_text/import-export.h
index 7851bd00..d33e68ca 100644
--- a/lib/format_text/import-export.h
+++ b/lib/format_text/import-export.h
@@ -10,6 +10,7 @@
#include "config.h"
#include "lvm-types.h"
#include "metadata.h"
+#include "uuid-map.h"
#include <stdio.h>
@@ -24,6 +25,7 @@ int read_flags(uint32_t *status, int type, struct config_value *cv);
int text_vg_export(FILE *fp, struct volume_group *vg);
-struct volume_group *text_vg_import(struct cmd_context *cmd, const char *file);
+struct volume_group *text_vg_import(struct cmd_context *cmd, const char *file,
+ struct uuid_map *um);
#endif
diff --git a/lib/format_text/import.c b/lib/format_text/import.c
index 83fd665e..b650cf67 100644
--- a/lib/format_text/import.c
+++ b/lib/format_text/import.c
@@ -14,7 +14,8 @@
typedef int (*section_fn)(struct pool *mem,
struct volume_group *vg, struct config_node *pvn,
- struct config_node *vgn, struct hash_table *pv_hash);
+ struct config_node *vgn, struct hash_table *pv_hash,
+ struct uuid_map *um);
#define _read_int32(root, path, result) \
get_config_uint32(root, path, '/', result)
@@ -48,7 +49,8 @@ static int _read_id(struct id *id, struct config_node *cn, const char *path)
static int _read_pv(struct pool *mem,
struct volume_group *vg, struct config_node *pvn,
struct config_node *vgn,
- struct hash_table *pv_hash)
+ struct hash_table *pv_hash,
+ struct uuid_map *um)
{
struct physical_volume *pv;
struct pv_list *pvl;
@@ -61,22 +63,46 @@ static int _read_pv(struct pool *mem,
pv = &pvl->pv;
- if (!_read_id(&pv->id, vgn, "id")) {
+ /*
+ * Add the pv to the pv hash for quick lookup when we read
+ * the lv segments.
+ */
+ if (!hash_insert(pv_hash, pvn->key, pv)) {
+ stack;
+ return 0;
+ }
+
+ if (!(pvn = pvn->child)) {
+ log_err("Empty pv section.");
+ return 0;
+ }
+
+ if (!_read_id(&pv->id, pvn, "id")) {
log_err("Couldn't read uuid for volume group.");
return 0;
}
/*
- * FIXME: need label/vgcache code to convert the uuid
- * into a device.
+ * Use the uuid map to convert the uuid into a device.
*/
+ if (!(pv->dev = uuid_map_lookup(um, &pv->id))) {
+ char buffer[64];
+
+ if (!id_write_format(&pv->id, buffer, sizeof(buffer))) {
+ log_err("Couldn't find device.");
+ return 0;
+ }
+
+ log_err("Couldn't find device with uuid '%s'.", buffer);
+ return 0;
+ }
if (!(pv->vg_name = pool_strdup(mem, vg->name))) {
stack;
return 0;
}
- if (!(cn = find_config_node(vgn, "status", '/'))) {
+ if (!(cn = find_config_node(pvn, "status", '/'))) {
log_err("Couldn't find status flags for physical volume.");
return 0;
}
@@ -104,17 +130,9 @@ static int _read_pv(struct pool *mem,
pv->size = pv->pe_size * (uint64_t) pv->pe_count;
pv->pe_allocated = 0;
+ vg->pv_count++;
list_add(&vg->pvs, &pvl->list);
- /*
- * Add the pv to the pv hash for quick lookup when we read
- * the lv segments.
- */
- if (!hash_insert(pv_hash, pvn->key, pv)) {
- stack;
- return 0;
- }
-
return 1;
}
@@ -133,6 +151,7 @@ static void _insert_segment(struct logical_volume *lv,
}
}
+ lv->le_count += seg->len;
list_add(&lv->segments, &seg->list);
}
@@ -141,14 +160,29 @@ static int _read_segment(struct pool *mem, struct volume_group *vg,
struct hash_table *pv_hash)
{
int s;
+ uint32_t stripes;
struct stripe_segment *seg;
struct config_node *cn;
struct config_value *cv;
+ const char *seg_name = sn->key;
- if (!(seg = pool_zalloc(mem, sizeof(*seg)))) {
+ if (!(sn = sn->child)) {
+ log_err("Empty segment section.");
+ return 0;
+ }
+
+ if (!_read_int32(sn, "stripes", &stripes)) {
+ log_err("Couldn't read 'stripes' for segment '%s'.",
+ sn->key);
+ return 0;
+ }
+
+ if (!(seg = pool_zalloc(mem, sizeof(*seg) +
+ (sizeof(seg->area[0]) * stripes)))) {
stack;
return 0;
}
+ seg->stripes = stripes;
if (!_read_int32(sn, "start_extent", &seg->le)) {
log_err("Couldn't read 'start_extent' for segment '%s'.",
@@ -162,12 +196,6 @@ static int _read_segment(struct pool *mem, struct volume_group *vg,
return 0;
}
- if (!_read_int32(sn, "stripes", &seg->stripes)) {
- log_err("Couldn't read 'stripes' for segment '%s'.",
- sn->key);
- return 0;
- }
-
if (seg->stripes == 0) {
log_err("Zero stripes is *not* allowed for segment '%s'.",
sn->key);
@@ -204,9 +232,10 @@ static int _read_segment(struct pool *mem, struct volume_group *vg,
}
if (!(pv = hash_lookup(pv_hash, cv->v.str))) {
- log_err("Couldn't find physical volume (%s) for "
+ log_err("Couldn't find physical volume '%s' for "
"segment '%s'.",
- cn->v->v.str ? cn->v->v.str : "NULL", sn->key);
+ cn->v->v.str ? cn->v->v.str : "NULL",
+ seg_name);
return 0;
}
@@ -237,7 +266,7 @@ static int _read_segment(struct pool *mem, struct volume_group *vg,
*/
if (cv || (s < seg->stripes)) {
log_err("Incorrect number of stripes in 'area' array "
- "for segment '%s'.", sn->key);
+ "for segment '%s'.", seg_name);
return 0;
}
@@ -255,12 +284,12 @@ static int _read_segments(struct pool *mem, struct volume_group *vg,
struct config_node *sn;
int count = 0, seg_count;
- for (sn = lvn->child; sn; sn = sn->sib) {
+ for (sn = lvn; sn; sn = sn->sib) {
/*
* All sub-sections are assumed to be segments.
*/
- if (sn->v) {
+ if (!sn->v) {
if (!_read_segment(mem, vg, lv, sn, pv_hash)) {
stack;
return 0;
@@ -302,7 +331,8 @@ static int _read_segments(struct pool *mem, struct volume_group *vg,
static int _read_lv(struct pool *mem,
struct volume_group *vg, struct config_node *lvn,
- struct config_node *vgn, struct hash_table *pv_hash)
+ struct config_node *vgn, struct hash_table *pv_hash,
+ struct uuid_map *um)
{
struct logical_volume *lv;
struct lv_list *lvl;
@@ -320,8 +350,14 @@ static int _read_lv(struct pool *mem,
return 0;
}
+ if (!(lvn = lvn->child)) {
+ log_err("Empty logical volume section.");
+ return 0;
+ }
+
lv->vg = vg;
+
if (!(cn = find_config_node(lvn, "status", '/'))) {
log_err("Couldn't find status flags for logical volume.");
return 0;
@@ -343,7 +379,9 @@ static int _read_lv(struct pool *mem,
stack;
return 0;
}
+ lv->size = (uint64_t) lv->le_count * (uint64_t) vg->extent_size;
+ vg->lv_count++;
list_add(&vg->lvs, &lvl->list);
return 1;
@@ -352,7 +390,8 @@ static int _read_lv(struct pool *mem,
static int _read_sections(const char *section, section_fn fn,
struct pool *mem,
struct volume_group *vg, struct config_node *vgn,
- struct hash_table *pv_hash)
+ struct hash_table *pv_hash,
+ struct uuid_map *um)
{
struct config_node *n;
@@ -362,7 +401,7 @@ static int _read_sections(const char *section, section_fn fn,
}
for (n = n->child; n; n = n->sib) {
- if (!fn(mem, vg, vgn, n, pv_hash)) {
+ if (!fn(mem, vg, n, vgn, pv_hash, um)) {
stack;
return 0;
}
@@ -371,19 +410,20 @@ static int _read_sections(const char *section, section_fn fn,
return 1;
}
-static struct volume_group *_read_vg(struct pool *mem, struct config_file *cf)
+static struct volume_group *_read_vg(struct pool *mem, struct config_file *cf,
+ struct uuid_map *um)
{
struct config_node *vgn = cf->root, *cn;
struct volume_group *vg;
struct hash_table *pv_hash = NULL;
if (!vgn) {
- log_err("Couldn't not find volume group.");
+ log_err("Couldn't find volume group.");
return NULL;
}
- if (!(vgn = find_config_node(cf->root, "volume_group", '/'))) {
- log_err("Couldn't find volume_group section.");
+ if (!(vgn = cf->root)) {
+ log_err("Couldn't find volume group in file.");
return NULL;
}
@@ -392,13 +432,14 @@ static struct volume_group *_read_vg(struct pool *mem, struct config_file *cf)
return NULL;
}
- if (!_read_id(&vg->id, vgn, "id")) {
- log_err("Couldn't read uuid for volume group.");
+ if (!(vg->name = pool_strdup(mem, vgn->key))) {
+ stack;
goto bad;
}
- if (!(vg->name = pool_strdup(mem, vgn->key))) {
- stack;
+ vgn = vgn->child;
+ if (!_read_id(&vg->id, vgn, "id")) {
+ log_err("Couldn't read uuid for volume group.");
goto bad;
}
@@ -443,7 +484,7 @@ static struct volume_group *_read_vg(struct pool *mem, struct config_file *cf)
list_init(&vg->pvs);
if (!_read_sections("physical_volumes", _read_pv, mem, vg,
- vgn, pv_hash)) {
+ vgn, pv_hash, um)) {
log_err("Couldn't read all physical volumes for volume "
"group.");
goto bad;
@@ -451,7 +492,7 @@ static struct volume_group *_read_vg(struct pool *mem, struct config_file *cf)
list_init(&vg->lvs);
if (!_read_sections("logical_volumes", _read_lv, mem, vg,
- vgn, pv_hash)) {
+ vgn, pv_hash, um)) {
log_err("Couldn't read all logical volumes for volume "
"group.");
goto bad;
@@ -473,7 +514,8 @@ static struct volume_group *_read_vg(struct pool *mem, struct config_file *cf)
}
struct volume_group *text_vg_import(struct cmd_context *cmd,
- const char *file)
+ const char *file,
+ struct uuid_map *um)
{
struct volume_group *vg = NULL;
struct config_file *cf;
@@ -488,9 +530,11 @@ struct volume_group *text_vg_import(struct cmd_context *cmd,
goto out;
}
- if (!(vg = _read_vg(cmd->mem, cf)))
+ if (!(vg = _read_vg(cmd->mem, cf, um)))
stack;
+ vg->cmd = cmd;
+
out:
destroy_config_file(cf);
return vg;
diff --git a/lib/label/label.c b/lib/label/label.c
index 6289adb3..461fe5f0 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -129,7 +129,7 @@ int label_read(struct device *dev, struct label **result)
}
if ((r = l->ops->read(l, dev, result)))
- *result->labeller = l;
+ (*result)->labeller = l;
return r;
}
@@ -146,9 +146,7 @@ int label_verify(struct device *dev)
return l->ops->verify(l, dev);
}
-void label_free(struct label *l)
+void label_destroy(struct label *lab)
{
- dbg_free(l->extra_info);
- dbg_free(l);
+ lab->labeller->ops->destroy_label(lab->labeller, lab);
}
-
diff --git a/lib/label/label.h b/lib/label/label.h
index 911fd0b3..ec652c84 100644
--- a/lib/label/label.h
+++ b/lib/label/label.h
@@ -54,7 +54,7 @@ struct label_ops {
/*
* Destroy a previously read label.
*/
- int (*destroy_label)(struct labeller *l, struct label *label);
+ void (*destroy_label)(struct labeller *l, struct label *label);
/*
* Destructor.
diff --git a/lib/metadata/merge.c b/lib/metadata/merge.c
index ea17931e..790c57ef 100644
--- a/lib/metadata/merge.c
+++ b/lib/metadata/merge.c
@@ -53,7 +53,6 @@ int lv_merge_segments(struct logical_volume *lv)
return 1;
}
-/**** FIXME Dummy ****/
int lv_check_segments(struct logical_volume *lv)
{
return 1;
diff --git a/lib/mm/pool-debug.c b/lib/mm/pool-debug.c
index d7530e5c..f5b1ec89 100644
--- a/lib/mm/pool-debug.c
+++ b/lib/mm/pool-debug.c
@@ -37,6 +37,7 @@ struct pool *pool_create(size_t chunk_hint)
return NULL;
}
+ mem->begun = 0;
mem->object = 0;
mem->blocks = mem->tail = NULL;
return mem;
@@ -143,10 +144,14 @@ int pool_begin_object(struct pool *p, size_t init_size)
int pool_grow_object(struct pool *p, const void *buffer, size_t delta)
{
struct block *new;
+ size_t size = delta;
assert(p->begun);
- if (!(new = _new_block(p->object->size + delta, DEFAULT_ALIGNMENT))) {
+ if (p->object)
+ size += p->object->size;
+
+ if (!(new = _new_block(size, DEFAULT_ALIGNMENT))) {
log_err("Couldn't extend object.");
return 0;
}
diff --git a/tools/Makefile.in b/tools/Makefile.in
index 9da2f41e..a0a4ab86 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -39,6 +39,7 @@ SOURCES=\
pvscan.c \
toollib.c \
vgcfgbackup.c \
+ vgcfgrestore.c \
vgchange.c \
vgck.c \
vgcreate.c \
diff --git a/tools/archive.c b/tools/archive.c
index 5ca151ac..cbdd7760 100644
--- a/tools/archive.c
+++ b/tools/archive.c
@@ -151,7 +151,7 @@ static int __backup(struct volume_group *vg)
log_verbose("Creating volume group backup %s", name);
- if (!(tf = text_format_create(vg->cmd, name))) {
+ if (!(tf = text_format_create(vg->cmd, name, the_um))) {
stack;
return 0;
}
@@ -207,7 +207,7 @@ static struct volume_group *_read_vg(struct cmd_context *cmd,
struct volume_group *vg;
struct format_instance *tf;
- if (!(tf = text_format_create(cmd, file))) {
+ if (!(tf = text_format_create(cmd, file, the_um))) {
log_error("Couldn't create text format object.");
return 0;
}
@@ -226,7 +226,7 @@ int backup_restore_from_file(const char *vg_name, const char *file)
/*
* Read in the volume group.
*/
- if (!(vg = _read_vg(vg->cmd, vg_name, file))) {
+ if (!(vg = _read_vg(fid->cmd, vg_name, file))) {
stack;
return 0;
}
diff --git a/tools/lvm.c b/tools/lvm.c
index 2559ad8d..d2364cbe 100644
--- a/tools/lvm.c
+++ b/tools/lvm.c
@@ -7,6 +7,8 @@
#include "tools.h"
#include "archive.h"
#include "defaults.h"
+#include "lvm1_label.h"
+#include "label.h"
#include "stub.h"
@@ -43,6 +45,9 @@ static struct command *_commands;
/* Exported LVM1 disk format */
struct format_instance *fid;
+/* Map of uuid -> device */
+struct uuid_map *the_um;
+
/* Export command being processed */
struct command *the_command;
@@ -54,6 +59,10 @@ static int _dump_filter;
static int _interactive;
static FILE *_log;
+/* lvm1 label handler */
+static struct labeller *_lvm1_label;
+
+
/*
* This structure only contains those options that
* can have a default and per command setting.
@@ -508,7 +517,7 @@ static int merge_synonym(int oldarg, int newarg)
if (arg_count(oldarg) && arg_count(newarg)) {
log_error("%s and %s are synonyms. Please only supply one.",
- the_args[oldarg].long_arg,
+ the_args[oldarg].long_arg,
the_args[newarg].long_arg);
return 0;
}
@@ -535,7 +544,7 @@ static int process_common_commands(struct command *com)
kill(getpid(), SIGSTOP);
if (arg_count(debug_ARG))
- _current_settings.debug = _LOG_FATAL +
+ _current_settings.debug = _LOG_FATAL +
(arg_count(debug_ARG) - 1);
if (arg_count(verbose_ARG))
@@ -880,6 +889,31 @@ static struct dev_filter *filter_setup(struct config_file *cf)
return f4;
}
+static int _init_uuid_map(struct dev_filter *filter)
+{
+ label_init();
+
+ /* add in the lvm1 labeller */
+ if (!(_lvm1_label = lvm1_labeller_create())) {
+ log_err("Couldn't create lvm1 label handler.");
+ return 0;
+ }
+
+ if (!(label_register_handler("lvm1", _lvm1_label))) {
+ log_err("Couldn't register lvm1 label handler.");
+ return 0;
+ }
+
+ return (the_um = uuid_map_create(filter)) ? 1 : 0;
+}
+
+static void _exit_uuid_map(void)
+{
+ uuid_map_destroy(the_um);
+ label_exit();
+ _lvm1_label->ops->destroy(_lvm1_label);
+}
+
static int _get_env_vars(void)
{
const char *e;
@@ -944,8 +978,8 @@ static int init(void)
__init_log(cmd->cf);
}
- _default_settings.umask = find_config_int(cmd->cf->root,
- "global/umask", '/',
+ _default_settings.umask = find_config_int(cmd->cf->root,
+ "global/umask", '/',
DEFAULT_UMASK);
if ((old_umask = umask((mode_t)_default_settings.umask)) !=
@@ -975,6 +1009,12 @@ static int init(void)
return 0;
}
+ /* the uuid map uses the filter */
+ if (!_init_uuid_map(cmd->filter)) {
+ log_err("Failed to set up the uuid map.");
+ return 0;
+ }
+
if (!(cmd->mem = pool_create(4 * 1024))) {
log_error("Command pool creation failed");
return 0;
@@ -1014,6 +1054,7 @@ static void fin(void)
__fin_commands();
dump_memory();
fin_log();
+ _exit_uuid_map();
if (_log)
fclose(_log);
diff --git a/tools/stub.h b/tools/stub.h
index fa6e6e3a..5bf2e78d 100644
--- a/tools/stub.h
+++ b/tools/stub.h
@@ -13,5 +13,4 @@ int vgexport(int argc, char **argv) {return 1;}
int vgimport(int argc, char **argv) {return 1;}
int vgmknodes(int argc, char **argv) {return 1;}
int vgsplit(int argc, char **argv) {return 1;}
-int vgcfgrestore(int argc, char **argv) {return 1;}
diff --git a/tools/tools.h b/tools/tools.h
index 9594d392..73006c29 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -100,6 +100,7 @@ struct command {
};
extern struct command *the_command;
+extern struct uuid_map *the_um;
void usage(const char *name);
diff --git a/tools/vgcfgbackup.c b/tools/vgcfgbackup.c
index f6f450be..d2ad0401 100644
--- a/tools/vgcfgbackup.c
+++ b/tools/vgcfgbackup.c
@@ -13,7 +13,7 @@ static int _backup_to_file(const char *file, struct volume_group *vg)
int r;
struct format_instance *tf;
- if (!(tf = text_format_create(vg->cmd, file))) {
+ if (!(tf = text_format_create(vg->cmd, file, the_um))) {
log_error("Couldn't create backup object.");
return 0;
}