1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
9 #include "common/async/context_pool.h"
10 #include "common/ceph_context.h"
11 #include "common/ceph_argparse.h"
12 #include "common/config.h"
13 #include "global/global_init.h"
15 #include "auth/KeyRing.h"
16 #include "mon/MonClient.h"
18 #include "mount.ceph.h"
21 extern "C" void mount_ceph_get_config_info(const char *config_file
,
24 struct ceph_config_info
*cci
)
29 std::string secret_str
;
31 vector
<const char *> args
= { "--name", name
};
35 args
.push_back("--conf");
36 args
.push_back(config_file
);
39 /* Create CephContext */
40 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
41 CODE_ENVIRONMENT_UTILITY
,
42 CINIT_FLAG_NO_DAEMON_ACTIONS
|CINIT_FLAG_NO_MON_CONFIG
);
43 auto& conf
= cct
->_conf
;
45 conf
.parse_env(cct
->get_module_type()); // environment variables override
46 conf
.apply_changes(nullptr);
48 ceph::async::io_context_pool
ioc(1);
49 MonClient monc
= MonClient(cct
.get(), ioc
);
50 err
= monc
.build_initial_monmap();
54 for (const auto& mon
: monc
.monmap
.addr_mons
) {
55 auto& eaddr
= mon
.first
;
58 * Filter v1 addrs if we're running in ms_mode=legacy. Filter
59 * v2 addrs for any other ms_mode.
62 if (!eaddr
.is_msgr2())
65 if (!eaddr
.is_legacy())
70 addr
+= eaddr
.ip_only_to_str();
72 addr
+= std::to_string(eaddr
.get_port());
73 /* If this will overrun cci_mons, stop here */
74 if (monaddrs
.length() + 1 + addr
.length() + 1 > sizeof(cci
->cci_mons
))
85 if (monaddrs
.length())
86 strcpy(cci
->cci_mons
, monaddrs
.c_str());
88 mount_ceph_debug("Could not discover monitor addresses\n");
91 err
= keyring
.from_ceph_context(cct
.get());
93 mount_ceph_debug("keyring.from_ceph_context failed: %d\n", err
);
97 if (!keyring
.get_secret(conf
->name
, secret
)) {
98 mount_ceph_debug("keyring.get_secret failed\n");
102 secret
.encode_base64(secret_str
);
104 if (secret_str
.length() + 1 > sizeof(cci
->cci_secret
)) {
105 mount_ceph_debug("secret is too long\n");
108 strcpy(cci
->cci_secret
, secret_str
.c_str());