From f0d1816182d32ba1a8b4d915981919a9eabbb577 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 24 Sep 2019 09:17:52 -0500 Subject: [PATCH] cls/hello,ceph_test_cls_hello: test returning data from a mutation Signed-off-by: Sage Weil --- src/cls/hello/cls_hello.cc | 21 ++++++++++----------- src/test/cls_hello/test_cls_hello.cc | 21 +++++++++++++++++++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/cls/hello/cls_hello.cc b/src/cls/hello/cls_hello.cc index fd4e9ba4b6c..880c97b122d 100644 --- a/src/cls/hello/cls_hello.cc +++ b/src/cls/hello/cls_hello.cc @@ -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); diff --git a/src/test/cls_hello/test_cls_hello.cc b/src/test/cls_hello/test_cls_hello.cc index 7cf30125f0b..f37df635bbe 100644 --- a/src/test/cls_hello/test_cls_hello.cc +++ b/src/test/cls_hello/test_cls_hello.cc @@ -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)); } -- 2.39.5