4 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
6 * This file is part of LVM2.
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.
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
18 #include "toolcontext.h"
21 #include "text_export.h"
22 #include "text_import.h"
26 #include "lvm-string.h"
31 static const char *_unknown_name(const struct lv_segment
*seg
)
34 return seg
->segtype
->name
;
37 static int _unknown_text_import(struct lv_segment
*seg
, const struct config_node
*sn
,
38 struct dm_hash_table
*pv_hash
)
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"))
47 new = clone_config_node(seg
->lv
->vg
->vgmem
, current
, 0);
56 seg
->segtype_private
= head
;
60 static int _unknown_text_export(const struct lv_segment
*seg
, struct formatter
*f
)
62 struct config_node
*cn
= seg
->segtype_private
;
63 return out_config_node(f
, cn
);
66 #ifdef DEVMAPPER_SUPPORT
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
)))
75 return dm_tree_node_add_error_target(node
, len
);
79 static void _unknown_destroy(const struct segment_type
*segtype
)
81 dm_free((void *)segtype
);
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
,
91 .destroy
= _unknown_destroy
,
94 struct segment_type
*init_unknown_segtype(struct cmd_context
*cmd
, const char *name
)
96 struct segment_type
*segtype
= dm_malloc(sizeof(*segtype
));
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
;
107 log_very_verbose("Initialised segtype: %s", segtype
->name
);