Commit 0a06a6ab authored by Artur Paszkiewicz's avatar Artur Paszkiewicz Committed by Jim Harris
Browse files

bdev: only allocate quiesce_ctx in the quiesce path



quiesce_ctx is available via range->locked_ctx. It can be allocated on
quiesce and freed in the unquiesce range unlocked callback.

Change-Id: I57b0fcc233a6feaba349388ae071b35eb7caea4f
Signed-off-by: default avatarArtur Paszkiewicz <artur.paszkiewicz@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/18100


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 9d5dd7cc
Loading
Loading
Loading
Loading
+24 −16
Original line number Diff line number Diff line
@@ -9531,17 +9531,23 @@ bdev_quiesce_range_locked(struct lba_range *range, void *ctx, int status)
	struct spdk_bdev_module *module = range->bdev->module;

	if (status != 0) {
		goto out;
		if (quiesce_ctx->cb_fn != NULL) {
			quiesce_ctx->cb_fn(quiesce_ctx->cb_arg, status);
		}
		free(quiesce_ctx);
		return;
	}

	spdk_spin_lock(&module->internal.spinlock);
	TAILQ_INSERT_TAIL(&module->internal.quiesced_ranges, range, tailq_module);
	spdk_spin_unlock(&module->internal.spinlock);
out:

	if (quiesce_ctx->cb_fn != NULL) {
		quiesce_ctx->cb_fn(quiesce_ctx->cb_arg, status);
		quiesce_ctx->cb_fn = NULL;
		quiesce_ctx->cb_arg = NULL;
	}
	free(quiesce_ctx);
	/* quiesce_ctx will be freed on unquiesce */
}

static int
@@ -9562,14 +9568,6 @@ _spdk_bdev_quiesce(struct spdk_bdev *bdev, struct spdk_bdev_module *module,
		return -EINVAL;
	}

	quiesce_ctx = malloc(sizeof(*quiesce_ctx));
	if (quiesce_ctx == NULL) {
		return -ENOMEM;
	}

	quiesce_ctx->cb_fn = cb_fn;
	quiesce_ctx->cb_arg = cb_arg;

	if (unquiesce) {
		struct lba_range *range;

@@ -9587,18 +9585,28 @@ _spdk_bdev_quiesce(struct spdk_bdev *bdev, struct spdk_bdev_module *module,

		if (range == NULL) {
			SPDK_ERRLOG("The range to unquiesce was not found.\n");
			free(quiesce_ctx);
			return -EINVAL;
		}

		quiesce_ctx = range->locked_ctx;
		quiesce_ctx->cb_fn = cb_fn;
		quiesce_ctx->cb_arg = cb_arg;

		rc = _bdev_unlock_lba_range(bdev, offset, length, bdev_unquiesce_range_unlocked, quiesce_ctx);
	} else {
		rc = _bdev_lock_lba_range(bdev, NULL, offset, length, bdev_quiesce_range_locked, quiesce_ctx);
		quiesce_ctx = malloc(sizeof(*quiesce_ctx));
		if (quiesce_ctx == NULL) {
			return -ENOMEM;
		}

		quiesce_ctx->cb_fn = cb_fn;
		quiesce_ctx->cb_arg = cb_arg;

		rc = _bdev_lock_lba_range(bdev, NULL, offset, length, bdev_quiesce_range_locked, quiesce_ctx);
		if (rc != 0) {
			free(quiesce_ctx);
		}
	}

	return rc;
}