Skip to contentSkip to conversation

master - lvcreate: new cache or writecache lv with single command

PATCH David Teigland 1 participant 1 message Jun 22, 2020

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=2aed2a41f7602e9168613a0c37d8dd557e7dba9b
Commit:        2aed2a41f7602e9168613a0c37d8dd557e7dba9b
Parent:        21b37964eb88d404998e37acae5530ec102a2116
Author:        David Teigland <[email protected]>
AuthorDate:    Fri Apr 10 13:17:37 2020 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Tue Jun 16 13:46:51 2020 -0500

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
---
 lib/metadata/metadata-exported.h |   1 +
 tools/args.h                     |   2 +-
 tools/command-lines.in           | 126 ++++++++++++++++-------------
 tools/command.c                  |   3 +
 tools/lvconvert.c                | 166 ++++++++++++++++++++++-----------------
 tools/lvcreate.c                 | 153 +++++++++++++++++++++++++++++++++++-
 tools/lvmcmdline.c               |   6 ++
 tools/tools.h                    |  11 +++
 8 files changed, 341 insertions(+), 127 deletions(-)
lib/metadata/metadata-exported.h +1 -0
index 0d6be136b..0cc5f37a0 100644
@@ -954,6 +954,7 @@ struct lvcreate_params {
 	int thin_chunk_size_calc_policy;
 	unsigned suppress_zero_warn : 1;
 	unsigned needs_lockd_init : 1;
+	unsigned ignore_type : 1;
 
 	const char *vg_name; /* only-used when VG is not yet opened (in /tools) */
 	const char *lv_name; /* all */
tools/args.h +1 -1
index c69a0ecce..3a7e5d488 100644
@@ -126,7 +126,7 @@ arg(cachepool_ARG, '\0', "cachepool", lv_VAL, 0, 0,
 arg(cachevol_ARG, '\0', "cachevol", lv_VAL, 0, 0,
     "The name of a cache volume.\n")
 
-arg(cachedevice_ARG, '\0', "cachedevice", pv_VAL, 0, 0,
+arg(cachedevice_ARG, '\0', "cachedevice", pv_VAL, ARG_GROUPABLE, 0,
     "The name of a device to use for a cache.\n")
 
 arg(cachesize_ARG, '\0', "cachesize", sizemb_VAL, 0, 0,
tools/command-lines.in +73 -53

160 lines not on this page · raw message

tools/command.c +3 -0
index 511dda13d..2d0184941 100644
@@ -1420,6 +1420,9 @@ int define_commands(struct cmd_context *cmdtool, const char *run_name)
 		if (line[0] == '\n')
 			break;
 
+		if (!strcmp(line, "---") || !strcmp(line, "--"))
+			continue;
+
 		if ((n = strchr(line, '\n')))
 			*n = '\0';
 
tools/lvconvert.c +94 -72

264 lines not on this page · raw message

tools/lvcreate.c +152 -1

162 lines not on this page · raw message

tools/lvmcmdline.c +6 -0
index 9c345bd99..7cf4e3ff0 100644
@@ -154,6 +154,12 @@ static const struct command_function _command_functions[CMD_COUNT] = {
 	/* lvconvert for integrity */
 	{ lvconvert_integrity_CMD, lvconvert_integrity_cmd },
 
+	/* lvcreate */
+	{ lvcreate_and_attach_cachevol_for_cache_CMD,		lvcreate_and_attach_cache_cmd },
+	{ lvcreate_and_attach_cachedevice_for_cache_CMD,	lvcreate_and_attach_cache_cmd },
+	{ lvcreate_and_attach_cachevol_for_writecache_CMD,	lvcreate_and_attach_writecache_cmd },
+	{ lvcreate_and_attach_cachedevice_for_writecache_CMD,	lvcreate_and_attach_writecache_cmd },
+
 	{ pvscan_display_CMD, pvscan_display_cmd },
 	{ pvscan_cache_CMD, pvscan_cache_cmd },
 };
tools/tools.h +11 -0
index 7f2434d06..c3d780d36 100644
@@ -278,7 +278,18 @@ int lvconvert_to_vdopool_param_cmd(struct cmd_context *cmd, int argc, char **arg
 
 int lvconvert_integrity_cmd(struct cmd_context *cmd, int argc, char **argv);
 
+int lvcreate_and_attach_writecache_cmd(struct cmd_context *cmd, int argc, char **argv);
+int lvcreate_and_attach_cache_cmd(struct cmd_context *cmd, int argc, char **argv);
+
 int pvscan_display_cmd(struct cmd_context *cmd, int argc, char **argv);
 int pvscan_cache_cmd(struct cmd_context *cmd, int argc, char **argv);
 
+
+int lvconvert_writecache_attach_single(struct cmd_context *cmd,
+                                        struct logical_volume *lv,
+                                        struct processing_handle *handle);
+int lvconvert_cachevol_attach_single(struct cmd_context *cmd,
+                                     struct logical_volume *lv,
+                                     struct processing_handle *handle);
+
 #endif