4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
7 * This file is part of LVM2.
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.
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
20 #include "import-export.h"
21 #include "lvm-string.h"
24 * Bitsets held in the 'status' flags get
25 * converted into arrays of strings.
29 const char *description
;
33 static struct flag _vg_flags
[] = {
34 {EXPORTED_VG
, "EXPORTED", STATUS_FLAG
},
35 {RESIZEABLE_VG
, "RESIZEABLE", STATUS_FLAG
},
36 {PVMOVE
, "PVMOVE", STATUS_FLAG
},
37 {LVM_READ
, "READ", STATUS_FLAG
},
38 {LVM_WRITE
, "WRITE", STATUS_FLAG
},
39 {CLUSTERED
, "CLUSTERED", STATUS_FLAG
},
40 {SHARED
, "SHARED", STATUS_FLAG
},
41 {PARTIAL_VG
, NULL
, 0},
42 {PRECOMMITTED
, NULL
, 0},
46 static struct flag _pv_flags
[] = {
47 {ALLOCATABLE_PV
, "ALLOCATABLE", STATUS_FLAG
},
48 {EXPORTED_VG
, "EXPORTED", STATUS_FLAG
},
49 {MISSING_PV
, "MISSING", COMPATIBLE_FLAG
},
53 static struct flag _lv_flags
[] = {
54 {LVM_READ
, "READ", STATUS_FLAG
},
55 {LVM_WRITE
, "WRITE", STATUS_FLAG
},
56 {FIXED_MINOR
, "FIXED_MINOR", STATUS_FLAG
},
57 {VISIBLE_LV
, "VISIBLE", STATUS_FLAG
},
58 {PVMOVE
, "PVMOVE", STATUS_FLAG
},
59 {LOCKED
, "LOCKED", STATUS_FLAG
},
60 {MIRROR_NOTSYNCED
, "NOTSYNCED", STATUS_FLAG
},
61 {MIRROR_IMAGE
, NULL
, 0},
62 {MIRROR_LOG
, NULL
, 0},
66 {ACTIVATE_EXCL
, NULL
, 0},
67 {CONVERTING
, NULL
, 0},
68 {PARTIAL_LV
, NULL
, 0},
69 {POSTORDER_FLAG
, NULL
, 0},
70 {VIRTUAL_ORIGIN
, NULL
, 0},
74 static struct flag
*_get_flags(int type
)
76 switch (type
& ~STATUS_FLAG
) {
87 log_error("Unknown flag set requested.");
92 * Converts a bitset to an array of string values,
93 * using one of the tables defined at the top of
96 int print_flags(uint32_t status
, int type
, char *buffer
, size_t size
)
101 if (!(flags
= _get_flags(type
)))
104 if (!emit_to_buffer(&buffer
, &size
, "["))
107 for (f
= 0; flags
[f
].mask
; f
++) {
108 if (status
& flags
[f
].mask
) {
109 status
&= ~flags
[f
].mask
;
111 if ((type
& STATUS_FLAG
) != flags
[f
].kind
)
114 /* Internal-only flag? */
115 if (!flags
[f
].description
)
119 if (!emit_to_buffer(&buffer
, &size
, ", "))
124 if (!emit_to_buffer(&buffer
, &size
, "\"%s\"",
125 flags
[f
].description
))
130 if (!emit_to_buffer(&buffer
, &size
, "]"))
134 log_error("Metadata inconsistency: Not all flags successfully "
140 int read_flags(uint32_t *status
, int type
, struct config_value
*cv
)
146 if (!(flags
= _get_flags(type
)))
149 if (cv
->type
== CFG_EMPTY_ARRAY
)
153 if (cv
->type
!= CFG_STRING
) {
154 log_error("Status value is not a string.");
158 for (f
= 0; flags
[f
].description
; f
++)
159 if (!strcmp(flags
[f
].description
, cv
->v
.str
)) {
164 if (type
== VG_FLAGS
&& !strcmp(cv
->v
.str
, "PARTIAL")) {
166 * Exception: We no longer write this flag out, but it
167 * might be encountered in old backup files, so restore
168 * it in that case. It is never part of live metadata
169 * though, so only vgcfgrestore needs to be concerned
173 } else if (!flags
[f
].description
&& (type
& STATUS_FLAG
)) {
174 log_error("Unknown status flag '%s'.", cv
->v
.str
);