]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - scrub/common.h
xfs_scrub: remove moveon from phase 2 functions
[thirdparty/xfsprogs-dev.git] / scrub / common.h
CommitLineData
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
16bool xfs_scrub_excessive_errors(struct scrub_ctx *ctx);
17
18enum error_level {
19 S_ERROR = 0,
abc2e70d 20 S_CORRUPT,
49e05cb0 21 S_UNFIXABLE,
f0585fce
DW
22 S_WARN,
23 S_INFO,
ca427fe8 24 S_REPAIR,
19852474 25 S_PREEN,
f0585fce
DW
26};
27
28void __str_out(struct scrub_ctx *ctx, const char *descr, enum error_level level,
29 int error, const char *file, int line, const char *format, ...);
30
31#define str_errno(ctx, str) \
32 __str_out(ctx, str, S_ERROR, errno, __FILE__, __LINE__, NULL)
9612817d
DW
33#define str_liberror(ctx, error, str) \
34 __str_out(ctx, str, S_ERROR, error, __FILE__, __LINE__, NULL)
abc2e70d
DW
35#define str_corrupt(ctx, str, ...) \
36 __str_out(ctx, str, S_CORRUPT, 0, __FILE__, __LINE__, __VA_ARGS__)
f0585fce
DW
37#define str_error(ctx, str, ...) \
38 __str_out(ctx, str, S_ERROR, 0, __FILE__, __LINE__, __VA_ARGS__)
39#define str_warn(ctx, str, ...) \
40 __str_out(ctx, str, S_WARN, 0, __FILE__, __LINE__, __VA_ARGS__)
41#define str_info(ctx, str, ...) \
42 __str_out(ctx, str, S_INFO, 0, __FILE__, __LINE__, __VA_ARGS__)
19852474
DW
43#define record_repair(ctx, str, ...) \
44 __str_out(ctx, str, S_REPAIR, 0, __FILE__, __LINE__, __VA_ARGS__)
45#define record_preen(ctx, str, ...) \
46 __str_out(ctx, str, S_PREEN, 0, __FILE__, __LINE__, __VA_ARGS__)
49e05cb0
DW
47#define str_unfixable_error(ctx, str, ...) \
48 __str_out(ctx, str, S_UNFIXABLE, 0, __FILE__, __LINE__, __VA_ARGS__)
f0585fce
DW
49
50#define dbg_printf(fmt, ...) \
51 do {if (debug > 1) {printf(fmt, __VA_ARGS__);}} while (0)
52
7c309151
DW
53void __str_log(struct scrub_ctx *ctx, enum error_level level,
54 const char *format, ...);
55
56#define log_info(ctx, ...) \
57 __str_log(ctx, S_INFO, __VA_ARGS__)
58#define log_warn(ctx, ...) \
59 __str_log(ctx, S_WARN, __VA_ARGS__)
60#define log_err(ctx, ...) \
61 __str_log(ctx, S_ERROR, __VA_ARGS__)
62
828105d1
DW
63/* Is this debug tweak enabled? */
64static inline bool
65debug_tweak_on(
66 const char *name)
67{
68 return debug && getenv(name) != NULL;
69}
70
173a0283
DW
71double timeval_subtract(struct timeval *tv1, struct timeval *tv2);
72double auto_space_units(unsigned long long kilobytes, char **units);
058f45da 73double auto_units(unsigned long long number, char **units, int *precision);
e031d90f
DW
74unsigned int scrub_nproc(struct scrub_ctx *ctx);
75unsigned int scrub_nproc_workqueue(struct scrub_ctx *ctx);
173a0283 76
50a573a7
DW
77#ifndef HAVE_SYNCFS
78static inline int syncfs(int fd)
79{
80 sync();
81 return 0;
82}
83#endif
84
fd7d73c0 85void background_sleep(void);
396cd022
DW
86char *string_escape(const char *in);
87
88#define TOO_MANY_NAME_WARNINGS 10000
89bool should_warn_about_name(struct scrub_ctx *ctx);
50a573a7 90
698c6c7c
DW
91bool within_range(struct scrub_ctx *ctx, unsigned long long value,
92 unsigned long long desired, unsigned long long abs_threshold,
93 unsigned int n, unsigned int d, const char *descr);
94
15589f0a
DW
95int scrub_render_ino_descr(const struct scrub_ctx *ctx, char *buf,
96 size_t buflen, uint64_t ino, uint32_t gen,
97 const char *format, ...);
98
95b1e505 99#endif /* XFS_SCRUB_COMMON_H_ */