bpf: switch map 'pin_subdir' to 'pin_prefix'

which simplifies NetBpfLoad logic

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3600cf45ae14a20801b5beca0aa9e79bb3052c57
This commit is contained in:
Maciej Żenczykowski 2025-07-30 17:26:15 -07:00
commit 667dfa97e6
3 changed files with 5 additions and 16 deletions

View file

@ -880,13 +880,6 @@ static enum bpf_map_type sanitizeMapType(enum bpf_map_type type) {
return type;
}
static string buildMapPinLoc(const char pin_subdir[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE],
const string& objName, const string& mapName) {
// Format of pin location is /sys/fs/bpf/<pin_subdir>map_<objName>_<mapName>
// Note: <objName> refers to the extension-less basename of the .o file (without @ suffix).
return string(BPF_FS_PATH) + pin_subdir + "map_" + objName + "_" + mapName;
}
static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>& mapFds,
const unsigned int bpfloader_ver) {
int ret;
@ -967,7 +960,7 @@ static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>&
if (max_entries < page_size) max_entries = page_size;
}
string mapPinLoc = buildMapPinLoc(md[i].pin_subdir, objName, mapNames[i]);
string mapPinLoc = string(md[i].pin_prefix) + mapNames[i];
unique_fd fd;
int saved_errno;
@ -1368,7 +1361,7 @@ static int pinMaps(const char* const elfPath, const struct bpf_object* obj,
// This map was skipped
if (!bpf_map__autocreate(m)) continue;
string mapPinLoc = buildMapPinLoc(md[i].pin_subdir, objName, mapNames[i]);
string mapPinLoc = string(md[i].pin_prefix) + mapNames[i];
if (access(mapPinLoc.c_str(), F_OK) == 0) {
ALOGE("Reusing map is not supported: %s", mapNames[i].c_str());
return -1;

View file

@ -260,7 +260,7 @@ static int (*bpf_sk_storage_delete_unsafe) (const void* sk_storage,
.min_kver = (minkver).kver, \
.max_kver = (maxkver).kver, \
.create_location = CREATE_LOCATION(selinux), \
.pin_subdir = pindir "/", \
.pin_prefix = "/sys/fs/bpf/" pindir "/map_" BPF_OBJ_NAME "_", \
};
#define __uint(name, val) int (*name)[val]

View file

@ -141,13 +141,9 @@ struct bpf_map_def {
unsigned int min_kver;
unsigned int max_kver;
// These are fixed length strings, padded with null bytes
//
// overrides default selinux context (which is based on pin subdir)
// These are fixed length ASCIIZ strings, padded with null bytes
char create_location[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE];
//
// overrides default prefix (which is based on .o location)
char pin_subdir[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE];
char pin_prefix[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE];
};
// This needs to be updated whenever the above structure definition is expanded.