Home | History | Annotate | Line # | Download | only in format1
      1 /*	$NetBSD: disk-rep.h,v 1.1.1.2 2009/12/02 00:26:48 haad Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
      5  * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
      6  *
      7  * This file is part of LVM2.
      8  *
      9  * This copyrighted material is made available to anyone wishing to use,
     10  * modify, copy, or redistribute it subject to the terms and conditions
     11  * of the GNU Lesser General Public License v.2.1.
     12  *
     13  * You should have received a copy of the GNU Lesser General Public License
     14  * along with this program; if not, write to the Free Software Foundation,
     15  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     16  */
     17 
     18 #ifndef DISK_REP_FORMAT1_H
     19 #define DISK_REP_FORMAT1_H
     20 
     21 #include "lvm-types.h"
     22 #include "metadata.h"
     23 #include "toolcontext.h"
     24 
     25 #define MAX_PV 256
     26 #define MAX_LV 256
     27 #define MAX_VG 99
     28 
     29 #define LVM_BLK_MAJOR 58
     30 
     31 #define MAX_PV_SIZE	((uint32_t) -1)	/* 2TB in sectors - 1 */
     32 #define MIN_PE_SIZE	(8192L >> SECTOR_SHIFT)	/* 8 KB in sectors */
     33 #define MAX_PE_SIZE	(16L * 1024L * (1024L >> SECTOR_SHIFT) * 1024L)
     34 #define PE_SIZE_PV_SIZE_REL 5	/* PV size must be at least 5 times PE size */
     35 #define	MAX_LE_TOTAL	65534	/* 2^16 - 2 */
     36 #define	MAX_PE_TOTAL	((uint32_t) -2)
     37 
     38 #define UNMAPPED_EXTENT 0
     39 
     40 /* volume group */
     41 #define	VG_ACTIVE            0x01	/* vg_status */
     42 #define	VG_EXPORTED          0x02	/*     "     */
     43 #define	VG_EXTENDABLE        0x04	/*     "     */
     44 
     45 #define	VG_READ              0x01	/* vg_access */
     46 #define	VG_WRITE             0x02	/*     "     */
     47 #define	VG_CLUSTERED         0x04	/*     "     */
     48 #define	VG_SHARED            0x08	/*     "     */
     49 
     50 /* logical volume */
     51 #define	LV_ACTIVE            0x01	/* lv_status */
     52 #define	LV_SPINDOWN          0x02	/*     "     */
     53 #define LV_PERSISTENT_MINOR  0x04	/*     "     */
     54 
     55 #define	LV_READ              0x01	/* lv_access */
     56 #define	LV_WRITE             0x02	/*     "     */
     57 #define	LV_SNAPSHOT          0x04	/*     "     */
     58 #define	LV_SNAPSHOT_ORG      0x08	/*     "     */
     59 
     60 #define	LV_BADBLOCK_ON       0x01	/* lv_badblock */
     61 
     62 #define	LV_STRICT            0x01	/* lv_allocation */
     63 #define	LV_CONTIGUOUS        0x02	/*       "       */
     64 
     65 /* physical volume */
     66 #define	PV_ACTIVE            0x01	/* pv_status */
     67 #define	PV_ALLOCATABLE       0x02	/* pv_allocatable */
     68 
     69 #define EXPORTED_TAG "PV_EXP"	/* Identifier for exported PV */
     70 #define IMPORTED_TAG "PV_IMP"	/* Identifier for imported PV */
     71 
     72 struct data_area {
     73 	uint32_t base;
     74 	uint32_t size;
     75 } __attribute__ ((packed));
     76 
     77 struct pv_disk {
     78 	int8_t id[2];
     79 	uint16_t version;	/* lvm version */
     80 	struct data_area pv_on_disk;
     81 	struct data_area vg_on_disk;
     82 	struct data_area pv_uuidlist_on_disk;
     83 	struct data_area lv_on_disk;
     84 	struct data_area pe_on_disk;
     85 	int8_t pv_uuid[NAME_LEN];
     86 	int8_t vg_name[NAME_LEN];
     87 	int8_t system_id[NAME_LEN];	/* for vgexport/vgimport */
     88 	uint32_t pv_major;
     89 	uint32_t pv_number;
     90 	uint32_t pv_status;
     91 	uint32_t pv_allocatable;
     92 	uint32_t pv_size;
     93 	uint32_t lv_cur;
     94 	uint32_t pe_size;
     95 	uint32_t pe_total;
     96 	uint32_t pe_allocated;
     97 
     98 	/* only present on version == 2 pv's */
     99 	uint32_t pe_start;
    100 } __attribute__ ((packed));
    101 
    102 struct lv_disk {
    103 	int8_t lv_name[NAME_LEN];
    104 	int8_t vg_name[NAME_LEN];
    105 	uint32_t lv_access;
    106 	uint32_t lv_status;
    107 	uint32_t lv_open;
    108 	uint32_t lv_dev;
    109 	uint32_t lv_number;
    110 	uint32_t lv_mirror_copies;	/* for future use */
    111 	uint32_t lv_recovery;	/*       "        */
    112 	uint32_t lv_schedule;	/*       "        */
    113 	uint32_t lv_size;
    114 	uint32_t lv_snapshot_minor;	/* minor number of original */
    115 	uint16_t lv_chunk_size;	/* chunk size of snapshot */
    116 	uint16_t dummy;
    117 	uint32_t lv_allocated_le;
    118 	uint32_t lv_stripes;
    119 	uint32_t lv_stripesize;
    120 	uint32_t lv_badblock;	/* for future use */
    121 	uint32_t lv_allocation;
    122 	uint32_t lv_io_timeout;	/* for future use */
    123 	uint32_t lv_read_ahead;
    124 } __attribute__ ((packed));
    125 
    126 struct vg_disk {
    127 	int8_t vg_uuid[ID_LEN];	/* volume group UUID */
    128 	int8_t vg_name_dummy[NAME_LEN - ID_LEN];	/* rest of v1 VG name */
    129 	uint32_t vg_number;	/* volume group number */
    130 	uint32_t vg_access;	/* read/write */
    131 	uint32_t vg_status;	/* active or not */
    132 	uint32_t lv_max;	/* maximum logical volumes */
    133 	uint32_t lv_cur;	/* current logical volumes */
    134 	uint32_t lv_open;	/* open logical volumes */
    135 	uint32_t pv_max;	/* maximum physical volumes */
    136 	uint32_t pv_cur;	/* current physical volumes FU */
    137 	uint32_t pv_act;	/* active physical volumes */
    138 	uint32_t dummy;
    139 	uint32_t vgda;		/* volume group descriptor arrays FU */
    140 	uint32_t pe_size;	/* physical extent size in sectors */
    141 	uint32_t pe_total;	/* total of physical extents */
    142 	uint32_t pe_allocated;	/* allocated physical extents */
    143 	uint32_t pvg_total;	/* physical volume groups FU */
    144 } __attribute__ ((packed));
    145 
    146 struct pe_disk {
    147 	uint16_t lv_num;
    148 	uint16_t le_num;
    149 } __attribute__ ((packed));
    150 
    151 struct uuid_list {
    152 	struct dm_list list;
    153 	char uuid[NAME_LEN] __attribute((aligned(8)));
    154 };
    155 
    156 struct lvd_list {
    157 	struct dm_list list;
    158 	struct lv_disk lvd;
    159 };
    160 
    161 struct disk_list {
    162 	struct dm_list list;
    163 	struct dm_pool *mem;
    164 	struct device *dev;
    165 
    166 	struct pv_disk pvd __attribute((aligned(8)));
    167 	struct vg_disk vgd __attribute((aligned(8)));
    168 	struct dm_list uuids __attribute((aligned(8)));
    169 	struct dm_list lvds __attribute((aligned(8)));
    170 	struct pe_disk *extents __attribute((aligned(8)));
    171 };
    172 
    173 /*
    174  * Layout constants.
    175  */
    176 #define METADATA_ALIGN 4096UL
    177 #define LVM1_PE_ALIGN (65536UL >> SECTOR_SHIFT)      /* PE alignment */
    178 
    179 #define	METADATA_BASE 0UL
    180 #define	PV_SIZE 1024UL
    181 #define	VG_SIZE 4096UL
    182 
    183 /*
    184  * Functions to calculate layout info.
    185  */
    186 int calculate_layout(struct disk_list *dl);
    187 int calculate_extent_count(struct physical_volume *pv, uint32_t extent_size,
    188 			   uint32_t max_extent_count, uint64_t pe_start);
    189 
    190 /*
    191  * Low level io routines which read/write
    192  * disk_lists.
    193  */
    194 
    195 struct disk_list *read_disk(const struct format_type *fmt, struct device *dev,
    196 			    struct dm_pool *mem, const char *vg_name);
    197 
    198 int read_pvs_in_vg(const struct format_type *fmt, const char *vg_name,
    199 		   struct dev_filter *filter,
    200 		   struct dm_pool *mem, struct dm_list *results);
    201 
    202 int write_disks(const struct format_type *fmt, struct dm_list *pvds);
    203 
    204 /*
    205  * Functions to translate to between disk and in
    206  * core structures.
    207  */
    208 int import_pv(const struct format_type *fmt, struct dm_pool *mem,
    209 	      struct device *dev, struct volume_group *vg,
    210 	      struct physical_volume *pv, struct pv_disk *pvd,
    211 	      struct vg_disk *vgd);
    212 int export_pv(struct cmd_context *cmd, struct dm_pool *mem,
    213 	      struct volume_group *vg,
    214 	      struct pv_disk *pvd, struct physical_volume *pv);
    215 
    216 int import_vg(struct dm_pool *mem,
    217 	      struct volume_group *vg, struct disk_list *dl);
    218 int export_vg(struct vg_disk *vgd, struct volume_group *vg);
    219 
    220 int import_lv(struct cmd_context *cmd, struct dm_pool *mem,
    221 	      struct logical_volume *lv, struct lv_disk *lvd);
    222 
    223 int import_extents(struct cmd_context *cmd, struct volume_group *vg,
    224 		   struct dm_list *pvds);
    225 int export_extents(struct disk_list *dl, uint32_t lv_num,
    226 		   struct logical_volume *lv, struct physical_volume *pv);
    227 
    228 int import_pvs(const struct format_type *fmt, struct dm_pool *mem,
    229 	       struct volume_group *vg,
    230 	       struct dm_list *pvds, struct dm_list *results, uint32_t *count);
    231 
    232 int import_lvs(struct dm_pool *mem, struct volume_group *vg, struct dm_list *pvds);
    233 int export_lvs(struct disk_list *dl, struct volume_group *vg,
    234 	       struct physical_volume *pv, const char *dev_dir);
    235 
    236 int import_snapshots(struct dm_pool *mem, struct volume_group *vg,
    237 		     struct dm_list *pvds);
    238 
    239 int export_uuids(struct disk_list *dl, struct volume_group *vg);
    240 
    241 void export_numbers(struct dm_list *pvds, struct volume_group *vg);
    242 
    243 void export_pv_act(struct dm_list *pvds);
    244 int munge_pvd(struct device *dev, struct pv_disk *pvd);
    245 int read_vgd(struct device *dev, struct vg_disk *vgd, struct pv_disk *pvd);
    246 
    247 /* blech */
    248 int get_free_vg_number(struct format_instance *fid, struct dev_filter *filter,
    249 		       const char *candidate_vg, int *result);
    250 int export_vg_number(struct format_instance *fid, struct dm_list *pvds,
    251 		     const char *vg_name, struct dev_filter *filter);
    252 
    253 #endif
    254