Skip to contentSkip to conversation

Block layer support ZAC/ZBC commands

PATCH Superseded Shaun Tancheff 2 participants 5 messages Jun 19, 2016

Subsystems (3)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover Block layer support ZAC/ZBC commands

Hi Jens,

This series is on linux-next tag next-20160617.

As Host Aware drives are becoming available we would like to be able to make use of such drives. This series is also intended to be suitable for use by Host Managed drives.

ZAC/ZBC drives add new commands for discovering and working with Zones.

This extends the ZAC/ZBC support up to the block layer.

Patches for util-linux can be found here:
https://github.com/Seagate/ZDM-Device-Mapper/tree/master/patches/util-linux

Using BIOs to issue ZBC commands allows DM targets (such as ZDM) or file-systems such as f2fs, btrfs or nilfs2 to extend their block allocation schemes and/or issue discards that are zone aligned.

A perhaps non-obvious approach is that a conventional drive will returns a zone report descriptor with a single large conventional zone.

v4:
- Rebase on linux-next tag next-20160617.
- Change bio flags to bio op's
- Dropped ata16 hackery
V3:
- Rebase on Mike Cristie's separate bio operations
- Update blkzoned_api.h to include report zones PARTIAL bit.
- Use zoned report reserved bit for ata-passthrough flag.

V2:
- Changed bi_rw to op_flags clarify sepeartion of bio op from flags.
- Fixed memory leak in blkdev_issue_zone_report failing to put_bio().
- Documented opt in blkdev_issue_zone_report.
- Moved include/uapi/linux/fs.h changes to patch 3
- Fixed commit message for first patch in series.

Shaun Tancheff (2):
Add bio/request flags for using ZBC/ZAC commands Add ioctl to issue ZBC/ZAC commands via block layer

 MAINTAINERS                       |   9 ++
 block/blk-lib.c                   |  97 +++++++++++++++++
 block/ioctl.c                     | 110 +++++++++++++++++++
 drivers/scsi/sd.c                 | 122 +++++++++++++++++++++
 drivers/scsi/sd.h                 |   1 +
 include/linux/bio.h               |   7 +-
 include/linux/blk_types.h         |   6 +-
 include/linux/blkzoned_api.h      |  25 +++++
 include/uapi/linux/Kbuild         |   1 +
 include/uapi/linux/blkzoned_api.h | 220 ++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/fs.h           |   1 +
 11 files changed, 597 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/blkzoned_api.h
 create mode 100644 include/uapi/linux/blkzoned_api.h
Signature · 1 line
2.8.1
#1 lore raw

PATCH v4 1/2 Add bio/request flags for using ZBC/ZAC commands

T10 ZBC and T13 ZAC specify operations for Zoned devices.

To be able to access the zone information and open and close zones adding op's for:
- Report zones command: REQ_OP_ZONE_REPORT
- Open zone: REQ_OP_ZONE_OPEN
- Close zone: REQ_OP_ZONE_CLOSE
- Reset Write Pointer: REQ_OP_ZONE_RESET
to be used to create struct bio / struct request to issue ZBC commands.

Report zones is a device read that requires a buffer. Open, Close and Reset are device commands that have no associated data transfer.

The Finish zone command is intentionally not implimented as there is no current use case for that operation.

Report zones currently defaults to reporting on all zones. It expected that support for the zone option flag will piggy back on streamid support. The report option flag is useful as it can reduce the number of zones in each report, but not critical.

---
v4:
- Rebase on linux-next tag next-20160617.
- Change bio flags to bio op's
V3:
- Rebase on Mike Cristie's separate bio operations
- Update blkzoned_api.h to include report zones PARTIAL bit.
V2:
- Changed bi_rw to op_flags clarify sepeartion of bio op from flags.
- Fixed memory leak in blkdev_issue_zone_report failing to put_bio().
- Documented opt in blkdev_issue_zone_report.
- Removed include/uapi/linux/fs.h from this patch.

