Skip to contentSkip to conversation

master - vdo: introduce segment types and manip functions

PATCH Zdenek Kabelac 1 participant 1 message Jul 9, 2018 Library code

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a8f84f78015326125c4884046014a5b93fded77f
Commit:        a8f84f78015326125c4884046014a5b93fded77f
Parent:        c66a960149ae28f057bc1a91d6974e92fc572c30
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Fri Jun 29 11:11:14 2018 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Mon Jul 9 15:28:35 2018 +0200

vdo: introduce segment types and manip functions

Core functionality introducing lvm VDO support.

---
 lib/Makefile.in                  |    5 +
 lib/activate/activate.h          |    1 +
 lib/activate/dev_manager.c       |    6 +-
 lib/commands/toolcontext.c       |    5 +
 lib/format_text/flags.c          |    3 +
 lib/metadata/lv.c                |    3 +
 lib/metadata/lv_manip.c          |   93 +++++++-
 lib/metadata/metadata-exported.h |   29 ++-
 lib/metadata/segtype.h           |   12 +
 lib/metadata/vdo_manip.c         |  269 +++++++++++++++++++++
 lib/misc/lvm-string.c            |    2 +
 lib/vdo/vdo.c                    |  484 ++++++++++++++++++++++++++++++++++++++
 12 files changed, 903 insertions(+), 9 deletions(-)
lib/Makefile.in +5 -0
index ead443e..737208b 100644
@@ -77,6 +77,7 @@ SOURCES =\
 	metadata/segtype.c \
 	metadata/snapshot_manip.c \
 	metadata/thin_manip.c \
+	metadata/vdo_manip.c \
 	metadata/vg.c \
 	mirror/mirrored.c \
 	misc/crc.c \
@@ -126,6 +127,10 @@ ifeq ("@BUILD_LVMLOCKD@", "yes")
 	locking/lvmlockd.c
 endif
 
+ifeq ("@VDO@", "internal")
+  SOURCES += vdo/vdo.c
+endif
+
 LIB_NAME = liblvm-internal
 LIB_STATIC = $(LIB_NAME).a
 
lib/activate/activate.h +1 -0
index 5d77f40..09cd688 100644
@@ -261,6 +261,7 @@ void fs_unlock(void);
 #define TARGET_NAME_STRIPED "striped"
 #define TARGET_NAME_THIN "thin"
 #define TARGET_NAME_THIN_POOL "thin-pool"
+#define TARGET_NAME_VDO "vdo"
 #define TARGET_NAME_ZERO "zero"
 
 #define MODULE_NAME_CLUSTERED_MIRROR "clog"
lib/activate/dev_manager.c +5 -1
index 3e4ec86..07fc93e 100644
@@ -45,7 +45,7 @@ typedef enum {
 } action_t;
 
 /* This list must match lib/misc/lvm-string.c:build_dm_uuid(). */
