2 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
3 // vim: ts=8 sw=2 smarttab
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2011 New Dream Network
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.
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"
24 #include <semaphore.h>
33 using std::ostringstream;
38 * rados_open_pools_parallel
40 * This tests creating a pool in one Runnable, and then opening an io context
41 * based on that pool in another.
43 * EXPECT: * can't create the same pool twice
44 * * one Runnable can use the pool after the other one creates it
46 * DO NOT EXPECT * hangs, crashes
48 class StRadosOpenPool : public SysTestRunnable
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)
62 ~StRadosOpenPool() override
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));
78 m_pool_setup_sem->wait();
80 printf("%s: rados_pool_create.\n", get_id_str());
81 rados_pool_create(cl, m_pool_name.c_str());
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));
86 m_open_pool_sem->post();
87 rados_ioctx_destroy(io_ctx);
88 rados_pool_delete(cl, m_pool_name.c_str());
94 CrossProcessSem *m_pool_setup_sem;
95 CrossProcessSem *m_open_pool_sem;
96 std::string m_pool_name;
99 const char *get_id_str()
104 int main(int argc, const char **argv)
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,
113 StRadosOpenPool r2(argc, argv, pool_setup_sem, NULL, pool);
114 vector < SysTestRunnable* > vec;
117 std::string error = SysTestRunnable::run_until_finished(vec);
118 if (!error.empty()) {
119 printf("test1: got error: %s\n", error.c_str());
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,
131 StRadosOpenPool r4(argc, argv, pool_setup_sem2, open_pool_sem2, pool);
132 vector < SysTestRunnable* > vec2;
135 error = SysTestRunnable::run_until_finished(vec2);
136 if (!error.empty()) {
137 printf("test2: got error: %s\n", error.c_str());
141 printf("******* SUCCESS **********\n");