Skip to content

Commit

Permalink
Add the default_credits command
Browse files Browse the repository at this point in the history
The `default_credits` command is designed for integration into
configuration files, serving as a replacement of the `-C` command-line
option.

Usage:
   default_credits credits=<INTEGER>
  • Loading branch information
nichamon authored and tom95858 committed Mar 5, 2024
1 parent 8af9586 commit 62b0d0b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ldms/src/ldmsd/ldmsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,11 @@ int main(int argc, char *argv[])
"The option `-P` is obsolete. "
"Please specify `worker_threads num=<NUMBER OF THREADS> in a configuration file.\n");
cleanup(EINVAL, "Received an obsolete command-line option");
case 'C':
ovis_log(NULL, OVIS_LCRIT,
"The option `-C` is obsolete. "
"Please specify `default_credits credits=<INTEGER> in a configuration file.\n");
cleanup(EINVAL, "Received an obsolete command-line option");
default:
ret = ldmsd_process_cmd_line_arg(op, optarg);
if (ret) {
Expand Down
29 changes: 29 additions & 0 deletions ldms/src/ldmsd/ldmsd_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ static int log_file_handler(ldmsd_req_ctxt_t reqc);
static int publish_kernel_handler(ldmsd_req_ctxt_t reqc);
static int daemon_name_set_handler(ldmsd_req_ctxt_t reqc);
static int worker_threads_set_handler(ldmsd_req_ctxt_t reqc);
static int default_credits_set_handler(ldmsd_req_ctxt_t reqc);

/* executable for all */
#define XALL 0111
Expand Down Expand Up @@ -675,6 +676,9 @@ static struct request_handler_entry request_handler[] = {
[LDMSD_WORKER_THR_SET_REQ] = {
LDMSD_WORKER_THR_SET_REQ, worker_threads_set_handler, XUG
},
[LDMSD_DEFAULT_CREDITS_REQ] = {
LDMSD_DEFAULT_CREDITS_REQ, default_credits_set_handler, XUG
},
};

int is_req_id_priority(enum ldmsd_request req_id)
Expand All @@ -692,6 +696,7 @@ int is_req_id_priority(enum ldmsd_request req_id)
case LDMSD_PUBLISH_KERNEL_REQ:
case LDMSD_DAEMON_NAME_SET_REQ:
case LDMSD_WORKER_THR_SET_REQ:
case LDMSD_DEFAULT_CREDITS_REQ:
return 1;
default:
return 0;
Expand Down Expand Up @@ -9238,3 +9243,27 @@ static int worker_threads_set_handler(ldmsd_req_ctxt_t reqc)
free(value);
return rc;
}

static int default_credits_set_handler(ldmsd_req_ctxt_t reqc)
{
int rc = 0;
char *value = NULL;

value = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_CREDITS);
if (!value) {
reqc->errcode = EINVAL;
reqc->line_off = snprintf(reqc->line_buf, reqc->line_len,
"The attribute 'credits' is missing.");
goto send_reply;
}
reqc->errcode = ldmsd_process_cmd_line_arg('C', value);
if (reqc->errcode) {
reqc->line_off = snprintf(reqc->line_buf, reqc->line_len,
"Failed to process the 'default_credits' command");
goto send_reply;
}
send_reply:
ldmsd_send_req_response(reqc, reqc->line_buf);
free(value);
return rc;
}
1 change: 1 addition & 0 deletions ldms/src/ldmsd/ldmsd_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ enum ldmsd_request {
LDMSD_PUBLISH_KERNEL_REQ,
LDMSD_DAEMON_NAME_SET_REQ,
LDMSD_WORKER_THR_SET_REQ,
LDMSD_DEFAULT_CREDITS_REQ,

/* failover requests by user */
LDMSD_FAILOVER_CONFIG_REQ = 0x700, /* "failover_config" user command */
Expand Down
1 change: 1 addition & 0 deletions ldms/src/ldmsd/ldmsd_request_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const struct req_str_id req_str_id_table[] = {
{ "daemon_name", LDMSD_DAEMON_NAME_SET_REQ },
{ "daemon_status", LDMSD_DAEMON_STATUS_REQ },
{ "default_auth", LDMSD_DEFAULT_AUTH_REQ },
{ "default_credits", LDMSD_DEFAULT_CREDITS_REQ },
{ "dump_cfg", LDMSD_DUMP_CFG_REQ },
{ "env", LDMSD_ENV_REQ },
{ "exit", LDMSD_EXIT_DAEMON_REQ },
Expand Down

0 comments on commit 62b0d0b

Please sign in to comment.