2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include "import-export.h"
20 #include "toolcontext.h"
23 /* FIXME Use tidier inclusion method */
24 static struct text_vg_version_ops *(_text_vsn_list[2]);
26 static int _text_import_initialised = 0;
28 static void _init_text_import(void)
30 if (_text_import_initialised)
33 _text_vsn_list[0] = text_vg_vsn1_init();
34 _text_vsn_list[1] = NULL;
35 _text_import_initialised = 1;
38 const char *text_vgname_import(const struct format_type *fmt,
40 off_t offset, uint32_t size,
41 off_t offset2, uint32_t size2,
42 checksum_fn_t checksum_fn, uint32_t checksum,
43 struct id *vgid, uint64_t *vgstatus,
46 struct config_tree *cft;
47 struct text_vg_version_ops **vsn;
48 const char *vgname = NULL;
52 if (!(cft = create_config_tree(NULL, 0)))
55 if ((!dev && !read_config_file(cft)) ||
56 (dev && !read_config_fd(cft, dev, offset, size,
57 offset2, size2, checksum_fn, checksum)))
61 * Find a set of version functions that can read this file
63 for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
64 if (!(*vsn)->check_version(cft))
67 if (!(vgname = (*vsn)->read_vgname(fmt, cft, vgid, vgstatus,
75 destroy_config_tree(cft);
79 struct volume_group *text_vg_import_fd(struct format_instance *fid,
82 off_t offset, uint32_t size,
83 off_t offset2, uint32_t size2,
84 checksum_fn_t checksum_fn,
86 time_t *when, char **desc)
88 struct volume_group *vg = NULL;
89 struct config_tree *cft;
90 struct text_vg_version_ops **vsn;
97 if (!(cft = create_config_tree(file, 0)))
100 if ((!dev && !read_config_file(cft)) ||
101 (dev && !read_config_fd(cft, dev, offset, size,
102 offset2, size2, checksum_fn, checksum))) {
103 log_error("Couldn't read volume group metadata.");
108 * Find a set of version functions that can read this file
110 for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
111 if (!(*vsn)->check_version(cft))
114 if (!(vg = (*vsn)->read_vg(fid, cft, 0)))
117 (*vsn)->read_desc(vg->vgmem, cft, when, desc);
122 destroy_config_tree(cft);
126 struct volume_group *text_vg_import_file(struct format_instance *fid,
128 time_t *when, char **desc)
130 return text_vg_import_fd(fid, file, NULL, (off_t)0, 0, (off_t)0, 0, NULL, 0,
134 struct volume_group *import_vg_from_buffer(const char *buf,
135 struct format_instance *fid)
137 struct volume_group *vg = NULL;
138 struct config_tree *cft;
139 struct text_vg_version_ops **vsn;
143 if (!(cft = create_config_tree_from_string(fid->fmt->cmd, buf)))
146 for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
147 if (!(*vsn)->check_version(cft))
150 * The only path to this point uses cached vgmetadata,
151 * so it can use cached PV state too.
153 if (!(vg = (*vsn)->read_vg(fid, cft, 1)))
158 destroy_config_tree(cft);