From: Sage Weil Date: Thu, 1 Jun 2017 20:54:28 +0000 (-0400) Subject: os/filestore: is_rotational() X-Git-Tag: v12.1.0~249^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f697f09a6affe19d2a2ab2f371e06cff71721875;p=ceph.git os/filestore: is_rotational() Signed-off-by: Sage Weil --- diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index 1d527e0c12004..f01ae5cd20071 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -1123,6 +1123,30 @@ bool FileStore::test_mount_in_use() return inuse; } +bool FileStore::is_rotational() +{ + bool rotational; + if (backend) { + rotational = backend->is_rotational(); + } else { + int fd = ::open(basedir.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); + rotational = backend->is_rotational(); + delete backend; + backend = NULL; + } + dout(10) << __func__ << " " << (int)rotational << dendl; + return rotational; +} + int FileStore::_detect_fs() { struct statfs st; diff --git a/src/os/filestore/FileStore.h b/src/os/filestore/FileStore.h index 63523ec11fe15..88a1d3170d08b 100644 --- a/src/os/filestore/FileStore.h +++ b/src/os/filestore/FileStore.h @@ -481,6 +481,9 @@ public: bool needs_journal() override { return false; } + + bool is_rotational() override; + void dump_perf_counters(Formatter *f) override { f->open_object_section("perf_counters"); logger->dump_formatted(f, false); @@ -864,6 +867,7 @@ public: virtual int syncfs() = 0; virtual bool has_fiemap() = 0; virtual bool has_seek_data_hole() = 0; + virtual bool is_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 4821621f45661..33680a4ca6b79 100644 --- a/src/os/filestore/GenericFileStoreBackend.cc +++ b/src/os/filestore/GenericFileStoreBackend.cc @@ -39,6 +39,7 @@ #include "common/errno.h" #include "common/config.h" #include "common/sync_filesystem.h" +#include "common/blkdev.h" #include "common/SloppyCRCMap.h" #include "os/filestore/chain_xattr.h" @@ -63,7 +64,30 @@ GenericFileStoreBackend::GenericFileStoreBackend(FileStore *fs): m_filestore_fiemap(cct()->_conf->filestore_fiemap), m_filestore_seek_data_hole(cct()->_conf->filestore_seek_data_hole), m_filestore_fsync_flushes_journal_data(cct()->_conf->filestore_fsync_flushes_journal_data), - m_filestore_splice(cct()->_conf->filestore_splice) {} + m_filestore_splice(cct()->_conf->filestore_splice) +{ + // rotational? + { + // NOTE: the below won't work on btrfs; we'll assume rotational. + string fn = get_basedir_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 device name for " << get_basedir_path() << ": " + << cpp_strerror(r) << dendl; + m_rotational = true; + } else { + m_rotational = block_device_is_rotational(devname); + dout(20) << __func__ << " devname " << devname + << " rotational " << (int)m_rotational << dendl; + } + ::close(fd); + } +} int GenericFileStoreBackend::detect_features() { diff --git a/src/os/filestore/GenericFileStoreBackend.h b/src/os/filestore/GenericFileStoreBackend.h index df5d1acf30765..8478067fa8fb8 100644 --- a/src/os/filestore/GenericFileStoreBackend.h +++ b/src/os/filestore/GenericFileStoreBackend.h @@ -28,6 +28,7 @@ private: bool m_filestore_seek_data_hole; bool m_filestore_fsync_flushes_journal_data; bool m_filestore_splice; + bool m_rotational = true; public: explicit GenericFileStoreBackend(FileStore *fs); ~GenericFileStoreBackend() override {} @@ -38,6 +39,9 @@ public: int detect_features() override; int create_current() override; bool can_checkpoint() override { return false; } + bool is_rotational() override { + return m_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; }