stable-2.02 - thin: use lv_status_thin and lv_status_thin_pool
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0a825734161d2c90a5dfea091bf5e94e7002382a Commit: 0a825734161d2c90a5dfea091bf5e94e7002382a Parent: 45121aafe9f7623b7ca26678a9fa8ff659aaf1b0 Author: Zdenek Kabelac <[email protected]> AuthorDate: Sun Sep 27 01:11:47 2020 +0200 Committer: Zdenek Kabelac <[email protected]> CommitterDate: Fri Oct 16 18:09:54 2020 +0200
thin: use lv_status_thin and lv_status_thin_pool
Introduce structures lv_status_thin_pool and lv_status_thin (pair to lv_status_cache, lv_status_vdo)
Convert lv_thin_percent() -> lv_thin_status()
and lv_thin_pool_percent() + lv_thin_pool_transaction_id() -> lv_thin_pool_status().
This way a function user can see not only percentages, but also other important status info about thin-pool.
TODO:
This patch tries to not change too many other things, but pool_below_threshold() now uses new thin-pool info to return failure if thin-pool cannot be actually modified.
This should be handle separately in a better way.
--- lib/activate/activate.c | 83 ++++++++------------------- lib/activate/activate.h | 10 ++-- lib/activate/dev_manager.c | 118 +++++++++++++++++++++++++-------------- lib/activate/dev_manager.h | 16 ++---- lib/display/display.c | 22 +++++--- lib/metadata/lv_manip.c | 38 ++++++++----- lib/metadata/metadata-exported.h | 14 +++++ lib/metadata/thin_manip.c | 75 +++++++++++++++++++------ lib/report/properties.c | 60 ++++++++++++-------- 9 files changed, 255 insertions(+), 181 deletions(-)
lib/activate/activate.c +22 -61
@@ -285,18 +285,13 @@ int lv_raid_message(const struct logical_volume *lv, const char *msg) {return 0 ; } -int lv_thin_pool_percent (const struct logical_volume *lv,int metadata, -dm_percent_t *percent) +int lv_thin_pool_status (const struct logical_volume *lv,int flush, +struct lv_status_thin_pool **thin_pool_status) {return 0 ; } -int lv_thin_percent (const struct logical_volume *lv,int mapped, -dm_percent_t *percent) -{ -return 0 ; -} -int lv_thin_pool_transaction_id (const struct logical_volume *lv, -uint64_t *transaction_id) +int lv_thin_status (const struct logical_volume *lv,int flush, +struct lv_status_thin **thin_status) {return 0 ; }
@@ -1256,86 +1251,52 @@ int lv_cache_status(const struct logical_volume *cache_lv,return 1 ; } -/* -* Returns data or metadata percent usage, depends on metadata 0/1. -* Returns 1 if percent set, else 0 on failure. -*/ -int lv_thin_pool_percent (const struct logical_volume *lv,int metadata, -dm_percent_t *percent) +int lv_thin_pool_status (const struct logical_volume *lv,int flush, +struct lv_status_thin_pool **thin_pool_status) { -int r;struct dev_manager *dm;if (!lv_info (lv->vg->cmd, lv,1 ,NULL ,0 ,0 ))return 0 ; -log_debug_activation ("Checking thin %sdata percent for LV %s." , - (metadata) ?"meta" :"" ,display_lvname (lv)); +log_debug_activation ("Checking thin pool status for LV %s." , +display_lvname (lv));if (!(dm =dev_manager_create (lv->vg->cmd, lv->vg->name,1 ))) return_0; -if (!(r =dev_manager_thin_pool_percent (dm, lv, metadata, percent))) - stack; +if (!dev_manager_thin_pool_status (dm, lv, flush, thin_pool_status)) { +dev_manager_destroy (dm); + return_0; + } -dev_manager_destroy (dm); +/* User has to call dm_pool_destroy(thin_pool_status->mem)! */ -return r; +return 1 ; } -/* -* Returns 1 if percent set, else 0 on failure. -*/ -int lv_thin_percent (const struct logical_volume *lv, -int mapped,dm_percent_t *percent) +int lv_thin_status (const struct logical_volume *lv,int flush, +struct lv_status_thin **thin_status) { -int r;struct dev_manager *dm;if (!lv_info (lv->vg->cmd, lv,0 ,NULL ,0 ,0 ))return 0 ; -log_debug_activation ("Checking thin percent for LV %s." , +log_debug_activation ("Checking thin status for LV %s." ,display_lvname (lv));if (!(dm =dev_manager_create (lv->vg->cmd, lv->vg->name,1 ))) return_0; -if (!(r =dev_manager_thin_percent (dm, lv, mapped, percent))) - stack; - -dev_manager_destroy (dm); - -return r; -} - -/* -* Returns 1 if transaction_id set, else 0 on failure. -*/ -int lv_thin_pool_transaction_id (const struct logical_volume *lv, -uint64_t *transaction_id) -{ -int r; -struct dev_manager *dm; -struct dm_status_thin_pool *status; - -if (!lv_info (lv->vg->cmd, lv,1 ,NULL ,0 ,0 )) -return 0 ; - -log_debug_activation ("Checking thin-pool transaction id for LV %s." , -display_lvname (lv)); - -if (!(dm =dev_manager_create (lv->vg->cmd, lv->vg->name,1 ))) +if (!dev_manager_thin_status (dm, lv, flush, thin_status)) { +dev_manager_destroy (dm); return_0; + } -if (!(r =dev_manager_thin_pool_status (dm, lv, &status,0 ))) - stack; -else - *transaction_id = status->transaction_id; - -dev_manager_destroy (dm); +/* User has to call dm_pool_destroy(thin_status->mem)! */ -return r; +return 1 ; }int lv_thin_device_id (const struct logical_volume *lv,uint32_t *device_id)
lib/activate/activate.h +4 -6
@@ -178,13 +178,11 @@ int lv_raid_sync_action(const struct logical_volume *lv, char **sync_action);int lv_raid_message (const struct logical_volume *lv,const char *msg);int lv_cache_status (const struct logical_volume *cache_lv,struct lv_status_cache **status); -int lv_thin_pool_percent (const struct logical_volume *lv,int metadata, -dm_percent_t *percent); -int lv_thin_percent (const struct logical_volume *lv,int mapped, -dm_percent_t *percent); -int lv_thin_pool_transaction_id (const struct logical_volume *lv, -uint64_t *transaction_id);int lv_thin_device_id (const struct logical_volume *lv,uint32_t *device_id); +int lv_thin_status (const struct logical_volume *lv,int flush, +struct lv_status_thin **status); +int lv_thin_pool_status (const struct logical_volume *lv,int flush, +struct lv_status_thin_pool **status);/* * Return number of LVs in the VG that are active.
lib/activate/dev_manager.c +77 -41
167 lines not on this page · raw message
lib/activate/dev_manager.h +6 -10
@@ -66,19 +66,15 @@ int dev_manager_raid_message(struct dev_manager *dm,int dev_manager_cache_status (struct dev_manager *dm,const struct logical_volume *lv,struct lv_status_cache **status); -int dev_manager_thin_pool_status (struct dev_manager *dm, -const struct logical_volume *lv, -struct dm_status_thin_pool **status, -int flush); -int dev_manager_thin_pool_percent (struct dev_manager *dm, -const struct logical_volume *lv, -int metadata,dm_percent_t *percent); -int dev_manager_thin_percent (struct dev_manager *dm, -const struct logical_volume *lv, -int mapped,dm_percent_t *percent); +int dev_manager_thin_status (struct dev_manager *dm, +const struct logical_volume *lv,int flush, +struct lv_status_thin **status);int dev_manager_thin_device_id (struct dev_manager *dm,const struct logical_volume *lv,uint32_t *device_id); +int dev_manager_thin_pool_status (struct dev_manager *dm, +const struct logical_volume *lv,int flush, +struct lv_status_thin_pool **status);int dev_manager_suspend (struct dev_manager *dm,const struct logical_volume *lv,struct lv_activate_opts *laopts,int lockfs,int flush_required); int dev_manager_activate(struct dev_manager *dm, const struct logical_volume *lv,
lib/display/display.c +13 -9
@@ -406,10 +406,12 @@ int lvdisplay_full(struct cmd_context *cmd,struct lv_segment *seg =NULL ;int lvm1compat;dm_percent_t snap_percent; -int thin_data_active =0 , thin_metadata_active =0 ; +int thin_pool_active =0 ;dm_percent_t thin_data_percent, thin_metadata_percent;int thin_active =0 ;dm_percent_t thin_percent; +struct lv_status_thin *thin_status =NULL ; +struct lv_status_thin_pool *thin_pool_status =NULL ;struct lv_status_cache *cache_status =NULL ;if (lv_is_historical (lv))
@@ -502,15 +504,18 @@ int lvdisplay_full(struct cmd_context *cmd,if (seg->merge_lv)log_print ("LV merging to %s" , seg->merge_lv->name); -if (inkernel) - thin_active =lv_thin_percent (lv,0 , &thin_percent); +if (inkernel && (thin_active =lv_thin_status (lv,0 , &thin_status))) { + thin_percent = thin_status->usage; +dm_pool_destroy (thin_status->mem); + }if (lv_is_merging_origin (lv))log_print ("LV merged with %s" ,find_snapshot (lv)->lv->name); }else if (lv_is_thin_pool (lv)) { -if (lv_info (cmd, lv,1 , &info,1 ,1 ) && info.exists) { - thin_data_active =lv_thin_pool_percent (lv,0 , &thin_data_percent); - thin_metadata_active =lv_thin_pool_percent (lv,1 , &thin_metadata_percent); +if ((thin_pool_active =lv_thin_pool_status (lv,0 , &thin_pool_status))) { + thin_data_percent = thin_pool_status->data_usage; + thin_metadata_percent = thin_pool_status->metadata_usage; +dm_pool_destroy (thin_pool_status->mem); }/* FIXME: display thin_pool targets transid for activated LV as well */ seg =first_seg (lv);
@@ -569,13 +574,12 @@ int lvdisplay_full(struct cmd_context *cmd,dm_pool_destroy (cache_status->mem); } -if (thin_data_active) +if (thin_pool_active) {log_print ("Allocated pool data %s%%" ,display_percent (cmd, thin_data_percent)); - -if (thin_metadata_active)log_print ("Allocated metadata %s%%" ,display_percent (cmd, thin_metadata_percent)); + }if (thin_active) log_print("Mapped size %s%%",
lib/metadata/lv_manip.c +24 -14
@@ -4674,6 +4674,7 @@ static int _lvresize_adjust_policy(const struct logical_volume *lv,dm_percent_t percent;dm_percent_t min_threshold;int policy_threshold, policy_amount; +struct lv_status_thin_pool *thin_pool_status; *amount = *meta_amount =0 ;
@@ -4717,21 +4718,26 @@ static int _lvresize_adjust_policy(const struct logical_volume *lv, }if (lv_is_thin_pool (lv)) { -if (!lv_thin_pool_percent (lv,1 , &percent)) - return_0; +if (!lv_thin_pool_status (lv,0 , &thin_pool_status)) + goto_bad;/* Resize below the minimal usable value */ min_threshold =pool_metadata_min_threshold (first_seg (lv)) /DM_PERCENT_1 ; - *meta_amount =_adjust_amount (percent, (min_threshold < policy_threshold) ? + *meta_amount =_adjust_amount (thin_pool_status->metadata_usage, + (min_threshold < policy_threshold) ? min_threshold : policy_threshold, policy_amount);if (*meta_amount)/* Compensate possible extra space consumption by kernel on resize */ (*meta_amount)++; -if (!lv_thin_pool_percent (lv,0 , &percent)) - return_0; - }else { -if (!lv_snapshot_percent (lv, &percent)) - return_0; + percent = thin_pool_status->data_usage; +dm_pool_destroy (thin_pool_status->mem); + }else if (!lv_snapshot_percent (lv, &percent)) + goto_bad; +else if (!lv_is_active (lv)) { + bad: +log_error ("Can't read state of locally inactive LV %s." , +display_lvname (lv)); +return 0 ; } *amount =_adjust_amount (percent, policy_threshold, policy_amount);
@@ -7996,17 +8002,21 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,* and needs to be restored to the state from this canceled segment. * TODO: there is low chance actual suspend has failed */ -if (!lv_thin_pool_transaction_id (pool_lv, &transaction_id)) { +struct lv_status_thin_pool *tpstatus; +if (!lv_thin_pool_status (pool_lv,1 , &tpstatus))log_error ("Aborting. Failed to read transaction_id from thin pool %s." ,display_lvname (pool_lv));/* Can't even get thin pool transaction id ??? */ - }else if (transaction_id !=first_seg (pool_lv)->transaction_id) { -if (transaction_id == seg->transaction_id) -log_debug_metadata ("Reverting back transaction_id " FMTu64" for thin pool %s." , - seg->transaction_id,display_lvname (pool_lv)); -else +else { + transaction_id = tpstatus->thin_pool->transaction_id; +dm_pool_destroy (tpstatus->mem); + +if ((transaction_id !=first_seg (pool_lv)->transaction_id) && + (transaction_id != seg->transaction_id))log_warn ("WARNING: Metadata for thin pool %s have transaction_id " FMTu64", but active pool has " FMTu64"." ,display_lvname (pool_lv), seg->transaction_id, transaction_id); +log_debug_metadata ("Restoring previous transaction_id " FMTu64" for thin pool %s." , + seg->transaction_id,display_lvname (pool_lv));first_seg (pool_lv)->transaction_id = seg->transaction_id;first_seg (lv)->device_id =0 ;/* no delete of never existing thin device */ }
lib/metadata/metadata-exported.h +14 -0
@@ -861,6 +861,20 @@ int update_thin_pool_params(struct cmd_context *cmd,uint32_t *pool_metadata_extents, int *chunk_size_calc_method, uint32_t *chunk_size, thin_discards_t *discards, thin_zero_t *zero_new_blocks); + +struct lv_status_thin_pool { +struct dm_pool *mem; +struct dm_status_thin_pool *thin_pool; +dm_percent_t data_usage; +dm_percent_t metadata_usage; +}; + +struct lv_status_thin { +struct dm_pool *mem; +struct dm_status_thin *thin; +dm_percent_t usage; +}; +const char *get_pool_discards_name (thin_discards_t discards);int set_pool_discards (thin_discards_t *discards,const char *str); struct logical_volume *alloc_pool_metadata(struct logical_volume *pool_lv,
lib/metadata/thin_manip.c +57 -18
126 lines not on this page · raw message
lib/report/properties.c +38 -22
85 lines not on this page · raw message