-const char *uuid_suffix_list[] = { "pool", "cdata", "cmeta", "tdata", "tmeta", NULL};
+const char *uuid_suffix_list[] = { "pool", "cdata", "cmeta", "tdata", "tmeta", "vdata", "vpool", NULL};
 
 struct dlid_list {
 	struct dm_list list;
@@ -275,6 +275,10 @@ static int _info_run(const char *dlid, struct dm_info *dminfo,
 		    (length > DM_THIN_MAX_METADATA_SIZE))
 			length = DM_THIN_MAX_METADATA_SIZE;
 
+		/* Uses virtual size with headers for VDO pool device */
+		if (lv_is_vdo_pool(seg_status->seg->lv))
+			length = get_vdo_pool_virtual_size(seg_status->seg);
+
 		do {
 			target = dm_get_next_target(dmt, target, &target_start,
 						    &target_length, &target_name, &target_params);
lib/commands/toolcontext.c +5 -0
index eb15581..ec44bdb 100644
@@ -1399,6 +1399,11 @@ static int _init_segtypes(struct cmd_context *cmd)
 		return 0;
 #endif
 
+#ifdef VDO_INTERNAL
+	if (!init_vdo_segtypes(cmd, &seglib))
+		return_0;
+#endif
+
 #ifdef HAVE_LIBDL
 	/* Load any formats in shared libs unless static */
 	if (!is_static() &&
lib/format_text/flags.c +3 -0
index 98894e7..6f5ff9f 100644
@@ -98,6 +98,9 @@ static const struct flag _lv_flags[] = {
 	{CACHE_POOL, NULL, 0},
 	{CACHE_POOL_DATA, NULL, 0},
 	{CACHE_POOL_METADATA, NULL, 0},
+	{LV_VDO, NULL, 0},
+	{LV_VDO_POOL, NULL, 0},
+	{LV_VDO_POOL_DATA, NULL, 0},
 	{LV_PENDING_DELETE, NULL, 0}, /* FIXME Display like COMPATIBLE_FLAG */
 	{LV_REMOVED, NULL, 0},
 	{0, NULL, 0}
lib/metadata/lv.c +3 -0
index 7ab06cb..cf6fafa 100644
@@ -797,6 +797,9 @@ const char *lv_layer(const struct logical_volume *lv)
 	if (lv_is_thin_pool(lv))
 		return "tpool";
 
+	if (lv_is_vdo_pool(lv))
+		return "vpool";
+
 	if (lv_is_origin(lv) || lv_is_external_origin(lv))
 		return "real";
 
lib/metadata/lv_manip.c +87 -6

188 lines not on this page · raw message

lib/metadata/metadata-exported.h +27 -2
index 501d0fa..4a9f2e0 100644
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2017 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2018 Red Hat, Inc. All rights reserved.
  *
  * This file is part of LVM2.
  *
@@ -145,7 +145,12 @@
 #define LV_RESHAPE		UINT64_C(0x1000000000000000)    /* Ongoing reshape (number of stripes, stripesize or raid algorithm change):
 								   used as SEGTYPE_FLAG to prevent activation on old runtime */
 #define LV_RESHAPE_DATA_OFFSET	UINT64_C(0x2000000000000000)    /* LV reshape flag data offset (out of place reshaping) */
-/* Next unused flag:		UINT64_C(0x8000000000000000)    */
+
+
+#define LV_VDO			UINT64_C(0x0000000020000000)    /* LV - Internal user only */
+#define LV_VDO_POOL		UINT64_C(0x0000000040000000)    /* LV - Internal user only */
+#define LV_VDO_POOL_DATA	UINT64_C(0x8000000000000000)    /* LV - Internal user only */
+
 
 /* Format features flags */
 #define FMT_SEGMENTS		0x00000001U	/* Arbitrary segment params? */
@@ -251,6 +256,11 @@
 #define lv_is_pool_metadata_spare(lv)	(((lv)->status & POOL_METADATA_SPARE) ? 1 : 0)
 #define lv_is_lockd_sanlock_lv(lv)	(((lv)->status & LOCKD_SANLOCK_LV) ? 1 : 0)
 
+#define lv_is_vdo(lv)		(((lv)->status & LV_VDO) ? 1 : 0)
+#define lv_is_vdo_pool(lv)	(((lv)->status & LV_VDO_POOL) ? 1 : 0)
+#define lv_is_vdo_pool_data(lv)	(((lv)->status & LV_VDO_POOL_DATA) ? 1 : 0)
+#define lv_is_vdo_type(lv)	(((lv)->status & (LV_VDO | LV_VDO_POOL | LV_VDO_POOL_DATA)) ? 1 : 0)
+
 #define lv_is_removed(lv)	(((lv)->status & LV_REMOVED) ? 1 : 0)
 
 /* Recognize component LV (matching lib/misc/lvm-string.c _lvname_has_reserved_component_string()) */
@@ -487,6 +497,10 @@ struct lv_segment {
 	const char *policy_name;		/* For cache_pool */
 	struct dm_config_node *policy_settings;	/* For cache_pool */
 	unsigned cleaner_policy;		/* For cache */
+
+	struct dm_vdo_target_params vdo_params;	/* For VDO-pool */
+	uint32_t vdo_pool_header_size;		/* For VDO-pool */
+	uint32_t vdo_pool_virtual_extents;	/* For VDO-pool */
 };
 
 #define seg_type(seg, s)	(seg)->areas[(s)].type
@@ -950,6 +964,7 @@ struct lvcreate_params {
 	uint32_t read_ahead; /* all */
 	int approx_alloc;     /* all */
 	alloc_policy_t alloc; /* all */
+	struct dm_vdo_target_params vdo_params; /* vdo */
 
 	struct dm_list tags;	/* all */
 
@@ -1232,6 +1247,16 @@ int lv_cache_remove(struct logical_volume *cache_lv);
 int wipe_cache_pool(struct logical_volume *cache_pool_lv);
 /* --  metadata/cache_manip.c */
 
+
+/* ++  metadata/vdo_manip.c */
+
+uint64_t get_vdo_pool_virtual_size(const struct lv_segment *vdo_pool_seg);
+struct logical_volume *convert_vdo_pool_lv(struct logical_volume *data_lv,
+					   const struct dm_vdo_target_params *vtp,
+					   uint32_t *virtual_extents);
+int get_vdo_write_policy(enum dm_vdo_write_policy *vwp, const char *policy);
+/* --  metadata/vdo_manip.c */
+
 struct logical_volume *find_pvmove_lv(struct volume_group *vg,
 				      struct device *dev, uint64_t lv_type);
 const struct logical_volume *find_pvmove_lv_in_lv(const struct logical_volume *lv);
lib/metadata/segtype.h +12 -0
index 5484c23..6fdf075 100644
@@ -69,6 +69,8 @@ struct dev_manager;
 
 #define SEG_STRIPED_TARGET	(1ULL << 39)
 #define SEG_LINEAR_TARGET	(1ULL << 40)
+#define SEG_VDO			(1ULL << 41)
+#define SEG_VDO_POOL		(1ULL << 42)
 
 #define SEG_UNKNOWN		(1ULL << 63)
 
@@ -83,6 +85,8 @@ struct dev_manager;
 #define SEG_TYPE_NAME_ERROR		"error"
 #define SEG_TYPE_NAME_FREE		"free"
 #define SEG_TYPE_NAME_ZERO		"zero"
+#define SEG_TYPE_NAME_VDO		"vdo"
+#define SEG_TYPE_NAME_VDO_POOL		"vdo-pool"
 #define SEG_TYPE_NAME_RAID		"raid"
 #define SEG_TYPE_NAME_RAID0		"raid0"
 #define SEG_TYPE_NAME_RAID0_META	"raid0_meta"
@@ -151,6 +155,8 @@ struct dev_manager;
 #define segtype_is_thin(segtype)	((segtype)->flags & (SEG_THIN_POOL|SEG_THIN_VOLUME) ? 1 : 0)
 #define segtype_is_thin_pool(segtype)	((segtype)->flags & SEG_THIN_POOL ? 1 : 0)
 #define segtype_is_thin_volume(segtype)	((segtype)->flags & SEG_THIN_VOLUME ? 1 : 0)
+#define segtype_is_vdo(segtype)		((segtype)->flags & SEG_VDO ? 1 : 0)
+#define segtype_is_vdo_pool(segtype)	((segtype)->flags & SEG_VDO_POOL ? 1 : 0)
 #define segtype_is_virtual(segtype)	((segtype)->flags & SEG_VIRTUAL ? 1 : 0)
 #define segtype_is_unknown(segtype)	((segtype)->flags & SEG_UNKNOWN ? 1 : 0)
 
@@ -202,6 +208,8 @@ struct dev_manager;
 #define seg_is_thin(seg)	segtype_is_thin((seg)->segtype)
 #define seg_is_thin_pool(seg)	segtype_is_thin_pool((seg)->segtype)
 #define seg_is_thin_volume(seg)	segtype_is_thin_volume((seg)->segtype)
+#define seg_is_vdo(seg)		segtype_is_vdo((seg)->segtype)
+#define seg_is_vdo_pool(seg)	segtype_is_vdo_pool((seg)->segtype)
 #define seg_is_virtual(seg)	segtype_is_virtual((seg)->segtype)
 #define seg_unknown(seg)	segtype_is_unknown((seg)->segtype)
 #define seg_can_split(seg)	segtype_can_split((seg)->segtype)
@@ -329,6 +337,10 @@ int init_thin_segtypes(struct cmd_context *cmd, struct segtype_library *seglib);
 int init_cache_segtypes(struct cmd_context *cmd, struct segtype_library *seglib);
 #endif
 
+#ifdef VDO_INTERNAL
+int init_vdo_segtypes(struct cmd_context *cmd, struct segtype_library *seglib);
+#endif
+
 #define CACHE_FEATURE_POLICY_MQ			(1U << 0)
 #define CACHE_FEATURE_POLICY_SMQ		(1U << 1)
 #define CACHE_FEATURE_METADATA2			(1U << 2)
lib/metadata/vdo_manip.c new file +269 -0

269 lines not on this page · raw message

lib/misc/lvm-string.c +2 -0
index 1e9af66..689a6b5 100644
@@ -258,6 +258,8 @@ char *build_dm_uuid(struct dm_pool *mem, const struct logical_volume *lv,
 			lv_is_thin_pool(lv) ? "pool" :
 			lv_is_thin_pool_data(lv) ? "tdata" :
 			lv_is_thin_pool_metadata(lv) ? "tmeta" :
+			lv_is_vdo_pool(lv) ? "vpool" :
+			lv_is_vdo_pool_data(lv) ? "vdata" :
 			NULL;
 	}
 
lib/vdo/vdo.c new file +484 -0

484 lines not on this page · raw message