mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-20 18:09:23 +03:00
e8bbcda2a3
The lv_layout and lv_type fields together help with LV identification. We can do basic identification using the lv_attr field which provides very condensed view. In contrast to that, the new lv_layout and lv_type fields provide more detialed information on exact layout and type used for LVs. For top-level LVs which are pure types not combined with any other LV types, the lv_layout value is equal to lv_type value. For non-top-level LVs which may be combined with other types, the lv_layout describes the underlying layout used, while the lv_type describes the use/type/usage of the LV. These two new fields are both string lists so selection (-S/--select) criteria can be defined using the list operators easily: [] for strict matching {} for subset matching. For example, let's consider this: $ lvs -a -o name,vg_name,lv_attr,layout,type LV VG Attr Layout Type [lvol1_pmspare] vg ewi------- linear metadata,pool,spare pool vg twi-a-tz-- pool,thin pool,thin [pool_tdata] vg rwi-aor--- level10,raid data,pool,thin [pool_tdata_rimage_0] vg iwi-aor--- linear image,raid [pool_tdata_rimage_1] vg iwi-aor--- linear image,raid [pool_tdata_rimage_2] vg iwi-aor--- linear image,raid [pool_tdata_rimage_3] vg iwi-aor--- linear image,raid [pool_tdata_rmeta_0] vg ewi-aor--- linear metadata,raid [pool_tdata_rmeta_1] vg ewi-aor--- linear metadata,raid [pool_tdata_rmeta_2] vg ewi-aor--- linear metadata,raid [pool_tdata_rmeta_3] vg ewi-aor--- linear metadata,raid [pool_tmeta] vg ewi-aor--- level1,raid metadata,pool,thin [pool_tmeta_rimage_0] vg iwi-aor--- linear image,raid [pool_tmeta_rimage_1] vg iwi-aor--- linear image,raid [pool_tmeta_rmeta_0] vg ewi-aor--- linear metadata,raid [pool_tmeta_rmeta_1] vg ewi-aor--- linear metadata,raid thin_snap1 vg Vwi---tz-k thin snapshot,thin thin_snap2 vg Vwi---tz-k thin snapshot,thin thin_vol1 vg Vwi-a-tz-- thin thin thin_vol2 vg Vwi-a-tz-- thin multiple,origin,thin Which is a situation with thin pool, thin volumes and thin snapshots. We can see internal 'pool_tdata' volume that makes up thin pool has actually a level10 raid layout and the internal 'pool_tmeta' has level1 raid layout. Also, we can see that 'thin_snap1' and 'thin_snap2' are both thin snapshots while 'thin_vol1' is thin origin (having multiple snapshots). Such reporting scheme provides much better base for selection criteria in addition to providing more detailed information, for example: $ lvs -a -o name,vg_name,lv_attr,layout,type -S 'type=metadata' LV VG Attr Layout Type [lvol1_pmspare] vg ewi------- linear metadata,pool,spare [pool_tdata_rmeta_0] vg ewi-aor--- linear metadata,raid [pool_tdata_rmeta_1] vg ewi-aor--- linear metadata,raid [pool_tdata_rmeta_2] vg ewi-aor--- linear metadata,raid [pool_tdata_rmeta_3] vg ewi-aor--- linear metadata,raid [pool_tmeta] vg ewi-aor--- level1,raid metadata,pool,thin [pool_tmeta_rmeta_0] vg ewi-aor--- linear metadata,raid [pool_tmeta_rmeta_1] vg ewi-aor--- linear metadata,raid (selected all LVs which are related to metadata of any type) lvs -a -o name,vg_name,lv_attr,layout,type -S 'type={metadata,thin}' LV VG Attr Layout Type [pool_tmeta] vg ewi-aor--- level1,raid metadata,pool,thin (selected all LVs which hold metadata related to thin) lvs -a -o name,vg_name,lv_attr,layout,type -S 'type={thin,snapshot}' LV VG Attr Layout Type thin_snap1 vg Vwi---tz-k thin snapshot,thin thin_snap2 vg Vwi---tz-k thin snapshot,thin (selected all LVs which are thin snapshots) lvs -a -o name,vg_name,lv_attr,layout,type -S 'layout=raid' LV VG Attr Layout Type [pool_tdata] vg rwi-aor--- level10,raid data,pool,thin [pool_tmeta] vg ewi-aor--- level1,raid metadata,pool,thin (selected all LVs with raid layout, any raid layout) lvs -a -o name,vg_name,lv_attr,layout,type -S 'layout={raid,level1}' LV VG Attr Layout Type [pool_tmeta] vg ewi-aor--- level1,raid metadata,pool,thin (selected all LVs with raid level1 layout exactly) And so on...
133 lines
2.7 KiB
C
133 lines
2.7 KiB
C
/*
|
|
* Copyright (C) 2003-2004 Sistina Software, Inc. All rights reserved.
|
|
* Copyright (C) 2004-2012 Red Hat, Inc. All rights reserved.
|
|
*
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include "lib.h"
|
|
#include "str_list.h"
|
|
|
|
struct dm_list *str_list_create(struct dm_pool *mem)
|
|
{
|
|
struct dm_list *sl;
|
|
|
|
if (!(sl = dm_pool_alloc(mem, sizeof(struct dm_list)))) {
|
|
log_errno(ENOMEM, "str_list allocation failed");
|
|
return NULL;
|
|
}
|
|
|
|
dm_list_init(sl);
|
|
|
|
return sl;
|
|
}
|
|
|
|
int str_list_add_no_dup_check(struct dm_pool *mem, struct dm_list *sll, const char *str)
|
|
{
|
|
struct dm_str_list *sln;
|
|
|
|
if (!str)
|
|
return_0;
|
|
|
|
if (!(sln = dm_pool_alloc(mem, sizeof(*sln))))
|
|
return_0;
|
|
|
|
sln->str = str;
|
|
dm_list_add(sll, &sln->list);
|
|
|
|
return 1;
|
|
}
|
|
|
|
int str_list_add(struct dm_pool *mem, struct dm_list *sll, const char *str)
|
|
{
|
|
if (!str)
|
|
return_0;
|
|
|
|
/* Already in list? */
|
|
if (str_list_match_item(sll, str))
|
|
return 1;
|
|
|
|
return str_list_add_no_dup_check(mem, sll, str);
|
|
}
|
|
|
|
void str_list_del(struct dm_list *sll, const char *str)
|
|
{
|
|
struct dm_list *slh, *slht;
|
|
|
|
dm_list_iterate_safe(slh, slht, sll)
|
|
if (!strcmp(str, dm_list_item(slh, struct dm_str_list)->str))
|
|
dm_list_del(slh);
|
|
}
|
|
|
|
int str_list_dup(struct dm_pool *mem, struct dm_list *sllnew,
|
|
const struct dm_list *sllold)
|
|
{
|
|
struct dm_str_list *sl;
|
|
|
|
dm_list_init(sllnew);
|
|
|
|
dm_list_iterate_items(sl, sllold) {
|
|
if (!str_list_add(mem, sllnew, dm_pool_strdup(mem, sl->str)))
|
|
return_0;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
/*
|
|
* Is item on list?
|
|
*/
|
|
int str_list_match_item(const struct dm_list *sll, const char *str)
|
|
{
|
|
struct dm_str_list *sl;
|
|
|
|
dm_list_iterate_items(sl, sll)
|
|
if (!strcmp(str, sl->str))
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Is at least one item on both lists?
|
|
* If tag_matched is non-NULL, it is set to the tag that matched.
|
|
*/
|
|
int str_list_match_list(const struct dm_list *sll, const struct dm_list *sll2, const char **tag_matched)
|
|
{
|
|
struct dm_str_list *sl;
|
|
|
|
dm_list_iterate_items(sl, sll)
|
|
if (str_list_match_item(sll2, sl->str)) {
|
|
if (tag_matched)
|
|
*tag_matched = sl->str;
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Do both lists contain the same set of items?
|
|
*/
|
|
int str_list_lists_equal(const struct dm_list *sll, const struct dm_list *sll2)
|
|
{
|
|
struct dm_str_list *sl;
|
|
|
|
if (dm_list_size(sll) != dm_list_size(sll2))
|
|
return 0;
|
|
|
|
dm_list_iterate_items(sl, sll)
|
|
if (!str_list_match_item(sll2, sl->str))
|
|
return 0;
|
|
|
|
return 1;
|
|
}
|