diff options
author | Thomas Haller <thaller@redhat.com> | 2022-04-29 08:29:59 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-05-05 08:37:29 +0200 |
commit | 061c05ca393e847c07707ea22fe892fb08cc48a4 (patch) | |
tree | 0095b22a7735f33b6dca2497bf026565a38f7954 /src/nm-cloud-setup | |
parent | 3a9ec3c5a3799eccb58d268100212fe6172f00dc (diff) | |
download | NetworkManager-061c05ca393e847c07707ea22fe892fb08cc48a4.tar.gz |
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.
(cherry picked from commit 069946cda14b2465d1eb5434402609fcd96f35ba)
Diffstat (limited to 'src/nm-cloud-setup')
-rw-r--r-- | src/nm-cloud-setup/nmcs-provider-aliyun.c | 4 | ||||
-rw-r--r-- | src/nm-cloud-setup/nmcs-provider-azure.c | 4 | ||||
-rw-r--r-- | src/nm-cloud-setup/nmcs-provider-ec2.c | 4 | ||||
-rw-r--r-- | src/nm-cloud-setup/nmcs-provider-gcp.c | 4 | ||||
-rw-r--r-- | src/nm-cloud-setup/nmcs-provider.c | 21 | ||||
-rw-r--r-- | src/nm-cloud-setup/nmcs-provider.h | 24 |
6 files changed, 35 insertions, 26 deletions
diff --git a/src/nm-cloud-setup/nmcs-provider-aliyun.c b/src/nm-cloud-setup/nmcs-provider-aliyun.c index 9aabca80b3..02fd7a01aa 100644 --- a/src/nm-cloud-setup/nmcs-provider-aliyun.c +++ b/src/nm-cloud-setup/nmcs-provider-aliyun.c @@ -352,9 +352,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us } 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); diff --git a/src/nm-cloud-setup/nmcs-provider-azure.c b/src/nm-cloud-setup/nmcs-provider-azure.c index 06f23ea73e..9b27af288a 100644 --- a/src/nm-cloud-setup/nmcs-provider-azure.c +++ b/src/nm-cloud-setup/nmcs-provider-azure.c @@ -387,9 +387,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", diff --git a/src/nm-cloud-setup/nmcs-provider-ec2.c b/src/nm-cloud-setup/nmcs-provider-ec2.c index ee4e2a95fa..8362dd7c79 100644 --- a/src/nm-cloud-setup/nmcs-provider-ec2.c +++ b/src/nm-cloud-setup/nmcs-provider-ec2.c @@ -244,9 +244,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); diff --git a/src/nm-cloud-setup/nmcs-provider-gcp.c b/src/nm-cloud-setup/nmcs-provider-gcp.c index 0df2bdd607..a325f31a17 100644 --- a/src/nm-cloud-setup/nmcs-provider-gcp.c +++ b/src/nm-cloud-setup/nmcs-provider-gcp.c @@ -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) { diff --git a/src/nm-cloud-setup/nmcs-provider.c b/src/nm-cloud-setup/nmcs-provider.c index f14a3d0272..a519ef9b5e 100644 --- a/src/nm-cloud-setup/nmcs-provider.c +++ b/src/nm-cloud-setup/nmcs-provider.c @@ -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; diff --git a/src/nm-cloud-setup/nmcs-provider.h b/src/nm-cloud-setup/nmcs-provider.h index 8ec240e5b9..d1ab0a33c2 100644 --- a/src/nm-cloud-setup/nmcs-provider.h +++ b/src/nm-cloud-setup/nmcs-provider.h @@ -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; @@ -57,10 +62,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 { @@ -95,9 +96,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 @@ -117,6 +120,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) \ @@ -130,7 +142,7 @@ typedef struct { struct _NMCSProviderPrivate; -typedef struct { +typedef struct _NMCSProvider { GObject parent; struct _NMCSProviderPrivate *_priv; } NMCSProvider; |