From bf407f6bc49dd64f437bf0aff35908349c3a9dc8 Mon Sep 17 00:00:00 2001 From: Motomu Utsumi Date: Thu, 24 Jul 2025 13:08:34 +0900 Subject: [PATCH] NetBpfLoad: Extract building map pin loc to a helper function Bug: 428792764 Flag: EXEMPT no-op Test: TH Change-Id: I4e66c7127f210a2264b370e079c1fb7b44958886 --- bpf/loader/NetBpfLoad.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index 19588c11a4..294df834b2 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -979,6 +979,16 @@ static enum bpf_map_type sanitizeMapType(enum bpf_map_type type) { return type; } +static string buildMapPinLoc(const domain pin_subdir, const char* prefix, + const struct bpf_map_def& mapDef, const string& objName, + const string& mapName) { + // Format of pin location is /sys/fs/bpf/map__ + // except that maps shared across .o's have empty + // Note: refers to the extension-less basename of the .o file (without @ suffix). + return string(BPF_FS_PATH) + lookupPinSubdir(pin_subdir, prefix) + "map_" + + (mapDef.shared ? "" : objName) + "_" + mapName; +} + static int createMaps(const char* elfPath, ifstream& elfFile, vector& mapFds, const char* prefix, const unsigned int bpfloader_ver) { int ret; @@ -1066,11 +1076,7 @@ static int createMaps(const char* elfPath, ifstream& elfFile, vector& abort(); } - // Format of pin location is /sys/fs/bpf/map__ - // except that maps shared across .o's have empty - // Note: refers to the extension-less basename of the .o file (without @ suffix). - string mapPinLoc = string(BPF_FS_PATH) + lookupPinSubdir(pin_subdir, prefix) + "map_" + - (md[i].shared ? "" : objName) + "_" + mapNames[i]; + string mapPinLoc = buildMapPinLoc(pin_subdir, prefix, md[i], objName, mapNames[i]); unique_fd fd; int saved_errno;