master - writecache: use two step detach
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c32d7fed4f78b4537f4ada4318866786a9fab493 Commit: c32d7fed4f78b4537f4ada4318866786a9fab493 Parent: d1b7438c9fb7ab9b0940ce433c0ece2fa17a6f03 Author: David Teigland <[email protected]> AuthorDate: Thu Jun 11 13:33:40 2020 -0500 Committer: David Teigland <[email protected]> CommitterDate: Thu Oct 1 11:33:02 2020 -0500
writecache: use two step detach
When detaching a writecache, use the cleaner setting by default to writeback data prior to suspending the lv to detach the writecache. This avoids potentially blocking for a long period with the device suspended.
Detaching a writecache first sets the cleaner option, waits for a short period of time (less than a second), and checks if the writecache has quickly become clean. If so, the writecache is detached immediately. This optimizes the case where little writeback is needed.
If the writecache does not quickly become clean, then the detach command leaves the writecache attached with the cleaner option set. This leaves the LV in the same state as if the user had set the cleaner option directly with lvchange --cachesettings cleaner=1 LV.
After leaving the LV with the cleaner option set, the detach command will wait and watch the writeback progress, and will finally detach the writecache when the writeback is finished. The detach command does not need to wait during the writeback phase, and can be canceled, in which case the LV will remain with the writecache attached and the cleaner option set. When the user runs the detach command again it will complete the detach.
To detach a writecache directly, without using the cleaner step (which has been the approach previously), add the option --cachesettings cleaner=0 to the detach command.
--- lib/metadata/metadata-exported.h | 3 + lib/metadata/writecache_manip.c | 63 ++++++++- lib/writecache/writecache.c | 25 +++- tools/command-lines.in | 4 +- tools/lvconvert.c | 285 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 357 insertions(+), 23 deletions(-)
lib/metadata/metadata-exported.h +3 -0
@@ -1114,6 +1114,9 @@ int lv_is_cache_origin(const struct logical_volume *lv);int lv_is_writecache_origin (const struct logical_volume *lv);int lv_is_writecache_cachevol (const struct logical_volume *lv);int writecache_settings_to_str_list (struct writecache_settings *settings,struct dm_list *result,struct dm_pool *mem); +int lv_writecache_set_cleaner (struct logical_volume *lv); +bool lv_writecache_is_clean (struct cmd_context *cmd,struct logical_volume *lv,uint64_t *dirty_blocks); +bool writecache_cleaner_supported (struct cmd_context *cmd);int lv_is_integrity_origin (const struct logical_volume *lv);
lib/metadata/writecache_manip.c +58 -5
93 lines not on this page · raw message
lib/writecache/writecache.c +22 -3
@@ -238,13 +238,20 @@ static int _target_present(struct cmd_context *cmd,if (!_writecache_checked) { _writecache_checked =1 ; - _writecache_present =target_present (cmd,TARGET_NAME_WRITECACHE ,1 ); + _writecache_present =target_present (cmd,TARGET_NAME_WRITECACHE ,1 ); -if (!target_version (TARGET_NAME_WRITECACHE , &maj, &min, &patchlevel)) +if (!_writecache_present) { +log_error ("dm-writecache module not found in kernel." ); +return 0 ; + } + +if (!target_version (TARGET_NAME_WRITECACHE , &maj, &min, &patchlevel)) { +log_error ("dm-writecache module version not found." ); return_0; + }if (maj <1 ) { -log_error ("writecache target version older than minimum 1.0.0" ); +log_error ("dm-writecache module version older than minimum 1.0.0" );return 0 ; }
@@ -257,6 +264,12 @@ static int _target_present(struct cmd_context *cmd,return _writecache_present; } +bool writecache_cleaner_supported (struct cmd_context *cmd) +{ +_target_present (cmd,NULL ,NULL ); +return _writecache_cleaner_supported ? true : false; +} +static int _modules_needed (struct dm_pool *mem,const struct lv_segment *seg __attribute__((unused)),struct dm_list *modules)
@@ -268,6 +281,12 @@ static int _modules_needed(struct dm_pool *mem, return 1; } + +#else +bool writecache_cleaner_supported (struct cmd_context *cmd) +{ +return 0 ; +}#endif /* DEVMAPPER_SUPPORT */ #ifdef DEVMAPPER_SUPPORT
tools/command-lines.in +2 -2
@@ -620,14 +620,14 @@ FLAGS: SECONDARY_SYNTAX --- lvconvert --splitcache LV_cachepool_cache_thinpool_vdopool_writecache -OO: OO_LVCONVERT +OO: OO_LVCONVERT, --cachesettings String ID: lvconvert_split_and_keep_cache DESC: Detach a cache from an LV. --- lvconvert --uncache LV_cache_thinpool_vdopool_writecache -OO: OO_LVCONVERT +OO: OO_LVCONVERT, --cachesettings String ID: lvconvert_split_and_remove_cache DESC: Detach and delete a cache from an LV. FLAGS: SECONDARY_SYNTAX
tools/lvconvert.c +272 -13
345 lines not on this page · raw message