---
 MAINTAINERS                       |   9 ++
 block/blk-lib.c                   |  97 +++++++++++++++++
 drivers/scsi/sd.c                 | 122 ++++++++++++++++++++++
 drivers/scsi/sd.h                 |   1 +
 include/linux/bio.h               |   7 +-
 include/linux/blk_types.h         |   6 +-
 include/linux/blkzoned_api.h      |  25 +++++
 include/uapi/linux/Kbuild         |   1 +
 include/uapi/linux/blkzoned_api.h | 214 ++++++++++++++++++++++++++++++++++++++
 9 files changed, 480 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/blkzoned_api.h
 create mode 100644 include/uapi/linux/blkzoned_api.h
MAINTAINERS +9 -0
index d174e34..280f87b 100644
@@ -12815,6 +12815,15 @@ F:	Documentation/networking/z8530drv.txt
 F:	drivers/net/hamradio/*scc.c
 F:	drivers/net/hamradio/z8530.h
 
+ZBC AND ZBC BLOCK DEVICES
+M:	Shaun Tancheff <[email protected]>
+W:	http://seagate.com
+W:	https://github.com/Seagate/ZDM-Device-Mapper
+L:	[email protected]
+S:	Maintained
+F:	include/linux/blkzoned_api.h
+F:	include/uapi/linux/blkzoned_api.h
+
 ZBUD COMPRESSED PAGE ALLOCATOR
 M:	Seth Jennings <[email protected]>
 L:	[email protected]
block/blk-lib.c +97 -0

106 lines not on this page · raw message

drivers/scsi/sd.c +122 -0

146 lines not on this page · raw message

drivers/scsi/sd.h +1 -0
index 765a6f1..f782990 100644
@@ -94,6 +94,7 @@ struct scsi_disk {
 	unsigned	lbpvpd : 1;
 	unsigned	ws10 : 1;
 	unsigned	ws16 : 1;
+	unsigned	zoned: 2;
 };
 #define to_scsi_disk(obj) container_of(obj,struct scsi_disk,dev)
 
include/linux/bio.h +6 -1
index b7e1a008..b63a281 100644
@@ -79,7 +79,12 @@ static inline bool bio_has_data(struct bio *bio)
 
 static inline bool bio_no_advance_iter(struct bio *bio)
 {
-	return bio_op(bio) == REQ_OP_DISCARD || bio_op(bio) == REQ_OP_WRITE_SAME;
+	return bio_op(bio) == REQ_OP_DISCARD ||
+	       bio_op(bio) == REQ_OP_WRITE_SAME ||
+	       bio_op(bio) == REQ_OP_ZONE_REPORT ||
+	       bio_op(bio) == REQ_OP_ZONE_OPEN ||
+	       bio_op(bio) == REQ_OP_ZONE_CLOSE ||
+	       bio_op(bio) == REQ_OP_ZONE_RESET;
 }
 
 static inline bool bio_is_rw(struct bio *bio)
include/linux/blk_types.h +5 -1
index c92f7f8..b2e0e25 100644
@@ -225,13 +225,17 @@ enum rq_flag_bits {
 enum req_op {
 	REQ_OP_READ,
 	REQ_OP_WRITE,
+	REQ_OP_ZONE_REPORT,
+	REQ_OP_ZONE_OPEN,
+	REQ_OP_ZONE_CLOSE,
+	REQ_OP_ZONE_RESET,
 	REQ_OP_DISCARD,		/* request to discard sectors */
 	REQ_OP_SECURE_ERASE,	/* request to securely erase sectors */
 	REQ_OP_WRITE_SAME,	/* write same block many times */
 	REQ_OP_FLUSH,		/* request for cache flush */
 };
 
-#define REQ_OP_BITS 3
+#define REQ_OP_BITS 4
 
 typedef unsigned int blk_qc_t;
 #define BLK_QC_T_NONE	-1U
