From: John Spray Date: Tue, 11 Aug 2015 12:17:22 +0000 (+0100) Subject: cls: add a filter to the hello class for testing X-Git-Tag: v9.1.0~287^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=60d51fc4a987cc9d92be9f0691c47f44f45fed6a;p=ceph.git cls: add a filter to the hello class for testing Signed-off-by: John Spray --- diff --git a/src/cls/hello/cls_hello.cc b/src/cls/hello/cls_hello.cc index 0d5c78b16176..a7bc9e865ff0 100644 --- a/src/cls/hello/cls_hello.cc +++ b/src/cls/hello/cls_hello.cc @@ -258,6 +258,35 @@ static int bad_writer(cls_method_context_t hctx, bufferlist *in, bufferlist *out } +class PGLSHelloFilter : public PGLSFilter { + string val; +public: + PGLSHelloFilter(bufferlist::iterator& params) { + ::decode(xattr, params); + ::decode(val, params); + } + virtual ~PGLSHelloFilter() {} + virtual bool filter(const hobject_t &obj, bufferlist& xattr_data, + bufferlist& outdata) + { + if (val.size() != xattr_data.length()) + return false; + + if (memcmp(val.c_str(), xattr_data.c_str(), val.size())) + return false; + + return true; + } +}; + + +PGLSFilter *hello_filter(bufferlist::iterator *q) +{ + assert(q); + return new PGLSHelloFilter(*q); +} + + /** * initialize class * @@ -304,4 +333,7 @@ void __cls_init() bad_reader, &h_bad_reader); cls_register_cxx_method(h_class, "bad_writer", CLS_METHOD_RD, bad_writer, &h_bad_writer); + + // A PGLS filter + cls_register_cxx_filter(h_class, "hello", hello_filter); }