diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/test/test_mutate.cc | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test_mutate.cc')
-rw-r--r-- | src/test/test_mutate.cc | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/test/test_mutate.cc b/src/test/test_mutate.cc new file mode 100644 index 00000000..b453895c --- /dev/null +++ b/src/test/test_mutate.cc @@ -0,0 +1,113 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2011 New Dream Network + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +/* + * Test Ioctx::operate + */ + +#include "common/ceph_argparse.h" +#include "common/debug.h" +#include "common/config.h" +#include "global/global_init.h" +#include "include/rados/librados.hpp" +#include "include/types.h" + +#include <errno.h> +#include <iostream> +#include <string> + +using std::cerr; +using std::string; + +using namespace librados; + +static void usage(void) +{ + cerr << "--oid set object id to 'operate' on" << std::endl; + cerr << "--pool set pool to 'operate' on" << std::endl; +} + +int main(int argc, const char **argv) +{ + int ret = 0; + vector<const char*> args; + argv_to_vec(argc, argv, args); + auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, + CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); + common_init_finish(g_ceph_context); + + string val; + string oid("ceph_test_object"); + string pool_name("test_pool"); + for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) { + if (ceph_argparse_double_dash(args, i)) { + break; + } + else if (ceph_argparse_witharg(args, i, &val, "--oid", "-o", (char*)NULL)) { + oid = val; + } + else if (ceph_argparse_witharg(args, i, &val, "--pool", "-p", (char*)NULL)) { + pool_name = val; + } + else { + cerr << "unknown command line option: " << *i << std::endl; + cerr << std::endl; + usage(); + return 2; + } + } + + Rados rados; + if (rados.init_with_context(g_ceph_context) < 0) { + cerr << "couldn't initialize rados!" << std::endl; + return 1; + } + if (rados.conf_read_file(NULL) < 0) { + cerr << "failed to read rados configuration file!" << std::endl; + return 1; + } + if (rados.connect() < 0) { + cerr << "couldn't connect to cluster!" << std::endl; + return 1; + } + + librados::ObjectWriteOperation o; + IoCtx ioctx; + if (rados.pool_lookup(pool_name.c_str()) <= 0) { + ret = rados.pool_create(pool_name.c_str()); + if (ret) { + cerr << "failed to create pool named '" << pool_name + << "': error " << ret << std::endl; + return 1; + } + } + ret = rados.ioctx_create(pool_name.c_str(), ioctx); + if (ret) { + cerr << "failed to create ioctx for pool '" << pool_name + << "': error " << ret << std::endl; + return 1; + } + ioctx.application_enable("rados", true); + + librados::ObjectWriteOperation op; + op.create(true); + ret = ioctx.operate(oid, &op); + if (ret) { + cerr << "ioctx.operate failed: ret = " << ret << std::endl; + return 1; + } + + return 0; +} |