Skip to content

libkrun: Refactor VirtioFsTable to VirtioFsLookup trait#44

Merged
gurchetansingh merged 1 commit into
magma-gpu:libkrunfrom
dorindabassey:virtiofs
Feb 26, 2026
Merged

libkrun: Refactor VirtioFsTable to VirtioFsLookup trait#44
gurchetansingh merged 1 commit into
magma-gpu:libkrunfrom
dorindabassey:virtiofs

Conversation

@dorindabassey
Copy link
Copy Markdown

Introduce a trait-based abstraction for VirtioFS file descriptor lookup. The trait design enables future extensions like inode-based lookups for O_PATH file descriptors (needed for D-Bus over virtgpu with file transfer support). Provides DefaultVirtioFsLookup for backward compatibility.

This supersedes #43

@dorindabassey
Copy link
Copy Markdown
Author

Hi @valpackett wdyt?

@valpackett
Copy link
Copy Markdown
Collaborator

Oh wow, I didn't even realize the previous thing was merged and released- oh, on a temporary libkrun branch with its own releases, I see! Seems a bit early to commit to backwards compat and provide deprecated annotations but fine :)

Actual substance: LGTM 👍

Comment thread src/rutabaga_core.rs Outdated
@dorindabassey dorindabassey force-pushed the virtiofs branch 2 times, most recently from 77a9cf2 to 0a2ead1 Compare February 25, 2026 10:55
Copy link
Copy Markdown

@mtjhrc mtjhrc left a comment

Choose a reason for hiding this comment

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

I would remove the default impl, otherwise this LGTM.

Comment thread src/rutabaga_core.rs Outdated
Comment thread src/rutabaga_core.rs Outdated
Comment thread src/rutabaga_core.rs Outdated
@gurchetansingh
Copy link
Copy Markdown
Collaborator

gurchetansingh commented Feb 25, 2026

How does everyone feel about modifying the RutabagaHandler to be more generic, and even renaming it to RutabagaCallback (it actually compiles with crosvm with no source modifications outside of rutabaga, since RutabagaCallback isn't used directly):

#[derive(Clone)]
pub struct RutabagaCallback<S, T> {
    closure: Arc<dyn Fn(S) -> T + Send + Sync>,
}

impl<S, T> RutabagaCallback<S, T>
where
    S: Send + Sync + Clone + 'static,
    T: Send + Sync + Clone + 'static,
{
    /// Creates a new handler from a closure.
    pub fn new(closure: impl Fn(S) -> T + Send + Sync + 'static) -> Self {
        RutabagaCallback {
            closure: Arc::new(closure),
        }
    }

    /// Executes the stored closure with the provided data.
    pub fn call(&self, data: S) -> T {
        (self.closure)(data)
    }
}

pub type RutabagaFenceHandler = RutabagaCallback<RutabagaFence, ()>;
pub type RutabagaDebugHandler = RutabagaCallback<RutabagaDebug, ()>;
pub type RutabagaFsLookup = RutabagaCallback<u64, RutabagaDescriptor>;

@dorindabassey
Copy link
Copy Markdown
Author

dorindabassey commented Feb 25, 2026

How does everyone feel about modifying the RutabagaHandler to be more generic, and even renaming it to RutabagaCallback (it actually compiles with crosvm with no source modifications outside of rutabaga, since RutabagaCallback isn't used directly):

yeah, I think it makes sense consolidating to a generic RutabagaCallback - it's cleaner. One small issue though: VirtioFsLookup takes two u64 parameters (fs_id and handle), so it should probably be:

  pub type RutabagaFsLookup = RutabagaCallback<(u64, u64), RutabagaResult<RutabagaDescriptor>>;

@gurchetansingh
Copy link
Copy Markdown
Collaborator

One small issue though: VirtioFsLookup takes two u64 parameters (fs_id and handle), so it should probably be:

Ack, you can also do:

struct RutabagaFsKey {
    fs_id: u64,
   handle: u64
}

leave it up to you if you prefer the pair or struct

@dorindabassey dorindabassey force-pushed the virtiofs branch 2 times, most recently from 864bcde to d477dd4 Compare February 26, 2026 08:06
@valpackett
Copy link
Copy Markdown
Collaborator

But now we're back to just a single callback type that can't be easily extended.. Well I can extend everything "not-easily", sure :)

Why do we need the double Arc btw? (i.e. virtiofs_lookup: Option<Arc<RutabagaFsLookup>> where RutabagaFsLookup = RutabagaCallback<…> which is struct RutabagaCallback<S, T> { closure: Arc<dyn Fn(S) -> T + Send + Sync> }?

@mtjhrc
Copy link
Copy Markdown

mtjhrc commented Feb 26, 2026

Hmm, thinking about it, I think the trait was better, we could extend it like Val wants by adding methods with default impl quite easily.

@dorindabassey
Copy link
Copy Markdown
Author

I could bring back the VirtioFsLookup trait and still keep the RutabagaCallback for simple handlers.

@mtjhrc
Copy link
Copy Markdown

mtjhrc commented Feb 26, 2026

IMHO just the simple specific-purpose trait without any of the RutabagaCallback/RutabagaHandler is the best (especially because we already expect it to have to be extended).

@gurchetansingh
Copy link
Copy Markdown
Collaborator

Sure if the separate trait is better, no problem supporting that. We can probably optimize later anyways,

@gurchetansingh gurchetansingh self-requested a review February 26, 2026 14:48
Comment thread src/rutabaga_core.rs Outdated
Comment thread src/rutabaga_utils.rs Outdated
Introduce a trait-based abstraction for VirtioFS
file descriptor lookup. The trait design enables
future extensions like inode-based lookups for O_PATH
file descriptors (needed for D-Bus over virtgpu with
file transfer support)

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
@dorindabassey
Copy link
Copy Markdown
Author

Fixed, Thanks all!

@gurchetansingh gurchetansingh merged commit 107faef into magma-gpu:libkrun Feb 26, 2026
4 of 7 checks passed
@gurchetansingh
Copy link
Copy Markdown
Collaborator

https://crates.io/crates/rutabaga_gfx/0.1.76-libkrun.1 <-- cut release with this commit

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.

4 participants