18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
48c2ecf20Sopenharmony_ci * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef __UTIL_DOT_H__
88c2ecf20Sopenharmony_ci#define __UTIL_DOT_H__
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifdef pr_fmt
118c2ecf20Sopenharmony_ci#undef pr_fmt
128c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
138c2ecf20Sopenharmony_ci#endif
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/mempool.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "incore.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define fs_emerg(fs, fmt, ...)						\
208c2ecf20Sopenharmony_ci	pr_emerg("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
218c2ecf20Sopenharmony_ci#define fs_warn(fs, fmt, ...)						\
228c2ecf20Sopenharmony_ci	pr_warn("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
238c2ecf20Sopenharmony_ci#define fs_err(fs, fmt, ...)						\
248c2ecf20Sopenharmony_ci	pr_err("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
258c2ecf20Sopenharmony_ci#define fs_info(fs, fmt, ...)						\
268c2ecf20Sopenharmony_ci	pr_info("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_civoid gfs2_assert_i(struct gfs2_sbd *sdp);
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define gfs2_assert(sdp, assertion) \
318c2ecf20Sopenharmony_cido { \
328c2ecf20Sopenharmony_ci	if (unlikely(!(assertion))) { \
338c2ecf20Sopenharmony_ci		gfs2_assert_i(sdp); \
348c2ecf20Sopenharmony_ci		BUG(); \
358c2ecf20Sopenharmony_ci        } \
368c2ecf20Sopenharmony_ci} while (0)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_civoid gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
408c2ecf20Sopenharmony_ci			    const char *function, char *file, unsigned int line,
418c2ecf20Sopenharmony_ci			    bool delayed);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define gfs2_assert_withdraw(sdp, assertion) \
448c2ecf20Sopenharmony_ci	({ \
458c2ecf20Sopenharmony_ci		bool _bool = (assertion); \
468c2ecf20Sopenharmony_ci		if (unlikely(!_bool)) \
478c2ecf20Sopenharmony_ci			gfs2_assert_withdraw_i((sdp), #assertion, \
488c2ecf20Sopenharmony_ci					__func__, __FILE__, __LINE__, false); \
498c2ecf20Sopenharmony_ci		!_bool; \
508c2ecf20Sopenharmony_ci	})
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define gfs2_assert_withdraw_delayed(sdp, assertion) \
538c2ecf20Sopenharmony_ci	({ \
548c2ecf20Sopenharmony_ci		bool _bool = (assertion); \
558c2ecf20Sopenharmony_ci		if (unlikely(!_bool)) \
568c2ecf20Sopenharmony_ci			gfs2_assert_withdraw_i((sdp), #assertion, \
578c2ecf20Sopenharmony_ci					__func__, __FILE__, __LINE__, true); \
588c2ecf20Sopenharmony_ci		!_bool; \
598c2ecf20Sopenharmony_ci	})
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_civoid gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
628c2ecf20Sopenharmony_ci			const char *function, char *file, unsigned int line);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define gfs2_assert_warn(sdp, assertion) \
658c2ecf20Sopenharmony_ci	({ \
668c2ecf20Sopenharmony_ci		bool _bool = (assertion); \
678c2ecf20Sopenharmony_ci		if (unlikely(!_bool)) \
688c2ecf20Sopenharmony_ci			gfs2_assert_warn_i((sdp), #assertion, \
698c2ecf20Sopenharmony_ci					__func__, __FILE__, __LINE__); \
708c2ecf20Sopenharmony_ci		!_bool; \
718c2ecf20Sopenharmony_ci	})
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_civoid gfs2_consist_i(struct gfs2_sbd *sdp,
748c2ecf20Sopenharmony_ci		    const char *function, char *file, unsigned int line);
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#define gfs2_consist(sdp) \
778c2ecf20Sopenharmony_cigfs2_consist_i((sdp), __func__, __FILE__, __LINE__)
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_civoid gfs2_consist_inode_i(struct gfs2_inode *ip,
818c2ecf20Sopenharmony_ci			  const char *function, char *file, unsigned int line);
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define gfs2_consist_inode(ip) \
848c2ecf20Sopenharmony_cigfs2_consist_inode_i((ip), __func__, __FILE__, __LINE__)
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_civoid gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd,
888c2ecf20Sopenharmony_ci			  const char *function, char *file, unsigned int line);
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define gfs2_consist_rgrpd(rgd) \
918c2ecf20Sopenharmony_cigfs2_consist_rgrpd_i((rgd), __func__, __FILE__, __LINE__)
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ciint gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
958c2ecf20Sopenharmony_ci		       const char *type, const char *function,
968c2ecf20Sopenharmony_ci		       char *file, unsigned int line);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic inline int gfs2_meta_check(struct gfs2_sbd *sdp,
998c2ecf20Sopenharmony_ci				    struct buffer_head *bh)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
1028c2ecf20Sopenharmony_ci	u32 magic = be32_to_cpu(mh->mh_magic);
1038c2ecf20Sopenharmony_ci	if (unlikely(magic != GFS2_MAGIC)) {
1048c2ecf20Sopenharmony_ci		fs_err(sdp, "Magic number missing at %llu\n",
1058c2ecf20Sopenharmony_ci		       (unsigned long long)bh->b_blocknr);
1068c2ecf20Sopenharmony_ci		return -EIO;
1078c2ecf20Sopenharmony_ci	}
1088c2ecf20Sopenharmony_ci	return 0;
1098c2ecf20Sopenharmony_ci}
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ciint gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
1128c2ecf20Sopenharmony_ci			   u16 type, u16 t,
1138c2ecf20Sopenharmony_ci			   const char *function,
1148c2ecf20Sopenharmony_ci			   char *file, unsigned int line);
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp,
1178c2ecf20Sopenharmony_ci					struct buffer_head *bh,
1188c2ecf20Sopenharmony_ci					u16 type,
1198c2ecf20Sopenharmony_ci					const char *function,
1208c2ecf20Sopenharmony_ci					char *file, unsigned int line)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
1238c2ecf20Sopenharmony_ci	u32 magic = be32_to_cpu(mh->mh_magic);
1248c2ecf20Sopenharmony_ci	u16 t = be32_to_cpu(mh->mh_type);
1258c2ecf20Sopenharmony_ci	if (unlikely(magic != GFS2_MAGIC))
1268c2ecf20Sopenharmony_ci		return gfs2_meta_check_ii(sdp, bh, "magic number", function,
1278c2ecf20Sopenharmony_ci					  file, line);
1288c2ecf20Sopenharmony_ci        if (unlikely(t != type))
1298c2ecf20Sopenharmony_ci		return gfs2_metatype_check_ii(sdp, bh, type, t, function,
1308c2ecf20Sopenharmony_ci					      file, line);
1318c2ecf20Sopenharmony_ci	return 0;
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci#define gfs2_metatype_check(sdp, bh, type) \
1358c2ecf20Sopenharmony_cigfs2_metatype_check_i((sdp), (bh), (type), __func__, __FILE__, __LINE__)
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistatic inline void gfs2_metatype_set(struct buffer_head *bh, u16 type,
1388c2ecf20Sopenharmony_ci				     u16 format)
1398c2ecf20Sopenharmony_ci{
1408c2ecf20Sopenharmony_ci	struct gfs2_meta_header *mh;
1418c2ecf20Sopenharmony_ci	mh = (struct gfs2_meta_header *)bh->b_data;
1428c2ecf20Sopenharmony_ci	mh->mh_type = cpu_to_be32(type);
1438c2ecf20Sopenharmony_ci	mh->mh_format = cpu_to_be32(format);
1448c2ecf20Sopenharmony_ci}
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ciint gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,
1488c2ecf20Sopenharmony_ci		    char *file, unsigned int line);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciextern int check_journal_clean(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
1518c2ecf20Sopenharmony_ci			       bool verbose);
1528c2ecf20Sopenharmony_ciextern int gfs2_freeze_lock(struct gfs2_sbd *sdp,
1538c2ecf20Sopenharmony_ci			    struct gfs2_holder *freeze_gh, int caller_flags);
1548c2ecf20Sopenharmony_ciextern void gfs2_freeze_unlock(struct gfs2_holder *freeze_gh);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci#define gfs2_io_error(sdp) \
1578c2ecf20Sopenharmony_cigfs2_io_error_i((sdp), __func__, __FILE__, __LINE__);
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_civoid gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
1618c2ecf20Sopenharmony_ci			const char *function, char *file, unsigned int line,
1628c2ecf20Sopenharmony_ci			bool withdraw);
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci#define gfs2_io_error_bh_wd(sdp, bh) \
1658c2ecf20Sopenharmony_cigfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, true);
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci#define gfs2_io_error_bh(sdp, bh) \
1688c2ecf20Sopenharmony_cigfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, false);
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ciextern struct kmem_cache *gfs2_glock_cachep;
1728c2ecf20Sopenharmony_ciextern struct kmem_cache *gfs2_glock_aspace_cachep;
1738c2ecf20Sopenharmony_ciextern struct kmem_cache *gfs2_inode_cachep;
1748c2ecf20Sopenharmony_ciextern struct kmem_cache *gfs2_bufdata_cachep;
1758c2ecf20Sopenharmony_ciextern struct kmem_cache *gfs2_rgrpd_cachep;
1768c2ecf20Sopenharmony_ciextern struct kmem_cache *gfs2_quotad_cachep;
1778c2ecf20Sopenharmony_ciextern struct kmem_cache *gfs2_qadata_cachep;
1788c2ecf20Sopenharmony_ciextern struct kmem_cache *gfs2_trans_cachep;
1798c2ecf20Sopenharmony_ciextern mempool_t *gfs2_page_pool;
1808c2ecf20Sopenharmony_ciextern struct workqueue_struct *gfs2_control_wq;
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
1838c2ecf20Sopenharmony_ci					   unsigned int *p)
1848c2ecf20Sopenharmony_ci{
1858c2ecf20Sopenharmony_ci	unsigned int x;
1868c2ecf20Sopenharmony_ci	spin_lock(&gt->gt_spin);
1878c2ecf20Sopenharmony_ci	x = *p;
1888c2ecf20Sopenharmony_ci	spin_unlock(&gt->gt_spin);
1898c2ecf20Sopenharmony_ci	return x;
1908c2ecf20Sopenharmony_ci}
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci/**
1938c2ecf20Sopenharmony_ci * gfs2_withdraw_delayed - withdraw as soon as possible without deadlocks
1948c2ecf20Sopenharmony_ci * @sdp: the superblock
1958c2ecf20Sopenharmony_ci */
1968c2ecf20Sopenharmony_cistatic inline void gfs2_withdraw_delayed(struct gfs2_sbd *sdp)
1978c2ecf20Sopenharmony_ci{
1988c2ecf20Sopenharmony_ci	set_bit(SDF_WITHDRAWING, &sdp->sd_flags);
1998c2ecf20Sopenharmony_ci}
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/**
2028c2ecf20Sopenharmony_ci * gfs2_withdrawn - test whether the file system is withdrawing or withdrawn
2038c2ecf20Sopenharmony_ci * @sdp: the superblock
2048c2ecf20Sopenharmony_ci */
2058c2ecf20Sopenharmony_cistatic inline bool gfs2_withdrawn(struct gfs2_sbd *sdp)
2068c2ecf20Sopenharmony_ci{
2078c2ecf20Sopenharmony_ci	return test_bit(SDF_WITHDRAWN, &sdp->sd_flags) ||
2088c2ecf20Sopenharmony_ci		test_bit(SDF_WITHDRAWING, &sdp->sd_flags);
2098c2ecf20Sopenharmony_ci}
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci/**
2128c2ecf20Sopenharmony_ci * gfs2_withdrawing - check if a withdraw is pending
2138c2ecf20Sopenharmony_ci * @sdp: the superblock
2148c2ecf20Sopenharmony_ci */
2158c2ecf20Sopenharmony_cistatic inline bool gfs2_withdrawing(struct gfs2_sbd *sdp)
2168c2ecf20Sopenharmony_ci{
2178c2ecf20Sopenharmony_ci	return test_bit(SDF_WITHDRAWING, &sdp->sd_flags) &&
2188c2ecf20Sopenharmony_ci	       !test_bit(SDF_WITHDRAWN, &sdp->sd_flags);
2198c2ecf20Sopenharmony_ci}
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci#define gfs2_tune_get(sdp, field) \
2228c2ecf20Sopenharmony_cigfs2_tune_get_i(&(sdp)->sd_tune, &(sdp)->sd_tune.field)
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci__printf(2, 3)
2258c2ecf20Sopenharmony_civoid gfs2_lm(struct gfs2_sbd *sdp, const char *fmt, ...);
2268c2ecf20Sopenharmony_ciint gfs2_withdraw(struct gfs2_sbd *sdp);
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci#endif /* __UTIL_DOT_H__ */
229