Commit af561c1a authored by GangCao's avatar GangCao Committed by Tomasz Zawadzki
Browse files

Bdev/QoS: add a specific bdev_start_qos function



Change-Id: I93f930faf88703e22e156f4fe0c22e162f030894
Signed-off-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1030


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 70cc99bc
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -5180,11 +5180,32 @@ bdev_dummy_event_cb(void *remove_ctx)
	SPDK_DEBUGLOG(SPDK_LOG_BDEV, "Bdev remove event received with no remove callback specified");
}

static int
bdev_start_qos(struct spdk_bdev *bdev)
{
	struct set_qos_limit_ctx *ctx;

	/* Enable QoS */
	if (bdev->internal.qos && bdev->internal.qos->thread == NULL) {
		ctx = calloc(1, sizeof(*ctx));
		if (ctx == NULL) {
			SPDK_ERRLOG("Failed to allocate memory for QoS context\n");
			return -ENOMEM;
		}
		ctx->bdev = bdev;
		spdk_for_each_channel(__bdev_to_io_dev(bdev),
				      bdev_enable_qos_msg, ctx,
				      bdev_enable_qos_done);
	}

	return 0;
}

static int
bdev_open(struct spdk_bdev *bdev, bool write, struct spdk_bdev_desc *desc)
{
	struct spdk_thread *thread;
	struct set_qos_limit_ctx *ctx;
	int rc = 0;

	thread = spdk_get_thread();
	if (!thread) {
@@ -5212,18 +5233,11 @@ bdev_open(struct spdk_bdev *bdev, bool write, struct spdk_bdev_desc *desc)
		return -EPERM;
	}

	/* Enable QoS */
	if (bdev->internal.qos && bdev->internal.qos->thread == NULL) {
		ctx = calloc(1, sizeof(*ctx));
		if (ctx == NULL) {
			SPDK_ERRLOG("Failed to allocate memory for QoS context\n");
	rc = bdev_start_qos(bdev);
	if (rc != 0) {
		SPDK_ERRLOG("Failed to start QoS on bdev %s\n", bdev->name);
		pthread_mutex_unlock(&bdev->internal.mutex);
			return -ENOMEM;
		}
		ctx->bdev = bdev;
		spdk_for_each_channel(__bdev_to_io_dev(bdev),
				      bdev_enable_qos_msg, ctx,
				      bdev_enable_qos_done);
		return rc;
	}

	TAILQ_INSERT_TAIL(&bdev->internal.open_descs, desc, link);