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;
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;
}
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;
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);
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));
}