From 9fae689b6ebd8471fdd65b7c5140892a9b893984 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 7 Jan 2019 18:50:05 +0800 Subject: [PATCH] crimson: add a dummy object store CyanStore only provides just-enough facility for booting an OSD. Signed-off-by: Kefu Chai --- src/crimson/CMakeLists.txt | 1 + src/crimson/os/CMakeLists.txt | 4 ++++ src/crimson/os/cyan_store.cc | 31 +++++++++++++++++++++++++++++++ src/crimson/os/cyan_store.h | 20 ++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 src/crimson/os/CMakeLists.txt create mode 100644 src/crimson/os/cyan_store.cc create mode 100644 src/crimson/os/cyan_store.h diff --git a/src/crimson/CMakeLists.txt b/src/crimson/CMakeLists.txt index a04ade8f0b5..cff5f86c01b 100644 --- a/src/crimson/CMakeLists.txt +++ b/src/crimson/CMakeLists.txt @@ -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 index 00000000000..edc3f493605 --- /dev/null +++ b/src/crimson/os/CMakeLists.txt @@ -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 index 00000000000..0d7cbdf620b --- /dev/null +++ b/src/crimson/os/cyan_store.cc @@ -0,0 +1,31 @@ +#include "cyan_store.h" + +#include + +#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 index 00000000000..0683d4e427d --- /dev/null +++ b/src/crimson/os/cyan_store.h @@ -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 +#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); +}; -- 2.39.5