Bug 1805927

Summary: single command to add writecache to an LV
Product: Red Hat Enterprise Linux 8 Reporter: David Teigland <teigland>
Component: lvm2Assignee: David Teigland <teigland>
lvm2 sub component: Cache Logical Volumes QA Contact: cluster-qe <cluster-qe>
Status: CLOSED ERRATA Docs Contact:
Severity: unspecified    
Priority: unspecified CC: agk, cmarthal, heinzm, jbrassow, mcsontos, msnitzer, pasik, prajnoha, zkabelac
Version: 8.4Flags: pm-rhel: mirror+
Target Milestone: rc   
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: lvm2-2.03.09-3.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-11-04 02:00:25 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description David Teigland 2020-02-21 17:37:37 UTC
Description of problem:

Have a single command that can be used to add cache|writecache to an LV.

The two-step process involves:
1. creating a cachepool or cachevol LV
2. attaching the cachepool|cachevol to an existing LV to start caching.

A single command would create the cachepool|cachevol automatically (step 1), and then attach it to the existing LV (step 2.)

An lvcreate command already exists that creates a new cache-pool LV, and then attaches it to an existing LV using dm-cache: lvcreate --type cache --size SizeMB LV.
In this command "LV" already exists, and is converted to type cache after creating a new LV with type cache-pool.

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 2 David Teigland 2020-06-01 17:05:56 UTC
This comes in two parts/commits:
1. the ability to create a writecache|cache with a single command via lvconvert when the main LV already exists.
2. the ability to create a writecache|cache with a single command via lvcreate when the main LV does not yet exist.


PART 1
======

lvconvert: single step cachevol creation and attachment

To add a cache or writecache to a main LV with a single command:

lvconvert --type cache|writecache --cachedevice /dev/ssd vg/main

A cachevol LV will be allocated from the specified cache device,
then attached to the main LV.  Include --cachesize to specify the
size of cachevol to create, otherwise the entire cachedevice is
used.  The cachedevice option can be repeated to create a cachevol
from multiple devices.

Example
-------

A user has an existing main LV that they want to speed up
using a new ssd.

user adds the new ssd to the VG:

$ vgextend vg /dev/ssd

user attaches the new ssd their main LV:

$ lvconvert --type writecache --cachedevice /dev/ssd vg/main

Example
-------

A user has two existing main LVs that they want to speed up
with a new ssd.

user adds the new 16G ssd to the VG:

$ vgextend vg /dev/ssd

user attaches some of the new ssd to the first main LV,
using half of the space:

$ lvconvert --type writecache --cachedevice /dev/ssd
    --cachesize 8G vg/main1

user attaches some of the new ssd to the second main LV,
using the other half of the space:

$ lvconvert --type writecache --cachedevice /dev/ssd
    --cachesize 8G vg/main2

Example
-------

A user has an existing main LV that they want to speed up using
two new ssds.

user adds the new two ssds the VG:

$ vgextend vg /dev/ssd1
$ vgextend vg /dev/ssd2

user attaches both ssds their main LV:

$ lvconvert --type writecache
    --cachedevice /dev/ssd1 --cachedevice /dev/ssd2 vg/main


PART 2
======

lvcreate: new cache or writecache lv with single command

To create a new cache or writecache LV with a single command:

lvcreate --type cache|writecache
    -n Name -L Size --cachedevice PVfast VG [PVslow ...]

- A new main linear|striped LV is created as usual, using the
  specified -n Name and -L Size, and using the optionally
  specified PVslow devices.
- Then, a new cachevol LV is created internally, using PVfast
  specified by the cachedevice option.
- Then, the cachevol is attached to the main LV, converting the
  main LV to type cache|writecache.

Include --cachesize Size to specify the size of cache|writecache
to create from the specified --cachedevice PVs, otherwise the
entire cachedevice PV is used.  The --cachedevice option can be
repeated to create the cache from multiple devices, or the
cachedevice option can contain a tag name specifying a set of PVs
to allocate the cache from.

To create a new cache or writecache LV with a single command
using an existing cachevol LV:

