Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / lib / error / errseg.c
blob055ec548ba0114355f2aa76088d27df6e137512c
1 /* $NetBSD$ */
3 /*
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
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"
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;
41 return 1;
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)))
67 _errseg_present = 1;
69 _errseg_checked = 1;
70 return _errseg_present;
72 #endif
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");
80 return 0;
83 return 1;
86 static void _errseg_destroy(const struct segment_type *segtype)
88 dm_free((void *)segtype);
91 static struct segtype_handler _error_ops = {
92 .name = _errseg_name,
93 .merge_segments = _errseg_merge_segments,
94 #ifdef DEVMAPPER_SUPPORT
95 .add_target_line = _errseg_add_target_line,
96 .target_present = _errseg_target_present,
97 #endif
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));
106 if (!segtype)
107 return_NULL;
109 segtype->cmd = cmd;
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);
117 return segtype;