30 #include <linux/sched.h>
31 #include <linux/wait.h>
32 #include <linux/list.h>
33 #include <linux/rbtree.h>
59 #define OCFS2_CACHE_INFO_MAX_ARRAY 2
99 #define OCFS2_NODE_MAP_MAX_NODES 256
120 #define OCFS2_LOCK_ATTACHED (0x00000001)
122 #define OCFS2_LOCK_BUSY (0x00000002)
124 #define OCFS2_LOCK_BLOCKED (0x00000004)
126 #define OCFS2_LOCK_LOCAL (0x00000008)
127 #define OCFS2_LOCK_NEEDS_REFRESH (0x00000010)
128 #define OCFS2_LOCK_REFRESHING (0x00000020)
129 #define OCFS2_LOCK_INITIALIZED (0x00000040)
131 #define OCFS2_LOCK_FREEING (0x00000080)
136 #define OCFS2_LOCK_QUEUED (0x00000100)
137 #define OCFS2_LOCK_NOCACHE (0x00000200)
138 #define OCFS2_LOCK_PENDING (0x00000400)
141 #define OCFS2_LOCK_UPCONVERT_FINISHING (0x00000800)
150 #ifdef CONFIG_OCFS2_FS_STATS
151 struct ocfs2_lock_stats {
195 #ifdef CONFIG_OCFS2_FS_STATS
196 struct ocfs2_lock_stats l_lock_prmode;
198 struct ocfs2_lock_stats l_lock_exmode;
200 #ifdef CONFIG_DEBUG_LOCK_ALLOC
201 struct lockdep_map l_lockdep_map;
222 struct kref d_refcnt;
277 #define OCFS2_OSB_SOFT_RO 0x0001
278 #define OCFS2_OSB_HARD_RO 0x0002
279 #define OCFS2_OSB_ERROR_FS 0x0004
280 #define OCFS2_OSB_DROP_DENTRY_LOCK_IMMED 0x0008
282 #define OCFS2_DEFAULT_ATIME_QUANTUM 60
454 #define OCFS2_SB(sb) ((struct ocfs2_super *)(sb)->s_fs_info)
459 struct buffer_head *bh,
int type);
461 static inline int ocfs2_should_order_data(
struct inode *
inode)
470 static inline int ocfs2_sparse_alloc(
struct ocfs2_super *osb)
477 static inline int ocfs2_writes_unwritten_extents(
struct ocfs2_super *osb)
482 if (!ocfs2_sparse_alloc(osb))
490 static inline int ocfs2_supports_inline_data(
struct ocfs2_super *osb)
497 static inline int ocfs2_supports_xattr(
struct ocfs2_super *osb)
504 static inline int ocfs2_meta_ecc(
struct ocfs2_super *osb)
511 static inline int ocfs2_supports_indexed_dirs(
struct ocfs2_super *osb)
518 static inline int ocfs2_supports_discontig_bg(
struct ocfs2_super *osb)
525 static inline unsigned int ocfs2_link_max(
struct ocfs2_super *osb)
527 if (ocfs2_supports_indexed_dirs(osb))
532 static inline unsigned int ocfs2_read_links_count(
struct ocfs2_dinode *di)
543 static inline void ocfs2_set_links_count(
struct ocfs2_dinode *di,
u32 nlink)
554 static inline void ocfs2_add_links_count(
struct ocfs2_dinode *di,
int n)
556 u32 links = ocfs2_read_links_count(di);
560 ocfs2_set_links_count(di, links);
574 static inline void ocfs2_set_osb_flag(
struct ocfs2_super *osb,
583 static inline unsigned long ocfs2_test_osb_flag(
struct ocfs2_super *osb,
594 static inline void ocfs2_set_ro_flag(
struct ocfs2_super *osb,
606 static inline int ocfs2_is_hard_readonly(
struct ocfs2_super *osb)
617 static inline int ocfs2_is_soft_readonly(
struct ocfs2_super *osb)
628 static inline int ocfs2_clusterinfo_valid(
struct ocfs2_super *osb)
635 static inline int ocfs2_userspace_stack(
struct ocfs2_super *osb)
637 if (ocfs2_clusterinfo_valid(osb) &&
644 static inline int ocfs2_o2cb_stack(
struct ocfs2_super *osb)
646 if (ocfs2_clusterinfo_valid(osb) &&
653 static inline int ocfs2_cluster_o2cb_global_heartbeat(
struct ocfs2_super *osb)
655 return ocfs2_o2cb_stack(osb) &&
659 static inline int ocfs2_mount_local(
struct ocfs2_super *osb)
664 static inline int ocfs2_uses_extended_slot_map(
struct ocfs2_super *osb)
671 #define OCFS2_IS_VALID_DINODE(ptr) \
672 (!strcmp((ptr)->i_signature, OCFS2_INODE_SIGNATURE))
674 #define OCFS2_IS_VALID_EXTENT_BLOCK(ptr) \
675 (!strcmp((ptr)->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE))
677 #define OCFS2_IS_VALID_GROUP_DESC(ptr) \
678 (!strcmp((ptr)->bg_signature, OCFS2_GROUP_DESC_SIGNATURE))
681 #define OCFS2_IS_VALID_XATTR_BLOCK(ptr) \
682 (!strcmp((ptr)->xb_signature, OCFS2_XATTR_BLOCK_SIGNATURE))
684 #define OCFS2_IS_VALID_DIR_TRAILER(ptr) \
685 (!strcmp((ptr)->db_signature, OCFS2_DIR_TRAILER_SIGNATURE))
687 #define OCFS2_IS_VALID_DX_ROOT(ptr) \
688 (!strcmp((ptr)->dr_signature, OCFS2_DX_ROOT_SIGNATURE))
690 #define OCFS2_IS_VALID_DX_LEAF(ptr) \
691 (!strcmp((ptr)->dl_signature, OCFS2_DX_LEAF_SIGNATURE))
693 #define OCFS2_IS_VALID_REFCOUNT_BLOCK(ptr) \
694 (!strcmp((ptr)->rf_signature, OCFS2_REFCOUNT_BLOCK_SIGNATURE))
696 static inline unsigned long ino_from_blkno(
struct super_block *
sb,
705 int c_to_b_bits =
OCFS2_SB(sb)->s_clustersize_bits -
708 return (
u64)clusters << c_to_b_bits;
711 static inline u32 ocfs2_blocks_to_clusters(
struct super_block *sb,
714 int b_to_c_bits =
OCFS2_SB(sb)->s_clustersize_bits -
717 return (
u32)(blocks >> b_to_c_bits);
720 static inline unsigned int ocfs2_clusters_for_bytes(
struct super_block *sb,
723 int cl_bits =
OCFS2_SB(sb)->s_clustersize_bits;
724 unsigned int clusters;
726 bytes +=
OCFS2_SB(sb)->s_clustersize - 1;
728 clusters = (
unsigned int)(bytes >> cl_bits);
743 return (
u64)clusters <<
OCFS2_SB(sb)->s_clustersize_bits;
746 static inline u64 ocfs2_block_to_cluster_start(
struct super_block *sb,
750 unsigned int clusters;
752 clusters = ocfs2_blocks_to_clusters(sb, blocks);
756 static inline u64 ocfs2_align_bytes_to_clusters(
struct super_block *sb,
759 int cl_bits =
OCFS2_SB(sb)->s_clustersize_bits;
760 unsigned int clusters;
762 clusters = ocfs2_clusters_for_bytes(sb, bytes);
763 return (
u64)clusters << cl_bits;
766 static inline u64 ocfs2_align_bytes_to_blocks(
struct super_block *sb,
771 blocks = ocfs2_blocks_for_bytes(sb, bytes);
775 static inline unsigned long ocfs2_align_bytes_to_sectors(
u64 bytes)
777 return (
unsigned long)((bytes + 511) >> 9);
780 static inline unsigned int ocfs2_page_index_to_clusters(
struct super_block *sb,
781 unsigned long pg_index)
783 u32 clusters = pg_index;
784 unsigned int cbits =
OCFS2_SB(sb)->s_clustersize_bits;
800 unsigned int cbits =
OCFS2_SB(sb)->s_clustersize_bits;
812 static inline unsigned int ocfs2_pages_per_cluster(
struct super_block *sb)
814 unsigned int cbits =
OCFS2_SB(sb)->s_clustersize_bits;
815 unsigned int pages_per_cluster = 1;
820 return pages_per_cluster;
823 static inline unsigned int ocfs2_megabytes_to_clusters(
struct super_block *sb,
828 return megs << (20 -
OCFS2_SB(sb)->s_clustersize_bits);
831 static inline unsigned int ocfs2_clusters_to_megabytes(
struct super_block *sb,
832 unsigned int clusters)
834 return clusters >> (20 -
OCFS2_SB(sb)->s_clustersize_bits);
837 static inline void _ocfs2_set_bit(
unsigned int bit,
unsigned long *
bitmap)
839 __set_bit_le(bit, bitmap);
841 #define ocfs2_set_bit(bit, addr) _ocfs2_set_bit((bit), (unsigned long *)(addr))
843 static inline void _ocfs2_clear_bit(
unsigned int bit,
unsigned long *
bitmap)
845 __clear_bit_le(bit, bitmap);
847 #define ocfs2_clear_bit(bit, addr) _ocfs2_clear_bit((bit), (unsigned long *)(addr))
849 #define ocfs2_test_bit test_bit_le
850 #define ocfs2_find_next_zero_bit find_next_zero_bit_le
851 #define ocfs2_find_next_bit find_next_bit_le
853 static inline void *correct_addr_and_bit_unaligned(
int *
bit,
void *
addr)
855 #if BITS_PER_LONG == 64
856 *bit += ((
unsigned long) addr & 7
UL) << 3;
857 addr = (
void *) ((
unsigned long) addr & ~7
UL);
858 #elif BITS_PER_LONG == 32
859 *bit += ((
unsigned long) addr & 3UL) << 3;
860 addr = (
void *) ((
unsigned long) addr & ~3
UL);
862 #error "how many bits you are?!"
867 static inline void ocfs2_set_bit_unaligned(
int bit,
void *
bitmap)
869 bitmap = correct_addr_and_bit_unaligned(&bit, bitmap);
873 static inline void ocfs2_clear_bit_unaligned(
int bit,
void *
bitmap)
875 bitmap = correct_addr_and_bit_unaligned(&bit, bitmap);
879 static inline int ocfs2_test_bit_unaligned(
int bit,
void *
bitmap)
881 bitmap = correct_addr_and_bit_unaligned(&bit, bitmap);
885 static inline int ocfs2_find_next_zero_bit_unaligned(
void *
bitmap,
int max,
888 int fix = 0,
ret, tmpmax;
889 bitmap = correct_addr_and_bit_unaligned(&fix, bitmap);