scsi: add spdk_io_channel support

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I189ea68c8550bbaeab79be36cb3c4faba7cd2f69
This commit is contained in:
Jim Harris 2016-09-20 12:46:28 -07:00
parent 746a54bef8
commit 06ef766bc0
6 changed files with 93 additions and 1 deletions

View File

@ -41,6 +41,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <pthread.h>
#include <sys/uio.h> #include <sys/uio.h>
#include "spdk/queue.h" #include "spdk/queue.h"
@ -193,6 +194,14 @@ struct spdk_scsi_lun {
/** The blockdev associated with this LUN. */ /** The blockdev associated with this LUN. */
struct spdk_bdev *bdev; struct spdk_bdev *bdev;
/** I/O channel for the blockdev associated with this LUN. */
struct spdk_io_channel *io_channel;
/** Thread ID for the thread that allocated the I/O channel for this
* LUN. All I/O to this LUN must be performed from this thread.
*/
pthread_t thread_id;
/** Name for this LUN. */ /** Name for this LUN. */
char name[SPDK_SCSI_LUN_MAX_NAME_LENGTH]; char name[SPDK_SCSI_LUN_MAX_NAME_LENGTH];
@ -206,6 +215,8 @@ void spdk_scsi_dev_queue_task(struct spdk_scsi_dev *dev, struct spdk_scsi_task *
int spdk_scsi_dev_add_port(struct spdk_scsi_dev *dev, uint64_t id, const char *name); int spdk_scsi_dev_add_port(struct spdk_scsi_dev *dev, uint64_t id, const char *name);
struct spdk_scsi_port *spdk_scsi_dev_find_port_by_id(struct spdk_scsi_dev *dev, uint64_t id); struct spdk_scsi_port *spdk_scsi_dev_find_port_by_id(struct spdk_scsi_dev *dev, uint64_t id);
void spdk_scsi_dev_print(struct spdk_scsi_dev *dev); void spdk_scsi_dev_print(struct spdk_scsi_dev *dev);
int spdk_scsi_dev_allocate_io_channels(struct spdk_scsi_dev *dev);
void spdk_scsi_dev_free_io_channels(struct spdk_scsi_dev *dev);
/** /**

View File

@ -256,3 +256,34 @@ spdk_scsi_dev_print(struct spdk_scsi_dev *dev)
} }
} }
void
spdk_scsi_dev_free_io_channels(struct spdk_scsi_dev *dev)
{
int i;
for (i = 0; i < SPDK_SCSI_DEV_MAX_LUN; i++) {
if (dev->lun[i] == NULL) {
continue;
}
spdk_scsi_lun_free_io_channel(dev->lun[i]);
}
}
int
spdk_scsi_dev_allocate_io_channels(struct spdk_scsi_dev *dev)
{
int i, rc;
for (i = 0; i < SPDK_SCSI_DEV_MAX_LUN; i++) {
if (dev->lun[i] == NULL) {
continue;
}
rc = spdk_scsi_lun_allocate_io_channel(dev->lun[i]);
if (rc < 0) {
spdk_scsi_dev_free_io_channels(dev);
return -1;
}
}
return 0;
}

View File

@ -34,6 +34,7 @@
#include "scsi_internal.h" #include "scsi_internal.h"
#include "spdk/endian.h" #include "spdk/endian.h"
#include "spdk/io_channel.h"
void void
spdk_scsi_lun_complete_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task) spdk_scsi_lun_complete_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task)
@ -391,3 +392,29 @@ spdk_scsi_lun_delete(const char *lun_name)
spdk_scsi_lun_destruct(lun); spdk_scsi_lun_destruct(lun);
pthread_mutex_unlock(&g_spdk_scsi.mutex); pthread_mutex_unlock(&g_spdk_scsi.mutex);
} }
int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun)
{
if (lun->io_channel != NULL) {
if (pthread_self() == lun->thread_id) {
return 0;
}
SPDK_ERRLOG("io_channel already allocated for lun %s\n", lun->name);
return -1;
}
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();
return 0;
}
void spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun)
{
if (lun->io_channel != NULL) {
spdk_put_io_channel(lun->io_channel);
lun->io_channel = NULL;
}
}

View File

@ -85,6 +85,8 @@ int spdk_scsi_lun_claim(struct spdk_scsi_lun *lun);
int spdk_scsi_lun_unclaim(struct spdk_scsi_lun *lun); int spdk_scsi_lun_unclaim(struct spdk_scsi_lun *lun);
int spdk_scsi_lun_deletable(const char *name); int spdk_scsi_lun_deletable(const char *name);
void spdk_scsi_lun_delete(const char *lun_name); void spdk_scsi_lun_delete(const char *lun_name);
int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun);
void spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun);
int spdk_scsi_lun_db_add(struct spdk_scsi_lun *lun); int spdk_scsi_lun_db_add(struct spdk_scsi_lun *lun);
int spdk_scsi_lun_db_delete(struct spdk_scsi_lun *lun); int spdk_scsi_lun_db_delete(struct spdk_scsi_lun *lun);

View File

@ -117,6 +117,17 @@ spdk_scsi_lun_execute_tasks(struct spdk_scsi_lun *lun)
{ {
} }
int
spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun)
{
return 0;
}
void
spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun)
{
}
static void static void
dev_destruct_null_dev(void) dev_destruct_null_dev(void)

View File

@ -140,7 +140,17 @@ spdk_bdev_scsi_execute(struct spdk_bdev *bdev, struct spdk_scsi_task *task)
void spdk_bdev_unregister(struct spdk_bdev *bdev) void spdk_bdev_unregister(struct spdk_bdev *bdev)
{ {
return; }
struct spdk_io_channel *
spdk_bdev_get_io_channel(struct spdk_bdev *bdev, uint32_t priority)
{
return NULL;
}
void
spdk_put_io_channel(struct spdk_io_channel *ch)
{
} }
void spdk_event_call(spdk_event_t event) void spdk_event_call(spdk_event_t event)