]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson: add a dummy object store
authorKefu Chai <kchai@redhat.com>
Mon, 7 Jan 2019 10:50:05 +0000 (18:50 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 18 Jan 2019 04:32:21 +0000 (12:32 +0800)
CyanStore only provides just-enough facility for booting an OSD.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/CMakeLists.txt
src/crimson/os/CMakeLists.txt [new file with mode: 0644]
src/crimson/os/cyan_store.cc [new file with mode: 0644]
src/crimson/os/cyan_store.h [new file with mode: 0644]

index a04ade8f0b5c648bfa5359a02e73460515cd08a6..cff5f86c01befb967a7446a05343dce21c65f372 100644 (file)
@@ -133,3 +133,4 @@ target_link_libraries(crimson
   PUBLIC
     crimson-common
     crimson::cflags)
+add_subdirectory(os)
diff --git a/src/crimson/os/CMakeLists.txt b/src/crimson/os/CMakeLists.txt
new file mode 100644 (file)
index 0000000..edc3f49
--- /dev/null
@@ -0,0 +1,4 @@
+add_library(crimson-os
+  cyan_store.cc)
+target_link_libraries(crimson-os
+  fmt::fmt crimson-common)
diff --git a/src/crimson/os/cyan_store.cc b/src/crimson/os/cyan_store.cc
new file mode 100644 (file)
index 0000000..0d7cbdf
--- /dev/null
@@ -0,0 +1,31 @@
+#include "cyan_store.h"
+
+#include <fmt/format.h>
+
+#include "common/safe_io.h"
+
+void CyanStore::write_meta(const std::string& key,
+                           const std::string& value)
+{
+  std::string v = value;
+  v += "\n";
+  if (int r = safe_write_file(path.c_str(), key.c_str(),
+                              v.c_str(), v.length());
+      r < 0) {
+    throw std::runtime_error{fmt::format("unable to write_meta({})", key)};
+  }
+}
+
+std::string CyanStore::read_meta(const std::string& key)
+{
+  char buf[4096];
+  int r = safe_read_file(path.c_str(), key.c_str(),
+                         buf, sizeof(buf));
+  if (r <= 0)
+    throw std::runtime_error{fmt::format("unable to read_meta({})", key)};
+  // drop trailing newlines
+  while (r && isspace(buf[r-1])) {
+    --r;
+  }
+  return std::string(buf, r);
+}
diff --git a/src/crimson/os/cyan_store.h b/src/crimson/os/cyan_store.h
new file mode 100644 (file)
index 0000000..0683d4e
--- /dev/null
@@ -0,0 +1,20 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include <string>
+#include "include/uuid.h"
+
+// a just-enough store for reading/writing the superblock
+class CyanStore {
+  const std::string path;
+public:
+  CyanStore(const std::string& path)
+    : path{path}
+  {}
+
+  void write_meta(const std::string& key,
+                 const std::string& value);
+  std::string read_meta(const std::string& key);
+};