1*86d7f5d3SJohn Marino /* $NetBSD: lvmcache.h,v 1.1.1.2 2009/12/02 00:26:21 haad Exp $ */ 2*86d7f5d3SJohn Marino 3*86d7f5d3SJohn Marino /* 4*86d7f5d3SJohn Marino * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. 5*86d7f5d3SJohn Marino * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. 6*86d7f5d3SJohn Marino * 7*86d7f5d3SJohn Marino * This file is part of LVM2. 8*86d7f5d3SJohn Marino * 9*86d7f5d3SJohn Marino * This copyrighted material is made available to anyone wishing to use, 10*86d7f5d3SJohn Marino * modify, copy, or redistribute it subject to the terms and conditions 11*86d7f5d3SJohn Marino * of the GNU Lesser General Public License v.2.1. 12*86d7f5d3SJohn Marino * 13*86d7f5d3SJohn Marino * You should have received a copy of the GNU Lesser General Public License 14*86d7f5d3SJohn Marino * along with this program; if not, write to the Free Software Foundation, 15*86d7f5d3SJohn Marino * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16*86d7f5d3SJohn Marino */ 17*86d7f5d3SJohn Marino 18*86d7f5d3SJohn Marino #ifndef _LVM_CACHE_H 19*86d7f5d3SJohn Marino #define _LVM_CACHE_H 20*86d7f5d3SJohn Marino 21*86d7f5d3SJohn Marino #include "dev-cache.h" 22*86d7f5d3SJohn Marino #include "uuid.h" 23*86d7f5d3SJohn Marino #include "label.h" 24*86d7f5d3SJohn Marino 25*86d7f5d3SJohn Marino #define ORPHAN_PREFIX "#" 26*86d7f5d3SJohn Marino #define ORPHAN_VG_NAME(fmt) ORPHAN_PREFIX "orphans_" fmt 27*86d7f5d3SJohn Marino 28*86d7f5d3SJohn Marino #define CACHE_INVALID 0x00000001 29*86d7f5d3SJohn Marino #define CACHE_LOCKED 0x00000002 30*86d7f5d3SJohn Marino 31*86d7f5d3SJohn Marino /* LVM specific per-volume info */ 32*86d7f5d3SJohn Marino /* Eventual replacement for struct physical_volume perhaps? */ 33*86d7f5d3SJohn Marino 34*86d7f5d3SJohn Marino struct cmd_context; 35*86d7f5d3SJohn Marino struct format_type; 36*86d7f5d3SJohn Marino struct volume_group; 37*86d7f5d3SJohn Marino 38*86d7f5d3SJohn Marino /* One per VG */ 39*86d7f5d3SJohn Marino struct lvmcache_vginfo { 40*86d7f5d3SJohn Marino struct dm_list list; /* Join these vginfos together */ 41*86d7f5d3SJohn Marino struct dm_list infos; /* List head for lvmcache_infos */ 42*86d7f5d3SJohn Marino const struct format_type *fmt; 43*86d7f5d3SJohn Marino char *vgname; /* "" == orphan */ 44*86d7f5d3SJohn Marino uint32_t status; 45*86d7f5d3SJohn Marino char vgid[ID_LEN + 1]; 46*86d7f5d3SJohn Marino char _padding[7]; 47*86d7f5d3SJohn Marino struct lvmcache_vginfo *next; /* Another VG with same name? */ 48*86d7f5d3SJohn Marino char *creation_host; 49*86d7f5d3SJohn Marino char *vgmetadata; /* Copy of VG metadata as format_text string */ 50*86d7f5d3SJohn Marino unsigned precommitted; /* Is vgmetadata live or precommitted? */ 51*86d7f5d3SJohn Marino }; 52*86d7f5d3SJohn Marino 53*86d7f5d3SJohn Marino /* One per device */ 54*86d7f5d3SJohn Marino struct lvmcache_info { 55*86d7f5d3SJohn Marino struct dm_list list; /* Join VG members together */ 56*86d7f5d3SJohn Marino struct dm_list mdas; /* list head for metadata areas */ 57*86d7f5d3SJohn Marino struct dm_list das; /* list head for data areas */ 58*86d7f5d3SJohn Marino struct lvmcache_vginfo *vginfo; /* NULL == unknown */ 59*86d7f5d3SJohn Marino struct label *label; 60*86d7f5d3SJohn Marino const struct format_type *fmt; 61*86d7f5d3SJohn Marino struct device *dev; 62*86d7f5d3SJohn Marino uint64_t device_size; /* Bytes */ 63*86d7f5d3SJohn Marino uint32_t status; 64*86d7f5d3SJohn Marino }; 65*86d7f5d3SJohn Marino 66*86d7f5d3SJohn Marino int lvmcache_init(void); 67*86d7f5d3SJohn Marino void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans); 68*86d7f5d3SJohn Marino 69*86d7f5d3SJohn Marino /* Set full_scan to 1 to reread every filtered device label or 70*86d7f5d3SJohn Marino * 2 to rescan /dev for new devices */ 71*86d7f5d3SJohn Marino int lvmcache_label_scan(struct cmd_context *cmd, int full_scan); 72*86d7f5d3SJohn Marino 73*86d7f5d3SJohn Marino /* Add/delete a device */ 74*86d7f5d3SJohn Marino struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid, 75*86d7f5d3SJohn Marino struct device *dev, 76*86d7f5d3SJohn Marino const char *vgname, const char *vgid, 77*86d7f5d3SJohn Marino uint32_t vgstatus); 78*86d7f5d3SJohn Marino int lvmcache_add_orphan_vginfo(const char *vgname, struct format_type *fmt); 79*86d7f5d3SJohn Marino void lvmcache_del(struct lvmcache_info *info); 80*86d7f5d3SJohn Marino 81*86d7f5d3SJohn Marino /* Update things */ 82*86d7f5d3SJohn Marino int lvmcache_update_vgname_and_id(struct lvmcache_info *info, 83*86d7f5d3SJohn Marino const char *vgname, const char *vgid, 84*86d7f5d3SJohn Marino uint32_t vgstatus, const char *hostname); 85*86d7f5d3SJohn Marino int lvmcache_update_vg(struct volume_group *vg, unsigned precommitted); 86*86d7f5d3SJohn Marino 87*86d7f5d3SJohn Marino void lvmcache_lock_vgname(const char *vgname, int read_only); 88*86d7f5d3SJohn Marino void lvmcache_unlock_vgname(const char *vgname); 89*86d7f5d3SJohn Marino int lvmcache_verify_lock_order(const char *vgname); 90*86d7f5d3SJohn Marino 91*86d7f5d3SJohn Marino /* Queries */ 92*86d7f5d3SJohn Marino const struct format_type *fmt_from_vgname(const char *vgname, const char *vgid); 93*86d7f5d3SJohn Marino struct lvmcache_vginfo *vginfo_from_vgname(const char *vgname, 94*86d7f5d3SJohn Marino const char *vgid); 95*86d7f5d3SJohn Marino struct lvmcache_vginfo *vginfo_from_vgid(const char *vgid); 96*86d7f5d3SJohn Marino struct lvmcache_info *info_from_pvid(const char *pvid, int valid_only); 97*86d7f5d3SJohn Marino const char *vgname_from_vgid(struct dm_pool *mem, const char *vgid); 98*86d7f5d3SJohn Marino struct device *device_from_pvid(struct cmd_context *cmd, struct id *pvid); 99*86d7f5d3SJohn Marino int vgs_locked(void); 100*86d7f5d3SJohn Marino int vgname_is_locked(const char *vgname); 101*86d7f5d3SJohn Marino 102*86d7f5d3SJohn Marino /* Returns list of struct str_lists containing pool-allocated copy of vgnames */ 103*86d7f5d3SJohn Marino /* Set full_scan to 1 to reread every filtered device label */ 104*86d7f5d3SJohn Marino struct dm_list *lvmcache_get_vgnames(struct cmd_context *cmd, int full_scan); 105*86d7f5d3SJohn Marino 106*86d7f5d3SJohn Marino /* Returns list of struct str_lists containing pool-allocated copy of vgids */ 107*86d7f5d3SJohn Marino /* Set full_scan to 1 to reread every filtered device label */ 108*86d7f5d3SJohn Marino struct dm_list *lvmcache_get_vgids(struct cmd_context *cmd, int full_scan); 109*86d7f5d3SJohn Marino 110*86d7f5d3SJohn Marino /* Returns list of struct str_lists containing pool-allocated copy of pvids */ 111*86d7f5d3SJohn Marino struct dm_list *lvmcache_get_pvids(struct cmd_context *cmd, const char *vgname, 112*86d7f5d3SJohn Marino const char *vgid); 113*86d7f5d3SJohn Marino 114*86d7f5d3SJohn Marino /* Returns cached volume group metadata. */ 115*86d7f5d3SJohn Marino struct volume_group *lvmcache_get_vg(const char *vgid, unsigned precommitted); 116*86d7f5d3SJohn Marino void lvmcache_drop_metadata(const char *vgname); 117*86d7f5d3SJohn Marino 118*86d7f5d3SJohn Marino #endif 119