vhost: don't expose backend structures outside backend implementation

Theres no need to have vhost SCSI (and incoming vhost block) structures
available in public API. Generic spdk_vhost_dev might be used to
communicate with backedns. Backends are responsible to check if type of
passed vdev valid.

Change-Id: I850a1cc661166ee146d513b0069bb40edc9a761a
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/363581
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Pawel Wodkowski 2017-06-02 18:00:22 +02:00 committed by Ben Walker
parent 329d5510e9
commit 1b93872dbb
6 changed files with 61 additions and 72 deletions

View File

@ -51,7 +51,6 @@ void spdk_vhost_shutdown_cb(void);
/* Forward declaration */ /* Forward declaration */
struct spdk_vhost_dev; struct spdk_vhost_dev;
struct spdk_vhost_scsi_dev;
/** /**
* Get handle to next controller. * Get handle to next controller.
@ -64,4 +63,13 @@ const char *spdk_vhost_dev_get_name(struct spdk_vhost_dev *ctrl);
uint64_t spdk_vhost_dev_get_cpumask(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_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_remove(struct spdk_vhost_dev *vdev);
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);
#endif /* SPDK_VHOST_H */ #endif /* SPDK_VHOST_H */

View File

@ -39,7 +39,6 @@
#include "spdk/vhost.h" #include "spdk/vhost.h"
#include "vhost_internal.h" #include "vhost_internal.h"
#include "vhost_scsi.h"
#include "task.h" #include "task.h"
#include "vhost_iommu.h" #include "vhost_iommu.h"

View File

@ -53,6 +53,8 @@
#define MAX_VHOST_VRINGS 256 #define MAX_VHOST_VRINGS 256
#define SPDK_VHOST_SCSI_CTRLR_MAX_DEVS 8
enum spdk_vhost_dev_type { enum spdk_vhost_dev_type {
SPDK_VHOST_DEV_T_SCSI, SPDK_VHOST_DEV_T_SCSI,
}; };

View File

