aboutsummaryrefslogtreecommitdiff
path: root/filesystem
diff options
context:
space:
mode:
authorNymanRobin <robin.nyman@est.tech>2024-05-02 11:20:01 +0300
committerNymanRobin <robin.nyman@est.tech>2024-05-02 20:47:35 +0300
commit068b9f8f5dec46b222470f6d3f03244ba5b65f5c (patch)
tree09bf87792cb014f01a6b5b9121275eadaa655a78 /filesystem
parent54745f1c7b5e1c51e7842df2d95b37e0de4695ca (diff)
Compare mount by value instead of reference
This has to be since the mounts are reloaded each time a mount is added. In case of two mounts mounting at the same time there will be a race condition for applying policy. Signed-off-by: NymanRobin <robin.nyman@est.tech>
Diffstat (limited to 'filesystem')
-rw-r--r--filesystem/mountpoint_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/filesystem/mountpoint_test.go b/filesystem/mountpoint_test.go
index f06219c..fd7e05d 100644
--- a/filesystem/mountpoint_test.go
+++ b/filesystem/mountpoint_test.go
@@ -27,6 +27,7 @@ import (
"fmt"
"os"
"path/filepath"
+ "reflect"
"strings"
"testing"
)
@@ -544,3 +545,21 @@ func BenchmarkLoadFirst(b *testing.B) {
}
}
}
+
+// Test mount comparison by values instead of by reference,
+// as the map mountsByDevice gets recreated on each load.
+// This ensures that concurrent mounts work properly.
+func TestMountComparison(t *testing.T) {
+ var mountinfo = `
+15 0 259:3 / /home rw,relatime shared:1 - ext4 /dev/root rw,data=ordered
+`
+ beginLoadMountInfoTest()
+ defer endLoadMountInfoTest()
+ loadMountInfoFromString(mountinfo)
+ firstMnt := mountForDevice("259:3")
+ loadMountInfoFromString(mountinfo)
+ secondMnt := mountForDevice("259:3")
+ if !reflect.DeepEqual(firstMnt, secondMnt) {
+ t.Errorf("Mount comparison does not work")
+ }
+}