scsi: added lun hotremove callback

Added optional callback inside scsi lun hotremove, so that higher-level
abstraction can be notified about hotremove.

Change-Id: I5f1bd8160e3d770a484068dd73928bc2b64c876f
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/367309
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2017-06-28 12:21:21 +02:00 committed by Jim Harris
parent a502b88da6
commit 72343bcf23
9 changed files with 57 additions and 25 deletions

View File

@ -162,6 +162,7 @@ int spdk_scsi_fini(void);
int spdk_scsi_lun_get_id(const struct spdk_scsi_lun *lun); int spdk_scsi_lun_get_id(const struct spdk_scsi_lun *lun);
const char *spdk_scsi_lun_get_name(const struct spdk_scsi_lun *lun); const char *spdk_scsi_lun_get_name(const struct spdk_scsi_lun *lun);
const struct spdk_scsi_dev *spdk_scsi_lun_get_dev(const struct spdk_scsi_lun *lun);
const char *spdk_scsi_dev_get_name(const struct spdk_scsi_dev *dev); const char *spdk_scsi_dev_get_name(const struct spdk_scsi_dev *dev);
int spdk_scsi_dev_get_id(const struct spdk_scsi_dev *dev); int spdk_scsi_dev_get_id(const struct spdk_scsi_dev *dev);
@ -189,13 +190,18 @@ void spdk_scsi_dev_free_io_channels(struct spdk_scsi_dev *dev);
* responsible for managing the memory containing this list. * responsible for managing the memory containing this list.
* lun_id_list[x] is the LUN ID for lun_list[x]. * lun_id_list[x] is the LUN ID for lun_list[x].
* \param num_luns Number of entries in lun_list and lun_id_list. * \param num_luns Number of entries in lun_list and lun_id_list.
* \param hotremove_cb Callback to lun hotremoval. Will be called
* once hotremove is first triggered.
* \param hotremove_ctx Additional argument to hotremove_cb
* \return The constructed spdk_scsi_dev object. * \return The constructed spdk_scsi_dev object.
*/ */
struct spdk_scsi_dev *spdk_scsi_dev_construct(const char *name, struct spdk_scsi_dev *spdk_scsi_dev_construct(const char *name,
char *lun_name_list[], char *lun_name_list[],
int *lun_id_list, int *lun_id_list,
int num_luns, int num_luns,
uint8_t protocol_id); uint8_t protocol_id,
void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
void *hotremove_ctx);
void spdk_scsi_dev_delete_lun(struct spdk_scsi_dev *dev, struct spdk_scsi_lun *lun); void spdk_scsi_dev_delete_lun(struct spdk_scsi_dev *dev, struct spdk_scsi_lun *lun);

View File

