Commit 72343bcf authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Jim Harris
Browse files

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: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/367309


Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent a502b88d
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -162,6 +162,7 @@ int spdk_scsi_fini(void);

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 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);
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.
 *		      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 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.
 */
struct spdk_scsi_dev *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);

void spdk_scsi_dev_delete_lun(struct spdk_scsi_dev *dev, struct spdk_scsi_lun *lun);

+1 −1
Original line number Diff line number Diff line
@@ -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,
					      SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI);
					      SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI, NULL, NULL);

	if (!target->dev) {
		SPDK_ERRLOG("Could not construct SCSI device\n");
+3 −2
Original line number Diff line number Diff line
@@ -139,7 +139,8 @@ typedef struct 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,
			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_bdev *bdev;
@@ -181,7 +182,7 @@ spdk_scsi_dev_construct(const char *name, char *lun_name_list[], int *lun_id_lis
			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) {
			goto error;
		}
+17 −4
Original line number Diff line number Diff line
@@ -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;

	lun->removed = true;
	spdk_poller_register(&lun->hotplug_poller, spdk_scsi_lun_hotplug, lun,
			     lun->lcore, 0);
	if (lun->hotremove_cb) {
		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
 */
_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;
	int rc;
@@ -284,6 +289,8 @@ spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev)

	lun->bdev = bdev;
	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);
	if (rc < 0) {
@@ -403,3 +410,9 @@ spdk_scsi_lun_get_name(const struct spdk_scsi_lun *lun)
{
	return lun->name;
}

const struct spdk_scsi_dev *
spdk_scsi_lun_get_dev(const struct spdk_scsi_lun *lun)
{
	return lun->dev;
}
+9 −1
Original line number Diff line number Diff line
@@ -108,6 +108,12 @@ struct spdk_scsi_lun {
	/** The LUN is clamed */
	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(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;

_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);

void spdk_scsi_lun_clear_all(struct spdk_scsi_lun *lun);
Loading