diff mbox series

[bpf-next,v2,3/4] bpftool: migrate from bpf_prog_test_run_xattr

Message ID 20220128012319.2494472-4-delyank@fb.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series migrate from bpf_prog_test_run{,_xattr} | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 8 maintainers not CCed: quentin@isovalent.com kpsingh@kernel.org john.fastabend@gmail.com kafai@fb.com songliubraving@fb.com davemarchevsky@fb.com yhs@fb.com netdev@vger.kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 114 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next success VM_Test

Commit Message

Delyan Kratunov Jan. 28, 2022, 1:23 a.m. UTC
bpf_prog_test_run_xattr is being deprecated in favor of bpf_prog_test_run_opts.

Signed-off-by: Delyan Kratunov <delyank@fb.com>
---
 tools/bpf/bpftool/prog.c | 55 ++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

Comments

Andrii Nakryiko Feb. 1, 2022, 1:33 a.m. UTC | #1
On Thu, Jan 27, 2022 at 5:23 PM Delyan Kratunov <delyank@fb.com> wrote:
>
> bpf_prog_test_run_xattr is being deprecated in favor of bpf_prog_test_run_opts.
>
> Signed-off-by: Delyan Kratunov <delyank@fb.com>
> ---
>  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);

let's name it "test_attr" and avoid most of the code churn?

Otherwise it looks good, thanks!

>
>         if (!REQ_ARGS(4))
>                 return -1;

[...]
diff mbox series

Patch

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: