]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
11fdf7f2 | 3 | |
7c673cae FG |
4 | /* |
5 | * Ceph - scalable distributed file system | |
6 | * | |
1e59de90 | 7 | * Copyright (C) 2022 New Dream Network |
7c673cae FG |
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 | */ | |
11fdf7f2 | 15 | |
7c673cae FG |
16 | #include <sys/types.h> |
17 | #include <string.h> | |
18 | #include <chrono> | |
19 | ||
7c673cae | 20 | #include "include/rados/librgw.h" |
7c673cae FG |
21 | |
22 | #include "include/str_list.h" | |
7c673cae FG |
23 | #include "common/ceph_argparse.h" |
24 | #include "common/ceph_context.h" | |
7c673cae FG |
25 | #include "common/dout.h" |
26 | ||
7c673cae | 27 | #include "rgw_lib.h" |
9f95a23c | 28 | |
7c673cae | 29 | #include <errno.h> |
7c673cae FG |
30 | #include <thread> |
31 | #include <string> | |
7c673cae FG |
32 | #include <mutex> |
33 | ||
7c673cae FG |
34 | #define dout_subsys ceph_subsys_rgw |
35 | ||
7c673cae FG |
36 | namespace rgw { |
37 | ||
1e59de90 TL |
38 | bool global_stop = false; |
39 | static std::mutex librgw_mtx; | |
40 | static RGWLib rgwlib; | |
7c673cae | 41 | |
1e59de90 | 42 | } // namespace rgw |
7c673cae FG |
43 | |
44 | extern "C" { | |
45 | ||
46 | int librgw_create(librgw_t* rgw, int argc, char **argv) | |
47 | { | |
48 | using namespace rgw; | |
49 | ||
50 | int rc = -EINVAL; | |
51 | ||
1e59de90 TL |
52 | g_rgwlib = &rgwlib; |
53 | ||
7c673cae FG |
54 | if (! g_ceph_context) { |
55 | std::lock_guard<std::mutex> lg(librgw_mtx); | |
56 | if (! g_ceph_context) { | |
7c673cae FG |
57 | std::vector<std::string> spl_args; |
58 | // last non-0 argument will be split and consumed | |
59 | if (argc > 1) { | |
60 | const std::string spl_arg{argv[(--argc)]}; | |
61 | get_str_vec(spl_arg, " \t", spl_args); | |
62 | } | |
20effc67 | 63 | auto args = argv_to_vec(argc, argv); |
7c673cae FG |
64 | // append split args, if any |
65 | for (const auto& elt : spl_args) { | |
66 | args.push_back(elt.c_str()); | |
67 | } | |
7c673cae FG |
68 | rc = rgwlib.init(args); |
69 | } | |
70 | } | |
71 | ||
72 | *rgw = g_ceph_context->get(); | |
73 | ||
74 | return rc; | |
75 | } | |
76 | ||
77 | void librgw_shutdown(librgw_t rgw) | |
78 | { | |
79 | using namespace rgw; | |
80 | ||
81 | CephContext* cct = static_cast<CephContext*>(rgw); | |
82 | rgwlib.stop(); | |
1e59de90 TL |
83 | |
84 | dout(1) << "final shutdown" << dendl; | |
85 | ||
7c673cae FG |
86 | cct->put(); |
87 | } | |
88 | ||
89 | } /* extern "C" */ |