From eed28daaf8927339c2ecae1b1b06c1b63678ab03 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 22 Oct 2012 17:30:37 -0700 Subject: [PATCH] osd: return EOPNOTSUPP on bad class or method name Currently we return EIO, which isn't particularly informative. Signed-off-by: Sage Weil --- src/Makefile.am | 6 ++++++ src/osd/ClassHandler.cc | 5 +++++ src/osd/OSD.cc | 8 +++++++- src/osd/ReplicatedPG.cc | 2 +- src/test/rados-api/cls.cc | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/test/rados-api/cls.cc diff --git a/src/Makefile.am b/src/Makefile.am index 10ba0df922dbf..dbb37df5fe22a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -875,6 +875,12 @@ test_rados_api_snapshots_LDADD = librados.la ${UNITTEST_STATIC_LDADD} test_rados_api_snapshots_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS} bin_DEBUGPROGRAMS += test_rados_api_snapshots +test_rados_api_cls_SOURCES = test/rados-api/cls.cc test/rados-api/test.cc +test_rados_api_cls_LDFLAGS = ${AM_LDFLAGS} +test_rados_api_cls_LDADD = librados.la ${UNITTEST_STATIC_LDADD} +test_rados_api_cls_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS} +bin_DEBUGPROGRAMS += test_rados_api_cls + test_rados_api_misc_SOURCES = test/rados-api/misc.cc test/rados-api/test.cc test_rados_api_misc_LDFLAGS = ${AM_LDFLAGS} test_rados_api_misc_LDADD = librados.la ${UNITTEST_STATIC_LDADD} diff --git a/src/osd/ClassHandler.cc b/src/osd/ClassHandler.cc index 35768c25272e8..5ff8e73309c1b 100644 --- a/src/osd/ClassHandler.cc +++ b/src/osd/ClassHandler.cc @@ -61,6 +61,11 @@ int ClassHandler::_load_class(ClassData *cls) cls->name.c_str()); dout(10) << "_load_class " << cls->name << " from " << fname << dendl; + struct stat st; + int r = ::stat(fname, &st); + if (r < 0) + return -errno; + cls->handle = dlopen(fname, RTLD_NOW); if (!cls->handle) { dout(0) << "_load_class could not open class " << fname diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 6b02cbaa48887..84104838605af 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -5693,8 +5693,14 @@ int OSD::init_op_flags(MOSDOp *op) ClassHandler::ClassData *cls; int r = class_handler->open_class(cname, &cls); - if (r) + if (r) { + dout(10) << "class " << cname << " open got " << cpp_strerror(r) << dendl; + if (r == -ENOENT) + r = -EOPNOTSUPP; + else + r = -EIO; return r; + } int flags = cls->get_method_flags(mname.c_str()); is_read = flags & CLS_METHOD_RD; is_write = flags & CLS_METHOD_WR; diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 153984d34a0b7..7a9f9e80f99a7 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -1862,7 +1862,7 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops) ClassHandler::ClassMethod *method = cls->get_method(mname.c_str()); if (!method) { dout(10) << "call method " << cname << "." << mname << " does not exist" << dendl; - result = -EINVAL; + result = -EOPNOTSUPP; break; } diff --git a/src/test/rados-api/cls.cc b/src/test/rados-api/cls.cc new file mode 100644 index 0000000000000..e20ee11e406bd --- /dev/null +++ b/src/test/rados-api/cls.cc @@ -0,0 +1,37 @@ +#include "include/rados/librados.h" +#include "include/rados/librados.hpp" +#include "test/rados-api/test.h" + +#include "gtest/gtest.h" +#include +#include +#include +#include + +using namespace librados; +using ceph::buffer; +using std::map; +using std::ostringstream; +using std::string; + +TEST(LibRadosCls, DNE) { + Rados cluster; + std::string pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_pool_pp(pool_name, cluster)); + IoCtx ioctx; + cluster.ioctx_create(pool_name.c_str(), ioctx); + + // create an object + string oid = "foo"; + bufferlist bl; + ASSERT_EQ(0, ioctx.write(oid, bl, bl.length(), 0)); + + // call a bogus class + ASSERT_EQ(-EOPNOTSUPP, ioctx.exec(oid, "doesnotexistasdfasdf", "method", bl, bl)); + + // call a bogus method on existent class + ASSERT_EQ(-EOPNOTSUPP, ioctx.exec(oid, "lock", "doesnotexistasdfasdfasdf", bl, bl)); + + ioctx.close(); + ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster)); +} -- 2.39.5