1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
19 #include "common/ceph_argparse.h"
20 #include "common/debug.h"
21 #include "common/config.h"
22 #include "global/global_init.h"
23 #include "include/rados/librados.hpp"
24 #include "include/types.h"
33 using namespace librados
;
35 static void usage(void)
37 cerr
<< "--oid set object id to 'operate' on" << std::endl
;
38 cerr
<< "--pool set pool to 'operate' on" << std::endl
;
41 int main(int argc
, const char **argv
)
43 auto args
= argv_to_vec(argc
, argv
);
44 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
45 CODE_ENVIRONMENT_UTILITY
,
46 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE
);
47 common_init_finish(g_ceph_context
);
50 string
oid("ceph_test_object");
51 string
pool_name("test_pool");
52 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
53 if (ceph_argparse_double_dash(args
, i
)) {
56 else if (ceph_argparse_witharg(args
, i
, &val
, "--oid", "-o", (char*)NULL
)) {
59 else if (ceph_argparse_witharg(args
, i
, &val
, "--pool", "-p", (char*)NULL
)) {
63 cerr
<< "unknown command line option: " << *i
<< std::endl
;
71 if (rados
.init_with_context(g_ceph_context
) < 0) {
72 cerr
<< "couldn't initialize rados!" << std::endl
;
75 if (rados
.conf_read_file(NULL
) < 0) {
76 cerr
<< "failed to read rados configuration file!" << std::endl
;
79 if (rados
.connect() < 0) {
80 cerr
<< "couldn't connect to cluster!" << std::endl
;
85 librados::ObjectWriteOperation o
;
87 if (rados
.pool_lookup(pool_name
.c_str()) <= 0) {
88 ret
= rados
.pool_create(pool_name
.c_str());
90 cerr
<< "failed to create pool named '" << pool_name
91 << "': error " << ret
<< std::endl
;
95 ret
= rados
.ioctx_create(pool_name
.c_str(), ioctx
);
97 cerr
<< "failed to create ioctx for pool '" << pool_name
98 << "': error " << ret
<< std::endl
;
101 ioctx
.application_enable("rados", true);
103 librados::ObjectWriteOperation op
;
105 ret
= ioctx
.operate(oid
, &op
);
107 cerr
<< "ioctx.operate failed: ret = " << ret
<< std::endl
;