From patchwork Thu Jan 27 23:58:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12727565 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7520C433EF for ; Thu, 27 Jan 2022 23:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344018AbiA0X6d (ORCPT ); Thu, 27 Jan 2022 18:58:33 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:10550 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240891AbiA0X6c (ORCPT ); Thu, 27 Jan 2022 18:58:32 -0500 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20RNalg0027480 for ; Thu, 27 Jan 2022 15:58:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=xHh8N/PPB/iULui+5aVxLZ40s/lOuk/q/vP+616KAEE=; b=OTxROSqygFhCKCboJqLPnGsSixV0WX8W7rg/vu1EpGnsXpK26iy6oAkAWdo47hqafxNn L+84QSX0mybEWTt1Zekonu1ryHgiPQl6D6gOnSpCbLK7JiRLUO6fEgvgRvU+0zK+P+ct yy9jfcG/7TWaMiran+2VQJX5hwq5Y81S46A= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3duv8gby88-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 27 Jan 2022 15:58:31 -0800 Received: from twshared18912.14.frc2.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 27 Jan 2022 15:58:29 -0800 Received: by devvm3278.frc0.facebook.com (Postfix, from userid 8598) id 9BFB31C1148A6; Thu, 27 Jan 2022 15:58:25 -0800 (PST) From: Delyan Kratunov To: , , , CC: Delyan Kratunov Subject: [PATCH bpf-next 2/3] bpftool: migrate from bpf_prog_test_run_xattr Date: Thu, 27 Jan 2022 15:58:04 -0800 Message-ID: <20220127235805.1608540-3-delyank@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220127235805.1608540-1-delyank@fb.com> References: <20220127235805.1608540-1-delyank@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: G5Btv3T9OlkDH2wz1a-VtSjTwY4s_UCU X-Proofpoint-ORIG-GUID: G5Btv3T9OlkDH2wz1a-VtSjTwY4s_UCU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-27_06,2022-01-27_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 mlxlogscore=830 mlxscore=0 clxscore=1015 malwarescore=0 priorityscore=1501 bulkscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2201270133 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net bpf_prog_test_run_xattr is being deprecated in favor of bpf_prog_test_run_opts. Signed-off-by: Delyan Kratunov --- tools/bpf/bpftool/prog.c | 55 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 87593f98d2d1..4f96c229ba77 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -1272,12 +1272,12 @@ static int do_run(int argc, char **argv) { char *data_fname_in = NULL, *data_fname_out = NULL; char *ctx_fname_in = NULL, *ctx_fname_out = NULL; - struct bpf_prog_test_run_attr test_attr = {0}; const unsigned int default_size = SZ_32K; void *data_in = NULL, *data_out = NULL; void *ctx_in = NULL, *ctx_out = NULL; unsigned int repeat = 1; int fd, err; + LIBBPF_OPTS(bpf_test_run_opts, topts); if (!REQ_ARGS(4)) return -1; @@ -1315,7 +1315,7 @@ static int do_run(int argc, char **argv) if (!REQ_ARGS(1)) return -1; - test_attr.data_size_out = strtoul(*argv, &endptr, 0); + topts.data_size_out = strtoul(*argv, &endptr, 0); if (*endptr) { p_err("can't parse %s as output data size", *argv); @@ -1343,7 +1343,7 @@ static int do_run(int argc, char **argv) if (!REQ_ARGS(1)) return -1; - test_attr.ctx_size_out = strtoul(*argv, &endptr, 0); + topts.ctx_size_out = strtoul(*argv, &endptr, 0); if (*endptr) { p_err("can't parse %s as output context size", *argv); @@ -1371,38 +1371,37 @@ static int do_run(int argc, char **argv) } } - err = get_run_data(data_fname_in, &data_in, &test_attr.data_size_in); + err = get_run_data(data_fname_in, &data_in, &topts.data_size_in); if (err) return -1; if (data_in) { - if (!test_attr.data_size_out) - test_attr.data_size_out = default_size; - err = alloc_run_data(&data_out, test_attr.data_size_out); + if (!topts.data_size_out) + topts.data_size_out = default_size; + err = alloc_run_data(&data_out, topts.data_size_out); if (err) goto free_data_in; } - err = get_run_data(ctx_fname_in, &ctx_in, &test_attr.ctx_size_in); + err = get_run_data(ctx_fname_in, &ctx_in, &topts.ctx_size_in); if (err) goto free_data_out; if (ctx_in) { - if (!test_attr.ctx_size_out) - test_attr.ctx_size_out = default_size; - err = alloc_run_data(&ctx_out, test_attr.ctx_size_out); + if (!topts.ctx_size_out) + topts.ctx_size_out = default_size; + err = alloc_run_data(&ctx_out, topts.ctx_size_out); if (err) goto free_ctx_in; } - test_attr.prog_fd = fd; - test_attr.repeat = repeat; - test_attr.data_in = data_in; - test_attr.data_out = data_out; - test_attr.ctx_in = ctx_in; - test_attr.ctx_out = ctx_out; + topts.repeat = repeat; + topts.data_in = data_in; + topts.data_out = data_out; + topts.ctx_in = ctx_in; + topts.ctx_out = ctx_out; - err = bpf_prog_test_run_xattr(&test_attr); + err = bpf_prog_test_run_opts(fd, &topts); if (err) { p_err("failed to run program: %s", strerror(errno)); goto free_ctx_out; @@ -1416,23 +1415,23 @@ static int do_run(int argc, char **argv) /* Do not exit on errors occurring when printing output data/context, * we still want to print return value and duration for program run. */ - if (test_attr.data_size_out) - err += print_run_output(test_attr.data_out, - test_attr.data_size_out, + if (topts.data_size_out) + err += print_run_output(topts.data_out, + topts.data_size_out, data_fname_out, "data_out"); - if (test_attr.ctx_size_out) - err += print_run_output(test_attr.ctx_out, - test_attr.ctx_size_out, + if (topts.ctx_size_out) + err += print_run_output(topts.ctx_out, + topts.ctx_size_out, ctx_fname_out, "ctx_out"); if (json_output) { - jsonw_uint_field(json_wtr, "retval", test_attr.retval); - jsonw_uint_field(json_wtr, "duration", test_attr.duration); + jsonw_uint_field(json_wtr, "retval", topts.retval); + jsonw_uint_field(json_wtr, "duration", topts.duration); jsonw_end_object(json_wtr); /* root */ } else { fprintf(stdout, "Return value: %u, duration%s: %uns\n", - test_attr.retval, - repeat > 1 ? " (average)" : "", test_attr.duration); + topts.retval, + repeat > 1 ? " (average)" : "", topts.duration); } free_ctx_out: