From: Niklas Cassel <Niklas.Cassel@wdc.com>
To: Andreas Hindborg <nmi@metaspace.dk>
Cc: "linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
"Hans Holmberg" <Hans.Holmberg@wdc.com>,
"Matias Bjørling" <Matias.Bjorling@wdc.com>,
"kernel test robot" <lkp@intel.com>,
"Ming Lei" <ming.lei@redhat.com>, "Jens Axboe" <axboe@kernel.dk>,
"open list" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] block: ublk: enable zoned storage support
Date: Mon, 27 Feb 2023 10:20:07 +0000 [thread overview]
Message-ID: <Y/yD1WMJ5zc7KkBz@x1-carbon> (raw)
In-Reply-To: <20230224200502.391570-1-nmi@metaspace.dk>
On Fri, Feb 24, 2023 at 09:05:01PM +0100, Andreas Hindborg wrote:
> Add zoned storage support to ublk: report_zones and operations:
> - REQ_OP_ZONE_OPEN
> - REQ_OP_ZONE_CLOSE
> - REQ_OP_ZONE_FINISH
> - REQ_OP_ZONE_RESET
>
> This allows implementation of zoned storage devices in user space. An
> example user space implementation based on ubdsrv is available [1].
>
> [1] https://github.com/metaspace/ubdsrv/commit/14a2b708f74f70cfecb076d92e680dc718cc1f6d
>
> Signed-off-by: Andreas Hindborg <a.hindborg@samsung.com>
> ---
> Changes since v1:
> - Fixed conditional compilation bug
> - Refactored to collect conditional code additions together
> - Fixed style errors
> - Zero stack allocated value used for zone report
>
> Reported-by: Niklas Cassel <Niklas.Cassel@wdc.com>
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/oe-kbuild-all/202302250222.XOrw9j6z-lkp@intel.com/
> v1: https://lore.kernel.org/linux-block/20230224125950.214779-1-nmi@metaspace.dk/
>
> drivers/block/ublk_drv.c | 150 ++++++++++++++++++++++++++++++++--
> include/uapi/linux/ublk_cmd.h | 18 ++++
> 2 files changed, 162 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 6368b56eacf1..37e516903867 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -20,6 +20,7 @@
> #include <linux/major.h>
> #include <linux/wait.h>
> #include <linux/blkdev.h>
> +#include <linux/blkzoned.h>
> #include <linux/init.h>
> #include <linux/swap.h>
> #include <linux/slab.h>
> @@ -51,10 +52,12 @@
> | UBLK_F_URING_CMD_COMP_IN_TASK \
> | UBLK_F_NEED_GET_DATA \
> | UBLK_F_USER_RECOVERY \
> - | UBLK_F_USER_RECOVERY_REISSUE)
> + | UBLK_F_USER_RECOVERY_REISSUE \
> + | UBLK_F_ZONED)
>
> /* All UBLK_PARAM_TYPE_* should be included here */
> -#define UBLK_PARAM_TYPE_ALL (UBLK_PARAM_TYPE_BASIC | UBLK_PARAM_TYPE_DISCARD)
> +#define UBLK_PARAM_TYPE_ALL (UBLK_PARAM_TYPE_BASIC | UBLK_PARAM_TYPE_DISCARD \
> + | UBLK_PARAM_TYPE_ZONED)
>
> struct ublk_rq_data {
> struct llist_node node;
> @@ -187,6 +190,98 @@ static DEFINE_MUTEX(ublk_ctl_mutex);
>
> static struct miscdevice ublk_misc;
>
> +#ifdef CONFIG_BLK_DEV_ZONED
> +static void ublk_set_nr_zones(struct ublk_device *ub)
> +{
> + const struct ublk_param_basic *p = &ub->params.basic;
> +
> + if (ub->dev_info.flags & UBLK_F_ZONED && p->chunk_sectors)
> + ub->ub_disk->nr_zones = p->dev_sectors / p->chunk_sectors;
> +}
> +
> +static void ublk_dev_param_zoned_apply(struct ublk_device *ub)
> +{
> + const struct ublk_param_zoned *p = &ub->params.zoned;
> +
> + if (ub->dev_info.flags & UBLK_F_ZONED) {
> + disk_set_max_active_zones(ub->ub_disk, p->max_active_zones);
> + disk_set_max_open_zones(ub->ub_disk, p->max_open_zones);
> + }
> +}
> +
> +static int ublk_revalidate_disk_zones(struct gendisk *disk)
> +{
> + return blk_revalidate_disk_zones(disk, NULL);
> +}
> +
> +static int ublk_report_zones(struct gendisk *disk, sector_t sector,
> + unsigned int nr_zones, report_zones_cb cb,
> + void *data)
> +{
> + struct ublk_device *ub;
> + unsigned int zone_size;
> + unsigned int first_zone;
> + int ret = 0;
> +
> + ub = disk->private_data;
> +
> + if (!(ub->dev_info.flags & UBLK_F_ZONED))
> + return -EINVAL;
> +
> + zone_size = disk->queue->limits.chunk_sectors;
> + first_zone = sector >> ilog2(zone_size);
> + nr_zones = min(ub->ub_disk->nr_zones - first_zone, nr_zones);
> +
> + for (unsigned int i = 0; i < nr_zones; i++) {
> + struct request *req;
> + blk_status_t status;
> + struct blk_zone info = {0};
> +
> + req = blk_mq_alloc_request(disk->queue, REQ_OP_DRV_IN, 0);
> +
> + if (IS_ERR(req)) {
> + ret = PTR_ERR(req);
> + goto out;
> + }
> +
> + req->__sector = sector;
> +
> + ret = blk_rq_map_kern(disk->queue, req, &info, sizeof(info),
> + GFP_KERNEL);
> +
> + if (ret)
> + goto out;
> +
> + status = blk_execute_rq(req, 0);
> + ret = blk_status_to_errno(status);
> + if (ret)
> + goto out;
> +
> + blk_mq_free_request(req);
> +
> + ret = cb(&info, i, data);
> + if (ret)
> + goto out;
> +
> + /* A zero length zone means don't ask for more zones */
> + if (!info.len) {
> + nr_zones = i;
> + break;
> + }
> +
> + sector += zone_size;
> + }
> + ret = nr_zones;
> +
> + out:
> + return ret;
> +}
> +#else
> +void ublk_set_nr_zones(struct ublk_device *ub);
> +void ublk_dev_param_zoned_apply(struct ublk_device *ub);
> +int ublk_revalidate_disk_zones(struct gendisk *disk);
These are declarations, shouldn't they be dummy definitions instead?
e.g.
static int ublk_revalidate_disk_zones(struct gendisk *disk) { return -EOPNOTSUPP; };
It would be nice if they could be avoided altogether.
Looking how e.g. null-blk and btrfs has solved this:
https://github.com/torvalds/linux/blob/v6.2/fs/btrfs/Makefile#L39
https://github.com/torvalds/linux/blob/v6.2/drivers/block/null_blk/Makefile#L11
They have put the zoned stuff in a separate C file that is only compiled
when CONFIG_BLK_DEV_ZONED is set.
I'm not sure if a similar design is desired for ublk or not.
However, if a similar design pattern was used, it could probably avoid
some of these unpleasant dummy definitions altogether.
Kind regards,
Niklas
> +#endif
> +
next prev parent reply other threads:[~2023-02-27 10:20 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-24 20:05 [PATCH v2] block: ublk: enable zoned storage support Andreas Hindborg
2023-02-27 10:20 ` Niklas Cassel [this message]
2023-02-27 11:59 ` Andreas Hindborg
2023-02-27 14:29 ` Niklas Cassel
2023-02-27 14:41 ` Andreas Hindborg
2023-02-27 15:20 ` Minwoo Im
2023-02-27 15:36 ` Andreas Hindborg
2023-02-28 9:52 ` Hans Holmberg
2023-03-01 7:28 ` Andreas Hindborg
2023-03-02 2:50 ` Ming Lei
2023-03-02 7:31 ` Andreas Hindborg
2023-03-02 8:19 ` Damien Le Moal
2023-03-02 8:32 ` Ming Lei
2023-03-02 9:01 ` Ming Lei
2023-03-02 9:14 ` Ming Lei
2023-03-02 10:07 ` Andreas Hindborg
2023-03-02 13:16 ` Ming Lei
2023-03-02 13:28 ` Andreas Hindborg
2023-03-03 2:59 ` Ming Lei
2023-03-03 8:27 ` Andreas Hindborg
2023-03-03 11:47 ` Ming Lei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y/yD1WMJ5zc7KkBz@x1-carbon \
--to=niklas.cassel@wdc.com \
--cc=Hans.Holmberg@wdc.com \
--cc=Matias.Bjorling@wdc.com \
--cc=a.hindborg@samsung.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=ming.lei@redhat.com \
--cc=nmi@metaspace.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox