From ee082d3120f29af98bd8f1e933a9a3706e1f6386 Mon Sep 17 00:00:00 2001
From: gcontini <1121667+gcontini@users.noreply.github.com>
Date: 周日, 08 11月 2020 09:15:12 +0800
Subject: [PATCH] centos fix

---
 src/library/os/linux/os_linux.cpp |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/src/library/os/linux/os_linux.cpp b/src/library/os/linux/os_linux.cpp
index 9e75125..2915808 100644
--- a/src/library/os/linux/os_linux.cpp
+++ b/src/library/os/linux/os_linux.cpp
@@ -97,7 +97,7 @@
 
 FUNCTION_RETURN parse_blkid(const std::string &blkid_file_content, std::vector<DiskInfo> &diskInfos_out,
 							std::unordered_map<std::string, int> &disk_by_uuid) {
-	DiskInfo diskInfo;
+	DiskInfo diskInfo = {};
 	int diskNum = 0;
 	for (std::size_t oldpos = 0, pos = 0; (pos = blkid_file_content.find("</device>", oldpos)) != std::string::npos;
 		 oldpos = pos + 1) {
@@ -111,6 +111,8 @@
 		parseUUID(disk_sn.c_str(), diskInfo.disk_sn, sizeof(diskInfo.disk_sn));
 		std::string disk_type = getAttribute(cur_dev, "TYPE");
 		disk_by_uuid.insert(std::pair<std::string, int>(disk_sn, diskInfo.id));
+		diskInfo.label_initialized = true;
+		diskInfo.sn_initialized = true;
 		// unlikely that somebody put the swap on a removable disk.
 		// this is a first rough guess on what can be a preferred disk for blkid devices
 		// just in case /etc/fstab can't be accessed or it is not up to date.
@@ -277,6 +279,16 @@
 			} else {
 				LOG_DEBUG("fstab device %s found, but no corresponding diskInfo", ent->mnt_fsname);
 			}
+		} else if (strncmp("LABEL=", ent->mnt_fsname, 6) == 0) {
+			// fstab entry is uuid
+			device_name_s = device_name_s.substr(6);
+			for (auto &disk_info : diskInfos) {
+				if (device_name_s == disk_info.label) {
+					disk_info.preferred = true;
+					LOG_DEBUG("Disk %d device %s set as preferred", disk_info.id, disk_info.device);
+					break;
+				}
+			}
 		} else {
 			// fstab entry is a device
 			auto pos = device_name_s.find_last_of("/");

--
Gitblit v1.9.1