nm: Improve checkpoint refresh

Instead of having multiple checkpoint refresh call, this patch add
`NmApi.set_checkpoint_auto_refresh(true)` to automatically refresh
on every dbus method call if checkpoint elapsed half of it.

Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
Gris Ge 2022-12-18 19:33:46 +08:00 committed by Fernando Fernández Mancera
parent 2a5063795a
commit 94c7341ac5
7 changed files with 130 additions and 126 deletions

View File

@ -1,7 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
use std::collections::HashSet;
use std::time::Instant;
use super::{
device::create_index_for_nm_devs,
@ -10,7 +9,7 @@ use super::{
profile::{
activate_nm_profiles, create_index_for_nm_conns_by_name_type,
deactivate_nm_profiles, delete_exist_profiles, delete_profiles,
extend_timeout_if_required, save_nm_profiles,
save_nm_profiles,
},
query::{
get_orphan_ovs_port_uuids, is_mptcp_flags_changed, is_mptcp_supported,
@ -30,6 +29,10 @@ use crate::{Interface, InterfaceType, NetworkState, NmstateError, RouteEntry};
const ACTIVATION_RETRY_COUNT: usize = 6;
const ACTIVATION_RETRY_INTERVAL: u64 = 1;
// There is plan to simply the `add_net_state`, `chg_net_state`, `del_net_state`
// `cur_net_state`, `des_net_state` into single struct. Suppress the clippy
// warning for now
#[allow(clippy::too_many_arguments)]
pub(crate) fn nm_apply(
add_net_state: &NetworkState,
chg_net_state: &NetworkState,
@ -37,27 +40,28 @@ pub(crate) fn nm_apply(
cur_net_state: &NetworkState,
des_net_state: &NetworkState,
checkpoint: &str,
timeout: u32,
memory_only: bool,
) -> Result<(), NmstateError> {
let nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
let mut nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
nm_api.set_checkpoint(checkpoint, timeout);
nm_api.set_checkpoint_auto_refresh(true);
if !memory_only {
delete_net_state(&nm_api, del_net_state, checkpoint)?;
delete_net_state(&mut nm_api, del_net_state)?;
}
apply_single_state(
&nm_api,
&mut nm_api,
add_net_state,
cur_net_state,
des_net_state,
checkpoint,
memory_only,
)?;
apply_single_state(
&nm_api,
&mut nm_api,
chg_net_state,
cur_net_state,
des_net_state,
checkpoint,
memory_only,
)?;
@ -65,9 +69,8 @@ pub(crate) fn nm_apply(
}
fn delete_net_state(
nm_api: &NmApi,
nm_api: &mut NmApi,
net_state: &NetworkState,
checkpoint: &str,
) -> Result<(), NmstateError> {
let all_nm_conns = nm_api.connections_get().map_err(nm_error_to_nmstate)?;
@ -128,28 +131,24 @@ fn delete_net_state(
}
}
let mut now = Instant::now();
for uuid in &uuids_to_delete {
extend_timeout_if_required(&mut now, checkpoint)?;
nm_api
.connection_delete(uuid)
.map_err(nm_error_to_nmstate)?;
}
delete_orphan_ports(nm_api, &uuids_to_delete, checkpoint)?;
delete_remain_virtual_interface_as_desired(nm_api, net_state, checkpoint)?;
delete_orphan_ports(nm_api, &uuids_to_delete)?;
delete_remain_virtual_interface_as_desired(nm_api, net_state)?;
Ok(())
}
fn apply_single_state(
nm_api: &NmApi,
nm_api: &mut NmApi,
net_state: &NetworkState,
cur_net_state: &NetworkState,
des_net_state: &NetworkState,
checkpoint: &str,
memory_only: bool,
) -> Result<(), NmstateError> {
let mut now = Instant::now();
if let Some(hostname) =
net_state.hostname.as_ref().and_then(|c| c.config.as_ref())
{
@ -171,11 +170,9 @@ fn apply_single_state(
let exist_nm_conns =
nm_api.connections_get().map_err(nm_error_to_nmstate)?;
extend_timeout_if_required(&mut now, checkpoint)?;
let nm_acs = nm_api
.active_connections_get()
.map_err(nm_error_to_nmstate)?;
extend_timeout_if_required(&mut now, checkpoint)?;
let nm_ac_uuids: Vec<&str> =
nm_acs.iter().map(|nm_ac| &nm_ac.uuid as &str).collect();
let activated_nm_conns: Vec<&NmConnection> = exist_nm_conns
@ -274,33 +271,12 @@ fn apply_single_state(
nm_conns_to_activate.as_slice(),
activated_nm_conns.as_slice(),
);
// Previous `NmApi` call might be time consuming on system with 1000+
// connections. Hence we do force checkpoint refresh here
extend_timeout_if_required(&mut now, checkpoint)?;
deactivate_nm_profiles(
nm_api,
nm_conns_to_deactivate_first.as_slice(),
checkpoint,
)?;
extend_timeout_if_required(&mut now, checkpoint)?;
save_nm_profiles(
nm_api,
nm_conns_to_update.as_slice(),
checkpoint,
memory_only,
)?;
extend_timeout_if_required(&mut now, checkpoint)?;
deactivate_nm_profiles(nm_api, nm_conns_to_deactivate_first.as_slice())?;
save_nm_profiles(nm_api, nm_conns_to_update.as_slice(), memory_only)?;
if !memory_only {
delete_exist_profiles(
nm_api,
&exist_nm_conns,
&nm_conns_to_activate,
checkpoint,
)?;
delete_profiles(nm_api, &ovs_port_nm_conn_uuids_to_delete, checkpoint)?;
delete_exist_profiles(nm_api, &exist_nm_conns, &nm_conns_to_activate)?;
delete_profiles(nm_api, &ovs_port_nm_conn_uuids_to_delete)?;
}
extend_timeout_if_required(&mut now, checkpoint)?;
let mut nm_conns: Vec<&NmConnection> =
nm_conns_to_activate.as_slice().iter().collect();
@ -311,7 +287,6 @@ fn apply_single_state(
nm_api,
nm_conns.as_slice(),
nm_ac_uuids.as_slice(),
checkpoint,
)?;
if remain_nm_conns.is_empty() {
break;
@ -327,7 +302,9 @@ fn apply_single_state(
let wait_internal = ACTIVATION_RETRY_INTERVAL * (1 << i);
log::info!("Will retry activation {wait_internal} seconds");
for _ in 0..wait_internal {
extend_timeout_if_required(&mut now, checkpoint)?;
nm_api
.extend_timeout_if_required()
.map_err(nm_error_to_nmstate)?;
std::thread::sleep(std::time::Duration::from_secs(1));
}
} else {
@ -335,23 +312,16 @@ fn apply_single_state(
}
}
deactivate_nm_profiles(
nm_api,
nm_conns_to_deactivate.as_slice(),
checkpoint,
)?;
extend_timeout_if_required(&mut now, checkpoint)?;
deactivate_nm_profiles(nm_api, nm_conns_to_deactivate.as_slice())?;
Ok(())
}
fn delete_remain_virtual_interface_as_desired(
nm_api: &NmApi,
nm_api: &mut NmApi,
net_state: &NetworkState,
checkpoint: &str,
) -> Result<(), NmstateError> {
let nm_devs = nm_api.devices_get().map_err(nm_error_to_nmstate)?;
let nm_devs_indexed = create_index_for_nm_devs(&nm_devs);
let mut now = Instant::now();
// Interfaces created by non-NM tools will not be deleted by connection
// deletion, remove manually.
for iface in &(net_state.interfaces.to_vec()) {
@ -371,7 +341,6 @@ fn delete_remain_virtual_interface_as_desired(
);
// There might be an race with on-going profile/connection
// deletion, verification will raise error for it later.
extend_timeout_if_required(&mut now, checkpoint)?;
if let Err(e) = nm_api.device_delete(&nm_dev.obj_path) {
log::debug!("Failed to delete interface {:?}", e);
}
@ -383,9 +352,8 @@ fn delete_remain_virtual_interface_as_desired(
// If any connection still referring to deleted UUID, we should delete it also
fn delete_orphan_ports(
nm_api: &NmApi,
nm_api: &mut NmApi,
uuids_deleted: &HashSet<&str>,
checkpoint: &str,
) -> Result<(), NmstateError> {
let mut uuids_to_delete = Vec::new();
let all_nm_conns = nm_api.connections_get().map_err(nm_error_to_nmstate)?;
@ -407,9 +375,7 @@ fn delete_orphan_ports(
}
}
}
let mut now = Instant::now();
for uuid in &uuids_to_delete {
extend_timeout_if_required(&mut now, checkpoint)?;
nm_api
.connection_delete(uuid)
.map_err(nm_error_to_nmstate)?;

View File

@ -9,7 +9,7 @@ pub(crate) const CHECKPOINT_ROLLBACK_TIMEOUT: u32 = 60;
pub(crate) fn nm_checkpoint_create(
timeout: u32,
) -> Result<String, NmstateError> {
let nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
let mut nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
nm_api
.checkpoint_create(timeout)
.map_err(nm_error_to_nmstate)
@ -18,7 +18,7 @@ pub(crate) fn nm_checkpoint_create(
pub(crate) fn nm_checkpoint_rollback(
checkpoint: &str,
) -> Result<(), NmstateError> {
let nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
let mut nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
nm_api
.checkpoint_rollback(checkpoint)
.map_err(nm_error_to_nmstate)?;
@ -32,7 +32,7 @@ pub(crate) fn nm_checkpoint_rollback(
pub(crate) fn nm_checkpoint_destroy(
checkpoint: &str,
) -> Result<(), NmstateError> {
let nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
let mut nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
nm_api
.checkpoint_destroy(checkpoint)
.map_err(nm_error_to_nmstate)

View File

@ -22,40 +22,74 @@ use super::{
pub struct NmApi<'a> {
pub(crate) dbus: NmDbus<'a>,
checkpoint: Option<String>,
cp_refresh_time: Option<std::time::Instant>,
cp_timeout: u32,
auto_cp_refresh: bool,
}
impl<'a> NmApi<'a> {
pub fn new() -> Result<Self, NmError> {
Ok(Self {
dbus: NmDbus::new()?,
checkpoint: None,
cp_refresh_time: None,
cp_timeout: 0,
auto_cp_refresh: false,
})
}
pub fn set_checkpoint(&mut self, checkpoint: &str, timeout: u32) {
self.checkpoint = Some(checkpoint.to_string());
self.cp_timeout = timeout;
self.cp_refresh_time = Some(std::time::Instant::now());
}
pub fn set_checkpoint_auto_refresh(&mut self, value: bool) {
self.auto_cp_refresh = value;
}
pub fn version(&self) -> Result<String, NmError> {
self.dbus.version()
}
pub fn checkpoint_create(&self, timeout: u32) -> Result<String, NmError> {
pub fn checkpoint_create(
&mut self,
timeout: u32,
) -> Result<String, NmError> {
debug!("checkpoint_create");
let cp = self.dbus.checkpoint_create(timeout)?;
debug!("checkpoint created: {}", &cp);
self.checkpoint = Some(cp.clone());
self.cp_refresh_time = Some(std::time::Instant::now());
self.cp_timeout = timeout;
Ok(cp)
}
pub fn checkpoint_destroy(&self, checkpoint: &str) -> Result<(), NmError> {
pub fn checkpoint_destroy(
&mut self,
checkpoint: &str,
) -> Result<(), NmError> {
let mut checkpoint_to_destroy: String = checkpoint.to_string();
if checkpoint_to_destroy.is_empty() {
checkpoint_to_destroy = self.last_active_checkpoint()?
}
self.checkpoint = None;
self.cp_refresh_time = None;
debug!("checkpoint_destroy: {}", checkpoint_to_destroy);
self.dbus.checkpoint_destroy(checkpoint_to_destroy.as_str())
}
pub fn checkpoint_rollback(&self, checkpoint: &str) -> Result<(), NmError> {
pub fn checkpoint_rollback(
&mut self,
checkpoint: &str,
) -> Result<(), NmError> {
let mut checkpoint_to_rollback: String = checkpoint.to_string();
if checkpoint_to_rollback.is_empty() {
checkpoint_to_rollback = self.last_active_checkpoint()?
}
self.checkpoint = None;
self.cp_refresh_time = None;
debug!("checkpoint_rollback: {}", checkpoint_to_rollback);
self.dbus
.checkpoint_rollback(checkpoint_to_rollback.as_str())
@ -74,14 +108,16 @@ impl<'a> NmApi<'a> {
}
}
pub fn connection_activate(&self, uuid: &str) -> Result<(), NmError> {
pub fn connection_activate(&mut self, uuid: &str) -> Result<(), NmError> {
debug!("connection_activate: {}", uuid);
self.extend_timeout_if_required()?;
let nm_conn = self.dbus.get_conn_obj_path_by_uuid(uuid)?;
self.dbus.connection_activate(&nm_conn)
}
pub fn connection_deactivate(&self, uuid: &str) -> Result<(), NmError> {
pub fn connection_deactivate(&mut self, uuid: &str) -> Result<(), NmError> {
debug!("connection_deactivate: {}", uuid);
self.extend_timeout_if_required()?;
if let Ok(nm_ac) = get_nm_ac_obj_path_by_uuid(&self.dbus, uuid) {
if !nm_ac.is_empty() {
self.dbus.connection_deactivate(&nm_ac)?;
@ -90,8 +126,9 @@ impl<'a> NmApi<'a> {
Ok(())
}
pub fn connections_get(&self) -> Result<Vec<NmConnection>, NmError> {
pub fn connections_get(&mut self) -> Result<Vec<NmConnection>, NmError> {
debug!("connections_get");
self.extend_timeout_if_required()?;
let mut nm_conns = Vec::new();
for nm_conn_obj_path in self.dbus.nm_conn_obj_paths_get()? {
// Race: Connection might just been deleted, hence we ignore error
@ -108,12 +145,14 @@ impl<'a> NmApi<'a> {
}
pub fn applied_connections_get(
&self,
&mut self,
) -> Result<Vec<NmConnection>, NmError> {
debug!("applied_connections_get");
self.extend_timeout_if_required()?;
let nm_dev_obj_paths = self.dbus.nm_dev_obj_paths_get()?;
let mut nm_conns: Vec<NmConnection> = Vec::new();
for nm_dev_obj_path in nm_dev_obj_paths {
self.extend_timeout_if_required()?;
match self.dbus.nm_dev_applied_connection_get(&nm_dev_obj_path) {
Ok(nm_conn) => nm_conns.push(nm_conn),
Err(e) => {
@ -132,11 +171,12 @@ impl<'a> NmApi<'a> {
}
pub fn connection_add(
&self,
&mut self,
nm_conn: &NmConnection,
memory_only: bool,
) -> Result<(), NmError> {
debug!("connection_add: {:?}", nm_conn);
self.extend_timeout_if_required()?;
if !nm_conn.obj_path.is_empty() {
self.dbus.connection_update(
nm_conn.obj_path.as_str(),
@ -148,8 +188,9 @@ impl<'a> NmApi<'a> {
}
}
pub fn connection_delete(&self, uuid: &str) -> Result<(), NmError> {
pub fn connection_delete(&mut self, uuid: &str) -> Result<(), NmError> {
debug!("connection_delete: {}", uuid);
self.extend_timeout_if_required()?;
if let Ok(con_obj_path) = self.dbus.get_conn_obj_path_by_uuid(uuid) {
debug!("Found nm_connection {} for UUID {}", con_obj_path, uuid);
if !con_obj_path.is_empty() {
@ -160,10 +201,11 @@ impl<'a> NmApi<'a> {
}
pub fn connection_reapply(
&self,
&mut self,
nm_conn: &NmConnection,
) -> Result<(), NmError> {
debug!("connection_reapply: {:?}", nm_conn);
self.extend_timeout_if_required()?;
if let Some(iface_name) = nm_conn.iface_name() {
let nm_dev_obj_path = self.dbus.nm_dev_obj_path_get(iface_name)?;
self.dbus.nm_dev_reapply(&nm_dev_obj_path, nm_conn)
@ -178,9 +220,10 @@ impl<'a> NmApi<'a> {
}
pub fn active_connections_get(
&self,
&mut self,
) -> Result<Vec<NmActiveConnection>, NmError> {
debug!("active_connections_get");
self.extend_timeout_if_required()?;
let mut nm_acs = Vec::new();
let nm_ac_obj_paths = self.dbus.active_connections()?;
for nm_ac_obj_path in nm_ac_obj_paths {
@ -209,8 +252,9 @@ impl<'a> NmApi<'a> {
.checkpoint_timeout_extend(checkpoint, added_time_sec)
}
pub fn devices_get(&self) -> Result<Vec<NmDevice>, NmError> {
pub fn devices_get(&mut self) -> Result<Vec<NmDevice>, NmError> {
debug!("devices_get");
self.extend_timeout_if_required()?;
let mut ret = Vec::new();
for nm_dev_obj_path in &self.dbus.nm_dev_obj_paths_get()? {
match nm_dev_from_obj_path(&self.dbus.connection, nm_dev_obj_path) {
@ -231,21 +275,26 @@ impl<'a> NmApi<'a> {
Ok(ret)
}
pub fn device_delete(&self, nm_dev_obj_path: &str) -> Result<(), NmError> {
pub fn device_delete(
&mut self,
nm_dev_obj_path: &str,
) -> Result<(), NmError> {
self.extend_timeout_if_required()?;
nm_dev_delete(&self.dbus.connection, nm_dev_obj_path)
}
pub fn device_lldp_neighbor_get(
&self,
&mut self,
nm_dev_obj_path: &str,
) -> Result<Vec<NmLldpNeighbor>, NmError> {
self.extend_timeout_if_required()?;
nm_dev_get_llpd(&self.dbus.connection, nm_dev_obj_path)
}
// If any device is with NewActivation or IpConfig state,
// we wait its activation.
pub fn wait_checkpoint_rollback(
&self,
&mut self,
// TODO: return error when waiting_nm_dev is not changing for given
// time.
timeout: u32,
@ -279,15 +328,19 @@ impl<'a> NmApi<'a> {
))
}
pub fn get_dns_configuration(&self) -> Result<Vec<NmDnsEntry>, NmError> {
pub fn get_dns_configuration(
&mut self,
) -> Result<Vec<NmDnsEntry>, NmError> {
let mut ret: Vec<NmDnsEntry> = Vec::new();
self.extend_timeout_if_required()?;
for dns_value in self.dbus.get_dns_configuration()? {
ret.push(NmDnsEntry::try_from(dns_value)?);
}
Ok(ret)
}
pub fn hostname_set(&self, hostname: &str) -> Result<(), NmError> {
pub fn hostname_set(&mut self, hostname: &str) -> Result<(), NmError> {
self.extend_timeout_if_required()?;
if hostname.is_empty() {
// Due to bug https://bugzilla.redhat.com/2090946
// NetworkManager daemon cannot remove static hostname, hence we
@ -302,6 +355,23 @@ impl<'a> NmApi<'a> {
self.dbus.hostname_set(hostname)
}
}
pub fn extend_timeout_if_required(&mut self) -> Result<(), NmError> {
if let (Some(cp_refresh_time), Some(checkpoint)) =
(self.cp_refresh_time.as_ref(), self.checkpoint.as_ref())
{
// Only extend the timeout when only half of it elapsed
if self.auto_cp_refresh
&& cp_refresh_time.elapsed().as_secs()
>= self.cp_timeout as u64 / 2
{
log::debug!("Extending checkpoint timeout");
self.checkpoint_timeout_extend(checkpoint, self.cp_timeout)?;
self.cp_refresh_time = Some(Instant::now());
}
}
Ok(())
}
}
fn get_nm_ac_obj_path_by_uuid(

View File

@ -1,12 +1,10 @@
// SPDX-License-Identifier: Apache-2.0
use std::collections::{hash_map::Entry, HashMap};
use std::time::Instant;
use super::nm_dbus::{NmApi, NmConnection, NmSettingsConnectionFlag};
use crate::{
nm::checkpoint::{
nm_checkpoint_timeout_extend, CHECKPOINT_ROLLBACK_TIMEOUT,
},
nm::error::nm_error_to_nmstate,
nm::settings::{
NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BRIDGE_SETTING_NAME,
@ -26,10 +24,9 @@ pub(crate) const NM_SETTING_CONTROLLERS: [&str; 5] = [
];
pub(crate) fn delete_exist_profiles(
nm_api: &NmApi,
nm_api: &mut NmApi,
exist_nm_conns: &[NmConnection],
nm_conns: &[NmConnection],
checkpoint: &str,
) -> Result<(), NmstateError> {
let mut excluded_uuids: Vec<&str> = Vec::new();
let mut changed_iface_name_types: Vec<(&str, &str)> = Vec::new();
@ -84,18 +81,15 @@ pub(crate) fn delete_exist_profiles(
}
}
}
delete_profiles(nm_api, &uuids_to_delete, checkpoint)
delete_profiles(nm_api, &uuids_to_delete)
}
pub(crate) fn save_nm_profiles(
nm_api: &NmApi,
nm_api: &mut NmApi,
nm_conns: &[NmConnection],
checkpoint: &str,
memory_only: bool,
) -> Result<(), NmstateError> {
let mut now = Instant::now();
for nm_conn in nm_conns {
extend_timeout_if_required(&mut now, checkpoint)?;
if nm_conn.obj_path.is_empty() {
log::info!(
"Creating connection UUID {:?}, ID {:?}, type {:?} name {:?}",
@ -122,19 +116,16 @@ pub(crate) fn save_nm_profiles(
// Return list of activation failed `NmConnection` which we can retry
pub(crate) fn activate_nm_profiles<'a>(
nm_api: &NmApi,
nm_api: &mut NmApi,
nm_conns: &[&'a NmConnection],
nm_ac_uuids: &[&str],
checkpoint: &str,
) -> Result<Vec<(&'a NmConnection, NmstateError)>, NmstateError> {
let mut now = Instant::now();
let mut new_controllers: Vec<&str> = Vec::new();
let mut failed_nm_conns: Vec<(&NmConnection, NmstateError)> = Vec::new();
for nm_conn in nm_conns.iter().filter(|c| {
c.iface_type().map(|t| NM_SETTING_CONTROLLERS.contains(&t))
== Some(true)
}) {
extend_timeout_if_required(&mut now, checkpoint)?;
if let Some(uuid) = nm_conn.uuid() {
log::info!(
"Activating connection {}: {}/{}",
@ -169,8 +160,6 @@ pub(crate) fn activate_nm_profiles<'a>(
c.iface_type().map(|t| NM_SETTING_CONTROLLERS.contains(&t))
!= Some(true)
}) {
extend_timeout_if_required(&mut now, checkpoint)?;
if let Some(uuid) = nm_conn.uuid() {
if nm_ac_uuids.contains(&uuid) {
log::info!(
@ -228,13 +217,10 @@ pub(crate) fn activate_nm_profiles<'a>(
}
pub(crate) fn deactivate_nm_profiles(
nm_api: &NmApi,
nm_api: &mut NmApi,
nm_conns: &[&NmConnection],
checkpoint: &str,
) -> Result<(), NmstateError> {
let mut now = Instant::now();
for nm_conn in nm_conns {
extend_timeout_if_required(&mut now, checkpoint)?;
if let Some(uuid) = nm_conn.uuid() {
log::info!(
"Deactivating connection {}: {}/{}",
@ -250,19 +236,6 @@ pub(crate) fn deactivate_nm_profiles(
Ok(())
}
pub(crate) fn extend_timeout_if_required(
now: &mut Instant,
checkpoint: &str,
) -> Result<(), NmstateError> {
// Only extend the timeout when only half of it elapsed
if now.elapsed().as_secs() >= CHECKPOINT_ROLLBACK_TIMEOUT as u64 / 2 {
log::debug!("Extending checkpoint timeout");
nm_checkpoint_timeout_extend(checkpoint, CHECKPOINT_ROLLBACK_TIMEOUT)?;
*now = Instant::now();
}
Ok(())
}
pub(crate) fn create_index_for_nm_conns_by_ctrler_type(
nm_conns: &[NmConnection],
) -> HashMap<(&str, &str), Vec<&NmConnection>> {
@ -382,13 +355,10 @@ pub(crate) fn get_port_nm_conns<'a>(
}
pub(crate) fn delete_profiles(
nm_api: &NmApi,
nm_api: &mut NmApi,
uuids: &[&str],
checkpoint: &str,
) -> Result<(), NmstateError> {
let mut now = Instant::now();
for uuid in uuids {
extend_timeout_if_required(&mut now, checkpoint)?;
nm_api
.connection_delete(uuid)
.map_err(nm_error_to_nmstate)?;
@ -397,7 +367,7 @@ pub(crate) fn delete_profiles(
}
fn reapply_or_activate(
nm_api: &NmApi,
nm_api: &mut NmApi,
nm_conn: &NmConnection,
) -> Result<(), NmstateError> {
if let Err(e) = nm_api.connection_reapply(nm_conn) {

View File

@ -43,7 +43,7 @@ pub(crate) fn nm_dns_to_nmstate(
}
pub(crate) fn retrieve_dns_info(
nm_api: &NmApi,
nm_api: &mut NmApi,
ifaces: &Interfaces,
) -> Result<DnsState, NmstateError> {
let mut nm_dns_entires = nm_api

View File

@ -45,7 +45,7 @@ pub(crate) fn nm_retrieve(
) -> Result<NetworkState, NmstateError> {
let mut net_state = NetworkState::new();
net_state.prop_list = vec!["interfaces", "dns"];
let nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
let mut nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
let nm_conns = nm_api
.applied_connections_get()
.map_err(nm_error_to_nmstate)?;
@ -190,7 +190,7 @@ pub(crate) fn nm_retrieve(
}
}
net_state.dns = retrieve_dns_info(&nm_api, &net_state.interfaces)?;
net_state.dns = retrieve_dns_info(&mut nm_api, &net_state.interfaces)?;
if running_config_only {
net_state.dns.running = None;
}

View File

@ -172,10 +172,7 @@ impl NetworkState {
VERIFY_RETRY_INTERVAL_MILLISECONDS,
VERIFY_RETRY_NM,
|| {
nm_checkpoint_timeout_extend(
&checkpoint,
timeout,
)?;
nm_checkpoint_timeout_extend(&checkpoint, timeout)?;
nm_apply(
&add_net_state,
&chg_net_state,
@ -186,6 +183,7 @@ impl NetworkState {
&cur_net_state,
&desire_state_to_apply,
&checkpoint,
timeout,
self.memory_only,
)?;
if desire_state_to_apply.prop_list.contains(&"ovsdb")