Whamcloud - gitweb
LU-19098 hsm: don't print progname twice with lhsmtool
[fs/lustre-release.git] / lustre / utils / ofd_access_batch.h
1 #ifndef _OFD_ACCESS_BATCH_H_
2 #define _OFD_ACCESS_BATCH_H_
3 #include <pthread.h>
4 #include <sys/types.h>
5 #include <linux/types.h>
6 #include <libcfs/util/list.h>
7 #include <errno.h>
8
9 extern FILE *debug_file;
10 extern FILE *trace_file;
11
12 #define DEBUG(fmt, args...)                                             \
13         do {                                                            \
14                 if (debug_file != NULL)                                 \
15                         fprintf(debug_file, "DEBUG %s:%d: "fmt,         \
16                                 __func__, __LINE__, ##args);            \
17         } while (0)
18
19 #define TRACE(fmt, args...)                                             \
20         do {                                                            \
21                 if (trace_file != NULL)                                 \
22                         fprintf(trace_file, "TRACE "fmt, ##args);       \
23         } while (0)
24
25 #define DEBUG_D(x) DEBUG("%s = %"PRIdMAX"\n", #x, (intmax_t)x)
26 #define DEBUG_P(x) DEBUG("%s = %p\n", #x, x)
27 #define DEBUG_S(x) DEBUG("%s = '%s'\n", #x, x)
28 #define DEBUG_U(x) DEBUG("%s = %"PRIuMAX"\n", #x, (uintmax_t)x)
29
30 #define ERROR(fmt, args...) \
31         fprintf(stderr, "%s: "fmt, program_invocation_short_name, ##args)
32
33 #define FATAL(fmt, args...)                     \
34         do {                                    \
35                 ERROR("FATAL: "fmt, ##args);    \
36                 exit(EXIT_FAILURE);             \
37         } while (0)
38
39 struct lu_fid;
40 struct alr_batch;
41 extern unsigned long keepalive_interval;
42
43 struct alr_batch *alr_batch_create(unsigned int shift);
44 void alr_batch_destroy(struct alr_batch *alrb);
45 int alr_batch_add(struct alr_batch *alrb, const char *obd_name,
46                 const struct lu_fid *pfid, time_t time, __u64 begin, __u64 end,
47                 __u32 size, __u32 segment_count, __u32 flags);
48 int alr_batch_print(struct alr_batch *alrb, FILE *file,
49                     pthread_mutex_t *file_mutex, int fraction);
50
51 /*
52  * The code is inspired by the kernel list implementation. Hence, this has
53  * a weird param order to be consistent with the kernel list_replace_init().
54  */
55 static inline void list_replace_init(struct list_head *old_node,
56                                      struct list_head *new_node)
57 {
58         list_add(new_node, old_node);
59         list_del_init(old_node);
60 }
61
62 #endif /* _OFD_ACCESS_BATCH_H_ */