bdev_nvme: record io paths' stat before being destroyed

The io paths' stat will get lost when they are destroyed. Record
the stat in the nvme_ns structure.

Change-Id: I12fc0b04fac0d59e7465fe543ee733f2822a9cdb
Signed-off-by: Richael Zhuang <richael.zhuang@arm.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14744
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Richael Zhuang 2022-09-29 11:53:57 +08:00 committed by Jim Harris
parent 9c6d4dbebb
commit 4d7b2b36aa
3 changed files with 37 additions and 1 deletions

View File

@ -637,6 +637,16 @@ _bdev_nvme_delete_io_path(struct nvme_bdev_channel *nbdev_ch, struct nvme_io_pat
struct spdk_io_channel *ch;
struct nvme_qpair *nvme_qpair;
struct nvme_ctrlr_channel *ctrlr_ch;
struct nvme_bdev *nbdev;
nbdev = spdk_io_channel_get_io_device(spdk_io_channel_from_ctx(nbdev_ch));
/* Add the statistics to nvme_ns before this path is destroyed. */
pthread_mutex_lock(&nbdev->mutex);
if (nbdev->ref != 0 && io_path->nvme_ns->stat != NULL && io_path->stat != NULL) {
spdk_bdev_add_io_stat(io_path->nvme_ns->stat, io_path->stat);
}
pthread_mutex_unlock(&nbdev->mutex);
bdev_nvme_clear_current_io_path(nbdev_ch);
@ -3651,12 +3661,29 @@ timeout_cb(void *cb_arg, struct spdk_nvme_ctrlr *ctrlr,
static struct nvme_ns *
nvme_ns_alloc(void)
{
return calloc(1, sizeof(struct nvme_ns));
struct nvme_ns *nvme_ns;
nvme_ns = calloc(1, sizeof(struct nvme_ns));
if (nvme_ns == NULL) {
return NULL;
}
if (g_opts.io_path_stat) {
nvme_ns->stat = calloc(1, sizeof(struct spdk_bdev_io_stat));
if (nvme_ns->stat == NULL) {
free(nvme_ns);
return NULL;
}
spdk_bdev_reset_io_stat(nvme_ns->stat, BDEV_RESET_STAT_MAXMIN);
}
return nvme_ns;
}
static void
nvme_ns_free(struct nvme_ns *nvme_ns)
{
free(nvme_ns->stat);
free(nvme_ns);
}

View File

@ -75,6 +75,13 @@ struct nvme_ns {
struct nvme_async_probe_ctx *probe_ctx;
TAILQ_ENTRY(nvme_ns) tailq;
RB_ENTRY(nvme_ns) node;
/**
* record io path stat before destroyed. Allocation of stat is
* decided by option io_path_stat of RPC
* bdev_nvme_set_options
*/
struct spdk_bdev_io_stat *stat;
};
struct nvme_bdev_io;

View File

@ -62,6 +62,8 @@ DEFINE_STUB(spdk_bdev_io_get_submit_tsc, uint64_t, (struct spdk_bdev_io *bdev_io
DEFINE_STUB_V(spdk_bdev_reset_io_stat, (struct spdk_bdev_io_stat *stat,
enum spdk_bdev_reset_stat_mode mode));
DEFINE_STUB_V(spdk_bdev_add_io_stat, (struct spdk_bdev_io_stat *total,
struct spdk_bdev_io_stat *add));
int
spdk_nvme_ctrlr_get_memory_domains(const struct spdk_nvme_ctrlr *ctrlr,