1*86d7f5d3SJohn Marino /* $NetBSD: errseg.c,v 1.1.1.2 2009/12/02 00:26:45 haad Exp $ */
2*86d7f5d3SJohn Marino
3*86d7f5d3SJohn Marino /*
4*86d7f5d3SJohn Marino * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
5*86d7f5d3SJohn Marino *
6*86d7f5d3SJohn Marino * This file is part of LVM2.
7*86d7f5d3SJohn Marino *
8*86d7f5d3SJohn Marino * This copyrighted material is made available to anyone wishing to use,
9*86d7f5d3SJohn Marino * modify, copy, or redistribute it subject to the terms and conditions
10*86d7f5d3SJohn Marino * of the GNU Lesser General Public License v.2.1.
11*86d7f5d3SJohn Marino *
12*86d7f5d3SJohn Marino * You should have received a copy of the GNU Lesser General Public License
13*86d7f5d3SJohn Marino * along with this program; if not, write to the Free Software Foundation,
14*86d7f5d3SJohn Marino * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*86d7f5d3SJohn Marino */
16*86d7f5d3SJohn Marino
17*86d7f5d3SJohn Marino #include "lib.h"
18*86d7f5d3SJohn Marino #include "toolcontext.h"
19*86d7f5d3SJohn Marino #include "segtype.h"
20*86d7f5d3SJohn Marino #include "display.h"
21*86d7f5d3SJohn Marino #include "text_export.h"
22*86d7f5d3SJohn Marino #include "text_import.h"
23*86d7f5d3SJohn Marino #include "config.h"
24*86d7f5d3SJohn Marino #include "str_list.h"
25*86d7f5d3SJohn Marino #include "targets.h"
26*86d7f5d3SJohn Marino #include "lvm-string.h"
27*86d7f5d3SJohn Marino #include "activate.h"
28*86d7f5d3SJohn Marino #include "str_list.h"
29*86d7f5d3SJohn Marino #include "metadata.h"
30*86d7f5d3SJohn Marino
_errseg_name(const struct lv_segment * seg)31*86d7f5d3SJohn Marino static const char *_errseg_name(const struct lv_segment *seg)
32*86d7f5d3SJohn Marino {
33*86d7f5d3SJohn Marino return seg->segtype->name;
34*86d7f5d3SJohn Marino }
35*86d7f5d3SJohn Marino
_errseg_merge_segments(struct lv_segment * seg1,struct lv_segment * seg2)36*86d7f5d3SJohn Marino static int _errseg_merge_segments(struct lv_segment *seg1, struct lv_segment *seg2)
37*86d7f5d3SJohn Marino {
38*86d7f5d3SJohn Marino seg1->len += seg2->len;
39*86d7f5d3SJohn Marino seg1->area_len += seg2->area_len;
40*86d7f5d3SJohn Marino
41*86d7f5d3SJohn Marino return 1;
42*86d7f5d3SJohn Marino }
43*86d7f5d3SJohn Marino
44*86d7f5d3SJohn Marino #ifdef DEVMAPPER_SUPPORT
_errseg_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)))45*86d7f5d3SJohn Marino static int _errseg_add_target_line(struct dev_manager *dm __attribute((unused)),
46*86d7f5d3SJohn Marino struct dm_pool *mem __attribute((unused)),
47*86d7f5d3SJohn Marino struct cmd_context *cmd __attribute((unused)),
48*86d7f5d3SJohn Marino void **target_state __attribute((unused)),
49*86d7f5d3SJohn Marino struct lv_segment *seg __attribute((unused)),
50*86d7f5d3SJohn Marino struct dm_tree_node *node, uint64_t len,
51*86d7f5d3SJohn Marino uint32_t *pvmove_mirror_count __attribute((unused)))
52*86d7f5d3SJohn Marino {
53*86d7f5d3SJohn Marino return dm_tree_node_add_error_target(node, len);
54*86d7f5d3SJohn Marino }
55*86d7f5d3SJohn Marino
_errseg_target_present(struct cmd_context * cmd,const struct lv_segment * seg __attribute ((unused)),unsigned * attributes __attribute ((unused)))56*86d7f5d3SJohn Marino static int _errseg_target_present(struct cmd_context *cmd,
57*86d7f5d3SJohn Marino const struct lv_segment *seg __attribute((unused)),
58*86d7f5d3SJohn Marino unsigned *attributes __attribute((unused)))
59*86d7f5d3SJohn Marino {
60*86d7f5d3SJohn Marino static int _errseg_checked = 0;
61*86d7f5d3SJohn Marino static int _errseg_present = 0;
62*86d7f5d3SJohn Marino
63*86d7f5d3SJohn Marino /* Reported truncated in older kernels */
64*86d7f5d3SJohn Marino if (!_errseg_checked &&
65*86d7f5d3SJohn Marino (target_present(cmd, "error", 0) ||
66*86d7f5d3SJohn Marino target_present(cmd, "erro", 0)))
67*86d7f5d3SJohn Marino _errseg_present = 1;
68*86d7f5d3SJohn Marino
69*86d7f5d3SJohn Marino _errseg_checked = 1;
70*86d7f5d3SJohn Marino return _errseg_present;
71*86d7f5d3SJohn Marino }
72*86d7f5d3SJohn Marino #endif
73*86d7f5d3SJohn Marino
_errseg_modules_needed(struct dm_pool * mem,const struct lv_segment * seg __attribute ((unused)),struct dm_list * modules)74*86d7f5d3SJohn Marino static int _errseg_modules_needed(struct dm_pool *mem,
75*86d7f5d3SJohn Marino const struct lv_segment *seg __attribute((unused)),
76*86d7f5d3SJohn Marino struct dm_list *modules)
77*86d7f5d3SJohn Marino {
78*86d7f5d3SJohn Marino if (!str_list_add(mem, modules, "error")) {
79*86d7f5d3SJohn Marino log_error("error module string list allocation failed");
80*86d7f5d3SJohn Marino return 0;
81*86d7f5d3SJohn Marino }
82*86d7f5d3SJohn Marino
83*86d7f5d3SJohn Marino return 1;
84*86d7f5d3SJohn Marino }
85*86d7f5d3SJohn Marino
_errseg_destroy(const struct segment_type * segtype)86*86d7f5d3SJohn Marino static void _errseg_destroy(const struct segment_type *segtype)
87*86d7f5d3SJohn Marino {
88*86d7f5d3SJohn Marino dm_free((void *)segtype);
89*86d7f5d3SJohn Marino }
90*86d7f5d3SJohn Marino
91*86d7f5d3SJohn Marino static struct segtype_handler _error_ops = {
92*86d7f5d3SJohn Marino .name = _errseg_name,
93*86d7f5d3SJohn Marino .merge_segments = _errseg_merge_segments,
94*86d7f5d3SJohn Marino #ifdef DEVMAPPER_SUPPORT
95*86d7f5d3SJohn Marino .add_target_line = _errseg_add_target_line,
96*86d7f5d3SJohn Marino .target_present = _errseg_target_present,
97*86d7f5d3SJohn Marino #endif
98*86d7f5d3SJohn Marino .modules_needed = _errseg_modules_needed,
99*86d7f5d3SJohn Marino .destroy = _errseg_destroy,
100*86d7f5d3SJohn Marino };
101*86d7f5d3SJohn Marino
init_error_segtype(struct cmd_context * cmd)102*86d7f5d3SJohn Marino struct segment_type *init_error_segtype(struct cmd_context *cmd)
103*86d7f5d3SJohn Marino {
104*86d7f5d3SJohn Marino struct segment_type *segtype = dm_malloc(sizeof(*segtype));
105*86d7f5d3SJohn Marino
106*86d7f5d3SJohn Marino if (!segtype)
107*86d7f5d3SJohn Marino return_NULL;
108*86d7f5d3SJohn Marino
109*86d7f5d3SJohn Marino segtype->cmd = cmd;
110*86d7f5d3SJohn Marino segtype->ops = &_error_ops;
111*86d7f5d3SJohn Marino segtype->name = "error";
112*86d7f5d3SJohn Marino segtype->private = NULL;
113*86d7f5d3SJohn Marino segtype->flags = SEG_CAN_SPLIT | SEG_VIRTUAL | SEG_CANNOT_BE_ZEROED;
114*86d7f5d3SJohn Marino
115*86d7f5d3SJohn Marino log_very_verbose("Initialised segtype: %s", segtype->name);
116*86d7f5d3SJohn Marino
117*86d7f5d3SJohn Marino return segtype;
118*86d7f5d3SJohn Marino }
119