| 190 | } |
| 191 | |
| 192 | static int build_map_buf(CephContext *cct, const krbd_spec& spec, |
| 193 | const string& options, string *pbuf) |
| 194 | { |
| 195 | bool msgr2 = true; |
| 196 | bool ms_mode_specified = false; |
| 197 | std::ostringstream oss; |
| 198 | int r; |
| 199 | |
| 200 | boost::char_separator<char> sep(","); |
| 201 | boost::tokenizer<boost::char_separator<char>> tok(options, sep); |
| 202 | for (const auto& t : tok) { |
| 203 | if (boost::starts_with(t, "ms_mode=")) { |
| 204 | /* msgr2 unless ms_mode=legacy */ |
| 205 | msgr2 = t.compare(8, t.npos, "legacy"); |
| 206 | ms_mode_specified = true; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | MonMap monmap; |
| 211 | r = monmap.build_initial(cct, false, std::cerr); |
| 212 | if (r < 0) |
| 213 | return r; |
| 214 | |
| 215 | /* |
| 216 | * If msgr2, filter TYPE_MSGR2 addresses. Otherwise, filter |
| 217 | * TYPE_LEGACY addresses. |
| 218 | */ |
| 219 | for (const auto& p : monmap.mon_info) { |
| 220 | for (const auto& a : p.second.public_addrs.v) { |
| 221 | if ((msgr2 && a.is_msgr2()) || (!msgr2 && a.is_legacy())) { |
| 222 | if (oss.tellp() > 0) { |
| 223 | oss << ","; |
| 224 | } |
| 225 | oss << a.get_sockaddr(); |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | if (oss.tellp() == 0) { |
| 231 | std::cerr << "rbd: failed to get mon address (possible ms_mode mismatch)" << std::endl; |
| 232 | return -ENOENT; |
| 233 | } |
| 234 | |
| 235 | oss << " name=" << cct->_conf->name.get_id(); |
| 236 | |
| 237 | KeyRing keyring; |
| 238 | auto auth_client_required = |
| 239 | cct->_conf.get_val<std::string>("auth_client_required"); |
| 240 | if (auth_client_required != "none") { |
| 241 | r = keyring.from_ceph_context(cct); |
| 242 | auto keyfile = cct->_conf.get_val<std::string>("keyfile"); |
| 243 | auto key = cct->_conf.get_val<std::string>("key"); |
| 244 | if (r == -ENOENT && keyfile.empty() && key.empty()) |
| 245 | r = 0; |
| 246 | if (r < 0) { |
| 247 | std::cerr << "rbd: failed to get secret" << std::endl; |
| 248 | return r; |
| 249 | } |
no test coverage detected