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