Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: Anand Jain <anand.jain@oracle.com>, linux-btrfs@vger.kernel.org
Cc: dsterba@suse.com
Subject: Re: [PATCH v8 1/3] btrfs: add btrfs_strmatch helper
Date: Wed, 21 Oct 2020 10:44:47 -0400	[thread overview]
Message-ID: <e599667f-af00-7cbf-65c8-fb1151e66411@toxicpanda.com> (raw)
In-Reply-To: <7418ae34e5a4cc7d110eed756d9e37c5630ec568.1602756068.git.anand.jain@oracle.com>

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

  reply	other threads:[~2020-10-21 14:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-20 14:02 [PATCH v8 0/3] readmirror feature (read_policy sysfs and Anand Jain
2020-10-20 14:02 ` [PATCH v8 1/3] btrfs: add btrfs_strmatch helper Anand Jain
2020-10-21 14:44   ` Josef Bacik [this message]
2020-10-22  7:40     ` Anand Jain
2020-10-20 14:02 ` [PATCH v8 2/3] btrfs: create read policy framework Anand Jain
2020-10-21 14:46   ` Josef Bacik
2020-10-20 14:02 ` [PATCH v8 3/3] btrfs: create read policy sysfs attribute, pid Anand Jain
2020-10-21 14:42   ` Josef Bacik
2020-10-22  7:40     ` Anand Jain
2020-10-20 14:22 ` [PATCH v8 0/3] readmirror feature (read_policy sysfs and in-memory only approach) 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=e599667f-af00-7cbf-65c8-fb1151e66411@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=anand.jain@oracle.com \
    --cc=dsterba@suse.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