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_list_objects.h"
18 #include "systest_runnable.h"
19 #include "systest_settings.h"
28 using std::ostringstream;
31 StRadosListObjects(int argc, const char **argv,
32 const std::string &pool_name,
33 bool accept_list_errors,
35 CrossProcessSem *pool_setup_sem,
36 CrossProcessSem *midway_sem_wait,
37 CrossProcessSem *midway_sem_post)
38 : SysTestRunnable(argc, argv),
39 m_pool_name(pool_name),
40 m_accept_list_errors(accept_list_errors),
41 m_midway_cnt(midway_cnt),
42 m_pool_setup_sem(pool_setup_sem),
43 m_midway_sem_wait(midway_sem_wait),
44 m_midway_sem_post(midway_sem_post)
53 int StRadosListObjects::
58 RETURN1_IF_NONZERO(rados_create(&cl, NULL));
59 rados_conf_parse_argv(cl, m_argc, m_argv);
60 RETURN1_IF_NONZERO(rados_conf_read_file(cl, NULL));
61 rados_conf_parse_env(cl, NULL);
62 RETURN1_IF_NONZERO(rados_connect(cl));
63 m_pool_setup_sem->wait();
64 m_pool_setup_sem->post();
67 rados_pool_create(cl, m_pool_name.c_str());
68 RETURN1_IF_NONZERO(rados_ioctx_create(cl, m_pool_name.c_str(), &io_ctx));
73 printf("%s: listing objects.\n", get_id_str());
74 RETURN1_IF_NONZERO(rados_nobjects_list_open(io_ctx, &h));
76 int ret = rados_nobjects_list_next(h, &obj_name, NULL, NULL);
81 if (m_accept_list_errors && (!m_midway_sem_post || saw > m_midway_cnt))
83 printf("%s: rados_objects_list_next error: %d\n", get_id_str(), ret);
87 if ((saw % 25) == 0) {
88 printf("%s: listed object %d...\n", get_id_str(), saw);
91 if (saw == m_midway_cnt) {
92 if (m_midway_sem_wait)
93 m_midway_sem_wait->wait();
94 if (m_midway_sem_post)
95 m_midway_sem_post->post();
99 printf("%s: saw %d objects\n", get_id_str(), saw);
102 rados_nobjects_list_close(h);
103 rados_ioctx_destroy(io_ctx);