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

cache: add wipe_cache_pool

Add function for wiping cache pool volume.
Only unused cache-pool could be wiped.
This commit is contained in:
Zdenek Kabelac 2014-11-02 18:36:41 +01:00
parent 0b7335f847
commit d2e9802ba7
2 changed files with 42 additions and 0 deletions

View File

@ -369,3 +369,44 @@ int lv_is_cache_origin(const struct logical_volume *lv)
seg = get_only_segment_using_this_lv(lv); seg = get_only_segment_using_this_lv(lv);
return seg && lv_is_cache(seg->lv) && (seg_lv(seg, 0) == lv); return seg && lv_is_cache(seg->lv) && (seg_lv(seg, 0) == lv);
} }
/*
* Wipe cache pool metadata area before use.
*
* Activates metadata volume as 'cache-pool' so regular wiping
* of existing visible volume may proceed.
*/
int wipe_cache_pool(struct logical_volume *cache_pool_lv)
{
int r;
/* Only unused cache-pool could be activated and wiped */
if (!lv_is_cache_pool(cache_pool_lv) ||
!dm_list_empty(&cache_pool_lv->segs_using_this_lv)) {
log_error(INTERNAL_ERROR "Failed to wipe cache pool for volume %s.",
display_lvname(cache_pool_lv));
return 0;
}
cache_pool_lv->status |= LV_TEMPORARY;
if (!activate_lv_local(cache_pool_lv->vg->cmd, cache_pool_lv)) {
log_error("Aborting. Failed to activate cache pool %s.",
display_lvname(cache_pool_lv));
return 0;
}
cache_pool_lv->status &= ~LV_TEMPORARY;
if (!(r = wipe_lv(cache_pool_lv, (struct wipe_params) { .do_zero = 1 }))) {
log_error("Aborting. Failed to wipe cache pool %s.",
display_lvname(cache_pool_lv));
/* Delay return of error after deactivation */
}
/* Deactivate cleared cache-pool metadata */
if (!deactivate_lv(cache_pool_lv->vg->cmd, cache_pool_lv)) {
log_error("Aborting. Could not deactivate cache pool %s.",
display_lvname(cache_pool_lv));
r = 0;
}
return r;
}

View File

@ -1099,6 +1099,7 @@ struct logical_volume *lv_cache_create(struct logical_volume *pool,
struct logical_volume *origin); struct logical_volume *origin);
int lv_cache_remove(struct logical_volume *cache_lv); int lv_cache_remove(struct logical_volume *cache_lv);
int get_cache_mode(const char *str, uint32_t *flags); int get_cache_mode(const char *str, uint32_t *flags);
int wipe_cache_pool(struct logical_volume *cache_pool_lv);
/* -- metadata/cache_manip.c */ /* -- metadata/cache_manip.c */
struct cmd_vg *cmd_vg_add(struct dm_pool *mem, struct dm_list *cmd_vgs, struct cmd_vg *cmd_vg_add(struct dm_pool *mem, struct dm_list *cmd_vgs,