1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
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.
15 #include "cross_process_sem.h"
16 #include "include/rados/librados.h"
17 #include "st_rados_create_pool.h"
18 #include "st_rados_delete_pool.h"
19 #include "st_rados_delete_objs.h"
20 #include "st_rados_watch.h"
21 #include "st_rados_notify.h"
22 #include "systest_runnable.h"
23 #include "systest_settings.h"
24 #include "include/stringify.h"
28 #include <semaphore.h>
36 #include <sys/types.h>
39 using std::ostringstream;
46 * This tests watch/notify with pool and object deletion.
48 * EXPECT: * notifies to a deleted object or pool are not received
49 * * notifies to existing objects are received
51 * DO NOT EXPECT * hangs, crashes
54 const char *get_id_str()
59 int main(int argc, const char **argv)
61 std::string pool = "foo." + stringify(getpid());
62 CrossProcessSem *setup_sem = NULL;
63 RETURN1_IF_NONZERO(CrossProcessSem::create(0, &setup_sem));
64 CrossProcessSem *watch_sem = NULL;
65 RETURN1_IF_NONZERO(CrossProcessSem::create(0, &watch_sem));
66 CrossProcessSem *notify_sem = NULL;
67 RETURN1_IF_NONZERO(CrossProcessSem::create(0, ¬ify_sem));
69 // create a pool and an object, watch the object, notify.
71 StRadosCreatePool r1(argc, argv, NULL, setup_sem, NULL, pool, 1, ".obj");
72 StRadosWatch r2(argc, argv, setup_sem, watch_sem, notify_sem,
74 StRadosNotify r3(argc, argv, setup_sem, watch_sem, notify_sem,
76 StRadosDeletePool r4(argc, argv, notify_sem, NULL, pool);
77 vector<SysTestRunnable*> vec;
82 std::string error = SysTestRunnable::run_until_finished(vec);
84 printf("test1: got error: %s\n", error.c_str());
89 RETURN1_IF_NONZERO(setup_sem->reinit(0));
90 RETURN1_IF_NONZERO(watch_sem->reinit(0));
91 RETURN1_IF_NONZERO(notify_sem->reinit(0));
93 // create a pool and an object, watch a non-existent object,
94 // notify non-existent object.watch
97 StRadosCreatePool r1(argc, argv, NULL, setup_sem, NULL, pool, 0, ".obj");
98 StRadosWatch r2(argc, argv, setup_sem, watch_sem, notify_sem,
99 0, -ENOENT, pool, "0.obj");
100 StRadosNotify r3(argc, argv, setup_sem, watch_sem, notify_sem,
101 -ENOENT, pool, "0.obj");
102 StRadosDeletePool r4(argc, argv, notify_sem, NULL, pool);
103 vector<SysTestRunnable*> vec;
108 std::string error = SysTestRunnable::run_until_finished(vec);
109 if (!error.empty()) {
110 printf("test2: got error: %s\n", error.c_str());
115 RETURN1_IF_NONZERO(setup_sem->reinit(0));
116 RETURN1_IF_NONZERO(watch_sem->reinit(0));
117 RETURN1_IF_NONZERO(notify_sem->reinit(0));
119 CrossProcessSem *finished_notifies_sem = NULL;
120 RETURN1_IF_NONZERO(CrossProcessSem::create(0, &finished_notifies_sem));
121 CrossProcessSem *deleted_sem = NULL;
122 RETURN1_IF_NONZERO(CrossProcessSem::create(0, &deleted_sem));
123 CrossProcessSem *second_pool_sem = NULL;
124 RETURN1_IF_NONZERO(CrossProcessSem::create(0, &second_pool_sem));
126 // create a pool and an object, watch the object, notify,
127 // then delete the pool.
128 // Create a new pool and write to it to make the osd get the updated map,
129 // then try notifying on the deleted pool.
132 StRadosCreatePool r1(argc, argv, NULL, setup_sem, NULL, pool, 1, ".obj");
133 StRadosWatch r2(argc, argv, setup_sem, watch_sem, finished_notifies_sem,
134 1, 0, pool, "0.obj");
135 StRadosNotify r3(argc, argv, setup_sem, watch_sem, notify_sem,
137 StRadosDeletePool r4(argc, argv, notify_sem, deleted_sem, pool);
138 StRadosCreatePool r5(argc, argv, deleted_sem, second_pool_sem, NULL,
140 StRadosNotify r6(argc, argv, second_pool_sem, NULL, finished_notifies_sem,
142 StRadosDeletePool r7(argc, argv, finished_notifies_sem, NULL, "bar");
143 vector<SysTestRunnable*> vec;
151 std::string error = SysTestRunnable::run_until_finished(vec);
152 if (!error.empty()) {
153 printf("test3: got error: %s\n", error.c_str());
158 RETURN1_IF_NONZERO(setup_sem->reinit(0));
159 RETURN1_IF_NONZERO(watch_sem->reinit(0));
160 RETURN1_IF_NONZERO(notify_sem->reinit(0));
161 RETURN1_IF_NONZERO(finished_notifies_sem->reinit(0));
162 RETURN1_IF_NONZERO(deleted_sem->reinit(0));
164 // create a pool and an object, watch the object, notify,
165 // then delete the object, notify
166 // this test is enabled for the resolution of bug #2339.
169 StRadosCreatePool r1(argc, argv, NULL, setup_sem, NULL, pool, 1, ".obj");
170 StRadosWatch r2(argc, argv, setup_sem, watch_sem, finished_notifies_sem,
171 1, 0, pool, "0.obj");
172 StRadosNotify r3(argc, argv, setup_sem, watch_sem, notify_sem,
174 StRadosDeleteObjs r4(argc, argv, notify_sem, deleted_sem, 1, pool, ".obj");
175 StRadosNotify r5(argc, argv, setup_sem, deleted_sem, finished_notifies_sem,
176 -ENOENT, pool, "0.obj");
177 StRadosDeletePool r6(argc, argv, finished_notifies_sem, NULL, pool);
179 vector<SysTestRunnable*> vec;
186 std::string error = SysTestRunnable::run_until_finished(vec);
187 if (!error.empty()) {
188 printf("test4: got error: %s\n", error.c_str());
193 printf("******* SUCCESS **********\n");