summaryrefslogtreecommitdiffstats
path: root/src/ceph/examples/librados/hello_radosstriper.cc
diff options
context:
space:
mode:
authorQiaowei Ren <qiaowei.ren@intel.com>2018-01-04 13:43:33 +0800
committerQiaowei Ren <qiaowei.ren@intel.com>2018-01-05 11:59:39 +0800
commit812ff6ca9fcd3e629e49d4328905f33eee8ca3f5 (patch)
tree04ece7b4da00d9d2f98093774594f4057ae561d4 /src/ceph/examples/librados/hello_radosstriper.cc
parent15280273faafb77777eab341909a3f495cf248d9 (diff)
initial code repo
This patch creates initial code repo. For ceph, luminous stable release will be used for base code, and next changes and optimization for ceph will be added to it. For opensds, currently any changes can be upstreamed into original opensds repo (https://github.com/opensds/opensds), and so stor4nfv will directly clone opensds code to deploy stor4nfv environment. And the scripts for deployment based on ceph and opensds will be put into 'ci' directory. Change-Id: I46a32218884c75dda2936337604ff03c554648e4 Signed-off-by: Qiaowei Ren <qiaowei.ren@intel.com>
Diffstat (limited to 'src/ceph/examples/librados/hello_radosstriper.cc')
-rw-r--r--src/ceph/examples/librados/hello_radosstriper.cc102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/ceph/examples/librados/hello_radosstriper.cc b/src/ceph/examples/librados/hello_radosstriper.cc
new file mode 100644
index 0000000..f1b43d8
--- /dev/null
+++ b/src/ceph/examples/librados/hello_radosstriper.cc
@@ -0,0 +1,102 @@
+#include "rados/librados.hpp"
+#include "radosstriper/libradosstriper.hpp"
+#include <iostream>
+#include <string>
+
+
+int main(int argc, char* argv[])
+{
+ if(argc != 6)
+ {
+ std::cout <<"Please put in correct params\n"<<
+ "Stripe Count:\n"<<
+ "Object Size:\n" <<
+ "File Name:\n" <<
+ "Object Name:\n"
+ "Pool Name:"<< std::endl;
+ return EXIT_FAILURE;
+ }
+ uint32_t strip_count = std::stoi(argv[1]);
+ uint32_t obj_size = std::stoi(argv[2]);
+ std::string fname = argv[3];
+ std::string obj_name = argv[4];
+ std::string pool_name = argv[5];
+ int ret = 0;
+ librados::IoCtx io_ctx;
+ librados::Rados cluster;
+ libradosstriper::RadosStriper* rs = new libradosstriper::RadosStriper;
+
+ // make sure the keyring file is in /etc/ceph/ and is world readable
+ ret = cluster.init2("client.admin","ceph",0);
+ if( ret < 0)
+ {
+ std::cerr << "Couldn't init cluster "<< ret << std::endl;
+ }
+
+ // make sure ceph.conf is in /etc/ceph/ and is world readable
+ ret = cluster.conf_read_file("ceph.conf");
+ if( ret < 0)
+ {
+ std::cerr << "Couldn't read conf file "<< ret << std::endl;
+ }
+ ret = cluster.connect();
+ if(ret < 0)
+ {
+ std::cerr << "Couldn't connect to cluster "<< ret << std::endl;
+ }
+ else
+ {
+ std::cout << "Connected to Cluster"<< std::endl;
+ }
+
+ ret = cluster.ioctx_create(pool_name.c_str(), io_ctx);
+
+ if(ret < 0)
+ {
+ std::cerr << "Couldn't Create IO_CTX"<< ret << std::endl;
+ }
+ ret = libradosstriper::RadosStriper::striper_create(io_ctx,rs);
+ if(ret < 0)
+ {
+ std::cerr << "Couldn't Create RadosStriper"<< ret << std::endl;
+ delete rs;
+ }
+ uint64_t alignment = 0;
+ ret = io_ctx.pool_required_alignment2(&alignment);
+ if(ret < 0)
+ {
+ std::cerr << "IO_CTX didn't give alignment "<< ret
+ << "\n Is this an erasure coded pool? "<< std::endl;
+
+ delete rs;
+ io_ctx.close();
+ cluster.shutdown();
+ return EXIT_FAILURE;
+ }
+ std::cout << "Pool alignment: "<< alignment << std::endl;
+ rs->set_object_layout_stripe_unit(alignment);
+ // how many objects are we striping across?
+ rs->set_object_layout_stripe_count(strip_count);
+ // how big should each object be?
+ rs->set_object_layout_object_size(obj_size);
+
+ std::string err = "no_err";
+ librados::bufferlist bl;
+ bl.read_file(fname.c_str(),&err);
+ if(err != "no_err")
+ {
+ std::cout << "Error reading file into bufferlist: "<< err << std::endl;
+ delete rs;
+ io_ctx.close();
+ cluster.shutdown();
+ return EXIT_FAILURE;
+ }
+
+ std::cout << "Writing: " << fname << "\nas: "<< obj_name << std::endl;
+ rs->write_full(obj_name,bl);
+ std::cout << "done with: " << fname << std::endl;
+
+ delete rs;
+ io_ctx.close();
+ cluster.shutdown();
+}