platform: add nm_platform_refresh_all() API

Add a function that allows to re-request all objects of a certain type.
Usually, the cache is supposed to keep itself in a consistent state and
this function is not useful.

It is however useful during testing and debugging to explicitly reload
an object type.

If you ever think to need this function in non-testing code, then
something else is probably wrong with the cache implementation.
This commit is contained in:
Thomas Haller
2018-02-08 15:17:23 +01:00
parent 5c4f4b3540
commit 06b968a820
3 changed files with 26 additions and 0 deletions

View File

@@ -4829,6 +4829,12 @@ link_refresh (NMPlatform *platform, int ifindex)
return !!nm_platform_link_get_obj (platform, ifindex, TRUE);
}
static void
refresh_all (NMPlatform *platform, NMPObjectType obj_type)
{
do_request_one_type (platform, obj_type);
}
static gboolean
link_set_netns (NMPlatform *platform,
int ifindex,
@@ -7196,6 +7202,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->link_add = link_add;
platform_class->link_delete = link_delete;
platform_class->refresh_all = refresh_all;
platform_class->link_refresh = link_refresh;
platform_class->link_set_netns = link_set_netns;

View File

@@ -1117,6 +1117,21 @@ nm_platform_link_supports_slaves (NMPlatform *self, int ifindex)
return (nm_platform_link_get_type (self, ifindex) & 0x20000);
}
/**
* nm_platform_refresh_all:
* @self: platform instance
* @obj_type: The object type to request.
*
* Resync and re-request all objects from kernel of a certain @obj_type.
*/
void
nm_platform_refresh_all (NMPlatform *self, NMPObjectType obj_type)
{
_CHECK_SELF_VOID (self, klass);
klass->refresh_all (self, obj_type);
}
/**
* nm_platform_link_refresh:
* @self: platform instance

View File

@@ -719,6 +719,8 @@ typedef struct {
gboolean (*sysctl_set) (NMPlatform *, const char *pathid, int dirfd, const char *path, const char *value);
char * (*sysctl_get) (NMPlatform *, const char *pathid, int dirfd, const char *path);
void (*refresh_all) (NMPlatform *self, NMPObjectType obj_type);
gboolean (*link_add) (NMPlatform *,
const char *name,
NMLinkType type,
@@ -1033,6 +1035,8 @@ gboolean nm_platform_sysctl_set_ip6_hop_limit_safe (NMPlatform *self, const char
const char *nm_platform_if_indextoname (NMPlatform *self, int ifindex, char *out_ifname/* of size IFNAMSIZ */);
int nm_platform_if_nametoindex (NMPlatform *self, const char *ifname);
void nm_platform_refresh_all (NMPlatform *self, NMPObjectType obj_type);
const NMPObject *nm_platform_link_get_obj (NMPlatform *self,
int ifindex,
gboolean visible_only);