cloud-setup: track config-task-data in iface-data

Let NMCSProviderGetConfigIfaceData.get_config_data have a pointer to the
NMCSProviderGetConfigTaskData. This will allow two things:

- at several places we pass on `nm_utils_user_data_pack(get_config_data,
  config_iface_data)` as user data. We can avoid that, by just letting
  config_iface_data have a pointer to get_config_data.

- NMCSProviderGetConfigIfaceData contains a provider specific field
  "priv". That may also require special initialization or destruction,
  depending on the type. We thus need access to the provider type,
  which we have via iface_data->get_config_data->self.

Also let NMCSProviderGetConfigTaskData have a pointer "self" to the
NMCSProvider. While there was already the "task", which contains the
provider as source-object, this is more convenient.

Conflicts: missing nmcs-provider-aliyun

(cherry picked from commit 069946cda1)
(cherry picked from commit 061c05ca39)
(cherry picked from commit 1cf4fd0235)
(cherry picked from commit be1dce951e)
(cherry picked from commit 646bc7a10e)
This commit is contained in:
Thomas Haller 2022-04-29 08:29:59 +02:00 committed by Íñigo Huguet
parent c5530797c2
commit bf2a3ff277
5 changed files with 34 additions and 23 deletions

View file

@ -395,9 +395,7 @@ _get_config_iface_cb(GObject *source, GAsyncResult *result, gpointer user_data)
goto out_done;
}
iface_data->iface_get_config =
nmcs_provider_get_config_iface_data_create(get_config_data->result_dict,
FALSE,
v_hwaddr);
nmcs_provider_get_config_iface_data_create(get_config_data, FALSE, v_hwaddr);
} else {
if (iface_data->iface_get_config->iface_idx >= 0) {
_LOGI("interface[%" G_GSSIZE_FORMAT "]: duplicate MAC address %s returned",

View file

@ -258,9 +258,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us
continue;
}
config_iface_data =
nmcs_provider_get_config_iface_data_create(get_config_data->result_dict,
FALSE,
v_hwaddr);
nmcs_provider_get_config_iface_data_create(get_config_data, FALSE, v_hwaddr);
}
nm_assert(config_iface_data->iface_idx == -1);

View file

@ -282,9 +282,7 @@ _get_config_iface_cb(GObject *source, GAsyncResult *result, gpointer user_data)
goto out_done;
}
iface_data->iface_get_config =
nmcs_provider_get_config_iface_data_create(get_config_data->result_dict,
FALSE,
v_hwaddr);
nmcs_provider_get_config_iface_data_create(get_config_data, FALSE, v_hwaddr);
is_requested = FALSE;
} else {
if (iface_data->iface_get_config->iface_idx >= 0) {

View file

@ -174,24 +174,27 @@ nmcs_provider_detect_finish(NMCSProvider *self, GAsyncResult *result, GError **e
/*****************************************************************************/
NMCSProviderGetConfigIfaceData *
nmcs_provider_get_config_iface_data_create(GHashTable *iface_datas,
gboolean was_requested,
const char *hwaddr)
nmcs_provider_get_config_iface_data_create(NMCSProviderGetConfigTaskData *get_config_data,
gboolean was_requested,
const char *hwaddr)
{
NMCSProviderGetConfigIfaceData *iface_data;
nm_assert(hwaddr);
nm_assert(get_config_data);
nm_assert(NMCS_IS_PROVIDER(get_config_data->self));
iface_data = g_slice_new(NMCSProviderGetConfigIfaceData);
*iface_data = (NMCSProviderGetConfigIfaceData){
.hwaddr = g_strdup(hwaddr),
.iface_idx = -1,
.was_requested = was_requested,
.get_config_data = get_config_data,
.hwaddr = g_strdup(hwaddr),
.iface_idx = -1,
.was_requested = was_requested,
};
/* the has does not own the key (iface_datta->hwaddr), the lifetime of the
* key is associated with the iface_data instance. */
g_hash_table_replace(iface_datas, (char *) iface_data->hwaddr, iface_data);
g_hash_table_replace(get_config_data->result_dict, (char *) iface_data->hwaddr, iface_data);
return iface_data;
}
@ -280,6 +283,8 @@ nmcs_provider_get_config(NMCSProvider * self,
get_config_data = g_slice_new(NMCSProviderGetConfigTaskData);
*get_config_data = (NMCSProviderGetConfigTaskData){
/* "self" is kept alive by "task". */
.self = self,
.task = nm_g_task_new(self, cancellable, nmcs_provider_get_config, callback, user_data),
.any = any,
.result_dict = g_hash_table_new_full(nm_str_hash, g_str_equal, NULL, _iface_data_free),
@ -288,7 +293,7 @@ nmcs_provider_get_config(NMCSProvider * self,
nmcs_wait_for_objects_register(get_config_data->task);
for (; hwaddrs && hwaddrs[0]; hwaddrs++)
nmcs_provider_get_config_iface_data_create(get_config_data->result_dict, TRUE, hwaddrs[0]);
nmcs_provider_get_config_iface_data_create(get_config_data, TRUE, hwaddrs[0]);
if (cancellable) {
gulong cancelled_id;

View file

@ -9,11 +9,16 @@
/*****************************************************************************/
struct _NMCSProvider;
struct _NMCSProviderGetConfigTaskData;
typedef struct {
/* And it's exactly the same pointer that is also the key for the iface_datas
* dictionary. */
const char *hwaddr;
struct _NMCSProviderGetConfigTaskData *get_config_data;
in_addr_t *ipv4s_arr;
gsize ipv4s_len;
@ -45,10 +50,6 @@ nmcs_provider_get_config_iface_data_is_valid(const NMCSProviderGetConfigIfaceDat
&& ((config_data->has_ipv4s && config_data->has_cidr) || config_data->iproutes_len);
}
NMCSProviderGetConfigIfaceData *nmcs_provider_get_config_iface_data_create(GHashTable *iface_datas,
gboolean was_requested,
const char *hwaddr);
/*****************************************************************************/
typedef struct {
@ -83,9 +84,11 @@ NM_AUTO_DEFINE_FCN0(NMCSProviderGetConfigResult *,
/*****************************************************************************/
typedef struct {
typedef struct _NMCSProviderGetConfigTaskData {
GTask *task;
struct _NMCSProvider *self;
GHashTable *result_dict;
/* this cancellable should be used for the provider implementation
@ -105,6 +108,15 @@ typedef struct {
bool any : 1;
} NMCSProviderGetConfigTaskData;
/*****************************************************************************/
NMCSProviderGetConfigIfaceData *
nmcs_provider_get_config_iface_data_create(NMCSProviderGetConfigTaskData *get_config_data,
gboolean was_requested,
const char *hwaddr);
/*****************************************************************************/
#define NMCS_TYPE_PROVIDER (nmcs_provider_get_type())
#define NMCS_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NMCS_TYPE_PROVIDER, NMCSProvider))
#define NMCS_PROVIDER_CLASS(klass) \
@ -118,7 +130,7 @@ typedef struct {
struct _NMCSProviderPrivate;
typedef struct {
typedef struct _NMCSProvider {
GObject parent;
struct _NMCSProviderPrivate *_priv;
} NMCSProvider;