Commit f9faa074 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

bdev/ocssd: Factor out pushing and notifying media event in chunk_notification_cb()



This is to improve readability even if the factored functions are
used only in a single place.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ifa6c7ba4380124a957e66e31123e3743d83e7615
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5146


Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent ae3b179a
Loading
Loading
Loading
Loading
+64 −45
Original line number Diff line number Diff line
@@ -847,40 +847,16 @@ bdev_ocssd_free_namespace(struct nvme_bdev_ns *nvme_ns)
}

static void
bdev_ocssd_chunk_notification_cb(void *ctx, const struct spdk_nvme_cpl *cpl)
bdev_ocssd_push_media_events(struct nvme_bdev_ns *nvme_ns,
			     struct spdk_ocssd_chunk_notification_entry *chunk_entry)
{
	struct nvme_bdev_ns *nvme_ns = ctx;
	struct bdev_ocssd_ns *ocssd_ns = bdev_ocssd_get_ns_from_nvme(nvme_ns);
	struct spdk_bdev_media_event event;
	struct spdk_ocssd_chunk_notification_entry *chunk_entry;
	struct nvme_bdev *nvme_bdev;
	struct ocssd_bdev *ocssd_bdev;
	size_t chunk_id, num_blocks, lba;
	size_t num_blocks, lba;
	int rc;

	ocssd_ns->num_outstanding--;

	/* The namespace could have been depopulated in the meantime */
	if (!nvme_ns->populated) {
		if (ocssd_ns->num_outstanding == 0) {
			bdev_ocssd_free_namespace(nvme_ns);
		}

		return;
	}

	if (spdk_nvme_cpl_is_error(cpl)) {
		SPDK_ERRLOG("Failed to retrieve chunk notification log\n");
		return;
	}

	for (chunk_id = 0; chunk_id < CHUNK_NOTIFICATION_ENTRY_COUNT; ++chunk_id) {
		chunk_entry = &ocssd_ns->chunk[chunk_id];
		if (chunk_entry->nc <= ocssd_ns->chunk_notify_count) {
			break;
		}

		ocssd_ns->chunk_notify_count = chunk_entry->nc;
	if (chunk_entry->mask.lblk) {
		num_blocks = chunk_entry->nlb;
	} else if (chunk_entry->mask.chunk) {
@@ -889,19 +865,19 @@ bdev_ocssd_chunk_notification_cb(void *ctx, const struct spdk_nvme_cpl *cpl)
		num_blocks = ocssd_ns->geometry.clba * ocssd_ns->geometry.num_chk;
	} else {
		SPDK_WARNLOG("Invalid chunk notification mask\n");
			continue;
		return;
	}

	TAILQ_FOREACH(nvme_bdev, &nvme_ns->bdevs, tailq) {
		ocssd_bdev = SPDK_CONTAINEROF(nvme_bdev, struct ocssd_bdev, nvme_bdev);
		if (bdev_ocssd_lba_in_range(ocssd_bdev, chunk_entry->lba)) {
				break;
			return;
		}
	}

	if (nvme_bdev == NULL) {
		SPDK_INFOLOG(bdev_ocssd, "Dropping media management event\n");
			continue;
		return;
	}

	lba = bdev_ocssd_from_disk_lba(ocssd_bdev, chunk_entry->lba);
@@ -922,13 +898,56 @@ bdev_ocssd_chunk_notification_cb(void *ctx, const struct spdk_nvme_cpl *cpl)
	}
}

	/* If at least one notification has been processed send out media event */
	if (chunk_id > 0) {
static void
bdev_ocssd_notify_media_management(struct nvme_bdev_ns *nvme_ns)
{
	struct nvme_bdev *nvme_bdev;

	TAILQ_FOREACH(nvme_bdev, &nvme_ns->bdevs, tailq) {
		spdk_bdev_notify_media_management(&nvme_bdev->disk);
	}
}

static void
bdev_ocssd_chunk_notification_cb(void *ctx, const struct spdk_nvme_cpl *cpl)
{
	struct nvme_bdev_ns *nvme_ns = ctx;
	struct bdev_ocssd_ns *ocssd_ns = bdev_ocssd_get_ns_from_nvme(nvme_ns);
	struct spdk_ocssd_chunk_notification_entry *chunk_entry;
	size_t chunk_id;

	ocssd_ns->num_outstanding--;

	/* The namespace could have been depopulated in the meantime */
	if (!nvme_ns->populated) {
		if (ocssd_ns->num_outstanding == 0) {
			bdev_ocssd_free_namespace(nvme_ns);
		}

		return;
	}

	if (spdk_nvme_cpl_is_error(cpl)) {
		SPDK_ERRLOG("Failed to retrieve chunk notification log\n");
		return;
	}

	for (chunk_id = 0; chunk_id < CHUNK_NOTIFICATION_ENTRY_COUNT; ++chunk_id) {
		chunk_entry = &ocssd_ns->chunk[chunk_id];
		if (chunk_entry->nc <= ocssd_ns->chunk_notify_count) {
			break;
		}

		ocssd_ns->chunk_notify_count = chunk_entry->nc;

		bdev_ocssd_push_media_events(nvme_ns, chunk_entry);
	}

	/* If at least one notification has been processed send out media event */
	if (chunk_id > 0) {
		bdev_ocssd_notify_media_management(nvme_ns);
	}

	/* If we filled the full array of events, there may be more still pending.  Set the pending
	 * flag back to true so that we try to get more events again next time the poller runs.
	 */