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