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