@ -694,7 +694,7 @@ spdk_iscsi_tgt_node_construct(int target_index,
} }
target->dev = spdk_scsi_dev_construct(name, lun_name_list, lun_id_list, num_luns, target->dev = spdk_scsi_dev_construct(name, lun_name_list, lun_id_list, num_luns,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI); SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI, NULL, NULL);
if (!target->dev) { if (!target->dev) {
SPDK_ERRLOG("Could not construct SCSI device\n"); SPDK_ERRLOG("Could not construct SCSI device\n");

View File

@ -139,7 +139,8 @@ typedef struct spdk_scsi_dev _spdk_scsi_dev;
_spdk_scsi_dev * _spdk_scsi_dev *
spdk_scsi_dev_construct(const char *name, char *lun_name_list[], int *lun_id_list, int num_luns, spdk_scsi_dev_construct(const char *name, char *lun_name_list[], int *lun_id_list, int num_luns,
uint8_t protocol_id) uint8_t protocol_id, void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
void *hotremove_ctx)
{ {
struct spdk_scsi_dev *dev; struct spdk_scsi_dev *dev;
struct spdk_bdev *bdev; struct spdk_bdev *bdev;
@ -181,7 +182,7 @@ spdk_scsi_dev_construct(const char *name, char *lun_name_list[], int *lun_id_lis
goto error; goto error;
} }
lun = spdk_scsi_lun_construct(spdk_bdev_get_name(bdev), bdev); lun = spdk_scsi_lun_construct(spdk_bdev_get_name(bdev), bdev, hotremove_cb, hotremove_ctx);
if (lun == NULL) { if (lun == NULL) {
goto error; goto error;
} }

View File

@ -232,13 +232,17 @@ spdk_scsi_lun_hotplug(void *arg)
} }
} }
static void spdk_scsi_lun_hot_remove(void *remove_ctx) static void
spdk_scsi_lun_hot_remove(void *remove_ctx)
{ {
struct spdk_scsi_lun *lun = (struct spdk_scsi_lun *)remove_ctx; struct spdk_scsi_lun *lun = (struct spdk_scsi_lun *)remove_ctx;
lun->removed = true; lun->removed = true;
spdk_poller_register(&lun->hotplug_poller, spdk_scsi_lun_hotplug, lun, if (lun->hotremove_cb) {
lun->lcore, 0); lun->hotremove_cb(lun, lun->hotremove_ctx);
}
spdk_poller_register(&lun->hotplug_poller, spdk_scsi_lun_hotplug, lun, lun->lcore, 0);
} }
/** /**
@ -251,7 +255,8 @@ static void spdk_scsi_lun_hot_remove(void *remove_ctx)
* \return pointer to the new spdk_scsi_lun object otherwise * \return pointer to the new spdk_scsi_lun object otherwise
*/ */
_spdk_scsi_lun * _spdk_scsi_lun *
spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev) spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev,
void (*hotremove_cb)(const struct spdk_scsi_lun *, void *), void *hotremove_ctx)
{ {
struct spdk_scsi_lun *lun; struct spdk_scsi_lun *lun;
int rc; int rc;
@ -284,6 +289,8 @@ spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev)
lun->bdev = bdev; lun->bdev = bdev;
snprintf(lun->name, sizeof(lun->name), "%s", name); snprintf(lun->name, sizeof(lun->name), "%s", name);
lun->hotremove_cb = hotremove_cb;
lun->hotremove_ctx = hotremove_ctx;
rc = spdk_scsi_lun_db_add(lun); rc = spdk_scsi_lun_db_add(lun);
if (rc < 0) { if (rc < 0) {
@ -403,3 +410,9 @@ spdk_scsi_lun_get_name(const struct spdk_scsi_lun *lun)
{ {
return lun->name; return lun->name;
} }
const struct spdk_scsi_dev *
spdk_scsi_lun_get_dev(const struct spdk_scsi_lun *lun)
{
return lun->dev;
}

View File

@ -108,6 +108,12 @@ struct spdk_scsi_lun {
/** The LUN is clamed */ /** The LUN is clamed */
bool claimed; bool claimed;
/** 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;
TAILQ_HEAD(tasks, spdk_scsi_task) tasks; /* submitted tasks */ TAILQ_HEAD(tasks, spdk_scsi_task) tasks; /* submitted tasks */
TAILQ_HEAD(pending_tasks, spdk_scsi_task) pending_tasks; /* pending tasks */ TAILQ_HEAD(pending_tasks, spdk_scsi_task) pending_tasks; /* pending tasks */
}; };
@ -124,7 +130,9 @@ extern struct spdk_lun_db_entry *spdk_scsi_lun_list_head;
*/ */
typedef struct spdk_scsi_lun _spdk_scsi_lun; typedef struct spdk_scsi_lun _spdk_scsi_lun;
_spdk_scsi_lun *spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev); _spdk_scsi_lun *spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev,
void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
void *hotremove_ctx);
int spdk_scsi_lun_destruct(struct spdk_scsi_lun *lun); int spdk_scsi_lun_destruct(struct spdk_scsi_lun *lun);
void spdk_scsi_lun_clear_all(struct spdk_scsi_lun *lun); void spdk_scsi_lun_clear_all(struct spdk_scsi_lun *lun);

