From e1bc0576eaebf5cc09245512d5eb185072b2d408 Mon Sep 17 00:00:00 2001
From: gcontini <1121667+gcontini@users.noreply.github.com>
Date: 周日, 25 10月 2020 18:45:51 +0800
Subject: [PATCH] fix fstab LABEL= entries

---
 test/library/os_linux_test.cpp    |    2 +-
 src/library/os/linux/os_linux.cpp |   10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/src/library/os/linux/os_linux.cpp b/src/library/os/linux/os_linux.cpp
index 9e75125..c203e4e 100644
--- a/src/library/os/linux/os_linux.cpp
+++ b/src/library/os/linux/os_linux.cpp
@@ -277,6 +277,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("/");
diff --git a/test/library/os_linux_test.cpp b/test/library/os_linux_test.cpp
index ed9d43e..bfb6a91 100644
--- a/test/library/os_linux_test.cpp
+++ b/test/library/os_linux_test.cpp
@@ -45,7 +45,7 @@
 		}
 		BOOST_CHECK_MESSAGE(uuid_found, "At least one UUID initialized");
 		BOOST_CHECK_MESSAGE(label_found, "At least one label found");
-		// BOOST_CHECK_MESSAGE(preferred_found, "At least one standard mounted file system");
+		BOOST_CHECK_MESSAGE(preferred_found, "At least one standard mounted file system");
 	} else if (virt == LCC_API_VIRTUALIZATION_SUMMARY::CONTAINER) {
 		// in docker or lxc diskInfo is very likely not to find any good disk.
 		BOOST_CHECK_EQUAL(result, FUNC_RET_NOT_AVAIL);

--
Gitblit v1.9.1