bcache-tools: changes for large bucket size
Subsystems (3)
cover bcache-tools: changes for large bucket size
These are user space tools changes necessary for bcache large bucket size. When setting bucket size with '-u' larger than 16MB for cache device, BCACHE_SB_VERSION_CDEV_WITH_FEATURES will be set automatically. Otherwise, the new added members in super block won't be touched.
Coly Li
---
Coly Li (4):
bcache-tools: comments offset for members of struct cache_sb
struct_offset: print offset of each member of the on-disk data
structure
bcache-tools: The new super block version
BCACHE_SB_VERSION_BDEV_WITH_FEATURES
bcache-tools: add large_bucket incompat feature
Makefile | 6 +- bcache.h | 153 ++++++++++++++++++++++++++++++++++++++---------- features.c | 24 ++++++++ lib.c | 24 ++++++++ lib.h | 2 + make.c | 36 ++++++++---- struct_offset.c | 63 ++++++++++++++++++++ 7 files changed, 265 insertions(+), 43 deletions(-) create mode 100644 features.c create mode 100644 struct_offset.c
Signature · 1 line
2.26.2
RFC PATCH 1/4 bcache-tools: comments offset for members of struct cache_sb
This patch adds code comments to mark the offset of each member from struct cache_sb. It is helpful for understand the super block on disk.
--- bcache.h | 64 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 30 deletions(-)
bcache.h +34 -30
@@ -41,54 +41,58 @@ static const char bcache_magic[] = {#define SB_START (SB_SECTOR * 512)struct cache_sb { -uint64_t csum; -uint64_t offset;/* sector where this sb was written */ -uint64_t version; +/*000*/ uint64_t csum; +/* sector where this sb was written */ +/*008*/ uint64_t offset; +/*010*/ uint64_t version; -uint8_t magic[16 ]; +/*018*/ uint8_t magic[16 ]; -uint8_t uuid[16 ]; +/*028*/ uint8_t uuid[16 ];union { -uint8_t set_uuid[16 ]; -uint64_t set_magic; +/*038*/ uint8_t set_uuid[16 ]; +/*038*/ uint64_t set_magic; }; -uint8_t label[SB_LABEL_SIZE ]; +/*048*/ uint8_t label[SB_LABEL_SIZE ]; -uint64_t flags; -uint64_t seq; -uint64_t pad[8 ]; +/*068*/ uint64_t flags; +/*070*/ uint64_t seq; +/*078*/ uint64_t pad[8 ];union {struct { -/* Cache devices */ -uint64_t nbuckets;/* device size */ +/* Cache devices */ +/*0b8*/ uint64_t nbuckets;/* device size */ -uint16_t block_size;/* sectors */ -uint16_t bucket_size;/* sectors */ +/*0c0*/ uint16_t block_size;/* sectors */ +/*0c2*/ uint16_t bucket_size;/* sectors */ -uint16_t nr_in_set; -uint16_t nr_this_dev; +/*0c4*/ uint16_t nr_in_set; +/*0c6*/ uint16_t nr_this_dev; };struct { -/* Backing devices */ -uint64_t data_offset; - -/* -* block_size from the cache device section is still used by -* backing devices, so don't add anything here until we fix -* things to not need it for backing devices anymore -*/ +/* Backing devices */ +/*0b8*/ uint64_t data_offset; + +/* +* block_size from the cache device section is still +* used by backing devices, so don't add anything here +* until we fix things to not need it for backing +* devices anymore +*/ }; }; -uint32_t last_mount;/* time_t */ +/*0c8*/ uint32_t last_mount;/* time_t */ -uint16_t first_bucket; +/*0cc*/ uint16_t first_bucket;union { -uint16_t njournal_buckets; -uint16_t keys; +/*0ce*/ uint16_t njournal_buckets; +/*0ce*/ uint16_t keys; }; -uint64_t d[SB_JOURNAL_BUCKETS ];/* journal buckets */ +/* journal buckets */ +/*0d0*/ uint64_t d[SB_JOURNAL_BUCKETS ]; +/*8d0*/ };static inline bool SB_IS_BDEV (const struct cache_sb *sb)
Signature · 1 line
2.26.2
RFC PATCH 2/4 struct_offset: print offset of each member of the on-disk data structure
In reply to Coly LiThis is a helper small program to print out the offset in bytes of each member of the on-disk data structure. Currently the member print lines are coded manually, hope latter it can be more intelligent to avoid the hard code.
--- Makefile | 4 +++- struct_offset.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 struct_offset.c
Makefile +3 -1
@@ -5,7 +5,7 @@ DRACUTLIBDIR=/lib/dracut INSTALL=install CFLAGS+=-O2 -Wall -g -all: make-bcache probe-bcache bcache-super-show bcache-register bcache +all: make-bcache probe-bcache bcache-super-show bcache-register bcache struct_offset install: make-bcache probe-bcache bcache-super-show $(INSTALL) -m0755 make-bcache bcache-super-show bcache $(DESTDIR)${PREFIX}/sbin/
@@ -22,6 +22,8 @@ clean: bcache-test: LDLIBS += `pkg-config --libs openssl` -lm +struct_offset: struct_offset.o + make-bcache: LDLIBS += `pkg-config --libs uuid blkid smartcols` make-bcache: CFLAGS += `pkg-config --cflags uuid blkid smartcols` make-bcache: make.o crc64.o lib.o zoned.o
struct_offset.c new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.26.2
RFC PATCH 3/4 bcache-tools: The new super block version BCACHE_SB_VERSION_BDEV_WITH_FEATURES
In reply to Coly LiThe new super block version BCACHE_SB_VERSION_BDEV_WITH_FEATURES value is 5, both cache device and backing device share this version number.
Devices have super block version equal to the new version will have three new members,
/*078*/ uint64_t feature_compat; /*080*/ uint64_t feature_incompat; /*088*/ uint64_t feature_ro_compat;
They are used for further new features which may introduce on-disk format change, the very basic features handling code skeleton is also initialized in this patch.
--- Makefile | 2 +- bcache.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++-- features.c | 22 +++++++++++++ make.c | 8 +++++ struct_offset.c | 2 +- 5 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 features.c
Makefile +1 -1
@@ -40,4 +40,4 @@ bcache-register: bcache-register.o bcache: CFLAGS += `pkg-config --cflags blkid uuid smartcols` bcache: LDLIBS += `pkg-config --libs blkid uuid smartcols` bcache: CFLAGS += -std=gnu99 -bcache: crc64.o lib.o make.o zoned.o +bcache: crc64.o lib.o make.o zoned.o features.o
bcache.h +81 -2
104 lines not on this page · raw message
features.c new file +22 -0
@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Author: Coly Li <[email protected]> +* +* Inspired by e2fsprogs features compat/incompat/ro_compat +* related code. +*/ +#include <stdbool.h> +#include <stdint.h> +#include <sys/types.h> + +#include "bcache.h" + +struct feature { +int compat; +unsigned int mask; +const char *string; +}; + +static struct feature feature_list[] = { + {0 ,0 ,0 }, +};
make.c +8 -0
@@ -250,6 +250,14 @@ static void swap_sb(struct cache_sb *sb, int write_cdev_super)/* Backing devices */ sb->data_offset =cpu_to_le64 (sb->data_offset); } + +/* Convert feature set and version at last */ +if (sb->version >=BCACHE_SB_VERSION_CDEV_WITH_FEATURES ) { + sb->feature_compat =cpu_to_le64 (sb->feature_compat); + sb->feature_incompat =cpu_to_le64 (sb->feature_incompat); + sb->feature_ro_compat =cpu_to_le64 (sb->feature_ro_compat); + } + sb->version =cpu_to_le64 (sb->version); } static void write_sb(char *dev, unsigned int block_size,
struct_offset.c +1 -1
@@ -52,7 +52,7 @@ void print_cache_sb()printf ("/* %3.3lx */ uint16_t keys;\n" ,OFF_SB (keys));printf (" };\n" );printf ("/* %3.3lx */ uint64_t d[%u];\n" ,OFF_SB (d),SB_JOURNAL_BUCKETS ); -printf ("/* %3.3lx */ }\n" ,OFF_SB (d) +sizeof (uint64_t ) *SB_JOURNAL_BUCKETS ); +printf ("/* %3.3lx */ }\n" ,sizeof (struct cache_sb )); }int main (int argc,char *argv[])
Signature · 1 line
2.26.2
RFC PATCH 4/4 bcache-tools: add large_bucket incompat feature
In reply to Coly LiThis feature adds uint32_t bucket_size_hi into struct cache_sb, permit bucket size to be 32bit width. Current maximum bucket size is 32MB, extend it to 32bits will permit much large bucket size which is desired by zoned SSD devices (a typical zone size is 256MB).
When setting a bucket size > 32MB, large_bucket feature will be set automatically and the super block version will also be set to BCACHE_SB_VERSION_CDEV_WITH_FEATURES.
--- bcache.h | 10 +++++++++- features.c | 2 ++ lib.c | 24 ++++++++++++++++++++++++ lib.h | 2 ++ make.c | 28 ++++++++++++++++++---------- struct_offset.c | 1 + 6 files changed, 56 insertions(+), 11 deletions(-)
bcache.h +9 -1
@@ -101,7 +101,8 @@ struct cache_sb { };/* journal buckets */ /*0d0*/ uint64_t d[SB_JOURNAL_BUCKETS ]; -/*8d0*/ +/*8d0*/ uint32_t bucket_size_hi; +/*8d4*/ };static inline bool SB_IS_BDEV (const struct cache_sb *sb)
@@ -155,6 +156,11 @@ uint64_t crc64(const void *data, size_t len);/* Feature set definition */ +/* Feature set definition */ + +/* Incompat feature set */ +#define BCH_FEATURE_INCOMPAT_LARGE_BUCKET 0x0001/* 32bit bucket size */ +#define BCH_FEATURE_COMPAT_FUNCS (name, flagname) \ static inline int bch_has_feature_##name(struct cache_sb *sb) \ { \
@@ -206,4 +212,6 @@ static inline void bch_clear_feature_##name(struct cache_sb *sb) \ ~BCH##_FEATURE_INCOMPAT_##flagname; \ } +BCH_FEATURE_INCOMPAT_FUNCS (large_bucket,LARGE_BUCKET ); +#endif
features.c +2 -0
@@ -18,5 +18,7 @@ struct feature { };static struct feature feature_list[] = { + {BCH_FEATURE_COMPAT ,BCH_FEATURE_INCOMPAT_LARGE_BUCKET , +"large_bucket" }, {0 ,0 ,0 }, };
lib.c +24 -0
@@ -4,6 +4,7 @@#include <stdbool.h> #include <blkid.h> #include <dirent.h> +#include <limits.h> #include <sys/types.h> #include <unistd.h> #include <stdio.h>
@@ -681,3 +682,26 @@ int set_label(char *devname, char *label)close (fd);return 0 ; } + +void set_bucket_size (struct cache_sb *sb,unsigned int bucket_size) +{ +if (bucket_size >USHRT_MAX ) { + sb->version =BCACHE_SB_VERSION_CDEV_WITH_FEATURES ; +bch_set_feature_large_bucket (sb); + sb->bucket_size = (uint16_t )bucket_size; + sb->bucket_size_hi = (uint32_t )(bucket_size >>16 ); + }else { + sb->bucket_size = bucket_size; + } +} + +unsigned int get_bucket_size (struct cache_sb *sb) +{ +unsigned int bucket_size = sb->bucket_size; + +if (sb->version >=BCACHE_SB_VERSION_CDEV_WITH_FEATURES && +bch_has_feature_large_bucket (sb)) + bucket_size |= sb->bucket_size_hi <<16 ; + +return bucket_size; +}
lib.h +2 -0
@@ -50,6 +50,8 @@ int detach_backdev(char *devname);int set_backdev_cachemode (char *devname,char *cachemode);int set_label (char *devname,char *label);int cset_to_devname (struct list_head *head,char *cset,char *devname); +void set_bucket_size (struct cache_sb *sb,unsigned int bucket_size); +unsigned int get_bucket_size (struct cache_sb *sb);#define DEVLEN sizeof(struct dev)
make.c +18 -10
@@ -83,7 +83,9 @@ uint64_t hatoi(const char *s)return i; } -unsigned int hatoi_validate (const char *s,const char *msg) +unsigned int hatoi_validate (const char *s, +const char *msg, +unsigned long max) {uint64_t v =hatoi (s);
@@ -94,7 +96,7 @@ unsigned int hatoi_validate(const char *s, const char *msg) v /=512 ; -if (v >USHRT_MAX ) { +if (v > max) {fprintf (stderr,"%s too large\n" , msg);exit (EXIT_FAILURE ); }
@@ -229,7 +231,6 @@ static void swap_sb(struct cache_sb *sb, int write_cdev_super)/* swap to little endian byte order to write */ sb->offset =cpu_to_le64 (sb->offset); - sb->version =cpu_to_le64 (sb->version); sb->flags =cpu_to_le64 (sb->flags); sb->seq =cpu_to_le64 (sb->seq); sb->last_mount =cpu_to_le32 (sb->last_mount);
@@ -244,6 +245,9 @@ static void swap_sb(struct cache_sb *sb, int write_cdev_super)/* Cache devices */ sb->nbuckets =cpu_to_le64 (sb->nbuckets); sb->bucket_size =cpu_to_le16 (sb->bucket_size); +if (sb->version >=BCACHE_SB_VERSION_CDEV_WITH_FEATURES && +bch_has_feature_large_bucket (sb)) + sb->bucket_size_hi =cpu_to_le32 (sb->bucket_size_hi); sb->nr_in_set =cpu_to_le16 (sb->nr_in_set); sb->nr_this_dev =cpu_to_le16 (sb->nr_this_dev); }else {
@@ -374,7 +378,7 @@ static void write_sb(char *dev, unsigned int block_size,uuid_generate (sb.uuid);memcpy (sb.set_uuid, set_uuid,sizeof (sb.set_uuid)); - sb.bucket_size = bucket_size; +set_bucket_size (&sb, bucket_size); sb.block_size = block_size;uuid_unparse (sb.uuid, uuid_str);
@@ -400,7 +404,8 @@ static void write_sb(char *dev, unsigned int block_size, }if (data_offset !=BDEV_DATA_START_DEFAULT ) { - sb.version =BCACHE_SB_VERSION_BDEV_WITH_OFFSET ; +if (sb.version <BCACHE_SB_VERSION_BDEV_WITH_OFFSET ) + sb.version =BCACHE_SB_VERSION_BDEV_WITH_OFFSET ; sb.data_offset = data_offset; }
@@ -418,9 +423,10 @@ static void write_sb(char *dev, unsigned int block_size, data_offset);putchar ('\n' ); }else { - sb.nbuckets =getblocks (fd) / sb.bucket_size; + sb.nbuckets =getblocks (fd) /get_bucket_size (&sb); sb.nr_in_set =1 ; - sb.first_bucket = (23 / sb.bucket_size) +1 ; +/* 23 is (SB_SECTOR + SB_SIZE) - 1 sectors */ + sb.first_bucket = (23 /get_bucket_size (&sb)) +1 ;if (sb.nbuckets <1 <<7 ) { fprintf(stderr, "Not enough buckets: %ju, need %u\n",
@@ -447,7 +453,7 @@ static void write_sb(char *dev, unsigned int block_size, (unsigned int ) sb.version, sb.nbuckets, sb.block_size, - sb.bucket_size, +get_bucket_size (&sb), sb.nr_in_set, sb.nr_this_dev, sb.first_bucket);
@@ -576,10 +582,12 @@ int make_bcache(int argc, char **argv) bdev =1 ;break ;case 'b' : - bucket_size =hatoi_validate (optarg,"bucket size" ); + bucket_size = +hatoi_validate (optarg,"bucket size" ,UINT_MAX );break ;case 'w' : - block_size =hatoi_validate (optarg,"block size" ); + block_size = +hatoi_validate (optarg,"block size" ,USHRT_MAX );break ;#if 0 case 'U' :
struct_offset.c +1 -0
@@ -52,6 +52,7 @@ void print_cache_sb()printf ("/* %3.3lx */ uint16_t keys;\n" ,OFF_SB (keys));printf (" };\n" );printf ("/* %3.3lx */ uint64_t d[%u];\n" ,OFF_SB (d),SB_JOURNAL_BUCKETS ); +printf ("/* %3.3lx */ uint32_t bucket_size_hi;\n" ,OFF_SB (bucket_size_hi));printf ("/* %3.3lx */ }\n" ,sizeof (struct cache_sb )); }
Signature · 1 line
2.26.2