Project

General

Profile

Actions

Bug #70100

closed
AC PD

Inconsistent lookup results in ENOENT after readdir

Bug #70100: Inconsistent lookup results in ENOENT after readdir

Added by Anoop C S almost 2 years ago. Updated about 1 year ago.

Status:
Resolved
Priority:
Normal
Category:
Correctness/Safety
Target version:
Due date:
% Done:

0%

Source:
Community (dev)
Backport:
squid,reef
Regression:
No
Severity:
2 - major
Reviewed:
Affected Versions:
ceph-qa-suite:
Component(FS):
Client, Samba VFS, libcephfs
Labels (FS):
Samba/CIFS, snapshots
Pull request ID:
Tags (freeform):
Fixed In:
v20.0.0
Released In:
v20.2.0~961
Upkeep Timestamp:
2025-11-01T01:11:21+00:00

Description

Following a readdir(or readdir_r) on the subvolume root, an attempt to lookup a file under a subdirectory fails with ENOENT as seen with the reproducer attached. It is interesting to note that the very same lookup performed prior to readdir succeeds.

# gcc -D_FILE_OFFSET_BITS=64 -lcephfs libcephfs_ll_readdir_lookup.c -o lookup

# ./lookup
Usage: ./lookup <client-id> <filesystem> <subvol-path> <lookup-path>

# ./lookup foo cephvol /volumes/_nogroup/subvol/d2916e6d-a054-41f1-ac77-17ee77f22365 dir/shift.txt
cwd = /volumes/_nogroup/subvol/d2916e6d-a054-41f1-ac77-17ee77f22365
subvol inode = 1099511627779
file inode = 1099511627887
ceph_ll_lookup failed: No such file or directory

# ./lookup foo cephvol /volumes/_nogroup/subvol/d2916e6d-a054-41f1-ac77-17ee77f22365 /_snap_2025-02-12-163817_1099511627778
cwd = /volumes/_nogroup/subvol/d2916e6d-a054-41f1-ac77-17ee77f22365
subvol inode = 1099511627779
/_snap_2025-02-12-163817_1099511627778 inode = 1099511627779
ceph_ll_lookup failed: No such file or directory

# ./lookup foo cephvol /volumes/_nogroup/subvol/d2916e6d-a054-41f1-ac77-17ee77f22365 /_snap_2025-02-12-163817_1099511627778/foobar.txt
cwd = /volumes/_nogroup/subvol/d2916e6d-a054-41f1-ac77-17ee77f22365
subvol inode = 1099511627779
/_snap_2025-02-12-163817_1099511627778/foobar.txt inode = 1099511627781
ceph_ll_lookup failed: No such file or directory

The reproducer was crafted out of a setup where Windows clients tries to list snapshots as previous versions using shadow_copy2 VFS module, connected via low-level APIs from ceph_new VFS module. As per the client logs this might be related to marking(and/or dropping) of I_COMPLETE flag on the parent inode while traversing the directory for immediate entries.

There is also an associated behaviour when snapshot directories are looked up using snapdir name(".snap") as illustrated with an additional reproducer attached. Here the assumption of `//` as snapdir is kind of expected(instead of literal snapdir name) which is a bit unfortunate for consumers of low-level APIs.

# gcc -D_FILE_OFFSET_BITS=64 -lcephfs libcephfs_ll_lookup_snap.c -o lookup_snap

# ./lookup_snap 
Usage: ./lookup_snap <client-id> <filesystem> <subvolume-path> <snapshot-name>

# ./lookup_snap foo cephvol /volumes/_nogroup/subvol/d2916e6d-a054-41f1-ac77-17ee77f22365 _snap_2025-02-12-163817_1099511627778
cwd = /volumes/_nogroup/subvol/d2916e6d-a054-41f1-ac77-17ee77f22365
subvol inode = 1099511627779
snapshot(_snap_2025-02-12-163817_1099511627778) inode = 1099511627779
ceph_ll_lookup failed: No such file or directory


Files

libcephfs_ll_readdir_lookup.c (3.17 KB) libcephfs_ll_readdir_lookup.c Anoop C S, 02/20/2025 09:50 AM
libcephfs_ll_lookup_snap.c (2.52 KB) libcephfs_ll_lookup_snap.c Anoop C S, 02/24/2025 08:57 AM

