From d6eafafac1fe782f6fa36488a4716e5b0bab9937 Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Thu, 11 Apr 2024 18:56:15 +0200 Subject: [PATCH] librbd: replace assert with error check in clone() With an error check for p_snap_name, it doesn't make much sense to crash if "either p_id or p_name" contract is violated. Replace the assert with a similar error check. Signed-off-by: Ilya Dryomov --- src/librbd/internal.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 3cd699b2c81..33b9dcfa5af 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -729,9 +729,13 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { const std::string &non_primary_global_image_id, const std::string &primary_mirror_uuid) { - ceph_assert((p_id == nullptr) ^ (p_name == nullptr)); - CephContext *cct = (CephContext *)p_ioctx.cct(); + + if (((p_id == nullptr) ^ (p_name == nullptr)) == 0) { + lderr(cct) << "must specify either parent image id or parent image name" + << dendl; + return -EINVAL; + } if (p_snap_name == nullptr) { lderr(cct) << "image to be cloned must be a snapshot" << dendl; return -EINVAL; -- 2.39.5