Skip to contentSkip to conversation

bcache-tools: store meta data on NVDIMM

PATCH Superseded Coly Li 1 participant 7 messages Feb 6, 2021

Subsystems (3)

v1 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Coly Li

author
#0 lore raw

cover bcache-tools: store meta data on NVDIMM

This series is the first effort to support NVDIMM for bcache: store journal meta data on nvdimm namespace.

With this series, a NVDIMM namespace can be formatted as a bcache meta device with '-M' option. This meta device can be shared among multiple cache sets.

Except for adding BCH_FEATURE_INCOMPAT_NVDIMM_META to incompatible feature set, there is no on-disk layout change for supporting NVDIMM.

A new super block format struct bch_nvm_pages_sb is introduced for the NVDIMM meta-data device, it might be changed time-to-time before the EXPERIMENTAL removed from Linux kernel code.

This series is just enough to make things work, more changes will follow up to make more improvement later.

Coly Li
---

Coly Li (6):
bcache-tools: add initial data structures for nvm_pages
bcache-tools: reduce parameters of write_sb()
bcache-tools: add BCH_FEATURE_INCOMPAT_NVDIMM_META to incompatible
feature set
bcache-tools: move super block info display routines into show.c
bcache-tools: write nvm namespace super block on nvdimm
bcache-tools: support "bcache show -d" for nvdimm-meta device

 Makefile            |   2 +-
 bcache-super-show.c |  24 ----
 bcache.c            | 289 +--------------------------------------
 bcache.h            |   7 +-
 features.c          |   2 +
 lib.c               | 158 +++++++++++++++++++---
 lib.h               |  28 +++-
 make.c              | 244 +++++++++++++++++++++++++++++----
 nvm_pages.h         | 187 ++++++++++++++++++++++++++
 show.c              | 321 ++++++++++++++++++++++++++++++++++++++++++++
 show.h              |  10 ++
 11 files changed, 917 insertions(+), 355 deletions(-)
 create mode 100644 nvm_pages.h
 create mode 100644 show.c
 create mode 100644 show.h
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH 1/6 bcache-tools: add initial data structures for nvm_pages

This patch initializes the prototype data structures for nvm pages allocator,

- struct bch_nvm_pages_sb
This is the super block allocated on each nvmdimm name space. A nvdimm
set may have multiple namespaces, bch_nvm_pages_sb->set_uuid is used to mark which nvmdimm set this name space belongs to. Normally we will use the bcache's cache set UUID to initialize this uuid, to connect this nvdimm set to a specified bcache cache set.

- struct bch_owner_list_head
This is a table for all heads of all owner lists. A owner list records
which page(s) allocated to which owner. After reboot from power failure, the ownwer may find all its requested and allocated pages from the owner list by a handler which is converted by a UUID.

- struct bch_nvm_pages_owner_head
This is a head of an owner list. Each owner only has one owner list,
and a nvm page only belongs to an specific owner. uuid[] will be set to owner's uuid, for bcache it is the bcache's cache set uuid. label is not mandatory, it is a human-readable string for debug purpose. The pointer *recs references to separated nvm page which hold the table of struct bch_nvm_pgalloc_rec.

- struct bch_nvm_pgalloc_recs
This structure occupies a whole page, owner_uuid should match the uuid
in struct bch_nvm_pages_owner_head. recs[] is the real table contains all allocated records.

- struct bch_nvm_pgalloc_rec
Each structure records a range of allocated nvm pages. pgoff is offset
in unit of page size of this allocated nvm page range. The adjoint page ranges of same owner can be merged into a larger one, therefore pages_nr is NOT always power of 2.

---
 nvm_pages.h | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 187 insertions(+)
 create mode 100644 nvm_pages.h