PD Updated by Patrick Donnelly almost 2 years ago Actions #1

Odd coincidence to see this ticket come in. I think I have independently discovered this and wrote a fix in:

https://github.com/ceph/ceph/pull/60746

in commit

client: init dentry shared_gen with invalid value

AC Updated by Anoop C S almost 2 years ago Actions #2

Patrick Donnelly wrote in #note-1:

Odd coincidence to see this ticket come in. I think I have independently discovered this and wrote a fix in:

https://github.com/ceph/ceph/pull/60746

in commit

client: init dentry shared_gen with invalid value

Do we have other dependent patches required for fixing the issue? At least the single line change from the above mentioned commit couldn't successfully get past the reproducer attached.

AC Updated by Anoop C S almost 2 years ago Actions #3

  • File deleted (libcephfs_ll_lookup_snap.c)

AC Updated by Anoop C S almost 2 years ago Actions #5

Also how are we supposed to lookup snapdir within a directory(or sub directory) from root of the subvolume/volume? Following doesn't work:
lookup(".snap") -> 0(Success)
lookup("/") -> 0(Success)
lookup("dir/.snap") -> ENOENT
lookup("dir/subdir/.snap") -> ENOENT
lookup("dir//") -> EINVAL

VS Updated by Venky Shankar almost 2 years ago Actions #6

  • Status changed from New to Triaged
  • Assignee set to Patrick Donnelly
  • Priority changed from Normal to High
  • Target version set to v20.0.0
  • Backport set to reef,squid

PD Updated by Patrick Donnelly almost 2 years ago Actions #7

  • Status changed from Triaged to Need More Info
  • Assignee deleted (Patrick Donnelly)
  • Priority changed from High to Normal
  • Target version deleted (v20.0.0)
  • Backport deleted (reef,squid)

Anoop, I'm having difficulty transplanting your test to a unittest:

diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc
index de9dd53a7bd5..006ab02d4e78 100644
--- a/src/test/libcephfs/test.cc
+++ b/src/test/libcephfs/test.cc
@@ -3638,6 +3638,60 @@ TEST(LibCephFS, SnapdirAttrs) {
   ceph_shutdown(cmount);
 }

+TEST(LibCephFS, SnapDirLookup) {
+  struct ceph_mount_info *cmount;
+  ASSERT_EQ(ceph_create(&cmount, NULL), 0);
+  ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
+  ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
+  ASSERT_EQ(0, ceph_mount(cmount, NULL));
+
+  ASSERT_EQ(ceph_mkdir(cmount, "foo", 0777), 0);
+  ASSERT_EQ(ceph_mkdir(cmount, "foo/bar", 0777), 0);
+  ASSERT_EQ(ceph_mkdir(cmount, "foo/.snap/snap", 0777), 0);
+
+  ASSERT_EQ(0, ceph_unmount(cmount));
+  ASSERT_EQ(0, ceph_mount(cmount, NULL));
+  ASSERT_EQ(0, ceph_chdir(cmount, "foo/"));
+
+  {
+    struct ceph_dir_result *cdr = NULL;
+    struct dirent* de = nullptr;
+    ASSERT_EQ(0, ceph_opendir(cmount, ".", &cdr));
+    while((de = ceph_readdir(cmount, cdr))) {
+      continue;
+    }
+    ASSERT_EQ(0, ceph_closedir(cmount, cdr));
+  }
+
+  {
+    struct stat buf;
+    ASSERT_EQ(0, ceph_stat(cmount, "bar", &buf));
+  }
+
+  ASSERT_EQ(0, ceph_unmount(cmount));
+  ASSERT_EQ(0, ceph_mount(cmount, NULL));
+  ASSERT_EQ(0, ceph_chdir(cmount, "foo/"));
+
+  {
+    struct ceph_dir_result *cdr = NULL;
+    struct dirent* de = nullptr;
+    ASSERT_EQ(0, ceph_opendir(cmount, ".snap/snap", &cdr));
+    while((de = ceph_readdir(cmount, cdr))) {
+      continue;
+    }
+    ASSERT_EQ(0, ceph_closedir(cmount, cdr));
+  }
+
+
+  {
+    struct stat buf;
+    ASSERT_EQ(0, ceph_stat(cmount, ".snap/snap/bar", &buf));
+  }
+
+  ASSERT_EQ(0, ceph_unmount(cmount));
+  ceph_shutdown(cmount);
+}
+

