vhost-scsi: use first free SCSI target ID if -1 specified
Fixes #328 Change-Id: I34b816a31a51d1a8aa4c61285e01d0249c283f53 Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-on: https://review.gerrithub.io/c/442434 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
4e614b3127
commit
48834f0daa
@ -4094,9 +4094,13 @@ In vhost target `ctrlr` create SCSI target with ID `scsi_target_num` and add `bd
|
|||||||
Name | Optional | Type | Description
|
Name | Optional | Type | Description
|
||||||
----------------------- | -------- | ----------- | -----------
|
----------------------- | -------- | ----------- | -----------
|
||||||
ctrlr | Required | string | Controller name
|
ctrlr | Required | string | Controller name
|
||||||
scsi_target_num | Required | number | SCSI target ID between 0 and 7
|
scsi_target_num | Required | number | SCSI target ID between 0 and 7 or -1 to use first free ID.
|
||||||
bdev_name | Required | string | Name of bdev to expose as a LUN 0
|
bdev_name | Required | string | Name of bdev to expose as a LUN 0
|
||||||
|
|
||||||
|
### Response
|
||||||
|
|
||||||
|
SCSI target ID.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
Example request:
|
Example request:
|
||||||
@ -4121,7 +4125,7 @@ response:
|
|||||||
{
|
{
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"result": true
|
"result": 1
|
||||||
}
|
}
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
|
@ -207,12 +207,19 @@ int spdk_vhost_scsi_dev_construct(const char *name, const char *cpumask);
|
|||||||
* automatically detected by the other side.
|
* automatically detected by the other side.
|
||||||
*
|
*
|
||||||
* \param vdev vhost SCSI device.
|
* \param vdev vhost SCSI device.
|
||||||
* \param scsi_tgt_num slot to attach to.
|
* \param scsi_tgt_num slot to attach to or negative value to use first free.
|
||||||
* \param bdev_name name of the SPDK bdev to associate with SCSI LUN0.
|
* \param bdev_name name of the SPDK bdev to associate with SCSI LUN0.
|
||||||
*
|
*
|
||||||
* \return 0 on success, negative errno on error.
|
* \return value >= 0 on success - the SCSI target ID, negative errno code:
|
||||||
|
* -EINVAL - one of the arguments is invalid:
|
||||||
|
* - vdev is not vhost SCSI device
|
||||||
|
* - SCSI target ID is out of range
|
||||||
|
* - bdev name is NULL
|
||||||
|
* - can't create SCSI LUN because of other errors e.g.: bdev does not exist
|
||||||
|
* -ENOSPC - scsi_tgt_num is -1 and maximum targets in vhost SCSI device reached
|
||||||
|
* -EEXIST - SCSI target ID already exists
|
||||||
*/
|
*/
|
||||||
int spdk_vhost_scsi_dev_add_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_num,
|
int spdk_vhost_scsi_dev_add_tgt(struct spdk_vhost_dev *vdev, int scsi_tgt_num,
|
||||||
const char *bdev_name);
|
const char *bdev_name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,7 +103,7 @@ SPDK_RPC_REGISTER("construct_vhost_scsi_controller", spdk_rpc_construct_vhost_sc
|
|||||||
|
|
||||||
struct rpc_add_vhost_scsi_ctrlr_lun {
|
struct rpc_add_vhost_scsi_ctrlr_lun {
|
||||||
char *ctrlr;
|
char *ctrlr;
|
||||||
uint32_t scsi_target_num;
|
int32_t scsi_target_num;
|
||||||
char *bdev_name;
|
char *bdev_name;
|
||||||
|
|
||||||
struct spdk_jsonrpc_request *request;
|
struct spdk_jsonrpc_request *request;
|
||||||
@ -119,7 +119,7 @@ free_rpc_add_vhost_scsi_ctrlr_lun(struct rpc_add_vhost_scsi_ctrlr_lun *req)
|
|||||||
|
|
||||||
static const struct spdk_json_object_decoder rpc_vhost_add_lun[] = {
|
static const struct spdk_json_object_decoder rpc_vhost_add_lun[] = {
|
||||||
{"ctrlr", offsetof(struct rpc_add_vhost_scsi_ctrlr_lun, ctrlr), spdk_json_decode_string },
|
{"ctrlr", offsetof(struct rpc_add_vhost_scsi_ctrlr_lun, ctrlr), spdk_json_decode_string },
|
||||||
{"scsi_target_num", offsetof(struct rpc_add_vhost_scsi_ctrlr_lun, scsi_target_num), spdk_json_decode_uint32},
|
{"scsi_target_num", offsetof(struct rpc_add_vhost_scsi_ctrlr_lun, scsi_target_num), spdk_json_decode_int32},
|
||||||
{"bdev_name", offsetof(struct rpc_add_vhost_scsi_ctrlr_lun, bdev_name), spdk_json_decode_string },
|
{"bdev_name", offsetof(struct rpc_add_vhost_scsi_ctrlr_lun, bdev_name), spdk_json_decode_string },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ spdk_rpc_add_vhost_scsi_lun_cb(struct spdk_vhost_dev *vdev, void *arg)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
spdk_json_write_bool(w, true);
|
spdk_json_write_int32(w, rc);
|
||||||
spdk_jsonrpc_end_result(request, w);
|
spdk_jsonrpc_end_result(request, w);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -938,7 +938,7 @@ spdk_vhost_scsi_session_add_tgt(struct spdk_vhost_dev *vdev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
spdk_vhost_scsi_dev_add_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_num,
|
spdk_vhost_scsi_dev_add_tgt(struct spdk_vhost_dev *vdev, int scsi_tgt_num,
|
||||||
const char *bdev_name)
|
const char *bdev_name)
|
||||||
{
|
{
|
||||||
struct spdk_vhost_scsi_dev *svdev;
|
struct spdk_vhost_scsi_dev *svdev;
|
||||||
@ -952,11 +952,24 @@ spdk_vhost_scsi_dev_add_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_num,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scsi_tgt_num < 0) {
|
||||||
|
for (scsi_tgt_num = 0; scsi_tgt_num < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; scsi_tgt_num++) {
|
||||||
|
if (svdev->scsi_dev_state[scsi_tgt_num].dev == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scsi_tgt_num == SPDK_VHOST_SCSI_CTRLR_MAX_DEVS) {
|
||||||
|
SPDK_ERRLOG("Controller %s - all targets already in use.\n", vdev->name);
|
||||||
|
return -ENOSPC;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (scsi_tgt_num >= SPDK_VHOST_SCSI_CTRLR_MAX_DEVS) {
|
if (scsi_tgt_num >= SPDK_VHOST_SCSI_CTRLR_MAX_DEVS) {
|
||||||
SPDK_ERRLOG("Controller %d target number too big (max %d)\n", scsi_tgt_num,
|
SPDK_ERRLOG("Controller %s target %d number too big (max %d)\n", vdev->name, scsi_tgt_num,
|
||||||
SPDK_VHOST_SCSI_CTRLR_MAX_DEVS);
|
SPDK_VHOST_SCSI_CTRLR_MAX_DEVS);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bdev_name == NULL) {
|
if (bdev_name == NULL) {
|
||||||
SPDK_ERRLOG("No lun name specified\n");
|
SPDK_ERRLOG("No lun name specified\n");
|
||||||
@ -993,7 +1006,7 @@ spdk_vhost_scsi_dev_add_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_num,
|
|||||||
|
|
||||||
spdk_vhost_dev_foreach_session(vdev, spdk_vhost_scsi_session_add_tgt,
|
spdk_vhost_dev_foreach_session(vdev, spdk_vhost_scsi_session_add_tgt,
|
||||||
(void *)(uintptr_t)scsi_tgt_num);
|
(void *)(uintptr_t)scsi_tgt_num);
|
||||||
return 0;
|
return scsi_tgt_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -1580,10 +1580,10 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
|
|||||||
p.set_defaults(func=construct_vhost_scsi_controller)
|
p.set_defaults(func=construct_vhost_scsi_controller)
|
||||||
|
|
||||||
def add_vhost_scsi_lun(args):
|
def add_vhost_scsi_lun(args):
|
||||||
rpc.vhost.add_vhost_scsi_lun(args.client,
|
print(rpc.vhost.add_vhost_scsi_lun(args.client,
|
||||||
ctrlr=args.ctrlr,
|
ctrlr=args.ctrlr,
|
||||||
scsi_target_num=args.scsi_target_num,
|
scsi_target_num=args.scsi_target_num,
|
||||||
bdev_name=args.bdev_name)
|
bdev_name=args.bdev_name))
|
||||||
|
|
||||||
p = subparsers.add_parser('add_vhost_scsi_lun',
|
p = subparsers.add_parser('add_vhost_scsi_lun',
|
||||||
help='Add lun to vhost controller')
|
help='Add lun to vhost controller')
|
||||||
|
@ -198,7 +198,7 @@ function create_vhost_subsystem_config() {
|
|||||||
|
|
||||||
tgt_rpc construct_vhost_scsi_controller VhostScsiCtrlr0
|
tgt_rpc construct_vhost_scsi_controller VhostScsiCtrlr0
|
||||||
tgt_rpc add_vhost_scsi_lun VhostScsiCtrlr0 0 MallocForVhost0p3
|
tgt_rpc add_vhost_scsi_lun VhostScsiCtrlr0 0 MallocForVhost0p3
|
||||||
tgt_rpc add_vhost_scsi_lun VhostScsiCtrlr0 1 MallocForVhost0p4
|
tgt_rpc add_vhost_scsi_lun VhostScsiCtrlr0 -1 MallocForVhost0p4
|
||||||
tgt_rpc set_vhost_controller_coalescing VhostScsiCtrlr0 1 100
|
tgt_rpc set_vhost_controller_coalescing VhostScsiCtrlr0 1 100
|
||||||
|
|
||||||
tgt_rpc construct_vhost_blk_controller VhostBlkCtrlr0 MallocForVhost0p5
|
tgt_rpc construct_vhost_blk_controller VhostBlkCtrlr0 MallocForVhost0p5
|
||||||
|
Loading…
Reference in New Issue
Block a user