#include "include/rados/librados.hpp"
#include "include/log_message.h"
#include <iostream>
int32_t main(int32_t argc, const char* argv[]) {
int32_t error_code = 0;
librados::Rados cluster;
char cluster_name[] = "ceph";
char user_name[] = "client.admin";
uint64_t flags = 0;
error_code = cluster.init2(user_name, cluster_name, flags);
if (error_code < 0) {
std::cerr << "Couldn't initialize the cluster handle! error " << error_code << std::endl;
return -1;
}
error_code = cluster.conf_read_file("/data/home/richardyao/workspace/github/ceph/build/ceph.conf");
if (error_code < 0) {
std::cout << "Couldn't read the Ceph configuration file! error_code " << error_code << std::endl;
return -1;
}
error_code = cluster.conf_parse_argv(argc, argv);
if (error_code < 0) {
std::cout << "Couldn't parse command line options! error_code " << error_code << std::endl;
return -1;
}
error_code = cluster.connect();
if (error_code < 0) {
std::cerr << "Couldn't connect to cluster! error_code " << error_code << std::endl;
return -1;
}
LOG(INFO) << "Connected to the cluster.";
/* Continued from previous C++ example, where cluster handle and
* * connection are established. First declare an I/O Context.
* */
librados::IoCtx io_ctx;
const char *pool_name = "testpool";
error_code = cluster.ioctx_create(pool_name, io_ctx);
if (error_code < 0) {
std::cerr << "Couldn't set up ioctx! error " << error_code << std::endl;
return -1;
}
/* Write an object synchronously. */
librados::bufferlist bl;
bl.append("Hello World!");
error_code = io_ctx.write_full("hello.txt", bl);
if (error_code < 0) {
std::cerr << "Couldn't write object! error " << error_code << std::endl;
return -1;
}
LOG(INFO) << "hello.txt is written";
io_ctx.close();
cluster.shutdown();
return 0;
}
librados的一個(gè)使用示例
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門之宿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人苛坚,你說我怎么就攤上這事比被。” “怎么了泼舱?”我有些...
- 文/不壞的土叔 我叫張陵等缀,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我娇昙,道長(zhǎng)尺迂,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任冒掌,我火速辦了婚禮噪裕,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘股毫。我一直安慰自己膳音,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開白布铃诬。 她就那樣靜靜地躺著严蓖,像睡著了一般。 火紅的嫁衣襯著肌膚如雪氧急。 梳的紋絲不亂的頭發(fā)上颗胡,一...
- 文/蒼蘭香墨 我猛地睜開眼嵌纲,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼俘枫!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起逮走,我...
- 序言:老撾萬榮一對(duì)情侶失蹤鸠蚪,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體茅信,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡盾舌,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了蘸鲸。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片妖谴。...
- 正文 年R本政府宣布铸史,位于F島的核電站,受9級(jí)特大地震影響怯伊,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜判沟,卻給世界環(huán)境...
- 文/蒙蒙 一耿芹、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧挪哄,春花似錦吧秕、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至斯入,卻和暖如春砂碉,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背刻两。 一陣腳步聲響...
- 正文 我出身青樓滋迈,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親户誓。 傳聞我的和親對(duì)象是個(gè)殘疾皇子饼灿,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 你猜我現(xiàn)在最懼怕什么碍彭? 不是讀書,不是寫字,不是講話硕旗,而是打開手機(jī)流量窗骑。 一打開,就意味著微信漆枚,qq里的消息一...
- 非常巧墙基,昨天早晨打開《簡(jiǎn)書》软族,在首頁,發(fā)現(xiàn)了一位女寫友的文章残制,文中講訴她堅(jiān)持每天早晨5點(diǎn)開始進(jìn)行寫作立砸,并且堅(jiān)持了一...
- QQ里的頭像突然閃動(dòng) 青果眼前一亮便也只是愣愣的看著。 第一次也是唯一的一次青果沒有給對(duì)方回復(fù)初茶。 一個(gè)月了沒有聯(lián)絡(luò)...