2001-09-25 16:49:28 +04:00
/*
2004-03-30 23:35:44 +04:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
* Copyright ( C ) 2004 Red Hat , Inc . All rights reserved .
2001-09-25 16:49:28 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
2001-09-25 16:49:28 +04:00
*
2004-03-30 23:35:44 +04:00
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
* of the GNU General Public License v .2 .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
/*
2001-10-02 02:12:10 +04:00
* This is the in core representation of a volume group and its
2001-09-28 17:15:30 +04:00
* associated physical and logical volumes .
2001-09-25 16:49:28 +04:00
*/
2001-10-01 19:14:39 +04:00
# ifndef _LVM_METADATA_H
# define _LVM_METADATA_H
2001-09-25 16:49:28 +04:00
2002-11-18 17:04:08 +03:00
# include "ctype.h"
2001-10-01 20:21:21 +04:00
# include "dev-cache.h"
2001-10-12 14:32:06 +04:00
# include "uuid.h"
2002-12-20 02:25:55 +03:00
2001-10-02 21:09:05 +04:00
# define NAME_LEN 128
2001-12-03 19:27:16 +03:00
# define MAX_STRIPES 128
2002-11-18 17:04:08 +03:00
# define SECTOR_SHIFT 9L
# define SECTOR_SIZE ( 1L << SECTOR_SHIFT )
2003-03-24 21:08:53 +03:00
# define STRIPE_SIZE_MIN ( getpagesize() >> SECTOR_SHIFT) /* PAGESIZE in sectors */
2002-11-18 17:04:08 +03:00
# define STRIPE_SIZE_MAX ( 512L * 1024L >> SECTOR_SHIFT) /* 512 KB in sectors */
# define PV_MIN_SIZE ( 512L * 1024L >> SECTOR_SHIFT) /* 512 KB in sectors */
# define PE_ALIGN (65536UL >> SECTOR_SHIFT) /* PE alignment */
2003-11-06 19:58:38 +03:00
# define MAX_RESTRICTED_LVS 255 /* Used by FMT_RESTRICTED_LVIDS */
2001-10-02 02:12:10 +04:00
/* Various flags */
/* Note that the bits no longer necessarily correspond to LVM1 disk format */
2002-11-18 17:04:08 +03:00
# define PARTIAL_VG 0x00000001 /* VG */
# define EXPORTED_VG 0x00000002 /* VG PV */
# define RESIZEABLE_VG 0x00000004 /* VG */
2002-07-11 18:36:45 +04:00
2002-11-18 17:04:08 +03:00
/* May any free extents on this PV be used or must they be left free? */
# define ALLOCATABLE_PV 0x00000008 /* PV */
2001-10-02 02:12:10 +04:00
2002-11-18 17:04:08 +03:00
# define SPINDOWN_LV 0x00000010 /* LV */
# define BADBLOCK_ON 0x00000020 /* LV */
# define VISIBLE_LV 0x00000040 /* LV */
# define FIXED_MINOR 0x00000080 /* LV */
/* FIXME Remove when metadata restructuring is completed */
2005-04-07 16:39:44 +04:00
# define SNAPSHOT 0x00001000 /* LV - internal use only */
2003-05-06 16:06:02 +04:00
# define PVMOVE 0x00002000 /* VG LV SEG */
# define LOCKED 0x00004000 /* LV */
2004-05-05 01:25:57 +04:00
# define MIRRORED 0x00008000 /* LV - internal use only */
2004-05-11 20:01:58 +04:00
# define VIRTUAL 0x00010000 /* LV - internal use only */
2005-06-01 20:51:55 +04:00
# define MIRROR_LOG 0x00020000 /* LV */
2005-06-03 18:49:51 +04:00
# define MIRROR_IMAGE 0x00040000 /* LV */
2005-08-15 03:18:28 +04:00
# define ACTIVATE_EXCL 0x00080000 /* LV - internal use only */
2005-10-31 05:37:29 +03:00
# define PRECOMMITTED 0x00100000 /* VG - internal use only */
2002-04-24 22:20:51 +04:00
2002-11-18 17:04:08 +03:00
# define LVM_READ 0x00000100 /* LV VG */
# define LVM_WRITE 0x00000200 /* LV VG */
# define CLUSTERED 0x00000400 /* VG */
# define SHARED 0x00000800 /* VG */
2001-10-02 02:12:10 +04:00
2002-11-18 17:04:08 +03:00
/* Format features flags */
# define FMT_SEGMENTS 0x00000001 /* Arbitrary segment params? */
# define FMT_MDAS 0x00000002 /* Proper metadata areas? */
2003-11-06 19:58:38 +03:00
# define FMT_TAGS 0x00000004 /* Tagging? */
# define FMT_UNLIMITED_VOLS 0x00000008 /* Unlimited PVs/LVs? */
# define FMT_RESTRICTED_LVIDS 0x00000010 /* LVID <= 255 */
2003-11-06 23:15:13 +03:00
# define FMT_ORPHAN_ALLOCATABLE 0x00000020 /* Orphan PV allocatable? */
2005-04-06 22:59:55 +04:00
# define FMT_PRECOMMIT 0x00000040 /* Supports pre-commit? */
2005-10-31 05:37:29 +03:00
# define FMT_RESIZE_PV 0x00000080 /* Supports pvresize? */
2004-05-05 01:25:57 +04:00
2002-07-11 18:21:49 +04:00
typedef enum {
2004-05-19 02:12:53 +04:00
ALLOC_INVALID ,
ALLOC_INHERIT ,
ALLOC_CONTIGUOUS ,
ALLOC_NORMAL ,
ALLOC_ANYWHERE
2002-07-11 18:21:49 +04:00
} alloc_policy_t ;
2003-04-25 02:23:24 +04:00
typedef enum {
2005-06-14 21:54:48 +04:00
AREA_UNASSIGNED = 0 ,
2003-04-25 02:23:24 +04:00
AREA_PV ,
AREA_LV
} area_type_t ;
2001-11-12 15:16:57 +03:00
struct cmd_context ;
2002-11-18 17:04:08 +03:00
struct format_handler ;
struct labeller ;
2001-11-12 15:16:57 +03:00
2002-04-24 22:20:51 +04:00
struct format_type {
2002-11-18 17:04:08 +03:00
struct list list ;
2002-04-24 22:20:51 +04:00
struct cmd_context * cmd ;
struct format_handler * ops ;
2002-11-18 17:04:08 +03:00
struct labeller * labeller ;
2002-04-24 22:20:51 +04:00
const char * name ;
2002-11-18 17:04:08 +03:00
const char * alias ;
2002-04-24 22:20:51 +04:00
uint32_t features ;
2002-11-18 17:04:08 +03:00
void * library ;
2002-04-24 22:20:51 +04:00
void * private ;
} ;
2005-04-20 00:52:35 +04:00
struct pv_segment {
struct list list ; /* Member of pv->segments: ordered list
* covering entire data area on this PV */
struct physical_volume * pv ;
uint32_t pe ;
uint32_t len ;
struct lv_segment * lvseg ; /* NULL if free space */
uint32_t lv_area ; /* Index to area in LV segment */
} ;
2002-11-18 17:04:08 +03:00
struct physical_volume {
struct id id ;
struct device * dev ;
2002-12-20 02:25:55 +03:00
const struct format_type * fmt ;
const char * vg_name ;
2002-11-18 17:04:08 +03:00
uint32_t status ;
uint64_t size ;
/* physical extents */
2002-12-20 02:25:55 +03:00
uint32_t pe_size ;
2002-11-18 17:04:08 +03:00
uint64_t pe_start ;
uint32_t pe_count ;
uint32_t pe_alloc_count ;
2004-03-08 20:19:15 +03:00
2005-04-20 00:52:35 +04:00
struct list segments ; /* Ordered pv_segments covering complete PV */
2004-03-08 20:19:15 +03:00
struct list tags ;
2002-11-18 17:04:08 +03:00
} ;
struct metadata_area ;
struct format_instance ;
/* Per-format per-metadata area operations */
struct metadata_area_ops {
struct volume_group * ( * vg_read ) ( struct format_instance * fi ,
const char * vg_name ,
struct metadata_area * mda ) ;
2005-04-06 22:59:55 +04:00
struct volume_group * ( * vg_read_precommit ) ( struct format_instance * fi ,
const char * vg_name ,
struct metadata_area * mda ) ;
2002-11-18 17:04:08 +03:00
/*
* Write out complete VG metadata . You must ensure internal
* consistency before calling . eg . PEs can ' t refer to PVs not
* part of the VG .
*
* It is also the responsibility of the caller to ensure external
* consistency , eg by calling pv_write ( ) if removing PVs from
* a VG or calling vg_write ( ) a second time if splitting a VG
* into two .
*
* vg_write ( ) should not read or write from any PVs not included
* in the volume_group structure it is handed .
* ( format1 currently breaks this rule . )
*/
int ( * vg_write ) ( struct format_instance * fid , struct volume_group * vg ,
struct metadata_area * mda ) ;
2005-04-06 22:59:55 +04:00
int ( * vg_precommit ) ( struct format_instance * fid ,
struct volume_group * vg ,
struct metadata_area * mda ) ;
2002-11-18 17:04:08 +03:00
int ( * vg_commit ) ( struct format_instance * fid ,
struct volume_group * vg , struct metadata_area * mda ) ;
2003-07-05 02:34:56 +04:00
int ( * vg_revert ) ( struct format_instance * fid ,
struct volume_group * vg , struct metadata_area * mda ) ;
2002-11-18 17:04:08 +03:00
int ( * vg_remove ) ( struct format_instance * fi , struct volume_group * vg ,
struct metadata_area * mda ) ;
} ;
2002-04-24 22:20:51 +04:00
struct metadata_area {
struct list list ;
2002-11-18 17:04:08 +03:00
struct metadata_area_ops * ops ;
2002-04-24 22:20:51 +04:00
void * metadata_locn ;
} ;
struct format_instance {
2002-12-20 02:25:55 +03:00
const struct format_type * fmt ;
2002-04-24 22:20:51 +04:00
struct list metadata_areas ; /* e.g. metadata locations */
2005-10-23 04:14:48 +04:00
void * private ;
2002-04-24 22:20:51 +04:00
} ;
2001-09-28 17:15:30 +04:00
struct volume_group {
2001-11-12 15:16:57 +03:00
struct cmd_context * cmd ;
2002-04-24 22:20:51 +04:00
struct format_instance * fid ;
2002-11-18 17:04:08 +03:00
uint32_t seqno ; /* Metadata sequence number */
2001-11-12 15:16:57 +03:00
2001-10-08 20:08:16 +04:00
struct id id ;
2001-10-12 14:32:06 +04:00
char * name ;
2002-01-29 20:23:33 +03:00
char * system_id ;
2001-09-25 16:49:28 +04:00
2002-11-18 17:04:08 +03:00
uint32_t status ;
2004-05-19 02:12:53 +04:00
alloc_policy_t alloc ;
2001-10-03 16:34:08 +04:00
2002-11-18 17:04:08 +03:00
uint32_t extent_size ;
uint32_t extent_count ;
uint32_t free_count ;
2001-09-25 16:49:28 +04:00
2002-11-18 17:04:08 +03:00
uint32_t max_lv ;
uint32_t max_pv ;
2001-10-04 00:38:07 +04:00
2002-11-18 17:04:08 +03:00
/* physical volumes */
uint32_t pv_count ;
2001-10-31 15:47:01 +03:00
struct list pvs ;
2001-09-25 16:49:28 +04:00
2002-11-18 17:04:08 +03:00
/* logical volumes */
uint32_t lv_count ;
2002-02-12 19:31:31 +03:00
uint32_t snapshot_count ;
2005-04-07 16:39:44 +04:00
struct list lvs ;
2004-03-08 20:19:15 +03:00
struct list tags ;
2001-09-28 17:15:30 +04:00
} ;
2001-09-25 16:49:28 +04:00
2005-10-18 17:43:40 +04:00
/* There will be one area for each stripe */
struct lv_segment_area {
area_type_t type ;
union {
struct {
struct pv_segment * pvseg ;
} pv ;
struct {
struct logical_volume * lv ;
uint32_t le ;
} lv ;
} u ;
} ;
2004-05-05 01:25:57 +04:00
struct segment_type ;
2002-11-18 17:04:08 +03:00
struct lv_segment {
2001-11-27 19:37:33 +03:00
struct list list ;
struct logical_volume * lv ;
2002-11-18 17:04:08 +03:00
2004-05-05 01:25:57 +04:00
struct segment_type * segtype ;
2001-11-27 19:37:33 +03:00
uint32_t le ;
uint32_t len ;
2002-11-18 17:04:08 +03:00
2003-05-06 16:06:02 +04:00
uint32_t status ;
2002-11-18 17:04:08 +03:00
/* FIXME Fields depend on segment type */
2001-11-27 19:37:33 +03:00
uint32_t stripe_size ;
2003-04-25 02:23:24 +04:00
uint32_t area_count ;
uint32_t area_len ;
2002-11-18 17:04:08 +03:00
struct logical_volume * origin ;
struct logical_volume * cow ;
2005-04-07 16:39:44 +04:00
struct list origin_list ;
2005-06-01 20:51:55 +04:00
uint32_t chunk_size ; /* For snapshots - in sectors */
uint32_t region_size ; /* For mirrors - in sectors */
2004-05-05 21:56:20 +04:00
uint32_t extents_copied ;
2005-06-01 20:51:55 +04:00
struct logical_volume * log_lv ;
2005-10-27 23:58:22 +04:00
struct lv_segment * mirror_seg ;
2001-11-27 19:37:33 +03:00
2004-03-08 20:19:15 +03:00
struct list tags ;
2005-10-18 17:43:40 +04:00
struct lv_segment_area * areas ;
2001-11-27 19:37:33 +03:00
} ;
2005-10-18 17:43:40 +04:00
# define seg_type(seg, s) (seg)->areas[(s)].type
# define seg_pvseg(seg, s) (seg)->areas[(s)].u.pv.pvseg
# define seg_pv(seg, s) (seg)->areas[(s)].u.pv.pvseg->pv
# define seg_dev(seg, s) (seg)->areas[(s)].u.pv.pvseg->pv->dev
# define seg_pe(seg, s) (seg)->areas[(s)].u.pv.pvseg->pe
# define seg_lv(seg, s) (seg)->areas[(s)].u.lv.lv
# define seg_le(seg, s) (seg)->areas[(s)].u.lv.le
2005-06-01 20:51:55 +04:00
2001-10-31 20:59:52 +03:00
struct logical_volume {
2002-03-05 23:03:09 +03:00
union lvid lvid ;
2002-11-18 17:04:08 +03:00
char * name ;
2001-10-31 20:59:52 +03:00
struct volume_group * vg ;
2002-11-18 17:04:08 +03:00
uint32_t status ;
2002-07-11 18:21:49 +04:00
alloc_policy_t alloc ;
2001-10-31 20:59:52 +03:00
uint32_t read_ahead ;
2003-04-02 23:14:43 +04:00
int32_t major ;
2002-02-01 20:54:39 +03:00
int32_t minor ;
2001-10-31 20:59:52 +03:00
2002-11-18 17:04:08 +03:00
uint64_t size ;
uint32_t le_count ;
2001-10-31 20:59:52 +03:00
2005-04-07 16:39:44 +04:00
uint32_t origin_count ;
struct list snapshot_segs ;
struct lv_segment * snapshot ;
2001-11-26 19:18:48 +03:00
struct list segments ;
2004-03-08 20:19:15 +03:00
struct list tags ;
2001-10-31 20:59:52 +03:00
} ;
2001-10-05 02:53:37 +04:00
struct name_list {
2001-10-31 15:47:01 +03:00
struct list list ;
2001-10-08 20:08:16 +04:00
char * name ;
2001-10-02 21:09:05 +04:00
} ;
2004-08-18 01:55:23 +04:00
struct pe_range {
2003-04-25 02:23:24 +04:00
struct list list ;
uint32_t start ; /* PEs */
uint32_t count ; /* PEs */
} ;
2001-10-02 21:09:05 +04:00
struct pv_list {
2001-10-31 15:47:01 +03:00
struct list list ;
2002-01-21 19:05:23 +03:00
struct physical_volume * pv ;
2003-04-25 02:23:24 +04:00
struct list * mdas ; /* Metadata areas */
2004-08-18 01:55:23 +04:00
struct list * pe_ranges ; /* Ranges of PEs e.g. for allocation */
2001-10-02 21:09:05 +04:00
} ;
2001-10-02 02:12:10 +04:00
2001-10-08 13:45:16 +04:00
struct lv_list {
2001-10-31 15:47:01 +03:00
struct list list ;
2002-01-21 19:49:32 +03:00
struct logical_volume * lv ;
2001-10-08 13:45:16 +04:00
} ;
2002-11-18 17:04:08 +03:00
struct mda_list {
struct list list ;
struct device_area mda ;
} ;
2001-11-12 15:16:57 +03:00
2005-04-20 00:52:35 +04:00
struct peg_list {
struct list list ;
struct pv_segment * peg ;
} ;
2001-10-10 13:25:04 +04:00
/*
* Ownership of objects passes to caller .
*/
2001-11-12 15:16:57 +03:00
struct format_handler {
2001-10-10 13:25:04 +04:00
/*
2002-11-18 17:04:08 +03:00
* Scan any metadata areas that aren ' t referenced in PV labels
2001-10-10 13:25:04 +04:00
*/
2002-12-20 02:25:55 +03:00
int ( * scan ) ( const struct format_type * fmt ) ;
2001-09-25 16:49:28 +04:00
2001-10-10 13:25:04 +04:00
/*
* Return PV with given path .
*/
2002-12-20 02:25:55 +03:00
int ( * pv_read ) ( const struct format_type * fmt , const char * pv_name ,
2002-11-18 17:04:08 +03:00
struct physical_volume * pv , struct list * mdas ) ;
2001-10-05 02:53:37 +04:00
2001-10-10 13:25:04 +04:00
/*
2001-11-12 15:16:57 +03:00
* Tweak an already filled out a pv ready for importing into a
* vg . eg . pe_count is format specific .
2001-10-10 13:25:04 +04:00
*/
2002-12-20 02:25:55 +03:00
int ( * pv_setup ) ( const struct format_type * fmt ,
2002-11-18 17:04:08 +03:00
uint64_t pe_start , uint32_t extent_count ,
uint32_t extent_size ,
int pvmetadatacopies ,
uint64_t pvmetadatasize , struct list * mdas ,
struct physical_volume * pv , struct volume_group * vg ) ;
2001-10-10 13:25:04 +04:00
/*
2001-11-12 15:16:57 +03:00
* Write a PV structure to disk . Fails if the PV is in a VG ie
* pv - > vg_name must be null .
2001-10-10 13:25:04 +04:00
*/
2002-12-20 02:25:55 +03:00
int ( * pv_write ) ( const struct format_type * fmt ,
struct physical_volume * pv , struct list * mdas ,
int64_t label_sector ) ;
2001-09-25 16:49:28 +04:00
2002-01-24 20:15:49 +03:00
/*
* Tweak an already filled out a lv eg , check there
* aren ' t too many extents .
*/
2002-11-18 17:04:08 +03:00
int ( * lv_setup ) ( struct format_instance * fi ,
struct logical_volume * lv ) ;
2002-01-24 20:15:49 +03:00
2001-10-12 18:25:53 +04:00
/*
2001-11-12 15:16:57 +03:00
* Tweak an already filled out vg . eg , max_pv is format
* specific .
2001-10-12 18:25:53 +04:00
*/
2002-11-18 17:04:08 +03:00
int ( * vg_setup ) ( struct format_instance * fi , struct volume_group * vg ) ;
2001-10-05 02:53:37 +04:00
2004-09-14 17:56:18 +04:00
/*
* Check whether particular segment type is supported .
*/
int ( * segtype_supported ) ( struct format_instance * fid ,
struct segment_type * segtype ) ;
2002-04-24 22:20:51 +04:00
/*
* Create format instance with a particular metadata area
*/
2002-12-20 02:25:55 +03:00
struct format_instance * ( * create_instance ) ( const struct format_type *
fmt , const char * vgname ,
2002-11-18 17:04:08 +03:00
void * context ) ;
2002-04-24 22:20:51 +04:00
/*
* Destructor for format instance
*/
2002-11-18 17:04:08 +03:00
void ( * destroy_instance ) ( struct format_instance * fid ) ;
2001-10-05 02:53:37 +04:00
2001-10-10 13:25:04 +04:00
/*
2002-04-24 22:20:51 +04:00
* Destructor for format type
2001-10-10 13:25:04 +04:00
*/
2002-12-20 02:25:55 +03:00
void ( * destroy ) ( const struct format_type * fmt ) ;
2001-09-28 17:15:30 +04:00
} ;
2001-09-25 16:49:28 +04:00
2001-10-12 14:32:06 +04:00
/*
* Utility functions
*/
2005-07-12 23:40:59 +04:00
int vg_validate ( struct volume_group * vg ) ;
2002-04-24 22:20:51 +04:00
int vg_write ( struct volume_group * vg ) ;
2003-07-05 02:34:56 +04:00
int vg_commit ( struct volume_group * vg ) ;
int vg_revert ( struct volume_group * vg ) ;
2002-11-18 17:04:08 +03:00
struct volume_group * vg_read ( struct cmd_context * cmd , const char * vg_name ,
int * consistent ) ;
struct physical_volume * pv_read ( struct cmd_context * cmd , const char * pv_name ,
2004-06-19 23:27:00 +04:00
struct list * mdas , uint64_t * label_sector ,
int warnings ) ;
2002-04-24 22:20:51 +04:00
struct list * get_pvs ( struct cmd_context * cmd ) ;
2002-11-18 17:04:08 +03:00
/* Set full_scan to 1 to re-read every (filtered) device label */
struct list * get_vgs ( struct cmd_context * cmd , int full_scan ) ;
int pv_write ( struct cmd_context * cmd , struct physical_volume * pv ,
struct list * mdas , int64_t label_sector ) ;
2002-04-24 22:20:51 +04:00
2002-11-18 17:04:08 +03:00
/* pe_start and pe_end relate to any existing data so that new metadata
* areas can avoid overlap */
2002-12-20 02:25:55 +03:00
struct physical_volume * pv_create ( const struct format_type * fmt ,
2002-11-18 17:04:08 +03:00
struct device * dev ,
2002-02-15 04:26:16 +03:00
struct id * id ,
2002-11-18 17:04:08 +03:00
uint64_t size ,
uint64_t pe_start ,
uint32_t existing_extent_count ,
uint32_t existing_extent_size ,
int pvmetadatacopies ,
uint64_t pvmetadatasize , struct list * mdas ) ;
2005-10-31 05:37:29 +03:00
int pv_resize ( struct physical_volume * pv , struct volume_group * vg ,
uint32_t new_pe_count ) ;
2001-11-12 15:16:57 +03:00
2002-04-24 22:20:51 +04:00
struct volume_group * vg_create ( struct cmd_context * cmd , const char * name ,
2002-12-20 02:25:55 +03:00
uint32_t extent_size , uint32_t max_pv ,
2004-05-19 02:12:53 +04:00
uint32_t max_lv , alloc_policy_t alloc ,
int pv_count , char * * pv_names ) ;
2002-04-24 22:20:51 +04:00
int vg_remove ( struct volume_group * vg ) ;
2002-12-20 02:25:55 +03:00
int vg_rename ( struct cmd_context * cmd , struct volume_group * vg ,
const char * new_name ) ;
2002-11-18 17:04:08 +03:00
int vg_extend ( struct format_instance * fi , struct volume_group * vg ,
int pv_count , char * * pv_names ) ;
2005-04-18 18:56:42 +04:00
int vg_change_pesize ( struct cmd_context * cmd , struct volume_group * vg ,
uint32_t new_extent_size ) ;
2001-10-12 14:32:06 +04:00
2004-05-05 22:49:21 +04:00
/* Manipulate LVs */
2003-04-25 02:23:24 +04:00
struct logical_volume * lv_create_empty ( struct format_instance * fi ,
const char * name ,
2005-04-07 16:29:46 +04:00
union lvid * lvid ,
2003-04-25 02:23:24 +04:00
uint32_t status ,
alloc_policy_t alloc ,
2005-04-07 16:39:44 +04:00
int import ,
2003-04-25 02:23:24 +04:00
struct volume_group * vg ) ;
2001-11-06 14:19:33 +03:00
2005-06-14 21:54:48 +04:00
/* Reduce the size of an LV by extents */
2005-05-09 20:59:01 +04:00
int lv_reduce ( struct logical_volume * lv , uint32_t extents ) ;
2001-11-06 14:19:33 +03:00
2005-06-14 21:54:48 +04:00
/* Empty an LV prior to deleting it */
int lv_empty ( struct logical_volume * lv ) ;
2005-05-09 20:59:01 +04:00
/* Entry point for all LV extent allocations */
int lv_extend ( struct logical_volume * lv ,
2004-05-05 01:25:57 +04:00
struct segment_type * segtype ,
uint32_t stripes , uint32_t stripe_size ,
uint32_t mirrors , uint32_t extents ,
struct physical_volume * mirrored_pv , uint32_t mirrored_pe ,
2004-05-05 22:49:21 +04:00
uint32_t status , struct list * allocatable_pvs ,
alloc_policy_t alloc ) ;
2003-04-30 19:23:43 +04:00
2005-05-09 20:59:01 +04:00
/* lv must be part of lv->vg->lvs */
int lv_remove ( struct logical_volume * lv ) ;
2001-11-12 22:28:50 +03:00
2001-10-05 02:53:37 +04:00
/* Manipulate PV structures */
2001-10-02 02:12:10 +04:00
int pv_add ( struct volume_group * vg , struct physical_volume * pv ) ;
2001-10-03 16:34:08 +04:00
int pv_remove ( struct volume_group * vg , struct physical_volume * pv ) ;
2002-11-18 17:04:08 +03:00
struct physical_volume * pv_find ( struct volume_group * vg , const char * pv_name ) ;
2001-10-05 02:53:37 +04:00
2001-10-29 16:52:23 +03:00
/* Find a PV within a given VG */
2002-01-21 17:28:12 +03:00
struct pv_list * find_pv_in_vg ( struct volume_group * vg , const char * pv_name ) ;
2002-11-18 17:04:08 +03:00
struct physical_volume * find_pv_in_vg_by_uuid ( struct volume_group * vg ,
struct id * id ) ;
2005-04-18 03:57:44 +04:00
int get_pv_from_vg_by_id ( const struct format_type * fmt , const char * vg_name ,
const char * id , struct physical_volume * pv ) ;
2001-10-05 02:53:37 +04:00
/* Find an LV within a given VG */
2002-01-21 17:28:12 +03:00
struct lv_list * find_lv_in_vg ( struct volume_group * vg , const char * lv_name ) ;
2002-11-18 17:04:08 +03:00
struct lv_list * find_lv_in_vg_by_lvid ( struct volume_group * vg ,
2002-12-20 02:25:55 +03:00
const union lvid * lvid ) ;
2001-10-29 16:52:23 +03:00
/* Return the VG that contains a given LV (based on path given in lv_name) */
/* or environment var */
struct volume_group * find_vg_with_lv ( const char * lv_name ) ;
2002-11-18 17:04:08 +03:00
/* Find LV with given lvid (used during activation) */
struct logical_volume * lv_from_lvid ( struct cmd_context * cmd ,
2005-10-31 23:15:28 +03:00
const char * lvid_s ,
int precommitted ) ;
2001-10-29 16:52:23 +03:00
/* FIXME Merge these functions with ones above */
2001-11-27 19:37:33 +03:00
struct physical_volume * find_pv ( struct volume_group * vg , struct device * dev ) ;
2001-10-29 16:52:23 +03:00
struct logical_volume * find_lv ( struct volume_group * vg , const char * lv_name ) ;
2004-05-05 15:04:28 +04:00
struct physical_volume * find_pv_by_name ( struct cmd_context * cmd ,
const char * pv_name ) ;
2001-09-28 17:15:30 +04:00
2003-04-25 02:23:24 +04:00
/* Find LV segment containing given LE */
struct lv_segment * find_seg_by_le ( struct logical_volume * lv , uint32_t le ) ;
2005-10-28 16:48:50 +04:00
struct lv_segment * first_seg ( struct logical_volume * lv ) ;
2003-04-25 02:23:24 +04:00
2005-05-03 21:28:23 +04:00
/* Find PV segment containing given LE */
struct pv_segment * find_peg_by_pe ( struct physical_volume * pv , uint32_t pe ) ;
2001-11-12 15:16:57 +03:00
/*
2001-11-14 16:52:38 +03:00
* Remove a dev_dir if present .
2001-11-12 15:16:57 +03:00
*/
const char * strip_dir ( const char * vg_name , const char * dir ) ;
2001-10-15 22:39:40 +04:00
2002-01-10 14:18:08 +03:00
/*
* Checks that an lv has no gaps or overlapping segments .
2005-10-28 01:51:28 +04:00
* Set complete_vg to perform additional VG level checks .
2002-01-10 14:18:08 +03:00
*/
2005-10-28 01:51:28 +04:00
int check_lv_segments ( struct logical_volume * lv , int complete_vg ) ;
2002-01-10 14:18:08 +03:00
/*
* Sometimes ( eg , after an lvextend ) , it is possible to merge two
* adjacent segments into a single segment . This function trys
* to merge as many segments as possible .
*/
int lv_merge_segments ( struct logical_volume * lv ) ;
2003-09-15 22:22:50 +04:00
/*
* Ensure there ' s a segment boundary at a given LE , splitting if necessary
*/
int lv_split_segment ( struct logical_volume * lv , uint32_t le ) ;
2002-02-12 19:31:31 +03:00
/*
* Useful functions for managing snapshots .
*/
2002-12-20 02:25:55 +03:00
int lv_is_origin ( const struct logical_volume * lv ) ;
int lv_is_cow ( const struct logical_volume * lv ) ;
2002-02-12 19:31:31 +03:00
2003-01-18 00:04:26 +03:00
int pv_is_in_vg ( struct volume_group * vg , struct physical_volume * pv ) ;
2005-04-07 16:39:44 +04:00
struct lv_segment * find_cow ( const struct logical_volume * lv ) ;
2002-02-21 13:16:33 +03:00
2005-04-07 16:39:44 +04:00
int vg_add_snapshot ( struct format_instance * fid , const char * name ,
struct logical_volume * origin , struct logical_volume * cow ,
2005-04-07 16:27:57 +04:00
union lvid * lvid , uint32_t extent_count ,
2005-01-19 20:19:39 +03:00
uint32_t chunk_size ) ;
2002-02-12 19:31:31 +03:00
2005-05-09 20:59:01 +04:00
int vg_remove_snapshot ( struct logical_volume * cow ) ;
2002-02-12 19:31:31 +03:00
2003-04-30 19:23:43 +04:00
/*
* Mirroring functions
*/
2005-06-03 18:49:51 +04:00
struct alloc_handle ;
2005-08-12 23:23:08 +04:00
uint32_t adjusted_mirror_region_size ( uint32_t extent_size , uint32_t extents ,
uint32_t region_size ) ;
2005-06-03 18:49:51 +04:00
int create_mirror_layers ( struct alloc_handle * ah ,
uint32_t first_area ,
uint32_t num_mirrors ,
struct logical_volume * lv ,
struct segment_type * segtype ,
uint32_t status ,
uint32_t region_size ,
struct logical_volume * log_lv ) ;
2005-11-29 21:20:23 +03:00
int add_mirror_layers ( struct alloc_handle * ah ,
uint32_t num_mirrors ,
uint32_t existing_mirrors ,
struct logical_volume * lv ,
struct segment_type * segtype ) ;
int remove_mirror_images ( struct lv_segment * mirrored_seg , uint32_t num_mirrors ,
struct list * removable_pvs , int remove_log ) ;
2005-10-27 23:58:22 +04:00
/*
* Given mirror image or mirror log segment , find corresponding mirror segment
*/
struct lv_segment * find_mirror_seg ( struct lv_segment * seg ) ;
2005-10-28 01:51:28 +04:00
int fixup_imported_mirrors ( struct volume_group * vg ) ;
2005-06-14 22:22:31 +04:00
2003-04-30 19:23:43 +04:00
int insert_pvmove_mirrors ( struct cmd_context * cmd ,
struct logical_volume * lv_mirr ,
2004-08-18 02:09:02 +04:00
struct list * source_pvl ,
2003-04-30 19:23:43 +04:00
struct logical_volume * lv ,
struct list * allocatable_pvs ,
2005-05-09 20:59:01 +04:00
alloc_policy_t alloc ,
2003-04-30 19:23:43 +04:00
struct list * lvs_changed ) ;
2003-05-06 16:06:02 +04:00
int remove_pvmove_mirrors ( struct volume_group * vg ,
struct logical_volume * lv_mirr ) ;
struct logical_volume * find_pvmove_lv ( struct volume_group * vg ,
2004-05-05 21:56:20 +04:00
struct device * dev , uint32_t lv_type ) ;
struct logical_volume * find_pvmove_lv_from_pvname ( struct cmd_context * cmd ,
struct volume_group * vg ,
const char * name ,
uint32_t lv_type ) ;
const char * get_pvmove_pvname_from_lv ( struct logical_volume * lv ) ;
const char * get_pvmove_pvname_from_lv_mirr ( struct logical_volume * lv_mirr ) ;
float copy_percent ( struct logical_volume * lv_mirr ) ;
2003-05-06 16:06:02 +04:00
struct list * lvs_using_lv ( struct cmd_context * cmd , struct volume_group * vg ,
struct logical_volume * lv ) ;
2003-04-30 19:23:43 +04:00
2003-11-06 19:58:38 +03:00
uint32_t find_free_lvnum ( struct logical_volume * lv ) ;
2005-06-03 18:49:51 +04:00
char * generate_lv_name ( struct volume_group * vg , const char * format ,
char * buffer , size_t len ) ;
2003-11-06 19:58:38 +03:00
2003-02-03 23:09:58 +03:00
static inline int validate_name ( const char * n )
2002-11-18 17:04:08 +03:00
{
register char c ;
register int len = 0 ;
if ( ! n | | ! * n )
return 0 ;
/* Hyphen used as VG-LV separator - ambiguity if LV starts with it */
if ( * n = = ' - ' )
return 0 ;
2005-06-06 22:16:33 +04:00
if ( ! strcmp ( n , " . " ) | | ! strcmp ( n , " .. " ) )
return 0 ;
2002-11-18 17:04:08 +03:00
while ( ( len + + , c = * n + + ) )
if ( ! isalnum ( c ) & & c ! = ' . ' & & c ! = ' _ ' & & c ! = ' - ' & & c ! = ' + ' )
return 0 ;
if ( len > NAME_LEN )
return 0 ;
return 1 ;
}
2002-02-12 19:31:31 +03:00
2001-09-28 17:15:30 +04:00
# endif