ecryptfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tiezhu Yang <yangtiezhu@loongson.cn>
To: Eric Biggers <ebiggers@kernel.org>, Matthew Wilcox <willy@infradead.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	"Theodore Y. Ts'o" <tytso@mit.edu>,
	Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <yuchao0@huawei.com>,
	Tyler Hicks <tyhicks@canonical.com>,
	linux-fsdevel@vger.kernel.org, ecryptfs@vger.kernel.org,
	linux-fscrypt@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5] fs: introduce is_dot_or_dotdot helper for cleanup
Date: Wed, 11 Dec 2019 11:59:40 +0800	[thread overview]
Message-ID: <febbd7eb-5e53-6e7c-582d-5b224e441e37@loongson.cn> (raw)
In-Reply-To: <20191211024858.GB732@sol.localdomain>

On 12/11/2019 10:48 AM, Eric Biggers wrote:
> On Wed, Dec 11, 2019 at 10:20:01AM +0800, Tiezhu Yang wrote:
>> diff --git a/include/linux/namei.h b/include/linux/namei.h
>> index 7fe7b87..0fd9315 100644
>> --- a/include/linux/namei.h
>> +++ b/include/linux/namei.h
>> @@ -92,4 +92,14 @@ retry_estale(const long error, const unsigned int flags)
>>   	return error == -ESTALE && !(flags & LOOKUP_REVAL);
>>   }
>>   
>> +static inline bool is_dot_or_dotdot(const unsigned char *name, size_t len)
>> +{
>> +	if (unlikely(name[0] == '.')) {
>> +		if (len == 1 || (len == 2 && name[1] == '.'))
>> +			return true;
>> +	}
>> +
>> +	return false;
>> +}
>> +
>>   #endif /* _LINUX_NAMEI_H */
> I had suggested adding a len >= 1 check to handle the empty name case correctly.
> What I had in mind was
>
> static inline bool is_dot_or_dotdot(const unsigned char *name, size_t len)
> {
> 	if (len >= 1 && unlikely(name[0] == '.')) {
> 		if (len < 2 || (len == 2 && name[1] == '.'))
> 			return true;
> 	}
>
> 	return false;
> }
>
> As is, you're proposing that it always dereference the first byte even when
> len=0, which seems like a bad idea for a shared helper function.  Did you check
> whether it's okay for all the existing callers?  fscrypt_fname_disk_to_usr() is
> called from 6 places, did you check all of them?
>
> How about keeping the existing optimized code for the hot path in fs/namei.c
> (i.e. not using the helper function), while having the helper function do the
> extra check to handle len=0 correctly?

Hi Eric,

Thank you for reminding me.  How about using the following helper for
all callers?

static inline bool is_dot_or_dotdot(const unsigned char *name, size_t len)
{
         if (len == 1 && name[0] == '.')
                 return true;

         if (len == 2 && name[0] == '.' && name[1] == '.')
                 return true;

         return false;
}

Hi Matthew,

How do you think? I think the performance influence is very small
due to is_dot_or_dotdot() is a such short static inline function.

Thanks,

Tiezhu Yang

>
> - Eric


  reply	other threads:[~2019-12-11  3:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-11  2:20 [PATCH v5] fs: introduce is_dot_or_dotdot helper for cleanup Tiezhu Yang
2019-12-11  2:48 ` Eric Biggers
2019-12-11  3:59   ` Tiezhu Yang [this message]
2019-12-11  4:47     ` Al Viro
2019-12-11  6:38       ` Tiezhu Yang
2019-12-11  7:17         ` Gao Xiang
2019-12-11 13:40           ` Matthew Wilcox
2019-12-11 14:41             ` Gao Xiang

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=febbd7eb-5e53-6e7c-582d-5b224e441e37@loongson.cn \
    --to=yangtiezhu@loongson.cn \
    --cc=ebiggers@kernel.org \
    --cc=ecryptfs@vger.kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tyhicks@canonical.com \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    --cc=yuchao0@huawei.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).