2014-02-05 02:50:16 +04:00
#!/bin/sh
# Copyright (C) 2014 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
2016-01-21 13:49:46 +03:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2014-02-05 02:50:16 +04:00
2014-10-03 21:02:37 +04:00
# Exercise creation of cache and cache pool volumes
# Full CLI uses --type
2014-10-20 16:56:55 +04:00
# Shorthand CLI uses -H | --cache
2014-10-03 21:02:37 +04:00
2016-02-23 01:13:42 +03:00
SKIP_WITH_LVMLOCKD = 1
2015-10-27 17:10:06 +03:00
SKIP_WITH_LVMPOLLD = 1
2014-02-05 02:50:16 +04:00
2015-10-27 17:10:06 +03:00
. lib/inittest
2015-05-09 02:59:18 +03:00
2014-05-20 21:54:48 +04:00
aux have_cache 1 3 0 || skip
2014-02-05 02:50:16 +04:00
2014-10-03 21:02:37 +04:00
# FIXME: parallel cache metadata allocator is crashing when used value 8000!
aux prepare_vg 5 80000
2014-02-05 02:50:16 +04:00
2015-08-12 15:18:28 +03:00
aux lvmconf 'global/cache_disabled_features = [ "policy_smq" ]'
2014-10-20 16:56:55 +04:00
2014-10-03 21:02:37 +04:00
#######################
# Cache_Pool creation #
#######################
2014-10-20 16:56:55 +04:00
# TODO: Unsupported yet creation of cache pool and cached volume at once
# TODO: Introduce --pooldatasize
# TODO: Policy to determine cache pool size and cache pool name
2014-10-03 21:02:37 +04:00
invalid lvcreate -H -l 1 $vg
2014-10-20 16:56:55 +04:00
invalid lvcreate -H -l 1 --name $lv1 $vg
invalid lvcreate -l 1 --cache $vg
# Only cached volume could be created
invalid lvcreate -l 1 --type cache $vg
2015-09-10 17:54:40 +03:00
# Striping is not supported with cache-pool creation
invalid lvcreate -l 1 -i 2 --type cache-pool $vg
2014-10-20 16:56:55 +04:00
# Fails as it needs to see VG content
fail lvcreate -l 1 --type cache --cachepool $vg /pool1
fail lvcreate -l 1 --type cache --cachepool pool2 $vg
fail lvcreate -l 1 --cache $vg /pool3
fail lvcreate -l 1 -H --cachepool pool4 $vg
fail lvcreate -l 1 -H --name $lv2 $vg /pool5
fail lvcreate -l 1 -H --name $lv3 --cachepool $vg /pool6
fail lvcreate -l 1 -H --name $vg /$lv4 --cachepool pool7
2014-02-05 02:50:16 +04:00
2014-10-20 16:56:55 +04:00
# Unlike in thin pool case - cache pool and cache volume both need size arg.
2014-10-03 21:02:37 +04:00
# So we require cache pool to exist and need to fail when it's missing.
#
2014-10-20 16:56:55 +04:00
# --cachepool gives implicit --cache
fail lvcreate -l 1 --cachepool pool8 $vg
# no size specified
2015-05-14 11:20:24 +03:00
invalid lvcreate --cachepool pool $vg 2>& 1 | tee err
commands: new method for defining commands
. Define a prototype for every lvm command.
. Match every user command with one definition.
. Generate help text and man pages from them.
The new file command-lines.in defines a prototype for every
unique lvm command. A unique lvm command is a unique
combination of: command name + required option args +
required positional args. Each of these prototypes also
includes the optional option args and optional positional
args that the command will accept, a description, and a
unique string ID for the definition. Any valid command
will match one of the prototypes.
Here's an example of the lvresize command definitions from
command-lines.in, there are three unique lvresize commands:
lvresize --size SizeMB LV
OO: --alloc Alloc, --autobackup Bool, --force,
--nofsck, --nosync, --noudevsync, --reportformat String, --resizefs,
--stripes Number, --stripesize SizeKB, --poolmetadatasize SizeMB
OP: PV ...
ID: lvresize_by_size
DESC: Resize an LV by a specified size.
lvresize LV PV ...
OO: --alloc Alloc, --autobackup Bool, --force,
--nofsck, --nosync, --noudevsync,
--reportformat String, --resizefs, --stripes Number, --stripesize SizeKB
ID: lvresize_by_pv
DESC: Resize an LV by specified PV extents.
FLAGS: SECONDARY_SYNTAX
lvresize --poolmetadatasize SizeMB LV_thinpool
OO: --alloc Alloc, --autobackup Bool, --force,
--nofsck, --nosync, --noudevsync,
--reportformat String, --stripes Number, --stripesize SizeKB
OP: PV ...
ID: lvresize_pool_metadata_by_size
DESC: Resize a pool metadata SubLV by a specified size.
The three commands have separate definitions because they have
different required parameters. Required parameters are specified
on the first line of the definition. Optional options are
listed after OO, and optional positional args are listed after OP.
This data is used to generate corresponding command definition
structures for lvm in command-lines.h. usage/help output is also
auto generated, so it is always in sync with the definitions.
Every user-entered command is compared against the set of
command structures, and matched with one. An error is
reported if an entered command does not have the required
parameters for any definition. The closest match is printed
as a suggestion, and running lvresize --help will display
the usage for each possible lvresize command.
The prototype syntax used for help/man output includes
required --option and positional args on the first line,
and optional --option and positional args enclosed in [ ]
on subsequent lines.
command_name <required_opt_args> <required_pos_args>
[ <optional_opt_args> ]
[ <optional_pos_args> ]
Command definitions that are not to be advertised/suggested
have the flag SECONDARY_SYNTAX. These commands will not be
printed in the normal help output.
Man page prototypes are also generated from the same original
command definitions, and are always in sync with the code
and help text.
Very early in command execution, a matching command definition
is found. lvm then knows the operation being done, and that
the provided args conform to the definition. This will allow
lots of ad hoc checking/validation to be removed throughout
the code.
Each command definition can also be routed to a specific
function to implement it. The function is associated with
an enum value for the command definition (generated from
the ID string.) These per-command-definition implementation
functions have not yet been created, so all commands
currently fall back to the existing per-command-name
implementation functions.
Using per-command-definition functions will allow lots of
code to be removed which tries to figure out what the
command is meant to do. This is currently based on ad hoc
and complicated option analysis. When using the new
functions, what the command is doing is already known
from the associated command definition.
2016-08-12 23:52:18 +03:00
# grep "specify either size or extents" err
2014-10-03 21:02:37 +04:00
# Check nothing has been created yet
check vg_field $vg lv_count 0
2014-10-20 16:56:55 +04:00
# With --type cache-pool we are clear which segtype has to be created
lvcreate -l 1 --type cache-pool $vg /pool1
2014-10-03 21:02:37 +04:00
check lv_field $vg /pool1 segtype "cache-pool"
2014-10-20 16:56:55 +04:00
lvcreate -l 1 --type cache-pool --name $vg /pool2 $vg
2014-10-03 21:02:37 +04:00
check lv_field $vg /pool2 segtype "cache-pool"
2014-10-20 16:56:55 +04:00
lvcreate -l 1 --type cache-pool --cachepool $vg /pool3 $vg
2014-10-03 21:02:37 +04:00
check lv_field $vg /pool3 segtype "cache-pool"
2014-10-20 16:56:55 +04:00
lvcreate -l 1 --type cache-pool --cachepool $vg /pool4
2014-10-03 21:02:37 +04:00
check lv_field $vg /pool4 segtype "cache-pool"
2014-10-20 16:56:55 +04:00
lvcreate -l 1 --type cache-pool --cachepool pool5 $vg
2014-10-03 21:02:37 +04:00
check lv_field $vg /pool5 segtype "cache-pool"
2014-10-20 16:56:55 +04:00
lvcreate -l 1 --type cache-pool --name pool6 $vg
2014-10-03 21:02:37 +04:00
check lv_field $vg /pool6 segtype "cache-pool"
2014-10-20 16:56:55 +04:00
lvcreate -l 1 --type cache-pool --name $vg /pool7
2014-10-03 21:02:37 +04:00
check lv_field $vg /pool7 segtype "cache-pool"
lvremove -f $vg
2014-02-05 02:50:16 +04:00
2014-10-20 16:56:55 +04:00
2016-09-09 15:24:49 +03:00
# Check the percentage values are reported for both cache and cache-pool
lvcreate --type cache-pool -L1 $vg /cpool
lvcreate -H -L4 -n $lv1 $vg /cpool
2016-09-20 15:26:11 +03:00
check lv_field $vg /$lv1 origin " [ ${ lv1 } _corig] "
2016-09-09 21:45:37 +03:00
check lv_field $vg /$lv1 copy_percent "0.00"
2016-09-13 12:30:16 +03:00
# there should be something present (value differs per policy version)
test -n " $( get lv_field $vg /$lv1 data_percent) "
test -n " $( get lv_field $vg /$lv1 metadata_percent) "
2016-09-09 21:45:37 +03:00
check lv_field $vg /cpool copy_percent "0.00"
2016-09-13 12:30:16 +03:00
test -n " $( get lv_field $vg /cpool data_percent) "
test -n " $( get lv_field $vg /cpool metadata_percent) "
2016-09-09 15:24:49 +03:00
# check we also display percent value for segmented output (-o+devices)
lvs -a -o+devices $vg /cpool | tee out
2016-09-09 21:45:37 +03:00
grep "0.00" out
2016-09-09 15:24:49 +03:00
lvremove -f $vg
2014-10-07 01:25:49 +04:00
# Validate ambiguous pool name is detected
2014-10-03 21:02:37 +04:00
invalid lvcreate -l 1 --type cache-pool --cachepool pool1 $vg /pool2
invalid lvcreate -l 1 --type cache-pool --name pool3 --cachepool pool4 $vg
invalid lvcreate -l 1 --type cache-pool --name pool6 --cachepool pool6 $vg /pool7
invalid lvcreate -l 1 --type cache-pool --name pool8 $vg /pool9
2014-10-20 16:56:55 +04:00
# Unsupported with cache & cache pool
invalid lvcreate --type cache-pool --discards passdown -l1 $vg
invalid lvcreate -H --discards passdown -l1 $vg
invalid lvcreate --type cache-pool --virtualsize 1T -l1 $vg
invalid lvcreate -H --virtualsize 1T -l1 $vg
2014-10-03 21:02:37 +04:00
check vg_field $vg lv_count 0
2014-02-05 02:50:16 +04:00
2014-10-20 16:56:55 +04:00
2014-10-03 21:02:37 +04:00
for mode in "" "--cachemode writethrough"
do
2014-02-05 02:50:16 +04:00
################
# Cache creation
# Creating a cache is a two phase process
# - first, cache_pool (or origin)
# - then, the cache LV (lvcreate distinguishes supplied origin vs cache_pool)
################
2014-10-03 21:02:37 +04:00
lvcreate --type cache-pool -l 1 -n pool $vg $mode
# Select automatic name for cached LV
lvcreate --type cache -l1 $vg /pool
lvcreate --type cache-pool -l 1 -n pool1 $vg $mode
lvcreate --cache -l1 -n $lv1 --cachepool $vg /pool1
2014-02-15 02:03:23 +04:00
dmsetup table ${ vg } -$lv1 | grep cache # ensure it is loaded in kernel
2014-02-05 02:50:16 +04:00
2014-10-03 21:02:37 +04:00
lvcreate --type cache-pool -l 1 -n pool2 $vg $mode
lvcreate -H -l1 -n $lv2 --cachepool pool2 $vg
2014-02-05 02:50:16 +04:00
2014-10-03 21:02:37 +04:00
#
# Now check removals
#
# Removal of cached LV removes every related LV
check lv_field $vg /$lv1 segtype "cache"
2014-04-01 19:52:29 +04:00
lvremove -f $vg /$lv1
2014-10-03 21:02:37 +04:00
check lv_not_exists $vg $lv1 pool1 pool1_cdata pool1_cmeta
# to preserve cachepool use lvconvert --splitcache $vg/$lv1
# Removal of cache pool leaves origin uncached
check lv_field $vg /$lv2 segtype "cache"
lvremove -f $vg /pool2
check lv_not_exists $vg pool2 pool2_cdata pool2_cmeta
check lv_field $vg /$lv2 segtype "linear"
2014-02-05 02:50:16 +04:00
2014-10-03 21:02:37 +04:00
lvremove -f $vg
2014-02-05 02:50:16 +04:00
2014-10-03 21:02:37 +04:00
done
2014-02-05 02:50:16 +04:00
2014-10-20 16:56:55 +04:00
2014-10-03 21:02:37 +04:00
# Conversion through lvcreate case
2014-06-17 03:15:39 +04:00
# Bug 1110026
2014-10-03 21:02:37 +04:00
# Create origin, then cache pool and cache the origin
2014-07-23 02:25:49 +04:00
lvcreate -aey -l 2 -n $lv1 $vg
2014-06-17 03:15:39 +04:00
lvcreate --type cache -l 1 $vg /$lv1
2014-10-03 21:02:37 +04:00
dmsetup table ${ vg } -$lv1 | grep cache # ensure it is loaded in kernel
2014-06-17 03:15:39 +04:00
2014-10-03 21:02:37 +04:00
lvremove -f $vg
2014-02-05 02:50:16 +04:00
2014-10-03 21:02:37 +04:00
# Check minimum cache pool metadata size
lvcreate -l 1 --type cache-pool --poolmetadatasize 1 $vg 2>out
grep "WARNING: Minimum" out
# FIXME: This test is failing in allocator with smaller VG sizes
lvcreate -l 1 --type cache-pool --poolmetadatasize 17G $vg 2>out
grep "WARNING: Maximum" out
lvremove -f $vg
2014-10-20 16:56:55 +04:00
########################################
# Cache conversion and r/w permissions #
########################################
# writeable origin and 'default' => writable cache + origin
lvcreate -an -l1 -n $vg /$lv1
2015-09-10 17:54:40 +03:00
# do not allow stripping for cache-pool
fail lvcreate -H -i 2 -l1 -n cpool1 $vg /$lv1
2014-10-20 16:56:55 +04:00
lvcreate -H -l1 -n cpool1 $vg /$lv1
check lv_attr_bit perm $vg /cpool1 "w"
check lv_attr_bit perm $vg /${ lv1 } _corig "w"
check lv_attr_bit perm $vg /$lv1 "w"
# writeable origin and -pr => conversion is not supported
lvcreate -an -l1 -n $vg /$lv2
fail lvcreate -H -l1 -pr -n cpool2 $vg /$lv2
# read-only origin and -pr => read-only cache + origin
lvcreate -an -pr -l1 -n $vg /$lv3
lvcreate -an -H -l1 -pr -n cpool3 $vg /$lv3
check lv_attr_bit perm $vg /cpool3 "w"
check lv_attr_bit perm $vg /${ lv3 } _corig "r"
check lv_attr_bit perm $vg /$lv3 "r"
check inactive $vg $lv3
check inactive $vg cpool3
# read-only origin and 'default' => read-only cache + origin
lvcreate -an -pr -l1 -n $vg /$lv4
lvcreate -H -l1 -n cpool4 $vg /$lv4
check lv_attr_bit perm $vg /cpool4 "w"
check lv_attr_bit perm $vg /${ lv4 } _corig "r"
check lv_attr_bit perm $vg /$lv4 "r"
# read-only origin and -prw => conversion unsupported
lvcreate -an -pr -l1 -n $vg /$lv5
fail lvcreate -H -l1 -prw -n cpool5 $vg /$lv5
# cached volume respects permissions
lvcreate --type cache-pool -l1 -n $vg /cpool
lvcreate -H -l1 -pr -n $lv6 $vg /cpool
check lv_attr_bit perm $vg /cpool "w"
check lv_attr_bit perm $vg /$lv6 "r"
lvremove -f $vg
2014-10-26 18:19:30 +03:00
########################################
# Validate args are properly preserved #
########################################
lvcreate --type cache-pool -L10 --chunksize 256 --cachemode writeback $vg /cpool1
check lv_field $vg /cpool1 chunksize "256.00k"
check lv_field $vg /cpool1 cachemode "writeback"
2015-09-10 17:54:40 +03:00
# check striping is supported when creating a cached LV
lvcreate -H -L10 -i 2 -n $lv1 $vg /cpool1
check lv_field $vg /${ lv1 } _corig stripes "2" -a
2014-11-10 23:29:20 +03:00
check lv_field $vg /$lv1 chunksize "256.00k"
check lv_field $vg /$lv1 cachemode "writeback"
2014-10-26 18:19:30 +03:00
lvcreate --type cache-pool -L10 --chunksize 256 --cachemode writethrough $vg /cpool2
2014-11-10 23:29:20 +03:00
lvcreate -H -L10 --chunksize 512 --cachemode writeback -n $lv2 $vg /cpool2
check lv_field $vg /$lv2 chunksize "512.00k"
check lv_field $vg /$lv2 cachemode "writeback"
2014-10-26 18:19:30 +03:00
# Chunk bigger then pool size
fail lvcreate --type cache-pool -l1 --chunksize 1G $vg /cpool3
lvcreate --type cache-pool -L10 $vg /cpool4
fail lvcreate -H -L10 --chunksize 16M $vg /cpool4
lvremove -f $vg
2014-11-27 22:21:41 +03:00
lvcreate --type cache-pool -L10 $vg /cpool
2016-05-05 22:35:19 +03:00
lvcreate --type cache -l 1 --cachepool $vg /cpool -n corigin $vg --cachesettings migration_threshold = 233
2014-11-27 22:21:41 +03:00
dmsetup status | grep $vg
dmsetup status | grep $vg -corigin | grep 'migration_threshold 233'
2014-12-15 22:48:05 +03:00
lvchange -an $vg
lvchange -ay $vg
dmsetup status | grep $vg -corigin | grep 'migration_threshold 233'
2014-11-27 22:21:41 +03:00
lvremove -f $vg
lvcreate --type cache-pool -L10 --cachepolicy mq --cachesettings migration_threshold = 233 $vg /cpool
lvcreate --type cache -l 1 --cachepool $vg /cpool -n corigin $vg
dmsetup status | grep $vg
dmsetup status | grep $vg -corigin | grep 'migration_threshold 233'
lvremove -f $vg
2014-02-05 02:50:16 +04:00
##############################
# Test things that should fail
##############################
2014-10-20 16:56:55 +04:00
# Creation of read-only cache pool is not supported
invalid lvcreate -pr --type cache-pool -l1 -n $vg /cpool
2014-10-03 21:02:37 +04:00
# Atempt to use bigger chunk size then cache pool data size
fail lvcreate -l 1 --type cache-pool --chunksize 16M $vg 2>out
2014-10-20 16:56:55 +04:00
grep "chunk size" out
2014-02-05 02:50:16 +04:00
# Option testing
# --chunksize
# --cachepolicy
# --poolmetadatasize
# --poolmetadataspare
2014-02-27 02:25:30 +04:00
vgremove -ff $vg