diff --git a/doc/vhost.md b/doc/vhost.md index c876d50d04..bffdd82f52 100644 --- a/doc/vhost.md +++ b/doc/vhost.md @@ -60,30 +60,34 @@ is specified in the configuration file as: ~~~ [VhostBlkX] - Name vhost.X # Name of vhost socket - Dev BackendX # "BackendX" is block device name from previous - # sections in config file - #Cpumask 0x1 # Optional parameter defining which core controller uses + Name vhost.X # Name of vhost socket + Dev BackendX # "BackendX" is block device name from previous + # sections in config file + + #Cpumask 0x1 # Optional parameter defining which core controller uses ~~~ ### Mappings Between SCSI Controllers and Storage Backends -The vhost target exposes SCSI controllers to the virtual machines. -Each device in the vhost controller is associated with an SPDK block device and -configuration file defines those associations. The block device to Dev mappings -are specified in the configuration file as: +The vhost target exposes SCSI controllers to the virtual machine application(s). +Each SPDK vhost SCSI controller can expose up to eight targets (0..7). LUN 0 of each target +is associated with an SPDK block device and configuration file defines those associations. +The block device to Target mappings are specified in the configuration file as: ~~~ [VhostScsiX] - Name vhost.X # Name of vhost socket - Dev 0 BackendX # "BackendX" is block device name from previous - # sections in config file - Dev 1 BackendY + Name vhost.X # Name of vhost socket + Target 0 BackendX # "BackendX" is block device name from previous + # sections in config file + Target 1 BackendY ... - Dev n BackendN - #Cpumask 0x1 # Optional parameter defining which core controller uses + Target n BackendN + + #Cpumask 0x1 # Optional parameter defining which core controller uses ~~~ +Users should update configuration with 'Target' keyword. + ### Vhost Sockets Userspace vhost uses UNIX domain sockets for communication between QEMU @@ -197,8 +201,8 @@ EAL: VFIO support initialized << REMOVED CONSOLE LOG >> VHOST_CONFIG: bind to vhost_scsi0_socket vhost.c: 592:spdk_vhost_dev_construct: *NOTICE*: Controller vhost_scsi0_socket: new controller added -vhost_scsi.c: 840:spdk_vhost_scsi_dev_add_dev: *NOTICE*: Controller vhost_scsi0_socket: defined device 'Dev 1' using lun 'Malloc0' -vhost_scsi.c: 840:spdk_vhost_scsi_dev_add_dev: *NOTICE*: Controller vhost_scsi0_socket: defined device 'Dev 5' using lun 'Malloc1' +vhost_scsi.c: 840:spdk_vhost_scsi_dev_add_tgt: *NOTICE*: Controller vhost_scsi0_socket: defined target 'Target 1' using lun 'Malloc0' +vhost_scsi.c: 840:spdk_vhost_scsi_dev_add_tgt: *NOTICE*: Controller vhost_scsi0_socket: defined target 'Target 5' using lun 'Malloc1' VHOST_CONFIG: vhost-user server: socket created, fd: 65 VHOST_CONFIG: bind to vhost_blk0_socket vhost.c: 592:spdk_vhost_dev_construct: *NOTICE*: Controller vhost_blk0_socket: new controller added diff --git a/include/spdk/vhost.h b/include/spdk/vhost.h index f920699503..0ce98f4309 100644 --- a/include/spdk/vhost.h +++ b/include/spdk/vhost.h @@ -67,9 +67,9 @@ void spdk_vhost_shutdown_cb(void); * SPDK vhost device (vdev). An equivalent of Virtio device. * Both virtio-blk and virtio-scsi devices are represented by this * struct. For virtio-scsi a single vhost device (also called SCSI - * controller) may contain multiple devices (SCSI targets), each of + * controller) may contain multiple SCSI targets (devices), each of * which may contain multiple logical units (SCSI LUNs). For now - * only one LUN per device is available. + * only one LUN per target is available. * * All vdev-changing functions operate directly on this object. * Note that \c spdk_vhost_dev cannot be acquired. This object is @@ -140,7 +140,7 @@ int spdk_vhost_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_u * starts after receiving proper message on the created socket. * See QEMU's vhost-user documentation for details. * All physical devices have to be separately attached to this - * vdev via \c spdk_vhost_scsi_dev_add_dev(). + * vdev via \c spdk_vhost_scsi_dev_add_tgt(). * * This function is thread-safe. * @@ -164,7 +164,7 @@ int spdk_vhost_scsi_dev_construct(const char *name, const char *cpumask); int spdk_vhost_scsi_dev_remove(struct spdk_vhost_dev *vdev); /** - * Construct and attach new SCSI device to the vhost SCSI device + * Construct and attach new SCSI target to the vhost SCSI device * on given (unoccupied) slot. The device will be created with a single * LUN0 associated with given SPDK bdev. Currently only one LUN per * device is supported. @@ -174,15 +174,15 @@ int spdk_vhost_scsi_dev_remove(struct spdk_vhost_dev *vdev); * flag. Otherwise an -ENOTSUP error code is returned. * * \param vdev vhost SCSI device - * \param scsi_dev_num slot to attach to + * \param scsi_tgt_num slot to attach to * \param lun_name name of the SPDK bdev to associate with SCSI LUN0 * \return 0 on success, negative errno on error. */ -int spdk_vhost_scsi_dev_add_dev(struct spdk_vhost_dev *vdev, unsigned scsi_dev_num, +int spdk_vhost_scsi_dev_add_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_num, const char *lun_name); /** - * Get SCSI device from vhost SCSI device on given slot. Max + * Get SCSI target from vhost SCSI device on given slot. Max * number of available slots is defined by * \c SPDK_VHOST_SCSI_CTRLR_MAX_DEVS. * @@ -190,10 +190,10 @@ int spdk_vhost_scsi_dev_add_dev(struct spdk_vhost_dev *vdev, unsigned scsi_dev_n * \param num slot id * \return SCSI device on given slot or NULL */ -struct spdk_scsi_dev *spdk_vhost_scsi_dev_get_dev(struct spdk_vhost_dev *vdev, uint8_t num); +struct spdk_scsi_dev *spdk_vhost_scsi_dev_get_tgt(struct spdk_vhost_dev *vdev, uint8_t num); /** - * Detach and destruct SCSI device from a vhost SCSI device. + * Detach and destruct SCSI target from a vhost SCSI device. * * If vhost SCSI device has an active socket connection, it is * required that it has negotiated \c VIRTIO_SCSI_F_HOTPLUG feature @@ -202,18 +202,18 @@ struct spdk_scsi_dev *spdk_vhost_scsi_dev_get_dev(struct spdk_vhost_dev *vdev, u * deletion is deferred until after all pending I/O to this device * has finished. * - * Once the device has been deleted (whether or not vhost SCSI + * Once the target has been deleted (whether or not vhost SCSI * device is in use) given callback will be called. * * \param vdev vhost SCSI device - * \param scsi_dev_num slot id to delete device from - * \param cb_fn callback to be fired once device has been successfully + * \param scsi_tgt_num slot id to delete target from + * \param cb_fn callback to be fired once target has been successfully * deleted. The first parameter of callback function is the vhost SCSI * device, the second is user provided argument *cb_arg*. * \param cb_arg parameter to be passed to *cb_fn*. * \return 0 on success, negative errno on error. */ -int spdk_vhost_scsi_dev_remove_dev(struct spdk_vhost_dev *vdev, unsigned scsi_dev_num, +int spdk_vhost_scsi_dev_remove_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_num, spdk_vhost_event_fn cb_fn, void *cb_arg); /** @@ -244,7 +244,7 @@ int spdk_vhost_blk_construct(const char *name, const char *cpumask, const char * bool readonly); /** - * Remove a vhost blk device. The device must not have any + * Remove a vhost blk device. The device must not have any * open connections on it's socket. * * \param vdev vhost blk device diff --git a/lib/vhost/vhost_rpc.c b/lib/vhost/vhost_rpc.c index 4ec5fc008a..e3f53adee3 100644 --- a/lib/vhost/vhost_rpc.c +++ b/lib/vhost/vhost_rpc.c @@ -103,7 +103,7 @@ SPDK_RPC_REGISTER("construct_vhost_scsi_controller", spdk_rpc_construct_vhost_sc struct rpc_add_vhost_scsi_ctrlr_lun { char *ctrlr; - uint32_t scsi_dev_num; + uint32_t scsi_target_num; char *lun_name; 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[] = { {"ctrlr", offsetof(struct rpc_add_vhost_scsi_ctrlr_lun, ctrlr), spdk_json_decode_string }, - {"scsi_dev_num", offsetof(struct rpc_add_vhost_scsi_ctrlr_lun, scsi_dev_num), spdk_json_decode_uint32}, + {"scsi_target_num", offsetof(struct rpc_add_vhost_scsi_ctrlr_lun, scsi_target_num), spdk_json_decode_uint32}, {"lun_name", offsetof(struct rpc_add_vhost_scsi_ctrlr_lun, lun_name), spdk_json_decode_string }, }; @@ -137,7 +137,7 @@ spdk_rpc_add_vhost_scsi_lun_cb(struct spdk_vhost_dev *vdev, void *arg) goto invalid; } - rc = spdk_vhost_scsi_dev_add_dev(vdev, rpc->scsi_dev_num, rpc->lun_name); + rc = spdk_vhost_scsi_dev_add_tgt(vdev, rpc->scsi_target_num, rpc->lun_name); if (rc < 0) { goto invalid; } @@ -202,33 +202,33 @@ invalid: } SPDK_RPC_REGISTER("add_vhost_scsi_lun", spdk_rpc_add_vhost_scsi_lun) -struct rpc_remove_vhost_scsi_ctrlr_dev { +struct rpc_remove_vhost_scsi_ctrlr_target { char *ctrlr; - uint32_t scsi_dev_num; + uint32_t scsi_target_num; struct spdk_jsonrpc_request *request; }; static void -free_rpc_remove_vhost_scsi_ctrlr_dev(struct rpc_remove_vhost_scsi_ctrlr_dev *req) +free_rpc_remove_vhost_scsi_ctrlr_target(struct rpc_remove_vhost_scsi_ctrlr_target *req) { free(req->ctrlr); free(req); } -static const struct spdk_json_object_decoder rpc_vhost_remove_dev[] = { - {"ctrlr", offsetof(struct rpc_remove_vhost_scsi_ctrlr_dev, ctrlr), spdk_json_decode_string }, - {"scsi_dev_num", offsetof(struct rpc_remove_vhost_scsi_ctrlr_dev, scsi_dev_num), spdk_json_decode_uint32}, +static const struct spdk_json_object_decoder rpc_vhost_remove_target[] = { + {"ctrlr", offsetof(struct rpc_remove_vhost_scsi_ctrlr_target, ctrlr), spdk_json_decode_string }, + {"scsi_target_num", offsetof(struct rpc_remove_vhost_scsi_ctrlr_target, scsi_target_num), spdk_json_decode_uint32}, }; static int -spdk_rpc_remove_vhost_scsi_dev_finish_cb(struct spdk_vhost_dev *vdev, void *arg) +spdk_rpc_remove_vhost_scsi_target_finish_cb(struct spdk_vhost_dev *vdev, void *arg) { - struct rpc_remove_vhost_scsi_ctrlr_dev *rpc = arg; + struct rpc_remove_vhost_scsi_ctrlr_target *rpc = arg; struct spdk_jsonrpc_request *request = rpc->request; struct spdk_json_write_ctx *w; - free_rpc_remove_vhost_scsi_ctrlr_dev(rpc); + free_rpc_remove_vhost_scsi_ctrlr_target(rpc); w = spdk_jsonrpc_begin_result(request); if (w == NULL) { @@ -241,9 +241,9 @@ spdk_rpc_remove_vhost_scsi_dev_finish_cb(struct spdk_vhost_dev *vdev, void *arg) } static int -spdk_rpc_remove_vhost_scsi_dev_cb(struct spdk_vhost_dev *vdev, void *arg) +spdk_rpc_remove_vhost_scsi_target_cb(struct spdk_vhost_dev *vdev, void *arg) { - struct rpc_remove_vhost_scsi_ctrlr_dev *rpc = arg; + struct rpc_remove_vhost_scsi_ctrlr_target *rpc = arg; struct spdk_jsonrpc_request *request = rpc->request; char buf[64]; int rc; @@ -253,8 +253,8 @@ spdk_rpc_remove_vhost_scsi_dev_cb(struct spdk_vhost_dev *vdev, void *arg) goto invalid; } - rc = spdk_vhost_scsi_dev_remove_dev(vdev, rpc->scsi_dev_num, - spdk_rpc_remove_vhost_scsi_dev_finish_cb, rpc); + rc = spdk_vhost_scsi_dev_remove_tgt(vdev, rpc->scsi_target_num, + spdk_rpc_remove_vhost_scsi_target_finish_cb, rpc); if (rc < 0) { goto invalid; } @@ -262,17 +262,17 @@ spdk_rpc_remove_vhost_scsi_dev_cb(struct spdk_vhost_dev *vdev, void *arg) return 0; invalid: - free_rpc_remove_vhost_scsi_ctrlr_dev(rpc); + free_rpc_remove_vhost_scsi_ctrlr_target(rpc); spdk_strerror_r(-rc, buf, sizeof(buf)); spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); return rc; } static void -spdk_rpc_remove_vhost_scsi_dev(struct spdk_jsonrpc_request *request, - const struct spdk_json_val *params) +spdk_rpc_remove_vhost_scsi_target(struct spdk_jsonrpc_request *request, + const struct spdk_json_val *params) { - struct rpc_remove_vhost_scsi_ctrlr_dev *req; + struct rpc_remove_vhost_scsi_ctrlr_target *req; int rc; char buf[64]; @@ -283,27 +283,27 @@ spdk_rpc_remove_vhost_scsi_dev(struct spdk_jsonrpc_request *request, } req->request = request; - if (spdk_json_decode_object(params, rpc_vhost_remove_dev, - SPDK_COUNTOF(rpc_vhost_remove_dev), + if (spdk_json_decode_object(params, rpc_vhost_remove_target, + SPDK_COUNTOF(rpc_vhost_remove_target), req)) { SPDK_DEBUGLOG(SPDK_LOG_VHOST_RPC, "spdk_json_decode_object failed\n"); rc = -EINVAL; goto invalid; } - spdk_vhost_call_external_event(req->ctrlr, spdk_rpc_remove_vhost_scsi_dev_cb, req); + spdk_vhost_call_external_event(req->ctrlr, spdk_rpc_remove_vhost_scsi_target_cb, req); return; invalid: if (req) { - free_rpc_remove_vhost_scsi_ctrlr_dev(req); + free_rpc_remove_vhost_scsi_ctrlr_target(req); } spdk_strerror_r(-rc, buf, sizeof(buf)); spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); } -SPDK_RPC_REGISTER("remove_vhost_scsi_dev", spdk_rpc_remove_vhost_scsi_dev) +SPDK_RPC_REGISTER("remove_vhost_scsi_target", spdk_rpc_remove_vhost_scsi_target) struct rpc_vhost_blk_ctrlr { char *ctrlr; diff --git a/lib/vhost/vhost_scsi.c b/lib/vhost/vhost_scsi.c index b65f18a862..74a3aeafa3 100644 --- a/lib/vhost/vhost_scsi.c +++ b/lib/vhost/vhost_scsi.c @@ -729,7 +729,7 @@ spdk_vhost_scsi_dev_remove(struct spdk_vhost_dev *vdev) } struct spdk_scsi_dev * -spdk_vhost_scsi_dev_get_dev(struct spdk_vhost_dev *vdev, uint8_t num) +spdk_vhost_scsi_dev_get_tgt(struct spdk_vhost_dev *vdev, uint8_t num) { struct spdk_vhost_scsi_dev *svdev; @@ -768,15 +768,15 @@ spdk_vhost_scsi_lun_hotremove(const struct spdk_scsi_lun *lun, void *arg) } /* remove entire device */ - spdk_vhost_scsi_dev_remove_dev(&svdev->vdev, scsi_dev_num, NULL, NULL); + spdk_vhost_scsi_dev_remove_tgt(&svdev->vdev, scsi_dev_num, NULL, NULL); } int -spdk_vhost_scsi_dev_add_dev(struct spdk_vhost_dev *vdev, unsigned scsi_dev_num, +spdk_vhost_scsi_dev_add_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_num, const char *lun_name) { struct spdk_vhost_scsi_dev *svdev; - char dev_name[SPDK_SCSI_DEV_MAX_NAME]; + char target_name[SPDK_SCSI_DEV_MAX_NAME]; int lun_id_list[1]; char *lun_names_list[1]; @@ -785,8 +785,8 @@ spdk_vhost_scsi_dev_add_dev(struct spdk_vhost_dev *vdev, unsigned scsi_dev_num, return -EINVAL; } - if (scsi_dev_num >= SPDK_VHOST_SCSI_CTRLR_MAX_DEVS) { - SPDK_ERRLOG("Controller %d device number too big (max %d)\n", scsi_dev_num, + 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_VHOST_SCSI_CTRLR_MAX_DEVS); return -EINVAL; } @@ -804,41 +804,42 @@ spdk_vhost_scsi_dev_add_dev(struct spdk_vhost_dev *vdev, unsigned scsi_dev_num, return -ENOTSUP; } - if (svdev->scsi_dev[scsi_dev_num] != NULL) { - SPDK_ERRLOG("Controller %s dev %u already occupied\n", vdev->name, scsi_dev_num); + if (svdev->scsi_dev[scsi_tgt_num] != NULL) { + SPDK_ERRLOG("Controller %s target %u already occupied\n", vdev->name, scsi_tgt_num); return -EEXIST; } /* - * At this stage only one LUN per device + * At this stage only one LUN per target */ - snprintf(dev_name, sizeof(dev_name), "Dev %u", scsi_dev_num); + snprintf(target_name, sizeof(target_name), "Target %u", scsi_tgt_num); lun_id_list[0] = 0; lun_names_list[0] = (char *)lun_name; - svdev->scsi_dev_state[scsi_dev_num].removed = false; - svdev->scsi_dev[scsi_dev_num] = spdk_scsi_dev_construct(dev_name, lun_names_list, lun_id_list, 1, + svdev->scsi_dev_state[scsi_tgt_num].removed = false; + svdev->scsi_dev[scsi_tgt_num] = spdk_scsi_dev_construct(target_name, lun_names_list, lun_id_list, + 1, SPDK_SPC_PROTOCOL_IDENTIFIER_SAS, spdk_vhost_scsi_lun_hotremove, svdev); - 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); + if (svdev->scsi_dev[scsi_tgt_num] == NULL) { + SPDK_ERRLOG("Couldn't create spdk SCSI target '%s' using lun device '%s' in controller: %s\n", + target_name, lun_name, vdev->name); return -EINVAL; } - spdk_scsi_dev_add_port(svdev->scsi_dev[scsi_dev_num], 0, "vhost"); + spdk_scsi_dev_add_port(svdev->scsi_dev[scsi_tgt_num], 0, "vhost"); if (vdev->lcore != -1) { - spdk_scsi_dev_allocate_io_channels(svdev->scsi_dev[scsi_dev_num]); - eventq_enqueue(svdev, scsi_dev_num, VIRTIO_SCSI_T_TRANSPORT_RESET, VIRTIO_SCSI_EVT_RESET_RESCAN); + spdk_scsi_dev_allocate_io_channels(svdev->scsi_dev[scsi_tgt_num]); + eventq_enqueue(svdev, scsi_tgt_num, VIRTIO_SCSI_T_TRANSPORT_RESET, VIRTIO_SCSI_EVT_RESET_RESCAN); } - SPDK_NOTICELOG("Controller %s: defined device '%s' using lun '%s'\n", - vdev->name, dev_name, lun_name); + SPDK_NOTICELOG("Controller %s: defined target '%s' using lun '%s'\n", + vdev->name, target_name, lun_name); return 0; } int -spdk_vhost_scsi_dev_remove_dev(struct spdk_vhost_dev *vdev, unsigned scsi_dev_num, +spdk_vhost_scsi_dev_remove_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_num, spdk_vhost_event_fn cb_fn, void *cb_arg) { struct spdk_vhost_scsi_dev *svdev; @@ -846,8 +847,8 @@ spdk_vhost_scsi_dev_remove_dev(struct spdk_vhost_dev *vdev, unsigned scsi_dev_nu struct spdk_scsi_dev_vhost_state *scsi_dev_state; int rc = 0; - if (scsi_dev_num >= SPDK_VHOST_SCSI_CTRLR_MAX_DEVS) { - SPDK_ERRLOG("%s: invalid device number %d\n", vdev->name, scsi_dev_num); + if (scsi_tgt_num >= SPDK_VHOST_SCSI_CTRLR_MAX_DEVS) { + SPDK_ERRLOG("%s: invalid target number %d\n", vdev->name, scsi_tgt_num); return -EINVAL; } @@ -856,42 +857,42 @@ spdk_vhost_scsi_dev_remove_dev(struct spdk_vhost_dev *vdev, unsigned scsi_dev_nu return -ENODEV; } - scsi_dev = svdev->scsi_dev[scsi_dev_num]; + scsi_dev = svdev->scsi_dev[scsi_tgt_num]; if (scsi_dev == NULL) { - SPDK_ERRLOG("Controller %s dev %u is not occupied\n", vdev->name, scsi_dev_num); + SPDK_ERRLOG("Controller %s target %u is not occupied\n", vdev->name, scsi_tgt_num); return -ENODEV; } if (svdev->vdev.lcore == -1) { /* controller is not in use, remove dev and exit */ spdk_scsi_dev_destruct(scsi_dev); - svdev->scsi_dev[scsi_dev_num] = NULL; + svdev->scsi_dev[scsi_tgt_num] = NULL; if (cb_fn) { rc = cb_fn(vdev, cb_arg); } - SPDK_NOTICELOG("%s: removed device 'Dev %u'\n", vdev->name, scsi_dev_num); + SPDK_NOTICELOG("%s: removed target 'Target %u'\n", vdev->name, scsi_tgt_num); return rc; } if (!spdk_vhost_dev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) { - SPDK_WARNLOG("%s: 'Dev %u' is in use and hot-detach is not enabled for this controller.\n", - svdev->vdev.name, scsi_dev_num); + SPDK_WARNLOG("%s: 'Target %u' is in use and hot-detach is not enabled for this controller.\n", + svdev->vdev.name, scsi_tgt_num); return -ENOTSUP; } - scsi_dev_state = &svdev->scsi_dev_state[scsi_dev_num]; + scsi_dev_state = &svdev->scsi_dev_state[scsi_tgt_num]; if (scsi_dev_state->removed) { - SPDK_WARNLOG("%s: 'Dev %u' has been already marked to hotremove.\n", svdev->vdev.name, - scsi_dev_num); + SPDK_WARNLOG("%s: 'Target %u' has been already marked to hotremove.\n", svdev->vdev.name, + scsi_tgt_num); return -EBUSY; } scsi_dev_state->remove_cb = cb_fn; scsi_dev_state->remove_ctx = cb_arg; scsi_dev_state->removed = true; - eventq_enqueue(svdev, scsi_dev_num, VIRTIO_SCSI_T_TRANSPORT_RESET, VIRTIO_SCSI_EVT_RESET_REMOVED); + eventq_enqueue(svdev, scsi_tgt_num, VIRTIO_SCSI_T_TRANSPORT_RESET, VIRTIO_SCSI_EVT_RESET_REMOVED); - SPDK_NOTICELOG("%s: queued 'Dev %u' for hot-detach.\n", vdev->name, scsi_dev_num); + SPDK_NOTICELOG("%s: queued 'Target %u' for hot-detach.\n", vdev->name, scsi_tgt_num); return 0; } @@ -902,9 +903,11 @@ spdk_vhost_scsi_controller_construct(void) struct spdk_vhost_dev *vdev; int i, dev_num; unsigned ctrlr_num = 0; - char *lun_name, *dev_num_str; + char *lun_name, *tgt_num_str; char *cpumask; char *name; + char *keyword; + char *dev = NULL, *tgt = NULL; while (sp != NULL) { if (!spdk_conf_section_match_prefix(sp, "VhostScsi")) { @@ -928,30 +931,50 @@ spdk_vhost_scsi_controller_construct(void) vdev = spdk_vhost_dev_find(name); assert(vdev); - for (i = 0; spdk_conf_section_get_nval(sp, "Dev", i) != NULL; i++) { - dev_num_str = spdk_conf_section_get_nmval(sp, "Dev", i, 0); - if (dev_num_str == NULL) { - SPDK_ERRLOG("%s: Invalid or missing Dev number\n", name); + dev = spdk_conf_section_get_nval(sp, "Dev", 0); + tgt = spdk_conf_section_get_nval(sp, "Target", 0); + + if (dev && tgt) { + SPDK_ERRLOG("Used both 'Dev' and 'Target' keywords in section [VhostScsi%u]\n" + "Please use one.\n", ctrlr_num); + return -1; + } else if (dev) { + SPDK_NOTICELOG("'Dev' mnemonic is deprecated, and will be removed shortly.\n" + "Please, use 'Target' instead\n"); + keyword = "Dev"; + } else { + keyword = "Target"; + } + + for (i = 0; ; i++) { + + tgt = spdk_conf_section_get_nval(sp, keyword, i); + if (tgt == NULL) { + break; + } + + tgt_num_str = spdk_conf_section_get_nmval(sp, keyword, i, 0); + if (tgt_num_str == NULL) { + SPDK_ERRLOG("%s: Invalid or missing target number\n", name); return -1; } - dev_num = (int)strtol(dev_num_str, NULL, 10); - lun_name = spdk_conf_section_get_nmval(sp, "Dev", i, 1); + dev_num = (int)strtol(tgt_num_str, NULL, 10); + lun_name = spdk_conf_section_get_nmval(sp, keyword, i, 1); if (lun_name == NULL) { - SPDK_ERRLOG("%s: Invalid or missing LUN name for dev %d\n", name, dev_num); + SPDK_ERRLOG("%s: Invalid or missing LUN name for target %d\n", name, dev_num); return -1; - } else if (spdk_conf_section_get_nmval(sp, "Dev", i, 2)) { + } else if (spdk_conf_section_get_nmval(sp, keyword, i, 2)) { SPDK_ERRLOG("%s: Only one LUN per vhost SCSI device supported\n", name); return -1; } - if (spdk_vhost_scsi_dev_add_dev(vdev, dev_num, lun_name) < 0) { + if (spdk_vhost_scsi_dev_add_tgt(vdev, dev_num, lun_name) < 0) { return -1; } } sp = spdk_conf_next_section(sp); - } return 0; @@ -1139,7 +1162,7 @@ spdk_vhost_scsi_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ spdk_json_write_name(w, "scsi"); spdk_json_write_object_begin(w); for (dev_idx = 0; dev_idx < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; dev_idx++) { - sdev = spdk_vhost_scsi_dev_get_dev(vdev, dev_idx); + sdev = spdk_vhost_scsi_dev_get_tgt(vdev, dev_idx); if (!sdev) { continue; } @@ -1150,7 +1173,7 @@ spdk_vhost_scsi_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ spdk_json_write_name(w, "id"); spdk_json_write_int32(w, spdk_scsi_dev_get_id(sdev)); - spdk_json_write_name(w, "device_name"); + spdk_json_write_name(w, "target_name"); spdk_json_write_string(w, spdk_scsi_dev_get_name(sdev)); spdk_json_write_name(w, "luns"); diff --git a/scripts/rpc.py b/scripts/rpc.py index ae80a75974..fe36fa2689 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -750,28 +750,29 @@ p.set_defaults(func=construct_vhost_scsi_controller) def add_vhost_scsi_lun(args): params = { 'ctrlr': args.ctrlr, - 'scsi_dev_num': args.scsi_dev_num, - 'lun_name': args.lun_name + 'lun_name': args.lun_name, + 'scsi_target_num': args.scsi_target_num } + jsonrpc_call('add_vhost_scsi_lun', params) p = subparsers.add_parser('add_vhost_scsi_lun', help='Add lun to vhost controller') p.add_argument('ctrlr', help='conntroller name where add lun') -p.add_argument('scsi_dev_num', help='scsi_dev_num', type=int) +p.add_argument('scsi_target_num', help='scsi_target_num', type=int) p.add_argument('lun_name', help='lun name') p.set_defaults(func=add_vhost_scsi_lun) -def remove_vhost_scsi_dev(args): +def remove_vhost_scsi_target(args): params = { 'ctrlr': args.ctrlr, - 'scsi_dev_num': args.scsi_dev_num, + 'scsi_target_num': args.scsi_target_num } - jsonrpc_call('remove_vhost_scsi_dev', params) + jsonrpc_call('remove_vhost_scsi_target', params) -p = subparsers.add_parser('remove_vhost_scsi_dev', help='Remove device from vhost controller') -p.add_argument('ctrlr', help='controller name to remove device from') -p.add_argument('scsi_dev_num', help='scsi_dev_num', type=int) -p.set_defaults(func=remove_vhost_scsi_dev) +p = subparsers.add_parser('remove_vhost_scsi_target', help='Remove target from vhost controller') +p.add_argument('ctrlr', help='controller name to remove target from') +p.add_argument('scsi_target_num', help='scsi_target_num', type=int) +p.set_defaults(func=remove_vhost_scsi_target) def construct_vhost_blk_controller(args): params = { diff --git a/test/unit/lib/vhost/vhost_scsi.c/vhost_scsi_ut.c b/test/unit/lib/vhost/vhost_scsi.c/vhost_scsi_ut.c index 29cf3cf816..5e03d40188 100644 --- a/test/unit/lib/vhost/vhost_scsi.c/vhost_scsi_ut.c +++ b/test/unit/lib/vhost/vhost_scsi.c/vhost_scsi_ut.c @@ -194,11 +194,12 @@ vhost_scsi_dev_remove_dev_test(void) svdev->vdev.name = strdup("vhost.0"); /* Invalid device number */ - rc = spdk_vhost_scsi_dev_remove_dev(&svdev->vdev, SPDK_VHOST_SCSI_CTRLR_MAX_DEVS + 1, NULL, NULL); + rc = spdk_vhost_scsi_dev_remove_tgt(&svdev->vdev, SPDK_VHOST_SCSI_CTRLR_MAX_DEVS + 1, NULL, + NULL); CU_ASSERT(rc == -EINVAL); /* Try to remove nonexistent device */ - rc = spdk_vhost_scsi_dev_remove_dev(&svdev->vdev, 0, NULL, NULL); + rc = spdk_vhost_scsi_dev_remove_tgt(&svdev->vdev, 0, NULL, NULL); CU_ASSERT(rc == -ENODEV); /* Try to remove device when controller is in use */ @@ -206,7 +207,7 @@ vhost_scsi_dev_remove_dev_test(void) scsi_dev = alloc_scsi_dev(); svdev->scsi_dev[0] = scsi_dev; MOCK_SET(spdk_vhost_dev_has_feature, bool, false); - rc = spdk_vhost_scsi_dev_remove_dev(&svdev->vdev, 0, NULL, NULL); + rc = spdk_vhost_scsi_dev_remove_tgt(&svdev->vdev, 0, NULL, NULL); CU_ASSERT(rc == -ENOTSUP); free(scsi_dev); free(svdev->vdev.name); @@ -223,7 +224,7 @@ vhost_scsi_dev_add_dev_test(void) struct spdk_scsi_dev *scsi_dev; /* Add device to controller without name */ - rc = spdk_vhost_scsi_dev_add_dev(NULL, 0, "Malloc0"); + rc = spdk_vhost_scsi_dev_add_tgt(NULL, 0, "Malloc0"); CU_ASSERT(rc == -EINVAL); svdev = alloc_svdev(); @@ -231,37 +232,37 @@ vhost_scsi_dev_add_dev_test(void) MOCK_SET(spdk_vhost_dev_has_feature, bool, false); /* Add device when max devices is reached */ - rc = spdk_vhost_scsi_dev_add_dev(vdev, + rc = spdk_vhost_scsi_dev_add_tgt(vdev, SPDK_VHOST_SCSI_CTRLR_MAX_DEVS + 1, "Malloc0"); CU_ASSERT(rc == -EINVAL); /* Add device but lun has no name */ - rc = spdk_vhost_scsi_dev_add_dev(vdev, 0, NULL); + rc = spdk_vhost_scsi_dev_add_tgt(vdev, 0, NULL); CU_ASSERT(rc == -EINVAL); /* Add device but lun has too long name */ memset(long_name, 'x', sizeof(long_name)); long_name[SPDK_SCSI_DEV_MAX_NAME] = 0; - rc = spdk_vhost_scsi_dev_add_dev(vdev, 0, long_name); + rc = spdk_vhost_scsi_dev_add_tgt(vdev, 0, long_name); CU_ASSERT(rc != 0); /* Add device to a controller which is in use */ svdev->vdev.lcore = 0; - rc = spdk_vhost_scsi_dev_add_dev(vdev, 0, "Malloc0"); + rc = spdk_vhost_scsi_dev_add_tgt(vdev, 0, "Malloc0"); CU_ASSERT(rc == -ENOTSUP); /* Add device to controller with already occupied device */ vdev->lcore = -1; scsi_dev = alloc_scsi_dev(); svdev->scsi_dev[0] = scsi_dev; - rc = spdk_vhost_scsi_dev_add_dev(vdev, 0, "Malloc0"); + rc = spdk_vhost_scsi_dev_add_tgt(vdev, 0, "Malloc0"); CU_ASSERT(rc == -EEXIST); free(scsi_dev); svdev->scsi_dev[0] = NULL; /* Failed to create device */ MOCK_SET_P(spdk_scsi_dev_construct, struct spdk_scsi_dev *, NULL); - rc = spdk_vhost_scsi_dev_add_dev(vdev, 0, "Malloc0"); + rc = spdk_vhost_scsi_dev_add_tgt(vdev, 0, "Malloc0"); CU_ASSERT(rc == -EINVAL); free(svdev); diff --git a/test/vhost/lvol/lvol_test.sh b/test/vhost/lvol/lvol_test.sh index f54e2e0cdb..ae5bccf13a 100755 --- a/test/vhost/lvol/lvol_test.sh +++ b/test/vhost/lvol/lvol_test.sh @@ -233,7 +233,7 @@ if [[ "$ctrl_type" == "vhost_scsi" ]]; then for (( i=0; i<$vm_count; i++)); do echo "INFO: Removing devices from vhost SCSI controller naa.0.$i" for (( j=0; j<${#bdevs[@]}; j++)); do - $rpc_py remove_vhost_scsi_dev naa.0.$i $j + $rpc_py remove_vhost_scsi_target naa.0.$i $j echo -e "\tINFO: Removed device $j" done echo "Removing vhost SCSI controller naa.0.$i"