2023-11-23 19:53:53

by Al Viro

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH v6 0/9] Support negative dentries on case-insensitive ext4 and f2fs

On Thu, Nov 23, 2023 at 02:06:39PM -0500, Gabriel Krisman Bertazi wrote:

> > A paragraph above you've said that it's not constant over the entire
> > filesystem.
>
> The same ->d_op is used by every dentry in the filesystem if the superblock
> has the casefold bit enabled, regardless of whether a specific inode is
> casefolded or not. See generic_set_encrypted_ci_d_ops in my tree. It is
> called unconditionally by ext4_lookup and only checks the superblock:
>
> void generic_set_encrypted_ci_d_ops(struct dentry *dentry)
> {
> if (dentry->d_sb->s_encoding) {
> d_set_d_op(dentry, &generic_encrypted_ci_dentry_ops);
> return;
> }
> ...
>
> What I meant was that this used to be set once at sb->s_d_op, and
> propagated during dentry allocation. Therefore, the propagation to the
> alias would happen inside __d_alloc. Once we enabled fscrypt and
> casefold to work together, sb->s_d_op is NULL

Why? That's what I don't understand - if you really want it for
all dentries on that filesystem, that's what ->s_d_op is for.
If it is not, you have that problem, no matter which way you flip ->d_op
value.

> and we always set the same
> handler for every dentry during lookup.

Not every dentry goes through lookup - see upthread for details.

> > Look, it's really simple - any setup work of that sort done in ->lookup()
> > is either misplaced, or should be somehow transferred over to the alias
> > if one gets picked.
> >
> > As for d_obtain_alias()... AFAICS, it's far more limited in what information
> > it could access. It knows the inode, but it has no idea about the parent
> > to be.
>
> Since it has the inode, d_obtain_alias has the superblock. I think that's all
> we need for generic_set_encrypted_ci_d_ops.

Huh? If it really depends only upon the superblock, just set it in ->s_d_op
when you set the superblock up.

Again, whatever setup you do for dentry in ->lookup(), you either
* have a filesystem that never picks an existing directory alias
(e.g. doesn't allow open-by-fhandle or has a very unusual implementation
of related methods, like e.g. shmem), or
* have that setup misplaced, in part that applies to all dentries out
there (->s_d_op for universal ->d_op value, ->d_init() for uniform allocation
of objects hanging from ->d_fsdata and other things like that), or
* need to figure out how to transfer the result to alias (manually
after d_splice_alias(), if races do not matter or using a new method explicitly
for that), or
* lose that state for aliases.


2023-11-23 20:15:34

by Al Viro

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH v6 0/9] Support negative dentries on case-insensitive ext4 and f2fs

On Thu, Nov 23, 2023 at 07:53:27PM +0000, Al Viro wrote:

> Huh? If it really depends only upon the superblock, just set it in ->s_d_op
> when you set the superblock up.
>
> Again, whatever setup you do for dentry in ->lookup(), you either
> * have a filesystem that never picks an existing directory alias
> (e.g. doesn't allow open-by-fhandle or has a very unusual implementation
> of related methods, like e.g. shmem), or
> * have that setup misplaced, in part that applies to all dentries out
> there (->s_d_op for universal ->d_op value, ->d_init() for uniform allocation
> of objects hanging from ->d_fsdata and other things like that), or
> * need to figure out how to transfer the result to alias (manually
> after d_splice_alias(), if races do not matter or using a new method explicitly
> for that), or
> * lose that state for aliases.

Note, BTW, that fscrypt tries to be very special in its handling of that
stuff - see fscrypt_handle_d_move() thing and comments in front of its
definition. Then take a look at the place where it's called.

BTW, it looks like it's broken, since it discounts the possibility of splice
caused by lookup on no-key name. You get DCACHE_NOKEY_NAME removed unconditionally
there, no-key or not.

It's not impossible that the boilerplate around the fscrypt_has_permitted_context()
calls in fscrypt-enabled ->lookup() instances somehow prevents those, but if so,
it's not obvious from the causual look.

2023-11-24 15:20:59

by Gabriel Krisman Bertazi

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH v6 0/9] Support negative dentries on case-insensitive ext4 and f2fs

Al Viro <[email protected]> writes:

> On Thu, Nov 23, 2023 at 02:06:39PM -0500, Gabriel Krisman Bertazi wrote:
>
>> > A paragraph above you've said that it's not constant over the entire
>> > filesystem.
>>
>> The same ->d_op is used by every dentry in the filesystem if the superblock
>> has the casefold bit enabled, regardless of whether a specific inode is
>> casefolded or not. See generic_set_encrypted_ci_d_ops in my tree. It is
>> called unconditionally by ext4_lookup and only checks the superblock:
>>
>> void generic_set_encrypted_ci_d_ops(struct dentry *dentry)
>> {
>> if (dentry->d_sb->s_encoding) {
>> d_set_d_op(dentry, &generic_encrypted_ci_dentry_ops);
>> return;
>> }
>> ...
>>
>> What I meant was that this used to be set once at sb->s_d_op, and
>> propagated during dentry allocation. Therefore, the propagation to the
>> alias would happen inside __d_alloc. Once we enabled fscrypt and
>> casefold to work together, sb->s_d_op is NULL
>
> Why? That's what I don't understand - if you really want it for
> all dentries on that filesystem, that's what ->s_d_op is for.
> If it is not, you have that problem, no matter which way you flip ->d_op
> value.

I'm not sure why it changed. I'm guessing that, since it doesn't make
sense to set fscrypt_d_revalidate for every dentry in the
!case-insensitive case, they just kept the same behavior for
case-insensitive+fscrypt. This is what I get from looking at the git
history.

I will get a new series reverting to use ->s_d_op, folding the
dentry_cmp behavior you mentioned, and based on what you merge in your
branch.

>> and we always set the same
>> handler for every dentry during lookup.
>
> Not every dentry goes through lookup - see upthread for details.

Yes, I got that already. This should be "we always set the same handler
for every dentry that goes through lookup and bork whatever doesn't come
through lookup."

--
Gabriel Krisman Bertazi