2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
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.
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
19 #include "dev-cache.h"
24 #define ORPHAN_PREFIX VG_ORPHANS
25 #define ORPHAN_VG_NAME(fmt) ORPHAN_PREFIX "_" fmt
27 #define CACHE_INVALID 0x00000001
28 #define CACHE_LOCKED 0x00000002
30 /* LVM specific per-volume info */
31 /* Eventual replacement for struct physical_volume perhaps? */
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 */
44 char vgid[ID_LEN + 1];
46 struct lvmcache_vginfo *next; /* Another VG with same name? */
48 char *vgmetadata; /* Copy of VG metadata as format_text string */
49 unsigned precommitted; /* Is vgmetadata live or precommitted? */
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 */
59 const struct format_type *fmt;
61 uint64_t device_size; /* Bytes */
65 int lvmcache_init(void);
66 void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans);
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);
72 /* Add/delete a device */
73 struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
75 const char *vgname, const char *vgid,
77 int lvmcache_add_orphan_vginfo(const char *vgname, struct format_type *fmt);
78 void lvmcache_del(struct lvmcache_info *info);
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);
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);
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,
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);
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);
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);
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,
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);