2016-07-27 16:32:00 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "scsi_internal.h"
|
2016-08-02 17:43:00 +00:00
|
|
|
#include "spdk/endian.h"
|
2017-03-27 19:59:40 +00:00
|
|
|
#include "spdk/env.h"
|
2016-09-20 19:46:28 +00:00
|
|
|
#include "spdk/io_channel.h"
|
2017-01-16 13:18:12 +00:00
|
|
|
#include "spdk/event.h"
|
2017-05-01 20:42:29 +00:00
|
|
|
#include "spdk/util.h"
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
spdk_scsi_lun_complete_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task)
|
|
|
|
{
|
|
|
|
if (lun) {
|
2017-05-13 00:31:46 +00:00
|
|
|
TAILQ_REMOVE(&lun->tasks, task, scsi_link);
|
2016-07-27 16:32:00 +00:00
|
|
|
spdk_trace_record(TRACE_SCSI_TASK_DONE, lun->dev->id, 0, (uintptr_t)task, 0);
|
|
|
|
}
|
|
|
|
spdk_event_call(task->cb_event);
|
|
|
|
}
|
|
|
|
|
2017-05-13 00:31:46 +00:00
|
|
|
void
|
|
|
|
spdk_scsi_lun_complete_mgmt_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task)
|
|
|
|
{
|
|
|
|
spdk_event_call(task->cb_event);
|
|
|
|
}
|
|
|
|
|
2016-07-27 16:32:00 +00:00
|
|
|
void
|
|
|
|
spdk_scsi_lun_clear_all(struct spdk_scsi_lun *lun)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_task *task, *task_tmp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called from one location, after the backend LUN
|
|
|
|
* device was reset. Can assume are no active tasks in the
|
|
|
|
* backend that need to be terminated. Just need to queue all tasks
|
|
|
|
* back to frontend for any final processing and cleanup.
|
|
|
|
*
|
|
|
|
* Queue the tasks back roughly in the order they were received
|
|
|
|
* ('cleanup' = oldest, 'tasks' = current, and 'pending' = newest)
|
|
|
|
*/
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(task, &lun->tasks, scsi_link, task_tmp) {
|
2016-10-28 19:56:36 +00:00
|
|
|
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
|
|
|
|
SPDK_SCSI_SENSE_ABORTED_COMMAND,
|
|
|
|
SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE,
|
|
|
|
SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
|
2016-07-27 16:32:00 +00:00
|
|
|
spdk_scsi_lun_complete_task(lun, task);
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(task, &lun->pending_tasks, scsi_link, task_tmp) {
|
|
|
|
TAILQ_REMOVE(&lun->pending_tasks, task, scsi_link);
|
2017-01-06 16:18:15 +00:00
|
|
|
TAILQ_INSERT_TAIL(&lun->tasks, task, scsi_link);
|
2016-10-28 19:56:36 +00:00
|
|
|
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
|
|
|
|
SPDK_SCSI_SENSE_ABORTED_COMMAND,
|
|
|
|
SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE,
|
|
|
|
SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
|
2016-07-27 16:32:00 +00:00
|
|
|
spdk_scsi_lun_complete_task(lun, task);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-05-13 01:23:54 +00:00
|
|
|
spdk_scsi_lun_task_mgmt_execute(struct spdk_scsi_task *task,
|
|
|
|
enum spdk_scsi_task_func func)
|
2016-07-27 16:32:00 +00:00
|
|
|
{
|
|
|
|
if (!task) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-05-23 20:11:49 +00:00
|
|
|
if (!task->lun) {
|
|
|
|
/* LUN does not exist */
|
|
|
|
task->response = SPDK_SCSI_TASK_MGMT_RESP_INVALID_LUN;
|
|
|
|
spdk_scsi_lun_complete_mgmt_task(NULL, task);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-05-13 01:23:54 +00:00
|
|
|
switch (func) {
|
2016-07-27 16:32:00 +00:00
|
|
|
case SPDK_SCSI_TASK_FUNC_ABORT_TASK:
|
2017-05-23 20:11:49 +00:00
|
|
|
task->response = SPDK_SCSI_TASK_MGMT_RESP_REJECT_FUNC_NOT_SUPPORTED;
|
|
|
|
SPDK_ERRLOG("ABORT_TASK failed\n");
|
2016-07-27 16:32:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SPDK_SCSI_TASK_FUNC_ABORT_TASK_SET:
|
2017-05-23 20:11:49 +00:00
|
|
|
task->response = SPDK_SCSI_TASK_MGMT_RESP_REJECT_FUNC_NOT_SUPPORTED;
|
|
|
|
SPDK_ERRLOG("ABORT_TASK_SET failed\n");
|
2016-07-27 16:32:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SPDK_SCSI_TASK_FUNC_LUN_RESET:
|
2017-05-23 20:11:49 +00:00
|
|
|
spdk_bdev_scsi_reset(task->lun->bdev, task);
|
|
|
|
return 0;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Unknown Task Management Function!\n");
|
|
|
|
/*
|
|
|
|
* Task management functions other than those above should never
|
|
|
|
* reach this point having been filtered by the frontend. Reject
|
|
|
|
* the task as being unsupported.
|
|
|
|
*/
|
|
|
|
task->response = SPDK_SCSI_TASK_MGMT_RESP_REJECT_FUNC_NOT_SUPPORTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-05-13 00:31:46 +00:00
|
|
|
spdk_scsi_lun_complete_mgmt_task(task->lun, task);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-05-23 20:11:49 +00:00
|
|
|
return -1;
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
2017-02-26 12:41:06 +00:00
|
|
|
void
|
|
|
|
spdk_scsi_task_process_null_lun(struct spdk_scsi_task *task)
|
2016-07-27 16:32:00 +00:00
|
|
|
{
|
2016-10-24 15:23:35 +00:00
|
|
|
uint8_t buffer[36];
|
2016-07-27 16:32:00 +00:00
|
|
|
uint32_t allocation_len;
|
2016-10-24 15:23:35 +00:00
|
|
|
uint32_t data_len;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-02-26 12:41:06 +00:00
|
|
|
task->length = task->transfer_len;
|
2016-07-27 16:32:00 +00:00
|
|
|
if (task->cdb[0] == SPDK_SPC_INQUIRY) {
|
|
|
|
/*
|
|
|
|
* SPC-4 states that INQUIRY commands to an unsupported LUN
|
|
|
|
* must be served with PERIPHERAL QUALIFIER = 0x3 and
|
|
|
|
* PERIPHERAL DEVICE TYPE = 0x1F.
|
|
|
|
*/
|
2016-10-24 15:23:35 +00:00
|
|
|
data_len = sizeof(buffer);
|
|
|
|
|
2016-11-14 19:14:12 +00:00
|
|
|
memset(buffer, 0, data_len);
|
|
|
|
/* PERIPHERAL QUALIFIER(7-5) PERIPHERAL DEVICE TYPE(4-0) */
|
|
|
|
buffer[0] = 0x03 << 5 | 0x1f;
|
|
|
|
/* ADDITIONAL LENGTH */
|
|
|
|
buffer[4] = data_len - 5;
|
|
|
|
|
|
|
|
allocation_len = from_be16(&task->cdb[3]);
|
2017-05-01 20:42:29 +00:00
|
|
|
if (spdk_scsi_task_scatter_data(task, buffer, spdk_min(allocation_len, data_len)) >= 0) {
|
2016-11-14 19:14:12 +00:00
|
|
|
task->data_transferred = data_len;
|
|
|
|
task->status = SPDK_SCSI_STATUS_GOOD;
|
|
|
|
}
|
2016-07-27 16:32:00 +00:00
|
|
|
} else {
|
|
|
|
/* LOGICAL UNIT NOT SUPPORTED */
|
2016-10-28 19:56:36 +00:00
|
|
|
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
|
|
|
|
SPDK_SCSI_SENSE_ILLEGAL_REQUEST,
|
|
|
|
SPDK_SCSI_ASC_LOGICAL_UNIT_NOT_SUPPORTED,
|
|
|
|
SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
|
2016-07-27 16:32:00 +00:00
|
|
|
task->data_transferred = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 18:12:49 +00:00
|
|
|
int
|
2016-07-27 16:32:00 +00:00
|
|
|
spdk_scsi_lun_append_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task)
|
|
|
|
{
|
|
|
|
TAILQ_INSERT_TAIL(&lun->pending_tasks, task, scsi_link);
|
2016-11-08 18:12:49 +00:00
|
|
|
return 0;
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_scsi_lun_execute_tasks(struct spdk_scsi_lun *lun)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_task *task, *task_tmp;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(task, &lun->pending_tasks, scsi_link, task_tmp) {
|
|
|
|
task->status = SPDK_SCSI_STATUS_GOOD;
|
2016-09-20 23:18:44 +00:00
|
|
|
task->ch = lun->io_channel;
|
2016-07-27 16:32:00 +00:00
|
|
|
spdk_trace_record(TRACE_SCSI_TASK_START, lun->dev->id, task->length, (uintptr_t)task, 0);
|
|
|
|
TAILQ_REMOVE(&lun->pending_tasks, task, scsi_link);
|
2017-01-06 16:18:15 +00:00
|
|
|
TAILQ_INSERT_TAIL(&lun->tasks, task, scsi_link);
|
2017-01-16 13:18:12 +00:00
|
|
|
if (!lun->removed) {
|
|
|
|
rc = spdk_bdev_scsi_execute(lun->bdev, task);
|
|
|
|
} else {
|
|
|
|
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
|
|
|
|
SPDK_SCSI_SENSE_ABORTED_COMMAND,
|
|
|
|
SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE,
|
|
|
|
SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
|
|
|
|
rc = SPDK_SCSI_TASK_COMPLETE;
|
|
|
|
}
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
switch (rc) {
|
|
|
|
case SPDK_SCSI_TASK_PENDING:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SPDK_SCSI_TASK_COMPLETE:
|
|
|
|
spdk_scsi_lun_complete_task(lun, task);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 13:18:12 +00:00
|
|
|
static void
|
|
|
|
spdk_scsi_lun_hotplug(void *arg)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun = (struct spdk_scsi_lun *)arg;
|
|
|
|
|
|
|
|
if (TAILQ_EMPTY(&lun->pending_tasks) && TAILQ_EMPTY(&lun->tasks)) {
|
|
|
|
spdk_scsi_lun_free_io_channel(lun);
|
|
|
|
spdk_scsi_lun_delete(lun->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void spdk_scsi_lun_hot_remove(void *remove_ctx)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun = (struct spdk_scsi_lun *)remove_ctx;
|
|
|
|
|
|
|
|
lun->removed = true;
|
|
|
|
spdk_poller_register(&lun->hotplug_poller, spdk_scsi_lun_hotplug, lun,
|
|
|
|
lun->lcore, 0);
|
|
|
|
}
|
|
|
|
|
2017-04-24 18:14:41 +00:00
|
|
|
/**
|
2017-04-25 17:35:22 +00:00
|
|
|
* \brief Constructs a new spdk_scsi_lun object based on the provided parameters.
|
|
|
|
*
|
|
|
|
* \param name Name for the SCSI LUN.
|
|
|
|
* \param blockdev Blockdev associated with this LUN
|
|
|
|
*
|
|
|
|
* \return NULL if blockdev == NULL
|
|
|
|
* \return pointer to the new spdk_scsi_lun object otherwise
|
|
|
|
*/
|
2016-07-27 16:32:00 +00:00
|
|
|
_spdk_scsi_lun *
|
|
|
|
spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (bdev == NULL) {
|
|
|
|
SPDK_ERRLOG("blockdev must be non-NULL\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-02 17:11:56 +00:00
|
|
|
lun = spdk_lun_db_get_lun(name);
|
2016-07-27 16:32:00 +00:00
|
|
|
if (lun) {
|
2017-01-20 10:20:18 +00:00
|
|
|
SPDK_ERRLOG("LUN %s already created\n", lun->name);
|
|
|
|
return NULL;
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lun = calloc(1, sizeof(*lun));
|
|
|
|
if (lun == NULL) {
|
|
|
|
SPDK_ERRLOG("could not allocate lun\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-01-16 13:18:12 +00:00
|
|
|
if (!spdk_bdev_claim(bdev, spdk_scsi_lun_hot_remove, lun)) {
|
2017-05-10 20:29:31 +00:00
|
|
|
SPDK_ERRLOG("LUN %s: bdev %s is already claimed\n", name, spdk_bdev_get_name(bdev));
|
2017-01-10 16:54:23 +00:00
|
|
|
free(lun);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-27 16:32:00 +00:00
|
|
|
TAILQ_INIT(&lun->tasks);
|
|
|
|
TAILQ_INIT(&lun->pending_tasks);
|
|
|
|
|
|
|
|
lun->bdev = bdev;
|
2017-03-23 23:02:28 +00:00
|
|
|
snprintf(lun->name, sizeof(lun->name), "%s", name);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
rc = spdk_scsi_lun_db_add(lun);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to add LUN %s to DB\n", lun->name);
|
2017-02-07 13:08:06 +00:00
|
|
|
spdk_bdev_unclaim(bdev);
|
2016-07-27 16:32:00 +00:00
|
|
|
free(lun);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lun;
|
|
|
|
}
|
|
|
|
|
2017-02-08 11:17:25 +00:00
|
|
|
int
|
2016-07-27 16:32:00 +00:00
|
|
|
spdk_scsi_lun_destruct(struct spdk_scsi_lun *lun)
|
|
|
|
{
|
2017-01-10 16:54:23 +00:00
|
|
|
spdk_bdev_unclaim(lun->bdev);
|
2017-01-16 13:18:12 +00:00
|
|
|
spdk_poller_unregister(&lun->hotplug_poller, NULL);
|
2016-07-27 16:32:00 +00:00
|
|
|
spdk_scsi_lun_db_delete(lun);
|
|
|
|
|
|
|
|
free(lun);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_scsi_lun_claim(struct spdk_scsi_lun *lun)
|
|
|
|
{
|
2017-03-02 17:11:56 +00:00
|
|
|
assert(spdk_lun_db_get_lun(lun->name) != NULL);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-03-02 17:11:56 +00:00
|
|
|
if (lun->claimed != false) {
|
2016-07-27 16:32:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-03-02 17:11:56 +00:00
|
|
|
lun->claimed = true;
|
2016-07-27 16:32:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_scsi_lun_unclaim(struct spdk_scsi_lun *lun)
|
|
|
|
{
|
2017-03-02 17:11:56 +00:00
|
|
|
assert(spdk_lun_db_get_lun(lun->name) != NULL);
|
|
|
|
assert(lun->claimed == true);
|
|
|
|
lun->claimed = false;
|
2016-07-27 16:32:00 +00:00
|
|
|
lun->dev = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_scsi_lun_delete(const char *lun_name)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
|
|
|
struct spdk_scsi_dev *dev;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&g_spdk_scsi.mutex);
|
2017-03-02 17:11:56 +00:00
|
|
|
lun = spdk_lun_db_get_lun(lun_name);
|
2017-01-03 21:22:34 +00:00
|
|
|
if (lun == NULL) {
|
2017-03-02 17:11:56 +00:00
|
|
|
SPDK_ERRLOG("LUN '%s' not found", lun_name);
|
2016-07-27 16:32:00 +00:00
|
|
|
pthread_mutex_unlock(&g_spdk_scsi.mutex);
|
2017-03-02 17:11:56 +00:00
|
|
|
return -1;
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dev = lun->dev;
|
|
|
|
|
|
|
|
/* Remove the LUN from the device */
|
|
|
|
if (dev != NULL) {
|
|
|
|
spdk_scsi_dev_delete_lun(dev, lun);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Destroy this lun */
|
|
|
|
spdk_scsi_lun_destruct(lun);
|
|
|
|
pthread_mutex_unlock(&g_spdk_scsi.mutex);
|
2017-03-02 17:11:56 +00:00
|
|
|
return 0;
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
2016-09-20 19:46:28 +00:00
|
|
|
|
|
|
|
int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun)
|
|
|
|
{
|
|
|
|
if (lun->io_channel != NULL) {
|
|
|
|
if (pthread_self() == lun->thread_id) {
|
2016-12-23 07:34:53 +00:00
|
|
|
lun->ref++;
|
2016-09-20 19:46:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SPDK_ERRLOG("io_channel already allocated for lun %s\n", lun->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-03-27 19:59:40 +00:00
|
|
|
lun->lcore = spdk_env_get_current_core();
|
2017-01-16 13:18:12 +00:00
|
|
|
|
2016-09-20 19:46:28 +00:00
|
|
|
lun->io_channel = spdk_bdev_get_io_channel(lun->bdev, SPDK_IO_PRIORITY_DEFAULT);
|
|
|
|
if (lun->io_channel == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
lun->thread_id = pthread_self();
|
2016-12-23 07:34:53 +00:00
|
|
|
lun->ref = 1;
|
2016-09-20 19:46:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun)
|
|
|
|
{
|
|
|
|
if (lun->io_channel != NULL) {
|
2016-12-23 07:34:53 +00:00
|
|
|
lun->ref--;
|
|
|
|
if (lun->ref == 0) {
|
|
|
|
spdk_put_io_channel(lun->io_channel);
|
|
|
|
lun->io_channel = NULL;
|
|
|
|
}
|
2016-09-20 19:46:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-01 20:32:34 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
spdk_scsi_lun_get_id(const struct spdk_scsi_lun *lun)
|
|
|
|
{
|
|
|
|
return lun->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
spdk_scsi_lun_get_name(const struct spdk_scsi_lun *lun)
|
|
|
|
{
|
|
|
|
return lun->name;
|
|
|
|
}
|