From 5aaffa842eb307e1f2da766223418ab2621c5059 Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Thu, 10 Aug 2017 20:11:14 +0200 Subject: [PATCH] vhost: removed parse_core_mask function from public API This function was unnecessarily exposed in public vhost headers. Controller-constructing functions now take string cpumask param. Change-Id: Ie97d218c525b1dfb11cfd7e7e13c1bf702b1a58d Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/373759 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker --- include/spdk/vhost.h | 8 +++--- lib/vhost/vhost.c | 53 +++++++++++++++++++------------------- lib/vhost/vhost_blk.c | 13 +++------- lib/vhost/vhost_internal.h | 2 +- lib/vhost/vhost_rpc.c | 18 ++----------- lib/vhost/vhost_scsi.c | 13 +++------- 6 files changed, 38 insertions(+), 69 deletions(-) diff --git a/include/spdk/vhost.h b/include/spdk/vhost.h index ab82844a5..3b819b2ed 100644 --- a/include/spdk/vhost.h +++ b/include/spdk/vhost.h @@ -64,17 +64,15 @@ struct spdk_vhost_dev *spdk_vhost_dev_next(struct spdk_vhost_dev *prev); struct spdk_vhost_dev *spdk_vhost_dev_find(const char *ctrlr_name); const char *spdk_vhost_dev_get_name(struct spdk_vhost_dev *ctrl); uint64_t spdk_vhost_dev_get_cpumask(struct spdk_vhost_dev *ctrl); -int spdk_vhost_parse_core_mask(const char *mask, uint64_t *cpumask); int spdk_vhost_scsi_controller_construct(void); -int spdk_vhost_scsi_dev_construct(const char *name, uint64_t cpumask); +int spdk_vhost_scsi_dev_construct(const char *name, const char *cpumask); int spdk_vhost_scsi_dev_remove(struct spdk_vhost_dev *vdev); -struct spdk_scsi_dev *spdk_vhost_scsi_dev_get_dev(struct spdk_vhost_dev *ctrl, - uint8_t num); +struct spdk_scsi_dev *spdk_vhost_scsi_dev_get_dev(struct spdk_vhost_dev *ctrl, uint8_t num); int spdk_vhost_scsi_dev_add_dev(const char *name, unsigned scsi_dev_num, const char *lun_name); int spdk_vhost_scsi_dev_remove_dev(struct spdk_vhost_dev *vdev, unsigned scsi_dev_num); -int spdk_vhost_blk_construct(const char *name, uint64_t cpumask, const char *dev_name, +int spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_name, bool readonly); int spdk_vhost_blk_destroy(struct spdk_vhost_dev *dev); struct spdk_bdev *spdk_vhost_blk_get_dev(struct spdk_vhost_dev *ctrlr); diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index d693e50b5..5c4051a8a 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -297,14 +297,36 @@ spdk_vhost_dev_find(const char *ctrlr_name) return NULL; } +static int +spdk_vhost_parse_core_mask(const char *mask, uint64_t *cpumask) +{ + char *end; + + if (mask == NULL || cpumask == NULL) { + *cpumask = spdk_app_get_core_mask(); + return 0; + } + + errno = 0; + *cpumask = strtoull(mask, &end, 16); + + if (*end != '\0' || errno || !*cpumask || + ((*cpumask & spdk_app_get_core_mask()) != *cpumask)) { + return -1; + } + + return 0; +} + int -spdk_vhost_dev_construct(struct spdk_vhost_dev *vdev, const char *name, uint64_t cpumask, +spdk_vhost_dev_construct(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str, enum spdk_vhost_dev_type type, const struct spdk_vhost_dev_backend *backend) { unsigned ctrlr_num; char path[PATH_MAX]; struct stat file_stat; char buf[64]; + uint64_t cpumask; assert(vdev); @@ -313,9 +335,9 @@ spdk_vhost_dev_construct(struct spdk_vhost_dev *vdev, const char *name, uint64_t return -EINVAL; } - if ((cpumask & spdk_app_get_core_mask()) != cpumask) { - SPDK_ERRLOG("cpumask 0x%jx not a subset of app mask 0x%jx\n", - cpumask, spdk_app_get_core_mask()); + if (spdk_vhost_parse_core_mask(mask_str, &cpumask) != 0) { + SPDK_ERRLOG("cpumask %s not a subset of app mask 0x%jx\n", + mask_str, spdk_app_get_core_mask()); return -EINVAL; } @@ -435,29 +457,6 @@ spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev) return 0; } -int -spdk_vhost_parse_core_mask(const char *mask, uint64_t *cpumask) -{ - char *end; - - if (mask == NULL || cpumask == NULL) { - return -1; - } - - errno = 0; - *cpumask = strtoull(mask, &end, 16); - - if (*end != '\0' || errno || !*cpumask || - ((*cpumask & spdk_app_get_core_mask()) != *cpumask)) { - - SPDK_ERRLOG("cpumask %s not a subset of app mask 0x%jx\n", - mask, spdk_app_get_core_mask()); - return -1; - } - - return 0; -} - struct spdk_vhost_dev * spdk_vhost_dev_next(struct spdk_vhost_dev *prev) { diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index c0b846ff3..86c243148 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -621,9 +621,8 @@ spdk_vhost_blk_controller_construct(void) struct spdk_conf_section *sp; unsigned ctrlr_num; char *bdev_name; - char *cpumask_str; + char *cpumask; char *name; - uint64_t cpumask; bool readonly; for (sp = spdk_conf_first_section(NULL); sp != NULL; sp = spdk_conf_next_section(sp)) { @@ -643,14 +642,8 @@ spdk_vhost_blk_controller_construct(void) return -1; } - cpumask_str = spdk_conf_section_get_val(sp, "Cpumask"); + cpumask = spdk_conf_section_get_val(sp, "Cpumask"); readonly = spdk_conf_section_get_boolval(sp, "ReadOnly", false); - if (cpumask_str == NULL) { - cpumask = spdk_app_get_core_mask(); - } else if (spdk_vhost_parse_core_mask(cpumask_str, &cpumask)) { - SPDK_ERRLOG("%s: Error parsing cpumask '%s' while creating controller\n", name, cpumask_str); - return -1; - } bdev_name = spdk_conf_section_get_val(sp, "Dev"); if (bdev_name == NULL) { @@ -666,7 +659,7 @@ spdk_vhost_blk_controller_construct(void) } int -spdk_vhost_blk_construct(const char *name, uint64_t cpumask, const char *dev_name, bool readonly) +spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_name, bool readonly) { struct spdk_vhost_blk_dev *bvdev; struct spdk_bdev *bdev; diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index 6105bf294..8202cc5c2 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -131,7 +131,7 @@ int spdk_vhost_vring_desc_to_iov(struct spdk_vhost_dev *vdev, struct iovec *iov, uint16_t *iov_index, const struct vring_desc *desc); bool spdk_vhost_dev_has_feature(struct spdk_vhost_dev *vdev, unsigned feature_id); -int spdk_vhost_dev_construct(struct spdk_vhost_dev *vdev, const char *name, uint64_t cpumask, +int spdk_vhost_dev_construct(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str, enum spdk_vhost_dev_type type, const struct spdk_vhost_dev_backend *backend); int spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev); diff --git a/lib/vhost/vhost_rpc.c b/lib/vhost/vhost_rpc.c index 510334032..d3e86c705 100644 --- a/lib/vhost/vhost_rpc.c +++ b/lib/vhost/vhost_rpc.c @@ -68,7 +68,6 @@ spdk_rpc_construct_vhost_scsi_controller(struct spdk_jsonrpc_request *request, struct spdk_json_write_ctx *w; int rc; char buf[64]; - uint64_t cpumask; if (spdk_json_decode_object(params, rpc_construct_vhost_ctrlr, SPDK_COUNTOF(rpc_construct_vhost_ctrlr), @@ -78,13 +77,7 @@ spdk_rpc_construct_vhost_scsi_controller(struct spdk_jsonrpc_request *request, goto invalid; } - cpumask = spdk_app_get_core_mask(); - if (req.cpumask != NULL && spdk_vhost_parse_core_mask(req.cpumask, &cpumask)) { - rc = -EINVAL; - goto invalid; - } - - rc = spdk_vhost_scsi_dev_construct(req.ctrlr, cpumask); + rc = spdk_vhost_scsi_dev_construct(req.ctrlr, req.cpumask); if (rc < 0) { goto invalid; } @@ -319,7 +312,6 @@ spdk_rpc_construct_vhost_blk_controller(struct spdk_jsonrpc_request *request, struct spdk_json_write_ctx *w; int rc; char buf[64]; - uint64_t cpumask; if (spdk_json_decode_object(params, rpc_construct_vhost_blk_ctrlr, SPDK_COUNTOF(rpc_construct_vhost_blk_ctrlr), @@ -329,13 +321,7 @@ spdk_rpc_construct_vhost_blk_controller(struct spdk_jsonrpc_request *request, goto invalid; } - cpumask = spdk_app_get_core_mask(); - if (req.cpumask != NULL && spdk_vhost_parse_core_mask(req.cpumask, &cpumask)) { - rc = -EINVAL; - goto invalid; - } - - rc = spdk_vhost_blk_construct(req.ctrlr, cpumask, req.dev_name, req.readonly); + rc = spdk_vhost_blk_construct(req.ctrlr, req.cpumask, req.dev_name, req.readonly); if (rc < 0) { goto invalid; } diff --git a/lib/vhost/vhost_scsi.c b/lib/vhost/vhost_scsi.c index 45c9d64bf..0aad25cbb 100644 --- a/lib/vhost/vhost_scsi.c +++ b/lib/vhost/vhost_scsi.c @@ -744,7 +744,7 @@ to_scsi_dev(struct spdk_vhost_dev *ctrlr) } int -spdk_vhost_scsi_dev_construct(const char *name, uint64_t cpumask) +spdk_vhost_scsi_dev_construct(const char *name, const char *cpumask) { struct spdk_vhost_scsi_dev *svdev = spdk_dma_zmalloc(sizeof(struct spdk_vhost_scsi_dev), SPDK_CACHE_LINE_SIZE, NULL); @@ -967,9 +967,8 @@ spdk_vhost_scsi_controller_construct(void) int i, dev_num; unsigned ctrlr_num = 0; char *lun_name, *dev_num_str; - char *cpumask_str; + char *cpumask; char *name; - uint64_t cpumask; while (sp != NULL) { if (!spdk_conf_section_match_prefix(sp, "VhostScsi")) { @@ -984,13 +983,7 @@ spdk_vhost_scsi_controller_construct(void) } name = spdk_conf_section_get_val(sp, "Name"); - cpumask_str = spdk_conf_section_get_val(sp, "Cpumask"); - if (cpumask_str == NULL) { - cpumask = spdk_app_get_core_mask(); - } else if (spdk_vhost_parse_core_mask(cpumask_str, &cpumask)) { - SPDK_ERRLOG("%s: Error parsing cpumask '%s' while creating controller\n", name, cpumask_str); - return -1; - } + cpumask = spdk_conf_section_get_val(sp, "Cpumask"); if (spdk_vhost_scsi_dev_construct(name, cpumask) < 0) { return -1;