mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 04:58:01 +02: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. Conflicts: missing nmcs-provider-aliyun (cherry picked from commit069946cda1) (cherry picked from commit061c05ca39) (cherry picked from commit1cf4fd0235) (cherry picked from commitbe1dce951e) (cherry picked from commit646bc7a10e)
This commit is contained in:
parent
c5530797c2
commit
bf2a3ff277
5 changed files with 34 additions and 23 deletions
|
|
@ -395,9 +395,7 @@ _get_config_iface_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||||
goto out_done;
|
goto out_done;
|
||||||
}
|
}
|
||||||
iface_data->iface_get_config =
|
iface_data->iface_get_config =
|
||||||
nmcs_provider_get_config_iface_data_create(get_config_data->result_dict,
|
nmcs_provider_get_config_iface_data_create(get_config_data, FALSE, v_hwaddr);
|
||||||
FALSE,
|
|
||||||
v_hwaddr);
|
|
||||||
} else {
|
} else {
|
||||||
if (iface_data->iface_get_config->iface_idx >= 0) {
|
if (iface_data->iface_get_config->iface_idx >= 0) {
|
||||||
_LOGI("interface[%" G_GSSIZE_FORMAT "]: duplicate MAC address %s returned",
|
_LOGI("interface[%" G_GSSIZE_FORMAT "]: duplicate MAC address %s returned",
|
||||||
|
|
|
||||||
|
|
@ -258,9 +258,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
config_iface_data =
|
config_iface_data =
|
||||||
nmcs_provider_get_config_iface_data_create(get_config_data->result_dict,
|
nmcs_provider_get_config_iface_data_create(get_config_data, FALSE, v_hwaddr);
|
||||||
FALSE,
|
|
||||||
v_hwaddr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nm_assert(config_iface_data->iface_idx == -1);
|
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;
|
goto out_done;
|
||||||
}
|
}
|
||||||
iface_data->iface_get_config =
|
iface_data->iface_get_config =
|
||||||
nmcs_provider_get_config_iface_data_create(get_config_data->result_dict,
|
nmcs_provider_get_config_iface_data_create(get_config_data, FALSE, v_hwaddr);
|
||||||
FALSE,
|
|
||||||
v_hwaddr);
|
|
||||||
is_requested = FALSE;
|
is_requested = FALSE;
|
||||||
} else {
|
} else {
|
||||||
if (iface_data->iface_get_config->iface_idx >= 0) {
|
if (iface_data->iface_get_config->iface_idx >= 0) {
|
||||||
|
|
|
||||||
|
|
@ -174,24 +174,27 @@ nmcs_provider_detect_finish(NMCSProvider *self, GAsyncResult *result, GError **e
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
NMCSProviderGetConfigIfaceData *
|
NMCSProviderGetConfigIfaceData *
|
||||||
nmcs_provider_get_config_iface_data_create(GHashTable *iface_datas,
|
nmcs_provider_get_config_iface_data_create(NMCSProviderGetConfigTaskData *get_config_data,
|
||||||
gboolean was_requested,
|
gboolean was_requested,
|
||||||
const char *hwaddr)
|
const char *hwaddr)
|
||||||
{
|
{
|
||||||
NMCSProviderGetConfigIfaceData *iface_data;
|
NMCSProviderGetConfigIfaceData *iface_data;
|
||||||
|
|
||||||
nm_assert(hwaddr);
|
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 = g_slice_new(NMCSProviderGetConfigIfaceData);
|
||||||
*iface_data = (NMCSProviderGetConfigIfaceData){
|
*iface_data = (NMCSProviderGetConfigIfaceData){
|
||||||
.hwaddr = g_strdup(hwaddr),
|
.get_config_data = get_config_data,
|
||||||
.iface_idx = -1,
|
.hwaddr = g_strdup(hwaddr),
|
||||||
.was_requested = was_requested,
|
.iface_idx = -1,
|
||||||
|
.was_requested = was_requested,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* the has does not own the key (iface_datta->hwaddr), the lifetime of the
|
/* the has does not own the key (iface_datta->hwaddr), the lifetime of the
|
||||||
* key is associated with the iface_data instance. */
|
* 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;
|
return iface_data;
|
||||||
}
|
}
|
||||||
|
|
@ -280,6 +283,8 @@ nmcs_provider_get_config(NMCSProvider * self,
|
||||||
|
|
||||||
get_config_data = g_slice_new(NMCSProviderGetConfigTaskData);
|
get_config_data = g_slice_new(NMCSProviderGetConfigTaskData);
|
||||||
*get_config_data = (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),
|
.task = nm_g_task_new(self, cancellable, nmcs_provider_get_config, callback, user_data),
|
||||||
.any = any,
|
.any = any,
|
||||||
.result_dict = g_hash_table_new_full(nm_str_hash, g_str_equal, NULL, _iface_data_free),
|
.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);
|
nmcs_wait_for_objects_register(get_config_data->task);
|
||||||
|
|
||||||
for (; hwaddrs && hwaddrs[0]; hwaddrs++)
|
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) {
|
if (cancellable) {
|
||||||
gulong cancelled_id;
|
gulong cancelled_id;
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,16 @@
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
struct _NMCSProvider;
|
||||||
|
struct _NMCSProviderGetConfigTaskData;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* And it's exactly the same pointer that is also the key for the iface_datas
|
/* And it's exactly the same pointer that is also the key for the iface_datas
|
||||||
* dictionary. */
|
* dictionary. */
|
||||||
const char *hwaddr;
|
const char *hwaddr;
|
||||||
|
|
||||||
|
struct _NMCSProviderGetConfigTaskData *get_config_data;
|
||||||
|
|
||||||
in_addr_t *ipv4s_arr;
|
in_addr_t *ipv4s_arr;
|
||||||
gsize ipv4s_len;
|
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);
|
&& ((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 {
|
typedef struct {
|
||||||
|
|
@ -83,9 +84,11 @@ NM_AUTO_DEFINE_FCN0(NMCSProviderGetConfigResult *,
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
typedef struct {
|
typedef struct _NMCSProviderGetConfigTaskData {
|
||||||
GTask *task;
|
GTask *task;
|
||||||
|
|
||||||
|
struct _NMCSProvider *self;
|
||||||
|
|
||||||
GHashTable *result_dict;
|
GHashTable *result_dict;
|
||||||
|
|
||||||
/* this cancellable should be used for the provider implementation
|
/* this cancellable should be used for the provider implementation
|
||||||
|
|
@ -105,6 +108,15 @@ typedef struct {
|
||||||
bool any : 1;
|
bool any : 1;
|
||||||
} NMCSProviderGetConfigTaskData;
|
} 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_TYPE_PROVIDER (nmcs_provider_get_type())
|
||||||
#define NMCS_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NMCS_TYPE_PROVIDER, NMCSProvider))
|
#define NMCS_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NMCS_TYPE_PROVIDER, NMCSProvider))
|
||||||
#define NMCS_PROVIDER_CLASS(klass) \
|
#define NMCS_PROVIDER_CLASS(klass) \
|
||||||
|
|
@ -118,7 +130,7 @@ typedef struct {
|
||||||
|
|
||||||
struct _NMCSProviderPrivate;
|
struct _NMCSProviderPrivate;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct _NMCSProvider {
|
||||||
GObject parent;
|
GObject parent;
|
||||||
struct _NMCSProviderPrivate *_priv;
|
struct _NMCSProviderPrivate *_priv;
|
||||||
} NMCSProvider;
|
} NMCSProvider;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue