2007-07-18 19:38:58 +04:00
/*
2009-09-03 01:39:07 +04:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
* Copyright ( C ) 2004 - 2009 Red Hat , Inc . All rights reserved .
2007-07-18 19:38:58 +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 .
2007-07-18 19:38:58 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2007-07-18 19:38:58 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
/*
* This is the representation of LVM metadata that is being adapted
* for library export .
*/
# ifndef _LVM_METADATA_EXPORTED_H
# define _LVM_METADATA_EXPORTED_H
# include "uuid.h"
# define MAX_STRIPES 128U
# define SECTOR_SHIFT 9L
2010-02-14 06:21:06 +03:00
# define SECTOR_SIZE ( 1L << SECTOR_SHIFT )
2007-07-18 19:38:58 +04:00
# define STRIPE_SIZE_MIN ( (unsigned) lvm_getpagesize() >> SECTOR_SHIFT) /* PAGESIZE in sectors */
# define STRIPE_SIZE_MAX ( 512L * 1024L >> SECTOR_SHIFT) /* 512 KB in sectors */
# define STRIPE_SIZE_LIMIT ((UINT_MAX >> 2) + 1)
# define PV_MIN_SIZE ( 512L * 1024L >> SECTOR_SHIFT) /* 512 KB in sectors */
# define MAX_RESTRICTED_LVS 255 /* Used by FMT_RESTRICTED_LVIDS */
2007-12-22 05:13:00 +03:00
/* Layer suffix */
# define MIRROR_SYNC_LAYER "_mimagetmp"
2007-07-18 19:38:58 +04:00
/* Various flags */
/* Note that the bits no longer necessarily correspond to LVM1 disk format */
# define PARTIAL_VG 0x00000001U /* VG */
# define EXPORTED_VG 0x00000002U /* VG PV */
# define RESIZEABLE_VG 0x00000004U /* VG */
/* May any free extents on this PV be used or must they be left free? */
# define ALLOCATABLE_PV 0x00000008U /* PV */
//#define SPINDOWN_LV 0x00000010U /* LV */
//#define BADBLOCK_ON 0x00000020U /* LV */
# define VISIBLE_LV 0x00000040U /* LV */
# define FIXED_MINOR 0x00000080U /* LV */
/* FIXME Remove when metadata restructuring is completed */
# define SNAPSHOT 0x00001000U /* LV - internal use only */
# define PVMOVE 0x00002000U /* VG LV SEG */
# define LOCKED 0x00004000U /* LV */
# define MIRRORED 0x00008000U /* LV - internal use only */
//#define VIRTUAL 0x00010000U /* LV - internal use only */
# define MIRROR_LOG 0x00020000U /* LV */
# define MIRROR_IMAGE 0x00040000U /* LV */
# define MIRROR_NOTSYNCED 0x00080000U /* LV */
//#define ACTIVATE_EXCL 0x00100000U /* LV - internal use only */
//#define PRECOMMITTED 0x00200000U /* VG - internal use only */
2008-01-10 21:35:51 +03:00
# define CONVERTING 0x00400000U /* LV */
2007-07-18 19:38:58 +04:00
2008-09-19 10:42:00 +04:00
# define MISSING_PV 0x00800000U /* PV */
# define PARTIAL_LV 0x01000000U / * LV - derived flag, not
written out in metadata */
2008-09-25 19:57:02 +04:00
//#define POSTORDER_FLAG 0x02000000U /* Not real flags, reserved for
2009-01-26 22:01:32 +03:00
//#define POSTORDER_OPEN_FLAG 0x04000000U temporary use inside vg_read_internal. */
2009-04-25 05:17:59 +04:00
//#define VIRTUAL_ORIGIN 0x08000000U /* LV - internal use only */
2008-09-19 10:42:00 +04:00
2010-01-13 04:56:18 +03:00
# define MERGING 0x10000000U /* LV SEG */
2010-01-13 04:35:49 +03:00
2007-07-18 19:38:58 +04:00
# define LVM_READ 0x00000100U /* LV VG */
# define LVM_WRITE 0x00000200U /* LV VG */
# define CLUSTERED 0x00000400U /* VG */
//#define SHARED 0x00000800U /* VG */
/* Format features flags */
# define FMT_SEGMENTS 0x00000001U /* Arbitrary segment params? */
# define FMT_MDAS 0x00000002U /* Proper metadata areas? */
# define FMT_TAGS 0x00000004U /* Tagging? */
# define FMT_UNLIMITED_VOLS 0x00000008U /* Unlimited PVs/LVs? */
# define FMT_RESTRICTED_LVIDS 0x00000010U /* LVID <= 255 */
# define FMT_ORPHAN_ALLOCATABLE 0x00000020U /* Orphan PV allocatable? */
//#define FMT_PRECOMMIT 0x00000040U /* Supports pre-commit? */
# define FMT_RESIZE_PV 0x00000080U /* Supports pvresize? */
# define FMT_UNLIMITED_STRIPESIZE 0x00000100U /* Unlimited stripe size? */
2007-11-09 19:51:54 +03:00
# define FMT_RESTRICTED_READAHEAD 0x00000200U /* Readahead restricted to 2-120? */
2007-07-18 19:38:58 +04:00
2007-12-21 01:37:42 +03:00
/* Mirror conversion type flags */
# define MIRROR_BY_SEG 0x00000001U /* segment-by-segment mirror */
2008-01-17 20:17:09 +03:00
# define MIRROR_BY_LV 0x00000002U /* mirror using whole mimage LVs */
2008-01-19 01:02:37 +03:00
# define MIRROR_SKIP_INIT_SYNC 0x00000010U /* skip initial sync */
2007-12-21 01:37:42 +03:00
2009-01-27 01:13:22 +03:00
/* vg_read and vg_read_for_update flags */
# define READ_ALLOW_INCONSISTENT 0x00010000U
# define READ_ALLOW_EXPORTED 0x00020000U
2009-07-15 09:50:22 +04:00
# define READ_WITHOUT_LOCK 0x00040000U
2009-01-27 01:13:22 +03:00
/* A meta-flag, useful with toollib for_each_* functions. */
# define READ_FOR_UPDATE 0x00100000U
/* vg's "read_status" field */
# define FAILED_INCONSISTENT 0x00000001U
# define FAILED_LOCKING 0x00000002U
# define FAILED_NOTFOUND 0x00000004U
# define FAILED_READ_ONLY 0x00000008U
# define FAILED_EXPORTED 0x00000010U
# define FAILED_RESIZEABLE 0x00000020U
# define FAILED_CLUSTERED 0x00000040U
# define FAILED_ALLOCATION 0x00000080U
Add vg_lock_newname() library function.
Various tools need to check for existence of a VG before doing something
(vgsplit, vgrename, vgcreate). Currently we don't have an interface to
check for existence, but the existence check is part of the vg_read* call(s).
This patch is an attempt to pull out some of that functionality into a
separate function, and hopefully simplify our vg_read interface, and
move those patches along.
vg_lock_newname() is only concerned about checking whether a vg exists in
the system. Unfortunately, we cannot just scan the system, but we must first
obtain a lock. Since we are reserving a vgname, we take a WRITE lock on
the vgname. Once obtained, we scan the system to ensure the name does
not exist. The return codes and behavior is in the function header.
You might think of this function as similar to an open() call with
O_CREAT and O_EXCL flags (returns failure with -EEXIST if file already
exists).
NOTE: I think including the word "lock" in the function name is important,
as it clearly states the function obtains a lock and makes the code more
readable, especially when it comes to cleanup / unlocking. The ultimate
function name is somewhat open for debate though so later we may rename.
2009-06-09 18:29:10 +04:00
# define FAILED_EXIST 0x00000100U
# define SUCCESS 0x00000000U
2009-01-27 01:13:22 +03:00
2007-07-18 19:38:58 +04:00
/* Ordered list - see lv_manip.c */
typedef enum {
ALLOC_INVALID ,
ALLOC_CONTIGUOUS ,
ALLOC_CLING ,
ALLOC_NORMAL ,
ALLOC_ANYWHERE ,
ALLOC_INHERIT
} alloc_policy_t ;
typedef enum {
AREA_UNASSIGNED ,
AREA_PV ,
AREA_LV
} area_type_t ;
2007-08-20 20:16:54 +04:00
/*
* Whether or not to force an operation .
*/
typedef enum {
2007-08-21 20:40:33 +04:00
PROMPT = 0 , /* Issue yes/no prompt to confirm operation */
DONT_PROMPT = 1 , /* Skip yes/no prompt */
DONT_PROMPT_OVERRIDE = 2 /* Skip prompt + override a second condition */
2007-08-20 20:16:54 +04:00
} force_t ;
2009-10-01 04:35:29 +04:00
typedef enum {
PERCENT_0 = 0 ,
PERCENT_0_TO_100 = 1 ,
PERCENT_100 = 2 ,
PERCENT_INVALID = 3
} percent_range_t ;
2007-07-18 19:38:58 +04:00
struct cmd_context ;
struct format_handler ;
struct labeller ;
struct format_type {
2008-11-04 01:14:30 +03:00
struct dm_list list ;
2007-07-18 19:38:58 +04:00
struct cmd_context * cmd ;
struct format_handler * ops ;
struct labeller * labeller ;
const char * name ;
const char * alias ;
2008-02-06 18:47:28 +03:00
const char * orphan_vg_name ;
2007-07-18 19:38:58 +04:00
uint32_t features ;
void * library ;
void * private ;
} ;
struct pv_segment {
2008-11-04 01:14:30 +03:00
struct dm_list list ; /* Member of pv->segments: ordered list
2007-07-18 19:38:58 +04:00
* 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 */
} ;
2008-03-26 19:48:10 +03:00
# define pvseg_is_allocated(pvseg) ((pvseg)->lvseg)
2007-07-18 19:38:58 +04:00
struct physical_volume {
struct id id ;
struct device * dev ;
const struct format_type * fmt ;
const char * vg_name ;
struct id vgid ;
2009-11-25 01:55:55 +03:00
uint64_t status ;
2007-07-18 19:38:58 +04:00
uint64_t size ;
/* physical extents */
uint32_t pe_size ;
uint64_t pe_start ;
uint32_t pe_count ;
uint32_t pe_alloc_count ;
2008-09-19 08:28:58 +04:00
unsigned long pe_align ;
2009-07-30 21:45:28 +04:00
unsigned long pe_align_offset ;
2007-07-18 19:38:58 +04:00
2008-11-04 01:14:30 +03:00
struct dm_list segments ; /* Ordered pv_segments covering complete PV */
struct dm_list tags ;
2007-07-18 19:38:58 +04:00
} ;
struct format_instance {
const struct format_type * fmt ;
2008-11-04 01:14:30 +03:00
struct dm_list metadata_areas ; /* e.g. metadata locations */
2007-07-18 19:38:58 +04:00
void * private ;
} ;
struct volume_group {
struct cmd_context * cmd ;
2009-04-10 13:59:18 +04:00
struct dm_pool * vgmem ;
2007-07-18 19:38:58 +04:00
struct format_instance * fid ;
uint32_t seqno ; /* Metadata sequence number */
2009-11-25 01:55:55 +03:00
alloc_policy_t alloc ;
uint64_t status ;
2007-07-18 19:38:58 +04:00
struct id id ;
char * name ;
char * system_id ;
uint32_t extent_size ;
uint32_t extent_count ;
uint32_t free_count ;
uint32_t max_lv ;
uint32_t max_pv ;
/* physical volumes */
uint32_t pv_count ;
2008-11-04 01:14:30 +03:00
struct dm_list pvs ;
2007-07-18 19:38:58 +04:00
2008-04-23 18:33:06 +04:00
/*
* logical volumes
* The following relationship should always hold :
2009-05-14 01:27:43 +04:00
* dm_list_size ( lvs ) = user visible lv_count + snapshot_count + other invisible LVs
2008-04-23 18:33:06 +04:00
*
* Snapshots consist of 2 instances of " struct logical_volume " :
* - cow ( lv_name is visible to the user )
* - snapshot ( lv_name is ' snapshotN ' )
*
* Mirrors consist of multiple instances of " struct logical_volume " :
* - one for the mirror log
* - one for each mirror leg
* - one for the user - visible mirror LV
*/
2008-11-04 01:14:30 +03:00
struct dm_list lvs ;
2007-07-18 19:38:58 +04:00
2008-11-04 01:14:30 +03:00
struct dm_list tags ;
2009-01-27 01:13:22 +03:00
/*
2009-07-29 17:26:01 +04:00
* FIXME : Move the next fields into a different struct ?
2009-01-27 01:13:22 +03:00
*/
2009-07-27 21:43:39 +04:00
/*
* List of removed physical volumes by pvreduce .
* They have to get cleared on vg_commit .
*/
struct dm_list removed_pvs ;
2009-07-28 19:14:56 +04:00
uint32_t open_mode ; /* FIXME: read or write - check lock type? */
2009-07-27 21:43:39 +04:00
2009-01-27 01:13:22 +03:00
/*
* Store result of the last vg_read ( ) .
* 0 for success else appropriate FAILURE_ * bits set .
*/
uint32_t read_status ;
2007-07-18 19:38:58 +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 ;
} ;
struct segment_type ;
struct lv_segment {
2008-11-04 01:14:30 +03:00
struct dm_list list ;
2007-07-18 19:38:58 +04:00
struct logical_volume * lv ;
const struct segment_type * segtype ;
uint32_t le ;
uint32_t len ;
2009-11-25 01:55:55 +03:00
uint64_t status ;
2007-07-18 19:38:58 +04:00
/* FIXME Fields depend on segment type */
uint32_t stripe_size ;
uint32_t area_count ;
uint32_t area_len ;
2009-11-25 01:55:55 +03:00
uint32_t chunk_size ; /* For snapshots - in sectors */
2007-07-18 19:38:58 +04:00
struct logical_volume * origin ;
struct logical_volume * cow ;
2008-11-04 01:14:30 +03:00
struct dm_list origin_list ;
2007-07-18 19:38:58 +04:00
uint32_t region_size ; /* For mirrors - in sectors */
uint32_t extents_copied ;
struct logical_volume * log_lv ;
2009-10-16 21:41:49 +04:00
void * segtype_private ;
2007-07-18 19:38:58 +04:00
2008-11-04 01:14:30 +03:00
struct dm_list tags ;
2007-07-18 19:38:58 +04:00
struct lv_segment_area * areas ;
} ;
# define seg_type(seg, s) (seg)->areas[(s)].type
# define seg_pv(seg, s) (seg)->areas[(s)].u.pv.pvseg->pv
# define seg_lv(seg, s) (seg)->areas[(s)].u.lv.lv
struct logical_volume {
union lvid lvid ;
char * name ;
struct volume_group * vg ;
2009-11-25 01:55:55 +03:00
uint64_t status ;
2007-07-18 19:38:58 +04:00
alloc_policy_t alloc ;
uint32_t read_ahead ;
int32_t major ;
int32_t minor ;
uint64_t size ; /* Sectors */
uint32_t le_count ;
uint32_t origin_count ;
2008-11-04 01:14:30 +03:00
struct dm_list snapshot_segs ;
2007-07-18 19:38:58 +04:00
struct lv_segment * snapshot ;
2008-11-04 01:14:30 +03:00
struct dm_list segments ;
struct dm_list tags ;
struct dm_list segs_using_this_lv ;
2007-07-18 19:38:58 +04:00
} ;
struct pe_range {
2008-11-04 01:14:30 +03:00
struct dm_list list ;
2007-07-18 19:38:58 +04:00
uint32_t start ; /* PEs */
uint32_t count ; /* PEs */
} ;
struct pv_list {
2008-11-04 01:14:30 +03:00
struct dm_list list ;
2007-07-18 19:38:58 +04:00
struct physical_volume * pv ;
2008-11-04 01:14:30 +03:00
struct dm_list * mdas ; /* Metadata areas */
struct dm_list * pe_ranges ; /* Ranges of PEs e.g. for allocation */
2007-07-18 19:38:58 +04:00
} ;
struct lv_list {
2008-11-04 01:14:30 +03:00
struct dm_list list ;
2007-07-18 19:38:58 +04:00
struct logical_volume * lv ;
} ;
2009-07-26 05:53:09 +04:00
struct pvcreate_params {
int zero ;
uint64_t size ;
uint64_t data_alignment ;
2009-07-30 21:45:28 +04:00
uint64_t data_alignment_offset ;
2009-07-26 05:53:09 +04:00
int pvmetadatacopies ;
uint64_t pvmetadatasize ;
int64_t labelsector ;
struct id id ; /* FIXME: redundant */
struct id * idp ; /* 0 if no --uuid option */
uint64_t pe_start ;
uint32_t extent_count ;
uint32_t extent_size ;
const char * restorefile ; /* 0 if no --restorefile option */
force_t force ;
unsigned yes ;
} ;
2009-07-29 17:26:01 +04:00
struct physical_volume * pvcreate_single ( struct cmd_context * cmd ,
const char * pv_name ,
struct pvcreate_params * pp ) ;
2009-11-01 22:51:54 +03:00
void pvcreate_params_set_defaults ( struct pvcreate_params * pp ) ;
2009-07-26 05:53:09 +04:00
2007-07-18 19:38:58 +04:00
/*
* Utility functions
*/
int vg_write ( struct volume_group * vg ) ;
int vg_commit ( struct volume_group * vg ) ;
int vg_revert ( struct volume_group * vg ) ;
2009-11-23 13:44:50 +03:00
struct volume_group * vg_read_internal ( struct cmd_context * cmd , const char * vg_name ,
const char * vgid , int * consistent ) ;
2007-07-18 19:38:58 +04:00
struct physical_volume * pv_read ( struct cmd_context * cmd , const char * pv_name ,
2008-11-04 01:14:30 +03:00
struct dm_list * mdas , uint64_t * label_sector ,
2009-02-26 02:29:06 +03:00
int warnings , int scan_label_only ) ;
2008-11-04 01:14:30 +03:00
struct dm_list * get_pvs ( struct cmd_context * cmd ) ;
2007-07-18 19:38:58 +04:00
2009-05-14 01:25:01 +04:00
/*
* Add / remove LV to / from volume group
*/
int link_lv_to_vg ( struct volume_group * vg , struct logical_volume * lv ) ;
int unlink_lv_from_vg ( struct logical_volume * lv ) ;
2009-05-14 01:26:45 +04:00
void lv_set_visible ( struct logical_volume * lv ) ;
2009-05-21 07:04:52 +04:00
void lv_set_hidden ( struct logical_volume * lv ) ;
2009-05-14 01:25:01 +04:00
2010-03-16 19:57:03 +03:00
struct dm_list * get_vgnames ( struct cmd_context * cmd , int include_internal ) ;
struct dm_list * get_vgids ( struct cmd_context * cmd , int include_internal ) ;
2008-01-16 21:15:26 +03:00
int scan_vgs_for_pvs ( struct cmd_context * cmd ) ;
2007-07-18 19:38:58 +04:00
int pv_write ( struct cmd_context * cmd , struct physical_volume * pv ,
2008-11-04 01:14:30 +03:00
struct dm_list * mdas , int64_t label_sector ) ;
2009-07-29 17:26:01 +04:00
int is_pv ( struct physical_volume * pv ) ;
2009-07-14 06:15:21 +04:00
int move_pv ( struct volume_group * vg_from , struct volume_group * vg_to ,
const char * pv_name ) ;
int move_pvs_used_by_lv ( struct volume_group * vg_from ,
struct volume_group * vg_to ,
const char * lv_name ) ;
2007-11-02 16:06:42 +03:00
int is_orphan_vg ( const char * vg_name ) ;
2009-07-29 17:26:01 +04:00
int is_orphan ( const struct physical_volume * pv ) ;
2010-03-16 17:37:38 +03:00
int is_missing_pv ( const struct physical_volume * pv ) ;
2008-01-16 22:54:39 +03:00
int vgs_are_compatible ( struct cmd_context * cmd ,
struct volume_group * vg_from ,
struct volume_group * vg_to ) ;
Add vg_lock_newname() library function.
Various tools need to check for existence of a VG before doing something
(vgsplit, vgrename, vgcreate). Currently we don't have an interface to
check for existence, but the existence check is part of the vg_read* call(s).
This patch is an attempt to pull out some of that functionality into a
separate function, and hopefully simplify our vg_read interface, and
move those patches along.
vg_lock_newname() is only concerned about checking whether a vg exists in
the system. Unfortunately, we cannot just scan the system, but we must first
obtain a lock. Since we are reserving a vgname, we take a WRITE lock on
the vgname. Once obtained, we scan the system to ensure the name does
not exist. The return codes and behavior is in the function header.
You might think of this function as similar to an open() call with
O_CREAT and O_EXCL flags (returns failure with -EEXIST if file already
exists).
NOTE: I think including the word "lock" in the function name is important,
as it clearly states the function obtains a lock and makes the code more
readable, especially when it comes to cleanup / unlocking. The ultimate
function name is somewhat open for debate though so later we may rename.
2009-06-09 18:29:10 +04:00
uint32_t vg_lock_newname ( struct cmd_context * cmd , const char * vgname ) ;
2007-07-18 19:38:58 +04:00
2009-01-27 04:48:47 +03:00
/*
* Return a handle to VG metadata .
*/
2009-07-29 17:26:01 +04:00
struct volume_group * vg_read ( struct cmd_context * cmd , const char * vg_name ,
2009-01-27 03:40:44 +03:00
const char * vgid , uint32_t flags ) ;
2009-07-29 17:26:01 +04:00
struct volume_group * vg_read_for_update ( struct cmd_context * cmd , const char * vg_name ,
2009-01-27 03:40:44 +03:00
const char * vgid , uint32_t flags ) ;
2009-01-27 04:48:47 +03:00
/*
* Test validity of a VG handle .
*/
2009-07-29 17:26:01 +04:00
uint32_t vg_read_error ( struct volume_group * vg_handle ) ;
2009-01-27 04:48:47 +03:00
2007-07-18 19:38:58 +04:00
/* pe_start and pe_end relate to any existing data so that new metadata
* areas can avoid overlap */
2009-07-29 17:26:01 +04:00
struct physical_volume * pv_create ( const struct cmd_context * cmd ,
2007-07-18 19:38:58 +04:00
struct device * dev ,
struct id * id ,
uint64_t size ,
2009-02-22 22:00:26 +03:00
unsigned long data_alignment ,
2009-07-30 21:45:28 +04:00
unsigned long data_alignment_offset ,
2007-07-18 19:38:58 +04:00
uint64_t pe_start ,
uint32_t existing_extent_count ,
uint32_t existing_extent_size ,
int pvmetadatacopies ,
2008-11-04 01:14:30 +03:00
uint64_t pvmetadatasize , struct dm_list * mdas ) ;
2007-07-18 19:38:58 +04:00
int pv_resize ( struct physical_volume * pv , struct volume_group * vg ,
uint32_t new_pe_count ) ;
int pv_analyze ( struct cmd_context * cmd , const char * pv_name ,
2007-08-22 18:38:18 +04:00
uint64_t label_sector ) ;
2007-07-18 19:38:58 +04:00
2007-09-21 01:39:08 +04:00
/* FIXME: move internal to library */
2008-11-04 01:14:30 +03:00
uint32_t pv_list_extents_free ( const struct dm_list * pvh ) ;
2007-09-21 01:39:08 +04:00
2009-07-29 17:26:01 +04:00
struct volume_group * vg_create ( struct cmd_context * cmd , const char * vg_name ) ;
2009-09-03 01:39:07 +04:00
int vg_remove_mdas ( struct volume_group * vg ) ;
2009-09-03 01:39:29 +04:00
int vg_remove_check ( struct volume_group * vg ) ;
int vg_remove ( struct volume_group * vg ) ;
2007-07-18 19:38:58 +04:00
int vg_rename ( struct cmd_context * cmd , struct volume_group * vg ,
const char * new_name ) ;
2009-10-06 00:02:48 +04:00
int vg_extend ( struct volume_group * vg , int pv_count , char * * pv_names ,
struct pvcreate_params * pp ) ;
2009-07-27 21:43:39 +04:00
int vg_reduce ( struct volume_group * vg , char * pv_name ) ;
2010-02-24 21:15:05 +03:00
int vg_change_tag ( struct volume_group * vg , const char * tag , int add_tag ) ;
2009-07-29 17:26:01 +04:00
int vg_set_extent_size ( struct volume_group * vg , uint32_t new_extent_size ) ;
int vg_set_max_lv ( struct volume_group * vg , uint32_t max_lv ) ;
int vg_set_max_pv ( struct volume_group * vg , uint32_t max_pv ) ;
int vg_set_alloc_policy ( struct volume_group * vg , alloc_policy_t alloc ) ;
2009-10-31 20:30:52 +03:00
int vg_set_clustered ( struct volume_group * vg , int clustered ) ;
2007-07-18 19:38:58 +04:00
int vg_split_mdas ( struct cmd_context * cmd , struct volume_group * vg_from ,
struct volume_group * vg_to ) ;
2009-07-11 00:07:02 +04:00
/* FIXME: refactor / unexport when lvremove liblvm refactoring dones */
int remove_lvs_in_vg ( struct cmd_context * cmd ,
struct volume_group * vg ,
force_t force ) ;
2009-05-21 07:04:52 +04:00
/*
* vg_release ( ) must be called on every struct volume_group allocated
2009-11-23 13:44:50 +03:00
* by vg_create ( ) or vg_read_internal ( ) to free it when no longer required .
2009-05-21 07:04:52 +04:00
*/
2009-04-10 13:59:18 +04:00
void vg_release ( struct volume_group * vg ) ;
2009-05-21 07:04:52 +04:00
2007-07-18 19:38:58 +04:00
/* Manipulate LVs */
2007-10-11 23:20:38 +04:00
struct logical_volume * lv_create_empty ( const char * name ,
2007-07-18 19:38:58 +04:00
union lvid * lvid ,
2009-11-25 01:55:55 +03:00
uint64_t status ,
2007-07-18 19:38:58 +04:00
alloc_policy_t alloc ,
struct volume_group * vg ) ;
2007-12-21 01:37:42 +03:00
/* Write out LV contents */
int set_lv ( struct cmd_context * cmd , struct logical_volume * lv ,
uint64_t sectors , int value ) ;
2010-02-24 21:15:49 +03:00
int lv_change_tag ( struct logical_volume * lv , const char * tag , int add_tag ) ;
2007-07-18 19:38:58 +04:00
/* Reduce the size of an LV by extents */
int lv_reduce ( struct logical_volume * lv , uint32_t extents ) ;
/* Empty an LV prior to deleting it */
int lv_empty ( struct logical_volume * lv ) ;
2008-01-17 16:13:54 +03:00
/* Empty an LV and add error segment */
2008-01-17 16:54:05 +03:00
int replace_lv_with_error_segment ( struct logical_volume * lv ) ;
2008-01-17 16:13:54 +03:00
2007-07-18 19:38:58 +04:00
/* Entry point for all LV extent allocations */
int lv_extend ( struct logical_volume * lv ,
const 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 ,
2009-11-25 01:55:55 +03:00
uint64_t status , struct dm_list * allocatable_pvs ,
2007-07-18 19:38:58 +04:00
alloc_policy_t alloc ) ;
/* lv must be part of lv->vg->lvs */
int lv_remove ( struct logical_volume * lv ) ;
2007-08-20 21:04:53 +04:00
int lv_remove_single ( struct cmd_context * cmd , struct logical_volume * lv ,
force_t force ) ;
2008-08-05 16:05:26 +04:00
int lv_remove_with_dependencies ( struct cmd_context * cmd , struct logical_volume * lv ,
force_t force ) ;
2007-08-04 01:22:10 +04:00
int lv_rename ( struct cmd_context * cmd , struct logical_volume * lv ,
2007-08-06 18:57:48 +04:00
const char * new_name ) ;
2007-08-04 01:22:10 +04:00
2009-07-26 06:34:09 +04:00
uint64_t extents_from_size ( struct cmd_context * cmd , uint64_t size ,
uint32_t extent_size ) ;
2009-07-26 06:33:35 +04:00
/* FIXME: refactor and reduce the size of this struct! */
struct lvcreate_params {
/* flags */
int snapshot ; /* snap */
int zero ; /* all */
int major ; /* all */
int minor ; /* all */
2010-01-09 01:32:35 +03:00
int log_count ; /* mirror */
2009-07-26 06:33:35 +04:00
int nosync ; /* mirror */
2010-03-24 01:30:18 +03:00
int activation_monitoring ; /* all */
2009-07-26 06:33:35 +04:00
char * origin ; /* snap */
const char * vg_name ; /* all */
const char * lv_name ; /* all */
uint32_t stripes ; /* striped */
uint32_t stripe_size ; /* striped */
uint32_t chunk_size ; /* snapshot */
uint32_t region_size ; /* mirror */
uint32_t mirrors ; /* mirror */
const struct segment_type * segtype ; /* all */
/* size */
uint32_t extents ; /* all */
uint32_t voriginextents ; /* snapshot */
uint64_t voriginsize ; /* snapshot */
struct dm_list * pvh ; /* all */
uint32_t permission ; /* all */
uint32_t read_ahead ; /* all */
alloc_policy_t alloc ; /* all */
const char * tag ; /* all */
} ;
int lv_create_single ( struct volume_group * vg ,
struct lvcreate_params * lp ) ;
2007-12-20 18:42:55 +03:00
/*
* Functions for layer manipulation
*/
int insert_layer_for_segments_on_pv ( struct cmd_context * cmd ,
struct logical_volume * lv_where ,
struct logical_volume * layer_lv ,
2009-11-25 01:55:55 +03:00
uint64_t status ,
2007-12-20 18:42:55 +03:00
struct pv_list * pv ,
2008-11-04 01:14:30 +03:00
struct dm_list * lvs_changed ) ;
2007-12-20 18:42:55 +03:00
int remove_layers_for_segments ( struct cmd_context * cmd ,
struct logical_volume * lv ,
struct logical_volume * layer_lv ,
2009-11-25 01:55:55 +03:00
uint64_t status_mask , struct dm_list * lvs_changed ) ;
2007-12-20 18:42:55 +03:00
int remove_layers_for_segments_all ( struct cmd_context * cmd ,
struct logical_volume * layer_lv ,
2009-11-25 01:55:55 +03:00
uint64_t status_mask ,
2008-11-04 01:14:30 +03:00
struct dm_list * lvs_changed ) ;
2007-12-20 18:42:55 +03:00
int split_parent_segments_for_layer ( struct cmd_context * cmd ,
struct logical_volume * layer_lv ) ;
2007-12-20 21:55:46 +03:00
int remove_layer_from_lv ( struct logical_volume * lv ,
struct logical_volume * layer_lv ) ;
2007-12-20 18:42:55 +03:00
struct logical_volume * insert_layer_for_lv ( struct cmd_context * cmd ,
struct logical_volume * lv_where ,
2009-11-25 01:55:55 +03:00
uint64_t status ,
2007-12-20 18:42:55 +03:00
const char * layer_suffix ) ;
2007-07-18 19:38:58 +04:00
/* Find a PV within a given VG */
2008-03-14 01:51:24 +03:00
struct pv_list * find_pv_in_vg ( const struct volume_group * vg ,
const char * pv_name ) ;
2010-03-16 18:30:48 +03:00
struct pv_list * find_pv_in_vg_by_uuid ( const struct volume_group * vg ,
const struct id * id ) ;
2007-07-18 19:38:58 +04:00
/* Find an LV within a given VG */
2008-03-14 01:51:24 +03:00
struct lv_list * find_lv_in_vg ( const struct volume_group * vg ,
const char * lv_name ) ;
2007-07-18 19:38:58 +04:00
/* FIXME Merge these functions with ones above */
2008-03-14 01:51:24 +03:00
struct logical_volume * find_lv ( const struct volume_group * vg ,
const char * lv_name ) ;
2007-07-18 19:38:58 +04:00
struct physical_volume * find_pv_by_name ( struct cmd_context * cmd ,
const char * pv_name ) ;
/* Find LV segment containing given LE */
2007-12-20 21:55:46 +03:00
struct lv_segment * first_seg ( const struct logical_volume * lv ) ;
2007-07-18 19:38:58 +04:00
/*
* Useful functions for managing snapshots .
*/
int lv_is_origin ( const struct logical_volume * lv ) ;
2009-04-25 05:17:59 +04:00
int lv_is_virtual_origin ( const struct logical_volume * lv ) ;
2007-07-18 19:38:58 +04:00
int lv_is_cow ( const struct logical_volume * lv ) ;
2010-01-13 04:55:43 +03:00
int lv_is_merging_origin ( const struct logical_volume * origin ) ;
int lv_is_merging_cow ( const struct logical_volume * snapshot ) ;
2007-07-18 19:38:58 +04:00
2008-12-04 18:54:26 +03:00
/* Test if given LV is visible from user's perspective */
2009-05-14 01:27:43 +04:00
int lv_is_visible ( const struct logical_volume * lv ) ;
2008-12-04 18:54:26 +03:00
2007-07-18 19:38:58 +04:00
int pv_is_in_vg ( struct volume_group * vg , struct physical_volume * pv ) ;
2010-01-13 04:55:43 +03:00
struct lv_segment * find_merging_cow ( const struct logical_volume * origin ) ;
2007-07-18 19:38:58 +04:00
/* Given a cow LV, return return the snapshot lv_segment that uses it */
struct lv_segment * find_cow ( const struct logical_volume * lv ) ;
/* Given a cow LV, return its origin */
struct logical_volume * origin_from_cow ( const struct logical_volume * lv ) ;
2009-05-14 01:21:58 +04:00
void init_snapshot_seg ( struct lv_segment * seg , struct logical_volume * origin ,
2010-01-13 04:35:49 +03:00
struct logical_volume * cow , uint32_t chunk_size , int merge ) ;
void init_snapshot_merge ( struct lv_segment * cow_seg , struct logical_volume * origin ) ;
2009-05-14 01:21:58 +04:00
2010-01-13 04:55:43 +03:00
void clear_snapshot_merge ( struct logical_volume * origin ) ;
2009-05-14 01:21:58 +04:00
int vg_add_snapshot ( struct logical_volume * origin , struct logical_volume * cow ,
2007-07-18 19:38:58 +04:00
union lvid * lvid , uint32_t extent_count ,
uint32_t chunk_size ) ;
int vg_remove_snapshot ( struct logical_volume * cow ) ;
2009-11-25 01:55:55 +03:00
int vg_check_status ( const struct volume_group * vg , uint64_t status ) ;
2007-07-18 19:38:58 +04:00
2009-05-14 01:27:43 +04:00
/*
* Returns visible LV count - number of LVs from user perspective
*/
unsigned vg_visible_lvs ( const struct volume_group * vg ) ;
2009-05-14 01:22:57 +04:00
2009-05-14 01:29:10 +04:00
/*
* Check if the VG reached maximal LVs count ( if set )
*/
int vg_max_lv_reached ( struct volume_group * vg ) ;
2007-07-18 19:38:58 +04:00
/*
* Mirroring functions
*/
2008-01-16 22:00:59 +03:00
struct lv_segment * find_mirror_seg ( struct lv_segment * seg ) ;
2007-12-20 18:42:55 +03:00
int lv_add_mirrors ( struct cmd_context * cmd , struct logical_volume * lv ,
uint32_t mirrors , uint32_t stripes ,
uint32_t region_size , uint32_t log_count ,
2008-11-04 01:14:30 +03:00
struct dm_list * pvs , alloc_policy_t alloc , uint32_t flags ) ;
2010-01-09 01:32:35 +03:00
int lv_split_mirror_images ( struct logical_volume * lv , const char * split_lv_name ,
uint32_t split_count , struct dm_list * removable_pvs ) ;
2007-12-20 18:42:55 +03:00
int lv_remove_mirrors ( struct cmd_context * cmd , struct logical_volume * lv ,
uint32_t mirrors , uint32_t log_count ,
2009-11-25 01:55:55 +03:00
struct dm_list * pvs , uint64_t status_mask ) ;
2007-12-20 18:42:55 +03:00
2007-12-20 21:55:46 +03:00
int is_temporary_mirror_layer ( const struct logical_volume * lv ) ;
2008-01-16 22:13:51 +03:00
struct logical_volume * find_temporary_mirror ( const struct logical_volume * lv ) ;
2007-12-20 21:55:46 +03:00
uint32_t lv_mirror_count ( const struct logical_volume * lv ) ;
2007-07-18 19:38:58 +04:00
uint32_t adjusted_mirror_region_size ( uint32_t extent_size , uint32_t extents ,
uint32_t region_size ) ;
2007-12-20 18:42:55 +03:00
int remove_mirrors_from_segments ( struct logical_volume * lv ,
2009-11-25 01:55:55 +03:00
uint32_t new_mirrors , uint64_t status_mask ) ;
2007-12-20 18:42:55 +03:00
int add_mirrors_to_segments ( struct cmd_context * cmd , struct logical_volume * lv ,
uint32_t mirrors , uint32_t region_size ,
2008-11-04 01:14:30 +03:00
struct dm_list * allocatable_pvs , alloc_policy_t alloc ) ;
2007-07-18 19:38:58 +04:00
2007-12-20 21:55:46 +03:00
int remove_mirror_images ( struct logical_volume * lv , uint32_t num_mirrors ,
2008-11-04 01:14:30 +03:00
struct dm_list * removable_pvs , unsigned remove_log ) ;
2007-12-20 18:42:55 +03:00
int add_mirror_images ( struct cmd_context * cmd , struct logical_volume * lv ,
uint32_t mirrors , uint32_t stripes , uint32_t region_size ,
2008-11-04 01:14:30 +03:00
struct dm_list * allocatable_pvs , alloc_policy_t alloc ,
2007-12-20 18:42:55 +03:00
uint32_t log_count ) ;
2008-01-26 03:25:04 +03:00
struct logical_volume * detach_mirror_log ( struct lv_segment * seg ) ;
int attach_mirror_log ( struct lv_segment * seg , struct logical_volume * lv ) ;
2007-12-20 18:42:55 +03:00
int remove_mirror_log ( struct cmd_context * cmd , struct logical_volume * lv ,
2008-11-04 01:14:30 +03:00
struct dm_list * removable_pvs ) ;
2007-12-20 18:42:55 +03:00
int add_mirror_log ( struct cmd_context * cmd , struct logical_volume * lv ,
uint32_t log_count , uint32_t region_size ,
2008-11-04 01:14:30 +03:00
struct dm_list * allocatable_pvs , alloc_policy_t alloc ) ;
2007-12-20 18:42:55 +03:00
2007-07-18 19:38:58 +04:00
int reconfigure_mirror_images ( struct lv_segment * mirrored_seg , uint32_t num_mirrors ,
2008-11-04 01:14:30 +03:00
struct dm_list * removable_pvs , unsigned remove_log ) ;
2007-12-20 21:55:46 +03:00
int collapse_mirrored_lv ( struct logical_volume * lv ) ;
2008-09-18 23:56:50 +04:00
int shift_mirror_images ( struct lv_segment * mirrored_seg , unsigned mimage ) ;
2007-07-18 19:38:58 +04:00
struct logical_volume * find_pvmove_lv ( struct volume_group * vg ,
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 ,
2009-06-01 18:43:27 +04:00
const char * uuid ,
2007-07-18 19:38:58 +04:00
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 ) ;
2009-10-01 05:04:27 +04:00
float copy_percent ( struct logical_volume * lv_mirr ,
percent_range_t * percent_range ) ;
2008-11-04 01:14:30 +03:00
struct dm_list * lvs_using_lv ( struct cmd_context * cmd , struct volume_group * vg ,
2007-07-18 19:38:58 +04:00
struct logical_volume * lv ) ;
uint32_t find_free_lvnum ( struct logical_volume * lv ) ;
char * generate_lv_name ( struct volume_group * vg , const char * format ,
char * buffer , size_t len ) ;
/*
* Begin skeleton for external LVM library
*/
2009-07-29 17:26:01 +04:00
struct device * pv_dev ( const struct physical_volume * pv ) ;
const char * pv_vg_name ( const struct physical_volume * pv ) ;
const char * pv_dev_name ( const struct physical_volume * pv ) ;
uint64_t pv_size ( const struct physical_volume * pv ) ;
2010-02-14 06:21:37 +03:00
uint64_t pv_size_field ( const struct physical_volume * pv ) ;
uint64_t pv_dev_size ( const struct physical_volume * pv ) ;
uint64_t pv_free ( const struct physical_volume * pv ) ;
2009-11-25 01:55:55 +03:00
uint64_t pv_status ( const struct physical_volume * pv ) ;
2009-07-29 17:26:01 +04:00
uint32_t pv_pe_size ( const struct physical_volume * pv ) ;
uint64_t pv_pe_start ( const struct physical_volume * pv ) ;
uint32_t pv_pe_count ( const struct physical_volume * pv ) ;
uint32_t pv_pe_alloc_count ( const struct physical_volume * pv ) ;
uint32_t pv_mda_count ( const struct physical_volume * pv ) ;
uint64_t lv_size ( const struct logical_volume * lv ) ;
int vg_missing_pv_count ( const struct volume_group * vg ) ;
uint32_t vg_seqno ( const struct volume_group * vg ) ;
2009-11-25 01:55:55 +03:00
uint64_t vg_status ( const struct volume_group * vg ) ;
2009-07-29 17:26:01 +04:00
uint64_t vg_size ( const struct volume_group * vg ) ;
uint64_t vg_free ( const struct volume_group * vg ) ;
uint64_t vg_extent_size ( const struct volume_group * vg ) ;
uint64_t vg_extent_count ( const struct volume_group * vg ) ;
uint64_t vg_free_count ( const struct volume_group * vg ) ;
uint64_t vg_pv_count ( const struct volume_group * vg ) ;
2009-09-14 19:45:23 +04:00
uint64_t vg_max_pv ( const struct volume_group * vg ) ;
uint64_t vg_max_lv ( const struct volume_group * vg ) ;
2009-10-31 20:26:13 +03:00
uint32_t vg_mda_count ( const struct volume_group * vg ) ;
2009-07-29 17:26:01 +04:00
int vg_check_write_mode ( struct volume_group * vg ) ;
2008-04-10 21:09:32 +04:00
# define vg_is_clustered(vg) (vg_status((vg)) & CLUSTERED)
2009-09-14 23:43:11 +04:00
# define vg_is_exported(vg) (vg_status((vg)) & EXPORTED_VG)
2009-09-15 22:35:13 +04:00
# define vg_is_resizeable(vg) (vg_status((vg)) & RESIZEABLE_VG)
2007-07-18 19:38:58 +04:00
2009-10-16 21:41:49 +04:00
int lv_has_unknown_segments ( const struct logical_volume * lv ) ;
int vg_has_unknown_segments ( const struct volume_group * vg ) ;
2008-01-15 00:07:58 +03:00
struct vgcreate_params {
char * vg_name ;
uint32_t extent_size ;
size_t max_pv ;
size_t max_lv ;
alloc_policy_t alloc ;
int clustered ; /* FIXME: put this into a 'status' variable instead? */
} ;
2009-11-01 23:05:17 +03:00
int vgcreate_params_validate ( struct cmd_context * cmd ,
struct vgcreate_params * vp ) ;
2008-01-15 00:07:58 +03:00
2008-01-16 01:56:30 +03:00
int validate_vg_rename_params ( struct cmd_context * cmd ,
const char * vg_name_old ,
const char * vg_name_new ) ;
2007-07-18 19:38:58 +04:00
# endif