1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

lv_prop: simplier macro usage

Use more simple macros - as there is likely not going to happen
any macro replacement - so use more effient structure layout.
This commit is contained in:
Zdenek Kabelac 2024-05-13 01:01:18 +02:00
parent f86bdcb6e9
commit 429ab45a1c
5 changed files with 61 additions and 58 deletions

View File

@ -55,7 +55,8 @@ static const struct opt_name opt_names[ARG_COUNT + 1] = {
/* create table of lv property names, e.g. lv_is_foo, and corresponding enum from lv_props.h */
static const struct lv_prop lv_props[LVP_COUNT + 1] = {
#define lvp(a, b, c) { # a, a, b, c },
{ "" },
#define lvp(a) { "lv_" # a, a ## _LVP },
#include "lv_props.h"
#undef lvp
};

View File

@ -249,10 +249,8 @@ struct val_name {
/* see global lv_props[] */
struct lv_prop {
const char enum_name[30]; /* "is_foo_LVP" */
const char name[30]; /* "lv_is_foo" */
uint16_t lvp_enum; /* is_foo_LVP */
const char name[32]; /* "lv_is_foo" */
int (*fn) (struct cmd_context *cmd, struct logical_volume *lv); /* lv_is_foo() */
};
/* see global lv_types[] */

View File

@ -37,9 +37,11 @@ enum {
/* define enums for LV properties, foo_LVP */
enum {
#define lvp(a, b, c) a ,
LVP_NONE,
#define lvp(a) a ## _LVP ,
#include "lv_props.h"
#undef lvp
LVP_COUNT
};
/* define enums for LV types, foo_LVT */

View File

@ -1,62 +1,67 @@
/*
* NULL in the last arg can be replaced with actual
* calls to the lv_is_prop() function when those
* become functions (are #define now), take uniform
* args (e.g. some take cmd others don't), and are
* exposed in tools.h
* Copyright (C) 2016-2024 Red Hat, Inc. All rights reserved.
*
* Until then, the lv_is_prop() functions are
* called indirectly through _lv_is_prop().
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v.2.1.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
lvp(LVP_NONE, "", NULL) /* enum value 0 means none */
lvp(is_locked_LVP, "lv_is_locked", NULL)
lvp(is_partial_LVP, "lv_is_partial", NULL)
lvp(is_virtual_LVP, "lv_is_virtual", NULL)
lvp(is_merging_LVP, "lv_is_merging", NULL)
lvp(is_merging_origin_LVP, "lv_is_merging_origin", NULL)
lvp(is_converting_LVP, "lv_is_converting", NULL)
lvp(is_external_origin_LVP, "lv_is_external_origin", NULL)
lvp(is_virtual_origin_LVP, "lv_is_virtual_origin", NULL)
lvp(is_not_synced_LVP, "lv_is_not_synced", NULL)
lvp(is_pending_delete_LVP, "lv_is_pending_delete", NULL)
lvp(is_error_when_full_LVP, "lv_is_error_when_full", NULL)
lvp(is_pvmove_LVP, "lv_is_pvmove", NULL)
lvp(is_removed_LVP, "lv_is_removed", NULL)
lvp(is_vg_writable_LVP, "lv_is_vg_writable", NULL)
lvp(is_writable_LVP, "lv_is_writable", NULL)
/*
* Update toollib.c:_lv_is_prop() when adding
* new is_XXXXX_LVP test
*/
/* enum value 0 means none */
lvp(is_locked)
lvp(is_partial)
lvp(is_virtual)
lvp(is_merging)
lvp(is_merging_origin)
lvp(is_converting)
lvp(is_external_origin)
lvp(is_virtual_origin)
lvp(is_not_synced)
lvp(is_pending_delete)
lvp(is_error_when_full)
lvp(is_pvmove)
lvp(is_removed)
lvp(is_vg_writable)
lvp(is_writable)
/* kinds of sub LV */
lvp(is_thinpool_data_LVP, "lv_is_thinpool_data", NULL)
lvp(is_thinpool_metadata_LVP, "lv_is_thinpool_metadata", NULL)
lvp(is_cachepool_data_LVP, "lv_is_cachepool_data", NULL)
lvp(is_cachepool_metadata_LVP, "lv_is_cachepool_metadata", NULL)
lvp(is_mirror_image_LVP, "lv_is_mirror_image", NULL)
lvp(is_mirror_log_LVP, "lv_is_mirror_log", NULL)
lvp(is_raid_image_LVP, "lv_is_raid_image", NULL)
lvp(is_raid_metadata_LVP, "lv_is_raid_metadata", NULL)
lvp(is_thinpool_data)
lvp(is_thinpool_metadata)
lvp(is_cachepool_data)
lvp(is_cachepool_metadata)
lvp(is_mirror_image)
lvp(is_mirror_log)
lvp(is_raid_image)
lvp(is_raid_metadata)
/*
* is_thick_origin should be used instead of is_origin
* is_thick_snapshot is generally used as LV_snapshot from lv_types.h
*/
lvp(is_origin_LVP, "lv_is_origin", NULL)
lvp(is_thick_origin_LVP, "lv_is_thick_origin", NULL)
lvp(is_thick_snapshot_LVP, "lv_is_thick_snapshot", NULL)
lvp(is_thin_origin_LVP, "lv_is_thin_origin", NULL)
lvp(is_thin_snapshot_LVP, "lv_is_thin_snapshot", NULL)
lvp(is_origin)
lvp(is_thick_origin)
lvp(is_thick_snapshot)
lvp(is_thin_origin)
lvp(is_thin_snapshot)
lvp(is_error_LVP, "lv_is_error", NULL)
lvp(is_zero_LVP, "lv_is_zero", NULL)
lvp(is_cache_origin_LVP, "lv_is_cache_origin", NULL)
lvp(is_cow_LVP, "lv_is_cow", NULL)
lvp(is_merging_cow_LVP, "lv_is_merging_cow", NULL)
lvp(is_cow_covering_origin_LVP, "lv_is_cow_covering_origin", NULL)
lvp(is_visible_LVP, "lv_is_visible", NULL)
lvp(is_historical_LVP, "lv_is_historical", NULL)
lvp(is_raid_with_tracking_LVP, "lv_is_raid_with_tracking", NULL)
lvp(is_raid_with_integrity_LVP, "lv_is_raid_with_integrity", NULL)
lvp(LVP_COUNT, "", NULL)
lvp(is_error)
lvp(is_zero)
lvp(is_cache_origin)
lvp(is_cow)
lvp(is_merging_cow)
lvp(is_cow_covering_origin)
lvp(is_visible)
lvp(is_historical)
lvp(is_raid_with_tracking)
lvp(is_raid_with_integrity)

View File

@ -2976,10 +2976,7 @@ static int _lv_props_match(struct cmd_context *cmd, struct logical_volume *lv, u
if (!(prop = get_lv_prop(lvp_enum)))
continue;
if (!prop->fn)
match = _lv_is_prop(cmd, lv, lvp_enum);
else
match = prop->fn(cmd, lv);
match = _lv_is_prop(cmd, lv, lvp_enum);
if (!match)
found_a_mismatch = 1;