Skip to content

Commit

Permalink
os/FileJournal: Tune the judge logic for read_header.
Browse files Browse the repository at this point in the history
When reading journal-header, it should firstly check the result of
pread and then do decoce operation.

Signed-off-by: Ma Jianpeng <jianpeng.ma@intel.com>
  • Loading branch information
majianpeng committed Aug 21, 2014
1 parent b0aa846 commit c8e2b89
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/os/FileJournal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,13 @@ int FileJournal::read_header()
buffer::ptr bp = buffer::create_page_aligned(block_size);
bp.zero();
int r = ::pread(fd, bp.c_str(), bp.length(), 0);

if (r < 0) {
int err = errno;
dout(0) << "read_header got " << cpp_strerror(err) << dendl;
return -err;
}

bl.push_back(bp);

try {
Expand All @@ -660,11 +667,6 @@ int FileJournal::read_header()
return -EINVAL;
}

if (r < 0) {
int err = errno;
dout(0) << "read_header got " << cpp_strerror(err) << dendl;
return -err;
}

/*
* Unfortunately we weren't initializing the flags field for new
Expand Down

0 comments on commit c8e2b89

Please sign in to comment.