linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Anand Jain <anand.jain@oracle.com>
Cc: linux-btrfs@vger.kernel.org, josef@toxicpanda.com, dsterba@suse.com
Subject: Re: [PATCH v9 1/3] btrfs: add btrfs_strmatch helper
Date: Mon, 26 Oct 2020 18:52:28 +0100	[thread overview]
Message-ID: <20201026175228.GS6756@twin.jikos.cz> (raw)
In-Reply-To: <75264e50d49f3c68cc14dc87510c8f3767390dcf.1603347462.git.anand.jain@oracle.com>

On Thu, Oct 22, 2020 at 03:43:35PM +0800, 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>
> ---
> v9: use Josef suggested C coding style, using single if statement.
> v5: born
> 
>  fs/btrfs/sysfs.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 8424f5d0e5ed..5ea262d289c6 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -863,6 +863,26 @@ 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 */

This is confusing as it's not stripping the space but merely skipping
it.  The arguments are not changed so you also don't need the separate
variable and just update 'given'.

> +	stripped = skip_spaces(given);
> +
> +	/* strip trailing whitespace */
> +	if ((strncmp(stripped, golden, len) == 0) &&
> +	    (strlen(skip_spaces(stripped + len)) == 0))
> +		return 0;

This a bit hard to read but ok, essentially we can do the string
comparison in a loop or use the library functions.

> +
> +	return -EINVAL;

This does not make sense as it's an error code while the function is a
predicate, without error states.

> +}
> +
>  static const struct attribute *btrfs_attrs[] = {
>  	BTRFS_ATTR_PTR(, label),
>  	BTRFS_ATTR_PTR(, nodesize),
> -- 
> 2.25.1

  parent reply	other threads:[~2020-10-26 17:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-22  7:43 [PATCH v9 0/3] readmirror feature (read_policy sysfs and in-memory only approach) Anand Jain
2020-10-22  7:43 ` [PATCH v9 1/3] btrfs: add btrfs_strmatch helper Anand Jain
2020-10-23 11:12   ` Christoph Hellwig
2020-10-27 13:25     ` Anand Jain
2020-10-26 17:52   ` David Sterba [this message]
2020-10-27 13:19     ` Anand Jain
2020-10-27 18:00       ` David Sterba
2020-10-22  7:43 ` [PATCH v9 2/3] btrfs: create read policy framework Anand Jain
2020-10-22  7:43 ` [PATCH v9 3/3] btrfs: create read policy sysfs attribute, pid Anand Jain
2020-10-26 17:57   ` David Sterba
2020-10-28 12:37     ` Anand Jain
2020-10-23 17:04 ` [PATCH v9 0/3] readmirror feature (read_policy sysfs and in-memory only approach) David Sterba
2020-10-27  1:52   ` Anand Jain
2020-10-27 18:02     ` David Sterba
2020-10-28 12:06       ` Anand Jain
2020-10-26 14:01 ` Josef Bacik
2020-10-28  4:25 ` [PATCH v10 " Anand Jain
2020-10-28  4:25   ` [PATCH v10 1/3] btrfs: add btrfs_strmatch helper Anand Jain
2020-10-28  4:25   ` [PATCH v10 2/3] btrfs: create read policy framework Anand Jain
2020-10-28  4:25   ` [PATCH v10 3/3] btrfs: create read policy sysfs attribute, pid Anand Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201026175228.GS6756@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=anand.jain@oracle.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).