12fe4d
From 3aa31813980d22719277a04797df48310acdff66 Mon Sep 17 00:00:00 2001
12fe4d
From: Jonas Jelten <jj@sft.lol>
12fe4d
Date: Mon, 15 Mar 2021 23:21:07 +0100
12fe4d
Subject: [PATCH] os/bluestore: strip trailing slash for directory listings
12fe4d
12fe4d
Calls to BlueRocksEnv::GetChildren may contain a trailing / in the
12fe4d
queried directory, which is stripped away with this patch.
12fe4d
12fe4d
If it's not stripped, the directory entry is not found in BlueFS:
12fe4d
```
12fe4d
10 bluefs readdir db/
12fe4d
20 bluefs readdir dir db/ not found
12fe4d
 3 rocksdb: [db/db_impl/db_impl_open.cc:1785] Persisting Option File error: OK
12fe4d
```
12fe4d
12fe4d
Fixes: https://tracker.ceph.com/issues/49815
12fe4d
Signed-off-by: Jonas Jelten <jj@sft.lol>
12fe4d
---
12fe4d
 src/os/bluestore/BlueFS.cc | 4 ++++
12fe4d
 1 file changed, 4 insertions(+)
12fe4d
12fe4d
diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc
12fe4d
index ea39626aef..62b9d27f58 100644
12fe4d
--- a/src/os/bluestore/BlueFS.cc
12fe4d
+++ b/src/os/bluestore/BlueFS.cc
12fe4d
@@ -3493,9 +3493,14 @@
12fe4d
 
12fe4d
 int BlueFS::readdir(const string& dirname, vector<string> *ls)
12fe4d
 {
12fe4d
+  std::string dname = dirname;
12fe4d
+  // dirname may contain a trailing /
12fe4d
+  if (!dname.empty() && dname.back() == '/') {
12fe4d
+    dname.pop_back();
12fe4d
+  }
12fe4d
   std::lock_guard l(lock);
12fe4d
-  dout(10) << __func__ << " " << dirname << dendl;
12fe4d
-  if (dirname.empty()) {
12fe4d
+  dout(10) << __func__ << " " << dname << dendl;
12fe4d
+  if (dname.empty()) {
12fe4d
     // list dirs
12fe4d
     ls->reserve(dir_map.size() + 2);
12fe4d
     for (auto& q : dir_map) {
12fe4d
@@ -3503,9 +3508,9 @@
12fe4d
     }
12fe4d
   } else {
12fe4d
     // list files in dir
12fe4d
-    map<string,DirRef>::iterator p = dir_map.find(dirname);
12fe4d
+    map<string,DirRef>::iterator p = dir_map.find(dname);
12fe4d
     if (p == dir_map.end()) {
12fe4d
-      dout(20) << __func__ << " dir " << dirname << " not found" << dendl;
12fe4d
+      dout(20) << __func__ << " dir " << dname << " not found" << dendl;
12fe4d
       return -ENOENT;
12fe4d
     }
12fe4d
     DirRef dir = p->second;
12fe4d
-- 
12fe4d
2.26.2
12fe4d