1 /* $NetBSD: errseg.c,v 1.1.1.1 2008/12/22 00:17:57 haad Exp $ */ 2 3 /* 4 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. 5 * 6 * This file is part of LVM2. 7 * 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. 11 * 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 15 */ 16 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" 30 31 static const char *_errseg_name(const struct lv_segment *seg) 32 { 33 return seg->segtype->name; 34 } 35 36 static int _errseg_merge_segments(struct lv_segment *seg1, struct lv_segment *seg2) 37 { 38 seg1->len += seg2->len; 39 seg1->area_len += seg2->area_len; 40 41 return 1; 42 } 43 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))) 52 { 53 return dm_tree_node_add_error_target(node, len); 54 } 55 56 static int _errseg_target_present(const struct lv_segment *seg __attribute((unused)), 57 unsigned *attributes __attribute((unused))) 58 { 59 static int _errseg_checked = 0; 60 static int _errseg_present = 0; 61 62 /* Reported truncated in older kernels */ 63 if (!_errseg_checked && 64 (target_present("error", 0) || target_present("erro", 0))) 65 _errseg_present = 1; 66 67 _errseg_checked = 1; 68 return _errseg_present; 69 } 70 #endif 71 72 static int _errseg_modules_needed(struct dm_pool *mem, 73 const struct lv_segment *seg __attribute((unused)), 74 struct dm_list *modules) 75 { 76 if (!str_list_add(mem, modules, "error")) { 77 log_error("error module string list allocation failed"); 78 return 0; 79 } 80 81 return 1; 82 } 83 84 static void _errseg_destroy(const struct segment_type *segtype) 85 { 86 dm_free((void *)segtype); 87 } 88 89 static struct segtype_handler _error_ops = { 90 .name = _errseg_name, 91 .merge_segments = _errseg_merge_segments, 92 #ifdef DEVMAPPER_SUPPORT 93 .add_target_line = _errseg_add_target_line, 94 .target_present = _errseg_target_present, 95 #endif 96 .modules_needed = _errseg_modules_needed, 97 .destroy = _errseg_destroy, 98 }; 99 100 struct segment_type *init_error_segtype(struct cmd_context *cmd) 101 { 102 struct segment_type *segtype = dm_malloc(sizeof(*segtype)); 103 104 if (!segtype) 105 return_NULL; 106 107 segtype->cmd = cmd; 108 segtype->ops = &_error_ops; 109 segtype->name = "error"; 110 segtype->private = NULL; 111 segtype->flags = SEG_CAN_SPLIT | SEG_VIRTUAL | SEG_CANNOT_BE_ZEROED; 112 113 log_very_verbose("Initialised segtype: %s", segtype->name); 114 115 return segtype; 116 } 117