From d01967d372f75bd0539a3edf8e2233c3e84048b9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 6 Jan 2016 17:56:12 -0500 Subject: [PATCH] osd: osd_objectstore_fuse Expose underlying ObjectStore via fuse at $osd_data/fuse/. Can be enabled/ disabled at runtime. Signed-off-by: Sage Weil --- src/CMakeLists.txt | 2 +- src/common/config_opts.h | 1 + src/osd/OSD.cc | 52 ++++++++++++++++++++++++++++++++++++++++ src/osd/OSD.h | 4 ++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 254947e109b3..371587e38df7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -727,7 +727,7 @@ add_executable(ceph-osd ${ceph_osd_srcs} $ $) add_dependencies(ceph-osd erasure_code_plugins) -target_link_libraries(ceph-osd osd os global ${BLKID_LIBRARIES} ${ALLOC_LIBS}) +target_link_libraries(ceph-osd osd os global ${BLKID_LIBRARIES} ${ALLOC_LIBS} fuse) install(TARGETS ceph-osd DESTINATION bin) # MDS diff --git a/src/common/config_opts.h b/src/common/config_opts.h index f0277be2b402..a5f4afd1dede 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -833,6 +833,7 @@ OPTION(osd_objectstore_tracing, OPT_BOOL, false) // true if LTTng-UST tracepoint // Override maintaining compatibility with older OSDs // Set to true for testing. Users should NOT set this. OPTION(osd_debug_override_acting_compat, OPT_BOOL, false) +OPTION(osd_objectstore_fuse, OPT_BOOL, false) OPTION(osd_bench_small_size_max_iops, OPT_U32, 100) // 100 IOPS OPTION(osd_bench_large_size_max_throughput, OPT_U64, 100 << 20) // 100 MB/s diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index a8889293adc3..5c664be9f310 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -44,6 +44,7 @@ #include "common/io_priority.h" #include "os/ObjectStore.h" +#include "os/FuseStore.h" #include "ReplicatedPG.h" @@ -1549,6 +1550,7 @@ OSD::OSD(CephContext *cct_, ObjectStore *store_, logger(NULL), recoverystate_perf(NULL), store(store_), + fuse_store(NULL), log_client(cct, client_messenger, &mc->monmap, LogClient::NO_FLAGS), clog(log_client.create_channel()), whoami(id), @@ -1810,6 +1812,45 @@ public: }; +int OSD::enable_disable_fuse(bool stop) +{ + int r; + string mntpath = g_conf->osd_data + "/fuse"; + if (fuse_store && (stop || !g_conf->osd_objectstore_fuse)) { + dout(1) << __func__ << " disabling" << dendl; + fuse_store->stop(); + delete fuse_store; + fuse_store = NULL; + r = ::rmdir(mntpath.c_str()); + if (r < 0) + r = -errno; + if (r < 0) { + derr << __func__ << " failed to rmdir " << mntpath << dendl; + return r; + } + } + if (!fuse_store && g_conf->osd_objectstore_fuse) { + dout(1) << __func__ << " enabling" << dendl; + r = ::mkdir(mntpath.c_str(), 0700); + if (r < 0) + r = -errno; + if (r < 0 && r != -EEXIST) { + derr << __func__ << " unable to create " << mntpath << ": " + << cpp_strerror(r) << dendl; + return r; + } + fuse_store = new FuseStore(store, mntpath); + r = fuse_store->start(); + if (r < 0) { + derr << __func__ << " unable to start fuse: " << cpp_strerror(r) << dendl; + delete fuse_store; + fuse_store = NULL; + return r; + } + } + return 0; +} + int OSD::init() { CompatSet initial, diff; @@ -1832,6 +1873,8 @@ int OSD::init() return r; } + enable_disable_fuse(false); + dout(2) << "boot" << dendl; // initialize the daily loadavg with current 15min loadavg @@ -2022,8 +2065,10 @@ monout: monc->shutdown(); out: + enable_disable_fuse(true); store->umount(); delete store; + store = NULL; return r; } @@ -2455,6 +2500,7 @@ int OSD::shutdown() } dout(10) << "syncing store" << dendl; + enable_disable_fuse(true); store->umount(); delete store; store = 0; @@ -8568,6 +8614,7 @@ const char** OSD::get_tracked_conf_keys() const "clog_to_syslog", "clog_to_syslog_facility", "clog_to_syslog_level", + "osd_objectstore_fuse", NULL }; return KEYS; @@ -8612,6 +8659,11 @@ void OSD::handle_conf_change(const struct md_config_t *conf, changed.count("clog_to_syslog_facility")) { update_log_config(); } + if (changed.count("osd_objectstore_fuse")) { + if (store) { + enable_disable_fuse(false); + } + } check_config(); } diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 0b2bbbbea2fa..6faa5771abd4 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -202,6 +202,7 @@ class Message; class MonClient; class PerfCounters; class ObjectStore; +class FuseStore; class OSDMap; class MLog; class MClass; @@ -1079,6 +1080,7 @@ protected: PerfCounters *logger; PerfCounters *recoverystate_perf; ObjectStore *store; + FuseStore *fuse_store; LogClient log_client; LogChannelRef clog; @@ -2354,6 +2356,8 @@ public: int init(); void final_init(); + int enable_disable_fuse(bool stop); + void suicide(int exitcode); int shutdown(); -- 2.47.3