mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
misc: Replace map_or on false with is_some_and
Replace `map_or()` on false condition with `is_some_and` to provide better readability, as suggestted by v1.84.0-beta.1 `cargo clippy`. Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
This commit is contained in:
parent
7e419784cd
commit
ab7b294688
@ -75,9 +75,7 @@ pub fn open_tap(
|
|||||||
let mut ifname: String = String::new();
|
let mut ifname: String = String::new();
|
||||||
let vnet_hdr_size = vnet_hdr_len() as i32;
|
let vnet_hdr_size = vnet_hdr_len() as i32;
|
||||||
// Check if the given interface exists before we create it.
|
// Check if the given interface exists before we create it.
|
||||||
let tap_existed = if_name.map_or(false, |n| {
|
let tap_existed = if_name.is_some_and(|n| Path::new(&format!("/sys/class/net/{n}")).exists());
|
||||||
Path::new(&format!("/sys/class/net/{n}")).exists()
|
|
||||||
});
|
|
||||||
|
|
||||||
// In case the tap interface already exists, check if the number of
|
// In case the tap interface already exists, check if the number of
|
||||||
// queues is appropriate. The tap might not support multiqueue while
|
// queues is appropriate. The tap might not support multiqueue while
|
||||||
|
@ -468,7 +468,7 @@ impl NetQueuePair {
|
|||||||
let rate_limit_reached = self
|
let rate_limit_reached = self
|
||||||
.rx_rate_limiter
|
.rx_rate_limiter
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |r| r.is_blocked());
|
.is_some_and(|r| r.is_blocked());
|
||||||
|
|
||||||
// Stop listening on the `RX_TAP_EVENT` when:
|
// Stop listening on the `RX_TAP_EVENT` when:
|
||||||
// 1) there is no available describes, or
|
// 1) there is no available describes, or
|
||||||
|
@ -9401,7 +9401,7 @@ mod live_migration {
|
|||||||
|
|
||||||
// Check the source vm has been terminated successful (give it '3s' to settle)
|
// Check the source vm has been terminated successful (give it '3s' to settle)
|
||||||
thread::sleep(std::time::Duration::new(3, 0));
|
thread::sleep(std::time::Duration::new(3, 0));
|
||||||
if !src_child.try_wait().unwrap().map_or(false, |s| s.success()) {
|
if !src_child.try_wait().unwrap().is_some_and(|s| s.success()) {
|
||||||
print_and_panic(
|
print_and_panic(
|
||||||
src_child,
|
src_child,
|
||||||
dest_child,
|
dest_child,
|
||||||
@ -9575,7 +9575,7 @@ mod live_migration {
|
|||||||
|
|
||||||
// Check the source vm has been terminated successful (give it '3s' to settle)
|
// Check the source vm has been terminated successful (give it '3s' to settle)
|
||||||
thread::sleep(std::time::Duration::new(3, 0));
|
thread::sleep(std::time::Duration::new(3, 0));
|
||||||
if !src_child.try_wait().unwrap().map_or(false, |s| s.success()) {
|
if !src_child.try_wait().unwrap().is_some_and(|s| s.success()) {
|
||||||
print_and_panic(
|
print_and_panic(
|
||||||
src_child,
|
src_child,
|
||||||
dest_child,
|
dest_child,
|
||||||
@ -9793,7 +9793,7 @@ mod live_migration {
|
|||||||
|
|
||||||
// Check the source vm has been terminated successful (give it '3s' to settle)
|
// Check the source vm has been terminated successful (give it '3s' to settle)
|
||||||
thread::sleep(std::time::Duration::new(3, 0));
|
thread::sleep(std::time::Duration::new(3, 0));
|
||||||
if !src_child.try_wait().unwrap().map_or(false, |s| s.success()) {
|
if !src_child.try_wait().unwrap().is_some_and(|s| s.success()) {
|
||||||
print_and_panic(
|
print_and_panic(
|
||||||
src_child,
|
src_child,
|
||||||
dest_child,
|
dest_child,
|
||||||
@ -10009,7 +10009,7 @@ mod live_migration {
|
|||||||
|
|
||||||
// Check the source vm has been terminated successful (give it '3s' to settle)
|
// Check the source vm has been terminated successful (give it '3s' to settle)
|
||||||
thread::sleep(std::time::Duration::new(3, 0));
|
thread::sleep(std::time::Duration::new(3, 0));
|
||||||
if !src_child.try_wait().unwrap().map_or(false, |s| s.success()) {
|
if !src_child.try_wait().unwrap().is_some_and(|s| s.success()) {
|
||||||
print_and_panic(
|
print_and_panic(
|
||||||
src_child,
|
src_child,
|
||||||
dest_child,
|
dest_child,
|
||||||
@ -10119,7 +10119,7 @@ mod live_migration {
|
|||||||
|
|
||||||
// Check the source vm has been terminated successful (give it '3s' to settle)
|
// Check the source vm has been terminated successful (give it '3s' to settle)
|
||||||
thread::sleep(std::time::Duration::new(3, 0));
|
thread::sleep(std::time::Duration::new(3, 0));
|
||||||
if !src_child.try_wait().unwrap().map_or(false, |s| s.success()) {
|
if !src_child.try_wait().unwrap().is_some_and(|s| s.success()) {
|
||||||
print_and_panic(
|
print_and_panic(
|
||||||
src_child,
|
src_child,
|
||||||
dest_child,
|
dest_child,
|
||||||
@ -10266,7 +10266,7 @@ mod live_migration {
|
|||||||
|
|
||||||
// Check the source vm has been terminated successful (give it '3s' to settle)
|
// Check the source vm has been terminated successful (give it '3s' to settle)
|
||||||
thread::sleep(std::time::Duration::new(3, 0));
|
thread::sleep(std::time::Duration::new(3, 0));
|
||||||
if !src_child.try_wait().unwrap().map_or(false, |s| s.success()) {
|
if !src_child.try_wait().unwrap().is_some_and(|s| s.success()) {
|
||||||
print_and_panic(
|
print_and_panic(
|
||||||
src_child,
|
src_child,
|
||||||
dest_child,
|
dest_child,
|
||||||
|
@ -489,8 +489,7 @@ impl EpollHelperHandler for BlockEpollHandler {
|
|||||||
EpollHelperError::HandleEvent(anyhow!("Failed to get queue event: {:?}", e))
|
EpollHelperError::HandleEvent(anyhow!("Failed to get queue event: {:?}", e))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let rate_limit_reached =
|
let rate_limit_reached = self.rate_limiter.as_ref().is_some_and(|r| r.is_blocked());
|
||||||
self.rate_limiter.as_ref().map_or(false, |r| r.is_blocked());
|
|
||||||
|
|
||||||
// Process the queue only when the rate limit is not reached
|
// Process the queue only when the rate limit is not reached
|
||||||
if !rate_limit_reached {
|
if !rate_limit_reached {
|
||||||
@ -509,8 +508,7 @@ impl EpollHelperHandler for BlockEpollHandler {
|
|||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let rate_limit_reached =
|
let rate_limit_reached = self.rate_limiter.as_ref().is_some_and(|r| r.is_blocked());
|
||||||
self.rate_limiter.as_ref().map_or(false, |r| r.is_blocked());
|
|
||||||
|
|
||||||
// Process the queue only when the rate limit is not reached
|
// Process the queue only when the rate limit is not reached
|
||||||
if !rate_limit_reached {
|
if !rate_limit_reached {
|
||||||
|
@ -201,7 +201,7 @@ impl NetEpollHandler {
|
|||||||
.net
|
.net
|
||||||
.rx_rate_limiter
|
.rx_rate_limiter
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |r| r.is_blocked());
|
.is_some_and(|r| r.is_blocked());
|
||||||
|
|
||||||
// Start to listen on RX_TAP_EVENT only when the rate limit is not reached
|
// Start to listen on RX_TAP_EVENT only when the rate limit is not reached
|
||||||
if !self.net.rx_tap_listening && !rate_limit_reached {
|
if !self.net.rx_tap_listening && !rate_limit_reached {
|
||||||
@ -238,7 +238,7 @@ impl NetEpollHandler {
|
|||||||
.net
|
.net
|
||||||
.tx_rate_limiter
|
.tx_rate_limiter
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |r| r.is_blocked());
|
.is_some_and(|r| r.is_blocked());
|
||||||
|
|
||||||
if !rate_limit_reached {
|
if !rate_limit_reached {
|
||||||
self.process_tx()?;
|
self.process_tx()?;
|
||||||
|
Loading…
Reference in New Issue
Block a user