summaryrefslogtreecommitdiff
path: root/src/nm-cloud-setup
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-09-01 09:42:37 +0200
committerThomas Haller <thaller@redhat.com>2021-09-16 15:51:02 +0200
commita3cd66d3fadcecab9b186cc7f634f6ec6a5a92ee (patch)
tree2f67d9ffdced0ed000d532ed45808f12c03d97b9 /src/nm-cloud-setup
parent323e18276894591712a5e29f6e907562c79c5216 (diff)
downloadNetworkManager-a3cd66d3fadcecab9b186cc7f634f6ec6a5a92ee.tar.gz
cloud-setup: cache number of valid interfaces in get-config result
Now that we return a struct from get_config(), we can have system-wide properties returned. Let it count and cache the number of valid iface_datas. Currently that is not yet used, but it will be.
Diffstat (limited to 'src/nm-cloud-setup')
-rw-r--r--src/nm-cloud-setup/main.c22
-rw-r--r--src/nm-cloud-setup/nmcs-provider.c15
-rw-r--r--src/nm-cloud-setup/nmcs-provider.h3
3 files changed, 17 insertions, 23 deletions
diff --git a/src/nm-cloud-setup/main.c b/src/nm-cloud-setup/main.c
index 04b29f8a4b..686cd2fc0c 100644
--- a/src/nm-cloud-setup/main.c
+++ b/src/nm-cloud-setup/main.c
@@ -395,26 +395,9 @@ _nmc_mangle_connection(NMDevice * device,
/*****************************************************************************/
-static guint
-_config_data_get_num_valid(const NMCSProviderGetConfigResult *result)
-{
- const NMCSProviderGetConfigIfaceData *config_data;
- GHashTableIter h_iter;
- guint n = 0;
-
- g_hash_table_iter_init(&h_iter, result->iface_datas);
- while (g_hash_table_iter_next(&h_iter, NULL, (gpointer *) &config_data)) {
- if (nmcs_provider_get_config_iface_data_is_valid(config_data))
- n++;
- }
-
- return n;
-}
-
static gboolean
_config_one(GCancellable * sigterm_cancellable,
NMClient * nmc,
- gboolean is_single_nic,
const char * hwaddr,
const NMCSProviderGetConfigIfaceData *config_data)
{
@@ -532,14 +515,11 @@ _config_all(GCancellable * sigterm_cancellable,
GHashTableIter h_iter;
const NMCSProviderGetConfigIfaceData *c_config_data;
const char * c_hwaddr;
- gboolean is_single_nic;
gboolean any_changes = FALSE;
- is_single_nic = (_config_data_get_num_valid(result) <= 1);
-
g_hash_table_iter_init(&h_iter, result->iface_datas);
while (g_hash_table_iter_next(&h_iter, (gpointer *) &c_hwaddr, (gpointer *) &c_config_data)) {
- if (_config_one(sigterm_cancellable, nmc, is_single_nic, c_hwaddr, c_config_data))
+ if (_config_one(sigterm_cancellable, nmc, c_hwaddr, c_config_data))
any_changes = TRUE;
}
diff --git a/src/nm-cloud-setup/nmcs-provider.c b/src/nm-cloud-setup/nmcs-provider.c
index 77f8090a82..8f82ddb493 100644
--- a/src/nm-cloud-setup/nmcs-provider.c
+++ b/src/nm-cloud-setup/nmcs-provider.c
@@ -54,12 +54,23 @@ nmcs_provider_get_main_context(NMCSProvider *self)
static NMCSProviderGetConfigResult *
nmcs_provider_get_config_result_new(GHashTable *iface_datas)
{
- NMCSProviderGetConfigResult *result;
+ const NMCSProviderGetConfigIfaceData *iface_data;
+ NMCSProviderGetConfigResult * result;
+ GHashTableIter h_iter;
+ guint num_valid_ifaces = 0;
+
+ g_hash_table_iter_init(&h_iter, iface_datas);
+ while (g_hash_table_iter_next(&h_iter, NULL, (gpointer *) &iface_data)) {
+ if (nmcs_provider_get_config_iface_data_is_valid(iface_data))
+ num_valid_ifaces++;
+ }
result = g_new(NMCSProviderGetConfigResult, 1);
*result = (NMCSProviderGetConfigResult){
- .iface_datas = g_hash_table_ref(iface_datas),
+ .iface_datas = g_hash_table_ref(iface_datas),
+ .num_valid_ifaces = num_valid_ifaces,
};
+
return result;
}
diff --git a/src/nm-cloud-setup/nmcs-provider.h b/src/nm-cloud-setup/nmcs-provider.h
index 730ddc9d8f..2e4c8d167a 100644
--- a/src/nm-cloud-setup/nmcs-provider.h
+++ b/src/nm-cloud-setup/nmcs-provider.h
@@ -49,6 +49,9 @@ typedef struct {
/* A dictionary of (const char *) -> (NMCSProviderGetConfigIfaceData *).
* This is the per-interface result of get_config(). */
GHashTable *iface_datas;
+
+ /* The number of iface_datas that are nmcs_provider_get_config_iface_data_is_valid(). */
+ guint num_valid_ifaces;
} NMCSProviderGetConfigResult;
void nmcs_provider_get_config_result_free(NMCSProviderGetConfigResult *result);