]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
95b1e505 DW |
2 | /* |
3 | * Copyright (C) 2018 Oracle. All Rights Reserved. | |
95b1e505 | 4 | * Author: Darrick J. Wong <darrick.wong@oracle.com> |
95b1e505 DW |
5 | */ |
6 | #ifndef XFS_SCRUB_COMMON_H_ | |
7 | #define XFS_SCRUB_COMMON_H_ | |
8 | ||
f0585fce DW |
9 | /* |
10 | * When reporting a defective metadata object to the console, this | |
11 | * is the size of the buffer to use to store the description of that | |
12 | * item. | |
13 | */ | |
14 | #define DESCR_BUFSZ 256 | |
15 | ||
16 | bool xfs_scrub_excessive_errors(struct scrub_ctx *ctx); | |
17 | ||
18 | enum error_level { | |
19 | S_ERROR = 0, | |
abc2e70d | 20 | S_CORRUPT, |
f0585fce DW |
21 | S_WARN, |
22 | S_INFO, | |
ca427fe8 | 23 | S_REPAIR, |
19852474 | 24 | S_PREEN, |
f0585fce DW |
25 | }; |
26 | ||
27 | void __str_out(struct scrub_ctx *ctx, const char *descr, enum error_level level, | |
28 | int error, const char *file, int line, const char *format, ...); | |
29 | ||
30 | #define str_errno(ctx, str) \ | |
31 | __str_out(ctx, str, S_ERROR, errno, __FILE__, __LINE__, NULL) | |
9612817d DW |
32 | #define str_liberror(ctx, error, str) \ |
33 | __str_out(ctx, str, S_ERROR, error, __FILE__, __LINE__, NULL) | |
abc2e70d DW |
34 | #define str_corrupt(ctx, str, ...) \ |
35 | __str_out(ctx, str, S_CORRUPT, 0, __FILE__, __LINE__, __VA_ARGS__) | |
f0585fce DW |
36 | #define str_error(ctx, str, ...) \ |
37 | __str_out(ctx, str, S_ERROR, 0, __FILE__, __LINE__, __VA_ARGS__) | |
38 | #define str_warn(ctx, str, ...) \ | |
39 | __str_out(ctx, str, S_WARN, 0, __FILE__, __LINE__, __VA_ARGS__) | |
40 | #define str_info(ctx, str, ...) \ | |
41 | __str_out(ctx, str, S_INFO, 0, __FILE__, __LINE__, __VA_ARGS__) | |
19852474 DW |
42 | #define record_repair(ctx, str, ...) \ |
43 | __str_out(ctx, str, S_REPAIR, 0, __FILE__, __LINE__, __VA_ARGS__) | |
44 | #define record_preen(ctx, str, ...) \ | |
45 | __str_out(ctx, str, S_PREEN, 0, __FILE__, __LINE__, __VA_ARGS__) | |
f0585fce DW |
46 | |
47 | #define dbg_printf(fmt, ...) \ | |
48 | do {if (debug > 1) {printf(fmt, __VA_ARGS__);}} while (0) | |
49 | ||
7c309151 DW |
50 | void __str_log(struct scrub_ctx *ctx, enum error_level level, |
51 | const char *format, ...); | |
52 | ||
53 | #define log_info(ctx, ...) \ | |
54 | __str_log(ctx, S_INFO, __VA_ARGS__) | |
55 | #define log_warn(ctx, ...) \ | |
56 | __str_log(ctx, S_WARN, __VA_ARGS__) | |
57 | #define log_err(ctx, ...) \ | |
58 | __str_log(ctx, S_ERROR, __VA_ARGS__) | |
59 | ||
828105d1 DW |
60 | /* Is this debug tweak enabled? */ |
61 | static inline bool | |
62 | debug_tweak_on( | |
63 | const char *name) | |
64 | { | |
65 | return debug && getenv(name) != NULL; | |
66 | } | |
67 | ||
173a0283 DW |
68 | double timeval_subtract(struct timeval *tv1, struct timeval *tv2); |
69 | double auto_space_units(unsigned long long kilobytes, char **units); | |
058f45da | 70 | double auto_units(unsigned long long number, char **units, int *precision); |
e031d90f DW |
71 | unsigned int scrub_nproc(struct scrub_ctx *ctx); |
72 | unsigned int scrub_nproc_workqueue(struct scrub_ctx *ctx); | |
173a0283 | 73 | |
50a573a7 DW |
74 | #ifndef HAVE_SYNCFS |
75 | static inline int syncfs(int fd) | |
76 | { | |
77 | sync(); | |
78 | return 0; | |
79 | } | |
80 | #endif | |
81 | ||
fd7d73c0 | 82 | void background_sleep(void); |
396cd022 DW |
83 | char *string_escape(const char *in); |
84 | ||
85 | #define TOO_MANY_NAME_WARNINGS 10000 | |
86 | bool should_warn_about_name(struct scrub_ctx *ctx); | |
50a573a7 | 87 | |
698c6c7c DW |
88 | bool within_range(struct scrub_ctx *ctx, unsigned long long value, |
89 | unsigned long long desired, unsigned long long abs_threshold, | |
90 | unsigned int n, unsigned int d, const char *descr); | |
91 | ||
15589f0a DW |
92 | int scrub_render_ino_descr(const struct scrub_ctx *ctx, char *buf, |
93 | size_t buflen, uint64_t ino, uint32_t gen, | |
94 | const char *format, ...); | |
95 | ||
95b1e505 | 96 | #endif /* XFS_SCRUB_COMMON_H_ */ |