From 6ca9a21fb2b24bccddf0bfe0bd38aaa7dac210fc Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Thu, 6 Jan 2022 15:43:29 +0800 Subject: [PATCH] mds: fix seg fault in expire_recursive MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Range-based for should not be used when we are altering the container. Use iterator explicitly instead. Fixes: https://tracker.ceph.com/issues/53805 Signed-off-by: 胡玮文 (cherry picked from commit d48a2cf7e2481cf9758f2934464ec6d9c35d898b) --- src/mds/MDCache.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index dc4358d396277..b87121914d44b 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -3732,8 +3732,9 @@ bool MDCache::expire_recursive(CInode *in, expiremap &expiremap) return true; } - for (auto &it : subdir->items) { - CDentry *dn = it.second; + for (auto it = subdir->items.begin(); it != subdir->items.end();) { + CDentry *dn = it->second; + it++; CDentry::linkage_t *dnl = dn->get_linkage(); if (dnl->is_primary()) { CInode *tin = dnl->get_inode(); -- 2.39.5