]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/bluefs: Add tags and comments for locks
authorAdam Kupczyk <akupczyk@redhat.com>
Tue, 4 Jan 2022 18:03:16 +0000 (19:03 +0100)
committerIgor Fedotov <igor.fedotov@croit.io>
Tue, 27 Jun 2023 11:34:35 +0000 (14:34 +0300)
Add function tags and comments related to locks.
Fixed locking graph documentation.

Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
(cherry picked from commit a091ea714d546d91b10484bcac59d6a356591be6)

 Conflicts:
src/os/bluestore/BlueFS.h
 (Lacking backport for https://github.com/ceph/ceph/pull/41557/)

src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueFS.h

index 1b63bc81cc22c68206bd3ff6a7c25c9dd5b52d72..cde46201eb1650e0c77b0b1a50e9bd684deb7fcd 100644 (file)
@@ -2176,13 +2176,13 @@ uint64_t BlueFS::_estimate_log_size_N()
   return round_up_to(size, super.block_size);
 }
 
-void BlueFS::compact_log()
+void BlueFS::compact_log()/*_LNF_LD_NF_D*/
 {
   if (!cct->_conf->bluefs_replay_recovery_disable_compact) {
     if (cct->_conf->bluefs_compact_log_sync) {
       _compact_log_sync_LNF_LD();
     } else {
-      _compact_log_async_LD_NF_D();
+      _compact_log_async_LD_LNF_D();
     }
   }
 }
