2 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * This file is part of LVM2.
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU Lesser General Public License v.2.1.
10 * You should have received a copy of the GNU Lesser General Public License
11 * along with this program; if not, write to the Free Software Foundation,
12 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #include "toolcontext.h"
19 #include "text_export.h"
20 #include "text_import.h"
24 #include "lvm-string.h"
28 static const char *_zero_name(const struct lv_segment *seg)
30 return seg->segtype->name;
33 static int _zero_merge_segments(struct lv_segment *seg1, struct lv_segment *seg2)
35 seg1->len += seg2->len;
36 seg1->area_len += seg2->area_len;
41 #ifdef DEVMAPPER_SUPPORT
42 static int _zero_add_target_line(struct dev_manager *dm __attribute__((unused)),
43 struct dm_pool *mem __attribute__((unused)),
44 struct cmd_context *cmd __attribute__((unused)),
45 void **target_state __attribute__((unused)),
46 struct lv_segment *seg __attribute__((unused)),
47 struct dm_tree_node *node,uint64_t len,
48 uint32_t *pvmove_mirror_count __attribute__((unused)))
50 return dm_tree_node_add_zero_target(node, len);
53 static int _zero_target_present(struct cmd_context *cmd,
54 const struct lv_segment *seg __attribute__((unused)),
55 unsigned *attributes __attribute__((unused)))
57 static int _zero_checked = 0;
58 static int _zero_present = 0;
61 _zero_present = target_present(cmd, "zero", 1);
69 static int _zero_modules_needed(struct dm_pool *mem,
70 const struct lv_segment *seg __attribute__((unused)),
71 struct dm_list *modules)
73 if (!str_list_add(mem, modules, "zero")) {
74 log_error("zero module string list allocation failed");
81 static void _zero_destroy(struct segment_type *segtype)
86 static struct segtype_handler _zero_ops = {
88 .merge_segments = _zero_merge_segments,
89 #ifdef DEVMAPPER_SUPPORT
90 .add_target_line = _zero_add_target_line,
91 .target_present = _zero_target_present,
93 .modules_needed = _zero_modules_needed,
94 .destroy = _zero_destroy,
97 struct segment_type *init_zero_segtype(struct cmd_context *cmd)
99 struct segment_type *segtype = dm_malloc(sizeof(*segtype));
105 segtype->ops = &_zero_ops;
106 segtype->name = "zero";
107 segtype->private = NULL;
108 segtype->flags = SEG_CAN_SPLIT | SEG_VIRTUAL | SEG_CANNOT_BE_ZEROED;
110 log_very_verbose("Initialised segtype: %s", segtype->name);