-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
objclass-sdk: create SDK for Ceph object classes
Creates an installable version of "src/rados/objclass.h" that allows object classes to be compiled outside of the Ceph tree. cls_sdk is an example of such an object class. Signed-off-by: Neha Ojha <nojha@redhat.com>
- Loading branch information
Showing
15 changed files
with
1,776 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
usr/include/rados/objclass.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
=========================== | ||
SDK for Ceph Object Classes | ||
=========================== | ||
|
||
`Ceph` can be extended by creating shared object classes called `Ceph Object | ||
Classes`. The existing framework to build these object classes has dependencies | ||
on the internal functionality of `Ceph`, which restricts users to build object | ||
classes within the tree. The aim of this project is to create an independent | ||
object class interface, which can be used to build object classes outside the | ||
`Ceph` tree. This allows us to have two types of object classes, 1) those that | ||
have in-tree dependencies and reside in the tree and 2) those that can make use | ||
of the `Ceph Object Class SDK framework` and can be built outside of the `Ceph` | ||
tree because they do not depend on any internal implementation of `Ceph`. This | ||
project decouples object class development from Ceph and encourages creation | ||
and distribution of object classes as packages. | ||
|
||
In order to demonstrate the use of this framework, we have two examples. The | ||
first one is called ``cls_sdk``, which is a very simple object class that | ||
makes use of the SDK framework. This object class resides in the ``src/cls`` | ||
directory. | ||
|
||
The second example is a project called, `ZLog`, which is a strongly | ||
consistent shared-log designed to run at high-performance over distributed | ||
storage systems. `ZLog <https://github.com/noahdesu/zlog>`_ makes use of | ||
`Ceph` as a storage backend to provide high performance and reliability. | ||
`ZLog` was earlier dependent on `Ceph's` ``encoding.h`` interface. Now, this | ||
dependency has been eliminated by means of `Google Protocol Buffers`. | ||
Therefore, in order to use `ZLog` with `Ceph's Object Class SDK framework`, | ||
users need to setup the appropriate `Protobuf Packages | ||
<https://github.com/google/protobuf>`_, based on their platform. | ||
|
||
|
||
Installing objclass.h | ||
--------------------- | ||
|
||
The object class interface that enables out-of-tree development of object | ||
classes resides in ``src/include/rados/`` and gets installed with `Ceph` | ||
installation. It can be found in ``<prefix>/include/rados``. :: | ||
|
||
ls /usr/local/include/rados | ||
|
||
Using the SDK example | ||
--------------------- | ||
|
||
The ``cls_sdk`` object class resides in ``src/cls/sdk/``. This gets built and | ||
loaded into Ceph, with the Ceph build process. You can run the | ||
``ceph_test_cls_sdk`` unittest to test this class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* This is an example RADOS object class built using only the Ceph SDK interface. | ||
*/ | ||
#include "include/rados/objclass.h" | ||
|
||
CLS_VER(1,0) | ||
CLS_NAME(sdk) | ||
|
||
cls_handle_t h_class; | ||
cls_method_handle_t h_test_coverage_write; | ||
cls_method_handle_t h_test_coverage_replay; | ||
|
||
/** | ||
* test_coverage_write - a "write" method that creates an object | ||
* | ||
* This method modifies the object by making multiple write calls (write, | ||
* setxattr and set_val). | ||
*/ | ||
static int test_coverage_write(cls_method_context_t hctx, bufferlist *in, bufferlist *out) | ||
{ | ||
// create the object | ||
int ret = cls_cxx_create(hctx, false); | ||
if (ret < 0) { | ||
CLS_LOG(0, "ERROR: %s(): cls_cxx_create returned %d", __func__, ret); | ||
return ret; | ||
} | ||
|
||
uint64_t size; | ||
// get the size of the object | ||
ret = cls_cxx_stat(hctx, &size, NULL); | ||
if (ret < 0) | ||
return ret; | ||
|
||
std::string c = "test"; | ||
bufferlist bl; | ||
bl.append(c); | ||
|
||
// write to the object | ||
ret = cls_cxx_write(hctx, 0, bl.length(), &bl); | ||
if (ret < 0) | ||
return ret; | ||
|
||
uint64_t new_size; | ||
// get the new size of the object | ||
ret = cls_cxx_stat(hctx, &new_size, NULL); | ||
if (ret < 0) | ||
return ret; | ||
|
||
// make some change to the xattr | ||
ret = cls_cxx_setxattr(hctx, "foo", &bl); | ||
if (ret < 0) | ||
return ret; | ||
|
||
// make some change to the omap | ||
ret = cls_cxx_map_set_val(hctx, "foo", &bl); | ||
if (ret < 0) | ||
return ret; | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* test_coverage_replay - a "read" method to retrieve previously written data | ||
* | ||
* This method reads the object by making multiple read calls (read, getxattr | ||
* and get_val). It also removes the object after reading. | ||
*/ | ||
|
||
static int test_coverage_replay(cls_method_context_t hctx, bufferlist *in, bufferlist *out) | ||
{ | ||
CLS_LOG(0, "reading already written object"); | ||
uint64_t size; | ||
// get the size of the object | ||
int ret = cls_cxx_stat(hctx, &size, NULL); | ||
if (ret < 0) | ||
return ret; | ||
|
||
bufferlist bl; | ||
// read the object entry | ||
ret = cls_cxx_read(hctx, 0, size, &bl); | ||
if (ret < 0) | ||
return ret; | ||
|
||
// if the size is incorrect | ||
if (bl.length() != size) | ||
return -EIO; | ||
|
||
bl.clear(); | ||
|
||
// read xattr entry | ||
ret = cls_cxx_getxattr(hctx, "foo", &bl); | ||
if (ret < 0) | ||
return ret; | ||
|
||
// if the size is incorrect | ||
if (bl.length() != size) | ||
return -EIO; | ||
|
||
bl.clear(); | ||
|
||
// read omap entry | ||
ret = cls_cxx_map_get_val(hctx, "foo", &bl); | ||
if (ret < 0) | ||
return ret; | ||
|
||
// if the size is incorrect | ||
if (bl.length() != size) | ||
return -EIO; | ||
|
||
// remove the object | ||
ret = cls_cxx_remove(hctx); | ||
if (ret < 0) | ||
return ret; | ||
|
||
return 0; | ||
} | ||
|
||
void __cls_init() | ||
{ | ||
CLS_LOG(0, "loading cls_sdk"); | ||
|
||
cls_register("sdk", &h_class); | ||
|
||
cls_register_cxx_method(h_class, "test_coverage_write", | ||
CLS_METHOD_RD|CLS_METHOD_WR, | ||
test_coverage_write, &h_test_coverage_write); | ||
|
||
cls_register_cxx_method(h_class, "test_coverage_replay", | ||
CLS_METHOD_RD|CLS_METHOD_WR, | ||
test_coverage_replay, &h_test_coverage_replay); | ||
} |
Oops, something went wrong.