View File

@ -635,7 +635,7 @@ spdk_vhost_scsi_dev_add_dev(const char *ctrlr_name, unsigned scsi_dev_num, const
lun_names_list[0] = (char *)lun_name; lun_names_list[0] = (char *)lun_name;
svdev->scsi_dev[scsi_dev_num] = spdk_scsi_dev_construct(dev_name, lun_names_list, lun_id_list, 1, svdev->scsi_dev[scsi_dev_num] = spdk_scsi_dev_construct(dev_name, lun_names_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_SAS); SPDK_SPC_PROTOCOL_IDENTIFIER_SAS, NULL, NULL);
if (svdev->scsi_dev[scsi_dev_num] == NULL) { 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", SPDK_ERRLOG("Couldn't create spdk SCSI device '%s' using lun device '%s' in controller: %s\n",

View File

@ -103,7 +103,9 @@ spdk_event_allocate(uint32_t core, spdk_event_fn fn, void *arg1, void *arg2)
struct spdk_scsi_dev * struct spdk_scsi_dev *
spdk_scsi_dev_construct(const char *name, char **lun_name_list, spdk_scsi_dev_construct(const char *name, char **lun_name_list,
int *lun_id_list, int num_luns, uint8_t protocol_id) int *lun_id_list, int num_luns, uint8_t protocol_id,
void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
void *hotremove_ctx)
{ {
return NULL; return NULL;
} }

View File

@ -85,7 +85,9 @@ spdk_scsi_task_put(struct spdk_scsi_task *task)
} }
_spdk_scsi_lun * _spdk_scsi_lun *
spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev) spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev,
void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
void *hotremove_ctx)
{ {
struct spdk_scsi_lun *lun; struct spdk_scsi_lun *lun;
@ -234,7 +236,7 @@ dev_construct_num_luns_zero(void)
int lun_id_list[1] = { 0 }; int lun_id_list[1] = { 0 };
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 0, dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 0,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI); SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI, NULL, NULL);
/* dev should be null since we passed num_luns = 0 */ /* dev should be null since we passed num_luns = 0 */
CU_ASSERT_TRUE(dev == NULL); CU_ASSERT_TRUE(dev == NULL);
@ -250,7 +252,7 @@ dev_construct_no_lun_zero(void)
lun_id_list[0] = 1; lun_id_list[0] = 1;
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1, dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI); SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI, NULL, NULL);
/* dev should be null since no LUN0 was specified (lun_id_list[0] = 1) */ /* dev should be null since no LUN0 was specified (lun_id_list[0] = 1) */
CU_ASSERT_TRUE(dev == NULL); CU_ASSERT_TRUE(dev == NULL);
@ -264,7 +266,7 @@ dev_construct_null_lun(void)
int lun_id_list[1] = { 0 }; int lun_id_list[1] = { 0 };
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1, dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI); SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI, NULL, NULL);
/* dev should be null since no LUN0 was specified (lun_list[0] = NULL) */ /* dev should be null since no LUN0 was specified (lun_list[0] = NULL) */
CU_ASSERT_TRUE(dev == NULL); CU_ASSERT_TRUE(dev == NULL);
@ -278,7 +280,7 @@ dev_construct_success(void)
int lun_id_list[1] = { 0 }; int lun_id_list[1] = { 0 };
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1, dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI); SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI, NULL, NULL);
/* Successfully constructs and returns a dev */ /* Successfully constructs and returns a dev */
CU_ASSERT_TRUE(dev != NULL); CU_ASSERT_TRUE(dev != NULL);
@ -297,13 +299,13 @@ dev_construct_same_lun_two_devices(void)
int lun_id_list[1] = { 0 }; int lun_id_list[1] = { 0 };
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1, dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI); SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI, NULL, NULL);
/* Successfully constructs and returns a dev */ /* Successfully constructs and returns a dev */
CU_ASSERT_TRUE(dev != NULL); CU_ASSERT_TRUE(dev != NULL);
dev2 = spdk_scsi_dev_construct("Name2", lun_name_list, lun_id_list, 1, dev2 = spdk_scsi_dev_construct("Name2", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI); SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI, NULL, NULL);
/* Fails to construct dev and returns NULL */ /* Fails to construct dev and returns NULL */
CU_ASSERT_TRUE(dev2 == NULL); CU_ASSERT_TRUE(dev2 == NULL);
@ -322,7 +324,7 @@ dev_construct_same_lun_one_device(void)
int lun_id_list[2] = { 0, 1 }; int lun_id_list[2] = { 0, 1 };
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 2, dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 2,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI); SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI, NULL, NULL);
/* Fails to construct dev and returns NULL */ /* Fails to construct dev and returns NULL */
CU_ASSERT_TRUE(dev == NULL); CU_ASSERT_TRUE(dev == NULL);
@ -339,7 +341,7 @@ dev_queue_mgmt_task_success(void)
struct spdk_scsi_task *task; struct spdk_scsi_task *task;
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1, dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI); SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI, NULL, NULL);
/* Successfully constructs and returns a dev */ /* Successfully constructs and returns a dev */
CU_ASSERT_TRUE(dev != NULL); CU_ASSERT_TRUE(dev != NULL);
@ -362,7 +364,7 @@ dev_queue_task_success(void)
struct spdk_scsi_task *task; struct spdk_scsi_task *task;
dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1, dev = spdk_scsi_dev_construct("Name", lun_name_list, lun_id_list, 1,
SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI); SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI, NULL, NULL);
/* Successfully constructs and returns a dev */ /* Successfully constructs and returns a dev */
CU_ASSERT_TRUE(dev != NULL); CU_ASSERT_TRUE(dev != NULL);

