]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: return EOPNOTSUPP on bad class or method name
authorSage Weil <sage@inktank.com>
Tue, 23 Oct 2012 00:30:37 +0000 (17:30 -0700)
committerSage Weil <sage@inktank.com>
Tue, 23 Oct 2012 00:39:47 +0000 (17:39 -0700)
Currently we return EIO, which isn't particularly informative.

Signed-off-by: Sage Weil <sage@inktank.com>
src/Makefile.am
src/osd/ClassHandler.cc
src/osd/OSD.cc
src/osd/ReplicatedPG.cc
src/test/rados-api/cls.cc [new file with mode: 0644]

index 10ba0df922dbfd42be5699045a83a33a9457547c..dbb37df5fe22addcd29166db7fa2b555f17fb04b 100644 (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}
index 35768c25272e82c3d9642ef24498796629e65c70..5ff8e73309c1b4ad05cdd94cfb9ae090a4ac1c58 100644 (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
index 6b02cbaa48887037f8da275a63619b505dd52c5a..84104838605af77eeb731adce87ef5c3178fa246 100644 (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;
index 153984d34a0b7337c97211c8426fe216aa69a03c..7a9f9e80f99a7828bcf9849d615b62d26f9ea760 100644 (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;
        }
 
diff --git a/src/test/rados-api/cls.cc b/src/test/rados-api/cls.cc
new file mode 100644 (file)
index 0000000..e20ee11
--- /dev/null
@@ -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));
+}