|
1 | 1 | /* |
2 | 2 | * Copyright(c) 2012-2022 Intel Corporation |
3 | 3 | * Copyright(c) 2024 Huawei Technologies |
| 4 | + * Copyright(c) 2026 Unvertical |
4 | 5 | * SPDX-License-Identifier: BSD-3-Clause |
5 | 6 | */ |
6 | 7 | #include "metadata.h" |
@@ -230,7 +231,7 @@ static void metadata_io_req_finalize(struct metadata_io_request *m_req) |
230 | 231 | struct metadata_io_request_asynch *a_req = m_req->asynch; |
231 | 232 |
|
232 | 233 | if (env_atomic_dec_return(&a_req->req_active) == 0) |
233 | | - env_mpool_del(m_req->cache->owner->resources.mio, a_req, |
| 234 | + env_mpool_del(m_req->cache->owner->resources.mio.mpool, a_req, |
234 | 235 | a_req->alloc_req_count); |
235 | 236 | } |
236 | 237 |
|
@@ -388,7 +389,7 @@ static int metadata_io_i_asynch(ocf_cache_t cache, ocf_queue_t queue, int dir, |
388 | 389 | uint32_t io_count = OCF_DIV_ROUND_UP(count, max_count); |
389 | 390 | uint32_t req_count = OCF_MIN(io_count, METADATA_IO_REQS_LIMIT); |
390 | 391 | int i; |
391 | | - struct env_mpool *mio_allocator = cache->owner->resources.mio; |
| 392 | + struct env_mpool *mio_allocator = cache->owner->resources.mio.mpool; |
392 | 393 |
|
393 | 394 | if (count == 0) |
394 | 395 | return 0; |
@@ -483,29 +484,49 @@ int metadata_io_read_i_asynch(ocf_cache_t cache, ocf_queue_t queue, |
483 | 484 | not exceed one page (4096B). |
484 | 485 | Change if apropriate. */ |
485 | 486 |
|
486 | | -int ocf_metadata_io_ctx_init(struct ocf_ctx *ocf_ctx) |
| 487 | +int ocf_metadata_io_open(struct ocf_ctx *ocf_ctx) |
487 | 488 | { |
488 | 489 | uint32_t limits[] = { |
489 | 490 | [0 ... MIO_RPOOL_THRESHOLD - 1] = -1, |
490 | 491 | [MIO_RPOOL_THRESHOLD ... ocf_mio_size_max - 1] = MIO_RPOOL_LIMIT, |
491 | 492 | [ocf_mio_size_max ... env_mpool_max] = -1, |
492 | 493 | }; |
493 | 494 |
|
494 | | - ocf_ctx->resources.mio = env_mpool_create( |
| 495 | + if (ocf_ctx->resources.mio.ref_count > 0) |
| 496 | + goto out; |
| 497 | + |
| 498 | + ocf_ctx->resources.mio.mpool = env_mpool_create( |
495 | 499 | sizeof(struct metadata_io_request_asynch), |
496 | 500 | sizeof(struct metadata_io_request), |
497 | 501 | ENV_MEM_NOIO, ocf_mio_size_max - 1, true, |
498 | 502 | limits, |
499 | 503 | "ocf_mio", |
500 | 504 | true); |
501 | | - if (ocf_ctx->resources.mio == NULL) |
502 | | - return -1; |
| 505 | + if (ocf_ctx->resources.mio.mpool == NULL) |
| 506 | + return -OCF_ERR_NO_MEM; |
| 507 | + |
| 508 | +out: |
| 509 | + ocf_ctx->resources.mio.ref_count++; |
| 510 | + return 0; |
| 511 | +} |
| 512 | + |
| 513 | +void ocf_metadata_io_close(struct ocf_ctx *ocf_ctx) |
| 514 | +{ |
| 515 | + if (--ocf_ctx->resources.mio.ref_count == 0) { |
| 516 | + env_mpool_destroy(ocf_ctx->resources.mio.mpool); |
| 517 | + ocf_ctx->resources.mio.mpool = NULL; |
| 518 | + } |
| 519 | +} |
| 520 | + |
| 521 | +int ocf_metadata_io_ctx_init(struct ocf_ctx *ocf_ctx) |
| 522 | +{ |
| 523 | + ocf_ctx->resources.mio.mpool = NULL; |
| 524 | + ocf_ctx->resources.mio.ref_count = 0; |
503 | 525 |
|
504 | 526 | return 0; |
505 | 527 | } |
506 | 528 |
|
507 | 529 | void ocf_metadata_io_ctx_deinit(struct ocf_ctx *ocf_ctx) |
508 | 530 | { |
509 | | - env_mpool_destroy(ocf_ctx->resources.mio); |
510 | | - ocf_ctx->resources.mio = NULL; |
| 531 | + ENV_BUG_ON(ocf_ctx->resources.mio.ref_count != 0); |
511 | 532 | } |
0 commit comments