bcache-tools: suport zoned device as making backing evice
Subsystems (3)
cover bcache-tools: suport zoned device as making backing evice
Hi folks,
This series is for bcache-tools to support making zoned device as bcache backing device.
There are two major ideas to support zoned device as bcache backing device,
- The super block data_offset should be aligned to zone size. By default the data_offset is set to 1 zone size for zoned backing device.
- Writeback mode is not supported yet. If the cache mode is explicitly set to writeback, print message to terminal to inform users that the cache mode is converted to wrightthough.
After the data_offset and cache mode is set properly, the rested stuffs for zoned device support are from bcache driver in Linux kernel.
Thanks for your review in advance.
Coly Li
---
Coly Li (3):
bcache-tools: set zoned size aligned data_offset on backing device for
zoned devive
bcache-tools: add is_zoned_device()
bcache-tools: convert writeback to writethrough mode for zoned backing
device
Makefile | 4 +-- make.c | 20 +++++++++++- zoned.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ zoned.h | 14 +++++++++ 4 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 zoned.c create mode 100644 zoned.h
Signature · 1 line
2.25.0
PATCH 1/3 bcache-tools: set zoned size aligned data_offset on backing device for zoned devive
If the backing device is a zoned device, e.g. host managed SMR hard drive, the data_offset of the backing device should be set to a zone size aligned value, this is necessary for the zoned device I/O LBA and length requirement.
This patch set the data_offset for zoned backing device by following rules,
- If no manually inputed data_offset specified, set it to default value:
- If BDEV_DATA_START_DEFAULT >= zone size and aligned to zone size, keep data_offset as BDEV_DATA_START_DEFAULT.
- If BDEV_DATA_START_DEFAULT < zone size, set data_offset to zone size.
- If data_offset is manually set, it must be a non-zero value aligned to zone size. Of cause it can be multiple zones size, but must be aligned to zone size.
This patch also creates a new zone.c and zone.h and places all the above zoned device related code there.
--- Makefile | 4 +-- make.c | 7 ++++- zoned.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ zoned.h | 13 +++++++++ 4 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 zoned.c create mode 100644 zoned.h
Makefile +2 -2
@@ -24,7 +24,7 @@ bcache-test: LDLIBS += `pkg-config --libs openssl` -lm 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 +make-bcache: make.o crc64.o lib.o zoned.o probe-bcache: LDLIBS += `pkg-config --libs uuid blkid` probe-bcache: CFLAGS += `pkg-config --cflags uuid blkid`
@@ -38,4 +38,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 +bcache: crc64.o lib.o make.o zoned.o
make.c +6 -1
@@ -35,6 +35,7 @@#include "bcache.h" #include "lib.h" #include "bitwise.h" +#include "zoned.h" #define max (x, y) ({ \ typeof(x) _max1 = (x); \
@@ -636,11 +637,15 @@ int make_bcache(int argc, char **argv) cache_replacement_policy, data_offset, set_uuid, false, force, label); -for (i =0 ; i < nbacking_devices; i++) +for (i =0 ; i < nbacking_devices; i++) { +check_data_offset_for_zoned_device (backing_devices[i], + &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); + }return 0 ; }
zoned.c new file +89 -0
89 lines not on this page · raw message
zoned.h new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* This file is part of bcache tools. +* Copyright (c) 2020 SUSE Software Solutions +* +* Authors: Coly Li <[email protected]> +*/ +#ifndef __ZONED_H +#define __ZONED_H + +void check_data_offset_for_zoned_device (char *devname,uint64_t *data_offset); + +#endif
Signature · 1 line
2.25.0
PATCH 2/3 bcache-tools: add is_zoned_device()
In reply to Coly LiThis is a wrapper of get_zone_size(), to check whether a device is zoned device or not by checking its chunk_sectors.
--- zoned.c | 5 +++++ zoned.h | 1 + 2 files changed, 6 insertions(+)
zoned.c +5 -0
@@ -87,3 +87,8 @@ void check_data_offset_for_zoned_device(char *devname, *data_offset = _data_offset; } + +int is_zoned_device (char *devname) +{ +return (get_zone_size (devname) !=0 ); +}
zoned.h +1 -0
@@ -9,5 +9,6 @@#define __ZONED_Hvoid check_data_offset_for_zoned_device (char *devname,uint64_t *data_offset); +int is_zoned_device (char *devname);#endif
Signature · 1 line
2.25.0
PATCH 3/3 bcache-tools: convert writeback to writethrough mode for zoned backing device
In reply to Coly LiCurrently bcache does not support writeback cache mode for zoned device as backing device.
If the backing device is zoned device, and cache mode is explicitly set to writeback mode, a information will be print to terminal,
"Zoned device <device name> detected: convert to writethrough mode."
Then the cache mode will be automatically converted to writethrough, which is the default cache mode of bcache-tools.
--- make.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
make.c +13 -0
@@ -378,6 +378,19 @@ static void write_sb(char *dev, unsigned int block_size,SET_BDEV_CACHE_MODE (&sb, writeback ?CACHE_MODE_WRITEBACK :CACHE_MODE_WRITETHROUGH ); +/* +* Currently bcache does not support writeback mode for +* zoned device as backing device. If the cache mode is +* explicitly set to writeback, automatically convert to +* writethough mode. +*/ +if (is_zoned_device (dev) && +BDEV_CACHE_MODE (&sb) ==CACHE_MODE_WRITEBACK ) { +printf ("Zoned device %s detected: convert to writethrough mode.\n" , + dev); +SET_BDEV_CACHE_MODE (&sb,CACHE_MODE_WRITETHROUGH ); + } +if (data_offset !=BDEV_DATA_START_DEFAULT ) { sb.version =BCACHE_SB_VERSION_BDEV_WITH_OFFSET ; sb.data_offset = data_offset;
Signature · 1 line
2.25.0