master - Allow dm-cache cache device to be standard LV
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=cac4a9743acb826d785c0e51e9a752d8959ced80 Commit: cac4a9743acb826d785c0e51e9a752d8959ced80 Parent: 8c9d9a744605e37799a2475932ae7dfd43831d08 Author: David Teigland <[email protected]> AuthorDate: Fri Aug 17 15:45:52 2018 -0500 Committer: David Teigland <[email protected]> CommitterDate: Tue Nov 6 13:44:54 2018 -0600
Allow dm-cache cache device to be standard LV
If a single, standard LV is specified as the cache, use it directly instead of converting it into a cache-pool object with two separate LVs (for data and metadata).
With a single LV as the cache, lvm will use blocks at the beginning for metadata, and the rest for data. Separate dm linear devices are set up to point at the metadata and data areas of the LV. These dm devs are given to the dm-cache target to use.
The single LV cache cannot be resized without recreating it.
If the --poolmetadata option is used to specify an LV for metadata, then a cache pool will be created (with separate LVs for data and metadata.)
Usage:
$ lvcreate -n main -L 128M vg /dev/loop0
$ lvcreate -n fast -L 64M vg /dev/loop1
$ lvs -a vg LV VG Attr LSize Type Devices main vg -wi-a----- 128.00m linear /dev/loop0(0) fast vg -wi-a----- 64.00m linear /dev/loop1(0)
$ lvconvert --type cache --cachepool fast vg/main
$ lvs -a vg LV VG Attr LSize Origin Pool Type Devices [fast] vg Cwi---C--- 64.00m linear /dev/loop1(0) main vg Cwi---C--- 128.00m [main_corig] [fast] cache main_corig(0) [main_corig] vg owi---C--- 128.00m linear /dev/loop0(0)
$ lvchange -ay vg/main
$ dmsetup ls vg-fast_cdata (253:4) vg-fast_cmeta (253:5) vg-main_corig (253:6) vg-main (253:24) vg-fast (253:3)
$ dmsetup table vg-fast_cdata: 0 98304 linear 253:3 32768 vg-fast_cmeta: 0 32768 linear 253:3 0 vg-main_corig: 0 262144 linear 7:0 2048 vg-main: 0 262144 cache 253:5 253:4 253:6 128 2 metadata2 writethrough mq 0 vg-fast: 0 131072 linear 7:1 2048
$ lvchange -an vg/min
$ lvconvert --splitcache vg/main
$ lvs -a vg LV VG Attr LSize Type Devices fast vg -wi------- 64.00m linear /dev/loop1(0) main vg -wi------- 128.00m linear /dev/loop0(0) --- device_mapper/all.h | 4 + device_mapper/libdm-deptree.c | 15 +- lib/activate/dev_manager.c | 269 ++++++++++++++++++++- lib/activate/dev_manager.h | 10 + lib/cache_segtype/cache.c | 125 +++++++++- lib/format_text/flags.c | 1 + lib/locking/lvmlockd.c | 3 + lib/metadata/cache_manip.c | 478 +++++++++++++++++++++++++++++++++--- lib/metadata/lv.c | 18 +- lib/metadata/lv_manip.c | 10 +- lib/metadata/merge.c | 43 +++- lib/metadata/metadata-exported.h | 24 ++- lib/report/report.c | 20 ++- test/shell/cache-single-options.sh | 269 ++++++++++++++++++++ test/shell/cache-single-thin.sh | 43 ++++ test/shell/cache-single-types.sh | 88 +++++++ test/shell/cache-single-usage.sh | 129 ++++++++++ test/shell/lvconvert-cache-raid.sh | 41 ++-- test/shell/lvconvert-cache.sh | 1 + test/shell/lvrename-cache-thin.sh | 2 + tools/lvchange.c | 5 +- tools/lvconvert.c | 174 ++++++++++++-- tools/vgsplit.c | 5 +- 23 files changed, 1666 insertions(+), 111 deletions(-)
device_mapper/all.h +4 -0
@@ -912,6 +912,10 @@ int dm_tree_node_add_cache_target(struct dm_tree_node *node,const char *origin_uuid, const char *policy_name, const struct dm_config_node *policy_settings, + uint64_t metadata_start, + uint64_t metadata_len, + uint64_t data_start, + uint64_t data_len, uint32_t data_block_size);/*
device_mapper/libdm-deptree.c +14 -1
@@ -189,6 +189,11 @@ struct load_segment {uint32_t min_recovery_rate;/* raid kB/sec/disk */ uint32_t data_copies;/* raid10 data_copies */ +uint64_t metadata_start;/* Cache */ +uint64_t metadata_len;/* Cache */ +uint64_t data_start;/* Cache */ +uint64_t data_len;/* Cache */ +struct dm_tree_node *metadata;/* Thin_pool + Cache */ struct dm_tree_node *pool;/* Thin_pool, Thin */ struct dm_tree_node *external;/* Thin */
@@ -3473,6 +3478,10 @@ int dm_tree_node_add_cache_target(struct dm_tree_node *node,const char *origin_uuid, const char *policy_name, const struct dm_config_node *policy_settings, + uint64_t metadata_start, + uint64_t metadata_len, + uint64_t data_start, + uint64_t data_len, uint32_t data_block_size) { struct dm_config_node *cn;
@@ -3548,6 +3557,10 @@ int dm_tree_node_add_cache_target(struct dm_tree_node *node,if (!_link_tree_nodes (node, seg->origin)) return_0; + seg->metadata_start = metadata_start; + seg->metadata_len = metadata_len; + seg->data_start = data_start; + seg->data_len = data_len; seg->data_block_size = data_block_size; seg->flags = feature_flags; seg->policy_name = policy_name;
@@ -4026,7 +4039,7 @@ int dm_tree_node_add_cache_target_base(struct dm_tree_node *node,return dm_tree_node_add_cache_target (node, size, feature_flags & _mask, metadata_uuid, data_uuid, origin_uuid, - policy_name, policy_settings, data_block_size); + policy_name, policy_settings, 0, 0, 0, 0, data_block_size); }#endif
lib/activate/dev_manager.c +261 -8
317 lines not on this page · raw message
lib/activate/dev_manager.h +10 -0
@@ -103,4 +103,14 @@ int dev_manager_execute(struct dev_manager *dm);int dev_manager_device_uses_vg (struct device *dev,struct volume_group *vg); +int dev_manager_remove_dm_major_minor (uint32_t major,uint32_t minor); + +int get_cache_single_meta_data (struct cmd_context *cmd, +struct logical_volume *lv, +struct logical_volume *pool_lv, +struct dm_info *info_meta,struct dm_info *info_data); + +int remove_cache_single_meta_data (struct cmd_context *cmd, +struct dm_info *info_meta,struct dm_info *info_data); +#endif
lib/cache_segtype/cache.c +113 -12
182 lines not on this page · raw message
lib/format_text/flags.c +1 -0
@@ -72,6 +72,7 @@ static const struct flag _lv_flags[] = { {LV_ACTIVATION_SKIP, "ACTIVATION_SKIP", COMPATIBLE_FLAG}, {LV_ERROR_WHEN_FULL, "ERROR_WHEN_FULL", COMPATIBLE_FLAG}, {LV_METADATA_FORMAT, "METADATA_FORMAT", SEGTYPE_FLAG}, + {LV_CACHE_SINGLE, "CACHE_SINGLE", STATUS_FLAG}, {LV_NOSCAN, NULL, 0}, {LV_TEMPORARY, NULL, 0}, {POOL_METADATA_SPARE, NULL, 0},
lib/locking/lvmlockd.c +3 -0
@@ -2779,6 +2779,9 @@ int lockd_lv_uses_lock(struct logical_volume *lv)if (lv_is_pool_metadata_spare (lv))return 0 ; +if (lv_is_cache_single (lv)) +return 0 ; +if (lv_is_cache_pool (lv))return 0 ;
lib/metadata/cache_manip.c +449 -29
542 lines not on this page · raw message
lib/metadata/lv.c +14 -4
@@ -333,6 +333,8 @@ uint64_t lvseg_chunksize(const struct lv_segment *seg)if (lv_is_cow (seg->lv)) size = (uint64_t )find_snapshot (seg->lv)->chunk_size; +else if (seg_is_cache (seg) &&lv_is_cache_single (seg->pool_lv)) + size = (uint64_t ) seg->chunk_size;else if (seg_is_pool (seg)) size = (uint64_t ) seg->chunk_size;else if (seg_is_cache (seg))
@@ -932,10 +934,18 @@ uint64_t lv_origin_size(const struct logical_volume *lv)uint64_t lv_metadata_size (const struct logical_volume *lv) { -struct lv_segment *seg = (lv_is_thin_pool (lv) ||lv_is_cache_pool (lv)) ? -first_seg (lv) :NULL ; +struct lv_segment *seg; + +if (!(seg =first_seg (lv))) +return 0 ; + +if (seg_is_cache (seg) &&lv_is_cache_single (seg->pool_lv)) +return seg->metadata_len; -return seg ? seg->metadata_lv->size :0 ; +if (lv_is_thin_pool (lv) ||lv_is_cache_pool (lv)) +return seg->metadata_lv->size; + +return 0 ; }char *lv_path_dup (struct dm_pool *mem,const struct logical_volume *lv)
@@ -1297,7 +1307,7 @@ 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)) repstr[6 ] ='t' ; -else if (lv_is_cache_pool (lv) ||lv_is_cache (lv) ||lv_is_cache_origin (lv)) +else if (lv_is_cache_pool (lv) ||lv_is_cache_single (lv) ||lv_is_cache (lv) ||lv_is_cache_origin (lv)) repstr[6 ] ='C' ;else if (lv_is_raid_type (lv)) repstr[6 ] ='r' ;
lib/metadata/lv_manip.c +9 -1
@@ -422,7 +422,7 @@ static int _lv_layout_and_role_cache(struct dm_pool *mem,if (lv_is_cache (lv) && !str_list_add_no_dup_check (mem, layout, _lv_type_names[LV_TYPE_CACHE ])) goto_bad; -else if (lv_is_cache_pool (lv)) { +else if (lv_is_cache_pool (lv) ||lv_is_cache_single (lv)) {if (!str_list_add_no_dup_check (mem, layout, _lv_type_names[LV_TYPE_CACHE ]) || !str_list_add_no_dup_check (mem, layout, _lv_type_names[LV_TYPE_POOL ])) goto_bad;
@@ -4449,6 +4449,7 @@ static int _rename_skip_pools_externals_cb(struct logical_volume *lv, void *data {if (lv_is_pool (lv) ||lv_is_vdo_pool (lv) || +lv_is_cache_single (lv) ||lv_is_external_origin (lv))return -1 ;/* and skip subLVs */
@@ -6147,6 +6148,13 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,if (!lockd_lv (cmd, lock_lv,"ex" ,LDLV_PERSISTENT )) return_0; +if (lv_is_cache (lv) &&lv_is_cache_single (first_seg (lv)->pool_lv)) { +if (!lv_detach_cache_single (lv)) { +log_error ("Failed to detach cache from %s" ,display_lvname (lv)); +return 0 ; + } + } +/* FIXME Ensure not referred to by another existing LVs */ ask_discard =find_config_tree_bool (cmd, devices_issue_discards_CFG,NULL );
lib/metadata/merge.c +31 -12
90 lines not on this page · raw message
lib/metadata/metadata-exported.h +22 -2
@@ -151,6 +151,8 @@#define LV_VDO_POOL UINT64_C(0x0000000040000000)/* LV - Internal user only */ #define LV_VDO_POOL_DATA UINT64_C(0x8000000000000000)/* LV - Internal user only */ +#define LV_CACHE_SINGLE UINT64_C(0x0010000000000000)/* LV - also a PV flag */ +/* Format features flags */ #define FMT_SEGMENTS 0x00000001U/* Arbitrary segment params? */
@@ -245,10 +247,11 @@#define lv_is_cache (lv) (((lv)->status & CACHE) ? 1 : 0)#define lv_is_cache_pool (lv) (((lv)->status & CACHE_POOL) ? 1 : 0) +#define lv_is_cache_single (lv) (((lv)->status & LV_CACHE_SINGLE) ? 1 : 0)#define lv_is_used_cache_pool (lv) (lv_is_cache_pool(lv) && !dm_list_empty(&(lv)->segs_using_this_lv))#define lv_is_cache_pool_data (lv) (((lv)->status & CACHE_POOL_DATA) ? 1 : 0)#define lv_is_cache_pool_metadata (lv) (((lv)->status & CACHE_POOL_METADATA) ? 1 : 0) -#define lv_is_cache_type (lv) (((lv)->status & (CACHE | CACHE_POOL | CACHE_POOL_DATA | CACHE_POOL_METADATA)) ? 1 : 0) +#define lv_is_cache_type (lv) (((lv)->status & (CACHE | CACHE_POOL | LV_CACHE_SINGLE | CACHE_POOL_DATA | CACHE_POOL_METADATA)) ? 1 : 0)#define lv_is_pool (lv) (((lv)->status & (CACHE_POOL | THIN_POOL)) ? 1 : 0)#define lv_is_pool_data (lv) (((lv)->status & (CACHE_POOL_DATA | THIN_POOL_DATA)) ? 1 : 0)
@@ -493,6 +496,13 @@ struct lv_segment {struct logical_volume *pool_lv;/* For thin, cache */ uint32_t device_id;/* For thin, 24bit */ +uint64_t metadata_start;/* For cache */ +uint64_t metadata_len;/* For cache */ +uint64_t data_start;/* For cache */ +uint64_t data_len;/* For cache */ +struct id metadata_id;/* For cache */ +struct id data_id;/* For cache */ +cache_metadata_format_t cache_metadata_format;/* For cache_pool */ cache_mode_t cache_mode;/* For cache_pool */ const char *policy_name;/* For cache_pool */
@@ -1218,7 +1228,7 @@ struct lv_status_cache {const char *cache_mode_num_to_str (cache_mode_t mode);const char *display_cache_mode (const struct lv_segment *seg); -const char *get_cache_mode_name (const struct lv_segment *pool_seg); +const char *get_cache_mode_name (const struct lv_segment *seg);int set_cache_mode (cache_mode_t *mode,const char *cache_mode);int cache_set_cache_mode (struct lv_segment *seg,cache_mode_t mode);int cache_set_metadata_format (struct lv_segment *seg,cache_metadata_format_t format);
@@ -1230,6 +1240,15 @@ int cache_set_params(struct lv_segment *seg,cache_mode_t mode, const char *policy_name, const struct dm_config_tree *policy_settings); +int cache_single_set_params (struct cmd_context *cmd, +struct logical_volume *cache_lv, +struct logical_volume *pool_lv, +uint64_t poolmetadatasize, +uint32_t chunk_size, +cache_metadata_format_t format, +cache_mode_t mode, +const char *policy, +const struct dm_config_tree *settings);void cache_check_for_warns (const struct lv_segment *seg); int update_cache_pool_params(struct cmd_context *cmd, struct profile *profile,
@@ -1246,6 +1265,7 @@ struct logical_volume *lv_cache_create(struct logical_volume *pool_lv, struct logical_volume *origin_lv);int lv_cache_wait_for_clean (struct logical_volume *cache_lv,int *is_clean);int lv_cache_remove (struct logical_volume *cache_lv); +int lv_detach_cache_single (struct logical_volume *cache_lv);int wipe_cache_pool (struct logical_volume *cache_pool_lv);/* -- metadata/cache_manip.c */
lib/report/report.c +17 -3
@@ -1430,7 +1430,10 @@ static int _cache_settings_disp(struct dm_report *rh, struct dm_pool *mem,struct _str_list_append_baton baton;struct dm_list dummy_list;/* dummy list to display "nothing" */ -if (seg_is_cache_pool (seg)) +if (seg_is_cache (seg) &&lv_is_cache_single (seg->pool_lv)) + setting_seg = seg; + +else if (seg_is_cache_pool (seg)) setting_seg = seg;else if (seg_is_cache (seg))
@@ -1565,7 +1568,10 @@ static int _cache_policy_disp(struct dm_report *rh, struct dm_pool *mem,const struct lv_segment *seg = (const struct lv_segment *) data;const struct lv_segment *setting_seg =NULL ; -if (seg_is_cache_pool (seg)) +if (seg_is_cache (seg) &&lv_is_cache_single (seg->pool_lv)) + setting_seg = seg; + +else if (seg_is_cache_pool (seg)) setting_seg = seg;else if (seg_is_cache (seg))
@@ -2747,7 +2753,10 @@ static int _cachemetadataformat_disp(struct dm_report *rh, struct dm_pool *mem,const struct lv_segment *setting_seg =NULL ;const uint64_t *fmt; -if (seg_is_cache_pool (seg)) +if (seg_is_cache (seg) &&lv_is_cache_single (seg->pool_lv)) + setting_seg = seg; + +else if (seg_is_cache_pool (seg)) setting_seg = seg;else if (seg_is_cache (seg))
@@ -3222,6 +3231,11 @@ static int _lvmetadatasize_disp(struct dm_report *rh, struct dm_pool *mem,const struct logical_volume *lv = (const struct logical_volume *) data;uint64_t size; +if (lv_is_cache (lv) &&lv_is_cache_single (first_seg (lv)->pool_lv)) { + size =lv_metadata_size (lv); +return _size64_disp (rh, mem, field, &size, private); + } +if (lv_is_thin_pool (lv) ||lv_is_cache_pool (lv)) { size =lv_metadata_size (lv);return _size64_disp (rh, mem, field, &size, private);
test/shell/cache-single-options.sh new file +269 -0
269 lines not on this page · raw message
test/shell/cache-single-thin.sh new file +43 -0
43 lines not on this page · raw message
test/shell/cache-single-types.sh new file +88 -0
88 lines not on this page · raw message
test/shell/cache-single-usage.sh new file +129 -0
129 lines not on this page · raw message
test/shell/lvconvert-cache-raid.sh +25 -16
47 lines not on this page · raw message
test/shell/lvconvert-cache.sh +1 -0
@@ -104,6 +104,7 @@ lvcreate -n pool -l 10 $vg lvs -a -o +devices fail lvconvert --type cache --cachepool $vg/pool $vg/corigin lvconvert --yes --cache --cachepool $vg/pool $vg/corigin +lvconvert --splitcache $vg/corigin lvremove -ff $vg # Check we also support conversion that uses 'cleaner' cache policy
test/shell/lvrename-cache-thin.sh +2 -0
@@ -26,6 +26,8 @@ lvcreate -L10 -n cpool $vg lvcreate -L10 -n tpool $vg lvcreate -L10 -n $lv1 $vg +lvconvert --yes --type cache-pool $vg/cpool + lvconvert --yes --cache --cachepool cpool $vg/tpool # currently the only allowed stacking is cache thin data volume
tools/lvchange.c +4 -1
@@ -643,7 +643,10 @@ static int _lvchange_cache(struct cmd_context *cmd, seg =first_seg (lv); -if (seg_is_cache_pool (seg)) +if (seg_is_cache (seg) &&lv_is_cache_single (seg->pool_lv)) + setting_seg = seg; + +else if (seg_is_cache_pool (seg)) setting_seg = seg;else if (seg_is_cache (seg))
tools/lvconvert.c +153 -21
256 lines not on this page · raw message
tools/vgsplit.c +4 -1
@@ -402,7 +402,10 @@ static int _move_cache(struct volume_group *vg_from,/* NOTREACHED */ -if (lv_is_cache (lv)) { +if (lv_is_cache (lv) &&lv_is_cache_single (seg->pool_lv)) { +log_error ("Cannot split while LV %s has cache attached." ,display_lvname (lv)); +return 0 ; + }else if (lv_is_cache (lv)) { orig =seg_lv (seg,0 ); data =seg_lv (first_seg (seg->pool_lv),0 ); meta =first_seg (seg->pool_lv)->metadata_lv;