import source from lvm2 2.02.79
[external/device-mapper.git] / lib / cache / lvmcache.h
1 /*
2  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.  
3  * Copyright (C) 2004-2008 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 _LVM_CACHE_H
17 #define _LVM_CACHE_H
18
19 #include "dev-cache.h"
20 #include "uuid.h"
21 #include "label.h"
22 #include "locking.h"
23
24 #define ORPHAN_PREFIX VG_ORPHANS
25 #define ORPHAN_VG_NAME(fmt) ORPHAN_PREFIX "_" fmt
26
27 #define CACHE_INVALID   0x00000001
28 #define CACHE_LOCKED    0x00000002
29
30 /* LVM specific per-volume info */
31 /* Eventual replacement for struct physical_volume perhaps? */
32
33 struct cmd_context;
34 struct format_type;
35 struct volume_group;
36
37 /* One per VG */
38 struct lvmcache_vginfo {
39         struct dm_list list;    /* Join these vginfos together */
40         struct dm_list infos;   /* List head for lvmcache_infos */
41         const struct format_type *fmt;
42         char *vgname;           /* "" == orphan */
43         uint32_t status;
44         char vgid[ID_LEN + 1];
45         char _padding[7];
46         struct lvmcache_vginfo *next; /* Another VG with same name? */
47         char *creation_host;
48         char *vgmetadata;       /* Copy of VG metadata as format_text string */
49         unsigned precommitted;  /* Is vgmetadata live or precommitted? */
50 };
51
52 /* One per device */
53 struct lvmcache_info {
54         struct dm_list list;    /* Join VG members together */
55         struct dm_list mdas;    /* list head for metadata areas */
56         struct dm_list das;     /* list head for data areas */
57         struct lvmcache_vginfo *vginfo; /* NULL == unknown */
58         struct label *label;
59         const struct format_type *fmt;
60         struct device *dev;
61         uint64_t device_size;   /* Bytes */
62         uint32_t status;
63 };
64
65 int lvmcache_init(void);
66 void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans);
67
68 /* Set full_scan to 1 to reread every filtered device label or
69  * 2 to rescan /dev for new devices */
70 int lvmcache_label_scan(struct cmd_context *cmd, int full_scan);
71
72 /* Add/delete a device */
73 struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
74                                    struct device *dev,
75                                    const char *vgname, const char *vgid,
76                                    uint32_t vgstatus);
77 int lvmcache_add_orphan_vginfo(const char *vgname, struct format_type *fmt);
78 void lvmcache_del(struct lvmcache_info *info);
79
80 /* Update things */
81 int lvmcache_update_vgname_and_id(struct lvmcache_info *info,
82                                   const char *vgname, const char *vgid,
83                                   uint32_t vgstatus, const char *hostname);
84 int lvmcache_update_vg(struct volume_group *vg, unsigned precommitted);
85
86 void lvmcache_lock_vgname(const char *vgname, int read_only);
87 void lvmcache_unlock_vgname(const char *vgname);
88 int lvmcache_verify_lock_order(const char *vgname);
89
90 /* Queries */
91 const struct format_type *fmt_from_vgname(const char *vgname, const char *vgid, unsigned revalidate_labels);
92 struct lvmcache_vginfo *vginfo_from_vgname(const char *vgname,
93                                            const char *vgid);
94 struct lvmcache_vginfo *vginfo_from_vgid(const char *vgid);
95 struct lvmcache_info *info_from_pvid(const char *pvid, int valid_only);
96 const char *vgname_from_vgid(struct dm_pool *mem, const char *vgid);
97 struct device *device_from_pvid(struct cmd_context *cmd, const struct id *pvid,
98                                 unsigned *scan_done_once);
99 const char *pvid_from_devname(struct cmd_context *cmd,
100                               const char *dev_name);
101 char *lvmcache_vgname_from_pvid(struct cmd_context *cmd, const char *pvid);
102 int vgs_locked(void);
103 int vgname_is_locked(const char *vgname);
104
105 /* Returns list of struct str_lists containing pool-allocated copy of vgnames */
106 /* If include_internal is not set, return only proper vg names. */
107 struct dm_list *lvmcache_get_vgnames(struct cmd_context *cmd,
108                                      int include_internal);
109
110 /* Returns list of struct str_lists containing pool-allocated copy of vgids */
111 /* If include_internal is not set, return only proper vg ids. */
112 struct dm_list *lvmcache_get_vgids(struct cmd_context *cmd,
113                                    int include_internal);
114
115 /* Returns list of struct str_lists containing pool-allocated copy of pvids */
116 struct dm_list *lvmcache_get_pvids(struct cmd_context *cmd, const char *vgname,
117                                 const char *vgid);
118
119 /* Returns cached volume group metadata. */
120 struct volume_group *lvmcache_get_vg(const char *vgid, unsigned precommitted);
121 void lvmcache_drop_metadata(const char *vgname, int drop_precommitted);
122 void lvmcache_commit_metadata(const char *vgname);
123
124 #endif