]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cls: add a filter to the hello class for testing
authorJohn Spray <john.spray@redhat.com>
Tue, 11 Aug 2015 12:17:22 +0000 (13:17 +0100)
committerJohn Spray <john.spray@redhat.com>
Thu, 27 Aug 2015 13:13:46 +0000 (14:13 +0100)
Signed-off-by: John Spray <john.spray@redhat.com>
src/cls/hello/cls_hello.cc

index 0d5c78b161762d70cecd025018003d6fcbaca79e..a7bc9e865ff0c011d0b72d02d6d20d81b427e6d1 100644 (file)
@@ -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);
 }