lvcreate --type cache|writecache
    -n Name -L Size --cachevol LVfast VG [PVslow ...]

- A new main linear|striped LV is created as usual, using the
  specified -n Name and -L Size, and using the optionally
  specified PVslow devices.
- Then, the cachevol LVfast is attached to the main LV, converting
  the main LV to type cache|writecache.

In cases where more advanced types (for the main LV or cachevol LV)
are needed, they should be created independently and then combined
with lvconvert.

Example
-------

user creates a new VG with one slow device and one fast device:

$ vgcreate vg /dev/slow1 /dev/fast1

user creates a new 8G main LV on /dev/slow1 that uses all of
/dev/fast1 as a writecache:

$ lvcreate --type writecache --cachedevice /dev/fast1
    -n main -L 8G vg /dev/slow1

Example
-------

user creates a new VG with two slow devs and two fast devs:

$ vgcreate vg /dev/slow1 /dev/slow2 /dev/fast1 /dev/fast2

user creates a new 8G main LV on /dev/slow1 and /dev/slow2
that uses all of /dev/fast1 and /dev/fast2 as a writecache:

$ lvcreate --type writecache --cachedevice /dev/fast1 --cachedevice /dev/fast2
    -n main -L 8G vg /dev/slow1 /dev/slow2

Example
-------

A user has several slow devices and several fast devices in their VG,
the slow devs have tag @slow, the fast devs have tag @fast.

user creates a new 8G main LV on the slow devs with a
2G writecache on the fast devs:

$ lvcreate --type writecache -n main -L 8G
    --cachedevice @fast --cachesize 2G vg @slow

Comment 3 David Teigland 2020-06-22 16:42:01 UTC
pushed to master
https://sourceware.org/git?p=lvm2.git;a=commit;h=21b37964eb88d404998e37acae5530ec102a2116
https://sourceware.org/git?p=lvm2.git;a=commit;h=2aed2a41f7602e9168613a0c37d8dd557e7dba9b
https://sourceware.org/git?p=lvm2.git;a=commit;h=ae5634a8be3eedb556325a4b81540896fa6cac16
https://sourceware.org/git?p=lvm2.git;a=commit;h=3bd9d81b29fb8ba490d87b3557861bf00047855d

3bd9d81b29fb man: lvmcache info about cachedevice usage
ae5634a8be3e tests: cachevol-cachedevice
2aed2a41f760 lvcreate: new cache or writecache lv with single command
21b37964eb88 lvconvert: single step cachevol creation and attachment

Comment 6 Corey Marthaler 2020-07-24 21:19:03 UTC
Feature verified in the latest rpms.

kernel-4.18.0-221.el8    BUILT: Thu Jun 25 16:28:39 CDT 2020
lvm2-2.03.09-3.el8    BUILT: Mon Jun 29 13:50:23 CDT 2020
lvm2-libs-2.03.09-3.el8    BUILT: Mon Jun 29 13:50:23 CDT 2020
lvm2-dbusd-2.03.09-3.el8    BUILT: Mon Jun 29 13:53:38 CDT 2020
lvm2-lockd-2.03.09-3.el8    BUILT: Mon Jun 29 13:50:23 CDT 2020
device-mapper-1.02.171-3.el8    BUILT: Mon Jun 29 13:50:23 CDT 2020
device-mapper-libs-1.02.171-3.el8    BUILT: Mon Jun 29 13:50:23 CDT 2020
device-mapper-event-1.02.171-3.el8    BUILT: Mon Jun 29 13:50:23 CDT 2020
device-mapper-event-libs-1.02.171-3.el8    BUILT: Mon Jun 29 13:50:23 CDT 2020


SCENARIO - [single_cmd_conversion]
Create an existing origin volume with out a cache pool, and then convert it to a writecache volume in one command (RFE 1805927)

*** Writecache info for this scenario ***
*  origin (slow):  /dev/sdj1
*  pool (fast):    /dev/sdg1 /dev/sdf1
************************************

Adding "slow" and "fast" tags to corresponding pvs

Create origin (slow) volume
lvcreate --wipesignatures y  -L 10G -n single1 writecache_sanity @slow

