186d7f5d3SJohn Marino /* $NetBSD: lvmcache.h,v 1.1.1.2 2009/12/02 00:25:44 haad Exp $ */ 286d7f5d3SJohn Marino 386d7f5d3SJohn Marino /* 486d7f5d3SJohn Marino * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. 586d7f5d3SJohn Marino * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. 686d7f5d3SJohn Marino * 786d7f5d3SJohn Marino * This file is part of LVM2. 886d7f5d3SJohn Marino * 986d7f5d3SJohn Marino * This copyrighted material is made available to anyone wishing to use, 1086d7f5d3SJohn Marino * modify, copy, or redistribute it subject to the terms and conditions 1186d7f5d3SJohn Marino * of the GNU Lesser General Public License v.2.1. 1286d7f5d3SJohn Marino * 1386d7f5d3SJohn Marino * You should have received a copy of the GNU Lesser General Public License 1486d7f5d3SJohn Marino * along with this program; if not, write to the Free Software Foundation, 1586d7f5d3SJohn Marino * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1686d7f5d3SJohn Marino */ 1786d7f5d3SJohn Marino 1886d7f5d3SJohn Marino #ifndef _LVM_CACHE_H 1986d7f5d3SJohn Marino #define _LVM_CACHE_H 2086d7f5d3SJohn Marino 2186d7f5d3SJohn Marino #include "dev-cache.h" 2286d7f5d3SJohn Marino #include "uuid.h" 2386d7f5d3SJohn Marino #include "label.h" 2486d7f5d3SJohn Marino 2586d7f5d3SJohn Marino #define ORPHAN_PREFIX "#" 2686d7f5d3SJohn Marino #define ORPHAN_VG_NAME(fmt) ORPHAN_PREFIX "orphans_" fmt 2786d7f5d3SJohn Marino 2886d7f5d3SJohn Marino #define CACHE_INVALID 0x00000001 2986d7f5d3SJohn Marino #define CACHE_LOCKED 0x00000002 3086d7f5d3SJohn Marino 3186d7f5d3SJohn Marino /* LVM specific per-volume info */ 3286d7f5d3SJohn Marino /* Eventual replacement for struct physical_volume perhaps? */ 3386d7f5d3SJohn Marino 3486d7f5d3SJohn Marino struct cmd_context; 3586d7f5d3SJohn Marino struct format_type; 3686d7f5d3SJohn Marino struct volume_group; 3786d7f5d3SJohn Marino 3886d7f5d3SJohn Marino /* One per VG */ 3986d7f5d3SJohn Marino struct lvmcache_vginfo { 4086d7f5d3SJohn Marino struct dm_list list; /* Join these vginfos together */ 4186d7f5d3SJohn Marino struct dm_list infos; /* List head for lvmcache_infos */ 4286d7f5d3SJohn Marino const struct format_type *fmt; 4386d7f5d3SJohn Marino char *vgname; /* "" == orphan */ 4486d7f5d3SJohn Marino uint32_t status; 4586d7f5d3SJohn Marino char vgid[ID_LEN + 1]; 4686d7f5d3SJohn Marino char _padding[7]; 4786d7f5d3SJohn Marino struct lvmcache_vginfo *next; /* Another VG with same name? */ 4886d7f5d3SJohn Marino char *creation_host; 4986d7f5d3SJohn Marino char *vgmetadata; /* Copy of VG metadata as format_text string */ 5086d7f5d3SJohn Marino unsigned precommitted; /* Is vgmetadata live or precommitted? */ 5186d7f5d3SJohn Marino }; 5286d7f5d3SJohn Marino 5386d7f5d3SJohn Marino /* One per device */ 5486d7f5d3SJohn Marino struct lvmcache_info { 5586d7f5d3SJohn Marino struct dm_list list; /* Join VG members together */ 5686d7f5d3SJohn Marino struct dm_list mdas; /* list head for metadata areas */ 5786d7f5d3SJohn Marino struct dm_list das; /* list head for data areas */ 5886d7f5d3SJohn Marino struct lvmcache_vginfo *vginfo; /* NULL == unknown */ 5986d7f5d3SJohn Marino struct label *label; 6086d7f5d3SJohn Marino const struct format_type *fmt; 6186d7f5d3SJohn Marino struct device *dev; 6286d7f5d3SJohn Marino uint64_t device_size; /* Bytes */ 6386d7f5d3SJohn Marino uint32_t status; 6486d7f5d3SJohn Marino }; 6586d7f5d3SJohn Marino 6686d7f5d3SJohn Marino int lvmcache_init(void); 6786d7f5d3SJohn Marino void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans); 6886d7f5d3SJohn Marino 6986d7f5d3SJohn Marino /* Set full_scan to 1 to reread every filtered device label or 7086d7f5d3SJohn Marino * 2 to rescan /dev for new devices */ 7186d7f5d3SJohn Marino int lvmcache_label_scan(struct cmd_context *cmd, int full_scan); 7286d7f5d3SJohn Marino 7386d7f5d3SJohn Marino /* Add/delete a device */ 7486d7f5d3SJohn Marino struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid, 7586d7f5d3SJohn Marino struct device *dev, 7686d7f5d3SJohn Marino const char *vgname, const char *vgid, 7786d7f5d3SJohn Marino uint32_t vgstatus); 7886d7f5d3SJohn Marino int lvmcache_add_orphan_vginfo(const char *vgname, struct format_type *fmt); 7986d7f5d3SJohn Marino void lvmcache_del(struct lvmcache_info *info); 8086d7f5d3SJohn Marino 8186d7f5d3SJohn Marino /* Update things */ 8286d7f5d3SJohn Marino int lvmcache_update_vgname_and_id(struct lvmcache_info *info, 8386d7f5d3SJohn Marino const char *vgname, const char *vgid, 8486d7f5d3SJohn Marino uint32_t vgstatus, const char *hostname); 8586d7f5d3SJohn Marino int lvmcache_update_vg(struct volume_group *vg, unsigned precommitted); 8686d7f5d3SJohn Marino 8786d7f5d3SJohn Marino void lvmcache_lock_vgname(const char *vgname, int read_only); 8886d7f5d3SJohn Marino void lvmcache_unlock_vgname(const char *vgname); 8986d7f5d3SJohn Marino int lvmcache_verify_lock_order(const char *vgname); 9086d7f5d3SJohn Marino 9186d7f5d3SJohn Marino /* Queries */ 9286d7f5d3SJohn Marino const struct format_type *fmt_from_vgname(const char *vgname, const char *vgid); 9386d7f5d3SJohn Marino struct lvmcache_vginfo *vginfo_from_vgname(const char *vgname, 9486d7f5d3SJohn Marino const char *vgid); 9586d7f5d3SJohn Marino struct lvmcache_vginfo *vginfo_from_vgid(const char *vgid); 9686d7f5d3SJohn Marino struct lvmcache_info *info_from_pvid(const char *pvid, int valid_only); 9786d7f5d3SJohn Marino const char *vgname_from_vgid(struct dm_pool *mem, const char *vgid); 9886d7f5d3SJohn Marino struct device *device_from_pvid(struct cmd_context *cmd, struct id *pvid); 9986d7f5d3SJohn Marino int vgs_locked(void); 10086d7f5d3SJohn Marino int vgname_is_locked(const char *vgname); 10186d7f5d3SJohn Marino 10286d7f5d3SJohn Marino /* Returns list of struct str_lists containing pool-allocated copy of vgnames */ 10386d7f5d3SJohn Marino /* Set full_scan to 1 to reread every filtered device label */ 10486d7f5d3SJohn Marino struct dm_list *lvmcache_get_vgnames(struct cmd_context *cmd, int full_scan); 10586d7f5d3SJohn Marino 10686d7f5d3SJohn Marino /* Returns list of struct str_lists containing pool-allocated copy of vgids */ 10786d7f5d3SJohn Marino /* Set full_scan to 1 to reread every filtered device label */ 10886d7f5d3SJohn Marino struct dm_list *lvmcache_get_vgids(struct cmd_context *cmd, int full_scan); 10986d7f5d3SJohn Marino 11086d7f5d3SJohn Marino /* Returns list of struct str_lists containing pool-allocated copy of pvids */ 11186d7f5d3SJohn Marino struct dm_list *lvmcache_get_pvids(struct cmd_context *cmd, const char *vgname, 11286d7f5d3SJohn Marino const char *vgid); 11386d7f5d3SJohn Marino 11486d7f5d3SJohn Marino /* Returns cached volume group metadata. */ 11586d7f5d3SJohn Marino struct volume_group *lvmcache_get_vg(const char *vgid, unsigned precommitted); 11686d7f5d3SJohn Marino void lvmcache_drop_metadata(const char *vgname); 11786d7f5d3SJohn Marino 11886d7f5d3SJohn Marino #endif 119