]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/librgw.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rgw / librgw.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2022 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 <sys/types.h>
17 #include <string.h>
18 #include <chrono>
19
20 #include "include/rados/librgw.h"
21
22 #include "include/str_list.h"
23 #include "common/ceph_argparse.h"
24 #include "common/ceph_context.h"
25 #include "common/dout.h"
26
27 #include "rgw_lib.h"
28
29 #include <errno.h>
30 #include <thread>
31 #include <string>
32 #include <mutex>
33
34 #define dout_subsys ceph_subsys_rgw
35
36 namespace rgw {
37
38 bool global_stop = false;
39 static std::mutex librgw_mtx;
40 static RGWLib rgwlib;
41
42 } // namespace rgw
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
52 g_rgwlib = &rgwlib;
53
54 if (! g_ceph_context) {
55 std::lock_guard<std::mutex> lg(librgw_mtx);
56 if (! g_ceph_context) {
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 }
63 auto args = argv_to_vec(argc, argv);
64 // append split args, if any
65 for (const auto& elt : spl_args) {
66 args.push_back(elt.c_str());
67 }
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();
83
84 dout(1) << "final shutdown" << dendl;
85
86 cct->put();
87 }
88
89 } /* extern "C" */