From 3d9fde9d92322cd8ac3e3d8bcbf5b0a01ef0528b Mon Sep 17 00:00:00 2001 From: David Zafman Date: Wed, 14 May 2014 15:41:15 -0700 Subject: [PATCH] os: Add optional flags to generic ObjectStore creation (SKIP_JOURNAL_REPLAY and SKIP_MOUNT_OMAP) Only FileStore cares about these flags, so passed on during create() Signed-off-by: David Zafman --- src/os/FileStore.cc | 41 +++++++++++-------- src/os/FileStore.h | 5 ++- src/os/JournalingObjectStore.cc | 5 +++ src/os/JournalingObjectStore.h | 1 + src/os/ObjectStore.cc | 5 ++- src/os/ObjectStore.h | 9 +++- .../objectstore/test_idempotent_sequence.cc | 4 +- 7 files changed, 46 insertions(+), 24 deletions(-) diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 805b57990675e..4e7c1a32f2413 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -492,10 +492,11 @@ int FileStore::lfn_unlink(coll_t cid, const ghobject_t& o, return index->unlink(o); } -FileStore::FileStore(const std::string &base, const std::string &jdev, const char *name, bool do_update) : +FileStore::FileStore(const std::string &base, const std::string &jdev, osflagbits_t flags, const char *name, bool do_update) : JournalingObjectStore(base), internal_name(name), basedir(base), journalpath(jdev), + generic_flags(flags), blk_size(0), fsid_fd(-1), op_fd(-1), basedir_fd(-1), current_fd(-1), @@ -1196,7 +1197,7 @@ int FileStore::write_op_seq(int fd, uint64_t seq) return ret; } -int FileStore::mount() +int FileStore::mount() { int ret; char buf[PATH_MAX]; @@ -1424,7 +1425,7 @@ int FileStore::mount() ::unlink(nosnapfn); } - { + if (!(generic_flags & SKIP_MOUNT_OMAP)) { KeyValueDB * omap_store = KeyValueDB::create(g_ceph_context, superblock.omap_backend, omap_dir); @@ -1528,24 +1529,26 @@ int FileStore::mount() wbthrottle.start(); sync_thread.create(); - ret = journal_replay(initial_op_seq); - if (ret < 0) { - derr << "mount failed to open journal " << journalpath << ": " << cpp_strerror(ret) << dendl; - if (ret == -ENOTTY) { - derr << "maybe journal is not pointing to a block device and its size " - << "wasn't configured?" << dendl; - } + if (!(generic_flags & SKIP_JOURNAL_REPLAY)) { + ret = journal_replay(initial_op_seq); + if (ret < 0) { + derr << "mount failed to open journal " << journalpath << ": " << cpp_strerror(ret) << dendl; + if (ret == -ENOTTY) { + derr << "maybe journal is not pointing to a block device and its size " + << "wasn't configured?" << dendl; + } - // stop sync thread - lock.Lock(); - stop = true; - sync_cond.Signal(); - lock.Unlock(); - sync_thread.join(); + // stop sync thread + lock.Lock(); + stop = true; + sync_cond.Signal(); + lock.Unlock(); + sync_thread.join(); - wbthrottle.stop(); + wbthrottle.stop(); - goto close_current_fd; + goto close_current_fd; + } } { @@ -1597,6 +1600,8 @@ int FileStore::umount() op_tp.stop(); journal_stop(); + if (!(generic_flags & SKIP_JOURNAL_REPLAY)) + journal_write_close(); op_finisher.stop(); ondisk_finisher.stop(); diff --git a/src/os/FileStore.h b/src/os/FileStore.h index f18b238393bf7..f6ed7bb4b7130 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -119,6 +119,7 @@ public: private: string internal_name; ///< internal name, used to name the perfcounter instance string basedir, journalpath; + osflagbits_t generic_flags; std::string current_fn; std::string current_op_seq_fn; std::string omap_dir; @@ -399,7 +400,9 @@ public: bool force_clear_omap=false); public: - FileStore(const std::string &base, const std::string &jdev, const char *internal_name = "filestore", bool update_to=false); + FileStore(const std::string &base, const std::string &jdev, + osflagbits_t flags = 0, + const char *internal_name = "filestore", bool update_to=false); ~FileStore(); int _detect_fs(); diff --git a/src/os/JournalingObjectStore.cc b/src/os/JournalingObjectStore.cc index 490a014c5d182..518d54edf6621 100644 --- a/src/os/JournalingObjectStore.cc +++ b/src/os/JournalingObjectStore.cc @@ -21,6 +21,11 @@ void JournalingObjectStore::journal_stop() { dout(10) << "journal_stop" << dendl; finisher.stop(); +} + +// A journal_replay() makes journal writeable, this closes that out. +void JournalingObjectStore::journal_write_close() +{ if (journal) { journal->close(); delete journal; diff --git a/src/os/JournalingObjectStore.h b/src/os/JournalingObjectStore.h index fb7f0eca6d78b..6a09c6133de90 100644 --- a/src/os/JournalingObjectStore.h +++ b/src/os/JournalingObjectStore.h @@ -111,6 +111,7 @@ protected: protected: void journal_start(); void journal_stop(); + void journal_write_close(); int journal_replay(uint64_t fs_op_seq); void _op_journal_transactions(list& tls, uint64_t op, diff --git a/src/os/ObjectStore.cc b/src/os/ObjectStore.cc index 5a7d2175d3af0..f9f6e1142478f 100644 --- a/src/os/ObjectStore.cc +++ b/src/os/ObjectStore.cc @@ -24,10 +24,11 @@ ObjectStore *ObjectStore::create(CephContext *cct, const string& type, const string& data, - const string& journal) + const string& journal, + osflagbits_t flags) { if (type == "filestore") { - return new FileStore(data, journal); + return new FileStore(data, journal, flags); } if (type == "memstore") { return new MemStore(cct, data); diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index b2d3f2ccb3860..20f925bc66bef 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -80,6 +80,11 @@ static inline void encode(const map *attrset, bufferlist &bl) ::encode(*attrset, bl); } +// Flag bits +typedef uint32_t osflagbits_t; +const int SKIP_JOURNAL_REPLAY = 1 << 0; +const int SKIP_MOUNT_OMAP = 1 << 1; + class ObjectStore { protected: string path; @@ -93,11 +98,13 @@ public: * @param type type of store. This is a string from the configuration file. * @param data path (or other descriptor) for data * @param journal path (or other descriptor) for journal (optional) + * @param flags which filestores should check if applicable */ static ObjectStore *create(CephContext *cct, const string& type, const string& data, - const string& journal); + const string& journal, + osflagbits_t flag = 0); Logger *logger; diff --git a/src/test/objectstore/test_idempotent_sequence.cc b/src/test/objectstore/test_idempotent_sequence.cc index 3ef2c79987d81..df502f8bfa13b 100644 --- a/src/test/objectstore/test_idempotent_sequence.cc +++ b/src/test/objectstore/test_idempotent_sequence.cc @@ -79,8 +79,8 @@ std::string status_file; int run_diff(std::string& a_path, std::string& a_journal, std::string& b_path, std::string& b_journal) { - FileStore *a = new FileStore(a_path, a_journal, "a"); - FileStore *b = new FileStore(b_path, b_journal, "b"); + FileStore *a = new FileStore(a_path, a_journal, 0, "a"); + FileStore *b = new FileStore(b_path, b_journal, 0, "b"); int ret = 0; { -- 2.39.5