6 * Copyright (C) 1997 - 2002 Heinz Mauelshagen, Sistina Software
8 * February-November 1997
10 * January-March,July,September,October,Dezember 1999
11 * January,February,July,November 2000
12 * January-March,June,July 2001
15 * lvm is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
20 * lvm is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with GNU CC; see the file COPYING. If not, write to
27 * the Free Software Foundation, 59 Temple Place - Suite 330,
28 * Boston, MA 02111-1307, USA.
35 * 10/10/1997 - beginning of new structure creation
36 * 12/05/1998 - incorporated structures from lvm_v1.h and deleted lvm_v1.h
37 * 07/06/1998 - avoided LVM_KMALLOC_MAX define by using vmalloc/vfree
38 * instead of kmalloc/kfree
39 * 01/07/1998 - fixed wrong LVM_MAX_SIZE
40 * 07/07/1998 - extended pe_t structure by ios member (for statistic)
41 * 02/08/1998 - changes for official char/block major numbers
42 * 07/08/1998 - avoided init_module() and cleanup_module() to be static
43 * 29/08/1998 - seprated core and disk structure type definitions
44 * 01/09/1998 - merged kernel integration version (mike)
45 * 20/01/1999 - added LVM_PE_DISK_OFFSET macro for use in
46 * vg_read_with_pv_and_lv(), pv_move_pe(), pv_show_pe_text()...
47 * 18/02/1999 - added definition of time_disk_t structure for;
48 * keeps time stamps on disk for nonatomic writes (future)
49 * 15/03/1999 - corrected LV() and VG() macro definition to use argument
51 * 03/07/1999 - define for genhd.c name handling
52 * 23/07/1999 - implemented snapshot part
53 * 08/12/1999 - changed LVM_LV_SIZE_MAX macro to reflect current 1TB limit
54 * 01/01/2000 - extended lv_v2 core structure by wait_queue member
55 * 12/02/2000 - integrated Andrea Arcagnelli's snapshot work
56 * 18/02/2000 - seperated user and kernel space parts by
57 * #ifdef them with __KERNEL__
58 * 08/03/2000 - implemented cluster/shared bits for vg_access
59 * 26/06/2000 - implemented snapshot persistency and resizing support
60 * 02/11/2000 - added hash table size member to lv structure
61 * 12/11/2000 - removed unneeded timestamp definitions
62 * 24/12/2000 - removed LVM_TO_{CORE,DISK}*, use cpu_{from, to}_le*
63 * instead - Christoph Hellwig
64 * 22/01/2001 - Change ulong to uint32_t
65 * 14/02/2001 - changed LVM_SNAPSHOT_MIN_CHUNK to 1 page
66 * 20/02/2001 - incremented IOP version to 11 because of incompatible
67 * change in VG activation (in order to support devfs better)
68 * 01/03/2001 - Revert to IOP10 and add VG_CREATE_OLD call for compatibility
69 * 08/03/2001 - new lv_t (in core) version number 5: changed page member
70 * to (struct kiobuf *) to use for COW exception table io
71 * 26/03/2001 - changed lv_v4 to lv_v5 in structure definition (HM)
72 * 21/06/2001 - changed BLOCK_SIZE back to 1024 for non S/390
73 * 22/06/2001 - added Andreas Dilger's PE on 4k boundary alignment enhancements
74 * 19/07/2001 - added rwsem compatibility macros for 2.2 kernels
75 * 13/11/2001 - reduced userspace inclusion of kernel headers to a minimum
80 #ifndef _LVM_H_INCLUDE
81 #define _LVM_H_INCLUDE
83 #define LVM_RELEASE_NAME "1.0.5+"
84 #define LVM_RELEASE_DATE "22/07/2002"
86 #define _LVM_KERNEL_H_VERSION "LVM "LVM_RELEASE_NAME" ("LVM_RELEASE_DATE")"
88 #include <linux/version.h>
91 * preprocessor definitions
93 /* if you like emergency reset code in the driver */
94 #define LVM_TOTAL_RESET
97 #undef LVM_HD_NAME /* display nice names in /proc/partitions */
99 /* lots of debugging output (see driver source)
100 #define DEBUG_LVM_GET_INFO
103 #define DEBUG_MAP_SIZE
106 #define DEBUG_GENDISK
107 #define DEBUG_VG_CREATE
112 #include <linux/kdev_t.h>
113 #include <linux/list.h>
114 #include <asm/types.h>
115 #include <linux/major.h>
117 /* This prevents the need to include <linux/list.h> which
118 causes problems on some platforms. It's not nice but then
119 neither is the alternative. */
121 struct list_head *next, *prev;
124 #include <linux/kdev_t.h>
126 #endif /* #ifndef __KERNEL__ */
130 #include <linux/spinlock.h>
132 #include <asm/semaphore.h>
133 #endif /* #ifdef __KERNEL__ */
136 #include <asm/page.h>
138 #if !defined ( LVM_BLK_MAJOR) || !defined ( LVM_CHAR_MAJOR)
139 #error Bad include/linux/major.h - LVM MAJOR undefined
146 #ifdef CONFIG_ARCH_S390
147 #define BLOCK_SIZE 4096
149 #define BLOCK_SIZE 1024
153 #define SECTOR_SIZE 512
156 /* structure version */
157 #define LVM_STRUCT_VERSION 1
159 #define LVM_DIR_PREFIX "/dev/"
162 * i/o protocol version
164 * defined here for the driver and defined seperate in the
165 * user land tools/lib/liblvm.h
168 #define LVM_DRIVER_IOP_VERSION 10
170 #define LVM_NAME "lvm"
171 #define LVM_GLOBAL "global"
172 #define LVM_DIR "lvm"
173 #define LVM_VG_SUBDIR "VGs"
174 #define LVM_LV_SUBDIR "LVs"
175 #define LVM_PV_SUBDIR "PVs"
178 * VG/LV indexing macros
180 /* character minor maps directly to volume group */
181 #define VG_CHR(a) ( a)
183 /* block minor indexes into a volume group/logical volume indirection table */
184 #define VG_BLK(a) ( vg_lv_map[a].vg_number)
185 #define LV_BLK(a) ( vg_lv_map[a].lv_number)
188 * absolute limits for VGs, PVs per VG and LVs per VG
190 #define ABS_MAX_VG 99
191 #define ABS_MAX_PV 256
192 #define ABS_MAX_LV 256 /* caused by 8 bit minor */
194 #define MAX_VG ABS_MAX_VG
195 #define MAX_LV ABS_MAX_LV
196 #define MAX_PV ABS_MAX_PV
198 #if ( MAX_VG > ABS_MAX_VG)
200 #define MAX_VG ABS_MAX_VG
203 #if ( MAX_LV > ABS_MAX_LV)
205 #define MAX_LV ABS_MAX_LV
210 * VGDA: default disk spaces and offsets
212 * there's space after the structures for later extensions.
215 * --------------- ---------------------------------- ------------
216 * 0 physical volume structure ~500 byte
218 * 1K volume group structure ~200 byte
220 * 6K namelist of physical volumes 128 byte each
222 * 6k + n * ~300byte n logical volume structures ~300 byte each
224 * + m * 4byte m physical extent alloc. structs 4 byte each
226 * End of disk - first physical extent typically 4 megabyte
233 /* DONT TOUCH THESE !!! */
242 * LVM_PE_T_MAX corresponds to:
244 * 8KB PE size can map a ~512 MB logical volume at the cost of 1MB memory,
246 * 128MB PE size can map a 8TB logical volume at the same cost of memory.
248 * Default PE size of 4 MB gives a maximum logical volume size of 256 GB.
250 * Maximum PE size of 16GB gives a maximum logical volume size of 1024 TB.
252 * AFAIK, the actual kernels limit this to 1 TB.
254 * Should be a sufficient spectrum ;*)
257 /* This is the usable size of pe_disk_t.le_num !!! v v */
258 #define LVM_PE_T_MAX ( ( 1 << ( sizeof ( uint16_t) * 8)) - 2)
260 #define LVM_LV_SIZE_MAX(a) ( ( long long) LVM_PE_T_MAX * (a)->pe_size > ( long long) 1024*1024/SECTOR_SIZE*1024*1024 ? ( long long) 1024*1024/SECTOR_SIZE*1024*1024 : ( long long) LVM_PE_T_MAX * (a)->pe_size)
261 #define LVM_MIN_PE_SIZE ( 8192L / SECTOR_SIZE) /* 8 KB in sectors */
262 #define LVM_MAX_PE_SIZE ( 16L * 1024L * 1024L / SECTOR_SIZE * 1024) /* 16GB in sectors */
263 #define LVM_DEFAULT_PE_SIZE ( 4096L * 1024 / SECTOR_SIZE) /* 4 MB in sectors */
264 #define LVM_DEFAULT_STRIPE_SIZE 16L /* 16 KB */
265 #define LVM_MIN_STRIPE_SIZE ( PAGE_SIZE/SECTOR_SIZE) /* PAGESIZE in sectors */
266 #define LVM_MAX_STRIPE_SIZE ( 512L * 1024 / SECTOR_SIZE) /* 512 KB in sectors */
267 #define LVM_MAX_STRIPES 128 /* max # of stripes */
268 #define LVM_MAX_SIZE ( 1024LU * 1024 / SECTOR_SIZE * 1024 * 1024) /* 1TB[sectors] */
269 #define LVM_MAX_MIRRORS 2 /* future use */
270 #define LVM_MIN_READ_AHEAD 0 /* minimum read ahead sectors */
271 #define LVM_DEFAULT_READ_AHEAD 1024 /* sectors for 512k scsi segments */
272 #define LVM_MAX_READ_AHEAD 1024 /* maximum read ahead sectors */
273 #define LVM_MAX_LV_IO_TIMEOUT 60 /* seconds I/O timeout (future use) */
274 #define LVM_PARTITION 0xfe /* LVM partition id */
275 #define LVM_NEW_PARTITION 0x8e /* new LVM partition id (10/09/1999) */
276 #define LVM_PE_SIZE_PV_SIZE_REL 5 /* max relation PV size and PE size */
278 #define LVM_SNAPSHOT_MAX_CHUNK 1024 /* 1024 KB */
279 #define LVM_SNAPSHOT_DEF_CHUNK 64 /* 64 KB */
280 #define LVM_SNAPSHOT_MIN_CHUNK (PAGE_SIZE/1024) /* 4 or 8 KB */
286 * FIXME: the last parameter to _IO{W,R,WR} is a data type. The macro will
287 * expand this using sizeof(), so putting "1" there is misleading
288 * because sizeof(1) = sizeof(int) = sizeof(2) = 4 on a 32-bit machine!
291 #define VG_CREATE_OLD _IOW ( 0xfe, 0x00, 1)
292 #define VG_REMOVE _IOW ( 0xfe, 0x01, 1)
294 #define VG_EXTEND _IOW ( 0xfe, 0x03, 1)
295 #define VG_REDUCE _IOW ( 0xfe, 0x04, 1)
297 #define VG_STATUS _IOWR ( 0xfe, 0x05, 1)
298 #define VG_STATUS_GET_COUNT _IOWR ( 0xfe, 0x06, 1)
299 #define VG_STATUS_GET_NAMELIST _IOWR ( 0xfe, 0x07, 1)
301 #define VG_SET_EXTENDABLE _IOW ( 0xfe, 0x08, 1)
302 #define VG_RENAME _IOW ( 0xfe, 0x09, 1)
305 #define VG_CREATE _IOW ( 0xfe, 0x0a, 1)
308 #define LV_CREATE _IOW ( 0xfe, 0x20, 1)
309 #define LV_REMOVE _IOW ( 0xfe, 0x21, 1)
311 #define LV_ACTIVATE _IO ( 0xfe, 0x22)
312 #define LV_DEACTIVATE _IO ( 0xfe, 0x23)
314 #define LV_EXTEND _IOW ( 0xfe, 0x24, 1)
315 #define LV_REDUCE _IOW ( 0xfe, 0x25, 1)
317 #define LV_STATUS_BYNAME _IOWR ( 0xfe, 0x26, 1)
318 #define LV_STATUS_BYINDEX _IOWR ( 0xfe, 0x27, 1)
320 #define LV_SET_ACCESS _IOW ( 0xfe, 0x28, 1)
321 #define LV_SET_ALLOCATION _IOW ( 0xfe, 0x29, 1)
322 #define LV_SET_STATUS _IOW ( 0xfe, 0x2a, 1)
324 #define LE_REMAP _IOW ( 0xfe, 0x2b, 1)
326 #define LV_SNAPSHOT_USE_RATE _IOWR ( 0xfe, 0x2c, 1)
328 #define LV_STATUS_BYDEV _IOWR ( 0xfe, 0x2e, 1)
330 #define LV_RENAME _IOW ( 0xfe, 0x2f, 1)
332 #define LV_BMAP _IOWR ( 0xfe, 0x30, 1)
335 /* physical volume */
336 #define PV_STATUS _IOWR ( 0xfe, 0x40, 1)
337 #define PV_CHANGE _IOWR ( 0xfe, 0x41, 1)
338 #define PV_FLUSH _IOW ( 0xfe, 0x42, 1)
340 /* physical extent */
341 #define PE_LOCK_UNLOCK _IOW ( 0xfe, 0x50, 1)
343 /* i/o protocol version */
344 #define LVM_GET_IOP_VERSION _IOR ( 0xfe, 0x98, 1)
346 #ifdef LVM_TOTAL_RESET
347 /* special reset function for testing purposes */
348 #define LVM_RESET _IO ( 0xfe, 0x99)
351 /* lock the logical volume manager */
352 #if LVM_DRIVER_IOP_VERSION > 11
353 #define LVM_LOCK_LVM _IO ( 0xfe, 0x9A)
355 /* This is actually the same as _IO ( 0xff, 0x00), oops. Remove for IOP 12+ */
356 #define LVM_LOCK_LVM _IO ( 0xfe, 0x100)
365 #define VG_ACTIVE 0x01 /* vg_status */
366 #define VG_EXPORTED 0x02 /* " */
367 #define VG_EXTENDABLE 0x04 /* " */
369 #define VG_READ 0x01 /* vg_access */
370 #define VG_WRITE 0x02 /* " */
371 #define VG_CLUSTERED 0x04 /* " */
372 #define VG_SHARED 0x08 /* " */
375 #define LV_ACTIVE 0x01 /* lv_status */
376 #define LV_SPINDOWN 0x02 /* " */
378 #define LV_READ 0x01 /* lv_access */
379 #define LV_WRITE 0x02 /* " */
380 #define LV_SNAPSHOT 0x04 /* " */
381 #define LV_SNAPSHOT_ORG 0x08 /* " */
383 #define LV_BADBLOCK_ON 0x01 /* lv_badblock */
385 #define LV_STRICT 0x01 /* lv_allocation */
386 #define LV_CONTIGUOUS 0x02 /* " */
388 /* physical volume */
389 #define PV_ACTIVE 0x01 /* pv_status */
390 #define PV_ALLOCATABLE 0x02 /* pv_allocatable */
394 #define LVM_SNAPSHOT_DROPPED_SECTOR 1
397 * Structure definitions core/disk follow
399 * conditional conversion takes place on big endian architectures
400 * in functions * pv_copy_*(), vg_copy_*() and lv_copy_*()
404 #define NAME_LEN 128 /* don't change!!! */
405 #define UUID_LEN 32 /* don't change!!! */
407 /* copy on write tables in disk format */
408 typedef struct lv_COW_table_disk_v1 {
409 uint64_t pv_org_number;
410 uint64_t pv_org_rsector;
411 uint64_t pv_snap_number;
412 uint64_t pv_snap_rsector;
413 } lv_COW_table_disk_t;
415 /* remap physical sector/rdev pairs including hash */
416 typedef struct lv_block_exception_v1 {
417 struct list_head hash;
418 uint32_t rsector_org;
420 uint32_t rsector_new;
422 } lv_block_exception_t;
424 /* disk stored pe information */
430 /* disk stored PV, VG, LV and PE size and offset information */
438 * physical volume structures
442 typedef struct pv_v2 {
443 char id[2]; /* Identifier */
444 unsigned short version; /* HM lvm version */
445 lvm_disk_data_t pv_on_disk;
446 lvm_disk_data_t vg_on_disk;
447 lvm_disk_data_t pv_uuidlist_on_disk;
448 lvm_disk_data_t lv_on_disk;
449 lvm_disk_data_t pe_on_disk;
450 char pv_name[NAME_LEN];
451 char vg_name[NAME_LEN];
452 char system_id[NAME_LEN]; /* for vgexport/vgimport */
457 uint pv_size; /* HM */
462 uint pe_stale; /* for future use */
463 pe_disk_t *pe; /* HM */
464 struct block_device *bd;
465 char pv_uuid[UUID_LEN+1];
468 uint32_t pe_start; /* in sectors */
474 typedef struct pv_disk_v2 {
475 uint8_t id[2]; /* Identifier */
476 uint16_t version; /* HM lvm version */
477 lvm_disk_data_t pv_on_disk;
478 lvm_disk_data_t vg_on_disk;
479 lvm_disk_data_t pv_uuidlist_on_disk;
480 lvm_disk_data_t lv_on_disk;
481 lvm_disk_data_t pe_on_disk;
482 uint8_t pv_uuid[NAME_LEN];
483 uint8_t vg_name[NAME_LEN];
484 uint8_t system_id[NAME_LEN]; /* for vgexport/vgimport */
488 uint32_t pv_allocatable;
489 uint32_t pv_size; /* HM */
493 uint32_t pe_allocated;
495 /* new in struct version 2 */
496 uint32_t pe_start; /* in sectors */
502 * Structures for Logical Volume (LV)
505 /* core PE information */
508 uint32_t pe; /* to be changed if > 2TB */
514 char lv_name[NAME_LEN];
521 typedef struct lv_bmap {
527 * Structure Logical Volume (LV) Version 3
531 typedef struct lv_v5 {
532 char lv_name[NAME_LEN];
533 char vg_name[NAME_LEN];
536 uint lv_open; /* HM */
537 kdev_t lv_dev; /* HM */
538 uint lv_number; /* HM */
539 uint lv_mirror_copies; /* for future use */
540 uint lv_recovery; /* " */
541 uint lv_schedule; /* " */
543 pe_t *lv_current_pe; /* HM */
544 uint lv_current_le; /* for future use */
545 uint lv_allocated_le;
548 uint lv_badblock; /* for future use */
550 uint lv_io_timeout; /* for future use */
553 /* delta to version 1 starts here */
554 struct lv_v5 *lv_snapshot_org;
555 struct lv_v5 *lv_snapshot_prev;
556 struct lv_v5 *lv_snapshot_next;
557 lv_block_exception_t *lv_block_exception;
561 uint lv_snapshot_minor;
563 struct kiobuf *lv_iobuf;
564 struct kiobuf *lv_COW_table_iobuf;
565 struct rw_semaphore lv_lock;
566 struct list_head *lv_snapshot_hash_table;
567 uint32_t lv_snapshot_hash_table_size;
568 uint32_t lv_snapshot_hash_mask;
569 wait_queue_head_t lv_snapshot_wait;
570 int lv_snapshot_use_rate;
573 uint lv_allocated_snapshot_le;
580 typedef struct lv_disk_v3 {
581 uint8_t lv_name[NAME_LEN];
582 uint8_t vg_name[NAME_LEN];
585 uint32_t lv_open; /* HM */
586 uint32_t lv_dev; /* HM */
587 uint32_t lv_number; /* HM */
588 uint32_t lv_mirror_copies; /* for future use */
589 uint32_t lv_recovery; /* " */
590 uint32_t lv_schedule; /* " */
592 uint32_t lv_snapshot_minor;/* minor number of original */
593 uint16_t lv_chunk_size; /* chunk size of snapshot */
595 uint32_t lv_allocated_le;
597 uint32_t lv_stripesize;
598 uint32_t lv_badblock; /* for future use */
599 uint32_t lv_allocation;
600 uint32_t lv_io_timeout; /* for future use */
601 uint32_t lv_read_ahead; /* HM */
605 * Structure Volume Group (VG) Version 1
609 typedef struct vg_v3 {
610 char vg_name[NAME_LEN]; /* volume group name */
611 uint vg_number; /* volume group number */
612 uint vg_access; /* read/write */
613 uint vg_status; /* active or not */
614 uint lv_max; /* maximum logical volumes */
615 uint lv_cur; /* current logical volumes */
616 uint lv_open; /* open logical volumes */
617 uint pv_max; /* maximum physical volumes */
618 uint pv_cur; /* current physical volumes FU */
619 uint pv_act; /* active physical volumes */
620 uint dummy; /* was obsolete max_pe_per_pv */
621 uint vgda; /* volume group descriptor arrays FU */
622 uint pe_size; /* physical extent size in sectors */
623 uint pe_total; /* total of physical extents */
624 uint pe_allocated; /* allocated physical extents */
625 uint pvg_total; /* physical volume groups FU */
626 struct proc_dir_entry *proc;
627 pv_t *pv[ABS_MAX_PV + 1]; /* physical volume struct pointers */
628 lv_t *lv[ABS_MAX_LV + 1]; /* logical volume struct pointers */
629 char vg_uuid[UUID_LEN+1]; /* volume group UUID */
631 struct proc_dir_entry *vg_dir_pde;
632 struct proc_dir_entry *lv_subdir_pde;
633 struct proc_dir_entry *pv_subdir_pde;
641 typedef struct vg_disk_v2 {
642 uint8_t vg_uuid[UUID_LEN]; /* volume group UUID */
643 uint8_t vg_name_dummy[NAME_LEN-UUID_LEN]; /* rest of v1 VG name */
644 uint32_t vg_number; /* volume group number */
645 uint32_t vg_access; /* read/write */
646 uint32_t vg_status; /* active or not */
647 uint32_t lv_max; /* maximum logical volumes */
648 uint32_t lv_cur; /* current logical volumes */
649 uint32_t lv_open; /* open logical volumes */
650 uint32_t pv_max; /* maximum physical volumes */
651 uint32_t pv_cur; /* current physical volumes FU */
652 uint32_t pv_act; /* active physical volumes */
654 uint32_t vgda; /* volume group descriptor arrays FU */
655 uint32_t pe_size; /* physical extent size in sectors */
656 uint32_t pe_total; /* total of physical extents */
657 uint32_t pe_allocated; /* allocated physical extents */
658 uint32_t pvg_total; /* physical volume groups FU */
663 * Request structures for ioctls
666 /* Request structure PV_STATUS_BY_NAME... */
668 char pv_name[NAME_LEN];
670 } pv_status_req_t, pv_change_req_t;
672 /* Request structure PV_FLUSH */
674 char pv_name[NAME_LEN];
679 /* Request structure PE_MOVE */
692 /* Request structure LV_STATUS_BYNAME */
694 char lv_name[NAME_LEN];
696 } lv_status_byname_req_t, lv_req_t;
698 /* Request structure LV_STATUS_BYINDEX */
702 /* Transfer size because user space and kernel space differ */
704 } lv_status_byindex_req_t;
706 /* Request structure LV_STATUS_BYDEV... */
710 } lv_status_bydev_req_t;
713 /* Request structure LV_SNAPSHOT_USE_RATE */
717 } lv_snapshot_use_rate_req_t;
722 static inline ulong round_up(ulong n, ulong size) {
724 return (n + size) & ~size;
727 static inline ulong div_up(ulong n, ulong size) {
728 return round_up(n, size) / size;
731 /* FIXME: nasty capital letters */
732 static int inline LVM_GET_COW_TABLE_CHUNKS_PER_PE(vg_t *vg, lv_t *lv) {
733 return vg->pe_size / lv->lv_chunk_size;
736 static int inline LVM_GET_COW_TABLE_ENTRIES_PER_PE(vg_t *vg, lv_t *lv) {
737 ulong chunks = vg->pe_size / lv->lv_chunk_size;
738 ulong entry_size = sizeof(lv_COW_table_disk_t);
739 ulong chunk_size = lv->lv_chunk_size * SECTOR_SIZE;
740 ulong entries = (vg->pe_size * SECTOR_SIZE) /
741 (entry_size + chunk_size);
746 for(; entries; entries--)
747 if((div_up(entries * entry_size, chunk_size) + entries) <=
755 #endif /* #ifndef _LVM_H_INCLUDE */