vhost: add (set|get)_coalescing to backend interface

The current code for setting/getting coalescing setting only works with
vhost-user devices, while users can create virtio-blk devices with
non-vhost-user transport.  Calling spdk_vhost_(set|get)coalescing() on
such device results in a segfault.

So, spdk_vhost_dev_backend interface is extended with methods to
set / get coalescing parameters.  In the following patch, the virtio_blk
interface will be also extended with similar callbacks allowing us to
pipe coalescing settings to the appropriate transport.

Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: Ide5d5f633b17dcdbedb4b7804d5e45bf41373eca
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15771
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Konrad Sztyber 2022-12-05 11:25:36 +01:00 committed by Tomasz Zawadzki
parent a64acd100c
commit 25d55f48c1
5 changed files with 31 additions and 2 deletions

View File

@ -1685,7 +1685,7 @@ vhost_user_session_set_coalescing(struct spdk_vhost_dev *vdev,
}
int
spdk_vhost_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us,
vhost_user_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us,
uint32_t iops_threshold)
{
int rc;
@ -1696,11 +1696,12 @@ spdk_vhost_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us,
}
vhost_user_dev_foreach_session(vdev, vhost_user_session_set_coalescing, NULL, NULL);
return 0;
}
void
spdk_vhost_get_coalescing(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us,
vhost_user_get_coalescing(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us,
uint32_t *iops_threshold)
{
struct spdk_vhost_user_dev *user_dev = to_user_dev(vdev);

View File

@ -207,6 +207,22 @@ spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev)
return vdev->backend->remove_device(vdev);
}
int
spdk_vhost_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us,
uint32_t iops_threshold)
{
assert(vdev->backend->set_coalescing != NULL);
return vdev->backend->set_coalescing(vdev, delay_base_us, iops_threshold);
}
void
spdk_vhost_get_coalescing(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us,
uint32_t *iops_threshold)
{
assert(vdev->backend->get_coalescing != NULL);
vdev->backend->get_coalescing(vdev, delay_base_us, iops_threshold);
}
void
spdk_vhost_lock(void)
{

View File

@ -1557,6 +1557,8 @@ static const struct spdk_vhost_dev_backend vhost_blk_device_backend = {
.dump_info_json = vhost_blk_dump_info_json,
.write_config_json = vhost_blk_write_config_json,
.remove_device = vhost_blk_destroy,
.set_coalescing = vhost_user_set_coalescing,
.get_coalescing = vhost_user_get_coalescing,
};
int

View File

@ -234,6 +234,10 @@ struct spdk_vhost_dev_backend {
void (*dump_info_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
void (*write_config_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
int (*remove_device)(struct spdk_vhost_dev *vdev);
int (*set_coalescing)(struct spdk_vhost_dev *vdev, uint32_t delay_base_us,
uint32_t iops_threshold);
void (*get_coalescing)(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us,
uint32_t *iops_threshold);
};
void *vhost_gpa_to_vva(struct spdk_vhost_session *vsession, uint64_t addr, uint64_t len);
@ -501,6 +505,10 @@ int vhost_user_dev_register(struct spdk_vhost_dev *vdev, const char *name,
int vhost_user_dev_unregister(struct spdk_vhost_dev *vdev);
int vhost_user_init(void);
void vhost_user_fini(spdk_vhost_fini_cb vhost_cb);
int vhost_user_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us,
uint32_t iops_threshold);
void vhost_user_get_coalescing(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us,
uint32_t *iops_threshold);
int virtio_blk_construct_ctrlr(struct spdk_vhost_dev *vdev, const char *address,
struct spdk_cpuset *cpumask, const struct spdk_json_val *params,

View File

@ -136,6 +136,8 @@ static const struct spdk_vhost_dev_backend spdk_vhost_scsi_device_backend = {
.dump_info_json = vhost_scsi_dump_info_json,
.write_config_json = vhost_scsi_write_config_json,
.remove_device = vhost_scsi_dev_remove,
.set_coalescing = vhost_user_set_coalescing,
.get_coalescing = vhost_user_get_coalescing,
};
static inline void