From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Aring Date: Fri, 26 Jun 2020 12:44:43 -0400 Subject: [Cluster-devel] [PATCHv2 dlm-tool 1/4] dlm_controld: add support for unsigned int values In-Reply-To: <20200626164446.114220-1-aahringo@redhat.com> References: <20200626164446.114220-1-aahringo@redhat.com> Message-ID: <20200626164446.114220-2-aahringo@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This patch adds support for setting a unsigned integer value. --- dlm_controld/config.c | 25 +++++++++++++++++++++++++ dlm_controld/dlm_daemon.h | 5 +++++ dlm_controld/main.c | 3 +++ 3 files changed, 33 insertions(+) diff --git a/dlm_controld/config.c b/dlm_controld/config.c index 3ba8a53b..ec269168 100644 --- a/dlm_controld/config.c +++ b/dlm_controld/config.c @@ -156,6 +156,19 @@ static void get_val_int(char *line, int *val_out) *val_out = atoi(val); } +static void get_val_uint(char *line, unsigned int *val_out) +{ + char key[MAX_LINE]; + char val[MAX_LINE]; + int rv; + + rv = sscanf(line, "%[^=]=%s", key, val); + if (rv != 2) + return; + + *val_out = strtoul(val, NULL, 0); +} + static void get_val_str(char *line, char *val_out) { char key[MAX_LINE]; @@ -171,6 +184,7 @@ static void get_val_str(char *line, char *val_out) void set_opt_file(int update) { + unsigned int uval = 0; struct dlm_option *o; FILE *file; char line[MAX_LINE]; @@ -238,6 +252,17 @@ void set_opt_file(int update) log_debug("config file %s = %d cli_set %d use %d", o->name, o->file_int, o->cli_set, o->use_int); + } else if (o->req_arg == req_arg_uint) { + get_val_uint(line, &uval); + + o->file_uint = uval; + + if (!o->cli_set) + o->use_uint = o->file_uint; + + log_debug("config file %s = %u cli_set %d use %u", + o->name, o->file_uint, o->cli_set, o->use_uint); + } else if (o->req_arg == req_arg_bool) { get_val_int(line, &val); diff --git a/dlm_controld/dlm_daemon.h b/dlm_controld/dlm_daemon.h index 5b9a52da..3dad0bf1 100644 --- a/dlm_controld/dlm_daemon.h +++ b/dlm_controld/dlm_daemon.h @@ -86,6 +86,7 @@ enum { req_arg_bool = 1, req_arg_int = 2, req_arg_str = 3, + req_arg_uint = 4, }; enum { @@ -125,6 +126,7 @@ struct dlm_option { int use_int; char *use_str; + unsigned int use_uint; int default_int; const char *default_str; @@ -132,15 +134,18 @@ struct dlm_option { int cli_set; int cli_int; char *cli_str; + unsigned int cli_uint; int file_set; int file_int; char *file_str; + unsigned int file_uint; }; EXTERN struct dlm_option dlm_options[dlm_options_max]; #define opt(x) dlm_options[x].use_int #define opts(x) dlm_options[x].use_str +#define optu(x) dlm_options[x].use_uint /* DLM_LOCKSPACE_LEN: maximum lockspace name length, from linux/dlmconstants.h. diff --git a/dlm_controld/main.c b/dlm_controld/main.c index 8be6a4bc..b4f4ffb8 100644 --- a/dlm_controld/main.c +++ b/dlm_controld/main.c @@ -1972,6 +1972,9 @@ static void set_opt_cli(int argc, char **argv) } else if (o->req_arg == req_arg_bool) { o->cli_int = atoi(arg_str) ? 1 : 0; o->use_int = o->cli_int; + } else if (o->req_arg == req_arg_uint) { + o->cli_uint = strtoul(arg_str, NULL, 0); + o->use_uint = o->cli_uint; } } -- 2.26.2