Skip to content

Commit 167651b

Browse files
authored
Merge branch 'rust-vmm:main' into issue123-typed-ring-accessors
2 parents 0562ce3 + f72ca02 commit 167651b

File tree

10 files changed

+68
-67
lines changed

10 files changed

+68
-67
lines changed

virtio-blk/src/request.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Display for Error {
6262
match self {
6363
DescriptorChainTooShort => write!(f, "descriptor chain too short"),
6464
DescriptorLengthTooSmall => write!(f, "descriptor length too small"),
65-
GuestMemory(ref err) => write!(f, "error accessing guest memory: {}", err),
65+
GuestMemory(ref err) => write!(f, "error accessing guest memory: {err}"),
6666
InvalidFlushSector => write!(f, "invalid sector in flush request, it should be 0"),
6767
UnexpectedReadOnlyDescriptor => write!(f, "unexpected read only descriptor"),
6868
UnexpectedWriteOnlyDescriptor => write!(f, "unexpected write only descriptor"),
@@ -207,8 +207,8 @@ impl Request {
207207
/// descriptor (the chain tail) is device-writable.
208208
///
209209
/// # Arguments
210-
/// * `desc_chain` - A mutable reference to the descriptor chain that should point to the
211-
/// buffers of a virtio block request.
210+
///
211+
/// * `desc_chain` - A mutable reference to the descriptor chain that should point to the buffers of a virtio block request.
212212
pub fn parse<M>(desc_chain: &mut DescriptorChain<M>) -> Result<Request>
213213
where
214214
M: Deref,
@@ -269,7 +269,7 @@ mod tests {
269269
(DescriptorChainTooShort, DescriptorChainTooShort) => true,
270270
(DescriptorLengthTooSmall, DescriptorLengthTooSmall) => true,
271271
(GuestMemory(ref e), GuestMemory(ref other_e)) => {
272-
format!("{}", e).eq(&format!("{}", other_e))
272+
format!("{e}").eq(&format!("{other_e}"))
273273
}
274274
(InvalidFlushSector, InvalidFlushSector) => true,
275275
(UnexpectedReadOnlyDescriptor, UnexpectedReadOnlyDescriptor) => true,

virtio-blk/src/stdio_executor.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,22 @@ impl Display for Error {
129129

130130
match self {
131131
DiscardWriteZeroes(ref err) => {
132-
write!(f, "discard/write zeroes execution failed: {}", err)
132+
write!(f, "discard/write zeroes execution failed: {err}")
133133
}
134-
Flush(ref err) => write!(f, "flush execution failed: {}", err),
135-
GuestMemory(ref err) => write!(f, "error accessing guest memory: {}", err),
134+
Flush(ref err) => write!(f, "flush execution failed: {err}"),
135+
GuestMemory(ref err) => write!(f, "error accessing guest memory: {err}"),
136136
InvalidAccess => write!(f, "invalid file access"),
137137
InvalidDataLength => write!(f, "invalid data length of request"),
138138
InvalidFlags => write!(f, "invalid flags for discard/write zeroes request"),
139139
Overflow => write!(f, "overflow when computing memory address"),
140-
Read(ref err, _) => write!(f, "error during read request execution: {}", err),
140+
Read(ref err, _) => write!(f, "error during read request execution: {err}"),
141141
ReadOnly => write!(
142142
f,
143143
"can't execute an operation other than `read` on a read-only device"
144144
),
145-
Write(ref err) => write!(f, "error during write request execution: {}", err),
146-
Seek(ref err) => write!(f, "file seek execution failed: {}", err),
147-
Unsupported(t) => write!(f, "can't execute unsupported request {}", t),
145+
Write(ref err) => write!(f, "error during write request execution: {err}"),
146+
Seek(ref err) => write!(f, "file seek execution failed: {err}"),
147+
Unsupported(t) => write!(f, "can't execute unsupported request {t}"),
148148
}
149149
}
150150
}
@@ -224,8 +224,8 @@ impl<B: Backend> StdIoBackend<B> {
224224
/// Sets the `device_id`.
225225
///
226226
/// # Arguments
227-
/// * `device_id` - The block device id. On Linux guests, this information can be read from
228-
/// `/sys/block/<device>/serial`.
227+
///
228+
/// * `device_id` - The block device id. On Linux guests, this information can be read from `/sys/block/<device>/serial`.
229229
pub fn with_device_id(mut self, device_id: [u8; VIRTIO_BLK_ID_BYTES as usize]) -> Self {
230230
self.device_id = Some(device_id);
231231
self
@@ -244,6 +244,7 @@ impl<B: Backend> StdIoBackend<B> {
244244
/// byte).
245245
///
246246
/// # Arguments
247+
///
247248
/// * `mem` - A reference to the guest memory.
248249
/// * `request` - The request to execute.
249250
pub fn process_request<M: GuestMemory>(
@@ -506,22 +507,22 @@ mod tests {
506507
use self::Error::*;
507508
match (self, other) {
508509
(DiscardWriteZeroes(ref e), DiscardWriteZeroes(ref other_e)) => {
509-
format!("{}", e).eq(&format!("{}", other_e))
510+
format!("{e}").eq(&format!("{other_e}"))
510511
}
511-
(Flush(ref e), Flush(ref other_e)) => format!("{}", e).eq(&format!("{}", other_e)),
512+
(Flush(ref e), Flush(ref other_e)) => format!("{e}").eq(&format!("{other_e}")),
512513
(GuestMemory(ref e), GuestMemory(ref other_e)) => {
513-
format!("{}", e).eq(&format!("{}", other_e))
514+
format!("{e}").eq(&format!("{other_e}"))
514515
}
515516
(InvalidAccess, InvalidAccess) => true,
516517
(InvalidDataLength, InvalidDataLength) => true,
517518
(InvalidFlags, InvalidFlags) => true,
518519
(Overflow, Overflow) => true,
519520
(Read(ref e, bytes), Read(ref other_e, other_bytes)) => {
520-
format!("{}", e).eq(&format!("{}", other_e)) && bytes == other_bytes
521+
format!("{e}").eq(&format!("{other_e}")) && bytes == other_bytes
521522
}
522523
(ReadOnly, ReadOnly) => true,
523-
(Write(ref e), Write(ref other_e)) => format!("{}", e).eq(&format!("{}", other_e)),
524-
(Seek(ref e), Seek(ref other_e)) => format!("{}", e).eq(&format!("{}", other_e)),
524+
(Write(ref e), Write(ref other_e)) => format!("{e}").eq(&format!("{other_e}")),
525+
(Seek(ref e), Seek(ref other_e)) => format!("{e}").eq(&format!("{other_e}")),
525526
(Unsupported(val), Unsupported(other_val)) => val == other_val,
526527
_ => false,
527528
}

virtio-console/src/console.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ impl Display for Error {
4646

4747
match self {
4848
WriteToGuestFailed(ref err) => {
49-
write!(f, "Console failed to write slice to guest memory: {}", err)
49+
write!(f, "Console failed to write slice to guest memory: {err}")
5050
}
5151
WriteToOutputFailed(ref err) => {
52-
write!(f, "Console failed to write data to output sink: {}", err)
52+
write!(f, "Console failed to write data to output sink: {err}")
5353
}
5454
ChainLengthOverflow => {
5555
write!(f, "Console transmitq chain length has overflown usize.")
@@ -73,7 +73,7 @@ impl Display for Error {
7373
)
7474
}
7575
OutputSinkFlushFailed(ref err) => {
76-
write!(f, "Output sink flush has not written all bytes: {}", err)
76+
write!(f, "Output sink flush has not written all bytes: {err}")
7777
}
7878
}
7979
}
@@ -115,9 +115,11 @@ where
115115
/// Create new console object with the default `capacity`.
116116
///
117117
/// # Arguments
118-
/// * `output` - The output sink where all the data received from
119-
/// the transmitq will be written.
118+
///
119+
/// * `output` - The output sink where all the data received from the transmitq will be written.
120+
///
120121
/// # Returns
122+
///
121123
/// The console object.
122124
pub fn new(output: T) -> Self {
123125
Self::new_with_capacity(DEFAULT_CAPACITY, output).unwrap()
@@ -126,10 +128,12 @@ where
126128
/// Create new console object with specified `capacity`.
127129
///
128130
/// # Arguments
131+
///
129132
/// * `capacity` - The capacity of the input buffer.
130-
/// * `output` - The output sink where all the data received from
131-
/// the transmitq will be written.
133+
/// * `output` - The output sink where all the data received from the transmitq will be written.
134+
///
132135
/// # Returns
136+
///
133137
/// The console object or an `Error` if the capacity is 0 or higher than [`MAX_CAPACITY`].
134138
pub fn new_with_capacity(capacity: usize, output: T) -> Result<Self, Error> {
135139
// There is no use case for 0 capacity
@@ -150,8 +154,8 @@ where
150154
/// returned.
151155
///
152156
/// # Arguments
153-
/// * `data` - A mutable reference to a `Vec<u8>` containing the raw bytes that will be
154-
/// sent to the driver when the `process_receiveq_chain` method is called.
157+
///
158+
/// * `data` - A mutable reference to a `Vec<u8>` containing the raw bytes that will be sent to the driver when the `process_receiveq_chain` method is called.
155159
pub fn enqueue_data(&self, data: &mut Vec<u8>) -> Result<(), Error> {
156160
let mut input_buffer = self.input_buffer.lock().unwrap();
157161
let total_length = input_buffer
@@ -189,8 +193,8 @@ where
189193
/// Read data from a `desc_chain` of the transmit queue and write it to the output sink.
190194
///
191195
/// # Arguments
192-
/// * `desc_chain` - A mutable reference to the descriptor chain that should point to the
193-
/// buffers that the virtio console driver has sent to the device.
196+
///
197+
/// * `desc_chain` - A mutable reference to the descriptor chain that should point to the buffers that the virtio console driver has sent to the device.
194198
pub fn process_transmitq_chain<M>(
195199
&mut self,
196200
desc_chain: &mut DescriptorChain<M>,
@@ -224,9 +228,11 @@ where
224228
/// add more.
225229
///
226230
/// # Arguments
227-
/// * `desc_chain` - A mutable reference to the descriptor chain that should point to the
228-
/// empty buffers that the virtio driver has offered the device.
231+
///
232+
/// * `desc_chain` - A mutable reference to the descriptor chain that should point to the empty buffers that the virtio driver has offered the device.
233+
///
229234
/// # Returns
235+
///
230236
/// The number of raw bytes written to guest memory.
231237
pub fn process_receiveq_chain<M>(
232238
&self,
@@ -291,10 +297,10 @@ mod tests {
291297
use self::Error::*;
292298
match (self, other) {
293299
(WriteToGuestFailed(ref e), WriteToGuestFailed(ref other_e)) => {
294-
format!("{}", e).eq(&format!("{}", other_e))
300+
format!("{e}").eq(&format!("{other_e}"))
295301
}
296302
(WriteToOutputFailed(ref e), WriteToOutputFailed(ref other_e)) => {
297-
format!("{}", e).eq(&format!("{}", other_e))
303+
format!("{e}").eq(&format!("{other_e}"))
298304
}
299305
(ChainLengthOverflow, ChainLengthOverflow) => true,
300306
(BufferCapacityExceeded, BufferCapacityExceeded) => true,

virtio-queue/benches/queue/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn benchmark_queue(c: &mut Criterion) {
5858
for indirect in [false, true].iter().copied() {
5959
bench_queue(
6060
c,
61-
&format!("single chain (indirect={})", indirect),
61+
&format!("single chain (indirect={indirect})"),
6262
|| queue_with_chains(1, 128, indirect),
6363
|mut q| {
6464
let (num_chains, num_descriptors) = walk_queue(&mut q, &mem);
@@ -69,7 +69,7 @@ pub fn benchmark_queue(c: &mut Criterion) {
6969

7070
bench_queue(
7171
c,
72-
&format!("multiple chains (indirect={})", indirect),
72+
&format!("multiple chains (indirect={indirect})"),
7373
|| queue_with_chains(128, 1, indirect),
7474
|mut q| {
7575
let (num_chains, num_descriptors) = walk_queue(&mut q, &mem);

virtio-queue/src/chain.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ where
6060
/// Create a new `DescriptorChain` instance.
6161
///
6262
/// # Arguments
63-
/// * `mem` - the `GuestMemory` object that can be used to access the buffers pointed to by the
64-
/// descriptor chain.
63+
///
64+
/// * `mem` - the `GuestMemory` object that can be used to access the buffers pointed to by the descriptor chain.
6565
/// * `desc_table` - the address of the descriptor table.
66-
/// * `queue_size` - the size of the queue, which is also the maximum size of a descriptor
67-
/// chain.
66+
/// * `queue_size` - the size of the queue, which is also the maximum size of a descriptor chain.
6867
/// * `head_index` - the descriptor index of the chain head.
6968
pub(crate) fn new(mem: M, desc_table: GuestAddress, queue_size: u16, head_index: u16) -> Self {
7069
Self::with_ttl(mem, desc_table, queue_size, queue_size, head_index)

virtio-queue/src/descriptor_utils.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,14 @@ mod tests {
482482

483483
let mut buffer = [0_u8; 64];
484484
if let Err(e) = reader.read_exact(&mut buffer) {
485-
panic!("read_exact should not fail here: {:?}", e);
485+
panic!("read_exact should not fail here: {e:?}");
486486
}
487487

488488
assert_eq!(reader.available_bytes(), 42);
489489
assert_eq!(reader.bytes_read(), 64);
490490

491491
match reader.read(&mut buffer) {
492-
Err(e) => panic!("read should not fail here: {:?}", e),
492+
Err(e) => panic!("read should not fail here: {e:?}"),
493493
Ok(length) => assert_eq!(length, 42),
494494
}
495495

@@ -522,14 +522,14 @@ mod tests {
522522

523523
let buffer = [0_u8; 64];
524524
if let Err(e) = writer.write_all(&buffer) {
525-
panic!("write_all should not fail here: {:?}", e);
525+
panic!("write_all should not fail here: {e:?}");
526526
}
527527

528528
assert_eq!(writer.available_bytes(), 42);
529529
assert_eq!(writer.bytes_written(), 64);
530530

531531
match writer.write(&buffer) {
532-
Err(e) => panic!("write should not fail here {:?}", e),
532+
Err(e) => panic!("write should not fail here {e:?}"),
533533
Ok(length) => assert_eq!(length, 42),
534534
}
535535

@@ -641,7 +641,7 @@ mod tests {
641641
.expect("create_descriptor_chain failed");
642642
let mut writer = Writer::new(&memory, chain_writer).expect("failed to create Writer");
643643
if let Err(e) = writer.write_obj(secret) {
644-
panic!("write_obj should not fail here: {:?}", e);
644+
panic!("write_obj should not fail here: {e:?}");
645645
}
646646

647647
// Now create new descriptor chain pointing to the same memory and try to read it.
@@ -654,7 +654,7 @@ mod tests {
654654
.expect("create_descriptor_chain failed");
655655
let mut reader = Reader::new(&memory, chain_reader).expect("failed to create Reader");
656656
match reader.read_obj::<Le32>() {
657-
Err(e) => panic!("read_obj should not fail here: {:?}", e),
657+
Err(e) => panic!("read_obj should not fail here: {e:?}"),
658658
Ok(read_secret) => assert_eq!(read_secret, secret),
659659
}
660660
}

virtio-queue/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Display for MockError {
4949
f,
5050
"invalid next available descriptor chain head in the queue"
5151
),
52-
GuestMem(e) => write!(f, "guest memory error: {}", e),
52+
GuestMem(e) => write!(f, "guest memory error: {e}"),
5353
}
5454
}
5555
}

virtio-queue/src/queue.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -690,11 +690,10 @@ where
690690
/// Create a new instance of `AvailInter`.
691691
///
692692
/// # Arguments
693+
///
693694
/// * `mem` - the `GuestMemory` object that can be used to access the queue buffers.
694-
/// * `idx` - the index of the available ring entry where the driver would put the next
695-
/// available descriptor chain.
696-
/// * `queue` - the `Queue` object from which the needed data to create the `AvailIter` can
697-
/// be retrieved.
695+
/// * `idx` - the index of the available ring entry where the driver would put the next available descriptor chain.
696+
/// * `queue` - the `Queue` object from which the needed data to create the `AvailIter` can be retrieved.
698697
pub(crate) fn new(mem: M, idx: Wrapping<u16>, queue: &'b mut Queue) -> Result<Self, Error> {
699698
// The number of descriptor chain heads to process should always
700699
// be smaller or equal to the queue size, as the driver should
@@ -770,7 +769,7 @@ where
770769
// proper implementation as `GuestMemory` errors cannot implement `PartialEq`.
771770
impl PartialEq for Error {
772771
fn eq(&self, other: &Self) -> bool {
773-
format!("{}", &self) == format!("{}", other)
772+
format!("{}", &self) == format!("{other}")
774773
}
775774
}
776775

virtio-vsock/src/packet.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ impl Display for Error {
8282
"The descriptor is pointing to a buffer that has a longer length than expected."
8383
),
8484
Error::InvalidHeaderInputSize(size) => {
85-
write!(f, "Invalid header input size: {}", size)
85+
write!(f, "Invalid header input size: {size}")
8686
}
8787
Error::InvalidHeaderLen(size) => {
88-
write!(f, "Invalid header `len` field value: {}", size)
88+
write!(f, "Invalid header `len` field value: {size}")
8989
}
9090
Error::InvalidMemoryAccess(error) => {
91-
write!(f, "Invalid guest memory access: {}", error)
91+
write!(f, "Invalid guest memory access: {error}")
9292
}
9393
Error::InvalidVolatileAccess(error) => {
94-
write!(f, "Invalid volatile memory access: {}", error)
94+
write!(f, "Invalid volatile memory access: {error}")
9595
}
9696
Error::UnexpectedReadOnlyDescriptor => {
9797
write!(f, "Unexpected read-only descriptor.")
@@ -363,12 +363,10 @@ impl<'a, B: BitmapSlice> VsockPacket<'a, B> {
363363
/// descriptor can optionally end the chain.
364364
///
365365
/// # Arguments
366+
///
366367
/// * `mem` - the `GuestMemory` object that can be used to access the queue buffers.
367368
/// * `desc_chain` - the descriptor chain corresponding to a packet.
368-
/// * `max_data_size` - the maximum size allowed for the packet payload, that was negotiated
369-
/// between the device and the driver. Tracking issue for defining this
370-
/// feature in virtio-spec
371-
/// [here](https://github.com/oasis-tcs/virtio-spec/issues/140).
369+
/// * `max_data_size` - the maximum size allowed for the packet payload, that was negotiated between the device and the driver. Tracking issue for defining this feature in virtio-spec [here](https://github.com/oasis-tcs/virtio-spec/issues/140).
372370
///
373371
/// # Example
374372
///
@@ -504,12 +502,10 @@ impl<'a, B: BitmapSlice> VsockPacket<'a, B> {
504502
/// descriptor.
505503
///
506504
/// # Arguments
505+
///
507506
/// * `mem` - the `GuestMemory` object that can be used to access the queue buffers.
508507
/// * `desc_chain` - the descriptor chain corresponding to a packet.
509-
/// * `max_data_size` - the maximum size allowed for the packet payload, that was negotiated
510-
/// between the device and the driver. Tracking issue for defining this
511-
/// feature in virtio-spec
512-
/// [here](https://github.com/oasis-tcs/virtio-spec/issues/140).
508+
/// * `max_data_size` - the maximum size allowed for the packet payload, that was negotiated between the device and the driver. Tracking issue for defining this feature in virtio-spec [here](https://github.com/oasis-tcs/virtio-spec/issues/140).
513509
///
514510
/// # Example
515511
///
@@ -699,10 +695,10 @@ mod tests {
699695
}
700696
(InvalidHeaderLen(size), InvalidHeaderLen(other_size)) => size == other_size,
701697
(InvalidMemoryAccess(ref e), InvalidMemoryAccess(ref other_e)) => {
702-
format!("{}", e).eq(&format!("{}", other_e))
698+
format!("{e}").eq(&format!("{other_e}"))
703699
}
704700
(InvalidVolatileAccess(ref e), InvalidVolatileAccess(ref other_e)) => {
705-
format!("{}", e).eq(&format!("{}", other_e))
701+
format!("{e}").eq(&format!("{other_e}"))
706702
}
707703
(UnexpectedReadOnlyDescriptor, UnexpectedReadOnlyDescriptor) => true,
708704
(UnexpectedWriteOnlyDescriptor, UnexpectedWriteOnlyDescriptor) => true,

0 commit comments

Comments
 (0)