From: Sage Weil Date: Tue, 1 Dec 2015 22:16:11 +0000 (-0500) Subject: osd: make block device fsid probing generic X-Git-Tag: v10.0.2~106^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=880a59d1b769d689361af08ce46fa811e9e37196;p=ceph.git osd: make block device fsid probing generic Currently the option name and invocation assume that the block device is a journal (and FileStore journal, managed by FileJournal). Rework the interface so that we can probe any block device and other ObjectStore implementations will have a chance to identify the device (and return the osd fsid). Switch to a static method while we are at it so we avoid instantiating each backend. Note that only FileStore is probed at the moment; that will change soon! Signed-off-by: Sage Weil --- diff --git a/src/ceph-disk b/src/ceph-disk index 7f4a00988f31..0a91fa99ec4d 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -2870,9 +2870,7 @@ def get_journal_osd_uuid(path): out = _check_output( args=[ 'ceph-osd', - '-i', '0', # this is ignored - '--get-journal-uuid', - '--osd-journal', + '--get-device-fsid', path, ], close_fds=True, diff --git a/src/ceph_osd.cc b/src/ceph_osd.cc index 7a429ff6bd4f..aad4307d2e50 100644 --- a/src/ceph_osd.cc +++ b/src/ceph_osd.cc @@ -71,8 +71,8 @@ void handle_osd_signal(int signum) void usage() { cout << "usage: ceph-osd -i \n" - << " --osd-data=path data directory\n" - << " --osd-journal=path\n" + << " --osd-data PATH data directory\n" + << " --osd-journal PATH\n" << " journal file or block device\n" << " --mkfs create a [new] data directory\n" << " --convert-filestore\n" @@ -85,7 +85,9 @@ void usage() << " check whether a journal is allowed\n" << " --check-needs-journal\n" << " check whether a journal is required\n" - << " --debug_osd N set debug level (e.g. 10)" + << " --debug_osd set debug level (e.g. 10)" + << " --get-device-fsid PATH\n" + << " get OSD fsid for the given block device\n" << std::endl; generic_server_usage(); cout.flush(); @@ -130,9 +132,11 @@ int main(int argc, const char **argv) bool flushjournal = false; bool dump_journal = false; bool convertfilestore = false; - bool get_journal_fsid = false; bool get_osd_fsid = false; bool get_cluster_fsid = false; + bool get_journal_fsid = false; + bool get_device_fsid = false; + string device_path; std::string dump_pg_log; std::string val; @@ -168,6 +172,9 @@ int main(int argc, const char **argv) get_osd_fsid = true; } else if (ceph_argparse_flag(args, i, "--get-journal-fsid", "--get-journal-uuid", (char*)NULL)) { get_journal_fsid = true; + } else if (ceph_argparse_witharg(args, i, &device_path, + "--get-device-fsid", (char*)NULL)) { + get_device_fsid = true; } else { ++i; } @@ -177,6 +184,22 @@ int main(int argc, const char **argv) usage(); } + if (get_journal_fsid) { + device_path = g_conf->osd_journal; + get_device_fsid = true; + } + if (get_device_fsid) { + uuid_d uuid; + int r = ObjectStore::probe_block_device_fsid(device_path, &uuid); + if (r < 0) { + cerr << "failed to get device fsid for " << device_path + << ": " << cpp_strerror(r) << std::endl; + exit(1); + } + cout << uuid << std::endl; + return 0; + } + if (!dump_pg_log.empty()) { common_init_finish(g_ceph_context); bufferlist bl; @@ -365,14 +388,6 @@ int main(int argc, const char **argv) exit(0); } - if (get_journal_fsid) { - uuid_d fsid; - int r = store->peek_journal_fsid(&fsid); - if (r == 0) - cout << fsid << std::endl; - exit(r); - } - string magic; uuid_d cluster_fsid, osd_fsid; int w; diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 4134c0d4b81d..24653164ff31 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -123,13 +123,12 @@ static CompatSet get_fs_supported_compat_set() { return compat; } - -int FileStore::peek_journal_fsid(uuid_d *fsid) +int FileStore::get_block_device_fsid(const string& path, uuid_d *fsid) { // make sure we don't try to use aio or direct_io (and get annoying // error messages from failing to do so); performance implications // should be irrelevant for this use - FileJournal j(*fsid, 0, 0, journalpath.c_str(), false, false); + FileJournal j(*fsid, 0, 0, path.c_str(), false, false); return j.peek_fsid(*fsid); } diff --git a/src/os/FileStore.h b/src/os/FileStore.h index 883167821c28..be5e668b8ebf 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -96,7 +96,7 @@ public: return target_version; } - int peek_journal_fsid(uuid_d *fsid); + static int get_block_device_fsid(const string& path, uuid_d *fsid); struct FSPerfTracker { PerfCounters::avg_tracker os_commit_latency; diff --git a/src/os/KeyValueStore.h b/src/os/KeyValueStore.h index 4307901e5150..914ce1dff3e4 100644 --- a/src/os/KeyValueStore.h +++ b/src/os/KeyValueStore.h @@ -494,10 +494,6 @@ class KeyValueStore : public ObjectStore, uint32_t get_target_version() { return target_version; } - int peek_journal_fsid(uuid_d *id) { - *id = fsid; - return 0; - } int write_version_stamp(); int mount(); diff --git a/src/os/MemStore.cc b/src/os/MemStore.cc index 080f731e1a8f..678b16d2138f 100644 --- a/src/os/MemStore.cc +++ b/src/os/MemStore.cc @@ -41,12 +41,6 @@ bool operator>(const MemStore::CollectionRef& l, } -int MemStore::peek_journal_fsid(uuid_d *fsid) -{ - *fsid = uuid_d(); - return 0; -} - int MemStore::mount() { int r = _load(); diff --git a/src/os/MemStore.h b/src/os/MemStore.h index efaa2cf8141c..fc047c09ad9d 100644 --- a/src/os/MemStore.h +++ b/src/os/MemStore.h @@ -348,8 +348,6 @@ public: sharded(false) {} ~MemStore() { } - int peek_journal_fsid(uuid_d *fsid); - bool test_mount_in_use() { return false; } diff --git a/src/os/ObjectStore.cc b/src/os/ObjectStore.cc index aa62fbda691d..e47a94cc4279 100644 --- a/src/os/ObjectStore.cc +++ b/src/os/ObjectStore.cc @@ -85,6 +85,20 @@ ObjectStore *ObjectStore::create(CephContext *cct, return NULL; } +int ObjectStore::probe_block_device_fsid( + const string& path, + uuid_d *fsid) +{ + int r; + + // okay, try FileStore (journal). + r = FileStore::get_block_device_fsid(path, fsid); + if (r == 0) + return r; + + return -EINVAL; +} + int ObjectStore::write_meta(const std::string& key, const std::string& value) { diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 3b00ac73ebe8..8f2b749ae677 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -114,6 +114,16 @@ public: const string& journal, osflagbits_t flags = 0); + /** + * probe a block device to learn the uuid of the owning OSD + * + * @param cct cct + * @param path path to device + * @param fsid [out] osd uuid + */ + static int probe_block_device_fsid(const string& path, + uuid_d *fsid); + Logger *logger; /** @@ -1826,11 +1836,6 @@ public: virtual void collect_metadata(map *pm) { } - /** - * check the journal uuid/fsid, without opening - */ - virtual int peek_journal_fsid(uuid_d *fsid) = 0; - /** * write_meta - write a simple configuration key out-of-band *