1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-28 20:25:52 +03:00
lvm2/lib/metadata/metadata.h

256 lines
6.2 KiB
C
Raw Normal View History

2001-09-25 16:49:28 +04:00
/*
* Copyright (C) 2001 Sistina Software (UK) Limited.
2001-09-25 16:49:28 +04:00
*
2001-09-28 17:15:30 +04:00
* This file is released under the GPL.
2001-09-25 16:49:28 +04:00
*
* This is the in core representation of a volume group and its
2001-09-28 17:15:30 +04:00
* associated physical and logical volumes.
2001-09-25 16:49:28 +04:00
*/
2001-10-01 19:14:39 +04:00
#ifndef _LVM_METADATA_H
#define _LVM_METADATA_H
2001-09-25 16:49:28 +04:00
#include <sys/types.h>
2001-10-01 20:21:21 +04:00
#include "dev-cache.h"
2001-10-02 21:09:05 +04:00
#include "list.h"
#include "uuid.h"
2001-10-01 20:21:21 +04:00
2001-10-02 21:09:05 +04:00
#define NAME_LEN 128
/* Various flags */
/* Note that the bits no longer necessarily correspond to LVM1 disk format */
2001-10-05 17:03:03 +04:00
#define ACTIVE 0x00000001 /* PV VG LV */
#define EXPORTED_VG 0x00000002 /* VG */ /* And PV too perhaps? */
#define EXTENDABLE_VG 0x00000004 /* VG */
2001-10-09 21:20:02 +04:00
#define ALLOCATED_PV 0x00000008 /* PV */
2001-10-05 17:03:03 +04:00
#define SPINDOWN_LV 0x00000010 /* LV */
#define BADBLOCK_ON 0x00000020 /* LV */
2001-10-05 17:03:03 +04:00
#define LVM_READ 0x00000100 /* LV VG */
#define LVM_WRITE 0x00000200 /* LV VG */
#define CLUSTERED 0x00000400 /* VG */
#define SHARED 0x00000800 /* VG */
2001-10-05 17:03:03 +04:00
#define ALLOC_STRICT 0x00001000 /* LV */
#define ALLOC_CONTIGUOUS 0x00002000 /* LV */
#define SNAPSHOT 0x00004000 /* LV */
#define SNAPSHOT_ORG 0x00008000 /* LV */
2001-10-02 21:09:05 +04:00
#define EXPORTED_TAG "PV_EXP" /* Identifier of exported PV */
#define IMPORTED_TAG "PV_IMP" /* Identifier of imported PV */
2001-09-28 17:15:30 +04:00
struct physical_volume {
2001-10-08 20:08:16 +04:00
struct id id;
2001-09-28 17:15:30 +04:00
struct device *dev;
char *vg_name;
2001-10-02 21:09:05 +04:00
char *exported;
2001-09-25 16:49:28 +04:00
uint32_t status;
uint64_t size;
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
/* physical extents */
uint64_t pe_size;
uint64_t pe_start;
uint32_t pe_count;
uint32_t pe_allocated;
2001-09-28 17:15:30 +04:00
};
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
struct pe_specifier {
struct physical_volume *pv;
uint32_t pe;
2001-09-28 17:15:30 +04:00
};
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
struct logical_volume {
/* disk */
2001-10-08 20:08:16 +04:00
struct id id;
char *name;
2001-09-25 16:49:28 +04:00
uint32_t status;
uint32_t read_ahead;
uint32_t stripes;
2001-09-25 16:49:28 +04:00
uint64_t size;
uint32_t le_count;
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
/* le -> pe mapping array */
struct pe_specifier *map;
};
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
struct volume_group {
2001-10-08 20:08:16 +04:00
struct id id;
char *name;
2001-09-25 16:49:28 +04:00
uint32_t status;
2001-10-03 16:34:08 +04:00
uint64_t extent_size;
uint32_t extent_count;
uint32_t free_count;
2001-09-25 16:49:28 +04:00
uint32_t max_lv;
uint32_t max_pv;
2001-10-04 00:38:07 +04:00
2001-09-28 17:15:30 +04:00
/* physical volumes */
uint32_t pv_count;
2001-10-08 13:45:16 +04:00
struct list_head pvs;
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
/* logical volumes */
uint32_t lv_count;
2001-10-08 13:45:16 +04:00
struct list_head lvs;
2001-09-28 17:15:30 +04:00
};
2001-09-25 16:49:28 +04:00
struct name_list {
2001-10-02 21:09:05 +04:00
struct list_head list;
2001-10-08 20:08:16 +04:00
char *name;
2001-10-02 21:09:05 +04:00
};
struct pv_list {
struct list_head list;
struct physical_volume pv;
};
2001-10-08 13:45:16 +04:00
struct lv_list {
struct list_head list;
struct logical_volume lv;
};
/*
* Ownership of objects passes to caller.
*/
2001-09-28 17:15:30 +04:00
struct io_space {
/*
* Returns a name_list of vg's.
*/
struct list_head *(*get_vgs)(struct io_space *is);
/*
* Returns pv_list of fully-populated pv structures.
*/
struct list_head *(*get_pvs)(struct io_space *is);
2001-09-25 16:49:28 +04:00
/*
* Return PV with given path.
*/
struct physical_volume *(*pv_read)(struct io_space *is,
2001-10-09 21:20:02 +04:00
const char *pv_name);
/*
2001-10-12 18:25:53 +04:00
* Tweak an already filled out a pv ready
* for importing into a vg. eg. pe_count
* is format specific.
*/
int (*pv_setup)(struct io_space *is, struct physical_volume *pv,
struct volume_group *vg);
/*
* Write a PV structure to disk. Fails if
* the PV is in a VG ie pv->vg_name must
* be null.
*/
int (*pv_write)(struct io_space *is, struct physical_volume *pv);
2001-09-25 16:49:28 +04:00
2001-10-12 18:25:53 +04:00
/*
* Tweak an already filled out vg. eg,
* max_pv is format specific.
*/
int (*vg_setup)(struct io_space *is, struct volume_group *vg);
/*
* If vg_name doesn't contain any slash,
* this function adds prefix.
*/
2001-10-01 20:21:21 +04:00
struct volume_group *(*vg_read)(struct io_space *is,
2001-09-28 17:15:30 +04:00
const char *vg_name);
/*
* Write out complete VG metadata. Ensure
* *internal* consistency before writing
* anything. eg. PEs can't refer to PVs
* not part of the VG. Order write sequence
* to aid recovery if process is aborted
* (eg flush entire set of changes to each
* disk in turn) It is the responsibility
* of the caller to ensure external
* consistency, eg by calling pv_write()
* if removing PVs from a VG or calling
* vg_write() a second time if splitting a
* VG into two. vg_write() must not read
* or write from any PVs not included in
* the volume_group structure it is
* handed.
*/
2001-10-01 20:21:21 +04:00
int (*vg_write)(struct io_space *is, struct volume_group *vg);
/*
* Destructor for this object.
*/
void (*destroy)(struct io_space *is);
2001-09-25 16:49:28 +04:00
/*
* Current volume group prefix.
*/
2001-10-06 01:39:30 +04:00
char *prefix;
2001-10-08 13:45:16 +04:00
struct pool *mem;
2001-10-01 20:21:21 +04:00
struct dev_filter *filter;
2001-09-28 17:15:30 +04:00
void *private;
};
2001-09-25 16:49:28 +04:00
/*
* Utility functions
*/
2001-10-12 18:25:53 +04:00
struct volume_group *vg_create(struct io_space *ios, const char *name,
uint64_t extent_size, int max_pv, int max_lv,
int pv_count, char **pv_names);
struct physical_volume *pv_create(struct io_space *ios, const char *name);
2001-10-16 02:04:27 +04:00
int vg_extend(struct io_space *ios, struct volume_group *vg, int pv_count,
char **pv_names);
/* FIXME: Move to other files */
struct io_space *create_text_format(struct dev_filter *filter,
2001-09-28 17:15:30 +04:00
const char *text_file);
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
int id_eq(struct id *op1, struct id *op2);
/* Create consistent new empty structures, populated with defaults */
struct volume_group *vg_create();
2001-09-28 17:15:30 +04:00
int vg_destroy(struct volume_group *vg);
/* Manipulate PV structures */
int pv_add(struct volume_group *vg, struct physical_volume *pv);
2001-10-03 16:34:08 +04:00
int pv_remove(struct volume_group *vg, struct physical_volume *pv);
struct physical_volume *pv_find(struct volume_group *vg,
2001-10-03 16:34:08 +04:00
const char *pv_name);
2001-09-25 16:49:28 +04:00
/* Add an LV to a given VG */
int lv_add(struct volume_group *vg, struct logical_volume *lv);
/* Remove an LV from a given VG */
2001-10-29 16:52:23 +03:00
int lv_remove(struct volume_group *vg, struct list_head *lvh);
2001-10-29 16:52:23 +03:00
/* Find a PV within a given VG */
struct list_head *find_pv_in_vg(struct volume_group *vg, const char *pv_name);
/* Find an LV within a given VG */
2001-10-29 16:52:23 +03:00
struct list_head *find_lv_in_vg(struct volume_group *vg, const char *lv_name);
/* Return the VG that contains a given LV (based on path given in lv_name) */
/* or environment var */
struct volume_group *find_vg_with_lv(const char *lv_name);
/* FIXME Merge these functions with ones above */
struct physical_volume *_find_pv(struct volume_group *vg, struct device *dev);
struct logical_volume *find_lv(struct volume_group *vg, const char *lv_name);
2001-09-28 17:15:30 +04:00
2001-10-15 22:39:40 +04:00
2001-09-28 17:15:30 +04:00
#endif