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