[DTrace-devel] [PATCH 12/16] Support safe removal of probes during dt_probe_iter()

Kris Van Hees kris.van.hees at oracle.com
Thu Mar 18 21:54:51 PDT 2021


It may be necessary to destroy probes that are found using the
dt_probe_iter() functionality.  This requires the traversal of probe
lists and hashtables to be safe in view of potential probe removal.

This patch also ensures that when a probe is destroyed, it is also
removed from the global probe array.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_probe.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/libdtrace/dt_probe.c b/libdtrace/dt_probe.c
index 597f8c07..c8732e9b 100644
--- a/libdtrace/dt_probe.c
+++ b/libdtrace/dt_probe.c
@@ -456,6 +456,8 @@ dt_probe_destroy(dt_probe_t *prp)
 		dtp = yypcb->pcb_hdl;
 
 	if (prp->desc) {
+		dtp->dt_probes[prp->desc->id] = NULL;
+
 		dt_htab_delete(dtp->dt_byprv, prp);
 		dt_htab_delete(dtp->dt_bymod, prp);
 		dt_htab_delete(dtp->dt_byfun, prp);
@@ -1159,12 +1161,15 @@ dt_probe_iter(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp,
 
 #define HTAB_GMATCH(c, nam)						\
 	if (!c##_is_glob) {						\
+		dt_probe_t	*nxt;					\
+									\
 		prp = dt_htab_lookup(dtp->dt_by##nam, &tmpl);		\
 		if (!prp)						\
 			goto done;					\
 									\
 		desc.nam = NULL;					\
 		do {							\
+			nxt = prp->he_##nam.next;			\
 			if (!dt_probe_gmatch(prp, &desc))		\
 				continue;				\
 									\
@@ -1177,7 +1182,7 @@ dt_probe_iter(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp,
 				return rv;				\
 									\
 			matches++;					\
-		} while ((prp = prp->he_##nam.next));			\
+		} while ((prp = nxt));					\
 									\
 		goto done;						\
 	}
@@ -1374,6 +1379,11 @@ dt_probe_fini(dtrace_hdl_t *dtp)
 	dt_htab_destroy(dtp, dtp->dt_byfun);
 	dt_htab_destroy(dtp, dtp->dt_byprb);
 	dt_htab_destroy(dtp, dtp->dt_byfqn);
+	dtp->dt_byprv = NULL;
+	dtp->dt_bymod = NULL;
+	dtp->dt_byfun = NULL;
+	dtp->dt_byprb = NULL;
+	dtp->dt_byfqn = NULL;
 
 	dt_free(dtp, dtp->dt_probes);
 	dtp->dt_probes = NULL;
-- 
2.28.0




More information about the DTrace-devel mailing list