]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/system/rados_open_pools_parallel.cc
update sources to v12.1.2
[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_NONZERO(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_pool_delete(cl, m_pool_name.c_str());
89 rados_shutdown(cl);
90 return 0;
91 }
92
93 private:
94 CrossProcessSem *m_pool_setup_sem;
95 CrossProcessSem *m_open_pool_sem;
96 std::string m_pool_name;
97 };
98
99 const char *get_id_str()
100 {
101 return "main";
102 }
103
104 int main(int argc, const char **argv)
105 {
106 const std::string pool = get_temp_pool_name(argv[0]);
107 // first test: create a pool, shut down the client, access that
108 // pool in a different process.
109 CrossProcessSem *pool_setup_sem = NULL;
110 RETURN1_IF_NONZERO(CrossProcessSem::create(0, &pool_setup_sem));
111 StRadosCreatePool r1(argc, argv, NULL, pool_setup_sem, NULL,
112 pool, 50, ".obj");
113 StRadosOpenPool r2(argc, argv, pool_setup_sem, NULL, pool);
114 vector < SysTestRunnable* > vec;
115 vec.push_back(&r1);
116 vec.push_back(&r2);
117 std::string error = SysTestRunnable::run_until_finished(vec);
118 if (!error.empty()) {
119 printf("test1: got error: %s\n", error.c_str());
120 return EXIT_FAILURE;
121 }
122
123 // second test: create a pool, access that
124 // pool in a different process, THEN shut down the first client.
125 CrossProcessSem *pool_setup_sem2 = NULL;
126 RETURN1_IF_NONZERO(CrossProcessSem::create(0, &pool_setup_sem2));
127 CrossProcessSem *open_pool_sem2 = NULL;
128 RETURN1_IF_NONZERO(CrossProcessSem::create(0, &open_pool_sem2));
129 StRadosCreatePool r3(argc, argv, NULL, pool_setup_sem2, open_pool_sem2,
130 pool, 50, ".obj");
131 StRadosOpenPool r4(argc, argv, pool_setup_sem2, open_pool_sem2, pool);
132 vector < SysTestRunnable* > vec2;
133 vec2.push_back(&r3);
134 vec2.push_back(&r4);
135 error = SysTestRunnable::run_until_finished(vec2);
136 if (!error.empty()) {
137 printf("test2: got error: %s\n", error.c_str());
138 return EXIT_FAILURE;
139 }
140
141 printf("******* SUCCESS **********\n");
142 return EXIT_SUCCESS;
143 }