Commit 458214e2 authored by Changpeng Liu's avatar Changpeng Liu Committed by Tomasz Zawadzki
Browse files

nvme/opal: remove the revert asynchronous API



The revert asynchronous API doesn't run as the *real* asynchronous
way, because the drive can only support synchronous module and only
1 session is supported.  The reason why we added this API is that
RPC call has the default timeout value here, while the revert may
take over several minutes, the API itself doesn't short the revert
action, so just remove it and use the synchronous API instead.

The revert action will erase all the users data and bring the drive
back to the factory state, it should run in the synchronous mode,
so just remove the asynchronous API and we can increase the timeout
value when using RPC to call this API.

Change-Id: I08a082edea6385e378399423bbb229d05f8bc262
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1232


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 3502a45d
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
@@ -97,8 +97,6 @@ struct spdk_opal_locking_range_info {

struct spdk_opal_dev;

typedef void (*spdk_opal_revert_cb)(struct spdk_opal_dev *dev, void *ctx, int rc);

struct spdk_opal_dev *spdk_opal_dev_construct(struct spdk_nvme_ctrlr *ctrlr);
void spdk_opal_dev_destruct(struct spdk_opal_dev *dev);

@@ -108,24 +106,6 @@ bool spdk_opal_supported(struct spdk_opal_dev *dev);

int spdk_opal_cmd_take_ownership(struct spdk_opal_dev *dev, char *new_passwd);

/**
 * Users should periodically call spdk_opal_revert_poll to check if the response is received.
 * Once a final result is received, no matter success or failure, dev->revert_cb_fn will be called.
 * Error code is put to dev->revert_cb_fn.
 *
 * Return: -EAGAIN for no result yet. 0 for final result received.
 */
int spdk_opal_revert_poll(struct spdk_opal_dev *dev);

/**
 * asynchronous function: Just send cmd and return.
 *
 * Users should periodically call spdk_opal_revert_poll to check if the response is received.
 * Because usually revert TPer operation will take a while.
 */
int spdk_opal_cmd_revert_tper_async(struct spdk_opal_dev *dev, const char *passwd,
				    spdk_opal_revert_cb cb_fn, void *cb_ctx);

/**
 * synchronous function: send and then receive.
 *
+0 −90
Original line number Diff line number Diff line
@@ -1971,96 +1971,6 @@ end:
	return ret;
}

int
spdk_opal_revert_poll(struct spdk_opal_dev *dev)
{
	void *response = dev->resp;
	struct spdk_opal_compacket *header = response;
	int ret;

	assert(dev->revert_cb_fn);

	ret = spdk_nvme_ctrlr_security_receive(dev->ctrlr, SPDK_SCSI_SECP_TCG, dev->comid,
					       0, dev->resp, IO_BUFFER_LENGTH);
	if (ret) {
		SPDK_ERRLOG("Security Receive Error on dev = %p\n", dev);
		dev->revert_cb_fn(dev, dev->ctx, ret);
		return 0;
	}

	if (header->outstanding_data == 0 &&
	    header->min_transfer == 0) {
		ret = opal_parse_and_check_status(dev, NULL);
		dev->revert_cb_fn(dev, dev->ctx, ret);
		return 0;
	} else {
		memset(response, 0, IO_BUFFER_LENGTH);
	}

	return -EAGAIN;
}

int
spdk_opal_cmd_revert_tper_async(struct spdk_opal_dev *dev, const char *passwd,
				spdk_opal_revert_cb cb_fn, void *cb_ctx)
{
	int ret;
	struct spdk_opal_key opal_key = {};

	if (dev->supported == false) {
		return -ENOTSUP;
	}

	if (cb_fn == NULL) {
		SPDK_ERRLOG("No revert callback function specified.\n");
		return -EFAULT;
	}

	dev->revert_cb_fn = cb_fn;
	dev->ctx = cb_ctx;

	ret = opal_init_key(&opal_key, passwd, OPAL_LOCKING_RANGE_GLOBAL);
	if (ret) {
		SPDK_ERRLOG("Init key failed\n");
		return ret;
	}

	pthread_mutex_lock(&dev->mutex_lock);
	opal_setup_dev(dev);

	ret = opal_start_generic_session(dev, UID_SID, UID_ADMINSP,
					 opal_key.key, opal_key.key_len);
	if (ret) {
		opal_end_session(dev);
		SPDK_ERRLOG("Error on starting admin SP session with error %d\n", ret);
		goto end;
	}

	ret = opal_revert_tper(dev);
	if (ret) {
		opal_end_session(dev);
		SPDK_ERRLOG("Error on reverting TPer with error %d\n", ret);
		goto end;
	}

	ret = opal_cmd_finalize(dev, dev->hsn, dev->tsn, true);    /* true: end of data */
	if (ret) {
		SPDK_ERRLOG("Error finalizing command buffer: %d\n", ret);
		goto end;
	}

	ret = opal_send_cmd(dev);
	if (ret) {
		SPDK_ERRLOG("Error sending opal command: %d\n", ret);
	}

	/* Controller will terminate session. No "end session" here needed. */

end:
	pthread_mutex_unlock(&dev->mutex_lock);
	return ret;
}

int
spdk_opal_cmd_activate_locking_sp(struct spdk_opal_dev *dev, const char *passwd)
{
+0 −1
Original line number Diff line number Diff line
@@ -291,7 +291,6 @@ struct spdk_opal_dev {
	struct spdk_opal_locking_range_info locking_ranges[SPDK_OPAL_MAX_LOCKING_RANGE];

	pthread_mutex_t mutex_lock; /* some structs are accessed by current thread only */
	spdk_opal_revert_cb revert_cb_fn;
	void *ctx;  /* user context data */
};

+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 2
SO_MINOR := 0
SO_MINOR := 1
SO_SUFFIX := $(SO_VER).$(SO_MINOR)

C_SRCS = bdev_nvme.c bdev_nvme_rpc.c nvme_rpc.c common.c bdev_ocssd.c bdev_ocssd_rpc.c
+0 −5
Original line number Diff line number Diff line
@@ -155,11 +155,6 @@ nvme_bdev_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)

	spdk_poller_unregister(&nvme_bdev_ctrlr->destruct_poller);
	if (nvme_bdev_ctrlr->opal_dev) {
		if (nvme_bdev_ctrlr->opal_poller != NULL) {
			spdk_poller_unregister(&nvme_bdev_ctrlr->opal_poller);
			/* wait until we get the result */
			while (spdk_opal_revert_poll(nvme_bdev_ctrlr->opal_dev) == -EAGAIN);
		}
		spdk_opal_dev_destruct(nvme_bdev_ctrlr->opal_dev);
		nvme_bdev_ctrlr->opal_dev = NULL;
	}
Loading