Skip to content

Commit b735d5c

Browse files
committed
Dont remount /run/virtiofs when adding container
1 parent 50f7722 commit b735d5c

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

Sources/Containerization/LinuxPod.swift

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ public final class LinuxPod: Sendable {
195195
var phase: Phase
196196
var containers: [String: PodContainer]
197197
var pauseProcess: LinuxProcess?
198+
// Whether the unified virtiofs share is mounted at `/run/virtiofs` in the guest
199+
var unifiedVirtiofsMounted: Bool = false
198200
}
199201

200202
private enum Phase: Sendable {
@@ -451,17 +453,17 @@ extension LinuxPod {
451453
// and is never consumed from /run/virtiofs.
452454
let newVirtiofsTags = try virtioFSMounts.map { try hashFilePath(path: $0.source) }
453455
if !newVirtiofsTags.isEmpty {
454-
// Tags already mounted in the guest at boot or by a
455-
// prior hotplug (i.e. present on another container).
456-
let alreadyMounted = Set(
457-
vm.mounts
458-
.filter { $0.key != id }
459-
.values.flatMap { $0 }
460-
.filter { $0.type == "virtiofs" }
461-
.map { $0.source }
462-
)
463456
try await agent.mkdir(path: "/run/virtiofs", all: true, perms: 0o755)
464457
if vm.virtiofsLayout == .perTag {
458+
// Tags already mounted in the guest at boot or by a
459+
// prior hotplug (i.e. present on another container).
460+
let alreadyMounted = Set(
461+
vm.mounts
462+
.filter { $0.key != id }
463+
.values.flatMap { $0 }
464+
.filter { $0.type == "virtiofs" }
465+
.map { $0.source }
466+
)
465467
var seen: Set<String> = []
466468
for tag in newVirtiofsTags
467469
where !alreadyMounted.contains(tag) && seen.insert(tag).inserted {
@@ -475,16 +477,18 @@ extension LinuxPod {
475477
options: []
476478
))
477479
}
478-
} else if alreadyMounted.isEmpty {
479-
// Unified layout: one /run/virtiofs mount, needed
480-
// only if nothing mounted it at boot / earlier.
480+
} else if !state.unifiedVirtiofsMounted && vm.virtiofsLayout == .unified {
481+
// Unified layout: one /run/virtiofs mount for the
482+
// VM's lifetime, so mount it only if nothing has
483+
// mounted it at boot or on an earlier hotplug.
481484
try await agent.mount(
482485
ContainerizationOCI.Mount(
483486
type: "virtiofs",
484487
source: "virtiofs",
485488
destination: "/run/virtiofs",
486489
options: []
487490
))
491+
state.unifiedVirtiofsMounted = true
488492
}
489493
}
490494

@@ -812,6 +816,7 @@ extension LinuxPod {
812816
}
813817

814818
state.pauseProcess = pauseProcessHolder.withLock { $0 }
819+
state.unifiedVirtiofsMounted = hasVirtiofsMount && vm.virtiofsLayout == .unified
815820

816821
// Apply file mount context updates.
817822
let updates = fileMountContextUpdates.withLock { $0 }

0 commit comments

Comments
 (0)