Create origin (slow) volume
lvcreate --wipesignatures y  -L 10G -n single2 writecache_sanity @slow

Create origin (slow) volume
lvcreate --wipesignatures y  -L 10G -n single3 writecache_sanity @slow

Create origin (slow) volume
lvcreate --wipesignatures y  -L 10G -n single4 writecache_sanity @slow

** Single cmd (lvconvert) Check 1. Existing origin volume, non existent (single device) write cache pool **
lvconvert --type writecache --cachedevice /dev/sdg1 --cachesize 2G writecache_sanity/single1

** Single cmd (lvconvert) Check 2. Existing multiple origin volumes, non existent (single device) write cache pool **
lvconvert --type writecache --cachedevice /dev/sdg1 --cachesize 2G writecache_sanity/single2
lvconvert --type writecache --cachedevice /dev/sdg1 --cachesize 2G writecache_sanity/single3

** Single cmd (lvconvert) Check 3. Existing origin volume, non existent write cache pool (multiple devices) **
 Turned off due to bug 1855038

** Single cmd (lvcreate) Check 4. Non existing (single device) origin volume, non existent (single device) write cache pool **
lvcreate --type writecache --cachedevice /dev/sdg1 --cachesize 2G -n single5 -L 6G writecache_sanity /dev/sdj1

** Single cmd (lvcreate) Check 5. Non existing (mulitiple device) stripe origin volume, non existent (single device) write cache pool **
lvcreate --type writecache --cachedevice /dev/sdg1 --cachesize 2G -n single6 -L 6G -i 2  writecache_sanity /dev/sdj1 /dev/sdf1

[root@hayes-03 ~]# lvs -a -o +devices,segtype
  LV                   VG                Attr       LSize  Pool                 Origin           Data% Devices                       Type
  single1              writecache_sanity Cwi-a-C--- 10.00g [single1_cache_cvol] [single1_wcorig] 0.00  single1_wcorig(0)             writecache
  [single1_cache_cvol] writecache_sanity Cwi-aoC---  2.00g                                             /dev/sdl1(0)                  linear
  [single1_wcorig]     writecache_sanity owi-aoC--- 10.00g                                             /dev/sdi1(0)                  linear
  single2              writecache_sanity Cwi-a-C--- 10.00g [single2_cache_cvol] [single2_wcorig] 0.00  single2_wcorig(0)             writecache
  [single2_cache_cvol] writecache_sanity Cwi-aoC---  2.00g                                             /dev/sdl1(512)                linear
  [single2_wcorig]     writecache_sanity owi-aoC--- 10.00g                                             /dev/sdi1(2560)               linear
  single3              writecache_sanity Cwi-a-C--- 10.00g [single3_cache_cvol] [single3_wcorig] 0.00  single3_wcorig(0)             writecache
  [single3_cache_cvol] writecache_sanity Cwi-aoC---  2.00g                                             /dev/sdl1(1024)               linear
  [single3_wcorig]     writecache_sanity owi-aoC--- 10.00g                                             /dev/sdi1(5120)               linear
  single4              writecache_sanity -wi-a----- 10.00g                                             /dev/sdi1(7680)               linear
  single5              writecache_sanity Cwi-a-C---  6.00g [single5_cache_cvol] [single5_wcorig] 0.00  single5_wcorig(0)             writecache
  [single5_cache_cvol] writecache_sanity Cwi-aoC---  2.00g                                             /dev/sdl1(1536)               linear
  [single5_wcorig]     writecache_sanity owi-aoC---  6.00g                                             /dev/sdi1(10240)              linear
  single6              writecache_sanity Cwi-a-C---  6.00g [single6_cache_cvol] [single6_wcorig] 0.00  single6_wcorig(0)             writecache
  [single6_cache_cvol] writecache_sanity Cwi-aoC---  2.00g                                             /dev/sdl1(2048)               linear
  [single6_wcorig]     writecache_sanity owi-aoC---  6.00g                                             /dev/sdi1(11776),/dev/sde1(0) striped

Comment 9 errata-xmlrpc 2020-11-04 02:00:25 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (lvm2 bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:4546