lib/vhost: Allocate cpumask statically for struct spdk_vhost_dev

Following the recent effort, allocate struct spdk_cpuset statically
for struct spdk_vhost_dev. In vhost_dev_register(), a dynamically
allocated  cpumask had been set to spdk_vhost_dev, but change it
to spdk_cpuset_copy().  So use local cpuset instance in vhost_dev_register()
accordingly.

To reduce the size of patch, this patch doesn't include the change
for g_tmp_cpuset. This will be done by the next patch.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ic97753d1f470cbfd9ae7fc7f2af8ced5a31c8477
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478578
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>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-12-20 02:56:57 -05:00 committed by Tomasz Zawadzki
parent 5b87daa92f
commit 1a1cbdf303
5 changed files with 10 additions and 18 deletions

View File

@ -592,7 +592,7 @@ vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *ma
const struct spdk_vhost_dev_backend *backend) const struct spdk_vhost_dev_backend *backend)
{ {
char path[PATH_MAX]; char path[PATH_MAX];
struct spdk_cpuset *cpumask; struct spdk_cpuset cpumask = {};
int rc; int rc;
assert(vdev); assert(vdev);
@ -601,13 +601,7 @@ vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *ma
return -EINVAL; return -EINVAL;
} }
cpumask = spdk_cpuset_alloc(); if (vhost_parse_core_mask(mask_str, &cpumask) != 0) {
if (!cpumask) {
SPDK_ERRLOG("spdk_cpuset_alloc failed\n");
return -ENOMEM;
}
if (vhost_parse_core_mask(mask_str, cpumask) != 0) {
SPDK_ERRLOG("cpumask %s is invalid (app mask is 0x%s)\n", SPDK_ERRLOG("cpumask %s is invalid (app mask is 0x%s)\n",
mask_str, spdk_cpuset_fmt(spdk_app_get_core_mask())); mask_str, spdk_cpuset_fmt(spdk_app_get_core_mask()));
rc = -EINVAL; rc = -EINVAL;
@ -636,7 +630,7 @@ vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *ma
goto out; goto out;
} }
vdev->cpumask = cpumask; spdk_cpuset_copy(&vdev->cpumask, &cpumask);
vdev->registered = true; vdev->registered = true;
vdev->backend = backend; vdev->backend = backend;
TAILQ_INIT(&vdev->vsessions); TAILQ_INIT(&vdev->vsessions);
@ -658,7 +652,6 @@ vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *ma
return 0; return 0;
out: out:
spdk_cpuset_free(cpumask);
return rc; return rc;
} }
@ -681,7 +674,6 @@ vhost_dev_unregister(struct spdk_vhost_dev *vdev)
free(vdev->name); free(vdev->name);
free(vdev->path); free(vdev->path);
spdk_cpuset_free(vdev->cpumask);
TAILQ_REMOVE(&g_vhost_devices, vdev, tailq); TAILQ_REMOVE(&g_vhost_devices, vdev, tailq);
return 0; return 0;
} }
@ -711,7 +703,7 @@ const struct spdk_cpuset *
spdk_vhost_dev_get_cpumask(struct spdk_vhost_dev *vdev) spdk_vhost_dev_get_cpumask(struct spdk_vhost_dev *vdev)
{ {
assert(vdev != NULL); assert(vdev != NULL);
return vdev->cpumask; return &vdev->cpumask;
} }
struct vhost_poll_group * struct vhost_poll_group *

View File

@ -792,7 +792,7 @@ vhost_blk_start(struct spdk_vhost_session *vsession)
{ {
struct vhost_poll_group *pg; struct vhost_poll_group *pg;
pg = vhost_get_poll_group(vsession->vdev->cpumask); pg = vhost_get_poll_group(&vsession->vdev->cpumask);
return vhost_session_send_event(pg, vsession, vhost_blk_start_cb, return vhost_session_send_event(pg, vsession, vhost_blk_start_cb,
3, "start session"); 3, "start session");
} }
@ -891,7 +891,7 @@ vhost_blk_write_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_
spdk_json_write_named_object_begin(w, "params"); spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_string(w, "ctrlr", vdev->name); spdk_json_write_named_string(w, "ctrlr", vdev->name);
spdk_json_write_named_string(w, "dev_name", spdk_bdev_get_name(bvdev->bdev)); spdk_json_write_named_string(w, "dev_name", spdk_bdev_get_name(bvdev->bdev));
spdk_json_write_named_string(w, "cpumask", spdk_cpuset_fmt(vdev->cpumask)); spdk_json_write_named_string(w, "cpumask", spdk_cpuset_fmt(&vdev->cpumask));
spdk_json_write_named_bool(w, "readonly", bvdev->readonly); spdk_json_write_named_bool(w, "readonly", bvdev->readonly);
spdk_json_write_object_end(w); spdk_json_write_object_end(w);

View File

@ -157,7 +157,7 @@ struct spdk_vhost_dev {
char *name; char *name;
char *path; char *path;
struct spdk_cpuset *cpumask; struct spdk_cpuset cpumask;
bool registered; bool registered;
uint64_t virtio_features; uint64_t virtio_features;

View File

@ -372,7 +372,7 @@ _spdk_rpc_get_vhost_controller(struct spdk_json_write_ctx *w, struct spdk_vhost_
spdk_json_write_object_begin(w); spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "ctrlr", spdk_vhost_dev_get_name(vdev)); spdk_json_write_named_string(w, "ctrlr", spdk_vhost_dev_get_name(vdev));
spdk_json_write_named_string_fmt(w, "cpumask", "0x%s", spdk_cpuset_fmt(vdev->cpumask)); spdk_json_write_named_string_fmt(w, "cpumask", "0x%s", spdk_cpuset_fmt(&vdev->cpumask));
spdk_json_write_named_uint32(w, "delay_base_us", delay_base_us); spdk_json_write_named_uint32(w, "delay_base_us", delay_base_us);
spdk_json_write_named_uint32(w, "iops_threshold", iops_threshold); spdk_json_write_named_uint32(w, "iops_threshold", iops_threshold);
spdk_json_write_named_string(w, "socket", vdev->path); spdk_json_write_named_string(w, "socket", vdev->path);

View File

@ -1367,7 +1367,7 @@ vhost_scsi_start(struct spdk_vhost_session *vsession)
svsession->svdev = svdev; svsession->svdev = svdev;
if (svdev->vdev.active_session_num == 0) { if (svdev->vdev.active_session_num == 0) {
svdev->poll_group = vhost_get_poll_group(svdev->vdev.cpumask); svdev->poll_group = vhost_get_poll_group(&svdev->vdev.cpumask);
} }
return vhost_session_send_event(svdev->poll_group, vsession, return vhost_session_send_event(svdev->poll_group, vsession,
@ -1521,7 +1521,7 @@ vhost_scsi_write_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write
spdk_json_write_named_object_begin(w, "params"); spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_string(w, "ctrlr", vdev->name); spdk_json_write_named_string(w, "ctrlr", vdev->name);
spdk_json_write_named_string(w, "cpumask", spdk_cpuset_fmt(vdev->cpumask)); spdk_json_write_named_string(w, "cpumask", spdk_cpuset_fmt(&vdev->cpumask));
spdk_json_write_object_end(w); spdk_json_write_object_end(w);
spdk_json_write_object_end(w); spdk_json_write_object_end(w);