On Fri, Sep 01, 2023 at 08:02:30PM +0200, mwilck@xxxxxxxx wrote: > From: Martin Wilck <mwilck@xxxxxxxx> > > This way we can test the parsing of input lines from the bindings > file more easily. > Reviewed-by: Benjamin Marzinski <bmarzins@xxxxxxxxxx> > Signed-off-by: Martin Wilck <mwilck@xxxxxxxx> > --- > libmultipath/alias.c | 58 ++++++++++++++++++++++++++++++-------------- > 1 file changed, 40 insertions(+), 18 deletions(-) > > diff --git a/libmultipath/alias.c b/libmultipath/alias.c > index 9ca5da8..2f9bc82 100644 > --- a/libmultipath/alias.c > +++ b/libmultipath/alias.c > @@ -647,6 +647,43 @@ void cleanup_bindings(void) > free_bindings(&global_bindings); > } > > +enum { > + READ_BINDING_OK, > + READ_BINDING_SKIP, > +}; > + > +static int read_binding(char *line, unsigned int linenr, char **alias, > + char **wwid) { > + char *c, *saveptr; > + > + c = strpbrk(line, "#\n\r"); > + if (c) > + *c = '\0'; > + > + *alias = strtok_r(line, " \t", &saveptr); > + if (!*alias) /* blank line */ > + return READ_BINDING_SKIP; > + > + *wwid = strtok_r(NULL, " \t", &saveptr); > + if (!*wwid) { > + condlog(1, "invalid line %u in bindings file, missing WWID", > + linenr); > + return READ_BINDING_SKIP; > + } > + if (strlen(*wwid) > WWID_SIZE - 1) { > + condlog(3, > + "Ignoring too large wwid at %u in bindings file", > + linenr); > + return READ_BINDING_SKIP; > + } > + c = strtok_r(NULL, " \t", &saveptr); > + if (c) > + /* This is non-fatal */ > + condlog(1, "invalid line %d in bindings file, extra args \"%s\"", > + linenr, c); > + return READ_BINDING_OK; > +} > + > static int _check_bindings_file(const struct config *conf, FILE *file, > Bindings *bindings) > { > @@ -658,27 +695,12 @@ static int _check_bindings_file(const struct config *conf, FILE *file, > > pthread_cleanup_push(cleanup_free_ptr, &line); > while ((n = getline(&line, &line_len, file)) >= 0) { > - char *c, *alias, *wwid, *saveptr; > + char *alias, *wwid; > const char *mpe_wwid; > > - linenr++; > - c = strpbrk(line, "#\n\r"); > - if (c) > - *c = '\0'; > - alias = strtok_r(line, " \t", &saveptr); > - if (!alias) /* blank line */ > + if (read_binding(line, ++linenr, &alias, &wwid) > + == READ_BINDING_SKIP) > continue; > - wwid = strtok_r(NULL, " \t", &saveptr); > - if (!wwid) { > - condlog(1, "invalid line %d in bindings file, missing WWID", > - linenr); > - continue; > - } > - c = strtok_r(NULL, " \t", &saveptr); > - if (c) > - /* This is non-fatal */ > - condlog(1, "invalid line %d in bindings file, extra args \"%s\"", > - linenr, c); > > mpe_wwid = get_mpe_wwid(conf->mptable, alias); > if (mpe_wwid && strcmp(mpe_wwid, wwid)) { > -- > 2.41.0 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/dm-devel