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"
22 extern "C" void mount_ceph_get_config_info(const char *config_file
,
25 struct ceph_config_info
*cci
)
30 std::string secret_str
;
32 vector
<const char *> args
= { "--name", name
};
36 args
.push_back("--conf");
37 args
.push_back(config_file
);
40 /* Create CephContext */
41 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
42 CODE_ENVIRONMENT_UTILITY
,
43 CINIT_FLAG_NO_DAEMON_ACTIONS
|CINIT_FLAG_NO_MON_CONFIG
);
44 auto& conf
= cct
->_conf
;
46 conf
.parse_env(cct
->get_module_type()); // environment variables override
47 conf
.apply_changes(nullptr);
49 auto fsid
= conf
.get_val
<uuid_d
>("fsid");
50 fsid
.print(cci
->cci_fsid
);
52 ceph::async::io_context_pool
ioc(1);
53 MonClient monc
= MonClient(cct
.get(), ioc
);
54 err
= monc
.build_initial_monmap();
58 for (const auto& mon
: monc
.monmap
.addr_mons
) {
59 auto& eaddr
= mon
.first
;
62 * Filter v1 addrs if we're running in ms_mode=legacy. Filter
63 * v2 addrs for any other ms_mode.
66 if (!eaddr
.is_msgr2())
69 if (!eaddr
.is_legacy())
74 addr
+= eaddr
.ip_only_to_str();
76 addr
+= std::to_string(eaddr
.get_port());
77 /* If this will overrun cci_mons, stop here */
78 if (monaddrs
.length() + 1 + addr
.length() + 1 > sizeof(cci
->cci_mons
))
89 if (monaddrs
.length())
90 strcpy(cci
->cci_mons
, monaddrs
.c_str());
92 mount_ceph_debug("Could not discover monitor addresses\n");
95 err
= keyring
.from_ceph_context(cct
.get());
97 mount_ceph_debug("keyring.from_ceph_context failed: %d\n", err
);
101 if (!keyring
.get_secret(conf
->name
, secret
)) {
102 mount_ceph_debug("keyring.get_secret failed\n");
106 secret
.encode_base64(secret_str
);
108 if (secret_str
.length() + 1 > sizeof(cci
->cci_secret
)) {
109 mount_ceph_debug("secret is too long\n");
112 strcpy(cci
->cci_secret
, secret_str
.c_str());