Support negative dentries on case-insensitive directories
Subsystems (3)
cover Support negative dentries on case-insensitive directories
Hi,
This survives every corner case I could think of for negative dentries on case-insensitive filesystems, including those already tested by fstests. I also ran sanity checks to show it uses the created negative dentries, and I observed the expected performance increase of the negative dentry cache hit.
* Background
Negative dentries have always been disabled in case-insensitive directories because they don't provide enough assurance that every case variation of a filename doesn't exist in a directory and because there are known corner cases in file creation where negative dentries can't be instantiated.
In the trivial case the upstream implementation already works for negative dentries, even though it is disabled. That is: if the lookup that caused the dentry to be created was done in a case-insensitive way, the negative dentry can already be trusted, since it means that no valid dcache entry exists, *and* that no variation of the file exists on disk (since the lookup failed). A following lookup will then be executed with case-insensitive-aware d_hash and d_lookup, it will find the right negative dentry and can trust it. It has a creation problem, though, discussed below.
The first problem appears when a case-insensitive directory has negative dentries that were created when the directory was case-sensitive. A further lookup would incorrectly trust it:
This sequence demonstrates the problem:
mkdir d touch d/$1 touch d/$2
unlink d/$1 <- leaves negative dentry.
unlink d/$2 <- leaves negative dentry.
chattr +F d
touch d/$1 <- finds one of the negative dentries, makes it positive
< if d/$1 is d_drop somehow >
access d/$2 <- Might find the other negative dentry, get -ENOENT
There are actually a few problems here. The first is that a preexisting negative dentry created during a case-sensitive lookup doesn't guarantee that no other variation of the name exists. This is not a big problem in the common case, since the directory has to be empty to be converted, and the d_hash and d_compare are case-insensitive; which means they will find the same dentry and reuse it most of the time (except for invalidations and hash collisions). But it means that we are leaving behind a stalled dentry that shouldn't be there.
The real problem happens if $1 and $2 are two strings where:
(i) casefold($1) == casefold($2)
(ii) hash($1) == hash($2) == hash(casefold($1))This condition is the worst case. Both negative dentries can potentially be found during a case-insensitive lookup if the wrong dentry is invalidated.
In fact, this is a problem even on the current implementation. There was a bug reported by Al in 2020 [1], where a directory might end up with dangling negative dentries created during a case-sensitive lookup, because when the +F attribute is set; even though that code requires an empty directory, it doesn't check for negative dentries.
Condition (ii) is hard to test, but not impossible. But, even if it is not present, we still leave negative dentries behind, which shouldn't currently exist for a case-insensitive directory.
A completely different problem with negative dentries on case-insensitive directories exist when turning a negative dentry to positive. If the negative dentry has a different case than what is currently being looked up, the dentry cannot be reused without changing its name, because we guarantee filename-preserving semantics. We need to either change the name or invalidate the dentry. This is currently done in the upstream kernel by completely stopping negative dentries from being created in the first place.
* Proposal
The proposed solution is to differentiate negative dentries created from a case-insensitive context from those created during a case-sensitive one via a new dentry flag, D_CASEFOLD_LOOKUP, set by the filesystem during d_lookup. Since a negative dentry created during a case-insensitive lookup can be trusted (except for the name-preserving issue), we can check that flag during d_revalidate to quickly accept or reject the negative dentry.
Another solution for that problem would be to guarantee that no negative dentry exists during the Case-sensitive to case-insensitive directory conversion (the other direction is safe). This has the following problems:
1) It is not trivial to implement a race-free mechanism to ensure negative dentries won't be recreated immediately after invalidation while converting the directory.
2) The knowledge whether the negative dentry can be is valid (i.e. comes from a case-insensitive lookup) is implicit on the fact that we are correctly invalidating dentries when converting the directory.
Having a D_CASEFOLD_LOOKUP avoids both issues, and seems to be a cheap solution to explicitly decide whether to validate a negative dentry.
As explained, in order to maintain the filename preserving semantics, it is not sufficient to reuse the dentry.
One solution would be to invalidate the negative dentry when it is decided to turn it positive, instead of reusing it. I implemented that in the past (2018) but my understanding is that we don't want to incur costs on the VFS critical path for other filesystems who don't care about case-insensitiveness. I think there is also a challenge in making this invalidation race-free, but it might be simpler than I thought.
Instead, I'm suggesting that we only validate negative dentries in casefold directories during lookups that will instantiate the dentry when the lookup name is exactly what is cached.
* caveats
1) Encryption
Currently, negative dentries on encrypted directories are also disabled. No semantic change on encrypted directories is intended in this patchset; we just bypass the revalidation directly to fscrypt, for positive dentries. I'm working on this case as future work.
2) revalidate the cached dentry using the name under lookup
This is strange for a cache. the new semantic is implemented on d_revalidate() to stay out of the critical path of filesystems that don't care about case-insensitive. But this requires the revalidation hook to validate based on what name is under lookup, which is odd for a cache.
* Tests
There are a few tests for the corner cases discussed above in generic/556. They mainly verify the name-preserving semantics. The invalidation when converting the directory is harder to test, because it is hard to force the invalidation of specific cached dentries that occlude a dangling invalid dentry. I tested it with forcing the positive dentries to be removed, but I'm not sure how to write an upstreamable test for it.
This also survives smoke test on ext4 and f2fs.
* patchset
Patch 1 introduces a new version of d_revalidate to provide the filesystem with the name under lookup; Patch 2 introduces a new dentry flag to mark dentries as created during a case-insensitive lookup; Patch 3 introduces a libfs helper to validate negative dentries on case-insensitive directories; Patch 4 deals with encryption; Patch 5 cleans up the now redundant dentry operations for case-insensitive with and without encryption; Finally, Patch 6 and 7 enable negative dentries on case-insensitive directories for ext4 and f2fs, respectively.
Gabriel Krisman Bertazi (7):
fs: Expose name under lookup to d_revalidate hook
fs: Add DCACHE_CASEFOLD_LOOKUP flag
libfs: Validate negative dentries in case-insensitive directories
libfs: Support revalidation of encrypted case-insensitive dentries
libfs: Merge encrypted_ci_dentry_ops and ci_dentry_ops
ext4: Enable negative dentries on case-insensitive lookup
f2fs: Enable negative dentries on case-insensitive lookup
fs/dcache.c | 9 +++++- fs/ext4/namei.c | 35 +++----------------- fs/f2fs/namei.c | 23 ++------------ fs/libfs.c | 72 ++++++++++++++++++++++++------------------ fs/namei.c | 23 ++++++++------ include/linux/dcache.h | 9 ++++++ 6 files changed, 78 insertions(+), 93 deletions(-)
Signature · 1 line
2.36.1
PATCH 1/7 fs: Expose name under lookup to d_revalidate hook
Negative dentries support on case-insensitive ext4/f2fs will require access to the name under lookup to ensure it matches the dentry. This adds an optional new flavor of cached dentry revalidation hook to expose this extra parameter.
I'm fine with extending d_revalidate instead of adding a new hook, if it is considered cleaner and the approach is accepted. I wrote a new hook to simplify reviewing.
--- fs/dcache.c | 2 +- fs/namei.c | 23 ++++++++++++++--------- include/linux/dcache.h | 1 + 3 files changed, 16 insertions(+), 10 deletions(-)
fs/dcache.c +1 -1
@@ -1928,7 +1928,7 @@ void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op) dentry->d_flags |=DCACHE_OP_HASH ;if (op->d_compare) dentry->d_flags |=DCACHE_OP_COMPARE ; -if (op->d_revalidate) +if (op->d_revalidate || op->d_revalidate_name) dentry->d_flags |=DCACHE_OP_REVALIDATE ;if (op->d_weak_revalidate) dentry->d_flags |=DCACHE_OP_WEAK_REVALIDATE ;
fs/namei.c +14 -9
@@ -842,11 +842,16 @@ static bool try_to_unlazy_next(struct nameidata *nd, struct dentry *dentry, unsireturn false; } -static inline int d_revalidate (struct dentry *dentry,unsigned int flags) +static inline int d_revalidate (struct dentry *dentry, +const struct qstr *name, +unsigned int flags) { -if (unlikely (dentry->d_flags &DCACHE_OP_REVALIDATE )) + +if (unlikely (dentry->d_flags &DCACHE_OP_REVALIDATE )) { +if (dentry->d_op->d_revalidate_name) +return dentry->d_op->d_revalidate_name (dentry, name, flags);return dentry->d_op->d_revalidate (dentry, flags); -else + }else return 1 ; }
@@ -1563,7 +1568,7 @@ static struct dentry *lookup_dcache(const struct qstr *name, {struct dentry *dentry =d_lookup (dir, name);if (dentry) { -int error =d_revalidate (dentry, flags); +int error =d_revalidate (dentry, name, flags);if (unlikely (error <=0 )) {if (!error)d_invalidate (dentry);
@@ -1647,19 +1652,19 @@ static struct dentry *lookup_fast(struct nameidata *nd,return ERR_PTR (-ECHILD ); *seqp = seq; - status =d_revalidate (dentry, nd->flags); + status =d_revalidate (dentry, &nd->last, nd->flags);if (likely (status >0 ))return dentry;if (!try_to_unlazy_next (nd, dentry, seq))return ERR_PTR (-ECHILD );if (status == -ECHILD )/* we'd been told to redo it in non-rcu mode */ - status =d_revalidate (dentry, nd->flags); + status =d_revalidate (dentry, &nd->last, nd->flags); }else { dentry =__d_lookup (parent, &nd->last);if (unlikely (!dentry))return NULL ; - status =d_revalidate (dentry, nd->flags); + status =d_revalidate (dentry, &nd->last, nd->flags); }if (unlikely (status <=0 )) {if (!status)
@@ -1687,7 +1692,7 @@ static struct dentry *__lookup_slow(const struct qstr *name,if (IS_ERR (dentry))return dentry;if (unlikely (!d_in_lookup (dentry))) { -int error =d_revalidate (dentry, flags); +int error =d_revalidate (dentry, name, flags);if (unlikely (error <=0 )) {if (!error) {d_invalidate (dentry);
@@ -3302,7 +3307,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,if (d_in_lookup (dentry))break ; - error =d_revalidate (dentry, nd->flags); + error =d_revalidate (dentry, &nd->last, nd->flags);if (likely (error >0 ))break ;if (error)
include/linux/dcache.h +1 -0
@@ -126,6 +126,7 @@ enum dentry_d_lock_classstruct dentry_operations {int (*d_revalidate)(struct dentry *,unsigned int ); +int (*d_revalidate_name)(struct dentry *,const struct qstr *,unsigned int );int (*d_weak_revalidate)(struct dentry *,unsigned int );int (*d_hash)(const struct dentry *,struct qstr *); int (*d_compare)(const struct dentry *,
Signature · 1 line
2.36.1
Re: [PATCH 1/7] fs: Expose name under lookup to d_revalidate hook
Quoted 10 lines · Gabriel Krisman Bertazi
Negative dentries support on case-insensitive ext4/f2fs will require access to the name under lookup to ensure it matches the dentry. This adds an optional new flavor of cached dentry revalidation hook to expose this extra parameter.
I'm fine with extending
d_revalidateinstead of adding a new hook, if it is considered cleaner and the approach is accepted. I wrote a new hook to simplify reviewing.Signed-off-by Gabriel Krisman Bertazi <[email protected]>
Al, could you take a look and see if you have any objections?
Also, any thoughts about adding the new d_revalidate_name() callback as opposed to change d_revalidate() to add an extra parameter? It looks like there are some 33 d_revalidate callbacks, from 24 file sysetms, that would have to be changed.
Cheers,
- Ted
Theodore Ts'o
maintainerRe: [PATCH 1/7] fs: Expose name under lookup to d_revalidate hook
Quoted 10 lines · Theodore Ts'o
Quoted 9 lines · Gabriel Krisman Bertazi
Negative dentries support on case-insensitive ext4/f2fs will require access to the name under lookup to ensure it matches the dentry. This adds an optional new flavor of cached dentry revalidation hook to expose this extra parameter.
I'm fine with extending
d_revalidateinstead of adding a new hook, if it is considered cleaner and the approach is accepted. I wrote a new hook to simplify reviewing.
Quoted 5 lines
Quoted 1 line
Signed-off-by Gabriel Krisman Bertazi <[email protected]>Reviewed-by Theodore Ts'o <[email protected]>Al, could you take a look and see if you have any objections?
Ping, Al, any objsections if I take Gabriel's patch series via the ext4 tree?
- Ted
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Al Viro
maintainerRe: [PATCH 1/7] fs: Expose name under lookup to d_revalidate hook
Quoted 11 lines · Theodore Ts'o
Quoted 10 lines · Theodore Ts'o
Quoted 9 lines · Gabriel Krisman Bertazi
Negative dentries support on case-insensitive ext4/f2fs will require access to the name under lookup to ensure it matches the dentry. This adds an optional new flavor of cached dentry revalidation hook to expose this extra parameter.
I'm fine with extending
d_revalidateinstead of adding a new hook, if it is considered cleaner and the approach is accepted. I wrote a new hook to simplify reviewing.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Gabriel Krisman Bertazi <[email protected]>Reviewed-by Theodore Ts'o <[email protected]>Al, could you take a look and see if you have any objections?
Ping, Al, any objsections if I take Gabriel's patch series via the ext4 tree?
The really subtle part is ->d_name stability in there. We probably are OK as it is with the current tree (at least I hope so), but it really needs to be documented - the proof of correctness is not straightforward and it's going to be brittle; it's not obvious that this memcmp() relies upon the parent being locked in all cases when we get to calling it. And if that ever becomes not true, we have a hard-to-debug source of occasional oopsen ;-/
It can be done without reliance on locking - take a look at the vicinity of dentry_cmp() in fs/dcache.c for example of such, but it's very much not a blind memcmp(). And I suspect that it would be an overkill here.
In any case, that needs to be discussed in commit message and clearly spelled out. Otherwise it's a trouble waiting to happen.
PATCH 2/7 fs: Add DCACHE_CASEFOLD_LOOKUP flag
In reply to Gabriel Krisman BertaziThis flag marks a negative or positive dentry as being created after a case-insensitive lookup operation. It is useful to differentiate dentries this way to detect whether the negative dentry can be trusted during a case-insensitive lookup.
--- fs/dcache.c | 7 +++++++ include/linux/dcache.h | 8 ++++++++ 2 files changed, 15 insertions(+)
fs/dcache.c +7 -0
@@ -1958,6 +1958,13 @@ void d_set_fallthru(struct dentry *dentry) }EXPORT_SYMBOL (d_set_fallthru); +void d_set_casefold_lookup (struct dentry *dentry) +{ +spin_lock (&dentry->d_lock); + dentry->d_flags |=DCACHE_CASEFOLD_LOOKUP ; +spin_unlock (&dentry->d_lock); +} +static unsigned d_flags_for_inode (struct inode *inode) {unsigned add_flags =DCACHE_REGULAR_TYPE ;
include/linux/dcache.h +8 -0
@@ -208,6 +208,7 @@ struct dentry_operations {#define DCACHE_FALLTHRU 0x01000000/* Fall through to lower layer */ #define DCACHE_NOKEY_NAME 0x02000000/* Encrypted name encoded without key */ #define DCACHE_OP_REAL 0x04000000 +#define DCACHE_CASEFOLD_LOOKUP 0x08000000/* Dentry comes from a casefold directory */ #define DCACHE_PAR_LOOKUP 0x10000000/* being looked up (with parent locked shared) */ #define DCACHE_DENTRY_CURSOR 0x20000000
@@ -497,6 +498,13 @@ static inline bool d_is_fallthru(const struct dentry *dentry)return dentry->d_flags &DCACHE_FALLTHRU ; } +extern void d_set_casefold_lookup (struct dentry *dentry); + +static inline bool d_is_casefold_lookup (const struct dentry *dentry) +{ +return dentry->d_flags &DCACHE_CASEFOLD_LOOKUP ; +} +extern int sysctl_vfs_cache_pressure;
Signature · 8 lines
2.36.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [PATCH 2/7] fs: Add DCACHE_CASEFOLD_LOOKUP flag
Quoted 6 lines · Gabriel Krisman Bertazi
This flag marks a negative or positive dentry as being created after a case-insensitive lookup operation. It is useful to differentiate dentries this way to detect whether the negative dentry can be trusted during a case-insensitive lookup.
Signed-off-by Gabriel Krisman Bertazi <[email protected]>
PATCH 3/7 libfs: Validate negative dentries in case-insensitive directories
In reply to Gabriel Krisman BertaziIntroduce a dentry revalidation helper to be used by case-insensitive filesystems to check if it is safe to reuse a negative dentry.
A negative dentry is safe to be reused on a case-insensitive lookup if it was created during a case-insensitive lookup and this is not a lookup that will instantiate a dentry. If this is a creation lookup, we also need to make sure the name matches sensitively the name under lookup in order to assure the name preserving semantics.
--- fs/libfs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
fs/libfs.c +24 -0
@@ -1450,9 +1450,33 @@ static int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str)return 0 ; } +static inline int generic_ci_d_revalidate (struct dentry *dentry, +const struct qstr *name, +unsigned int flags) +{ +int is_creation = flags & (LOOKUP_CREATE |LOOKUP_RENAME_TARGET ); + +if (d_is_negative (dentry)) { +const struct dentry *parent =READ_ONCE (dentry->d_parent); +const struct inode *dir =READ_ONCE (parent->d_inode); + +if (dir &&needs_casefold (dir)) { +if (!d_is_casefold_lookup (dentry)) +return 0 ; + +if (is_creation && + (dentry->d_name.len != name->len || +memcmp (dentry->d_name.name, name->name, name->len))) +return 0 ; + } + } +return 1 ; +} +static const struct dentry_operations generic_ci_dentry_ops = { .d_hash = generic_ci_d_hash, .d_compare = generic_ci_d_compare, + .d_revalidate_name = generic_ci_d_revalidate, };#endif
Signature · 8 lines
2.36.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [PATCH 3/7] libfs: Validate negative dentries in case-insensitive directories
Quoted 10 lines · Gabriel Krisman Bertazi
Introduce a dentry revalidation helper to be used by case-insensitive filesystems to check if it is safe to reuse a negative dentry.
A negative dentry is safe to be reused on a case-insensitive lookup if it was created during a case-insensitive lookup and this is not a lookup that will instantiate a dentry. If this is a creation lookup, we also need to make sure the name matches sensitively the name under lookup in order to assure the name preserving semantics.
Signed-off-by Gabriel Krisman Bertazi <[email protected]>
Al Viro
maintainerRe: [PATCH 3/7] libfs: Validate negative dentries in case-insensitive directories
In reply to Gabriel Krisman Bertazifs/libfs.c static int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str) · line 1465
Quoted 13 lines · Gabriel Krisman Bertazi
fs/libfs.c +13
-0+static inline int generic_ci_d_revalidate (struct dentry *dentry, +const struct qstr *name, +unsigned int flags) +{ +int is_creation = flags & (LOOKUP_CREATE |LOOKUP_RENAME_TARGET ); + +if (d_is_negative (dentry)) { +const struct dentry *parent =READ_ONCE (dentry->d_parent); +const struct inode *dir =READ_ONCE (parent->d_inode); + +if (dir &&needs_casefold (dir)) { +if (!d_is_casefold_lookup (dentry)) +return 0 ;
In which conditions does that happen?
fs/libfs.c static int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str) · line 1474
Quoted 8 lines
fs/libfs.c +8
-0+if (is_creation && + (dentry->d_name.len != name->len || +memcmp (dentry->d_name.name, name->name, name->len))) +return 0 ; + } + } +return 1 ; +}
Analysis of stability of ->d_name, please. It's *probably* safe, but
the details are subtle and IMO should be accompanied by several asserts. E.g. "we never get LOOKUP_CREATE in op->intent without O_CREAT in op->open_flag for such and such reasons, and we verify that in such and such place"...
A part of that would be "the call in lookup_dcache() can only get there
with non-zero flags when coming from __lookup_hash(), and that has parent locked, stabilizing the name; the same goes for the call in __lookup_slow(), with the only call chain with possibly non-zero flags is through lookup_slow(), where we have the parent locked". However, lookup_fast() and lookup_open() have the flags come from nd->flags, and LOOKUP_CREATE can be found there in several areas. I _think_ we are guaranteed the parent locked in all such call chains, but that is definitely worth at least a comment.
Re: [f2fs-dev] [PATCH 3/7] libfs: Validate negative dentries in case-insensitive directories
Quoted 17 lines · Al Viro
fs/libfs.c static int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str) · line 1465
Quoted 13 lines · Gabriel Krisman Bertazi
fs/libfs.c +13
-0+static inline int generic_ci_d_revalidate (struct dentry *dentry, +const struct qstr *name, +unsigned int flags) +{ +int is_creation = flags & (LOOKUP_CREATE |LOOKUP_RENAME_TARGET ); + +if (d_is_negative (dentry)) { +const struct dentry *parent =READ_ONCE (dentry->d_parent); +const struct inode *dir =READ_ONCE (parent->d_inode); + +if (dir &&needs_casefold (dir)) { +if (!d_is_casefold_lookup (dentry)) +return 0 ;In which conditions does that happen?
Hi Al,
This can happen right after a case-sensitive directory is converted to case-insensitive. A previous case-sensitive lookup could have left a negative dentry in the dcache that we need to reject, because it doesn't have the same assurance of absence of all-variation of names as a negative dentry created during a case-insensitive lookup.
Quoted 14 lines
fs/libfs.c static int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str) · line 1474
Quoted 8 lines
fs/libfs.c +8
-0+if (is_creation && + (dentry->d_name.len != name->len || +memcmp (dentry->d_name.name, name->name, name->len))) +return 0 ; + } + } +return 1 ; +}Analysis of stability of ->d_name, please. It's *probably* safe, butthe details are subtle and IMO should be accompanied by several asserts. E.g. "we never get
LOOKUP_CREATEinop->intentwithoutO_CREATinop->open_flagfor such and such reasons, and we verify that in such and such place"...
Quoted 8 lines
A part of that would be "the call in
lookup_dcache()can only get there
with non-zero flags when coming from__lookup_hash(), and that has parent locked, stabilizing the name; the same goes for the call in__lookup_slow(), with the only call chain with possibly non-zero flags is throughlookup_slow(), where we have the parent locked". However,lookup_fast()andlookup_open()have the flags come fromnd->flags, andLOOKUP_CREATEcan be found there in several areas. I _think_ we are guaranteed the parent locked in all such call chains, but that is definitely worth at least a comment.
Thanks for the example of the analysis what you are looking for here. That will help me quite a bit. I wrote this code a while ago and I don't recall the exact details. I will go through the code again and send a new version with the detailed analysis.
Signature · 1 line
Gabriel Krisman Bertazi
PATCH 4/7 libfs: Support revalidation of encrypted case-insensitive dentries
In reply to Gabriel Krisman BertaziPreserve the existing behavior for encrypted directories, by rejecting negative dentries of encrypted+casefolded directories. This allows generic_ci_d_revalidate to be used by filesystems with both features enabled, as long as the directory is either casefolded or encrypted, but not both at the same time.
--- fs/libfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/libfs.c +6 -2
@@ -1461,6 +1461,9 @@ static inline int generic_ci_d_revalidate(struct dentry *dentry,const struct inode *dir =READ_ONCE (parent->d_inode);if (dir &&needs_casefold (dir)) { +if (IS_ENCRYPTED (dir)) +return 0 ; +if (!d_is_casefold_lookup (dentry))return 0 ;
@@ -1470,7 +1473,8 @@ static inline int generic_ci_d_revalidate(struct dentry *dentry,return 0 ; } } -return 1 ; + +return fscrypt_d_revalidate (dentry, flags); }static const struct dentry_operations generic_ci_dentry_ops = {
@@ -1490,7 +1494,7 @@ static const struct dentry_operations generic_encrypted_dentry_ops = {static const struct dentry_operations generic_encrypted_ci_dentry_ops = { .d_hash = generic_ci_d_hash, .d_compare = generic_ci_d_compare, - .d_revalidate = fscrypt_d_revalidate, + .d_revalidate_name = generic_ci_d_revalidate, };#endif
Signature · 8 lines
2.36.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [PATCH 4/7] libfs: Support revalidation of encrypted case-insensitive dentries
Quoted 7 lines · Gabriel Krisman Bertazi
Preserve the existing behavior for encrypted directories, by rejecting negative dentries of encrypted+casefolded directories. This allows
generic_ci_d_revalidateto be used by filesystems with both features enabled, as long as the directory is either casefolded or encrypted, but not both at the same time.Signed-off-by Gabriel Krisman Bertazi <[email protected]>
PATCH 5/7 libfs: Merge encrypted_ci_dentry_ops and ci_dentry_ops
In reply to Gabriel Krisman BertaziNow that casefold needs d_revalidate and calls fscrypt_d_revalidate itself, generic_encrypt_ci_dentry_ops and generic_ci_dentry_ops are now equivalent. Merge them together and simplify the setup code.
--- fs/libfs.c | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-)
fs/libfs.c +13 -31
@@ -1477,7 +1477,7 @@ static inline int generic_ci_d_revalidate(struct dentry *dentry,return fscrypt_d_revalidate (dentry, flags); } -static const struct dentry_operations generic_ci_dentry_ops = { +static const struct dentry_operations generic_encrypted_ci_dentry_ops = { .d_hash = generic_ci_d_hash, .d_compare = generic_ci_d_compare, .d_revalidate_name = generic_ci_d_revalidate,
@@ -1490,26 +1490,20 @@ static const struct dentry_operations generic_encrypted_dentry_ops = { };#endif -#if defined(CONFIG_FS_ENCRYPTION ) &&IS_ENABLED (CONFIG_UNICODE ) -static const struct dentry_operations generic_encrypted_ci_dentry_ops = { - .d_hash = generic_ci_d_hash, - .d_compare = generic_ci_d_compare, - .d_revalidate_name = generic_ci_d_revalidate, -}; -#endif -/** * generic_set_encrypted_ci_d_ops - helper for setting d_ops for given dentry * @dentry: dentry to set ops on * -* Casefolded directories need d_hash and d_compare set, so that the dentries -* contained in them are handled case-insensitively. Note that these operations -* are needed on the parent directory rather than on the dentries in it, and -* while the casefolding flag can be toggled on and off on an empty directory, -* dentry_operations can't be changed later. As a result, if the filesystem has -* casefolding support enabled at all, we have to give all dentries the -* casefolding operations even if their inode doesn't have the casefolding flag -* currently (and thus the casefolding ops would be no-ops for now). +* Casefolded directories need d_hash, d_compare and d_revalidate set, so +* that the dentries contained in them are handled case-insensitively, +* but implement support for fs_encryption. Note that these operations +* are needed on the parent directory rather than on the dentries in it, +* and while the casefolding flag can be toggled on and off on an empty +* directory, dentry_operations can't be changed later. As a result, if +* the filesystem has casefolding support enabled at all, we have to +* give all dentries the casefolding operations even if their inode +* doesn't have the casefolding flag currently (and thus the casefolding +* ops would be no-ops for now). * * Encryption works differently in that the only dentry operation it needs is * d_revalidate, which it only needs on dentries that have the no-key name flag.
@@ -1522,29 +1516,17 @@ static const struct dentry_operations generic_encrypted_ci_dentry_ops = {*/ void generic_set_encrypted_ci_d_ops (struct dentry *dentry) { -#ifdef CONFIG_FS_ENCRYPTION -bool needs_encrypt_ops = dentry->d_flags &DCACHE_NOKEY_NAME ; -#endif #if IS_ENABLED (CONFIG_UNICODE ) -bool needs_ci_ops = dentry->d_sb->s_encoding; -#endif -#if defined(CONFIG_FS_ENCRYPTION ) &&IS_ENABLED (CONFIG_UNICODE ) -if (needs_encrypt_ops && needs_ci_ops) { +if (dentry->d_sb->s_encoding) {d_set_d_op (dentry, &generic_encrypted_ci_dentry_ops);return ; }#endif #ifdef CONFIG_FS_ENCRYPTION -if (needs_encrypt_ops) { +if (dentry->d_flags &DCACHE_NOKEY_NAME ) {d_set_d_op (dentry, &generic_encrypted_dentry_ops);return ; }#endif -#if IS_ENABLED (CONFIG_UNICODE ) -if (needs_ci_ops) { -d_set_d_op (dentry, &generic_ci_dentry_ops); -return ; - } -#endif }EXPORT_SYMBOL (generic_set_encrypted_ci_d_ops);
Signature · 8 lines
2.36.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [PATCH 5/7] libfs: Merge encrypted_ci_dentry_ops and ci_dentry_ops
Quoted 5 lines · Gabriel Krisman Bertazi
Now that casefold needs
d_revalidateand callsfscrypt_d_revalidateitself,generic_encrypt_ci_dentry_opsandgeneric_ci_dentry_opsare now equivalent. Merge them together and simplify the setup code.Signed-off-by Gabriel Krisman Bertazi <[email protected]>
PATCH 6/7 ext4: Enable negative dentries on case-insensitive lookup
In reply to Gabriel Krisman BertaziInstead of invalidating negative dentries during case-insensitive lookups, mark them as such and let them be added to the dcache. d_ci_revalidate is able to properly filter them out if necessary based on the dentry casefold flag.
--- fs/ext4/namei.c | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-)
fs/ext4/namei.c +4 -31
@@ -1823,16 +1823,9 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi } } -#if IS_ENABLED (CONFIG_UNICODE ) -if (!inode &&IS_CASEFOLDED (dir)) { -/* Eventually we want to call d_add_ci(dentry, NULL) -* for negative dentries in the encoding case as -* well. For now, prevent the negative dentry -* from being cached. -*/ -return NULL ; - } -#endif +if (IS_ENABLED (CONFIG_UNICODE ) &&IS_CASEFOLDED (dir)) +d_set_casefold_lookup (dentry); +return d_splice_alias (inode, dentry); }
@@ -3153,17 +3146,6 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)ext4_fc_track_unlink (handle, dentry); retval =ext4_mark_inode_dirty (handle, dir); -#if IS_ENABLED (CONFIG_UNICODE ) -/* VFS negative dentries are incompatible with Encoding and -* Case-insensitiveness. Eventually we'll want avoid -* invalidating the dentries here, alongside with returning the -* negative dentries at ext4_lookup(), when it is better -* supported by the VFS for the CI case. -*/ -if (IS_CASEFOLDED (dir)) -d_invalidate (dentry); -#endif - end_rmdir:brelse (bh);if (handle)
@@ -3258,16 +3240,7 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) retval =__ext4_unlink (handle, dir, &dentry->d_name,d_inode (dentry));if (!retval)ext4_fc_track_unlink (handle, dentry); -#if IS_ENABLED (CONFIG_UNICODE ) -/* VFS negative dentries are incompatible with Encoding and -* Case-insensitiveness. Eventually we'll want avoid -* invalidating the dentries here, alongside with returning the -* negative dentries at ext4_lookup(), when it is better -* supported by the VFS for the CI case. -*/ -if (IS_CASEFOLDED (dir)) -d_invalidate (dentry); -#endif +if (handle)ext4_journal_stop (handle);
Signature · 8 lines
2.36.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
kernel test robot
build botRe: [PATCH 6/7] ext4: Enable negative dentries on case-insensitive lookup
I love your patch! Yet something to improve:
Hi Gabriel,
I love your patch! Yet something to improve:
[auto build test ERROR on tytso-ext4/dev]
[also build test ERROR on jaegeuk-f2fs/dev-test linus/master v5.19-rc3 next-20220622] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Gabriel-Krisman-Bertazi/Support-negative-dentries-on-case-insensitive-directories/20220623-034942 base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev config: x86_64-randconfig-a006 (https://download.01.org/0day-ci/archive/20220623/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-3) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/69488ccc517a48af2f1cec0efb84651397edf6f6 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Gabriel-Krisman-Bertazi/Support-negative-dentries-on-case-insensitive-directories/20220623-034942 git checkout 69488ccc517a48af2f1cec0efb84651397edf6f6 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "d_set_casefold_lookup" [fs/ext4/ext4.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
Re: [PATCH 6/7] ext4: Enable negative dentries on case-insensitive lookup
Quoted 23 lines · kernel test robot
Hi Gabriel,
I love your patch! Yet something to improve:
[auto build test ERROR on tytso-ext4/dev]
[also build test ERROR on jaegeuk-f2fs/dev-test linus/master v5.19-rc3 next-20220622] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]url: https://github.com/intel-lab-lkp/linux/commits/Gabriel-Krisman-Bertazi/Support-negative-dentries-on-case-insensitive-directories/20220623-034942 base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev config: x86_64-randconfig-a006 (https://download.01.org/0day-ci/archive/20220623/202206231550.0JrilBjp-lkp(a)intel.com/config) compiler: gcc-11 (Debian 11.3.0-3) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/69488ccc517a48af2f1cec0efb84651397edf6f6 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Gabriel-Krisman-Bertazi/Support-negative-dentries-on-case-insensitive-directories/20220623-034942 git checkout 69488ccc517a48af2f1cec0efb84651397edf6f6 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
Quoted 6 lines
If you fix the issue, kindly add following tag where applicable
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>, old ones prefixed by <<):
Quoted 1 line
Quoted 1 line
ERROR: modpost: "
d_set_casefold_lookup" [fs/ext4/ext4.ko] undefined!
Hm, missing the EXPORT_SYMBOL() since this is called from filesystems. I will add it for v2.
Signature · 1 line
Gabriel Krisman Bertazi
Re: [PATCH 6/7] ext4: Enable negative dentries on case-insensitive lookup
In reply to Gabriel Krisman BertaziQuoted 6 lines · Gabriel Krisman Bertazi
Instead of invalidating negative dentries during case-insensitive lookups, mark them as such and let them be added to the dcache.
d_ci_revalidateis able to properly filter them out if necessary based on the dentry casefold flag.Signed-off-by Gabriel Krisman Bertazi <[email protected]>
PATCH 7/7 f2fs: Enable negative dentries on case-insensitive lookup
In reply to Gabriel Krisman BertaziInstead of invalidating negative dentries during case-insensitive lookups, mark them as such and let them be added to the dcache. d_ci_revalidate is able to properly filter them out if necessary based on the dentry casefold flag.
--- fs/f2fs/namei.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-)
fs/f2fs/namei.c +2 -21
@@ -566,17 +566,8 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, goto out_iput; } out_splice: -#if IS_ENABLED (CONFIG_UNICODE ) -if (!inode &&IS_CASEFOLDED (dir)) { -/* Eventually we want to call d_add_ci(dentry, NULL) -* for negative dentries in the encoding case as -* well. For now, prevent the negative dentry -* from being cached. -*/ -trace_f2fs_lookup_end (dir, dentry, ino, err); -return NULL ; - } -#endif +if (IS_ENABLED (CONFIG_UNICODE ) &&IS_CASEFOLDED (dir)) +d_set_casefold_lookup (dentry); new =d_splice_alias (inode, dentry); err =PTR_ERR_OR_ZERO (new);trace_f2fs_lookup_end (dir, dentry, ino, !new ? -ENOENT : err);
@@ -627,16 +618,6 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry) goto fail; }f2fs_delete_entry (de, page, dir, inode); -#if IS_ENABLED (CONFIG_UNICODE ) -/* VFS negative dentries are incompatible with Encoding and -* Case-insensitiveness. Eventually we'll want avoid -* invalidating the dentries here, alongside with returning the -* negative dentries at f2fs_lookup(), when it is better -* supported by the VFS for the CI case. -*/ -if (IS_CASEFOLDED (dir)) -d_invalidate (dentry); -#endif f2fs_unlock_op (sbi);if (IS_DIRSYNC (dir))
Signature · 8 lines
2.36.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
kernel test robot
build botRe: [PATCH 7/7] f2fs: Enable negative dentries on case-insensitive lookup
I love your patch! Yet something to improve:
Hi Gabriel,
I love your patch! Yet something to improve:
[auto build test ERROR on tytso-ext4/dev]
[also build test ERROR on jaegeuk-f2fs/dev-test linus/master v5.19-rc3 next-20220623] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Gabriel-Krisman-Bertazi/Support-negative-dentries-on-case-insensitive-directories/20220623-034942 base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev config: x86_64-randconfig-a006 (https://download.01.org/0day-ci/archive/20220623/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-3) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/ab740b793e65b54ce8f48c693b86761f5bcaa911 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Gabriel-Krisman-Bertazi/Support-negative-dentries-on-case-insensitive-directories/20220623-034942 git checkout ab740b793e65b54ce8f48c693b86761f5bcaa911 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
All errors (new ones prefixed by >>, old ones prefixed by <<):
ERROR: modpost: "d_set_casefold_lookup" [fs/ext4/ext4.ko] undefined!
>> ERROR: modpost: "d_set_casefold_lookup" [fs/f2fs/f2fs.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
These look good to me. It will be nice to have negative dentries back for casefolded directories.
-Daniel Rosenberg