Can you please update this test case as appropriate?

AC Updated by Anoop C S almost 2 years ago Actions #8

Can you please update this test case as appropriate?

As mentioned in the tracker description, issue was discovered using low-level APIs. I couldn't see any low-level API calls in the test case. Also please note that the contents being looked up need not be within snapshot directory but files or directories present elsewhere other than root of the volume/subvolume. Let me see if I can convert the attached reproducer into a test case.

PD Updated by Patrick Donnelly almost 2 years ago Actions #9

Anoop C S wrote in #note-8:

Can you please update this test case as appropriate?

As mentioned in the tracker description, issue was discovered using low-level APIs. I couldn't see any low-level API calls in the test case. Also please note that the contents being looked up need not be within snapshot directory but files or directories present elsewhere other than root of the volume/subvolume. Let me see if I can convert the attached reproducer into a test case.

You can also use the `Client` directly from `src/test/client/`

AC Updated by Anoop C S almost 2 years ago Actions #10

Can you please update this test case as appropriate?

diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc
index de9dd53a7bd..6e34c6e00bd 100644
--- a/src/test/libcephfs/test.cc
+++ b/src/test/libcephfs/test.cc
@@ -3793,3 +3793,47 @@ TEST(LibCephFS, SnapdirAttrsOnSnapRename) {
   ASSERT_EQ(0, ceph_unmount(cmount));
   ceph_shutdown(cmount);
 }
+
+TEST(LibCephFS, SubdirLookupAfterReaddir_ll) {
+  struct ceph_mount_info *cmount;
+  Inode *root, *subdir = NULL;
+  struct ceph_statx stx;
+
+  ASSERT_EQ(ceph_create(&cmount, NULL), 0);
+  ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
+  ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
+  ASSERT_EQ(0, ceph_mount(cmount, NULL));
+
+  ceph_rmdir(cmount, "foo/bar");
+  ceph_rmdir(cmount, "foo");
+
+  ASSERT_EQ(ceph_mkdir(cmount, "foo", 0777), 0);
+  ASSERT_EQ(ceph_mkdir(cmount, "foo/bar", 0777), 0);
+
+  ASSERT_EQ(0, ceph_unmount(cmount));
+  ASSERT_EQ(0, ceph_mount(cmount, NULL));
+
+  UserPerm *perms = ceph_mount_perms(cmount);
+
+  {
+    ASSERT_EQ(0, ceph_ll_walk(cmount, ".", &root, &stx, CEPH_STATX_INO, 0, perms));
+    ASSERT_EQ(0, ceph_ll_lookup(cmount, root, "foo/bar", &subdir, &stx, CEPH_STATX_INO, 0, perms));
+  }
+
+  {
+    struct ceph_dir_result *cdr = NULL;
+    struct dirent *de = NULL;
+    ASSERT_EQ(0, ceph_ll_opendir(cmount, root, &cdr, perms));
+    while((de = ceph_readdir(cmount, cdr))) {
+      continue;
+    }
+    ASSERT_EQ(0, ceph_ll_releasedir(cmount, cdr));
+  }
+
+  {
+    ASSERT_EQ(0, ceph_ll_lookup(cmount, root, "foo/bar", &subdir, &stx, CEPH_STATX_INO, 0, perms));
+  }
+
+  ASSERT_EQ(0, ceph_unmount(cmount));
+  ceph_shutdown(cmount);
+}

The above test case fails at the second lookup after readdir:

# bin/ceph_test_libcephfs --gtest_filter="LibCephFS.SubdirLookupAfterReaddir_ll" 
Note: Google Test filter = LibCephFS.SubdirLookupAfterReaddir_ll
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from LibCephFS
[ RUN      ] LibCephFS.SubdirLookupAfterReaddir_ll
/home/workspace/ceph.git/src/test/libcephfs/test.cc:3833: Failure
Expected equality of these values:
  0
  ceph_ll_lookup(cmount, root, "foo/bar", &subdir, &stx, 0x00000100U, 0, perms)
    Which is: -2
