]> git.proxmox.com Git - ceph.git/blob - ceph/examples/librados/hello_radosstriper.cc
update sources to v12.1.0
[ceph.git] / ceph / examples / librados / hello_radosstriper.cc
1 #include "rados/librados.hpp"
2 #include "radosstriper/libradosstriper.hpp"
3 #include <iostream>
4 #include <string>
5
6
7 int main(int argc, char* argv[])
8 {
9 if(argc != 6)
10 {
11 std::cout <<"Please put in correct params\n"<<
12 "Stripe Count:\n"<<
13 "Object Size:\n" <<
14 "File Name:\n" <<
15 "Object Name:\n"
16 "Pool Name:"<< std::endl;
17 return EXIT_FAILURE;
18 }
19 uint32_t strip_count = std::stoi(argv[1]);
20 uint32_t obj_size = std::stoi(argv[2]);
21 std::string fname = argv[3];
22 std::string obj_name = argv[4];
23 std::string pool_name = argv[5];
24 int ret = 0;
25 librados::IoCtx io_ctx;
26 librados::Rados cluster;
27 libradosstriper::RadosStriper* rs = new libradosstriper::RadosStriper;
28
29 // make sure the keyring file is in /etc/ceph/ and is world readable
30 ret = cluster.init2("client.admin","ceph",0);
31 if( ret < 0)
32 {
33 std::cerr << "Couldn't init cluster "<< ret << std::endl;
34 }
35
36 // make sure ceph.conf is in /etc/ceph/ and is world readable
37 ret = cluster.conf_read_file("ceph.conf");
38 if( ret < 0)
39 {
40 std::cerr << "Couldn't read conf file "<< ret << std::endl;
41 }
42 ret = cluster.connect();
43 if(ret < 0)
44 {
45 std::cerr << "Couldn't connect to cluster "<< ret << std::endl;
46 }
47 else
48 {
49 std::cout << "Connected to Cluster"<< std::endl;
50 }
51
52 ret = cluster.ioctx_create(pool_name.c_str(), io_ctx);
53
54 if(ret < 0)
55 {
56 std::cerr << "Couldn't Create IO_CTX"<< ret << std::endl;
57 }
58 ret = libradosstriper::RadosStriper::striper_create(io_ctx,rs);
59 if(ret < 0)
60 {
61 std::cerr << "Couldn't Create RadosStriper"<< ret << std::endl;
62 delete rs;
63 }
64 uint64_t alignment = 0;
65 ret = io_ctx.pool_required_alignment2(&alignment);
66 if(ret < 0)
67 {
68 std::cerr << "IO_CTX didn't give alignment "<< ret
69 << "\n Is this an erasure coded pool? "<< std::endl;
70
71 delete rs;
72 io_ctx.close();
73 cluster.shutdown();
74 return EXIT_FAILURE;
75 }
76 std::cout << "Pool alignment: "<< alignment << std::endl;
77 rs->set_object_layout_stripe_unit(alignment);
78 // how many objects are we striping across?
79 rs->set_object_layout_stripe_count(strip_count);
80 // how big should each object be?
81 rs->set_object_layout_object_size(obj_size);
82
83 std::string err = "no_err";
84 librados::bufferlist bl;
85 bl.read_file(fname.c_str(),&err);
86 if(err != "no_err")
87 {
88 std::cout << "Error reading file into bufferlist: "<< err << std::endl;
89 delete rs;
90 io_ctx.close();
91 cluster.shutdown();
92 return EXIT_FAILURE;
93 }
94
95 std::cout << "Writing: " << fname << "\nas: "<< obj_name << std::endl;
96 rs->write_full(obj_name,bl);
97 std::cout << "done with: " << fname << std::endl;
98
99 delete rs;
100 io_ctx.close();
101 cluster.shutdown();
102 }