1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

writecache: use dm suffixes and lv attributes

- use internal CACHE_VOL flag on cachevol LV
- add suffixes to dm uuids for internal LVs
- display appropriate letters in the LV attr field
- display writecache's cachevol in lvs output
This commit is contained in:
David Teigland 2019-09-20 14:04:18 -05:00
parent 6f355c6736
commit 6f7d7089b4
6 changed files with 46 additions and 14 deletions

View File

@ -716,6 +716,9 @@ struct logical_volume *lv_pool_lv(const struct logical_volume *lv)
if (lv_is_vdo(lv)) if (lv_is_vdo(lv))
return seg_lv(first_seg(lv), 0); return seg_lv(first_seg(lv), 0);
if (lv_is_writecache(lv))
return first_seg(lv)->writecache;
return NULL; return NULL;
} }
@ -1235,7 +1238,7 @@ char *lv_attr_dup_with_info_and_seg_status(struct dm_pool *mem, const struct lv_
repstr[0] = 'l'; repstr[0] = 'l';
else if (lv_is_cow(lv)) else if (lv_is_cow(lv))
repstr[0] = (lv_is_merging_cow(lv)) ? 'S' : 's'; repstr[0] = (lv_is_merging_cow(lv)) ? 'S' : 's';
else if (lv_is_cache_origin(lv)) else if (lv_is_cache_origin(lv) || lv_is_writecache_origin(lv))
repstr[0] = 'o'; repstr[0] = 'o';
else else
repstr[0] = '-'; repstr[0] = '-';
@ -1314,7 +1317,12 @@ char *lv_attr_dup_with_info_and_seg_status(struct dm_pool *mem, const struct lv_
if (lv_is_thin_pool(lv) || lv_is_thin_volume(lv)) if (lv_is_thin_pool(lv) || lv_is_thin_volume(lv))
repstr[6] = 't'; repstr[6] = 't';
else if (lv_is_cache_pool(lv) || lv_is_cache_vol(lv) || lv_is_cache(lv) || lv_is_cache_origin(lv)) else if (lv_is_cache_pool(lv) ||
lv_is_cache_vol(lv) ||
lv_is_cache(lv) ||
lv_is_cache_origin(lv) ||
lv_is_writecache(lv) ||
lv_is_writecache_origin(lv))
repstr[6] = 'C'; repstr[6] = 'C';
else if (lv_is_raid_type(lv)) else if (lv_is_raid_type(lv))
repstr[6] = 'r'; repstr[6] = 'r';

View File

@ -269,16 +269,19 @@
#define lv_is_removed(lv) (((lv)->status & LV_REMOVED) ? 1 : 0) #define lv_is_removed(lv) (((lv)->status & LV_REMOVED) ? 1 : 0)
/* Recognize component LV (matching lib/misc/lvm-string.c _lvname_has_reserved_component_string()) */ /* Recognize component LV (matching lib/misc/lvm-string.c _lvname_has_reserved_component_string()) */
#define lv_is_component(lv) (lv_is_cache_origin(lv) || ((lv)->status & (\ #define lv_is_component(lv) (lv_is_cache_origin(lv) || \
CACHE_POOL_DATA |\ lv_is_writecache_origin(lv) || \
CACHE_POOL_METADATA |\ ((lv)->status & (\
LV_VDO_POOL_DATA |\ CACHE_POOL_DATA |\
MIRROR_IMAGE |\ CACHE_POOL_METADATA |\
MIRROR_LOG |\ LV_CACHE_VOL |\
RAID_IMAGE |\ LV_VDO_POOL_DATA |\
RAID_META |\ MIRROR_IMAGE |\
THIN_POOL_DATA |\ MIRROR_LOG |\
THIN_POOL_METADATA)) ? 1 : 0) RAID_IMAGE |\
RAID_META |\
THIN_POOL_DATA |\
THIN_POOL_METADATA)) ? 1 : 0)
int lv_layout_and_role(struct dm_pool *mem, const struct logical_volume *lv, int lv_layout_and_role(struct dm_pool *mem, const struct logical_volume *lv,
struct dm_list **layout, struct dm_list **role); struct dm_list **layout, struct dm_list **role);
@ -1077,6 +1080,7 @@ int lv_is_cow(const struct logical_volume *lv);
#define lv_is_thick_snapshot lv_is_cow #define lv_is_thick_snapshot lv_is_cow
int lv_is_cache_origin(const struct logical_volume *lv); int lv_is_cache_origin(const struct logical_volume *lv);
int lv_is_writecache_origin(const struct logical_volume *lv);
int lv_is_merging_cow(const struct logical_volume *cow); int lv_is_merging_cow(const struct logical_volume *cow);
uint32_t cow_max_extents(const struct logical_volume *origin, uint32_t chunk_size); uint32_t cow_max_extents(const struct logical_volume *origin, uint32_t chunk_size);

