osd: return EOPNOTSUPP on bad class or method name

Currently we return EIO, which isn't particularly informative.

Signed-off-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Sage Weil 2012-10-22 17:30:37 -07:00
parent 31260a3530
commit eed28daaf8
5 changed files with 56 additions and 2 deletions

View File

@ -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}

View File

@ -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

View File

@ -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;

View File

@ -1862,7 +1862,7 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& 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;
}

37
src/test/rados-api/cls.cc Normal file
View File

@ -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 <errno.h>
#include <map>
#include <sstream>
#include <string>
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));
}