include/linux/blkzoned_api.h new file +25 -0
new file mode 100644
index 0000000..47c091a
@@ -0,0 +1,25 @@
+/*
+ * Functions for zone based SMR devices.
+ *
+ * Copyright (C) 2015 Seagate Technology PLC
+ *
+ * Written by:
+ * Shaun Tancheff <[email protected]>
+ *
+ * This file is licensed under  the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef _BLKZONED_API_H
+#define _BLKZONED_API_H
+
+#include <uapi/linux/blkzoned_api.h>
+
+extern int blkdev_issue_zone_action(struct block_device *, unsigned int op,
+				    unsigned int op_flags, sector_t, gfp_t);
+extern int blkdev_issue_zone_report(struct block_device *, unsigned int op_flgs,
+				    sector_t, u8 opt, struct page *, size_t,
+				    gfp_t);
+
+#endif /* _BLKZONED_API_H */
include/uapi/linux/Kbuild +1 -0
index ad821a3..86d9efe 100644
@@ -70,6 +70,7 @@ header-y += bfs_fs.h
 header-y += binfmts.h
 header-y += blkpg.h
 header-y += blktrace_api.h
+header-y += blkzoned_api.h
 header-y += bpf_common.h
 header-y += bpf.h
 header-y += bpqether.h
include/uapi/linux/blkzoned_api.h new file +214 -0

214 lines not on this page · raw message

Signature · 1 line
2.8.1
#4 lore raw

PATCH v4 2/2 Add ioctl to issue ZBC/ZAC commands via block layer

In reply to Shaun Tancheff

Add New ioctl types
BLKREPORT - Issue Report Zones to device.
BLKOPENZONE - Issue an Zone Action: Open Zone command. BLKCLOSEZONE - Issue an Zone Action: Close Zone command. BLKRESETZONE - Issue an Zone Action: Reset Zone command.

---
v4:
- Rebase on linux-next tag next-20160617.
- Change bio flags to bio op's

---
 block/ioctl.c                     | 110 ++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/blkzoned_api.h |   6 +++
 include/uapi/linux/fs.h           |   1 +
 3 files changed, 117 insertions(+)
block/ioctl.c +110 -0
index ed2397f..97e685e 100644
@@ -7,6 +7,7 @@
 #include <linux/backing-dev.h>
 #include <linux/fs.h>
 #include <linux/blktrace_api.h>
+#include <linux/blkzoned_api.h>
 #include <linux/pr.h>
 #include <asm/uaccess.h>
 
@@ -194,6 +195,109 @@ int blkdev_reread_part(struct block_device *bdev)
 }
 EXPORT_SYMBOL(blkdev_reread_part);
 
