From 44a31d2b770ef016271f9285447c601921b9c838 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Fri, 1 Apr 2016 08:27:03 +0300 Subject: [PATCH] objclass: add method to list watchers Signed-off-by: Mykola Golub --- src/objclass/class_api.cc | 23 ++++++++++++++++++ src/objclass/objclass.h | 5 ++++ .../librados_test_stub/LibradosTestStub.cc | 24 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/src/objclass/class_api.cc b/src/objclass/class_api.cc index d0d0827690aaa..6752e5175bf70 100644 --- a/src/objclass/class_api.cc +++ b/src/objclass/class_api.cc @@ -6,6 +6,7 @@ #include "objclass/objclass.h" #include "osd/ReplicatedPG.h" +#include "osd/osd_types.h" #include "osd/ClassHandler.h" @@ -606,6 +607,28 @@ int cls_cxx_map_remove_key(cls_method_context_t hctx, const string &key) return (*pctx)->pg->do_osd_ops(*pctx, ops); } +int cls_cxx_list_watchers(cls_method_context_t hctx, + obj_list_watch_response_t *watchers) +{ + ReplicatedPG::OpContext **pctx = (ReplicatedPG::OpContext **)hctx; + vector nops(1); + OSDOp& op = nops[0]; + int r; + + op.op.op = CEPH_OSD_OP_LIST_WATCHERS; + r = (*pctx)->pg->do_osd_ops(*pctx, nops); + if (r < 0) + return r; + + bufferlist::iterator iter = op.outdata.begin(); + try { + ::decode(*watchers, iter); + } catch (buffer::error& err) { + return -EIO; + } + return 0; +} + int cls_gen_random_bytes(char *buf, int size) { return get_random_bytes(buf, size); diff --git a/src/objclass/objclass.h b/src/objclass/objclass.h index 8bc3a0a6eae95..49a97ddd8ef49 100644 --- a/src/objclass/objclass.h +++ b/src/objclass/objclass.h @@ -11,6 +11,8 @@ #include "common/hobject.h" #include "common/ceph_time.h" +struct obj_list_watch_response_t; + extern "C" { #endif @@ -181,6 +183,9 @@ extern int cls_cxx_map_write_header(cls_method_context_t hctx, bufferlist *inbl) extern int cls_cxx_map_remove_key(cls_method_context_t hctx, const string &key); extern int cls_cxx_map_update(cls_method_context_t hctx, bufferlist *inbl); +extern int cls_cxx_list_watchers(cls_method_context_t hctx, + obj_list_watch_response_t *watchers); + /* utility functions */ extern int cls_gen_random_bytes(char *buf, int size); extern int cls_gen_rand_base64(char *dest, int size); /* size should be the required string size + 1 */ diff --git a/src/test/librados_test_stub/LibradosTestStub.cc b/src/test/librados_test_stub/LibradosTestStub.cc index 7176ba470250d..dac71e948e927 100644 --- a/src/test/librados_test_stub/LibradosTestStub.cc +++ b/src/test/librados_test_stub/LibradosTestStub.cc @@ -15,6 +15,7 @@ #include "test/librados_test_stub/TestRadosClient.h" #include "test/librados_test_stub/TestMemRadosClient.h" #include "objclass/objclass.h" +#include "osd/osd_types.h" #include #include #include @@ -1159,6 +1160,29 @@ int cls_cxx_write_full(cls_method_context_t hctx, bufferlist *inbl) { return ctx->io_ctx_impl->write_full(ctx->oid, *inbl, ctx->snapc); } +int cls_cxx_list_watchers(cls_method_context_t hctx, + obj_list_watch_response_t *watchers) { + librados::TestClassHandler::MethodContext *ctx = + reinterpret_cast(hctx); + + std::list obj_watchers; + int r = ctx->io_ctx_impl->list_watchers(ctx->oid, &obj_watchers); + if (r < 0) { + return r; + } + + for (auto &w : obj_watchers) { + watch_item_t watcher; + watcher.name = entity_name_t::CLIENT(w.watcher_id); + watcher.cookie = w.cookie; + watcher.timeout_seconds = w.timeout_seconds; + watcher.addr.parse(w.addr, 0); + watchers->entries.push_back(watcher); + } + + return 0; +} + int cls_log(int level, const char *format, ...) { int size = 256; va_list ap; -- 2.39.5