From: Damien Le Moal <dlemoal@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
"Martin K . Petersen" <martin.petersen@oracle.com>
Subject: Re: [PATCH v3 3/7] block: add storage element management ioctls
Date: Wed, 7 Oct 2026 16:37:49 +0200 [thread overview]
Message-ID: <e11de48b-e719-4cfc-a08d-916a8603782d@kernel.org> (raw)
In-Reply-To: <20261007133922.GC31906@lst.de>
On 2026/10/07 15:39, Christoph Hellwig wrote:
>> + if (copy_from_user(&rep, argp,
>> + sizeof(struct blk_storage_elements_report)))
>
> Can we shorten the name of the struct a bit? blk_se_report?
> Similar for other identifiers?
Sure.
>
>> + return -EFAULT;
>> +
>> + ret = bdev_report_storage_elements(bdev, NULL, &nr_elements);
>> + if (ret)
>> + return ret;
>> +
>> + nr_elements = min(rep.nr_elements, nr_elements);
>> + if (!nr_elements)
>> + return -EINVAL;
>> +
>> + elements = kzalloc_objs(struct blk_storage_element, nr_elements);
>
> This doesn't work as it could race. We'll always need to allocate
> the space for all the elements the user asked for?
I am not following... The number of elements of a drive never changes, and that
is what nr_elements indicates. So getting the min with the user indicated value
still gives all elements, and that also creates a bound in case we get a crazy
large value from the user.
>
>> + retc = copy_to_user(argp + sizeof(struct blk_storage_elements_report),
>> + elements,
>> + sizeof(struct blk_storage_element) * nr_elements);
>> + if (retc) {
>> + ret = -EFAULT;
>> + goto free_elements;
>> + }
>> +
>> + rep.nr_elements = nr_elements;
>> + retc = copy_to_user(argp, &rep,
>> + sizeof(struct blk_storage_elements_report));
>
> Why not copy back the entire struct in one go?
Indeed.
>> + ret = truncate_bdev_range(bdev, mode, 0,
>> + (get_capacity(bdev->bd_disk) << SECTOR_SHIFT) - 1);
>
> Use bdev_nr_bytes() here?
>
>> + /*
>> + * Storage element restoration is a destructive operation that will
>> + * reset all zones. So fflush the device volatile write cache and
>> + * invalidate all cached data that we may have.
>> + */
>> + filemap_invalidate_lock(bdev->bd_mapping);
>> + ret = blkdev_issue_flush(bdev->bd_disk->part0);
>> + if (!ret)
>> + ret = truncate_bdev_range(bdev, mode, 0,
>> + (get_capacity(bdev->bd_disk) << SECTOR_SHIFT) - 1);
>
> Same. Also what about factoring the duplicate code block into a helper?
Yes.
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2026-10-07 14:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 8:23 [PATCH v3 0/7] Add support for storage element depopulation Damien Le Moal
2026-10-07 8:23 ` [PATCH v3 1/7] block: fail reads to offline zones early Damien Le Moal
2026-10-07 8:41 ` sashiko-bot
2026-10-07 13:29 ` Christoph Hellwig
2026-10-07 14:31 ` Damien Le Moal
2026-10-07 8:23 ` [PATCH v3 2/7] block: introduce storage element management Damien Le Moal
2026-10-07 8:34 ` sashiko-bot
2026-10-07 13:35 ` Christoph Hellwig
2026-10-07 14:35 ` Damien Le Moal
2026-10-07 8:23 ` [PATCH v3 3/7] block: add storage element management ioctls Damien Le Moal
2026-10-07 8:39 ` sashiko-bot
2026-10-07 13:39 ` Christoph Hellwig
2026-10-07 14:37 ` Damien Le Moal [this message]
2026-10-07 15:28 ` Christoph Hellwig
2026-10-07 8:23 ` [PATCH v3 4/7] zloop: add storage element emulation Damien Le Moal
2026-10-07 8:35 ` sashiko-bot
2026-10-07 13:40 ` Christoph Hellwig
2026-10-07 8:23 ` [PATCH v3 5/7] zloop: add degrade_element control command Damien Le Moal
2026-10-07 8:39 ` sashiko-bot
2026-10-07 8:23 ` [PATCH v3 6/7] scsi: sd_zbc: always revalidate zones for disks supporting head depopulation Damien Le Moal
2026-10-07 8:35 ` sashiko-bot
2026-10-07 8:23 ` [PATCH v3 7/7] scsi: sd_zbc: define storage element management operations Damien Le Moal
2026-10-07 8:40 ` sashiko-bot
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=e11de48b-e719-4cfc-a08d-916a8603782d@kernel.org \
--to=dlemoal@kernel.org \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox