1/* $NetBSD: segtype.h,v 1.1.1.2 2009/12/02 00:25:42 haad Exp $ */ 2 3/* 4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. 5 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. 6 * 7 * This file is part of LVM2. 8 * 9 * This copyrighted material is made available to anyone wishing to use, 10 * modify, copy, or redistribute it subject to the terms and conditions 11 * of the GNU Lesser General Public License v.2.1. 12 * 13 * You should have received a copy of the GNU Lesser General Public License 14 * along with this program; if not, write to the Free Software Foundation, 15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 */ 17 18#ifndef _SEGTYPES_H 19#define _SEGTYPES_H 20 21#include "metadata-exported.h" 22 23struct segtype_handler; 24struct cmd_context; 25struct config_tree; 26struct lv_segment; 27struct formatter; 28struct config_node; 29struct dev_manager; 30 31/* Feature flags */ 32#define SEG_CAN_SPLIT 0x00000001U 33#define SEG_AREAS_STRIPED 0x00000002U 34#define SEG_AREAS_MIRRORED 0x00000004U 35#define SEG_SNAPSHOT 0x00000008U 36#define SEG_FORMAT1_SUPPORT 0x00000010U 37#define SEG_VIRTUAL 0x00000020U 38#define SEG_CANNOT_BE_ZEROED 0x00000040U 39#define SEG_MONITORED 0x00000080U 40#define SEG_UNKNOWN 0x80000000U 41 42#define seg_is_mirrored(seg) ((seg)->segtype->flags & SEG_AREAS_MIRRORED ? 1 : 0) 43#define seg_is_striped(seg) ((seg)->segtype->flags & SEG_AREAS_STRIPED ? 1 : 0) 44#define seg_is_snapshot(seg) ((seg)->segtype->flags & SEG_SNAPSHOT ? 1 : 0) 45#define seg_is_virtual(seg) ((seg)->segtype->flags & SEG_VIRTUAL ? 1 : 0) 46#define seg_can_split(seg) ((seg)->segtype->flags & SEG_CAN_SPLIT ? 1 : 0) 47#define seg_cannot_be_zeroed(seg) ((seg)->segtype->flags & SEG_CANNOT_BE_ZEROED ? 1 : 0) 48#define seg_monitored(seg) ((seg)->segtype->flags & SEG_MONITORED ? 1 : 0) 49#define seg_unknown(seg) ((seg)->segtype->flags & SEG_UNKNOWN ? 1 : 0) 50 51#define segtype_is_striped(segtype) ((segtype)->flags & SEG_AREAS_STRIPED ? 1 : 0) 52#define segtype_is_mirrored(segtype) ((segtype)->flags & SEG_AREAS_MIRRORED ? 1 : 0) 53#define segtype_is_virtual(segtype) ((segtype)->flags & SEG_VIRTUAL ? 1 : 0) 54 55struct segment_type { 56 struct dm_list list; /* Internal */ 57 struct cmd_context *cmd; /* lvm_register_segtype() sets this. */ 58 uint32_t flags; 59 struct segtype_handler *ops; 60 const char *name; 61 void *library; /* lvm_register_segtype() sets this. */ 62 void *private; /* For the segtype handler to use. */ 63}; 64 65struct segtype_handler { 66 const char *(*name) (const struct lv_segment * seg); 67 void (*display) (const struct lv_segment * seg); 68 int (*text_export) (const struct lv_segment * seg, 69 struct formatter * f); 70 int (*text_import_area_count) (struct config_node * sn, 71 uint32_t *area_count); 72 int (*text_import) (struct lv_segment * seg, 73 const struct config_node * sn, 74 struct dm_hash_table * pv_hash); 75 int (*merge_segments) (struct lv_segment * seg1, 76 struct lv_segment * seg2); 77 int (*add_target_line) (struct dev_manager *dm, struct dm_pool *mem, 78 struct cmd_context *cmd, void **target_state, 79 struct lv_segment *seg, 80 struct dm_tree_node *node, uint64_t len, 81 uint32_t *pvmove_mirror_count); 82 int (*target_percent) (void **target_state, 83 percent_range_t *percent_range, 84 struct dm_pool * mem, 85 struct cmd_context *cmd, 86 struct lv_segment *seg, char *params, 87 uint64_t *total_numerator, 88 uint64_t *total_denominator); 89 int (*target_present) (struct cmd_context *cmd, 90 const struct lv_segment *seg, 91 unsigned *attributes); 92 int (*modules_needed) (struct dm_pool *mem, 93 const struct lv_segment *seg, 94 struct dm_list *modules); 95 void (*destroy) (const struct segment_type * segtype); 96 int (*target_monitored) (struct lv_segment *seg, int *pending); 97 int (*target_monitor_events) (struct lv_segment *seg, int events); 98 int (*target_unmonitor_events) (struct lv_segment *seg, int events); 99}; 100 101struct segment_type *get_segtype_from_string(struct cmd_context *cmd, 102 const char *str); 103 104struct segtype_library; 105int lvm_register_segtype(struct segtype_library *seglib, 106 struct segment_type *segtype); 107 108struct segment_type *init_striped_segtype(struct cmd_context *cmd); 109struct segment_type *init_zero_segtype(struct cmd_context *cmd); 110struct segment_type *init_error_segtype(struct cmd_context *cmd); 111struct segment_type *init_free_segtype(struct cmd_context *cmd); 112struct segment_type *init_unknown_segtype(struct cmd_context *cmd, const char *name); 113 114#ifdef SNAPSHOT_INTERNAL 115struct segment_type *init_snapshot_segtype(struct cmd_context *cmd); 116#endif 117 118#ifdef MIRRORED_INTERNAL 119struct segment_type *init_mirrored_segtype(struct cmd_context *cmd); 120#endif 121 122#ifdef CRYPT_INTERNAL 123struct segment_type *init_crypt_segtype(struct cmd_context *cmd); 124#endif 125 126#endif 127