nvme/cuse: get functions for cuse ctrlr/ns names to accept a buffer
This was changed to better facilitate thread safety. In next patch a lock will be held when going over the cuse devices list. Now user is expected to pass a buffer of a sufficient size that will be filled with ctrlr or ns cuse device name. Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Change-Id: I3202ef285e427111e3595389619463fda58dbef6 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1978 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
d9a11fd5b1
commit
e396d97db0
@ -3008,20 +3008,29 @@ void spdk_nvme_rdma_init_hooks(struct spdk_nvme_rdma_hooks *hooks);
|
|||||||
* Get name of cuse device associated with NVMe controller.
|
* Get name of cuse device associated with NVMe controller.
|
||||||
*
|
*
|
||||||
* \param ctrlr Opaque handle to NVMe controller.
|
* \param ctrlr Opaque handle to NVMe controller.
|
||||||
|
* \param name Buffer of be filled with cuse device name.
|
||||||
|
* \param size Size of name buffer.
|
||||||
*
|
*
|
||||||
* \return Pointer to the name of device.
|
* \return 0 on success. Negated errno on the following error conditions:
|
||||||
|
* -ENODEV: No cuse device registered for the controller.
|
||||||
|
* -ENSPC: Too small buffer size passed. Value of size pointer changed to the required length.
|
||||||
*/
|
*/
|
||||||
char *spdk_nvme_cuse_get_ctrlr_name(struct spdk_nvme_ctrlr *ctrlr);
|
int spdk_nvme_cuse_get_ctrlr_name(struct spdk_nvme_ctrlr *ctrlr, char *name, size_t *size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get name of cuse device associated with NVMe namespace.
|
* Get name of cuse device associated with NVMe namespace.
|
||||||
*
|
*
|
||||||
* \param ctrlr Opaque handle to NVMe controller.
|
* \param ctrlr Opaque handle to NVMe controller.
|
||||||
* \param nsid Namespace id.
|
* \param nsid Namespace id.
|
||||||
|
* \param name Buffer of be filled with cuse device name.
|
||||||
|
* \param size Size of name buffer.
|
||||||
*
|
*
|
||||||
* \return Pointer to the name of device.
|
* \return 0 on success. Negated errno on the following error conditions:
|
||||||
|
* -ENODEV: No cuse device registered for the namespace.
|
||||||
|
* -ENSPC: Too small buffer size passed. Value of size pointer changed to the required length.
|
||||||
*/
|
*/
|
||||||
char *spdk_nvme_cuse_get_ns_name(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid);
|
int spdk_nvme_cuse_get_ns_name(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
|
||||||
|
char *name, size_t *size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a character device at the path specified (Experimental)
|
* Create a character device at the path specified (Experimental)
|
||||||
|
@ -960,28 +960,44 @@ spdk_nvme_cuse_unregister(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
int
|
||||||
spdk_nvme_cuse_get_ctrlr_name(struct spdk_nvme_ctrlr *ctrlr)
|
spdk_nvme_cuse_get_ctrlr_name(struct spdk_nvme_ctrlr *ctrlr, char *name, size_t *size)
|
||||||
{
|
{
|
||||||
struct cuse_device *ctrlr_device;
|
struct cuse_device *ctrlr_device;
|
||||||
|
size_t req_len;
|
||||||
|
|
||||||
ctrlr_device = nvme_cuse_get_cuse_ctrlr_device(ctrlr);
|
ctrlr_device = nvme_cuse_get_cuse_ctrlr_device(ctrlr);
|
||||||
if (!ctrlr_device) {
|
if (!ctrlr_device) {
|
||||||
return NULL;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctrlr_device->dev_name;
|
req_len = strnlen(ctrlr_device->dev_name, sizeof(ctrlr_device->dev_name));
|
||||||
|
if (*size < req_len) {
|
||||||
|
*size = req_len;
|
||||||
|
return -ENOSPC;
|
||||||
|
}
|
||||||
|
snprintf(name, req_len + 1, "%s", ctrlr_device->dev_name);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
int
|
||||||
spdk_nvme_cuse_get_ns_name(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid)
|
spdk_nvme_cuse_get_ns_name(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid, char *name, size_t *size)
|
||||||
{
|
{
|
||||||
struct cuse_device *ns_device;
|
struct cuse_device *ns_device;
|
||||||
|
size_t req_len;
|
||||||
|
|
||||||
ns_device = nvme_cuse_get_cuse_ns_device(ctrlr, nsid);
|
ns_device = nvme_cuse_get_cuse_ns_device(ctrlr, nsid);
|
||||||
if (!ns_device) {
|
if (!ns_device) {
|
||||||
return NULL;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ns_device->dev_name;
|
req_len = strnlen(ns_device->dev_name, sizeof(ns_device->dev_name));
|
||||||
|
if (*size < req_len) {
|
||||||
|
*size = req_len;
|
||||||
|
return -ENOSPC;
|
||||||
|
}
|
||||||
|
snprintf(name, req_len + 1, "%s", ns_device->dev_name);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -765,12 +765,13 @@ bdev_nvme_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
|
|||||||
spdk_json_write_object_end(w);
|
spdk_json_write_object_end(w);
|
||||||
|
|
||||||
#ifdef SPDK_CONFIG_NVME_CUSE
|
#ifdef SPDK_CONFIG_NVME_CUSE
|
||||||
char *cuse_device;
|
size_t cuse_name_size = 128;
|
||||||
|
char cuse_name[cuse_name_size];
|
||||||
|
|
||||||
cuse_device = spdk_nvme_cuse_get_ns_name(nvme_bdev->nvme_bdev_ctrlr->ctrlr,
|
int rc = spdk_nvme_cuse_get_ns_name(nvme_bdev->nvme_bdev_ctrlr->ctrlr, spdk_nvme_ns_get_id(ns),
|
||||||
spdk_nvme_ns_get_id(ns));
|
cuse_name, &cuse_name_size);
|
||||||
if (cuse_device) {
|
if (rc == 0) {
|
||||||
spdk_json_write_named_string(w, "cuse_device", cuse_device);
|
spdk_json_write_named_string(w, "cuse_device", cuse_name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -355,11 +355,12 @@ spdk_rpc_dump_nvme_controller_info(struct spdk_json_write_ctx *w,
|
|||||||
spdk_json_write_named_string(w, "name", nvme_bdev_ctrlr->name);
|
spdk_json_write_named_string(w, "name", nvme_bdev_ctrlr->name);
|
||||||
|
|
||||||
#ifdef SPDK_CONFIG_NVME_CUSE
|
#ifdef SPDK_CONFIG_NVME_CUSE
|
||||||
char *cuse_device;
|
size_t cuse_name_size = 128;
|
||||||
|
char cuse_name[cuse_name_size];
|
||||||
|
|
||||||
cuse_device = spdk_nvme_cuse_get_ctrlr_name(nvme_bdev_ctrlr->ctrlr);
|
int rc = spdk_nvme_cuse_get_ctrlr_name(nvme_bdev_ctrlr->ctrlr, cuse_name, &cuse_name_size);
|
||||||
if (cuse_device) {
|
if (rc == 0) {
|
||||||
spdk_json_write_named_string(w, "cuse_device", cuse_device);
|
spdk_json_write_named_string(w, "cuse_device", cuse_name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user