nvm_pages.h new file +187 -0
new file mode 100644
index 0000000..1ed18a8
@@ -0,0 +1,187 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _BCACHE_NVM_PAGES_H
+#define _BCACHE_NVM_PAGES_H
+
+/*
+ * - struct bch_nvm_pages_sb
+ *   This is the super block allocated on each nvmdimm name space. A nvdimm
+ * set may have multiple namespaces, bch_nvm_pages_sb->set_uuid is used to
+ * mark which nvmdimm set this name space belongs to. Normally we will use
+ * the bcache's cache set UUID to initialize this uuid, to connect this nvdimm
+ * set to a specified bcache cache set.
+ *
+ * - struct bch_owner_list_head
+ *   This is a table for all heads of all owner lists. A owner list records
+ * which page(s) allocated to which owner. After reboot from power failure,
+ * the ownwer may find all its requested and allocated pages from the owner
+ * list by a handler which is converted by a UUID.
+ *
+ * - struct bch_nvm_pages_owner_head
+ *   This is a head of an owner list. Each owner only has one owner list,
+ * and a nvm page only belongs to an specific owner. uuid[] will be set to
+ * owner's uuid, for bcache it is the bcache's cache set uuid. label is not
+ * mandatory, it is a human-readable string for debug purpose. The pointer
+ * recs references to separated nvm page which hold the table of struct
+ * nvm_pgalloc_rec.
+ *
+ *- struct bch_nvm_pgalloc_recs
+ *  This structure occupies a whole page, owner_uuid should match the uuid
+ * in struct bch_nvm_pages_owner_head. recs[] is the real table contains all
+ * allocated records.
+ *
+ * - struct bch_nvm_pgalloc_rec
+ *   Each structure records a range of allocated nvm pages. pgoff is offset
+ * in unit of page size of this allocated nvm page range. The adjoint page
+ * ranges of same owner can be merged into a larger one, therefore pages_nr
+ * is NOT always power of 2.
+ *
+ *
+ * Memory layout on nvdimm namespace 0
+ *
+ *    0 +----------------------------+
+ *      |                            |
+ *  4KB +----------------------------+
+ *      |   bch_nvme_pages_sb        |
+ *  8KB +----------------------------+ <--- bch_nvme_pages_sb.owner_list_head
+ *      |   bch_owner_list_head      |
+ *      |                            |
+ * 16KB +----------------------------+ <--- bch_owner_list_head.heads[0].recs[0]
+ *      |   bch_nvm_pgalloc_recs     |
+ *      | (nvm pages internal usage) |
+ * 24KB +----------------------------+
+ *      |                            |
+ *      |                            |
+ * 1MB  +----------------------------+
+ *      |    allocable nvm pages     |
+ *      |    for buddy allocator     |
+ * end  +----------------------------+
+ *
+ *
+ *
+ * Memory layout on nvdimm namespace N
+ * (doesn't have owner list)
+ *
+ *    0 +----------------------------+
+ *      |                            |
+ *  4KB +----------------------------+
+ *      |     bch_nvme_pages_sb      |
+ *  8KB +----------------------------+
+ *      |                            |
+ *      |                            |
+ *      |                            |
+ *      |                            |
+ *      |                            |
+ *      |                            |
+ * 1MB  +----------------------------+
+ *      |    allocable nvm pages     |
+ *      |    for buddy allocator     |
+ * end  +----------------------------+
+ *
+
+ */
+
+#include <limits.h>
+#include <linux/types.h>
+
+/* In sectors */
+#define BCH_NVM_PAGES_SB_OFFSET			4096
+#define BCH_NVM_PAGES_OFFSET			(16 << 20)
+
+#define BCH_NVM_PAGES_LABEL_SIZE		32
+#define BCH_NVM_PAGES_NAMESPACES_MAX		8
+
+#define BCH_NVM_PAGES_OWNER_LIST_HEAD_OFFSET	(8<<10)
+#define BCH_NVM_PAGES_SYS_RECS_HEAD_OFFSET	(16<<10)
+
+#define BCH_NVM_PAGES_SB_VERSION		0
+#define BCH_NVM_PAGES_SB_VERSION_MAX		0
+
+static const char bch_nvm_pages_magic[] = {
+	0x17, 0xbd, 0x53, 0x7f, 0x1b, 0x23, 0xd6, 0x83,
+	0x46, 0xa4, 0xf8, 0x28, 0x17, 0xda, 0xec, 0xa9 };
+static const char bch_nvm_pages_pgalloc_magic[] = {
+	0x39, 0x25, 0x3f, 0xf7, 0x27, 0x17, 0xd0, 0xb9,
+	0x10, 0xe6, 0xd2, 0xda, 0x38, 0x68, 0x26, 0xae };
+
+struct bch_nvm_pgalloc_rec {
+	__u32			pgoff;
+	__u32			nr;
+};
+
+struct bch_nvm_pgalloc_recs {
+union {
+	struct {
+		struct bch_nvm_pages_owner_head	*owner;
+		struct bch_nvm_pgalloc_recs	*next;
+		__u8				magic[16];
+		__u8				owner_uuid[16];
+		__u32				size;
+		__u32				used;
+		__u64				_pad[4];
+		struct bch_nvm_pgalloc_rec	recs[];
+	};
+	__u8	pad[8192];
+};
+};
+
+struct bch_nvm_pages_owner_head {
+	__u8				uuid[16];
+	char				label[BCH_NVM_PAGES_LABEL_SIZE];
+	/* Per-namespace own lists */
+	struct bch_nvm_pgalloc_recs	*recs[BCH_NVM_PAGES_NAMESPACES_MAX];
+};
+
+/* heads[0] is always for nvm_pages internal usage */
+struct bch_owner_list_head {
+union {
+	struct {
+		__u32				size;
+		__u32				used;
+		__u64				_pad[4];
+		struct bch_nvm_pages_owner_head	heads[];
+	};
+	__u8	pad[8192];
+};
+};
+
+
+/* The on-media bit order is local CPU order */
+struct bch_nvm_pages_sb {
+	__u64			csum;
+	__u64			ns_start;
+	__u64			sb_offset;
+	__u64			version;
+	__u8			magic[16];
+	__u8			uuid[16];
+	__u32			page_size;
+	__u32			total_namespaces_nr;
+	__u32			this_namespace_nr;
+	union {
+		__u8		set_uuid[16];
+		__u64		set_magic;
+	};
+
+	__u64			flags;
+	__u64			seq;
+
+	__u64			feature_compat;
+	__u64			feature_incompat;
+	__u64			feature_ro_compat;
+
+	/* For allocable nvm pages from buddy systems */
+	__u64			pages_offset;
+	__u64			pages_total;
+
+	__u64			pad[8];
+
+	/* Only on the first name space */
+	struct bch_owner_list_head	*owner_list_head;
+
+	/* Just for csum_set() */
+	__u32			keys;
+	__u64			d[0];
+};
+
+
+#endif
Signature · 1 line
2.26.2
author
#2 lore raw

