Skip to content

vhost-device-console: add Unix domain socket backend support #821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

DarcySail
Copy link

Summary of the PR

Please summarize here why the changes in this PR are needed.
kata platform use uds to connect with VM layer.

#815

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • [ x] All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • [ x] All added/changed functionality has a corresponding unit/integration
    test.
  • [ x] All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • [ x] Any newly added unsafe code is properly documented.

@DarcySail
Copy link
Author

I see some CI fails, trying to reproduce on my dev machine, but currently blocked by some dependency of a newer libc version, I'll try to solve the problem next week.

Copy link
Member

@stefano-garzarella stefano-garzarella left a comment

Choose a reason for hiding this comment

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

Thanks for this PR!

I like the new backend, but please add a better description in the PR and also don't mix fixes, refactoring and new feature in a single commit, otherwise it's a mess to review and also to maintain.

I'll wait better commits before a deeper review.

@DarcySail DarcySail force-pushed the dali-console-uds branch 3 times, most recently from 1f6dc04 to 68d1378 Compare March 7, 2025 03:49
Copy link
Member

@stefano-garzarella stefano-garzarella left a comment

Choose a reason for hiding this comment

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

Thanks, now the commit are much much better!

About the changes, I'd check better that --tcp-port is used only with network backend and --uds-path only with uds.

@DarcySail
Copy link
Author

Thanks for your patient review. This week, I have some higher-priority work to do, and I will complete the changes you suggested next week.

@stefano-garzarella
Copy link
Member

Thanks for your patient review.

You're welcome!

This week, I have some higher-priority work to do, and I will complete the changes you suggested next week.

@DarcySail sure, it's not a problem at all, take your time!

Hang SU added 3 commits March 17, 2025 14:38
Replace non-informative expect() messages with meaningful error
contexts.

Signed-off-by: Hang SU <[email protected]>
Rename TCP-related identifiers to generic socket terminology:
generate_tcp_addrs → generate_vm_socks
tcp_addr → vm_sock
listener → tcp_listener

Simplify stream handler method names:
write_tcp_stream → write_stream
read_tcp_stream → read_stream

conventions without functional changes.

Signed-off-by: Hang SU <[email protected]>
Rework conditional logic using match expressions for backend type dispatch.
No functional changes, this patch is a preparation for new backend
type: uds.

Signed-off-by: Hang SU <[email protected]>
Copy link
Member

@stefano-garzarella stefano-garzarella left a comment

Choose a reason for hiding this comment

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

LGTM! Just minor comments.

@DarcySail DarcySail force-pushed the dali-console-uds branch 2 times, most recently from 9569918 to aa6ab82 Compare March 24, 2025 06:45
@DarcySail
Copy link
Author

Agreed, I add a check patch for parameter mutual exclusivity~
@stefano-garzarella

@DarcySail DarcySail force-pushed the dali-console-uds branch 2 times, most recently from 72ae395 to eae96e0 Compare March 24, 2025 07:32
Hang SU added 2 commits March 24, 2025 15:37
- Introduce `BackendType::Uds` for VM communication via Unix sockets
- Refactor address generation logic with `generate_vm_sock_addrs`
- Add CLI parameter `--vm-sock` to specify UDS path
- Update documentation and error handling

Signed-off-by: Hang SU <[email protected]>
Suggested-by: Xuewei Niu <[email protected]>
- Verify UDS path parent directory existence check
- Test UDS address generation logic with multiple sockets
- Add error handling test for invalid UDS backend initialization

Signed-off-by: Hang SU <[email protected]>
- Introduce `InvalidCmdlineOption` error type to handle conflicting parameters
- Implement backend-specific parameter checks:
  * Nested backend:
    - Require single socket (socket_count=1)
    - Disallow TCP port/UDS path
  * Network backend: Disallow UDS path
  * UDS backend: Disallow TCP port
- Remove default TCP port value to enforce explicit configuration

Signed-off-by: Hang SU <[email protected]>
Copy link
Contributor

@justxuewei justxuewei left a comment

Choose a reason for hiding this comment

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

Some comments here...

<normal UML options> \
virtio_uml.device=/tmp/console.sock0:3 console=tty0 console=hvc0 \
init=/bin/systemd \
systemd.unit=kata-containers.target agent.debug_console
Copy link
Contributor

@justxuewei justxuewei Apr 1, 2025

Choose a reason for hiding this comment

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

I think testing with UML does not need to depend on Kata Containers:

  • Remove staff regarding kata-containers: systemd.unit, debug_console.
  • Use /bin/bash instead.
$ sudo linux ubd0=kata-ubuntu-latest.image \
    root=/dev/ubda1 \
    init=/bin/bash \
    console=hvc0 \
    virtio_uml.device=/tmp/console.sock0:3

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, Kata's rootfs image can still be used here.

let uds_parent = self
.uds_path
.parent()
.expect("uds has no parent directory.");
Copy link
Contributor

@justxuewei justxuewei Apr 1, 2025

Choose a reason for hiding this comment

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

I prefer to create all directories, instead of doing expect() here.

Comment on lines +89 to +116
if args.backend == BackendType::Nested {
if args.socket_count != 1 {
return Err(Error::WrongBackendSocket);
}

if (args.tcp_port.as_ref().map_or(false, |s| !s.is_empty()))
|| (args
.uds_path
.as_ref()
.map_or(false, |path| !path.as_os_str().is_empty()))
{
return Err(Error::InvalidCmdlineOption);
}
}

if args.backend == BackendType::Network
&& args
.uds_path
.as_ref()
.map_or(false, |path| !path.as_os_str().is_empty())
{
return Err(Error::InvalidCmdlineOption);
}

if args.backend == BackendType::Uds
&& args.tcp_port.as_ref().map_or(false, |s| !s.is_empty())
{
return Err(Error::InvalidCmdlineOption);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use match args.backend?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your reply.
I get several high-priority tasks this week, I will make time to implement the code changes as your comments.

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