1 1.1 haad /* $NetBSD: metadata-exported.h,v 1.1.1.3 2009/12/02 00:25:43 haad Exp $ */ 2 1.1 haad 3 1.1 haad /* 4 1.1.1.3 haad * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. 5 1.1.1.3 haad * Copyright (C) 2004-2009 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 representation of LVM metadata that is being adapted 20 1.1 haad * for library export. 21 1.1 haad */ 22 1.1 haad 23 1.1 haad #ifndef _LVM_METADATA_EXPORTED_H 24 1.1 haad #define _LVM_METADATA_EXPORTED_H 25 1.1 haad 26 1.1 haad #include "uuid.h" 27 1.1 haad 28 1.1 haad #define MAX_STRIPES 128U 29 1.1 haad #define SECTOR_SHIFT 9L 30 1.1 haad #define STRIPE_SIZE_MIN ( (unsigned) lvm_getpagesize() >> SECTOR_SHIFT) /* PAGESIZE in sectors */ 31 1.1 haad #define STRIPE_SIZE_MAX ( 512L * 1024L >> SECTOR_SHIFT) /* 512 KB in sectors */ 32 1.1 haad #define STRIPE_SIZE_LIMIT ((UINT_MAX >> 2) + 1) 33 1.1 haad #define PV_MIN_SIZE ( 512L * 1024L >> SECTOR_SHIFT) /* 512 KB in sectors */ 34 1.1 haad #define MAX_RESTRICTED_LVS 255 /* Used by FMT_RESTRICTED_LVIDS */ 35 1.1 haad 36 1.1 haad /* Layer suffix */ 37 1.1 haad #define MIRROR_SYNC_LAYER "_mimagetmp" 38 1.1 haad 39 1.1 haad /* Various flags */ 40 1.1 haad /* Note that the bits no longer necessarily correspond to LVM1 disk format */ 41 1.1 haad 42 1.1 haad #define PARTIAL_VG 0x00000001U /* VG */ 43 1.1 haad #define EXPORTED_VG 0x00000002U /* VG PV */ 44 1.1 haad #define RESIZEABLE_VG 0x00000004U /* VG */ 45 1.1 haad 46 1.1 haad /* May any free extents on this PV be used or must they be left free? */ 47 1.1 haad #define ALLOCATABLE_PV 0x00000008U /* PV */ 48 1.1 haad 49 1.1 haad //#define SPINDOWN_LV 0x00000010U /* LV */ 50 1.1 haad //#define BADBLOCK_ON 0x00000020U /* LV */ 51 1.1 haad #define VISIBLE_LV 0x00000040U /* LV */ 52 1.1 haad #define FIXED_MINOR 0x00000080U /* LV */ 53 1.1 haad /* FIXME Remove when metadata restructuring is completed */ 54 1.1 haad #define SNAPSHOT 0x00001000U /* LV - internal use only */ 55 1.1 haad #define PVMOVE 0x00002000U /* VG LV SEG */ 56 1.1 haad #define LOCKED 0x00004000U /* LV */ 57 1.1 haad #define MIRRORED 0x00008000U /* LV - internal use only */ 58 1.1 haad //#define VIRTUAL 0x00010000U /* LV - internal use only */ 59 1.1 haad #define MIRROR_LOG 0x00020000U /* LV */ 60 1.1 haad #define MIRROR_IMAGE 0x00040000U /* LV */ 61 1.1 haad #define MIRROR_NOTSYNCED 0x00080000U /* LV */ 62 1.1 haad //#define ACTIVATE_EXCL 0x00100000U /* LV - internal use only */ 63 1.1 haad //#define PRECOMMITTED 0x00200000U /* VG - internal use only */ 64 1.1 haad #define CONVERTING 0x00400000U /* LV */ 65 1.1 haad 66 1.1 haad #define MISSING_PV 0x00800000U /* PV */ 67 1.1 haad #define PARTIAL_LV 0x01000000U /* LV - derived flag, not 68 1.1 haad written out in metadata*/ 69 1.1 haad 70 1.1 haad //#define POSTORDER_FLAG 0x02000000U /* Not real flags, reserved for 71 1.1.1.3 haad //#define POSTORDER_OPEN_FLAG 0x04000000U temporary use inside vg_read_internal. */ 72 1.1.1.3 haad //#define VIRTUAL_ORIGIN 0x08000000U /* LV - internal use only */ 73 1.1 haad 74 1.1 haad #define LVM_READ 0x00000100U /* LV VG */ 75 1.1 haad #define LVM_WRITE 0x00000200U /* LV VG */ 76 1.1 haad #define CLUSTERED 0x00000400U /* VG */ 77 1.1 haad //#define SHARED 0x00000800U /* VG */ 78 1.1 haad 79 1.1 haad /* Format features flags */ 80 1.1 haad #define FMT_SEGMENTS 0x00000001U /* Arbitrary segment params? */ 81 1.1 haad #define FMT_MDAS 0x00000002U /* Proper metadata areas? */ 82 1.1 haad #define FMT_TAGS 0x00000004U /* Tagging? */ 83 1.1 haad #define FMT_UNLIMITED_VOLS 0x00000008U /* Unlimited PVs/LVs? */ 84 1.1 haad #define FMT_RESTRICTED_LVIDS 0x00000010U /* LVID <= 255 */ 85 1.1 haad #define FMT_ORPHAN_ALLOCATABLE 0x00000020U /* Orphan PV allocatable? */ 86 1.1 haad //#define FMT_PRECOMMIT 0x00000040U /* Supports pre-commit? */ 87 1.1 haad #define FMT_RESIZE_PV 0x00000080U /* Supports pvresize? */ 88 1.1 haad #define FMT_UNLIMITED_STRIPESIZE 0x00000100U /* Unlimited stripe size? */ 89 1.1 haad #define FMT_RESTRICTED_READAHEAD 0x00000200U /* Readahead restricted to 2-120? */ 90 1.1 haad 91 1.1 haad /* Mirror conversion type flags */ 92 1.1 haad #define MIRROR_BY_SEG 0x00000001U /* segment-by-segment mirror */ 93 1.1 haad #define MIRROR_BY_LV 0x00000002U /* mirror using whole mimage LVs */ 94 1.1 haad #define MIRROR_SKIP_INIT_SYNC 0x00000010U /* skip initial sync */ 95 1.1 haad 96 1.1.1.3 haad /* vg_read and vg_read_for_update flags */ 97 1.1.1.3 haad #define READ_ALLOW_INCONSISTENT 0x00010000U 98 1.1.1.3 haad #define READ_ALLOW_EXPORTED 0x00020000U 99 1.1.1.3 haad #define READ_WITHOUT_LOCK 0x00040000U 100 1.1.1.3 haad 101 1.1.1.3 haad /* A meta-flag, useful with toollib for_each_* functions. */ 102 1.1.1.3 haad #define READ_FOR_UPDATE 0x00100000U 103 1.1.1.3 haad 104 1.1.1.3 haad /* vg's "read_status" field */ 105 1.1.1.3 haad #define FAILED_INCONSISTENT 0x00000001U 106 1.1.1.3 haad #define FAILED_LOCKING 0x00000002U 107 1.1.1.3 haad #define FAILED_NOTFOUND 0x00000004U 108 1.1.1.3 haad #define FAILED_READ_ONLY 0x00000008U 109 1.1.1.3 haad #define FAILED_EXPORTED 0x00000010U 110 1.1.1.3 haad #define FAILED_RESIZEABLE 0x00000020U 111 1.1.1.3 haad #define FAILED_CLUSTERED 0x00000040U 112 1.1.1.3 haad #define FAILED_ALLOCATION 0x00000080U 113 1.1.1.3 haad #define FAILED_EXIST 0x00000100U 114 1.1.1.3 haad #define SUCCESS 0x00000000U 115 1.1.1.3 haad 116 1.1 haad /* Ordered list - see lv_manip.c */ 117 1.1 haad typedef enum { 118 1.1 haad ALLOC_INVALID, 119 1.1 haad ALLOC_CONTIGUOUS, 120 1.1 haad ALLOC_CLING, 121 1.1 haad ALLOC_NORMAL, 122 1.1 haad ALLOC_ANYWHERE, 123 1.1 haad ALLOC_INHERIT 124 1.1 haad } alloc_policy_t; 125 1.1 haad 126 1.1 haad typedef enum { 127 1.1 haad AREA_UNASSIGNED, 128 1.1 haad AREA_PV, 129 1.1 haad AREA_LV 130 1.1 haad } area_type_t; 131 1.1 haad 132 1.1 haad /* 133 1.1 haad * Whether or not to force an operation. 134 1.1 haad */ 135 1.1 haad typedef enum { 136 1.1 haad PROMPT = 0, /* Issue yes/no prompt to confirm operation */ 137 1.1 haad DONT_PROMPT = 1, /* Skip yes/no prompt */ 138 1.1 haad DONT_PROMPT_OVERRIDE = 2 /* Skip prompt + override a second condition */ 139 1.1 haad } force_t; 140 1.1 haad 141 1.1.1.3 haad typedef enum { 142 1.1.1.3 haad PERCENT_0 = 0, 143 1.1.1.3 haad PERCENT_0_TO_100 = 1, 144 1.1.1.3 haad PERCENT_100 = 2, 145 1.1.1.3 haad PERCENT_INVALID = 3 146 1.1.1.3 haad } percent_range_t; 147 1.1.1.3 haad 148 1.1 haad struct cmd_context; 149 1.1 haad struct format_handler; 150 1.1 haad struct labeller; 151 1.1 haad 152 1.1 haad struct format_type { 153 1.1 haad struct dm_list list; 154 1.1 haad struct cmd_context *cmd; 155 1.1 haad struct format_handler *ops; 156 1.1 haad struct labeller *labeller; 157 1.1 haad const char *name; 158 1.1 haad const char *alias; 159 1.1 haad const char *orphan_vg_name; 160 1.1 haad uint32_t features; 161 1.1 haad void *library; 162 1.1 haad void *private; 163 1.1 haad }; 164 1.1 haad 165 1.1 haad struct pv_segment { 166 1.1 haad struct dm_list list; /* Member of pv->segments: ordered list 167 1.1 haad * covering entire data area on this PV */ 168 1.1 haad 169 1.1 haad struct physical_volume *pv; 170 1.1 haad uint32_t pe; 171 1.1 haad uint32_t len; 172 1.1 haad 173 1.1 haad struct lv_segment *lvseg; /* NULL if free space */ 174 1.1 haad uint32_t lv_area; /* Index to area in LV segment */ 175 1.1 haad }; 176 1.1 haad 177 1.1 haad #define pvseg_is_allocated(pvseg) ((pvseg)->lvseg) 178 1.1 haad 179 1.1 haad struct physical_volume { 180 1.1 haad struct id id; 181 1.1 haad struct device *dev; 182 1.1 haad const struct format_type *fmt; 183 1.1 haad const char *vg_name; 184 1.1 haad struct id vgid; 185 1.1 haad 186 1.1 haad uint32_t status; 187 1.1 haad uint64_t size; 188 1.1 haad 189 1.1 haad /* physical extents */ 190 1.1 haad uint32_t pe_size; 191 1.1 haad uint64_t pe_start; 192 1.1 haad uint32_t pe_count; 193 1.1 haad uint32_t pe_alloc_count; 194 1.1 haad unsigned long pe_align; 195 1.1.1.3 haad unsigned long pe_align_offset; 196 1.1 haad 197 1.1 haad struct dm_list segments; /* Ordered pv_segments covering complete PV */ 198 1.1 haad struct dm_list tags; 199 1.1 haad }; 200 1.1 haad 201 1.1 haad struct format_instance { 202 1.1 haad const struct format_type *fmt; 203 1.1 haad struct dm_list metadata_areas; /* e.g. metadata locations */ 204 1.1 haad void *private; 205 1.1 haad }; 206 1.1 haad 207 1.1 haad struct volume_group { 208 1.1 haad struct cmd_context *cmd; 209 1.1.1.3 haad struct dm_pool *vgmem; 210 1.1 haad struct format_instance *fid; 211 1.1 haad uint32_t seqno; /* Metadata sequence number */ 212 1.1 haad 213 1.1 haad struct id id; 214 1.1 haad char *name; 215 1.1 haad char *system_id; 216 1.1 haad 217 1.1 haad uint32_t status; 218 1.1 haad alloc_policy_t alloc; 219 1.1 haad 220 1.1 haad uint32_t extent_size; 221 1.1 haad uint32_t extent_count; 222 1.1 haad uint32_t free_count; 223 1.1 haad 224 1.1 haad uint32_t max_lv; 225 1.1 haad uint32_t max_pv; 226 1.1 haad 227 1.1 haad /* physical volumes */ 228 1.1 haad uint32_t pv_count; 229 1.1 haad struct dm_list pvs; 230 1.1 haad 231 1.1 haad /* 232 1.1 haad * logical volumes 233 1.1 haad * The following relationship should always hold: 234 1.1.1.3 haad * dm_list_size(lvs) = user visible lv_count + snapshot_count + other invisible LVs 235 1.1 haad * 236 1.1 haad * Snapshots consist of 2 instances of "struct logical_volume": 237 1.1 haad * - cow (lv_name is visible to the user) 238 1.1 haad * - snapshot (lv_name is 'snapshotN') 239 1.1 haad * 240 1.1 haad * Mirrors consist of multiple instances of "struct logical_volume": 241 1.1 haad * - one for the mirror log 242 1.1 haad * - one for each mirror leg 243 1.1 haad * - one for the user-visible mirror LV 244 1.1 haad */ 245 1.1 haad struct dm_list lvs; 246 1.1 haad 247 1.1 haad struct dm_list tags; 248 1.1.1.3 haad 249 1.1.1.3 haad /* 250 1.1.1.3 haad * FIXME: Move the next fields into a different struct? 251 1.1.1.3 haad */ 252 1.1.1.3 haad 253 1.1.1.3 haad /* 254 1.1.1.3 haad * List of removed physical volumes by pvreduce. 255 1.1.1.3 haad * They have to get cleared on vg_commit. 256 1.1.1.3 haad */ 257 1.1.1.3 haad struct dm_list removed_pvs; 258 1.1.1.3 haad uint32_t open_mode; /* FIXME: read or write - check lock type? */ 259 1.1.1.3 haad 260 1.1.1.3 haad /* 261 1.1.1.3 haad * Store result of the last vg_read(). 262 1.1.1.3 haad * 0 for success else appropriate FAILURE_* bits set. 263 1.1.1.3 haad */ 264 1.1.1.3 haad uint32_t read_status; 265 1.1 haad }; 266 1.1 haad 267 1.1 haad /* There will be one area for each stripe */ 268 1.1 haad struct lv_segment_area { 269 1.1 haad area_type_t type; 270 1.1 haad union { 271 1.1 haad struct { 272 1.1 haad struct pv_segment *pvseg; 273 1.1 haad } pv; 274 1.1 haad struct { 275 1.1 haad struct logical_volume *lv; 276 1.1 haad uint32_t le; 277 1.1 haad } lv; 278 1.1 haad } u; 279 1.1 haad }; 280 1.1 haad 281 1.1 haad struct segment_type; 282 1.1 haad struct lv_segment { 283 1.1 haad struct dm_list list; 284 1.1 haad struct logical_volume *lv; 285 1.1 haad 286 1.1 haad const struct segment_type *segtype; 287 1.1 haad uint32_t le; 288 1.1 haad uint32_t len; 289 1.1 haad 290 1.1 haad uint32_t status; 291 1.1 haad 292 1.1 haad /* FIXME Fields depend on segment type */ 293 1.1 haad uint32_t stripe_size; 294 1.1 haad uint32_t area_count; 295 1.1 haad uint32_t area_len; 296 1.1 haad struct logical_volume *origin; 297 1.1 haad struct logical_volume *cow; 298 1.1 haad struct dm_list origin_list; 299 1.1 haad uint32_t chunk_size; /* For snapshots - in sectors */ 300 1.1 haad uint32_t region_size; /* For mirrors - in sectors */ 301 1.1 haad uint32_t extents_copied; 302 1.1 haad struct logical_volume *log_lv; 303 1.1.1.3 haad void *segtype_private; 304 1.1 haad 305 1.1 haad struct dm_list tags; 306 1.1 haad 307 1.1 haad struct lv_segment_area *areas; 308 1.1 haad }; 309 1.1 haad 310 1.1 haad #define seg_type(seg, s) (seg)->areas[(s)].type 311 1.1 haad #define seg_pv(seg, s) (seg)->areas[(s)].u.pv.pvseg->pv 312 1.1 haad #define seg_lv(seg, s) (seg)->areas[(s)].u.lv.lv 313 1.1 haad 314 1.1 haad struct logical_volume { 315 1.1 haad union lvid lvid; 316 1.1 haad char *name; 317 1.1 haad 318 1.1 haad struct volume_group *vg; 319 1.1 haad 320 1.1 haad uint32_t status; 321 1.1 haad alloc_policy_t alloc; 322 1.1 haad uint32_t read_ahead; 323 1.1 haad int32_t major; 324 1.1 haad int32_t minor; 325 1.1 haad 326 1.1 haad uint64_t size; /* Sectors */ 327 1.1 haad uint32_t le_count; 328 1.1 haad 329 1.1 haad uint32_t origin_count; 330 1.1 haad struct dm_list snapshot_segs; 331 1.1 haad struct lv_segment *snapshot; 332 1.1 haad 333 1.1 haad struct dm_list segments; 334 1.1 haad struct dm_list tags; 335 1.1 haad struct dm_list segs_using_this_lv; 336 1.1 haad }; 337 1.1 haad 338 1.1 haad struct pe_range { 339 1.1 haad struct dm_list list; 340 1.1 haad uint32_t start; /* PEs */ 341 1.1 haad uint32_t count; /* PEs */ 342 1.1 haad }; 343 1.1 haad 344 1.1 haad struct pv_list { 345 1.1 haad struct dm_list list; 346 1.1 haad struct physical_volume *pv; 347 1.1 haad struct dm_list *mdas; /* Metadata areas */ 348 1.1 haad struct dm_list *pe_ranges; /* Ranges of PEs e.g. for allocation */ 349 1.1 haad }; 350 1.1 haad 351 1.1 haad struct lv_list { 352 1.1 haad struct dm_list list; 353 1.1 haad struct logical_volume *lv; 354 1.1 haad }; 355 1.1 haad 356 1.1.1.3 haad struct pvcreate_params { 357 1.1.1.3 haad int zero; 358 1.1.1.3 haad uint64_t size; 359 1.1.1.3 haad uint64_t data_alignment; 360 1.1.1.3 haad uint64_t data_alignment_offset; 361 1.1.1.3 haad int pvmetadatacopies; 362 1.1.1.3 haad uint64_t pvmetadatasize; 363 1.1.1.3 haad int64_t labelsector; 364 1.1.1.3 haad struct id id; /* FIXME: redundant */ 365 1.1.1.3 haad struct id *idp; /* 0 if no --uuid option */ 366 1.1.1.3 haad uint64_t pe_start; 367 1.1.1.3 haad uint32_t extent_count; 368 1.1.1.3 haad uint32_t extent_size; 369 1.1.1.3 haad const char *restorefile; /* 0 if no --restorefile option */ 370 1.1.1.3 haad force_t force; 371 1.1.1.3 haad unsigned yes; 372 1.1.1.3 haad }; 373 1.1.1.3 haad 374 1.1.1.3 haad struct physical_volume *pvcreate_single(struct cmd_context *cmd, 375 1.1.1.3 haad const char *pv_name, 376 1.1.1.3 haad struct pvcreate_params *pp); 377 1.1.1.3 haad void pvcreate_params_set_defaults(struct pvcreate_params *pp); 378 1.1.1.3 haad 379 1.1 haad /* 380 1.1 haad * Utility functions 381 1.1 haad */ 382 1.1 haad int vg_write(struct volume_group *vg); 383 1.1 haad int vg_commit(struct volume_group *vg); 384 1.1 haad int vg_revert(struct volume_group *vg); 385 1.1.1.3 haad struct volume_group *vg_read_internal(struct cmd_context *cmd, const char *vg_name, 386 1.1 haad const char *vgid, int *consistent); 387 1.1 haad struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name, 388 1.1 haad struct dm_list *mdas, uint64_t *label_sector, 389 1.1.1.3 haad int warnings, int scan_label_only); 390 1.1 haad struct dm_list *get_pvs(struct cmd_context *cmd); 391 1.1 haad 392 1.1.1.3 haad /* 393 1.1.1.3 haad * Add/remove LV to/from volume group 394 1.1.1.3 haad */ 395 1.1.1.3 haad int link_lv_to_vg(struct volume_group *vg, struct logical_volume *lv); 396 1.1.1.3 haad int unlink_lv_from_vg(struct logical_volume *lv); 397 1.1.1.3 haad void lv_set_visible(struct logical_volume *lv); 398 1.1.1.3 haad void lv_set_hidden(struct logical_volume *lv); 399 1.1.1.3 haad 400 1.1 haad /* Set full_scan to 1 to re-read every (filtered) device label */ 401 1.1.1.3 haad struct dm_list *get_vgnames(struct cmd_context *cmd, int full_scan); 402 1.1 haad struct dm_list *get_vgids(struct cmd_context *cmd, int full_scan); 403 1.1 haad int scan_vgs_for_pvs(struct cmd_context *cmd); 404 1.1 haad 405 1.1 haad int pv_write(struct cmd_context *cmd, struct physical_volume *pv, 406 1.1 haad struct dm_list *mdas, int64_t label_sector); 407 1.1.1.3 haad int is_pv(struct physical_volume *pv); 408 1.1.1.3 haad int move_pv(struct volume_group *vg_from, struct volume_group *vg_to, 409 1.1.1.3 haad const char *pv_name); 410 1.1.1.3 haad int move_pvs_used_by_lv(struct volume_group *vg_from, 411 1.1.1.3 haad struct volume_group *vg_to, 412 1.1.1.3 haad const char *lv_name); 413 1.1 haad int is_orphan_vg(const char *vg_name); 414 1.1.1.3 haad int is_orphan(const struct physical_volume *pv); 415 1.1 haad int vgs_are_compatible(struct cmd_context *cmd, 416 1.1 haad struct volume_group *vg_from, 417 1.1 haad struct volume_group *vg_to); 418 1.1.1.3 haad uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname); 419 1.1.1.3 haad 420 1.1.1.3 haad /* 421 1.1.1.3 haad * Return a handle to VG metadata. 422 1.1.1.3 haad */ 423 1.1.1.3 haad struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, 424 1.1.1.3 haad const char *vgid, uint32_t flags); 425 1.1.1.3 haad struct volume_group *vg_read_for_update(struct cmd_context *cmd, const char *vg_name, 426 1.1.1.3 haad const char *vgid, uint32_t flags); 427 1.1.1.3 haad 428 1.1.1.3 haad /* 429 1.1.1.3 haad * Test validity of a VG handle. 430 1.1.1.3 haad */ 431 1.1.1.3 haad uint32_t vg_read_error(struct volume_group *vg_handle); 432 1.1 haad 433 1.1 haad /* pe_start and pe_end relate to any existing data so that new metadata 434 1.1 haad * areas can avoid overlap */ 435 1.1.1.3 haad struct physical_volume *pv_create(const struct cmd_context *cmd, 436 1.1 haad struct device *dev, 437 1.1 haad struct id *id, 438 1.1 haad uint64_t size, 439 1.1.1.3 haad unsigned long data_alignment, 440 1.1.1.3 haad unsigned long data_alignment_offset, 441 1.1 haad uint64_t pe_start, 442 1.1 haad uint32_t existing_extent_count, 443 1.1 haad uint32_t existing_extent_size, 444 1.1 haad int pvmetadatacopies, 445 1.1 haad uint64_t pvmetadatasize, struct dm_list *mdas); 446 1.1 haad int pv_resize(struct physical_volume *pv, struct volume_group *vg, 447 1.1 haad uint32_t new_pe_count); 448 1.1 haad int pv_analyze(struct cmd_context *cmd, const char *pv_name, 449 1.1 haad uint64_t label_sector); 450 1.1 haad 451 1.1 haad /* FIXME: move internal to library */ 452 1.1 haad uint32_t pv_list_extents_free(const struct dm_list *pvh); 453 1.1 haad 454 1.1.1.3 haad struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name); 455 1.1.1.3 haad int vg_remove_mdas(struct volume_group *vg); 456 1.1.1.3 haad int vg_remove_check(struct volume_group *vg); 457 1.1 haad int vg_remove(struct volume_group *vg); 458 1.1 haad int vg_rename(struct cmd_context *cmd, struct volume_group *vg, 459 1.1 haad const char *new_name); 460 1.1.1.3 haad int vg_extend(struct volume_group *vg, int pv_count, char **pv_names, 461 1.1.1.3 haad struct pvcreate_params *pp); 462 1.1.1.3 haad int vg_reduce(struct volume_group *vg, char *pv_name); 463 1.1.1.3 haad int vg_set_extent_size(struct volume_group *vg, uint32_t new_extent_size); 464 1.1.1.3 haad int vg_set_max_lv(struct volume_group *vg, uint32_t max_lv); 465 1.1.1.3 haad int vg_set_max_pv(struct volume_group *vg, uint32_t max_pv); 466 1.1.1.3 haad int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc); 467 1.1.1.3 haad int vg_set_clustered(struct volume_group *vg, int clustered); 468 1.1 haad int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from, 469 1.1 haad struct volume_group *vg_to); 470 1.1 haad 471 1.1.1.3 haad /* FIXME: refactor / unexport when lvremove liblvm refactoring dones */ 472 1.1.1.3 haad int remove_lvs_in_vg(struct cmd_context *cmd, 473 1.1.1.3 haad struct volume_group *vg, 474 1.1.1.3 haad force_t force); 475 1.1.1.3 haad /* 476 1.1.1.3 haad * vg_release() must be called on every struct volume_group allocated 477 1.1.1.3 haad * by vg_create() or vg_read_internal() to free it when no longer required. 478 1.1.1.3 haad */ 479 1.1.1.3 haad void vg_release(struct volume_group *vg); 480 1.1.1.3 haad 481 1.1 haad /* Manipulate LVs */ 482 1.1 haad struct logical_volume *lv_create_empty(const char *name, 483 1.1 haad union lvid *lvid, 484 1.1 haad uint32_t status, 485 1.1 haad alloc_policy_t alloc, 486 1.1 haad struct volume_group *vg); 487 1.1 haad 488 1.1 haad /* Write out LV contents */ 489 1.1 haad int set_lv(struct cmd_context *cmd, struct logical_volume *lv, 490 1.1 haad uint64_t sectors, int value); 491 1.1 haad 492 1.1 haad /* Reduce the size of an LV by extents */ 493 1.1 haad int lv_reduce(struct logical_volume *lv, uint32_t extents); 494 1.1 haad 495 1.1 haad /* Empty an LV prior to deleting it */ 496 1.1 haad int lv_empty(struct logical_volume *lv); 497 1.1 haad 498 1.1 haad /* Empty an LV and add error segment */ 499 1.1 haad int replace_lv_with_error_segment(struct logical_volume *lv); 500 1.1 haad 501 1.1 haad /* Entry point for all LV extent allocations */ 502 1.1 haad int lv_extend(struct logical_volume *lv, 503 1.1 haad const struct segment_type *segtype, 504 1.1 haad uint32_t stripes, uint32_t stripe_size, 505 1.1 haad uint32_t mirrors, uint32_t extents, 506 1.1 haad struct physical_volume *mirrored_pv, uint32_t mirrored_pe, 507 1.1 haad uint32_t status, struct dm_list *allocatable_pvs, 508 1.1 haad alloc_policy_t alloc); 509 1.1 haad 510 1.1 haad /* lv must be part of lv->vg->lvs */ 511 1.1 haad int lv_remove(struct logical_volume *lv); 512 1.1 haad 513 1.1 haad int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, 514 1.1 haad force_t force); 515 1.1 haad 516 1.1 haad int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *lv, 517 1.1 haad force_t force); 518 1.1 haad 519 1.1 haad int lv_rename(struct cmd_context *cmd, struct logical_volume *lv, 520 1.1 haad const char *new_name); 521 1.1 haad 522 1.1.1.3 haad uint64_t extents_from_size(struct cmd_context *cmd, uint64_t size, 523 1.1.1.3 haad uint32_t extent_size); 524 1.1.1.3 haad 525 1.1.1.3 haad /* FIXME: refactor and reduce the size of this struct! */ 526 1.1.1.3 haad struct lvcreate_params { 527 1.1.1.3 haad /* flags */ 528 1.1.1.3 haad int snapshot; /* snap */ 529 1.1.1.3 haad int zero; /* all */ 530 1.1.1.3 haad int major; /* all */ 531 1.1.1.3 haad int minor; /* all */ 532 1.1.1.3 haad int corelog; /* mirror */ 533 1.1.1.3 haad int nosync; /* mirror */ 534 1.1.1.3 haad 535 1.1.1.3 haad char *origin; /* snap */ 536 1.1.1.3 haad const char *vg_name; /* all */ 537 1.1.1.3 haad const char *lv_name; /* all */ 538 1.1.1.3 haad 539 1.1.1.3 haad uint32_t stripes; /* striped */ 540 1.1.1.3 haad uint32_t stripe_size; /* striped */ 541 1.1.1.3 haad uint32_t chunk_size; /* snapshot */ 542 1.1.1.3 haad uint32_t region_size; /* mirror */ 543 1.1.1.3 haad 544 1.1.1.3 haad uint32_t mirrors; /* mirror */ 545 1.1.1.3 haad 546 1.1.1.3 haad const struct segment_type *segtype; /* all */ 547 1.1.1.3 haad 548 1.1.1.3 haad /* size */ 549 1.1.1.3 haad uint32_t extents; /* all */ 550 1.1.1.3 haad uint32_t voriginextents; /* snapshot */ 551 1.1.1.3 haad uint64_t voriginsize; /* snapshot */ 552 1.1.1.3 haad struct dm_list *pvh; /* all */ 553 1.1.1.3 haad 554 1.1.1.3 haad uint32_t permission; /* all */ 555 1.1.1.3 haad uint32_t read_ahead; /* all */ 556 1.1.1.3 haad alloc_policy_t alloc; /* all */ 557 1.1.1.3 haad 558 1.1.1.3 haad const char *tag; /* all */ 559 1.1.1.3 haad }; 560 1.1.1.3 haad 561 1.1.1.3 haad int lv_create_single(struct volume_group *vg, 562 1.1.1.3 haad struct lvcreate_params *lp); 563 1.1.1.3 haad 564 1.1 haad /* 565 1.1 haad * Functions for layer manipulation 566 1.1 haad */ 567 1.1 haad int insert_layer_for_segments_on_pv(struct cmd_context *cmd, 568 1.1 haad struct logical_volume *lv_where, 569 1.1 haad struct logical_volume *layer_lv, 570 1.1 haad uint32_t status, 571 1.1 haad struct pv_list *pv, 572 1.1 haad struct dm_list *lvs_changed); 573 1.1 haad int remove_layers_for_segments(struct cmd_context *cmd, 574 1.1 haad struct logical_volume *lv, 575 1.1 haad struct logical_volume *layer_lv, 576 1.1 haad uint32_t status_mask, struct dm_list *lvs_changed); 577 1.1 haad int remove_layers_for_segments_all(struct cmd_context *cmd, 578 1.1 haad struct logical_volume *layer_lv, 579 1.1 haad uint32_t status_mask, 580 1.1 haad struct dm_list *lvs_changed); 581 1.1 haad int split_parent_segments_for_layer(struct cmd_context *cmd, 582 1.1 haad struct logical_volume *layer_lv); 583 1.1 haad int remove_layer_from_lv(struct logical_volume *lv, 584 1.1 haad struct logical_volume *layer_lv); 585 1.1 haad struct logical_volume *insert_layer_for_lv(struct cmd_context *cmd, 586 1.1 haad struct logical_volume *lv_where, 587 1.1 haad uint32_t status, 588 1.1 haad const char *layer_suffix); 589 1.1 haad 590 1.1 haad /* Find a PV within a given VG */ 591 1.1 haad struct pv_list *find_pv_in_vg(const struct volume_group *vg, 592 1.1 haad const char *pv_name); 593 1.1.1.3 haad struct physical_volume *find_pv_in_vg_by_uuid(const struct volume_group *vg, 594 1.1 haad const struct id *id); 595 1.1 haad 596 1.1 haad /* Find an LV within a given VG */ 597 1.1 haad struct lv_list *find_lv_in_vg(const struct volume_group *vg, 598 1.1 haad const char *lv_name); 599 1.1 haad 600 1.1 haad /* FIXME Merge these functions with ones above */ 601 1.1 haad struct logical_volume *find_lv(const struct volume_group *vg, 602 1.1 haad const char *lv_name); 603 1.1 haad struct physical_volume *find_pv_by_name(struct cmd_context *cmd, 604 1.1 haad const char *pv_name); 605 1.1 haad 606 1.1 haad /* Find LV segment containing given LE */ 607 1.1 haad struct lv_segment *first_seg(const struct logical_volume *lv); 608 1.1 haad 609 1.1 haad 610 1.1 haad /* 611 1.1 haad * Useful functions for managing snapshots. 612 1.1 haad */ 613 1.1 haad int lv_is_origin(const struct logical_volume *lv); 614 1.1.1.3 haad int lv_is_virtual_origin(const struct logical_volume *lv); 615 1.1 haad int lv_is_cow(const struct logical_volume *lv); 616 1.1 haad 617 1.1.1.2 haad /* Test if given LV is visible from user's perspective */ 618 1.1.1.3 haad int lv_is_visible(const struct logical_volume *lv); 619 1.1.1.2 haad 620 1.1 haad int pv_is_in_vg(struct volume_group *vg, struct physical_volume *pv); 621 1.1 haad 622 1.1 haad /* Given a cow LV, return return the snapshot lv_segment that uses it */ 623 1.1 haad struct lv_segment *find_cow(const struct logical_volume *lv); 624 1.1 haad 625 1.1 haad /* Given a cow LV, return its origin */ 626 1.1 haad struct logical_volume *origin_from_cow(const struct logical_volume *lv); 627 1.1 haad 628 1.1.1.3 haad void init_snapshot_seg(struct lv_segment *seg, struct logical_volume *origin, 629 1.1.1.3 haad struct logical_volume *cow, uint32_t chunk_size); 630 1.1.1.3 haad 631 1.1.1.3 haad int vg_add_snapshot(struct logical_volume *origin, struct logical_volume *cow, 632 1.1 haad union lvid *lvid, uint32_t extent_count, 633 1.1 haad uint32_t chunk_size); 634 1.1 haad 635 1.1 haad int vg_remove_snapshot(struct logical_volume *cow); 636 1.1 haad 637 1.1 haad int vg_check_status(const struct volume_group *vg, uint32_t status); 638 1.1 haad 639 1.1 haad /* 640 1.1.1.3 haad * Returns visible LV count - number of LVs from user perspective 641 1.1.1.3 haad */ 642 1.1.1.3 haad unsigned vg_visible_lvs(const struct volume_group *vg); 643 1.1.1.3 haad 644 1.1.1.3 haad /* 645 1.1.1.3 haad * Check if the VG reached maximal LVs count (if set) 646 1.1.1.3 haad */ 647 1.1.1.3 haad int vg_max_lv_reached(struct volume_group *vg); 648 1.1.1.3 haad 649 1.1.1.3 haad /* 650 1.1 haad * Mirroring functions 651 1.1 haad */ 652 1.1 haad struct lv_segment *find_mirror_seg(struct lv_segment *seg); 653 1.1 haad int lv_add_mirrors(struct cmd_context *cmd, struct logical_volume *lv, 654 1.1 haad uint32_t mirrors, uint32_t stripes, 655 1.1 haad uint32_t region_size, uint32_t log_count, 656 1.1 haad struct dm_list *pvs, alloc_policy_t alloc, uint32_t flags); 657 1.1 haad int lv_remove_mirrors(struct cmd_context *cmd, struct logical_volume *lv, 658 1.1 haad uint32_t mirrors, uint32_t log_count, 659 1.1 haad struct dm_list *pvs, uint32_t status_mask); 660 1.1 haad 661 1.1 haad int is_temporary_mirror_layer(const struct logical_volume *lv); 662 1.1 haad struct logical_volume * find_temporary_mirror(const struct logical_volume *lv); 663 1.1 haad uint32_t lv_mirror_count(const struct logical_volume *lv); 664 1.1 haad uint32_t adjusted_mirror_region_size(uint32_t extent_size, uint32_t extents, 665 1.1 haad uint32_t region_size); 666 1.1 haad int remove_mirrors_from_segments(struct logical_volume *lv, 667 1.1 haad uint32_t new_mirrors, uint32_t status_mask); 668 1.1 haad int add_mirrors_to_segments(struct cmd_context *cmd, struct logical_volume *lv, 669 1.1 haad uint32_t mirrors, uint32_t region_size, 670 1.1 haad struct dm_list *allocatable_pvs, alloc_policy_t alloc); 671 1.1 haad 672 1.1 haad int remove_mirror_images(struct logical_volume *lv, uint32_t num_mirrors, 673 1.1 haad struct dm_list *removable_pvs, unsigned remove_log); 674 1.1 haad int add_mirror_images(struct cmd_context *cmd, struct logical_volume *lv, 675 1.1 haad uint32_t mirrors, uint32_t stripes, uint32_t region_size, 676 1.1 haad struct dm_list *allocatable_pvs, alloc_policy_t alloc, 677 1.1 haad uint32_t log_count); 678 1.1 haad struct logical_volume *detach_mirror_log(struct lv_segment *seg); 679 1.1 haad int attach_mirror_log(struct lv_segment *seg, struct logical_volume *lv); 680 1.1 haad int remove_mirror_log(struct cmd_context *cmd, struct logical_volume *lv, 681 1.1 haad struct dm_list *removable_pvs); 682 1.1 haad int add_mirror_log(struct cmd_context *cmd, struct logical_volume *lv, 683 1.1 haad uint32_t log_count, uint32_t region_size, 684 1.1 haad struct dm_list *allocatable_pvs, alloc_policy_t alloc); 685 1.1 haad 686 1.1 haad int reconfigure_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors, 687 1.1 haad struct dm_list *removable_pvs, unsigned remove_log); 688 1.1 haad int collapse_mirrored_lv(struct logical_volume *lv); 689 1.1 haad int shift_mirror_images(struct lv_segment *mirrored_seg, unsigned mimage); 690 1.1 haad 691 1.1 haad struct logical_volume *find_pvmove_lv(struct volume_group *vg, 692 1.1 haad struct device *dev, uint32_t lv_type); 693 1.1 haad struct logical_volume *find_pvmove_lv_from_pvname(struct cmd_context *cmd, 694 1.1 haad struct volume_group *vg, 695 1.1 haad const char *name, 696 1.1.1.3 haad const char *uuid, 697 1.1 haad uint32_t lv_type); 698 1.1 haad const char *get_pvmove_pvname_from_lv(struct logical_volume *lv); 699 1.1 haad const char *get_pvmove_pvname_from_lv_mirr(struct logical_volume *lv_mirr); 700 1.1.1.3 haad float copy_percent(struct logical_volume *lv_mirr, 701 1.1.1.3 haad percent_range_t *percent_range); 702 1.1 haad struct dm_list *lvs_using_lv(struct cmd_context *cmd, struct volume_group *vg, 703 1.1 haad struct logical_volume *lv); 704 1.1 haad 705 1.1 haad uint32_t find_free_lvnum(struct logical_volume *lv); 706 1.1 haad char *generate_lv_name(struct volume_group *vg, const char *format, 707 1.1 haad char *buffer, size_t len); 708 1.1 haad 709 1.1 haad /* 710 1.1 haad * Begin skeleton for external LVM library 711 1.1 haad */ 712 1.1.1.3 haad struct device *pv_dev(const struct physical_volume *pv); 713 1.1.1.3 haad const char *pv_vg_name(const struct physical_volume *pv); 714 1.1.1.3 haad const char *pv_dev_name(const struct physical_volume *pv); 715 1.1.1.3 haad uint64_t pv_size(const struct physical_volume *pv); 716 1.1.1.3 haad uint32_t pv_status(const struct physical_volume *pv); 717 1.1.1.3 haad uint32_t pv_pe_size(const struct physical_volume *pv); 718 1.1.1.3 haad uint64_t pv_pe_start(const struct physical_volume *pv); 719 1.1.1.3 haad uint32_t pv_pe_count(const struct physical_volume *pv); 720 1.1.1.3 haad uint32_t pv_pe_alloc_count(const struct physical_volume *pv); 721 1.1.1.3 haad uint32_t pv_mda_count(const struct physical_volume *pv); 722 1.1.1.3 haad 723 1.1.1.3 haad uint64_t lv_size(const struct logical_volume *lv); 724 1.1.1.3 haad 725 1.1.1.3 haad int vg_missing_pv_count(const struct volume_group *vg); 726 1.1.1.3 haad uint32_t vg_seqno(const struct volume_group *vg); 727 1.1.1.3 haad uint32_t vg_status(const struct volume_group *vg); 728 1.1.1.3 haad uint64_t vg_size(const struct volume_group *vg); 729 1.1.1.3 haad uint64_t vg_free(const struct volume_group *vg); 730 1.1.1.3 haad uint64_t vg_extent_size(const struct volume_group *vg); 731 1.1.1.3 haad uint64_t vg_extent_count(const struct volume_group *vg); 732 1.1.1.3 haad uint64_t vg_free_count(const struct volume_group *vg); 733 1.1.1.3 haad uint64_t vg_pv_count(const struct volume_group *vg); 734 1.1.1.3 haad uint64_t vg_max_pv(const struct volume_group *vg); 735 1.1.1.3 haad uint64_t vg_max_lv(const struct volume_group *vg); 736 1.1.1.3 haad uint32_t vg_mda_count(const struct volume_group *vg); 737 1.1.1.3 haad int vg_check_write_mode(struct volume_group *vg); 738 1.1 haad #define vg_is_clustered(vg) (vg_status((vg)) & CLUSTERED) 739 1.1.1.3 haad #define vg_is_exported(vg) (vg_status((vg)) & EXPORTED_VG) 740 1.1.1.3 haad #define vg_is_resizeable(vg) (vg_status((vg)) & RESIZEABLE_VG) 741 1.1.1.3 haad 742 1.1.1.3 haad int lv_has_unknown_segments(const struct logical_volume *lv); 743 1.1.1.3 haad int vg_has_unknown_segments(const struct volume_group *vg); 744 1.1 haad 745 1.1 haad struct vgcreate_params { 746 1.1 haad char *vg_name; 747 1.1 haad uint32_t extent_size; 748 1.1 haad size_t max_pv; 749 1.1 haad size_t max_lv; 750 1.1 haad alloc_policy_t alloc; 751 1.1 haad int clustered; /* FIXME: put this into a 'status' variable instead? */ 752 1.1 haad }; 753 1.1 haad 754 1.1.1.3 haad int vgcreate_params_validate(struct cmd_context *cmd, 755 1.1.1.3 haad struct vgcreate_params *vp); 756 1.1 haad 757 1.1 haad int validate_vg_rename_params(struct cmd_context *cmd, 758 1.1 haad const char *vg_name_old, 759 1.1 haad const char *vg_name_new); 760 1.1 haad #endif 761