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 *_errseg_name(const struct lv_segment
*seg
)
33 return seg
->segtype
->name
;
36 static int _errseg_merge_segments(struct lv_segment
*seg1
, struct lv_segment
*seg2
)
38 seg1
->len
+= seg2
->len
;
39 seg1
->area_len
+= seg2
->area_len
;
44 #ifdef DEVMAPPER_SUPPORT
45 static int _errseg_add_target_line(struct dev_manager
*dm
__attribute((unused
)),
46 struct dm_pool
*mem
__attribute((unused
)),
47 struct cmd_context
*cmd
__attribute((unused
)),
48 void **target_state
__attribute((unused
)),
49 struct lv_segment
*seg
__attribute((unused
)),
50 struct dm_tree_node
*node
, uint64_t len
,
51 uint32_t *pvmove_mirror_count
__attribute((unused
)))
53 return dm_tree_node_add_error_target(node
, len
);
56 static int _errseg_target_present(struct cmd_context
*cmd
,
57 const struct lv_segment
*seg
__attribute((unused
)),
58 unsigned *attributes
__attribute((unused
)))
60 static int _errseg_checked
= 0;
61 static int _errseg_present
= 0;
63 /* Reported truncated in older kernels */
64 if (!_errseg_checked
&&
65 (target_present(cmd
, "error", 0) ||
66 target_present(cmd
, "erro", 0)))
70 return _errseg_present
;
74 static int _errseg_modules_needed(struct dm_pool
*mem
,
75 const struct lv_segment
*seg
__attribute((unused
)),
76 struct dm_list
*modules
)
78 if (!str_list_add(mem
, modules
, "error")) {
79 log_error("error module string list allocation failed");
86 static void _errseg_destroy(const struct segment_type
*segtype
)
88 dm_free((void *)segtype
);
91 static struct segtype_handler _error_ops
= {
93 .merge_segments
= _errseg_merge_segments
,
94 #ifdef DEVMAPPER_SUPPORT
95 .add_target_line
= _errseg_add_target_line
,
96 .target_present
= _errseg_target_present
,
98 .modules_needed
= _errseg_modules_needed
,
99 .destroy
= _errseg_destroy
,
102 struct segment_type
*init_error_segtype(struct cmd_context
*cmd
)
104 struct segment_type
*segtype
= dm_malloc(sizeof(*segtype
));
110 segtype
->ops
= &_error_ops
;
111 segtype
->name
= "error";
112 segtype
->private = NULL
;
113 segtype
->flags
= SEG_CAN_SPLIT
| SEG_VIRTUAL
| SEG_CANNOT_BE_ZEROED
;
115 log_very_verbose("Initialised segtype: %s", segtype
->name
);