Skip to content

Commit

Permalink
style: cargo fmt
Browse files Browse the repository at this point in the history
Runs updated `cargo fmt`.

Signed-off-by: Jonathan Woollett-Light <jcawl@amazon.co.uk>
  • Loading branch information
Jonathan Woollett-Light authored and JonathanWoollett-Light committed Oct 6, 2023
1 parent b4871b1 commit 9ea964c
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 54 deletions.
7 changes: 3 additions & 4 deletions src/jailer/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,9 @@ impl Env {

// We do a copy instead of a hard-link for 2 reasons
// 1. hard-linking is not possible if the file is in another device
// 2. while hardlinking would save up disk space and also memory by
// sharing parts of the Firecracker binary (like the executable .text
// section), this latter part is not desirable in Firecracker's
// threat model. Copying prevents 2 Firecracker processes from
// 2. while hardlinking would save up disk space and also memory by sharing parts of the
// Firecracker binary (like the executable .text section), this latter part is not
// desirable in Firecracker's threat model. Copying prevents 2 Firecracker processes from
// sharing memory.
fs::copy(&self.exec_file_path, &self.chroot_dir).map_err(|err| {
JailerError::Copy(self.exec_file_path.clone(), self.chroot_dir.clone(), err)
Expand Down
9 changes: 4 additions & 5 deletions src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,13 +1025,12 @@ pub mod tests {
fn cmdline_contains(cmdline: &Cmdline, slug: &str) -> bool {
// The following unwraps can never fail; the only way any of these methods
// would return an `Err` is if one of the following conditions is met:
// 1. The command line is empty: We just added things to it, and if insertion
// of an argument goes wrong, then `Cmdline::insert` would have already
// returned `Err`.
// 1. The command line is empty: We just added things to it, and if insertion of an
// argument goes wrong, then `Cmdline::insert` would have already returned `Err`.
// 2. There's a spurious null character somewhere in the command line: The
// `Cmdline::insert` methods verify that this is not the case.
// 3. The `CString` is not valid UTF8: It just got created from a `String`,
// which was valid UTF8.
// 3. The `CString` is not valid UTF8: It just got created from a `String`, which was
// valid UTF8.

cmdline
.as_cstring()
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/devices/virtio/balloon/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ impl VirtioDevice for Balloon {
let end = start.and_then(|s| s.checked_add(data.len()));
let Some(dst) = start
.zip(end)
.and_then(|(start, end)| config_space_bytes.get_mut(start..end)) else
{
.and_then(|(start, end)| config_space_bytes.get_mut(start..end))
else {
error!("Failed to write config space");
return;
};
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/devices/virtio/block/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ impl VirtioDevice for Block {
let end = start.and_then(|s| s.checked_add(data.len()));
let Some(dst) = start
.zip(end)
.and_then(|(start, end)| self.config_space.get_mut(start..end)) else
{
.and_then(|(start, end)| self.config_space.get_mut(start..end))
else {
error!("Failed to write config space");
METRICS.block.cfg_fails.inc();
return;
Expand Down
12 changes: 6 additions & 6 deletions src/vmm/src/devices/virtio/iovec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ impl IoVecBuffer {
// The call to `copy_nonoverlapping` is safe because:
// 1. `iov` describes a valid range in guest memory. The constructor of `IoVecBuffer`
// has checked that.
// 2. `buf_ptr` is a pointer inside the `buf` slice. We only get this pointer using
// safe methods.
// 2. `buf_ptr` is a pointer inside the `buf` slice. We only get this pointer using safe
// methods.
// 3. Both pointers point to `u8` elements, so they're always aligned.
// 4. The memory regions these pointers point to are not overlapping. `src` points to
// guest physical memory and `buf_ptr` to Firecracker-owned memory.
Expand Down Expand Up @@ -229,10 +229,10 @@ impl IoVecBufferMut {

// SAFETY:
// The call to `copy_nonoverlapping` is safe because:
// 1. `iov` describes a valid range in guest memory. The constructor of
// `IoVecBufferMut` has checked that.
// 2. `buf_ptr` is a pointer inside the `buf` slice. We only get this pointer using
// safe methods.
// 1. `iov` describes a valid range in guest memory. The constructor of `IoVecBufferMut`
// has checked that.
// 2. `buf_ptr` is a pointer inside the `buf` slice. We only get this pointer using safe
// methods.
// 3. Both pointers point to `u8` elements, so they're always aligned.
// 4. The memory regions these pointers point to are not overlapping. `dst` points to
// guest physical memory and `buf_ptr` to Firecracker-owned memory.
Expand Down
5 changes: 2 additions & 3 deletions src/vmm/src/devices/virtio/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ impl MmioTransport {
self.queue_select = 0;
self.interrupt_status.store(0, Ordering::SeqCst);
self.device_status = device_status::INIT;
// . Keep interrupt_evt and queue_evts as is. There may be pending
// notifications in those eventfds, but nothing will happen other
// than supurious wakeups.
// . Keep interrupt_evt and queue_evts as is. There may be pending notifications in those
// eventfds, but nothing will happen other than supurious wakeups.
// . Do not reset config_generation and keep it monotonically increasing
for queue in self.locked_device().queues_mut() {
*queue = Queue::new(queue.get_max_size());
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/devices/virtio/net/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,8 @@ impl VirtioDevice for Net {
let end = start.and_then(|s| s.checked_add(data.len()));
let Some(dst) = start
.zip(end)
.and_then(|(start, end)| config_space_bytes.get_mut(start..end)) else
{
.and_then(|(start, end)| config_space_bytes.get_mut(start..end))
else {
error!("Failed to write config space");
METRICS.net.cfg_fails.inc();
return;
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/devices/virtio/net/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ impl TapTrafficSimulator {
// sizeof::<libc::sockaddr_ll>(), so to return an owned value of sockaddr_ll
// from the stack-local libc::sockaddr_storage that we have, we need to
// 1. Create a zeroed out libc::sockaddr_ll,
// 2. Copy over the first size_of::<libc::sockaddr_ll>() bytes into the struct we
// want to return
// 2. Copy over the first size_of::<libc::sockaddr_ll>() bytes into the struct we want
// to return
// We cannot simply return "*(send_addr_ptr as *const libc::sockaddr_ll)", as this
// would return a reference to a variable that lives in the stack frame of the current
// function, and which will no longer be valid after returning.
Expand Down
26 changes: 12 additions & 14 deletions src/vmm/src/devices/virtio/vsock/csm/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ use std::fmt::Debug;
// Short primer on the vsock protocol
// ----------------------------------
//
// 1. Establishing a connection
// A vsock connection is considered established after a two-way handshake:
// 1. Establishing a connection A vsock connection is considered established after a two-way
// handshake:
// - the initiating peer sends a connection request packet (`hdr.op` == VSOCK_OP_REQUEST);
// then
// - the listening peer sends back a connection response packet (`hdr.op` ==
// VSOCK_OP_RESPONSE).
//
// 2. Terminating a connection
// When a peer wants to shut down an established connection, it sends a VSOCK_OP_SHUTDOWN
// packet. Two header flags are used with VSOCK_OP_SHUTDOWN, indicating the sender's
// intention:
// 2. Terminating a connection When a peer wants to shut down an established connection, it
// sends a VSOCK_OP_SHUTDOWN packet. Two header flags are used with VSOCK_OP_SHUTDOWN,
// indicating the sender's intention:
// - VSOCK_FLAGS_SHUTDOWN_RCV: the sender will receive no more data for this connection; and
// - VSOCK_FLAGS_SHUTDOWN_SEND: the sender will send no more data for this connection.
// After a shutdown packet, the receiving peer will have some protocol-undefined time to
Expand All @@ -51,14 +50,13 @@ use std::fmt::Debug;
// cannot be taken back. That is, `hdr.flags` will be ORed between subsequent
// VSOCK_OP_SHUTDOWN packets.
//
// 3. Flow control
// Before sending a data packet (VSOCK_OP_RW), the sender must make sure that the receiver
// has enough free buffer space to store that data. If this condition is not respected, the
// receiving peer's behaviour is undefined. In this implementation, we forcefully terminate
// the connection by sending back a VSOCK_OP_RST packet.
// Note: all buffer space information is computed and stored on a per-connection basis.
// Peers keep each other informed about the free buffer space they have by filling in two
// packet header members with each packet they send:
// 3. Flow control Before sending a data packet (VSOCK_OP_RW), the sender must make sure that
// the receiver has enough free buffer space to store that data. If this condition is not
// respected, the receiving peer's behaviour is undefined. In this implementation, we
// forcefully terminate the connection by sending back a VSOCK_OP_RST packet. Note: all
// buffer space information is computed and stored on a per-connection basis. Peers keep
// each other informed about the free buffer space they have by filling in two packet header
// members with each packet they send:
// - `hdr.buf_alloc`: the total buffer space the peer has allocated for receiving data; and
// - `hdr.fwd_cnt`: the total number of bytes the peer has successfully flushed out of its
// buffer.
Expand Down
6 changes: 3 additions & 3 deletions src/vmm/src/devices/virtio/vsock/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ pub struct Vsock<B> {
}

// TODO: Detect / handle queue deadlock:
// 1. If the driver halts RX queue processing, we'll need to notify `self.backend`, so that it
// can unregister any EPOLLIN listeners, since otherwise it will keep spinning, unable to consume
// its EPOLLIN events.
// 1. If the driver halts RX queue processing, we'll need to notify `self.backend`, so that it can
// unregister any EPOLLIN listeners, since otherwise it will keep spinning, unable to consume its
// EPOLLIN events.

impl<B> Vsock<B>
where
Expand Down
13 changes: 6 additions & 7 deletions src/vmm/src/devices/virtio/vsock/unix/muxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
/// device model.
///
/// The vsock muxer has two main roles:
/// 1. Vsock connection multiplexer:
/// It's the muxer's job to create, manage, and terminate `VsockConnection` objects. The
/// muxer also routes packets to their owning connections. It does so via a connection
/// `HashMap`, keyed by what is basically a (host_port, guest_port) tuple.
/// Vsock packet traffic needs to be inspected, in order to detect connection request
/// 1. Vsock connection multiplexer: It's the muxer's job to create, manage, and terminate
/// `VsockConnection` objects. The muxer also routes packets to their owning connections. It
/// does so via a connection `HashMap`, keyed by what is basically a (host_port, guest_port)
/// tuple. Vsock packet traffic needs to be inspected, in order to detect connection request
/// packets (leading to the creation of a new connection), and connection reset packets
/// (leading to the termination of an existing connection). All other packets, though, must
/// belong to an existing connection and, as such, the muxer simply forwards them.
/// 2. Event dispatcher
/// There are three event categories that the vsock backend is interested it:
/// 2. Event dispatcher There are three event categories that the vsock backend is interested
/// it:
/// 1. A new host-initiated connection is ready to be accepted from the listening host Unix
/// socket;
/// 2. Data is available for reading from a newly-accepted host-initiated connection (i.e.
Expand Down
6 changes: 2 additions & 4 deletions src/vmm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,8 @@ fn construct_kvm_mpidrs(vcpu_states: &[VcpuState]) -> Vec<u64> {
impl Drop for Vmm {
fn drop(&mut self) {
// There are two cases when `drop()` is called:
// 1) before the Vmm has been mutexed and subscribed to the event
// manager, or
// 2) after the Vmm has been registered as a subscriber to the
// event manager.
// 1) before the Vmm has been mutexed and subscribed to the event manager, or
// 2) after the Vmm has been registered as a subscriber to the event manager.
//
// The first scenario is bound to happen if an error is raised during
// Vmm creation (for example, during snapshot load), before the Vmm has
Expand Down

0 comments on commit 9ea964c

Please sign in to comment.