]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/system/rados_open_pools_parallel.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / system / rados_open_pools_parallel.cc
1
2 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
3 // vim: ts=8 sw=2 smarttab
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2011 New Dream Network
8 *
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
13 *
14 */
15
16 #include "cross_process_sem.h"
17 #include "include/rados/librados.h"
18 #include "st_rados_create_pool.h"
19 #include "systest_runnable.h"
20 #include "systest_settings.h"
21
22 #include <errno.h>
23 #include <pthread.h>
24 #include <semaphore.h>
25 #include <sstream>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string>
30 #include <time.h>
31 #include <vector>
32
33 using std::ostringstream;
34 using std::string;
35 using std::vector;
36
37 /*
38 * rados_open_pools_parallel
39 *
40 * This tests creating a pool in one Runnable, and then opening an io context
41 * based on that pool in another.
42 *
43 * EXPECT: * can't create the same pool twice
44 * * one Runnable can use the pool after the other one creates it
45 *
46 * DO NOT EXPECT * hangs, crashes
47 */
48 class StRadosOpenPool : public SysTestRunnable
49 {
50 public:
51 StRadosOpenPool(int argc, const char **argv,
52 CrossProcessSem *pool_setup_sem,
53 CrossProcessSem *open_pool_sem,
54 const std::string& pool_name)
55 : SysTestRunnable(argc, argv),
56 m_pool_setup_sem(pool_setup_sem),
57 m_open_pool_sem(open_pool_sem),
58 m_pool_name(pool_name)
59 {
60 }
61
62 ~StRadosOpenPool() override
63 {
64 }
65
66 int run() override
67 {
68 rados_t cl;
69 RETURN1_IF_NONZERO(rados_create(&cl, NULL));
70 rados_conf_parse_argv(cl, m_argc, m_argv);
71 std::string log_name = SysTestSettings::inst().get_log_name(get_id_str());
72 if (!log_name.empty())
73 rados_conf_set(cl, "log_file", log_name.c_str());
74 RETURN1_IF_NONZERO(rados_conf_read_file(cl, NULL));
75 rados_conf_parse_env(cl, NULL);
76 RETURN1_IF_NONZERO(rados_connect(cl));
77 if (m_pool_setup_sem)
78 m_pool_setup_sem->wait();
79
80 printf("%s: rados_pool_create.\n", get_id_str());
81 rados_pool_create(cl, m_pool_name.c_str());
82 rados_ioctx_t io_ctx;
83 printf("%s: rados_ioctx_create.\n", get_id_str());
84 RETURN1_IF_NOT_VAL(0, rados_ioctx_create(cl, m_pool_name.c_str(), &io_ctx));
85 if (m_open_pool_sem)
86 m_open_pool_sem->post();
87 rados_ioctx_destroy(io_ctx);
88 rados_shutdown(cl);
89 return 0;
90 }
91
92 private:
93 CrossProcessSem *m_pool_setup_sem;
94 CrossProcessSem *m_open_pool_sem;
95 std::string m_pool_name;
96 };
97
98 const char *get_id_str()
99 {
100 return "main";
101 }
102
103 int main(int argc, const char **argv)
104 {
105 const std::string pool = get_temp_pool_name(argv[0]);
106 // first test: create a pool, shut down the client, access that
107 // pool in a different process.
108 CrossProcessSem *pool_setup_sem = NULL;
109 RETURN1_IF_NONZERO(CrossProcessSem::create(0, &pool_setup_sem));
110 StRadosCreatePool r1(argc, argv, NULL, pool_setup_sem, NULL,
111 pool, 50, ".obj");
112 StRadosOpenPool r2(argc, argv, pool_setup_sem, NULL, pool);
113 vector < SysTestRunnable* > vec;
114 vec.push_back(&r1);
115 vec.push_back(&r2);
116 std::string error = SysTestRunnable::run_until_finished(vec);
117 if (!error.empty()) {
118 printf("test1: got error: %s\n", error.c_str());
119 return EXIT_FAILURE;
120 }
121
122 // second test: create a pool, access that
123 // pool in a different process, THEN shut down the first client.
124 CrossProcessSem *pool_setup_sem2 = NULL;
125 RETURN1_IF_NONZERO(CrossProcessSem::create(0, &pool_setup_sem2));
126 CrossProcessSem *open_pool_sem2 = NULL;
127 RETURN1_IF_NONZERO(CrossProcessSem::create(0, &open_pool_sem2));
128 StRadosCreatePool r3(argc, argv, NULL, pool_setup_sem2, open_pool_sem2,
129 pool, 50, ".obj");
130 StRadosOpenPool r4(argc, argv, pool_setup_sem2, open_pool_sem2, pool);
131 vector < SysTestRunnable* > vec2;
132 vec2.push_back(&r3);
133 vec2.push_back(&r4);
134 error = SysTestRunnable::run_until_finished(vec2);
135 if (!error.empty()) {
136 printf("test2: got error: %s\n", error.c_str());
137 return EXIT_FAILURE;
138 }
139
140 printf("******* SUCCESS **********\n");
141 return EXIT_SUCCESS;
142 }