Block layer support ZAC/ZBC commands
Subsystems (4)
v8 cover Block layer support ZAC/ZBC commands
Hi Jens,
This series is based on linus' v4.8-rc2 branch.
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.
ZBC [and ZAC] drives add new commands for discovering and working with Zones.
Part one of this series expands the bio/request reserved op size from 3 to 4 bits and then adds op codes for each of the ZBC commands:
Report zones, close zone, finish zone, open zone and reset zone.
Part two of this series deals with integrating these new bio/request op's with Hannes' zone cache.
This extends the ZBC support up to the block layer allowing direct control by file systems or device mapper targets. Also by deferring the zone handling to the authoritative subsystem there is an overall lower memory usage for holding the active zone information as well as clarifying responsible party for maintaining the write pointer for each active zone.
By way of example a DM target may have several writes in progress. To sector (or lba) for those writes will each depend on the previous write. While the drive's write pointer will be updated as writes are completed the DM target will be maintaining both where the next write should be scheduled from and where the write pointer is based on writes completed w/o errors.
Knowing the drive zone topology enables DM targets and file systems to extend their block allocation schemes and issue write pointer resets (or 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 is intended to allow a collection of zoned and non-zoned media to be stitched together to provide a file system with a zoned device with conventional space mapped to where it is useful.
Patches for util-linux can be found here:
[email protected]:stancheff/util-linux.git v2.28.1+biof https://github.com/stancheff/util-linux/tree/v2.28.1%2Bbiof
This patch is available here:
https://github.com/stancheff/linux/tree/v4.8-rc2%2Bbiof.v8 [email protected]:stancheff/linux.git v4.8-rc2+biof.v8
v8:
- Changed zone report to default to reading from zone cache.
- Changed ioctl for zone commands to support forcing a query or command to be sent to media.
- Fixed report zones copy to user to work when HARDENED_USERCOPY is enabled
v7:
- Initial support for Hannes' zone cache.
v6:
- Fix page alloc to include DMA flag for ioctl.
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 to issue ZBC/ZAC commands Add ioctl to issue ZBC/ZAC commands via block layer
MAINTAINERS | 9 ++ block/blk-lib.c | 94 +++++++++++++++++ block/ioctl.c | 149 +++++++++++++++++++++++++++ drivers/scsi/sd.c | 121 ++++++++++++++++++++++ drivers/scsi/sd.h | 1 + include/linux/bio.h | 8 +- include/linux/blk_types.h | 7 +- include/linux/blkdev.h | 1 + include/linux/blkzoned_api.h | 25 +++++ include/uapi/linux/Kbuild | 1 + include/uapi/linux/blkzoned_api.h | 210 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/fs.h | 1 + 12 files changed, 625 insertions(+), 2 deletions(-) create mode 100644 include/linux/blkzoned_api.h create mode 100644 include/uapi/linux/blkzoned_api.h
Signature · 1 line
2.9.3
PATCH v8 1/2 Add bio/request flags to issue ZBC/ZAC commands
Add op flags to access to zone information as well as open, close and reset zones:
- REQ_OP_ZONE_REPORT - Query zone information (Report zones)
- REQ_OP_ZONE_OPEN - Explicitly open a zone for writing
- REQ_OP_ZONE_CLOSE - Explicitly close a zone
- REQ_OP_ZONE_FINISH - Explicitly finish a zone
- REQ_OP_ZONE_RESET - Reset Write Pointer to start of zone
These op flags can be used to create bio's to control zoned devices through the block layer.
This is useful for file systems and device mappers that need explicit control of zoned devices such as Host Managed and Host Aware SMR drives,
Report zones is a device read that requires a buffer.
Open, Close, Finish and Reset are device commands that have no associated data transfer.
Open - Open is a zone for writing.
Close - Disallow writing to a zone.
Finish - Disallow writing a zone and set the WP to the end
of the zone.
Reset - Discard data in a zone and reset the WP to the start
of the zone.
Sending an LBA of ~0 will attempt to operate on all zones. This is typically used with Reset to wipe a drive as a Reset behaves similar to TRIM in that all data in the zone(s) is deleted.
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.
---
v8:
- Added Finish Zone op
- Fixed report zones copy to user to work when HARDENED_USERCOPY is enabled
v6:
- Added GFP_DMA to gfp mask.
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 | 94 ++++++++++++++++++++ drivers/scsi/sd.c | 121 +++++++++++++++++++++++++ drivers/scsi/sd.h | 1 + include/linux/bio.h | 8 +- include/linux/blk_types.h | 7 +- include/linux/blkdev.h | 1 + include/linux/blkzoned_api.h | 25 ++++++ include/uapi/linux/Kbuild | 1 + include/uapi/linux/blkzoned_api.h | 182 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 447 insertions(+), 2 deletions(-) create mode 100644 include/linux/blkzoned_api.h create mode 100644 include/uapi/linux/blkzoned_api.h
MAINTAINERS +9 -0
@@ -12984,6 +12984,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 +94 -0
97 lines not on this page · raw message
drivers/scsi/sd.c +121 -0
139 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 +7 -1
@@ -79,7 +79,13 @@ 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_FINISH || +bio_op (bio) ==REQ_OP_ZONE_RESET ; }static inline bool bio_is_rw (struct bio *bio)
include/linux/blk_types.h +6 -1
@@ -232,13 +232,18 @@ 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_FINISH , +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/blkdev.h +1 -0
@@ -24,6 +24,7 @@#include <linux/rcupdate.h> #include <linux/percpu-refcount.h> #include <linux/scatterlist.h> +#include <linux/blkzoned_api.h> struct module ;struct scsi_ioctl_command ;
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 +182 -0
182 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH RESEND v8 1/2 Add bio/request flags to issue ZBC/ZAC commands
(RESENDING to include f2fs, fs-devel and dm-devel)
Add op flags to access to zone information as well as open, close and reset zones:
- REQ_OP_ZONE_REPORT - Query zone information (Report zones)
- REQ_OP_ZONE_OPEN - Explicitly open a zone for writing
- REQ_OP_ZONE_CLOSE - Explicitly close a zone
- REQ_OP_ZONE_FINISH - Explicitly finish a zone
- REQ_OP_ZONE_RESET - Reset Write Pointer to start of zone
These op flags can be used to create bio's to control zoned devices through the block layer.
This is useful for file systems and device mappers that need explicit control of zoned devices such as Host Managed and Host Aware SMR drives,
Report zones is a device read that requires a buffer.
Open, Close, Finish and Reset are device commands that have no associated data transfer.
Open - Open is a zone for writing.
Close - Disallow writing to a zone.
Finish - Disallow writing a zone and set the WP to the end
of the zone.
Reset - Discard data in a zone and reset the WP to the start
of the zone.
Sending an LBA of ~0 will attempt to operate on all zones. This is typically used with Reset to wipe a drive as a Reset behaves similar to TRIM in that all data in the zone(s) is deleted.
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.
---
v8:
- Added Finish Zone op
- Fixed report zones copy to user to work when HARDENED_USERCOPY is enabled
v6:
- Added GFP_DMA to gfp mask.
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 | 94 ++++++++++++++++++++ drivers/scsi/sd.c | 121 +++++++++++++++++++++++++ drivers/scsi/sd.h | 1 + include/linux/bio.h | 8 +- include/linux/blk_types.h | 7 +- include/linux/blkdev.h | 1 + include/linux/blkzoned_api.h | 25 ++++++ include/uapi/linux/Kbuild | 1 + include/uapi/linux/blkzoned_api.h | 182 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 447 insertions(+), 2 deletions(-) create mode 100644 include/linux/blkzoned_api.h create mode 100644 include/uapi/linux/blkzoned_api.h
MAINTAINERS +9 -0
@@ -12984,6 +12984,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 +94 -0
97 lines not on this page · raw message
drivers/scsi/sd.c +121 -0
139 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 +7 -1
@@ -79,7 +79,13 @@ 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_FINISH || +bio_op (bio) ==REQ_OP_ZONE_RESET ; }static inline bool bio_is_rw (struct bio *bio)
include/linux/blk_types.h +6 -1
@@ -232,13 +232,18 @@ 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_FINISH , +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/blkdev.h +1 -0
@@ -24,6 +24,7 @@#include <linux/rcupdate.h> #include <linux/percpu-refcount.h> #include <linux/scatterlist.h> +#include <linux/blkzoned_api.h> struct module ;struct scsi_ioctl_command ;
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 +182 -0
182 lines not on this page · raw message
Signature · 1 line
2.9.3
Re: [PATCH v8 1/2 RESEND] Add bio/request flags to issue ZBC/ZAC commands
Shaun,
Quoted 10 lines · Shaun Tancheff
(RESENDING to include f2fs, fs-devel and dm-devel)
Add op flags to access to zone information as well as open, close and reset zones:
-REQ_OP_ZONE_REPORT- Query zone information (Report zones)
-REQ_OP_ZONE_OPEN- Explicitly open a zone for writing
-REQ_OP_ZONE_CLOSE- Explicitly close a zone
-REQ_OP_ZONE_FINISH- Explicitly finish a zone
-REQ_OP_ZONE_RESET- Reset Write Pointer to start of zone
Quoted 2 lines
These op flags can be used to create bio's to control zoned devices through the block layer.
I still have a hard time seeing the need for the REQ_OP_ZONE_REPORT operation assuming that the device queue will hold a zone information cache, Hannes RB-tree or your array type, whichever.
Let's try to think simply here: if the disk user (and FS, a device mapper or an application doing raw disk accesses) wants to access the disk zone information, why would it need to issue a BIO when calling blkdev_lookup_zone would exactly give that information straight out of memory (so much faster) ? I thought hard about this, but cannot think of any value for the BIO-to-disk option. It seems to me to be equivalent to systematically doing a page cache read even if the page cache tells us that the page is up-to-date...
Moreover, issuing a report zone to the disk may return information that is in fact incorrect, as that would not take into account the eventual set of write requests that was dispatched but not yet processed by the disk (some zone write pointer may be reported with a value lower than what the zone cache maintains).
Dealing (and fixing) these inconsistencies would force an update of the report zone result using the information of the zone cache, which in itself sounds like a good justification of not doing a report zones in the first place.
I am fine with the other operations, and in fact having a BIO interface for them to send down to the SCSI layer is better than any other method. It will causes them to be seen in sd_init_command, which is the path taken for read and write commands too. So all zone cache information checking and updating can be done in that single place and serialized with a spinlock. Maintenance of the zone cache information becomes very easy.
Any divergence of the zone cache information with the actual state of the disk will likely cause an error (unaligned write or other). Having a specific report zone BIO option will not help the disk user recover from those. Hannes current implementation make sure that the information of the zone for the failed request is automatically updated. That is enough to maintain the zone cache information uptodate, and a zone information can be marked as "in update" for the user to notice and wait for the refreshed information.
The ioctl code for reporting zones does not need the specific request op code either. Again, blkdev_lookup_zone can provide zone information, and an emulation of the reporting options filtering is also trivial to implement on top of that, if really required (I do not think that is strongly needed though).
Without the report zone operation, your patch set size would significantly shrink and merging with Hannes work becomes very easy too.
Please let me know what you think. If we drop this, we can get a clean and full ZBC support patch set ready in no time at all.
Best regards.
Signature · 8 lines
Damien Le Moal, Ph.D. Sr. Manager, System Software Group, HGST Research, HGST, a Western Digital brand [email protected] (+81) 0466-98-3593 (ext. 513593) 1 kirihara-cho, Fujisawa, Kanagawa, 252-0888 Japan www.hgst.com
Re: [PATCH v8 1/2 RESEND] Add bio/request flags to issue ZBC/ZAC commands
Quoted 23 lines · Damien Le Moal
Shaun,
Quoted 11 lines · Shaun Tancheff
(RESENDING to include f2fs, fs-devel and dm-devel)
Add op flags to access to zone information as well as open, close and reset zones:
-REQ_OP_ZONE_REPORT- Query zone information (Report zones)
-REQ_OP_ZONE_OPEN- Explicitly open a zone for writing
-REQ_OP_ZONE_CLOSE- Explicitly close a zone
-REQ_OP_ZONE_FINISH- Explicitly finish a zone
-REQ_OP_ZONE_RESET- Reset Write Pointer to start of zoneQuoted 2 lines
These op flags can be used to create bio's to control zoned devices through the block layer.
I still have a hard time seeing the need for the
REQ_OP_ZONE_REPORToperation assuming that the device queue will hold a zone information cache, Hannes RB-tree or your array type, whichever.
Quoted 8 lines
Let's try to think simply here: if the disk user (and FS, a device mapper or an application doing raw disk accesses) wants to access the disk zone information, why would it need to issue a BIO when calling
blkdev_lookup_zonewould exactly give that information straight out of memory (so much faster) ? I thought hard about this, but cannot think of any value for the BIO-to-disk option. It seems to me to be equivalent to systematically doing a page cache read even if the page cache tells us that the page is up-to-date...
Firstly the BIO abstraction here gives a common interface to getting the zone information and works even for embedded systems that are not willing / convinced to enable SCSI_ZBC + BLK_ZONED.
Secondly when SCSI_ZBC + BLK_ZONED are enabled it just returns from the zone cache [as you can hopefully find in the second half of this series]. I did add a 'force' option but it's not intended to be used lightly.
Thirdly it is my belief that BIO abstraction is more easily adapted to working with [and through] the device mapper layer (s).
Today we both have the issue where if a file system supports working with a ZBC device there can be no device mapper stacked between the file system and the actual zoned device. This is also true of our respective device mapper targets.
It is my current belief that teaching the device mapper layer to include REQ_OP_ZONE* operations is relatively straight forward and can be done w/o affecting existing targets that don't specifically need to operate on zones. Something similar to the way flush is handled currently. If the target doesn't ask to see zone operations the default mapping rules apply.
Examples of why I would like to add REQ_OP_ZONE*
support to the device mapper:
I think it would be really neat if I could just to a quick dm-linear and put big chunk of SSD in front of dm-zoned or dm-zdm as it would be a nice way to boost performance.
Similarly it enable using dm-linear to stitch together enough conventional space with a ZBC drive to see if Dave Chinner's XFS proposal from a couple of years ago could work.
Quoted 5 lines
Moreover, issuing a report zone to the disk may return information that is in fact incorrect, as that would not take into account the eventual set of write requests that was dispatched but not yet processed by the disk (some zone write pointer may be reported with a value lower than what the zone cache maintains).
Yes but issuing a zone report to media is not the expected path when the zone cache is available. It is there to 'force' a re-sync and it is intended that the user of the call knows that the force is being applied and wants it to happen. Perhaps I should make it two flags? One to force a reply form the device and second flag to re-sync the zone cache with the result? There is one piece of information that can only be retrieved by going to the device and that is the 'non-seq resources' flag and it is only used by Host Aware devices ... as far as I understand.
Quoted 4 lines
Dealing (and fixing) these inconsistencies would force an update of the report zone result using the information of the zone cache, which in itself sounds like a good justification of not doing a report zones in the first place.
When report zones is just pulling from the zone cache it should not be a problem. So the normal activity [when SCSI_ZBC + BLK_ZONED are enabled] should not be introducing any inconsistencies.
Quoted 7 lines
I am fine with the other operations, and in fact having a BIO interface for them to send down to the SCSI layer is better than any other method. It will causes them to be seen in
sd_init_command, which is the path taken for read and write commands too. So all zone cache information checking and updating can be done in that single place and serialized with a spinlock. Maintenance of the zone cache information becomes very easy.
Quoted 8 lines
Any divergence of the zone cache information with the actual state of the disk will likely cause an error (unaligned write or other). Having a specific report zone BIO option will not help the disk user recover from those. Hannes current implementation make sure that the information of the zone for the failed request is automatically updated. That is enough to maintain the zone cache information uptodate, and a zone information can be marked as "in update" for the user to notice and wait for the refreshed information.
Which is why the zone cache is consider the default authority .. when it is available.
Hopefully you will find this use case more compelling:
User issues:
# sg_reset_wp --all /dev/sdz User then proceeds to run: # mkfs.f2fs -m /dev/sdz
Now quite possibly the zone information is 'out of sync' because the user used a ZBC command that we to catch in the zone cache.
Now if mkfs.f2fs does a reports zones with a force it will fix the zone cache and everything goes nice and quick.
Since the output of report zones is the same format as the ZBC spec [and therefore SG_IO] it should be a stright forward change in mkfs.f2fs to call BLKREPORT instead of via SG_IO.
Quoted 11 lines
The ioctl code for reporting zones does not need the specific request op code either. Again,
blkdev_lookup_zonecan provide zone information, and an emulation of the reporting options filtering is also trivial to implement on top of that, if really required (I do not think that is strongly needed though).Without the report zone operation, your patch set size would significantly shrink and merging with Hannes work becomes very easy too.
Please let me know what you think. If we drop this, we can get a clean and full ZBC support patch set ready in no time at all.
Signature · 2 lines
Regards, Shaun Tancheff
PATCH v8 2/2 Add ioctl to issue ZBC/ZAC commands via block layer
In reply to Shaun TancheffAdd support for ZBC ioctl's
BLKREPORT - Issue Report Zones to device.
BLKZONEACTION - Issue a Zone Action (Close, Finish, Open, or Reset)
---
v8:
- Changed ioctl for zone actions to a single ioctl that takes a structure including the zone, zone action, all flag, and force option
- Mapped REQ_META flag to 'force unit access' for zone operations
v6:
- Added GFP_DMA to gfp mask.
v4:
- Rebase on linux-next tag next-20160617.
- Change bio flags to bio op's
block/ioctl.c | 149 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/blkzoned_api.h | 30 +++++++- include/uapi/linux/fs.h | 1 + 3 files changed, 179 insertions(+), 1 deletion(-)
block/ioctl.c +149 -0
@@ -194,6 +194,151 @@ 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 |GFP_DMA ; +void *iopg =NULL ; +struct bdev_zone_report_io *bzrpt =NULL ; +int order =0 ; +struct page *pgs =NULL ; +u32 alloc_size =PAGE_SIZE ; +unsigned int op_flags =0 ; +u8 opt =0 ; + +if (!(mode &FMODE_READ )) +return -EBADF ; + + iopg = (void *)get_zeroed_page (gfp); +if (!iopg) { + error = -ENOMEM ; + goto report_zones_out; + } + bzrpt = iopg; +if (copy_from_user (bzrpt, parg,sizeof (*bzrpt))) { + error = -EFAULT ; + goto report_zones_out; + } +if (bzrpt->data.in.return_page_count > alloc_size) { +int npages; + + alloc_size = bzrpt->data.in.return_page_count; + npages = (alloc_size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; + pgs =alloc_pages (gfp,ilog2 (npages)); +if (pgs) { +void *mem =page_address (pgs); + +if (!mem) { + error = -ENOMEM ; + goto report_zones_out; + } + order =ilog2 (npages); +memset (mem,0 , alloc_size); +memcpy (mem, bzrpt,sizeof (*bzrpt)); + bzrpt = mem; + }else { +/* Result requires DMA capable memory */ +pr_err ("Not enough memory available for request.\n" ); + error = -ENOMEM ; + goto report_zones_out; + } + }else { + alloc_size = bzrpt->data.in.return_page_count; + } +if (bzrpt->data.in.force_unit_access) + op_flags |=REQ_META ; + opt = bzrpt->data.in.report_option; + error =blkdev_issue_zone_report (bdev, op_flags, + bzrpt->data.in.zone_locator_lba, opt, + pgs ? pgs :virt_to_page (iopg), + alloc_size,GFP_KERNEL ); +if (error) + goto report_zones_out; + +if (pgs) { +void *src = bzrpt; +u32 off =0 ; + +/* +* When moving a multi-order page with GFP_DMA +* the copy to user can trap "<spans multiple pages>" +* so instead we copy out 1 page at a time. +*/ +while (off < alloc_size && !error) { +u32 len =min_t (u32,PAGE_SIZE , alloc_size - off); + +memcpy (iopg, src + off, len); +if (copy_to_user (parg + off, iopg, len)) + error = -EFAULT ; + off += len; + } + }else { +if (copy_to_user (parg, iopg, alloc_size)) + error = -EFAULT ; + } + +report_zones_out: +if (pgs) +__free_pages (pgs, order); +if (iopg) +free_page ((unsigned long )iopg); +return error; +} + +static int blk_zoned_action_ioctl (struct block_device *bdev,fmode_t mode, +void __user *parg) +{ +unsigned int op =0 ; +unsigned int op_flags =0 ; +sector_t lba; +struct bdev_zone_action za; + +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 ; + } + +if (copy_from_user (&za, parg,sizeof (za))) +return -EFAULT ; + +switch (za.action) { +case ZONE_ACTION_CLOSE : + op =REQ_OP_ZONE_CLOSE ; +break ; +case ZONE_ACTION_FINISH : + op =REQ_OP_ZONE_FINISH ; +break ; +case ZONE_ACTION_OPEN : + op =REQ_OP_ZONE_OPEN ; +break ; +case ZONE_ACTION_RESET : + op =REQ_OP_ZONE_RESET ; +break ; +default : +pr_err ("%s: Unknown action: %u\n" , __func__, za.action); +return -EINVAL ; + } + + lba = za.zone_locator_lba; +if (za.all_zones) { +if (lba) { +pr_err ("%s: if all_zones, LBA must be 0.\n" , __func__); +return -EINVAL ; + } + lba = ~0ul ; + } +if (za.force_unit_access || lba == ~0ul ) + op_flags |=REQ_META ; + +return blkdev_issue_zone_action (bdev, op, op_flags, lba,GFP_KERNEL ); +} +static int blk_ioctl_discard (struct block_device *bdev,fmode_t mode,unsigned long arg,unsigned long flags) {
@@ -568,6 +713,10 @@ 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 BLKZONEACTION : +return blk_zoned_action_ioctl (bdev, mode, argp);case IOC_PR_REGISTER :return blkdev_pr_register (bdev, argp);case IOC_PR_RESERVE :
include/uapi/linux/blkzoned_api.h +29 -1
@@ -115,6 +115,7 @@ enum bdev_zone_same {* @zone_locator_lba: starting lba for first [reported] zone * @return_page_count: number of *bytes* allocated for result * @report_option: see: zone_report_option enum +* @force_unit_access: Force report from media * * Used to issue report zones command to connected device */
@@ -122,6 +123,25 @@ struct bdev_zone_get_report {__u64 zone_locator_lba;__u32 return_page_count;__u8 report_option; +__u8 force_unit_access; +} __packed; + +/** +* struct bdev_zone_action - ioctl: Perform Zone Action +* +* @zone_locator_lba: starting lba for first [reported] zone +* @return_page_count: number of *bytes* allocated for result +* @action: One of the ZONE_ACTION_*'s Close,Finish,Open, or Reset +* @all_zones: Flag to indicate if command should apply to all zones. +* @force_unit_access: Force command to media and update zone cache on success +* +* Used to issue report zones command to connected device +*/ +struct bdev_zone_action { +__u64 zone_locator_lba; +__u32 action; +__u8 all_zones; +__u8 force_unit_access; } __packed;/**
@@ -134,7 +154,6 @@ struct bdev_zone_get_report {* @lba_start: lba where the zone starts. * @lba_wptr: lba of the current write pointer. * @reserved: padding -* */ struct bdev_zone_descriptor {__u8 type;
@@ -179,4 +198,13 @@ struct bdev_zone_report_io { } data; } __packed; +/* continuing from uapi/linux/fs.h: */ +#define BLKREPORT _IOWR(0x12, 130, struct bdev_zone_report_io) +#define BLKZONEACTION _IOW(0x12, 131, struct bdev_zone_action) + +#define ZONE_ACTION_CLOSE 0x01 +#define ZONE_ACTION_FINISH 0x02 +#define ZONE_ACTION_OPEN 0x03 +#define ZONE_ACTION_RESET 0x04 +#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 and 131. */ #define BMAP_IOCTL 1/* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1)/* bmap access */
Signature · 1 line
2.9.3
PATCH RESEND v8 2/2 Add ioctl to issue ZBC/ZAC commands via block layer
(RESENDING to include f2fs, fs-devel and dm-devel)
Add support for ZBC ioctl's
BLKREPORT - Issue Report Zones to device.
BLKZONEACTION - Issue a Zone Action (Close, Finish, Open, or Reset)
---
v8:
- Changed ioctl for zone actions to a single ioctl that takes a structure including the zone, zone action, all flag, and force option
- Mapped REQ_META flag to 'force unit access' for zone operations
v6:
- Added GFP_DMA to gfp mask.
v4:
- Rebase on linux-next tag next-20160617.
- Change bio flags to bio op's
block/ioctl.c | 149 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/blkzoned_api.h | 30 +++++++- include/uapi/linux/fs.h | 1 + 3 files changed, 179 insertions(+), 1 deletion(-)
block/ioctl.c +149 -0
@@ -194,6 +194,151 @@ 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 |GFP_DMA ; +void *iopg =NULL ; +struct bdev_zone_report_io *bzrpt =NULL ; +int order =0 ; +struct page *pgs =NULL ; +u32 alloc_size =PAGE_SIZE ; +unsigned int op_flags =0 ; +u8 opt =0 ; + +if (!(mode &FMODE_READ )) +return -EBADF ; + + iopg = (void *)get_zeroed_page (gfp); +if (!iopg) { + error = -ENOMEM ; + goto report_zones_out; + } + bzrpt = iopg; +if (copy_from_user (bzrpt, parg,sizeof (*bzrpt))) { + error = -EFAULT ; + goto report_zones_out; + } +if (bzrpt->data.in.return_page_count > alloc_size) { +int npages; + + alloc_size = bzrpt->data.in.return_page_count; + npages = (alloc_size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; + pgs =alloc_pages (gfp,ilog2 (npages)); +if (pgs) { +void *mem =page_address (pgs); + +if (!mem) { + error = -ENOMEM ; + goto report_zones_out; + } + order =ilog2 (npages); +memset (mem,0 , alloc_size); +memcpy (mem, bzrpt,sizeof (*bzrpt)); + bzrpt = mem; + }else { +/* Result requires DMA capable memory */ +pr_err ("Not enough memory available for request.\n" ); + error = -ENOMEM ; + goto report_zones_out; + } + }else { + alloc_size = bzrpt->data.in.return_page_count; + } +if (bzrpt->data.in.force_unit_access) + op_flags |=REQ_META ; + opt = bzrpt->data.in.report_option; + error =blkdev_issue_zone_report (bdev, op_flags, + bzrpt->data.in.zone_locator_lba, opt, + pgs ? pgs :virt_to_page (iopg), + alloc_size,GFP_KERNEL ); +if (error) + goto report_zones_out; + +if (pgs) { +void *src = bzrpt; +u32 off =0 ; + +/* +* When moving a multi-order page with GFP_DMA +* the copy to user can trap "<spans multiple pages>" +* so instead we copy out 1 page at a time. +*/ +while (off < alloc_size && !error) { +u32 len =min_t (u32,PAGE_SIZE , alloc_size - off); + +memcpy (iopg, src + off, len); +if (copy_to_user (parg + off, iopg, len)) + error = -EFAULT ; + off += len; + } + }else { +if (copy_to_user (parg, iopg, alloc_size)) + error = -EFAULT ; + } + +report_zones_out: +if (pgs) +__free_pages (pgs, order); +if (iopg) +free_page ((unsigned long )iopg); +return error; +} + +static int blk_zoned_action_ioctl (struct block_device *bdev,fmode_t mode, +void __user *parg) +{ +unsigned int op =0 ; +unsigned int op_flags =0 ; +sector_t lba; +struct bdev_zone_action za; + +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 ; + } + +if (copy_from_user (&za, parg,sizeof (za))) +return -EFAULT ; + +switch (za.action) { +case ZONE_ACTION_CLOSE : + op =REQ_OP_ZONE_CLOSE ; +break ; +case ZONE_ACTION_FINISH : + op =REQ_OP_ZONE_FINISH ; +break ; +case ZONE_ACTION_OPEN : + op =REQ_OP_ZONE_OPEN ; +break ; +case ZONE_ACTION_RESET : + op =REQ_OP_ZONE_RESET ; +break ; +default : +pr_err ("%s: Unknown action: %u\n" , __func__, za.action); +return -EINVAL ; + } + + lba = za.zone_locator_lba; +if (za.all_zones) { +if (lba) { +pr_err ("%s: if all_zones, LBA must be 0.\n" , __func__); +return -EINVAL ; + } + lba = ~0ul ; + } +if (za.force_unit_access || lba == ~0ul ) + op_flags |=REQ_META ; + +return blkdev_issue_zone_action (bdev, op, op_flags, lba,GFP_KERNEL ); +} +static int blk_ioctl_discard (struct block_device *bdev,fmode_t mode,unsigned long arg,unsigned long flags) {
@@ -568,6 +713,10 @@ 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 BLKZONEACTION : +return blk_zoned_action_ioctl (bdev, mode, argp);case IOC_PR_REGISTER :return blkdev_pr_register (bdev, argp);case IOC_PR_RESERVE :
include/uapi/linux/blkzoned_api.h +29 -1
@@ -115,6 +115,7 @@ enum bdev_zone_same {* @zone_locator_lba: starting lba for first [reported] zone * @return_page_count: number of *bytes* allocated for result * @report_option: see: zone_report_option enum +* @force_unit_access: Force report from media * * Used to issue report zones command to connected device */
@@ -122,6 +123,25 @@ struct bdev_zone_get_report {__u64 zone_locator_lba;__u32 return_page_count;__u8 report_option; +__u8 force_unit_access; +} __packed; + +/** +* struct bdev_zone_action - ioctl: Perform Zone Action +* +* @zone_locator_lba: starting lba for first [reported] zone +* @return_page_count: number of *bytes* allocated for result +* @action: One of the ZONE_ACTION_*'s Close,Finish,Open, or Reset +* @all_zones: Flag to indicate if command should apply to all zones. +* @force_unit_access: Force command to media and update zone cache on success +* +* Used to issue report zones command to connected device +*/ +struct bdev_zone_action { +__u64 zone_locator_lba; +__u32 action; +__u8 all_zones; +__u8 force_unit_access; } __packed;/**
@@ -134,7 +154,6 @@ struct bdev_zone_get_report {* @lba_start: lba where the zone starts. * @lba_wptr: lba of the current write pointer. * @reserved: padding -* */ struct bdev_zone_descriptor {__u8 type;
@@ -179,4 +198,13 @@ struct bdev_zone_report_io { } data; } __packed; +/* continuing from uapi/linux/fs.h: */ +#define BLKREPORT _IOWR(0x12, 130, struct bdev_zone_report_io) +#define BLKZONEACTION _IOW(0x12, 131, struct bdev_zone_action) + +#define ZONE_ACTION_CLOSE 0x01 +#define ZONE_ACTION_FINISH 0x02 +#define ZONE_ACTION_OPEN 0x03 +#define ZONE_ACTION_RESET 0x04 +#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 and 131. */ #define BMAP_IOCTL 1/* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1)/* bmap access */
Signature · 1 line
2.9.3
v8 cover Block layer support ZAC/ZBC commands
In reply to Shaun Tancheff(RESENDING to include f2fs, fs-devel and dm-devel)
Hi Jens,
This series is based on linus' v4.8-rc2 branch.
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.
ZBC [and ZAC] drives add new commands for discovering and working with Zones.
Part one of this series expands the bio/request reserved op size from 3 to 4 bits and then adds op codes for each of the ZBC commands:
Report zones, close zone, finish zone, open zone and reset zone.
Part two of this series deals with integrating these new bio/request op's with Hannes' zone cache.
This extends the ZBC support up to the block layer allowing direct control by file systems or device mapper targets. Also by deferring the zone handling to the authoritative subsystem there is an overall lower memory usage for holding the active zone information as well as clarifying responsible party for maintaining the write pointer for each active zone.
By way of example a DM target may have several writes in progress. To sector (or lba) for those writes will each depend on the previous write. While the drive's write pointer will be updated as writes are completed the DM target will be maintaining both where the next write should be scheduled from and where the write pointer is based on writes completed w/o errors.
Knowing the drive zone topology enables DM targets and file systems to extend their block allocation schemes and issue write pointer resets (or 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 is intended to allow a collection of zoned and non-zoned media to be stitched together to provide a file system with a zoned device with conventional space mapped to where it is useful.
Patches for util-linux can be found here:
[email protected]:stancheff/util-linux.git v2.28.1+biof https://github.com/stancheff/util-linux/tree/v2.28.1%2Bbiof
This patch is available here:
https://github.com/stancheff/linux/tree/v4.8-rc2%2Bbiof.v8 [email protected]:stancheff/linux.git v4.8-rc2+biof.v8
v8:
- Changed zone report to default to reading from zone cache.
- Changed ioctl for zone commands to support forcing a query or command to be sent to media.
- Fixed report zones copy to user to work when HARDENED_USERCOPY is enabled
v7:
- Initial support for Hannes' zone cache.
v6:
- Fix page alloc to include DMA flag for ioctl.
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 to issue ZBC/ZAC commands Add ioctl to issue ZBC/ZAC commands via block layer
MAINTAINERS | 9 ++ block/blk-lib.c | 94 +++++++++++++++++ block/ioctl.c | 149 +++++++++++++++++++++++++++ drivers/scsi/sd.c | 121 ++++++++++++++++++++++ drivers/scsi/sd.h | 1 + include/linux/bio.h | 8 +- include/linux/blk_types.h | 7 +- include/linux/blkdev.h | 1 + include/linux/blkzoned_api.h | 25 +++++ include/uapi/linux/Kbuild | 1 + include/uapi/linux/blkzoned_api.h | 210 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/fs.h | 1 + 12 files changed, 625 insertions(+), 2 deletions(-) create mode 100644 include/linux/blkzoned_api.h create mode 100644 include/uapi/linux/blkzoned_api.h
Signature · 1 line
2.9.3