@@ -716,24 +716,40 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
716716 opts.set (RBD_IMAGE_OPTION_STRIPE_UNIT, stripe_unit);
717717 opts.set (RBD_IMAGE_OPTION_STRIPE_COUNT, stripe_count);
718718
719- int r = clone (p_ioctx, nullptr , p_name, p_snap_name, c_ioctx, nullptr ,
720- c_name, opts, " " , " " );
719+ int r = clone (p_ioctx, nullptr , p_name, CEPH_NOSNAP, p_snap_name ,
720+ c_ioctx, nullptr , c_name, opts, " " , " " );
721721 opts.get (RBD_IMAGE_OPTION_ORDER, &order);
722722 *c_order = order;
723723 return r;
724724 }
725725
726726 int clone (IoCtx& p_ioctx, const char *p_id, const char *p_name,
727- const char *p_snap_name, IoCtx& c_ioctx, const char *c_id ,
728- const char *c_name, ImageOptions& c_opts,
727+ uint64_t p_snap_id, const char *p_snap_name, IoCtx& c_ioctx,
728+ const char *c_id, const char * c_name, ImageOptions& c_opts,
729729 const std::string &non_primary_global_image_id,
730730 const std::string &primary_mirror_uuid)
731731 {
732- ceph_assert ((p_id == nullptr ) ^ (p_name == nullptr ));
733-
734732 CephContext *cct = (CephContext *)p_ioctx.cct ();
735- if (p_snap_name == nullptr ) {
736- lderr (cct) << " image to be cloned must be a snapshot" << dendl;
733+ ldout (cct, 10 ) << __func__
734+ << " p_id=" << (p_id ?: " " )
735+ << " , p_name=" << (p_name ?: " " )
736+ << " , p_snap_id=" << p_snap_id
737+ << " , p_snap_name=" << (p_snap_name ?: " " )
738+ << " , c_id=" << (c_id ?: " " )
739+ << " , c_name=" << c_name
740+ << " , c_opts=" << c_opts
741+ << " , non_primary_global_image_id=" << non_primary_global_image_id
742+ << " , primary_mirror_uuid=" << primary_mirror_uuid
743+ << dendl;
744+
745+ if (((p_id == nullptr ) ^ (p_name == nullptr )) == 0 ) {
746+ lderr (cct) << " must specify either parent image id or parent image name"
747+ << dendl;
748+ return -EINVAL;
749+ }
750+ if (((p_snap_id == CEPH_NOSNAP) ^ (p_snap_name == nullptr )) == 0 ) {
751+ lderr (cct) << " must specify either parent snap id or parent snap name"
752+ << dendl;
737753 return -EINVAL;
738754 }
739755
@@ -766,10 +782,8 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
766782 clone_id = c_id;
767783 }
768784
769- ldout (cct, 10 ) << __func__ << " "
770- << " c_name=" << c_name << " , "
771- << " c_id= " << clone_id << " , "
772- << " c_opts=" << c_opts << dendl;
785+ ldout (cct, 10 ) << __func__ << " parent_id=" << parent_id
786+ << " , clone_id=" << clone_id << dendl;
773787
774788 ConfigProxy config{reinterpret_cast <CephContext *>(c_ioctx.cct ())->_conf };
775789 api::Config<>::apply_pool_overrides (c_ioctx, &config);
@@ -778,8 +792,8 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
778792
779793 C_SaferCond cond;
780794 auto *req = image::CloneRequest<>::create (
781- config, p_ioctx, parent_id, p_snap_name,
782- {cls::rbd::UserSnapshotNamespace{}}, CEPH_NOSNAP , c_ioctx, c_name,
795+ config, p_ioctx, parent_id, ( p_snap_name ?: " " ) ,
796+ {cls::rbd::UserSnapshotNamespace{}}, p_snap_id , c_ioctx, c_name,
783797 clone_id, c_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL,
784798 non_primary_global_image_id, primary_mirror_uuid,
785799 asio_engine.get_work_queue (), &cond);
0 commit comments