PATCH 2/6 bcache-tools: reduce parameters of write_sb()

In reply to Coly Li

There are 12 parameters in write_sb(), and in future there will be more paramerter added for new feature. In order to make the code more clear for adding more parameter, this patch introduces struct sb_context to hold most of these parameters, and send them into write_sb() via pointer of struct sb_context.

---
 make.c | 53 +++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 37 insertions(+), 16 deletions(-)
make.c +37 -16
index a3f97f6..e8840eb 100644
@@ -37,6 +37,19 @@
 #include "bitwise.h"
 #include "zoned.h"
 
+struct sb_context {
+	unsigned int	block_size;
+	unsigned int	bucket_size;
+	bool		writeback;
+	bool		discard;
+	bool		wipe_bcache;
+	unsigned int	cache_replacement_policy;
+	uint64_t	data_offset;
+	uuid_t		set_uuid;
+	char		*label;
+};
+
+
 #define max(x, y) ({				\
 	typeof(x) _max1 = (x);			\
 	typeof(y) _max2 = (y);			\
@@ -225,18 +238,21 @@ err:
 	return -1;
 }
 
-static void write_sb(char *dev, unsigned int block_size,
-			unsigned int bucket_size,
-			bool writeback, bool discard, bool wipe_bcache,
-			unsigned int cache_replacement_policy,
-			uint64_t data_offset,
-			uuid_t set_uuid, bool bdev, bool force, char *label)
+static void write_sb(char *dev, struct sb_context *sbc, bool bdev, bool force)
 {
 	int fd;
 	char uuid_str[40], set_uuid_str[40], zeroes[SB_START] = {0};
 	struct cache_sb_disk sb_disk;
 	struct cache_sb sb;
 	blkid_probe pr;
+	unsigned int block_size = sbc->block_size;
+	unsigned int bucket_size = sbc->bucket_size;
+	bool wipe_bcache = sbc->wipe_bcache;
+	bool writeback = sbc->writeback;
+	bool discard = sbc->discard;
+	char *label = sbc->label;
+	uint64_t data_offset = sbc->data_offset;
+	unsigned int cache_replacement_policy = sbc->cache_replacement_policy;
 
 	fd = open(dev, O_RDWR|O_EXCL);
 
@@ -338,7 +354,7 @@ static void write_sb(char *dev, unsigned int block_size,
 
 	memcpy(sb.magic, bcache_magic, 16);
 	uuid_generate(sb.uuid);
-	memcpy(sb.set_uuid, set_uuid, sizeof(sb.set_uuid));
+	memcpy(sb.set_uuid, sbc->set_uuid, sizeof(sb.set_uuid));
 
 	sb.block_size	= block_size;
 
@@ -510,6 +526,7 @@ int make_bcache(int argc, char **argv)
 	unsigned int cache_replacement_policy = 0;
 	uint64_t data_offset = BDEV_DATA_START_DEFAULT;
 	uuid_t set_uuid;
+	struct sb_context sbc;
 
 	uuid_generate(set_uuid);
 
@@ -626,20 +643,24 @@ int make_bcache(int argc, char **argv)
 					 get_blocksize(backing_devices[i]));
 	}
 
+	sbc.block_size = block_size;
+	sbc.bucket_size = bucket_size;
+	sbc.writeback = writeback;
+	sbc.discard = discard;
+	sbc.wipe_bcache = wipe_bcache;
+	sbc.cache_replacement_policy = cache_replacement_policy;
+	sbc.data_offset = data_offset;
+	memcpy(sbc.set_uuid, set_uuid, sizeof(sbc.set_uuid));
+	sbc.label = label;
+
 	for (i = 0; i < ncache_devices; i++)
-		write_sb(cache_devices[i], block_size, bucket_size,
-			 writeback, discard, wipe_bcache,
-			 cache_replacement_policy,
-			 data_offset, set_uuid, false, force, label);
+		write_sb(cache_devices[i], &sbc, false, force);
 
 	for (i = 0; i < nbacking_devices; i++) {
 		check_data_offset_for_zoned_device(backing_devices[i],
-						   &data_offset);
+						   &sbc.data_offset);
 
-		write_sb(backing_devices[i], block_size, bucket_size,
-			 writeback, discard, wipe_bcache,
-			 cache_replacement_policy,
-			 data_offset, set_uuid, true, force, label);
+		write_sb(backing_devices[i], &sbc, true, force);
 	}
 
 	return 0;
Signature · 1 line
2.26.2
author
#3 lore raw

PATCH 3/6 bcache-tools: add BCH_FEATURE_INCOMPAT_NVDIMM_META to incompatible feature set

In reply to Coly Li

A new incompatible feature bit BCH_FEATURE_INCOMPAT_NVDIMM_META is added into incompatible feature set. When "-M" or "--mdev" is specified to store cache device meta data on NVDIMM, this feature bit will be set on cache device's sb.feature_incompat. Then kernel code will know the journal and btree nodes are stored on nvdimm meta device.

---
 bcache.h   | 7 ++++++-
 features.c | 2 ++
 make.c     | 6 ++++++
 3 files changed, 14 insertions(+), 1 deletion(-)
bcache.h +6 -1
index 46d9683..2ae25ee 100644
@@ -203,7 +203,8 @@ uint64_t crc64(const void *data, size_t len);
 #define BCH_FEATURE_COMPAT_SUPP		0
 #define BCH_FEATURE_RO_COMPAT_SUPP	0
 #define BCH_FEATURE_INCOMPAT_SUPP	(BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET| \
-					 BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE)
+					 BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE| \
+					 BCH_FEATURE_INCOMPAT_NVDIMM_META)
 
 #define BCH_HAS_COMPAT_FEATURE(sb, mask) \
 		((sb)->feature_compat & (mask))
@@ -219,6 +220,9 @@ uint64_t crc64(const void *data, size_t len);
 #define BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET		0x0001
 /* real bucket size is (1 << bucket_size) */
 #define BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE	0x0002