@ -32,14 +32,13 @@
*/ */
#include "spdk/stdinc.h" #include "spdk/stdinc.h"
#include "spdk_internal/log.h" #include "spdk_internal/log.h"
#include "spdk/rpc.h" #include "spdk/rpc.h"
#include "spdk/util.h" #include "spdk/util.h"
#include "vhost_scsi.h"
#include "spdk/vhost.h" #include "spdk/vhost.h"
#include "task.h" #include "task.h"
#include "vhost_internal.h"
static void static void
json_scsi_dev_write(struct spdk_json_write_ctx *ctx, struct spdk_scsi_dev *dev) json_scsi_dev_write(struct spdk_json_write_ctx *ctx, struct spdk_scsi_dev *dev)
@ -108,7 +107,7 @@ spdk_rpc_get_vhost_scsi_controllers(struct spdk_jsonrpc_server_conn *conn,
spdk_json_write_array_begin(w); spdk_json_write_array_begin(w);
for (i = 0; i < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; i++) { for (i = 0; i < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; i++) {
dev = spdk_vhost_scsi_dev_get_dev((struct spdk_vhost_scsi_dev *) vdev, i); dev = spdk_vhost_scsi_dev_get_dev(vdev, i);
if (!dev) if (!dev)
continue; continue;
@ -224,7 +223,7 @@ spdk_rpc_remove_vhost_scsi_controller(struct spdk_jsonrpc_server_conn *conn,
goto invalid; goto invalid;
} }
rc = spdk_vhost_scsi_dev_remove((struct spdk_vhost_scsi_dev *) vdev); rc = spdk_vhost_scsi_dev_remove(vdev);
if (rc < 0) { if (rc < 0) {
goto invalid; goto invalid;
} }
@ -340,7 +339,7 @@ spdk_rpc_remove_vhost_scsi_dev(struct spdk_jsonrpc_server_conn *conn,
goto invalid; goto invalid;
} }
rc = spdk_vhost_scsi_dev_remove_dev((struct spdk_vhost_scsi_dev *) vdev, req.scsi_dev_num); rc = spdk_vhost_scsi_dev_remove_dev(vdev, req.scsi_dev_num);
if (rc < 0) { if (rc < 0) {
goto invalid; goto invalid;
} }

View File

@ -37,12 +37,12 @@
#include "spdk/env.h" #include "spdk/env.h"
#include "spdk/scsi.h" #include "spdk/scsi.h"
#include "spdk/scsi_spec.h"
#include "spdk/conf.h" #include "spdk/conf.h"
#include "spdk/event.h" #include "spdk/event.h"
#include "spdk/vhost.h" #include "spdk/vhost.h"
#include "vhost_internal.h" #include "vhost_internal.h"
#include "vhost_scsi.h"
#include "task.h" #include "task.h"
/* Features supported by SPDK VHOST lib. */ /* Features supported by SPDK VHOST lib. */
@ -566,6 +566,22 @@ remove_vdev_cb(void *arg)
spdk_vhost_dev_mem_unregister(&svdev->vdev); spdk_vhost_dev_mem_unregister(&svdev->vdev);
} }
static struct spdk_vhost_scsi_dev *
to_scsi_dev(struct spdk_vhost_dev *ctrlr)
{
if (ctrlr == NULL) {
return NULL;
}
if (ctrlr->type != SPDK_VHOST_DEV_T_SCSI) {
SPDK_ERRLOG("Controller %s: expected SCSI controller (%d) but got %d\n",
ctrlr->name, SPDK_VHOST_DEV_T_SCSI, ctrlr->type);
return NULL;
}
return (struct spdk_vhost_scsi_dev *)ctrlr;
}
int int
spdk_vhost_scsi_dev_construct(const char *name, uint64_t cpumask) spdk_vhost_scsi_dev_construct(const char *name, uint64_t cpumask)
{ {
@ -588,12 +604,15 @@ spdk_vhost_scsi_dev_construct(const char *name, uint64_t cpumask)
} }
int int
spdk_vhost_scsi_dev_remove(struct spdk_vhost_scsi_dev *svdev) spdk_vhost_scsi_dev_remove(struct spdk_vhost_dev *vdev)
{ {
struct spdk_vhost_dev *vdev; struct spdk_vhost_scsi_dev *svdev = to_scsi_dev(vdev);
int i; int i;
vdev = &svdev->vdev; if (svdev == NULL) {
return -EINVAL;
}
for (i = 0; i < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; ++i) { for (i = 0; i < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; ++i) {
if (svdev->scsi_dev[i]) { if (svdev->scsi_dev[i]) {
SPDK_ERRLOG("Trying to remove non-empty controller: %s.\n", vdev->name); SPDK_ERRLOG("Trying to remove non-empty controller: %s.\n", vdev->name);
@ -610,11 +629,14 @@ spdk_vhost_scsi_dev_remove(struct spdk_vhost_scsi_dev *svdev)
} }
struct spdk_scsi_dev * struct spdk_scsi_dev *
spdk_vhost_scsi_dev_get_dev(struct spdk_vhost_scsi_dev *svdev, uint8_t num) spdk_vhost_scsi_dev_get_dev(struct spdk_vhost_dev *vdev, uint8_t num)
{ {
assert(svdev != NULL); struct spdk_vhost_scsi_dev *svdev;
assert(num < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS); assert(num < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS);
return svdev->scsi_dev[num]; svdev = to_scsi_dev(vdev);
return svdev ? svdev->scsi_dev[num] : NULL;
} }
int int
@ -645,13 +667,16 @@ spdk_vhost_scsi_dev_add_dev(const char *ctrlr_name, unsigned scsi_dev_num, const
return -1; return -1;
} }
svdev = (struct spdk_vhost_scsi_dev *) spdk_vhost_dev_find(ctrlr_name); vdev = spdk_vhost_dev_find(ctrlr_name);
if (svdev == NULL) { if (vdev == NULL) {
SPDK_ERRLOG("Controller %s is not defined\n", ctrlr_name); SPDK_ERRLOG("Controller %s is not defined.\n", ctrlr_name);
return -ENODEV; return -ENODEV;
} }
vdev = &svdev->vdev; svdev = to_scsi_dev(vdev);
if (svdev == NULL) {
return -EINVAL;
}
if (vdev->lcore != -1) { if (vdev->lcore != -1) {
SPDK_ERRLOG("Controller %s is in use and hotplug is not supported\n", ctrlr_name); SPDK_ERRLOG("Controller %s is in use and hotplug is not supported\n", ctrlr_name);
@ -686,15 +711,21 @@ spdk_vhost_scsi_dev_add_dev(const char *ctrlr_name, unsigned scsi_dev_num, const
} }
int int
spdk_vhost_scsi_dev_remove_dev(struct spdk_vhost_scsi_dev *svdev, unsigned scsi_dev_num) spdk_vhost_scsi_dev_remove_dev(struct spdk_vhost_dev *vdev, unsigned scsi_dev_num)
{ {
struct spdk_vhost_dev *vdev = &svdev->vdev; struct spdk_vhost_scsi_dev *svdev;
assert(vdev != NULL);
if (vdev->lcore != -1) { if (vdev->lcore != -1) {
SPDK_ERRLOG("Controller %s is in use and hotremove is not supported\n", vdev->name); SPDK_ERRLOG("Controller %s is in use and hotremove is not supported\n", vdev->name);
return -EBUSY; return -EBUSY;
} }
svdev = to_scsi_dev(vdev);
if (svdev == NULL) {
return -ENODEV;
}
if (svdev->scsi_dev[scsi_dev_num] == NULL) { if (svdev->scsi_dev[scsi_dev_num] == NULL) {
SPDK_ERRLOG("Controller %s dev %u is not occupied\n", vdev->name, scsi_dev_num); SPDK_ERRLOG("Controller %s dev %u is not occupied\n", vdev->name, scsi_dev_num);
return -ENODEV; return -ENODEV;
@ -803,7 +834,8 @@ destroy_device(int vid)
if (vdev == NULL) { if (vdev == NULL) {
rte_panic("Couldn't find device with vid %d to stop.\n", vid); rte_panic("Couldn't find device with vid %d to stop.\n", vid);
} }
svdev = (struct spdk_vhost_scsi_dev *) vdev; svdev = to_scsi_dev(vdev);
assert(svdev);
spdk_vhost_timed_event_init(&event, vdev->lcore, NULL, NULL, 1); spdk_vhost_timed_event_init(&event, vdev->lcore, NULL, NULL, 1);
spdk_poller_unregister(&svdev->requestq_poller, event.spdk_event); spdk_poller_unregister(&svdev->requestq_poller, event.spdk_event);

View File

@ -1,51 +0,0 @@
/*-
* BSD LICENSE
*
* Copyright (c) Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SPDK_VHOST_SCSI_H
#define SPDK_VHOST_SCSI_H
#include "spdk/scsi_spec.h"
#define SPDK_VHOST_SCSI_CTRLR_MAX_DEVS 8
struct spdk_vhost_scsi_dev;
int spdk_vhost_scsi_controller_construct(void);
int spdk_vhost_scsi_dev_construct(const char *name, uint64_t cpumask);
int spdk_vhost_scsi_dev_remove(struct spdk_vhost_scsi_dev *vdev);
struct spdk_scsi_dev *spdk_vhost_scsi_dev_get_dev(struct spdk_vhost_scsi_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_scsi_dev *vdev, unsigned scsi_dev_num);
#endif /* SPDK_VHOST_SCSI_H */