Branch data Line data Source code
1 : : /*
2 : : * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
3 : : *
4 : : * This file is part of LVM2.
5 : : *
6 : : * This copyrighted material is made available to anyone wishing to use,
7 : : * modify, copy, or redistribute it subject to the terms and conditions
8 : : * of the GNU Lesser General Public License v.2.1.
9 : : *
10 : : * You should have received a copy of the GNU Lesser General Public License
11 : : * along with this program; if not, write to the Free Software Foundation,
12 : : * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13 : : */
14 : :
15 : : #include "lib.h"
16 : : #include "toolcontext.h"
17 : : #include "segtype.h"
18 : : #include "display.h"
19 : : #include "text_export.h"
20 : : #include "text_import.h"
21 : : #include "config.h"
22 : : #include "str_list.h"
23 : : #include "targets.h"
24 : : #include "lvm-string.h"
25 : : #include "activate.h"
26 : : #include "str_list.h"
27 : : #include "metadata.h"
28 : :
29 : 0 : static const char *_unknown_name(const struct lv_segment *seg)
30 : : {
31 : :
32 : 0 : return seg->segtype->name;
33 : : }
34 : :
35 : 0 : static int _unknown_text_import(struct lv_segment *seg, const struct config_node *sn,
36 : : struct dm_hash_table *pv_hash)
37 : : {
38 : 0 : struct config_node *new, *last = NULL, *head = NULL;
39 : : const struct config_node *current;
40 : 0 : log_verbose("importing unknown segment");
41 [ # # ]: 0 : for (current = sn; current != NULL; current = current->sib) {
42 [ # # ][ # # ]: 0 : if (!strcmp(current->key, "type") || !strcmp(current->key, "start_extent") ||
[ # # ][ # # ]
43 : 0 : !strcmp(current->key, "tags") || !strcmp(current->key, "extent_count"))
44 : 0 : continue;
45 : 0 : new = clone_config_node(seg->lv->vg->vgmem, current, 0);
46 [ # # ]: 0 : if (!new)
47 : 0 : return_0;
48 [ # # ]: 0 : if (last)
49 : 0 : last->sib = new;
50 [ # # ]: 0 : if (!head)
51 : 0 : head = new;
52 : 0 : last = new;
53 : : }
54 : 0 : seg->segtype_private = head;
55 : 0 : return 1;
56 : : }
57 : :
58 : 0 : static int _unknown_text_export(const struct lv_segment *seg, struct formatter *f)
59 : : {
60 : 0 : struct config_node *cn = seg->segtype_private;
61 : 0 : return out_config_node(f, cn);
62 : : }
63 : :
64 : : #ifdef DEVMAPPER_SUPPORT
65 : 0 : static int _unknown_add_target_line(struct dev_manager *dm __attribute((unused)),
66 : : struct dm_pool *mem __attribute((unused)),
67 : : struct cmd_context *cmd __attribute((unused)),
68 : : void **target_state __attribute((unused)),
69 : : struct lv_segment *seg __attribute((unused)),
70 : : struct dm_tree_node *node, uint64_t len,
71 : : uint32_t *pvmove_mirror_count __attribute((unused)))
72 : : {
73 : 0 : return dm_tree_node_add_error_target(node, len);
74 : : }
75 : : #endif
76 : :
77 : 0 : static void _unknown_destroy(const struct segment_type *segtype)
78 : : {
79 : 0 : dm_free((void *)segtype);
80 : 0 : }
81 : :
82 : : static struct segtype_handler _unknown_ops = {
83 : : .name = _unknown_name,
84 : : .text_import = _unknown_text_import,
85 : : .text_export = _unknown_text_export,
86 : : #ifdef DEVMAPPER_SUPPORT
87 : : .add_target_line = _unknown_add_target_line,
88 : : #endif
89 : : .destroy = _unknown_destroy,
90 : : };
91 : :
92 : 0 : struct segment_type *init_unknown_segtype(struct cmd_context *cmd, const char *name)
93 : : {
94 : 0 : struct segment_type *segtype = dm_malloc(sizeof(*segtype));
95 : :
96 [ # # ]: 0 : if (!segtype)
97 : 0 : return_NULL;
98 : :
99 : 0 : segtype->cmd = cmd;
100 : 0 : segtype->ops = &_unknown_ops;
101 : 0 : segtype->name = dm_pool_strdup(cmd->mem, name);
102 : 0 : segtype->private = NULL;
103 : 0 : segtype->flags = SEG_UNKNOWN | SEG_VIRTUAL | SEG_CANNOT_BE_ZEROED;
104 : :
105 : 0 : log_very_verbose("Initialised segtype: %s", segtype->name);
106 : :
107 : 0 : return segtype;
108 : : }
|