[  FAILED  ] LibCephFS.SubdirLookupAfterReaddir_ll (1516 ms)
[----------] 1 test from LibCephFS (1516 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (1516 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] LibCephFS.SubdirLookupAfterReaddir_ll

 1 FAILED TEST

PD Updated by Patrick Donnelly almost 2 years ago Actions #11

  • Status changed from Need More Info to Fix Under Review
  • Assignee set to Patrick Donnelly
  • Target version set to v20.0.0
  • Source set to Community (dev)
  • Backport set to squid,reef
  • Pull request ID set to 60746

The path walk refactor is what fixed this. I will likely break that out into a separate fix for reef. The full case sensitive PR will be backported to squid.

PD Updated by Patrick Donnelly almost 2 years ago Actions #12

BTW, thanks for the test case. I had some differences in mine which prevented reproduction.

AC Updated by Anoop C S almost 2 years ago Actions #13

Patrick Donnelly wrote in #note-11:

The path walk refactor is what fixed this.

Alright, I built libcephfs on top of your entire patch set and it worked very well in a way beyond my expectation. See below for an example:

Currently ceph_ll_lookup() had an assumption that the name is relative to the current working directory which does not seem to be the case after applying the changes i.e,

getcwd() -> /volumes/_nogroup/subvol/d2916e6d-a054-41f1-ac77-17ee77f22365
ll_walk(".") -> 0(Success)
ll_lookup("/volumes/_nogroup/subvol/d2916e6d-a054-41f1-ac77-17ee77f22365") -> ENOENT [without changes]
ll_lookup("/volumes/_nogroup/subvol/d2916e6d-a054-41f1-ac77-17ee77f22365") -> 0(Success) [with changes]

Whereas the very same assumption remains intact with ceph_ll_walk() .

Is this the intention or was that a side effect? Can we safely assume that the upcoming behaviour with the changes is going to stay in the near future?

Also should we expect something different with https://github.com/ceph/ceph/pull/61838?

PD Updated by Patrick Donnelly almost 2 years ago Actions #14

Anoop C S wrote in #note-13:

Patrick Donnelly wrote in #note-11:

The path walk refactor is what fixed this.

Alright, I built libcephfs on top of your entire patch set and it worked very well in a way beyond my expectation. See below for an example:

Currently ceph_ll_lookup() had an assumption that the name is relative to the current working directory which does not seem to be the case after applying the changes i.e,
[...]

Whereas the very same assumption remains intact with ceph_ll_walk() .

Is this the intention or was that a side effect?

I think I fixed many path walk bugs during the course of the refactor. Some I was aware of and others not.

Can we safely assume that the upcoming behaviour with the changes is going to stay in the near future?

If the behavior is correct then... yes? :)

Also should we expect something different with https://github.com/ceph/ceph/pull/61838?

Different how?

AC Updated by Anoop C S almost 2 years ago Actions #15

Is this the intention or was that a side effect?

I think I fixed many path walk bugs during the course of the refactor. Some I was aware of and others not.

Ok.

Can we safely assume that the upcoming behaviour with the changes is going to stay in the near future?

If the behavior is correct then... yes? :)

Fine.

Also should we expect something different with https://github.com/ceph/ceph/pull/61838?

Different how?

As in, can that change affect the behaviour with refactoring for path_walk() done in case insensitivity patch set? I see that it is addressing a crash but is that something touched via the case insensitivity PR?

PD Updated by Patrick Donnelly almost 2 years ago Actions #16

  • Status changed from Fix Under Review to Resolved

Will backport via #66373

AC Updated by Anoop C S almost 2 years ago Actions #17

On a second thought, regarding my #note-13, I think the ceph_ll_walk() behaviour is incorrect. If the provided name starts with '/' I think it should ignore the relative approach with current working directory and process it as an absolute path. What do you think?

AC Updated by Anoop C S over 1 year ago Actions #18

Anoop C S wrote in #note-17:

On a second thought, regarding my #note-13, I think the ceph_ll_walk() behaviour is incorrect. If the provided name starts with '/' I think it should ignore the relative approach with current working directory and process it as an absolute path. What do you think?

Patrick,
Can you please let me know your thoughts?

PD Updated by Patrick Donnelly over 1 year ago Actions #19

Anoop C S wrote in #note-18:

Anoop C S wrote in #note-17:

On a second thought, regarding my #note-13, I think the ceph_ll_walk() behaviour is incorrect. If the provided name starts with '/' I think it should ignore the relative approach with current working directory and process it as an absolute path. What do you think?

