[PATCH 4/4] perf tools: Honor namespace when synthesizing build-id

From: Namhyung Kim
Date: Fri Sep 16 2022 - 13:59:53 EST


It needs to go into a namespace before reading a file.

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/synthetic-events.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
index e6978b2dee8f..d0d540d09196 100644
--- a/tools/perf/util/synthetic-events.c
+++ b/tools/perf/util/synthetic-events.c
@@ -391,6 +391,8 @@ static void perf_record_mmap2__read_build_id(struct perf_record_mmap2 *event,
struct build_id _bid, *bid = &_bid;
struct dso *dso = NULL;
struct dso_id id;
+ struct nsinfo *nsi;
+ struct nscookie nc;
int rc;

if (is_kernel) {
@@ -410,8 +412,14 @@ static void perf_record_mmap2__read_build_id(struct perf_record_mmap2 *event,
goto out;
}

+ nsi = nsinfo__new(event->pid);
+ nsinfo__mountns_enter(nsi, &nc);
+
rc = filename__read_build_id(event->filename, bid) > 0 ? 0 : -1;

+ nsinfo__mountns_exit(&nc);
+ nsinfo__put(nsi);
+
out:
if (rc == 0) {
memcpy(event->build_id, bid->data, sizeof(bid->data));
--
2.37.3.968.ga6b4b080e4-goog