summaryrefslogtreecommitdiff
path: root/test/shell/lvconvert-thin-external-cache.sh
blob: a8b95b27450bbe7bc34ee1786847943eee765f54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash

# Copyright (C) 2016 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,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# Test conversion cached LV to thin with cached external origin

SKIP_WITH_LVMLOCKD=1
SKIP_WITH_LVMPOLLD=1

export LVM_TEST_THIN_REPAIR_CMD=${LVM_TEST_THIN_REPAIR_CMD-/bin/false}

. lib/inittest

which mkfs.ext2 || skip
which fsck || skip

#
# Main
#
aux have_thin 1 5 0 || skip
aux have_cache 1 7 0 || skip

aux prepare_vg 2 64

# Test will use thin-pool
lvcreate -L10 -T $vg/tpool

lvcreate -aey -L20 -n $lv1 $vg


mkfs.ext2 "$DM_DEV_DIR/$vg/$lv1"
mkdir mnt
mount "$DM_DEV_DIR/$vg/$lv1" mnt
touch mnt/test

# Prepared cached LV - first in 'writeback' mode
lvcreate -H --cachemode writeback -L10 -n cpool $vg/$lv1

# Can't convert  'writeback' cache
not lvconvert --thin --thinpool $vg/tpool $vg/$lv1

# Switch to 'writethrough' - this should be supported
lvchange --cachemode writethrough $vg/$lv1

# Check $lv1 remains mounted (so it's not been unmounted by systemd)
mountpoint "$PWD/mnt"

lvconvert --thin $vg/$lv1 --originname extorg --thinpool $vg/tpool

# check cache exist as extorg-real
check grep_dmsetup table  ${vg}-extorg-real "cache"


# Split cache from external origin (while in-use)
lvconvert --splitcache $vg/extorg

# check linear exist as extorg-real
check grep_dmsetup table  ${vg}-extorg-real "linear"
check lv_field $vg/extorg segtype linear

# Cache external origin in-use again
lvconvert -y -H $vg/extorg --cachepool $vg/cpool

get lv_field $vg/extorg attr | grep "^ori"

umount mnt

# Is filesystem still ok ?
fsck -n "$DM_DEV_DIR/$vg/$lv1"

lvchange -an $vg
lvchange -ay $vg

# Remove thin,   external origin remains
lvremove -f $vg/$lv1

#lvchange -prw  $vg/extorg
lvconvert --uncache $vg/extorg

lvremove -f $vg

#
# Check some more API variants
#

lvcreate -L10 -n pool $vg

lvcreate -aey -L2 -n $lv1 $vg
lvcreate -H -L2 $vg/$lv1

# Converts $vg/pool to thin-pool  AND  $vg/$lv1 to thin
lvconvert -y --type thin $vg/$lv1 --originname extorg --thinpool $vg/pool

check lv_field $vg/$lv1 segtype thin
check lv_field $vg/pool segtype thin-pool
check lv_field $vg/extorg segtype cache

lvconvert --uncache $vg/extorg

check lv_field $vg/extorg segtype linear

vgremove -ff $vg