Find a zoned partition automatically

Since we cannot create a gpt table on zoned LU, we cannot make a generic symlink
from it. Instead, let's make it by uevent, "/dev/block/by-name/zoned_device".
Note that, we support only one zoned device in the system.

Bug: 265180564
Change-Id: Ie62b0fd68b77e3e43cf0f5c5cad9503150174271
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
This commit is contained in:
Jaegeuk Kim 2023-01-12 13:08:15 -08:00
parent 9b9924b412
commit b92e5b5c48
2 changed files with 11 additions and 8 deletions

View file

@ -304,19 +304,16 @@ bool ParseFsMgrFlags(const std::string& flags, FstabEntry* entry) {
if (!ParseByteCount(arg, &entry->zram_backingdev_size)) {
LWARNING << "Warning: zram_backingdev_size= flag malformed: " << arg;
}
} else if (StartsWith(flag, "zoned_device=")) {
std::string zoned;
if (ReadFileToString("/sys/class/block/" + arg + "/queue/zoned", &zoned) &&
android::base::StartsWith(zoned, "host-managed")) {
entry->zoned_device = "/dev/block/" + arg;
} else if (flag == "zoned_device") {
if (access("/dev/block/by-name/zoned_device", F_OK) == 0) {
entry->zoned_device = "/dev/block/by-name/zoned_device";
// atgc in f2fs does not support a zoned device
auto options = Split(entry->fs_options, ",");
options.erase(std::remove(options.begin(), options.end(), "atgc"), options.end());
entry->fs_options = android::base::Join(options, ",");
LINFO << "Removed ATGC in fs_options as " << entry->fs_options;
} else {
LWARNING << "Warning: cannot find the zoned device: " << arg;
LINFO << "Removed ATGC in fs_options as " << entry->fs_options
<< " for zoned device=" << entry->zoned_device;
}
} else {
LWARNING << "Warning: unknown flag: " << flag;

View file

@ -431,6 +431,12 @@ std::vector<std::string> DeviceHandler::GetBlockDeviceSymlinks(const Uevent& uev
}
}
std::string model;
if (ReadFileToString("/sys/class/block/" + uevent.device_name + "/queue/zoned", &model) &&
!StartsWith(model, "none")) {
links.emplace_back("/dev/block/by-name/zoned_device");
}
auto last_slash = uevent.path.rfind('/');
links.emplace_back(link_path + "/" + uevent.path.substr(last_slash + 1));