generated from rust-vmm/crate-template
-
Notifications
You must be signed in to change notification settings - Fork 49
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
vsock: Use PathBuf for socket paths instead of Strings #446
Open
bilelmoussaoui
wants to merge
6
commits into
rust-vmm:main
Choose a base branch
from
bilelmoussaoui:bilelmoussaoui/vsock-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cfb7b82
vsock: Use PathBuf for socket paths instead of Strings
bilelmoussaoui 167e909
scmi: Use PathBuf for socket paths instead of Strings
bilelmoussaoui 14078ea
rng: Use PathBuf for socket paths instead of Strings
bilelmoussaoui e3d14d4
gpio: Use PathBuf for socket paths instead of Strings
bilelmoussaoui 04a69be
sound: Use PathBuf for socket paths instead of Strings
bilelmoussaoui e4058ed
Merge branch 'main' into bilelmoussaoui/vsock-path
bilelmoussaoui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Manos Pitsidianakis <[email protected]> | ||
// Stefano Garzarella <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause | ||
use std::convert::TryFrom; | ||
use std::{convert::TryFrom, path::PathBuf}; | ||
|
||
use clap::Parser; | ||
use vhost_device_sound::{start_backend_server, BackendType, Error, Result, SoundConfig}; | ||
|
@@ -11,7 +11,7 @@ use vhost_device_sound::{start_backend_server, BackendType, Error, Result, Sound | |
struct SoundArgs { | ||
/// vhost-user Unix domain socket path. | ||
#[clap(long)] | ||
socket: String, | ||
socket: PathBuf, | ||
/// audio backend to be used | ||
#[clap(long)] | ||
#[clap(value_enum)] | ||
|
@@ -22,9 +22,7 @@ impl TryFrom<SoundArgs> for SoundConfig { | |
type Error = Error; | ||
|
||
fn try_from(cmd_args: SoundArgs) -> Result<Self> { | ||
let socket = cmd_args.socket.trim().to_string(); | ||
|
||
Ok(SoundConfig::new(socket, false, cmd_args.backend)) | ||
Ok(SoundConfig::new(cmd_args.socket, false, cmd_args.backend)) | ||
} | ||
} | ||
|
||
|
@@ -45,9 +43,9 @@ mod tests { | |
use super::*; | ||
|
||
impl SoundArgs { | ||
fn from_args(socket: &str) -> Self { | ||
fn from_args(socket: PathBuf) -> Self { | ||
SoundArgs { | ||
socket: socket.to_string(), | ||
socket, | ||
backend: BackendType::default(), | ||
} | ||
} | ||
|
@@ -61,13 +59,16 @@ mod tests { | |
#[test] | ||
fn test_sound_config_setup() { | ||
init_logger(); | ||
let args = SoundArgs::from_args("/tmp/vhost-sound.socket"); | ||
let args = SoundArgs::from_args(PathBuf::from("/tmp/vhost-sound.socket")); | ||
|
||
let config = SoundConfig::try_from(args); | ||
assert!(config.is_ok()); | ||
|
||
let config = config.unwrap(); | ||
assert_eq!(config.get_socket_path(), "/tmp/vhost-sound.socket"); | ||
assert_eq!( | ||
config.get_socket_path(), | ||
PathBuf::from("/tmp/vhost-sound.socket") | ||
); | ||
} | ||
|
||
#[rstest] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path::join
does not append the suffix to the file name component, but pushes a new component (e.g. "foo.sock0" vs "foo.sock/0")There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess something like
let socket = config.socket_path.with_extension(format!("sock{i}"));
would work better? but that hardcodes the extension though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vhost-device/vhost-device-i2c/src/main.rs
Lines 239 to 256 in 1e6667f