scsi: Set proper transport protocol id

This patch adds property of transport protocol id to spdk_scsi_dev.
This allows to change it depending on which appliation is using
the device. Previously only iSCSI was used for all.

Setting protocol id is done at the time when device is added to
vhost controller (vhost) or target node (iSCSI).

Please note that for SPDK vhost SAS protocol id is used,
as that is what kernel vhost reports as well.

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I455a856c5d7796a749b6650fee0218d526e094ed
Reviewed-on: https://review.gerrithub.io/362864
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:
Tomasz Zawadzki 2017-05-24 16:08:25 +02:00 committed by Daniel Verkamp
parent 0888dd4cc6
commit 5e132b6b7a
8 changed files with 40 additions and 22 deletions

View File

@ -193,7 +193,8 @@ void spdk_scsi_dev_free_io_channels(struct spdk_scsi_dev *dev);
struct spdk_scsi_dev *spdk_scsi_dev_construct(const char *name,
char *lun_name_list[],
int *lun_id_list,
int num_luns);
int num_luns,
uint8_t protocol_id);
void spdk_scsi_dev_delete_lun(struct spdk_scsi_dev *dev, struct spdk_scsi_lun *lun);

View File

@ -693,8 +693,9 @@ spdk_iscsi_tgt_node_construct(int target_index,
}
}
target->dev = spdk_scsi_dev_construct(name, lun_name_list,
lun_id_list, num_luns);
target->dev = spdk_scsi_dev_construct(name, lun_name_list, lun_id_list, num_luns,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI);
if (!target->dev) {
SPDK_ERRLOG("Could not construct SCSI device\n");
spdk_iscsi_tgt_node_destruct(target);

View File

@ -138,7 +138,8 @@ spdk_scsi_dev_delete_lun(struct spdk_scsi_dev *dev,
typedef struct spdk_scsi_dev _spdk_scsi_dev;
_spdk_scsi_dev *
spdk_scsi_dev_construct(const char *name, char *lun_name_list[], int *lun_id_list, int num_luns)
spdk_scsi_dev_construct(const char *name, char *lun_name_list[], int *lun_id_list, int num_luns,
uint8_t protocol_id)
{
struct spdk_scsi_dev *dev;
struct spdk_bdev *bdev;
@ -172,6 +173,7 @@ spdk_scsi_dev_construct(const char *name, char *lun_name_list[], int *lun_id_lis
dev->num_ports = 0;
dev->maxlun = 0;
dev->protocol_id = protocol_id;
for (i = 0; i < num_luns; i++) {
bdev = spdk_bdev_get_by_name(lun_name_list[i]);

View File

@ -253,6 +253,7 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
case SPDK_SPC_VPD_DEVICE_IDENTIFICATION: {
const char *name = spdk_bdev_get_name(bdev);
const char *product_name = spdk_bdev_get_product_name(bdev);
uint8_t protocol_id = dev->protocol_id;
uint8_t *buf = vpage->params;
struct spdk_scsi_desig_desc *desig;
@ -279,7 +280,7 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
/* NAA designator */
desig = (struct spdk_scsi_desig_desc *)buf;
desig->code_set = SPDK_SPC_VPD_CODE_SET_BINARY;
desig->protocol_id = SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI;
desig->protocol_id = protocol_id;
desig->type = SPDK_SPC_VPD_IDENTIFIER_TYPE_NAA;
desig->association = SPDK_SPC_VPD_ASSOCIATION_LOGICAL_UNIT;
desig->reserved0 = 0;
@ -294,7 +295,7 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
/* T10 Vendor ID designator */
desig = (struct spdk_scsi_desig_desc *)buf;
desig->code_set = SPDK_SPC_VPD_CODE_SET_ASCII;
desig->protocol_id = SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI;
desig->protocol_id = protocol_id;
desig->type = SPDK_SPC_VPD_IDENTIFIER_TYPE_T10_VENDOR_ID;
desig->association = SPDK_SPC_VPD_ASSOCIATION_LOGICAL_UNIT;
desig->reserved0 = 0;
@ -311,7 +312,7 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
/* SCSI Device Name designator */
desig = (struct spdk_scsi_desig_desc *)buf;
desig->code_set = SPDK_SPC_VPD_CODE_SET_UTF8;
desig->protocol_id = SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI;
desig->protocol_id = protocol_id;
desig->type = SPDK_SPC_VPD_IDENTIFIER_TYPE_SCSI_NAME;
desig->association = SPDK_SPC_VPD_ASSOCIATION_TARGET_DEVICE;
desig->reserved0 = 0;
@ -325,7 +326,7 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
/* SCSI Port Name designator */
desig = (struct spdk_scsi_desig_desc *)buf;
desig->code_set = SPDK_SPC_VPD_CODE_SET_UTF8;
desig->protocol_id = SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI;
desig->protocol_id = protocol_id;
desig->type = SPDK_SPC_VPD_IDENTIFIER_TYPE_SCSI_NAME;
desig->association = SPDK_SPC_VPD_ASSOCIATION_TARGET_PORT;
desig->reserved0 = 0;
@ -339,7 +340,7 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
/* Relative Target Port designator */
desig = (struct spdk_scsi_desig_desc *)buf;
desig->code_set = SPDK_SPC_VPD_CODE_SET_BINARY;
desig->protocol_id = SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI;
desig->protocol_id = protocol_id;
desig->type = SPDK_SPC_VPD_IDENTIFIER_TYPE_RELATIVE_TARGET_PORT;
desig->association = SPDK_SPC_VPD_ASSOCIATION_TARGET_PORT;
desig->reserved0 = 0;
@ -355,7 +356,7 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
/* Target port group designator */
desig = (struct spdk_scsi_desig_desc *)buf;
desig->code_set = SPDK_SPC_VPD_CODE_SET_BINARY;
desig->protocol_id = SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI;
desig->protocol_id = protocol_id;
desig->type = SPDK_SPC_VPD_IDENTIFIER_TYPE_TARGET_PORT_GROUP;
desig->association = SPDK_SPC_VPD_ASSOCIATION_TARGET_PORT;
desig->reserved0 = 0;
@ -370,7 +371,7 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
/* Logical unit group designator */
desig = (struct spdk_scsi_desig_desc *)buf;
desig->code_set = SPDK_SPC_VPD_CODE_SET_BINARY;
desig->protocol_id = SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI;
desig->protocol_id = protocol_id;
desig->type = SPDK_SPC_VPD_IDENTIFIER_TYPE_LOGICAL_UNIT_GROUP;
desig->association = SPDK_SPC_VPD_ASSOCIATION_LOGICAL_UNIT;
desig->reserved0 = 0;

View File

@ -68,6 +68,8 @@ struct spdk_scsi_dev {
int num_ports;
struct spdk_scsi_port port[SPDK_SCSI_DEV_MAX_PORTS];
uint8_t protocol_id;
};
struct spdk_scsi_lun {

View File

@ -742,7 +742,9 @@ spdk_vhost_scsi_dev_add_dev(const char *ctrlr_name, unsigned scsi_dev_num, const
lun_id_list[0] = 0;
lun_names_list[0] = (char *)lun_name;
svdev->scsi_dev[scsi_dev_num] = spdk_scsi_dev_construct(dev_name, lun_names_list, lun_id_list, 1);
svdev->scsi_dev[scsi_dev_num] = spdk_scsi_dev_construct(dev_name, lun_names_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_SAS);
if (svdev->scsi_dev[scsi_dev_num] == NULL) {
SPDK_ERRLOG("Couldn't create spdk SCSI device '%s' using lun device '%s' in controller: %s\n",
dev_name, lun_name, vdev->name);

View File

@ -100,7 +100,7 @@ spdk_event_allocate(uint32_t core, spdk_event_fn fn, void *arg1, void *arg2)
struct spdk_scsi_dev *
spdk_scsi_dev_construct(const char *name, char **lun_name_list,
int *lun_id_list, int num_luns)
int *lun_id_list, int num_luns, uint8_t protocol_id)
{
return NULL;
}

View File

@ -238,7 +238,8 @@ dev_construct_num_luns_zero(void)
char *lun_name_list[1] = {};
int lun_id_list[1] = { 0 };
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 0);
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 0,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI);
/* dev should be null since we passed num_luns = 0 */
CU_ASSERT_TRUE(dev == NULL);
@ -253,7 +254,8 @@ dev_construct_no_lun_zero(void)
lun_id_list[0] = 1;
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1);
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI);
/* dev should be null since no LUN0 was specified (lun_id_list[0] = 1) */
CU_ASSERT_TRUE(dev == NULL);
@ -266,7 +268,8 @@ dev_construct_null_lun(void)
char *lun_name_list[1] = {};
int lun_id_list[1] = { 0 };
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1);
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI);
/* dev should be null since no LUN0 was specified (lun_list[0] = NULL) */
CU_ASSERT_TRUE(dev == NULL);
@ -279,7 +282,8 @@ dev_construct_success(void)
char *lun_name_list[1] = {"malloc0"};
int lun_id_list[1] = { 0 };
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1);
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI);
/* Successfully constructs and returns a dev */
CU_ASSERT_TRUE(dev != NULL);
@ -297,12 +301,14 @@ dev_construct_same_lun_two_devices(void)
char *lun_name_list[1] = {"malloc0"};
int lun_id_list[1] = { 0 };
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1);
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI);
/* Successfully constructs and returns a dev */
CU_ASSERT_TRUE(dev != NULL);
dev2 = spdk_scsi_dev_construct("Name2", lun_name_list, lun_id_list, 1);
dev2 = spdk_scsi_dev_construct("Name2", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI);
/* Fails to construct dev and returns NULL */
CU_ASSERT_TRUE(dev2 == NULL);
@ -320,7 +326,8 @@ dev_construct_same_lun_one_device(void)
char *lun_name_list[2] = {"malloc0", "malloc0"};
int lun_id_list[2] = { 0, 1 };
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 2);
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 2,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI);
/* Fails to construct dev and returns NULL */
CU_ASSERT_TRUE(dev == NULL);
@ -336,7 +343,8 @@ dev_queue_mgmt_task_success(void)
int lun_id_list[1] = { 0 };
struct spdk_scsi_task *task;
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1);
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI);
/* Successfully constructs and returns a dev */
CU_ASSERT_TRUE(dev != NULL);
@ -358,7 +366,8 @@ dev_queue_task_success(void)
int lun_id_list[1] = { 0 };
struct spdk_scsi_task *task;
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1);
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI);
/* Successfully constructs and returns a dev */
CU_ASSERT_TRUE(dev != NULL);