Patrick,
Can you please let me know your thoughts?

Yes, it should I think. It's doing that now with the case-insensitive subtree PR merged, yes?

AC Updated by Anoop C S over 1 year ago Actions #20

Patrick Donnelly wrote in #note-19:

Anoop C S wrote in #note-18:

Anoop C S wrote in #note-17:

On a second thought, regarding my #note-13, I think the ceph_ll_walk() behaviour is incorrect. If the provided name starts with '/' I think it should ignore the relative approach with current working directory and process it as an absolute path. What do you think?

Patrick,
Can you please let me know your thoughts?

Yes, it should I think. It's doing that now with the case-insensitive subtree PR merged, yes?

I'm afraid not.

ceph_chdir("/dir") => OK
ceph_getcwd() => /dir
ceph_ll_walk("/dir") => ENOENT

This is what I observe with the latest code base.

AC Updated by Anoop C S over 1 year ago Actions #21

Anoop C S wrote in #note-20:

Patrick Donnelly wrote in #note-19:

Anoop C S wrote in #note-18:

Anoop C S wrote in #note-17:

On a second thought, regarding my #note-13, I think the ceph_ll_walk() behaviour is incorrect. If the provided name starts with '/' I think it should ignore the relative approach with current working directory and process it as an absolute path. What do you think?

Patrick,
Can you please let me know your thoughts?

Yes, it should I think. It's doing that now with the case-insensitive subtree PR merged, yes?

I'm afraid not.

ceph_chdir("/dir") => OK
ceph_getcwd() => /dir
ceph_ll_walk("/dir") => ENOENT

This is what I observe with the latest code base.

Patrick,

Did you manage to verify the above scenario?

PD Updated by Patrick Donnelly over 1 year ago Actions #22

Anoop C S wrote in #note-20:

Patrick Donnelly wrote in #note-19:

Anoop C S wrote in #note-18:

Anoop C S wrote in #note-17:

On a second thought, regarding my #note-13, I think the ceph_ll_walk() behaviour is incorrect. If the provided name starts with '/' I think it should ignore the relative approach with current working directory and process it as an absolute path. What do you think?

Patrick,
Can you please let me know your thoughts?

Yes, it should I think. It's doing that now with the case-insensitive subtree PR merged, yes?

I'm afraid not.

ceph_chdir("/dir") => OK
ceph_getcwd() => /dir
ceph_ll_walk("/dir") => ENOENT

This is what I observe with the latest code base.

Hi Anoop, sorry I forgot about this even though I had a test case. thanks for the nudge. I will turn this into a new issue shortly. Thanks a lot!

PD Updated by Patrick Donnelly over 1 year ago Actions #23

Patrick Donnelly wrote in #note-22:

Anoop C S wrote in #note-20:

Patrick Donnelly wrote in #note-19:

Anoop C S wrote in #note-18:

Anoop C S wrote in #note-17:

On a second thought, regarding my #note-13, I think the ceph_ll_walk() behaviour is incorrect. If the provided name starts with '/' I think it should ignore the relative approach with current working directory and process it as an absolute path. What do you think?

Patrick,
Can you please let me know your thoughts?

Yes, it should I think. It's doing that now with the case-insensitive subtree PR merged, yes?

I'm afraid not.

ceph_chdir("/dir") => OK
ceph_getcwd() => /dir
ceph_ll_walk("/dir") => ENOENT

This is what I observe with the latest code base.

Hi Anoop, sorry I forgot about this even though I had a test case. thanks for the nudge. I will turn this into a new issue shortly. Thanks a lot!

#70573

PD Updated by Patrick Donnelly over 1 year ago Actions #24

  • Merge Commit set to 048fc68c517f50b9978457f478ca4638f01caa09
  • Fixed In set to v20.0.0

PD Updated by Patrick Donnelly over 1 year ago Actions #25

  • Released In set to v20.0.0^0

PD Updated by Patrick Donnelly over 1 year ago Actions #26

  • Released In deleted (v20.0.0^0)

UB Updated by Upkeep Bot about 1 year ago Actions #27

  • Released In set to v20.2.0~961
  • Upkeep Timestamp set to 2025-11-01T01:11:21+00:00
Actions

Also available in: PDF Atom