Skip to contentSkip to conversation

libdtrace: cache missing kernel CTF archives until paths change

PATCH In review Kris Van Hees 2 participants 3 messages Oct 30 – Nov 6

lore
Share & tools
lore
#0 lore raw

PATCH 11/20 libdtrace: cache missing kernel CTF archives until paths change

---
 libdtrace/dt_impl.h        |  1 +
 libdtrace/dt_module.c      | 16 +++++++++++--
 libdtrace/dt_options.c     |  3 +++
 test/triggers/Build        |  1 +
 test/triggers/shared-ctf.c | 49 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 68 insertions(+), 2 deletions(-)
libdtrace/dt_impl.h +1 -0
index 972fceaf..5487bfcf 100644
@@ -310,6 +310,7 @@ struct dtrace_hdl {
 	dt_list_t dt_modlist;	/* linked list of dt_module_t's */
 	dt_htab_t *dt_mods;	/* hash table of dt_module_t's */
 	dt_htab_t *dt_kernsyms; /* htab of kernel symbol names */
+	int dt_ctfa_missing;	/* cached ENOENT/ENOTDIR for the archive */
 	char *dt_ctfa_path;	/* path to vmlinux.ctfa */
 	ctf_archive_t *dt_ctfa; /* ctf archive for the entire kernel tree */
 	void *dt_ctfa_data;	/* backing data for dt_ctfa */
libdtrace/dt_module.c +14 -2
index ad43e815..f381bdcd 100644
@@ -1329,16 +1329,28 @@ dt_kern_module_find_ctf(dtrace_hdl_t *dtp, dt_module_t *dmp)
 		if (dtp->dt_ctfa_path == NULL) {
 			ctfa_name = malloc(strlen(dtp->dt_module_path) +
 			    strlen("/kernel/vmlinux.ctfa") + 1);
+			if (ctfa_name == NULL) {
+				dt_set_errno(dtp, EDT_NOMEM);
+				return;
+			}
 			to = stpcpy(ctfa_name, dtp->dt_module_path);
 			stpcpy(to, "/kernel/vmlinux.ctfa");
 		} else
 			ctfa_name = dtp->dt_ctfa_path;
 
+		/* Cache absence, but retry allocation, permission, and I/O errors. */
+		if (dtp->dt_ctfa_missing)
+			dtp->dt_ctferr = dtp->dt_ctfa_missing;
+		else {
 #ifdef HAVE_LIBCTF
-		dtp->dt_ctfa = dt_ctfa_open(dtp, ctfa_name);
+			dtp->dt_ctfa = dt_ctfa_open(dtp, ctfa_name);
 #else
-		dtp->dt_ctfa = ctf_arc_open(ctfa_name, &dtp->dt_ctferr);
+			dtp->dt_ctfa = ctf_arc_open(ctfa_name, &dtp->dt_ctferr);
 #endif
+			if (dtp->dt_ctfa == NULL &&
+			    (dtp->dt_ctferr == ENOENT || dtp->dt_ctferr == ENOTDIR))
+				dtp->dt_ctfa_missing = dtp->dt_ctferr;
+		}
 		if (dtp->dt_ctfa != NULL) {
 			/*
 			 * Load in the shared CTF immediately.
libdtrace/dt_options.c +3 -0
index 78ff23e5..2b75d3c0 100644
@@ -320,6 +320,7 @@ dt_opt_btf_path(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
 
 	free(dtp->dt_btf_path);
 	dtp->dt_btf_path = btf;
+	dtp->dt_ctfa_missing = 0;
 
 	return 0;
 }
@@ -340,6 +341,7 @@ dt_opt_ctfa_path(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
 
 	free(dtp->dt_ctfa_path);
 	dtp->dt_ctfa_path = ctfa;
+	dtp->dt_ctfa_missing = 0;
 
 	return 0;
 }
@@ -425,6 +427,7 @@ dt_opt_module_path(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
 
 	free(dtp->dt_module_path);
 	dtp->dt_module_path = proc;
+	dtp->dt_ctfa_missing = 0;
 
 	return 0;
 }
test/triggers/Build +1 -0
index 607ea00b..8d648bab 100644
@@ -267,6 +267,7 @@ module-discovery_LIBS := $(objdir)/build-libdtrace.a $(objdir)/build-libproc.a \
     $(objdir)/build-libcommon.a $(objdir)/build-libport.a $(libdtrace_LIBS)
 
 # Exercise shared dictionary ownership using libdtrace's private module APIs.
+shared-ctf_LDFLAGS := -Wl,--wrap=open64
 shared-ctf_CFLAGS := -Ilibproc -Ilibdtrace -Ilibcommon -Wno-pedantic
 shared-ctf_DEPS := build-libdtrace.a build-libproc.a libcommon.a libport.a
 shared-ctf_LIBS := $(objdir)/build-libdtrace.a $(objdir)/build-libproc.a \
test/triggers/shared-ctf.c +49 -0

68 lines not on this page · raw message

Signature · 1 line
2.52.0
#1 lore raw
Quoted 7 lines · Kris Van Hees
---
 libdtrace/dt_impl.h        |  1 +
 libdtrace/dt_module.c      | 16 +++++++++++--
 libdtrace/dt_options.c     |  3 +++
 test/triggers/Build        |  1 +
 test/triggers/shared-ctf.c | 49 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 68 insertions(+), 2 deletions(-)

... why on earth would they ever be missing? Surely fixing that instead is a good idea? (Or is this something to do with chroots and containers and the CTFA being in a filesystem path whose meaning will change in the middle of execution or something?)

Signature · 1 line
NULL && (void)
#2 lore raw
Quoted 10 lines · Nick Alcock
Quoted 7 lines · Kris Van Hees
---
 libdtrace/dt_impl.h        |  1 +
 libdtrace/dt_module.c      | 16 +++++++++++--
 libdtrace/dt_options.c     |  3 +++
 test/triggers/Build        |  1 +
 test/triggers/shared-ctf.c | 49 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 68 insertions(+), 2 deletions(-)
Quoted 4 lines

... why on earth would they ever be missing? Surely fixing that instead is a good idea? (Or is this something to do with chroots and containers and the CTFA being in a filesystem path whose meaning will change in the middle of execution or something?)

This was prompted by tests for the ctfpath option.