From 262f1e8096a0a93de4a7a6dba1ae38b88da2e82b Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 23 May 2024 11:20:07 -0700 Subject: [PATCH] Create the /dev/sys/block/by-name/zoned_device symbolic link This link will be used to change the sysfs attributes of the zoned block device from an .rc file. Bug: 335708738 Change-Id: I99f74c121e7d9da404c0564860c03ac1efe6c6d8 Signed-off-by: Bart Van Assche --- init/devices.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/init/devices.cpp b/init/devices.cpp index 792d8c843..5560c20bc 100644 --- a/init/devices.cpp +++ b/init/devices.cpp @@ -435,6 +435,7 @@ std::vector DeviceHandler::GetBlockDeviceSymlinks(const Uevent& uev if (ReadFileToString("/sys/class/block/" + uevent.device_name + "/queue/zoned", &model) && !StartsWith(model, "none")) { links.emplace_back("/dev/block/by-name/zoned_device"); + links.emplace_back("/dev/sys/block/by-name/zoned_device"); } auto last_slash = uevent.path.rfind('/'); @@ -483,11 +484,21 @@ void DeviceHandler::HandleDevice(const std::string& action, const std::string& d // event. if (action == "add" || (action == "change" && StartsWith(devpath, "/dev/block/dm-"))) { for (const auto& link : links) { + std::string target; + if (StartsWith(link, "/dev/block/")) { + target = devpath; + } else if (StartsWith(link, "/dev/sys/block/")) { + target = "/sys/class/block/" + Basename(devpath); + } else { + LOG(ERROR) << "Unrecognized link type: " << link; + continue; + } + if (!mkdir_recursive(Dirname(link), 0755)) { PLOG(ERROR) << "Failed to create directory " << Dirname(link); } - if (symlink(devpath.c_str(), link.c_str())) { + if (symlink(target.c_str(), link.c_str())) { if (errno != EEXIST) { PLOG(ERROR) << "Failed to symlink " << devpath << " to " << link; } else if (std::string link_path;