Skip to content

Conversation

xujihui1985
Copy link
Contributor

with_writer docs

  • Introduce try_with_writer<F, R, E> that builds a FuseDevWriter and returns
    the closure’s Result, converting super::Error via From.
    • Return SessionFailure("invalid fuse session") when self.file is absent.
    • Tweak with_writer doc to clarify it passes a writer to the given closure.

example(passthrough): update example to show how to use try_with_writer

`with_writer` docs

- Introduce `try_with_writer<F, R, E>` that builds a `FuseDevWriter` and
returns
  the closure’s `Result`, converting `super::Error` via `From`.
  - Return `SessionFailure("invalid fuse session")` when `self.file` is
  absent.
  - Tweak `with_writer` doc to clarify it passes a writer to the given
  closure.

example(passthrough): update example to show how to use try_with_writer
@sidneychang
Copy link
Contributor

Hello, could you also provide the same implementation in macos_session?
Without it, the macOS build in nydus CI will fail since the implementation cannot be found during compilation.

@xujihui1985
Copy link
Contributor Author

Hello, could you also provide the same implementation in macos_session? Without it, the macOS build in nydus CI will fail since the implementation cannot be found during compilation.

I didn't notice failed ci on macos, could you point out the failed test?

@sidneychang
Copy link
Contributor

sidneychang commented Sep 4, 2025

Hello, could you also provide the same implementation in macos_session? Without it, the macOS build in nydus CI will fail since the implementation cannot be found during compilation.

I didn't notice failed ci on macos, could you point out the failed test?

I noticed that this submission was originally prepared for the nydus PR #1740. In the original nydus code, the with_writer method was not used, which is why the macOS CI did not report any errors.

I tried to use the with_writer method in a PR, but in macos_session this method does not exist, causing nydus macos build CI fail. Here’s the error message I encountered:

error[E0599]: no method named `with_writer` found for struct `MutexGuard<'_, FuseSession>` in the current scope
   --> service/src/fusedev.rs:277:50
    |
277 |                     self.session.lock().unwrap().with_writer(|writer| {
    |                     -----------------------------^^^^^^^^^^^ method not found in `MutexGuard<'_, FuseSession>`

error[E0599]: no method named `with_writer` found for struct `MutexGuard<'_, FuseSession>` in the current scope
   --> service/src/fusedev.rs:286:46
    |
286 |                 self.session.lock().unwrap().with_writer(|writer| {
    |                 -----------------------------^^^^^^^^^^^ method not found in `MutexGuard<'_, FuseSession>`

If PR #1740 were to use try_with_writer, I think it would encounter the same issue. You can also see the CI run here: CI run link
.

@xujihui1985
Copy link
Contributor Author

oh I see, thanks for point out the problem

Xu Jihui added 2 commits September 5, 2025 11:10
To reduce code duplication between the Linux and macOS FuseSession
implementations, this change extracts the with_writer and
try_with_writer helper methods into a new extension trait,
FuseSessionExt.

The trait provides default implementations for these methods, which rely
on file() and bufsize() accessor methods that the concrete session types
must provide. Both linux_session::FuseSession and
macos_session::FuseSession now implement this trait, allowing them to
share the common logic.
@xujihui1985
Copy link
Contributor Author

Hello, could you also provide the same implementation in macos_session? Without it, the macOS build in nydus CI will fail since the implementation cannot be found during compilation.

I didn't notice failed ci on macos, could you point out the failed test?

I noticed that this submission was originally prepared for the nydus PR #1740. In the original nydus code, the with_writer method was not used, which is why the macOS CI did not report any errors.

I tried to use the with_writer method in a PR, but in macos_session this method does not exist, causing nydus macos build CI fail. Here’s the error message I encountered:

error[E0599]: no method named `with_writer` found for struct `MutexGuard<'_, FuseSession>` in the current scope
   --> service/src/fusedev.rs:277:50
    |
277 |                     self.session.lock().unwrap().with_writer(|writer| {
    |                     -----------------------------^^^^^^^^^^^ method not found in `MutexGuard<'_, FuseSession>`

error[E0599]: no method named `with_writer` found for struct `MutexGuard<'_, FuseSession>` in the current scope
   --> service/src/fusedev.rs:286:46
    |
286 |                 self.session.lock().unwrap().with_writer(|writer| {
    |                 -----------------------------^^^^^^^^^^^ method not found in `MutexGuard<'_, FuseSession>`

If PR #1740 were to use try_with_writer, I think it would encounter the same issue. You can also see the CI run here: CI run link .

Hi I have implement the method for macos in the latest commit

Copy link
Collaborator

@imeoer imeoer left a comment

Choose a reason for hiding this comment

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

LGTM!

@imeoer imeoer merged commit c07641c into cloud-hypervisor:master Sep 5, 2025
10 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.

3 participants