1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
9 #include "common/ceph_context.h"
10 #include "common/ceph_argparse.h"
11 #include "global/global_init.h"
12 #include "common/config.h"
13 #include "auth/KeyRing.h"
14 #include "mount.ceph.h"
15 #include "mon/MonClient.h"
17 extern "C" void mount_ceph_get_config_info(const char *config_file
,
19 struct ceph_config_info
*cci
)
24 std::string secret_str
;
26 vector
<const char *> args
= { "--name", name
};
30 args
.push_back("--conf");
31 args
.push_back(config_file
);
34 /* Create CephContext */
35 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
36 CODE_ENVIRONMENT_UTILITY
,
37 CINIT_FLAG_NO_DAEMON_ACTIONS
|CINIT_FLAG_NO_MON_CONFIG
);
38 auto& conf
= cct
->_conf
;
40 conf
.parse_env(cct
->get_module_type()); // environment variables override
41 conf
.apply_changes(nullptr);
43 MonClient monc
= MonClient(cct
.get());
44 err
= monc
.build_initial_monmap();
48 for (const auto& mon
: monc
.monmap
.addr_mons
) {
49 auto& eaddr
= mon
.first
;
51 // For now, kernel client only accepts legacy addrs
52 if (!eaddr
.is_legacy())
56 addr
+= eaddr
.ip_only_to_str();
58 addr
+= std::to_string(eaddr
.get_port());
59 /* If this will overrun cci_mons, stop here */
60 if (monaddrs
.length() + 1 + addr
.length() + 1 > sizeof(cci
->cci_mons
))
71 if (monaddrs
.length())
72 strcpy(cci
->cci_mons
, monaddrs
.c_str());
74 mount_ceph_debug("Could not discover monitor addresses\n");
77 err
= keyring
.from_ceph_context(cct
.get());
79 mount_ceph_debug("keyring.from_ceph_context failed: %d\n", err
);
83 if (!keyring
.get_secret(conf
->name
, secret
)) {
84 mount_ceph_debug("keyring.get_secret failed\n");
88 secret
.encode_base64(secret_str
);
90 if (secret_str
.length() + 1 > sizeof(cci
->cci_secret
)) {
91 mount_ceph_debug("secret is too long\n");
94 strcpy(cci
->cci_secret
, secret_str
.c_str());