@@ -2435,7 +2435,7 @@ void BlueFS::_rewrite_log_and_layout_sync_LNF_LD(bool allocate_with_fallback,
  * 8. Release the old log space.  Clean up.
  */
 
-void BlueFS::_compact_log_async_LD_NF_D() //also locks FW for new_writer
+void BlueFS::_compact_log_async_LD_LNF_D() //also locks FW for new_writer
 {
   dout(10) << __func__ << dendl;
   // only one compaction allowed at one time
@@ -2968,7 +2968,8 @@ int BlueFS::_signal_dirty_to_log_D(FileWriter *h)
   return 0;
 }
 
-void BlueFS::flush_range(FileWriter *h, uint64_t offset, uint64_t length) {
+void BlueFS::flush_range(FileWriter *h, uint64_t offset, uint64_t length)/*_WF*/
+{
   std::unique_lock hl(h->lock);
   _flush_range_F(h, offset, length);
 }
@@ -3143,7 +3144,7 @@ void BlueFS::_wait_for_aio(FileWriter *h)
 }
 #endif
 
-void BlueFS::append_try_flush(FileWriter *h, const char* buf, size_t len)
+void BlueFS::append_try_flush(FileWriter *h, const char* buf, size_t len)/*_WF_LNF_NF_LD_D*/
 {
   bool flushed_sum = false;
   {
@@ -3175,7 +3176,7 @@ void BlueFS::append_try_flush(FileWriter *h, const char* buf, size_t len)
   }
 }
 
-void BlueFS::flush(FileWriter *h, bool force)
+void BlueFS::flush(FileWriter *h, bool force)/*_WF_LNF_NF_LD_D*/
 {
   bool flushed = false;
   int r;
@@ -3241,7 +3242,7 @@ uint64_t BlueFS::_flush_special(FileWriter *h)
   return new_data;
 }
 
-int BlueFS::truncate(FileWriter *h, uint64_t offset)
+int BlueFS::truncate(FileWriter *h, uint64_t offset)/*_WF_L*/
 {
   std::lock_guard hl(h->lock);
   dout(10) << __func__ << " 0x" << std::hex << offset << std::dec
@@ -3283,7 +3284,7 @@ int BlueFS::truncate(FileWriter *h, uint64_t offset)
   return 0;
 }
 
-int BlueFS::fsync(FileWriter *h)
+int BlueFS::fsync(FileWriter *h)/*_WF_WD_WLD_WLNF_WNF*/
 {
   std::unique_lock hl(h->lock);
   uint64_t old_dirty_seq = 0;
@@ -3463,7 +3464,7 @@ int BlueFS::_allocate(uint8_t id, uint64_t len,
   return 0;
 }
 
-int BlueFS::preallocate(FileRef f, uint64_t off, uint64_t len)
+int BlueFS::preallocate(FileRef f, uint64_t off, uint64_t len)/*_LF*/
 {
   std::lock_guard ll(log.lock);
   std::lock_guard fl(f->lock);
@@ -3491,7 +3492,7 @@ int BlueFS::preallocate(FileRef f, uint64_t off, uint64_t len)
   return 0;
 }
 
-void BlueFS::sync_metadata(bool avoid_compact)
+void BlueFS::sync_metadata(bool avoid_compact)/*_LNF_NF_LD_D*/
 {
   bool can_skip_flush;
   {
@@ -3523,7 +3524,7 @@ void BlueFS::_maybe_compact_log_LNF_NF_LD_D()
     if (cct->_conf->bluefs_compact_log_sync) {
       _compact_log_sync_LNF_LD();
     } else {
-      _compact_log_async_LD_NF_D();
+      _compact_log_async_LD_LNF_D();
     }
   }
 }
@@ -3532,7 +3533,7 @@ int BlueFS::open_for_write(
   std::string_view dirname,
   std::string_view filename,
   FileWriter **h,
-  bool overwrite)
+  bool overwrite)/*_N_LD*/
 {
   FileRef file;
   bool create = false;
@@ -3686,7 +3687,7 @@ int BlueFS::open_for_read(
   std::string_view dirname,
   std::string_view filename,
   FileReader **h,
-  bool random)
+  bool random)/*_N*/
 {
   std::lock_guard nl(nodes.lock);
   dout(10) << __func__ << " " << dirname << "/" << filename
@@ -3715,7 +3716,7 @@ int BlueFS::open_for_read(
 
 int BlueFS::rename(
   std::string_view old_dirname, std::string_view old_filename,
-  std::string_view new_dirname, std::string_view new_filename)
+  std::string_view new_dirname, std::string_view new_filename)/*_LND*/
 {
   std::lock_guard ll(log.lock);
   std::lock_guard nl(nodes.lock);
@@ -3763,7 +3764,7 @@ int BlueFS::rename(
   return 0;
 }
 
-int BlueFS::mkdir(std::string_view dirname)
+int BlueFS::mkdir(std::string_view dirname)/*_LN*/
 {
   std::lock_guard ll(log.lock);
   std::lock_guard nl(nodes.lock);
@@ -3778,7 +3779,7 @@ int BlueFS::mkdir(std::string_view dirname)
   return 0;
 }
 
-int BlueFS::rmdir(std::string_view dirname)
+int BlueFS::rmdir(std::string_view dirname)/*_LN*/
 {
   std::lock_guard ll(log.lock);
   std::lock_guard nl(nodes.lock);
@@ -3798,7 +3799,7 @@ int BlueFS::rmdir(std::string_view dirname)
   return 0;
 }
 
-bool BlueFS::dir_exists(std::string_view dirname)
+bool BlueFS::dir_exists(std::string_view dirname)/*_N*/
 {
   std::lock_guard nl(nodes.lock);
   map<string,DirRef>::iterator p = nodes.dir_map.find(dirname);
@@ -3808,7 +3809,7 @@ bool BlueFS::dir_exists(std::string_view dirname)
 }
 
 int BlueFS::stat(std::string_view dirname, std::string_view filename,
-                uint64_t *size, utime_t *mtime)
+                uint64_t *size, utime_t *mtime)/*_N*/
 {
   std::lock_guard nl(nodes.lock);
   dout(10) << __func__ << " " << dirname << "/" << filename << dendl;
@@ -3836,7 +3837,7 @@ int BlueFS::stat(std::string_view dirname, std::string_view filename,
 }
 
 int BlueFS::lock_file(std::string_view dirname, std::string_view filename,
-                     FileLock **plock)
+                     FileLock **plock)/*_LN*/
 {
   std::lock_guard ll(log.lock);
   std::lock_guard nl(nodes.lock);
@@ -3876,7 +3877,7 @@ int BlueFS::lock_file(std::string_view dirname, std::string_view filename,
   return 0;
 }
 
-int BlueFS::unlock_file(FileLock *fl)
+int BlueFS::unlock_file(FileLock *fl)/*_N*/
 {
   std::lock_guard nl(nodes.lock);
   dout(10) << __func__ << " " << fl << " on " << fl->file->fnode << dendl;
@@ -3886,7 +3887,7 @@ int BlueFS::unlock_file(FileLock *fl)
   return 0;
 }
 
-int BlueFS::readdir(std::string_view dirname, vector<string> *ls)
+int BlueFS::readdir(std::string_view dirname, vector<string> *ls)/*_N*/
 {
   // dirname may contain a trailing /
   if (!dirname.empty() && dirname.back() == '/') {
@@ -3918,7 +3919,7 @@ int BlueFS::readdir(std::string_view dirname, vector<string> *ls)
   return 0;
 }
 
-int BlueFS::unlink(std::string_view dirname, std::string_view filename)
+int BlueFS::unlink(std::string_view dirname, std::string_view filename)/*_LND*/
 {
   std::lock_guard ll(log.lock);
   std::lock_guard nl(nodes.lock);
index 2ffb2b8bb780cd9fc10bbc836411bb6d08042b9c..614575fc5c487d7950cd71df1c975d8b6eb70ba0 100644 (file)
@@ -442,7 +442,7 @@ private:
                                           uint64_t capture_before_seq);
 
   void _compact_log_sync_LNF_LD();
-  void _compact_log_async_LD_NF_D();
+  void _compact_log_async_LD_LNF_D();
 
   void _rewrite_log_and_layout_sync_LNF_LD(bool allocate_with_fallback,
                                    int super_dev,
@@ -574,8 +574,6 @@ public:
 
   /// sync any uncommitted state to disk
   void sync_metadata(bool avoid_compact);
-  /// test and compact log, if necessary
-  void _maybe_compact_log_LNF_NF_LD_D();
 
   void set_volume_selector(BlueFSVolumeSelector* s) {
     vselector.reset(s);
@@ -619,11 +617,6 @@ public:
   void invalidate_cache(FileRef f, uint64_t offset, uint64_t len);
   int preallocate(FileRef f, uint64_t offset, uint64_t len);
   int truncate(FileWriter *h, uint64_t offset);
-  int _do_replay_recovery_read(FileReader *log,
-                              size_t log_pos,
-                              size_t read_offset,
-                              size_t read_len,
-                              bufferlist* bl);
 
   size_t probe_alloc_avail(int dev, uint64_t alloc_size);
 
@@ -640,6 +633,14 @@ private:
   int read(uint8_t ndev, uint64_t off, uint64_t len,
           ceph::buffer::list *pbl, IOContext *ioc, bool buffered);
   int read_random(uint8_t ndev, uint64_t off, uint64_t len, char *buf, bool buffered);
+
+  /// test and compact log, if necessary
+  void _maybe_compact_log_LNF_NF_LD_D();
+  int _do_replay_recovery_read(FileReader *log,
+                              size_t log_pos,
+                              size_t read_offset,
+                              size_t read_len,
+                              bufferlist* bl);
 };
 
 class OriginalVolumeSelector : public BlueFSVolumeSelector {
@@ -694,15 +695,15 @@ public:
  * Vertices - Locks. Edges (directed) - locking progression.
  * Edge A->B exist if last taken lock was A and next taken lock is B.
  * 
- * Column represents last lock taken.
- * Row represents next lock taken.
+ * Row represents last lock taken.
+ * Column represents next lock taken.
  *
- *     >        | W | L | D | N | F
+ *     >        | W | L | N | D | F
  * -------------|---|---|---|---|---
- * FileWriter W |   | > | > |   | >
+ * FileWriter W |   | > | > | > | >
  * log        L |       | > | > | >
+ * nodes      N |           | > | >
  * dirty      D |           |   | >
- * nodes      N |               | >
  * File       F |
  * 
  * Claim: Deadlock is possible IFF graph contains cycles.