xref: /dragonfly/contrib/lvm2/dist/include/metadata.h (revision 86d7f5d3)
1*86d7f5d3SJohn Marino /*	$NetBSD: metadata.h,v 1.1.1.3 2009/12/02 00:25:43 haad Exp $	*/
2*86d7f5d3SJohn Marino 
3*86d7f5d3SJohn Marino /*
4*86d7f5d3SJohn Marino  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5*86d7f5d3SJohn Marino  * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
6*86d7f5d3SJohn Marino  *
7*86d7f5d3SJohn Marino  * This file is part of LVM2.
8*86d7f5d3SJohn Marino  *
9*86d7f5d3SJohn Marino  * This copyrighted material is made available to anyone wishing to use,
10*86d7f5d3SJohn Marino  * modify, copy, or redistribute it subject to the terms and conditions
11*86d7f5d3SJohn Marino  * of the GNU Lesser General Public License v.2.1.
12*86d7f5d3SJohn Marino  *
13*86d7f5d3SJohn Marino  * You should have received a copy of the GNU Lesser General Public License
14*86d7f5d3SJohn Marino  * along with this program; if not, write to the Free Software Foundation,
15*86d7f5d3SJohn Marino  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16*86d7f5d3SJohn Marino  */
17*86d7f5d3SJohn Marino 
18*86d7f5d3SJohn Marino /*
19*86d7f5d3SJohn Marino  * This is the in core representation of a volume group and its
20*86d7f5d3SJohn Marino  * associated physical and logical volumes.
21*86d7f5d3SJohn Marino  */
22*86d7f5d3SJohn Marino 
23*86d7f5d3SJohn Marino #ifndef _LVM_METADATA_H
24*86d7f5d3SJohn Marino #define _LVM_METADATA_H
25*86d7f5d3SJohn Marino 
26*86d7f5d3SJohn Marino #include "ctype.h"
27*86d7f5d3SJohn Marino #include "dev-cache.h"
28*86d7f5d3SJohn Marino #include "lvm-string.h"
29*86d7f5d3SJohn Marino #include "metadata-exported.h"
30*86d7f5d3SJohn Marino 
31*86d7f5d3SJohn Marino //#define MAX_STRIPES 128U
32*86d7f5d3SJohn Marino //#define SECTOR_SHIFT 9L
33*86d7f5d3SJohn Marino #define SECTOR_SIZE ( 1L << SECTOR_SHIFT )
34*86d7f5d3SJohn Marino //#define STRIPE_SIZE_MIN ( (unsigned) lvm_getpagesize() >> SECTOR_SHIFT)	/* PAGESIZE in sectors */
35*86d7f5d3SJohn Marino //#define STRIPE_SIZE_MAX ( 512L * 1024L >> SECTOR_SHIFT)	/* 512 KB in sectors */
36*86d7f5d3SJohn Marino //#define STRIPE_SIZE_LIMIT ((UINT_MAX >> 2) + 1)
37*86d7f5d3SJohn Marino //#define PV_MIN_SIZE ( 512L * 1024L >> SECTOR_SHIFT)	/* 512 KB in sectors */
38*86d7f5d3SJohn Marino //#define MAX_RESTRICTED_LVS 255	/* Used by FMT_RESTRICTED_LVIDS */
39*86d7f5d3SJohn Marino #define MIRROR_LOG_OFFSET	2	/* sectors */
40*86d7f5d3SJohn Marino #define VG_MEMPOOL_CHUNK	10240	/* in bytes, hint only */
41*86d7f5d3SJohn Marino 
42*86d7f5d3SJohn Marino /*
43*86d7f5d3SJohn Marino  * Ceiling(n / sz)
44*86d7f5d3SJohn Marino  */
45*86d7f5d3SJohn Marino #define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz))
46*86d7f5d3SJohn Marino 
47*86d7f5d3SJohn Marino /*
48*86d7f5d3SJohn Marino  * Ceiling(n / size) * size
49*86d7f5d3SJohn Marino  */
50*86d7f5d3SJohn Marino #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
51*86d7f5d3SJohn Marino 
52*86d7f5d3SJohn Marino 
53*86d7f5d3SJohn Marino /* Various flags */
54*86d7f5d3SJohn Marino /* Note that the bits no longer necessarily correspond to LVM1 disk format */
55*86d7f5d3SJohn Marino 
56*86d7f5d3SJohn Marino //#define PARTIAL_VG		0x00000001U	/* VG */
57*86d7f5d3SJohn Marino //#define EXPORTED_VG          	0x00000002U	/* VG PV */
58*86d7f5d3SJohn Marino //#define RESIZEABLE_VG        	0x00000004U	/* VG */
59*86d7f5d3SJohn Marino 
60*86d7f5d3SJohn Marino /* May any free extents on this PV be used or must they be left free? */
61*86d7f5d3SJohn Marino //#define ALLOCATABLE_PV         	0x00000008U	/* PV */
62*86d7f5d3SJohn Marino 
63*86d7f5d3SJohn Marino #define SPINDOWN_LV          	0x00000010U	/* LV */
64*86d7f5d3SJohn Marino #define BADBLOCK_ON       	0x00000020U	/* LV */
65*86d7f5d3SJohn Marino //#define VISIBLE_LV		0x00000040U	/* LV */
66*86d7f5d3SJohn Marino //#define FIXED_MINOR		0x00000080U	/* LV */
67*86d7f5d3SJohn Marino /* FIXME Remove when metadata restructuring is completed */
68*86d7f5d3SJohn Marino //#define SNAPSHOT		0x00001000U	/* LV - internal use only */
69*86d7f5d3SJohn Marino //#define PVMOVE			0x00002000U	/* VG LV SEG */
70*86d7f5d3SJohn Marino //#define LOCKED			0x00004000U	/* LV */
71*86d7f5d3SJohn Marino //#define MIRRORED		0x00008000U	/* LV - internal use only */
72*86d7f5d3SJohn Marino #define VIRTUAL			0x00010000U	/* LV - internal use only */
73*86d7f5d3SJohn Marino //#define MIRROR_LOG		0x00020000U	/* LV */
74*86d7f5d3SJohn Marino //#define MIRROR_IMAGE		0x00040000U	/* LV */
75*86d7f5d3SJohn Marino //#define MIRROR_NOTSYNCED	0x00080000U	/* LV */
76*86d7f5d3SJohn Marino #define ACTIVATE_EXCL		0x00100000U	/* LV - internal use only */
77*86d7f5d3SJohn Marino #define PRECOMMITTED		0x00200000U	/* VG - internal use only */
78*86d7f5d3SJohn Marino //#define CONVERTING		0x00400000U	/* LV */
79*86d7f5d3SJohn Marino 
80*86d7f5d3SJohn Marino //#define MISSING_PV		0x00800000U	/* PV */
81*86d7f5d3SJohn Marino //#define PARTIAL_LV		0x01000000U	/* LV - derived flag, not
82*86d7f5d3SJohn Marino //						   written out in metadata*/
83*86d7f5d3SJohn Marino 
84*86d7f5d3SJohn Marino #define POSTORDER_FLAG		0x02000000U /* Not real flags, reserved for  */
85*86d7f5d3SJohn Marino #define POSTORDER_OPEN_FLAG	0x04000000U /* temporary use inside vg_read_internal. */
86*86d7f5d3SJohn Marino #define VIRTUAL_ORIGIN		0x08000000U	/* LV - internal use only */
87*86d7f5d3SJohn Marino 
88*86d7f5d3SJohn Marino //#define LVM_READ              	0x00000100U	/* LV VG */
89*86d7f5d3SJohn Marino //#define LVM_WRITE             	0x00000200U	/* LV VG */
90*86d7f5d3SJohn Marino //#define CLUSTERED         	0x00000400U	/* VG */
91*86d7f5d3SJohn Marino #define SHARED            	0x00000800U	/* VG */
92*86d7f5d3SJohn Marino 
93*86d7f5d3SJohn Marino /* Format features flags */
94*86d7f5d3SJohn Marino //#define FMT_SEGMENTS		0x00000001U	/* Arbitrary segment params? */
95*86d7f5d3SJohn Marino //#define FMT_MDAS		0x00000002U	/* Proper metadata areas? */
96*86d7f5d3SJohn Marino //#define FMT_TAGS		0x00000004U	/* Tagging? */
97*86d7f5d3SJohn Marino //#define FMT_UNLIMITED_VOLS	0x00000008U	/* Unlimited PVs/LVs? */
98*86d7f5d3SJohn Marino //#define FMT_RESTRICTED_LVIDS	0x00000010U	/* LVID <= 255 */
99*86d7f5d3SJohn Marino //#define FMT_ORPHAN_ALLOCATABLE	0x00000020U	/* Orphan PV allocatable? */
100*86d7f5d3SJohn Marino #define FMT_PRECOMMIT		0x00000040U	/* Supports pre-commit? */
101*86d7f5d3SJohn Marino //#define FMT_RESIZE_PV		0x00000080U	/* Supports pvresize? */
102*86d7f5d3SJohn Marino //#define FMT_UNLIMITED_STRIPESIZE 0x00000100U	/* Unlimited stripe size? */
103*86d7f5d3SJohn Marino 
104*86d7f5d3SJohn Marino struct metadata_area;
105*86d7f5d3SJohn Marino 
106*86d7f5d3SJohn Marino /* Per-format per-metadata area operations */
107*86d7f5d3SJohn Marino struct metadata_area_ops {
108*86d7f5d3SJohn Marino 	struct volume_group *(*vg_read) (struct format_instance * fi,
109*86d7f5d3SJohn Marino 					 const char *vg_name,
110*86d7f5d3SJohn Marino 					 struct metadata_area * mda);
111*86d7f5d3SJohn Marino 	struct volume_group *(*vg_read_precommit) (struct format_instance * fi,
112*86d7f5d3SJohn Marino 					 const char *vg_name,
113*86d7f5d3SJohn Marino 					 struct metadata_area * mda);
114*86d7f5d3SJohn Marino 	/*
115*86d7f5d3SJohn Marino 	 * Write out complete VG metadata.  You must ensure internal
116*86d7f5d3SJohn Marino 	 * consistency before calling. eg. PEs can't refer to PVs not
117*86d7f5d3SJohn Marino 	 * part of the VG.
118*86d7f5d3SJohn Marino 	 *
119*86d7f5d3SJohn Marino 	 * It is also the responsibility of the caller to ensure external
120*86d7f5d3SJohn Marino 	 * consistency, eg by calling pv_write() if removing PVs from
121*86d7f5d3SJohn Marino 	 * a VG or calling vg_write() a second time if splitting a VG
122*86d7f5d3SJohn Marino 	 * into two.
123*86d7f5d3SJohn Marino 	 *
124*86d7f5d3SJohn Marino 	 * vg_write() should not read or write from any PVs not included
125*86d7f5d3SJohn Marino 	 * in the volume_group structure it is handed.
126*86d7f5d3SJohn Marino 	 * (format1 currently breaks this rule.)
127*86d7f5d3SJohn Marino 	 */
128*86d7f5d3SJohn Marino 	int (*vg_write) (struct format_instance * fid, struct volume_group * vg,
129*86d7f5d3SJohn Marino 			 struct metadata_area * mda);
130*86d7f5d3SJohn Marino 	int (*vg_precommit) (struct format_instance * fid,
131*86d7f5d3SJohn Marino 			     struct volume_group * vg,
132*86d7f5d3SJohn Marino 			     struct metadata_area * mda);
133*86d7f5d3SJohn Marino 	int (*vg_commit) (struct format_instance * fid,
134*86d7f5d3SJohn Marino 			  struct volume_group * vg, struct metadata_area * mda);
135*86d7f5d3SJohn Marino 	int (*vg_revert) (struct format_instance * fid,
136*86d7f5d3SJohn Marino 			  struct volume_group * vg, struct metadata_area * mda);
137*86d7f5d3SJohn Marino 	int (*vg_remove) (struct format_instance * fi, struct volume_group * vg,
138*86d7f5d3SJohn Marino 			  struct metadata_area * mda);
139*86d7f5d3SJohn Marino 
140*86d7f5d3SJohn Marino 	/*
141*86d7f5d3SJohn Marino 	 * Returns number of free sectors in given metadata area.
142*86d7f5d3SJohn Marino 	 */
143*86d7f5d3SJohn Marino 	uint64_t (*mda_free_sectors) (struct metadata_area *mda);
144*86d7f5d3SJohn Marino 
145*86d7f5d3SJohn Marino 	/*
146*86d7f5d3SJohn Marino 	 * Returns number of total sectors in given metadata area.
147*86d7f5d3SJohn Marino 	 */
148*86d7f5d3SJohn Marino 	uint64_t (*mda_total_sectors) (struct metadata_area *mda);
149*86d7f5d3SJohn Marino 
150*86d7f5d3SJohn Marino 	/*
151*86d7f5d3SJohn Marino 	 * Check if metadata area belongs to vg
152*86d7f5d3SJohn Marino 	 */
153*86d7f5d3SJohn Marino 	int (*mda_in_vg) (struct format_instance * fi,
154*86d7f5d3SJohn Marino 			    struct volume_group * vg, struct metadata_area *mda);
155*86d7f5d3SJohn Marino 	/*
156*86d7f5d3SJohn Marino 	 * Analyze a metadata area on a PV.
157*86d7f5d3SJohn Marino 	 */
158*86d7f5d3SJohn Marino 	int (*pv_analyze_mda) (const struct format_type * fmt,
159*86d7f5d3SJohn Marino 			       struct metadata_area *mda);
160*86d7f5d3SJohn Marino 
161*86d7f5d3SJohn Marino };
162*86d7f5d3SJohn Marino 
163*86d7f5d3SJohn Marino struct metadata_area {
164*86d7f5d3SJohn Marino 	struct dm_list list;
165*86d7f5d3SJohn Marino 	struct metadata_area_ops *ops;
166*86d7f5d3SJohn Marino 	void *metadata_locn;
167*86d7f5d3SJohn Marino };
168*86d7f5d3SJohn Marino 
169*86d7f5d3SJohn Marino #define seg_pvseg(seg, s)	(seg)->areas[(s)].u.pv.pvseg
170*86d7f5d3SJohn Marino #define seg_dev(seg, s)		(seg)->areas[(s)].u.pv.pvseg->pv->dev
171*86d7f5d3SJohn Marino #define seg_pe(seg, s)		(seg)->areas[(s)].u.pv.pvseg->pe
172*86d7f5d3SJohn Marino #define seg_le(seg, s)		(seg)->areas[(s)].u.lv.le
173*86d7f5d3SJohn Marino 
174*86d7f5d3SJohn Marino struct name_list {
175*86d7f5d3SJohn Marino 	struct dm_list list;
176*86d7f5d3SJohn Marino 	char *name;
177*86d7f5d3SJohn Marino };
178*86d7f5d3SJohn Marino 
179*86d7f5d3SJohn Marino struct mda_list {
180*86d7f5d3SJohn Marino 	struct dm_list list;
181*86d7f5d3SJohn Marino 	struct device_area mda;
182*86d7f5d3SJohn Marino };
183*86d7f5d3SJohn Marino 
184*86d7f5d3SJohn Marino struct peg_list {
185*86d7f5d3SJohn Marino 	struct dm_list list;
186*86d7f5d3SJohn Marino 	struct pv_segment *peg;
187*86d7f5d3SJohn Marino };
188*86d7f5d3SJohn Marino 
189*86d7f5d3SJohn Marino struct seg_list {
190*86d7f5d3SJohn Marino 	struct dm_list list;
191*86d7f5d3SJohn Marino 	unsigned count;
192*86d7f5d3SJohn Marino 	struct lv_segment *seg;
193*86d7f5d3SJohn Marino };
194*86d7f5d3SJohn Marino 
195*86d7f5d3SJohn Marino /*
196*86d7f5d3SJohn Marino  * Ownership of objects passes to caller.
197*86d7f5d3SJohn Marino  */
198*86d7f5d3SJohn Marino struct format_handler {
199*86d7f5d3SJohn Marino 	/*
200*86d7f5d3SJohn Marino 	 * Scan any metadata areas that aren't referenced in PV labels
201*86d7f5d3SJohn Marino 	 */
202*86d7f5d3SJohn Marino 	int (*scan) (const struct format_type * fmt);
203*86d7f5d3SJohn Marino 
204*86d7f5d3SJohn Marino 	/*
205*86d7f5d3SJohn Marino 	 * Return PV with given path.
206*86d7f5d3SJohn Marino 	 */
207*86d7f5d3SJohn Marino 	int (*pv_read) (const struct format_type * fmt, const char *pv_name,
208*86d7f5d3SJohn Marino 			struct physical_volume * pv, struct dm_list *mdas,
209*86d7f5d3SJohn Marino 			int scan_label_only);
210*86d7f5d3SJohn Marino 
211*86d7f5d3SJohn Marino 	/*
212*86d7f5d3SJohn Marino 	 * Tweak an already filled out a pv ready for importing into a
213*86d7f5d3SJohn Marino 	 * vg.  eg. pe_count is format specific.
214*86d7f5d3SJohn Marino 	 */
215*86d7f5d3SJohn Marino 	int (*pv_setup) (const struct format_type * fmt,
216*86d7f5d3SJohn Marino 			 uint64_t pe_start, uint32_t extent_count,
217*86d7f5d3SJohn Marino 			 uint32_t extent_size, unsigned long data_alignment,
218*86d7f5d3SJohn Marino 			 unsigned long data_alignment_offset,
219*86d7f5d3SJohn Marino 			 int pvmetadatacopies,
220*86d7f5d3SJohn Marino 			 uint64_t pvmetadatasize, struct dm_list * mdas,
221*86d7f5d3SJohn Marino 			 struct physical_volume * pv, struct volume_group * vg);
222*86d7f5d3SJohn Marino 
223*86d7f5d3SJohn Marino 	/*
224*86d7f5d3SJohn Marino 	 * Write a PV structure to disk. Fails if the PV is in a VG ie
225*86d7f5d3SJohn Marino 	 * pv->vg_name must be a valid orphan VG name
226*86d7f5d3SJohn Marino 	 */
227*86d7f5d3SJohn Marino 	int (*pv_write) (const struct format_type * fmt,
228*86d7f5d3SJohn Marino 			 struct physical_volume * pv, struct dm_list * mdas,
229*86d7f5d3SJohn Marino 			 int64_t label_sector);
230*86d7f5d3SJohn Marino 
231*86d7f5d3SJohn Marino 	/*
232*86d7f5d3SJohn Marino 	 * Tweak an already filled out a lv eg, check there
233*86d7f5d3SJohn Marino 	 * aren't too many extents.
234*86d7f5d3SJohn Marino 	 */
235*86d7f5d3SJohn Marino 	int (*lv_setup) (struct format_instance * fi,
236*86d7f5d3SJohn Marino 			 struct logical_volume * lv);
237*86d7f5d3SJohn Marino 
238*86d7f5d3SJohn Marino 	/*
239*86d7f5d3SJohn Marino 	 * Tweak an already filled out vg.  eg, max_pv is format
240*86d7f5d3SJohn Marino 	 * specific.
241*86d7f5d3SJohn Marino 	 */
242*86d7f5d3SJohn Marino 	int (*vg_setup) (struct format_instance * fi, struct volume_group * vg);
243*86d7f5d3SJohn Marino 
244*86d7f5d3SJohn Marino 	/*
245*86d7f5d3SJohn Marino 	 * Check whether particular segment type is supported.
246*86d7f5d3SJohn Marino 	 */
247*86d7f5d3SJohn Marino 	int (*segtype_supported) (struct format_instance *fid,
248*86d7f5d3SJohn Marino 				  const struct segment_type *segtype);
249*86d7f5d3SJohn Marino 
250*86d7f5d3SJohn Marino 	/*
251*86d7f5d3SJohn Marino 	 * Create format instance with a particular metadata area
252*86d7f5d3SJohn Marino 	 */
253*86d7f5d3SJohn Marino 	struct format_instance *(*create_instance) (const struct format_type *
254*86d7f5d3SJohn Marino 						    fmt, const char *vgname,
255*86d7f5d3SJohn Marino 						    const char *vgid,
256*86d7f5d3SJohn Marino 						    void *context);
257*86d7f5d3SJohn Marino 
258*86d7f5d3SJohn Marino 	/*
259*86d7f5d3SJohn Marino 	 * Destructor for format instance
260*86d7f5d3SJohn Marino 	 */
261*86d7f5d3SJohn Marino 	void (*destroy_instance) (struct format_instance * fid);
262*86d7f5d3SJohn Marino 
263*86d7f5d3SJohn Marino 	/*
264*86d7f5d3SJohn Marino 	 * Destructor for format type
265*86d7f5d3SJohn Marino 	 */
266*86d7f5d3SJohn Marino 	void (*destroy) (const struct format_type * fmt);
267*86d7f5d3SJohn Marino };
268*86d7f5d3SJohn Marino 
269*86d7f5d3SJohn Marino /*
270*86d7f5d3SJohn Marino  * Utility functions
271*86d7f5d3SJohn Marino  */
272*86d7f5d3SJohn Marino unsigned long set_pe_align(struct physical_volume *pv, unsigned long data_alignment);
273*86d7f5d3SJohn Marino unsigned long set_pe_align_offset(struct physical_volume *pv,
274*86d7f5d3SJohn Marino 				  unsigned long data_alignment_offset);
275*86d7f5d3SJohn Marino int vg_validate(struct volume_group *vg);
276*86d7f5d3SJohn Marino 
277*86d7f5d3SJohn Marino int pv_write_orphan(struct cmd_context *cmd, struct physical_volume *pv);
278*86d7f5d3SJohn Marino 
279*86d7f5d3SJohn Marino /* Manipulate PV structures */
280*86d7f5d3SJohn Marino int pv_add(struct volume_group *vg, struct physical_volume *pv);
281*86d7f5d3SJohn Marino int pv_remove(struct volume_group *vg, struct physical_volume *pv);
282*86d7f5d3SJohn Marino struct physical_volume *pv_find(struct volume_group *vg, const char *pv_name);
283*86d7f5d3SJohn Marino 
284*86d7f5d3SJohn Marino /* Find a PV within a given VG */
285*86d7f5d3SJohn Marino int get_pv_from_vg_by_id(const struct format_type *fmt, const char *vg_name,
286*86d7f5d3SJohn Marino 			 const char *vgid, const char *pvid,
287*86d7f5d3SJohn Marino 			 struct physical_volume *pv);
288*86d7f5d3SJohn Marino 
289*86d7f5d3SJohn Marino struct lv_list *find_lv_in_vg_by_lvid(struct volume_group *vg,
290*86d7f5d3SJohn Marino 				      const union lvid *lvid);
291*86d7f5d3SJohn Marino 
292*86d7f5d3SJohn Marino struct lv_list *find_lv_in_lv_list(const struct dm_list *ll,
293*86d7f5d3SJohn Marino 				   const struct logical_volume *lv);
294*86d7f5d3SJohn Marino 
295*86d7f5d3SJohn Marino /* Return the VG that contains a given LV (based on path given in lv_name) */
296*86d7f5d3SJohn Marino /* or environment var */
297*86d7f5d3SJohn Marino struct volume_group *find_vg_with_lv(const char *lv_name);
298*86d7f5d3SJohn Marino 
299*86d7f5d3SJohn Marino /* Find LV with given lvid (used during activation) */
300*86d7f5d3SJohn Marino struct logical_volume *lv_from_lvid(struct cmd_context *cmd,
301*86d7f5d3SJohn Marino 				    const char *lvid_s,
302*86d7f5d3SJohn Marino 				    unsigned precommitted);
303*86d7f5d3SJohn Marino 
304*86d7f5d3SJohn Marino /* FIXME Merge these functions with ones above */
305*86d7f5d3SJohn Marino struct physical_volume *find_pv(struct volume_group *vg, struct device *dev);
306*86d7f5d3SJohn Marino 
307*86d7f5d3SJohn Marino struct pv_list *find_pv_in_pv_list(const struct dm_list *pl,
308*86d7f5d3SJohn Marino 				   const struct physical_volume *pv);
309*86d7f5d3SJohn Marino 
310*86d7f5d3SJohn Marino /* Find LV segment containing given LE */
311*86d7f5d3SJohn Marino struct lv_segment *find_seg_by_le(const struct logical_volume *lv, uint32_t le);
312*86d7f5d3SJohn Marino 
313*86d7f5d3SJohn Marino /* Find PV segment containing given LE */
314*86d7f5d3SJohn Marino struct pv_segment *find_peg_by_pe(const struct physical_volume *pv, uint32_t pe);
315*86d7f5d3SJohn Marino 
316*86d7f5d3SJohn Marino /*
317*86d7f5d3SJohn Marino  * Remove a dev_dir if present.
318*86d7f5d3SJohn Marino  */
319*86d7f5d3SJohn Marino const char *strip_dir(const char *vg_name, const char *dir);
320*86d7f5d3SJohn Marino 
321*86d7f5d3SJohn Marino struct logical_volume *alloc_lv(struct dm_pool *mem);
322*86d7f5d3SJohn Marino 
323*86d7f5d3SJohn Marino /*
324*86d7f5d3SJohn Marino  * Checks that an lv has no gaps or overlapping segments.
325*86d7f5d3SJohn Marino  * Set complete_vg to perform additional VG level checks.
326*86d7f5d3SJohn Marino  */
327*86d7f5d3SJohn Marino int check_lv_segments(struct logical_volume *lv, int complete_vg);
328*86d7f5d3SJohn Marino 
329*86d7f5d3SJohn Marino /*
330*86d7f5d3SJohn Marino  * Sometimes (eg, after an lvextend), it is possible to merge two
331*86d7f5d3SJohn Marino  * adjacent segments into a single segment.  This function trys
332*86d7f5d3SJohn Marino  * to merge as many segments as possible.
333*86d7f5d3SJohn Marino  */
334*86d7f5d3SJohn Marino int lv_merge_segments(struct logical_volume *lv);
335*86d7f5d3SJohn Marino 
336*86d7f5d3SJohn Marino /*
337*86d7f5d3SJohn Marino  * Ensure there's a segment boundary at a given LE, splitting if necessary
338*86d7f5d3SJohn Marino  */
339*86d7f5d3SJohn Marino int lv_split_segment(struct logical_volume *lv, uint32_t le);
340*86d7f5d3SJohn Marino 
341*86d7f5d3SJohn Marino /*
342*86d7f5d3SJohn Marino  * Add/remove upward link from underlying LV to the segment using it
343*86d7f5d3SJohn Marino  * FIXME: ridiculously long name
344*86d7f5d3SJohn Marino  */
345*86d7f5d3SJohn Marino int add_seg_to_segs_using_this_lv(struct logical_volume *lv, struct lv_segment *seg);
346*86d7f5d3SJohn Marino int remove_seg_from_segs_using_this_lv(struct logical_volume *lv, struct lv_segment *seg);
347*86d7f5d3SJohn Marino struct lv_segment *get_only_segment_using_this_lv(struct logical_volume *lv);
348*86d7f5d3SJohn Marino 
349*86d7f5d3SJohn Marino /*
350*86d7f5d3SJohn Marino  * Count snapshot LVs.
351*86d7f5d3SJohn Marino  */
352*86d7f5d3SJohn Marino unsigned snapshot_count(const struct volume_group *vg);
353*86d7f5d3SJohn Marino 
354*86d7f5d3SJohn Marino /*
355*86d7f5d3SJohn Marino  * Calculate readahead from underlying PV devices
356*86d7f5d3SJohn Marino  */
357*86d7f5d3SJohn Marino void lv_calculate_readahead(const struct logical_volume *lv, uint32_t *read_ahead);
358*86d7f5d3SJohn Marino 
359*86d7f5d3SJohn Marino /*
360*86d7f5d3SJohn Marino  * For internal metadata caching.
361*86d7f5d3SJohn Marino  */
362*86d7f5d3SJohn Marino int export_vg_to_buffer(struct volume_group *vg, char **buf);
363*86d7f5d3SJohn Marino struct volume_group *import_vg_from_buffer(char *buf,
364*86d7f5d3SJohn Marino 					   struct format_instance *fid);
365*86d7f5d3SJohn Marino 
366*86d7f5d3SJohn Marino /*
367*86d7f5d3SJohn Marino  * Mirroring functions
368*86d7f5d3SJohn Marino  */
369*86d7f5d3SJohn Marino 
370*86d7f5d3SJohn Marino /*
371*86d7f5d3SJohn Marino  * Given mirror image or mirror log segment, find corresponding mirror segment
372*86d7f5d3SJohn Marino  */
373*86d7f5d3SJohn Marino int fixup_imported_mirrors(struct volume_group *vg);
374*86d7f5d3SJohn Marino 
375*86d7f5d3SJohn Marino /*
376*86d7f5d3SJohn Marino  * Begin skeleton for external LVM library
377*86d7f5d3SJohn Marino  */
378*86d7f5d3SJohn Marino struct id pv_id(const struct physical_volume *pv);
379*86d7f5d3SJohn Marino const struct format_type *pv_format_type(const struct physical_volume *pv);
380*86d7f5d3SJohn Marino struct id pv_vgid(const struct physical_volume *pv);
381*86d7f5d3SJohn Marino 
382*86d7f5d3SJohn Marino struct physical_volume *pv_by_path(struct cmd_context *cmd, const char *pv_name);
383*86d7f5d3SJohn Marino int add_pv_to_vg(struct volume_group *vg, const char *pv_name,
384*86d7f5d3SJohn Marino 		 struct physical_volume *pv);
385*86d7f5d3SJohn Marino 
386*86d7f5d3SJohn Marino #endif
387