Skip to content

Commit

Permalink
os/bluestore/bluestore_tool: Move redundant code into one method
Browse files Browse the repository at this point in the history
Signed-off-by: Shinobu Kinjo <[email protected]>
  • Loading branch information
shinobu-x committed Nov 27, 2017
1 parent e984538 commit 6f6f433
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions src/os/bluestore/bluestore_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ BlueFS *open_bluefs(
return fs;
}

void infering_bluefs_devices(vector<string>& devs, std::string& path)
{
cout << "infering bluefs devices from bluestore path" << std::endl;
for (auto fn : {"block", "block.wal", "block.db"}) {
string p = path + "/" + fn;
struct stat st;
if (::stat(p.c_str(), &st) == 0) {
devs.push_back(p);
}
}
}

int main(int argc, char **argv)
{
string out_dir;
Expand Down Expand Up @@ -241,16 +253,8 @@ int main(int argc, char **argv)
cerr << "must specify bluestore path *or* raw device(s)" << std::endl;
exit(EXIT_FAILURE);
}
if (devs.empty()) {
cout << "infering bluefs devices from bluestore path" << std::endl;
for (auto fn : {"block", "block.wal", "block.db"}) {
string p = path + "/" + fn;
struct stat st;
if (::stat(p.c_str(), &st) == 0) {
devs.push_back(p);
}
}
}
if (devs.empty())
infering_bluefs_devices(devs, path);
}
if (action == "bluefs-export" || action == "bluefs-log-dump") {
if (path.empty()) {
Expand All @@ -261,28 +265,14 @@ int main(int argc, char **argv)
cerr << "must specify out-dir to export bluefs" << std::endl;
exit(EXIT_FAILURE);
}
cout << "infering bluefs devices from bluestore path" << std::endl;
for (auto fn : {"block", "block.wal", "block.db"}) {
string p = path + "/" + fn;
struct stat st;
if (::stat(p.c_str(), &st) == 0) {
devs.push_back(p);
}
}
infering_bluefs_devices(devs, path);
}
if (action == "bluefs-bdev-sizes" || action == "bluefs-bdev-expand") {
if (path.empty()) {
cerr << "must specify bluestore path" << std::endl;
exit(EXIT_FAILURE);
}
cout << "infering bluefs devices from bluestore path" << std::endl;
for (auto fn : {"block", "block.wal", "block.db"}) {
string p = path + "/" + fn;
struct stat st;
if (::stat(p.c_str(), &st) == 0) {
devs.push_back(p);
}
}
infering_bluefs_devices(devs, path);
}

vector<const char*> args;
Expand Down Expand Up @@ -538,7 +528,6 @@ int main(int argc, char **argv)
cerr << "open " << path << " failed: " << cpp_strerror(r) << std::endl;
exit(EXIT_FAILURE);
}
assert(fd >= 0);
if (size > 0) {
BlueFS::FileReader *h;
r = fs->open_for_read(dir, file, &h, false);
Expand Down

0 comments on commit 6f6f433

Please sign in to comment.