From e67e5700288bbb9ab1420beb85e091ffa8e0c994 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Tue, 15 Dec 2020 08:51:35 -0800 Subject: [PATCH] Add zoned device support Format f2fs zoned device. Bug: 172378121 Signed-off-by: Jaegeuk Kim Change-Id: Ic7f564ce5786c635ee1e1f6d0b33c1f4d08f780a --- fs_mgr/fs_mgr.cpp | 6 +++--- fs_mgr/fs_mgr_format.cpp | 15 +++++++++++---- fs_mgr/fs_mgr_fstab.cpp | 8 ++++++++ fs_mgr/include_fstab/fstab/fstab.h | 1 + 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp index 7c7979ba0..c12a6726f 100644 --- a/fs_mgr/fs_mgr.cpp +++ b/fs_mgr/fs_mgr.cpp @@ -1485,7 +1485,7 @@ MountAllResult fs_mgr_mount_all(Fstab* fstab, int mount_mode) { if (status == FS_MGR_MNTALL_DEV_NEEDS_METADATA_ENCRYPTION) { if (!call_vdc({"cryptfs", "encryptFstab", attempted_entry.blk_device, attempted_entry.mount_point, wiped ? "true" : "false", - attempted_entry.fs_type}, + attempted_entry.fs_type, attempted_entry.zoned_device}, nullptr)) { LERROR << "Encryption failed"; set_type_property(encryptable); @@ -1525,7 +1525,7 @@ MountAllResult fs_mgr_mount_all(Fstab* fstab, int mount_mode) { if (!call_vdc({"cryptfs", "encryptFstab", current_entry.blk_device, current_entry.mount_point, "true" /* shouldFormat */, - current_entry.fs_type}, + current_entry.fs_type, current_entry.zoned_device}, nullptr)) { LERROR << "Encryption failed"; } else { @@ -1550,7 +1550,7 @@ MountAllResult fs_mgr_mount_all(Fstab* fstab, int mount_mode) { if (mount_errno != EBUSY && mount_errno != EACCES && should_use_metadata_encryption(attempted_entry)) { if (!call_vdc({"cryptfs", "mountFstab", attempted_entry.blk_device, - attempted_entry.mount_point}, + attempted_entry.mount_point, attempted_entry.zoned_device}, nullptr)) { ++error_count; } else if (current_entry.mount_point == "/data") { diff --git a/fs_mgr/fs_mgr_format.cpp b/fs_mgr/fs_mgr_format.cpp index 6f59ed36e..7385f7961 100644 --- a/fs_mgr/fs_mgr_format.cpp +++ b/fs_mgr/fs_mgr_format.cpp @@ -117,7 +117,7 @@ static int format_ext4(const std::string& fs_blkdev, const std::string& fs_mnt_p } static int format_f2fs(const std::string& fs_blkdev, uint64_t dev_sz, bool needs_projid, - bool needs_casefold, bool fs_compress) { + bool needs_casefold, bool fs_compress, const std::string& zoned_device) { if (!dev_sz) { int rc = get_dev_sz(fs_blkdev, &dev_sz); if (rc) { @@ -146,8 +146,15 @@ static int format_f2fs(const std::string& fs_blkdev, uint64_t dev_sz, bool needs args.push_back("-O"); args.push_back("extra_attr"); } - args.push_back(fs_blkdev.c_str()); - args.push_back(size_str.c_str()); + if (!zoned_device.empty()) { + args.push_back("-c"); + args.push_back(zoned_device.c_str()); + args.push_back("-m"); + args.push_back(fs_blkdev.c_str()); + } else { + args.push_back(fs_blkdev.c_str()); + args.push_back(size_str.c_str()); + } return logwrap_fork_execvp(args.size(), args.data(), nullptr, false, LOG_KLOG, false, nullptr); } @@ -164,7 +171,7 @@ int fs_mgr_do_format(const FstabEntry& entry) { if (entry.fs_type == "f2fs") { return format_f2fs(entry.blk_device, entry.length, needs_projid, needs_casefold, - entry.fs_mgr_flags.fs_compress); + entry.fs_mgr_flags.fs_compress, entry.zoned_device); } else if (entry.fs_type == "ext4") { return format_ext4(entry.blk_device, entry.mount_point, needs_projid, entry.fs_mgr_flags.ext_meta_csum); diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp index 8c719c868..06368b86b 100644 --- a/fs_mgr/fs_mgr_fstab.cpp +++ b/fs_mgr/fs_mgr_fstab.cpp @@ -304,6 +304,14 @@ 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 { + LWARNING << "Warning: cannot find the zoned device: " << arg; + } } else { LWARNING << "Warning: unknown flag: " << flag; } diff --git a/fs_mgr/include_fstab/fstab/fstab.h b/fs_mgr/include_fstab/fstab/fstab.h index f26fb245a..8f200a819 100644 --- a/fs_mgr/include_fstab/fstab/fstab.h +++ b/fs_mgr/include_fstab/fstab/fstab.h @@ -31,6 +31,7 @@ namespace fs_mgr { struct FstabEntry { std::string blk_device; + std::string zoned_device; std::string logical_partition_name; std::string mount_point; std::string fs_type;