From: Ilya Dryomov Date: Thu, 11 Apr 2024 16:56:15 +0000 (+0200) Subject: librbd: replace assert with error check in clone() X-Git-Tag: v19.1.1~206^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7969c81b57c8a6eebf436e8e20d0a4adca731793;p=ceph.git 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 (cherry picked from commit d6eafafac1fe782f6fa36488a4716e5b0bab9937) --- diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 3cd699b2c814..33b9dcfa5afa 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;