Commit 5aaffa84 authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Daniel Verkamp
Browse files

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: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/373759


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent e6a37c6a
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -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);
+26 −27
Original line number Diff line number Diff line
@@ -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)
{
+3 −10
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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);

+2 −16
Original line number Diff line number Diff line
@@ -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;
	}
Loading