]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/hello,ceph_test_cls_hello: test returning data from a mutation
authorSage Weil <sage@redhat.com>
Tue, 24 Sep 2019 14:17:52 +0000 (09:17 -0500)
committerSage Weil <sage@redhat.com>
Wed, 25 Sep 2019 16:06:10 +0000 (11:06 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/cls/hello/cls_hello.cc
src/test/cls_hello/test_cls_hello.cc

index fd4e9ba4b6c1de2e8a6837bebe65e21fcd4905a5..880c97b122d93bb703d345c1b13d83bd5dc4d9a9 100644 (file)
@@ -139,7 +139,7 @@ static int record_hello(cls_method_context_t hctx, bufferlist *in, bufferlist *o
   return 0;
 }
 
-static int writes_dont_return_data(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
+static int write_return_data(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
 {
   // make some change to the object
   bufferlist attrbl;
@@ -156,14 +156,13 @@ static int writes_dont_return_data(cls_method_context_t hctx, bufferlist *in, bu
     return -EINVAL;
   }
 
-  // try to return some data.  note that this *won't* reach the
-  // client!  see the matching test case in test_cls_hello.cc.
-#warning "disable this return data temporarily"
-  //out->append("you will never see this");
+  // try to return some data.  note that this will only reach the client
+  // if the client has set the CEPH_OSD_FLAG_RETURNVEC flag on the op.
+  out->append("you might see this");
 
-  // if we try to return anything > 0 here the client will see 0.
-  //return 42;
-  return 0;
+  // client will only see a >0 value with the RETURNVEC flag is set; otherwise
+  // they will see 0.
+  return 42;
 }
 
 
@@ -299,7 +298,7 @@ CLS_INIT(hello)
   cls_method_handle_t h_say_hello;
   cls_method_handle_t h_record_hello;
   cls_method_handle_t h_replay;
-  cls_method_handle_t h_writes_dont_return_data;
+  cls_method_handle_t h_write_return_data;
   cls_method_handle_t h_turn_it_to_11;
   cls_method_handle_t h_bad_reader;
   cls_method_handle_t h_bad_writer;
@@ -321,9 +320,9 @@ CLS_INIT(hello)
   cls_register_cxx_method(h_class, "record_hello",
                          CLS_METHOD_WR | CLS_METHOD_PROMOTE,
                          record_hello, &h_record_hello);
-  cls_register_cxx_method(h_class, "writes_dont_return_data",
+  cls_register_cxx_method(h_class, "write_return_data",
                          CLS_METHOD_WR,
-                         writes_dont_return_data, &h_writes_dont_return_data);
+                         write_return_data, &h_write_return_data);
   cls_register_cxx_method(h_class, "replay",
                          CLS_METHOD_RD,
                          replay, &h_replay);
index 7cf30125f0b3e98b25001654b91abc82a1f404f2..f37df635bbe7efdde0402f77ae1fb93bc508908b 100644 (file)
@@ -84,17 +84,34 @@ TEST(ClsHello, WriteReturnData) {
   IoCtx ioctx;
   cluster.ioctx_create(pool_name.c_str(), ioctx);
 
+  // this will return nothing -- not flag set
   bufferlist in, out;
-  ASSERT_EQ(0, ioctx.exec("myobject", "hello", "writes_dont_return_data", in, out));
+  ASSERT_EQ(0, ioctx.exec("myobject", "hello", "write_return_data", in, out));
   ASSERT_EQ(std::string(), std::string(out.c_str(), out.length()));
 
+  // this will return return an error due to unexpected input
   char buf[4096];
   memset(buf, 1, sizeof(buf));
   in.append(buf, sizeof(buf));
-  ASSERT_EQ(-EINVAL, ioctx.exec("myobject2", "hello", "writes_dont_return_data", in, out));
+  ASSERT_EQ(-EINVAL, ioctx.exec("myobject2", "hello", "write_return_data", in, out));
   ASSERT_EQ(std::string("too much input data!"), std::string(out.c_str(), out.length()));
   ASSERT_EQ(-ENOENT, ioctx.getxattr("myobject2", "foo", out));
 
+  // this *will* return data due to the RETURNVEC flag
+  in.clear();
+  out.clear();
+  int rval;
+  ObjectWriteOperation o;
+  o.exec("hello", "write_return_data", in, &out, &rval);
+  librados::AioCompletion *completion = cluster.aio_create_completion();
+  ASSERT_EQ(0, ioctx.aio_operate("foo", completion, &o,
+                                librados::OPERATION_RETURNVEC));
+  completion->wait_for_safe();
+  ASSERT_EQ(42, completion->get_return_value());
+  ASSERT_EQ(42, rval);
+  out.hexdump(std::cout);
+  ASSERT_EQ("you might see this", std::string(out.c_str(), out.length()));
+
   ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
 }