xref: /openbmc/linux/fs/gfs2/util.h (revision 69511080)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
4  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
5  */
6 
7 #ifndef __UTIL_DOT_H__
8 #define __UTIL_DOT_H__
9 
10 #ifdef pr_fmt
11 #undef pr_fmt
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #endif
14 
15 #include <linux/mempool.h>
16 
17 #include "incore.h"
18 
19 #define fs_emerg(fs, fmt, ...)						\
20 	pr_emerg("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
21 #define fs_warn(fs, fmt, ...)						\
22 	pr_warn("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
23 #define fs_err(fs, fmt, ...)						\
24 	pr_err("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
25 #define fs_info(fs, fmt, ...)						\
26 	pr_info("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
27 
28 void gfs2_assert_i(struct gfs2_sbd *sdp);
29 
30 #define gfs2_assert(sdp, assertion) \
31 do { \
32 	if (unlikely(!(assertion))) { \
33 		gfs2_assert_i(sdp); \
34 		BUG(); \
35         } \
36 } while (0)
37 
38 
39 void gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
40 			    const char *function, char *file, unsigned int line);
41 
42 #define gfs2_assert_withdraw(sdp, assertion) \
43 	({ \
44 		bool _bool = (assertion); \
45 		if (unlikely(!_bool)) \
46 			gfs2_assert_withdraw_i((sdp), #assertion, \
47 					__func__, __FILE__, __LINE__); \
48 		!_bool; \
49 	})
50 
51 void gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
52 			const char *function, char *file, unsigned int line);
53 
54 #define gfs2_assert_warn(sdp, assertion) \
55 	({ \
56 		bool _bool = (assertion); \
57 		if (unlikely(!_bool)) \
58 			gfs2_assert_warn_i((sdp), #assertion, \
59 					__func__, __FILE__, __LINE__); \
60 		!_bool; \
61 	})
62 
63 void gfs2_consist_i(struct gfs2_sbd *sdp,
64 		    const char *function, char *file, unsigned int line);
65 
66 #define gfs2_consist(sdp) \
67 gfs2_consist_i((sdp), __func__, __FILE__, __LINE__)
68 
69 
70 void gfs2_consist_inode_i(struct gfs2_inode *ip,
71 			  const char *function, char *file, unsigned int line);
72 
73 #define gfs2_consist_inode(ip) \
74 gfs2_consist_inode_i((ip), __func__, __FILE__, __LINE__)
75 
76 
77 void gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd,
78 			  const char *function, char *file, unsigned int line);
79 
80 #define gfs2_consist_rgrpd(rgd) \
81 gfs2_consist_rgrpd_i((rgd), __func__, __FILE__, __LINE__)
82 
83 
84 int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
85 		       const char *type, const char *function,
86 		       char *file, unsigned int line);
87 
88 static inline int gfs2_meta_check(struct gfs2_sbd *sdp,
89 				    struct buffer_head *bh)
90 {
91 	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
92 	u32 magic = be32_to_cpu(mh->mh_magic);
93 	if (unlikely(magic != GFS2_MAGIC)) {
94 		fs_err(sdp, "Magic number missing at %llu\n",
95 		       (unsigned long long)bh->b_blocknr);
96 		return -EIO;
97 	}
98 	return 0;
99 }
100 
101 int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
102 			   u16 type, u16 t,
103 			   const char *function,
104 			   char *file, unsigned int line);
105 
106 static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp,
107 					struct buffer_head *bh,
108 					u16 type,
109 					const char *function,
110 					char *file, unsigned int line)
111 {
112 	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
113 	u32 magic = be32_to_cpu(mh->mh_magic);
114 	u16 t = be32_to_cpu(mh->mh_type);
115 	if (unlikely(magic != GFS2_MAGIC))
116 		return gfs2_meta_check_ii(sdp, bh, "magic number", function,
117 					  file, line);
118         if (unlikely(t != type))
119 		return gfs2_metatype_check_ii(sdp, bh, type, t, function,
120 					      file, line);
121 	return 0;
122 }
123 
124 #define gfs2_metatype_check(sdp, bh, type) \
125 gfs2_metatype_check_i((sdp), (bh), (type), __func__, __FILE__, __LINE__)
126 
127 static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type,
128 				     u16 format)
129 {
130 	struct gfs2_meta_header *mh;
131 	mh = (struct gfs2_meta_header *)bh->b_data;
132 	mh->mh_type = cpu_to_be32(type);
133 	mh->mh_format = cpu_to_be32(format);
134 }
135 
136 
137 int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,
138 		    char *file, unsigned int line);
139 
140 #define gfs2_io_error(sdp) \
141 gfs2_io_error_i((sdp), __func__, __FILE__, __LINE__);
142 
143 
144 void gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
145 			const char *function, char *file, unsigned int line,
146 			bool withdraw);
147 
148 #define gfs2_io_error_bh_wd(sdp, bh) \
149 gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, true);
150 
151 #define gfs2_io_error_bh(sdp, bh) \
152 gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, false);
153 
154 
155 extern struct kmem_cache *gfs2_glock_cachep;
156 extern struct kmem_cache *gfs2_glock_aspace_cachep;
157 extern struct kmem_cache *gfs2_inode_cachep;
158 extern struct kmem_cache *gfs2_bufdata_cachep;
159 extern struct kmem_cache *gfs2_rgrpd_cachep;
160 extern struct kmem_cache *gfs2_quotad_cachep;
161 extern struct kmem_cache *gfs2_qadata_cachep;
162 extern mempool_t *gfs2_page_pool;
163 extern struct workqueue_struct *gfs2_control_wq;
164 
165 static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
166 					   unsigned int *p)
167 {
168 	unsigned int x;
169 	spin_lock(&gt->gt_spin);
170 	x = *p;
171 	spin_unlock(&gt->gt_spin);
172 	return x;
173 }
174 
175 /**
176  * gfs2_withdraw_delayed - withdraw as soon as possible without deadlocks
177  * @sdp: the superblock
178  */
179 static inline void gfs2_withdraw_delayed(struct gfs2_sbd *sdp)
180 {
181 	set_bit(SDF_WITHDRAWING, &sdp->sd_flags);
182 }
183 
184 /**
185  * gfs2_withdrawn - test whether the file system is withdrawing or withdrawn
186  * @sdp: the superblock
187  */
188 static inline bool gfs2_withdrawn(struct gfs2_sbd *sdp)
189 {
190 	return test_bit(SDF_WITHDRAWN, &sdp->sd_flags) ||
191 		test_bit(SDF_WITHDRAWING, &sdp->sd_flags);
192 }
193 
194 #define gfs2_tune_get(sdp, field) \
195 gfs2_tune_get_i(&(sdp)->sd_tune, &(sdp)->sd_tune.field)
196 
197 __printf(2, 3)
198 void gfs2_lm(struct gfs2_sbd *sdp, const char *fmt, ...);
199 int gfs2_withdraw(struct gfs2_sbd *sdp);
200 
201 #endif /* __UTIL_DOT_H__ */
202