2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #ifndef DISK_REP_FORMAT1_H
17 #define DISK_REP_FORMAT1_H
19 #include "lvm-types.h"
21 #include "toolcontext.h"
27 #define LVM_BLK_MAJOR 58
29 #define MAX_PV_SIZE ((uint32_t) -1) /* 2TB in sectors - 1 */
30 #define MIN_PE_SIZE (8192L >> SECTOR_SHIFT) /* 8 KB in sectors */
31 #define MAX_PE_SIZE (16L * 1024L * (1024L >> SECTOR_SHIFT) * 1024L)
32 #define PE_SIZE_PV_SIZE_REL 5 /* PV size must be at least 5 times PE size */
33 #define MAX_LE_TOTAL 65534 /* 2^16 - 2 */
34 #define MAX_PE_TOTAL ((uint32_t) -2)
36 #define UNMAPPED_EXTENT 0
39 #define VG_ACTIVE 0x01 /* vg_status */
40 #define VG_EXPORTED 0x02 /* " */
41 #define VG_EXTENDABLE 0x04 /* " */
43 #define VG_READ 0x01 /* vg_access */
44 #define VG_WRITE 0x02 /* " */
45 #define VG_CLUSTERED 0x04 /* " */
46 #define VG_SHARED 0x08 /* " */
49 #define LV_ACTIVE 0x01 /* lv_status */
50 #define LV_SPINDOWN 0x02 /* " */
51 #define LV_PERSISTENT_MINOR 0x04 /* " */
53 #define LV_READ 0x01 /* lv_access */
54 #define LV_WRITE 0x02 /* " */
55 #define LV_SNAPSHOT 0x04 /* " */
56 #define LV_SNAPSHOT_ORG 0x08 /* " */
58 #define LV_BADBLOCK_ON 0x01 /* lv_badblock */
60 #define LV_STRICT 0x01 /* lv_allocation */
61 #define LV_CONTIGUOUS 0x02 /* " */
64 #define PV_ACTIVE 0x01 /* pv_status */
65 #define PV_ALLOCATABLE 0x02 /* pv_allocatable */
67 #define EXPORTED_TAG "PV_EXP" /* Identifier for exported PV */
68 #define IMPORTED_TAG "PV_IMP" /* Identifier for imported PV */
73 } __attribute__ ((packed
));
77 uint16_t version
; /* lvm version */
78 struct data_area pv_on_disk
;
79 struct data_area vg_on_disk
;
80 struct data_area pv_uuidlist_on_disk
;
81 struct data_area lv_on_disk
;
82 struct data_area pe_on_disk
;
83 int8_t pv_uuid
[NAME_LEN
];
84 int8_t vg_name
[NAME_LEN
];
85 int8_t system_id
[NAME_LEN
]; /* for vgexport/vgimport */
89 uint32_t pv_allocatable
;
94 uint32_t pe_allocated
;
96 /* only present on version == 2 pv's */
98 } __attribute__ ((packed
));
101 int8_t lv_name
[NAME_LEN
];
102 int8_t vg_name
[NAME_LEN
];
108 uint32_t lv_mirror_copies
; /* for future use */
109 uint32_t lv_recovery
; /* " */
110 uint32_t lv_schedule
; /* " */
112 uint32_t lv_snapshot_minor
; /* minor number of original */
113 uint16_t lv_chunk_size
; /* chunk size of snapshot */
115 uint32_t lv_allocated_le
;
117 uint32_t lv_stripesize
;
118 uint32_t lv_badblock
; /* for future use */
119 uint32_t lv_allocation
;
120 uint32_t lv_io_timeout
; /* for future use */
121 uint32_t lv_read_ahead
;
122 } __attribute__ ((packed
));
125 int8_t vg_uuid
[ID_LEN
]; /* volume group UUID */
126 int8_t vg_name_dummy
[NAME_LEN
- ID_LEN
]; /* rest of v1 VG name */
127 uint32_t vg_number
; /* volume group number */
128 uint32_t vg_access
; /* read/write */
129 uint32_t vg_status
; /* active or not */
130 uint32_t lv_max
; /* maximum logical volumes */
131 uint32_t lv_cur
; /* current logical volumes */
132 uint32_t lv_open
; /* open logical volumes */
133 uint32_t pv_max
; /* maximum physical volumes */
134 uint32_t pv_cur
; /* current physical volumes FU */
135 uint32_t pv_act
; /* active physical volumes */
137 uint32_t vgda
; /* volume group descriptor arrays FU */
138 uint32_t pe_size
; /* physical extent size in sectors */
139 uint32_t pe_total
; /* total of physical extents */
140 uint32_t pe_allocated
; /* allocated physical extents */
141 uint32_t pvg_total
; /* physical volume groups FU */
142 } __attribute__ ((packed
));
147 } __attribute__ ((packed
));
151 char uuid
[NAME_LEN
] __attribute__((aligned(8)));
164 struct pv_disk pvd
__attribute__((aligned(8)));
165 struct vg_disk vgd
__attribute__((aligned(8)));
166 struct dm_list uuids
__attribute__((aligned(8)));
167 struct dm_list lvds
__attribute__((aligned(8)));
168 struct pe_disk
*extents
__attribute__((aligned(8)));
174 #define METADATA_ALIGN 4096UL
175 #define LVM1_PE_ALIGN (65536UL >> SECTOR_SHIFT) /* PE alignment */
177 #define METADATA_BASE 0UL
178 #define PV_SIZE 1024UL
179 #define VG_SIZE 4096UL
182 * Functions to calculate layout info.
184 int calculate_layout(struct disk_list
*dl
);
185 int calculate_extent_count(struct physical_volume
*pv
, uint32_t extent_size
,
186 uint32_t max_extent_count
, uint64_t pe_start
);
189 * Low level io routines which read/write
193 struct disk_list
*read_disk(const struct format_type
*fmt
, struct device
*dev
,
194 struct dm_pool
*mem
, const char *vg_name
);
196 int read_pvs_in_vg(const struct format_type
*fmt
, const char *vg_name
,
197 struct dev_filter
*filter
,
198 struct dm_pool
*mem
, struct dm_list
*results
);
200 int write_disks(const struct format_type
*fmt
, struct dm_list
*pvds
);
203 * Functions to translate to between disk and in
206 int import_pv(const struct format_type
*fmt
, struct dm_pool
*mem
,
207 struct device
*dev
, struct volume_group
*vg
,
208 struct physical_volume
*pv
, struct pv_disk
*pvd
,
209 struct vg_disk
*vgd
);
210 int export_pv(struct cmd_context
*cmd
, struct dm_pool
*mem
,
211 struct volume_group
*vg
,
212 struct pv_disk
*pvd
, struct physical_volume
*pv
);
214 int import_vg(struct dm_pool
*mem
,
215 struct volume_group
*vg
, struct disk_list
*dl
);
216 int export_vg(struct vg_disk
*vgd
, struct volume_group
*vg
);
218 int import_lv(struct cmd_context
*cmd
, struct dm_pool
*mem
,
219 struct logical_volume
*lv
, struct lv_disk
*lvd
);
221 int import_extents(struct cmd_context
*cmd
, struct volume_group
*vg
,
222 struct dm_list
*pvds
);
223 int export_extents(struct disk_list
*dl
, uint32_t lv_num
,
224 struct logical_volume
*lv
, struct physical_volume
*pv
);
226 int import_pvs(const struct format_type
*fmt
, struct dm_pool
*mem
,
227 struct volume_group
*vg
, struct dm_list
*pvds
);
229 int import_lvs(struct dm_pool
*mem
, struct volume_group
*vg
, struct dm_list
*pvds
);
230 int export_lvs(struct disk_list
*dl
, struct volume_group
*vg
,
231 struct physical_volume
*pv
, const char *dev_dir
);
233 int import_snapshots(struct dm_pool
*mem
, struct volume_group
*vg
,
234 struct dm_list
*pvds
);
236 int export_uuids(struct disk_list
*dl
, struct volume_group
*vg
);
238 void export_numbers(struct dm_list
*pvds
, struct volume_group
*vg
);
240 void export_pv_act(struct dm_list
*pvds
);
241 int munge_pvd(struct device
*dev
, struct pv_disk
*pvd
);
242 int read_vgd(struct device
*dev
, struct vg_disk
*vgd
, struct pv_disk
*pvd
);
245 int get_free_vg_number(struct format_instance
*fid
, struct dev_filter
*filter
,
246 const char *candidate_vg
, int *result
);
247 int export_vg_number(struct format_instance
*fid
, struct dm_list
*pvds
,
248 const char *vg_name
, struct dev_filter
*filter
);