Skip to content

Commit

Permalink
fs,util: Fix a bug where zone locks are not handled correctly
Browse files Browse the repository at this point in the history
Change signature of `ListZenFileSystems` to return status by value and file
system list by reference.

Reported-by: Mohit Joshi <[email protected]>
Reported-by: Yura Sorokin <[email protected]>
Signed-off-by: Andreas Hindborg <[email protected]>
  • Loading branch information
metaspace authored and yhr committed Jan 5, 2022
1 parent 756b86e commit 52b9c51
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
32 changes: 21 additions & 11 deletions fs/fs_zenfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1155,8 +1155,9 @@ Status NewZenFS(FileSystem** fs, const std::string& bdevname,
return Status::OK();
}

std::map<std::string, std::string> ListZenFileSystems() {
Status ListZenFileSystems(std::map<std::string, std::string>& out_list) {
std::map<std::string, std::string> zenFileSystems;

auto closedirDeleter = [](DIR* d) {
if (d != nullptr) closedir(d);
};
Expand All @@ -1180,6 +1181,10 @@ std::map<std::string, std::string> ListZenFileSystems() {
for (const auto z : metazones) {
Superblock super_block;
std::unique_ptr<ZenMetaLog> log;
if (!z->Acquire()) {
return Status::Aborted("Could not aquire busy flag of zone" +
std::to_string(z->GetZoneNr()));
}
log.reset(new ZenMetaLog(zbd.get(), z));

if (!log->ReadRecord(&super_record, &scratch).ok()) continue;
Expand All @@ -1202,7 +1207,8 @@ std::map<std::string, std::string> ListZenFileSystems() {
}
}

return zenFileSystems;
out_list = std::move(zenFileSystems);
return Status::OK();
}

void ZenFS::GetZoneSnapshot(std::vector<ZoneSnapshot>& zones) {
Expand Down Expand Up @@ -1234,16 +1240,20 @@ FactoryFunc<FileSystem> zenfs_filesystem_reg =
*errmsg = s.ToString();
}
} else if (devID.rfind("uuid:") == 0) {
std::map<std::string, std::string> zenFileSystems =
ListZenFileSystems();
devID.replace(0, strlen("uuid:"), "");

if (zenFileSystems.find(devID) == zenFileSystems.end()) {
*errmsg = "UUID not found";
std::map<std::string, std::string> zenFileSystems;
s = ListZenFileSystems(zenFileSystems);
if (!s.ok()) {
*errmsg = s.ToString();
} else {
s = NewZenFS(&fs, zenFileSystems[devID]);
if (!s.ok()) {
*errmsg = s.ToString();
devID.replace(0, strlen("uuid:"), "");

if (zenFileSystems.find(devID) == zenFileSystems.end()) {
*errmsg = "UUID not found";
} else {
s = NewZenFS(&fs, zenFileSystems[devID]);
if (!s.ok()) {
*errmsg = s.ToString();
}
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion fs/fs_zenfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,6 @@ class ZenFS : public FileSystemWrapper {
Status NewZenFS(
FileSystem** fs, const std::string& bdevname,
std::shared_ptr<ZenFSMetrics> metrics = std::make_shared<NoZenFSMetrics>());
std::map<std::string, std::string> ListZenFileSystems();
Status ListZenFileSystems(std::map<std::string, std::string>& out_list);

} // namespace ROCKSDB_NAMESPACE
8 changes: 7 additions & 1 deletion util/zenfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,13 @@ int zenfs_tool_df() {
}

int zenfs_tool_lsuuid() {
std::map<std::string, std::string> zenFileSystems = ListZenFileSystems();
std::map<std::string, std::string> zenFileSystems;
Status s = ListZenFileSystems(zenFileSystems);
if (!s.ok()) {
fprintf(stderr, "Failed to enumerate file systems: %s",
s.ToString().c_str());
return 1;
}

for (const auto &p : zenFileSystems)
fprintf(stdout, "%s\t%s\n", p.first.c_str(), p.second.c_str());
Expand Down

0 comments on commit 52b9c51

Please sign in to comment.