From: John Spray Date: Tue, 20 May 2014 11:48:49 +0000 (+0100) Subject: tools/cephfs: error handling in EventOutput X-Git-Tag: v0.82~48^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F1739%2Fhead;p=ceph.git tools/cephfs: error handling in EventOutput Print error instead of hitting assertion if we e.g. can't create directory. Signed-off-by: John Spray --- diff --git a/src/tools/cephfs/EventOutput.cc b/src/tools/cephfs/EventOutput.cc index 63cb574521d4..e5cbf2478716 100644 --- a/src/tools/cephfs/EventOutput.cc +++ b/src/tools/cephfs/EventOutput.cc @@ -24,13 +24,13 @@ #include "EventOutput.h" -void EventOutput::binary() const +int EventOutput::binary() const { // Binary output, files int r = ::mkdir(path.c_str(), 0755); if (r != 0) { std::cerr << "Error creating output directory: " << cpp_strerror(r) << std::endl; - assert(r == 0); + return r; } for (JournalScanner::EventMap::const_iterator i = scan.events.begin(); i != scan.events.end(); ++i) { @@ -44,11 +44,16 @@ void EventOutput::binary() const std::ofstream bin_file(file_path.c_str(), std::ofstream::out | std::ofstream::binary); le_bin.write_stream(bin_file); bin_file.close(); + if (bin_file.fail()) { + return -EIO; + } } std::cerr << "Wrote output to binary files in directory '" << path << "'" << std::endl; + + return 0; } -void EventOutput::json() const +int EventOutput::json() const { JSONFormatter jf(true); std::ofstream out_file(path.c_str(), std::ofstream::out); @@ -66,7 +71,13 @@ void EventOutput::json() const jf.close_section(); // journal jf.flush(out_file); out_file.close(); - std::cerr << "Wrote output to JSON file '" << path << "'" << std::endl; + + if (out_file.fail()) { + return -EIO; + } else { + std::cerr << "Wrote output to JSON file '" << path << "'" << std::endl; + return 0; + } } void EventOutput::list() const diff --git a/src/tools/cephfs/EventOutput.h b/src/tools/cephfs/EventOutput.h index 2c93794dbd9c..65d968409b4e 100644 --- a/src/tools/cephfs/EventOutput.h +++ b/src/tools/cephfs/EventOutput.h @@ -34,8 +34,8 @@ class EventOutput void summary() const; void list() const; - void json() const; - void binary() const; + int json() const; + int binary() const; }; #endif // EVENT_OUTPUT_H diff --git a/src/tools/cephfs/JournalTool.cc b/src/tools/cephfs/JournalTool.cc index c11cabafd331..fa6bf2b1bd27 100644 --- a/src/tools/cephfs/JournalTool.cc +++ b/src/tools/cephfs/JournalTool.cc @@ -378,20 +378,25 @@ int JournalTool::main_event(std::vector &argv) // Generate output // =============== EventOutput output(js, output_path); + int output_result = 0; if (output_style == "binary") { - output.binary(); + output_result = output.binary(); } else if (output_style == "json") { - output.json(); + output_result = output.json(); } else if (output_style == "summary") { output.summary(); } else if (output_style == "list") { output.list(); } else { - derr << "Bad output command '" << output_style << "'" << dendl; + std::cerr << "Bad output command '" << output_style << "'" << std::endl; return -EINVAL; } - return 0; + if (output_result != 0) { + std::cerr << "Error writing output: " << cpp_strerror(output_result) << std::endl; + } + + return output_result; } /**