#ifndef SPDK_SCSI_INTERNAL_H
#define SPDK_SCSI_INTERNAL_H
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <pthread.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/uio.h>
+#include "spdk/stdinc.h"
#include "spdk/bdev.h"
#include "spdk/scsi.h"
#include "spdk_internal/log.h"
-
-/**
- * Macro to return the minimum of two numbers
- */
-#define SPDK_MIN(a, b) ({ \
- typeof (a) _a = (a); \
- typeof (b) _b = (b); \
- _a < _b ? _a : _b; \
- })
-
-/**
- * Macro to return the maximum of two numbers
- */
-#define SPDK_MAX(a, b) ({ \
- typeof (a) _a = (a); \
- typeof (b) _b = (b); \
- _a > _b ? _a : _b; \
- })
-
enum {
SPDK_SCSI_TASK_UNKNOWN = -1,
SPDK_SCSI_TASK_COMPLETE,
SPDK_SCSI_TASK_PENDING,
};
+struct spdk_scsi_port {
+ uint8_t is_used;
+ uint64_t id;
+ uint16_t index;
+ char name[SPDK_SCSI_PORT_MAX_NAME_LENGTH];
+};
+
+struct spdk_scsi_dev {
+ int id;
+ int is_allocated;
+ bool removed;
+
+ char name[SPDK_SCSI_DEV_MAX_NAME + 1];
+
+ struct spdk_scsi_lun *lun[SPDK_SCSI_DEV_MAX_LUN];
+
+ int num_ports;
+ struct spdk_scsi_port port[SPDK_SCSI_DEV_MAX_PORTS];
+
+ uint8_t protocol_id;
+};
+
+struct spdk_scsi_desc {
+ struct spdk_scsi_lun *lun;
+ spdk_scsi_remove_cb_t hotremove_cb;
+ void *hotremove_ctx;
+ TAILQ_ENTRY(spdk_scsi_desc) link;
+};
+
+struct spdk_scsi_lun {
+ /** LUN id for this logical unit. */
+ int id;
+
+ /** Pointer to the SCSI device containing this LUN. */
+ struct spdk_scsi_dev *dev;
+
+ /** The bdev associated with this LUN. */
+ struct spdk_bdev *bdev;
+
+ /** Descriptor for opened block device. */
+ struct spdk_bdev_desc *bdev_desc;
+
+ /** I/O channel for the bdev associated with this LUN. */
+ struct spdk_io_channel *io_channel;
+
+ /** The reference number for this LUN, thus we can correctly free the io_channel */
+ uint32_t ref;
+
+ /** Poller to release the resource of the lun when it is hot removed */
+ struct spdk_poller *hotremove_poller;
+
+ /** The LUN is removed */
+ bool removed;
+
+ /** Callback to be fired when LUN removal is first triggered. */
+ void (*hotremove_cb)(const struct spdk_scsi_lun *lun, void *arg);
+
+ /** Argument for hotremove_cb */
+ void *hotremove_ctx;
+
+ /** List of open descriptors for this LUN. */
+ TAILQ_HEAD(, spdk_scsi_desc) open_descs;
+
+ /** pending tasks */
+ TAILQ_HEAD(tasks, spdk_scsi_task) tasks;
+};
+
struct spdk_lun_db_entry {
struct spdk_scsi_lun *lun;
struct spdk_lun_db_entry *next;
*/
typedef struct spdk_scsi_lun _spdk_scsi_lun;
-_spdk_scsi_lun *spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev);
-int spdk_scsi_lun_destruct(struct spdk_scsi_lun *lun);
+_spdk_scsi_lun *spdk_scsi_lun_construct(struct spdk_bdev *bdev,
+ void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
+ void *hotremove_ctx);
+void spdk_scsi_lun_destruct(struct spdk_scsi_lun *lun);
-void spdk_scsi_lun_clear_all(struct spdk_scsi_lun *lun);
-int spdk_scsi_lun_append_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
-void spdk_scsi_lun_execute_tasks(struct spdk_scsi_lun *lun);
-int spdk_scsi_lun_task_mgmt_execute(struct spdk_scsi_task *task);
+void spdk_scsi_lun_execute_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
+int spdk_scsi_lun_task_mgmt_execute(struct spdk_scsi_task *task, enum spdk_scsi_task_func func);
void spdk_scsi_lun_complete_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
-int spdk_scsi_lun_claim(struct spdk_scsi_lun *lun);
-int spdk_scsi_lun_unclaim(struct spdk_scsi_lun *lun);
-int 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_delete(struct spdk_scsi_lun *lun);
-
-struct spdk_scsi_lun *spdk_lun_db_get_lun(const char *lun_name);
+void spdk_scsi_lun_complete_mgmt_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
+bool spdk_scsi_lun_has_pending_tasks(const struct spdk_scsi_lun *lun);
+int _spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun);
+void _spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun);
struct spdk_scsi_dev *spdk_scsi_dev_get_list(void);
-int spdk_bdev_scsi_execute(struct spdk_bdev *bdev, struct spdk_scsi_task *task);
-int spdk_bdev_scsi_reset(struct spdk_bdev *bdev, struct spdk_scsi_task *task);
-
-void spdk_scsi_nvme_translate(struct spdk_bdev_io *bdev_io, int *sc, int *sk, int *asc, int *ascq);
+int spdk_scsi_port_construct(struct spdk_scsi_port *port, uint64_t id,
+ uint16_t index, const char *name);
+void spdk_scsi_port_destruct(struct spdk_scsi_port *port);
-struct spdk_scsi_parameters {
- uint32_t max_unmap_lba_count;
- uint32_t max_unmap_block_descriptor_count;
- uint32_t optimal_unmap_granularity;
- uint32_t unmap_granularity_alignment;
- uint32_t ugavalid;
- uint64_t max_write_same_length;
-};
+int spdk_bdev_scsi_execute(struct spdk_scsi_task *task);
+void spdk_bdev_scsi_reset(struct spdk_scsi_task *task);
struct spdk_scsi_globals {
pthread_mutex_t mutex;
- struct spdk_scsi_parameters scsi_params;
};
extern struct spdk_scsi_globals g_spdk_scsi;