linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "André Almeida" <andrealmeid@collabora.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Theodore Ts'o <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>,
	kernel@collabora.com, Daniel Rosenberg <drosen@google.com>,
	linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
	krisman@collabora.com
Subject: Re: [PATCH 1/3] fs/dcache: Add d_clear_dir_neg_dentries()
Date: Tue, 30 Mar 2021 09:54:01 -0300	[thread overview]
Message-ID: <8ea3ba8e-2699-8786-5ca3-33ee3c70961b@collabora.com> (raw)
In-Reply-To: <YGKDfo1vZfFXwG/v@gmail.com>

Hi Eric,

Às 22:48 de 29/03/21, Eric Biggers escreveu:
> On Sun, Mar 28, 2021 at 11:43:54AM -0300, André Almeida wrote:
>> For directories with negative dentries that are becoming case-insensitive
>> dirs, we need to remove all those negative dentries, otherwise they will
>> become dangling dentries. During the creation of a new file, if a d_hash
>> collision happens and the names match in a case-insensitive way, the name
>> of the file will be the name defined at the negative dentry, that may be
>> different from the specified by the user. To prevent this from
>> happening, we need to remove all dentries in a directory. Given that the
>> directory must be empty before we call this function we are sure that
>> all dentries there will be negative.
>>
>> Create a function to remove all negative dentries from a directory, to
>> be used as explained above by filesystems that support case-insensitive
>> lookups.
>>
>> Signed-off-by: André Almeida <andrealmeid@collabora.com>
>> ---
>>   fs/dcache.c            | 27 +++++++++++++++++++++++++++
>>   include/linux/dcache.h |  1 +
>>   2 files changed, 28 insertions(+)
>>
>> diff --git a/fs/dcache.c b/fs/dcache.c
>> index 7d24ff7eb206..fafb3016d6fd 100644
>> --- a/fs/dcache.c
>> +++ b/fs/dcache.c
>> @@ -1723,6 +1723,33 @@ void d_invalidate(struct dentry *dentry)
>>   }
>>   EXPORT_SYMBOL(d_invalidate);
>>   
>> +/**
>> + * d_clear_dir_neg_dentries - Remove negative dentries in an inode
>> + * @dir: Directory to clear negative dentries
>> + *
>> + * For directories with negative dentries that are becoming case-insensitive
>> + * dirs, we need to remove all those negative dentries, otherwise they will
>> + * become dangling dentries. During the creation of a new file, if a d_hash
>> + * collision happens and the names match in a case-insensitive, the name of
>> + * the file will be the name defined at the negative dentry, that can be
>> + * different from the specified by the user. To prevent this from happening, we
>> + * need to remove all dentries in a directory. Given that the directory must be
>> + * empty before we call this function we are sure that all dentries there will
>> + * be negative.
>> + */
>> +void d_clear_dir_neg_dentries(struct inode *dir)
>> +{
>> +	struct dentry *alias, *dentry;
>> +
>> +	hlist_for_each_entry(alias, &dir->i_dentry, d_u.d_alias) {
>> +		list_for_each_entry(dentry, &alias->d_subdirs, d_child) {
>> +			d_drop(dentry);
>> +			dput(dentry);
>> +		}
>> +	}
>> +}
>> +EXPORT_SYMBOL(d_clear_dir_neg_dentries);
> 
> As Al already pointed out, this doesn't work as intended, for a number of
> different reasons.
> 
> Did you consider just using shrink_dcache_parent()?  That already does what you
> are trying to do here, I think.

When I wrote this patch, I didn't know it, but after Al Viro comments I 
get back to the code and found it, and it seems do do what I intend 
indeed, and my test is happy as well.

> 
> The harder part (which I don't think you've considered) is how to ensure that
> all negative dentries really get invalidated even if there are lookups of them
> happening concurrently.  Concurrent lookups can take temporary references to the
> negative dentries, preventing them from being invalidated.
> 

I didn't consider that, thanks for the feedback. So this means that 
those lookups will increase the refcount of the dentry, and it will only 
get really invalidated when refcount reaches 0? Or do would I need to 
call d_invalidate() again, until I succeed?

> - Eric
> 

  reply	other threads:[~2021-03-30 12:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-28 14:43 [PATCH 0/3] fs: Fix dangling dentries on casefold directories André Almeida
2021-03-28 14:43 ` [PATCH 1/3] fs/dcache: Add d_clear_dir_neg_dentries() André Almeida
2021-03-28 15:07   ` Matthew Wilcox
2021-03-28 15:49     ` André Almeida
2021-03-28 17:39   ` Al Viro
2021-03-30  1:48   ` Eric Biggers
2021-03-30 12:54     ` André Almeida [this message]
2021-03-28 14:43 ` [PATCH 2/3] ext4: Prevent dangling dentries on casefold directories André Almeida
2021-03-28 14:43 ` [PATCH 3/3] f2fs: " André Almeida

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=8ea3ba8e-2699-8786-5ca3-33ee3c70961b@collabora.com \
    --to=andrealmeid@collabora.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=chao@kernel.org \
    --cc=drosen@google.com \
    --cc=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=kernel@collabora.com \
    --cc=krisman@collabora.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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).