Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpftool: Migrate off of deprecated bpf_create_map_xattr() API

Switch to bpf_map_create() API instead.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211201232824.3166325-4-andrii@kernel.org

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
a15d408b dbdd2c7f

+13 -10
+13 -10
tools/bpf/bpftool/map.c
··· 1261 1261 1262 1262 static int do_create(int argc, char **argv) 1263 1263 { 1264 - struct bpf_create_map_attr attr = { NULL, }; 1264 + LIBBPF_OPTS(bpf_map_create_opts, attr); 1265 + enum bpf_map_type map_type = BPF_MAP_TYPE_UNSPEC; 1266 + __u32 key_size = 0, value_size = 0, max_entries = 0; 1267 + const char *map_name = NULL; 1265 1268 const char *pinfile; 1266 1269 int err = -1, fd; 1267 1270 ··· 1279 1276 if (is_prefix(*argv, "type")) { 1280 1277 NEXT_ARG(); 1281 1278 1282 - if (attr.map_type) { 1279 + if (map_type) { 1283 1280 p_err("map type already specified"); 1284 1281 goto exit; 1285 1282 } 1286 1283 1287 - attr.map_type = map_type_from_str(*argv); 1288 - if ((int)attr.map_type < 0) { 1284 + map_type = map_type_from_str(*argv); 1285 + if ((int)map_type < 0) { 1289 1286 p_err("unrecognized map type: %s", *argv); 1290 1287 goto exit; 1291 1288 } 1292 1289 NEXT_ARG(); 1293 1290 } else if (is_prefix(*argv, "name")) { 1294 1291 NEXT_ARG(); 1295 - attr.name = GET_ARG(); 1292 + map_name = GET_ARG(); 1296 1293 } else if (is_prefix(*argv, "key")) { 1297 - if (parse_u32_arg(&argc, &argv, &attr.key_size, 1294 + if (parse_u32_arg(&argc, &argv, &key_size, 1298 1295 "key size")) 1299 1296 goto exit; 1300 1297 } else if (is_prefix(*argv, "value")) { 1301 - if (parse_u32_arg(&argc, &argv, &attr.value_size, 1298 + if (parse_u32_arg(&argc, &argv, &value_size, 1302 1299 "value size")) 1303 1300 goto exit; 1304 1301 } else if (is_prefix(*argv, "entries")) { 1305 - if (parse_u32_arg(&argc, &argv, &attr.max_entries, 1302 + if (parse_u32_arg(&argc, &argv, &max_entries, 1306 1303 "max entries")) 1307 1304 goto exit; 1308 1305 } else if (is_prefix(*argv, "flags")) { ··· 1343 1340 } 1344 1341 } 1345 1342 1346 - if (!attr.name) { 1343 + if (!map_name) { 1347 1344 p_err("map name not specified"); 1348 1345 goto exit; 1349 1346 } 1350 1347 1351 1348 set_max_rlimit(); 1352 1349 1353 - fd = bpf_create_map_xattr(&attr); 1350 + fd = bpf_map_create(map_type, map_name, key_size, value_size, max_entries, &attr); 1354 1351 if (fd < 0) { 1355 1352 p_err("map create failed: %s", strerror(errno)); 1356 1353 goto exit;