View File

@ -5166,3 +5166,17 @@ struct volume_group *vg_read_for_update(struct cmd_context *cmd, const char *vg_
return vg; return vg;
} }
int lv_is_writecache_origin(const struct logical_volume *lv)
{
struct seg_list *sl;
dm_list_iterate_items(sl, &lv->segs_using_this_lv) {
if (!sl->seg || !sl->seg->lv || !sl->seg->origin)
continue;
if (lv_is_writecache(sl->seg->lv) && (sl->seg->origin == lv))
return 1;
}
return 0;
}

View File

@ -158,6 +158,7 @@ static const char *_lvname_has_reserved_component_string(const char *lvname)
"_cmeta", "_cmeta",
"_corig", "_corig",
"_cvol", "_cvol",
"_wcorig",
"_mimage", "_mimage",
"_mlog", "_mlog",
"_rimage", "_rimage",
@ -249,6 +250,7 @@ char *build_dm_uuid(struct dm_pool *mem, const struct logical_volume *lv,
*/ */
/* Suffixes used here MUST match lib/activate/dev_manager.c */ /* Suffixes used here MUST match lib/activate/dev_manager.c */
layer = lv_is_cache_origin(lv) ? "real" : layer = lv_is_cache_origin(lv) ? "real" :
lv_is_writecache_origin(lv) ? "real" :
(lv_is_cache(lv) && lv_is_pending_delete(lv)) ? "real" : (lv_is_cache(lv) && lv_is_pending_delete(lv)) ? "real" :
lv_is_cache_pool_data(lv) ? "cdata" : lv_is_cache_pool_data(lv) ? "cdata" :
lv_is_cache_pool_metadata(lv) ? "cmeta" : lv_is_cache_pool_metadata(lv) ? "cmeta" :

View File

@ -260,10 +260,10 @@ static int _writecache_add_target_line(struct dev_manager *dm,
if ((pmem = lv_on_pmem(seg->writecache)) < 0) if ((pmem = lv_on_pmem(seg->writecache)) < 0)
return_0; return_0;
if (!(origin_uuid = build_dm_uuid(mem, seg_lv(seg, 0), NULL))) if (!(origin_uuid = build_dm_uuid(mem, seg_lv(seg, 0), "real")))
return_0; return_0;
if (!(fast_uuid = build_dm_uuid(mem, seg->writecache, NULL))) if (!(fast_uuid = build_dm_uuid(mem, seg->writecache, "cvol")))
return_0; return_0;
if (!dm_tree_node_add_writecache_target(node, len, if (!dm_tree_node_add_writecache_target(node, len,

View File

@ -5230,6 +5230,8 @@ static int _lv_writecache_detach(struct cmd_context *cmd, struct logical_volume
lv->status &= ~WRITECACHE; lv->status &= ~WRITECACHE;
seg->writecache = NULL; seg->writecache = NULL;
lv_fast->status &= ~LV_CACHE_VOL;
if (!remove_layer_from_lv(lv, origin)) if (!remove_layer_from_lv(lv, origin))
return_0; return_0;
@ -5646,6 +5648,8 @@ static int _lvconvert_writecache_attach_single(struct cmd_context *cmd,
if (!archive(vg)) if (!archive(vg))
goto_bad; goto_bad;
lv_fast->status |= LV_CACHE_VOL;
/* /*
* TODO: use libblkid to get the sector size of lv. If it doesn't * TODO: use libblkid to get the sector size of lv. If it doesn't
* match the block_size we are using for the writecache, then warn that * match the block_size we are using for the writecache, then warn that