From: Kefu Chai Date: Thu, 13 Jun 2019 14:38:02 +0000 (+0800) Subject: auth/KeyRing: remove KeyRing::create_empty() X-Git-Tag: v15.1.0~2464^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=341245f5baa23d0f142b0a9d69e7cab89031cc10;p=ceph.git auth/KeyRing: remove KeyRing::create_empty() it never fails unless out of memory. and it would be simpler to just allocate it on stack. Signed-off-by: Kefu Chai --- diff --git a/src/auth/KeyRing.cc b/src/auth/KeyRing.cc index 7f207d8fa538..c436df52b564 100644 --- a/src/auth/KeyRing.cc +++ b/src/auth/KeyRing.cc @@ -82,11 +82,6 @@ int KeyRing::from_ceph_context(CephContext *cct) return ret; } -KeyRing *KeyRing::create_empty() -{ - return new KeyRing(); -} - int KeyRing::set_modifier(const char *type, const char *val, EntityName& name, diff --git a/src/auth/KeyRing.h b/src/auth/KeyRing.h index 551ff7acc96d..d5fe7fabbd49 100644 --- a/src/auth/KeyRing.h +++ b/src/auth/KeyRing.h @@ -29,9 +29,6 @@ public: * We will use the configuration stored inside the context. */ int from_ceph_context(CephContext *cct); - /* Create an empty KeyRing */ - static KeyRing *create_empty(); - std::map& get_keys() { return keys; } // yuck int load(CephContext *cct, const std::string &filename); diff --git a/src/ceph_osd.cc b/src/ceph_osd.cc index 4ce211fa90fa..145f404f4235 100644 --- a/src/ceph_osd.cc +++ b/src/ceph_osd.cc @@ -321,25 +321,21 @@ int main(int argc, const char **argv) if (mkkey) { common_init_finish(g_ceph_context); - KeyRing *keyring = KeyRing::create_empty(); - if (!keyring) { - derr << "Unable to get a Ceph keyring." << dendl; - forker.exit(1); - } + KeyRing keyring; EntityName ename{g_conf()->name}; EntityAuth eauth; std::string keyring_path = g_conf().get_val("keyring"); - int ret = keyring->load(g_ceph_context, keyring_path); + int ret = keyring.load(g_ceph_context, keyring_path); if (ret == 0 && - keyring->get_auth(ename, eauth)) { + keyring.get_auth(ename, eauth)) { derr << "already have key in keyring " << keyring_path << dendl; } else { eauth.key.create(g_ceph_context, CEPH_CRYPTO_AES); - keyring->add(ename, eauth); + keyring.add(ename, eauth); bufferlist bl; - keyring->encode_plaintext(bl); + keyring.encode_plaintext(bl); int r = bl.write_file(keyring_path.c_str(), 0600); if (r) derr << TEXT_RED << " ** ERROR: writing new keyring to "