Skip to content

Conversation

@realrajaryan
Copy link
Contributor

@realrajaryan realrajaryan commented Jul 22, 2025

Closes #339.

This change adds named volume support to container, providing volume management CLI commands - create, delete, list and inspect. The implementation uses EXT4 block-based persistent storage with a new VolumesService actor for thread-safe operations, integrates seamlessly with the existing container mount system through a new .volume filesystem type, and provides atomic volume operations with XPC-based API communication. Volumes are stored in isolated directories with configurable sizes (default 512GB) and include proper cleanup and container usage tracking for safe deletion.

Example Usage:

# Create a volume
container volume create mydata

# Use volume in container
container run -v mydata:/data alpine

# List volumes
container volume list

# Inspect volume details
container volume inspect mydata

# Clean up
container volume rm mydata

@realrajaryan realrajaryan requested review from dcantah and jglogan July 22, 2025 21:57
@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch from ce8c885 to 32360ad Compare July 22, 2025 22:15
@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch 2 times, most recently from 7f696c0 to 1886b21 Compare July 23, 2025 22:15
@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch from 1886b21 to a20913f Compare July 23, 2025 22:52
@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch from 8082c9d to f84e06b Compare July 25, 2025 02:03
@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch 2 times, most recently from a2ae64b to bc485a7 Compare July 25, 2025 02:40
Copy link
Contributor

@jglogan jglogan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - on to the sandbox work!

@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch 2 times, most recently from 0e34a15 to a637e3b Compare July 25, 2025 23:29
@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch 2 times, most recently from 6d6be85 to 12ef2af Compare July 26, 2025 02:05
@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch from 06da2d9 to 9a8d691 Compare July 28, 2025 21:33
@realrajaryan realrajaryan requested a review from dcantah July 28, 2025 21:37
@realrajaryan realrajaryan changed the title Named Volumes: stubs for CLI and option processing, and volume data structure Named Volumes Jul 28, 2025
}

public func list() async throws -> [Volume] {
try await store.list()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be in the lock?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it could be but the store is an actor with no awaits in it


public func delete(name: String) async throws {
try await lock.withLock { _ in
try await self._delete(name: name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very much a nit - but for code clarity

should we make it such that the _foo methods takes in an object of type AsyncLock.Context

So these invocations become

try await lock.withLock { ctx in
            try await self._delete(name: name, lock: ctx)
}

Dont need to make this update in this PR, it can be done as a quick follow up

Copy link
Contributor

@adityaramani adityaramani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had one question

@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch from 8cf2da1 to 4990c52 Compare August 4, 2025 23:38
}

// Check if volume is in use by any container atomically
let volumeInUse = try await containersService.withContainerList { containers in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the volume delete itself be executed in the block so that there's no chance of a reference being created to the volume after this block exits? Right now it seems that if another thread is creating a container that attaches the volume at the same time we're at line 197, there's a race still.

Comment on lines 186 to 202
let volumeInUse = try await containersService.withContainerList { containers in
for container in containers {
for mount in container.configuration.mounts {
if mount.isVolume && mount.volumeName == name {
return true
}
}
}
return false
}

if volumeInUse {
throw VolumeError.volumeInUse(name)
}

try await store.delete(name)
try removeVolumeDirectory(for: name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines should be inside the closure itself (for whatever reason John's comment isn't popping up in this view, but I'm mirroring his comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(197 to 202)

@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch from 4990c52 to 6432bac Compare August 5, 2025 00:56
Copy link
Contributor

@jglogan jglogan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix build errors after pulling volume delete into closure.

@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch 15 times, most recently from 52dcb0e to 3a12bb0 Compare August 5, 2025 22:25
@realrajaryan realrajaryan force-pushed the users/realrajaryan/named-volumes branch from 3a12bb0 to 8ff6472 Compare August 5, 2025 22:57
@realrajaryan realrajaryan requested a review from jglogan August 5, 2025 22:57
@realrajaryan realrajaryan merged commit b8965ca into apple:main Aug 6, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request]: Add support for named volumes for run

4 participants