Tizen 2.1 base
[external/device-mapper.git] / lib / format1 / disk-rep.h
1 /*
2  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.  
3  * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4  *
5  * This file is part of LVM2.
6  *
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.
10  *
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
14  */
15
16 #ifndef DISK_REP_FORMAT1_H
17 #define DISK_REP_FORMAT1_H
18
19 #include "lvm-types.h"
20 #include "metadata.h"
21 #include "toolcontext.h"
22
23 #define MAX_PV 256
24 #define MAX_LV 256
25 #define MAX_VG 99
26
27 #define LVM_BLK_MAJOR 58
28
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)
35
36 #define UNMAPPED_EXTENT 0
37
38 /* volume group */
39 #define VG_ACTIVE            0x01       /* vg_status */
40 #define VG_EXPORTED          0x02       /*     "     */
41 #define VG_EXTENDABLE        0x04       /*     "     */
42
43 #define VG_READ              0x01       /* vg_access */
44 #define VG_WRITE             0x02       /*     "     */
45 #define VG_CLUSTERED         0x04       /*     "     */
46 #define VG_SHARED            0x08       /*     "     */
47
48 /* logical volume */
49 #define LV_ACTIVE            0x01       /* lv_status */
50 #define LV_SPINDOWN          0x02       /*     "     */
51 #define LV_PERSISTENT_MINOR  0x04       /*     "     */
52
53 #define LV_READ              0x01       /* lv_access */
54 #define LV_WRITE             0x02       /*     "     */
55 #define LV_SNAPSHOT          0x04       /*     "     */
56 #define LV_SNAPSHOT_ORG      0x08       /*     "     */
57
58 #define LV_BADBLOCK_ON       0x01       /* lv_badblock */
59
60 #define LV_STRICT            0x01       /* lv_allocation */
61 #define LV_CONTIGUOUS        0x02       /*       "       */
62
63 /* physical volume */
64 #define PV_ACTIVE            0x01       /* pv_status */
65 #define PV_ALLOCATABLE       0x02       /* pv_allocatable */
66
67 #define EXPORTED_TAG "PV_EXP"   /* Identifier for exported PV */
68 #define IMPORTED_TAG "PV_IMP"   /* Identifier for imported PV */
69
70 struct data_area {
71         uint32_t base;
72         uint32_t size;
73 } __attribute__ ((packed));
74
75 struct pv_disk {
76         int8_t id[2];
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 */
86         uint32_t pv_major;
87         uint32_t pv_number;
88         uint32_t pv_status;
89         uint32_t pv_allocatable;
90         uint32_t pv_size;
91         uint32_t lv_cur;
92         uint32_t pe_size;
93         uint32_t pe_total;
94         uint32_t pe_allocated;
95
96         /* only present on version == 2 pv's */
97         uint32_t pe_start;
98 } __attribute__ ((packed));
99
100 struct lv_disk {
101         int8_t lv_name[NAME_LEN];
102         int8_t vg_name[NAME_LEN];
103         uint32_t lv_access;
104         uint32_t lv_status;
105         uint32_t lv_open;
106         uint32_t lv_dev;
107         uint32_t lv_number;
108         uint32_t lv_mirror_copies;      /* for future use */
109         uint32_t lv_recovery;   /*       "        */
110         uint32_t lv_schedule;   /*       "        */
111         uint32_t lv_size;
112         uint32_t lv_snapshot_minor;     /* minor number of original */
113         uint16_t lv_chunk_size; /* chunk size of snapshot */
114         uint16_t dummy;
115         uint32_t lv_allocated_le;
116         uint32_t lv_stripes;
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));
123
124 struct vg_disk {
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 */
136         uint32_t dummy;
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));
143
144 struct pe_disk {
145         uint16_t lv_num;
146         uint16_t le_num;
147 } __attribute__ ((packed));
148
149 struct uuid_list {
150         struct dm_list list;
151         char uuid[NAME_LEN] __attribute__((aligned(8)));
152 };
153
154 struct lvd_list {
155         struct dm_list list;
156         struct lv_disk lvd;
157 };
158
159 struct disk_list {
160         struct dm_list list;
161         struct dm_pool *mem;
162         struct device *dev;
163
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)));
169 };
170
171 /*
172  * Layout constants.
173  */
174 #define METADATA_ALIGN 4096UL
175 #define LVM1_PE_ALIGN (65536UL >> SECTOR_SHIFT)      /* PE alignment */
176
177 #define METADATA_BASE 0UL
178 #define PV_SIZE 1024UL
179 #define VG_SIZE 4096UL
180
181 /*
182  * Functions to calculate layout info.
183  */
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);
187
188 /*
189  * Low level io routines which read/write
190  * disk_lists.
191  */
192
193 struct disk_list *read_disk(const struct format_type *fmt, struct device *dev,
194                             struct dm_pool *mem, const char *vg_name);
195
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);
199
200 int write_disks(const struct format_type *fmt, struct dm_list *pvds);
201
202 /*
203  * Functions to translate to between disk and in
204  * core structures.
205  */
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);
213
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);
217
218 int import_lv(struct cmd_context *cmd, struct dm_pool *mem,
219               struct logical_volume *lv, struct lv_disk *lvd);
220
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);
225
226 int import_pvs(const struct format_type *fmt, struct dm_pool *mem,
227                struct volume_group *vg, struct dm_list *pvds);
228
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);
232
233 int import_snapshots(struct dm_pool *mem, struct volume_group *vg,
234                      struct dm_list *pvds);
235
236 int export_uuids(struct disk_list *dl, struct volume_group *vg);
237
238 void export_numbers(struct dm_list *pvds, struct volume_group *vg);
239
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);
243
244 /* blech */
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);
249
250 #endif