summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Dryomov <idryomov@gmail.com>2024-11-27 11:11:16 +0100
committerIlya Dryomov <idryomov@gmail.com>2024-12-18 12:44:36 +0100
commit97ed3fced13dd48520ec9c165537ff0bbc7cbb64 (patch)
treeca3bda6638d796d411fa555daac79cc7c8cffddc
parentMerge pull request #60635 from cah-hbaum/fix-subuser-creation-via-dashboard (diff)
downloadceph-97ed3fced13dd48520ec9c165537ff0bbc7cbb64.tar.xz
ceph-97ed3fced13dd48520ec9c165537ff0bbc7cbb64.zip
librbd: avoid data corruption on flatten when object map is inconsistent
By making flatten skip copyup in case the object is marked OBJECT_EXISTS or OBJECT_EXISTS_CLEAN, commit 40af4f87b64f ("librbd: flatten operation should use object map") introduced a critical regression. If the object map becomes inconsistent (e.g. because flatten gets interrupted by killing "rbd flatten" process or a client running on the clone crashes after updating the object map but before writing to the image), the following attempt to flatten would corrupt the clone if the copyup is actually still needed. By design, it's impossible to tell whether the object is "known to exist" based on the object map -- only telling whether the object is "known to NOT exist" is possible (i.e. only OBJECT_NONEXISTENT state is reliable). Negating OBJECT_NONEXISTENT tells that the object "may exist", not that the object is "known to exist". This is reflected in the name of object_may_exist() helper that was introduced together with the object map implementation. Something like object_may_not_exist() simply can't be constructed given the rest of librbd. This effectively reverts commits 4c86bccf07b8 ("librbd: add object_may_not_exist helper") and 40af4f87b64f ("librbd: flatten operation should use object map"). Fixes: https://tracker.ceph.com/issues/68998 Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
-rw-r--r--src/librbd/ObjectMap.cc26
-rw-r--r--src/librbd/ObjectMap.h1
-rw-r--r--src/librbd/operation/FlattenRequest.cc9
3 files changed, 0 insertions, 36 deletions
diff --git a/src/librbd/ObjectMap.cc b/src/librbd/ObjectMap.cc
index 65e3fc4a4c2..160bb4dcf9e 100644
--- a/src/librbd/ObjectMap.cc
+++ b/src/librbd/ObjectMap.cc
@@ -107,32 +107,6 @@ bool ObjectMap<I>::object_may_exist(uint64_t object_no) const
}
template <typename I>
-bool ObjectMap<I>::object_may_not_exist(uint64_t object_no) const
-{
- ceph_assert(ceph_mutex_is_locked(m_image_ctx.image_lock));
-
- // Fall back to default logic if object map is disabled or invalid
- if (!m_image_ctx.test_features(RBD_FEATURE_OBJECT_MAP,
- m_image_ctx.image_lock)) {
- return true;
- }
-
- bool flags_set;
- int r = m_image_ctx.test_flags(m_image_ctx.snap_id,
- RBD_FLAG_OBJECT_MAP_INVALID,
- m_image_ctx.image_lock, &flags_set);
- if (r < 0 || flags_set) {
- return true;
- }
-
- uint8_t state = (*this)[object_no];
- bool nonexistent = (state != OBJECT_EXISTS && state != OBJECT_EXISTS_CLEAN);
- ldout(m_image_ctx.cct, 20) << "object_no=" << object_no << " r="
- << nonexistent << dendl;
- return nonexistent;
-}
-
-template <typename I>
bool ObjectMap<I>::update_required(const ceph::BitVector<2>::Iterator& it,
uint8_t new_state) {
ceph_assert(ceph_mutex_is_locked(m_lock));
diff --git a/src/librbd/ObjectMap.h b/src/librbd/ObjectMap.h
index 35ea4cb88f9..5e7fcbbe9dd 100644
--- a/src/librbd/ObjectMap.h
+++ b/src/librbd/ObjectMap.h
@@ -65,7 +65,6 @@ public:
void close(Context *on_finish);
bool set_object_map(ceph::BitVector<2> &target_object_map);
bool object_may_exist(uint64_t object_no) const;
- bool object_may_not_exist(uint64_t object_no) const;
void aio_save(Context *on_finish);
void aio_resize(uint64_t new_size, uint8_t default_object_state,
diff --git a/src/librbd/operation/FlattenRequest.cc b/src/librbd/operation/FlattenRequest.cc
index 7bc34681924..8034637e8e6 100644
--- a/src/librbd/operation/FlattenRequest.cc
+++ b/src/librbd/operation/FlattenRequest.cc
@@ -49,15 +49,6 @@ public:
return -ERESTART;
}
- {
- std::shared_lock image_lock{image_ctx.image_lock};
- if (image_ctx.object_map != nullptr &&
- !image_ctx.object_map->object_may_not_exist(m_object_no)) {
- // can skip because the object already exists
- return 1;
- }
- }
-
if (!io::util::trigger_copyup(
&image_ctx, m_object_no, m_io_context, this)) {
// stop early if the parent went away - it just means