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