Skip to content

Commit

Permalink
Fix Sampler Advertisement bugs
Browse files Browse the repository at this point in the history
The patch fixes the following bugs:
 - prdcr_listen_status when there are multiple prdcr_listen objects
 - 'ip' attribute name isn't recognized by ldmsd_communicator.py
 - Remove prdcr_listen when an error at prdcr_listen_add
  • Loading branch information
nichamon authored and tom95858 committed Nov 20, 2024
1 parent afd3a00 commit 3991226
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
1 change: 1 addition & 0 deletions ldms/python/ldmsd/ldmsd_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class LDMSD_Req_Attr(object):
'reconnect' : INTERVAL,
'size' : SIZE,
'IP' : IP,
'ip' : IP,
'TERMINATING': LAST
}

Expand Down
59 changes: 45 additions & 14 deletions ldms/src/ldmsd/ldmsd_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -8505,6 +8505,19 @@ static int __cidr2addr6(const char *cdir_str, struct ldms_addr *addr, int *prefi
/* Aggregator */
/* The implementation is in ldmsd_prdcr.c */
extern int prdcr_ref_cmp(void *a, const void *b);

static void prdcr_listen___del(ldmsd_cfgobj_t obj)
{
ldmsd_prdcr_listen_t pl = (ldmsd_prdcr_listen_t)obj;
if (pl->cidr_str)
free((char*)pl->cidr_str);
if (pl->hostname_regex_s) {
regfree(&pl->regex);
free((char*)pl->hostname_regex_s);
}
ldmsd_cfgobj___del(obj);
}

static int prdcr_listen_add_handler(ldmsd_req_ctxt_t reqc)
{
int rc = 0;
Expand All @@ -8514,6 +8527,7 @@ static int prdcr_listen_add_handler(ldmsd_req_ctxt_t reqc)
char *disabled_start;
char *attr_name;
ldmsd_prdcr_listen_t pl;
extern struct rbt *cfgobj_trees[];

name = regex_str = cidr_str = disabled_start = NULL;

Expand All @@ -8528,9 +8542,25 @@ static int prdcr_listen_add_handler(ldmsd_req_ctxt_t reqc)

pl = (ldmsd_prdcr_listen_t)
ldmsd_cfgobj_new_with_auth(name, LDMSD_CFGOBJ_PRDCR_LISTEN,
sizeof(*pl), NULL, 0, 0, 0);
if (!pl)
goto enomem;
sizeof(*pl), prdcr_listen___del,
0, 0, 0);
if (!pl) {
if (errno == ENOMEM) {
goto enomem;
} else if (errno == EEXIST) {
reqc->errcode = EEXIST;
reqc->line_off = snprintf(reqc->line_buf, reqc->line_len,
"The prdcr_listen '%s' already exists.\n",
name);
goto send_reply;
} else {
reqc->errcode = errno;
reqc->line_off = snprintf(reqc->line_buf, reqc->line_len,
"Error %d: Failed to add prdcr_listen '%s'.\n",
reqc->errcode, name);
goto err;
}
}
pl->auto_start = 1;
if (disabled_start) {
if ((0 == strcmp(disabled_start, "1")) ||
Expand All @@ -8542,7 +8572,6 @@ static int prdcr_listen_add_handler(ldmsd_req_ctxt_t reqc)
if (regex_str) {
pl->hostname_regex_s = strdup(regex_str);
if (!pl->hostname_regex_s) {
ldmsd_cfgobj_put(&pl->obj);
goto enomem;
}

Expand All @@ -8552,28 +8581,22 @@ static int prdcr_listen_add_handler(ldmsd_req_ctxt_t reqc)
reqc->line_off = snprintf(reqc->line_buf, reqc->line_len,
"The regular expression string "
"'%s' is invalid.", regex_str);
ldmsd_cfgobj_put(&pl->obj);
goto send_reply;
goto err;
}
}

if (cidr_str) {
pl->cidr_str = strdup(cidr_str);
if (!pl->cidr_str) {
reqc->errcode = ENOMEM;
reqc->line_off = snprintf(reqc->line_buf, reqc->line_len,
"Memory allocation failure.");
ldmsd_cfgobj_put(&pl->obj);
goto send_reply;
goto enomem;
}
rc = __cidr2addr6(cidr_str, &pl->net_addr, &pl->prefix_len);
if (rc) {
reqc->errcode = EINVAL;
reqc->line_off = snprintf(reqc->line_buf, reqc->line_len,
"The given CIDR string '%s' "
"is invalid.", cidr_str);
ldmsd_cfgobj_put(&pl->obj);
goto send_reply;
goto err;
}
}

Expand All @@ -8591,11 +8614,18 @@ static int prdcr_listen_add_handler(ldmsd_req_ctxt_t reqc)
reqc->errcode = ENOMEM;
(void)snprintf(reqc->line_buf, reqc->line_len,
"Memory allocation failed.");
goto send_reply;
goto err;
einval:
reqc->errcode = EINVAL;
(void) snprintf(reqc->line_buf, reqc->line_len,
"The attribute '%s' is required.", attr_name);
goto err;
err:
ldmsd_cfg_lock(LDMSD_CFGOBJ_PRDCR_LISTEN);
rbt_del(cfgobj_trees[LDMSD_CFGOBJ_PRDCR_LISTEN], &pl->obj.rbn);
ldmsd_cfg_unlock(LDMSD_CFGOBJ_PRDCR_LISTEN);
ldmsd_cfgobj_unlock(&pl->obj);
ldmsd_cfgobj_put(&pl->obj);
goto send_reply;
}

Expand Down Expand Up @@ -8805,6 +8835,7 @@ static int prdcr_listen_status_handler(ldmsd_req_ctxt_t reqc)
);
if (rc)
goto err;
prdcr_cnt = 0;
RBT_FOREACH(rbn, &pl->prdcr_tree) {
pref = container_of(rbn, struct ldmsd_prdcr_ref, rbn);
if (prdcr_cnt) {
Expand Down

0 comments on commit 3991226

Please sign in to comment.