Skip to content

Commit

Permalink
virtio/vsock: Fix clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Fanelli <[email protected]>
  • Loading branch information
tylerfanelli committed Feb 25, 2025
1 parent 7ab42b4 commit a85d480
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/devices/src/virtio/vsock/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pub(crate) const EVQ_INDEX: usize = 2;
/// - VIRTIO_F_VERSION_1: the device conforms to at least version 1.0 of the VirtIO spec.
/// - VIRTIO_F_IN_ORDER: the device returns used buffers in the same order that the driver makes
/// them available.
pub(crate) const AVAIL_FEATURES: u64 = 1 << uapi::VIRTIO_F_VERSION_1 as u64
| 1 << uapi::VIRTIO_F_IN_ORDER as u64
| 1 << uapi::VIRTIO_VSOCK_F_DGRAM;
pub(crate) const AVAIL_FEATURES: u64 = (1 << uapi::VIRTIO_F_VERSION_1 as u64)
| (1 << uapi::VIRTIO_F_IN_ORDER as u64)
| (1 << uapi::VIRTIO_VSOCK_F_DGRAM);

pub struct Vsock {
cid: u64,
Expand Down
32 changes: 16 additions & 16 deletions src/devices/src/virtio/vsock/muxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl VsockMuxer {
match req._type {
defs::SOCK_STREAM => {
debug!("vsock: proxy create stream");
let id = (req.peer_port as u64) << 32 | defs::TSI_PROXY_PORT as u64;
let id = ((req.peer_port as u64) << 32) | (defs::TSI_PROXY_PORT as u64);
match TcpProxy::new(
id,
self.cid,
Expand All @@ -295,7 +295,7 @@ impl VsockMuxer {
}
defs::SOCK_DGRAM => {
debug!("vsock: proxy create dgram");
let id = (req.peer_port as u64) << 32 | defs::TSI_PROXY_PORT as u64;
let id = ((req.peer_port as u64) << 32) | (defs::TSI_PROXY_PORT as u64);
match UdpProxy::new(
id,
self.cid,
Expand All @@ -321,7 +321,7 @@ impl VsockMuxer {
fn process_connect(&self, pkt: &VsockPacket) {
debug!("vsock: proxy connect request");
if let Some(req) = pkt.read_connect_req() {
let id = (req.peer_port as u64) << 32 | defs::TSI_PROXY_PORT as u64;
let id = ((req.peer_port as u64) << 32) | (defs::TSI_PROXY_PORT as u64);
debug!("vsock: proxy connect request: id={}", id);
let update = self
.proxy_map
Expand All @@ -339,7 +339,7 @@ impl VsockMuxer {
fn process_getname(&self, pkt: &VsockPacket) {
debug!("vsock: new getname request");
if let Some(req) = pkt.read_getname_req() {
let id = (req.peer_port as u64) << 32 | (req.local_port as u64);
let id = ((req.peer_port as u64) << 32) | (req.local_port as u64);
debug!(
"vsock: new getname request: id={}, peer_port={}, local_port={}",
id, req.peer_port, req.local_port
Expand All @@ -354,7 +354,7 @@ impl VsockMuxer {
fn process_sendto_addr(&self, pkt: &VsockPacket) {
debug!("vsock: new DGRAM sendto addr: src={}", pkt.src_port());
if let Some(req) = pkt.read_sendto_addr() {
let id = (req.peer_port as u64) << 32 | defs::TSI_PROXY_PORT as u64;
let id = ((req.peer_port as u64) << 32) | (defs::TSI_PROXY_PORT as u64);
debug!("vsock: new DGRAM sendto addr: id={}", id);
let update = self
.proxy_map
Expand All @@ -370,7 +370,7 @@ impl VsockMuxer {
}

fn process_sendto_data(&self, pkt: &VsockPacket) {
let id = (pkt.src_port() as u64) << 32 | defs::TSI_PROXY_PORT as u64;
let id = ((pkt.src_port() as u64) << 32) | (defs::TSI_PROXY_PORT as u64);
debug!("vsock: DGRAM sendto data: id={} src={}", id, pkt.src_port());
if let Some(proxy) = self.proxy_map.read().unwrap().get(&id) {
proxy.lock().unwrap().sendto_data(pkt);
Expand All @@ -380,7 +380,7 @@ impl VsockMuxer {
fn process_listen_request(&self, pkt: &VsockPacket) {
debug!("vsock: DGRAM listen request: src={}", pkt.src_port());
if let Some(req) = pkt.read_listen_req() {
let id = (req.peer_port as u64) << 32 | defs::TSI_PROXY_PORT as u64;
let id = ((req.peer_port as u64) << 32) | (defs::TSI_PROXY_PORT as u64);
debug!("vsock: DGRAM listen request: id={}", id);
let update = self
.proxy_map
Expand All @@ -398,7 +398,7 @@ impl VsockMuxer {
fn process_accept_request(&self, pkt: &VsockPacket) {
debug!("vsock: DGRAM accept request: src={}", pkt.src_port());
if let Some(req) = pkt.read_accept_req() {
let id = (req.peer_port as u64) << 32 | defs::TSI_PROXY_PORT as u64;
let id = ((req.peer_port as u64) << 32) | (defs::TSI_PROXY_PORT as u64);
debug!("vsock: DGRAM accept request: id={}", id);
let update = self
.proxy_map
Expand All @@ -416,7 +416,7 @@ impl VsockMuxer {
fn process_proxy_release(&self, pkt: &VsockPacket) {
debug!("vsock: DGRAM release request: src={}", pkt.src_port());
if let Some(req) = pkt.read_release_req() {
let id = (req.peer_port as u64) << 32 | req.local_port as u64;
let id = ((req.peer_port as u64) << 32) | (req.local_port as u64);
debug!(
"vsock: DGRAM release request: id={} local_port={} peer_port={}",
id, req.local_port, req.peer_port
Expand Down Expand Up @@ -444,7 +444,7 @@ impl VsockMuxer {

fn process_dgram_rw(&self, pkt: &VsockPacket) {
debug!("vsock: DGRAM OP_RW");
let id = (pkt.src_port() as u64) << 32 | defs::TSI_PROXY_PORT as u64;
let id = ((pkt.src_port() as u64) << 32) | (defs::TSI_PROXY_PORT as u64);

if let Some(proxy_lock) = self.proxy_map.read().unwrap().get(&id) {
debug!("vsock: DGRAM allowing OP_RW for {}", pkt.src_port());
Expand Down Expand Up @@ -494,7 +494,7 @@ impl VsockMuxer {

fn process_op_request(&mut self, pkt: &VsockPacket) {
debug!("vsock: OP_REQUEST");
let id: u64 = (pkt.src_port() as u64) << 32 | pkt.dst_port() as u64;
let id: u64 = ((pkt.src_port() as u64) << 32) | (pkt.dst_port() as u64);
let mut proxy_map = self.proxy_map.write().unwrap();

if let Some(proxy) = proxy_map.get(&id) {
Expand Down Expand Up @@ -540,7 +540,7 @@ impl VsockMuxer {

fn process_op_response(&self, pkt: &VsockPacket) {
debug!("vsock: OP_RESPONSE");
let id: u64 = (pkt.src_port() as u64) << 32 | pkt.dst_port() as u64;
let id: u64 = ((pkt.src_port() as u64) << 32) | (pkt.dst_port() as u64);
let update = self
.proxy_map
.read()
Expand All @@ -565,15 +565,15 @@ impl VsockMuxer {

fn process_op_shutdown(&self, pkt: &VsockPacket) {
debug!("vsock: OP_SHUTDOWN");
let id: u64 = (pkt.src_port() as u64) << 32 | pkt.dst_port() as u64;
let id: u64 = ((pkt.src_port() as u64) << 32) | (pkt.dst_port() as u64);
if let Some(proxy) = self.proxy_map.read().unwrap().get(&id) {
proxy.lock().unwrap().shutdown(pkt);
}
}

fn process_op_credit_update(&self, pkt: &VsockPacket) {
debug!("vsock: OP_CREDIT_UPDATE");
let id: u64 = (pkt.src_port() as u64) << 32 | pkt.dst_port() as u64;
let id: u64 = ((pkt.src_port() as u64) << 32) | (pkt.dst_port() as u64);
let update = self
.proxy_map
.read()
Expand All @@ -587,7 +587,7 @@ impl VsockMuxer {

fn process_stream_rw(&self, pkt: &VsockPacket) {
debug!("vsock: OP_RW");
let id: u64 = (pkt.src_port() as u64) << 32 | pkt.dst_port() as u64;
let id: u64 = ((pkt.src_port() as u64) << 32) | (pkt.dst_port() as u64);
if let Some(proxy_lock) = self.proxy_map.read().unwrap().get(&id) {
debug!(
"vsock: allowing OP_RW: src={} dst={}",
Expand Down Expand Up @@ -625,7 +625,7 @@ impl VsockMuxer {

fn process_stream_rst(&self, pkt: &VsockPacket) {
debug!("vsock: OP_RST");
let id: u64 = (pkt.src_port() as u64) << 32 | pkt.dst_port() as u64;
let id: u64 = ((pkt.src_port() as u64) << 32) | (pkt.dst_port() as u64);
if let Some(proxy_lock) = self.proxy_map.read().unwrap().get(&id) {
debug!(
"vsock: allowing OP_RST: id={} src={} dst={}",
Expand Down
4 changes: 2 additions & 2 deletions src/devices/src/virtio/vsock/muxer_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl MuxerThread {

if let Some((peer_port, accept_fd, proxy_type)) = update.new_proxy {
let local_port: u32 = thread_rng.gen_range(1024..u32::MAX);
let new_id: u64 = (peer_port as u64) << 32 | local_port as u64;
let new_id: u64 = ((peer_port as u64) << 32) | (local_port as u64);
let new_proxy: Box<dyn Proxy> = match proxy_type {
NewProxyType::Tcp => Box::new(TcpProxy::new_reverse(
new_id,
Expand Down Expand Up @@ -171,7 +171,7 @@ impl MuxerThread {
if !do_listen {
continue;
}
let id = (*port as u64) << 32 | defs::TSI_PROXY_PORT as u64;
let id = ((*port as u64) << 32) | (defs::TSI_PROXY_PORT as u64);
let proxy = match UnixAcceptorProxy::new(id, path, *port) {
Ok(proxy) => proxy,
Err(e) => {
Expand Down

0 comments on commit a85d480

Please sign in to comment.