mountpoint-util: use mount_option_supported() to detect if 'discard' is support for an fs

This commit is contained in:
Lennart Poettering
2023-03-09 21:56:42 +01:00
parent 117e703447
commit 4e6d305ae2
2 changed files with 15 additions and 0 deletions
+9
View File
@@ -461,6 +461,15 @@ bool fstype_is_ro(const char *fstype) {
}
bool fstype_can_discard(const char *fstype) {
int r;
assert(fstype);
/* On new kernels we can just ask the kernel */
r = mount_option_supported(fstype, "discard", NULL);
if (r >= 0)
return r;
return STR_IN_SET(fstype,
"btrfs",
"f2fs",
+6
View File
@@ -349,6 +349,12 @@ TEST(mount_option_supported) {
assert_se(r >= 0 || (r < 0 && ERRNO_IS_PRIVILEGE(r)));
}
TEST(fstype_can_discard) {
assert_se(fstype_can_discard("ext4"));
assert_se(!fstype_can_discard("squashfs"));
assert_se(!fstype_can_discard("iso9660"));
}
static int intro(void) {
/* let's move into our own mount namespace with all propagation from the host turned off, so
* that /proc/self/mountinfo is static and constant for the whole time our test runs. */