Skip to content

Commit ec960f9

Browse files
committed
libsemanage: improve performance of semanage store rebuild
Commit 9d107ab ("libsemanage: Set new restorecon handle before doing restorecon ") added reopeniong selabel handle every time semanage_setfiles() is called. It means that during `semodule -B`, `selabel_close()` and `selabel_open()` could be called more than 1800x what could have a significant performance impact. It should be enough to reopen selabel handle just after semanage commit when changes are applied. Before 9d107ab: semodule -B 5.84s user 0.52s system 96% cpu 6.585 total After 9d107ab: semodule -B 11.15s user 0.64s system 98% cpu 11.952 total With this patch: semodule -B 5.51s user 0.41s system 98% cpu 6.014 total Signed-off-by: Petr Lautrbach <[email protected]> Acked-by: Jason Zaman <[email protected]>
1 parent 71aec30 commit ec960f9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

libsemanage/src/semanage_store.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,7 @@ static int semanage_commit_sandbox(semanage_handle_t * sh)
17121712
semanage_path(SEMANAGE_PREVIOUS, SEMANAGE_TOPLEVEL);
17131713
const char *sandbox = semanage_path(SEMANAGE_TMP, SEMANAGE_TOPLEVEL);
17141714
struct stat buf;
1715+
struct selabel_handle *sehandle;
17151716

17161717
/* update the commit number */
17171718
if ((commit_number = semanage_direct_get_serial(sh)) < 0) {
@@ -1822,6 +1823,8 @@ static int semanage_commit_sandbox(semanage_handle_t * sh)
18221823

18231824
cleanup:
18241825
semanage_release_active_lock(sh);
1826+
sehandle = selinux_restorecon_default_handle();
1827+
selinux_restorecon_set_sehandle(sehandle);
18251828
return retval;
18261829
}
18271830

@@ -3012,14 +3015,10 @@ log_callback_mute(__attribute__((unused)) int type, __attribute__((unused)) cons
30123015
void semanage_setfiles(semanage_handle_t * sh, const char *path){
30133016
struct stat sb;
30143017
int fd;
3015-
struct selabel_handle *sehandle;
30163018

30173019
union selinux_callback cb_orig = selinux_get_callback(SELINUX_CB_LOG);
30183020
union selinux_callback cb = { .func_log = log_callback_mute };
30193021

3020-
sehandle = selinux_restorecon_default_handle();
3021-
selinux_restorecon_set_sehandle(sehandle);
3022-
30233022
/* Mute all logs */
30243023
selinux_set_callback(SELINUX_CB_LOG, cb);
30253024

0 commit comments

Comments
 (0)