From 7e31e8b3014f54a309a02be9a1ad47758df69623 Mon Sep 17 00:00:00 2001 From: Dan van der Ster Date: Thu, 24 Feb 2022 09:42:00 +0100 Subject: [PATCH] osd: require osd_pg_max_concurrent_snap_trims > 0 If osd_pg_max_concurrent_snap_trims is zero, we mistakenly clear the snaptrim queue. Require it to be > 0. Fixes: https://tracker.ceph.com/issues/54396 Signed-off-by: Dan van der Ster (cherry picked from commit 29545b617b3b0324f9b0b20e032e3e38557115eb) --- src/common/options/global.yaml.in | 1 + src/osd/PrimaryLogPG.cc | 3 +++ src/osd/SnapMapper.cc | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/src/common/options/global.yaml.in b/src/common/options/global.yaml.in index c0e3b014d9a..7a4e581fbec 100644 --- a/src/common/options/global.yaml.in +++ b/src/common/options/global.yaml.in @@ -2817,6 +2817,7 @@ options: type: uint level: advanced default: 2 + min: 1 with_legacy: true # max number of trimming pgs - name: osd_max_trimming_pgs diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index b4b8f00ba8b..dc2160356a8 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -15594,6 +15594,9 @@ boost::statechart::result PrimaryLogPG::AwaitAsyncWork::react(const DoSnapWork&) vector to_trim; unsigned max = pg->cct->_conf->osd_pg_max_concurrent_snap_trims; + // we need to look for at least 1 snaptrim, otherwise we'll misinterpret + // the ENOENT below and erase snap_to_trim. + ceph_assert(max > 0); to_trim.reserve(max); int r = pg->snap_mapper.get_next_objects_to_trim( snap_to_trim, diff --git a/src/osd/SnapMapper.cc b/src/osd/SnapMapper.cc index 912c539b8bc..07c6f57c78a 100644 --- a/src/osd/SnapMapper.cc +++ b/src/osd/SnapMapper.cc @@ -322,6 +322,10 @@ int SnapMapper::get_next_objects_to_trim( { ceph_assert(out); ceph_assert(out->empty()); + + // if max would be 0, we return ENOENT and the caller would mistakenly + // trim the snaptrim queue + ceph_assert(max > 0); int r = 0; for (set::iterator i = prefixes.begin(); i != prefixes.end() && out->size() < max && r == 0; -- 2.47.3