Skip to content

Commit

Permalink
redfishpower: support setwaituntildelay config
Browse files Browse the repository at this point in the history
Problem: The wait until on/off retry delay in redfishpower is currently hard
coded to 1 second.  On some slow systems, it has been observed that
on/off can take upwards of a minute.  On that hardware, a 1 second
retry delay can lead to an excess amount of traffic on the network.

Support a prompt command that will allow change of the wait until delay
time.  Update redfishpower test helper as well.
  • Loading branch information
chu11 committed Jan 22, 2024
1 parent 6be3eb5 commit ba77a12
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
35 changes: 31 additions & 4 deletions redfishpower/redfishpower.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <sys/select.h>
#include <limits.h>
#include <sys/time.h>
#include <limits.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>
Expand Down Expand Up @@ -69,11 +70,13 @@ static char *cyclepostdata = NULL;

/* in usec
*
* wait delay of 1 second may seem long, but testing shows
* wait ranges from a few seconds to 20 seconds
* wait delay of 1 second may seem long, but testing shows wait ranges
* from a few seconds to almost a minute. Device files should adjust
* to longer times for really bad systems.
*/
#define WAIT_UNTIL_DELAY 1000000
#define WAIT_UNTIL_DELAY_DEFAULT 1000000

#define USEC_IN_SEC 1000000
#define MS_IN_SEC 1000

struct powermsg {
Expand Down Expand Up @@ -126,6 +129,10 @@ static struct option longopts[] = {
};

static time_t cmd_timeout = CMD_TIMEOUT_DEFAULT;
/* typically is of type suseconds_t, but has questionable portability,
* so use 'long int' instead
*/
static long int wait_until_delay = WAIT_UNTIL_DELAY_DEFAULT;

void help(void)
{
Expand All @@ -137,6 +144,7 @@ void help(void)
printf(" setoffpath url [data]\n");
printf(" setcyclepath url [data]\n");
printf(" settimeout seconds\n");
printf(" setwaituntildelay seconds\n");
printf(" stat [nodes]\n");
printf(" on [nodes]\n");
printf(" off [nodes]\n");
Expand Down Expand Up @@ -511,7 +519,7 @@ static void on_off_process(List delayedcmds, struct powermsg *pm)
statpath,
NULL,
&pm->start,
WAIT_UNTIL_DELAY);
wait_until_delay);
Curl_easy_setopt((nextpm->eh, CURLOPT_HTTPGET, 1));
nextpm->wait_until_on_off = 1;
if (!list_append(delayedcmds, nextpm))
Expand Down Expand Up @@ -622,6 +630,23 @@ static void settimeout(char **av)
}
}

static void setwaituntildelay(char **av)
{
if (av[0]) {
char *endptr;
long tmp;

errno = 0;
tmp = strtol (av[0], &endptr, 10);
if (errno
|| endptr[0] != '\0'
|| tmp <= 0
|| (tmp > (LONG_MAX / USEC_IN_SEC)))
printf("invalid wait until delay specified\n");
wait_until_delay = tmp * USEC_IN_SEC;
}
}

static void process_cmd(List activecmds, CURLM *mh, char **av, int *exitflag)
{
if (av[0] != NULL) {
Expand All @@ -643,6 +668,8 @@ static void process_cmd(List activecmds, CURLM *mh, char **av, int *exitflag)
setpowerpath(av + 1, &cyclepath, &cyclepostdata);
else if (strcmp(av[0], "settimeout") == 0)
settimeout(av + 1);
else if (strcmp(av[0], "setwaituntildelay") == 0)
setwaituntildelay(av + 1);
else if (strcmp(av[0], "stat") == 0)
stat_cmd(activecmds, mh, av + 1);
else if (strcmp(av[0], "on") == 0)
Expand Down
3 changes: 2 additions & 1 deletion test/redfishpower.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ _prompt_loop(void)
|| !strcmp(buf, "setonpath")
|| !strcmp(buf, "setoffpath")
|| !strcmp(buf, "setcyclepath")
|| !strcmp(buf, "settimeout")) {
|| !strcmp(buf, "settimeout")
|| !strcmp(buf, "setwaituntildelay")) {
/* do nothing with config, just accept */
;
} else if (!strcmp(buf, "stat")) {
Expand Down

0 comments on commit ba77a12

Please sign in to comment.