mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 22:50:08 +01:00
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 069946cda1)
This commit is contained in:
parent
3a9ec3c5a3
commit
061c05ca39
6 changed files with 35 additions and 26 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue