Skip to content

Commit ece30ba

Browse files
committed
rust: Migrate zbus v1 to V5
Fedora 42 is removing support of zbus V1 and we are suggested to use V4 or V5. The zbus V4 does not have Clone trait for OwnedValue which require massive changes to our code base. Hence using zbus V5. The zbus V5 need at least 1.77 to compile as it use a nightly feature of rust rust-lang/rust#91345 which only become stable in rust 1.77. It is impossible to compile this project in Rust 1.66 now, removing CI test for compiling on Rust 1.66. Downstream release should considering using Rust 1.77+ to compile this project. Signed-off-by: Gris Ge <[email protected]>
1 parent f858dd9 commit ece30ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+770
-590
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,6 @@ jobs:
203203
path: test_artifacts/
204204
retention-days: 5
205205

206-
build_on_rust_1_66:
207-
runs-on: ubuntu-22.04
208-
steps:
209-
- uses: actions/checkout@v4
210-
211-
- name: Install Rust 1.66
212-
run: rustup install 1.66
213-
214-
- name: Use rust vendoring
215-
run: |
216-
cd rust
217-
wget -qO- https://github.com/nmstate/nmstate/releases/download/v2.2.36/nmstate-vendor-2.2.36-rust-1.66.tar.xz | tar xJ
218-
mkdir .cargo
219-
echo '[source.crates-io]' > .cargo/config.toml
220-
echo 'replace-with = "vendored-sources"' >> .cargo/config.toml
221-
echo '[source.vendored-sources]' >> .cargo/config.toml
222-
echo 'directory = "vendor"' >> .cargo/config.toml
223-
224-
- name: Build on rust 1.66
225-
run: cd rust && cargo +1.66 build --ignore-rust-version
226-
227206
macos_gen_conf_build:
228207
strategy:
229208
fail-fast: true

rust/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ members = [
66
"src/lib",
77
]
88

9+
[workspace.package]
10+
rust-version = "1.77"
11+
912
[workspace.dependencies]
1013
log = "0.4.17"
1114
serde_yaml = "0.9"
@@ -15,8 +18,8 @@ nmstate = { path = "src/lib", version = "2.2", default-features = false }
1518
nispor = "1.2.21"
1619
uuid = { version = "1.1 ", default-features = false, features = ["v4"] }
1720
nix = { version = "0.26.2", default-features = false, features = ["feature", "hostname"] }
18-
zbus = { version = "1.9.2", default-features = false}
19-
zvariant = {version = "2.10.0", default-features = false}
21+
zbus = { version = "5.1.0", default-features = false, features = ["tokio"] }
22+
zvariant = {version = "5.1.0", default-features = false}
2023
libc = "0.2.74"
2124
once_cell = "1.12.0"
2225
env_logger = "0.10.0"

rust/src/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repository = "https://github.com/nmstate/nmstate"
1010
keywords = ["network", "linux"]
1111
categories = ["network-programming"]
1212
edition = "2021"
13-
rust-version = "1.66"
13+
rust-version.workspace = true
1414

1515
[[bin]]
1616
name = "nmstatectl"

rust/src/clib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version = "2.2.40"
55
authors = ["Gris Ge <[email protected]>"]
66
license = "Apache-2.0"
77
edition = "2021"
8-
rust-version = "1.66"
8+
rust-version.workspace = true
99
build = "build.rs"
1010

1111
[lib]

rust/src/lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ documentation = "https://nmstate.io"
99
repository = "https://github.com/nmstate/nmstate"
1010
keywords = ["network", "linux"]
1111
categories = ["network-programming", "os::linux-apis"]
12-
rust-version = "1.66"
12+
rust-version.workspace = true
1313
edition = "2021"
1414

1515
[lib]

rust/src/lib/nm/checkpoint.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,50 @@ use crate::{nm::error::nm_error_to_nmstate, NmstateError};
88
// Wait maximum 60 seconds for rollback
99
pub(crate) const CHECKPOINT_ROLLBACK_TIMEOUT: u32 = 60;
1010

