mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 07:18:03 +02:00
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. (cherry picked from commita3cd66d3fa) (cherry picked from commite74375fc3b)
This commit is contained in:
parent
b2ed9e7d5d
commit
7fcc89db6e
3 changed files with 17 additions and 23 deletions
|
|
@ -360,26 +360,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
|
static gboolean
|
||||||
_config_one(GCancellable * sigterm_cancellable,
|
_config_one(GCancellable * sigterm_cancellable,
|
||||||
NMClient * nmc,
|
NMClient * nmc,
|
||||||
gboolean is_single_nic,
|
|
||||||
const char * hwaddr,
|
const char * hwaddr,
|
||||||
const NMCSProviderGetConfigIfaceData *config_data)
|
const NMCSProviderGetConfigIfaceData *config_data)
|
||||||
{
|
{
|
||||||
|
|
@ -497,14 +480,11 @@ _config_all(GCancellable * sigterm_cancellable,
|
||||||
GHashTableIter h_iter;
|
GHashTableIter h_iter;
|
||||||
const NMCSProviderGetConfigIfaceData *c_config_data;
|
const NMCSProviderGetConfigIfaceData *c_config_data;
|
||||||
const char * c_hwaddr;
|
const char * c_hwaddr;
|
||||||
gboolean is_single_nic;
|
|
||||||
gboolean any_changes = FALSE;
|
gboolean any_changes = FALSE;
|
||||||
|
|
||||||
is_single_nic = (_config_data_get_num_valid(result) <= 1);
|
|
||||||
|
|
||||||
g_hash_table_iter_init(&h_iter, result->iface_datas);
|
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)) {
|
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;
|
any_changes = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,12 +54,23 @@ nmcs_provider_get_main_context(NMCSProvider *self)
|
||||||
static NMCSProviderGetConfigResult *
|
static NMCSProviderGetConfigResult *
|
||||||
nmcs_provider_get_config_result_new(GHashTable *iface_datas)
|
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 = g_new(NMCSProviderGetConfigResult, 1);
|
||||||
*result = (NMCSProviderGetConfigResult){
|
*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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,9 @@ typedef struct {
|
||||||
/* A dictionary of (const char *) -> (NMCSProviderGetConfigIfaceData *).
|
/* A dictionary of (const char *) -> (NMCSProviderGetConfigIfaceData *).
|
||||||
* This is the per-interface result of get_config(). */
|
* This is the per-interface result of get_config(). */
|
||||||
GHashTable *iface_datas;
|
GHashTable *iface_datas;
|
||||||
|
|
||||||
|
/* The number of iface_datas that are nmcs_provider_get_config_iface_data_is_valid(). */
|
||||||
|
guint num_valid_ifaces;
|
||||||
} NMCSProviderGetConfigResult;
|
} NMCSProviderGetConfigResult;
|
||||||
|
|
||||||
void nmcs_provider_get_config_result_free(NMCSProviderGetConfigResult *result);
|
void nmcs_provider_get_config_result_free(NMCSProviderGetConfigResult *result);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue