Block layer support ZAC/ZBC commands
Subsystems (4)
v5 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.
This patch is also at
https://github.com/stancheff/linux.git
[email protected]:stancheff/linux.git
branch: next-20160617+bio.zbc.v5
v5:
- In sd_setup_zone_action_cmnd, remove unused vars and fix switch indent
- In blk-lib fix documentation
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 | 98 +++++++++++++++++ block/ioctl.c | 110 +++++++++++++++++++ drivers/scsi/sd.c | 118 ++++++++++++++++++++ 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, 594 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
PATCH v5 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.
---
v5:
- In sd_setup_zone_action_cmnd, remove unused vars and fix switch indent
- In blk-lib fix documentation
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 | 98 +++++++++++++++++ drivers/scsi/sd.c | 118 +++++++++++++++++++++ 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, 477 insertions(+), 2 deletions(-) create mode 100644 include/linux/blkzoned_api.h create mode 100644 include/uapi/linux/blkzoned_api.h
MAINTAINERS +9 -0
@@ -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 +98 -0
107 lines not on this page · raw message
drivers/scsi/sd.c +118 -0
142 lines not on this page · raw message
drivers/scsi/sd.h +1 -0
@@ -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
@@ -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
@@ -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 4typedef unsigned int blk_qc_t ;#define BLK_QC_T_NONE -1U
include/linux/blkzoned_api.h new file +25 -0
@@ -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
@@ -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
PATCH v5 2/2 Add ioctl to issue ZBC/ZAC commands via block layer
In reply to Shaun TancheffAdd 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
@@ -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
@@ -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
@@ -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