4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
7 * This file is part of LVM2.
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.
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
18 #ifndef DISK_REP_FORMAT1_H
19 #define DISK_REP_FORMAT1_H
21 #include "lvm-types.h"
23 #include "toolcontext.h"
29 #define LVM_BLK_MAJOR 58
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)
38 #define UNMAPPED_EXTENT 0
41 #define VG_ACTIVE 0x01 /* vg_status */
42 #define VG_EXPORTED 0x02 /* " */
43 #define VG_EXTENDABLE 0x04 /* " */
45 #define VG_READ 0x01 /* vg_access */
46 #define VG_WRITE 0x02 /* " */
47 #define VG_CLUSTERED 0x04 /* " */
48 #define VG_SHARED 0x08 /* " */
51 #define LV_ACTIVE 0x01 /* lv_status */
52 #define LV_SPINDOWN 0x02 /* " */
53 #define LV_PERSISTENT_MINOR 0x04 /* " */
55 #define LV_READ 0x01 /* lv_access */
56 #define LV_WRITE 0x02 /* " */
57 #define LV_SNAPSHOT 0x04 /* " */
58 #define LV_SNAPSHOT_ORG 0x08 /* " */
60 #define LV_BADBLOCK_ON 0x01 /* lv_badblock */
62 #define LV_STRICT 0x01 /* lv_allocation */
63 #define LV_CONTIGUOUS 0x02 /* " */
66 #define PV_ACTIVE 0x01 /* pv_status */
67 #define PV_ALLOCATABLE 0x02 /* pv_allocatable */
69 #define EXPORTED_TAG "PV_EXP" /* Identifier for exported PV */
70 #define IMPORTED_TAG "PV_IMP" /* Identifier for imported PV */
75 } __attribute__ ((packed
));
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 */
91 uint32_t pv_allocatable
;
96 uint32_t pe_allocated
;
98 /* only present on version == 2 pv's */
100 } __attribute__ ((packed
));
103 int8_t lv_name
[NAME_LEN
];
104 int8_t vg_name
[NAME_LEN
];
110 uint32_t lv_mirror_copies
; /* for future use */
111 uint32_t lv_recovery
; /* " */
112 uint32_t lv_schedule
; /* " */
114 uint32_t lv_snapshot_minor
; /* minor number of original */
115 uint16_t lv_chunk_size
; /* chunk size of snapshot */
117 uint32_t lv_allocated_le
;
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
));
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 */
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
));
149 } __attribute__ ((packed
));
153 char uuid
[NAME_LEN
] __attribute((aligned(8)));
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)));
176 #define METADATA_ALIGN 4096UL
177 #define LVM1_PE_ALIGN (65536UL >> SECTOR_SHIFT) /* PE alignment */
179 #define METADATA_BASE 0UL
180 #define PV_SIZE 1024UL
181 #define VG_SIZE 4096UL
184 * Functions to calculate layout info.
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
);
191 * Low level io routines which read/write
195 struct disk_list
*read_disk(const struct format_type
*fmt
, struct device
*dev
,
196 struct dm_pool
*mem
, const char *vg_name
);
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
);
202 int write_disks(const struct format_type
*fmt
, struct dm_list
*pvds
);
205 * Functions to translate to between disk and in
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
);
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
);
220 int import_lv(struct cmd_context
*cmd
, struct dm_pool
*mem
,
221 struct logical_volume
*lv
, struct lv_disk
*lvd
);
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
);
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
);
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
);
236 int import_snapshots(struct dm_pool
*mem
, struct volume_group
*vg
,
237 struct dm_list
*pvds
);
239 int export_uuids(struct disk_list
*dl
, struct volume_group
*vg
);
241 void export_numbers(struct dm_list
*pvds
, struct volume_group
*vg
);
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
);
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
);