All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] bcache-tools: suport zoned device as making backing evice
@ 2020-05-16 14:09 Coly Li
  2020-05-16 14:09 ` [PATCH 1/3] bcache-tools: set zoned size aligned data_offset on backing device for zoned devive Coly Li
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Coly Li @ 2020-05-16 14:09 UTC (permalink / raw)
  To: linux-bcache; +Cc: linux-block, Coly Li

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

-- 
2.25.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] bcache-tools: set zoned size aligned data_offset on backing device for zoned devive
  2020-05-16 14:09 [PATCH 0/3] bcache-tools: suport zoned device as making backing evice Coly Li
@ 2020-05-16 14:09 ` Coly Li
  2020-05-16 14:09 ` [PATCH 2/3] bcache-tools: add is_zoned_device() Coly Li
  2020-05-16 14:09 ` [PATCH 3/3] bcache-tools: convert writeback to writethrough mode for zoned backing device Coly Li
  2 siblings, 0 replies; 4+ messages in thread
From: Coly Li @ 2020-05-16 14:09 UTC (permalink / raw)
  To: linux-bcache; +Cc: linux-block, Coly Li

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.

Signed-off-by: Coly Li <colyli@suse.de>
---
 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

diff --git a/Makefile b/Makefile
index 4359866..2c326cf 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/make.c b/make.c
index d46d925..c1090a6 100644
--- a/make.c
+++ b/make.c
@@ -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;
 }
diff --git a/zoned.c b/zoned.c
new file mode 100644
index 0000000..31c9136
--- /dev/null
+++ b/zoned.c
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * This file is part of bcache tools.
+ * Copyright (c) 2020 SUSE Software Solutions
+ *
+ * Authors: Coly Li <colyli@suse.de>
+ */
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libgen.h>
+
+#include "bcache.h"
+
+/*
+ * copied and modified from zonefs_get_dev_capacity() of
+ * zonefs-tools.
+ * returns   0: zone size 0 indicates a non-zoned device
+ *         > 0: actual zone size of the zoned device
+ */
+static size_t get_zone_size(char *devname)
+{
+	char str[128];
+	FILE *file;
+	int res;
+	size_t zone_size = 0;
+
+	snprintf(str, sizeof(str),
+		"/sys/block/%s/queue/chunk_sectors",
+		basename(devname));
+	file = fopen(str, "r");
+	if (!file)
+		goto out;
+
+	memset(str, 0, sizeof(str));
+	res = fscanf(file, "%s", str);
+	fclose(file);
+
+	if (res != 1)
+		goto out;
+
+	zone_size = atol(str);
+
+out:
+	return zone_size;
+}
+
+/*
+ * Update data_offset for zoned device, if the backing
+ * device is a zoned device,
+ * - just leave whole zone 0 to bcache super block on
+ *   backing device.
+ * - if data_offset is specified and larger than
+ *   BDEV_DATA_START_DEFAULT, then it should be a zone
+ *   size aligned value.
+ */
+void check_data_offset_for_zoned_device(char *devname,
+				       uint64_t *data_offset)
+{
+	uint64_t _data_offset = *data_offset;
+	size_t zone_size = get_zone_size(devname);
+
+	if (!zone_size)
+		return;
+
+	if (!_data_offset ||
+	    (_data_offset == BDEV_DATA_START_DEFAULT &&
+	     zone_size > BDEV_DATA_START_DEFAULT))
+		_data_offset = zone_size;
+
+	if (_data_offset < zone_size) {
+		fprintf(stderr,
+			"data_offset %lu should be larger than zone_size %lu for zoned device %s\n",
+			_data_offset, zone_size, devname);
+		exit(EXIT_FAILURE);
+	}
+
+	if (_data_offset & (zone_size - 1)) {
+		fprintf(stderr,
+			"data_offset %lu is not aligned to zone size %lu for zoned device %s\n",
+			_data_offset, zone_size, devname);
+	}
+
+	*data_offset = _data_offset;
+}
diff --git a/zoned.h b/zoned.h
new file mode 100644
index 0000000..1c5cce8
--- /dev/null
+++ b/zoned.h
@@ -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 <colyli@suse.de>
+ */
+#ifndef __ZONED_H
+#define __ZONED_H
+
+void check_data_offset_for_zoned_device(char *devname, uint64_t *data_offset);
+
+#endif
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] bcache-tools: add is_zoned_device()
  2020-05-16 14:09 [PATCH 0/3] bcache-tools: suport zoned device as making backing evice Coly Li
  2020-05-16 14:09 ` [PATCH 1/3] bcache-tools: set zoned size aligned data_offset on backing device for zoned devive Coly Li
@ 2020-05-16 14:09 ` Coly Li
  2020-05-16 14:09 ` [PATCH 3/3] bcache-tools: convert writeback to writethrough mode for zoned backing device Coly Li
  2 siblings, 0 replies; 4+ messages in thread
From: Coly Li @ 2020-05-16 14:09 UTC (permalink / raw)
  To: linux-bcache; +Cc: linux-block, Coly Li

This is a wrapper of get_zone_size(), to check whether a device is
zoned device or not by checking its chunk_sectors.

Signed-off-by: Coly Li <colyli@suse.de>
---
 zoned.c | 5 +++++
 zoned.h | 1 +
 2 files changed, 6 insertions(+)

diff --git a/zoned.c b/zoned.c
index 31c9136..d078286 100644
--- a/zoned.c
+++ b/zoned.c
@@ -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);
+}
diff --git a/zoned.h b/zoned.h
index 1c5cce8..25e5c91 100644
--- a/zoned.h
+++ b/zoned.h
@@ -9,5 +9,6 @@
 #define __ZONED_H
 
 void check_data_offset_for_zoned_device(char *devname, uint64_t *data_offset);
+int is_zoned_device(char *devname);
 
 #endif
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] bcache-tools: convert writeback to writethrough mode for zoned backing device
  2020-05-16 14:09 [PATCH 0/3] bcache-tools: suport zoned device as making backing evice Coly Li
  2020-05-16 14:09 ` [PATCH 1/3] bcache-tools: set zoned size aligned data_offset on backing device for zoned devive Coly Li
  2020-05-16 14:09 ` [PATCH 2/3] bcache-tools: add is_zoned_device() Coly Li
@ 2020-05-16 14:09 ` Coly Li
  2 siblings, 0 replies; 4+ messages in thread
From: Coly Li @ 2020-05-16 14:09 UTC (permalink / raw)
  To: linux-bcache; +Cc: linux-block, Coly Li

Currently 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.

Signed-off-by: Coly Li <colyli@suse.de>
---
 make.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/make.c b/make.c
index c1090a6..c5658ba 100644
--- a/make.c
+++ b/make.c
@@ -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;
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-16 14:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-16 14:09 [PATCH 0/3] bcache-tools: suport zoned device as making backing evice Coly Li
2020-05-16 14:09 ` [PATCH 1/3] bcache-tools: set zoned size aligned data_offset on backing device for zoned devive Coly Li
2020-05-16 14:09 ` [PATCH 2/3] bcache-tools: add is_zoned_device() Coly Li
2020-05-16 14:09 ` [PATCH 3/3] bcache-tools: convert writeback to writethrough mode for zoned backing device Coly Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.