11-
pub(crate) fn nm_checkpoint_create(
11+
pub(crate) async fn nm_checkpoint_create(
1212
timeout: u32,
1313
) -> Result<String, NmstateError> {
14-
let mut nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
14+
let mut nm_api = NmApi::new().await.map_err(nm_error_to_nmstate)?;
1515
nm_api
1616
.checkpoint_create(timeout)
17+
.await
1718
.map_err(nm_error_to_nmstate)
1819
}
1920

20-
pub(crate) fn nm_checkpoint_rollback(
21+
pub(crate) async fn nm_checkpoint_rollback(
2122
checkpoint: &str,
2223
) -> Result<(), NmstateError> {
23-
let mut nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
24+
let mut nm_api = NmApi::new().await.map_err(nm_error_to_nmstate)?;
2425
nm_api
2526
.checkpoint_rollback(checkpoint)
27+
.await
2628
.map_err(nm_error_to_nmstate)?;
27-
if let Err(e) = nm_api.wait_checkpoint_rollback(CHECKPOINT_ROLLBACK_TIMEOUT)
29+
if let Err(e) = nm_api
30+
.wait_checkpoint_rollback(CHECKPOINT_ROLLBACK_TIMEOUT)
31+
.await
2832
{
2933
warn!("{}", e);
3034
}
3135
Ok(())
3236
}
3337

34-
pub(crate) fn nm_checkpoint_destroy(
38+
pub(crate) async fn nm_checkpoint_destroy(
3539
checkpoint: &str,
3640
) -> Result<(), NmstateError> {
37-
let mut nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
41+
let mut nm_api = NmApi::new().await.map_err(nm_error_to_nmstate)?;
3842
nm_api
3943
.checkpoint_destroy(checkpoint)
44+
.await
4045
.map_err(nm_error_to_nmstate)
4146
}
4247

43-
pub(crate) fn nm_checkpoint_timeout_extend(
48+
pub(crate) async fn nm_checkpoint_timeout_extend(
4449
checkpoint: &str,
4550
added_time_sec: u32,
4651
) -> Result<(), NmstateError> {
47-
let nm_api = NmApi::new().map_err(nm_error_to_nmstate)?;
52+
let nm_api = NmApi::new().await.map_err(nm_error_to_nmstate)?;
4853
nm_api
4954
.checkpoint_timeout_extend(checkpoint, added_time_sec)
55+
.await
5056
.map_err(nm_error_to_nmstate)
5157
}

rust/src/lib/nm/nm_dbus/active_connection.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct NmActiveConnection {
1919
}
2020

2121
#[cfg(feature = "query_apply")]
22-
fn nm_ac_obj_path_state_flags_get(
22+
async fn nm_ac_obj_path_state_flags_get(
2323
dbus_conn: &zbus::Connection,
2424
obj_path: &str,
2525
) -> Result<u32, NmError> {
@@ -28,8 +28,9 @@ fn nm_ac_obj_path_state_flags_get(
2828
NM_DBUS_INTERFACE_ROOT,
2929
obj_path,
3030
NM_DBUS_INTERFACE_AC,
31-
)?;
32-
match proxy.get_property::<u32>("StateFlags") {
31+
)
32+
.await?;
33+
match proxy.get_property::<u32>("StateFlags").await {
3334
Ok(uuid) => Ok(uuid),
3435
Err(e) => Err(NmError::new(
3536
ErrorKind::Bug,
@@ -41,7 +42,7 @@ fn nm_ac_obj_path_state_flags_get(
4142
}
4243

4344
#[cfg(feature = "query_apply")]
44-
pub(crate) fn nm_ac_obj_path_uuid_get(
45+
pub(crate) async fn nm_ac_obj_path_uuid_get(
4546
dbus_conn: &zbus::Connection,
4647
obj_path: &str,
4748
) -> Result<String, NmError> {
@@ -50,8 +51,9 @@ pub(crate) fn nm_ac_obj_path_uuid_get(
5051
NM_DBUS_INTERFACE_ROOT,
5152
obj_path,
5253
NM_DBUS_INTERFACE_AC,
53-
)?;
54-
match proxy.get_property::<String>("Uuid") {
54+
)
55+
.await?;
56+
match proxy.get_property::<String>("Uuid").await {
5557
Ok(uuid) => Ok(uuid),
5658
Err(e) => Err(NmError::new(
5759
ErrorKind::Bug,
@@ -63,7 +65,7 @@ pub(crate) fn nm_ac_obj_path_uuid_get(
6365
}
6466

6567
#[cfg(feature = "query_apply")]
66-
fn nm_ac_obj_path_nm_con_obj_path_get(
68+
async fn nm_ac_obj_path_nm_con_obj_path_get(
6769
dbus_conn: &zbus::Connection,
6870
obj_path: &str,
6971
) -> Result<String, NmError> {
@@ -72,8 +74,12 @@ fn nm_ac_obj_path_nm_con_obj_path_get(
7274
NM_DBUS_INTERFACE_ROOT,
7375
obj_path,
7476
NM_DBUS_INTERFACE_AC,
75-
)?;
76-
match proxy.get_property::<zvariant::OwnedObjectPath>("Connection") {
77+
)
78+
.await?;
79+
match proxy
80+
.get_property::<zvariant::OwnedObjectPath>("Connection")
81+
.await
82+
{
7783
Ok(p) => Ok(obj_path_to_string(p)),
7884
// Sometimes the Active Connection is deleting or deactivating which
7985
// does not have connection associated, we return "" in this case
@@ -82,27 +88,29 @@ fn nm_ac_obj_path_nm_con_obj_path_get(
8288
}
8389

8490
#[cfg(feature = "query_apply")]
85-
pub(crate) fn get_nm_ac_by_obj_path(
91+
pub(crate) async fn get_nm_ac_by_obj_path(
8692
connection: &zbus::Connection,
8793
obj_path: &str,
8894
) -> Result<Option<NmActiveConnection>, NmError> {
8995
// Sometimes the Active Connection is deleting or deactivating which
9096
// does not have connection associated, we return None in this case
9197
let nm_conn_obj_path =
92-
nm_ac_obj_path_nm_con_obj_path_get(connection, obj_path)?;
98+
nm_ac_obj_path_nm_con_obj_path_get(connection, obj_path).await?;
9399

94100
if (!nm_conn_obj_path.is_empty()) && nm_conn_obj_path != "/" {
95-
let nm_conn = nm_con_get_from_obj_path(connection, &nm_conn_obj_path)?;
101+
let nm_conn =
102+
nm_con_get_from_obj_path(connection, &nm_conn_obj_path).await?;
96103
let iface_name = match nm_conn.iface_name() {
97104
Some(i) => i.to_string(),
98105
None => "".to_string(),
99106
};
100107
let iface_type = nm_conn.iface_type().cloned().unwrap_or_default();
101108
Ok(Some(NmActiveConnection {
102-
uuid: nm_ac_obj_path_uuid_get(connection, obj_path)?,
109+
uuid: nm_ac_obj_path_uuid_get(connection, obj_path).await?,
103110
iface_name,
104111
iface_type,
105-
state_flags: nm_ac_obj_path_state_flags_get(connection, obj_path)?,
112+
state_flags: nm_ac_obj_path_state_flags_get(connection, obj_path)
113+
.await?,
106114
}))
107115
} else {
108116
Ok(None)

rust/src/lib/nm/nm_dbus/connection/bond.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
use std::collections::HashMap;
44
use std::convert::TryFrom;
55

6-
use serde::Deserialize;
6+
use serde::{Deserialize, Serialize};
77
use zvariant::Value;
88

99
use super::super::{connection::DbusDictionary, NmError, ToDbusValue};
1010

11-
#[derive(Debug, Clone, PartialEq, Default, Deserialize)]
11+
#[derive(Debug, Clone, PartialEq, Default, Deserialize, Serialize)]
1212
#[serde(try_from = "DbusDictionary")]
1313
#[non_exhaustive]
1414
pub struct NmSettingBond {
@@ -44,7 +44,7 @@ impl ToDbusValue for NmSettingBond {
4444
}
4545
}
4646

47-
#[derive(Debug, Clone, PartialEq, Default)]
47+
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
4848
#[non_exhaustive]
4949
pub struct NmSettingBondPort {
5050
pub priority: Option<i32>,

rust/src/lib/nm/nm_dbus/connection/bridge.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
use std::collections::HashMap;
1919
use std::convert::TryFrom;
2020

21-
use serde::Deserialize;
21+
use serde::{Deserialize, Serialize};
2222

2323
use super::super::{
24-
connection::DbusDictionary,
24+
connection::{DbusDictionary, DBUS_ASV_SIGNATURE},
2525
convert::{
2626
mac_str_to_u8_array, own_value_to_bytes_array, u8_array_to_mac_string,
2727
},
2828
NmError, NmVlanProtocol, ToDbusValue,
2929
};
3030

31-
#[derive(Debug, Clone, PartialEq, Default, Deserialize)]
31+
#[derive(Debug, Clone, PartialEq, Default, Deserialize, Serialize)]
3232
#[serde(try_from = "DbusDictionary")]
3333
#[non_exhaustive]
3434
pub struct NmSettingBridge {
@@ -273,9 +273,8 @@ impl ToDbusValue for NmSettingBridge {
273273
ret.insert("vlan-stats-enabled", zvariant::Value::new(v));
274274
}
275275
if let Some(vlans) = &self.vlans {
276-
let mut vlan_values = zvariant::Array::new(
277-
zvariant::Signature::from_str_unchecked("a{sv}"),
278-
);
276+
let mut vlan_values = zvariant::Array::new(DBUS_ASV_SIGNATURE);
277+
279278
for vlan in vlans {
280279
vlan_values.append(vlan.to_value()?)?;
281280
}
@@ -288,7 +287,7 @@ impl ToDbusValue for NmSettingBridge {
288287
}
289288
}
290289

291-
#[derive(Debug, Clone, PartialEq, Default, Deserialize)]
290+
#[derive(Debug, Clone, PartialEq, Default, Deserialize, Serialize)]
292291
#[serde(try_from = "DbusDictionary")]
293292
#[non_exhaustive]
294293
pub struct NmSettingBridgeVlanRange {
@@ -318,8 +317,8 @@ impl TryFrom<DbusDictionary> for NmSettingBridgeVlanRange {
318317
impl NmSettingBridgeVlanRange {
319318
fn to_value(&self) -> Result<zvariant::Value, NmError> {
320319
let mut ret = zvariant::Dict::new(
321-
zvariant::Signature::from_str_unchecked("s"),
322-
zvariant::Signature::from_str_unchecked("v"),
320+
&zvariant::Signature::Str,
321+
&zvariant::Signature::Variant,
323322
);
324323
ret.append(
325324
zvariant::Value::new("vid-start"),
@@ -341,7 +340,7 @@ impl NmSettingBridgeVlanRange {
341340
}
342341
}
343342

344-
#[derive(Debug, Clone, PartialEq, Default)]
343+
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
345344
#[non_exhaustive]
346345
pub struct NmSettingBridgePort {
347346
pub hairpin_mode: Option<bool>,
@@ -376,9 +375,7 @@ impl ToDbusValue for NmSettingBridgePort {
376375
.map(|v| ret.insert("priority", zvariant::Value::new(v)));
377376

378377
if let Some(vlans) = self.vlans.as_ref() {
379-
let mut vlan_values = zvariant::Array::new(
380-
zvariant::Signature::from_str_unchecked("a{sv}"),
381-
);
378+
let mut vlan_values = zvariant::Array::new(DBUS_ASV_SIGNATURE);
382379
for vlan in vlans {
383380
vlan_values.append(vlan.to_value()?)?;
384381
}

0 commit comments

Comments
 (0)