From 83b695f08e6efa400a581a1cd56ae030661c3fbb Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Mon, 10 Apr 2017 22:51:18 +0200 Subject: [PATCH] osd: split mon_cmd_maybe_osd_create out of update_crush_location Signed-off-by: Loic Dachary --- src/osd/OSD.cc | 73 +++++++++++++++++++++++++++----------------------- src/osd/OSD.h | 1 + 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 4350b5de28c..ea67e40f843 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -3021,6 +3021,44 @@ int OSD::shutdown() return r; } +int OSD::mon_cmd_maybe_osd_create(string &cmd) +{ + bool created = false; + while (true) { + dout(10) << __func__ << " cmd: " << cmd << dendl; + vector vcmd{cmd}; + bufferlist inbl; + C_SaferCond w; + string outs; + monc->start_mon_command(vcmd, inbl, NULL, &outs, &w); + int r = w.wait(); + if (r < 0) { + if (r == -ENOENT && !created) { + string newcmd = "{\"prefix\": \"osd create\", \"id\": " + stringify(whoami) + + ", \"uuid\": \"" + stringify(superblock.osd_fsid) + "\"}"; + vector vnewcmd{newcmd}; + bufferlist inbl; + C_SaferCond w; + string outs; + monc->start_mon_command(vnewcmd, inbl, NULL, &outs, &w); + int r = w.wait(); + if (r < 0) { + derr << __func__ << " fail: osd does not exist and created failed: " + << cpp_strerror(r) << dendl; + return r; + } + created = true; + continue; + } + derr << __func__ << " fail: '" << outs << "': " << cpp_strerror(r) << dendl; + return r; + } + break; + } + + return 0; +} + int OSD::update_crush_location() { if (!cct->_conf->osd_crush_update_on_start) { @@ -3059,40 +3097,7 @@ int OSD::update_crush_location() } cmd += "]}"; - bool created = false; - while (true) { - dout(10) << __func__ << " cmd: " << cmd << dendl; - vector vcmd{cmd}; - bufferlist inbl; - C_SaferCond w; - string outs; - monc->start_mon_command(vcmd, inbl, NULL, &outs, &w); - int r = w.wait(); - if (r < 0) { - if (r == -ENOENT && !created) { - string newcmd = "{\"prefix\": \"osd create\", \"id\": " + stringify(whoami) - + ", \"uuid\": \"" + stringify(superblock.osd_fsid) + "\"}"; - vector vnewcmd{newcmd}; - bufferlist inbl; - C_SaferCond w; - string outs; - monc->start_mon_command(vnewcmd, inbl, NULL, &outs, &w); - int r = w.wait(); - if (r < 0) { - derr << __func__ << " fail: osd does not exist and created failed: " - << cpp_strerror(r) << dendl; - return r; - } - created = true; - continue; - } - derr << __func__ << " fail: '" << outs << "': " << cpp_strerror(r) << dendl; - return r; - } - break; - } - - return 0; + return mon_cmd_maybe_osd_create(cmd); } diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 33f54765e73..90821997caa 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -2414,6 +2414,7 @@ protected: } private: + int mon_cmd_maybe_osd_create(string &cmd); int update_crush_location(); static int write_meta(ObjectStore *store, -- 2.47.3