Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAOS-17086 cart: clean up context_quotas_init()/finalize() #15864

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 28 additions & 50 deletions src/cart/crt_context.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* (C) Copyright 2016-2024 Intel Corporation.
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand All @@ -10,12 +11,17 @@

#include "crt_internal.h"

static void crt_epi_destroy(struct crt_ep_inflight *epi);
static int context_quotas_init(crt_context_t crt_ctx);
static int context_quotas_finalize(crt_context_t crt_ctx);
static void
crt_epi_destroy(struct crt_ep_inflight *epi);
static void
context_quotas_init(struct crt_context *ctx);
static void
context_quotas_finalize(struct crt_context *ctx);

static inline int get_quota_resource(crt_context_t crt_ctx, crt_quota_type_t quota);
static inline void put_quota_resource(crt_context_t crt_ctx, crt_quota_type_t quota);
static inline int
get_quota_resource(crt_context_t crt_ctx, crt_quota_type_t quota);
static inline void
put_quota_resource(crt_context_t crt_ctx, crt_quota_type_t quota);

static struct crt_ep_inflight *
epi_link2ptr(d_list_t *rlink)
Expand Down Expand Up @@ -133,14 +139,12 @@ crt_context_ep_empty(crt_context_t crt_ctx)
}

static int
crt_context_init(crt_context_t crt_ctx)
crt_context_init(struct crt_context *ctx)
{
struct crt_context *ctx;
uint32_t bh_node_cnt;
int rc;
uint32_t bh_node_cnt;
int rc;

D_ASSERT(crt_ctx != NULL);
ctx = crt_ctx;
D_ASSERT(ctx != NULL);

rc = D_MUTEX_INIT(&ctx->cc_mutex, NULL);
if (rc != 0)
Expand All @@ -157,30 +161,29 @@ crt_context_init(crt_context_t crt_ctx)

/* create timeout binheap */
bh_node_cnt = CRT_DEFAULT_CREDITS_PER_EP_CTX * 64;
rc = d_binheap_create_inplace(DBH_FT_NOLOCK, bh_node_cnt,
NULL /* priv */, &crt_timeout_bh_ops,
&ctx->cc_bh_timeout);
rc = d_binheap_create_inplace(DBH_FT_NOLOCK, bh_node_cnt, NULL /* priv */,
&crt_timeout_bh_ops, &ctx->cc_bh_timeout);
if (rc != 0) {
D_ERROR("d_binheap_create() failed, " DF_RC "\n", DP_RC(rc));
D_GOTO(out_mutex_destroy, rc);
}

/* create epi table, use external lock */
rc = d_hash_table_create_inplace(D_HASH_FT_NOLOCK, CRT_EPI_TABLE_BITS,
NULL, &epi_table_ops,
rc = d_hash_table_create_inplace(D_HASH_FT_NOLOCK, CRT_EPI_TABLE_BITS, NULL, &epi_table_ops,
&ctx->cc_epi_table);
if (rc != 0) {
D_ERROR("d_hash_table_create() failed, " DF_RC "\n", DP_RC(rc));
D_GOTO(out_binheap_destroy, rc);
}

rc = context_quotas_init(crt_ctx);
context_quotas_init(ctx);

D_GOTO(out, rc);
return 0;

out_binheap_destroy:
d_binheap_destroy_inplace(&ctx->cc_bh_timeout);
out_mutex_destroy:
D_MUTEX_DESTROY(&ctx->cc_quotas.mutex);
D_MUTEX_DESTROY(&ctx->cc_mutex);
out:
return rc;
Expand Down Expand Up @@ -757,7 +760,7 @@ crt_context_abort(struct crt_context *ctx, bool force)
int
crt_context_destroy(crt_context_t crt_ctx, int force)
{
struct crt_context *ctx;
struct crt_context *ctx = crt_ctx;
uint32_t timeout_sec;
int ctx_idx;
int provider;
Expand All @@ -776,14 +779,7 @@ crt_context_destroy(crt_context_t crt_ctx, int force)
D_GOTO(out, rc = -DER_UNINIT);
}

rc = context_quotas_finalize(crt_ctx);
if (rc) {
DL_ERROR(rc, "context_quotas_finalize() failed");
if (!force)
D_GOTO(out, rc);
}

ctx = crt_ctx;
context_quotas_finalize(ctx);

rc = crt_context_idx(crt_ctx, &ctx_idx);
if (rc != 0) {
Expand Down Expand Up @@ -2113,41 +2109,23 @@ crt_req_force_completion(struct crt_rpc_priv *rpc_priv)
D_MUTEX_UNLOCK(&crt_ctx->cc_mutex);
}

static int
context_quotas_init(crt_context_t crt_ctx)
static void
context_quotas_init(struct crt_context *ctx)
{
struct crt_context *ctx = crt_ctx;
struct crt_quotas *quotas;
int rc = 0;

if (ctx == NULL) {
D_ERROR("NULL context\n");
D_GOTO(out, rc = -DER_INVAL);
}
struct crt_quotas *quotas;

quotas = &ctx->cc_quotas;

quotas->limit[CRT_QUOTA_RPCS] = crt_gdata.cg_rpc_quota;
quotas->current[CRT_QUOTA_RPCS] = 0;
quotas->enabled[CRT_QUOTA_RPCS] = crt_gdata.cg_rpc_quota > 0 ? true : false;
out:
return rc;
}

static int
context_quotas_finalize(crt_context_t crt_ctx)
static void
context_quotas_finalize(struct crt_context *ctx)
{
struct crt_context *ctx = crt_ctx;

if (ctx == NULL) {
D_ERROR("NULL context\n");
return -DER_INVAL;
}

for (int i = 0; i < CRT_QUOTA_COUNT; i++)
ctx->cc_quotas.enabled[i] = false;

return DER_SUCCESS;
}

int
Expand Down