lib/bdev: Added spdk_bdev_zone_management()

spdk_bdev_zone_management() allows to perform
management action on a zone. Zone is specified
by start logical block address. Available zone
actions: open, close, reset and finish.

Change-Id: Ie7eaed3e2cc7b9b49dd51ee2d6c28b4ef2f23eb9
Signed-off-by: Wojciech Malikowski <wojciech.malikowski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/460647
Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Wojciech Malikowski 2019-07-05 11:13:34 -04:00 committed by Jim Harris
parent 02cabd9eb8
commit 2b16dcc740
4 changed files with 59 additions and 0 deletions

View File

@ -127,6 +127,7 @@ enum spdk_bdev_io_type {
SPDK_BDEV_IO_TYPE_WRITE_ZEROES,
SPDK_BDEV_IO_TYPE_ZCOPY,
SPDK_BDEV_IO_TYPE_GET_ZONE_INFO,
SPDK_BDEV_IO_TYPE_ZONE_MANAGEMENT,
SPDK_BDEV_NUM_IO_TYPES /* Keep last */
};

View File

@ -520,6 +520,9 @@ struct spdk_bdev_io {
/* Number of zones */
uint32_t num_zones;
/* Used to change zoned device zone state */
enum spdk_bdev_zone_action zone_action;
/* The data buffer */
void *buf;
} zone_mgmt;

View File

@ -49,6 +49,13 @@
struct spdk_bdev;
enum spdk_bdev_zone_action {
SPDK_BDEV_ZONE_CLOSE,
SPDK_BDEV_ZONE_FINISH,
SPDK_BDEV_ZONE_OPEN,
SPDK_BDEV_ZONE_RESET
};
enum spdk_bdev_zone_state {
SPDK_BDEV_ZONE_STATE_EMPTY,
SPDK_BDEV_ZONE_STATE_OPEN,
@ -113,4 +120,26 @@ int spdk_bdev_get_zone_info(struct spdk_bdev_desc *desc, struct spdk_io_channel
uint64_t zone_id, size_t num_zones, struct spdk_bdev_zone_info *info,
spdk_bdev_io_completion_cb cb, void *cb_arg);
/**
* Submit a zone_management request to the bdev.
*
* \ingroup bdev_io_submit_functions
*
* \param desc Block device descriptor.
* \param ch I/O channel. Obtained by calling spdk_bdev_get_io_channel().
* \param zone_id First logical block of a zone.
* \param action Action to perform on a zone (open, close, reset, finish).
* \param cb Called when the request is complete.
* \param cb_arg Argument passed to cb.
*
* \return 0 on success. On success, the callback will always
* be called (even if the request ultimately failed). Return
* negated errno on failure, in which case the callback will not be called.
* * -ENOMEM - spdk_bdev_io buffer cannot be allocated
*/
int spdk_bdev_zone_management(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
uint64_t zone_id, enum spdk_bdev_zone_action action,
spdk_bdev_io_completion_cb cb, void *cb_arg);
#endif /* SPDK_BDEV_ZONE_H */

View File

@ -81,3 +81,29 @@ spdk_bdev_get_zone_info(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
spdk_bdev_io_submit(bdev_io);
return 0;
}
int
spdk_bdev_zone_management(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
uint64_t zone_id, enum spdk_bdev_zone_action action,
spdk_bdev_io_completion_cb cb, void *cb_arg)
{
struct spdk_bdev *bdev = spdk_bdev_desc_get_bdev(desc);
struct spdk_bdev_io *bdev_io;
struct spdk_bdev_channel *channel = spdk_io_channel_get_ctx(ch);
bdev_io = spdk_bdev_get_io(channel);
if (!bdev_io) {
return -ENOMEM;
}
bdev_io->internal.ch = channel;
bdev_io->internal.desc = desc;
bdev_io->type = SPDK_BDEV_IO_TYPE_ZONE_MANAGEMENT;
bdev_io->u.zone_mgmt.zone_action = action;
bdev_io->u.zone_mgmt.zone_id = zone_id;
bdev_io->u.zone_mgmt.num_zones = 1;
spdk_bdev_io_init(bdev_io, bdev, cb_arg, cb);
spdk_bdev_io_submit(bdev_io);
return 0;
}