mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
cleanup: separate type and mask
Split misused 'enum' into 2 fields - one for type of PV, VG, LV and other for mask.
This commit is contained in:
parent
8e0bc73eba
commit
966d1130db
@ -358,11 +358,12 @@ static int _print_header(struct cmd_context *cmd, struct formatter *f,
|
|||||||
static int _print_flag_config(struct formatter *f, uint64_t status, int type)
|
static int _print_flag_config(struct formatter *f, uint64_t status, int type)
|
||||||
{
|
{
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
if (!print_flags(status, type | STATUS_FLAG, buffer, sizeof(buffer)))
|
|
||||||
|
if (!print_flags(buffer, sizeof(buffer), type, STATUS_FLAG, status))
|
||||||
return_0;
|
return_0;
|
||||||
outf(f, "status = %s", buffer);
|
outf(f, "status = %s", buffer);
|
||||||
|
|
||||||
if (!print_flags(status, type, buffer, sizeof(buffer)))
|
if (!print_flags(buffer, sizeof(buffer), type, COMPATIBLE_FLAG, status))
|
||||||
return_0;
|
return_0;
|
||||||
outf(f, "flags = %s", buffer);
|
outf(f, "flags = %s", buffer);
|
||||||
|
|
||||||
|
@ -101,9 +101,9 @@ static const struct flag _lv_flags[] = {
|
|||||||
{0, NULL, 0}
|
{0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct flag *_get_flags(int type)
|
static const struct flag *_get_flags(enum pv_vg_lv_e type)
|
||||||
{
|
{
|
||||||
switch (type & ~STATUS_FLAG) {
|
switch (type) {
|
||||||
case VG_FLAGS:
|
case VG_FLAGS:
|
||||||
return _vg_flags;
|
return _vg_flags;
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ static const struct flag *_get_flags(int type)
|
|||||||
* using one of the tables defined at the top of
|
* using one of the tables defined at the top of
|
||||||
* the file.
|
* the file.
|
||||||
*/
|
*/
|
||||||
int print_flags(uint64_t status, int type, char *buffer, size_t size)
|
int print_flags(char *buffer, size_t size, enum pv_vg_lv_e type, int mask, uint64_t status)
|
||||||
{
|
{
|
||||||
int f, first = 1;
|
int f, first = 1;
|
||||||
const struct flag *flags;
|
const struct flag *flags;
|
||||||
@ -167,9 +167,9 @@ int print_flags(uint64_t status, int type, char *buffer, size_t size)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_flags(uint64_t *status, int type, const struct dm_config_value *cv)
|
int read_flags(uint64_t *status, enum pv_vg_lv_e type, int mask, const struct dm_config_value *cv)
|
||||||
{
|
{
|
||||||
int f;
|
unsigned f;
|
||||||
uint64_t s = UINT64_C(0);
|
uint64_t s = UINT64_C(0);
|
||||||
const struct flag *flags;
|
const struct flag *flags;
|
||||||
|
|
||||||
@ -186,7 +186,8 @@ int read_flags(uint64_t *status, int type, const struct dm_config_value *cv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (f = 0; flags[f].description; f++)
|
for (f = 0; flags[f].description; f++)
|
||||||
if (!strcmp(flags[f].description, cv->v.str)) {
|
if ((flags[f].kind & mask) &&
|
||||||
|
!strcmp(flags[f].description, cv->v.str)) {
|
||||||
s |= flags[f].mask;
|
s |= flags[f].mask;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -200,7 +201,7 @@ int read_flags(uint64_t *status, int type, const struct dm_config_value *cv)
|
|||||||
* by this case.
|
* by this case.
|
||||||
*/
|
*/
|
||||||
s |= PARTIAL_VG;
|
s |= PARTIAL_VG;
|
||||||
} else if (!flags[f].description && (type & STATUS_FLAG)) {
|
} else if (!flags[f].description && (mask & STATUS_FLAG)) {
|
||||||
log_error("Unknown status flag '%s'.", cv->v.str);
|
log_error("Unknown status flag '%s'.", cv->v.str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,15 @@
|
|||||||
* VGs, PVs and LVs all have status bitsets, we gather together
|
* VGs, PVs and LVs all have status bitsets, we gather together
|
||||||
* common code for reading and writing them.
|
* common code for reading and writing them.
|
||||||
*/
|
*/
|
||||||
enum {
|
enum pv_vg_lv_e {
|
||||||
COMPATIBLE_FLAG = 0x0,
|
PV_FLAGS = 1,
|
||||||
VG_FLAGS,
|
VG_FLAGS,
|
||||||
PV_FLAGS,
|
|
||||||
LV_FLAGS,
|
LV_FLAGS,
|
||||||
STATUS_FLAG = 0x8,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define COMPATIBLE_FLAG 0x01
|
||||||
|
#define STATUS_FLAG 0x02
|
||||||
|
|
||||||
struct text_vg_version_ops {
|
struct text_vg_version_ops {
|
||||||
int (*check_version) (const struct dm_config_tree * cf);
|
int (*check_version) (const struct dm_config_tree * cf);
|
||||||
struct volume_group *(*read_vg) (struct format_instance * fid,
|
struct volume_group *(*read_vg) (struct format_instance * fid,
|
||||||
@ -58,8 +59,8 @@ struct text_vg_version_ops {
|
|||||||
|
|
||||||
struct text_vg_version_ops *text_vg_vsn1_init(void);
|
struct text_vg_version_ops *text_vg_vsn1_init(void);
|
||||||
|
|
||||||
int print_flags(uint64_t status, int type, char *buffer, size_t size);
|
int print_flags(char *buffer, size_t size, enum pv_vg_lv_e type, int mask, uint64_t status);
|
||||||
int read_flags(uint64_t *status, int type, const struct dm_config_value *cv);
|
int read_flags(uint64_t *status, enum pv_vg_lv_e type, int mask, const struct dm_config_value *cv);
|
||||||
|
|
||||||
int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp);
|
int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp);
|
||||||
size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf);
|
size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf);
|
||||||
|
@ -140,13 +140,13 @@ static int _read_flag_config(const struct dm_config_node *n, uint64_t *status, i
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(read_flags(status, type | STATUS_FLAG, cv))) {
|
if (!(read_flags(status, type, STATUS_FLAG, cv))) {
|
||||||
log_error("Could not read status flags.");
|
log_error("Could not read status flags.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dm_config_get_list(n, "flags", &cv)) {
|
if (dm_config_get_list(n, "flags", &cv)) {
|
||||||
if (!(read_flags(status, type, cv))) {
|
if (!(read_flags(status, type, COMPATIBLE_FLAG, cv))) {
|
||||||
log_error("Could not read flags.");
|
log_error("Could not read flags.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user