From: Jason Dillaman Date: Thu, 16 Nov 2017 21:46:11 +0000 (-0500) Subject: cls/rbd: added async version of get_snapcontext X-Git-Tag: v13.0.1~134^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9d1fc4d8ad6c7f27943aeabb049ccc6ef7066857;p=ceph.git cls/rbd: added async version of get_snapcontext Signed-off-by: Jason Dillaman --- diff --git a/src/cls/rbd/cls_rbd_client.cc b/src/cls/rbd/cls_rbd_client.cc index 026d1219d680..90c25c6bcc29 100644 --- a/src/cls/rbd/cls_rbd_client.cc +++ b/src/cls/rbd/cls_rbd_client.cc @@ -517,28 +517,42 @@ namespace librbd { op->exec("rbd", "snapshot_rename", bl); } - int get_snapcontext(librados::IoCtx *ioctx, const std::string &oid, - ::SnapContext *snapc) + void get_snapcontext_start(librados::ObjectReadOperation *op) { - bufferlist inbl, outbl; - - int r = ioctx->exec(oid, "rbd", "get_snapcontext", inbl, outbl); - if (r < 0) - return r; + bufferlist bl; + op->exec("rbd", "get_snapcontext", bl); + } + int get_snapcontext_finish(bufferlist::iterator *it, + ::SnapContext *snapc) + { try { - bufferlist::iterator iter = outbl.begin(); - ::decode(*snapc, iter); + ::decode(*snapc, *it); } catch (const buffer::error &err) { return -EBADMSG; } - - if (!snapc->is_valid()) + if (!snapc->is_valid()) { return -EBADMSG; - + } return 0; } + int get_snapcontext(librados::IoCtx *ioctx, const std::string &oid, + ::SnapContext *snapc) + { + librados::ObjectReadOperation op; + get_snapcontext_start(&op); + + bufferlist out_bl; + int r = ioctx->operate(oid, &op, &out_bl); + if (r < 0) { + return r; + } + + auto bl_it = out_bl.begin(); + return get_snapcontext_finish(&bl_it, snapc); + } + void snapshot_list_start(librados::ObjectReadOperation *op, const std::vector &ids) { for (auto snap_id : ids) { diff --git a/src/cls/rbd/cls_rbd_client.h b/src/cls/rbd/cls_rbd_client.h index 4afe4b1112ca..dd0b27d52bd8 100644 --- a/src/cls/rbd/cls_rbd_client.h +++ b/src/cls/rbd/cls_rbd_client.h @@ -112,6 +112,9 @@ namespace librbd { void snapshot_rename(librados::ObjectWriteOperation *op, snapid_t src_snap_id, const std::string &dst_name); + void get_snapcontext_start(librados::ObjectReadOperation *op); + int get_snapcontext_finish(bufferlist::iterator *it, + ::SnapContext *snapc); int get_snapcontext(librados::IoCtx *ioctx, const std::string &oid, ::SnapContext *snapc);