Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * ocfs2.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Defines macros and structures used in OCFS2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #ifndef OCFS2_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define OCFS2_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/llist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/lockdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/jbd2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /* For union ocfs2_dlm_lksb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "stackglue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "ocfs2_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "ocfs2_lockid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include "ocfs2_ioctl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /* For struct ocfs2_blockcheck_stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include "blockcheck.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include "reservations.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include "filecheck.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /* Caching of metadata buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) /* Most user visible OCFS2 inodes will have very few pieces of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * metadata, but larger files (including bitmaps, etc) must be taken
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * into account when designing an access scheme. We allow a small
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * amount of inlined blocks to be stored on an array and grow the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * structure into a rb tree when necessary. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define OCFS2_CACHE_INFO_MAX_ARRAY 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) /* Flags for ocfs2_caching_info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) enum ocfs2_caching_info_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	/* Indicates that the metadata cache is using the inline array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	OCFS2_CACHE_FL_INLINE	= 1<<1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) struct ocfs2_caching_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) struct ocfs2_caching_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	 * The parent structure provides the locks, but because the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	 * parent structure can differ, it provides locking operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 * to struct ocfs2_caching_info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	const struct ocfs2_caching_operations *ci_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* next two are protected by trans_inc_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	/* which transaction were we created on? Zero if none. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned long		ci_created_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	/* last transaction we were a part of. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	unsigned long		ci_last_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/* Cache structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	unsigned int		ci_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	unsigned int		ci_num_cached;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	sector_t	ci_array[OCFS2_CACHE_INFO_MAX_ARRAY];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		struct rb_root	ci_tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	} ci_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * Need this prototype here instead of in uptodate.h because journal.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * uses it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) struct super_block *ocfs2_metadata_cache_get_super(struct ocfs2_caching_info *ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) /* this limits us to 256 nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * if we need more, we can do a kmalloc for the map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #define OCFS2_NODE_MAP_MAX_NODES    256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) struct ocfs2_node_map {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	u16 num_nodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	unsigned long map[BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) enum ocfs2_ast_action {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	OCFS2_AST_INVALID = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	OCFS2_AST_ATTACH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	OCFS2_AST_CONVERT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	OCFS2_AST_DOWNCONVERT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* actions for an unlockast function to take. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) enum ocfs2_unlock_action {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	OCFS2_UNLOCK_INVALID = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	OCFS2_UNLOCK_CANCEL_CONVERT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	OCFS2_UNLOCK_DROP_LOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* ocfs2_lock_res->l_flags flags. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define OCFS2_LOCK_ATTACHED      (0x00000001) /* we have initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 					       * the lvb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define OCFS2_LOCK_BUSY          (0x00000002) /* we are currently in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 					       * dlm_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define OCFS2_LOCK_BLOCKED       (0x00000004) /* blocked waiting to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 					       * downconvert*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define OCFS2_LOCK_LOCAL         (0x00000008) /* newly created inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define OCFS2_LOCK_NEEDS_REFRESH (0x00000010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define OCFS2_LOCK_REFRESHING    (0x00000020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define OCFS2_LOCK_INITIALIZED   (0x00000040) /* track initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 					       * for shutdown paths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define OCFS2_LOCK_FREEING       (0x00000080) /* help dlmglue track
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 					       * when to skip queueing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 					       * a lock because it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 					       * about to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 					       * dropped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define OCFS2_LOCK_QUEUED        (0x00000100) /* queued for downconvert */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define OCFS2_LOCK_NOCACHE       (0x00000200) /* don't use a holder count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #define OCFS2_LOCK_PENDING       (0x00000400) /* This lockres is pending a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 						 call to dlm_lock.  Only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 						 exists with BUSY set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #define OCFS2_LOCK_UPCONVERT_FINISHING (0x00000800) /* blocks the dc thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 						     * from downconverting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 						     * before the upconvert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 						     * has completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define OCFS2_LOCK_NONBLOCK_FINISHED (0x00001000) /* NONBLOCK cluster
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 						   * lock has already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 						   * returned, do not block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 						   * dc thread from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 						   * downconverting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct ocfs2_lock_res_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) typedef void (*ocfs2_lock_callback)(int status, unsigned long data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #ifdef CONFIG_OCFS2_FS_STATS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct ocfs2_lock_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	u64		ls_total;	/* Total wait in NSEC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	u32		ls_gets;	/* Num acquires */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	u32		ls_fail;	/* Num failed acquires */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/* Storing max wait in usecs saves 24 bytes per inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	u32		ls_max;		/* Max wait in USEC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	u64		ls_last;	/* Last unlock time in USEC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct ocfs2_lock_res {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	void                    *l_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct ocfs2_lock_res_ops *l_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct list_head         l_blocked_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct list_head         l_mask_waiters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	struct list_head	 l_holders;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	unsigned long		 l_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	char                     l_name[OCFS2_LOCK_ID_MAX_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	unsigned int             l_ro_holders;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	unsigned int             l_ex_holders;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	signed char		 l_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	signed char		 l_requested;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	signed char		 l_blocking;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* Data packed - type enum ocfs2_lock_type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	unsigned char            l_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	/* used from AST/BAST funcs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* Data packed - enum type ocfs2_ast_action */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	unsigned char            l_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	/* Data packed - enum type ocfs2_unlock_action */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	unsigned char            l_unlock_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	unsigned int             l_pending_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	spinlock_t               l_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct ocfs2_dlm_lksb    l_lksb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	wait_queue_head_t        l_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	struct list_head         l_debug_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #ifdef CONFIG_OCFS2_FS_STATS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct ocfs2_lock_stats  l_lock_prmode;		/* PR mode stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	u32                      l_lock_refresh;	/* Disk refreshes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	u64                      l_lock_wait;	/* First lock wait time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	struct ocfs2_lock_stats  l_lock_exmode;		/* EX mode stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #ifdef CONFIG_DEBUG_LOCK_ALLOC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct lockdep_map	 l_lockdep_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) enum ocfs2_orphan_reco_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	ORPHAN_NO_NEED_TRUNCATE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	ORPHAN_NEED_TRUNCATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) enum ocfs2_orphan_scan_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	ORPHAN_SCAN_ACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	ORPHAN_SCAN_INACTIVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct ocfs2_orphan_scan {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct mutex 		os_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct ocfs2_super 	*os_osb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct ocfs2_lock_res 	os_lockres;     /* lock to synchronize scans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct delayed_work 	os_orphan_scan_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	time64_t		os_scantime;  /* time this node ran the scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	u32			os_count;      /* tracks node specific scans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	u32  			os_seqno;       /* tracks cluster wide scans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	atomic_t		os_state;              /* ACTIVE or INACTIVE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct ocfs2_dlm_debug {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct kref d_refcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	u32 d_filter_secs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct list_head d_lockres_tracking;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) enum ocfs2_vol_state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	VOLUME_INIT = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	VOLUME_MOUNTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	VOLUME_MOUNTED_QUOTAS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	VOLUME_DISMOUNTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	VOLUME_DISABLED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct ocfs2_alloc_stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	atomic_t moves;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	atomic_t local_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	atomic_t bitmap_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	atomic_t bg_allocs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	atomic_t bg_extends;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) enum ocfs2_local_alloc_state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	OCFS2_LA_UNUSED = 0,	/* Local alloc will never be used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				 * this mountpoint. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	OCFS2_LA_ENABLED,	/* Local alloc is in use. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	OCFS2_LA_THROTTLED,	/* Local alloc is in use, but number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				 * of bits has been reduced. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	OCFS2_LA_DISABLED	/* Local alloc has temporarily been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 				 * disabled. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) enum ocfs2_mount_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	OCFS2_MOUNT_HB_LOCAL = 1 << 0, /* Local heartbeat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	OCFS2_MOUNT_BARRIER = 1 << 1,	/* Use block barriers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	OCFS2_MOUNT_NOINTR  = 1 << 2,   /* Don't catch signals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	OCFS2_MOUNT_NOUSERXATTR = 1 << 6, /* No user xattr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	OCFS2_MOUNT_INODE64 = 1 << 7,	/* Allow inode numbers > 2^32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	OCFS2_MOUNT_POSIX_ACL = 1 << 8,	/* Force POSIX access control lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	OCFS2_MOUNT_NO_POSIX_ACL = 1 << 9,	/* Disable POSIX access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 						   control lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	OCFS2_MOUNT_USRQUOTA = 1 << 10, /* We support user quotas */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	OCFS2_MOUNT_GRPQUOTA = 1 << 11, /* We support group quotas */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	OCFS2_MOUNT_COHERENCY_BUFFERED = 1 << 12, /* Allow concurrent O_DIRECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 						     writes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT = 1 << 15,  /* Journal Async Commit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	OCFS2_MOUNT_ERRORS_CONT = 1 << 16, /* Return EIO to the calling process on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	OCFS2_MOUNT_ERRORS_ROFS = 1 << 17, /* Change filesystem to read-only on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	OCFS2_MOUNT_NOCLUSTER = 1 << 18, /* No cluster aware filesystem mount */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #define OCFS2_OSB_SOFT_RO	0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #define OCFS2_OSB_HARD_RO	0x0002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #define OCFS2_OSB_ERROR_FS	0x0004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #define OCFS2_DEFAULT_ATIME_QUANTUM	60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct ocfs2_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) struct ocfs2_slot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct ocfs2_recovery_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct ocfs2_replay_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct ocfs2_quota_recovery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct ocfs2_super
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	struct task_struct *commit_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	struct inode *root_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	struct inode *sys_root_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	struct inode *global_system_inodes[NUM_GLOBAL_SYSTEM_INODES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct inode **local_system_inodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	struct ocfs2_slot_info *slot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	u32 *slot_recovery_generations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	spinlock_t node_map_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	u64 root_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	u64 system_dir_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	u64 bitmap_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	u32 bitmap_cpg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	char *uuid_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	u32 uuid_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	u8 *vol_label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	u64 first_cluster_group_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	u32 fs_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	u32 s_feature_compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	u32 s_feature_incompat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	u32 s_feature_ro_compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	/* Protects s_next_generation, osb_flags and s_inode_steal_slot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	 * Could protect more on osb as it's very short lived.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	spinlock_t osb_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	u32 s_next_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	unsigned long osb_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	u16 s_inode_steal_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	u16 s_meta_steal_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	atomic_t s_num_inodes_stolen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	atomic_t s_num_meta_stolen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	unsigned long s_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	unsigned int s_atime_quantum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	unsigned int max_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	unsigned int node_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	int slot_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	int preferred_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	int s_sectsize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	int s_clustersize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	int s_clustersize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	unsigned int s_xattr_inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	atomic_t vol_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	struct mutex recovery_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	struct ocfs2_recovery_map *recovery_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	struct ocfs2_replay_map *replay_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	struct task_struct *recovery_thread_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	int disable_recovery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	wait_queue_head_t checkpoint_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	struct ocfs2_journal *journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	unsigned long osb_commit_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	struct delayed_work		la_enable_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	 * Must hold local alloc i_mutex and osb->osb_lock to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	 * local_alloc_bits. Reads can be done under either lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	unsigned int local_alloc_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	unsigned int local_alloc_default_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	/* osb_clusters_at_boot can become stale! Do not trust it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	 * be up to date. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	unsigned int osb_clusters_at_boot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	enum ocfs2_local_alloc_state local_alloc_state; /* protected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 							 * by osb_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	struct buffer_head *local_alloc_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	u64 la_last_gd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	struct ocfs2_reservation_map	osb_la_resmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	unsigned int	osb_resv_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	unsigned int	osb_dir_resv_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	/* Next two fields are for local node slot recovery during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	 * mount. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	struct ocfs2_dinode *local_alloc_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	struct ocfs2_quota_recovery *quota_rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	struct ocfs2_blockcheck_stats osb_ecc_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	struct ocfs2_alloc_stats alloc_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	char dev_str[20];		/* "major,minor" of the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	u8 osb_stackflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	char osb_cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	char osb_cluster_name[OCFS2_CLUSTER_NAME_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	struct ocfs2_cluster_connection *cconn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	struct ocfs2_lock_res osb_super_lockres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	struct ocfs2_lock_res osb_rename_lockres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	struct ocfs2_lock_res osb_nfs_sync_lockres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct rw_semaphore nfs_sync_rwlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct ocfs2_lock_res osb_trim_fs_lockres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	struct mutex obs_trim_fs_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	struct ocfs2_dlm_debug *osb_dlm_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	struct dentry *osb_debug_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	wait_queue_head_t recovery_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	spinlock_t dc_task_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	struct task_struct *dc_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	wait_queue_head_t dc_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	unsigned long dc_wake_sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	unsigned long dc_work_sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	 * Any thread can add locks to the list, but the downconvert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	 * thread is the only one allowed to remove locks. Any change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	 * to this rule requires updating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	 * ocfs2_downconvert_thread_do_work().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	struct list_head blocked_lock_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	unsigned long blocked_lock_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	/* List of dquot structures to drop last reference to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	struct llist_head dquot_drop_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	struct work_struct dquot_drop_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	wait_queue_head_t		osb_mount_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	/* Truncate log info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	struct inode			*osb_tl_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	struct buffer_head		*osb_tl_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	struct delayed_work		osb_truncate_log_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	atomic_t			osb_tl_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	 * How many clusters in our truncate log.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	 * It must be protected by osb_tl_inode->i_mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	unsigned int truncated_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	struct ocfs2_node_map		osb_recovering_orphan_dirs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	unsigned int			*osb_orphan_wipes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	wait_queue_head_t		osb_wipe_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	struct ocfs2_orphan_scan	osb_orphan_scan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	/* used to protect metaecc calculation check of xattr. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	spinlock_t osb_xattr_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	unsigned int			osb_dx_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	u32				osb_dx_seed[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	/* the group we used to allocate inodes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	u64				osb_inode_alloc_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	/* rb tree root for refcount lock. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	struct rb_root	osb_rf_lock_tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	struct ocfs2_refcount_tree *osb_ref_tree_lru;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	struct mutex system_file_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	 * OCFS2 needs to schedule several different types of work which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	 * require cluster locking, disk I/O, recovery waits, etc. Since these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	 * types of work tend to be heavy we avoid using the kernel events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	 * workqueue and schedule on our own.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	struct workqueue_struct *ocfs2_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	/* sysfs directory per partition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	struct kset *osb_dev_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	/* file check related stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	struct ocfs2_filecheck_sysfs_entry osb_fc_ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) #define OCFS2_SB(sb)	    ((struct ocfs2_super *)(sb)->s_fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) /* Useful typedef for passing around journal access functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) typedef int (*ocfs2_journal_access_func)(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 					 struct ocfs2_caching_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 					 struct buffer_head *bh, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) static inline int ocfs2_should_order_data(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (!S_ISREG(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	if (OCFS2_SB(inode->i_sb)->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static inline int ocfs2_sparse_alloc(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) static inline int ocfs2_writes_unwritten_extents(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	 * Support for sparse files is a pre-requisite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	if (!ocfs2_sparse_alloc(osb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	if (osb->s_feature_ro_compat & OCFS2_FEATURE_RO_COMPAT_UNWRITTEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static inline int ocfs2_supports_append_dio(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_APPEND_DIO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) static inline int ocfs2_supports_inline_data(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_INLINE_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static inline int ocfs2_supports_xattr(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static inline int ocfs2_meta_ecc(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_META_ECC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) static inline int ocfs2_supports_indexed_dirs(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) static inline int ocfs2_supports_discontig_bg(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static inline unsigned int ocfs2_link_max(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	if (ocfs2_supports_indexed_dirs(osb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		return OCFS2_DX_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	return OCFS2_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static inline unsigned int ocfs2_read_links_count(struct ocfs2_dinode *di)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	u32 nlink = le16_to_cpu(di->i_links_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	u32 hi = le16_to_cpu(di->i_links_count_hi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	if (di->i_dyn_features & cpu_to_le16(OCFS2_INDEXED_DIR_FL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		nlink |= (hi << OCFS2_LINKS_HI_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	return nlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static inline void ocfs2_set_links_count(struct ocfs2_dinode *di, u32 nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	u16 lo, hi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	lo = nlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	hi = nlink >> OCFS2_LINKS_HI_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	di->i_links_count = cpu_to_le16(lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	di->i_links_count_hi = cpu_to_le16(hi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) static inline void ocfs2_add_links_count(struct ocfs2_dinode *di, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	u32 links = ocfs2_read_links_count(di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	links += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	ocfs2_set_links_count(di, links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) static inline int ocfs2_refcount_tree(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) /* set / clear functions because cluster events can make these happen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)  * in parallel so we want the transitions to be atomic. this also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)  * means that any future flags osb_flags must be protected by spinlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)  * too! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) static inline void ocfs2_set_osb_flag(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 				      unsigned long flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	osb->osb_flags |= flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) static inline void ocfs2_set_ro_flag(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 				     int hard)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	osb->osb_flags &= ~(OCFS2_OSB_SOFT_RO|OCFS2_OSB_HARD_RO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	if (hard)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		osb->osb_flags |= OCFS2_OSB_HARD_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		osb->osb_flags |= OCFS2_OSB_SOFT_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) static inline int ocfs2_is_hard_readonly(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	ret = osb->osb_flags & OCFS2_OSB_HARD_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	ret = osb->osb_flags & OCFS2_OSB_SOFT_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) static inline int ocfs2_clusterinfo_valid(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	return (osb->s_feature_incompat &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		(OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		 OCFS2_FEATURE_INCOMPAT_CLUSTERINFO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static inline int ocfs2_userspace_stack(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	if (ocfs2_clusterinfo_valid(osb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	    memcmp(osb->osb_cluster_stack, OCFS2_CLASSIC_CLUSTER_STACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 		   OCFS2_STACK_LABEL_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) static inline int ocfs2_o2cb_stack(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	if (ocfs2_clusterinfo_valid(osb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	    !memcmp(osb->osb_cluster_stack, OCFS2_CLASSIC_CLUSTER_STACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		   OCFS2_STACK_LABEL_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) static inline int ocfs2_cluster_o2cb_global_heartbeat(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	return ocfs2_o2cb_stack(osb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		(osb->osb_stackflags & OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) static inline int ocfs2_mount_local(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	return ((osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		|| (osb->s_mount_opt & OCFS2_MOUNT_NOCLUSTER));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) static inline int ocfs2_uses_extended_slot_map(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	return (osb->s_feature_incompat &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) #define OCFS2_IS_VALID_DINODE(ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	(!strcmp((ptr)->i_signature, OCFS2_INODE_SIGNATURE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) #define OCFS2_IS_VALID_EXTENT_BLOCK(ptr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	(!strcmp((ptr)->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) #define OCFS2_IS_VALID_GROUP_DESC(ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	(!strcmp((ptr)->bg_signature, OCFS2_GROUP_DESC_SIGNATURE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) #define OCFS2_IS_VALID_XATTR_BLOCK(ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	(!strcmp((ptr)->xb_signature, OCFS2_XATTR_BLOCK_SIGNATURE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) #define OCFS2_IS_VALID_DIR_TRAILER(ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	(!strcmp((ptr)->db_signature, OCFS2_DIR_TRAILER_SIGNATURE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) #define OCFS2_IS_VALID_DX_ROOT(ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	(!strcmp((ptr)->dr_signature, OCFS2_DX_ROOT_SIGNATURE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) #define OCFS2_IS_VALID_DX_LEAF(ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	(!strcmp((ptr)->dl_signature, OCFS2_DX_LEAF_SIGNATURE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) #define OCFS2_IS_VALID_REFCOUNT_BLOCK(ptr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	(!strcmp((ptr)->rf_signature, OCFS2_REFCOUNT_BLOCK_SIGNATURE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) static inline unsigned long ino_from_blkno(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 					   u64 blkno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	return (unsigned long)(blkno & (u64)ULONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static inline u64 ocfs2_clusters_to_blocks(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 					   u32 clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	int c_to_b_bits = OCFS2_SB(sb)->s_clustersize_bits -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 		sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	return (u64)clusters << c_to_b_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) static inline u32 ocfs2_clusters_for_blocks(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 		u64 blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	int b_to_c_bits = OCFS2_SB(sb)->s_clustersize_bits -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 			sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	blocks += (1 << b_to_c_bits) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	return (u32)(blocks >> b_to_c_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) static inline u32 ocfs2_blocks_to_clusters(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 					   u64 blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	int b_to_c_bits = OCFS2_SB(sb)->s_clustersize_bits -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 		sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	return (u32)(blocks >> b_to_c_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) static inline unsigned int ocfs2_clusters_for_bytes(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 						    u64 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	int cl_bits = OCFS2_SB(sb)->s_clustersize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	unsigned int clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	bytes += OCFS2_SB(sb)->s_clustersize - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	/* OCFS2 just cannot have enough clusters to overflow this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	clusters = (unsigned int)(bytes >> cl_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	return clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) static inline unsigned int ocfs2_bytes_to_clusters(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 		u64 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	int cl_bits = OCFS2_SB(sb)->s_clustersize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 	unsigned int clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 	clusters = (unsigned int)(bytes >> cl_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	return clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) static inline u64 ocfs2_blocks_for_bytes(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 					 u64 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	bytes += sb->s_blocksize - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	return bytes >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) static inline u64 ocfs2_clusters_to_bytes(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 					  u32 clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 	return (u64)clusters << OCFS2_SB(sb)->s_clustersize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) static inline u64 ocfs2_block_to_cluster_start(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 					       u64 blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	int bits = OCFS2_SB(sb)->s_clustersize_bits - sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	unsigned int clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	clusters = ocfs2_blocks_to_clusters(sb, blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	return (u64)clusters << bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) static inline u64 ocfs2_align_bytes_to_clusters(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 						u64 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	int cl_bits = OCFS2_SB(sb)->s_clustersize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 	unsigned int clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	clusters = ocfs2_clusters_for_bytes(sb, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 	return (u64)clusters << cl_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) static inline u64 ocfs2_align_bytes_to_blocks(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 					      u64 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	u64 blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)         blocks = ocfs2_blocks_for_bytes(sb, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	return blocks << sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) static inline unsigned long ocfs2_align_bytes_to_sectors(u64 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	return (unsigned long)((bytes + 511) >> 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) static inline unsigned int ocfs2_page_index_to_clusters(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 							unsigned long pg_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	u32 clusters = pg_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 	unsigned int cbits = OCFS2_SB(sb)->s_clustersize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	if (unlikely(PAGE_SHIFT > cbits))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 		clusters = pg_index << (PAGE_SHIFT - cbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	else if (PAGE_SHIFT < cbits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 		clusters = pg_index >> (cbits - PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	return clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)  * Find the 1st page index which covers the given clusters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) static inline pgoff_t ocfs2_align_clusters_to_page_index(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 							u32 clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	unsigned int cbits = OCFS2_SB(sb)->s_clustersize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)         pgoff_t index = clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 	if (PAGE_SHIFT > cbits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 		index = (pgoff_t)clusters >> (PAGE_SHIFT - cbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 	} else if (PAGE_SHIFT < cbits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 		index = (pgoff_t)clusters << (cbits - PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 	return index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) static inline unsigned int ocfs2_pages_per_cluster(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	unsigned int cbits = OCFS2_SB(sb)->s_clustersize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	unsigned int pages_per_cluster = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 	if (PAGE_SHIFT < cbits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 		pages_per_cluster = 1 << (cbits - PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	return pages_per_cluster;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) static inline unsigned int ocfs2_megabytes_to_clusters(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 						       unsigned int megs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	BUILD_BUG_ON(OCFS2_MAX_CLUSTERSIZE > 1048576);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 	return megs << (20 - OCFS2_SB(sb)->s_clustersize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) static inline unsigned int ocfs2_clusters_to_megabytes(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 						       unsigned int clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 	return clusters >> (20 - OCFS2_SB(sb)->s_clustersize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) static inline void _ocfs2_set_bit(unsigned int bit, unsigned long *bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 	__set_bit_le(bit, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) #define ocfs2_set_bit(bit, addr) _ocfs2_set_bit((bit), (unsigned long *)(addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) static inline void _ocfs2_clear_bit(unsigned int bit, unsigned long *bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 	__clear_bit_le(bit, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) #define ocfs2_clear_bit(bit, addr) _ocfs2_clear_bit((bit), (unsigned long *)(addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) #define ocfs2_test_bit test_bit_le
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) #define ocfs2_find_next_zero_bit find_next_zero_bit_le
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) #define ocfs2_find_next_bit find_next_bit_le
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) static inline void *correct_addr_and_bit_unaligned(int *bit, void *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 	*bit += ((unsigned long) addr & 7UL) << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 	addr = (void *) ((unsigned long) addr & ~7UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) #elif BITS_PER_LONG == 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 	*bit += ((unsigned long) addr & 3UL) << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 	addr = (void *) ((unsigned long) addr & ~3UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) #error "how many bits you are?!"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 	return addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) static inline void ocfs2_set_bit_unaligned(int bit, void *bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 	bitmap = correct_addr_and_bit_unaligned(&bit, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 	ocfs2_set_bit(bit, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) static inline void ocfs2_clear_bit_unaligned(int bit, void *bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 	bitmap = correct_addr_and_bit_unaligned(&bit, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) 	ocfs2_clear_bit(bit, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) static inline int ocfs2_test_bit_unaligned(int bit, void *bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) 	bitmap = correct_addr_and_bit_unaligned(&bit, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) 	return ocfs2_test_bit(bit, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) static inline int ocfs2_find_next_zero_bit_unaligned(void *bitmap, int max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) 							int start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 	int fix = 0, ret, tmpmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) 	bitmap = correct_addr_and_bit_unaligned(&fix, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) 	tmpmax = max + fix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 	start += fix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) 	ret = ocfs2_find_next_zero_bit(bitmap, tmpmax, start) - fix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) 	if (ret > max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) 		return max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) #endif  /* OCFS2_H */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)