From: Neha Ojha Date: Wed, 26 Jul 2017 21:58:43 +0000 (-0700) Subject: osd: Check whether journal is rotational or not X-Git-Tag: v12.1.3~93^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c1254b90765e10479c37d34b6a73fd7e46f18ab3;p=ceph.git osd: Check whether journal is rotational or not Signed-off-by: Neha Ojha --- diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index c88cf09c63af..97624c09fca6 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -1575,6 +1575,19 @@ public: return true; } + /** + * is_journal_rotational + * + * Check whether journal is backed by a rotational (HDD) or non-rotational + * (SSD) device. + * + * + * @return true for HDD, false for SSD + */ + virtual bool is_journal_rotational() { + return true; + } + virtual string get_default_device_class() { return is_rotational() ? "hdd" : "ssd"; } diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index ed94e60067c2..2a30e36e953d 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -2292,3 +2292,10 @@ int BlueFS::unlink(const string& dirname, const string& filename) _drop_link(file); return 0; } + +bool BlueFS::wal_is_rotational() +{ + if (!bdev[BDEV_WAL] || bdev[BDEV_WAL]->is_rotational()) + return true; + return false; +} diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index bb14ffc3697d..1b38a6ab1d49 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -370,6 +370,7 @@ public: int unlink(const string& dirname, const string& filename); int mkdir(const string& dirname); int rmdir(const string& dirname); + bool wal_is_rotational(); bool dir_exists(const string& dirname); int stat(const string& dirname, const string& filename, diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 1ad6c81e6c38..b01d6291bb30 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -4396,6 +4396,13 @@ bool BlueStore::is_rotational() return rotational; } +bool BlueStore::is_journal_rotational() +{ + assert(bluefs); + dout(10) << __func__ << " " << (int)bluefs->wal_is_rotational() << dendl; + return bluefs->wal_is_rotational(); +} + bool BlueStore::test_mount_in_use() { // most error conditions mean the mount is not in use (e.g., because diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 06a5418a64bf..d7a1980320eb 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2109,6 +2109,7 @@ public: bool allows_journal() override { return false; }; bool is_rotational() override; + bool is_journal_rotational() override; string get_default_device_class() override { string device_class; diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index f9b931a62861..b097a3c18a61 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -1157,6 +1157,30 @@ bool FileStore::is_rotational() return rotational; } +bool FileStore::is_journal_rotational() +{ + bool journal_rotational; + if (backend) { + journal_rotational = backend->is_journal_rotational(); + } else { + int fd = ::open(journalpath.c_str(), O_RDONLY); + if (fd < 0) + return true; + struct statfs st; + int r = ::fstatfs(fd, &st); + ::close(fd); + if (r < 0) { + return true; + } + create_backend(st.f_type); + journal_rotational = backend->is_journal_rotational(); + delete backend; + backend = NULL; + } + dout(10) << __func__ << " " << (int)journal_rotational << dendl; + return journal_rotational; +} + int FileStore::_detect_fs() { struct statfs st; diff --git a/src/os/filestore/FileStore.h b/src/os/filestore/FileStore.h index 7f2edb91a033..7af6863fed41 100644 --- a/src/os/filestore/FileStore.h +++ b/src/os/filestore/FileStore.h @@ -484,6 +484,7 @@ public: } bool is_rotational() override; + bool is_journal_rotational() override; void dump_perf_counters(Formatter *f) override { f->open_object_section("perf_counters"); @@ -837,6 +838,9 @@ protected: const string& get_basedir_path() { return filestore->basedir; } + const string& get_journal_path() { + return filestore->journalpath; + } const string& get_current_path() { return filestore->current_fn; } @@ -874,6 +878,7 @@ public: virtual bool has_fiemap() = 0; virtual bool has_seek_data_hole() = 0; virtual bool is_rotational() = 0; + virtual bool is_journal_rotational() = 0; virtual int do_fiemap(int fd, off_t start, size_t len, struct fiemap **pfiemap) = 0; virtual int clone_range(int from, int to, uint64_t srcoff, uint64_t len, uint64_t dstoff) = 0; virtual int set_alloc_hint(int fd, uint64_t hint) = 0; diff --git a/src/os/filestore/GenericFileStoreBackend.cc b/src/os/filestore/GenericFileStoreBackend.cc index 33680a4ca6b7..3ed4e4b5d941 100644 --- a/src/os/filestore/GenericFileStoreBackend.cc +++ b/src/os/filestore/GenericFileStoreBackend.cc @@ -87,6 +87,27 @@ GenericFileStoreBackend::GenericFileStoreBackend(FileStore *fs): } ::close(fd); } + // journal rotational? + { + // NOTE: the below won't work on btrfs; we'll assume rotational. + string fn = get_journal_path(); + int fd = ::open(fn.c_str(), O_RDONLY); + if (fd < 0) { + return; + } + char partition[PATH_MAX], devname[PATH_MAX]; + int r = get_device_by_fd(fd, partition, devname, sizeof(devname)); + if (r < 0) { + dout(1) << "unable to get journal device name for " + << get_journal_path() << ": " << cpp_strerror(r) << dendl; + m_journal_rotational = true; + } else { + m_journal_rotational = block_device_is_rotational(devname); + dout(20) << __func__ << " journal devname " << devname + << " journal rotational " << (int)m_journal_rotational << dendl; + } + ::close(fd); + } } int GenericFileStoreBackend::detect_features() diff --git a/src/os/filestore/GenericFileStoreBackend.h b/src/os/filestore/GenericFileStoreBackend.h index 8478067fa8fb..207c3d0d40c6 100644 --- a/src/os/filestore/GenericFileStoreBackend.h +++ b/src/os/filestore/GenericFileStoreBackend.h @@ -29,6 +29,7 @@ private: bool m_filestore_fsync_flushes_journal_data; bool m_filestore_splice; bool m_rotational = true; + bool m_journal_rotational = true; public: explicit GenericFileStoreBackend(FileStore *fs); ~GenericFileStoreBackend() override {} @@ -42,6 +43,9 @@ public: bool is_rotational() override { return m_rotational; } + bool is_journal_rotational() override { + return m_journal_rotational; + } int list_checkpoints(list& ls) override { return 0; } int create_checkpoint(const string& name, uint64_t *cid) override { return -EOPNOTSUPP; } int sync_checkpoint(uint64_t id) override { return -EOPNOTSUPP; } diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index d81907651b74..dd96a5b6cba3 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -2379,6 +2379,7 @@ int OSD::init() dout(2) << "init " << dev_path << " (looks like " << (store_is_rotational ? "hdd" : "ssd") << ")" << dendl; + dout(2) << "journal " << journal_path << dendl; assert(store); // call pre_init() first! store->set_cache_shards(get_num_op_shards()); @@ -2388,6 +2389,9 @@ int OSD::init() derr << "OSD:init: unable to mount object store" << dendl; return r; } + journal_is_rotational = store->is_journal_rotational(); + dout(2) << "journal looks like " << (journal_is_rotational ? "hdd" : "ssd") + << dendl; enable_disable_fuse(false); @@ -5889,6 +5893,7 @@ void OSD::_collect_metadata(map *pm) // backend (*pm)["osd_objectstore"] = store->get_type(); (*pm)["rotational"] = store_is_rotational ? "1" : "0"; + (*pm)["journal_rotational"] = journal_is_rotational ? "1" : "0"; (*pm)["default_device_class"] = store->get_default_device_class(); store->collect_metadata(pm); diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 33e5e3b27ac7..ccf318a39c07 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -1222,6 +1222,7 @@ protected: std::string dev_path, journal_path; bool store_is_rotational = true; + bool journal_is_rotational = true; ZTracer::Endpoint trace_endpoint; void create_logger();