From 313fe66fbd0cd3d62566edece7944d6cf45b1b21 Mon Sep 17 00:00:00 2001 From: kayrus Date: Fri, 29 Apr 2016 15:59:51 +0200 Subject: core: Filter by unit name behind the D-Bus, instead on the client side (#3142) This commit improves systemd performance on the systems which have thousands of units. --- src/shared/install.c | 11 ++++++++++- src/shared/install.h | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/shared') diff --git a/src/shared/install.c b/src/shared/install.c index b74ff6de22..931d3e2907 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -2653,7 +2653,9 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(UnitFileList*, unit_file_list_free_one); int unit_file_get_list( UnitFileScope scope, const char *root_dir, - Hashmap *h) { + Hashmap *h, + char **states, + char **patterns) { _cleanup_lookup_paths_free_ LookupPaths paths = {}; char **i; @@ -2685,6 +2687,9 @@ int unit_file_get_list( if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY)) continue; + if (!strv_fnmatch_or_empty(patterns, de->d_name, FNM_NOESCAPE)) + continue; + if (hashmap_get(h, de->d_name)) continue; @@ -2705,6 +2710,10 @@ int unit_file_get_list( if (r < 0) f->state = UNIT_FILE_BAD; + if (!strv_isempty(states) && + !strv_contains(states, unit_file_state_to_string(f->state))) + continue; + r = hashmap_put(h, basename(f->path), f); if (r < 0) return r; diff --git a/src/shared/install.h b/src/shared/install.h index 4133faffa2..4ffc5a21f2 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -232,7 +232,7 @@ int unit_file_add_dependency( int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret); int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name); -int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h); +int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns); Hashmap* unit_file_list_free(Hashmap *h); int unit_file_changes_add(UnitFileChange **changes, unsigned *n_changes, UnitFileChangeType type, const char *path, const char *source); -- cgit v1.2.3-54-g00ecf