All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: Sam Li <faithilikerun@gmail.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	Dmitry Fomichev <dmitry.fomichev@wdc.com>,
	Markus Armbruster <armbru@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	qemu block <qemu-block@nongnu.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
	Hannes Reinecke <hare@suse.de>, Hanna Reitz <hreitz@redhat.com>
Subject: Re: [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Date: Sun, 11 Sep 2022 15:48:15 +0900	[thread overview]
Message-ID: <27ff94db-fa64-a4d6-00fc-fb289a386337@opensource.wdc.com> (raw)
In-Reply-To: <CAAAx-8LvWtTGs0cJaQ_LQi9S5fhaLx827E_xfLs1VQbEp8v_Gw@mail.gmail.com>

On 2022/09/11 15:33, Sam Li wrote:
> Damien Le Moal <damien.lemoal@opensource.wdc.com> 于2022年9月11日周日 13:31写道:
[...]
>>> +/*
>>> + * 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 *zone_op_name;
>>> +    unsigned long zone_op;
>>> +    bool is_all = false;
>>> +
>>> +    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) {
>>
>> Linux allows SMR drives to have a smaller last zone. So this needs to be
>> accounted for here. Otherwise, a zone operation that includes the last smaller
>> zone would always fail. Something like this would work:
>>
>>         if (((offset + len) < capacity &&
>>             len & zone_sector_mask) ||
>>             offset + len > capacity) {
>>
> 
> I see. I think the offset can be removed, like:
> if (((len < capacity && len & zone_sector_mask) || len > capacity) {
> Then if we use the previous zone's len for the last smaller zone, it
> will be greater than its capacity.

Nope, you cannot remove the offset since the zone operation may be for that last
zone only, that is, offset == last zone start and len == last zone smaller size.
In that case, len is alwats smaller than capacity.

> 
> I will also include "opening the last zone" as a test case later.

Note that you can create such smaller last zone on the host with null_blk by
specifying a device capacity that is *not* a multiple of the zone size.

> 
>>> +        error_report("number of sectors %" PRId64 " is not aligned to zone size"
>>> +                      " %" PRId64 "", len, zone_sector);
>>> +        return -EINVAL;
>>> +    }
>>> +
>>> +    switch (op) {
>>> +    case BLK_ZO_OPEN:
>>> +        zone_op_name = "BLKOPENZONE";
>>> +        zone_op = BLKOPENZONE;
>>> +        break;
>>> +    case BLK_ZO_CLOSE:
>>> +        zone_op_name = "BLKCLOSEZONE";
>>> +        zone_op = BLKCLOSEZONE;
>>> +        break;
>>> +    case BLK_ZO_FINISH:
>>> +        zone_op_name = "BLKFINISHZONE";
>>> +        zone_op = BLKFINISHZONE;
>>> +        break;
>>> +    case BLK_ZO_RESET:
>>> +        zone_op_name = "BLKRESETZONE";
>>> +        zone_op = BLKRESETZONE;
>>> +        break;
>>> +    default:
>>> +        g_assert_not_reached();
>>> +    }
>>> +
>>> +    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,
>>> +                .zone_op_name = zone_op_name,
>>> +                .all = is_all,
>>> +        },
>>> +    };
>>> +
>>> +    return raw_thread_pool_submit(bs, handle_aiocb_zone_mgmt, &acb);
>>> +#else
>>> +    return -ENOTSUP;
>>> +#endif
>>> +}

-- 
Damien Le Moal
Western Digital Research



  reply	other threads:[~2022-09-11  6:51 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-10  5:27 [PATCH v9 0/7] Add support for zoned device Sam Li
2022-09-10  5:27 ` [PATCH v9 1/7] include: add zoned device structs Sam Li
2022-09-15  8:05   ` Eric Blake
2022-09-15 10:06     ` Sam Li
2022-09-16 15:16       ` Stefan Hajnoczi
2022-09-19  0:50         ` Sam Li
2022-09-19  8:04           ` Damien Le Moal
2022-09-19  8:06             ` Sam Li
2022-09-10  5:27 ` [PATCH v9 2/7] file-posix: introduce helper functions for sysfs attributes Sam Li
2022-09-11  4:56   ` Damien Le Moal
2022-09-10  5:27 ` [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls Sam Li
2022-09-11  5:31   ` Damien Le Moal
2022-09-11  6:33     ` Sam Li
2022-09-11  6:48       ` Damien Le Moal [this message]
2022-09-11  7:30         ` Sam Li
2022-09-11  7:02   ` Damien Le Moal
2022-09-16 16:00   ` Stefan Hajnoczi
2022-09-20  8:51   ` Klaus Jensen
2022-09-20 13:21     ` Sam Li
2022-09-21  4:44     ` Damien Le Moal
2022-09-21  9:08       ` Klaus Jensen
2022-09-10  5:27 ` [PATCH v9 4/7] raw-format: add zone operations to pass through requests Sam Li
2022-09-11  5:32   ` Damien Le Moal
2022-09-10  5:27 ` [PATCH v9 5/7] config: add check to block layer Sam Li
2022-09-11  5:34   ` Damien Le Moal
2022-09-11  6:54     ` Sam Li
2022-09-11  7:05       ` Damien Le Moal
2022-09-16 15:22   ` Stefan Hajnoczi
2022-09-10  5:27 ` [PATCH v9 6/7] qemu-iotests: test new zone operations Sam Li
2022-09-10  5:27 ` [PATCH v9 7/7] docs/zoned-storage: add zoned device documentation Sam Li
2022-09-11  5:38   ` Damien Le Moal

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=27ff94db-fa64-a4d6-00fc-fb289a386337@opensource.wdc.com \
    --to=damien.lemoal@opensource.wdc.com \
    --cc=armbru@redhat.com \
    --cc=dmitry.fomichev@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 \
    --cc=stefanha@redhat.com \
    /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.