+static int blk_zoned_report_ioctl(struct block_device *bdev, fmode_t mode,
+		void __user *parg)
+{
+	int error = -EFAULT;
+	gfp_t gfp = GFP_KERNEL;
+	struct bdev_zone_report_io *zone_iodata = NULL;
+	int order = 0;
+	struct page *pgs = NULL;
+	u32 alloc_size = PAGE_SIZE;
+	unsigned long op_flags = 0;
+	u8 opt = 0;
+
+	if (!(mode & FMODE_READ))
+		return -EBADF;
+
+	zone_iodata = (void *)get_zeroed_page(gfp);
+	if (!zone_iodata) {
+		error = -ENOMEM;
+		goto report_zones_out;
+	}
+	if (copy_from_user(zone_iodata, parg, sizeof(*zone_iodata))) {
+		error = -EFAULT;
+		goto report_zones_out;
+	}
+	if (zone_iodata->data.in.return_page_count > alloc_size) {
+		int npages;
+
+		alloc_size = zone_iodata->data.in.return_page_count;
+		npages = (alloc_size + PAGE_SIZE - 1) / PAGE_SIZE;
+		order =  ilog2(roundup_pow_of_two(npages));
+		pgs = alloc_pages(gfp, order);
+		if (pgs) {
+			void *mem = page_address(pgs);
+
+			if (!mem) {
+				error = -ENOMEM;
+				goto report_zones_out;
+			}
+			memset(mem, 0, alloc_size);
+			memcpy(mem, zone_iodata, sizeof(*zone_iodata));
+			free_page((unsigned long)zone_iodata);
+			zone_iodata = mem;
+		} else {
+			/* Result requires DMA capable memory */
+			pr_err("Not enough memory available for request.\n");
+			error = -ENOMEM;
+			goto report_zones_out;
+		}
+	}
+	opt = zone_iodata->data.in.report_option;
+	error = blkdev_issue_zone_report(bdev, op_flags,
+			zone_iodata->data.in.zone_locator_lba, opt,
+			pgs ? pgs : virt_to_page(zone_iodata),
+			alloc_size, GFP_KERNEL);
+
+	if (error)
+		goto report_zones_out;
+
+	if (copy_to_user(parg, zone_iodata, alloc_size))
+		error = -EFAULT;
+
+report_zones_out:
+	if (pgs)
+		__free_pages(pgs, order);
+	else if (zone_iodata)
+		free_page((unsigned long)zone_iodata);
+	return error;
+}
+
+static int blk_zoned_action_ioctl(struct block_device *bdev, fmode_t mode,
+				  unsigned int cmd, unsigned long arg)
+{
+	unsigned int op = 0;
+
+	if (!(mode & FMODE_WRITE))
+		return -EBADF;
+
+	/*
+	 * When acting on zones we explicitly disallow using a partition.
+	 */
+	if (bdev != bdev->bd_contains) {
+		pr_err("%s: All zone operations disallowed on this device\n",
+			__func__);
+		return -EFAULT;
+	}
+
+	switch (cmd) {
+	case BLKOPENZONE:
+		op = REQ_OP_ZONE_OPEN;
+		break;
+	case BLKCLOSEZONE:
+		op = REQ_OP_ZONE_CLOSE;
+		break;
+	case BLKRESETZONE:
+		op = REQ_OP_ZONE_RESET;
+		break;
+	default:
+		pr_err("%s: Unknown action: %u\n", __func__, cmd);
+		return -EINVAL;
+	}
+	return blkdev_issue_zone_action(bdev, op, 0, arg, GFP_KERNEL);
+}
+
 static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
 		unsigned long arg, unsigned long flags)
 {
@@ -568,6 +672,12 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
 	case BLKTRACESETUP:
 	case BLKTRACETEARDOWN:
 		return blk_trace_ioctl(bdev, cmd, argp);
+	case BLKREPORT:
+		return blk_zoned_report_ioctl(bdev, mode, argp);
+	case BLKOPENZONE:
+	case BLKCLOSEZONE:
+	case BLKRESETZONE:
+		return blk_zoned_action_ioctl(bdev, mode, cmd, arg);
 	case IOC_PR_REGISTER:
 		return blkdev_pr_register(bdev, argp);
 	case IOC_PR_RESERVE:
include/uapi/linux/blkzoned_api.h +6 -0
index 48c17ad..3566de0 100644
@@ -211,4 +211,10 @@ struct bdev_zone_report_io {
 	} data;
 } __packed;
 
+/* continuing from uapi/linux/fs.h: */
+#define BLKREPORT	_IOWR(0x12, 130, struct bdev_zone_report_io)
+#define BLKOPENZONE	_IO(0x12, 131)
+#define BLKCLOSEZONE	_IO(0x12, 132)
+#define BLKRESETZONE	_IO(0x12, 133)
+
 #endif /* _UAPI_BLKZONED_API_H */
include/uapi/linux/fs.h +1 -0
index 3b00f7c..c0b565b 100644
@@ -222,6 +222,7 @@ struct fsxattr {
 #define BLKSECDISCARD _IO(0x12,125)
 #define BLKROTATIONAL _IO(0x12,126)
 #define BLKZEROOUT _IO(0x12,127)
+/* A jump here: See blkzoned_api.h, Reserving 130 to 133. */
 
 #define BMAP_IOCTL 1		/* obsolete - kept for compatibility */
 #define FIBMAP	   _IO(0x00,1)	/* bmap access */
Signature · 1 line
2.8.1
#2 lore raw

Re: [PATCH v4 1/2] Add bio/request flags for using ZBC/ZAC commands

In reply to Shaun Tancheff
reproduce:

Hi,

[auto build test WARNING on block/for-next]
[also build test WARNING on next-20160617]
[cannot apply to v4.7-rc3]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Shaun-Tancheff/Add-bio-request-flags-for-using-ZBC-ZAC-commands/20160620-021844
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: i386-randconfig-x005-06192356 (attached as .config)
compiler: gcc-6 (Debian 6.1.1-1) 6.1.1 20160430
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

drivers/scsi/sd.c: In function 'sd_setup_zone_action_cmnd':

>> drivers/scsi/sd.c:1209:15: warning: unused variable 'nr_bytes' [-Wunused-variable]
     unsigned int nr_bytes = blk_rq_bytes(rq);
                  ^~~~~~~~
>> drivers/scsi/sd.c:1208:18: warning: unused variable 'disk' [-Wunused-variable]
     struct gendisk *disk = rq->rq_disk;
                     ^~~~
>> drivers/scsi/sd.c:1206:14: warning: unused variable 'bio' [-Wunused-variable]
     struct bio *bio = rq->bio;
                 ^~~
>> drivers/scsi/sd.c:1204:22: warning: unused variable 'sdp' [-Wunused-variable]
     struct scsi_device *sdp = cmd->device;
                         ^~~

vim +/nr_bytes +1209 drivers/scsi/sd.c

1198 return ret;
1199 }
1200
1201 static int sd_setup_zone_action_cmnd(struct scsi_cmnd *cmd)
1202 {
1203 struct request *rq = cmd->request;

> 1204		struct scsi_device *sdp = cmd->device;
  1205		struct scsi_disk *sdkp = scsi_disk(rq->rq_disk);
> 1206		struct bio *bio = rq->bio;
  1207		sector_t sector = blk_rq_pos(rq);
> 1208		struct gendisk *disk = rq->rq_disk;
> 1209		unsigned int nr_bytes = blk_rq_bytes(rq);

1210 int ret = BLKPREP_KILL;
1211 u8 allbit = 0;
1212

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw

Re: [PATCH v4 1/2] Add bio/request flags for using ZBC/ZAC commands

In reply to Shaun Tancheff
All warnings (new ones prefixed by >>):

Hi,

[auto build test WARNING on block/for-next]
[also build test WARNING on next-20160617]
[cannot apply to v4.7-rc3]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Shaun-Tancheff/Add-bio-request-flags-for-using-ZBC-ZAC-commands/20160620-021844
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

lib/crc32.c:148: warning: No description found for parameter 'tab)[256]' lib/crc32.c:148: warning: Excess function parameter 'tab' description in 'crc32_le_generic' lib/crc32.c:293: warning: No description found for parameter 'tab)[256]' lib/crc32.c:293: warning: Excess function parameter 'tab' description in 'crc32_be_generic' lib/crc32.c:1: warning: no structured comments found
mm/memory.c:2881: warning: No description found for parameter 'old'

>> block/blk-lib.c:337: warning: No description found for parameter 'op'

vim +/op +337 block/blk-lib.c

321 }
322 EXPORT_SYMBOL(blkdev_issue_zone_report);
323
324 /**
325 * blkdev_issue_zone_action - queue a report zones operation
326 * @bdev: target blockdev
327 * @op_flags: REQ_OPEN_ZONE, REQ_CLOSE_ZONE, or REQ_RESET_ZONE.
328 * @sector: starting lba of sector
329 * @gfp_mask: memory allocation flags (for bio_alloc)
330 *
331 * Description:
332 * Issue a zone report request for the sectors in question.
333 */
334 int blkdev_issue_zone_action(struct block_device *bdev, unsigned int op,
335 unsigned int op_flags, sector_t sector,
336 gfp_t gfp_mask)

 > 337	{

338 int ret;
339 struct bio *bio;
340
341 bio = bio_alloc(gfp_mask, 1);
342 if (!bio)
343 return -ENOMEM;
344
345 bio->bi_iter.bi_sector = sector;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation