From: Gu Zhongyan Date: Fri, 27 Apr 2018 10:20:02 +0000 (+0800) Subject: osd: fix osd smart data collection segment fault issue. X-Git-Tag: v14.0.0~144^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F21691%2Fhead;p=ceph.git osd: fix osd smart data collection segment fault issue. output.read_fd() could return zero length. it needs to be handled gracefully. always call invoke join() if spawn() is successfully returned. otherwise there will be assert failure in ~SubProcess(). Fixes: http://tracker.ceph.com/issues/23899 Signed-off-by: Gu Zhongyan --- diff --git a/src/crush/CrushLocation.cc b/src/crush/CrushLocation.cc index 4831616c0cb3..4766a618ab5e 100644 --- a/src/crush/CrushLocation.cc +++ b/src/crush/CrushLocation.cc @@ -76,7 +76,6 @@ int CrushLocation::update_from_hook() lderr(cct) << "stderr:\n"; err.hexdump(*_dout); *_dout << dendl; - return ret; } if (hook.join() != 0) { @@ -84,6 +83,9 @@ int CrushLocation::update_from_hook() return -EINVAL; } + if (ret < 0) + return ret; + std::string out; bl.copy(0, bl.length(), out); out.erase(out.find_last_not_of(" \n\r\t")+1); diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 734d1db7b47a..af085fc8320f 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -6301,17 +6301,19 @@ int OSD::probe_smart_device(const char *device, int timeout, std::string *result ret = output.read_fd(smartctl.get_stdout(), 100*1024); if (ret < 0) { derr << "failed read from smartctl: " << cpp_strerror(-ret) << dendl; - return ret; + } else { + *result = output.to_str(); + dout(10) << "smartctl output is: " << *result << dendl; } - derr << "smartctl output is: " << output.c_str() << dendl; - *result = output.c_str(); - if (smartctl.join() != 0) { derr << smartctl.err() << dendl; return -EINVAL; } + if (ret < 0) + return ret; + return 0; }