1328970deSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2fa60ce2cSMasahiro Yamada /*
3ccd979bdSMark Fasheh * ocfs2.h
4ccd979bdSMark Fasheh *
5ccd979bdSMark Fasheh * Defines macros and structures used in OCFS2
6ccd979bdSMark Fasheh *
7ccd979bdSMark Fasheh * Copyright (C) 2002, 2004 Oracle. All rights reserved.
8ccd979bdSMark Fasheh */
9ccd979bdSMark Fasheh
10ccd979bdSMark Fasheh #ifndef OCFS2_H
11ccd979bdSMark Fasheh #define OCFS2_H
12ccd979bdSMark Fasheh
13ccd979bdSMark Fasheh #include <linux/spinlock.h>
14ccd979bdSMark Fasheh #include <linux/sched.h>
15ccd979bdSMark Fasheh #include <linux/wait.h>
16ccd979bdSMark Fasheh #include <linux/list.h>
17e3a767b6SJan Kara #include <linux/llist.h>
18ccd979bdSMark Fasheh #include <linux/rbtree.h>
19ccd979bdSMark Fasheh #include <linux/workqueue.h>
20ccd979bdSMark Fasheh #include <linux/kref.h>
21c74ec2f7SArjan van de Ven #include <linux/mutex.h>
22cb25797dSJan Kara #include <linux/lockdep.h>
232b4e30fbSJoel Becker #include <linux/jbd2.h>
24ccd979bdSMark Fasheh
258f2c9c1bSJoel Becker /* For union ocfs2_dlm_lksb */
268f2c9c1bSJoel Becker #include "stackglue.h"
27ccd979bdSMark Fasheh
28ccd979bdSMark Fasheh #include "ocfs2_fs.h"
29ccd979bdSMark Fasheh #include "ocfs2_lockid.h"
309df5778eSTristan Ye #include "ocfs2_ioctl.h"
31ccd979bdSMark Fasheh
3273be192bSJoel Becker /* For struct ocfs2_blockcheck_stats */
3373be192bSJoel Becker #include "blockcheck.h"
3473be192bSJoel Becker
35d02f00ccSMark Fasheh #include "reservations.h"
3647460d65SJoel Becker
375f483c4aSGang He #include "filecheck.h"
385f483c4aSGang He
3947460d65SJoel Becker /* Caching of metadata buffers */
4047460d65SJoel Becker
41ccd979bdSMark Fasheh /* Most user visible OCFS2 inodes will have very few pieces of
42ccd979bdSMark Fasheh * metadata, but larger files (including bitmaps, etc) must be taken
43ccd979bdSMark Fasheh * into account when designing an access scheme. We allow a small
44ccd979bdSMark Fasheh * amount of inlined blocks to be stored on an array and grow the
45ccd979bdSMark Fasheh * structure into a rb tree when necessary. */
4647460d65SJoel Becker #define OCFS2_CACHE_INFO_MAX_ARRAY 2
4747460d65SJoel Becker
4847460d65SJoel Becker /* Flags for ocfs2_caching_info */
4947460d65SJoel Becker
5047460d65SJoel Becker enum ocfs2_caching_info_flags {
5147460d65SJoel Becker /* Indicates that the metadata cache is using the inline array */
5247460d65SJoel Becker OCFS2_CACHE_FL_INLINE = 1<<1,
5347460d65SJoel Becker };
54ccd979bdSMark Fasheh
556e5a3d75SJoel Becker struct ocfs2_caching_operations;
56ccd979bdSMark Fasheh struct ocfs2_caching_info {
5747460d65SJoel Becker /*
5847460d65SJoel Becker * The parent structure provides the locks, but because the
596e5a3d75SJoel Becker * parent structure can differ, it provides locking operations
606e5a3d75SJoel Becker * to struct ocfs2_caching_info.
6147460d65SJoel Becker */
626e5a3d75SJoel Becker const struct ocfs2_caching_operations *ci_ops;
6347460d65SJoel Becker
64292dd27eSJoel Becker /* next two are protected by trans_inc_lock */
65292dd27eSJoel Becker /* which transaction were we created on? Zero if none. */
66292dd27eSJoel Becker unsigned long ci_created_trans;
6766fb345dSJoel Becker /* last transaction we were a part of. */
6866fb345dSJoel Becker unsigned long ci_last_trans;
6966fb345dSJoel Becker
7066fb345dSJoel Becker /* Cache structures */
7147460d65SJoel Becker unsigned int ci_flags;
72ccd979bdSMark Fasheh unsigned int ci_num_cached;
73ccd979bdSMark Fasheh union {
7447460d65SJoel Becker sector_t ci_array[OCFS2_CACHE_INFO_MAX_ARRAY];
75ccd979bdSMark Fasheh struct rb_root ci_tree;
76ccd979bdSMark Fasheh } ci_cache;
77ccd979bdSMark Fasheh };
780cf2f763SJoel Becker /*
790cf2f763SJoel Becker * Need this prototype here instead of in uptodate.h because journal.h
800cf2f763SJoel Becker * uses it.
810cf2f763SJoel Becker */
820cf2f763SJoel Becker struct super_block *ocfs2_metadata_cache_get_super(struct ocfs2_caching_info *ci);
83ccd979bdSMark Fasheh
84ccd979bdSMark Fasheh /* this limits us to 256 nodes
85ccd979bdSMark Fasheh * if we need more, we can do a kmalloc for the map */
86ccd979bdSMark Fasheh #define OCFS2_NODE_MAP_MAX_NODES 256
87ccd979bdSMark Fasheh struct ocfs2_node_map {
88ccd979bdSMark Fasheh u16 num_nodes;
89ccd979bdSMark Fasheh unsigned long map[BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES)];
90ccd979bdSMark Fasheh };
91ccd979bdSMark Fasheh
92ccd979bdSMark Fasheh enum ocfs2_ast_action {
93ccd979bdSMark Fasheh OCFS2_AST_INVALID = 0,
94ccd979bdSMark Fasheh OCFS2_AST_ATTACH,
95ccd979bdSMark Fasheh OCFS2_AST_CONVERT,
96ccd979bdSMark Fasheh OCFS2_AST_DOWNCONVERT,
97ccd979bdSMark Fasheh };
98ccd979bdSMark Fasheh
99ccd979bdSMark Fasheh /* actions for an unlockast function to take. */
100ccd979bdSMark Fasheh enum ocfs2_unlock_action {
101ccd979bdSMark Fasheh OCFS2_UNLOCK_INVALID = 0,
102ccd979bdSMark Fasheh OCFS2_UNLOCK_CANCEL_CONVERT,
103ccd979bdSMark Fasheh OCFS2_UNLOCK_DROP_LOCK,
104ccd979bdSMark Fasheh };
105ccd979bdSMark Fasheh
106ccd979bdSMark Fasheh /* ocfs2_lock_res->l_flags flags. */
1073b5da018SColy Li #define OCFS2_LOCK_ATTACHED (0x00000001) /* we have initialized
108ccd979bdSMark Fasheh * the lvb */
109ccd979bdSMark Fasheh #define OCFS2_LOCK_BUSY (0x00000002) /* we are currently in
110ccd979bdSMark Fasheh * dlm_lock */
111ccd979bdSMark Fasheh #define OCFS2_LOCK_BLOCKED (0x00000004) /* blocked waiting to
112ccd979bdSMark Fasheh * downconvert*/
113ccd979bdSMark Fasheh #define OCFS2_LOCK_LOCAL (0x00000008) /* newly created inode */
114ccd979bdSMark Fasheh #define OCFS2_LOCK_NEEDS_REFRESH (0x00000010)
115ccd979bdSMark Fasheh #define OCFS2_LOCK_REFRESHING (0x00000020)
116ccd979bdSMark Fasheh #define OCFS2_LOCK_INITIALIZED (0x00000040) /* track initialization
117ccd979bdSMark Fasheh * for shutdown paths */
118ccd979bdSMark Fasheh #define OCFS2_LOCK_FREEING (0x00000080) /* help dlmglue track
119ccd979bdSMark Fasheh * when to skip queueing
120ccd979bdSMark Fasheh * a lock because it's
121ccd979bdSMark Fasheh * about to be
122ccd979bdSMark Fasheh * dropped. */
123ccd979bdSMark Fasheh #define OCFS2_LOCK_QUEUED (0x00000100) /* queued for downconvert */
124cf8e06f1SMark Fasheh #define OCFS2_LOCK_NOCACHE (0x00000200) /* don't use a holder count */
125de551246SJoel Becker #define OCFS2_LOCK_PENDING (0x00000400) /* This lockres is pending a
126de551246SJoel Becker call to dlm_lock. Only
127de551246SJoel Becker exists with BUSY set. */
128a1912826SSunil Mushran #define OCFS2_LOCK_UPCONVERT_FINISHING (0x00000800) /* blocks the dc thread
129a1912826SSunil Mushran * from downconverting
130a1912826SSunil Mushran * before the upconvert
131a1912826SSunil Mushran * has completed */
132ccd979bdSMark Fasheh
133d1e78238SXue jiufei #define OCFS2_LOCK_NONBLOCK_FINISHED (0x00001000) /* NONBLOCK cluster
134d1e78238SXue jiufei * lock has already
135d1e78238SXue jiufei * returned, do not block
136d1e78238SXue jiufei * dc thread from
137d1e78238SXue jiufei * downconverting */
138d1e78238SXue jiufei
139ccd979bdSMark Fasheh struct ocfs2_lock_res_ops;
140ccd979bdSMark Fasheh
141ccd979bdSMark Fasheh typedef void (*ocfs2_lock_callback)(int status, unsigned long data);
142ccd979bdSMark Fasheh
1435bc970e8SSunil Mushran #ifdef CONFIG_OCFS2_FS_STATS
1445bc970e8SSunil Mushran struct ocfs2_lock_stats {
1455bc970e8SSunil Mushran u64 ls_total; /* Total wait in NSEC */
1465bc970e8SSunil Mushran u32 ls_gets; /* Num acquires */
1475bc970e8SSunil Mushran u32 ls_fail; /* Num failed acquires */
1485bc970e8SSunil Mushran
1495bc970e8SSunil Mushran /* Storing max wait in usecs saves 24 bytes per inode */
1505bc970e8SSunil Mushran u32 ls_max; /* Max wait in USEC */
1518a7f5f4cSGang He u64 ls_last; /* Last unlock time in USEC */
1525bc970e8SSunil Mushran };
1535bc970e8SSunil Mushran #endif
1545bc970e8SSunil Mushran
155ccd979bdSMark Fasheh struct ocfs2_lock_res {
156ccd979bdSMark Fasheh void *l_priv;
157ccd979bdSMark Fasheh struct ocfs2_lock_res_ops *l_ops;
15883fd9c7fSGoldwyn Rodrigues
159ccd979bdSMark Fasheh
160ccd979bdSMark Fasheh struct list_head l_blocked_list;
161ccd979bdSMark Fasheh struct list_head l_mask_waiters;
162439a36b8SEric Ren struct list_head l_holders;
163ccd979bdSMark Fasheh
164ccd979bdSMark Fasheh unsigned long l_flags;
165ccd979bdSMark Fasheh char l_name[OCFS2_LOCK_ID_MAX_LEN];
166ccd979bdSMark Fasheh unsigned int l_ro_holders;
167ccd979bdSMark Fasheh unsigned int l_ex_holders;
168a2a2f552SMilton Miller signed char l_level;
169a2a2f552SMilton Miller signed char l_requested;
170a2a2f552SMilton Miller signed char l_blocking;
17183fd9c7fSGoldwyn Rodrigues
17283fd9c7fSGoldwyn Rodrigues /* Data packed - type enum ocfs2_lock_type */
17383fd9c7fSGoldwyn Rodrigues unsigned char l_type;
174ccd979bdSMark Fasheh
175ccd979bdSMark Fasheh /* used from AST/BAST funcs. */
17683fd9c7fSGoldwyn Rodrigues /* Data packed - enum type ocfs2_ast_action */
17783fd9c7fSGoldwyn Rodrigues unsigned char l_action;
17883fd9c7fSGoldwyn Rodrigues /* Data packed - enum type ocfs2_unlock_action */
17983fd9c7fSGoldwyn Rodrigues unsigned char l_unlock_action;
180de551246SJoel Becker unsigned int l_pending_gen;
181ccd979bdSMark Fasheh
18283fd9c7fSGoldwyn Rodrigues spinlock_t l_lock;
18383fd9c7fSGoldwyn Rodrigues
18483fd9c7fSGoldwyn Rodrigues struct ocfs2_dlm_lksb l_lksb;
18583fd9c7fSGoldwyn Rodrigues
186ccd979bdSMark Fasheh wait_queue_head_t l_event;
187ccd979bdSMark Fasheh
188ccd979bdSMark Fasheh struct list_head l_debug_list;
1898ddb7b00SSunil Mushran
1908ddb7b00SSunil Mushran #ifdef CONFIG_OCFS2_FS_STATS
1915bc970e8SSunil Mushran struct ocfs2_lock_stats l_lock_prmode; /* PR mode stats */
1925bc970e8SSunil Mushran u32 l_lock_refresh; /* Disk refreshes */
1935da844a2SGang He u64 l_lock_wait; /* First lock wait time */
1945bc970e8SSunil Mushran struct ocfs2_lock_stats l_lock_exmode; /* EX mode stats */
1958ddb7b00SSunil Mushran #endif
196cb25797dSJan Kara #ifdef CONFIG_DEBUG_LOCK_ALLOC
197cb25797dSJan Kara struct lockdep_map l_lockdep_map;
198cb25797dSJan Kara #endif
199ccd979bdSMark Fasheh };
200ccd979bdSMark Fasheh
201ed460cffSJoseph Qi enum ocfs2_orphan_reco_type {
202ed460cffSJoseph Qi ORPHAN_NO_NEED_TRUNCATE = 0,
203ed460cffSJoseph Qi ORPHAN_NEED_TRUNCATE,
204ed460cffSJoseph Qi };
205ed460cffSJoseph Qi
206692684e1SSunil Mushran enum ocfs2_orphan_scan_state {
207692684e1SSunil Mushran ORPHAN_SCAN_ACTIVE,
208692684e1SSunil Mushran ORPHAN_SCAN_INACTIVE
209692684e1SSunil Mushran };
210692684e1SSunil Mushran
21183273932SSrinivas Eeda struct ocfs2_orphan_scan {
21283273932SSrinivas Eeda struct mutex os_lock;
21383273932SSrinivas Eeda struct ocfs2_super *os_osb;
21483273932SSrinivas Eeda struct ocfs2_lock_res os_lockres; /* lock to synchronize scans */
21583273932SSrinivas Eeda struct delayed_work os_orphan_scan_work;
216395627b0SDeepa Dinamani time64_t os_scantime; /* time this node ran the scan */
21715633a22SSrinivas Eeda u32 os_count; /* tracks node specific scans */
21815633a22SSrinivas Eeda u32 os_seqno; /* tracks cluster wide scans */
219692684e1SSunil Mushran atomic_t os_state; /* ACTIVE or INACTIVE */
22083273932SSrinivas Eeda };
22183273932SSrinivas Eeda
222ccd979bdSMark Fasheh struct ocfs2_dlm_debug {
223ccd979bdSMark Fasheh struct kref d_refcnt;
2248056773aSGang He u32 d_filter_secs;
225ccd979bdSMark Fasheh struct list_head d_lockres_tracking;
226ccd979bdSMark Fasheh };
227ccd979bdSMark Fasheh
228ccd979bdSMark Fasheh enum ocfs2_vol_state
229ccd979bdSMark Fasheh {
230ccd979bdSMark Fasheh VOLUME_INIT = 0,
231ccd979bdSMark Fasheh VOLUME_MOUNTED,
23219ece546SJan Kara VOLUME_MOUNTED_QUOTAS,
233ccd979bdSMark Fasheh VOLUME_DISMOUNTED,
234ccd979bdSMark Fasheh VOLUME_DISABLED
235ccd979bdSMark Fasheh };
236ccd979bdSMark Fasheh
237ccd979bdSMark Fasheh struct ocfs2_alloc_stats
238ccd979bdSMark Fasheh {
239ccd979bdSMark Fasheh atomic_t moves;
240ccd979bdSMark Fasheh atomic_t local_data;
241ccd979bdSMark Fasheh atomic_t bitmap_data;
242ccd979bdSMark Fasheh atomic_t bg_allocs;
243ccd979bdSMark Fasheh atomic_t bg_extends;
244ccd979bdSMark Fasheh };
245ccd979bdSMark Fasheh
246ccd979bdSMark Fasheh enum ocfs2_local_alloc_state
247ccd979bdSMark Fasheh {
2489c7af40bSMark Fasheh OCFS2_LA_UNUSED = 0, /* Local alloc will never be used for
2499c7af40bSMark Fasheh * this mountpoint. */
2509c7af40bSMark Fasheh OCFS2_LA_ENABLED, /* Local alloc is in use. */
2519c7af40bSMark Fasheh OCFS2_LA_THROTTLED, /* Local alloc is in use, but number
2529c7af40bSMark Fasheh * of bits has been reduced. */
2539c7af40bSMark Fasheh OCFS2_LA_DISABLED /* Local alloc has temporarily been
2549c7af40bSMark Fasheh * disabled. */
255ccd979bdSMark Fasheh };
256ccd979bdSMark Fasheh
257ccd979bdSMark Fasheh enum ocfs2_mount_options
258ccd979bdSMark Fasheh {
2592c442719SSunil Mushran OCFS2_MOUNT_HB_LOCAL = 1 << 0, /* Local heartbeat */
260ccd979bdSMark Fasheh OCFS2_MOUNT_BARRIER = 1 << 1, /* Use block barriers */
261ccd979bdSMark Fasheh OCFS2_MOUNT_NOINTR = 1 << 2, /* Don't catch signals */
262ccd979bdSMark Fasheh OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
263ccd979bdSMark Fasheh OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
26453fc622bSMark Fasheh OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */
265cf1d6c76STiger Yang OCFS2_MOUNT_NOUSERXATTR = 1 << 6, /* No user xattr */
26612462f1dSJoel Becker OCFS2_MOUNT_INODE64 = 1 << 7, /* Allow inode numbers > 2^32 */
2675297aad8SJan Kara OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* Force POSIX access control lists */
2685297aad8SJan Kara OCFS2_MOUNT_NO_POSIX_ACL = 1 << 9, /* Disable POSIX access
2695297aad8SJan Kara control lists */
2705297aad8SJan Kara OCFS2_MOUNT_USRQUOTA = 1 << 10, /* We support user quotas */
2715297aad8SJan Kara OCFS2_MOUNT_GRPQUOTA = 1 << 11, /* We support group quotas */
272fc371891SJoel Becker OCFS2_MOUNT_COHERENCY_BUFFERED = 1 << 12, /* Allow concurrent O_DIRECT
2737bdb0d18STristan Ye writes */
274fc371891SJoel Becker OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
275fc371891SJoel Becker OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
2761dfeb768Salex chen
2771dfeb768Salex chen OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT = 1 << 15, /* Journal Async Commit */
2787d0fb914SGoldwyn Rodrigues OCFS2_MOUNT_ERRORS_CONT = 1 << 16, /* Return EIO to the calling process on error */
2797d0fb914SGoldwyn Rodrigues OCFS2_MOUNT_ERRORS_ROFS = 1 << 17, /* Change filesystem to read-only on error */
280ccd979bdSMark Fasheh };
281ccd979bdSMark Fasheh
282ccd979bdSMark Fasheh #define OCFS2_OSB_SOFT_RO 0x0001
283ccd979bdSMark Fasheh #define OCFS2_OSB_HARD_RO 0x0002
284ccd979bdSMark Fasheh #define OCFS2_OSB_ERROR_FS 0x0004
2857f1a37e3STiger Yang #define OCFS2_DEFAULT_ATIME_QUANTUM 60
286ccd979bdSMark Fasheh
287*67bcecd7SJoseph Qi struct ocfs2_triggers {
288*67bcecd7SJoseph Qi struct jbd2_buffer_trigger_type ot_triggers;
289*67bcecd7SJoseph Qi int ot_offset;
290*67bcecd7SJoseph Qi struct super_block *sb;
291*67bcecd7SJoseph Qi };
292*67bcecd7SJoseph Qi
293*67bcecd7SJoseph Qi enum ocfs2_journal_trigger_type {
294*67bcecd7SJoseph Qi OCFS2_JTR_DI,
295*67bcecd7SJoseph Qi OCFS2_JTR_EB,
296*67bcecd7SJoseph Qi OCFS2_JTR_RB,
297*67bcecd7SJoseph Qi OCFS2_JTR_GD,
298*67bcecd7SJoseph Qi OCFS2_JTR_DB,
299*67bcecd7SJoseph Qi OCFS2_JTR_XB,
300*67bcecd7SJoseph Qi OCFS2_JTR_DQ,
301*67bcecd7SJoseph Qi OCFS2_JTR_DR,
302*67bcecd7SJoseph Qi OCFS2_JTR_DL,
303*67bcecd7SJoseph Qi OCFS2_JTR_NONE /* This must be the last entry */
304*67bcecd7SJoseph Qi };
305*67bcecd7SJoseph Qi
306*67bcecd7SJoseph Qi #define OCFS2_JOURNAL_TRIGGER_COUNT OCFS2_JTR_NONE
307*67bcecd7SJoseph Qi
308*67bcecd7SJoseph Qi void ocfs2_initialize_journal_triggers(struct super_block *sb,
309*67bcecd7SJoseph Qi struct ocfs2_triggers triggers[]);
310*67bcecd7SJoseph Qi
311ccd979bdSMark Fasheh struct ocfs2_journal;
312d85b20e4SJoel Becker struct ocfs2_slot_info;
313553abd04SJoel Becker struct ocfs2_recovery_map;
3149140db04SSrinivas Eeda struct ocfs2_replay_map;
3152205363dSJan Kara struct ocfs2_quota_recovery;
316ccd979bdSMark Fasheh struct ocfs2_super
317ccd979bdSMark Fasheh {
318ccd979bdSMark Fasheh struct task_struct *commit_task;
319ccd979bdSMark Fasheh struct super_block *sb;
320ccd979bdSMark Fasheh struct inode *root_inode;
321ccd979bdSMark Fasheh struct inode *sys_root_inode;
322b4d693fcSTao Ma struct inode *global_system_inodes[NUM_GLOBAL_SYSTEM_INODES];
323b4d693fcSTao Ma struct inode **local_system_inodes;
324ccd979bdSMark Fasheh
325ccd979bdSMark Fasheh struct ocfs2_slot_info *slot_info;
326ccd979bdSMark Fasheh
327539d8264SSunil Mushran u32 *slot_recovery_generations;
328539d8264SSunil Mushran
329ccd979bdSMark Fasheh spinlock_t node_map_lock;
330ccd979bdSMark Fasheh
331ccd979bdSMark Fasheh u64 root_blkno;
332ccd979bdSMark Fasheh u64 system_dir_blkno;
333ccd979bdSMark Fasheh u64 bitmap_blkno;
334ccd979bdSMark Fasheh u32 bitmap_cpg;
335ccd979bdSMark Fasheh char *uuid_str;
336cf1d6c76STiger Yang u32 uuid_hash;
337ccd979bdSMark Fasheh u8 *vol_label;
338ccd979bdSMark Fasheh u64 first_cluster_group_blkno;
339ccd979bdSMark Fasheh u32 fs_generation;
340ccd979bdSMark Fasheh
341ccd979bdSMark Fasheh u32 s_feature_compat;
342ccd979bdSMark Fasheh u32 s_feature_incompat;
343ccd979bdSMark Fasheh u32 s_feature_ro_compat;
344ccd979bdSMark Fasheh
3454d0ddb2cSTao Ma /* Protects s_next_generation, osb_flags and s_inode_steal_slot.
3464d0ddb2cSTao Ma * Could protect more on osb as it's very short lived.
3474d0ddb2cSTao Ma */
348ccd979bdSMark Fasheh spinlock_t osb_lock;
349ccd979bdSMark Fasheh u32 s_next_generation;
350ccd979bdSMark Fasheh unsigned long osb_flags;
35138d51b2dSJunxiao Bi u16 s_inode_steal_slot;
35238d51b2dSJunxiao Bi u16 s_meta_steal_slot;
3534d0ddb2cSTao Ma atomic_t s_num_inodes_stolen;
354b89c5428STiger Yang atomic_t s_num_meta_stolen;
355ccd979bdSMark Fasheh
356ccd979bdSMark Fasheh unsigned long s_mount_opt;
3577f1a37e3STiger Yang unsigned int s_atime_quantum;
358ccd979bdSMark Fasheh
359fc881fa0SJoel Becker unsigned int max_slots;
36019fdb624SJoel Becker unsigned int node_num;
361fc881fa0SJoel Becker int slot_num;
362fc881fa0SJoel Becker int preferred_slot;
363ccd979bdSMark Fasheh int s_sectsize_bits;
364ccd979bdSMark Fasheh int s_clustersize;
365ccd979bdSMark Fasheh int s_clustersize_bits;
366fdd77704STiger Yang unsigned int s_xattr_inline_size;
367ccd979bdSMark Fasheh
368ccd979bdSMark Fasheh atomic_t vol_state;
369c74ec2f7SArjan van de Ven struct mutex recovery_lock;
370553abd04SJoel Becker struct ocfs2_recovery_map *recovery_map;
3719140db04SSrinivas Eeda struct ocfs2_replay_map *replay_map;
372ccd979bdSMark Fasheh struct task_struct *recovery_thread_task;
373ccd979bdSMark Fasheh int disable_recovery;
374ccd979bdSMark Fasheh wait_queue_head_t checkpoint_event;
375ccd979bdSMark Fasheh struct ocfs2_journal *journal;
376d147b3d6SMark Fasheh unsigned long osb_commit_interval;
377ccd979bdSMark Fasheh
378*67bcecd7SJoseph Qi /* Journal triggers for checksum */
379*67bcecd7SJoseph Qi struct ocfs2_triggers s_journal_triggers[OCFS2_JOURNAL_TRIGGER_COUNT];
380*67bcecd7SJoseph Qi
3819c7af40bSMark Fasheh struct delayed_work la_enable_wq;
3829c7af40bSMark Fasheh
3839c7af40bSMark Fasheh /*
384137cebf9Shongnanli * Must hold local alloc i_rwsem and osb->osb_lock to change
3859c7af40bSMark Fasheh * local_alloc_bits. Reads can be done under either lock.
3869c7af40bSMark Fasheh */
387ebcee4b5SMark Fasheh unsigned int local_alloc_bits;
3889c7af40bSMark Fasheh unsigned int local_alloc_default_bits;
3896b82021bSMark Fasheh /* osb_clusters_at_boot can become stale! Do not trust it to
3906b82021bSMark Fasheh * be up to date. */
3916b82021bSMark Fasheh unsigned int osb_clusters_at_boot;
3929c7af40bSMark Fasheh
3939c7af40bSMark Fasheh enum ocfs2_local_alloc_state local_alloc_state; /* protected
3949c7af40bSMark Fasheh * by osb_lock */
3959c7af40bSMark Fasheh
396ccd979bdSMark Fasheh struct buffer_head *local_alloc_bh;
3979c7af40bSMark Fasheh
398883d4caeSMark Fasheh u64 la_last_gd;
399ccd979bdSMark Fasheh
400d02f00ccSMark Fasheh struct ocfs2_reservation_map osb_la_resmap;
401d02f00ccSMark Fasheh
402d02f00ccSMark Fasheh unsigned int osb_resv_level;
40383f92318SMark Fasheh unsigned int osb_dir_resv_level;
404d02f00ccSMark Fasheh
405964f14a0SJun Piao /* Next two fields are for local node slot recovery during
406ccd979bdSMark Fasheh * mount. */
407ccd979bdSMark Fasheh struct ocfs2_dinode *local_alloc_copy;
4082205363dSJan Kara struct ocfs2_quota_recovery *quota_rec;
409ccd979bdSMark Fasheh
41073be192bSJoel Becker struct ocfs2_blockcheck_stats osb_ecc_stats;
411ccd979bdSMark Fasheh struct ocfs2_alloc_stats alloc_stats;
412ccd979bdSMark Fasheh char dev_str[20]; /* "major,minor" of the device */
413ccd979bdSMark Fasheh
41498f486f2SSunil Mushran u8 osb_stackflags;
41598f486f2SSunil Mushran
416b61817e1SJoel Becker char osb_cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
417c74a3bddSGoldwyn Rodrigues char osb_cluster_name[OCFS2_CLUSTER_NAME_LEN + 1];
4184670c46dSJoel Becker struct ocfs2_cluster_connection *cconn;
419ccd979bdSMark Fasheh struct ocfs2_lock_res osb_super_lockres;
420ccd979bdSMark Fasheh struct ocfs2_lock_res osb_rename_lockres;
4216ca497a8Swengang wang struct ocfs2_lock_res osb_nfs_sync_lockres;
4224cd9973fSJunxiao Bi struct rw_semaphore nfs_sync_rwlock;
4234882abebSGang He struct ocfs2_lock_res osb_trim_fs_lockres;
4245500ab4eSGang He struct mutex obs_trim_fs_mutex;
425ccd979bdSMark Fasheh struct ocfs2_dlm_debug *osb_dlm_debug;
426ccd979bdSMark Fasheh
427ccd979bdSMark Fasheh struct dentry *osb_debug_root;
428ccd979bdSMark Fasheh
429ccd979bdSMark Fasheh wait_queue_head_t recovery_event;
430ccd979bdSMark Fasheh
43134d024f8SMark Fasheh spinlock_t dc_task_lock;
43234d024f8SMark Fasheh struct task_struct *dc_task;
43334d024f8SMark Fasheh wait_queue_head_t dc_event;
43434d024f8SMark Fasheh unsigned long dc_wake_sequence;
43534d024f8SMark Fasheh unsigned long dc_work_sequence;
436ccd979bdSMark Fasheh
4377ec373cfSMark Fasheh /*
4387ec373cfSMark Fasheh * Any thread can add locks to the list, but the downconvert
4397ec373cfSMark Fasheh * thread is the only one allowed to remove locks. Any change
4407ec373cfSMark Fasheh * to this rule requires updating
4417ec373cfSMark Fasheh * ocfs2_downconvert_thread_do_work().
4427ec373cfSMark Fasheh */
443ccd979bdSMark Fasheh struct list_head blocked_lock_list;
444ccd979bdSMark Fasheh unsigned long blocked_lock_count;
445ccd979bdSMark Fasheh
446e3a767b6SJan Kara /* List of dquot structures to drop last reference to */
447e3a767b6SJan Kara struct llist_head dquot_drop_list;
448e3a767b6SJan Kara struct work_struct dquot_drop_work;
449e3a767b6SJan Kara
450ccd979bdSMark Fasheh wait_queue_head_t osb_mount_event;
451ccd979bdSMark Fasheh
452ccd979bdSMark Fasheh /* Truncate log info */
453ccd979bdSMark Fasheh struct inode *osb_tl_inode;
454ccd979bdSMark Fasheh struct buffer_head *osb_tl_bh;
455c4028958SDavid Howells struct delayed_work osb_truncate_log_wq;
456a9e9acaeSXue jiufei atomic_t osb_tl_disable;
45750308d81STao Ma /*
45850308d81STao Ma * How many clusters in our truncate log.
459137cebf9Shongnanli * It must be protected by osb_tl_inode->i_rwsem.
46050308d81STao Ma */
46150308d81STao Ma unsigned int truncated_clusters;
462b4df6ed8SMark Fasheh
463b4df6ed8SMark Fasheh struct ocfs2_node_map osb_recovering_orphan_dirs;
464b4df6ed8SMark Fasheh unsigned int *osb_orphan_wipes;
465b4df6ed8SMark Fasheh wait_queue_head_t osb_wipe_event;
466c8b9cf9aSTao Ma
46783273932SSrinivas Eeda struct ocfs2_orphan_scan osb_orphan_scan;
46883273932SSrinivas Eeda
469c8b9cf9aSTao Ma /* used to protect metaecc calculation check of xattr. */
470c8b9cf9aSTao Ma spinlock_t osb_xattr_lock;
4719b7895efSMark Fasheh
4729b7895efSMark Fasheh unsigned int osb_dx_mask;
4739b7895efSMark Fasheh u32 osb_dx_seed[4];
474feb473a6STao Ma
475feb473a6STao Ma /* the group we used to allocate inodes. */
476feb473a6STao Ma u64 osb_inode_alloc_group;
477374a263eSTao Ma
478374a263eSTao Ma /* rb tree root for refcount lock. */
479374a263eSTao Ma struct rb_root osb_rf_lock_tree;
480374a263eSTao Ma struct ocfs2_refcount_tree *osb_ref_tree_lru;
48143b10a20Sjiangyiwen
48243b10a20Sjiangyiwen struct mutex system_file_mutex;
48335ddf78eSjiangyiwen
48435ddf78eSjiangyiwen /*
48535ddf78eSjiangyiwen * OCFS2 needs to schedule several different types of work which
48635ddf78eSjiangyiwen * require cluster locking, disk I/O, recovery waits, etc. Since these
48735ddf78eSjiangyiwen * types of work tend to be heavy we avoid using the kernel events
48835ddf78eSjiangyiwen * workqueue and schedule on our own.
48935ddf78eSjiangyiwen */
49035ddf78eSjiangyiwen struct workqueue_struct *ocfs2_wq;
4915f483c4aSGang He
4925f483c4aSGang He /* sysfs directory per partition */
4935f483c4aSGang He struct kset *osb_dev_kset;
4945f483c4aSGang He
4955f483c4aSGang He /* file check related stuff */
4965f483c4aSGang He struct ocfs2_filecheck_sysfs_entry osb_fc_ent;
497ccd979bdSMark Fasheh };
498ccd979bdSMark Fasheh
499ccd979bdSMark Fasheh #define OCFS2_SB(sb) ((struct ocfs2_super *)(sb)->s_fs_info)
500ccd979bdSMark Fasheh
50113723d00SJoel Becker /* Useful typedef for passing around journal access functions */
5020cf2f763SJoel Becker typedef int (*ocfs2_journal_access_func)(handle_t *handle,
5030cf2f763SJoel Becker struct ocfs2_caching_info *ci,
50413723d00SJoel Becker struct buffer_head *bh, int type);
50513723d00SJoel Becker
ocfs2_should_order_data(struct inode * inode)506ccd979bdSMark Fasheh static inline int ocfs2_should_order_data(struct inode *inode)
507ccd979bdSMark Fasheh {
508ccd979bdSMark Fasheh if (!S_ISREG(inode->i_mode))
509ccd979bdSMark Fasheh return 0;
510ccd979bdSMark Fasheh if (OCFS2_SB(inode->i_sb)->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)
511ccd979bdSMark Fasheh return 0;
512ccd979bdSMark Fasheh return 1;
513ccd979bdSMark Fasheh }
514ccd979bdSMark Fasheh
ocfs2_sparse_alloc(struct ocfs2_super * osb)515dcd0538fSMark Fasheh static inline int ocfs2_sparse_alloc(struct ocfs2_super *osb)
516dcd0538fSMark Fasheh {
517dcd0538fSMark Fasheh if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC)
518dcd0538fSMark Fasheh return 1;
519dcd0538fSMark Fasheh return 0;
520dcd0538fSMark Fasheh }
521dcd0538fSMark Fasheh
ocfs2_writes_unwritten_extents(struct ocfs2_super * osb)522328d5752SMark Fasheh static inline int ocfs2_writes_unwritten_extents(struct ocfs2_super *osb)
523328d5752SMark Fasheh {
524328d5752SMark Fasheh /*
525328d5752SMark Fasheh * Support for sparse files is a pre-requisite
526328d5752SMark Fasheh */
527328d5752SMark Fasheh if (!ocfs2_sparse_alloc(osb))
528328d5752SMark Fasheh return 0;
529328d5752SMark Fasheh
530328d5752SMark Fasheh if (osb->s_feature_ro_compat & OCFS2_FEATURE_RO_COMPAT_UNWRITTEN)
531328d5752SMark Fasheh return 1;
532328d5752SMark Fasheh return 0;
533328d5752SMark Fasheh }
534328d5752SMark Fasheh
ocfs2_supports_append_dio(struct ocfs2_super * osb)535160cc266SJoseph Qi static inline int ocfs2_supports_append_dio(struct ocfs2_super *osb)
536160cc266SJoseph Qi {
53718d585f0SMark Fasheh if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_APPEND_DIO)
538160cc266SJoseph Qi return 1;
539160cc266SJoseph Qi return 0;
540160cc266SJoseph Qi }
541160cc266SJoseph Qi
542160cc266SJoseph Qi
ocfs2_supports_inline_data(struct ocfs2_super * osb)54315b1e36bSMark Fasheh static inline int ocfs2_supports_inline_data(struct ocfs2_super *osb)
54415b1e36bSMark Fasheh {
54515b1e36bSMark Fasheh if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_INLINE_DATA)
54615b1e36bSMark Fasheh return 1;
54715b1e36bSMark Fasheh return 0;
54815b1e36bSMark Fasheh }
54915b1e36bSMark Fasheh
ocfs2_supports_xattr(struct ocfs2_super * osb)5508154da3dSTiger Yang static inline int ocfs2_supports_xattr(struct ocfs2_super *osb)
5518154da3dSTiger Yang {
5528154da3dSTiger Yang if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR)
5538154da3dSTiger Yang return 1;
5548154da3dSTiger Yang return 0;
5558154da3dSTiger Yang }
5568154da3dSTiger Yang
ocfs2_meta_ecc(struct ocfs2_super * osb)55770ad1ba7SJoel Becker static inline int ocfs2_meta_ecc(struct ocfs2_super *osb)
55870ad1ba7SJoel Becker {
55970ad1ba7SJoel Becker if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_META_ECC)
56070ad1ba7SJoel Becker return 1;
56170ad1ba7SJoel Becker return 0;
56270ad1ba7SJoel Becker }
56370ad1ba7SJoel Becker
ocfs2_supports_indexed_dirs(struct ocfs2_super * osb)5649b7895efSMark Fasheh static inline int ocfs2_supports_indexed_dirs(struct ocfs2_super *osb)
5659b7895efSMark Fasheh {
5669b7895efSMark Fasheh if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS)
5679b7895efSMark Fasheh return 1;
5689b7895efSMark Fasheh return 0;
5699b7895efSMark Fasheh }
5709b7895efSMark Fasheh
ocfs2_supports_discontig_bg(struct ocfs2_super * osb)5714711954eSTao Ma static inline int ocfs2_supports_discontig_bg(struct ocfs2_super *osb)
572798db35fSJoel Becker {
573798db35fSJoel Becker if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG)
574798db35fSJoel Becker return 1;
575798db35fSJoel Becker return 0;
576798db35fSJoel Becker }
577798db35fSJoel Becker
ocfs2_link_max(struct ocfs2_super * osb)578198a1ca3SMark Fasheh static inline unsigned int ocfs2_link_max(struct ocfs2_super *osb)
579198a1ca3SMark Fasheh {
580198a1ca3SMark Fasheh if (ocfs2_supports_indexed_dirs(osb))
581198a1ca3SMark Fasheh return OCFS2_DX_LINK_MAX;
582198a1ca3SMark Fasheh return OCFS2_LINK_MAX;
583198a1ca3SMark Fasheh }
584198a1ca3SMark Fasheh
ocfs2_read_links_count(struct ocfs2_dinode * di)585198a1ca3SMark Fasheh static inline unsigned int ocfs2_read_links_count(struct ocfs2_dinode *di)
586198a1ca3SMark Fasheh {
587198a1ca3SMark Fasheh u32 nlink = le16_to_cpu(di->i_links_count);
588198a1ca3SMark Fasheh u32 hi = le16_to_cpu(di->i_links_count_hi);
589198a1ca3SMark Fasheh
590198a1ca3SMark Fasheh nlink |= (hi << OCFS2_LINKS_HI_SHIFT);
591198a1ca3SMark Fasheh
592198a1ca3SMark Fasheh return nlink;
593198a1ca3SMark Fasheh }
594198a1ca3SMark Fasheh
ocfs2_set_links_count(struct ocfs2_dinode * di,u32 nlink)595198a1ca3SMark Fasheh static inline void ocfs2_set_links_count(struct ocfs2_dinode *di, u32 nlink)
596198a1ca3SMark Fasheh {
597198a1ca3SMark Fasheh u16 lo, hi;
598198a1ca3SMark Fasheh
599198a1ca3SMark Fasheh lo = nlink;
600198a1ca3SMark Fasheh hi = nlink >> OCFS2_LINKS_HI_SHIFT;
601198a1ca3SMark Fasheh
602198a1ca3SMark Fasheh di->i_links_count = cpu_to_le16(lo);
603198a1ca3SMark Fasheh di->i_links_count_hi = cpu_to_le16(hi);
604198a1ca3SMark Fasheh }
605198a1ca3SMark Fasheh
ocfs2_add_links_count(struct ocfs2_dinode * di,int n)606198a1ca3SMark Fasheh static inline void ocfs2_add_links_count(struct ocfs2_dinode *di, int n)
607198a1ca3SMark Fasheh {
608198a1ca3SMark Fasheh u32 links = ocfs2_read_links_count(di);
609198a1ca3SMark Fasheh
610198a1ca3SMark Fasheh links += n;
611198a1ca3SMark Fasheh
612198a1ca3SMark Fasheh ocfs2_set_links_count(di, links);
613198a1ca3SMark Fasheh }
614198a1ca3SMark Fasheh
ocfs2_refcount_tree(struct ocfs2_super * osb)6151aa75feaSTao Ma static inline int ocfs2_refcount_tree(struct ocfs2_super *osb)
6161aa75feaSTao Ma {
6171aa75feaSTao Ma if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE)
6181aa75feaSTao Ma return 1;
6191aa75feaSTao Ma return 0;
6201aa75feaSTao Ma }
6211aa75feaSTao Ma
622ccd979bdSMark Fasheh /* set / clear functions because cluster events can make these happen
623ccd979bdSMark Fasheh * in parallel so we want the transitions to be atomic. this also
624ccd979bdSMark Fasheh * means that any future flags osb_flags must be protected by spinlock
625ccd979bdSMark Fasheh * too! */
ocfs2_set_osb_flag(struct ocfs2_super * osb,unsigned long flag)626ccd979bdSMark Fasheh static inline void ocfs2_set_osb_flag(struct ocfs2_super *osb,
627ccd979bdSMark Fasheh unsigned long flag)
628ccd979bdSMark Fasheh {
629ccd979bdSMark Fasheh spin_lock(&osb->osb_lock);
630ccd979bdSMark Fasheh osb->osb_flags |= flag;
631ccd979bdSMark Fasheh spin_unlock(&osb->osb_lock);
632ccd979bdSMark Fasheh }
633ccd979bdSMark Fasheh
ocfs2_set_ro_flag(struct ocfs2_super * osb,int hard)634ccd979bdSMark Fasheh static inline void ocfs2_set_ro_flag(struct ocfs2_super *osb,
635ccd979bdSMark Fasheh int hard)
636ccd979bdSMark Fasheh {
637ccd979bdSMark Fasheh spin_lock(&osb->osb_lock);
638ccd979bdSMark Fasheh osb->osb_flags &= ~(OCFS2_OSB_SOFT_RO|OCFS2_OSB_HARD_RO);
639ccd979bdSMark Fasheh if (hard)
640ccd979bdSMark Fasheh osb->osb_flags |= OCFS2_OSB_HARD_RO;
641ccd979bdSMark Fasheh else
642ccd979bdSMark Fasheh osb->osb_flags |= OCFS2_OSB_SOFT_RO;
643ccd979bdSMark Fasheh spin_unlock(&osb->osb_lock);
644ccd979bdSMark Fasheh }
645ccd979bdSMark Fasheh
ocfs2_is_hard_readonly(struct ocfs2_super * osb)646ccd979bdSMark Fasheh static inline int ocfs2_is_hard_readonly(struct ocfs2_super *osb)
647ccd979bdSMark Fasheh {
648ccd979bdSMark Fasheh int ret;
649ccd979bdSMark Fasheh
650ccd979bdSMark Fasheh spin_lock(&osb->osb_lock);
651ccd979bdSMark Fasheh ret = osb->osb_flags & OCFS2_OSB_HARD_RO;
652ccd979bdSMark Fasheh spin_unlock(&osb->osb_lock);
653ccd979bdSMark Fasheh
654ccd979bdSMark Fasheh return ret;
655ccd979bdSMark Fasheh }
656ccd979bdSMark Fasheh
ocfs2_is_soft_readonly(struct ocfs2_super * osb)657ccd979bdSMark Fasheh static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb)
658ccd979bdSMark Fasheh {
659ccd979bdSMark Fasheh int ret;
660ccd979bdSMark Fasheh
661ccd979bdSMark Fasheh spin_lock(&osb->osb_lock);
662ccd979bdSMark Fasheh ret = osb->osb_flags & OCFS2_OSB_SOFT_RO;
663ccd979bdSMark Fasheh spin_unlock(&osb->osb_lock);
664ccd979bdSMark Fasheh
665ccd979bdSMark Fasheh return ret;
666ccd979bdSMark Fasheh }
667ccd979bdSMark Fasheh
ocfs2_clusterinfo_valid(struct ocfs2_super * osb)66898f486f2SSunil Mushran static inline int ocfs2_clusterinfo_valid(struct ocfs2_super *osb)
669b61817e1SJoel Becker {
670b61817e1SJoel Becker return (osb->s_feature_incompat &
67198f486f2SSunil Mushran (OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK |
67298f486f2SSunil Mushran OCFS2_FEATURE_INCOMPAT_CLUSTERINFO));
67398f486f2SSunil Mushran }
67498f486f2SSunil Mushran
ocfs2_userspace_stack(struct ocfs2_super * osb)67598f486f2SSunil Mushran static inline int ocfs2_userspace_stack(struct ocfs2_super *osb)
67698f486f2SSunil Mushran {
67798f486f2SSunil Mushran if (ocfs2_clusterinfo_valid(osb) &&
67898f486f2SSunil Mushran memcmp(osb->osb_cluster_stack, OCFS2_CLASSIC_CLUSTER_STACK,
67998f486f2SSunil Mushran OCFS2_STACK_LABEL_LEN))
68098f486f2SSunil Mushran return 1;
68198f486f2SSunil Mushran return 0;
68298f486f2SSunil Mushran }
68398f486f2SSunil Mushran
ocfs2_o2cb_stack(struct ocfs2_super * osb)68498f486f2SSunil Mushran static inline int ocfs2_o2cb_stack(struct ocfs2_super *osb)
68598f486f2SSunil Mushran {
68698f486f2SSunil Mushran if (ocfs2_clusterinfo_valid(osb) &&
68798f486f2SSunil Mushran !memcmp(osb->osb_cluster_stack, OCFS2_CLASSIC_CLUSTER_STACK,
68898f486f2SSunil Mushran OCFS2_STACK_LABEL_LEN))
68998f486f2SSunil Mushran return 1;
69098f486f2SSunil Mushran return 0;
69198f486f2SSunil Mushran }
69298f486f2SSunil Mushran
ocfs2_cluster_o2cb_global_heartbeat(struct ocfs2_super * osb)69398f486f2SSunil Mushran static inline int ocfs2_cluster_o2cb_global_heartbeat(struct ocfs2_super *osb)
69498f486f2SSunil Mushran {
69598f486f2SSunil Mushran return ocfs2_o2cb_stack(osb) &&
69698f486f2SSunil Mushran (osb->osb_stackflags & OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT);
697b61817e1SJoel Becker }
698b61817e1SJoel Becker
ocfs2_mount_local(struct ocfs2_super * osb)699c271c5c2SSunil Mushran static inline int ocfs2_mount_local(struct ocfs2_super *osb)
700c271c5c2SSunil Mushran {
701c80af0c2SJunxiao Bi return (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT);
702c271c5c2SSunil Mushran }
703c271c5c2SSunil Mushran
ocfs2_uses_extended_slot_map(struct ocfs2_super * osb)704386a2ef8SJoel Becker static inline int ocfs2_uses_extended_slot_map(struct ocfs2_super *osb)
705386a2ef8SJoel Becker {
706386a2ef8SJoel Becker return (osb->s_feature_incompat &
707386a2ef8SJoel Becker OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP);
708386a2ef8SJoel Becker }
709386a2ef8SJoel Becker
710386a2ef8SJoel Becker
711ccd979bdSMark Fasheh #define OCFS2_IS_VALID_DINODE(ptr) \
712ccd979bdSMark Fasheh (!strcmp((ptr)->i_signature, OCFS2_INODE_SIGNATURE))
713ccd979bdSMark Fasheh
714ccd979bdSMark Fasheh #define OCFS2_IS_VALID_EXTENT_BLOCK(ptr) \
715ccd979bdSMark Fasheh (!strcmp((ptr)->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE))
716ccd979bdSMark Fasheh
717ccd979bdSMark Fasheh #define OCFS2_IS_VALID_GROUP_DESC(ptr) \
718ccd979bdSMark Fasheh (!strcmp((ptr)->bg_signature, OCFS2_GROUP_DESC_SIGNATURE))
719ccd979bdSMark Fasheh
720ccd979bdSMark Fasheh
721f6087fb7SJoel Becker #define OCFS2_IS_VALID_XATTR_BLOCK(ptr) \
722f6087fb7SJoel Becker (!strcmp((ptr)->xb_signature, OCFS2_XATTR_BLOCK_SIGNATURE))
723f6087fb7SJoel Becker
72487d35a74SMark Fasheh #define OCFS2_IS_VALID_DIR_TRAILER(ptr) \
72587d35a74SMark Fasheh (!strcmp((ptr)->db_signature, OCFS2_DIR_TRAILER_SIGNATURE))
72687d35a74SMark Fasheh
7279b7895efSMark Fasheh #define OCFS2_IS_VALID_DX_ROOT(ptr) \
7289b7895efSMark Fasheh (!strcmp((ptr)->dr_signature, OCFS2_DX_ROOT_SIGNATURE))
7299b7895efSMark Fasheh
7309b7895efSMark Fasheh #define OCFS2_IS_VALID_DX_LEAF(ptr) \
7319b7895efSMark Fasheh (!strcmp((ptr)->dl_signature, OCFS2_DX_LEAF_SIGNATURE))
7329b7895efSMark Fasheh
733f2c870e3STao Ma #define OCFS2_IS_VALID_REFCOUNT_BLOCK(ptr) \
734f2c870e3STao Ma (!strcmp((ptr)->rf_signature, OCFS2_REFCOUNT_BLOCK_SIGNATURE))
735f2c870e3STao Ma
ino_from_blkno(struct super_block * sb,u64 blkno)736ccd979bdSMark Fasheh static inline unsigned long ino_from_blkno(struct super_block *sb,
737ccd979bdSMark Fasheh u64 blkno)
738ccd979bdSMark Fasheh {
739ccd979bdSMark Fasheh return (unsigned long)(blkno & (u64)ULONG_MAX);
740ccd979bdSMark Fasheh }
741ccd979bdSMark Fasheh
ocfs2_clusters_to_blocks(struct super_block * sb,u32 clusters)742ccd979bdSMark Fasheh static inline u64 ocfs2_clusters_to_blocks(struct super_block *sb,
743ccd979bdSMark Fasheh u32 clusters)
744ccd979bdSMark Fasheh {
745ccd979bdSMark Fasheh int c_to_b_bits = OCFS2_SB(sb)->s_clustersize_bits -
746ccd979bdSMark Fasheh sb->s_blocksize_bits;
747ccd979bdSMark Fasheh
748ccd979bdSMark Fasheh return (u64)clusters << c_to_b_bits;
749ccd979bdSMark Fasheh }
750ccd979bdSMark Fasheh
ocfs2_clusters_for_blocks(struct super_block * sb,u64 blocks)751ae1f0814SJoseph Qi static inline u32 ocfs2_clusters_for_blocks(struct super_block *sb,
752ae1f0814SJoseph Qi u64 blocks)
753ae1f0814SJoseph Qi {
754ae1f0814SJoseph Qi int b_to_c_bits = OCFS2_SB(sb)->s_clustersize_bits -
755ae1f0814SJoseph Qi sb->s_blocksize_bits;
756ae1f0814SJoseph Qi
757ae1f0814SJoseph Qi blocks += (1 << b_to_c_bits) - 1;
758ae1f0814SJoseph Qi return (u32)(blocks >> b_to_c_bits);
759ae1f0814SJoseph Qi }
760ae1f0814SJoseph Qi
ocfs2_blocks_to_clusters(struct super_block * sb,u64 blocks)761ccd979bdSMark Fasheh static inline u32 ocfs2_blocks_to_clusters(struct super_block *sb,
762ccd979bdSMark Fasheh u64 blocks)
763ccd979bdSMark Fasheh {
764ccd979bdSMark Fasheh int b_to_c_bits = OCFS2_SB(sb)->s_clustersize_bits -
765ccd979bdSMark Fasheh sb->s_blocksize_bits;
766ccd979bdSMark Fasheh
767ccd979bdSMark Fasheh return (u32)(blocks >> b_to_c_bits);
768ccd979bdSMark Fasheh }
769ccd979bdSMark Fasheh
ocfs2_clusters_for_bytes(struct super_block * sb,u64 bytes)770ccd979bdSMark Fasheh static inline unsigned int ocfs2_clusters_for_bytes(struct super_block *sb,
771ccd979bdSMark Fasheh u64 bytes)
772ccd979bdSMark Fasheh {
773ccd979bdSMark Fasheh int cl_bits = OCFS2_SB(sb)->s_clustersize_bits;
774ccd979bdSMark Fasheh unsigned int clusters;
775ccd979bdSMark Fasheh
776ccd979bdSMark Fasheh bytes += OCFS2_SB(sb)->s_clustersize - 1;
777ccd979bdSMark Fasheh /* OCFS2 just cannot have enough clusters to overflow this */
778ccd979bdSMark Fasheh clusters = (unsigned int)(bytes >> cl_bits);
779ccd979bdSMark Fasheh
780ccd979bdSMark Fasheh return clusters;
781ccd979bdSMark Fasheh }
782ccd979bdSMark Fasheh
ocfs2_bytes_to_clusters(struct super_block * sb,u64 bytes)78324c40b32SJoseph Qi static inline unsigned int ocfs2_bytes_to_clusters(struct super_block *sb,
78424c40b32SJoseph Qi u64 bytes)
78524c40b32SJoseph Qi {
78624c40b32SJoseph Qi int cl_bits = OCFS2_SB(sb)->s_clustersize_bits;
78724c40b32SJoseph Qi unsigned int clusters;
78824c40b32SJoseph Qi
78924c40b32SJoseph Qi clusters = (unsigned int)(bytes >> cl_bits);
79024c40b32SJoseph Qi return clusters;
79124c40b32SJoseph Qi }
79224c40b32SJoseph Qi
ocfs2_blocks_for_bytes(struct super_block * sb,u64 bytes)793ccd979bdSMark Fasheh static inline u64 ocfs2_blocks_for_bytes(struct super_block *sb,
794ccd979bdSMark Fasheh u64 bytes)
795ccd979bdSMark Fasheh {
796ccd979bdSMark Fasheh bytes += sb->s_blocksize - 1;
797ccd979bdSMark Fasheh return bytes >> sb->s_blocksize_bits;
798ccd979bdSMark Fasheh }
799ccd979bdSMark Fasheh
ocfs2_clusters_to_bytes(struct super_block * sb,u32 clusters)800ccd979bdSMark Fasheh static inline u64 ocfs2_clusters_to_bytes(struct super_block *sb,
801ccd979bdSMark Fasheh u32 clusters)
802ccd979bdSMark Fasheh {
803ccd979bdSMark Fasheh return (u64)clusters << OCFS2_SB(sb)->s_clustersize_bits;
804ccd979bdSMark Fasheh }
805ccd979bdSMark Fasheh
ocfs2_block_to_cluster_start(struct super_block * sb,u64 blocks)8061d46dc08SMark Fasheh static inline u64 ocfs2_block_to_cluster_start(struct super_block *sb,
8071d46dc08SMark Fasheh u64 blocks)
8081d46dc08SMark Fasheh {
8091d46dc08SMark Fasheh int bits = OCFS2_SB(sb)->s_clustersize_bits - sb->s_blocksize_bits;
8101d46dc08SMark Fasheh unsigned int clusters;
8111d46dc08SMark Fasheh
8121d46dc08SMark Fasheh clusters = ocfs2_blocks_to_clusters(sb, blocks);
8131d46dc08SMark Fasheh return (u64)clusters << bits;
8141d46dc08SMark Fasheh }
8151d46dc08SMark Fasheh
ocfs2_align_bytes_to_clusters(struct super_block * sb,u64 bytes)816ccd979bdSMark Fasheh static inline u64 ocfs2_align_bytes_to_clusters(struct super_block *sb,
817ccd979bdSMark Fasheh u64 bytes)
818ccd979bdSMark Fasheh {
819ccd979bdSMark Fasheh int cl_bits = OCFS2_SB(sb)->s_clustersize_bits;
820ccd979bdSMark Fasheh unsigned int clusters;
821ccd979bdSMark Fasheh
822ccd979bdSMark Fasheh clusters = ocfs2_clusters_for_bytes(sb, bytes);
823ccd979bdSMark Fasheh return (u64)clusters << cl_bits;
824ccd979bdSMark Fasheh }
825ccd979bdSMark Fasheh
ocfs2_align_bytes_to_blocks(struct super_block * sb,u64 bytes)826ccd979bdSMark Fasheh static inline u64 ocfs2_align_bytes_to_blocks(struct super_block *sb,
827ccd979bdSMark Fasheh u64 bytes)
828ccd979bdSMark Fasheh {
829ccd979bdSMark Fasheh u64 blocks;
830ccd979bdSMark Fasheh
831ccd979bdSMark Fasheh blocks = ocfs2_blocks_for_bytes(sb, bytes);
832ccd979bdSMark Fasheh return blocks << sb->s_blocksize_bits;
833ccd979bdSMark Fasheh }
834ccd979bdSMark Fasheh
ocfs2_align_bytes_to_sectors(u64 bytes)835ccd979bdSMark Fasheh static inline unsigned long ocfs2_align_bytes_to_sectors(u64 bytes)
836ccd979bdSMark Fasheh {
837ccd979bdSMark Fasheh return (unsigned long)((bytes + 511) >> 9);
838ccd979bdSMark Fasheh }
839ccd979bdSMark Fasheh
ocfs2_page_index_to_clusters(struct super_block * sb,unsigned long pg_index)8409517bac6SMark Fasheh static inline unsigned int ocfs2_page_index_to_clusters(struct super_block *sb,
8419517bac6SMark Fasheh unsigned long pg_index)
8429517bac6SMark Fasheh {
8439517bac6SMark Fasheh u32 clusters = pg_index;
8449517bac6SMark Fasheh unsigned int cbits = OCFS2_SB(sb)->s_clustersize_bits;
8459517bac6SMark Fasheh
84609cbfeafSKirill A. Shutemov if (unlikely(PAGE_SHIFT > cbits))
84709cbfeafSKirill A. Shutemov clusters = pg_index << (PAGE_SHIFT - cbits);
84809cbfeafSKirill A. Shutemov else if (PAGE_SHIFT < cbits)
84909cbfeafSKirill A. Shutemov clusters = pg_index >> (cbits - PAGE_SHIFT);
8509517bac6SMark Fasheh
8519517bac6SMark Fasheh return clusters;
8529517bac6SMark Fasheh }
8539517bac6SMark Fasheh
8549517bac6SMark Fasheh /*
8559517bac6SMark Fasheh * Find the 1st page index which covers the given clusters.
8569517bac6SMark Fasheh */
ocfs2_align_clusters_to_page_index(struct super_block * sb,u32 clusters)8577c08d70cSMark Fasheh static inline pgoff_t ocfs2_align_clusters_to_page_index(struct super_block *sb,
8589517bac6SMark Fasheh u32 clusters)
8599517bac6SMark Fasheh {
8609517bac6SMark Fasheh unsigned int cbits = OCFS2_SB(sb)->s_clustersize_bits;
8617c08d70cSMark Fasheh pgoff_t index = clusters;
8629517bac6SMark Fasheh
86309cbfeafSKirill A. Shutemov if (PAGE_SHIFT > cbits) {
86409cbfeafSKirill A. Shutemov index = (pgoff_t)clusters >> (PAGE_SHIFT - cbits);
86509cbfeafSKirill A. Shutemov } else if (PAGE_SHIFT < cbits) {
86609cbfeafSKirill A. Shutemov index = (pgoff_t)clusters << (cbits - PAGE_SHIFT);
8679517bac6SMark Fasheh }
8689517bac6SMark Fasheh
8699517bac6SMark Fasheh return index;
8709517bac6SMark Fasheh }
8719517bac6SMark Fasheh
ocfs2_pages_per_cluster(struct super_block * sb)87260b11392SMark Fasheh static inline unsigned int ocfs2_pages_per_cluster(struct super_block *sb)
87360b11392SMark Fasheh {
87460b11392SMark Fasheh unsigned int cbits = OCFS2_SB(sb)->s_clustersize_bits;
87560b11392SMark Fasheh unsigned int pages_per_cluster = 1;
87660b11392SMark Fasheh
87709cbfeafSKirill A. Shutemov if (PAGE_SHIFT < cbits)
87809cbfeafSKirill A. Shutemov pages_per_cluster = 1 << (cbits - PAGE_SHIFT);
87960b11392SMark Fasheh
88060b11392SMark Fasheh return pages_per_cluster;
88160b11392SMark Fasheh }
88260b11392SMark Fasheh
ocfs2_megabytes_to_clusters(struct super_block * sb,unsigned int megs)883ebcee4b5SMark Fasheh static inline unsigned int ocfs2_megabytes_to_clusters(struct super_block *sb,
884ebcee4b5SMark Fasheh unsigned int megs)
885ebcee4b5SMark Fasheh {
886ebcee4b5SMark Fasheh BUILD_BUG_ON(OCFS2_MAX_CLUSTERSIZE > 1048576);
887ebcee4b5SMark Fasheh
888ebcee4b5SMark Fasheh return megs << (20 - OCFS2_SB(sb)->s_clustersize_bits);
889ebcee4b5SMark Fasheh }
890ebcee4b5SMark Fasheh
ocfs2_clusters_to_megabytes(struct super_block * sb,unsigned int clusters)89173c8a800SMark Fasheh static inline unsigned int ocfs2_clusters_to_megabytes(struct super_block *sb,
89273c8a800SMark Fasheh unsigned int clusters)
89373c8a800SMark Fasheh {
89473c8a800SMark Fasheh return clusters >> (20 - OCFS2_SB(sb)->s_clustersize_bits);
89573c8a800SMark Fasheh }
89673c8a800SMark Fasheh
_ocfs2_set_bit(unsigned int bit,unsigned long * bitmap)897b4414eeaSMark Fasheh static inline void _ocfs2_set_bit(unsigned int bit, unsigned long *bitmap)
898b4414eeaSMark Fasheh {
899730e663bSAkinobu Mita __set_bit_le(bit, bitmap);
900b4414eeaSMark Fasheh }
901b4414eeaSMark Fasheh #define ocfs2_set_bit(bit, addr) _ocfs2_set_bit((bit), (unsigned long *)(addr))
902b4414eeaSMark Fasheh
_ocfs2_clear_bit(unsigned int bit,unsigned long * bitmap)903b4414eeaSMark Fasheh static inline void _ocfs2_clear_bit(unsigned int bit, unsigned long *bitmap)
904b4414eeaSMark Fasheh {
905730e663bSAkinobu Mita __clear_bit_le(bit, bitmap);
906b4414eeaSMark Fasheh }
907b4414eeaSMark Fasheh #define ocfs2_clear_bit(bit, addr) _ocfs2_clear_bit((bit), (unsigned long *)(addr))
908b4414eeaSMark Fasheh
909c4354d0dSAkinobu Mita #define ocfs2_test_bit test_bit_le
910c4354d0dSAkinobu Mita #define ocfs2_find_next_zero_bit find_next_zero_bit_le
911c4354d0dSAkinobu Mita #define ocfs2_find_next_bit find_next_bit_le
91293925579SAkinobu Mita
correct_addr_and_bit_unaligned(int * bit,void * addr)91393925579SAkinobu Mita static inline void *correct_addr_and_bit_unaligned(int *bit, void *addr)
91493925579SAkinobu Mita {
91593925579SAkinobu Mita #if BITS_PER_LONG == 64
91693925579SAkinobu Mita *bit += ((unsigned long) addr & 7UL) << 3;
91793925579SAkinobu Mita addr = (void *) ((unsigned long) addr & ~7UL);
91893925579SAkinobu Mita #elif BITS_PER_LONG == 32
91993925579SAkinobu Mita *bit += ((unsigned long) addr & 3UL) << 3;
92093925579SAkinobu Mita addr = (void *) ((unsigned long) addr & ~3UL);
92193925579SAkinobu Mita #else
92293925579SAkinobu Mita #error "how many bits you are?!"
92393925579SAkinobu Mita #endif
92493925579SAkinobu Mita return addr;
92593925579SAkinobu Mita }
92693925579SAkinobu Mita
ocfs2_set_bit_unaligned(int bit,void * bitmap)92793925579SAkinobu Mita static inline void ocfs2_set_bit_unaligned(int bit, void *bitmap)
92893925579SAkinobu Mita {
92993925579SAkinobu Mita bitmap = correct_addr_and_bit_unaligned(&bit, bitmap);
93093925579SAkinobu Mita ocfs2_set_bit(bit, bitmap);
93193925579SAkinobu Mita }
93293925579SAkinobu Mita
ocfs2_clear_bit_unaligned(int bit,void * bitmap)93393925579SAkinobu Mita static inline void ocfs2_clear_bit_unaligned(int bit, void *bitmap)
93493925579SAkinobu Mita {
93593925579SAkinobu Mita bitmap = correct_addr_and_bit_unaligned(&bit, bitmap);
93693925579SAkinobu Mita ocfs2_clear_bit(bit, bitmap);
93793925579SAkinobu Mita }
93893925579SAkinobu Mita
ocfs2_test_bit_unaligned(int bit,void * bitmap)93993925579SAkinobu Mita static inline int ocfs2_test_bit_unaligned(int bit, void *bitmap)
94093925579SAkinobu Mita {
94193925579SAkinobu Mita bitmap = correct_addr_and_bit_unaligned(&bit, bitmap);
94293925579SAkinobu Mita return ocfs2_test_bit(bit, bitmap);
94393925579SAkinobu Mita }
94493925579SAkinobu Mita
ocfs2_find_next_zero_bit_unaligned(void * bitmap,int max,int start)94593925579SAkinobu Mita static inline int ocfs2_find_next_zero_bit_unaligned(void *bitmap, int max,
94693925579SAkinobu Mita int start)
94793925579SAkinobu Mita {
94893925579SAkinobu Mita int fix = 0, ret, tmpmax;
94993925579SAkinobu Mita bitmap = correct_addr_and_bit_unaligned(&fix, bitmap);
95093925579SAkinobu Mita tmpmax = max + fix;
95193925579SAkinobu Mita start += fix;
95293925579SAkinobu Mita
95393925579SAkinobu Mita ret = ocfs2_find_next_zero_bit(bitmap, tmpmax, start) - fix;
95493925579SAkinobu Mita if (ret > max)
95593925579SAkinobu Mita return max;
95693925579SAkinobu Mita return ret;
95793925579SAkinobu Mita }
95893925579SAkinobu Mita
959ccd979bdSMark Fasheh #endif /* OCFS2_H */
960ccd979bdSMark Fasheh
961