1 /* $NetBSD: zero.c,v 1.1.1.1 2008/12/22 00:17:52 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 "metadata.h" 29 30 static const char *_zero_name(const struct lv_segment *seg) 31 { 32 return seg->segtype->name; 33 } 34 35 static int _zero_merge_segments(struct lv_segment *seg1, struct lv_segment *seg2) 36 { 37 seg1->len += seg2->len; 38 seg1->area_len += seg2->area_len; 39 40 return 1; 41 } 42 43 #ifdef DEVMAPPER_SUPPORT 44 static int _zero_add_target_line(struct dev_manager *dm __attribute((unused)), 45 struct dm_pool *mem __attribute((unused)), 46 struct cmd_context *cmd __attribute((unused)), 47 void **target_state __attribute((unused)), 48 struct lv_segment *seg __attribute((unused)), 49 struct dm_tree_node *node,uint64_t len, 50 uint32_t *pvmove_mirror_count __attribute((unused))) 51 { 52 return dm_tree_node_add_zero_target(node, len); 53 } 54 55 static int _zero_target_present(const struct lv_segment *seg __attribute((unused)), 56 unsigned *attributes __attribute((unused))) 57 { 58 static int _zero_checked = 0; 59 static int _zero_present = 0; 60 61 if (!_zero_checked) 62 _zero_present = target_present("zero", 0); 63 64 _zero_checked = 1; 65 66 return _zero_present; 67 } 68 #endif 69 70 static int _zero_modules_needed(struct dm_pool *mem, 71 const struct lv_segment *seg __attribute((unused)), 72 struct dm_list *modules) 73 { 74 if (!str_list_add(mem, modules, "zero")) { 75 log_error("zero module string list allocation failed"); 76 return 0; 77 } 78 79 return 1; 80 } 81 82 static void _zero_destroy(const struct segment_type *segtype) 83 { 84 dm_free((void *) segtype); 85 } 86 87 static struct segtype_handler _zero_ops = { 88 .name = _zero_name, 89 .merge_segments = _zero_merge_segments, 90 #ifdef DEVMAPPER_SUPPORT 91 .add_target_line = _zero_add_target_line, 92 .target_present = _zero_target_present, 93 #endif 94 .modules_needed = _zero_modules_needed, 95 .destroy = _zero_destroy, 96 }; 97 98 struct segment_type *init_zero_segtype(struct cmd_context *cmd) 99 { 100 struct segment_type *segtype = dm_malloc(sizeof(*segtype)); 101 102 if (!segtype) 103 return_NULL; 104 105 segtype->cmd = cmd; 106 segtype->ops = &_zero_ops; 107 segtype->name = "zero"; 108 segtype->private = NULL; 109 segtype->flags = SEG_CAN_SPLIT | SEG_VIRTUAL | SEG_CANNOT_BE_ZEROED; 110 111 log_very_verbose("Initialised segtype: %s", segtype->name); 112 113 return segtype; 114 } 115