]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/system/st_rados_delete_objs.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / system / st_rados_delete_objs.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2011 New Dream Network
7 *
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.
12 *
13 */
14
15 #include "cross_process_sem.h"
16 #include "include/rados/librados.h"
17 #include "st_rados_delete_objs.h"
18 #include "systest_runnable.h"
19 #include "systest_settings.h"
20
21 #include <errno.h>
22
23 StRadosDeleteObjs::StRadosDeleteObjs(int argc, const char **argv,
24 CrossProcessSem *setup_sem,
25 CrossProcessSem *deleted_sem,
26 int num_objs,
27 const std::string &pool_name,
28 const std::string &suffix)
29 : SysTestRunnable(argc, argv),
30 m_setup_sem(setup_sem),
31 m_deleted_sem(deleted_sem),
32 m_num_objs(num_objs),
33 m_pool_name(pool_name),
34 m_suffix(suffix)
35 {
36 }
37
38 StRadosDeleteObjs::~StRadosDeleteObjs()
39 {
40 }
41
42 int StRadosDeleteObjs::run()
43 {
44 rados_t cl;
45 RETURN1_IF_NONZERO(rados_create(&cl, NULL));
46 rados_conf_parse_argv(cl, m_argc, m_argv);
47 RETURN1_IF_NONZERO(rados_conf_read_file(cl, NULL));
48 rados_conf_parse_env(cl, NULL);
49 RETURN1_IF_NONZERO(rados_connect(cl));
50 m_setup_sem->wait();
51 m_setup_sem->post();
52
53 rados_ioctx_t io_ctx;
54 rados_pool_create(cl, m_pool_name.c_str());
55 RETURN1_IF_NONZERO(rados_ioctx_create(cl, m_pool_name.c_str(), &io_ctx));
56
57 for (int i = 0; i < m_num_objs; ++i) {
58 char oid[128];
59 snprintf(oid, sizeof(oid), "%d%s", i, m_suffix.c_str());
60 RETURN1_IF_NONZERO(rados_remove(io_ctx, oid));
61 if (((i % 25) == 0) || (i == m_num_objs - 1)) {
62 printf("%s: deleted object %d...\n", get_id_str(), i);
63 }
64 }
65
66 rados_ioctx_destroy(io_ctx);
67 if (m_deleted_sem)
68 m_deleted_sem->post();
69 rados_shutdown(cl);
70 return 0;
71 }