xref: /linux/tools/perf/trace/beauty/sync_file_range.c (revision 36ec807b627b4c0a0a382f0ae48eac7187d14b2b)
1 // SPDX-License-Identifier: LGPL-2.1
2 /*
3  * trace/beauty/sync_file_range.c
4  *
5  *  Copyright (C) 2019, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
6  */
7 
8 #include "trace/beauty/beauty.h"
9 #include <linux/log2.h>
10 #include <linux/fs.h>
11 
12 #ifndef SYNC_FILE_RANGE_WRITE_AND_WAIT
13 #define SYNC_FILE_RANGE_WAIT_BEFORE     1
14 #define SYNC_FILE_RANGE_WRITE           2
15 #define SYNC_FILE_RANGE_WAIT_AFTER      4
16 #define SYNC_FILE_RANGE_WRITE_AND_WAIT  (SYNC_FILE_RANGE_WRITE | \
17                                          SYNC_FILE_RANGE_WAIT_BEFORE | \
18                                          SYNC_FILE_RANGE_WAIT_AFTER)
19 #endif
20 
21 static size_t sync_file_range__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix)
22 {
23 #include "trace/beauty/generated/sync_file_range_arrays.c"
24        static DEFINE_STRARRAY(sync_file_range_flags, "SYNC_FILE_RANGE_");
25        size_t printed = 0;
26 
27        if ((flags & SYNC_FILE_RANGE_WRITE_AND_WAIT) == SYNC_FILE_RANGE_WRITE_AND_WAIT) {
28                printed += scnprintf(bf + printed, size - printed, "%s%s", show_prefix ? "SYNC_FILE_RANGE_" : "", "WRITE_AND_WAIT");
29 	       flags &= ~SYNC_FILE_RANGE_WRITE_AND_WAIT;
30        }
31 
32        return printed + strarray__scnprintf_flags(&strarray__sync_file_range_flags, bf + printed, size - printed, show_prefix, flags);
33 }
34 
35 size_t syscall_arg__scnprintf_sync_file_range_flags(char *bf, size_t size, struct syscall_arg *arg)
36 {
37 	unsigned long flags = arg->val;
38 
39 	return sync_file_range__scnprintf_flags(flags, bf, size, arg->show_string_prefix);
40 }
41