Home | History | Annotate | Line # | Download | only in include
metadata-exported.h revision 1.1
      1  1.1  haad /*	$NetBSD: metadata-exported.h,v 1.1 2008/12/22 00:18:44 haad Exp $	*/
      2  1.1  haad 
      3  1.1  haad /*
      4  1.1  haad  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
      5  1.1  haad  * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
      6  1.1  haad  *
      7  1.1  haad  * This file is part of LVM2.
      8  1.1  haad  *
      9  1.1  haad  * This copyrighted material is made available to anyone wishing to use,
     10  1.1  haad  * modify, copy, or redistribute it subject to the terms and conditions
     11  1.1  haad  * of the GNU Lesser General Public License v.2.1.
     12  1.1  haad  *
     13  1.1  haad  * You should have received a copy of the GNU Lesser General Public License
     14  1.1  haad  * along with this program; if not, write to the Free Software Foundation,
     15  1.1  haad  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     16  1.1  haad  */
     17  1.1  haad 
     18  1.1  haad /*
     19  1.1  haad  * This is the representation of LVM metadata that is being adapted
     20  1.1  haad  * for library export.
     21  1.1  haad  */
     22  1.1  haad 
     23  1.1  haad #ifndef _LVM_METADATA_EXPORTED_H
     24  1.1  haad #define _LVM_METADATA_EXPORTED_H
     25  1.1  haad 
     26  1.1  haad #include "uuid.h"
     27  1.1  haad 
     28  1.1  haad struct physical_volume;
     29  1.1  haad typedef struct physical_volume pv_t;
     30  1.1  haad struct volume_group;
     31  1.1  haad typedef struct volume_group vg_t;
     32  1.1  haad 
     33  1.1  haad struct logical_volume;
     34  1.1  haad 
     35  1.1  haad struct lv_segment;
     36  1.1  haad struct pv_segment;
     37  1.1  haad 
     38  1.1  haad #define MAX_STRIPES 128U
     39  1.1  haad #define SECTOR_SHIFT 9L
     40  1.1  haad #define STRIPE_SIZE_MIN ( (unsigned) lvm_getpagesize() >> SECTOR_SHIFT)	/* PAGESIZE in sectors */
     41  1.1  haad #define STRIPE_SIZE_MAX ( 512L * 1024L >> SECTOR_SHIFT)	/* 512 KB in sectors */
     42  1.1  haad #define STRIPE_SIZE_LIMIT ((UINT_MAX >> 2) + 1)
     43  1.1  haad #define PV_MIN_SIZE ( 512L * 1024L >> SECTOR_SHIFT)	/* 512 KB in sectors */
     44  1.1  haad #define MAX_RESTRICTED_LVS 255	/* Used by FMT_RESTRICTED_LVIDS */
     45  1.1  haad 
     46  1.1  haad /* Layer suffix */
     47  1.1  haad #define MIRROR_SYNC_LAYER "_mimagetmp"
     48  1.1  haad 
     49  1.1  haad /* Various flags */
     50  1.1  haad /* Note that the bits no longer necessarily correspond to LVM1 disk format */
     51  1.1  haad 
     52  1.1  haad #define PARTIAL_VG		0x00000001U	/* VG */
     53  1.1  haad #define EXPORTED_VG          	0x00000002U	/* VG PV */
     54  1.1  haad #define RESIZEABLE_VG        	0x00000004U	/* VG */
     55  1.1  haad 
     56  1.1  haad /* May any free extents on this PV be used or must they be left free? */
     57  1.1  haad #define ALLOCATABLE_PV         	0x00000008U	/* PV */
     58  1.1  haad 
     59  1.1  haad //#define SPINDOWN_LV          	0x00000010U	/* LV */
     60  1.1  haad //#define BADBLOCK_ON       	0x00000020U	/* LV */
     61  1.1  haad #define VISIBLE_LV		0x00000040U	/* LV */
     62  1.1  haad #define FIXED_MINOR		0x00000080U	/* LV */
     63  1.1  haad /* FIXME Remove when metadata restructuring is completed */
     64  1.1  haad #define SNAPSHOT		0x00001000U	/* LV - internal use only */
     65  1.1  haad #define PVMOVE			0x00002000U	/* VG LV SEG */
     66  1.1  haad #define LOCKED			0x00004000U	/* LV */
     67  1.1  haad #define MIRRORED		0x00008000U	/* LV - internal use only */
     68  1.1  haad //#define VIRTUAL			0x00010000U	/* LV - internal use only */
     69  1.1  haad #define MIRROR_LOG		0x00020000U	/* LV */
     70  1.1  haad #define MIRROR_IMAGE		0x00040000U	/* LV */
     71  1.1  haad #define MIRROR_NOTSYNCED	0x00080000U	/* LV */
     72  1.1  haad //#define ACTIVATE_EXCL		0x00100000U	/* LV - internal use only */
     73  1.1  haad //#define PRECOMMITTED		0x00200000U	/* VG - internal use only */
     74  1.1  haad #define CONVERTING		0x00400000U	/* LV */
     75  1.1  haad 
     76  1.1  haad #define MISSING_PV              0x00800000U	/* PV */
     77  1.1  haad #define PARTIAL_LV              0x01000000U	/* LV - derived flag, not
     78  1.1  haad 						   written out in metadata*/
     79  1.1  haad 
     80  1.1  haad //#define POSTORDER_FLAG	0x02000000U /* Not real flags, reserved for
     81  1.1  haad //#define POSTORDER_OPEN_FLAG	0x04000000U    temporary use inside vg_read. */
     82  1.1  haad 
     83  1.1  haad #define LVM_READ              	0x00000100U	/* LV VG */
     84  1.1  haad #define LVM_WRITE             	0x00000200U	/* LV VG */
     85  1.1  haad #define CLUSTERED         	0x00000400U	/* VG */
     86  1.1  haad //#define SHARED            	0x00000800U	/* VG */
     87  1.1  haad 
     88  1.1  haad /* Format features flags */
     89  1.1  haad #define FMT_SEGMENTS		0x00000001U	/* Arbitrary segment params? */
     90  1.1  haad #define FMT_MDAS		0x00000002U	/* Proper metadata areas? */
     91  1.1  haad #define FMT_TAGS		0x00000004U	/* Tagging? */
     92  1.1  haad #define FMT_UNLIMITED_VOLS	0x00000008U	/* Unlimited PVs/LVs? */
     93  1.1  haad #define FMT_RESTRICTED_LVIDS	0x00000010U	/* LVID <= 255 */
     94  1.1  haad #define FMT_ORPHAN_ALLOCATABLE	0x00000020U	/* Orphan PV allocatable? */
     95  1.1  haad //#define FMT_PRECOMMIT		0x00000040U	/* Supports pre-commit? */
     96  1.1  haad #define FMT_RESIZE_PV		0x00000080U	/* Supports pvresize? */
     97  1.1  haad #define FMT_UNLIMITED_STRIPESIZE 0x00000100U	/* Unlimited stripe size? */
     98  1.1  haad #define FMT_RESTRICTED_READAHEAD 0x00000200U	/* Readahead restricted to 2-120? */
     99  1.1  haad 
    100  1.1  haad /* LVM2 external library flags */
    101  1.1  haad #define CORRECT_INCONSISTENT    0x00000001U /* Correct inconsistent metadata */
    102  1.1  haad #define FAIL_INCONSISTENT       0x00000002U /* Fail if metadata inconsistent */
    103  1.1  haad 
    104  1.1  haad /* Mirror conversion type flags */
    105  1.1  haad #define MIRROR_BY_SEG		0x00000001U	/* segment-by-segment mirror */
    106  1.1  haad #define MIRROR_BY_LV		0x00000002U	/* mirror using whole mimage LVs */
    107  1.1  haad #define MIRROR_SKIP_INIT_SYNC	0x00000010U	/* skip initial sync */
    108  1.1  haad 
    109  1.1  haad /* Ordered list - see lv_manip.c */
    110  1.1  haad typedef enum {
    111  1.1  haad 	ALLOC_INVALID,
    112  1.1  haad 	ALLOC_CONTIGUOUS,
    113  1.1  haad 	ALLOC_CLING,
    114  1.1  haad 	ALLOC_NORMAL,
    115  1.1  haad 	ALLOC_ANYWHERE,
    116  1.1  haad 	ALLOC_INHERIT
    117  1.1  haad } alloc_policy_t;
    118  1.1  haad 
    119  1.1  haad typedef enum {
    120  1.1  haad 	AREA_UNASSIGNED,
    121  1.1  haad 	AREA_PV,
    122  1.1  haad 	AREA_LV
    123  1.1  haad } area_type_t;
    124  1.1  haad 
    125  1.1  haad /*
    126  1.1  haad  * Whether or not to force an operation.
    127  1.1  haad  */
    128  1.1  haad typedef enum {
    129  1.1  haad 	PROMPT = 0, /* Issue yes/no prompt to confirm operation */
    130  1.1  haad 	DONT_PROMPT = 1, /* Skip yes/no prompt */
    131  1.1  haad 	DONT_PROMPT_OVERRIDE = 2 /* Skip prompt + override a second condition */
    132  1.1  haad } force_t;
    133  1.1  haad 
    134  1.1  haad struct cmd_context;
    135  1.1  haad struct format_handler;
    136  1.1  haad struct labeller;
    137  1.1  haad 
    138  1.1  haad struct format_type {
    139  1.1  haad 	struct dm_list list;
    140  1.1  haad 	struct cmd_context *cmd;
    141  1.1  haad 	struct format_handler *ops;
    142  1.1  haad 	struct labeller *labeller;
    143  1.1  haad 	const char *name;
    144  1.1  haad 	const char *alias;
    145  1.1  haad 	const char *orphan_vg_name;
    146  1.1  haad 	uint32_t features;
    147  1.1  haad 	void *library;
    148  1.1  haad 	void *private;
    149  1.1  haad };
    150  1.1  haad 
    151  1.1  haad struct pv_segment {
    152  1.1  haad 	struct dm_list list;	/* Member of pv->segments: ordered list
    153  1.1  haad 				 * covering entire data area on this PV */
    154  1.1  haad 
    155  1.1  haad 	struct physical_volume *pv;
    156  1.1  haad 	uint32_t pe;
    157  1.1  haad 	uint32_t len;
    158  1.1  haad 
    159  1.1  haad 	struct lv_segment *lvseg;	/* NULL if free space */
    160  1.1  haad 	uint32_t lv_area;	/* Index to area in LV segment */
    161  1.1  haad };
    162  1.1  haad 
    163  1.1  haad #define pvseg_is_allocated(pvseg) ((pvseg)->lvseg)
    164  1.1  haad 
    165  1.1  haad struct physical_volume {
    166  1.1  haad 	struct id id;
    167  1.1  haad 	struct device *dev;
    168  1.1  haad 	const struct format_type *fmt;
    169  1.1  haad 	const char *vg_name;
    170  1.1  haad 	struct id vgid;
    171  1.1  haad 
    172  1.1  haad 	uint32_t status;
    173  1.1  haad 	uint64_t size;
    174  1.1  haad 
    175  1.1  haad 	/* physical extents */
    176  1.1  haad 	uint32_t pe_size;
    177  1.1  haad 	uint64_t pe_start;
    178  1.1  haad 	uint32_t pe_count;
    179  1.1  haad 	uint32_t pe_alloc_count;
    180  1.1  haad 	unsigned long pe_align;
    181  1.1  haad 
    182  1.1  haad 	struct dm_list segments;	/* Ordered pv_segments covering complete PV */
    183  1.1  haad 	struct dm_list tags;
    184  1.1  haad };
    185  1.1  haad 
    186  1.1  haad struct format_instance {
    187  1.1  haad 	const struct format_type *fmt;
    188  1.1  haad 	struct dm_list metadata_areas;	/* e.g. metadata locations */
    189  1.1  haad 	void *private;
    190  1.1  haad };
    191  1.1  haad 
    192  1.1  haad struct volume_group {
    193  1.1  haad 	struct cmd_context *cmd;
    194  1.1  haad 	struct format_instance *fid;
    195  1.1  haad 	uint32_t seqno;		/* Metadata sequence number */
    196  1.1  haad 
    197  1.1  haad 	struct id id;
    198  1.1  haad 	char *name;
    199  1.1  haad 	char *system_id;
    200  1.1  haad 
    201  1.1  haad 	uint32_t status;
    202  1.1  haad 	alloc_policy_t alloc;
    203  1.1  haad 
    204  1.1  haad 	uint32_t extent_size;
    205  1.1  haad 	uint32_t extent_count;
    206  1.1  haad 	uint32_t free_count;
    207  1.1  haad 
    208  1.1  haad 	uint32_t max_lv;
    209  1.1  haad 	uint32_t max_pv;
    210  1.1  haad 
    211  1.1  haad 	/* physical volumes */
    212  1.1  haad 	uint32_t pv_count;
    213  1.1  haad 	struct dm_list pvs;
    214  1.1  haad 
    215  1.1  haad 	/*
    216  1.1  haad 	 * logical volumes
    217  1.1  haad 	 * The following relationship should always hold:
    218  1.1  haad 	 * dm_list_size(lvs) = lv_count + 2 * snapshot_count
    219  1.1  haad 	 *
    220  1.1  haad 	 * Snapshots consist of 2 instances of "struct logical_volume":
    221  1.1  haad 	 * - cow (lv_name is visible to the user)
    222  1.1  haad 	 * - snapshot (lv_name is 'snapshotN')
    223  1.1  haad 	 * Neither of these instances is reflected in lv_count, but we
    224  1.1  haad 	 * multiply the snapshot_count by 2.
    225  1.1  haad 	 *
    226  1.1  haad 	 * Mirrors consist of multiple instances of "struct logical_volume":
    227  1.1  haad 	 * - one for the mirror log
    228  1.1  haad 	 * - one for each mirror leg
    229  1.1  haad 	 * - one for the user-visible mirror LV
    230  1.1  haad 	 * all of the instances are reflected in lv_count.
    231  1.1  haad 	 */
    232  1.1  haad 	uint32_t lv_count;
    233  1.1  haad 	uint32_t snapshot_count;
    234  1.1  haad 	struct dm_list lvs;
    235  1.1  haad 
    236  1.1  haad 	struct dm_list tags;
    237  1.1  haad };
    238  1.1  haad 
    239  1.1  haad /* There will be one area for each stripe */
    240  1.1  haad struct lv_segment_area {
    241  1.1  haad 	area_type_t type;
    242  1.1  haad 	union {
    243  1.1  haad 		struct {
    244  1.1  haad 			struct pv_segment *pvseg;
    245  1.1  haad 		} pv;
    246  1.1  haad 		struct {
    247  1.1  haad 			struct logical_volume *lv;
    248  1.1  haad 			uint32_t le;
    249  1.1  haad 		} lv;
    250  1.1  haad 	} u;
    251  1.1  haad };
    252  1.1  haad 
    253  1.1  haad struct segment_type;
    254  1.1  haad struct lv_segment {
    255  1.1  haad 	struct dm_list list;
    256  1.1  haad 	struct logical_volume *lv;
    257  1.1  haad 
    258  1.1  haad 	const struct segment_type *segtype;
    259  1.1  haad 	uint32_t le;
    260  1.1  haad 	uint32_t len;
    261  1.1  haad 
    262  1.1  haad 	uint32_t status;
    263  1.1  haad 
    264  1.1  haad 	/* FIXME Fields depend on segment type */
    265  1.1  haad 	uint32_t stripe_size;
    266  1.1  haad 	uint32_t area_count;
    267  1.1  haad 	uint32_t area_len;
    268  1.1  haad 	struct logical_volume *origin;
    269  1.1  haad 	struct logical_volume *cow;
    270  1.1  haad 	struct dm_list origin_list;
    271  1.1  haad 	uint32_t chunk_size;	/* For snapshots - in sectors */
    272  1.1  haad 	uint32_t region_size;	/* For mirrors - in sectors */
    273  1.1  haad 	uint32_t extents_copied;
    274  1.1  haad 	struct logical_volume *log_lv;
    275  1.1  haad 
    276  1.1  haad 	struct dm_list tags;
    277  1.1  haad 
    278  1.1  haad 	struct lv_segment_area *areas;
    279  1.1  haad };
    280  1.1  haad 
    281  1.1  haad #define seg_type(seg, s)	(seg)->areas[(s)].type
    282  1.1  haad #define seg_pv(seg, s)		(seg)->areas[(s)].u.pv.pvseg->pv
    283  1.1  haad #define seg_lv(seg, s)		(seg)->areas[(s)].u.lv.lv
    284  1.1  haad 
    285  1.1  haad struct logical_volume {
    286  1.1  haad 	union lvid lvid;
    287  1.1  haad 	char *name;
    288  1.1  haad 
    289  1.1  haad 	struct volume_group *vg;
    290  1.1  haad 
    291  1.1  haad 	uint32_t status;
    292  1.1  haad 	alloc_policy_t alloc;
    293  1.1  haad 	uint32_t read_ahead;
    294  1.1  haad 	int32_t major;
    295  1.1  haad 	int32_t minor;
    296  1.1  haad 
    297  1.1  haad 	uint64_t size;		/* Sectors */
    298  1.1  haad 	uint32_t le_count;
    299  1.1  haad 
    300  1.1  haad 	uint32_t origin_count;
    301  1.1  haad 	struct dm_list snapshot_segs;
    302  1.1  haad 	struct lv_segment *snapshot;
    303  1.1  haad 
    304  1.1  haad 	struct dm_list segments;
    305  1.1  haad 	struct dm_list tags;
    306  1.1  haad 	struct dm_list segs_using_this_lv;
    307  1.1  haad };
    308  1.1  haad 
    309  1.1  haad struct pe_range {
    310  1.1  haad 	struct dm_list list;
    311  1.1  haad 	uint32_t start;		/* PEs */
    312  1.1  haad 	uint32_t count;		/* PEs */
    313  1.1  haad };
    314  1.1  haad 
    315  1.1  haad struct pv_list {
    316  1.1  haad 	struct dm_list list;
    317  1.1  haad 	struct physical_volume *pv;
    318  1.1  haad 	struct dm_list *mdas;	/* Metadata areas */
    319  1.1  haad 	struct dm_list *pe_ranges;	/* Ranges of PEs e.g. for allocation */
    320  1.1  haad };
    321  1.1  haad 
    322  1.1  haad struct lv_list {
    323  1.1  haad 	struct dm_list list;
    324  1.1  haad 	struct logical_volume *lv;
    325  1.1  haad };
    326  1.1  haad 
    327  1.1  haad /*
    328  1.1  haad * Utility functions
    329  1.1  haad */
    330  1.1  haad int vg_write(struct volume_group *vg);
    331  1.1  haad int vg_commit(struct volume_group *vg);
    332  1.1  haad int vg_revert(struct volume_group *vg);
    333  1.1  haad struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name,
    334  1.1  haad 			     const char *vgid, int *consistent);
    335  1.1  haad struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name,
    336  1.1  haad 				struct dm_list *mdas, uint64_t *label_sector,
    337  1.1  haad 				int warnings);
    338  1.1  haad struct dm_list *get_pvs(struct cmd_context *cmd);
    339  1.1  haad 
    340  1.1  haad /* Set full_scan to 1 to re-read every (filtered) device label */
    341  1.1  haad struct dm_list *get_vgs(struct cmd_context *cmd, int full_scan);
    342  1.1  haad struct dm_list *get_vgids(struct cmd_context *cmd, int full_scan);
    343  1.1  haad int scan_vgs_for_pvs(struct cmd_context *cmd);
    344  1.1  haad 
    345  1.1  haad int pv_write(struct cmd_context *cmd, struct physical_volume *pv,
    346  1.1  haad 	     struct dm_list *mdas, int64_t label_sector);
    347  1.1  haad int is_pv(pv_t *pv);
    348  1.1  haad int is_orphan_vg(const char *vg_name);
    349  1.1  haad int is_orphan(const pv_t *pv);
    350  1.1  haad int vgs_are_compatible(struct cmd_context *cmd,
    351  1.1  haad 		       struct volume_group *vg_from,
    352  1.1  haad 		       struct volume_group *vg_to);
    353  1.1  haad vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name,
    354  1.1  haad 		       const char *vgid,
    355  1.1  haad 		       uint32_t lock_flags, uint32_t status_flags,
    356  1.1  haad 		       uint32_t misc_flags);
    357  1.1  haad 
    358  1.1  haad /* pe_start and pe_end relate to any existing data so that new metadata
    359  1.1  haad * areas can avoid overlap */
    360  1.1  haad pv_t *pv_create(const struct cmd_context *cmd,
    361  1.1  haad 		      struct device *dev,
    362  1.1  haad 		      struct id *id,
    363  1.1  haad 		      uint64_t size,
    364  1.1  haad 		      uint64_t pe_start,
    365  1.1  haad 		      uint32_t existing_extent_count,
    366  1.1  haad 		      uint32_t existing_extent_size,
    367  1.1  haad 		      int pvmetadatacopies,
    368  1.1  haad 		      uint64_t pvmetadatasize, struct dm_list *mdas);
    369  1.1  haad int pv_resize(struct physical_volume *pv, struct volume_group *vg,
    370  1.1  haad              uint32_t new_pe_count);
    371  1.1  haad int pv_analyze(struct cmd_context *cmd, const char *pv_name,
    372  1.1  haad 	       uint64_t label_sector);
    373  1.1  haad 
    374  1.1  haad /* FIXME: move internal to library */
    375  1.1  haad uint32_t pv_list_extents_free(const struct dm_list *pvh);
    376  1.1  haad 
    377  1.1  haad struct volume_group *vg_create(struct cmd_context *cmd, const char *name,
    378  1.1  haad 			       uint32_t extent_size, uint32_t max_pv,
    379  1.1  haad 			       uint32_t max_lv, alloc_policy_t alloc,
    380  1.1  haad 			       int pv_count, char **pv_names);
    381  1.1  haad int vg_remove(struct volume_group *vg);
    382  1.1  haad int vg_remove_single(struct cmd_context *cmd, const char *vg_name,
    383  1.1  haad 		     struct volume_group *vg, int consistent,
    384  1.1  haad 		     force_t force);
    385  1.1  haad int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
    386  1.1  haad 	      const char *new_name);
    387  1.1  haad int vg_extend(struct volume_group *vg, int pv_count, char **pv_names);
    388  1.1  haad int vg_change_pesize(struct cmd_context *cmd, struct volume_group *vg,
    389  1.1  haad 		     uint32_t new_extent_size);
    390  1.1  haad int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from,
    391  1.1  haad 		  struct volume_group *vg_to);
    392  1.1  haad 
    393  1.1  haad /* Manipulate LVs */
    394  1.1  haad struct logical_volume *lv_create_empty(const char *name,
    395  1.1  haad 				       union lvid *lvid,
    396  1.1  haad 				       uint32_t status,
    397  1.1  haad 				       alloc_policy_t alloc,
    398  1.1  haad 				       int import,
    399  1.1  haad 				       struct volume_group *vg);
    400  1.1  haad 
    401  1.1  haad /* Write out LV contents */
    402  1.1  haad int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
    403  1.1  haad            uint64_t sectors, int value);
    404  1.1  haad 
    405  1.1  haad /* Reduce the size of an LV by extents */
    406  1.1  haad int lv_reduce(struct logical_volume *lv, uint32_t extents);
    407  1.1  haad 
    408  1.1  haad /* Empty an LV prior to deleting it */
    409  1.1  haad int lv_empty(struct logical_volume *lv);
    410  1.1  haad 
    411  1.1  haad /* Empty an LV and add error segment */
    412  1.1  haad int replace_lv_with_error_segment(struct logical_volume *lv);
    413  1.1  haad 
    414  1.1  haad /* Entry point for all LV extent allocations */
    415  1.1  haad int lv_extend(struct logical_volume *lv,
    416  1.1  haad 	      const struct segment_type *segtype,
    417  1.1  haad 	      uint32_t stripes, uint32_t stripe_size,
    418  1.1  haad 	      uint32_t mirrors, uint32_t extents,
    419  1.1  haad 	      struct physical_volume *mirrored_pv, uint32_t mirrored_pe,
    420  1.1  haad 	      uint32_t status, struct dm_list *allocatable_pvs,
    421  1.1  haad 	      alloc_policy_t alloc);
    422  1.1  haad 
    423  1.1  haad /* lv must be part of lv->vg->lvs */
    424  1.1  haad int lv_remove(struct logical_volume *lv);
    425  1.1  haad 
    426  1.1  haad int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
    427  1.1  haad 		     force_t force);
    428  1.1  haad 
    429  1.1  haad int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *lv,
    430  1.1  haad 				force_t force);
    431  1.1  haad 
    432  1.1  haad int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,
    433  1.1  haad 	      const char *new_name);
    434  1.1  haad 
    435  1.1  haad /*
    436  1.1  haad  * Functions for layer manipulation
    437  1.1  haad  */
    438  1.1  haad int insert_layer_for_segments_on_pv(struct cmd_context *cmd,
    439  1.1  haad 				    struct logical_volume *lv_where,
    440  1.1  haad 				    struct logical_volume *layer_lv,
    441  1.1  haad 				    uint32_t status,
    442  1.1  haad 				    struct pv_list *pv,
    443  1.1  haad 				    struct dm_list *lvs_changed);
    444  1.1  haad int remove_layers_for_segments(struct cmd_context *cmd,
    445  1.1  haad 			       struct logical_volume *lv,
    446  1.1  haad 			       struct logical_volume *layer_lv,
    447  1.1  haad 			       uint32_t status_mask, struct dm_list *lvs_changed);
    448  1.1  haad int remove_layers_for_segments_all(struct cmd_context *cmd,
    449  1.1  haad 				   struct logical_volume *layer_lv,
    450  1.1  haad 				   uint32_t status_mask,
    451  1.1  haad 				   struct dm_list *lvs_changed);
    452  1.1  haad int split_parent_segments_for_layer(struct cmd_context *cmd,
    453  1.1  haad 				    struct logical_volume *layer_lv);
    454  1.1  haad int remove_layer_from_lv(struct logical_volume *lv,
    455  1.1  haad 			 struct logical_volume *layer_lv);
    456  1.1  haad struct logical_volume *insert_layer_for_lv(struct cmd_context *cmd,
    457  1.1  haad 					   struct logical_volume *lv_where,
    458  1.1  haad 					   uint32_t status,
    459  1.1  haad 					   const char *layer_suffix);
    460  1.1  haad 
    461  1.1  haad /* Find a PV within a given VG */
    462  1.1  haad struct pv_list *find_pv_in_vg(const struct volume_group *vg,
    463  1.1  haad 			      const char *pv_name);
    464  1.1  haad pv_t *find_pv_in_vg_by_uuid(const struct volume_group *vg,
    465  1.1  haad 			    const struct id *id);
    466  1.1  haad 
    467  1.1  haad /* Find an LV within a given VG */
    468  1.1  haad struct lv_list *find_lv_in_vg(const struct volume_group *vg,
    469  1.1  haad 			      const char *lv_name);
    470  1.1  haad 
    471  1.1  haad /* FIXME Merge these functions with ones above */
    472  1.1  haad struct logical_volume *find_lv(const struct volume_group *vg,
    473  1.1  haad 			       const char *lv_name);
    474  1.1  haad struct physical_volume *find_pv_by_name(struct cmd_context *cmd,
    475  1.1  haad 					const char *pv_name);
    476  1.1  haad 
    477  1.1  haad /* Find LV segment containing given LE */
    478  1.1  haad struct lv_segment *first_seg(const struct logical_volume *lv);
    479  1.1  haad 
    480  1.1  haad 
    481  1.1  haad /*
    482  1.1  haad * Useful functions for managing snapshots.
    483  1.1  haad */
    484  1.1  haad int lv_is_origin(const struct logical_volume *lv);
    485  1.1  haad int lv_is_cow(const struct logical_volume *lv);
    486  1.1  haad int lv_is_visible(const struct logical_volume *lv);
    487  1.1  haad 
    488  1.1  haad int pv_is_in_vg(struct volume_group *vg, struct physical_volume *pv);
    489  1.1  haad 
    490  1.1  haad /* Given a cow LV, return return the snapshot lv_segment that uses it */
    491  1.1  haad struct lv_segment *find_cow(const struct logical_volume *lv);
    492  1.1  haad 
    493  1.1  haad /* Given a cow LV, return its origin */
    494  1.1  haad struct logical_volume *origin_from_cow(const struct logical_volume *lv);
    495  1.1  haad 
    496  1.1  haad int vg_add_snapshot(const char *name,
    497  1.1  haad 		    struct logical_volume *origin, struct logical_volume *cow,
    498  1.1  haad 		    union lvid *lvid, uint32_t extent_count,
    499  1.1  haad 		    uint32_t chunk_size);
    500  1.1  haad 
    501  1.1  haad int vg_remove_snapshot(struct logical_volume *cow);
    502  1.1  haad 
    503  1.1  haad int vg_check_status(const struct volume_group *vg, uint32_t status);
    504  1.1  haad 
    505  1.1  haad /*
    506  1.1  haad * Mirroring functions
    507  1.1  haad */
    508  1.1  haad struct lv_segment *find_mirror_seg(struct lv_segment *seg);
    509  1.1  haad int lv_add_mirrors(struct cmd_context *cmd, struct logical_volume *lv,
    510  1.1  haad 		   uint32_t mirrors, uint32_t stripes,
    511  1.1  haad 		   uint32_t region_size, uint32_t log_count,
    512  1.1  haad 		   struct dm_list *pvs, alloc_policy_t alloc, uint32_t flags);
    513  1.1  haad int lv_remove_mirrors(struct cmd_context *cmd, struct logical_volume *lv,
    514  1.1  haad 		      uint32_t mirrors, uint32_t log_count,
    515  1.1  haad 		      struct dm_list *pvs, uint32_t status_mask);
    516  1.1  haad 
    517  1.1  haad int is_temporary_mirror_layer(const struct logical_volume *lv);
    518  1.1  haad struct logical_volume * find_temporary_mirror(const struct logical_volume *lv);
    519  1.1  haad uint32_t lv_mirror_count(const struct logical_volume *lv);
    520  1.1  haad uint32_t adjusted_mirror_region_size(uint32_t extent_size, uint32_t extents,
    521  1.1  haad                                     uint32_t region_size);
    522  1.1  haad int remove_mirrors_from_segments(struct logical_volume *lv,
    523  1.1  haad 				 uint32_t new_mirrors, uint32_t status_mask);
    524  1.1  haad int add_mirrors_to_segments(struct cmd_context *cmd, struct logical_volume *lv,
    525  1.1  haad 			    uint32_t mirrors, uint32_t region_size,
    526  1.1  haad 			    struct dm_list *allocatable_pvs, alloc_policy_t alloc);
    527  1.1  haad 
    528  1.1  haad int remove_mirror_images(struct logical_volume *lv, uint32_t num_mirrors,
    529  1.1  haad 			 struct dm_list *removable_pvs, unsigned remove_log);
    530  1.1  haad int add_mirror_images(struct cmd_context *cmd, struct logical_volume *lv,
    531  1.1  haad 		      uint32_t mirrors, uint32_t stripes, uint32_t region_size,
    532  1.1  haad 		      struct dm_list *allocatable_pvs, alloc_policy_t alloc,
    533  1.1  haad 		      uint32_t log_count);
    534  1.1  haad struct logical_volume *detach_mirror_log(struct lv_segment *seg);
    535  1.1  haad int attach_mirror_log(struct lv_segment *seg, struct logical_volume *lv);
    536  1.1  haad int remove_mirror_log(struct cmd_context *cmd, struct logical_volume *lv,
    537  1.1  haad 		      struct dm_list *removable_pvs);
    538  1.1  haad int add_mirror_log(struct cmd_context *cmd, struct logical_volume *lv,
    539  1.1  haad 		   uint32_t log_count, uint32_t region_size,
    540  1.1  haad 		   struct dm_list *allocatable_pvs, alloc_policy_t alloc);
    541  1.1  haad 
    542  1.1  haad int reconfigure_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
    543  1.1  haad 			      struct dm_list *removable_pvs, unsigned remove_log);
    544  1.1  haad int collapse_mirrored_lv(struct logical_volume *lv);
    545  1.1  haad int shift_mirror_images(struct lv_segment *mirrored_seg, unsigned mimage);
    546  1.1  haad 
    547  1.1  haad struct logical_volume *find_pvmove_lv(struct volume_group *vg,
    548  1.1  haad 				      struct device *dev, uint32_t lv_type);
    549  1.1  haad struct logical_volume *find_pvmove_lv_from_pvname(struct cmd_context *cmd,
    550  1.1  haad 						  struct volume_group *vg,
    551  1.1  haad 						  const char *name,
    552  1.1  haad 						  uint32_t lv_type);
    553  1.1  haad const char *get_pvmove_pvname_from_lv(struct logical_volume *lv);
    554  1.1  haad const char *get_pvmove_pvname_from_lv_mirr(struct logical_volume *lv_mirr);
    555  1.1  haad float copy_percent(struct logical_volume *lv_mirr);
    556  1.1  haad struct dm_list *lvs_using_lv(struct cmd_context *cmd, struct volume_group *vg,
    557  1.1  haad 			  struct logical_volume *lv);
    558  1.1  haad 
    559  1.1  haad uint32_t find_free_lvnum(struct logical_volume *lv);
    560  1.1  haad char *generate_lv_name(struct volume_group *vg, const char *format,
    561  1.1  haad 		       char *buffer, size_t len);
    562  1.1  haad 
    563  1.1  haad /*
    564  1.1  haad * Begin skeleton for external LVM library
    565  1.1  haad */
    566  1.1  haad struct device *pv_dev(const pv_t *pv);
    567  1.1  haad const char *pv_vg_name(const pv_t *pv);
    568  1.1  haad const char *pv_dev_name(const pv_t *pv);
    569  1.1  haad uint64_t pv_size(const pv_t *pv);
    570  1.1  haad uint32_t pv_status(const pv_t *pv);
    571  1.1  haad uint32_t pv_pe_size(const pv_t *pv);
    572  1.1  haad uint64_t pv_pe_start(const pv_t *pv);
    573  1.1  haad uint32_t pv_pe_count(const pv_t *pv);
    574  1.1  haad uint32_t pv_pe_alloc_count(const pv_t *pv);
    575  1.1  haad 
    576  1.1  haad int vg_missing_pv_count(const vg_t *vg);
    577  1.1  haad uint32_t vg_status(const vg_t *vg);
    578  1.1  haad #define vg_is_clustered(vg) (vg_status((vg)) & CLUSTERED)
    579  1.1  haad 
    580  1.1  haad struct vgcreate_params {
    581  1.1  haad 	char *vg_name;
    582  1.1  haad 	uint32_t extent_size;
    583  1.1  haad 	size_t max_pv;
    584  1.1  haad 	size_t max_lv;
    585  1.1  haad 	alloc_policy_t alloc;
    586  1.1  haad 	int clustered; /* FIXME: put this into a 'status' variable instead? */
    587  1.1  haad };
    588  1.1  haad 
    589  1.1  haad int validate_vg_create_params(struct cmd_context *cmd,
    590  1.1  haad 			      struct vgcreate_params *vp);
    591  1.1  haad 
    592  1.1  haad int validate_vg_rename_params(struct cmd_context *cmd,
    593  1.1  haad 			      const char *vg_name_old,
    594  1.1  haad 			      const char *vg_name_new);
    595  1.1  haad #endif
    596