Skip to content

[vminitd]: api for freeze/thaw filesystem operations#685

Draft
saehejkang wants to merge 2 commits intoapple:mainfrom
saehejkang:add-vminit-api-freeze-thaw
Draft

[vminitd]: api for freeze/thaw filesystem operations#685
saehejkang wants to merge 2 commits intoapple:mainfrom
saehejkang:add-vminit-api-freeze-thaw

Conversation

@saehejkang
Copy link
Copy Markdown
Contributor

Addition of vminitd API for freeze/thaw filesystem operations

Closes #660

@jglogan
Copy link
Copy Markdown
Contributor

jglogan commented Apr 14, 2026

@dcantah wdyt?

@dcantah
Copy link
Copy Markdown
Member

dcantah commented Apr 14, 2026

Looks good!

Comment on lines +681 to +701
#if os(Linux)
static let FIFREEZE: UInt = 0xC004_5877
let rc: CInt = ioctl(fd, FIFREEZE, 0)
if rc != 0 {
throw RPCError(code: .internalError, message: "freeze failed")
}
#else
fatalError("freeze not supported on platform")
#endif
}

private func thawFilesystem(fd: Int32) throws {
#if os(Linux)
static let FITHAW: UInt = 0xC004_5878
let rc: CInt = ioctl(fd, FITHAW, 0)
if rc != 0 {
throw RPCError(code: .internalError, message: "thaw failed")
}
#else
fatalError("thaw not supported on platform")
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd leave off the ifdefs, I think we've somewhat accepted that we just care about linux here. I need to go and do a sweep everywhere.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The rpc itself is already linux specific.

Comment on lines +652 to +656
log.debug(
"filesystemOperation: freezing filesystem",
metadata: [
"path": "\(request.path)"
])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd get rid of these logs, it doesn't give us any extra info than the one at the top of the method.

Comment on lines +635 to +644
throw RPCError(code: .notFound, message: "failed to stat path")
}

if (finfo.st_mode & S_IFMT) == S_IFLNK {
throw RPCError(code: .internalError, message: "path cannot be a symlink")
}

fd = open(request.path, O_RDONLY)
if fd < 0 {
throw RPCError(code: .internalError, message: "failed to open path")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It'd be good in any syscall error return paths to include the errno, it'll be very hard to debug otherwise.


private func thawFilesystem(fd: Int32) throws {
#if os(Linux)
static let FITHAW: UInt = 0xC004_5878
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: static let inside Swift function is not allowed. Linux build will fail.


private func freezeFilesystem(fd: Int32) throws {
#if os(Linux)
static let FIFREEZE: UInt = 0xC004_5877
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same as the other comment.

throw RPCError(code: .internalError, message: "path cannot be a symlink")
}

fd = open(request.path, O_RDONLY)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let fd?

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]: vminit API for block device operations, initially for freeze/thaw.

4 participants