Message ID | 7418ae34e5a4cc7d110eed756d9e37c5630ec568.1602756068.git.anand.jain@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | readmirror feature (read_policy sysfs and | expand |
On 10/20/20 10:02 AM, Anand Jain wrote: > Add a generic helper to match the golden-string in the given-string, > and ignore the leading and trailing whitespaces if any. > > Signed-off-by: Anand Jain <anand.jain@oracle.com> > Suggested-by: David Sterba <dsterba@suse.com> > --- > v5: born > > fs/btrfs/sysfs.c | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c > index 8424f5d0e5ed..eb0b2bfcce67 100644 > --- a/fs/btrfs/sysfs.c > +++ b/fs/btrfs/sysfs.c > @@ -863,6 +863,29 @@ static ssize_t btrfs_generation_show(struct kobject *kobj, > } > BTRFS_ATTR(, generation, btrfs_generation_show); > > +/* > + * Match the %golden in the %given. Ignore the leading and trailing whitespaces > + * if any. > + */ > +static int btrfs_strmatch(const char *given, const char *golden) > +{ > + size_t len = strlen(golden); > + char *stripped; > + > + /* strip leading whitespace */ > + stripped = skip_spaces(given); > + > + if (strncmp(stripped, golden, len) == 0) { > + /* strip trailing whitespace */ > + if (strlen(skip_spaces(stripped + len))) > + return -EINVAL; if ((strncmp(stripped, golden, len) == 0) && (strlen(skip_spaces(stripped + len)) == 0)) return 0; Thanks, Josef
On 21/10/20 10:44 pm, Josef Bacik wrote: > On 10/20/20 10:02 AM, Anand Jain wrote: >> Add a generic helper to match the golden-string in the given-string, >> and ignore the leading and trailing whitespaces if any. >> >> Signed-off-by: Anand Jain <anand.jain@oracle.com> >> Suggested-by: David Sterba <dsterba@suse.com> >> --- >> v5: born >> >> fs/btrfs/sysfs.c | 23 +++++++++++++++++++++++ >> 1 file changed, 23 insertions(+) >> >> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c >> index 8424f5d0e5ed..eb0b2bfcce67 100644 >> --- a/fs/btrfs/sysfs.c >> +++ b/fs/btrfs/sysfs.c >> @@ -863,6 +863,29 @@ static ssize_t btrfs_generation_show(struct >> kobject *kobj, >> } >> BTRFS_ATTR(, generation, btrfs_generation_show); >> +/* >> + * Match the %golden in the %given. Ignore the leading and trailing >> whitespaces >> + * if any. >> + */ >> +static int btrfs_strmatch(const char *given, const char *golden) >> +{ >> + size_t len = strlen(golden); >> + char *stripped; >> + >> + /* strip leading whitespace */ >> + stripped = skip_spaces(given); >> + >> + if (strncmp(stripped, golden, len) == 0) { >> + /* strip trailing whitespace */ >> + if (strlen(skip_spaces(stripped + len))) >> + return -EINVAL; > > if ((strncmp(stripped, golden, len) == 0) && > (strlen(skip_spaces(stripped + len)) == 0)) > return 0; fixed in v9 as well. Thanks, Anand > > Thanks, > > Josef
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 8424f5d0e5ed..eb0b2bfcce67 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -863,6 +863,29 @@ static ssize_t btrfs_generation_show(struct kobject *kobj, } BTRFS_ATTR(, generation, btrfs_generation_show); +/* + * Match the %golden in the %given. Ignore the leading and trailing whitespaces + * if any. + */ +static int btrfs_strmatch(const char *given, const char *golden) +{ + size_t len = strlen(golden); + char *stripped; + + /* strip leading whitespace */ + stripped = skip_spaces(given); + + if (strncmp(stripped, golden, len) == 0) { + /* strip trailing whitespace */ + if (strlen(skip_spaces(stripped + len))) + return -EINVAL; + + return 0; + } + + return -EINVAL; +} + static const struct attribute *btrfs_attrs[] = { BTRFS_ATTR_PTR(, label), BTRFS_ATTR_PTR(, nodesize),
Add a generic helper to match the golden-string in the given-string, and ignore the leading and trailing whitespaces if any. Signed-off-by: Anand Jain <anand.jain@oracle.com> Suggested-by: David Sterba <dsterba@suse.com> --- v5: born fs/btrfs/sysfs.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)