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)
44 vector<const char*> args;
45 argv_to_vec(argc, argv, args);
47 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
48 CODE_ENVIRONMENT_UTILITY, 0);
49 common_init_finish(g_ceph_context);
52 string oid("ceph_test_object");
53 string pool_name("test_pool");
54 for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
55 if (ceph_argparse_double_dash(args, i)) {
58 else if (ceph_argparse_witharg(args, i, &val, "--oid", "-o", (char*)NULL)) {
61 else if (ceph_argparse_witharg(args, i, &val, "--pool", "-p", (char*)NULL)) {
65 cerr << "unknown command line option: " << *i << std::endl;
73 if (rados.init_with_context(g_ceph_context) < 0) {
74 cerr << "couldn't initialize rados!" << std::endl;
77 if (rados.conf_read_file(NULL) < 0) {
78 cerr << "failed to read rados configuration file!" << std::endl;
81 if (rados.connect() < 0) {
82 cerr << "couldn't connect to cluster!" << std::endl;
86 librados::ObjectWriteOperation o;
88 if (rados.pool_lookup(pool_name.c_str()) <= 0) {
89 ret = rados.pool_create(pool_name.c_str());
91 cerr << "failed to create pool named '" << pool_name
92 << "': error " << ret << std::endl;
96 ret = rados.ioctx_create(pool_name.c_str(), ioctx);
98 cerr << "failed to create ioctx for pool '" << pool_name
99 << "': error " << ret << std::endl;
102 ioctx.application_enable("rados", true);
104 librados::ObjectWriteOperation op;
106 ret = ioctx.operate(oid, &op);
108 cerr << "ioctx.operate failed: ret = " << ret << std::endl;