2004-05-05 01:25:57 +04:00
/*
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2015-09-22 20:03:33 +03:00
* Copyright ( C ) 2004 - 2015 Red Hat , Inc . All rights reserved .
2004-05-05 01:25:57 +04:00
*
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
2007-08-21 00:55:30 +04:00
* of the GNU Lesser General Public License v .2 .1 .
2004-05-05 01:25:57 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-05-05 01:25:57 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2004-05-05 01:25:57 +04:00
*/
# ifndef _SEGTYPES_H
# define _SEGTYPES_H
2009-10-01 04:35:29 +04:00
# include "metadata-exported.h"
2004-05-05 01:25:57 +04:00
struct segtype_handler ;
struct cmd_context ;
2011-08-30 18:55:15 +04:00
struct dm_config_tree ;
2004-05-05 01:25:57 +04:00
struct lv_segment ;
2011-06-17 18:14:19 +04:00
struct lv_activate_opts ;
2004-05-05 01:25:57 +04:00
struct formatter ;
2011-08-30 18:55:15 +04:00
struct dm_config_node ;
2004-05-05 01:25:57 +04:00
struct dev_manager ;
/* Feature flags */
2015-09-22 23:10:46 +03:00
# define SEG_CAN_SPLIT 0x0000000000000001ULL
# define SEG_AREAS_STRIPED 0x0000000000000002ULL
# define SEG_AREAS_MIRRORED 0x0000000000000004ULL
# define SEG_SNAPSHOT 0x0000000000000008ULL
# define SEG_FORMAT1_SUPPORT 0x0000000000000010ULL
# define SEG_VIRTUAL 0x0000000000000020ULL
# define SEG_CANNOT_BE_ZEROED 0x0000000000000040ULL
# define SEG_MONITORED 0x0000000000000080ULL
# define SEG_REPLICATOR 0x0000000000000100ULL
# define SEG_REPLICATOR_DEV 0x0000000000000200ULL
# define SEG_RAID 0x0000000000000400ULL
# define SEG_THIN_POOL 0x0000000000000800ULL
# define SEG_THIN_VOLUME 0x0000000000001000ULL
# define SEG_CACHE 0x0000000000002000ULL
# define SEG_CACHE_POOL 0x0000000000004000ULL
# define SEG_MIRROR 0x0000000000008000ULL
# define SEG_ONLY_EXCLUSIVE 0x0000000000010000ULL /* In cluster only exlusive activation */
# define SEG_CAN_ERROR_WHEN_FULL 0x0000000000020000ULL
2015-09-24 22:17:57 +03:00
# define SEG_RAID1 0x0000000000100000ULL
# define SEG_RAID10 0x0000000000200000ULL
# define SEG_RAID4 0x0000000000400000ULL
# define SEG_RAID5_N 0x0000000000800000ULL
# define SEG_RAID5_LA 0x0000000001000000ULL
# define SEG_RAID5_LS 0x0000000002000000ULL
# define SEG_RAID5_RA 0x0000000004000000ULL
# define SEG_RAID5_RS 0x0000000008000000ULL
# define SEG_RAID5 SEG_RAID5_LS
# define SEG_RAID6_NC 0x0000000010000000ULL
# define SEG_RAID6_NR 0x0000000020000000ULL
# define SEG_RAID6_ZR 0x0000000040000000ULL
# define SEG_RAID6_LA_6 0x0000000080000000ULL
# define SEG_RAID6_LS_6 0x0000000100000000ULL
# define SEG_RAID6_RA_6 0x0000000200000000ULL
# define SEG_RAID6_RS_6 0x0000000400000000ULL
# define SEG_RAID6_N_6 0x0000000800000000ULL
# define SEG_RAID6 SEG_RAID6_ZR
2015-09-22 23:10:46 +03:00
# define SEG_UNKNOWN 0x8000000000000000ULL
2015-09-22 20:03:33 +03:00
# define SEG_TYPE_NAME_LINEAR "linear"
# define SEG_TYPE_NAME_STRIPED "striped"
# define SEG_TYPE_NAME_MIRROR "mirror"
2015-09-22 21:04:12 +03:00
# define SEG_TYPE_NAME_SNAPSHOT "snapshot"
# define SEG_TYPE_NAME_THIN "thin"
# define SEG_TYPE_NAME_THIN_POOL "thin-pool"
# define SEG_TYPE_NAME_CACHE "cache"
# define SEG_TYPE_NAME_CACHE_POOL "cache-pool"
# define SEG_TYPE_NAME_ERROR "error"
# define SEG_TYPE_NAME_FREE "free"
# define SEG_TYPE_NAME_ZERO "zero"
# define SEG_TYPE_NAME_RAID "raid"
2015-09-24 21:52:22 +03:00
# define SEG_TYPE_NAME_RAID0 "raid0"
2015-09-22 20:03:33 +03:00
# define SEG_TYPE_NAME_RAID1 "raid1"
# define SEG_TYPE_NAME_RAID10 "raid10"
# define SEG_TYPE_NAME_RAID4 "raid4"
# define SEG_TYPE_NAME_RAID5 "raid5"
# define SEG_TYPE_NAME_RAID5_LA "raid5_la"
# define SEG_TYPE_NAME_RAID5_LS "raid5_ls"
# define SEG_TYPE_NAME_RAID5_RA "raid5_ra"
# define SEG_TYPE_NAME_RAID5_RS "raid5_rs"
# define SEG_TYPE_NAME_RAID6 "raid6"
# define SEG_TYPE_NAME_RAID6_NC "raid6_nc"
# define SEG_TYPE_NAME_RAID6_NR "raid6_nr"
# define SEG_TYPE_NAME_RAID6_ZR "raid6_zr"
# define segtype_is_linear(segtype) (!strcmp(segtype->name, SEG_TYPE_NAME_LINEAR))
2014-01-27 15:27:16 +04:00
# define segtype_is_cache(segtype) ((segtype)->flags & SEG_CACHE ? 1 : 0)
# define segtype_is_cache_pool(segtype) ((segtype)->flags & SEG_CACHE_POOL ? 1 : 0)
2013-12-10 13:45:21 +04:00
# define segtype_is_mirrored(segtype) ((segtype)->flags & SEG_AREAS_MIRRORED ? 1 : 0)
2014-09-16 03:13:46 +04:00
# define segtype_is_mirror(segtype) ((segtype)->flags & SEG_MIRROR ? 1 : 0)
2014-05-23 16:24:28 +04:00
# define segtype_is_pool(segtype) ((segtype)->flags & (SEG_CACHE_POOL | SEG_THIN_POOL) ? 1 : 0)
2013-12-10 13:45:21 +04:00
# define segtype_is_raid(segtype) ((segtype)->flags & SEG_RAID ? 1 : 0)
2015-09-24 22:26:33 +03:00
# define segtype_is_raid1(segtype) ((segtype)->flags & SEG_RAID1 ? 1 : 0)
# define segtype_is_raid4(segtype) ((segtype)->flags & SEG_RAID4 ? 1 : 0)
# define segtype_is_any_raid5(segtype) ((segtype)->flags & \
( SEG_RAID5_LS | SEG_RAID5_LA | SEG_RAID5_RS | SEG_RAID5_RA | SEG_RAID5_N ) ? 1 : 0 )
# define segtype_is_raid5_la(segtype) ((segtype)->flags & SEG_RAID5_LA ? 1 : 0)
# define segtype_is_raid5_ra(segtype) ((segtype)->flags & SEG_RAID5_RA ? 1 : 0)
# define segtype_is_raid5_ls(segtype) ((segtype)->flags & SEG_RAID5_LS ? 1 : 0)
# define segtype_is_raid5_rs(segtype) ((segtype)->flags & SEG_RAID5_RS ? 1 : 0)
# define segtype_is_any_raid6(segtype) ((segtype)->flags & \
( SEG_RAID6_ZR | SEG_RAID6_NC | SEG_RAID6_NR | \
SEG_RAID6_LA_6 | SEG_RAID6_LS_6 | SEG_RAID6_RA_6 | SEG_RAID6_RS_6 | SEG_RAID6_N_6 ) ? 1 : 0 )
# define segtype_is_raid6_nc(segtype) ((segtype)->flags & SEG_RAID6_NC ? 1 : 0)
# define segtype_is_raid6_nr(segtype) ((segtype)->flags & SEG_RAID6_NR ? 1 : 0)
# define segtype_is_raid6_zr(segtype) ((segtype)->flags & SEG_RAID6_ZR ? 1 : 0)
# define segtype_is_raid10(segtype) ((segtype)->flags & SEG_RAID10 ? 1 : 0)
# define segtype_is_snapshot(segtype) ((segtype)->flags & SEG_SNAPSHOT ? 1 : 0)
2013-12-10 13:45:21 +04:00
# define segtype_is_striped(segtype) ((segtype)->flags & SEG_AREAS_STRIPED ? 1 : 0)
# define segtype_is_thin(segtype) ((segtype)->flags & (SEG_THIN_POOL|SEG_THIN_VOLUME) ? 1 : 0)
# define segtype_is_thin_pool(segtype) ((segtype)->flags & SEG_THIN_POOL ? 1 : 0)
# define segtype_is_thin_volume(segtype) ((segtype)->flags & SEG_THIN_VOLUME ? 1 : 0)
# define segtype_is_virtual(segtype) ((segtype)->flags & SEG_VIRTUAL ? 1 : 0)
2014-10-11 00:22:43 +04:00
# define segtype_is_unknown(segtype) ((segtype)->flags & SEG_UNKNOWN ? 1 : 0)
2013-12-10 13:45:21 +04:00
2014-01-27 15:27:16 +04:00
# define seg_is_cache(seg) segtype_is_cache((seg)->segtype)
# define seg_is_cache_pool(seg) segtype_is_cache_pool((seg)->segtype)
2013-12-10 13:45:21 +04:00
# define seg_is_linear(seg) (seg_is_striped(seg) && ((seg)->area_count == 1))
2014-09-16 03:13:46 +04:00
# define seg_is_mirror(seg) segtype_is_mirror((seg)->segtype)
2013-12-10 13:45:21 +04:00
# define seg_is_mirrored(seg) segtype_is_mirrored((seg)->segtype)
2014-05-23 16:24:28 +04:00
# define seg_is_pool(seg) segtype_is_pool((seg)->segtype)
2013-12-10 13:45:21 +04:00
# define seg_is_raid(seg) segtype_is_raid((seg)->segtype)
2015-09-24 16:59:07 +03:00
# define seg_is_raid1(seg) segtype_is_raid1((seg)->segtype)
# define seg_is_raid4(seg) segtype_is_raid4((seg)->segtype)
# define seg_is_any_raid5(seg) segtype_is_any_raid5((seg)->segtype)
# define seg_is_raid5_la(seg) segtype_is_raid5_la((seg)->segtype)
# define seg_is_raid5_ra(seg) segtype_is_raid5_ra((seg)->segtype)
# define seg_is_raid5_ls(seg) segtype_is_raid5_ls((seg)->segtype)
# define seg_is_raid5_rs(seg) segtype_is_raid5_rs((seg)->segtype)
# define seg_is_any_raid6(seg) segtype_is_any_raid6((seg)->segtype)
# define seg_is_raid6_zr(seg) segtype_is_raid6_zr((seg)->segtype)
# define seg_is_raid6_nr(seg) segtype_is_raid6_nr((seg)->segtype)
# define seg_is_raid6_nc(seg) segtype_is_raid6_nc((seg)->segtype)
# define seg_is_raid10(seg) segtype_is_raid10((seg)->segtype)
2010-05-21 16:36:30 +04:00
# define seg_is_replicator(seg) ((seg)->segtype->flags & SEG_REPLICATOR ? 1 : 0)
# define seg_is_replicator_dev(seg) ((seg)->segtype->flags & SEG_REPLICATOR_DEV ? 1 : 0)
2015-09-24 22:26:33 +03:00
# define seg_is_snapshot(seg) segtype_is_snapshot((seg)->segtype)
2013-12-10 13:45:21 +04:00
# define seg_is_striped(seg) segtype_is_striped((seg)->segtype)
# define seg_is_thin(seg) segtype_is_thin((seg)->segtype)
# define seg_is_thin_pool(seg) segtype_is_thin_pool((seg)->segtype)
# define seg_is_thin_volume(seg) segtype_is_thin_volume((seg)->segtype)
# define seg_is_virtual(seg) segtype_is_virtual((seg)->segtype)
2014-10-11 00:22:43 +04:00
# define seg_unknown(seg) segtype_is_unknown((seg)->segtype)
2005-05-09 20:59:01 +04:00
# define seg_can_split(seg) ((seg)->segtype->flags & SEG_CAN_SPLIT ? 1 : 0)
2005-11-09 01:52:26 +03:00
# define seg_cannot_be_zeroed(seg) ((seg)->segtype->flags & SEG_CANNOT_BE_ZEROED ? 1 : 0)
2007-01-12 23:38:30 +03:00
# define seg_monitored(seg) ((seg)->segtype->flags & SEG_MONITORED ? 1 : 0)
2014-11-10 20:44:37 +03:00
# define seg_only_exclusive(seg) ((seg)->segtype->flags & SEG_ONLY_EXCLUSIVE ? 1 : 0)
2015-01-13 17:23:03 +03:00
# define seg_can_error_when_full(seg) ((seg)->segtype->flags & SEG_CAN_ERROR_WHEN_FULL ? 1 : 0)
2005-05-09 20:59:01 +04:00
2004-05-05 01:25:57 +04:00
struct segment_type {
2009-07-08 16:36:01 +04:00
struct dm_list list ; /* Internal */
2011-08-03 02:07:20 +04:00
2015-09-22 20:03:33 +03:00
uint64_t flags ;
2015-09-24 22:17:57 +03:00
uint32_t parity_devs ; /* Parity drives required by segtype */
2011-08-03 02:07:20 +04:00
2004-05-05 01:25:57 +04:00
struct segtype_handler * ops ;
const char * name ;
2011-08-03 02:07:20 +04:00
2009-07-08 16:36:01 +04:00
void * library ; /* lvm_register_segtype() sets this. */
void * private ; /* For the segtype handler to use. */
2004-05-05 01:25:57 +04:00
} ;
struct segtype_handler {
const char * ( * name ) ( const struct lv_segment * seg ) ;
2011-06-17 18:14:19 +04:00
const char * ( * target_name ) ( const struct lv_segment * seg ,
const struct lv_activate_opts * laopts ) ;
2004-05-05 01:25:57 +04:00
void ( * display ) ( const struct lv_segment * seg ) ;
int ( * text_export ) ( const struct lv_segment * seg ,
struct formatter * f ) ;
2011-08-30 18:55:15 +04:00
int ( * text_import_area_count ) ( const struct dm_config_node * sn ,
2004-05-05 01:25:57 +04:00
uint32_t * area_count ) ;
int ( * text_import ) ( struct lv_segment * seg ,
2011-08-30 18:55:15 +04:00
const struct dm_config_node * sn ,
2005-10-17 03:03:59 +04:00
struct dm_hash_table * pv_hash ) ;
2004-05-05 01:25:57 +04:00
int ( * merge_segments ) ( struct lv_segment * seg1 ,
struct lv_segment * seg2 ) ;
2005-11-09 01:52:26 +03:00
int ( * add_target_line ) ( struct dev_manager * dm , struct dm_pool * mem ,
2011-06-17 18:14:19 +04:00
struct cmd_context * cmd , void * * target_state ,
struct lv_segment * seg ,
const struct lv_activate_opts * laopts ,
struct dm_tree_node * node , uint64_t len ,
uint32_t * pvmove_mirror_count ) ;
2010-01-15 19:35:26 +03:00
int ( * target_status_compatible ) ( const char * type ) ;
2015-11-30 23:24:31 +03:00
int ( * check_transient_status ) ( struct dm_pool * mem ,
struct lv_segment * seg , char * params ) ;
2009-10-01 04:35:29 +04:00
int ( * target_percent ) ( void * * target_state ,
2014-06-09 14:08:27 +04:00
dm_percent_t * percent ,
2009-10-01 04:35:29 +04:00
struct dm_pool * mem ,
2006-05-17 00:53:13 +04:00
struct cmd_context * cmd ,
2006-05-16 20:48:31 +04:00
struct lv_segment * seg , char * params ,
2004-05-05 01:25:57 +04:00
uint64_t * total_numerator ,
2008-07-15 04:25:52 +04:00
uint64_t * total_denominator ) ;
2009-02-28 23:04:24 +03:00
int ( * target_present ) ( struct cmd_context * cmd ,
const struct lv_segment * seg ,
2008-04-07 14:23:47 +04:00
unsigned * attributes ) ;
2006-10-03 21:55:20 +04:00
int ( * modules_needed ) ( struct dm_pool * mem ,
const struct lv_segment * seg ,
2008-11-04 01:14:30 +03:00
struct dm_list * modules ) ;
2010-12-20 16:32:49 +03:00
void ( * destroy ) ( struct segment_type * segtype ) ;
2007-01-20 01:21:45 +03:00
int ( * target_monitored ) ( struct lv_segment * seg , int * pending ) ;
2007-01-24 19:51:24 +03:00
int ( * target_monitor_events ) ( struct lv_segment * seg , int events ) ;
int ( * target_unmonitor_events ) ( struct lv_segment * seg , int events ) ;
2004-05-05 01:25:57 +04:00
} ;
struct segment_type * get_segtype_from_string ( struct cmd_context * cmd ,
const char * str ) ;
2009-07-08 16:36:01 +04:00
struct segtype_library ;
int lvm_register_segtype ( struct segtype_library * seglib ,
struct segment_type * segtype ) ;
2004-05-05 01:25:57 +04:00
struct segment_type * init_striped_segtype ( struct cmd_context * cmd ) ;
2004-05-11 20:01:58 +04:00
struct segment_type * init_zero_segtype ( struct cmd_context * cmd ) ;
struct segment_type * init_error_segtype ( struct cmd_context * cmd ) ;
2008-06-25 20:52:27 +04:00
struct segment_type * init_free_segtype ( struct cmd_context * cmd ) ;
2011-08-03 02:07:20 +04:00
struct segment_type * init_unknown_segtype ( struct cmd_context * cmd ,
const char * name ) ;
2014-02-27 17:46:11 +04:00
# define RAID_FEATURE_RAID10 (1U << 0) /* version 1.3 */
2015-09-24 21:52:22 +03:00
# define RAID_FEATURE_RAID0 (1U << 1) /* version 1.7 */
# define RAID_FEATURE_RESHAPING (1U << 2) /* version 1.8 */
2014-02-27 17:46:11 +04:00
2011-08-03 02:07:20 +04:00
# ifdef RAID_INTERNAL
2011-08-24 17:41:46 +04:00
int init_raid_segtypes ( struct cmd_context * cmd , struct segtype_library * seglib ) ;
2011-08-03 02:07:20 +04:00
# endif
2004-05-05 01:25:57 +04:00
2010-05-21 16:36:30 +04:00
# ifdef REPLICATOR_INTERNAL
2011-08-24 17:41:46 +04:00
int init_replicator_segtype ( struct cmd_context * cmd , struct segtype_library * seglib ) ;
2010-05-21 16:36:30 +04:00
# endif
2014-02-27 17:46:11 +04:00
# define THIN_FEATURE_DISCARDS (1U << 0)
# define THIN_FEATURE_EXTERNAL_ORIGIN (1U << 1)
# define THIN_FEATURE_HELD_ROOT (1U << 2)
# define THIN_FEATURE_BLOCK_SIZE (1U << 3)
# define THIN_FEATURE_DISCARDS_NON_POWER_2 (1U << 4)
# define THIN_FEATURE_METADATA_RESIZE (1U << 5)
# define THIN_FEATURE_EXTERNAL_ORIGIN_EXTEND (1U << 6)
2015-01-13 17:23:03 +03:00
# define THIN_FEATURE_ERROR_IF_NO_SPACE (1U << 7)
2014-02-27 17:46:11 +04:00
2011-08-25 14:00:09 +04:00
# ifdef THIN_INTERNAL
int init_thin_segtypes ( struct cmd_context * cmd , struct segtype_library * seglib ) ;
# endif
2014-01-27 15:27:16 +04:00
# ifdef CACHE_INTERNAL
int init_cache_segtypes ( struct cmd_context * cmd , struct segtype_library * seglib ) ;
# endif
2015-07-23 12:32:09 +03:00
# define CACHE_FEATURE_POLICY_MQ (1U << 0)
# define CACHE_FEATURE_POLICY_SMQ (1U << 1)
2014-02-27 17:46:11 +04:00
# define SNAPSHOT_FEATURE_FIXED_LEAK (1U << 0) /* version 1.12 */
2004-05-05 01:25:57 +04:00
# ifdef SNAPSHOT_INTERNAL
struct segment_type * init_snapshot_segtype ( struct cmd_context * cmd ) ;
# endif
2014-02-27 17:46:11 +04:00
# define MIRROR_LOG_CLUSTERED (1U << 0)
2004-05-05 01:25:57 +04:00
# ifdef MIRRORED_INTERNAL
struct segment_type * init_mirrored_segtype ( struct cmd_context * cmd ) ;
# endif
2004-09-16 22:40:56 +04:00
# ifdef CRYPT_INTERNAL
struct segment_type * init_crypt_segtype ( struct cmd_context * cmd ) ;
# endif
2004-05-05 01:25:57 +04:00
# endif