View File

@ -211,7 +211,7 @@ lun_construct(void)
struct spdk_scsi_lun *lun; struct spdk_scsi_lun *lun;
struct spdk_bdev bdev; struct spdk_bdev bdev;
lun = spdk_scsi_lun_construct("lun0", &bdev); lun = spdk_scsi_lun_construct("lun0", &bdev, NULL, NULL);
SPDK_CU_ASSERT_FATAL(lun != NULL); SPDK_CU_ASSERT_FATAL(lun != NULL);
if (lun != NULL) { if (lun != NULL) {
@ -607,7 +607,7 @@ lun_construct_null_ctx(void)
{ {
struct spdk_scsi_lun *lun; struct spdk_scsi_lun *lun;
lun = spdk_scsi_lun_construct("lun0", NULL); lun = spdk_scsi_lun_construct("lun0", NULL, NULL, NULL);
/* lun should be NULL since we passed NULL for the ctx pointer. */ /* lun should be NULL since we passed NULL for the ctx pointer. */
CU_ASSERT(lun == NULL); CU_ASSERT(lun == NULL);
@ -630,12 +630,12 @@ lun_construct_same_same_twice(void)
struct spdk_scsi_lun *lun, *lun2; struct spdk_scsi_lun *lun, *lun2;
struct spdk_bdev bdev, bdev2; struct spdk_bdev bdev, bdev2;
lun = spdk_scsi_lun_construct("lun0", &bdev); lun = spdk_scsi_lun_construct("lun0", &bdev, NULL, NULL);
/* Successfully constructs and returns lun */ /* Successfully constructs and returns lun */
SPDK_CU_ASSERT_FATAL(lun != NULL); SPDK_CU_ASSERT_FATAL(lun != NULL);
lun2 = spdk_scsi_lun_construct("lun0", &bdev2); lun2 = spdk_scsi_lun_construct("lun0", &bdev2, NULL, NULL);
/* Fails to construct the same lun on another bdev and returns NULL */ /* Fails to construct the same lun on another bdev and returns NULL */
CU_ASSERT(lun2 == NULL); CU_ASSERT(lun2 == NULL);