]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: Check whether journal is rotational or not
authorNeha Ojha <nojha@redhat.com>
Wed, 26 Jul 2017 21:58:43 +0000 (14:58 -0700)
committerNeha Ojha <nojha@redhat.com>
Wed, 2 Aug 2017 17:15:55 +0000 (10:15 -0700)
Signed-off-by: Neha Ojha <nojha@redhat.com>
src/os/ObjectStore.h
src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueFS.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/filestore/FileStore.cc
src/os/filestore/FileStore.h
src/os/filestore/GenericFileStoreBackend.cc
src/os/filestore/GenericFileStoreBackend.h
src/osd/OSD.cc
src/osd/OSD.h

index c88cf09c63af518db187968404694fe2634ee60a..97624c09fca651dea2d43d193dc4de986c41a27f 100644 (file)
@@ -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";
   }
index ed94e60067c230e90cd5a661fd2cbfc6032dffa9..2a30e36e953d11ea6f58738ea4e6078278eab85b 100644 (file)
@@ -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;
+}
index bb14ffc3697d035347d9b502aa8e93266b7441b6..1b38a6ab1d493840046c58a8bcdb0c7ff547f920 100644 (file)
@@ -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,
index 1ad6c81e6c389762b29f91beebad1742c294631f..b01d6291bb30d2cdca774f93847b51a629d91324 100644 (file)
@@ -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
index 06a5418a64bf9e835765802db9f7ddeaa4de2952..d7a1980320ebb16151784804f71124919f802977 100644 (file)
@@ -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;
index f9b931a62861640e0edf94820a22aaf9794a6ef4..b097a3c18a61ba812932f636680b0470ebae1109 100644 (file)
@@ -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;
index 7f2edb91a0339afb0e75af2bf3ae9648e58e2449..7af6863fed41eec7b7afa2065529bdcdba3ec667 100644 (file)
@@ -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;
index 33680a4ca6b79ad5ac36fc97dbbfbcb12722ee4f..3ed4e4b5d941bc7ef4aa939bc6c2a1505a886d27 100644 (file)
@@ -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()
index 8478067fa8fb86b72e13621e0bc29a60be359be3..207c3d0d40c63445bc3f4957f7caa91c109e3897 100644 (file)
@@ -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<string>& 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; }
index d81907651b74fdaef5c6f194b42d04c28a38b949..dd96a5b6cba39cf39f6861d55e0d1d408dc44ffb 100644 (file)
@@ -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<string,string> *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);
 
index 33e5e3b27ac79f405af76a6c46841a06ecff30dd..ccf318a39c07209c46fdcc238d1a9ce9767101d2 100644 (file)
@@ -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();