]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
blk/kerneldevice: fix invalid iterator usage after erase in discard_queued traversal
authorYite Gu <yitegu0@gmail.com>
Tue, 25 Mar 2025 03:05:09 +0000 (11:05 +0800)
committerYite Gu <yitegu0@gmail.com>
Tue, 25 Mar 2025 11:24:24 +0000 (19:24 +0800)
fixes: https://tracker.ceph.com/issues/70636

Signed-off-by: Yite Gu <guyite@bytedance.com>
src/blk/kernel/KernelDevice.cc

index 0f75eccca42d5db297b5f5534fea8b95028fc4a8..d30d50fcda2c00ef1b9301ec65db18649a196d2d 100644 (file)
@@ -808,11 +808,11 @@ void KernelDevice::_discard_thread(uint64_t tid)
       // It will also allow threads to finish in a timely manner.
       constexpr unsigned MAX_LOCAL_DISCARD = 32;
       unsigned count = 0;
-      for (auto p = discard_queued.begin();
-          p != discard_queued.end() && count < MAX_LOCAL_DISCARD;
-          ++p, ++count) {
-       discard_processing.insert(p.get_start(), p.get_len());
-       discard_queued.erase(p);
+      for (auto it = discard_queued.begin();
+           it != discard_queued.end() && count < MAX_LOCAL_DISCARD;
+           ++count) {
+        discard_processing.insert(it.get_start(), it.get_len());
+        it = discard_queued.erase(it);
       }
 
       // there are multiple active threads -> must use a counter instead of a flag