]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/ceph-kvstore-tool: open DB in read-only whenever sufficient
authorIgor Fedotov <igor.fedotov@croit.io>
Sat, 13 Jan 2024 15:37:14 +0000 (18:37 +0300)
committerIgor Fedotov <igor.fedotov@croit.io>
Wed, 5 Mar 2025 10:46:54 +0000 (13:46 +0300)
Signed-off-by: Igor Fedotov <igor.fedotov@croit.io>
(cherry picked from commit 410d4748f9de94261d421576ed5433d2d0b0d4b3)

src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/bluestore/bluestore_tool.cc
src/tools/ceph_kvstore_tool.cc
src/tools/kvstore_tool.cc
src/tools/kvstore_tool.h

index 1d44d75eb4c7d560cfd85bff1bf144dc4c1c1095..390135500d18703c934752bcbde1269df6d1153b 100644 (file)
@@ -6547,10 +6547,10 @@ void BlueStore::_close_around_db()
   _close_path();
 }
 
-int BlueStore::open_db_environment(KeyValueDB **pdb, bool to_repair)
+int BlueStore::open_db_environment(KeyValueDB **pdb, bool read_only, bool to_repair)
 {
   _kv_only = true;
-  int r = _open_db_and_around(false, to_repair);
+  int r = _open_db_and_around(read_only, to_repair);
   if (r == 0) {
     *pdb = db;
   } else {
index 9896848a8ab2503f911baa7c701960831cd902c9..c517cfae3b9f70233b64477329d18eaa910e7c06 100644 (file)
@@ -2927,7 +2927,7 @@ public:
   }
   int umount() override;
 
-  int open_db_environment(KeyValueDB **pdb, bool to_repair);
+  int open_db_environment(KeyValueDB **pdb, bool read_only, bool to_repair);
   int close_db_environment();
   BlueFS* get_bluefs();
 
index e63616bdd0203bb1ae41a037e88b0ea019bc8025..ea99dcb62f6c30f62f1d22ce9fa1ed9e660b694a 100644 (file)
@@ -242,7 +242,7 @@ static void bluefs_import(
   }
   BlueStore bluestore(cct, path);
   KeyValueDB *db_ptr;
-  r = bluestore.open_db_environment(&db_ptr, false);
+  r = bluestore.open_db_environment(&db_ptr, false, false);
   if (r < 0) {
     cerr << "error preparing db environment: " << cpp_strerror(r) << std::endl;
     exit(EXIT_FAILURE);
@@ -1115,7 +1115,7 @@ int main(int argc, char **argv)
        exit(EXIT_FAILURE);
       }
     }
-    int r = bluestore.open_db_environment(&db_ptr, true);
+    int r = bluestore.open_db_environment(&db_ptr, false, true);
     if (r < 0) {
       cerr << "error preparing db environment: " << cpp_strerror(r) << std::endl;
       exit(EXIT_FAILURE);
@@ -1133,7 +1133,7 @@ int main(int argc, char **argv)
   } else if (action == "show-sharding") {
     BlueStore bluestore(cct.get(), path);
     KeyValueDB *db_ptr;
-    int r = bluestore.open_db_environment(&db_ptr, false);
+    int r = bluestore.open_db_environment(&db_ptr, false, false);
     if (r < 0) {
       cerr << "error preparing db environment: " << cpp_strerror(r) << std::endl;
       exit(EXIT_FAILURE);
index 61fe00cc9b42acb01e7bbae96e7cab4b00d24500..f07d4aa5b34143e41ed6cda5cf653cefaba4c093 100644 (file)
@@ -99,9 +99,20 @@ int main(int argc, const char *argv[])
     return 1;
   }
 
+  bool read_only =
+    cmd == "list" ||
+    cmd == "list-crc" ||
+    cmd == "dump" ||
+    cmd == "exists" ||
+    cmd == "get" ||
+    cmd == "crc" ||
+    cmd == "get-size" ||
+    cmd == "store-crc" ||
+    cmd == "stats" ||
+    cmd == "histogram";
   bool to_repair = (cmd == "destructive-repair");
   bool need_stats = (cmd == "stats");
-  StoreTool st(type, path, to_repair, need_stats);
+  StoreTool st(type, path, read_only, to_repair, need_stats);
 
   if (cmd == "destructive-repair") {
     int ret = st.destructive_repair();
index dfa600e83946a85f35862f47532cfb49f43876d2..53daa7b259ec1416e4a7fb19684aa1cd482ffc6e 100644 (file)
@@ -16,6 +16,7 @@ using namespace std;
 
 StoreTool::StoreTool(const string& type,
                     const string& path,
+                     bool read_only,
                     bool to_repair,
                     bool need_stats)
   : store_path(path)
@@ -28,7 +29,7 @@ StoreTool::StoreTool(const string& type,
 
   if (type == "bluestore-kv") {
 #ifdef WITH_BLUESTORE
-    if (load_bluestore(path, to_repair) != 0)
+    if (load_bluestore(path, read_only, to_repair) != 0)
       exit(1);
 #else
     cerr << "bluestore not compiled in" << std::endl;
@@ -37,7 +38,8 @@ StoreTool::StoreTool(const string& type,
   } else {
     auto db_ptr = KeyValueDB::create(g_ceph_context, type, path);
     if (!to_repair) {
-      if (int r = db_ptr->open(std::cerr); r < 0) {
+      int r = read_only ? db_ptr->open_read_only(std::cerr) : db_ptr->open(std::cerr);
+      if (r < 0) {
         cerr << "failed to open type " << type << " path " << path << ": "
              << cpp_strerror(r) << std::endl;
         exit(1);
@@ -47,11 +49,11 @@ StoreTool::StoreTool(const string& type,
   }
 }
 
-int StoreTool::load_bluestore(const string& path, bool to_repair)
+int StoreTool::load_bluestore(const string& path, bool read_only, bool to_repair)
 {
     auto bluestore = new BlueStore(g_ceph_context, path);
     KeyValueDB *db_ptr;
-    int r = bluestore->open_db_environment(&db_ptr, to_repair);
+    int r = bluestore->open_db_environment(&db_ptr, read_only, to_repair);
     if (r < 0) {
      return -EINVAL;
     }
index 330cba7c98dbd53ad9f3f931c57cd37531f5e53e..a0b906e96588a74bd69cf6fe4777871e4ebfaa15 100644 (file)
@@ -43,9 +43,10 @@ class StoreTool
 public:
   StoreTool(const std::string& type,
            const std::string& path,
+            bool read_only,
            bool need_open_db = true,
            bool need_stats = false);
-  int load_bluestore(const std::string& path, bool need_open_db);
+  int load_bluestore(const std::string& path, bool read_only, bool need_open_db);
   uint32_t traverse(const std::string& prefix,
                     const bool do_crc,
                     const bool do_value_dump,