From: Stefan Hajnoczi <stefanha@redhat.com>
To: Sam Li <faithilikerun@gmail.com>
Cc: qemu-devel@nongnu.org, damien.lemoal@opensource.wdc.com,
Dmitry.Fomichev@wdc.com, hare@suse.de, qemu-block@nongnu.org,
hreitz@redhat.com, eblake@redhat.com, armbru@redhat.com,
fam@euphon.net, kwolf@redhat.com
Subject: Re: [PATCH v8 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Date: Mon, 29 Aug 2022 15:29:48 -0400 [thread overview]
Message-ID: <Yw0TrFY3ImEngV6W@fedora> (raw)
In-Reply-To: <20220826161704.8076-1-faithilikerun@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4655 bytes --]
On Sat, Aug 27, 2022 at 12:17:04AM +0800, Sam Li wrote:
> +/*
> + * Send a zone_management command.
> + * op is the zone operation.
> + * offset is the starting zone specified as a sector offset.
Does "sector offset" mean "byte offset from the start of the device" or
does it mean in 512B sector units? For consistency this should be in
bytes.
> + * len is the maximum number of sectors the command should operate on. It
> + * should be aligned with the zone sector size.
Please use bytes for consistency with QEMU's block layer APIs.
> @@ -3022,6 +3183,118 @@ static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret)
> }
> }
>
> +/*
> + * zone report - Get a zone block device's information in the form
> + * of an array of zone descriptors.
> + *
> + * @param bs: passing zone block device file descriptor
> + * @param zones: an array of zone descriptors to hold zone
> + * information on reply
> + * @param offset: offset can be any byte within the zone size.
This isn't an offset within a zone, it's an offset within the entire
device, so I think "zone size" is confusing here.
> + * @param len: (not sure yet.
Please remove this and document nr_zones instead.
> + * @return 0 on success, -1 on failure
> + */
> +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset,
> + unsigned int *nr_zones,
> + BlockZoneDescriptor *zones) {
> +#if defined(CONFIG_BLKZONED)
> + BDRVRawState *s = bs->opaque;
> + RawPosixAIOData acb;
> +
> + acb = (RawPosixAIOData) {
> + .bs = bs,
> + .aio_fildes = s->fd,
> + .aio_type = QEMU_AIO_ZONE_REPORT,
> + .aio_offset = offset,
> + .zone_report = {
> + .nr_zones = nr_zones,
> + .zones = zones,
> + },
> + };
> +
> + return raw_thread_pool_submit(bs, handle_aiocb_zone_report, &acb);
> +#else
> + return -ENOTSUP;
> +#endif
> +}
> +
> +/*
> + * zone management operations - Execute an operation on a zone
> + */
> +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op,
> + int64_t offset, int64_t len) {
> +#if defined(CONFIG_BLKZONED)
> + BDRVRawState *s = bs->opaque;
> + RawPosixAIOData acb;
> + int64_t zone_sector, zone_sector_mask;
> + const char *ioctl_name;
> + unsigned long zone_op;
> + int ret;
> +
> + struct stat st;
> + if (fstat(s->fd, &st) < 0) {
> + ret = -errno;
> + return ret;
> + }
st is not used and can be removed.
> + zone_sector = bs->bl.zone_sectors;
> + zone_sector_mask = zone_sector - 1;
> + if (offset & zone_sector_mask) {
> + error_report("sector offset %" PRId64 " is not aligned to zone size "
> + "%" PRId64 "", offset, zone_sector);
> + return -EINVAL;
> + }
> +
> + if (len & zone_sector_mask) {
> + error_report("number of sectors %" PRId64 " is not aligned to zone size"
> + " %" PRId64 "", len, zone_sector);
> + return -EINVAL;
> + }
> +
> + switch (op) {
> + case BLK_ZO_OPEN:
> + ioctl_name = "BLKOPENZONE";
> + zone_op = BLKOPENZONE;
> + break;
> + case BLK_ZO_CLOSE:
> + ioctl_name = "BLKCLOSEZONE";
> + zone_op = BLKCLOSEZONE;
> + break;
> + case BLK_ZO_FINISH:
> + ioctl_name = "BLKFINISHZONE";
> + zone_op = BLKFINISHZONE;
> + break;
> + case BLK_ZO_RESET:
> + ioctl_name = "BLKRESETZONE";
> + zone_op = BLKRESETZONE;
> + break;
> + default:
> + error_report("Invalid zone operation 0x%x", op);
> + return -EINVAL;
> + }
> +
> + acb = (RawPosixAIOData) {
> + .bs = bs,
> + .aio_fildes = s->fd,
> + .aio_type = QEMU_AIO_ZONE_MGMT,
> + .aio_offset = offset,
> + .aio_nbytes = len,
> + .zone_mgmt = {
> + .zone_op = zone_op,
> + },
> + };
> +
> + ret = raw_thread_pool_submit(bs, handle_aiocb_zone_mgmt, &acb);
> + if (ret != 0) {
> + error_report("ioctl %s failed %d", ioctl_name, errno);
> + return -errno;
ret contains a negative errno value. The errno variable is not used by
raw_thread_pool_submit().
I suggest simplifying it to:
return raw_thread_pool_submit(bs, handle_aiocb_zone_mgmt, &acb);
That's what most of the other raw_thread_pool_submit() callers.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2022-08-29 19:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-26 16:17 [PATCH v8 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls Sam Li
2022-08-29 19:29 ` Stefan Hajnoczi [this message]
2022-08-30 11:57 ` Markus Armbruster
2022-08-30 15:05 ` Sam Li
2022-08-30 15:09 ` Markus Armbruster
2022-08-30 15:19 ` Sam Li
2022-08-31 8:35 ` Markus Armbruster
2022-08-31 8:48 ` Sam Li
2022-09-01 14:57 ` Markus Armbruster
2022-09-01 16:18 ` Markus Armbruster
2022-09-02 2:13 ` Damien Le Moal
2022-09-29 6:22 ` Markus Armbruster
-- strict thread matches above, loose matches on Subject: below --
2022-08-29 12:52 Sam Li
2022-08-29 13:00 ` Sam Li
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=Yw0TrFY3ImEngV6W@fedora \
--to=stefanha@redhat.com \
--cc=Dmitry.Fomichev@wdc.com \
--cc=armbru@redhat.com \
--cc=damien.lemoal@opensource.wdc.com \
--cc=eblake@redhat.com \
--cc=faithilikerun@gmail.com \
--cc=fam@euphon.net \
--cc=hare@suse.de \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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 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.