+/* store bcache meta data on nvdimm */
+#define BCH_FEATURE_INCOMPAT_NVDIMM_META		0x0004
+
 
 #define BCH_FEATURE_COMPAT_FUNCS(name, flagname) \
 static inline int bch_has_feature_##name(struct cache_sb *sb) \
@@ -279,5 +283,6 @@ static inline void bch_clear_feature_##name(struct cache_sb *sb) \
 
 BCH_FEATURE_INCOMPAT_FUNCS(obso_large_bucket, OBSO_LARGE_BUCKET);
 BCH_FEATURE_INCOMPAT_FUNCS(large_bucket, LOG_LARGE_BUCKET_SIZE);
+BCH_FEATURE_INCOMPAT_FUNCS(nvdimm_meta, NVDIMM_META);
 
 #endif
features.c +2 -0
index f7f6224..7d9eff6 100644
@@ -24,6 +24,8 @@ static struct feature feature_list[] = {
 		"obso_large_bucket"},
 	{BCH_FEATURE_INCOMPAT, BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE,
 		"large_bucket"},
+	{BCH_FEATURE_INCOMPAT, BCH_FEATURE_INCOMPAT_NVDIMM_META,
+		"nvdimm_meta"},
 	{0, 0, 0 },
 };
 
make.c +6 -0
index e8840eb..5c2c1dd 100644
@@ -43,6 +43,7 @@ struct sb_context {
 	bool		writeback;
 	bool		discard;
 	bool		wipe_bcache;
+	bool		nvdimm_meta;
 	unsigned int	cache_replacement_policy;
 	uint64_t	data_offset;
 	uuid_t		set_uuid;
@@ -250,6 +251,7 @@ static void write_sb(char *dev, struct sb_context *sbc, bool bdev, bool force)
 	bool wipe_bcache = sbc->wipe_bcache;
 	bool writeback = sbc->writeback;
 	bool discard = sbc->discard;
+	bool nvdimm_meta = sbc->nvdimm_meta;
 	char *label = sbc->label;
 	uint64_t data_offset = sbc->data_offset;
 	unsigned int cache_replacement_policy = sbc->cache_replacement_policy;
@@ -398,6 +400,9 @@ static void write_sb(char *dev, struct sb_context *sbc, bool bdev, bool force)
 		       data_offset);
 		putchar('\n');
 	} else {
+		if (nvdimm_meta)
+			bch_set_feature_nvdimm_meta(&sb);
+
 		set_bucket_size(&sb, bucket_size);
 
 		sb.nbuckets		= getblocks(fd) / sb.bucket_size;
@@ -652,6 +657,7 @@ int make_bcache(int argc, char **argv)
 	sbc.data_offset = data_offset;
 	memcpy(sbc.set_uuid, set_uuid, sizeof(sbc.set_uuid));
 	sbc.label = label;
+	sbc.nvdimm_meta = (mdev == 1) ? true : false;
 
 	for (i = 0; i < ncache_devices; i++)
 		write_sb(cache_devices[i], &sbc, false, force);
Signature · 1 line
2.26.2
author
#4 lore raw

PATCH 4/6 bcache-tools: move super block info display routines into show.c

In reply to Coly Li

This patch moves the following routines from bcache.c into show.c,
- show_bdevs_detail()
- show_bdevs()
- detail_single()

As side effect, in order to fix the calling dependences, these routines are moved into lib.c,
- accepted_char()
- print_encode()
- free_dev()

Now following changes to show related routines won't make bcache.c more complicated.

---
 Makefile            |   2 +-
 bcache-super-show.c |  24 ----
 bcache.c            | 278 +-------------------------------------------
 lib.c               |  97 +++++++++++++---
 lib.h               |   3 +
 make.c              |   1 -
 show.c              | 277 +++++++++++++++++++++++++++++++++++++++++++
 show.h              |  10 ++
 8 files changed, 371 insertions(+), 321 deletions(-)
 create mode 100644 show.c
 create mode 100644 show.h
Makefile +1 -1
index d914200..5496c35 100644
@@ -39,4 +39,4 @@ bcache-register: bcache-register.o
 bcache: CFLAGS += `pkg-config --cflags blkid uuid`
 bcache: LDLIBS += `pkg-config --libs blkid uuid`
 bcache: CFLAGS += -std=gnu99
-bcache: crc64.o lib.o make.o zoned.o features.o
+bcache: crc64.o lib.o make.o zoned.o features.o show.o
bcache-super-show.c +0 -24
index cc36029..407f418 100644
@@ -33,30 +33,6 @@ static void usage()
 	fprintf(stderr, "Usage: bcache-super-show [-f] <device>\n");
 }
 
-
-static bool accepted_char(char c)
-{
-	if ('0' <= c && c <= '9')
-		return true;
-	if ('A' <= c && c <= 'Z')
-		return true;
-	if ('a' <= c && c <= 'z')
-		return true;
-	if (strchr(".-_", c))
-		return true;
-	return false;
-}
-
-static void print_encode(char* in)
-{
-	for (char* pos = in; *pos; pos++)
-		if (accepted_char(*pos))
-			putchar(*pos);
-		else
-			printf("%%%x", *pos);
-}
-
-
 int main(int argc, char **argv)
 {
 	bool force_csum = false;
bcache.c +1 -277

293 lines not on this page · raw message

lib.c +79 -18

131 lines not on this page · raw message

lib.h +3 -0
index 0357a11..4c8df97 100644
@@ -57,6 +57,9 @@ int cset_to_devname(struct list_head *head, char *cset, char *devname);
 struct cache_sb *to_cache_sb(struct cache_sb *sb, struct cache_sb_disk *sb_disk);
 struct cache_sb_disk *to_cache_sb_disk(struct cache_sb_disk *sb_disk,struct cache_sb *sb);
 void set_bucket_size(struct cache_sb *sb, unsigned int bucket_size);
+void free_dev(struct list_head *head);
+void print_encode(char *in);
+bool accepted_char(char c);
 
 #define DEVLEN sizeof(struct dev)
 
make.c +0 -1
index 5c2c1dd..92fe2a2 100644
@@ -657,7 +657,6 @@ int make_bcache(int argc, char **argv)
 	sbc.data_offset = data_offset;
 	memcpy(sbc.set_uuid, set_uuid, sizeof(sbc.set_uuid));
 	sbc.label = label;
-	sbc.nvdimm_meta = (mdev == 1) ? true : false;
 
 	for (i = 0; i < ncache_devices; i++)
 		write_sb(cache_devices[i], &sbc, false, force);
show.c new file +277 -0

277 lines not on this page · raw message

show.h new file +10 -0
new file mode 100644
index 0000000..5ab9933
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _BCH_MAKE_H
+#define _BCH_MAKE_H
+
+int show_bdevs_detail(void);
+int show_bdevs(void);
+int detail_single(char *devname);
+
+#endif
Signature · 1 line
2.26.2
author
#5 lore raw

PATCH 5/6 bcache-tools: write nvm namespace super block on nvdimm

In reply to Coly Li

This patch adds following option to "bcache make",

        -M, --mdev              Format a cache nvmdimm-meta device

This option is used to specify a nvdimm device to store bcache mata data. Once one or more nvdimm devices are specified as nvdimm-meta device, routine write_nvm_namespace_sb() will write their super block (defined by struct bch_nvm_pages_sb) into corresponding location on the nvdimm-meta device.

---
 bcache.c |   1 +
 make.c   | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 174 insertions(+), 11 deletions(-)
bcache.c +1 -0
index 5558914..def1e93 100644
@@ -19,6 +19,7 @@
 #include <assert.h>
 
 #include "features.h"
+#include "nvm_pages.h"
 #include "show.h"
 
 #define BCACHE_TOOLS_VERSION	"1.1"
make.c +173 -11

270 lines not on this page · raw message

Signature · 1 line
2.26.2
author
#6 lore raw

PATCH 6/6 bcache-tools: support "bcache show -d" for nvdimm-meta device

In reply to Coly Li

This patch adds support to display detail information of a nvdimm-meta device by command "bcache show -d".

struct mdev is added into lib.h to represent nvdimm-meta device information.

At this moment, commands "bcache show" and "bcache show -m" don't support nvdimm-meta device yet.

---
 bcache.c |  10 ++---
 lib.c    |  63 ++++++++++++++++++++++++++-
 lib.h    |  25 ++++++++++-
 make.c   |   2 +-
 show.c   | 128 +++++++++++++++++++++++++++++++++++++------------------
 5 files changed, 178 insertions(+), 50 deletions(-)
bcache.c +5 -5
index def1e93..044d401 100644
@@ -220,7 +220,7 @@ int attach_both(char *cdev, char *backdev)
 	int ret;
 	char buf[100];
 
-	ret = detail_dev(backdev, &bd, &cd, &type);
+	ret = detail_dev(backdev, &bd, &cd, NULL, &type);
 	if (ret != 0)
 		return ret;
 	if (type != BCACHE_SB_VERSION_BDEV
@@ -235,7 +235,7 @@ int attach_both(char *cdev, char *backdev)
 	}
 
 	if (strlen(cdev) != 36) {
-		ret = detail_dev(cdev, &bd, &cd, &type);
+		ret = detail_dev(cdev, &bd, &cd, NULL, &type);
 		if (type != BCACHE_SB_VERSION_CDEV
 		    && type != BCACHE_SB_VERSION_CDEV_WITH_UUID) {
 			fprintf(stderr, "%s is not an cache device\n", cdev);
@@ -349,7 +349,7 @@ int main(int argc, char **argv)
 		int type = 1;
 		int ret;
 
-		ret = detail_dev(devname, &bd, &cd, &type);
+		ret = detail_dev(devname, &bd, &cd, NULL, &type);
 		if (ret != 0)
 			return ret;
 		if (type == BCACHE_SB_VERSION_BDEV) {
@@ -394,7 +394,7 @@ int main(int argc, char **argv)
 		int type = 1;
 		int ret;
 
-		ret = detail_dev(devname, &bd, &cd, &type);
+		ret = detail_dev(devname, &bd, &cd, NULL, &type);
 		if (ret != 0) {
 			fprintf(stderr,
 			"This device doesn't exist or failed to receive info from this device\n");
@@ -420,7 +420,7 @@ int main(int argc, char **argv)
 		int type = 5;
 		int ret;
 
-		ret = detail_dev(devname, &bd, &cd, &type);
+		ret = detail_dev(devname, &bd, &cd, NULL, &type);
 		if (ret != 0) {
 			fprintf(stderr,
 		"This device doesn't exist or failed to receive info from this device\n");
lib.c +62 -1

88 lines not on this page · raw message

lib.h +24 -1
index 4c8df97..152d9e8 100644
@@ -43,9 +43,32 @@ struct cdev {
 	unsigned int	replacement;
 };
 
+struct mdev {
+	struct cache_sb		*sb;
+	uint64_t		csum;
+	uint64_t		ns_start;
+	uint64_t		sb_offset;
+	uint64_t		version;
+	char			*magic;
+	char			uuid[40];
+	uint32_t		page_size;
+	uint32_t		total_namespaces_nr;
+	uint32_t		this_namespace_nr;
+	union {
+		char		set_uuid[40];
+		uint64_t	set_magic;
+	};
+	uint64_t		seq;
+	char			bname[40];
+	uint64_t		feature_compat;
+	uint64_t		feature_ro_compat;
+	uint64_t		feature_incompat;
+	uint64_t		pages_offset;
+	uint64_t		pages_total;
+};
 
 int list_bdevs(struct list_head *head);
-int detail_dev(char *devname, struct bdev *bd, struct cdev *cd, int *type);
+int detail_dev(char *devname, struct bdev *bd, struct cdev *cd, struct mdev *md, int *type);
 int register_dev(char *devname);
 int stop_backdev(char *devname);
 int unregister_cset(char *cset);
make.c +1 -1
index 79ecada..447c946 100644
@@ -269,7 +269,7 @@ static void write_sb(char *dev, struct sb_context *sbc, bool bdev, bool force)
 			int type = 1;
 			int ret;
 
-			ret = detail_dev(dev, &bd, &cd, &type);
+			ret = detail_dev(dev, &bd, &cd, NULL, &type);
 			if (ret != 0)
 				exit(EXIT_FAILURE);
 			if (type == BCACHE_SB_VERSION_BDEV) {
show.c +86 -42

187 lines not on this page · raw message

Signature · 1 line
2.26.2