From f745fc799096a26974f35fda95bf3353b7b7356e Mon Sep 17 00:00:00 2001 From: Gu Zhongyan Date: Fri, 27 Apr 2018 18:20:02 +0800 Subject: [PATCH] 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 (cherry picked from commit 00c5a30fa9b056ec97ff0b56e195b9a21dd1c136) --- src/crush/CrushLocation.cc | 4 +++- src/osd/OSD.cc | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/crush/CrushLocation.cc b/src/crush/CrushLocation.cc index 4831616c0cb3a..4766a618ab5ea 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 8a28fe55f8f93..931b7d86f954d 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; } -- 2.39.5