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