From db9ec690e6d7d173d978884d7a4cbd1f0bf3cf18 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 1 Dec 2015 17:21:00 -0500 Subject: [PATCH] osd: mark osd backend type in osd_data dir When we create an osd, mark the type of the backend in the osd_data dir in the 'type' file. On startup, if this file is present, us this to decide which ObjectStore to instantiate. If it is not present, use the osd_objectstore option as before. Signed-off-by: Sage Weil --- src/ceph_osd.cc | 17 ++++++++++++++++- src/os/FileStore.cc | 4 ++++ src/os/KeyValueStore.cc | 4 ++++ src/os/MemStore.cc | 4 ++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/ceph_osd.cc b/src/ceph_osd.cc index aad4307d2e50..fb5de3688a58 100644 --- a/src/ceph_osd.cc +++ b/src/ceph_osd.cc @@ -240,8 +240,23 @@ int main(int argc, const char **argv) } // the store + string store_type = g_conf->osd_objectstore; + { + char fn[PATH_MAX]; + snprintf(fn, sizeof(fn), "%s/type", g_conf->osd_data.c_str()); + int fd = ::open(fn, O_RDONLY); + if (fd >= 0) { + bufferlist bl; + bl.read_fd(fd, 64); + if (bl.length()) { + store_type = string(bl.c_str(), bl.length() - 1); // drop \n + dout(5) << "object store type is " << store_type << dendl; + } + ::close(fd); + } + } ObjectStore *store = ObjectStore::create(g_ceph_context, - g_conf->osd_objectstore, + store_type, g_conf->osd_data, g_conf->osd_journal); if (!store) { diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 24653164ff31..d58fa5ffe4cf 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -926,6 +926,10 @@ int FileStore::mkfs() if (ret) goto close_fsid_fd; + ret = write_meta("type", "filestore"); + if (ret) + goto close_fsid_fd; + dout(1) << "mkfs done in " << basedir << dendl; ret = 0; diff --git a/src/os/KeyValueStore.cc b/src/os/KeyValueStore.cc index 1d715222a875..481a8ac6f2c4 100644 --- a/src/os/KeyValueStore.cc +++ b/src/os/KeyValueStore.cc @@ -718,6 +718,10 @@ int KeyValueStore::mkfs() delete store; } + ret = write_meta("type", "keyvaluestore"); + if (ret < 0) + goto close_fsid_fd; + dout(1) << "mkfs done in " << basedir << dendl; ret = 0; diff --git a/src/os/MemStore.cc b/src/os/MemStore.cc index 678b16d2138f..f87e6287fb69 100644 --- a/src/os/MemStore.cc +++ b/src/os/MemStore.cc @@ -224,6 +224,10 @@ int MemStore::mkfs() if (r < 0) return r; + r = write_meta("type", "memstore"); + if (r < 0) + return r; + return 0; } -- 2.47.3