import source from lvm2 2.02.79
[external/device-mapper.git] / lib / metadata / vg.h
1 /*
2  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3  * Copyright (C) 2004-2010 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 #ifndef _LVM_VG_H
16 #define _LVM_VG_H
17
18 struct cmd_context;
19 struct dm_pool;
20 struct format_instance;
21 struct dm_list;
22 struct id;
23
24 typedef enum {
25         ALLOC_INVALID,
26         ALLOC_CONTIGUOUS,
27         ALLOC_CLING,
28         ALLOC_CLING_BY_TAGS,    /* Internal - never written or displayed. */
29         ALLOC_NORMAL,
30         ALLOC_ANYWHERE,
31         ALLOC_INHERIT
32 } alloc_policy_t;
33
34 struct volume_group {
35         struct cmd_context *cmd;
36         struct dm_pool *vgmem;
37         struct format_instance *fid;
38         struct dm_list *cmd_vgs;/* List of wanted/locked and opened VGs */
39         uint32_t cmd_missing_vgs;/* Flag marks missing VG */
40         uint32_t seqno;         /* Metadata sequence number */
41
42         alloc_policy_t alloc;
43         uint64_t status;
44
45         struct id id;
46         const char *name;
47         const char *old_name;           /* Set during vgrename and vgcfgrestore */
48         char *system_id;
49
50         uint32_t extent_size;
51         uint32_t extent_count;
52         uint32_t free_count;
53
54         uint32_t max_lv;
55         uint32_t max_pv;
56
57         /* physical volumes */
58         uint32_t pv_count;
59         struct dm_list pvs;
60
61         /*
62          * logical volumes
63          * The following relationship should always hold:
64          * dm_list_size(lvs) = user visible lv_count + snapshot_count + other invisible LVs
65          *
66          * Snapshots consist of 2 instances of "struct logical_volume":
67          * - cow (lv_name is visible to the user)
68          * - snapshot (lv_name is 'snapshotN')
69          *
70          * Mirrors consist of multiple instances of "struct logical_volume":
71          * - one for the mirror log
72          * - one for each mirror leg
73          * - one for the user-visible mirror LV
74          */
75         struct dm_list lvs;
76
77         struct dm_list tags;
78
79         /*
80          * FIXME: Move the next fields into a different struct?
81          */
82
83         /*
84          * List of removed physical volumes by pvreduce.
85          * They have to get cleared on vg_commit.
86          */
87         struct dm_list removed_pvs;
88         uint32_t open_mode; /* FIXME: read or write - check lock type? */
89
90         /*
91          * Store result of the last vg_read().
92          * 0 for success else appropriate FAILURE_* bits set.
93          */
94         uint32_t read_status;
95         uint32_t mda_copies; /* target number of mdas for this VG */
96 };
97
98 char *vg_fmt_dup(const struct volume_group *vg);
99 char *vg_name_dup(const struct volume_group *vg);
100 char *vg_system_id_dup(const struct volume_group *vg);
101 uint32_t vg_seqno(const struct volume_group *vg);
102 uint64_t vg_status(const struct volume_group *vg);
103 int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc);
104 int vg_set_clustered(struct volume_group *vg, int clustered);
105 uint64_t vg_size(const struct volume_group *vg);
106 uint64_t vg_free(const struct volume_group *vg);
107 uint64_t vg_extent_size(const struct volume_group *vg);
108 int vg_set_extent_size(struct volume_group *vg, uint32_t new_extent_size);
109 uint64_t vg_extent_count(const struct volume_group *vg);
110 uint64_t vg_free_count(const struct volume_group *vg);
111 uint64_t vg_pv_count(const struct volume_group *vg);
112 uint64_t vg_max_pv(const struct volume_group *vg);
113 int vg_set_max_pv(struct volume_group *vg, uint32_t max_pv);
114 uint64_t vg_max_lv(const struct volume_group *vg);
115 int vg_set_max_lv(struct volume_group *vg, uint32_t max_lv);
116 uint32_t vg_mda_count(const struct volume_group *vg);
117 uint32_t vg_mda_used_count(const struct volume_group *vg);
118 uint32_t vg_mda_copies(const struct volume_group *vg);
119 int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies);
120 /*
121  * Returns visible LV count - number of LVs from user perspective
122  */
123 unsigned vg_visible_lvs(const struct volume_group *vg);
124 /*
125  * Count snapshot LVs.
126  */
127 unsigned snapshot_count(const struct volume_group *vg);
128
129 uint64_t vg_mda_size(const struct volume_group *vg);
130 uint64_t vg_mda_free(const struct volume_group *vg);
131 char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg);
132 char *vg_uuid_dup(const struct volume_group *vg);
133 char *vg_tags_dup(const struct volume_group *vg);
134
135 #endif /* _LVM_VG_H */