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