2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2006 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
18 #include "import-export.h"
19 #include "lvm-string.h"
22 * Bitsets held in the 'status' flags get
23 * converted into arrays of strings.
27 const char *description;
31 static const struct flag _vg_flags[] = {
32 {EXPORTED_VG, "EXPORTED", STATUS_FLAG},
33 {RESIZEABLE_VG, "RESIZEABLE", STATUS_FLAG},
34 {PVMOVE, "PVMOVE", STATUS_FLAG},
35 {LVM_READ, "READ", STATUS_FLAG},
36 {LVM_WRITE, "WRITE", STATUS_FLAG},
37 {CLUSTERED, "CLUSTERED", STATUS_FLAG},
38 {SHARED, "SHARED", STATUS_FLAG},
39 {PARTIAL_VG, NULL, 0},
40 {PRECOMMITTED, NULL, 0},
44 static const struct flag _pv_flags[] = {
45 {ALLOCATABLE_PV, "ALLOCATABLE", STATUS_FLAG},
46 {EXPORTED_VG, "EXPORTED", STATUS_FLAG},
47 {MISSING_PV, "MISSING", COMPATIBLE_FLAG},
51 static const struct flag _lv_flags[] = {
52 {LVM_READ, "READ", STATUS_FLAG},
53 {LVM_WRITE, "WRITE", STATUS_FLAG},
54 {FIXED_MINOR, "FIXED_MINOR", STATUS_FLAG},
55 {VISIBLE_LV, "VISIBLE", STATUS_FLAG},
56 {PVMOVE, "PVMOVE", STATUS_FLAG},
57 {LOCKED, "LOCKED", STATUS_FLAG},
58 {MIRROR_NOTSYNCED, "NOTSYNCED", STATUS_FLAG},
59 {MIRROR_IMAGE, NULL, 0},
60 {MIRROR_LOG, NULL, 0},
65 {ACTIVATE_EXCL, NULL, 0},
66 {CONVERTING, NULL, 0},
67 {PARTIAL_LV, NULL, 0},
68 {POSTORDER_FLAG, NULL, 0},
69 {VIRTUAL_ORIGIN, NULL, 0},
70 {REPLICATOR, NULL, 0},
71 {REPLICATOR_LOG, NULL, 0},
75 static const struct flag *_get_flags(int type)
77 switch (type & ~STATUS_FLAG) {
88 log_error("Unknown flag set requested.");
93 * Converts a bitset to an array of string values,
94 * using one of the tables defined at the top of
97 int print_flags(uint64_t status, int type, char *buffer, size_t size)
100 const struct flag *flags;
102 if (!(flags = _get_flags(type)))
105 if (!emit_to_buffer(&buffer, &size, "["))
108 for (f = 0; flags[f].mask; f++) {
109 if (status & flags[f].mask) {
110 status &= ~flags[f].mask;
112 if ((type & STATUS_FLAG) != flags[f].kind)
115 /* Internal-only flag? */
116 if (!flags[f].description)
120 if (!emit_to_buffer(&buffer, &size, ", "))
125 if (!emit_to_buffer(&buffer, &size, "\"%s\"",
126 flags[f].description))
131 if (!emit_to_buffer(&buffer, &size, "]"))
135 log_error("Metadata inconsistency: Not all flags successfully "
141 int read_flags(uint64_t *status, int type, const struct config_value *cv)
144 uint64_t s = UINT64_C(0);
145 const struct flag *flags;
147 if (!(flags = _get_flags(type)))
150 if (cv->type == CFG_EMPTY_ARRAY)
154 if (cv->type != CFG_STRING) {
155 log_error("Status value is not a string.");
159 for (f = 0; flags[f].description; f++)
160 if (!strcmp(flags[f].description, cv->v.str)) {
165 if (type == VG_FLAGS && !strcmp(cv->v.str, "PARTIAL")) {
167 * Exception: We no longer write this flag out, but it
168 * might be encountered in old backup files, so restore
169 * it in that case. It is never part of live metadata
170 * though, so only vgcfgrestore needs to be concerned
174 } else if (!flags[f].description && (type & STATUS_FLAG)) {
175 log_error("Unknown status flag '%s'.", cv->v.str);