Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bdev ext api #36

Open
wants to merge 4 commits into
base: upstream_master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ parameter in spdk_bdev_get_opts function. Two fields `small_buf_pool_size` and
`large_buf_pool_size` were added into spdk_bdev_opts, which were used to determine
the small and large buffer pool size of the whole bdev module.

New API `spdk_bdev_get_caps` has been added, it allows to get extended bdev module
capabilities.

### blob

An `opts_size` element was added in the `spdk_bs_opts` structure to solve the
Expand Down
24 changes: 24 additions & 0 deletions include/spdk/bdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,30 @@ void spdk_bdev_histogram_get(struct spdk_bdev *bdev, struct spdk_histogram_data
size_t spdk_bdev_get_media_events(struct spdk_bdev_desc *bdev_desc,
struct spdk_bdev_media_event *events, size_t max_events);

enum spdk_bdev_capability_type {
/** Bdev supports indirect memory access using Memory Key.
* That means that the user of ext bdev API can fill spdk_bdev_ext_io_opts_mem_type
* structure and set SPDK_BDEV_EXT_IO_OPTS_MEM_TYPE flag in spdk_bdev_ext_io_opts structure */
SPDK_BDEV_CAP_EXT_MEMORY_TYPE_MKEY = 1u << 0u,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Bdev supports indirect memory access using Memory Key.

  • That means that the user of ext bdev API can fill spdk_bdev_ext_io_opts_mem_type
  • structure and set SPDK_BDEV_EXT_IO_OPTS_MEM_TYPE flag in spdk_bdev_ext_io_opts structure
  • That also means that bdev can work with regular memory buffers */

};

/** Describes capabilities of Block device */
struct spdk_bdev_capability {
/** Size of this structure in bytes, should be set by the user */
size_t size;
/** bitwise combination of \ref spdk_bdev_capability_type */
uint64_t flags;
};

/**
* Get bdev capabilities
*
* \param bdev Block device
* \param caps Capabilities of Block device to be filled by this function
* \return 0 on success, negated errno on failure.
*/
int spdk_bdev_get_caps(struct spdk_bdev *bdev, struct spdk_bdev_capability *caps);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to
spdk_bdev_get_ext_caps


#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions include/spdk/bdev_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ struct spdk_bdev_fn_table {

/** Get bdev module context. */
void *(*get_module_ctx)(void *ctx);

/** Get block device capabilities */
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extended capabilities

void (*get_caps)(void *ctx, struct spdk_bdev_capability *caps);
};

/** bdev I/O completion status */
Expand Down
23 changes: 23 additions & 0 deletions lib/bdev/bdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -6813,6 +6813,29 @@ bdev_unlock_lba_range(struct spdk_bdev_desc *desc, struct spdk_io_channel *_ch,
return 0;
}

int
spdk_bdev_get_caps(struct spdk_bdev *bdev, struct spdk_bdev_capability *caps)
{
struct spdk_bdev_capability caps_local;

if (!caps || !caps->size) {
return -EINVAL;
}

memset(&caps_local, 0, sizeof(caps_local));
caps_local.size = spdk_min(sizeof(caps_local), caps->size);

if (bdev->fn_table->get_caps) {
bdev->fn_table->get_caps(bdev->ctxt, &caps_local);
}

/* The user may use older or newer SPDK version where size of this structure can be different.
* Here we copy only the number of bytes requested by the user and supported by SPDK */
memcpy(caps, &caps_local, caps_local.size);

return 0;
}

SPDK_LOG_REGISTER_COMPONENT(bdev)

SPDK_TRACE_REGISTER_FN(bdev_trace, "bdev", TRACE_GROUP_BDEV)
Expand Down
11 changes: 11 additions & 0 deletions module/bdev/delay/vbdev_delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,16 @@ vbdev_delay_write_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx
/* No config per bdev needed */
}

static void
vbdev_delay_get_caps(void *ctx, struct spdk_bdev_capability *caps)
{
struct vbdev_delay *delay_node = (struct vbdev_delay *)ctx;

if (delay_node->base_bdev->fn_table->get_caps) {
delay_node->base_bdev->fn_table->get_caps(delay_node->base_bdev, caps);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint64_t local_flags = 0;

if (caps->flags & SPDK_BDEV_CAP_EXT_MEMORY_TYPE_MKEY) {
/* Delay bdev doesn't modify data so it can work with indirect memory if it is supported by underlying bdev */
local_flags |= SPDK_BDEV_CAP_EXT_MEMORY_TYPE_MKEY
}
caps->flags = local_flags;

compress/crypto:
uint64_t local_flags = 0;

}
}

/* When we register our bdev this is how we specify our entry points. */
static const struct spdk_bdev_fn_table vbdev_delay_fn_table = {
.destruct = vbdev_delay_destruct,
Expand All @@ -679,6 +689,7 @@ static const struct spdk_bdev_fn_table vbdev_delay_fn_table = {
.get_io_channel = vbdev_delay_get_io_channel,
.dump_info_json = vbdev_delay_dump_info_json,
.write_config_json = vbdev_delay_write_config_json,
.get_caps = vbdev_delay_get_caps,
};

static void
Expand Down
11 changes: 11 additions & 0 deletions module/bdev/nvme/bdev_nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,16 @@ bdev_nvme_get_module_ctx(void *ctx)
return bdev_nvme_get_ctrlr(&nvme_bdev->disk);
}

static void
bdev_nvme_get_caps(void *ctx, struct spdk_bdev_capability *caps)
{
struct nvme_bdev *nbdev = ctx;

if (nbdev->nvme_ns->ctrlr->connected_trid->trtype == SPDK_NVME_TRANSPORT_RDMA) {
caps->flags |= SPDK_BDEV_CAP_EXT_MEMORY_TYPE_MKEY;
}
}

static int
bdev_nvme_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
{
Expand Down Expand Up @@ -1132,6 +1142,7 @@ static const struct spdk_bdev_fn_table nvmelib_fn_table = {
.write_config_json = bdev_nvme_write_config_json,
.get_spin_time = bdev_nvme_get_spin_time,
.get_module_ctx = bdev_nvme_get_module_ctx,
.get_caps = bdev_nvme_get_caps,
};

static int
Expand Down
11 changes: 11 additions & 0 deletions module/bdev/passthru/vbdev_passthru.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,16 @@ vbdev_passthru_write_config_json(struct spdk_bdev *bdev, struct spdk_json_write_
/* No config per bdev needed */
}

static void
vbdev_passthru_get_caps(void *ctx, struct spdk_bdev_capability *caps)
{
struct vbdev_passthru *pt_node = (struct vbdev_passthru *)ctx;

if (pt_node->base_bdev->fn_table->get_caps) {
pt_node->base_bdev->fn_table->get_caps(pt_node->base_bdev, caps);
}
}

/* When we register our bdev this is how we specify our entry points. */
static const struct spdk_bdev_fn_table vbdev_passthru_fn_table = {
.destruct = vbdev_passthru_destruct,
Expand All @@ -558,6 +568,7 @@ static const struct spdk_bdev_fn_table vbdev_passthru_fn_table = {
.get_io_channel = vbdev_passthru_get_io_channel,
.dump_info_json = vbdev_passthru_dump_info_json,
.write_config_json = vbdev_passthru_write_config_json,
.get_caps = vbdev_passthru_get_caps,
};

static void
Expand Down