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.
This commit is contained in:
Thomas Haller 2021-09-01 09:42:37 +02:00
parent 323e182768
commit a3cd66d3fa
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
3 changed files with 17 additions and 23 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);