Commit 7d39db14a42cbd719c7515b9da8f85a2eb6a0633

Authored by Theodore Ts'o
1 parent 9f24e4208f

ext4: Use struct flex_groups to calculate get_orlov_stats()

Instead of looping over all of the block groups in a flex group
summing their summary statistics, start tracking used_dirs in struct
flex_groups, and use struct flex_groups instead.  This should save a
bit of CPU for mkdir-heavy workloads.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

Showing 3 changed files with 31 additions and 17 deletions Inline Diff

1 /* 1 /*
2 * ext4.h 2 * ext4.h
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal 6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI) 7 * Universite Pierre et Marie Curie (Paris VI)
8 * 8 *
9 * from 9 * from
10 * 10 *
11 * linux/include/linux/minix_fs.h 11 * linux/include/linux/minix_fs.h
12 * 12 *
13 * Copyright (C) 1991, 1992 Linus Torvalds 13 * Copyright (C) 1991, 1992 Linus Torvalds
14 */ 14 */
15 15
16 #ifndef _EXT4_H 16 #ifndef _EXT4_H
17 #define _EXT4_H 17 #define _EXT4_H
18 18
19 #include <linux/types.h> 19 #include <linux/types.h>
20 #include <linux/blkdev.h> 20 #include <linux/blkdev.h>
21 #include <linux/magic.h> 21 #include <linux/magic.h>
22 #include <linux/jbd2.h> 22 #include <linux/jbd2.h>
23 #include <linux/quota.h> 23 #include <linux/quota.h>
24 #include "ext4_i.h" 24 #include "ext4_i.h"
25 25
26 /* 26 /*
27 * The fourth extended filesystem constants/structures 27 * The fourth extended filesystem constants/structures
28 */ 28 */
29 29
30 /* 30 /*
31 * Define EXT4FS_DEBUG to produce debug messages 31 * Define EXT4FS_DEBUG to produce debug messages
32 */ 32 */
33 #undef EXT4FS_DEBUG 33 #undef EXT4FS_DEBUG
34 34
35 /* 35 /*
36 * Debug code 36 * Debug code
37 */ 37 */
38 #ifdef EXT4FS_DEBUG 38 #ifdef EXT4FS_DEBUG
39 #define ext4_debug(f, a...) \ 39 #define ext4_debug(f, a...) \
40 do { \ 40 do { \
41 printk(KERN_DEBUG "EXT4-fs DEBUG (%s, %d): %s:", \ 41 printk(KERN_DEBUG "EXT4-fs DEBUG (%s, %d): %s:", \
42 __FILE__, __LINE__, __func__); \ 42 __FILE__, __LINE__, __func__); \
43 printk(KERN_DEBUG f, ## a); \ 43 printk(KERN_DEBUG f, ## a); \
44 } while (0) 44 } while (0)
45 #else 45 #else
46 #define ext4_debug(f, a...) do {} while (0) 46 #define ext4_debug(f, a...) do {} while (0)
47 #endif 47 #endif
48 48
49 /* prefer goal again. length */ 49 /* prefer goal again. length */
50 #define EXT4_MB_HINT_MERGE 1 50 #define EXT4_MB_HINT_MERGE 1
51 /* blocks already reserved */ 51 /* blocks already reserved */
52 #define EXT4_MB_HINT_RESERVED 2 52 #define EXT4_MB_HINT_RESERVED 2
53 /* metadata is being allocated */ 53 /* metadata is being allocated */
54 #define EXT4_MB_HINT_METADATA 4 54 #define EXT4_MB_HINT_METADATA 4
55 /* first blocks in the file */ 55 /* first blocks in the file */
56 #define EXT4_MB_HINT_FIRST 8 56 #define EXT4_MB_HINT_FIRST 8
57 /* search for the best chunk */ 57 /* search for the best chunk */
58 #define EXT4_MB_HINT_BEST 16 58 #define EXT4_MB_HINT_BEST 16
59 /* data is being allocated */ 59 /* data is being allocated */
60 #define EXT4_MB_HINT_DATA 32 60 #define EXT4_MB_HINT_DATA 32
61 /* don't preallocate (for tails) */ 61 /* don't preallocate (for tails) */
62 #define EXT4_MB_HINT_NOPREALLOC 64 62 #define EXT4_MB_HINT_NOPREALLOC 64
63 /* allocate for locality group */ 63 /* allocate for locality group */
64 #define EXT4_MB_HINT_GROUP_ALLOC 128 64 #define EXT4_MB_HINT_GROUP_ALLOC 128
65 /* allocate goal blocks or none */ 65 /* allocate goal blocks or none */
66 #define EXT4_MB_HINT_GOAL_ONLY 256 66 #define EXT4_MB_HINT_GOAL_ONLY 256
67 /* goal is meaningful */ 67 /* goal is meaningful */
68 #define EXT4_MB_HINT_TRY_GOAL 512 68 #define EXT4_MB_HINT_TRY_GOAL 512
69 /* blocks already pre-reserved by delayed allocation */ 69 /* blocks already pre-reserved by delayed allocation */
70 #define EXT4_MB_DELALLOC_RESERVED 1024 70 #define EXT4_MB_DELALLOC_RESERVED 1024
71 71
72 72
73 struct ext4_allocation_request { 73 struct ext4_allocation_request {
74 /* target inode for block we're allocating */ 74 /* target inode for block we're allocating */
75 struct inode *inode; 75 struct inode *inode;
76 /* logical block in target inode */ 76 /* logical block in target inode */
77 ext4_lblk_t logical; 77 ext4_lblk_t logical;
78 /* phys. target (a hint) */ 78 /* phys. target (a hint) */
79 ext4_fsblk_t goal; 79 ext4_fsblk_t goal;
80 /* the closest logical allocated block to the left */ 80 /* the closest logical allocated block to the left */
81 ext4_lblk_t lleft; 81 ext4_lblk_t lleft;
82 /* phys. block for ^^^ */ 82 /* phys. block for ^^^ */
83 ext4_fsblk_t pleft; 83 ext4_fsblk_t pleft;
84 /* the closest logical allocated block to the right */ 84 /* the closest logical allocated block to the right */
85 ext4_lblk_t lright; 85 ext4_lblk_t lright;
86 /* phys. block for ^^^ */ 86 /* phys. block for ^^^ */
87 ext4_fsblk_t pright; 87 ext4_fsblk_t pright;
88 /* how many blocks we want to allocate */ 88 /* how many blocks we want to allocate */
89 unsigned int len; 89 unsigned int len;
90 /* flags. see above EXT4_MB_HINT_* */ 90 /* flags. see above EXT4_MB_HINT_* */
91 unsigned int flags; 91 unsigned int flags;
92 }; 92 };
93 93
94 /* 94 /*
95 * Special inodes numbers 95 * Special inodes numbers
96 */ 96 */
97 #define EXT4_BAD_INO 1 /* Bad blocks inode */ 97 #define EXT4_BAD_INO 1 /* Bad blocks inode */
98 #define EXT4_ROOT_INO 2 /* Root inode */ 98 #define EXT4_ROOT_INO 2 /* Root inode */
99 #define EXT4_BOOT_LOADER_INO 5 /* Boot loader inode */ 99 #define EXT4_BOOT_LOADER_INO 5 /* Boot loader inode */
100 #define EXT4_UNDEL_DIR_INO 6 /* Undelete directory inode */ 100 #define EXT4_UNDEL_DIR_INO 6 /* Undelete directory inode */
101 #define EXT4_RESIZE_INO 7 /* Reserved group descriptors inode */ 101 #define EXT4_RESIZE_INO 7 /* Reserved group descriptors inode */
102 #define EXT4_JOURNAL_INO 8 /* Journal inode */ 102 #define EXT4_JOURNAL_INO 8 /* Journal inode */
103 103
104 /* First non-reserved inode for old ext4 filesystems */ 104 /* First non-reserved inode for old ext4 filesystems */
105 #define EXT4_GOOD_OLD_FIRST_INO 11 105 #define EXT4_GOOD_OLD_FIRST_INO 11
106 106
107 /* 107 /*
108 * Maximal count of links to a file 108 * Maximal count of links to a file
109 */ 109 */
110 #define EXT4_LINK_MAX 65000 110 #define EXT4_LINK_MAX 65000
111 111
112 /* 112 /*
113 * Macro-instructions used to manage several block sizes 113 * Macro-instructions used to manage several block sizes
114 */ 114 */
115 #define EXT4_MIN_BLOCK_SIZE 1024 115 #define EXT4_MIN_BLOCK_SIZE 1024
116 #define EXT4_MAX_BLOCK_SIZE 65536 116 #define EXT4_MAX_BLOCK_SIZE 65536
117 #define EXT4_MIN_BLOCK_LOG_SIZE 10 117 #define EXT4_MIN_BLOCK_LOG_SIZE 10
118 #ifdef __KERNEL__ 118 #ifdef __KERNEL__
119 # define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize) 119 # define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize)
120 #else 120 #else
121 # define EXT4_BLOCK_SIZE(s) (EXT4_MIN_BLOCK_SIZE << (s)->s_log_block_size) 121 # define EXT4_BLOCK_SIZE(s) (EXT4_MIN_BLOCK_SIZE << (s)->s_log_block_size)
122 #endif 122 #endif
123 #define EXT4_ADDR_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof(__u32)) 123 #define EXT4_ADDR_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof(__u32))
124 #ifdef __KERNEL__ 124 #ifdef __KERNEL__
125 # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits) 125 # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
126 #else 126 #else
127 # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10) 127 # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
128 #endif 128 #endif
129 #ifdef __KERNEL__ 129 #ifdef __KERNEL__
130 #define EXT4_ADDR_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_addr_per_block_bits) 130 #define EXT4_ADDR_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_addr_per_block_bits)
131 #define EXT4_INODE_SIZE(s) (EXT4_SB(s)->s_inode_size) 131 #define EXT4_INODE_SIZE(s) (EXT4_SB(s)->s_inode_size)
132 #define EXT4_FIRST_INO(s) (EXT4_SB(s)->s_first_ino) 132 #define EXT4_FIRST_INO(s) (EXT4_SB(s)->s_first_ino)
133 #else 133 #else
134 #define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \ 134 #define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
135 EXT4_GOOD_OLD_INODE_SIZE : \ 135 EXT4_GOOD_OLD_INODE_SIZE : \
136 (s)->s_inode_size) 136 (s)->s_inode_size)
137 #define EXT4_FIRST_INO(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \ 137 #define EXT4_FIRST_INO(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
138 EXT4_GOOD_OLD_FIRST_INO : \ 138 EXT4_GOOD_OLD_FIRST_INO : \
139 (s)->s_first_ino) 139 (s)->s_first_ino)
140 #endif 140 #endif
141 #define EXT4_BLOCK_ALIGN(size, blkbits) ALIGN((size), (1 << (blkbits))) 141 #define EXT4_BLOCK_ALIGN(size, blkbits) ALIGN((size), (1 << (blkbits)))
142 142
143 /* 143 /*
144 * Structure of a blocks group descriptor 144 * Structure of a blocks group descriptor
145 */ 145 */
146 struct ext4_group_desc 146 struct ext4_group_desc
147 { 147 {
148 __le32 bg_block_bitmap_lo; /* Blocks bitmap block */ 148 __le32 bg_block_bitmap_lo; /* Blocks bitmap block */
149 __le32 bg_inode_bitmap_lo; /* Inodes bitmap block */ 149 __le32 bg_inode_bitmap_lo; /* Inodes bitmap block */
150 __le32 bg_inode_table_lo; /* Inodes table block */ 150 __le32 bg_inode_table_lo; /* Inodes table block */
151 __le16 bg_free_blocks_count_lo;/* Free blocks count */ 151 __le16 bg_free_blocks_count_lo;/* Free blocks count */
152 __le16 bg_free_inodes_count_lo;/* Free inodes count */ 152 __le16 bg_free_inodes_count_lo;/* Free inodes count */
153 __le16 bg_used_dirs_count_lo; /* Directories count */ 153 __le16 bg_used_dirs_count_lo; /* Directories count */
154 __le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */ 154 __le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */
155 __u32 bg_reserved[2]; /* Likely block/inode bitmap checksum */ 155 __u32 bg_reserved[2]; /* Likely block/inode bitmap checksum */
156 __le16 bg_itable_unused_lo; /* Unused inodes count */ 156 __le16 bg_itable_unused_lo; /* Unused inodes count */
157 __le16 bg_checksum; /* crc16(sb_uuid+group+desc) */ 157 __le16 bg_checksum; /* crc16(sb_uuid+group+desc) */
158 __le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */ 158 __le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */
159 __le32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */ 159 __le32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */
160 __le32 bg_inode_table_hi; /* Inodes table block MSB */ 160 __le32 bg_inode_table_hi; /* Inodes table block MSB */
161 __le16 bg_free_blocks_count_hi;/* Free blocks count MSB */ 161 __le16 bg_free_blocks_count_hi;/* Free blocks count MSB */
162 __le16 bg_free_inodes_count_hi;/* Free inodes count MSB */ 162 __le16 bg_free_inodes_count_hi;/* Free inodes count MSB */
163 __le16 bg_used_dirs_count_hi; /* Directories count MSB */ 163 __le16 bg_used_dirs_count_hi; /* Directories count MSB */
164 __le16 bg_itable_unused_hi; /* Unused inodes count MSB */ 164 __le16 bg_itable_unused_hi; /* Unused inodes count MSB */
165 __u32 bg_reserved2[3]; 165 __u32 bg_reserved2[3];
166 }; 166 };
167 167
168 /* 168 /*
169 * Structure of a flex block group info 169 * Structure of a flex block group info
170 */ 170 */
171 171
172 struct flex_groups { 172 struct flex_groups {
173 atomic_t free_inodes; 173 atomic_t free_inodes;
174 atomic_t free_blocks; 174 atomic_t free_blocks;
175 atomic_t used_dirs;
175 }; 176 };
176 177
177 #define EXT4_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */ 178 #define EXT4_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */
178 #define EXT4_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */ 179 #define EXT4_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */
179 #define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ 180 #define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */
180 181
181 #ifdef __KERNEL__ 182 #ifdef __KERNEL__
182 #include "ext4_sb.h" 183 #include "ext4_sb.h"
183 #endif 184 #endif
184 /* 185 /*
185 * Macro-instructions used to manage group descriptors 186 * Macro-instructions used to manage group descriptors
186 */ 187 */
187 #define EXT4_MIN_DESC_SIZE 32 188 #define EXT4_MIN_DESC_SIZE 32
188 #define EXT4_MIN_DESC_SIZE_64BIT 64 189 #define EXT4_MIN_DESC_SIZE_64BIT 64
189 #define EXT4_MAX_DESC_SIZE EXT4_MIN_BLOCK_SIZE 190 #define EXT4_MAX_DESC_SIZE EXT4_MIN_BLOCK_SIZE
190 #define EXT4_DESC_SIZE(s) (EXT4_SB(s)->s_desc_size) 191 #define EXT4_DESC_SIZE(s) (EXT4_SB(s)->s_desc_size)
191 #ifdef __KERNEL__ 192 #ifdef __KERNEL__
192 # define EXT4_BLOCKS_PER_GROUP(s) (EXT4_SB(s)->s_blocks_per_group) 193 # define EXT4_BLOCKS_PER_GROUP(s) (EXT4_SB(s)->s_blocks_per_group)
193 # define EXT4_DESC_PER_BLOCK(s) (EXT4_SB(s)->s_desc_per_block) 194 # define EXT4_DESC_PER_BLOCK(s) (EXT4_SB(s)->s_desc_per_block)
194 # define EXT4_INODES_PER_GROUP(s) (EXT4_SB(s)->s_inodes_per_group) 195 # define EXT4_INODES_PER_GROUP(s) (EXT4_SB(s)->s_inodes_per_group)
195 # define EXT4_DESC_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_desc_per_block_bits) 196 # define EXT4_DESC_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_desc_per_block_bits)
196 #else 197 #else
197 # define EXT4_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group) 198 # define EXT4_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
198 # define EXT4_DESC_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / EXT4_DESC_SIZE(s)) 199 # define EXT4_DESC_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / EXT4_DESC_SIZE(s))
199 # define EXT4_INODES_PER_GROUP(s) ((s)->s_inodes_per_group) 200 # define EXT4_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
200 #endif 201 #endif
201 202
202 /* 203 /*
203 * Constants relative to the data blocks 204 * Constants relative to the data blocks
204 */ 205 */
205 #define EXT4_NDIR_BLOCKS 12 206 #define EXT4_NDIR_BLOCKS 12
206 #define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS 207 #define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS
207 #define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1) 208 #define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1)
208 #define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1) 209 #define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1)
209 #define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1) 210 #define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1)
210 211
211 /* 212 /*
212 * Inode flags 213 * Inode flags
213 */ 214 */
214 #define EXT4_SECRM_FL 0x00000001 /* Secure deletion */ 215 #define EXT4_SECRM_FL 0x00000001 /* Secure deletion */
215 #define EXT4_UNRM_FL 0x00000002 /* Undelete */ 216 #define EXT4_UNRM_FL 0x00000002 /* Undelete */
216 #define EXT4_COMPR_FL 0x00000004 /* Compress file */ 217 #define EXT4_COMPR_FL 0x00000004 /* Compress file */
217 #define EXT4_SYNC_FL 0x00000008 /* Synchronous updates */ 218 #define EXT4_SYNC_FL 0x00000008 /* Synchronous updates */
218 #define EXT4_IMMUTABLE_FL 0x00000010 /* Immutable file */ 219 #define EXT4_IMMUTABLE_FL 0x00000010 /* Immutable file */
219 #define EXT4_APPEND_FL 0x00000020 /* writes to file may only append */ 220 #define EXT4_APPEND_FL 0x00000020 /* writes to file may only append */
220 #define EXT4_NODUMP_FL 0x00000040 /* do not dump file */ 221 #define EXT4_NODUMP_FL 0x00000040 /* do not dump file */
221 #define EXT4_NOATIME_FL 0x00000080 /* do not update atime */ 222 #define EXT4_NOATIME_FL 0x00000080 /* do not update atime */
222 /* Reserved for compression usage... */ 223 /* Reserved for compression usage... */
223 #define EXT4_DIRTY_FL 0x00000100 224 #define EXT4_DIRTY_FL 0x00000100
224 #define EXT4_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ 225 #define EXT4_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
225 #define EXT4_NOCOMPR_FL 0x00000400 /* Don't compress */ 226 #define EXT4_NOCOMPR_FL 0x00000400 /* Don't compress */
226 #define EXT4_ECOMPR_FL 0x00000800 /* Compression error */ 227 #define EXT4_ECOMPR_FL 0x00000800 /* Compression error */
227 /* End compression flags --- maybe not all used */ 228 /* End compression flags --- maybe not all used */
228 #define EXT4_INDEX_FL 0x00001000 /* hash-indexed directory */ 229 #define EXT4_INDEX_FL 0x00001000 /* hash-indexed directory */
229 #define EXT4_IMAGIC_FL 0x00002000 /* AFS directory */ 230 #define EXT4_IMAGIC_FL 0x00002000 /* AFS directory */
230 #define EXT4_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */ 231 #define EXT4_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
231 #define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */ 232 #define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */
232 #define EXT4_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 233 #define EXT4_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
233 #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ 234 #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
234 #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ 235 #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */
235 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ 236 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
236 #define EXT4_EXT_MIGRATE 0x00100000 /* Inode is migrating */ 237 #define EXT4_EXT_MIGRATE 0x00100000 /* Inode is migrating */
237 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */ 238 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
238 239
239 #define EXT4_FL_USER_VISIBLE 0x000BDFFF /* User visible flags */ 240 #define EXT4_FL_USER_VISIBLE 0x000BDFFF /* User visible flags */
240 #define EXT4_FL_USER_MODIFIABLE 0x000B80FF /* User modifiable flags */ 241 #define EXT4_FL_USER_MODIFIABLE 0x000B80FF /* User modifiable flags */
241 242
242 /* Flags that should be inherited by new inodes from their parent. */ 243 /* Flags that should be inherited by new inodes from their parent. */
243 #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\ 244 #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\
244 EXT4_SYNC_FL | EXT4_IMMUTABLE_FL | EXT4_APPEND_FL |\ 245 EXT4_SYNC_FL | EXT4_IMMUTABLE_FL | EXT4_APPEND_FL |\
245 EXT4_NODUMP_FL | EXT4_NOATIME_FL |\ 246 EXT4_NODUMP_FL | EXT4_NOATIME_FL |\
246 EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\ 247 EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\
247 EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL) 248 EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL)
248 249
249 /* Flags that are appropriate for regular files (all but dir-specific ones). */ 250 /* Flags that are appropriate for regular files (all but dir-specific ones). */
250 #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL)) 251 #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL))
251 252
252 /* Flags that are appropriate for non-directories/regular files. */ 253 /* Flags that are appropriate for non-directories/regular files. */
253 #define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL) 254 #define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL)
254 255
255 /* Mask out flags that are inappropriate for the given type of inode. */ 256 /* Mask out flags that are inappropriate for the given type of inode. */
256 static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags) 257 static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags)
257 { 258 {
258 if (S_ISDIR(mode)) 259 if (S_ISDIR(mode))
259 return flags; 260 return flags;
260 else if (S_ISREG(mode)) 261 else if (S_ISREG(mode))
261 return flags & EXT4_REG_FLMASK; 262 return flags & EXT4_REG_FLMASK;
262 else 263 else
263 return flags & EXT4_OTHER_FLMASK; 264 return flags & EXT4_OTHER_FLMASK;
264 } 265 }
265 266
266 /* 267 /*
267 * Inode dynamic state flags 268 * Inode dynamic state flags
268 */ 269 */
269 #define EXT4_STATE_JDATA 0x00000001 /* journaled data exists */ 270 #define EXT4_STATE_JDATA 0x00000001 /* journaled data exists */
270 #define EXT4_STATE_NEW 0x00000002 /* inode is newly created */ 271 #define EXT4_STATE_NEW 0x00000002 /* inode is newly created */
271 #define EXT4_STATE_XATTR 0x00000004 /* has in-inode xattrs */ 272 #define EXT4_STATE_XATTR 0x00000004 /* has in-inode xattrs */
272 #define EXT4_STATE_NO_EXPAND 0x00000008 /* No space for expansion */ 273 #define EXT4_STATE_NO_EXPAND 0x00000008 /* No space for expansion */
273 #define EXT4_STATE_DA_ALLOC_CLOSE 0x00000010 /* Alloc DA blks on close */ 274 #define EXT4_STATE_DA_ALLOC_CLOSE 0x00000010 /* Alloc DA blks on close */
274 275
275 /* Used to pass group descriptor data when online resize is done */ 276 /* Used to pass group descriptor data when online resize is done */
276 struct ext4_new_group_input { 277 struct ext4_new_group_input {
277 __u32 group; /* Group number for this data */ 278 __u32 group; /* Group number for this data */
278 __u64 block_bitmap; /* Absolute block number of block bitmap */ 279 __u64 block_bitmap; /* Absolute block number of block bitmap */
279 __u64 inode_bitmap; /* Absolute block number of inode bitmap */ 280 __u64 inode_bitmap; /* Absolute block number of inode bitmap */
280 __u64 inode_table; /* Absolute block number of inode table start */ 281 __u64 inode_table; /* Absolute block number of inode table start */
281 __u32 blocks_count; /* Total number of blocks in this group */ 282 __u32 blocks_count; /* Total number of blocks in this group */
282 __u16 reserved_blocks; /* Number of reserved blocks in this group */ 283 __u16 reserved_blocks; /* Number of reserved blocks in this group */
283 __u16 unused; 284 __u16 unused;
284 }; 285 };
285 286
286 /* The struct ext4_new_group_input in kernel space, with free_blocks_count */ 287 /* The struct ext4_new_group_input in kernel space, with free_blocks_count */
287 struct ext4_new_group_data { 288 struct ext4_new_group_data {
288 __u32 group; 289 __u32 group;
289 __u64 block_bitmap; 290 __u64 block_bitmap;
290 __u64 inode_bitmap; 291 __u64 inode_bitmap;
291 __u64 inode_table; 292 __u64 inode_table;
292 __u32 blocks_count; 293 __u32 blocks_count;
293 __u16 reserved_blocks; 294 __u16 reserved_blocks;
294 __u16 unused; 295 __u16 unused;
295 __u32 free_blocks_count; 296 __u32 free_blocks_count;
296 }; 297 };
297 298
298 /* 299 /*
299 * Following is used by preallocation code to tell get_blocks() that we 300 * Following is used by preallocation code to tell get_blocks() that we
300 * want uninitialzed extents. 301 * want uninitialzed extents.
301 */ 302 */
302 #define EXT4_CREATE_UNINITIALIZED_EXT 2 303 #define EXT4_CREATE_UNINITIALIZED_EXT 2
303 304
304 /* 305 /*
305 * ioctl commands 306 * ioctl commands
306 */ 307 */
307 #define EXT4_IOC_GETFLAGS FS_IOC_GETFLAGS 308 #define EXT4_IOC_GETFLAGS FS_IOC_GETFLAGS
308 #define EXT4_IOC_SETFLAGS FS_IOC_SETFLAGS 309 #define EXT4_IOC_SETFLAGS FS_IOC_SETFLAGS
309 #define EXT4_IOC_GETVERSION _IOR('f', 3, long) 310 #define EXT4_IOC_GETVERSION _IOR('f', 3, long)
310 #define EXT4_IOC_SETVERSION _IOW('f', 4, long) 311 #define EXT4_IOC_SETVERSION _IOW('f', 4, long)
311 #define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION 312 #define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION
312 #define EXT4_IOC_SETVERSION_OLD FS_IOC_SETVERSION 313 #define EXT4_IOC_SETVERSION_OLD FS_IOC_SETVERSION
313 #ifdef CONFIG_JBD2_DEBUG 314 #ifdef CONFIG_JBD2_DEBUG
314 #define EXT4_IOC_WAIT_FOR_READONLY _IOR('f', 99, long) 315 #define EXT4_IOC_WAIT_FOR_READONLY _IOR('f', 99, long)
315 #endif 316 #endif
316 #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long) 317 #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long)
317 #define EXT4_IOC_SETRSVSZ _IOW('f', 6, long) 318 #define EXT4_IOC_SETRSVSZ _IOW('f', 6, long)
318 #define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long) 319 #define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long)
319 #define EXT4_IOC_GROUP_ADD _IOW('f', 8, struct ext4_new_group_input) 320 #define EXT4_IOC_GROUP_ADD _IOW('f', 8, struct ext4_new_group_input)
320 #define EXT4_IOC_MIGRATE _IO('f', 9) 321 #define EXT4_IOC_MIGRATE _IO('f', 9)
321 /* note ioctl 10 reserved for an early version of the FIEMAP ioctl */ 322 /* note ioctl 10 reserved for an early version of the FIEMAP ioctl */
322 /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */ 323 /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */
323 #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12) 324 #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12)
324 325
325 /* 326 /*
326 * ioctl commands in 32 bit emulation 327 * ioctl commands in 32 bit emulation
327 */ 328 */
328 #define EXT4_IOC32_GETFLAGS FS_IOC32_GETFLAGS 329 #define EXT4_IOC32_GETFLAGS FS_IOC32_GETFLAGS
329 #define EXT4_IOC32_SETFLAGS FS_IOC32_SETFLAGS 330 #define EXT4_IOC32_SETFLAGS FS_IOC32_SETFLAGS
330 #define EXT4_IOC32_GETVERSION _IOR('f', 3, int) 331 #define EXT4_IOC32_GETVERSION _IOR('f', 3, int)
331 #define EXT4_IOC32_SETVERSION _IOW('f', 4, int) 332 #define EXT4_IOC32_SETVERSION _IOW('f', 4, int)
332 #define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int) 333 #define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int)
333 #define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int) 334 #define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int)
334 #define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int) 335 #define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int)
335 #ifdef CONFIG_JBD2_DEBUG 336 #ifdef CONFIG_JBD2_DEBUG
336 #define EXT4_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int) 337 #define EXT4_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int)
337 #endif 338 #endif
338 #define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION 339 #define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION
339 #define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION 340 #define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION
340 341
341 342
342 /* 343 /*
343 * Mount options 344 * Mount options
344 */ 345 */
345 struct ext4_mount_options { 346 struct ext4_mount_options {
346 unsigned long s_mount_opt; 347 unsigned long s_mount_opt;
347 uid_t s_resuid; 348 uid_t s_resuid;
348 gid_t s_resgid; 349 gid_t s_resgid;
349 unsigned long s_commit_interval; 350 unsigned long s_commit_interval;
350 u32 s_min_batch_time, s_max_batch_time; 351 u32 s_min_batch_time, s_max_batch_time;
351 #ifdef CONFIG_QUOTA 352 #ifdef CONFIG_QUOTA
352 int s_jquota_fmt; 353 int s_jquota_fmt;
353 char *s_qf_names[MAXQUOTAS]; 354 char *s_qf_names[MAXQUOTAS];
354 #endif 355 #endif
355 }; 356 };
356 357
357 /* 358 /*
358 * Structure of an inode on the disk 359 * Structure of an inode on the disk
359 */ 360 */
360 struct ext4_inode { 361 struct ext4_inode {
361 __le16 i_mode; /* File mode */ 362 __le16 i_mode; /* File mode */
362 __le16 i_uid; /* Low 16 bits of Owner Uid */ 363 __le16 i_uid; /* Low 16 bits of Owner Uid */
363 __le32 i_size_lo; /* Size in bytes */ 364 __le32 i_size_lo; /* Size in bytes */
364 __le32 i_atime; /* Access time */ 365 __le32 i_atime; /* Access time */
365 __le32 i_ctime; /* Inode Change time */ 366 __le32 i_ctime; /* Inode Change time */
366 __le32 i_mtime; /* Modification time */ 367 __le32 i_mtime; /* Modification time */
367 __le32 i_dtime; /* Deletion Time */ 368 __le32 i_dtime; /* Deletion Time */
368 __le16 i_gid; /* Low 16 bits of Group Id */ 369 __le16 i_gid; /* Low 16 bits of Group Id */
369 __le16 i_links_count; /* Links count */ 370 __le16 i_links_count; /* Links count */
370 __le32 i_blocks_lo; /* Blocks count */ 371 __le32 i_blocks_lo; /* Blocks count */
371 __le32 i_flags; /* File flags */ 372 __le32 i_flags; /* File flags */
372 union { 373 union {
373 struct { 374 struct {
374 __le32 l_i_version; 375 __le32 l_i_version;
375 } linux1; 376 } linux1;
376 struct { 377 struct {
377 __u32 h_i_translator; 378 __u32 h_i_translator;
378 } hurd1; 379 } hurd1;
379 struct { 380 struct {
380 __u32 m_i_reserved1; 381 __u32 m_i_reserved1;
381 } masix1; 382 } masix1;
382 } osd1; /* OS dependent 1 */ 383 } osd1; /* OS dependent 1 */
383 __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */ 384 __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */
384 __le32 i_generation; /* File version (for NFS) */ 385 __le32 i_generation; /* File version (for NFS) */
385 __le32 i_file_acl_lo; /* File ACL */ 386 __le32 i_file_acl_lo; /* File ACL */
386 __le32 i_size_high; 387 __le32 i_size_high;
387 __le32 i_obso_faddr; /* Obsoleted fragment address */ 388 __le32 i_obso_faddr; /* Obsoleted fragment address */
388 union { 389 union {
389 struct { 390 struct {
390 __le16 l_i_blocks_high; /* were l_i_reserved1 */ 391 __le16 l_i_blocks_high; /* were l_i_reserved1 */
391 __le16 l_i_file_acl_high; 392 __le16 l_i_file_acl_high;
392 __le16 l_i_uid_high; /* these 2 fields */ 393 __le16 l_i_uid_high; /* these 2 fields */
393 __le16 l_i_gid_high; /* were reserved2[0] */ 394 __le16 l_i_gid_high; /* were reserved2[0] */
394 __u32 l_i_reserved2; 395 __u32 l_i_reserved2;
395 } linux2; 396 } linux2;
396 struct { 397 struct {
397 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ 398 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
398 __u16 h_i_mode_high; 399 __u16 h_i_mode_high;
399 __u16 h_i_uid_high; 400 __u16 h_i_uid_high;
400 __u16 h_i_gid_high; 401 __u16 h_i_gid_high;
401 __u32 h_i_author; 402 __u32 h_i_author;
402 } hurd2; 403 } hurd2;
403 struct { 404 struct {
404 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ 405 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
405 __le16 m_i_file_acl_high; 406 __le16 m_i_file_acl_high;
406 __u32 m_i_reserved2[2]; 407 __u32 m_i_reserved2[2];
407 } masix2; 408 } masix2;
408 } osd2; /* OS dependent 2 */ 409 } osd2; /* OS dependent 2 */
409 __le16 i_extra_isize; 410 __le16 i_extra_isize;
410 __le16 i_pad1; 411 __le16 i_pad1;
411 __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */ 412 __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */
412 __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */ 413 __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */
413 __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ 414 __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */
414 __le32 i_crtime; /* File Creation time */ 415 __le32 i_crtime; /* File Creation time */
415 __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */ 416 __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */
416 __le32 i_version_hi; /* high 32 bits for 64-bit version */ 417 __le32 i_version_hi; /* high 32 bits for 64-bit version */
417 }; 418 };
418 419
419 420
420 #define EXT4_EPOCH_BITS 2 421 #define EXT4_EPOCH_BITS 2
421 #define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1) 422 #define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1)
422 #define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS) 423 #define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS)
423 424
424 /* 425 /*
425 * Extended fields will fit into an inode if the filesystem was formatted 426 * Extended fields will fit into an inode if the filesystem was formatted
426 * with large inodes (-I 256 or larger) and there are not currently any EAs 427 * with large inodes (-I 256 or larger) and there are not currently any EAs
427 * consuming all of the available space. For new inodes we always reserve 428 * consuming all of the available space. For new inodes we always reserve
428 * enough space for the kernel's known extended fields, but for inodes 429 * enough space for the kernel's known extended fields, but for inodes
429 * created with an old kernel this might not have been the case. None of 430 * created with an old kernel this might not have been the case. None of
430 * the extended inode fields is critical for correct filesystem operation. 431 * the extended inode fields is critical for correct filesystem operation.
431 * This macro checks if a certain field fits in the inode. Note that 432 * This macro checks if a certain field fits in the inode. Note that
432 * inode-size = GOOD_OLD_INODE_SIZE + i_extra_isize 433 * inode-size = GOOD_OLD_INODE_SIZE + i_extra_isize
433 */ 434 */
434 #define EXT4_FITS_IN_INODE(ext4_inode, einode, field) \ 435 #define EXT4_FITS_IN_INODE(ext4_inode, einode, field) \
435 ((offsetof(typeof(*ext4_inode), field) + \ 436 ((offsetof(typeof(*ext4_inode), field) + \
436 sizeof((ext4_inode)->field)) \ 437 sizeof((ext4_inode)->field)) \
437 <= (EXT4_GOOD_OLD_INODE_SIZE + \ 438 <= (EXT4_GOOD_OLD_INODE_SIZE + \
438 (einode)->i_extra_isize)) \ 439 (einode)->i_extra_isize)) \
439 440
440 static inline __le32 ext4_encode_extra_time(struct timespec *time) 441 static inline __le32 ext4_encode_extra_time(struct timespec *time)
441 { 442 {
442 return cpu_to_le32((sizeof(time->tv_sec) > 4 ? 443 return cpu_to_le32((sizeof(time->tv_sec) > 4 ?
443 time->tv_sec >> 32 : 0) | 444 time->tv_sec >> 32 : 0) |
444 ((time->tv_nsec << 2) & EXT4_NSEC_MASK)); 445 ((time->tv_nsec << 2) & EXT4_NSEC_MASK));
445 } 446 }
446 447
447 static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra) 448 static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra)
448 { 449 {
449 if (sizeof(time->tv_sec) > 4) 450 if (sizeof(time->tv_sec) > 4)
450 time->tv_sec |= (__u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) 451 time->tv_sec |= (__u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK)
451 << 32; 452 << 32;
452 time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> 2; 453 time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> 2;
453 } 454 }
454 455
455 #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \ 456 #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \
456 do { \ 457 do { \
457 (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \ 458 (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \
458 if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \ 459 if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \
459 (raw_inode)->xtime ## _extra = \ 460 (raw_inode)->xtime ## _extra = \
460 ext4_encode_extra_time(&(inode)->xtime); \ 461 ext4_encode_extra_time(&(inode)->xtime); \
461 } while (0) 462 } while (0)
462 463
463 #define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \ 464 #define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \
464 do { \ 465 do { \
465 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 466 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
466 (raw_inode)->xtime = cpu_to_le32((einode)->xtime.tv_sec); \ 467 (raw_inode)->xtime = cpu_to_le32((einode)->xtime.tv_sec); \
467 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \ 468 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \
468 (raw_inode)->xtime ## _extra = \ 469 (raw_inode)->xtime ## _extra = \
469 ext4_encode_extra_time(&(einode)->xtime); \ 470 ext4_encode_extra_time(&(einode)->xtime); \
470 } while (0) 471 } while (0)
471 472
472 #define EXT4_INODE_GET_XTIME(xtime, inode, raw_inode) \ 473 #define EXT4_INODE_GET_XTIME(xtime, inode, raw_inode) \
473 do { \ 474 do { \
474 (inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \ 475 (inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \
475 if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \ 476 if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \
476 ext4_decode_extra_time(&(inode)->xtime, \ 477 ext4_decode_extra_time(&(inode)->xtime, \
477 raw_inode->xtime ## _extra); \ 478 raw_inode->xtime ## _extra); \
478 } while (0) 479 } while (0)
479 480
480 #define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \ 481 #define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \
481 do { \ 482 do { \
482 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 483 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
483 (einode)->xtime.tv_sec = \ 484 (einode)->xtime.tv_sec = \
484 (signed)le32_to_cpu((raw_inode)->xtime); \ 485 (signed)le32_to_cpu((raw_inode)->xtime); \
485 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \ 486 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \
486 ext4_decode_extra_time(&(einode)->xtime, \ 487 ext4_decode_extra_time(&(einode)->xtime, \
487 raw_inode->xtime ## _extra); \ 488 raw_inode->xtime ## _extra); \
488 } while (0) 489 } while (0)
489 490
490 #define i_disk_version osd1.linux1.l_i_version 491 #define i_disk_version osd1.linux1.l_i_version
491 492
492 #if defined(__KERNEL__) || defined(__linux__) 493 #if defined(__KERNEL__) || defined(__linux__)
493 #define i_reserved1 osd1.linux1.l_i_reserved1 494 #define i_reserved1 osd1.linux1.l_i_reserved1
494 #define i_file_acl_high osd2.linux2.l_i_file_acl_high 495 #define i_file_acl_high osd2.linux2.l_i_file_acl_high
495 #define i_blocks_high osd2.linux2.l_i_blocks_high 496 #define i_blocks_high osd2.linux2.l_i_blocks_high
496 #define i_uid_low i_uid 497 #define i_uid_low i_uid
497 #define i_gid_low i_gid 498 #define i_gid_low i_gid
498 #define i_uid_high osd2.linux2.l_i_uid_high 499 #define i_uid_high osd2.linux2.l_i_uid_high
499 #define i_gid_high osd2.linux2.l_i_gid_high 500 #define i_gid_high osd2.linux2.l_i_gid_high
500 #define i_reserved2 osd2.linux2.l_i_reserved2 501 #define i_reserved2 osd2.linux2.l_i_reserved2
501 502
502 #elif defined(__GNU__) 503 #elif defined(__GNU__)
503 504
504 #define i_translator osd1.hurd1.h_i_translator 505 #define i_translator osd1.hurd1.h_i_translator
505 #define i_uid_high osd2.hurd2.h_i_uid_high 506 #define i_uid_high osd2.hurd2.h_i_uid_high
506 #define i_gid_high osd2.hurd2.h_i_gid_high 507 #define i_gid_high osd2.hurd2.h_i_gid_high
507 #define i_author osd2.hurd2.h_i_author 508 #define i_author osd2.hurd2.h_i_author
508 509
509 #elif defined(__masix__) 510 #elif defined(__masix__)
510 511
511 #define i_reserved1 osd1.masix1.m_i_reserved1 512 #define i_reserved1 osd1.masix1.m_i_reserved1
512 #define i_file_acl_high osd2.masix2.m_i_file_acl_high 513 #define i_file_acl_high osd2.masix2.m_i_file_acl_high
513 #define i_reserved2 osd2.masix2.m_i_reserved2 514 #define i_reserved2 osd2.masix2.m_i_reserved2
514 515
515 #endif /* defined(__KERNEL__) || defined(__linux__) */ 516 #endif /* defined(__KERNEL__) || defined(__linux__) */
516 517
517 /* 518 /*
518 * File system states 519 * File system states
519 */ 520 */
520 #define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */ 521 #define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */
521 #define EXT4_ERROR_FS 0x0002 /* Errors detected */ 522 #define EXT4_ERROR_FS 0x0002 /* Errors detected */
522 #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */ 523 #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */
523 524
524 /* 525 /*
525 * Misc. filesystem flags 526 * Misc. filesystem flags
526 */ 527 */
527 #define EXT2_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */ 528 #define EXT2_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */
528 #define EXT2_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */ 529 #define EXT2_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */
529 #define EXT2_FLAGS_TEST_FILESYS 0x0004 /* to test development code */ 530 #define EXT2_FLAGS_TEST_FILESYS 0x0004 /* to test development code */
530 531
531 /* 532 /*
532 * Mount flags 533 * Mount flags
533 */ 534 */
534 #define EXT4_MOUNT_OLDALLOC 0x00002 /* Don't use the new Orlov allocator */ 535 #define EXT4_MOUNT_OLDALLOC 0x00002 /* Don't use the new Orlov allocator */
535 #define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */ 536 #define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */
536 #define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */ 537 #define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */
537 #define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */ 538 #define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */
538 #define EXT4_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */ 539 #define EXT4_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */
539 #define EXT4_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */ 540 #define EXT4_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */
540 #define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */ 541 #define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */
541 #define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/ 542 #define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/
542 #define EXT4_MOUNT_ABORT 0x00200 /* Fatal error detected */ 543 #define EXT4_MOUNT_ABORT 0x00200 /* Fatal error detected */
543 #define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */ 544 #define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */
544 #define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */ 545 #define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */
545 #define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */ 546 #define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */
546 #define EXT4_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */ 547 #define EXT4_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */
547 #define EXT4_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */ 548 #define EXT4_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */
548 #define EXT4_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */ 549 #define EXT4_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */
549 #define EXT4_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */ 550 #define EXT4_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */
550 #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */ 551 #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
551 #define EXT4_MOUNT_RESERVATION 0x10000 /* Preallocation */ 552 #define EXT4_MOUNT_RESERVATION 0x10000 /* Preallocation */
552 #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */ 553 #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
553 #define EXT4_MOUNT_NOBH 0x40000 /* No bufferheads */ 554 #define EXT4_MOUNT_NOBH 0x40000 /* No bufferheads */
554 #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */ 555 #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
555 #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */ 556 #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
556 #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */ 557 #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
557 #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */ 558 #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */
558 #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */ 559 #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */
559 #define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */ 560 #define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */
560 #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */ 561 #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */
561 #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */ 562 #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */
562 563
563 /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */ 564 /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
564 #ifndef _LINUX_EXT2_FS_H 565 #ifndef _LINUX_EXT2_FS_H
565 #define clear_opt(o, opt) o &= ~EXT4_MOUNT_##opt 566 #define clear_opt(o, opt) o &= ~EXT4_MOUNT_##opt
566 #define set_opt(o, opt) o |= EXT4_MOUNT_##opt 567 #define set_opt(o, opt) o |= EXT4_MOUNT_##opt
567 #define test_opt(sb, opt) (EXT4_SB(sb)->s_mount_opt & \ 568 #define test_opt(sb, opt) (EXT4_SB(sb)->s_mount_opt & \
568 EXT4_MOUNT_##opt) 569 EXT4_MOUNT_##opt)
569 #else 570 #else
570 #define EXT2_MOUNT_NOLOAD EXT4_MOUNT_NOLOAD 571 #define EXT2_MOUNT_NOLOAD EXT4_MOUNT_NOLOAD
571 #define EXT2_MOUNT_ABORT EXT4_MOUNT_ABORT 572 #define EXT2_MOUNT_ABORT EXT4_MOUNT_ABORT
572 #define EXT2_MOUNT_DATA_FLAGS EXT4_MOUNT_DATA_FLAGS 573 #define EXT2_MOUNT_DATA_FLAGS EXT4_MOUNT_DATA_FLAGS
573 #endif 574 #endif
574 575
575 #define ext4_set_bit ext2_set_bit 576 #define ext4_set_bit ext2_set_bit
576 #define ext4_set_bit_atomic ext2_set_bit_atomic 577 #define ext4_set_bit_atomic ext2_set_bit_atomic
577 #define ext4_clear_bit ext2_clear_bit 578 #define ext4_clear_bit ext2_clear_bit
578 #define ext4_clear_bit_atomic ext2_clear_bit_atomic 579 #define ext4_clear_bit_atomic ext2_clear_bit_atomic
579 #define ext4_test_bit ext2_test_bit 580 #define ext4_test_bit ext2_test_bit
580 #define ext4_find_first_zero_bit ext2_find_first_zero_bit 581 #define ext4_find_first_zero_bit ext2_find_first_zero_bit
581 #define ext4_find_next_zero_bit ext2_find_next_zero_bit 582 #define ext4_find_next_zero_bit ext2_find_next_zero_bit
582 #define ext4_find_next_bit ext2_find_next_bit 583 #define ext4_find_next_bit ext2_find_next_bit
583 584
584 /* 585 /*
585 * Maximal mount counts between two filesystem checks 586 * Maximal mount counts between two filesystem checks
586 */ 587 */
587 #define EXT4_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */ 588 #define EXT4_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
588 #define EXT4_DFL_CHECKINTERVAL 0 /* Don't use interval check */ 589 #define EXT4_DFL_CHECKINTERVAL 0 /* Don't use interval check */
589 590
590 /* 591 /*
591 * Behaviour when detecting errors 592 * Behaviour when detecting errors
592 */ 593 */
593 #define EXT4_ERRORS_CONTINUE 1 /* Continue execution */ 594 #define EXT4_ERRORS_CONTINUE 1 /* Continue execution */
594 #define EXT4_ERRORS_RO 2 /* Remount fs read-only */ 595 #define EXT4_ERRORS_RO 2 /* Remount fs read-only */
595 #define EXT4_ERRORS_PANIC 3 /* Panic */ 596 #define EXT4_ERRORS_PANIC 3 /* Panic */
596 #define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE 597 #define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE
597 598
598 /* 599 /*
599 * Structure of the super block 600 * Structure of the super block
600 */ 601 */
601 struct ext4_super_block { 602 struct ext4_super_block {
602 /*00*/ __le32 s_inodes_count; /* Inodes count */ 603 /*00*/ __le32 s_inodes_count; /* Inodes count */
603 __le32 s_blocks_count_lo; /* Blocks count */ 604 __le32 s_blocks_count_lo; /* Blocks count */
604 __le32 s_r_blocks_count_lo; /* Reserved blocks count */ 605 __le32 s_r_blocks_count_lo; /* Reserved blocks count */
605 __le32 s_free_blocks_count_lo; /* Free blocks count */ 606 __le32 s_free_blocks_count_lo; /* Free blocks count */
606 /*10*/ __le32 s_free_inodes_count; /* Free inodes count */ 607 /*10*/ __le32 s_free_inodes_count; /* Free inodes count */
607 __le32 s_first_data_block; /* First Data Block */ 608 __le32 s_first_data_block; /* First Data Block */
608 __le32 s_log_block_size; /* Block size */ 609 __le32 s_log_block_size; /* Block size */
609 __le32 s_obso_log_frag_size; /* Obsoleted fragment size */ 610 __le32 s_obso_log_frag_size; /* Obsoleted fragment size */
610 /*20*/ __le32 s_blocks_per_group; /* # Blocks per group */ 611 /*20*/ __le32 s_blocks_per_group; /* # Blocks per group */
611 __le32 s_obso_frags_per_group; /* Obsoleted fragments per group */ 612 __le32 s_obso_frags_per_group; /* Obsoleted fragments per group */
612 __le32 s_inodes_per_group; /* # Inodes per group */ 613 __le32 s_inodes_per_group; /* # Inodes per group */
613 __le32 s_mtime; /* Mount time */ 614 __le32 s_mtime; /* Mount time */
614 /*30*/ __le32 s_wtime; /* Write time */ 615 /*30*/ __le32 s_wtime; /* Write time */
615 __le16 s_mnt_count; /* Mount count */ 616 __le16 s_mnt_count; /* Mount count */
616 __le16 s_max_mnt_count; /* Maximal mount count */ 617 __le16 s_max_mnt_count; /* Maximal mount count */
617 __le16 s_magic; /* Magic signature */ 618 __le16 s_magic; /* Magic signature */
618 __le16 s_state; /* File system state */ 619 __le16 s_state; /* File system state */
619 __le16 s_errors; /* Behaviour when detecting errors */ 620 __le16 s_errors; /* Behaviour when detecting errors */
620 __le16 s_minor_rev_level; /* minor revision level */ 621 __le16 s_minor_rev_level; /* minor revision level */
621 /*40*/ __le32 s_lastcheck; /* time of last check */ 622 /*40*/ __le32 s_lastcheck; /* time of last check */
622 __le32 s_checkinterval; /* max. time between checks */ 623 __le32 s_checkinterval; /* max. time between checks */
623 __le32 s_creator_os; /* OS */ 624 __le32 s_creator_os; /* OS */
624 __le32 s_rev_level; /* Revision level */ 625 __le32 s_rev_level; /* Revision level */
625 /*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */ 626 /*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */
626 __le16 s_def_resgid; /* Default gid for reserved blocks */ 627 __le16 s_def_resgid; /* Default gid for reserved blocks */
627 /* 628 /*
628 * These fields are for EXT4_DYNAMIC_REV superblocks only. 629 * These fields are for EXT4_DYNAMIC_REV superblocks only.
629 * 630 *
630 * Note: the difference between the compatible feature set and 631 * Note: the difference between the compatible feature set and
631 * the incompatible feature set is that if there is a bit set 632 * the incompatible feature set is that if there is a bit set
632 * in the incompatible feature set that the kernel doesn't 633 * in the incompatible feature set that the kernel doesn't
633 * know about, it should refuse to mount the filesystem. 634 * know about, it should refuse to mount the filesystem.
634 * 635 *
635 * e2fsck's requirements are more strict; if it doesn't know 636 * e2fsck's requirements are more strict; if it doesn't know
636 * about a feature in either the compatible or incompatible 637 * about a feature in either the compatible or incompatible
637 * feature set, it must abort and not try to meddle with 638 * feature set, it must abort and not try to meddle with
638 * things it doesn't understand... 639 * things it doesn't understand...
639 */ 640 */
640 __le32 s_first_ino; /* First non-reserved inode */ 641 __le32 s_first_ino; /* First non-reserved inode */
641 __le16 s_inode_size; /* size of inode structure */ 642 __le16 s_inode_size; /* size of inode structure */
642 __le16 s_block_group_nr; /* block group # of this superblock */ 643 __le16 s_block_group_nr; /* block group # of this superblock */
643 __le32 s_feature_compat; /* compatible feature set */ 644 __le32 s_feature_compat; /* compatible feature set */
644 /*60*/ __le32 s_feature_incompat; /* incompatible feature set */ 645 /*60*/ __le32 s_feature_incompat; /* incompatible feature set */
645 __le32 s_feature_ro_compat; /* readonly-compatible feature set */ 646 __le32 s_feature_ro_compat; /* readonly-compatible feature set */
646 /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */ 647 /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */
647 /*78*/ char s_volume_name[16]; /* volume name */ 648 /*78*/ char s_volume_name[16]; /* volume name */
648 /*88*/ char s_last_mounted[64]; /* directory where last mounted */ 649 /*88*/ char s_last_mounted[64]; /* directory where last mounted */
649 /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */ 650 /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */
650 /* 651 /*
651 * Performance hints. Directory preallocation should only 652 * Performance hints. Directory preallocation should only
652 * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on. 653 * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
653 */ 654 */
654 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ 655 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
655 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ 656 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
656 __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */ 657 __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */
657 /* 658 /*
658 * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set. 659 * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
659 */ 660 */
660 /*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */ 661 /*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */
661 /*E0*/ __le32 s_journal_inum; /* inode number of journal file */ 662 /*E0*/ __le32 s_journal_inum; /* inode number of journal file */
662 __le32 s_journal_dev; /* device number of journal file */ 663 __le32 s_journal_dev; /* device number of journal file */
663 __le32 s_last_orphan; /* start of list of inodes to delete */ 664 __le32 s_last_orphan; /* start of list of inodes to delete */
664 __le32 s_hash_seed[4]; /* HTREE hash seed */ 665 __le32 s_hash_seed[4]; /* HTREE hash seed */
665 __u8 s_def_hash_version; /* Default hash version to use */ 666 __u8 s_def_hash_version; /* Default hash version to use */
666 __u8 s_reserved_char_pad; 667 __u8 s_reserved_char_pad;
667 __le16 s_desc_size; /* size of group descriptor */ 668 __le16 s_desc_size; /* size of group descriptor */
668 /*100*/ __le32 s_default_mount_opts; 669 /*100*/ __le32 s_default_mount_opts;
669 __le32 s_first_meta_bg; /* First metablock block group */ 670 __le32 s_first_meta_bg; /* First metablock block group */
670 __le32 s_mkfs_time; /* When the filesystem was created */ 671 __le32 s_mkfs_time; /* When the filesystem was created */
671 __le32 s_jnl_blocks[17]; /* Backup of the journal inode */ 672 __le32 s_jnl_blocks[17]; /* Backup of the journal inode */
672 /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */ 673 /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
673 /*150*/ __le32 s_blocks_count_hi; /* Blocks count */ 674 /*150*/ __le32 s_blocks_count_hi; /* Blocks count */
674 __le32 s_r_blocks_count_hi; /* Reserved blocks count */ 675 __le32 s_r_blocks_count_hi; /* Reserved blocks count */
675 __le32 s_free_blocks_count_hi; /* Free blocks count */ 676 __le32 s_free_blocks_count_hi; /* Free blocks count */
676 __le16 s_min_extra_isize; /* All inodes have at least # bytes */ 677 __le16 s_min_extra_isize; /* All inodes have at least # bytes */
677 __le16 s_want_extra_isize; /* New inodes should reserve # bytes */ 678 __le16 s_want_extra_isize; /* New inodes should reserve # bytes */
678 __le32 s_flags; /* Miscellaneous flags */ 679 __le32 s_flags; /* Miscellaneous flags */
679 __le16 s_raid_stride; /* RAID stride */ 680 __le16 s_raid_stride; /* RAID stride */
680 __le16 s_mmp_interval; /* # seconds to wait in MMP checking */ 681 __le16 s_mmp_interval; /* # seconds to wait in MMP checking */
681 __le64 s_mmp_block; /* Block for multi-mount protection */ 682 __le64 s_mmp_block; /* Block for multi-mount protection */
682 __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ 683 __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/
683 __u8 s_log_groups_per_flex; /* FLEX_BG group size */ 684 __u8 s_log_groups_per_flex; /* FLEX_BG group size */
684 __u8 s_reserved_char_pad2; 685 __u8 s_reserved_char_pad2;
685 __le16 s_reserved_pad; 686 __le16 s_reserved_pad;
686 __le64 s_kbytes_written; /* nr of lifetime kilobytes written */ 687 __le64 s_kbytes_written; /* nr of lifetime kilobytes written */
687 __u32 s_reserved[160]; /* Padding to the end of the block */ 688 __u32 s_reserved[160]; /* Padding to the end of the block */
688 }; 689 };
689 690
690 #ifdef __KERNEL__ 691 #ifdef __KERNEL__
691 static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb) 692 static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
692 { 693 {
693 return sb->s_fs_info; 694 return sb->s_fs_info;
694 } 695 }
695 static inline struct ext4_inode_info *EXT4_I(struct inode *inode) 696 static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
696 { 697 {
697 return container_of(inode, struct ext4_inode_info, vfs_inode); 698 return container_of(inode, struct ext4_inode_info, vfs_inode);
698 } 699 }
699 700
700 static inline struct timespec ext4_current_time(struct inode *inode) 701 static inline struct timespec ext4_current_time(struct inode *inode)
701 { 702 {
702 return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ? 703 return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ?
703 current_fs_time(inode->i_sb) : CURRENT_TIME_SEC; 704 current_fs_time(inode->i_sb) : CURRENT_TIME_SEC;
704 } 705 }
705 706
706 707
707 static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) 708 static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
708 { 709 {
709 return ino == EXT4_ROOT_INO || 710 return ino == EXT4_ROOT_INO ||
710 ino == EXT4_JOURNAL_INO || 711 ino == EXT4_JOURNAL_INO ||
711 ino == EXT4_RESIZE_INO || 712 ino == EXT4_RESIZE_INO ||
712 (ino >= EXT4_FIRST_INO(sb) && 713 (ino >= EXT4_FIRST_INO(sb) &&
713 ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)); 714 ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count));
714 } 715 }
715 #else 716 #else
716 /* Assume that user mode programs are passing in an ext4fs superblock, not 717 /* Assume that user mode programs are passing in an ext4fs superblock, not
717 * a kernel struct super_block. This will allow us to call the feature-test 718 * a kernel struct super_block. This will allow us to call the feature-test
718 * macros from user land. */ 719 * macros from user land. */
719 #define EXT4_SB(sb) (sb) 720 #define EXT4_SB(sb) (sb)
720 #endif 721 #endif
721 722
722 #define NEXT_ORPHAN(inode) EXT4_I(inode)->i_dtime 723 #define NEXT_ORPHAN(inode) EXT4_I(inode)->i_dtime
723 724
724 /* 725 /*
725 * Codes for operating systems 726 * Codes for operating systems
726 */ 727 */
727 #define EXT4_OS_LINUX 0 728 #define EXT4_OS_LINUX 0
728 #define EXT4_OS_HURD 1 729 #define EXT4_OS_HURD 1
729 #define EXT4_OS_MASIX 2 730 #define EXT4_OS_MASIX 2
730 #define EXT4_OS_FREEBSD 3 731 #define EXT4_OS_FREEBSD 3
731 #define EXT4_OS_LITES 4 732 #define EXT4_OS_LITES 4
732 733
733 /* 734 /*
734 * Revision levels 735 * Revision levels
735 */ 736 */
736 #define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */ 737 #define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */
737 #define EXT4_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */ 738 #define EXT4_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
738 739
739 #define EXT4_CURRENT_REV EXT4_GOOD_OLD_REV 740 #define EXT4_CURRENT_REV EXT4_GOOD_OLD_REV
740 #define EXT4_MAX_SUPP_REV EXT4_DYNAMIC_REV 741 #define EXT4_MAX_SUPP_REV EXT4_DYNAMIC_REV
741 742
742 #define EXT4_GOOD_OLD_INODE_SIZE 128 743 #define EXT4_GOOD_OLD_INODE_SIZE 128
743 744
744 /* 745 /*
745 * Feature set definitions 746 * Feature set definitions
746 */ 747 */
747 748
748 #define EXT4_HAS_COMPAT_FEATURE(sb,mask) \ 749 #define EXT4_HAS_COMPAT_FEATURE(sb,mask) \
749 ((EXT4_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask)) != 0) 750 ((EXT4_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask)) != 0)
750 #define EXT4_HAS_RO_COMPAT_FEATURE(sb,mask) \ 751 #define EXT4_HAS_RO_COMPAT_FEATURE(sb,mask) \
751 ((EXT4_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask)) != 0) 752 ((EXT4_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask)) != 0)
752 #define EXT4_HAS_INCOMPAT_FEATURE(sb,mask) \ 753 #define EXT4_HAS_INCOMPAT_FEATURE(sb,mask) \
753 ((EXT4_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask)) != 0) 754 ((EXT4_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask)) != 0)
754 #define EXT4_SET_COMPAT_FEATURE(sb,mask) \ 755 #define EXT4_SET_COMPAT_FEATURE(sb,mask) \
755 EXT4_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask) 756 EXT4_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
756 #define EXT4_SET_RO_COMPAT_FEATURE(sb,mask) \ 757 #define EXT4_SET_RO_COMPAT_FEATURE(sb,mask) \
757 EXT4_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask) 758 EXT4_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
758 #define EXT4_SET_INCOMPAT_FEATURE(sb,mask) \ 759 #define EXT4_SET_INCOMPAT_FEATURE(sb,mask) \
759 EXT4_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask) 760 EXT4_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
760 #define EXT4_CLEAR_COMPAT_FEATURE(sb,mask) \ 761 #define EXT4_CLEAR_COMPAT_FEATURE(sb,mask) \
761 EXT4_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask) 762 EXT4_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
762 #define EXT4_CLEAR_RO_COMPAT_FEATURE(sb,mask) \ 763 #define EXT4_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
763 EXT4_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask) 764 EXT4_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
764 #define EXT4_CLEAR_INCOMPAT_FEATURE(sb,mask) \ 765 #define EXT4_CLEAR_INCOMPAT_FEATURE(sb,mask) \
765 EXT4_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask) 766 EXT4_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
766 767
767 #define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001 768 #define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001
768 #define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002 769 #define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
769 #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004 770 #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
770 #define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008 771 #define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
771 #define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010 772 #define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
772 #define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020 773 #define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
773 774
774 #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 775 #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
775 #define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 776 #define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
776 #define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 777 #define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
777 #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008 778 #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008
778 #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 779 #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
779 #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 780 #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
780 #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 781 #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
781 782
782 #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001 783 #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
783 #define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002 784 #define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
784 #define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ 785 #define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
785 #define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */ 786 #define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
786 #define EXT4_FEATURE_INCOMPAT_META_BG 0x0010 787 #define EXT4_FEATURE_INCOMPAT_META_BG 0x0010
787 #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */ 788 #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
788 #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 789 #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
789 #define EXT4_FEATURE_INCOMPAT_MMP 0x0100 790 #define EXT4_FEATURE_INCOMPAT_MMP 0x0100
790 #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 791 #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
791 792
792 #define EXT4_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR 793 #define EXT4_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
793 #define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 794 #define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \
794 EXT4_FEATURE_INCOMPAT_RECOVER| \ 795 EXT4_FEATURE_INCOMPAT_RECOVER| \
795 EXT4_FEATURE_INCOMPAT_META_BG| \ 796 EXT4_FEATURE_INCOMPAT_META_BG| \
796 EXT4_FEATURE_INCOMPAT_EXTENTS| \ 797 EXT4_FEATURE_INCOMPAT_EXTENTS| \
797 EXT4_FEATURE_INCOMPAT_64BIT| \ 798 EXT4_FEATURE_INCOMPAT_64BIT| \
798 EXT4_FEATURE_INCOMPAT_FLEX_BG) 799 EXT4_FEATURE_INCOMPAT_FLEX_BG)
799 #define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 800 #define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
800 EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 801 EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
801 EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \ 802 EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
802 EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \ 803 EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
803 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \ 804 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \
804 EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\ 805 EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\
805 EXT4_FEATURE_RO_COMPAT_HUGE_FILE) 806 EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
806 807
807 /* 808 /*
808 * Default values for user and/or group using reserved blocks 809 * Default values for user and/or group using reserved blocks
809 */ 810 */
810 #define EXT4_DEF_RESUID 0 811 #define EXT4_DEF_RESUID 0
811 #define EXT4_DEF_RESGID 0 812 #define EXT4_DEF_RESGID 0
812 813
813 #define EXT4_DEF_INODE_READAHEAD_BLKS 32 814 #define EXT4_DEF_INODE_READAHEAD_BLKS 32
814 815
815 /* 816 /*
816 * Default mount options 817 * Default mount options
817 */ 818 */
818 #define EXT4_DEFM_DEBUG 0x0001 819 #define EXT4_DEFM_DEBUG 0x0001
819 #define EXT4_DEFM_BSDGROUPS 0x0002 820 #define EXT4_DEFM_BSDGROUPS 0x0002
820 #define EXT4_DEFM_XATTR_USER 0x0004 821 #define EXT4_DEFM_XATTR_USER 0x0004
821 #define EXT4_DEFM_ACL 0x0008 822 #define EXT4_DEFM_ACL 0x0008
822 #define EXT4_DEFM_UID16 0x0010 823 #define EXT4_DEFM_UID16 0x0010
823 #define EXT4_DEFM_JMODE 0x0060 824 #define EXT4_DEFM_JMODE 0x0060
824 #define EXT4_DEFM_JMODE_DATA 0x0020 825 #define EXT4_DEFM_JMODE_DATA 0x0020
825 #define EXT4_DEFM_JMODE_ORDERED 0x0040 826 #define EXT4_DEFM_JMODE_ORDERED 0x0040
826 #define EXT4_DEFM_JMODE_WBACK 0x0060 827 #define EXT4_DEFM_JMODE_WBACK 0x0060
827 828
828 /* 829 /*
829 * Default journal batch times 830 * Default journal batch times
830 */ 831 */
831 #define EXT4_DEF_MIN_BATCH_TIME 0 832 #define EXT4_DEF_MIN_BATCH_TIME 0
832 #define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */ 833 #define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */
833 834
834 /* 835 /*
835 * Minimum number of groups in a flexgroup before we separate out 836 * Minimum number of groups in a flexgroup before we separate out
836 * directories into the first block group of a flexgroup 837 * directories into the first block group of a flexgroup
837 */ 838 */
838 #define EXT4_FLEX_SIZE_DIR_ALLOC_SCHEME 4 839 #define EXT4_FLEX_SIZE_DIR_ALLOC_SCHEME 4
839 840
840 /* 841 /*
841 * Structure of a directory entry 842 * Structure of a directory entry
842 */ 843 */
843 #define EXT4_NAME_LEN 255 844 #define EXT4_NAME_LEN 255
844 845
845 struct ext4_dir_entry { 846 struct ext4_dir_entry {
846 __le32 inode; /* Inode number */ 847 __le32 inode; /* Inode number */
847 __le16 rec_len; /* Directory entry length */ 848 __le16 rec_len; /* Directory entry length */
848 __le16 name_len; /* Name length */ 849 __le16 name_len; /* Name length */
849 char name[EXT4_NAME_LEN]; /* File name */ 850 char name[EXT4_NAME_LEN]; /* File name */
850 }; 851 };
851 852
852 /* 853 /*
853 * The new version of the directory entry. Since EXT4 structures are 854 * The new version of the directory entry. Since EXT4 structures are
854 * stored in intel byte order, and the name_len field could never be 855 * stored in intel byte order, and the name_len field could never be
855 * bigger than 255 chars, it's safe to reclaim the extra byte for the 856 * bigger than 255 chars, it's safe to reclaim the extra byte for the
856 * file_type field. 857 * file_type field.
857 */ 858 */
858 struct ext4_dir_entry_2 { 859 struct ext4_dir_entry_2 {
859 __le32 inode; /* Inode number */ 860 __le32 inode; /* Inode number */
860 __le16 rec_len; /* Directory entry length */ 861 __le16 rec_len; /* Directory entry length */
861 __u8 name_len; /* Name length */ 862 __u8 name_len; /* Name length */
862 __u8 file_type; 863 __u8 file_type;
863 char name[EXT4_NAME_LEN]; /* File name */ 864 char name[EXT4_NAME_LEN]; /* File name */
864 }; 865 };
865 866
866 /* 867 /*
867 * Ext4 directory file types. Only the low 3 bits are used. The 868 * Ext4 directory file types. Only the low 3 bits are used. The
868 * other bits are reserved for now. 869 * other bits are reserved for now.
869 */ 870 */
870 #define EXT4_FT_UNKNOWN 0 871 #define EXT4_FT_UNKNOWN 0
871 #define EXT4_FT_REG_FILE 1 872 #define EXT4_FT_REG_FILE 1
872 #define EXT4_FT_DIR 2 873 #define EXT4_FT_DIR 2
873 #define EXT4_FT_CHRDEV 3 874 #define EXT4_FT_CHRDEV 3
874 #define EXT4_FT_BLKDEV 4 875 #define EXT4_FT_BLKDEV 4
875 #define EXT4_FT_FIFO 5 876 #define EXT4_FT_FIFO 5
876 #define EXT4_FT_SOCK 6 877 #define EXT4_FT_SOCK 6
877 #define EXT4_FT_SYMLINK 7 878 #define EXT4_FT_SYMLINK 7
878 879
879 #define EXT4_FT_MAX 8 880 #define EXT4_FT_MAX 8
880 881
881 /* 882 /*
882 * EXT4_DIR_PAD defines the directory entries boundaries 883 * EXT4_DIR_PAD defines the directory entries boundaries
883 * 884 *
884 * NOTE: It must be a multiple of 4 885 * NOTE: It must be a multiple of 4
885 */ 886 */
886 #define EXT4_DIR_PAD 4 887 #define EXT4_DIR_PAD 4
887 #define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1) 888 #define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1)
888 #define EXT4_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \ 889 #define EXT4_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \
889 ~EXT4_DIR_ROUND) 890 ~EXT4_DIR_ROUND)
890 #define EXT4_MAX_REC_LEN ((1<<16)-1) 891 #define EXT4_MAX_REC_LEN ((1<<16)-1)
891 892
892 /* 893 /*
893 * Hash Tree Directory indexing 894 * Hash Tree Directory indexing
894 * (c) Daniel Phillips, 2001 895 * (c) Daniel Phillips, 2001
895 */ 896 */
896 897
897 #define is_dx(dir) (EXT4_HAS_COMPAT_FEATURE(dir->i_sb, \ 898 #define is_dx(dir) (EXT4_HAS_COMPAT_FEATURE(dir->i_sb, \
898 EXT4_FEATURE_COMPAT_DIR_INDEX) && \ 899 EXT4_FEATURE_COMPAT_DIR_INDEX) && \
899 (EXT4_I(dir)->i_flags & EXT4_INDEX_FL)) 900 (EXT4_I(dir)->i_flags & EXT4_INDEX_FL))
900 #define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX) 901 #define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX)
901 #define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1) 902 #define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
902 903
903 /* Legal values for the dx_root hash_version field: */ 904 /* Legal values for the dx_root hash_version field: */
904 905
905 #define DX_HASH_LEGACY 0 906 #define DX_HASH_LEGACY 0
906 #define DX_HASH_HALF_MD4 1 907 #define DX_HASH_HALF_MD4 1
907 #define DX_HASH_TEA 2 908 #define DX_HASH_TEA 2
908 #define DX_HASH_LEGACY_UNSIGNED 3 909 #define DX_HASH_LEGACY_UNSIGNED 3
909 #define DX_HASH_HALF_MD4_UNSIGNED 4 910 #define DX_HASH_HALF_MD4_UNSIGNED 4
910 #define DX_HASH_TEA_UNSIGNED 5 911 #define DX_HASH_TEA_UNSIGNED 5
911 912
912 #ifdef __KERNEL__ 913 #ifdef __KERNEL__
913 914
914 /* hash info structure used by the directory hash */ 915 /* hash info structure used by the directory hash */
915 struct dx_hash_info 916 struct dx_hash_info
916 { 917 {
917 u32 hash; 918 u32 hash;
918 u32 minor_hash; 919 u32 minor_hash;
919 int hash_version; 920 int hash_version;
920 u32 *seed; 921 u32 *seed;
921 }; 922 };
922 923
923 #define EXT4_HTREE_EOF 0x7fffffff 924 #define EXT4_HTREE_EOF 0x7fffffff
924 925
925 /* 926 /*
926 * Control parameters used by ext4_htree_next_block 927 * Control parameters used by ext4_htree_next_block
927 */ 928 */
928 #define HASH_NB_ALWAYS 1 929 #define HASH_NB_ALWAYS 1
929 930
930 931
931 /* 932 /*
932 * Describe an inode's exact location on disk and in memory 933 * Describe an inode's exact location on disk and in memory
933 */ 934 */
934 struct ext4_iloc 935 struct ext4_iloc
935 { 936 {
936 struct buffer_head *bh; 937 struct buffer_head *bh;
937 unsigned long offset; 938 unsigned long offset;
938 ext4_group_t block_group; 939 ext4_group_t block_group;
939 }; 940 };
940 941
941 static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc) 942 static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc)
942 { 943 {
943 return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset); 944 return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset);
944 } 945 }
945 946
946 /* 947 /*
947 * This structure is stuffed into the struct file's private_data field 948 * This structure is stuffed into the struct file's private_data field
948 * for directories. It is where we put information so that we can do 949 * for directories. It is where we put information so that we can do
949 * readdir operations in hash tree order. 950 * readdir operations in hash tree order.
950 */ 951 */
951 struct dir_private_info { 952 struct dir_private_info {
952 struct rb_root root; 953 struct rb_root root;
953 struct rb_node *curr_node; 954 struct rb_node *curr_node;
954 struct fname *extra_fname; 955 struct fname *extra_fname;
955 loff_t last_pos; 956 loff_t last_pos;
956 __u32 curr_hash; 957 __u32 curr_hash;
957 __u32 curr_minor_hash; 958 __u32 curr_minor_hash;
958 __u32 next_hash; 959 __u32 next_hash;
959 }; 960 };
960 961
961 /* calculate the first block number of the group */ 962 /* calculate the first block number of the group */
962 static inline ext4_fsblk_t 963 static inline ext4_fsblk_t
963 ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no) 964 ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no)
964 { 965 {
965 return group_no * (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) + 966 return group_no * (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) +
966 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); 967 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
967 } 968 }
968 969
969 /* 970 /*
970 * Special error return code only used by dx_probe() and its callers. 971 * Special error return code only used by dx_probe() and its callers.
971 */ 972 */
972 #define ERR_BAD_DX_DIR -75000 973 #define ERR_BAD_DX_DIR -75000
973 974
974 void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr, 975 void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
975 ext4_group_t *blockgrpp, ext4_grpblk_t *offsetp); 976 ext4_group_t *blockgrpp, ext4_grpblk_t *offsetp);
976 977
977 extern struct proc_dir_entry *ext4_proc_root; 978 extern struct proc_dir_entry *ext4_proc_root;
978 979
979 /* 980 /*
980 * Function prototypes 981 * Function prototypes
981 */ 982 */
982 983
983 /* 984 /*
984 * Ok, these declarations are also in <linux/kernel.h> but none of the 985 * Ok, these declarations are also in <linux/kernel.h> but none of the
985 * ext4 source programs needs to include it so they are duplicated here. 986 * ext4 source programs needs to include it so they are duplicated here.
986 */ 987 */
987 # define NORET_TYPE /**/ 988 # define NORET_TYPE /**/
988 # define ATTRIB_NORET __attribute__((noreturn)) 989 # define ATTRIB_NORET __attribute__((noreturn))
989 # define NORET_AND noreturn, 990 # define NORET_AND noreturn,
990 991
991 /* bitmap.c */ 992 /* bitmap.c */
992 extern unsigned int ext4_count_free(struct buffer_head *, unsigned); 993 extern unsigned int ext4_count_free(struct buffer_head *, unsigned);
993 994
994 /* balloc.c */ 995 /* balloc.c */
995 extern unsigned int ext4_block_group(struct super_block *sb, 996 extern unsigned int ext4_block_group(struct super_block *sb,
996 ext4_fsblk_t blocknr); 997 ext4_fsblk_t blocknr);
997 extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb, 998 extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb,
998 ext4_fsblk_t blocknr); 999 ext4_fsblk_t blocknr);
999 extern int ext4_bg_has_super(struct super_block *sb, ext4_group_t group); 1000 extern int ext4_bg_has_super(struct super_block *sb, ext4_group_t group);
1000 extern unsigned long ext4_bg_num_gdb(struct super_block *sb, 1001 extern unsigned long ext4_bg_num_gdb(struct super_block *sb,
1001 ext4_group_t group); 1002 ext4_group_t group);
1002 extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode, 1003 extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
1003 ext4_fsblk_t goal, unsigned long *count, int *errp); 1004 ext4_fsblk_t goal, unsigned long *count, int *errp);
1004 extern int ext4_claim_free_blocks(struct ext4_sb_info *sbi, s64 nblocks); 1005 extern int ext4_claim_free_blocks(struct ext4_sb_info *sbi, s64 nblocks);
1005 extern int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks); 1006 extern int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks);
1006 extern void ext4_free_blocks(handle_t *handle, struct inode *inode, 1007 extern void ext4_free_blocks(handle_t *handle, struct inode *inode,
1007 ext4_fsblk_t block, unsigned long count, int metadata); 1008 ext4_fsblk_t block, unsigned long count, int metadata);
1008 extern void ext4_add_groupblocks(handle_t *handle, struct super_block *sb, 1009 extern void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
1009 ext4_fsblk_t block, unsigned long count); 1010 ext4_fsblk_t block, unsigned long count);
1010 extern ext4_fsblk_t ext4_count_free_blocks(struct super_block *); 1011 extern ext4_fsblk_t ext4_count_free_blocks(struct super_block *);
1011 extern void ext4_check_blocks_bitmap(struct super_block *); 1012 extern void ext4_check_blocks_bitmap(struct super_block *);
1012 extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb, 1013 extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
1013 ext4_group_t block_group, 1014 ext4_group_t block_group,
1014 struct buffer_head ** bh); 1015 struct buffer_head ** bh);
1015 extern int ext4_should_retry_alloc(struct super_block *sb, int *retries); 1016 extern int ext4_should_retry_alloc(struct super_block *sb, int *retries);
1016 1017
1017 /* dir.c */ 1018 /* dir.c */
1018 extern int ext4_check_dir_entry(const char *, struct inode *, 1019 extern int ext4_check_dir_entry(const char *, struct inode *,
1019 struct ext4_dir_entry_2 *, 1020 struct ext4_dir_entry_2 *,
1020 struct buffer_head *, unsigned int); 1021 struct buffer_head *, unsigned int);
1021 extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash, 1022 extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
1022 __u32 minor_hash, 1023 __u32 minor_hash,
1023 struct ext4_dir_entry_2 *dirent); 1024 struct ext4_dir_entry_2 *dirent);
1024 extern void ext4_htree_free_dir_info(struct dir_private_info *p); 1025 extern void ext4_htree_free_dir_info(struct dir_private_info *p);
1025 1026
1026 /* fsync.c */ 1027 /* fsync.c */
1027 extern int ext4_sync_file(struct file *, struct dentry *, int); 1028 extern int ext4_sync_file(struct file *, struct dentry *, int);
1028 1029
1029 /* hash.c */ 1030 /* hash.c */
1030 extern int ext4fs_dirhash(const char *name, int len, struct 1031 extern int ext4fs_dirhash(const char *name, int len, struct
1031 dx_hash_info *hinfo); 1032 dx_hash_info *hinfo);
1032 1033
1033 /* ialloc.c */ 1034 /* ialloc.c */
1034 extern struct inode * ext4_new_inode(handle_t *, struct inode *, int); 1035 extern struct inode * ext4_new_inode(handle_t *, struct inode *, int);
1035 extern void ext4_free_inode(handle_t *, struct inode *); 1036 extern void ext4_free_inode(handle_t *, struct inode *);
1036 extern struct inode * ext4_orphan_get(struct super_block *, unsigned long); 1037 extern struct inode * ext4_orphan_get(struct super_block *, unsigned long);
1037 extern unsigned long ext4_count_free_inodes(struct super_block *); 1038 extern unsigned long ext4_count_free_inodes(struct super_block *);
1038 extern unsigned long ext4_count_dirs(struct super_block *); 1039 extern unsigned long ext4_count_dirs(struct super_block *);
1039 extern void ext4_check_inodes_bitmap(struct super_block *); 1040 extern void ext4_check_inodes_bitmap(struct super_block *);
1040 1041
1041 /* mballoc.c */ 1042 /* mballoc.c */
1042 extern long ext4_mb_stats; 1043 extern long ext4_mb_stats;
1043 extern long ext4_mb_max_to_scan; 1044 extern long ext4_mb_max_to_scan;
1044 extern int ext4_mb_init(struct super_block *, int); 1045 extern int ext4_mb_init(struct super_block *, int);
1045 extern int ext4_mb_release(struct super_block *); 1046 extern int ext4_mb_release(struct super_block *);
1046 extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *, 1047 extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,
1047 struct ext4_allocation_request *, int *); 1048 struct ext4_allocation_request *, int *);
1048 extern int ext4_mb_reserve_blocks(struct super_block *, int); 1049 extern int ext4_mb_reserve_blocks(struct super_block *, int);
1049 extern void ext4_discard_preallocations(struct inode *); 1050 extern void ext4_discard_preallocations(struct inode *);
1050 extern int __init init_ext4_mballoc(void); 1051 extern int __init init_ext4_mballoc(void);
1051 extern void exit_ext4_mballoc(void); 1052 extern void exit_ext4_mballoc(void);
1052 extern void ext4_mb_free_blocks(handle_t *, struct inode *, 1053 extern void ext4_mb_free_blocks(handle_t *, struct inode *,
1053 unsigned long, unsigned long, int, unsigned long *); 1054 unsigned long, unsigned long, int, unsigned long *);
1054 extern int ext4_mb_add_groupinfo(struct super_block *sb, 1055 extern int ext4_mb_add_groupinfo(struct super_block *sb,
1055 ext4_group_t i, struct ext4_group_desc *desc); 1056 ext4_group_t i, struct ext4_group_desc *desc);
1056 extern void ext4_mb_update_group_info(struct ext4_group_info *grp, 1057 extern void ext4_mb_update_group_info(struct ext4_group_info *grp,
1057 ext4_grpblk_t add); 1058 ext4_grpblk_t add);
1058 extern int ext4_mb_get_buddy_cache_lock(struct super_block *, ext4_group_t); 1059 extern int ext4_mb_get_buddy_cache_lock(struct super_block *, ext4_group_t);
1059 extern void ext4_mb_put_buddy_cache_lock(struct super_block *, 1060 extern void ext4_mb_put_buddy_cache_lock(struct super_block *,
1060 ext4_group_t, int); 1061 ext4_group_t, int);
1061 /* inode.c */ 1062 /* inode.c */
1062 int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode, 1063 int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,
1063 struct buffer_head *bh, ext4_fsblk_t blocknr); 1064 struct buffer_head *bh, ext4_fsblk_t blocknr);
1064 struct buffer_head *ext4_getblk(handle_t *, struct inode *, 1065 struct buffer_head *ext4_getblk(handle_t *, struct inode *,
1065 ext4_lblk_t, int, int *); 1066 ext4_lblk_t, int, int *);
1066 struct buffer_head *ext4_bread(handle_t *, struct inode *, 1067 struct buffer_head *ext4_bread(handle_t *, struct inode *,
1067 ext4_lblk_t, int, int *); 1068 ext4_lblk_t, int, int *);
1068 int ext4_get_block(struct inode *inode, sector_t iblock, 1069 int ext4_get_block(struct inode *inode, sector_t iblock,
1069 struct buffer_head *bh_result, int create); 1070 struct buffer_head *bh_result, int create);
1070 1071
1071 extern struct inode *ext4_iget(struct super_block *, unsigned long); 1072 extern struct inode *ext4_iget(struct super_block *, unsigned long);
1072 extern int ext4_write_inode(struct inode *, int); 1073 extern int ext4_write_inode(struct inode *, int);
1073 extern int ext4_setattr(struct dentry *, struct iattr *); 1074 extern int ext4_setattr(struct dentry *, struct iattr *);
1074 extern int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry, 1075 extern int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
1075 struct kstat *stat); 1076 struct kstat *stat);
1076 extern void ext4_delete_inode(struct inode *); 1077 extern void ext4_delete_inode(struct inode *);
1077 extern int ext4_sync_inode(handle_t *, struct inode *); 1078 extern int ext4_sync_inode(handle_t *, struct inode *);
1078 extern void ext4_dirty_inode(struct inode *); 1079 extern void ext4_dirty_inode(struct inode *);
1079 extern int ext4_change_inode_journal_flag(struct inode *, int); 1080 extern int ext4_change_inode_journal_flag(struct inode *, int);
1080 extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *); 1081 extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
1081 extern int ext4_can_truncate(struct inode *inode); 1082 extern int ext4_can_truncate(struct inode *inode);
1082 extern void ext4_truncate(struct inode *); 1083 extern void ext4_truncate(struct inode *);
1083 extern void ext4_set_inode_flags(struct inode *); 1084 extern void ext4_set_inode_flags(struct inode *);
1084 extern void ext4_get_inode_flags(struct ext4_inode_info *); 1085 extern void ext4_get_inode_flags(struct ext4_inode_info *);
1085 extern int ext4_alloc_da_blocks(struct inode *inode); 1086 extern int ext4_alloc_da_blocks(struct inode *inode);
1086 extern void ext4_set_aops(struct inode *inode); 1087 extern void ext4_set_aops(struct inode *inode);
1087 extern int ext4_writepage_trans_blocks(struct inode *); 1088 extern int ext4_writepage_trans_blocks(struct inode *);
1088 extern int ext4_meta_trans_blocks(struct inode *, int nrblocks, int idxblocks); 1089 extern int ext4_meta_trans_blocks(struct inode *, int nrblocks, int idxblocks);
1089 extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks); 1090 extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
1090 extern int ext4_block_truncate_page(handle_t *handle, 1091 extern int ext4_block_truncate_page(handle_t *handle,
1091 struct address_space *mapping, loff_t from); 1092 struct address_space *mapping, loff_t from);
1092 extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct page *page); 1093 extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct page *page);
1093 extern qsize_t ext4_get_reserved_space(struct inode *inode); 1094 extern qsize_t ext4_get_reserved_space(struct inode *inode);
1094 1095
1095 /* ioctl.c */ 1096 /* ioctl.c */
1096 extern long ext4_ioctl(struct file *, unsigned int, unsigned long); 1097 extern long ext4_ioctl(struct file *, unsigned int, unsigned long);
1097 extern long ext4_compat_ioctl(struct file *, unsigned int, unsigned long); 1098 extern long ext4_compat_ioctl(struct file *, unsigned int, unsigned long);
1098 1099
1099 /* migrate.c */ 1100 /* migrate.c */
1100 extern int ext4_ext_migrate(struct inode *); 1101 extern int ext4_ext_migrate(struct inode *);
1101 1102
1102 /* namei.c */ 1103 /* namei.c */
1103 extern unsigned int ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize); 1104 extern unsigned int ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize);
1104 extern __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize); 1105 extern __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize);
1105 extern int ext4_orphan_add(handle_t *, struct inode *); 1106 extern int ext4_orphan_add(handle_t *, struct inode *);
1106 extern int ext4_orphan_del(handle_t *, struct inode *); 1107 extern int ext4_orphan_del(handle_t *, struct inode *);
1107 extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash, 1108 extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
1108 __u32 start_minor_hash, __u32 *next_hash); 1109 __u32 start_minor_hash, __u32 *next_hash);
1109 1110
1110 /* resize.c */ 1111 /* resize.c */
1111 extern int ext4_group_add(struct super_block *sb, 1112 extern int ext4_group_add(struct super_block *sb,
1112 struct ext4_new_group_data *input); 1113 struct ext4_new_group_data *input);
1113 extern int ext4_group_extend(struct super_block *sb, 1114 extern int ext4_group_extend(struct super_block *sb,
1114 struct ext4_super_block *es, 1115 struct ext4_super_block *es,
1115 ext4_fsblk_t n_blocks_count); 1116 ext4_fsblk_t n_blocks_count);
1116 1117
1117 /* super.c */ 1118 /* super.c */
1118 extern void ext4_error(struct super_block *, const char *, const char *, ...) 1119 extern void ext4_error(struct super_block *, const char *, const char *, ...)
1119 __attribute__ ((format (printf, 3, 4))); 1120 __attribute__ ((format (printf, 3, 4)));
1120 extern void __ext4_std_error(struct super_block *, const char *, int); 1121 extern void __ext4_std_error(struct super_block *, const char *, int);
1121 extern void ext4_abort(struct super_block *, const char *, const char *, ...) 1122 extern void ext4_abort(struct super_block *, const char *, const char *, ...)
1122 __attribute__ ((format (printf, 3, 4))); 1123 __attribute__ ((format (printf, 3, 4)));
1123 extern void ext4_warning(struct super_block *, const char *, const char *, ...) 1124 extern void ext4_warning(struct super_block *, const char *, const char *, ...)
1124 __attribute__ ((format (printf, 3, 4))); 1125 __attribute__ ((format (printf, 3, 4)));
1125 extern void ext4_grp_locked_error(struct super_block *, ext4_group_t, 1126 extern void ext4_grp_locked_error(struct super_block *, ext4_group_t,
1126 const char *, const char *, ...) 1127 const char *, const char *, ...)
1127 __attribute__ ((format (printf, 4, 5))); 1128 __attribute__ ((format (printf, 4, 5)));
1128 extern void ext4_update_dynamic_rev(struct super_block *sb); 1129 extern void ext4_update_dynamic_rev(struct super_block *sb);
1129 extern int ext4_update_compat_feature(handle_t *handle, struct super_block *sb, 1130 extern int ext4_update_compat_feature(handle_t *handle, struct super_block *sb,
1130 __u32 compat); 1131 __u32 compat);
1131 extern int ext4_update_rocompat_feature(handle_t *handle, 1132 extern int ext4_update_rocompat_feature(handle_t *handle,
1132 struct super_block *sb, __u32 rocompat); 1133 struct super_block *sb, __u32 rocompat);
1133 extern int ext4_update_incompat_feature(handle_t *handle, 1134 extern int ext4_update_incompat_feature(handle_t *handle,
1134 struct super_block *sb, __u32 incompat); 1135 struct super_block *sb, __u32 incompat);
1135 extern ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, 1136 extern ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
1136 struct ext4_group_desc *bg); 1137 struct ext4_group_desc *bg);
1137 extern ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, 1138 extern ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
1138 struct ext4_group_desc *bg); 1139 struct ext4_group_desc *bg);
1139 extern ext4_fsblk_t ext4_inode_table(struct super_block *sb, 1140 extern ext4_fsblk_t ext4_inode_table(struct super_block *sb,
1140 struct ext4_group_desc *bg); 1141 struct ext4_group_desc *bg);
1141 extern __u32 ext4_free_blks_count(struct super_block *sb, 1142 extern __u32 ext4_free_blks_count(struct super_block *sb,
1142 struct ext4_group_desc *bg); 1143 struct ext4_group_desc *bg);
1143 extern __u32 ext4_free_inodes_count(struct super_block *sb, 1144 extern __u32 ext4_free_inodes_count(struct super_block *sb,
1144 struct ext4_group_desc *bg); 1145 struct ext4_group_desc *bg);
1145 extern __u32 ext4_used_dirs_count(struct super_block *sb, 1146 extern __u32 ext4_used_dirs_count(struct super_block *sb,
1146 struct ext4_group_desc *bg); 1147 struct ext4_group_desc *bg);
1147 extern __u32 ext4_itable_unused_count(struct super_block *sb, 1148 extern __u32 ext4_itable_unused_count(struct super_block *sb,
1148 struct ext4_group_desc *bg); 1149 struct ext4_group_desc *bg);
1149 extern void ext4_block_bitmap_set(struct super_block *sb, 1150 extern void ext4_block_bitmap_set(struct super_block *sb,
1150 struct ext4_group_desc *bg, ext4_fsblk_t blk); 1151 struct ext4_group_desc *bg, ext4_fsblk_t blk);
1151 extern void ext4_inode_bitmap_set(struct super_block *sb, 1152 extern void ext4_inode_bitmap_set(struct super_block *sb,
1152 struct ext4_group_desc *bg, ext4_fsblk_t blk); 1153 struct ext4_group_desc *bg, ext4_fsblk_t blk);
1153 extern void ext4_inode_table_set(struct super_block *sb, 1154 extern void ext4_inode_table_set(struct super_block *sb,
1154 struct ext4_group_desc *bg, ext4_fsblk_t blk); 1155 struct ext4_group_desc *bg, ext4_fsblk_t blk);
1155 extern void ext4_free_blks_set(struct super_block *sb, 1156 extern void ext4_free_blks_set(struct super_block *sb,
1156 struct ext4_group_desc *bg, __u32 count); 1157 struct ext4_group_desc *bg, __u32 count);
1157 extern void ext4_free_inodes_set(struct super_block *sb, 1158 extern void ext4_free_inodes_set(struct super_block *sb,
1158 struct ext4_group_desc *bg, __u32 count); 1159 struct ext4_group_desc *bg, __u32 count);
1159 extern void ext4_used_dirs_set(struct super_block *sb, 1160 extern void ext4_used_dirs_set(struct super_block *sb,
1160 struct ext4_group_desc *bg, __u32 count); 1161 struct ext4_group_desc *bg, __u32 count);
1161 extern void ext4_itable_unused_set(struct super_block *sb, 1162 extern void ext4_itable_unused_set(struct super_block *sb,
1162 struct ext4_group_desc *bg, __u32 count); 1163 struct ext4_group_desc *bg, __u32 count);
1163 1164
1164 static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es) 1165 static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es)
1165 { 1166 {
1166 return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) | 1167 return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) |
1167 le32_to_cpu(es->s_blocks_count_lo); 1168 le32_to_cpu(es->s_blocks_count_lo);
1168 } 1169 }
1169 1170
1170 static inline ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es) 1171 static inline ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es)
1171 { 1172 {
1172 return ((ext4_fsblk_t)le32_to_cpu(es->s_r_blocks_count_hi) << 32) | 1173 return ((ext4_fsblk_t)le32_to_cpu(es->s_r_blocks_count_hi) << 32) |
1173 le32_to_cpu(es->s_r_blocks_count_lo); 1174 le32_to_cpu(es->s_r_blocks_count_lo);
1174 } 1175 }
1175 1176
1176 static inline ext4_fsblk_t ext4_free_blocks_count(struct ext4_super_block *es) 1177 static inline ext4_fsblk_t ext4_free_blocks_count(struct ext4_super_block *es)
1177 { 1178 {
1178 return ((ext4_fsblk_t)le32_to_cpu(es->s_free_blocks_count_hi) << 32) | 1179 return ((ext4_fsblk_t)le32_to_cpu(es->s_free_blocks_count_hi) << 32) |
1179 le32_to_cpu(es->s_free_blocks_count_lo); 1180 le32_to_cpu(es->s_free_blocks_count_lo);
1180 } 1181 }
1181 1182
1182 static inline void ext4_blocks_count_set(struct ext4_super_block *es, 1183 static inline void ext4_blocks_count_set(struct ext4_super_block *es,
1183 ext4_fsblk_t blk) 1184 ext4_fsblk_t blk)
1184 { 1185 {
1185 es->s_blocks_count_lo = cpu_to_le32((u32)blk); 1186 es->s_blocks_count_lo = cpu_to_le32((u32)blk);
1186 es->s_blocks_count_hi = cpu_to_le32(blk >> 32); 1187 es->s_blocks_count_hi = cpu_to_le32(blk >> 32);
1187 } 1188 }
1188 1189
1189 static inline void ext4_free_blocks_count_set(struct ext4_super_block *es, 1190 static inline void ext4_free_blocks_count_set(struct ext4_super_block *es,
1190 ext4_fsblk_t blk) 1191 ext4_fsblk_t blk)
1191 { 1192 {
1192 es->s_free_blocks_count_lo = cpu_to_le32((u32)blk); 1193 es->s_free_blocks_count_lo = cpu_to_le32((u32)blk);
1193 es->s_free_blocks_count_hi = cpu_to_le32(blk >> 32); 1194 es->s_free_blocks_count_hi = cpu_to_le32(blk >> 32);
1194 } 1195 }
1195 1196
1196 static inline void ext4_r_blocks_count_set(struct ext4_super_block *es, 1197 static inline void ext4_r_blocks_count_set(struct ext4_super_block *es,
1197 ext4_fsblk_t blk) 1198 ext4_fsblk_t blk)
1198 { 1199 {
1199 es->s_r_blocks_count_lo = cpu_to_le32((u32)blk); 1200 es->s_r_blocks_count_lo = cpu_to_le32((u32)blk);
1200 es->s_r_blocks_count_hi = cpu_to_le32(blk >> 32); 1201 es->s_r_blocks_count_hi = cpu_to_le32(blk >> 32);
1201 } 1202 }
1202 1203
1203 static inline loff_t ext4_isize(struct ext4_inode *raw_inode) 1204 static inline loff_t ext4_isize(struct ext4_inode *raw_inode)
1204 { 1205 {
1205 if (S_ISREG(le16_to_cpu(raw_inode->i_mode))) 1206 if (S_ISREG(le16_to_cpu(raw_inode->i_mode)))
1206 return ((loff_t)le32_to_cpu(raw_inode->i_size_high) << 32) | 1207 return ((loff_t)le32_to_cpu(raw_inode->i_size_high) << 32) |
1207 le32_to_cpu(raw_inode->i_size_lo); 1208 le32_to_cpu(raw_inode->i_size_lo);
1208 else 1209 else
1209 return (loff_t) le32_to_cpu(raw_inode->i_size_lo); 1210 return (loff_t) le32_to_cpu(raw_inode->i_size_lo);
1210 } 1211 }
1211 1212
1212 static inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size) 1213 static inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size)
1213 { 1214 {
1214 raw_inode->i_size_lo = cpu_to_le32(i_size); 1215 raw_inode->i_size_lo = cpu_to_le32(i_size);
1215 raw_inode->i_size_high = cpu_to_le32(i_size >> 32); 1216 raw_inode->i_size_high = cpu_to_le32(i_size >> 32);
1216 } 1217 }
1217 1218
1218 static inline 1219 static inline
1219 struct ext4_group_info *ext4_get_group_info(struct super_block *sb, 1220 struct ext4_group_info *ext4_get_group_info(struct super_block *sb,
1220 ext4_group_t group) 1221 ext4_group_t group)
1221 { 1222 {
1222 struct ext4_group_info ***grp_info; 1223 struct ext4_group_info ***grp_info;
1223 long indexv, indexh; 1224 long indexv, indexh;
1224 grp_info = EXT4_SB(sb)->s_group_info; 1225 grp_info = EXT4_SB(sb)->s_group_info;
1225 indexv = group >> (EXT4_DESC_PER_BLOCK_BITS(sb)); 1226 indexv = group >> (EXT4_DESC_PER_BLOCK_BITS(sb));
1226 indexh = group & ((EXT4_DESC_PER_BLOCK(sb)) - 1); 1227 indexh = group & ((EXT4_DESC_PER_BLOCK(sb)) - 1);
1227 return grp_info[indexv][indexh]; 1228 return grp_info[indexv][indexh];
1228 } 1229 }
1229 1230
1230 1231
1231 static inline ext4_group_t ext4_flex_group(struct ext4_sb_info *sbi, 1232 static inline ext4_group_t ext4_flex_group(struct ext4_sb_info *sbi,
1232 ext4_group_t block_group) 1233 ext4_group_t block_group)
1233 { 1234 {
1234 return block_group >> sbi->s_log_groups_per_flex; 1235 return block_group >> sbi->s_log_groups_per_flex;
1235 } 1236 }
1236 1237
1237 static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi) 1238 static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi)
1238 { 1239 {
1239 return 1 << sbi->s_log_groups_per_flex; 1240 return 1 << sbi->s_log_groups_per_flex;
1240 } 1241 }
1241 1242
1242 #define ext4_std_error(sb, errno) \ 1243 #define ext4_std_error(sb, errno) \
1243 do { \ 1244 do { \
1244 if ((errno)) \ 1245 if ((errno)) \
1245 __ext4_std_error((sb), __func__, (errno)); \ 1246 __ext4_std_error((sb), __func__, (errno)); \
1246 } while (0) 1247 } while (0)
1247 1248
1248 #ifdef CONFIG_SMP 1249 #ifdef CONFIG_SMP
1249 /* Each CPU can accumulate percpu_counter_batch blocks in their local 1250 /* Each CPU can accumulate percpu_counter_batch blocks in their local
1250 * counters. So we need to make sure we have free blocks more 1251 * counters. So we need to make sure we have free blocks more
1251 * than percpu_counter_batch * nr_cpu_ids. Also add a window of 4 times. 1252 * than percpu_counter_batch * nr_cpu_ids. Also add a window of 4 times.
1252 */ 1253 */
1253 #define EXT4_FREEBLOCKS_WATERMARK (4 * (percpu_counter_batch * nr_cpu_ids)) 1254 #define EXT4_FREEBLOCKS_WATERMARK (4 * (percpu_counter_batch * nr_cpu_ids))
1254 #else 1255 #else
1255 #define EXT4_FREEBLOCKS_WATERMARK 0 1256 #define EXT4_FREEBLOCKS_WATERMARK 0
1256 #endif 1257 #endif
1257 1258
1258 static inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize) 1259 static inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize)
1259 { 1260 {
1260 /* 1261 /*
1261 * XXX: replace with spinlock if seen contended -bzzz 1262 * XXX: replace with spinlock if seen contended -bzzz
1262 */ 1263 */
1263 down_write(&EXT4_I(inode)->i_data_sem); 1264 down_write(&EXT4_I(inode)->i_data_sem);
1264 if (newsize > EXT4_I(inode)->i_disksize) 1265 if (newsize > EXT4_I(inode)->i_disksize)
1265 EXT4_I(inode)->i_disksize = newsize; 1266 EXT4_I(inode)->i_disksize = newsize;
1266 up_write(&EXT4_I(inode)->i_data_sem); 1267 up_write(&EXT4_I(inode)->i_data_sem);
1267 return ; 1268 return ;
1268 } 1269 }
1269 1270
1270 struct ext4_group_info { 1271 struct ext4_group_info {
1271 unsigned long bb_state; 1272 unsigned long bb_state;
1272 struct rb_root bb_free_root; 1273 struct rb_root bb_free_root;
1273 unsigned short bb_first_free; 1274 unsigned short bb_first_free;
1274 unsigned short bb_free; 1275 unsigned short bb_free;
1275 unsigned short bb_fragments; 1276 unsigned short bb_fragments;
1276 struct list_head bb_prealloc_list; 1277 struct list_head bb_prealloc_list;
1277 #ifdef DOUBLE_CHECK 1278 #ifdef DOUBLE_CHECK
1278 void *bb_bitmap; 1279 void *bb_bitmap;
1279 #endif 1280 #endif
1280 struct rw_semaphore alloc_sem; 1281 struct rw_semaphore alloc_sem;
1281 unsigned short bb_counters[]; 1282 unsigned short bb_counters[];
1282 }; 1283 };
1283 1284
1284 #define EXT4_GROUP_INFO_NEED_INIT_BIT 0 1285 #define EXT4_GROUP_INFO_NEED_INIT_BIT 0
1285 #define EXT4_GROUP_INFO_LOCKED_BIT 1 1286 #define EXT4_GROUP_INFO_LOCKED_BIT 1
1286 1287
1287 #define EXT4_MB_GRP_NEED_INIT(grp) \ 1288 #define EXT4_MB_GRP_NEED_INIT(grp) \
1288 (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) 1289 (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state)))
1289 1290
1290 static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group) 1291 static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group)
1291 { 1292 {
1292 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); 1293 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group);
1293 1294
1294 bit_spin_lock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state)); 1295 bit_spin_lock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state));
1295 } 1296 }
1296 1297
1297 static inline void ext4_unlock_group(struct super_block *sb, 1298 static inline void ext4_unlock_group(struct super_block *sb,
1298 ext4_group_t group) 1299 ext4_group_t group)
1299 { 1300 {
1300 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); 1301 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group);
1301 1302
1302 bit_spin_unlock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state)); 1303 bit_spin_unlock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state));
1303 } 1304 }
1304 1305
1305 static inline int ext4_is_group_locked(struct super_block *sb, 1306 static inline int ext4_is_group_locked(struct super_block *sb,
1306 ext4_group_t group) 1307 ext4_group_t group)
1307 { 1308 {
1308 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); 1309 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group);
1309 1310
1310 return bit_spin_is_locked(EXT4_GROUP_INFO_LOCKED_BIT, 1311 return bit_spin_is_locked(EXT4_GROUP_INFO_LOCKED_BIT,
1311 &(grinfo->bb_state)); 1312 &(grinfo->bb_state));
1312 } 1313 }
1313 1314
1314 /* 1315 /*
1315 * Inodes and files operations 1316 * Inodes and files operations
1316 */ 1317 */
1317 1318
1318 /* dir.c */ 1319 /* dir.c */
1319 extern const struct file_operations ext4_dir_operations; 1320 extern const struct file_operations ext4_dir_operations;
1320 1321
1321 /* file.c */ 1322 /* file.c */
1322 extern const struct inode_operations ext4_file_inode_operations; 1323 extern const struct inode_operations ext4_file_inode_operations;
1323 extern const struct file_operations ext4_file_operations; 1324 extern const struct file_operations ext4_file_operations;
1324 1325
1325 /* namei.c */ 1326 /* namei.c */
1326 extern const struct inode_operations ext4_dir_inode_operations; 1327 extern const struct inode_operations ext4_dir_inode_operations;
1327 extern const struct inode_operations ext4_special_inode_operations; 1328 extern const struct inode_operations ext4_special_inode_operations;
1328 1329
1329 /* symlink.c */ 1330 /* symlink.c */
1330 extern const struct inode_operations ext4_symlink_inode_operations; 1331 extern const struct inode_operations ext4_symlink_inode_operations;
1331 extern const struct inode_operations ext4_fast_symlink_inode_operations; 1332 extern const struct inode_operations ext4_fast_symlink_inode_operations;
1332 1333
1333 /* extents.c */ 1334 /* extents.c */
1334 extern int ext4_ext_tree_init(handle_t *handle, struct inode *); 1335 extern int ext4_ext_tree_init(handle_t *handle, struct inode *);
1335 extern int ext4_ext_writepage_trans_blocks(struct inode *, int); 1336 extern int ext4_ext_writepage_trans_blocks(struct inode *, int);
1336 extern int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks, 1337 extern int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks,
1337 int chunk); 1338 int chunk);
1338 extern int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, 1339 extern int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
1339 ext4_lblk_t iblock, unsigned int max_blocks, 1340 ext4_lblk_t iblock, unsigned int max_blocks,
1340 struct buffer_head *bh_result, 1341 struct buffer_head *bh_result,
1341 int create, int extend_disksize); 1342 int create, int extend_disksize);
1342 extern void ext4_ext_truncate(struct inode *); 1343 extern void ext4_ext_truncate(struct inode *);
1343 extern void ext4_ext_init(struct super_block *); 1344 extern void ext4_ext_init(struct super_block *);
1344 extern void ext4_ext_release(struct super_block *); 1345 extern void ext4_ext_release(struct super_block *);
1345 extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset, 1346 extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset,
1346 loff_t len); 1347 loff_t len);
1347 extern int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, 1348 extern int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode,
1348 sector_t block, unsigned int max_blocks, 1349 sector_t block, unsigned int max_blocks,
1349 struct buffer_head *bh, int create, 1350 struct buffer_head *bh, int create,
1350 int extend_disksize, int flag); 1351 int extend_disksize, int flag);
1351 extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 1352 extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
1352 __u64 start, __u64 len); 1353 __u64 start, __u64 len);
1353 1354
1354 /* 1355 /*
1355 * Add new method to test wether block and inode bitmaps are properly 1356 * Add new method to test wether block and inode bitmaps are properly
1356 * initialized. With uninit_bg reading the block from disk is not enough 1357 * initialized. With uninit_bg reading the block from disk is not enough
1357 * to mark the bitmap uptodate. We need to also zero-out the bitmap 1358 * to mark the bitmap uptodate. We need to also zero-out the bitmap
1358 */ 1359 */
1359 #define BH_BITMAP_UPTODATE BH_JBDPrivateStart 1360 #define BH_BITMAP_UPTODATE BH_JBDPrivateStart
1360 1361
1361 static inline int bitmap_uptodate(struct buffer_head *bh) 1362 static inline int bitmap_uptodate(struct buffer_head *bh)
1362 { 1363 {
1363 return (buffer_uptodate(bh) && 1364 return (buffer_uptodate(bh) &&
1364 test_bit(BH_BITMAP_UPTODATE, &(bh)->b_state)); 1365 test_bit(BH_BITMAP_UPTODATE, &(bh)->b_state));
1365 } 1366 }
1366 static inline void set_bitmap_uptodate(struct buffer_head *bh) 1367 static inline void set_bitmap_uptodate(struct buffer_head *bh)
1367 { 1368 {
1368 set_bit(BH_BITMAP_UPTODATE, &(bh)->b_state); 1369 set_bit(BH_BITMAP_UPTODATE, &(bh)->b_state);
1369 } 1370 }
1370 1371
1371 #endif /* __KERNEL__ */ 1372 #endif /* __KERNEL__ */
1372 1373
1373 #endif /* _EXT4_H */ 1374 #endif /* _EXT4_H */
1374 1375
1 /* 1 /*
2 * linux/fs/ext4/ialloc.c 2 * linux/fs/ext4/ialloc.c
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal 6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI) 7 * Universite Pierre et Marie Curie (Paris VI)
8 * 8 *
9 * BSD ufs-inspired inode and directory allocation by 9 * BSD ufs-inspired inode and directory allocation by
10 * Stephen Tweedie (sct@redhat.com), 1993 10 * Stephen Tweedie (sct@redhat.com), 1993
11 * Big-endian to little-endian byte-swapping/bitmaps by 11 * Big-endian to little-endian byte-swapping/bitmaps by
12 * David S. Miller (davem@caip.rutgers.edu), 1995 12 * David S. Miller (davem@caip.rutgers.edu), 1995
13 */ 13 */
14 14
15 #include <linux/time.h> 15 #include <linux/time.h>
16 #include <linux/fs.h> 16 #include <linux/fs.h>
17 #include <linux/jbd2.h> 17 #include <linux/jbd2.h>
18 #include <linux/stat.h> 18 #include <linux/stat.h>
19 #include <linux/string.h> 19 #include <linux/string.h>
20 #include <linux/quotaops.h> 20 #include <linux/quotaops.h>
21 #include <linux/buffer_head.h> 21 #include <linux/buffer_head.h>
22 #include <linux/random.h> 22 #include <linux/random.h>
23 #include <linux/bitops.h> 23 #include <linux/bitops.h>
24 #include <linux/blkdev.h> 24 #include <linux/blkdev.h>
25 #include <asm/byteorder.h> 25 #include <asm/byteorder.h>
26 #include "ext4.h" 26 #include "ext4.h"
27 #include "ext4_jbd2.h" 27 #include "ext4_jbd2.h"
28 #include "xattr.h" 28 #include "xattr.h"
29 #include "acl.h" 29 #include "acl.h"
30 #include "group.h" 30 #include "group.h"
31 31
32 /* 32 /*
33 * ialloc.c contains the inodes allocation and deallocation routines 33 * ialloc.c contains the inodes allocation and deallocation routines
34 */ 34 */
35 35
36 /* 36 /*
37 * The free inodes are managed by bitmaps. A file system contains several 37 * The free inodes are managed by bitmaps. A file system contains several
38 * blocks groups. Each group contains 1 bitmap block for blocks, 1 bitmap 38 * blocks groups. Each group contains 1 bitmap block for blocks, 1 bitmap
39 * block for inodes, N blocks for the inode table and data blocks. 39 * block for inodes, N blocks for the inode table and data blocks.
40 * 40 *
41 * The file system contains group descriptors which are located after the 41 * The file system contains group descriptors which are located after the
42 * super block. Each descriptor contains the number of the bitmap block and 42 * super block. Each descriptor contains the number of the bitmap block and
43 * the free blocks count in the block. 43 * the free blocks count in the block.
44 */ 44 */
45 45
46 /* 46 /*
47 * To avoid calling the atomic setbit hundreds or thousands of times, we only 47 * To avoid calling the atomic setbit hundreds or thousands of times, we only
48 * need to use it within a single byte (to ensure we get endianness right). 48 * need to use it within a single byte (to ensure we get endianness right).
49 * We can use memset for the rest of the bitmap as there are no other users. 49 * We can use memset for the rest of the bitmap as there are no other users.
50 */ 50 */
51 void mark_bitmap_end(int start_bit, int end_bit, char *bitmap) 51 void mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
52 { 52 {
53 int i; 53 int i;
54 54
55 if (start_bit >= end_bit) 55 if (start_bit >= end_bit)
56 return; 56 return;
57 57
58 ext4_debug("mark end bits +%d through +%d used\n", start_bit, end_bit); 58 ext4_debug("mark end bits +%d through +%d used\n", start_bit, end_bit);
59 for (i = start_bit; i < ((start_bit + 7) & ~7UL); i++) 59 for (i = start_bit; i < ((start_bit + 7) & ~7UL); i++)
60 ext4_set_bit(i, bitmap); 60 ext4_set_bit(i, bitmap);
61 if (i < end_bit) 61 if (i < end_bit)
62 memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3); 62 memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3);
63 } 63 }
64 64
65 /* Initializes an uninitialized inode bitmap */ 65 /* Initializes an uninitialized inode bitmap */
66 unsigned ext4_init_inode_bitmap(struct super_block *sb, struct buffer_head *bh, 66 unsigned ext4_init_inode_bitmap(struct super_block *sb, struct buffer_head *bh,
67 ext4_group_t block_group, 67 ext4_group_t block_group,
68 struct ext4_group_desc *gdp) 68 struct ext4_group_desc *gdp)
69 { 69 {
70 struct ext4_sb_info *sbi = EXT4_SB(sb); 70 struct ext4_sb_info *sbi = EXT4_SB(sb);
71 71
72 J_ASSERT_BH(bh, buffer_locked(bh)); 72 J_ASSERT_BH(bh, buffer_locked(bh));
73 73
74 /* If checksum is bad mark all blocks and inodes use to prevent 74 /* If checksum is bad mark all blocks and inodes use to prevent
75 * allocation, essentially implementing a per-group read-only flag. */ 75 * allocation, essentially implementing a per-group read-only flag. */
76 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { 76 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) {
77 ext4_error(sb, __func__, "Checksum bad for group %u", 77 ext4_error(sb, __func__, "Checksum bad for group %u",
78 block_group); 78 block_group);
79 ext4_free_blks_set(sb, gdp, 0); 79 ext4_free_blks_set(sb, gdp, 0);
80 ext4_free_inodes_set(sb, gdp, 0); 80 ext4_free_inodes_set(sb, gdp, 0);
81 ext4_itable_unused_set(sb, gdp, 0); 81 ext4_itable_unused_set(sb, gdp, 0);
82 memset(bh->b_data, 0xff, sb->s_blocksize); 82 memset(bh->b_data, 0xff, sb->s_blocksize);
83 return 0; 83 return 0;
84 } 84 }
85 85
86 memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8); 86 memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8);
87 mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), sb->s_blocksize * 8, 87 mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), sb->s_blocksize * 8,
88 bh->b_data); 88 bh->b_data);
89 89
90 return EXT4_INODES_PER_GROUP(sb); 90 return EXT4_INODES_PER_GROUP(sb);
91 } 91 }
92 92
93 /* 93 /*
94 * Read the inode allocation bitmap for a given block_group, reading 94 * Read the inode allocation bitmap for a given block_group, reading
95 * into the specified slot in the superblock's bitmap cache. 95 * into the specified slot in the superblock's bitmap cache.
96 * 96 *
97 * Return buffer_head of bitmap on success or NULL. 97 * Return buffer_head of bitmap on success or NULL.
98 */ 98 */
99 static struct buffer_head * 99 static struct buffer_head *
100 ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group) 100 ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
101 { 101 {
102 struct ext4_group_desc *desc; 102 struct ext4_group_desc *desc;
103 struct buffer_head *bh = NULL; 103 struct buffer_head *bh = NULL;
104 ext4_fsblk_t bitmap_blk; 104 ext4_fsblk_t bitmap_blk;
105 105
106 desc = ext4_get_group_desc(sb, block_group, NULL); 106 desc = ext4_get_group_desc(sb, block_group, NULL);
107 if (!desc) 107 if (!desc)
108 return NULL; 108 return NULL;
109 bitmap_blk = ext4_inode_bitmap(sb, desc); 109 bitmap_blk = ext4_inode_bitmap(sb, desc);
110 bh = sb_getblk(sb, bitmap_blk); 110 bh = sb_getblk(sb, bitmap_blk);
111 if (unlikely(!bh)) { 111 if (unlikely(!bh)) {
112 ext4_error(sb, __func__, 112 ext4_error(sb, __func__,
113 "Cannot read inode bitmap - " 113 "Cannot read inode bitmap - "
114 "block_group = %u, inode_bitmap = %llu", 114 "block_group = %u, inode_bitmap = %llu",
115 block_group, bitmap_blk); 115 block_group, bitmap_blk);
116 return NULL; 116 return NULL;
117 } 117 }
118 if (bitmap_uptodate(bh)) 118 if (bitmap_uptodate(bh))
119 return bh; 119 return bh;
120 120
121 lock_buffer(bh); 121 lock_buffer(bh);
122 if (bitmap_uptodate(bh)) { 122 if (bitmap_uptodate(bh)) {
123 unlock_buffer(bh); 123 unlock_buffer(bh);
124 return bh; 124 return bh;
125 } 125 }
126 spin_lock(sb_bgl_lock(EXT4_SB(sb), block_group)); 126 spin_lock(sb_bgl_lock(EXT4_SB(sb), block_group));
127 if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) { 127 if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {
128 ext4_init_inode_bitmap(sb, bh, block_group, desc); 128 ext4_init_inode_bitmap(sb, bh, block_group, desc);
129 set_bitmap_uptodate(bh); 129 set_bitmap_uptodate(bh);
130 set_buffer_uptodate(bh); 130 set_buffer_uptodate(bh);
131 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group)); 131 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group));
132 unlock_buffer(bh); 132 unlock_buffer(bh);
133 return bh; 133 return bh;
134 } 134 }
135 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group)); 135 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group));
136 if (buffer_uptodate(bh)) { 136 if (buffer_uptodate(bh)) {
137 /* 137 /*
138 * if not uninit if bh is uptodate, 138 * if not uninit if bh is uptodate,
139 * bitmap is also uptodate 139 * bitmap is also uptodate
140 */ 140 */
141 set_bitmap_uptodate(bh); 141 set_bitmap_uptodate(bh);
142 unlock_buffer(bh); 142 unlock_buffer(bh);
143 return bh; 143 return bh;
144 } 144 }
145 /* 145 /*
146 * submit the buffer_head for read. We can 146 * submit the buffer_head for read. We can
147 * safely mark the bitmap as uptodate now. 147 * safely mark the bitmap as uptodate now.
148 * We do it here so the bitmap uptodate bit 148 * We do it here so the bitmap uptodate bit
149 * get set with buffer lock held. 149 * get set with buffer lock held.
150 */ 150 */
151 set_bitmap_uptodate(bh); 151 set_bitmap_uptodate(bh);
152 if (bh_submit_read(bh) < 0) { 152 if (bh_submit_read(bh) < 0) {
153 put_bh(bh); 153 put_bh(bh);
154 ext4_error(sb, __func__, 154 ext4_error(sb, __func__,
155 "Cannot read inode bitmap - " 155 "Cannot read inode bitmap - "
156 "block_group = %u, inode_bitmap = %llu", 156 "block_group = %u, inode_bitmap = %llu",
157 block_group, bitmap_blk); 157 block_group, bitmap_blk);
158 return NULL; 158 return NULL;
159 } 159 }
160 return bh; 160 return bh;
161 } 161 }
162 162
163 /* 163 /*
164 * NOTE! When we get the inode, we're the only people 164 * NOTE! When we get the inode, we're the only people
165 * that have access to it, and as such there are no 165 * that have access to it, and as such there are no
166 * race conditions we have to worry about. The inode 166 * race conditions we have to worry about. The inode
167 * is not on the hash-lists, and it cannot be reached 167 * is not on the hash-lists, and it cannot be reached
168 * through the filesystem because the directory entry 168 * through the filesystem because the directory entry
169 * has been deleted earlier. 169 * has been deleted earlier.
170 * 170 *
171 * HOWEVER: we must make sure that we get no aliases, 171 * HOWEVER: we must make sure that we get no aliases,
172 * which means that we have to call "clear_inode()" 172 * which means that we have to call "clear_inode()"
173 * _before_ we mark the inode not in use in the inode 173 * _before_ we mark the inode not in use in the inode
174 * bitmaps. Otherwise a newly created file might use 174 * bitmaps. Otherwise a newly created file might use
175 * the same inode number (not actually the same pointer 175 * the same inode number (not actually the same pointer
176 * though), and then we'd have two inodes sharing the 176 * though), and then we'd have two inodes sharing the
177 * same inode number and space on the harddisk. 177 * same inode number and space on the harddisk.
178 */ 178 */
179 void ext4_free_inode(handle_t *handle, struct inode *inode) 179 void ext4_free_inode(handle_t *handle, struct inode *inode)
180 { 180 {
181 struct super_block *sb = inode->i_sb; 181 struct super_block *sb = inode->i_sb;
182 int is_directory; 182 int is_directory;
183 unsigned long ino; 183 unsigned long ino;
184 struct buffer_head *bitmap_bh = NULL; 184 struct buffer_head *bitmap_bh = NULL;
185 struct buffer_head *bh2; 185 struct buffer_head *bh2;
186 ext4_group_t block_group; 186 ext4_group_t block_group;
187 unsigned long bit; 187 unsigned long bit;
188 struct ext4_group_desc *gdp; 188 struct ext4_group_desc *gdp;
189 struct ext4_super_block *es; 189 struct ext4_super_block *es;
190 struct ext4_sb_info *sbi; 190 struct ext4_sb_info *sbi;
191 int fatal = 0, err, count, cleared; 191 int fatal = 0, err, count, cleared;
192 192
193 if (atomic_read(&inode->i_count) > 1) { 193 if (atomic_read(&inode->i_count) > 1) {
194 printk(KERN_ERR "ext4_free_inode: inode has count=%d\n", 194 printk(KERN_ERR "ext4_free_inode: inode has count=%d\n",
195 atomic_read(&inode->i_count)); 195 atomic_read(&inode->i_count));
196 return; 196 return;
197 } 197 }
198 if (inode->i_nlink) { 198 if (inode->i_nlink) {
199 printk(KERN_ERR "ext4_free_inode: inode has nlink=%d\n", 199 printk(KERN_ERR "ext4_free_inode: inode has nlink=%d\n",
200 inode->i_nlink); 200 inode->i_nlink);
201 return; 201 return;
202 } 202 }
203 if (!sb) { 203 if (!sb) {
204 printk(KERN_ERR "ext4_free_inode: inode on " 204 printk(KERN_ERR "ext4_free_inode: inode on "
205 "nonexistent device\n"); 205 "nonexistent device\n");
206 return; 206 return;
207 } 207 }
208 sbi = EXT4_SB(sb); 208 sbi = EXT4_SB(sb);
209 209
210 ino = inode->i_ino; 210 ino = inode->i_ino;
211 ext4_debug("freeing inode %lu\n", ino); 211 ext4_debug("freeing inode %lu\n", ino);
212 trace_mark(ext4_free_inode, 212 trace_mark(ext4_free_inode,
213 "dev %s ino %lu mode %d uid %lu gid %lu bocks %llu", 213 "dev %s ino %lu mode %d uid %lu gid %lu bocks %llu",
214 sb->s_id, inode->i_ino, inode->i_mode, 214 sb->s_id, inode->i_ino, inode->i_mode,
215 (unsigned long) inode->i_uid, (unsigned long) inode->i_gid, 215 (unsigned long) inode->i_uid, (unsigned long) inode->i_gid,
216 (unsigned long long) inode->i_blocks); 216 (unsigned long long) inode->i_blocks);
217 217
218 /* 218 /*
219 * Note: we must free any quota before locking the superblock, 219 * Note: we must free any quota before locking the superblock,
220 * as writing the quota to disk may need the lock as well. 220 * as writing the quota to disk may need the lock as well.
221 */ 221 */
222 vfs_dq_init(inode); 222 vfs_dq_init(inode);
223 ext4_xattr_delete_inode(handle, inode); 223 ext4_xattr_delete_inode(handle, inode);
224 vfs_dq_free_inode(inode); 224 vfs_dq_free_inode(inode);
225 vfs_dq_drop(inode); 225 vfs_dq_drop(inode);
226 226
227 is_directory = S_ISDIR(inode->i_mode); 227 is_directory = S_ISDIR(inode->i_mode);
228 228
229 /* Do this BEFORE marking the inode not in use or returning an error */ 229 /* Do this BEFORE marking the inode not in use or returning an error */
230 clear_inode(inode); 230 clear_inode(inode);
231 231
232 es = EXT4_SB(sb)->s_es; 232 es = EXT4_SB(sb)->s_es;
233 if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) { 233 if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
234 ext4_error(sb, "ext4_free_inode", 234 ext4_error(sb, "ext4_free_inode",
235 "reserved or nonexistent inode %lu", ino); 235 "reserved or nonexistent inode %lu", ino);
236 goto error_return; 236 goto error_return;
237 } 237 }
238 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); 238 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
239 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); 239 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
240 bitmap_bh = ext4_read_inode_bitmap(sb, block_group); 240 bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
241 if (!bitmap_bh) 241 if (!bitmap_bh)
242 goto error_return; 242 goto error_return;
243 243
244 BUFFER_TRACE(bitmap_bh, "get_write_access"); 244 BUFFER_TRACE(bitmap_bh, "get_write_access");
245 fatal = ext4_journal_get_write_access(handle, bitmap_bh); 245 fatal = ext4_journal_get_write_access(handle, bitmap_bh);
246 if (fatal) 246 if (fatal)
247 goto error_return; 247 goto error_return;
248 248
249 /* Ok, now we can actually update the inode bitmaps.. */ 249 /* Ok, now we can actually update the inode bitmaps.. */
250 spin_lock(sb_bgl_lock(sbi, block_group)); 250 spin_lock(sb_bgl_lock(sbi, block_group));
251 cleared = ext4_clear_bit(bit, bitmap_bh->b_data); 251 cleared = ext4_clear_bit(bit, bitmap_bh->b_data);
252 spin_unlock(sb_bgl_lock(sbi, block_group)); 252 spin_unlock(sb_bgl_lock(sbi, block_group));
253 if (!cleared) 253 if (!cleared)
254 ext4_error(sb, "ext4_free_inode", 254 ext4_error(sb, "ext4_free_inode",
255 "bit already cleared for inode %lu", ino); 255 "bit already cleared for inode %lu", ino);
256 else { 256 else {
257 gdp = ext4_get_group_desc(sb, block_group, &bh2); 257 gdp = ext4_get_group_desc(sb, block_group, &bh2);
258 258
259 BUFFER_TRACE(bh2, "get_write_access"); 259 BUFFER_TRACE(bh2, "get_write_access");
260 fatal = ext4_journal_get_write_access(handle, bh2); 260 fatal = ext4_journal_get_write_access(handle, bh2);
261 if (fatal) goto error_return; 261 if (fatal) goto error_return;
262 262
263 if (gdp) { 263 if (gdp) {
264 spin_lock(sb_bgl_lock(sbi, block_group)); 264 spin_lock(sb_bgl_lock(sbi, block_group));
265 count = ext4_free_inodes_count(sb, gdp) + 1; 265 count = ext4_free_inodes_count(sb, gdp) + 1;
266 ext4_free_inodes_set(sb, gdp, count); 266 ext4_free_inodes_set(sb, gdp, count);
267 if (is_directory) { 267 if (is_directory) {
268 count = ext4_used_dirs_count(sb, gdp) - 1; 268 count = ext4_used_dirs_count(sb, gdp) - 1;
269 ext4_used_dirs_set(sb, gdp, count); 269 ext4_used_dirs_set(sb, gdp, count);
270 if (sbi->s_log_groups_per_flex) {
271 ext4_group_t f;
272
273 f = ext4_flex_group(sbi, block_group);
274 atomic_dec(&sbi->s_flex_groups[f].free_inodes);
275 }
276
270 } 277 }
271 gdp->bg_checksum = ext4_group_desc_csum(sbi, 278 gdp->bg_checksum = ext4_group_desc_csum(sbi,
272 block_group, gdp); 279 block_group, gdp);
273 spin_unlock(sb_bgl_lock(sbi, block_group)); 280 spin_unlock(sb_bgl_lock(sbi, block_group));
274 percpu_counter_inc(&sbi->s_freeinodes_counter); 281 percpu_counter_inc(&sbi->s_freeinodes_counter);
275 if (is_directory) 282 if (is_directory)
276 percpu_counter_dec(&sbi->s_dirs_counter); 283 percpu_counter_dec(&sbi->s_dirs_counter);
277 284
278 if (sbi->s_log_groups_per_flex) { 285 if (sbi->s_log_groups_per_flex) {
279 ext4_group_t f; 286 ext4_group_t f;
280 287
281 f = ext4_flex_group(sbi, block_group); 288 f = ext4_flex_group(sbi, block_group);
282 atomic_inc(&sbi->s_flex_groups[f].free_inodes); 289 atomic_inc(&sbi->s_flex_groups[f].free_inodes);
283 } 290 }
284 } 291 }
285 BUFFER_TRACE(bh2, "call ext4_handle_dirty_metadata"); 292 BUFFER_TRACE(bh2, "call ext4_handle_dirty_metadata");
286 err = ext4_handle_dirty_metadata(handle, NULL, bh2); 293 err = ext4_handle_dirty_metadata(handle, NULL, bh2);
287 if (!fatal) fatal = err; 294 if (!fatal) fatal = err;
288 } 295 }
289 BUFFER_TRACE(bitmap_bh, "call ext4_handle_dirty_metadata"); 296 BUFFER_TRACE(bitmap_bh, "call ext4_handle_dirty_metadata");
290 err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh); 297 err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh);
291 if (!fatal) 298 if (!fatal)
292 fatal = err; 299 fatal = err;
293 sb->s_dirt = 1; 300 sb->s_dirt = 1;
294 error_return: 301 error_return:
295 brelse(bitmap_bh); 302 brelse(bitmap_bh);
296 ext4_std_error(sb, fatal); 303 ext4_std_error(sb, fatal);
297 } 304 }
298 305
299 /* 306 /*
300 * There are two policies for allocating an inode. If the new inode is 307 * There are two policies for allocating an inode. If the new inode is
301 * a directory, then a forward search is made for a block group with both 308 * a directory, then a forward search is made for a block group with both
302 * free space and a low directory-to-inode ratio; if that fails, then of 309 * free space and a low directory-to-inode ratio; if that fails, then of
303 * the groups with above-average free space, that group with the fewest 310 * the groups with above-average free space, that group with the fewest
304 * directories already is chosen. 311 * directories already is chosen.
305 * 312 *
306 * For other inodes, search forward from the parent directory\'s block 313 * For other inodes, search forward from the parent directory\'s block
307 * group to find a free inode. 314 * group to find a free inode.
308 */ 315 */
309 static int find_group_dir(struct super_block *sb, struct inode *parent, 316 static int find_group_dir(struct super_block *sb, struct inode *parent,
310 ext4_group_t *best_group) 317 ext4_group_t *best_group)
311 { 318 {
312 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; 319 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count;
313 unsigned int freei, avefreei; 320 unsigned int freei, avefreei;
314 struct ext4_group_desc *desc, *best_desc = NULL; 321 struct ext4_group_desc *desc, *best_desc = NULL;
315 ext4_group_t group; 322 ext4_group_t group;
316 int ret = -1; 323 int ret = -1;
317 324
318 freei = percpu_counter_read_positive(&EXT4_SB(sb)->s_freeinodes_counter); 325 freei = percpu_counter_read_positive(&EXT4_SB(sb)->s_freeinodes_counter);
319 avefreei = freei / ngroups; 326 avefreei = freei / ngroups;
320 327
321 for (group = 0; group < ngroups; group++) { 328 for (group = 0; group < ngroups; group++) {
322 desc = ext4_get_group_desc(sb, group, NULL); 329 desc = ext4_get_group_desc(sb, group, NULL);
323 if (!desc || !ext4_free_inodes_count(sb, desc)) 330 if (!desc || !ext4_free_inodes_count(sb, desc))
324 continue; 331 continue;
325 if (ext4_free_inodes_count(sb, desc) < avefreei) 332 if (ext4_free_inodes_count(sb, desc) < avefreei)
326 continue; 333 continue;
327 if (!best_desc || 334 if (!best_desc ||
328 (ext4_free_blks_count(sb, desc) > 335 (ext4_free_blks_count(sb, desc) >
329 ext4_free_blks_count(sb, best_desc))) { 336 ext4_free_blks_count(sb, best_desc))) {
330 *best_group = group; 337 *best_group = group;
331 best_desc = desc; 338 best_desc = desc;
332 ret = 0; 339 ret = 0;
333 } 340 }
334 } 341 }
335 return ret; 342 return ret;
336 } 343 }
337 344
338 #define free_block_ratio 10 345 #define free_block_ratio 10
339 346
340 static int find_group_flex(struct super_block *sb, struct inode *parent, 347 static int find_group_flex(struct super_block *sb, struct inode *parent,
341 ext4_group_t *best_group) 348 ext4_group_t *best_group)
342 { 349 {
343 struct ext4_sb_info *sbi = EXT4_SB(sb); 350 struct ext4_sb_info *sbi = EXT4_SB(sb);
344 struct ext4_group_desc *desc; 351 struct ext4_group_desc *desc;
345 struct buffer_head *bh; 352 struct buffer_head *bh;
346 struct flex_groups *flex_group = sbi->s_flex_groups; 353 struct flex_groups *flex_group = sbi->s_flex_groups;
347 ext4_group_t parent_group = EXT4_I(parent)->i_block_group; 354 ext4_group_t parent_group = EXT4_I(parent)->i_block_group;
348 ext4_group_t parent_fbg_group = ext4_flex_group(sbi, parent_group); 355 ext4_group_t parent_fbg_group = ext4_flex_group(sbi, parent_group);
349 ext4_group_t ngroups = sbi->s_groups_count; 356 ext4_group_t ngroups = sbi->s_groups_count;
350 int flex_size = ext4_flex_bg_size(sbi); 357 int flex_size = ext4_flex_bg_size(sbi);
351 ext4_group_t best_flex = parent_fbg_group; 358 ext4_group_t best_flex = parent_fbg_group;
352 int blocks_per_flex = sbi->s_blocks_per_group * flex_size; 359 int blocks_per_flex = sbi->s_blocks_per_group * flex_size;
353 int flexbg_free_blocks; 360 int flexbg_free_blocks;
354 int flex_freeb_ratio; 361 int flex_freeb_ratio;
355 ext4_group_t n_fbg_groups; 362 ext4_group_t n_fbg_groups;
356 ext4_group_t i; 363 ext4_group_t i;
357 364
358 n_fbg_groups = (sbi->s_groups_count + flex_size - 1) >> 365 n_fbg_groups = (sbi->s_groups_count + flex_size - 1) >>
359 sbi->s_log_groups_per_flex; 366 sbi->s_log_groups_per_flex;
360 367
361 find_close_to_parent: 368 find_close_to_parent:
362 flexbg_free_blocks = atomic_read(&flex_group[best_flex].free_blocks); 369 flexbg_free_blocks = atomic_read(&flex_group[best_flex].free_blocks);
363 flex_freeb_ratio = flexbg_free_blocks * 100 / blocks_per_flex; 370 flex_freeb_ratio = flexbg_free_blocks * 100 / blocks_per_flex;
364 if (atomic_read(&flex_group[best_flex].free_inodes) && 371 if (atomic_read(&flex_group[best_flex].free_inodes) &&
365 flex_freeb_ratio > free_block_ratio) 372 flex_freeb_ratio > free_block_ratio)
366 goto found_flexbg; 373 goto found_flexbg;
367 374
368 if (best_flex && best_flex == parent_fbg_group) { 375 if (best_flex && best_flex == parent_fbg_group) {
369 best_flex--; 376 best_flex--;
370 goto find_close_to_parent; 377 goto find_close_to_parent;
371 } 378 }
372 379
373 for (i = 0; i < n_fbg_groups; i++) { 380 for (i = 0; i < n_fbg_groups; i++) {
374 if (i == parent_fbg_group || i == parent_fbg_group - 1) 381 if (i == parent_fbg_group || i == parent_fbg_group - 1)
375 continue; 382 continue;
376 383
377 flexbg_free_blocks = atomic_read(&flex_group[i].free_blocks); 384 flexbg_free_blocks = atomic_read(&flex_group[i].free_blocks);
378 flex_freeb_ratio = flexbg_free_blocks * 100 / blocks_per_flex; 385 flex_freeb_ratio = flexbg_free_blocks * 100 / blocks_per_flex;
379 386
380 if (flex_freeb_ratio > free_block_ratio && 387 if (flex_freeb_ratio > free_block_ratio &&
381 (atomic_read(&flex_group[i].free_inodes))) { 388 (atomic_read(&flex_group[i].free_inodes))) {
382 best_flex = i; 389 best_flex = i;
383 goto found_flexbg; 390 goto found_flexbg;
384 } 391 }
385 392
386 if ((atomic_read(&flex_group[best_flex].free_inodes) == 0) || 393 if ((atomic_read(&flex_group[best_flex].free_inodes) == 0) ||
387 ((atomic_read(&flex_group[i].free_blocks) > 394 ((atomic_read(&flex_group[i].free_blocks) >
388 atomic_read(&flex_group[best_flex].free_blocks)) && 395 atomic_read(&flex_group[best_flex].free_blocks)) &&
389 atomic_read(&flex_group[i].free_inodes))) 396 atomic_read(&flex_group[i].free_inodes)))
390 best_flex = i; 397 best_flex = i;
391 } 398 }
392 399
393 if (!atomic_read(&flex_group[best_flex].free_inodes) || 400 if (!atomic_read(&flex_group[best_flex].free_inodes) ||
394 !atomic_read(&flex_group[best_flex].free_blocks)) 401 !atomic_read(&flex_group[best_flex].free_blocks))
395 return -1; 402 return -1;
396 403
397 found_flexbg: 404 found_flexbg:
398 for (i = best_flex * flex_size; i < ngroups && 405 for (i = best_flex * flex_size; i < ngroups &&
399 i < (best_flex + 1) * flex_size; i++) { 406 i < (best_flex + 1) * flex_size; i++) {
400 desc = ext4_get_group_desc(sb, i, &bh); 407 desc = ext4_get_group_desc(sb, i, &bh);
401 if (ext4_free_inodes_count(sb, desc)) { 408 if (ext4_free_inodes_count(sb, desc)) {
402 *best_group = i; 409 *best_group = i;
403 goto out; 410 goto out;
404 } 411 }
405 } 412 }
406 413
407 return -1; 414 return -1;
408 out: 415 out:
409 return 0; 416 return 0;
410 } 417 }
411 418
412 struct orlov_stats { 419 struct orlov_stats {
413 __u32 free_inodes; 420 __u32 free_inodes;
414 __u32 free_blocks; 421 __u32 free_blocks;
415 __u32 used_dirs; 422 __u32 used_dirs;
416 }; 423 };
417 424
418 /* 425 /*
419 * Helper function for Orlov's allocator; returns critical information 426 * Helper function for Orlov's allocator; returns critical information
420 * for a particular block group or flex_bg. If flex_size is 1, then g 427 * for a particular block group or flex_bg. If flex_size is 1, then g
421 * is a block group number; otherwise it is flex_bg number. 428 * is a block group number; otherwise it is flex_bg number.
422 */ 429 */
423 void get_orlov_stats(struct super_block *sb, ext4_group_t g, 430 void get_orlov_stats(struct super_block *sb, ext4_group_t g,
424 int flex_size, struct orlov_stats *stats) 431 int flex_size, struct orlov_stats *stats)
425 { 432 {
426 struct ext4_group_desc *desc; 433 struct ext4_group_desc *desc;
427 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; 434 struct flex_groups *flex_group = EXT4_SB(sb)->s_flex_groups;
428 int i;
429 435
430 stats->free_inodes = 0; 436 if (flex_size > 1) {
431 stats->free_blocks = 0; 437 stats->free_inodes = atomic_read(&flex_group[g].free_inodes);
432 stats->used_dirs = 0; 438 stats->free_blocks = atomic_read(&flex_group[g].free_blocks);
439 stats->used_dirs = atomic_read(&flex_group[g].used_dirs);
440 return;
441 }
433 442
434 g *= flex_size; 443 desc = ext4_get_group_desc(sb, g, NULL);
435 444 if (desc) {
436 for (i = 0; i < flex_size; i++) { 445 stats->free_inodes = ext4_free_inodes_count(sb, desc);
437 if (g >= ngroups) 446 stats->free_blocks = ext4_free_blks_count(sb, desc);
438 break; 447 stats->used_dirs = ext4_used_dirs_count(sb, desc);
439 desc = ext4_get_group_desc(sb, g++, NULL); 448 } else {
440 if (!desc) 449 stats->free_inodes = 0;
441 continue; 450 stats->free_blocks = 0;
442 451 stats->used_dirs = 0;
443 stats->free_inodes += ext4_free_inodes_count(sb, desc);
444 stats->free_blocks += ext4_free_blks_count(sb, desc);
445 stats->used_dirs += ext4_used_dirs_count(sb, desc);
446 } 452 }
447 } 453 }
448 454
449 /* 455 /*
450 * Orlov's allocator for directories. 456 * Orlov's allocator for directories.
451 * 457 *
452 * We always try to spread first-level directories. 458 * We always try to spread first-level directories.
453 * 459 *
454 * If there are blockgroups with both free inodes and free blocks counts 460 * If there are blockgroups with both free inodes and free blocks counts
455 * not worse than average we return one with smallest directory count. 461 * not worse than average we return one with smallest directory count.
456 * Otherwise we simply return a random group. 462 * Otherwise we simply return a random group.
457 * 463 *
458 * For the rest rules look so: 464 * For the rest rules look so:
459 * 465 *
460 * It's OK to put directory into a group unless 466 * It's OK to put directory into a group unless
461 * it has too many directories already (max_dirs) or 467 * it has too many directories already (max_dirs) or
462 * it has too few free inodes left (min_inodes) or 468 * it has too few free inodes left (min_inodes) or
463 * it has too few free blocks left (min_blocks) or 469 * it has too few free blocks left (min_blocks) or
464 * Parent's group is preferred, if it doesn't satisfy these 470 * Parent's group is preferred, if it doesn't satisfy these
465 * conditions we search cyclically through the rest. If none 471 * conditions we search cyclically through the rest. If none
466 * of the groups look good we just look for a group with more 472 * of the groups look good we just look for a group with more
467 * free inodes than average (starting at parent's group). 473 * free inodes than average (starting at parent's group).
468 */ 474 */
469 475
470 static int find_group_orlov(struct super_block *sb, struct inode *parent, 476 static int find_group_orlov(struct super_block *sb, struct inode *parent,
471 ext4_group_t *group, int mode) 477 ext4_group_t *group, int mode)
472 { 478 {
473 ext4_group_t parent_group = EXT4_I(parent)->i_block_group; 479 ext4_group_t parent_group = EXT4_I(parent)->i_block_group;
474 struct ext4_sb_info *sbi = EXT4_SB(sb); 480 struct ext4_sb_info *sbi = EXT4_SB(sb);
475 ext4_group_t ngroups = sbi->s_groups_count; 481 ext4_group_t ngroups = sbi->s_groups_count;
476 int inodes_per_group = EXT4_INODES_PER_GROUP(sb); 482 int inodes_per_group = EXT4_INODES_PER_GROUP(sb);
477 unsigned int freei, avefreei; 483 unsigned int freei, avefreei;
478 ext4_fsblk_t freeb, avefreeb; 484 ext4_fsblk_t freeb, avefreeb;
479 unsigned int ndirs; 485 unsigned int ndirs;
480 int max_dirs, min_inodes; 486 int max_dirs, min_inodes;
481 ext4_grpblk_t min_blocks; 487 ext4_grpblk_t min_blocks;
482 ext4_group_t i, grp, g; 488 ext4_group_t i, grp, g;
483 struct ext4_group_desc *desc; 489 struct ext4_group_desc *desc;
484 struct orlov_stats stats; 490 struct orlov_stats stats;
485 int flex_size = ext4_flex_bg_size(sbi); 491 int flex_size = ext4_flex_bg_size(sbi);
486 492
487 if (flex_size > 1) { 493 if (flex_size > 1) {
488 ngroups = (ngroups + flex_size - 1) >> 494 ngroups = (ngroups + flex_size - 1) >>
489 sbi->s_log_groups_per_flex; 495 sbi->s_log_groups_per_flex;
490 parent_group >>= sbi->s_log_groups_per_flex; 496 parent_group >>= sbi->s_log_groups_per_flex;
491 } 497 }
492 498
493 freei = percpu_counter_read_positive(&sbi->s_freeinodes_counter); 499 freei = percpu_counter_read_positive(&sbi->s_freeinodes_counter);
494 avefreei = freei / ngroups; 500 avefreei = freei / ngroups;
495 freeb = percpu_counter_read_positive(&sbi->s_freeblocks_counter); 501 freeb = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
496 avefreeb = freeb; 502 avefreeb = freeb;
497 do_div(avefreeb, ngroups); 503 do_div(avefreeb, ngroups);
498 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter); 504 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter);
499 505
500 if (S_ISDIR(mode) && 506 if (S_ISDIR(mode) &&
501 ((parent == sb->s_root->d_inode) || 507 ((parent == sb->s_root->d_inode) ||
502 (EXT4_I(parent)->i_flags & EXT4_TOPDIR_FL))) { 508 (EXT4_I(parent)->i_flags & EXT4_TOPDIR_FL))) {
503 int best_ndir = inodes_per_group; 509 int best_ndir = inodes_per_group;
504 int ret = -1; 510 int ret = -1;
505 511
506 get_random_bytes(&grp, sizeof(grp)); 512 get_random_bytes(&grp, sizeof(grp));
507 parent_group = (unsigned)grp % ngroups; 513 parent_group = (unsigned)grp % ngroups;
508 for (i = 0; i < ngroups; i++) { 514 for (i = 0; i < ngroups; i++) {
509 g = (parent_group + i) % ngroups; 515 g = (parent_group + i) % ngroups;
510 get_orlov_stats(sb, g, flex_size, &stats); 516 get_orlov_stats(sb, g, flex_size, &stats);
511 if (!stats.free_inodes) 517 if (!stats.free_inodes)
512 continue; 518 continue;
513 if (stats.used_dirs >= best_ndir) 519 if (stats.used_dirs >= best_ndir)
514 continue; 520 continue;
515 if (stats.free_inodes < avefreei) 521 if (stats.free_inodes < avefreei)
516 continue; 522 continue;
517 if (stats.free_blocks < avefreeb) 523 if (stats.free_blocks < avefreeb)
518 continue; 524 continue;
519 grp = g; 525 grp = g;
520 ret = 0; 526 ret = 0;
521 best_ndir = stats.used_dirs; 527 best_ndir = stats.used_dirs;
522 } 528 }
523 if (ret) 529 if (ret)
524 goto fallback; 530 goto fallback;
525 found_flex_bg: 531 found_flex_bg:
526 if (flex_size == 1) { 532 if (flex_size == 1) {
527 *group = grp; 533 *group = grp;
528 return 0; 534 return 0;
529 } 535 }
530 536
531 /* 537 /*
532 * We pack inodes at the beginning of the flexgroup's 538 * We pack inodes at the beginning of the flexgroup's
533 * inode tables. Block allocation decisions will do 539 * inode tables. Block allocation decisions will do
534 * something similar, although regular files will 540 * something similar, although regular files will
535 * start at 2nd block group of the flexgroup. See 541 * start at 2nd block group of the flexgroup. See
536 * ext4_ext_find_goal() and ext4_find_near(). 542 * ext4_ext_find_goal() and ext4_find_near().
537 */ 543 */
538 grp *= flex_size; 544 grp *= flex_size;
539 for (i = 0; i < flex_size; i++) { 545 for (i = 0; i < flex_size; i++) {
540 if (grp+i >= sbi->s_groups_count) 546 if (grp+i >= sbi->s_groups_count)
541 break; 547 break;
542 desc = ext4_get_group_desc(sb, grp+i, NULL); 548 desc = ext4_get_group_desc(sb, grp+i, NULL);
543 if (desc && ext4_free_inodes_count(sb, desc)) { 549 if (desc && ext4_free_inodes_count(sb, desc)) {
544 *group = grp+i; 550 *group = grp+i;
545 return 0; 551 return 0;
546 } 552 }
547 } 553 }
548 goto fallback; 554 goto fallback;
549 } 555 }
550 556
551 max_dirs = ndirs / ngroups + inodes_per_group / 16; 557 max_dirs = ndirs / ngroups + inodes_per_group / 16;
552 min_inodes = avefreei - inodes_per_group*flex_size / 4; 558 min_inodes = avefreei - inodes_per_group*flex_size / 4;
553 if (min_inodes < 1) 559 if (min_inodes < 1)
554 min_inodes = 1; 560 min_inodes = 1;
555 min_blocks = avefreeb - EXT4_BLOCKS_PER_GROUP(sb)*flex_size / 4; 561 min_blocks = avefreeb - EXT4_BLOCKS_PER_GROUP(sb)*flex_size / 4;
556 562
557 /* 563 /*
558 * Start looking in the flex group where we last allocated an 564 * Start looking in the flex group where we last allocated an
559 * inode for this parent directory 565 * inode for this parent directory
560 */ 566 */
561 if (EXT4_I(parent)->i_last_alloc_group != ~0) { 567 if (EXT4_I(parent)->i_last_alloc_group != ~0) {
562 parent_group = EXT4_I(parent)->i_last_alloc_group; 568 parent_group = EXT4_I(parent)->i_last_alloc_group;
563 if (flex_size > 1) 569 if (flex_size > 1)
564 parent_group >>= sbi->s_log_groups_per_flex; 570 parent_group >>= sbi->s_log_groups_per_flex;
565 } 571 }
566 572
567 for (i = 0; i < ngroups; i++) { 573 for (i = 0; i < ngroups; i++) {
568 grp = (parent_group + i) % ngroups; 574 grp = (parent_group + i) % ngroups;
569 get_orlov_stats(sb, grp, flex_size, &stats); 575 get_orlov_stats(sb, grp, flex_size, &stats);
570 if (stats.used_dirs >= max_dirs) 576 if (stats.used_dirs >= max_dirs)
571 continue; 577 continue;
572 if (stats.free_inodes < min_inodes) 578 if (stats.free_inodes < min_inodes)
573 continue; 579 continue;
574 if (stats.free_blocks < min_blocks) 580 if (stats.free_blocks < min_blocks)
575 continue; 581 continue;
576 goto found_flex_bg; 582 goto found_flex_bg;
577 } 583 }
578 584
579 fallback: 585 fallback:
580 ngroups = sbi->s_groups_count; 586 ngroups = sbi->s_groups_count;
581 avefreei = freei / ngroups; 587 avefreei = freei / ngroups;
582 parent_group = EXT4_I(parent)->i_block_group; 588 parent_group = EXT4_I(parent)->i_block_group;
583 for (i = 0; i < ngroups; i++) { 589 for (i = 0; i < ngroups; i++) {
584 grp = (parent_group + i) % ngroups; 590 grp = (parent_group + i) % ngroups;
585 desc = ext4_get_group_desc(sb, grp, NULL); 591 desc = ext4_get_group_desc(sb, grp, NULL);
586 if (desc && ext4_free_inodes_count(sb, desc) && 592 if (desc && ext4_free_inodes_count(sb, desc) &&
587 ext4_free_inodes_count(sb, desc) >= avefreei) { 593 ext4_free_inodes_count(sb, desc) >= avefreei) {
588 *group = grp; 594 *group = grp;
589 return 0; 595 return 0;
590 } 596 }
591 } 597 }
592 598
593 if (avefreei) { 599 if (avefreei) {
594 /* 600 /*
595 * The free-inodes counter is approximate, and for really small 601 * The free-inodes counter is approximate, and for really small
596 * filesystems the above test can fail to find any blockgroups 602 * filesystems the above test can fail to find any blockgroups
597 */ 603 */
598 avefreei = 0; 604 avefreei = 0;
599 goto fallback; 605 goto fallback;
600 } 606 }
601 607
602 return -1; 608 return -1;
603 } 609 }
604 610
605 static int find_group_other(struct super_block *sb, struct inode *parent, 611 static int find_group_other(struct super_block *sb, struct inode *parent,
606 ext4_group_t *group, int mode) 612 ext4_group_t *group, int mode)
607 { 613 {
608 ext4_group_t parent_group = EXT4_I(parent)->i_block_group; 614 ext4_group_t parent_group = EXT4_I(parent)->i_block_group;
609 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; 615 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count;
610 struct ext4_group_desc *desc; 616 struct ext4_group_desc *desc;
611 ext4_group_t i, last; 617 ext4_group_t i, last;
612 int flex_size = ext4_flex_bg_size(EXT4_SB(sb)); 618 int flex_size = ext4_flex_bg_size(EXT4_SB(sb));
613 619
614 /* 620 /*
615 * Try to place the inode is the same flex group as its 621 * Try to place the inode is the same flex group as its
616 * parent. If we can't find space, use the Orlov algorithm to 622 * parent. If we can't find space, use the Orlov algorithm to
617 * find another flex group, and store that information in the 623 * find another flex group, and store that information in the
618 * parent directory's inode information so that use that flex 624 * parent directory's inode information so that use that flex
619 * group for future allocations. 625 * group for future allocations.
620 */ 626 */
621 if (flex_size > 1) { 627 if (flex_size > 1) {
622 int retry = 0; 628 int retry = 0;
623 629
624 try_again: 630 try_again:
625 parent_group &= ~(flex_size-1); 631 parent_group &= ~(flex_size-1);
626 last = parent_group + flex_size; 632 last = parent_group + flex_size;
627 if (last > ngroups) 633 if (last > ngroups)
628 last = ngroups; 634 last = ngroups;
629 for (i = parent_group; i < last; i++) { 635 for (i = parent_group; i < last; i++) {
630 desc = ext4_get_group_desc(sb, i, NULL); 636 desc = ext4_get_group_desc(sb, i, NULL);
631 if (desc && ext4_free_inodes_count(sb, desc)) { 637 if (desc && ext4_free_inodes_count(sb, desc)) {
632 *group = i; 638 *group = i;
633 return 0; 639 return 0;
634 } 640 }
635 } 641 }
636 if (!retry && EXT4_I(parent)->i_last_alloc_group != ~0) { 642 if (!retry && EXT4_I(parent)->i_last_alloc_group != ~0) {
637 retry = 1; 643 retry = 1;
638 parent_group = EXT4_I(parent)->i_last_alloc_group; 644 parent_group = EXT4_I(parent)->i_last_alloc_group;
639 goto try_again; 645 goto try_again;
640 } 646 }
641 /* 647 /*
642 * If this didn't work, use the Orlov search algorithm 648 * If this didn't work, use the Orlov search algorithm
643 * to find a new flex group; we pass in the mode to 649 * to find a new flex group; we pass in the mode to
644 * avoid the topdir algorithms. 650 * avoid the topdir algorithms.
645 */ 651 */
646 *group = parent_group + flex_size; 652 *group = parent_group + flex_size;
647 if (*group > ngroups) 653 if (*group > ngroups)
648 *group = 0; 654 *group = 0;
649 return find_group_orlov(sb, parent, group, mode); 655 return find_group_orlov(sb, parent, group, mode);
650 } 656 }
651 657
652 /* 658 /*
653 * Try to place the inode in its parent directory 659 * Try to place the inode in its parent directory
654 */ 660 */
655 *group = parent_group; 661 *group = parent_group;
656 desc = ext4_get_group_desc(sb, *group, NULL); 662 desc = ext4_get_group_desc(sb, *group, NULL);
657 if (desc && ext4_free_inodes_count(sb, desc) && 663 if (desc && ext4_free_inodes_count(sb, desc) &&
658 ext4_free_blks_count(sb, desc)) 664 ext4_free_blks_count(sb, desc))
659 return 0; 665 return 0;
660 666
661 /* 667 /*
662 * We're going to place this inode in a different blockgroup from its 668 * We're going to place this inode in a different blockgroup from its
663 * parent. We want to cause files in a common directory to all land in 669 * parent. We want to cause files in a common directory to all land in
664 * the same blockgroup. But we want files which are in a different 670 * the same blockgroup. But we want files which are in a different
665 * directory which shares a blockgroup with our parent to land in a 671 * directory which shares a blockgroup with our parent to land in a
666 * different blockgroup. 672 * different blockgroup.
667 * 673 *
668 * So add our directory's i_ino into the starting point for the hash. 674 * So add our directory's i_ino into the starting point for the hash.
669 */ 675 */
670 *group = (*group + parent->i_ino) % ngroups; 676 *group = (*group + parent->i_ino) % ngroups;
671 677
672 /* 678 /*
673 * Use a quadratic hash to find a group with a free inode and some free 679 * Use a quadratic hash to find a group with a free inode and some free
674 * blocks. 680 * blocks.
675 */ 681 */
676 for (i = 1; i < ngroups; i <<= 1) { 682 for (i = 1; i < ngroups; i <<= 1) {
677 *group += i; 683 *group += i;
678 if (*group >= ngroups) 684 if (*group >= ngroups)
679 *group -= ngroups; 685 *group -= ngroups;
680 desc = ext4_get_group_desc(sb, *group, NULL); 686 desc = ext4_get_group_desc(sb, *group, NULL);
681 if (desc && ext4_free_inodes_count(sb, desc) && 687 if (desc && ext4_free_inodes_count(sb, desc) &&
682 ext4_free_blks_count(sb, desc)) 688 ext4_free_blks_count(sb, desc))
683 return 0; 689 return 0;
684 } 690 }
685 691
686 /* 692 /*
687 * That failed: try linear search for a free inode, even if that group 693 * That failed: try linear search for a free inode, even if that group
688 * has no free blocks. 694 * has no free blocks.
689 */ 695 */
690 *group = parent_group; 696 *group = parent_group;
691 for (i = 0; i < ngroups; i++) { 697 for (i = 0; i < ngroups; i++) {
692 if (++*group >= ngroups) 698 if (++*group >= ngroups)
693 *group = 0; 699 *group = 0;
694 desc = ext4_get_group_desc(sb, *group, NULL); 700 desc = ext4_get_group_desc(sb, *group, NULL);
695 if (desc && ext4_free_inodes_count(sb, desc)) 701 if (desc && ext4_free_inodes_count(sb, desc))
696 return 0; 702 return 0;
697 } 703 }
698 704
699 return -1; 705 return -1;
700 } 706 }
701 707
702 /* 708 /*
703 * claim the inode from the inode bitmap. If the group 709 * claim the inode from the inode bitmap. If the group
704 * is uninit we need to take the groups's sb_bgl_lock 710 * is uninit we need to take the groups's sb_bgl_lock
705 * and clear the uninit flag. The inode bitmap update 711 * and clear the uninit flag. The inode bitmap update
706 * and group desc uninit flag clear should be done 712 * and group desc uninit flag clear should be done
707 * after holding sb_bgl_lock so that ext4_read_inode_bitmap 713 * after holding sb_bgl_lock so that ext4_read_inode_bitmap
708 * doesn't race with the ext4_claim_inode 714 * doesn't race with the ext4_claim_inode
709 */ 715 */
710 static int ext4_claim_inode(struct super_block *sb, 716 static int ext4_claim_inode(struct super_block *sb,
711 struct buffer_head *inode_bitmap_bh, 717 struct buffer_head *inode_bitmap_bh,
712 unsigned long ino, ext4_group_t group, int mode) 718 unsigned long ino, ext4_group_t group, int mode)
713 { 719 {
714 int free = 0, retval = 0, count; 720 int free = 0, retval = 0, count;
715 struct ext4_sb_info *sbi = EXT4_SB(sb); 721 struct ext4_sb_info *sbi = EXT4_SB(sb);
716 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, group, NULL); 722 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, group, NULL);
717 723
718 spin_lock(sb_bgl_lock(sbi, group)); 724 spin_lock(sb_bgl_lock(sbi, group));
719 if (ext4_set_bit(ino, inode_bitmap_bh->b_data)) { 725 if (ext4_set_bit(ino, inode_bitmap_bh->b_data)) {
720 /* not a free inode */ 726 /* not a free inode */
721 retval = 1; 727 retval = 1;
722 goto err_ret; 728 goto err_ret;
723 } 729 }
724 ino++; 730 ino++;
725 if ((group == 0 && ino < EXT4_FIRST_INO(sb)) || 731 if ((group == 0 && ino < EXT4_FIRST_INO(sb)) ||
726 ino > EXT4_INODES_PER_GROUP(sb)) { 732 ino > EXT4_INODES_PER_GROUP(sb)) {
727 spin_unlock(sb_bgl_lock(sbi, group)); 733 spin_unlock(sb_bgl_lock(sbi, group));
728 ext4_error(sb, __func__, 734 ext4_error(sb, __func__,
729 "reserved inode or inode > inodes count - " 735 "reserved inode or inode > inodes count - "
730 "block_group = %u, inode=%lu", group, 736 "block_group = %u, inode=%lu", group,
731 ino + group * EXT4_INODES_PER_GROUP(sb)); 737 ino + group * EXT4_INODES_PER_GROUP(sb));
732 return 1; 738 return 1;
733 } 739 }
734 /* If we didn't allocate from within the initialized part of the inode 740 /* If we didn't allocate from within the initialized part of the inode
735 * table then we need to initialize up to this inode. */ 741 * table then we need to initialize up to this inode. */
736 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { 742 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
737 743
738 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) { 744 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {
739 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_INODE_UNINIT); 745 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_INODE_UNINIT);
740 /* When marking the block group with 746 /* When marking the block group with
741 * ~EXT4_BG_INODE_UNINIT we don't want to depend 747 * ~EXT4_BG_INODE_UNINIT we don't want to depend
742 * on the value of bg_itable_unused even though 748 * on the value of bg_itable_unused even though
743 * mke2fs could have initialized the same for us. 749 * mke2fs could have initialized the same for us.
744 * Instead we calculated the value below 750 * Instead we calculated the value below
745 */ 751 */
746 752
747 free = 0; 753 free = 0;
748 } else { 754 } else {
749 free = EXT4_INODES_PER_GROUP(sb) - 755 free = EXT4_INODES_PER_GROUP(sb) -
750 ext4_itable_unused_count(sb, gdp); 756 ext4_itable_unused_count(sb, gdp);
751 } 757 }
752 758
753 /* 759 /*
754 * Check the relative inode number against the last used 760 * Check the relative inode number against the last used
755 * relative inode number in this group. if it is greater 761 * relative inode number in this group. if it is greater
756 * we need to update the bg_itable_unused count 762 * we need to update the bg_itable_unused count
757 * 763 *
758 */ 764 */
759 if (ino > free) 765 if (ino > free)
760 ext4_itable_unused_set(sb, gdp, 766 ext4_itable_unused_set(sb, gdp,
761 (EXT4_INODES_PER_GROUP(sb) - ino)); 767 (EXT4_INODES_PER_GROUP(sb) - ino));
762 } 768 }
763 count = ext4_free_inodes_count(sb, gdp) - 1; 769 count = ext4_free_inodes_count(sb, gdp) - 1;
764 ext4_free_inodes_set(sb, gdp, count); 770 ext4_free_inodes_set(sb, gdp, count);
765 if (S_ISDIR(mode)) { 771 if (S_ISDIR(mode)) {
766 count = ext4_used_dirs_count(sb, gdp) + 1; 772 count = ext4_used_dirs_count(sb, gdp) + 1;
767 ext4_used_dirs_set(sb, gdp, count); 773 ext4_used_dirs_set(sb, gdp, count);
774 if (sbi->s_log_groups_per_flex) {
775 ext4_group_t f = ext4_flex_group(sbi, group);
776
777 atomic_inc(&sbi->s_flex_groups[f].free_inodes);
778 }
768 } 779 }
769 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp); 780 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp);
770 err_ret: 781 err_ret:
771 spin_unlock(sb_bgl_lock(sbi, group)); 782 spin_unlock(sb_bgl_lock(sbi, group));
772 return retval; 783 return retval;
773 } 784 }
774 785
775 /* 786 /*
776 * There are two policies for allocating an inode. If the new inode is 787 * There are two policies for allocating an inode. If the new inode is
777 * a directory, then a forward search is made for a block group with both 788 * a directory, then a forward search is made for a block group with both
778 * free space and a low directory-to-inode ratio; if that fails, then of 789 * free space and a low directory-to-inode ratio; if that fails, then of
779 * the groups with above-average free space, that group with the fewest 790 * the groups with above-average free space, that group with the fewest
780 * directories already is chosen. 791 * directories already is chosen.
781 * 792 *
782 * For other inodes, search forward from the parent directory's block 793 * For other inodes, search forward from the parent directory's block
783 * group to find a free inode. 794 * group to find a free inode.
784 */ 795 */
785 struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode) 796 struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode)
786 { 797 {
787 struct super_block *sb; 798 struct super_block *sb;
788 struct buffer_head *inode_bitmap_bh = NULL; 799 struct buffer_head *inode_bitmap_bh = NULL;
789 struct buffer_head *group_desc_bh; 800 struct buffer_head *group_desc_bh;
790 ext4_group_t group = 0; 801 ext4_group_t group = 0;
791 unsigned long ino = 0; 802 unsigned long ino = 0;
792 struct inode *inode; 803 struct inode *inode;
793 struct ext4_group_desc *gdp = NULL; 804 struct ext4_group_desc *gdp = NULL;
794 struct ext4_super_block *es; 805 struct ext4_super_block *es;
795 struct ext4_inode_info *ei; 806 struct ext4_inode_info *ei;
796 struct ext4_sb_info *sbi; 807 struct ext4_sb_info *sbi;
797 int ret2, err = 0; 808 int ret2, err = 0;
798 struct inode *ret; 809 struct inode *ret;
799 ext4_group_t i; 810 ext4_group_t i;
800 int free = 0; 811 int free = 0;
801 static int once = 1; 812 static int once = 1;
802 ext4_group_t flex_group; 813 ext4_group_t flex_group;
803 814
804 /* Cannot create files in a deleted directory */ 815 /* Cannot create files in a deleted directory */
805 if (!dir || !dir->i_nlink) 816 if (!dir || !dir->i_nlink)
806 return ERR_PTR(-EPERM); 817 return ERR_PTR(-EPERM);
807 818
808 sb = dir->i_sb; 819 sb = dir->i_sb;
809 trace_mark(ext4_request_inode, "dev %s dir %lu mode %d", sb->s_id, 820 trace_mark(ext4_request_inode, "dev %s dir %lu mode %d", sb->s_id,
810 dir->i_ino, mode); 821 dir->i_ino, mode);
811 inode = new_inode(sb); 822 inode = new_inode(sb);
812 if (!inode) 823 if (!inode)
813 return ERR_PTR(-ENOMEM); 824 return ERR_PTR(-ENOMEM);
814 ei = EXT4_I(inode); 825 ei = EXT4_I(inode);
815 826
816 sbi = EXT4_SB(sb); 827 sbi = EXT4_SB(sb);
817 es = sbi->s_es; 828 es = sbi->s_es;
818 829
819 if (sbi->s_log_groups_per_flex && test_opt(sb, OLDALLOC)) { 830 if (sbi->s_log_groups_per_flex && test_opt(sb, OLDALLOC)) {
820 ret2 = find_group_flex(sb, dir, &group); 831 ret2 = find_group_flex(sb, dir, &group);
821 if (ret2 == -1) { 832 if (ret2 == -1) {
822 ret2 = find_group_other(sb, dir, &group, mode); 833 ret2 = find_group_other(sb, dir, &group, mode);
823 if (ret2 == 0 && once) 834 if (ret2 == 0 && once)
824 once = 0; 835 once = 0;
825 printk(KERN_NOTICE "ext4: find_group_flex " 836 printk(KERN_NOTICE "ext4: find_group_flex "
826 "failed, fallback succeeded dir %lu\n", 837 "failed, fallback succeeded dir %lu\n",
827 dir->i_ino); 838 dir->i_ino);
828 } 839 }
829 goto got_group; 840 goto got_group;
830 } 841 }
831 842
832 if (S_ISDIR(mode)) { 843 if (S_ISDIR(mode)) {
833 if (test_opt(sb, OLDALLOC)) 844 if (test_opt(sb, OLDALLOC))
834 ret2 = find_group_dir(sb, dir, &group); 845 ret2 = find_group_dir(sb, dir, &group);
835 else 846 else
836 ret2 = find_group_orlov(sb, dir, &group, mode); 847 ret2 = find_group_orlov(sb, dir, &group, mode);
837 } else 848 } else
838 ret2 = find_group_other(sb, dir, &group, mode); 849 ret2 = find_group_other(sb, dir, &group, mode);
839 850
840 got_group: 851 got_group:
841 EXT4_I(dir)->i_last_alloc_group = group; 852 EXT4_I(dir)->i_last_alloc_group = group;
842 err = -ENOSPC; 853 err = -ENOSPC;
843 if (ret2 == -1) 854 if (ret2 == -1)
844 goto out; 855 goto out;
845 856
846 for (i = 0; i < sbi->s_groups_count; i++) { 857 for (i = 0; i < sbi->s_groups_count; i++) {
847 err = -EIO; 858 err = -EIO;
848 859
849 gdp = ext4_get_group_desc(sb, group, &group_desc_bh); 860 gdp = ext4_get_group_desc(sb, group, &group_desc_bh);
850 if (!gdp) 861 if (!gdp)
851 goto fail; 862 goto fail;
852 863
853 brelse(inode_bitmap_bh); 864 brelse(inode_bitmap_bh);
854 inode_bitmap_bh = ext4_read_inode_bitmap(sb, group); 865 inode_bitmap_bh = ext4_read_inode_bitmap(sb, group);
855 if (!inode_bitmap_bh) 866 if (!inode_bitmap_bh)
856 goto fail; 867 goto fail;
857 868
858 ino = 0; 869 ino = 0;
859 870
860 repeat_in_this_group: 871 repeat_in_this_group:
861 ino = ext4_find_next_zero_bit((unsigned long *) 872 ino = ext4_find_next_zero_bit((unsigned long *)
862 inode_bitmap_bh->b_data, 873 inode_bitmap_bh->b_data,
863 EXT4_INODES_PER_GROUP(sb), ino); 874 EXT4_INODES_PER_GROUP(sb), ino);
864 875
865 if (ino < EXT4_INODES_PER_GROUP(sb)) { 876 if (ino < EXT4_INODES_PER_GROUP(sb)) {
866 877
867 BUFFER_TRACE(inode_bitmap_bh, "get_write_access"); 878 BUFFER_TRACE(inode_bitmap_bh, "get_write_access");
868 err = ext4_journal_get_write_access(handle, 879 err = ext4_journal_get_write_access(handle,
869 inode_bitmap_bh); 880 inode_bitmap_bh);
870 if (err) 881 if (err)
871 goto fail; 882 goto fail;
872 883
873 BUFFER_TRACE(group_desc_bh, "get_write_access"); 884 BUFFER_TRACE(group_desc_bh, "get_write_access");
874 err = ext4_journal_get_write_access(handle, 885 err = ext4_journal_get_write_access(handle,
875 group_desc_bh); 886 group_desc_bh);
876 if (err) 887 if (err)
877 goto fail; 888 goto fail;
878 if (!ext4_claim_inode(sb, inode_bitmap_bh, 889 if (!ext4_claim_inode(sb, inode_bitmap_bh,
879 ino, group, mode)) { 890 ino, group, mode)) {
880 /* we won it */ 891 /* we won it */
881 BUFFER_TRACE(inode_bitmap_bh, 892 BUFFER_TRACE(inode_bitmap_bh,
882 "call ext4_handle_dirty_metadata"); 893 "call ext4_handle_dirty_metadata");
883 err = ext4_handle_dirty_metadata(handle, 894 err = ext4_handle_dirty_metadata(handle,
884 inode, 895 inode,
885 inode_bitmap_bh); 896 inode_bitmap_bh);
886 if (err) 897 if (err)
887 goto fail; 898 goto fail;
888 /* zero bit is inode number 1*/ 899 /* zero bit is inode number 1*/
889 ino++; 900 ino++;
890 goto got; 901 goto got;
891 } 902 }
892 /* we lost it */ 903 /* we lost it */
893 ext4_handle_release_buffer(handle, inode_bitmap_bh); 904 ext4_handle_release_buffer(handle, inode_bitmap_bh);
894 ext4_handle_release_buffer(handle, group_desc_bh); 905 ext4_handle_release_buffer(handle, group_desc_bh);
895 906
896 if (++ino < EXT4_INODES_PER_GROUP(sb)) 907 if (++ino < EXT4_INODES_PER_GROUP(sb))
897 goto repeat_in_this_group; 908 goto repeat_in_this_group;
898 } 909 }
899 910
900 /* 911 /*
901 * This case is possible in concurrent environment. It is very 912 * This case is possible in concurrent environment. It is very
902 * rare. We cannot repeat the find_group_xxx() call because 913 * rare. We cannot repeat the find_group_xxx() call because
903 * that will simply return the same blockgroup, because the 914 * that will simply return the same blockgroup, because the
904 * group descriptor metadata has not yet been updated. 915 * group descriptor metadata has not yet been updated.
905 * So we just go onto the next blockgroup. 916 * So we just go onto the next blockgroup.
906 */ 917 */
907 if (++group == sbi->s_groups_count) 918 if (++group == sbi->s_groups_count)
908 group = 0; 919 group = 0;
909 } 920 }
910 err = -ENOSPC; 921 err = -ENOSPC;
911 goto out; 922 goto out;
912 923
913 got: 924 got:
914 /* We may have to initialize the block bitmap if it isn't already */ 925 /* We may have to initialize the block bitmap if it isn't already */
915 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM) && 926 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM) &&
916 gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { 927 gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
917 struct buffer_head *block_bitmap_bh; 928 struct buffer_head *block_bitmap_bh;
918 929
919 block_bitmap_bh = ext4_read_block_bitmap(sb, group); 930 block_bitmap_bh = ext4_read_block_bitmap(sb, group);
920 BUFFER_TRACE(block_bitmap_bh, "get block bitmap access"); 931 BUFFER_TRACE(block_bitmap_bh, "get block bitmap access");
921 err = ext4_journal_get_write_access(handle, block_bitmap_bh); 932 err = ext4_journal_get_write_access(handle, block_bitmap_bh);
922 if (err) { 933 if (err) {
923 brelse(block_bitmap_bh); 934 brelse(block_bitmap_bh);
924 goto fail; 935 goto fail;
925 } 936 }
926 937
927 free = 0; 938 free = 0;
928 spin_lock(sb_bgl_lock(sbi, group)); 939 spin_lock(sb_bgl_lock(sbi, group));
929 /* recheck and clear flag under lock if we still need to */ 940 /* recheck and clear flag under lock if we still need to */
930 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { 941 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
931 free = ext4_free_blocks_after_init(sb, group, gdp); 942 free = ext4_free_blocks_after_init(sb, group, gdp);
932 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); 943 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);
933 ext4_free_blks_set(sb, gdp, free); 944 ext4_free_blks_set(sb, gdp, free);
934 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, 945 gdp->bg_checksum = ext4_group_desc_csum(sbi, group,
935 gdp); 946 gdp);
936 } 947 }
937 spin_unlock(sb_bgl_lock(sbi, group)); 948 spin_unlock(sb_bgl_lock(sbi, group));
938 949
939 /* Don't need to dirty bitmap block if we didn't change it */ 950 /* Don't need to dirty bitmap block if we didn't change it */
940 if (free) { 951 if (free) {
941 BUFFER_TRACE(block_bitmap_bh, "dirty block bitmap"); 952 BUFFER_TRACE(block_bitmap_bh, "dirty block bitmap");
942 err = ext4_handle_dirty_metadata(handle, 953 err = ext4_handle_dirty_metadata(handle,
943 NULL, block_bitmap_bh); 954 NULL, block_bitmap_bh);
944 } 955 }
945 956
946 brelse(block_bitmap_bh); 957 brelse(block_bitmap_bh);
947 if (err) 958 if (err)
948 goto fail; 959 goto fail;
949 } 960 }
950 BUFFER_TRACE(group_desc_bh, "call ext4_handle_dirty_metadata"); 961 BUFFER_TRACE(group_desc_bh, "call ext4_handle_dirty_metadata");
951 err = ext4_handle_dirty_metadata(handle, NULL, group_desc_bh); 962 err = ext4_handle_dirty_metadata(handle, NULL, group_desc_bh);
952 if (err) 963 if (err)
953 goto fail; 964 goto fail;
954 965
955 percpu_counter_dec(&sbi->s_freeinodes_counter); 966 percpu_counter_dec(&sbi->s_freeinodes_counter);
956 if (S_ISDIR(mode)) 967 if (S_ISDIR(mode))
957 percpu_counter_inc(&sbi->s_dirs_counter); 968 percpu_counter_inc(&sbi->s_dirs_counter);
958 sb->s_dirt = 1; 969 sb->s_dirt = 1;
959 970
960 if (sbi->s_log_groups_per_flex) { 971 if (sbi->s_log_groups_per_flex) {
961 flex_group = ext4_flex_group(sbi, group); 972 flex_group = ext4_flex_group(sbi, group);
962 atomic_dec(&sbi->s_flex_groups[flex_group].free_inodes); 973 atomic_dec(&sbi->s_flex_groups[flex_group].free_inodes);
963 } 974 }
964 975
965 inode->i_uid = current_fsuid(); 976 inode->i_uid = current_fsuid();
966 if (test_opt(sb, GRPID)) 977 if (test_opt(sb, GRPID))
967 inode->i_gid = dir->i_gid; 978 inode->i_gid = dir->i_gid;
968 else if (dir->i_mode & S_ISGID) { 979 else if (dir->i_mode & S_ISGID) {
969 inode->i_gid = dir->i_gid; 980 inode->i_gid = dir->i_gid;
970 if (S_ISDIR(mode)) 981 if (S_ISDIR(mode))
971 mode |= S_ISGID; 982 mode |= S_ISGID;
972 } else 983 } else
973 inode->i_gid = current_fsgid(); 984 inode->i_gid = current_fsgid();
974 inode->i_mode = mode; 985 inode->i_mode = mode;
975 986
976 inode->i_ino = ino + group * EXT4_INODES_PER_GROUP(sb); 987 inode->i_ino = ino + group * EXT4_INODES_PER_GROUP(sb);
977 /* This is the optimal IO size (for stat), not the fs block size */ 988 /* This is the optimal IO size (for stat), not the fs block size */
978 inode->i_blocks = 0; 989 inode->i_blocks = 0;
979 inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime = 990 inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime =
980 ext4_current_time(inode); 991 ext4_current_time(inode);
981 992
982 memset(ei->i_data, 0, sizeof(ei->i_data)); 993 memset(ei->i_data, 0, sizeof(ei->i_data));
983 ei->i_dir_start_lookup = 0; 994 ei->i_dir_start_lookup = 0;
984 ei->i_disksize = 0; 995 ei->i_disksize = 0;
985 996
986 /* 997 /*
987 * Don't inherit extent flag from directory, amongst others. We set 998 * Don't inherit extent flag from directory, amongst others. We set
988 * extent flag on newly created directory and file only if -o extent 999 * extent flag on newly created directory and file only if -o extent
989 * mount option is specified 1000 * mount option is specified
990 */ 1001 */
991 ei->i_flags = 1002 ei->i_flags =
992 ext4_mask_flags(mode, EXT4_I(dir)->i_flags & EXT4_FL_INHERITED); 1003 ext4_mask_flags(mode, EXT4_I(dir)->i_flags & EXT4_FL_INHERITED);
993 ei->i_file_acl = 0; 1004 ei->i_file_acl = 0;
994 ei->i_dtime = 0; 1005 ei->i_dtime = 0;
995 ei->i_block_group = group; 1006 ei->i_block_group = group;
996 ei->i_last_alloc_group = ~0; 1007 ei->i_last_alloc_group = ~0;
997 1008
998 ext4_set_inode_flags(inode); 1009 ext4_set_inode_flags(inode);
999 if (IS_DIRSYNC(inode)) 1010 if (IS_DIRSYNC(inode))
1000 ext4_handle_sync(handle); 1011 ext4_handle_sync(handle);
1001 if (insert_inode_locked(inode) < 0) { 1012 if (insert_inode_locked(inode) < 0) {
1002 err = -EINVAL; 1013 err = -EINVAL;
1003 goto fail_drop; 1014 goto fail_drop;
1004 } 1015 }
1005 spin_lock(&sbi->s_next_gen_lock); 1016 spin_lock(&sbi->s_next_gen_lock);
1006 inode->i_generation = sbi->s_next_generation++; 1017 inode->i_generation = sbi->s_next_generation++;
1007 spin_unlock(&sbi->s_next_gen_lock); 1018 spin_unlock(&sbi->s_next_gen_lock);
1008 1019
1009 ei->i_state = EXT4_STATE_NEW; 1020 ei->i_state = EXT4_STATE_NEW;
1010 1021
1011 ei->i_extra_isize = EXT4_SB(sb)->s_want_extra_isize; 1022 ei->i_extra_isize = EXT4_SB(sb)->s_want_extra_isize;
1012 1023
1013 ret = inode; 1024 ret = inode;
1014 if (vfs_dq_alloc_inode(inode)) { 1025 if (vfs_dq_alloc_inode(inode)) {
1015 err = -EDQUOT; 1026 err = -EDQUOT;
1016 goto fail_drop; 1027 goto fail_drop;
1017 } 1028 }
1018 1029
1019 err = ext4_init_acl(handle, inode, dir); 1030 err = ext4_init_acl(handle, inode, dir);
1020 if (err) 1031 if (err)
1021 goto fail_free_drop; 1032 goto fail_free_drop;
1022 1033
1023 err = ext4_init_security(handle, inode, dir); 1034 err = ext4_init_security(handle, inode, dir);
1024 if (err) 1035 if (err)
1025 goto fail_free_drop; 1036 goto fail_free_drop;
1026 1037
1027 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) { 1038 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) {
1028 /* set extent flag only for directory, file and normal symlink*/ 1039 /* set extent flag only for directory, file and normal symlink*/
1029 if (S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode)) { 1040 if (S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode)) {
1030 EXT4_I(inode)->i_flags |= EXT4_EXTENTS_FL; 1041 EXT4_I(inode)->i_flags |= EXT4_EXTENTS_FL;
1031 ext4_ext_tree_init(handle, inode); 1042 ext4_ext_tree_init(handle, inode);
1032 } 1043 }
1033 } 1044 }
1034 1045
1035 err = ext4_mark_inode_dirty(handle, inode); 1046 err = ext4_mark_inode_dirty(handle, inode);
1036 if (err) { 1047 if (err) {
1037 ext4_std_error(sb, err); 1048 ext4_std_error(sb, err);
1038 goto fail_free_drop; 1049 goto fail_free_drop;
1039 } 1050 }
1040 1051
1041 ext4_debug("allocating inode %lu\n", inode->i_ino); 1052 ext4_debug("allocating inode %lu\n", inode->i_ino);
1042 trace_mark(ext4_allocate_inode, "dev %s ino %lu dir %lu mode %d", 1053 trace_mark(ext4_allocate_inode, "dev %s ino %lu dir %lu mode %d",
1043 sb->s_id, inode->i_ino, dir->i_ino, mode); 1054 sb->s_id, inode->i_ino, dir->i_ino, mode);
1044 goto really_out; 1055 goto really_out;
1045 fail: 1056 fail:
1046 ext4_std_error(sb, err); 1057 ext4_std_error(sb, err);
1047 out: 1058 out:
1048 iput(inode); 1059 iput(inode);
1049 ret = ERR_PTR(err); 1060 ret = ERR_PTR(err);
1050 really_out: 1061 really_out:
1051 brelse(inode_bitmap_bh); 1062 brelse(inode_bitmap_bh);
1052 return ret; 1063 return ret;
1053 1064
1054 fail_free_drop: 1065 fail_free_drop:
1055 vfs_dq_free_inode(inode); 1066 vfs_dq_free_inode(inode);
1056 1067
1057 fail_drop: 1068 fail_drop:
1058 vfs_dq_drop(inode); 1069 vfs_dq_drop(inode);
1059 inode->i_flags |= S_NOQUOTA; 1070 inode->i_flags |= S_NOQUOTA;
1060 inode->i_nlink = 0; 1071 inode->i_nlink = 0;
1061 unlock_new_inode(inode); 1072 unlock_new_inode(inode);
1062 iput(inode); 1073 iput(inode);
1063 brelse(inode_bitmap_bh); 1074 brelse(inode_bitmap_bh);
1064 return ERR_PTR(err); 1075 return ERR_PTR(err);
1065 } 1076 }
1066 1077
1067 /* Verify that we are loading a valid orphan from disk */ 1078 /* Verify that we are loading a valid orphan from disk */
1068 struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino) 1079 struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
1069 { 1080 {
1070 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count); 1081 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
1071 ext4_group_t block_group; 1082 ext4_group_t block_group;
1072 int bit; 1083 int bit;
1073 struct buffer_head *bitmap_bh; 1084 struct buffer_head *bitmap_bh;
1074 struct inode *inode = NULL; 1085 struct inode *inode = NULL;
1075 long err = -EIO; 1086 long err = -EIO;
1076 1087
1077 /* Error cases - e2fsck has already cleaned up for us */ 1088 /* Error cases - e2fsck has already cleaned up for us */
1078 if (ino > max_ino) { 1089 if (ino > max_ino) {
1079 ext4_warning(sb, __func__, 1090 ext4_warning(sb, __func__,
1080 "bad orphan ino %lu! e2fsck was run?", ino); 1091 "bad orphan ino %lu! e2fsck was run?", ino);
1081 goto error; 1092 goto error;
1082 } 1093 }
1083 1094
1084 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); 1095 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
1085 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); 1096 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
1086 bitmap_bh = ext4_read_inode_bitmap(sb, block_group); 1097 bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
1087 if (!bitmap_bh) { 1098 if (!bitmap_bh) {
1088 ext4_warning(sb, __func__, 1099 ext4_warning(sb, __func__,
1089 "inode bitmap error for orphan %lu", ino); 1100 "inode bitmap error for orphan %lu", ino);
1090 goto error; 1101 goto error;
1091 } 1102 }
1092 1103
1093 /* Having the inode bit set should be a 100% indicator that this 1104 /* Having the inode bit set should be a 100% indicator that this
1094 * is a valid orphan (no e2fsck run on fs). Orphans also include 1105 * is a valid orphan (no e2fsck run on fs). Orphans also include
1095 * inodes that were being truncated, so we can't check i_nlink==0. 1106 * inodes that were being truncated, so we can't check i_nlink==0.
1096 */ 1107 */
1097 if (!ext4_test_bit(bit, bitmap_bh->b_data)) 1108 if (!ext4_test_bit(bit, bitmap_bh->b_data))
1098 goto bad_orphan; 1109 goto bad_orphan;
1099 1110
1100 inode = ext4_iget(sb, ino); 1111 inode = ext4_iget(sb, ino);
1101 if (IS_ERR(inode)) 1112 if (IS_ERR(inode))
1102 goto iget_failed; 1113 goto iget_failed;
1103 1114
1104 /* 1115 /*
1105 * If the orphans has i_nlinks > 0 then it should be able to be 1116 * If the orphans has i_nlinks > 0 then it should be able to be
1106 * truncated, otherwise it won't be removed from the orphan list 1117 * truncated, otherwise it won't be removed from the orphan list
1107 * during processing and an infinite loop will result. 1118 * during processing and an infinite loop will result.
1108 */ 1119 */
1109 if (inode->i_nlink && !ext4_can_truncate(inode)) 1120 if (inode->i_nlink && !ext4_can_truncate(inode))
1110 goto bad_orphan; 1121 goto bad_orphan;
1111 1122
1112 if (NEXT_ORPHAN(inode) > max_ino) 1123 if (NEXT_ORPHAN(inode) > max_ino)
1113 goto bad_orphan; 1124 goto bad_orphan;
1114 brelse(bitmap_bh); 1125 brelse(bitmap_bh);
1115 return inode; 1126 return inode;
1116 1127
1117 iget_failed: 1128 iget_failed:
1118 err = PTR_ERR(inode); 1129 err = PTR_ERR(inode);
1119 inode = NULL; 1130 inode = NULL;
1120 bad_orphan: 1131 bad_orphan:
1121 ext4_warning(sb, __func__, 1132 ext4_warning(sb, __func__,
1122 "bad orphan inode %lu! e2fsck was run?", ino); 1133 "bad orphan inode %lu! e2fsck was run?", ino);
1123 printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n", 1134 printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
1124 bit, (unsigned long long)bitmap_bh->b_blocknr, 1135 bit, (unsigned long long)bitmap_bh->b_blocknr,
1125 ext4_test_bit(bit, bitmap_bh->b_data)); 1136 ext4_test_bit(bit, bitmap_bh->b_data));
1126 printk(KERN_NOTICE "inode=%p\n", inode); 1137 printk(KERN_NOTICE "inode=%p\n", inode);
1127 if (inode) { 1138 if (inode) {
1128 printk(KERN_NOTICE "is_bad_inode(inode)=%d\n", 1139 printk(KERN_NOTICE "is_bad_inode(inode)=%d\n",
1129 is_bad_inode(inode)); 1140 is_bad_inode(inode));
1130 printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n", 1141 printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n",
1131 NEXT_ORPHAN(inode)); 1142 NEXT_ORPHAN(inode));
1132 printk(KERN_NOTICE "max_ino=%lu\n", max_ino); 1143 printk(KERN_NOTICE "max_ino=%lu\n", max_ino);
1133 printk(KERN_NOTICE "i_nlink=%u\n", inode->i_nlink); 1144 printk(KERN_NOTICE "i_nlink=%u\n", inode->i_nlink);
1134 /* Avoid freeing blocks if we got a bad deleted inode */ 1145 /* Avoid freeing blocks if we got a bad deleted inode */
1135 if (inode->i_nlink == 0) 1146 if (inode->i_nlink == 0)
1136 inode->i_blocks = 0; 1147 inode->i_blocks = 0;
1137 iput(inode); 1148 iput(inode);
1138 } 1149 }
1139 brelse(bitmap_bh); 1150 brelse(bitmap_bh);
1140 error: 1151 error:
1141 return ERR_PTR(err); 1152 return ERR_PTR(err);
1142 } 1153 }
1143 1154
1144 unsigned long ext4_count_free_inodes(struct super_block *sb) 1155 unsigned long ext4_count_free_inodes(struct super_block *sb)
1145 { 1156 {
1146 unsigned long desc_count; 1157 unsigned long desc_count;
1147 struct ext4_group_desc *gdp; 1158 struct ext4_group_desc *gdp;
1148 ext4_group_t i; 1159 ext4_group_t i;
1149 #ifdef EXT4FS_DEBUG 1160 #ifdef EXT4FS_DEBUG
1150 struct ext4_super_block *es; 1161 struct ext4_super_block *es;
1151 unsigned long bitmap_count, x; 1162 unsigned long bitmap_count, x;
1152 struct buffer_head *bitmap_bh = NULL; 1163 struct buffer_head *bitmap_bh = NULL;
1153 1164
1154 es = EXT4_SB(sb)->s_es; 1165 es = EXT4_SB(sb)->s_es;
1155 desc_count = 0; 1166 desc_count = 0;
1156 bitmap_count = 0; 1167 bitmap_count = 0;
1157 gdp = NULL; 1168 gdp = NULL;
1158 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) { 1169 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
1159 gdp = ext4_get_group_desc(sb, i, NULL); 1170 gdp = ext4_get_group_desc(sb, i, NULL);
1160 if (!gdp) 1171 if (!gdp)
1161 continue; 1172 continue;
1162 desc_count += ext4_free_inodes_count(sb, gdp); 1173 desc_count += ext4_free_inodes_count(sb, gdp);
1163 brelse(bitmap_bh); 1174 brelse(bitmap_bh);
1164 bitmap_bh = ext4_read_inode_bitmap(sb, i); 1175 bitmap_bh = ext4_read_inode_bitmap(sb, i);
1165 if (!bitmap_bh) 1176 if (!bitmap_bh)
1166 continue; 1177 continue;
1167 1178
1168 x = ext4_count_free(bitmap_bh, EXT4_INODES_PER_GROUP(sb) / 8); 1179 x = ext4_count_free(bitmap_bh, EXT4_INODES_PER_GROUP(sb) / 8);
1169 printk(KERN_DEBUG "group %lu: stored = %d, counted = %lu\n", 1180 printk(KERN_DEBUG "group %lu: stored = %d, counted = %lu\n",
1170 i, ext4_free_inodes_count(sb, gdp), x); 1181 i, ext4_free_inodes_count(sb, gdp), x);
1171 bitmap_count += x; 1182 bitmap_count += x;
1172 } 1183 }
1173 brelse(bitmap_bh); 1184 brelse(bitmap_bh);
1174 printk(KERN_DEBUG "ext4_count_free_inodes: " 1185 printk(KERN_DEBUG "ext4_count_free_inodes: "
1175 "stored = %u, computed = %lu, %lu\n", 1186 "stored = %u, computed = %lu, %lu\n",
1176 le32_to_cpu(es->s_free_inodes_count), desc_count, bitmap_count); 1187 le32_to_cpu(es->s_free_inodes_count), desc_count, bitmap_count);
1177 return desc_count; 1188 return desc_count;
1178 #else 1189 #else
1179 desc_count = 0; 1190 desc_count = 0;
1180 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) { 1191 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
1181 gdp = ext4_get_group_desc(sb, i, NULL); 1192 gdp = ext4_get_group_desc(sb, i, NULL);
1182 if (!gdp) 1193 if (!gdp)
1183 continue; 1194 continue;
1184 desc_count += ext4_free_inodes_count(sb, gdp); 1195 desc_count += ext4_free_inodes_count(sb, gdp);
1185 cond_resched(); 1196 cond_resched();
1186 } 1197 }
1187 return desc_count; 1198 return desc_count;
1188 #endif 1199 #endif
1189 } 1200 }
1190 1201
1191 /* Called at mount-time, super-block is locked */ 1202 /* Called at mount-time, super-block is locked */
1192 unsigned long ext4_count_dirs(struct super_block * sb) 1203 unsigned long ext4_count_dirs(struct super_block * sb)
1193 { 1204 {
1194 unsigned long count = 0; 1205 unsigned long count = 0;
1195 ext4_group_t i; 1206 ext4_group_t i;
1196 1207
1197 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) { 1208 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
1198 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL); 1209 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
1199 if (!gdp) 1210 if (!gdp)
1200 continue; 1211 continue;
1201 count += ext4_used_dirs_count(sb, gdp); 1212 count += ext4_used_dirs_count(sb, gdp);
1 /* 1 /*
2 * linux/fs/ext4/super.c 2 * linux/fs/ext4/super.c
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal 6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI) 7 * Universite Pierre et Marie Curie (Paris VI)
8 * 8 *
9 * from 9 * from
10 * 10 *
11 * linux/fs/minix/inode.c 11 * linux/fs/minix/inode.c
12 * 12 *
13 * Copyright (C) 1991, 1992 Linus Torvalds 13 * Copyright (C) 1991, 1992 Linus Torvalds
14 * 14 *
15 * Big-endian to little-endian byte-swapping/bitmaps by 15 * Big-endian to little-endian byte-swapping/bitmaps by
16 * David S. Miller (davem@caip.rutgers.edu), 1995 16 * David S. Miller (davem@caip.rutgers.edu), 1995
17 */ 17 */
18 18
19 #include <linux/module.h> 19 #include <linux/module.h>
20 #include <linux/string.h> 20 #include <linux/string.h>
21 #include <linux/fs.h> 21 #include <linux/fs.h>
22 #include <linux/time.h> 22 #include <linux/time.h>
23 #include <linux/jbd2.h> 23 #include <linux/jbd2.h>
24 #include <linux/slab.h> 24 #include <linux/slab.h>
25 #include <linux/init.h> 25 #include <linux/init.h>
26 #include <linux/blkdev.h> 26 #include <linux/blkdev.h>
27 #include <linux/parser.h> 27 #include <linux/parser.h>
28 #include <linux/smp_lock.h> 28 #include <linux/smp_lock.h>
29 #include <linux/buffer_head.h> 29 #include <linux/buffer_head.h>
30 #include <linux/exportfs.h> 30 #include <linux/exportfs.h>
31 #include <linux/vfs.h> 31 #include <linux/vfs.h>
32 #include <linux/random.h> 32 #include <linux/random.h>
33 #include <linux/mount.h> 33 #include <linux/mount.h>
34 #include <linux/namei.h> 34 #include <linux/namei.h>
35 #include <linux/quotaops.h> 35 #include <linux/quotaops.h>
36 #include <linux/seq_file.h> 36 #include <linux/seq_file.h>
37 #include <linux/proc_fs.h> 37 #include <linux/proc_fs.h>
38 #include <linux/ctype.h> 38 #include <linux/ctype.h>
39 #include <linux/marker.h> 39 #include <linux/marker.h>
40 #include <linux/log2.h> 40 #include <linux/log2.h>
41 #include <linux/crc16.h> 41 #include <linux/crc16.h>
42 #include <asm/uaccess.h> 42 #include <asm/uaccess.h>
43 43
44 #include "ext4.h" 44 #include "ext4.h"
45 #include "ext4_jbd2.h" 45 #include "ext4_jbd2.h"
46 #include "xattr.h" 46 #include "xattr.h"
47 #include "acl.h" 47 #include "acl.h"
48 #include "namei.h" 48 #include "namei.h"
49 #include "group.h" 49 #include "group.h"
50 50
51 struct proc_dir_entry *ext4_proc_root; 51 struct proc_dir_entry *ext4_proc_root;
52 static struct kset *ext4_kset; 52 static struct kset *ext4_kset;
53 53
54 static int ext4_load_journal(struct super_block *, struct ext4_super_block *, 54 static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
55 unsigned long journal_devnum); 55 unsigned long journal_devnum);
56 static int ext4_commit_super(struct super_block *sb, 56 static int ext4_commit_super(struct super_block *sb,
57 struct ext4_super_block *es, int sync); 57 struct ext4_super_block *es, int sync);
58 static void ext4_mark_recovery_complete(struct super_block *sb, 58 static void ext4_mark_recovery_complete(struct super_block *sb,
59 struct ext4_super_block *es); 59 struct ext4_super_block *es);
60 static void ext4_clear_journal_err(struct super_block *sb, 60 static void ext4_clear_journal_err(struct super_block *sb,
61 struct ext4_super_block *es); 61 struct ext4_super_block *es);
62 static int ext4_sync_fs(struct super_block *sb, int wait); 62 static int ext4_sync_fs(struct super_block *sb, int wait);
63 static const char *ext4_decode_error(struct super_block *sb, int errno, 63 static const char *ext4_decode_error(struct super_block *sb, int errno,
64 char nbuf[16]); 64 char nbuf[16]);
65 static int ext4_remount(struct super_block *sb, int *flags, char *data); 65 static int ext4_remount(struct super_block *sb, int *flags, char *data);
66 static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf); 66 static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf);
67 static int ext4_unfreeze(struct super_block *sb); 67 static int ext4_unfreeze(struct super_block *sb);
68 static void ext4_write_super(struct super_block *sb); 68 static void ext4_write_super(struct super_block *sb);
69 static int ext4_freeze(struct super_block *sb); 69 static int ext4_freeze(struct super_block *sb);
70 70
71 71
72 ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, 72 ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
73 struct ext4_group_desc *bg) 73 struct ext4_group_desc *bg)
74 { 74 {
75 return le32_to_cpu(bg->bg_block_bitmap_lo) | 75 return le32_to_cpu(bg->bg_block_bitmap_lo) |
76 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 76 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
77 (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0); 77 (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
78 } 78 }
79 79
80 ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, 80 ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
81 struct ext4_group_desc *bg) 81 struct ext4_group_desc *bg)
82 { 82 {
83 return le32_to_cpu(bg->bg_inode_bitmap_lo) | 83 return le32_to_cpu(bg->bg_inode_bitmap_lo) |
84 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 84 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
85 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0); 85 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
86 } 86 }
87 87
88 ext4_fsblk_t ext4_inode_table(struct super_block *sb, 88 ext4_fsblk_t ext4_inode_table(struct super_block *sb,
89 struct ext4_group_desc *bg) 89 struct ext4_group_desc *bg)
90 { 90 {
91 return le32_to_cpu(bg->bg_inode_table_lo) | 91 return le32_to_cpu(bg->bg_inode_table_lo) |
92 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 92 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
93 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0); 93 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0);
94 } 94 }
95 95
96 __u32 ext4_free_blks_count(struct super_block *sb, 96 __u32 ext4_free_blks_count(struct super_block *sb,
97 struct ext4_group_desc *bg) 97 struct ext4_group_desc *bg)
98 { 98 {
99 return le16_to_cpu(bg->bg_free_blocks_count_lo) | 99 return le16_to_cpu(bg->bg_free_blocks_count_lo) |
100 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 100 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
101 (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0); 101 (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0);
102 } 102 }
103 103
104 __u32 ext4_free_inodes_count(struct super_block *sb, 104 __u32 ext4_free_inodes_count(struct super_block *sb,
105 struct ext4_group_desc *bg) 105 struct ext4_group_desc *bg)
106 { 106 {
107 return le16_to_cpu(bg->bg_free_inodes_count_lo) | 107 return le16_to_cpu(bg->bg_free_inodes_count_lo) |
108 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 108 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
109 (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0); 109 (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0);
110 } 110 }
111 111
112 __u32 ext4_used_dirs_count(struct super_block *sb, 112 __u32 ext4_used_dirs_count(struct super_block *sb,
113 struct ext4_group_desc *bg) 113 struct ext4_group_desc *bg)
114 { 114 {
115 return le16_to_cpu(bg->bg_used_dirs_count_lo) | 115 return le16_to_cpu(bg->bg_used_dirs_count_lo) |
116 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 116 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
117 (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0); 117 (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0);
118 } 118 }
119 119
120 __u32 ext4_itable_unused_count(struct super_block *sb, 120 __u32 ext4_itable_unused_count(struct super_block *sb,
121 struct ext4_group_desc *bg) 121 struct ext4_group_desc *bg)
122 { 122 {
123 return le16_to_cpu(bg->bg_itable_unused_lo) | 123 return le16_to_cpu(bg->bg_itable_unused_lo) |
124 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 124 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
125 (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0); 125 (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0);
126 } 126 }
127 127
128 void ext4_block_bitmap_set(struct super_block *sb, 128 void ext4_block_bitmap_set(struct super_block *sb,
129 struct ext4_group_desc *bg, ext4_fsblk_t blk) 129 struct ext4_group_desc *bg, ext4_fsblk_t blk)
130 { 130 {
131 bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk); 131 bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk);
132 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 132 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
133 bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32); 133 bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32);
134 } 134 }
135 135
136 void ext4_inode_bitmap_set(struct super_block *sb, 136 void ext4_inode_bitmap_set(struct super_block *sb,
137 struct ext4_group_desc *bg, ext4_fsblk_t blk) 137 struct ext4_group_desc *bg, ext4_fsblk_t blk)
138 { 138 {
139 bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk); 139 bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk);
140 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 140 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
141 bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32); 141 bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32);
142 } 142 }
143 143
144 void ext4_inode_table_set(struct super_block *sb, 144 void ext4_inode_table_set(struct super_block *sb,
145 struct ext4_group_desc *bg, ext4_fsblk_t blk) 145 struct ext4_group_desc *bg, ext4_fsblk_t blk)
146 { 146 {
147 bg->bg_inode_table_lo = cpu_to_le32((u32)blk); 147 bg->bg_inode_table_lo = cpu_to_le32((u32)blk);
148 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 148 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
149 bg->bg_inode_table_hi = cpu_to_le32(blk >> 32); 149 bg->bg_inode_table_hi = cpu_to_le32(blk >> 32);
150 } 150 }
151 151
152 void ext4_free_blks_set(struct super_block *sb, 152 void ext4_free_blks_set(struct super_block *sb,
153 struct ext4_group_desc *bg, __u32 count) 153 struct ext4_group_desc *bg, __u32 count)
154 { 154 {
155 bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count); 155 bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count);
156 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 156 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
157 bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16); 157 bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16);
158 } 158 }
159 159
160 void ext4_free_inodes_set(struct super_block *sb, 160 void ext4_free_inodes_set(struct super_block *sb,
161 struct ext4_group_desc *bg, __u32 count) 161 struct ext4_group_desc *bg, __u32 count)
162 { 162 {
163 bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count); 163 bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count);
164 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 164 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
165 bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16); 165 bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16);
166 } 166 }
167 167
168 void ext4_used_dirs_set(struct super_block *sb, 168 void ext4_used_dirs_set(struct super_block *sb,
169 struct ext4_group_desc *bg, __u32 count) 169 struct ext4_group_desc *bg, __u32 count)
170 { 170 {
171 bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count); 171 bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count);
172 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 172 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
173 bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16); 173 bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16);
174 } 174 }
175 175
176 void ext4_itable_unused_set(struct super_block *sb, 176 void ext4_itable_unused_set(struct super_block *sb,
177 struct ext4_group_desc *bg, __u32 count) 177 struct ext4_group_desc *bg, __u32 count)
178 { 178 {
179 bg->bg_itable_unused_lo = cpu_to_le16((__u16)count); 179 bg->bg_itable_unused_lo = cpu_to_le16((__u16)count);
180 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) 180 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
181 bg->bg_itable_unused_hi = cpu_to_le16(count >> 16); 181 bg->bg_itable_unused_hi = cpu_to_le16(count >> 16);
182 } 182 }
183 183
184 /* 184 /*
185 * Wrappers for jbd2_journal_start/end. 185 * Wrappers for jbd2_journal_start/end.
186 * 186 *
187 * The only special thing we need to do here is to make sure that all 187 * The only special thing we need to do here is to make sure that all
188 * journal_end calls result in the superblock being marked dirty, so 188 * journal_end calls result in the superblock being marked dirty, so
189 * that sync() will call the filesystem's write_super callback if 189 * that sync() will call the filesystem's write_super callback if
190 * appropriate. 190 * appropriate.
191 */ 191 */
192 handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks) 192 handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
193 { 193 {
194 journal_t *journal; 194 journal_t *journal;
195 195
196 if (sb->s_flags & MS_RDONLY) 196 if (sb->s_flags & MS_RDONLY)
197 return ERR_PTR(-EROFS); 197 return ERR_PTR(-EROFS);
198 198
199 /* Special case here: if the journal has aborted behind our 199 /* Special case here: if the journal has aborted behind our
200 * backs (eg. EIO in the commit thread), then we still need to 200 * backs (eg. EIO in the commit thread), then we still need to
201 * take the FS itself readonly cleanly. */ 201 * take the FS itself readonly cleanly. */
202 journal = EXT4_SB(sb)->s_journal; 202 journal = EXT4_SB(sb)->s_journal;
203 if (journal) { 203 if (journal) {
204 if (is_journal_aborted(journal)) { 204 if (is_journal_aborted(journal)) {
205 ext4_abort(sb, __func__, 205 ext4_abort(sb, __func__,
206 "Detected aborted journal"); 206 "Detected aborted journal");
207 return ERR_PTR(-EROFS); 207 return ERR_PTR(-EROFS);
208 } 208 }
209 return jbd2_journal_start(journal, nblocks); 209 return jbd2_journal_start(journal, nblocks);
210 } 210 }
211 /* 211 /*
212 * We're not journaling, return the appropriate indication. 212 * We're not journaling, return the appropriate indication.
213 */ 213 */
214 current->journal_info = EXT4_NOJOURNAL_HANDLE; 214 current->journal_info = EXT4_NOJOURNAL_HANDLE;
215 return current->journal_info; 215 return current->journal_info;
216 } 216 }
217 217
218 /* 218 /*
219 * The only special thing we need to do here is to make sure that all 219 * The only special thing we need to do here is to make sure that all
220 * jbd2_journal_stop calls result in the superblock being marked dirty, so 220 * jbd2_journal_stop calls result in the superblock being marked dirty, so
221 * that sync() will call the filesystem's write_super callback if 221 * that sync() will call the filesystem's write_super callback if
222 * appropriate. 222 * appropriate.
223 */ 223 */
224 int __ext4_journal_stop(const char *where, handle_t *handle) 224 int __ext4_journal_stop(const char *where, handle_t *handle)
225 { 225 {
226 struct super_block *sb; 226 struct super_block *sb;
227 int err; 227 int err;
228 int rc; 228 int rc;
229 229
230 if (!ext4_handle_valid(handle)) { 230 if (!ext4_handle_valid(handle)) {
231 /* 231 /*
232 * Do this here since we don't call jbd2_journal_stop() in 232 * Do this here since we don't call jbd2_journal_stop() in
233 * no-journal mode. 233 * no-journal mode.
234 */ 234 */
235 current->journal_info = NULL; 235 current->journal_info = NULL;
236 return 0; 236 return 0;
237 } 237 }
238 sb = handle->h_transaction->t_journal->j_private; 238 sb = handle->h_transaction->t_journal->j_private;
239 err = handle->h_err; 239 err = handle->h_err;
240 rc = jbd2_journal_stop(handle); 240 rc = jbd2_journal_stop(handle);
241 241
242 if (!err) 242 if (!err)
243 err = rc; 243 err = rc;
244 if (err) 244 if (err)
245 __ext4_std_error(sb, where, err); 245 __ext4_std_error(sb, where, err);
246 return err; 246 return err;
247 } 247 }
248 248
249 void ext4_journal_abort_handle(const char *caller, const char *err_fn, 249 void ext4_journal_abort_handle(const char *caller, const char *err_fn,
250 struct buffer_head *bh, handle_t *handle, int err) 250 struct buffer_head *bh, handle_t *handle, int err)
251 { 251 {
252 char nbuf[16]; 252 char nbuf[16];
253 const char *errstr = ext4_decode_error(NULL, err, nbuf); 253 const char *errstr = ext4_decode_error(NULL, err, nbuf);
254 254
255 BUG_ON(!ext4_handle_valid(handle)); 255 BUG_ON(!ext4_handle_valid(handle));
256 256
257 if (bh) 257 if (bh)
258 BUFFER_TRACE(bh, "abort"); 258 BUFFER_TRACE(bh, "abort");
259 259
260 if (!handle->h_err) 260 if (!handle->h_err)
261 handle->h_err = err; 261 handle->h_err = err;
262 262
263 if (is_handle_aborted(handle)) 263 if (is_handle_aborted(handle))
264 return; 264 return;
265 265
266 printk(KERN_ERR "%s: aborting transaction: %s in %s\n", 266 printk(KERN_ERR "%s: aborting transaction: %s in %s\n",
267 caller, errstr, err_fn); 267 caller, errstr, err_fn);
268 268
269 jbd2_journal_abort_handle(handle); 269 jbd2_journal_abort_handle(handle);
270 } 270 }
271 271
272 /* Deal with the reporting of failure conditions on a filesystem such as 272 /* Deal with the reporting of failure conditions on a filesystem such as
273 * inconsistencies detected or read IO failures. 273 * inconsistencies detected or read IO failures.
274 * 274 *
275 * On ext2, we can store the error state of the filesystem in the 275 * On ext2, we can store the error state of the filesystem in the
276 * superblock. That is not possible on ext4, because we may have other 276 * superblock. That is not possible on ext4, because we may have other
277 * write ordering constraints on the superblock which prevent us from 277 * write ordering constraints on the superblock which prevent us from
278 * writing it out straight away; and given that the journal is about to 278 * writing it out straight away; and given that the journal is about to
279 * be aborted, we can't rely on the current, or future, transactions to 279 * be aborted, we can't rely on the current, or future, transactions to
280 * write out the superblock safely. 280 * write out the superblock safely.
281 * 281 *
282 * We'll just use the jbd2_journal_abort() error code to record an error in 282 * We'll just use the jbd2_journal_abort() error code to record an error in
283 * the journal instead. On recovery, the journal will compain about 283 * the journal instead. On recovery, the journal will compain about
284 * that error until we've noted it down and cleared it. 284 * that error until we've noted it down and cleared it.
285 */ 285 */
286 286
287 static void ext4_handle_error(struct super_block *sb) 287 static void ext4_handle_error(struct super_block *sb)
288 { 288 {
289 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 289 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
290 290
291 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 291 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
292 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 292 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
293 293
294 if (sb->s_flags & MS_RDONLY) 294 if (sb->s_flags & MS_RDONLY)
295 return; 295 return;
296 296
297 if (!test_opt(sb, ERRORS_CONT)) { 297 if (!test_opt(sb, ERRORS_CONT)) {
298 journal_t *journal = EXT4_SB(sb)->s_journal; 298 journal_t *journal = EXT4_SB(sb)->s_journal;
299 299
300 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT; 300 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
301 if (journal) 301 if (journal)
302 jbd2_journal_abort(journal, -EIO); 302 jbd2_journal_abort(journal, -EIO);
303 } 303 }
304 if (test_opt(sb, ERRORS_RO)) { 304 if (test_opt(sb, ERRORS_RO)) {
305 printk(KERN_CRIT "Remounting filesystem read-only\n"); 305 printk(KERN_CRIT "Remounting filesystem read-only\n");
306 sb->s_flags |= MS_RDONLY; 306 sb->s_flags |= MS_RDONLY;
307 } 307 }
308 ext4_commit_super(sb, es, 1); 308 ext4_commit_super(sb, es, 1);
309 if (test_opt(sb, ERRORS_PANIC)) 309 if (test_opt(sb, ERRORS_PANIC))
310 panic("EXT4-fs (device %s): panic forced after error\n", 310 panic("EXT4-fs (device %s): panic forced after error\n",
311 sb->s_id); 311 sb->s_id);
312 } 312 }
313 313
314 void ext4_error(struct super_block *sb, const char *function, 314 void ext4_error(struct super_block *sb, const char *function,
315 const char *fmt, ...) 315 const char *fmt, ...)
316 { 316 {
317 va_list args; 317 va_list args;
318 318
319 va_start(args, fmt); 319 va_start(args, fmt);
320 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 320 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function);
321 vprintk(fmt, args); 321 vprintk(fmt, args);
322 printk("\n"); 322 printk("\n");
323 va_end(args); 323 va_end(args);
324 324
325 ext4_handle_error(sb); 325 ext4_handle_error(sb);
326 } 326 }
327 327
328 static const char *ext4_decode_error(struct super_block *sb, int errno, 328 static const char *ext4_decode_error(struct super_block *sb, int errno,
329 char nbuf[16]) 329 char nbuf[16])
330 { 330 {
331 char *errstr = NULL; 331 char *errstr = NULL;
332 332
333 switch (errno) { 333 switch (errno) {
334 case -EIO: 334 case -EIO:
335 errstr = "IO failure"; 335 errstr = "IO failure";
336 break; 336 break;
337 case -ENOMEM: 337 case -ENOMEM:
338 errstr = "Out of memory"; 338 errstr = "Out of memory";
339 break; 339 break;
340 case -EROFS: 340 case -EROFS:
341 if (!sb || EXT4_SB(sb)->s_journal->j_flags & JBD2_ABORT) 341 if (!sb || EXT4_SB(sb)->s_journal->j_flags & JBD2_ABORT)
342 errstr = "Journal has aborted"; 342 errstr = "Journal has aborted";
343 else 343 else
344 errstr = "Readonly filesystem"; 344 errstr = "Readonly filesystem";
345 break; 345 break;
346 default: 346 default:
347 /* If the caller passed in an extra buffer for unknown 347 /* If the caller passed in an extra buffer for unknown
348 * errors, textualise them now. Else we just return 348 * errors, textualise them now. Else we just return
349 * NULL. */ 349 * NULL. */
350 if (nbuf) { 350 if (nbuf) {
351 /* Check for truncated error codes... */ 351 /* Check for truncated error codes... */
352 if (snprintf(nbuf, 16, "error %d", -errno) >= 0) 352 if (snprintf(nbuf, 16, "error %d", -errno) >= 0)
353 errstr = nbuf; 353 errstr = nbuf;
354 } 354 }
355 break; 355 break;
356 } 356 }
357 357
358 return errstr; 358 return errstr;
359 } 359 }
360 360
361 /* __ext4_std_error decodes expected errors from journaling functions 361 /* __ext4_std_error decodes expected errors from journaling functions
362 * automatically and invokes the appropriate error response. */ 362 * automatically and invokes the appropriate error response. */
363 363
364 void __ext4_std_error(struct super_block *sb, const char *function, int errno) 364 void __ext4_std_error(struct super_block *sb, const char *function, int errno)
365 { 365 {
366 char nbuf[16]; 366 char nbuf[16];
367 const char *errstr; 367 const char *errstr;
368 368
369 /* Special case: if the error is EROFS, and we're not already 369 /* Special case: if the error is EROFS, and we're not already
370 * inside a transaction, then there's really no point in logging 370 * inside a transaction, then there's really no point in logging
371 * an error. */ 371 * an error. */
372 if (errno == -EROFS && journal_current_handle() == NULL && 372 if (errno == -EROFS && journal_current_handle() == NULL &&
373 (sb->s_flags & MS_RDONLY)) 373 (sb->s_flags & MS_RDONLY))
374 return; 374 return;
375 375
376 errstr = ext4_decode_error(sb, errno, nbuf); 376 errstr = ext4_decode_error(sb, errno, nbuf);
377 printk(KERN_CRIT "EXT4-fs error (device %s) in %s: %s\n", 377 printk(KERN_CRIT "EXT4-fs error (device %s) in %s: %s\n",
378 sb->s_id, function, errstr); 378 sb->s_id, function, errstr);
379 379
380 ext4_handle_error(sb); 380 ext4_handle_error(sb);
381 } 381 }
382 382
383 /* 383 /*
384 * ext4_abort is a much stronger failure handler than ext4_error. The 384 * ext4_abort is a much stronger failure handler than ext4_error. The
385 * abort function may be used to deal with unrecoverable failures such 385 * abort function may be used to deal with unrecoverable failures such
386 * as journal IO errors or ENOMEM at a critical moment in log management. 386 * as journal IO errors or ENOMEM at a critical moment in log management.
387 * 387 *
388 * We unconditionally force the filesystem into an ABORT|READONLY state, 388 * We unconditionally force the filesystem into an ABORT|READONLY state,
389 * unless the error response on the fs has been set to panic in which 389 * unless the error response on the fs has been set to panic in which
390 * case we take the easy way out and panic immediately. 390 * case we take the easy way out and panic immediately.
391 */ 391 */
392 392
393 void ext4_abort(struct super_block *sb, const char *function, 393 void ext4_abort(struct super_block *sb, const char *function,
394 const char *fmt, ...) 394 const char *fmt, ...)
395 { 395 {
396 va_list args; 396 va_list args;
397 397
398 printk(KERN_CRIT "ext4_abort called.\n"); 398 printk(KERN_CRIT "ext4_abort called.\n");
399 399
400 va_start(args, fmt); 400 va_start(args, fmt);
401 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 401 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function);
402 vprintk(fmt, args); 402 vprintk(fmt, args);
403 printk("\n"); 403 printk("\n");
404 va_end(args); 404 va_end(args);
405 405
406 if (test_opt(sb, ERRORS_PANIC)) 406 if (test_opt(sb, ERRORS_PANIC))
407 panic("EXT4-fs panic from previous error\n"); 407 panic("EXT4-fs panic from previous error\n");
408 408
409 if (sb->s_flags & MS_RDONLY) 409 if (sb->s_flags & MS_RDONLY)
410 return; 410 return;
411 411
412 printk(KERN_CRIT "Remounting filesystem read-only\n"); 412 printk(KERN_CRIT "Remounting filesystem read-only\n");
413 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 413 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
414 sb->s_flags |= MS_RDONLY; 414 sb->s_flags |= MS_RDONLY;
415 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT; 415 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
416 if (EXT4_SB(sb)->s_journal) 416 if (EXT4_SB(sb)->s_journal)
417 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO); 417 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
418 } 418 }
419 419
420 void ext4_warning(struct super_block *sb, const char *function, 420 void ext4_warning(struct super_block *sb, const char *function,
421 const char *fmt, ...) 421 const char *fmt, ...)
422 { 422 {
423 va_list args; 423 va_list args;
424 424
425 va_start(args, fmt); 425 va_start(args, fmt);
426 printk(KERN_WARNING "EXT4-fs warning (device %s): %s: ", 426 printk(KERN_WARNING "EXT4-fs warning (device %s): %s: ",
427 sb->s_id, function); 427 sb->s_id, function);
428 vprintk(fmt, args); 428 vprintk(fmt, args);
429 printk("\n"); 429 printk("\n");
430 va_end(args); 430 va_end(args);
431 } 431 }
432 432
433 void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp, 433 void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp,
434 const char *function, const char *fmt, ...) 434 const char *function, const char *fmt, ...)
435 __releases(bitlock) 435 __releases(bitlock)
436 __acquires(bitlock) 436 __acquires(bitlock)
437 { 437 {
438 va_list args; 438 va_list args;
439 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 439 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
440 440
441 va_start(args, fmt); 441 va_start(args, fmt);
442 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 442 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function);
443 vprintk(fmt, args); 443 vprintk(fmt, args);
444 printk("\n"); 444 printk("\n");
445 va_end(args); 445 va_end(args);
446 446
447 if (test_opt(sb, ERRORS_CONT)) { 447 if (test_opt(sb, ERRORS_CONT)) {
448 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 448 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
449 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 449 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
450 ext4_commit_super(sb, es, 0); 450 ext4_commit_super(sb, es, 0);
451 return; 451 return;
452 } 452 }
453 ext4_unlock_group(sb, grp); 453 ext4_unlock_group(sb, grp);
454 ext4_handle_error(sb); 454 ext4_handle_error(sb);
455 /* 455 /*
456 * We only get here in the ERRORS_RO case; relocking the group 456 * We only get here in the ERRORS_RO case; relocking the group
457 * may be dangerous, but nothing bad will happen since the 457 * may be dangerous, but nothing bad will happen since the
458 * filesystem will have already been marked read/only and the 458 * filesystem will have already been marked read/only and the
459 * journal has been aborted. We return 1 as a hint to callers 459 * journal has been aborted. We return 1 as a hint to callers
460 * who might what to use the return value from 460 * who might what to use the return value from
461 * ext4_grp_locked_error() to distinguish beween the 461 * ext4_grp_locked_error() to distinguish beween the
462 * ERRORS_CONT and ERRORS_RO case, and perhaps return more 462 * ERRORS_CONT and ERRORS_RO case, and perhaps return more
463 * aggressively from the ext4 function in question, with a 463 * aggressively from the ext4 function in question, with a
464 * more appropriate error code. 464 * more appropriate error code.
465 */ 465 */
466 ext4_lock_group(sb, grp); 466 ext4_lock_group(sb, grp);
467 return; 467 return;
468 } 468 }
469 469
470 470
471 void ext4_update_dynamic_rev(struct super_block *sb) 471 void ext4_update_dynamic_rev(struct super_block *sb)
472 { 472 {
473 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 473 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
474 474
475 if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV) 475 if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV)
476 return; 476 return;
477 477
478 ext4_warning(sb, __func__, 478 ext4_warning(sb, __func__,
479 "updating to rev %d because of new feature flag, " 479 "updating to rev %d because of new feature flag, "
480 "running e2fsck is recommended", 480 "running e2fsck is recommended",
481 EXT4_DYNAMIC_REV); 481 EXT4_DYNAMIC_REV);
482 482
483 es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO); 483 es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO);
484 es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE); 484 es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE);
485 es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV); 485 es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV);
486 /* leave es->s_feature_*compat flags alone */ 486 /* leave es->s_feature_*compat flags alone */
487 /* es->s_uuid will be set by e2fsck if empty */ 487 /* es->s_uuid will be set by e2fsck if empty */
488 488
489 /* 489 /*
490 * The rest of the superblock fields should be zero, and if not it 490 * The rest of the superblock fields should be zero, and if not it
491 * means they are likely already in use, so leave them alone. We 491 * means they are likely already in use, so leave them alone. We
492 * can leave it up to e2fsck to clean up any inconsistencies there. 492 * can leave it up to e2fsck to clean up any inconsistencies there.
493 */ 493 */
494 } 494 }
495 495
496 /* 496 /*
497 * Open the external journal device 497 * Open the external journal device
498 */ 498 */
499 static struct block_device *ext4_blkdev_get(dev_t dev) 499 static struct block_device *ext4_blkdev_get(dev_t dev)
500 { 500 {
501 struct block_device *bdev; 501 struct block_device *bdev;
502 char b[BDEVNAME_SIZE]; 502 char b[BDEVNAME_SIZE];
503 503
504 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); 504 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE);
505 if (IS_ERR(bdev)) 505 if (IS_ERR(bdev))
506 goto fail; 506 goto fail;
507 return bdev; 507 return bdev;
508 508
509 fail: 509 fail:
510 printk(KERN_ERR "EXT4-fs: failed to open journal device %s: %ld\n", 510 printk(KERN_ERR "EXT4-fs: failed to open journal device %s: %ld\n",
511 __bdevname(dev, b), PTR_ERR(bdev)); 511 __bdevname(dev, b), PTR_ERR(bdev));
512 return NULL; 512 return NULL;
513 } 513 }
514 514
515 /* 515 /*
516 * Release the journal device 516 * Release the journal device
517 */ 517 */
518 static int ext4_blkdev_put(struct block_device *bdev) 518 static int ext4_blkdev_put(struct block_device *bdev)
519 { 519 {
520 bd_release(bdev); 520 bd_release(bdev);
521 return blkdev_put(bdev, FMODE_READ|FMODE_WRITE); 521 return blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
522 } 522 }
523 523
524 static int ext4_blkdev_remove(struct ext4_sb_info *sbi) 524 static int ext4_blkdev_remove(struct ext4_sb_info *sbi)
525 { 525 {
526 struct block_device *bdev; 526 struct block_device *bdev;
527 int ret = -ENODEV; 527 int ret = -ENODEV;
528 528
529 bdev = sbi->journal_bdev; 529 bdev = sbi->journal_bdev;
530 if (bdev) { 530 if (bdev) {
531 ret = ext4_blkdev_put(bdev); 531 ret = ext4_blkdev_put(bdev);
532 sbi->journal_bdev = NULL; 532 sbi->journal_bdev = NULL;
533 } 533 }
534 return ret; 534 return ret;
535 } 535 }
536 536
537 static inline struct inode *orphan_list_entry(struct list_head *l) 537 static inline struct inode *orphan_list_entry(struct list_head *l)
538 { 538 {
539 return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode; 539 return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode;
540 } 540 }
541 541
542 static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi) 542 static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi)
543 { 543 {
544 struct list_head *l; 544 struct list_head *l;
545 545
546 printk(KERN_ERR "sb orphan head is %d\n", 546 printk(KERN_ERR "sb orphan head is %d\n",
547 le32_to_cpu(sbi->s_es->s_last_orphan)); 547 le32_to_cpu(sbi->s_es->s_last_orphan));
548 548
549 printk(KERN_ERR "sb_info orphan list:\n"); 549 printk(KERN_ERR "sb_info orphan list:\n");
550 list_for_each(l, &sbi->s_orphan) { 550 list_for_each(l, &sbi->s_orphan) {
551 struct inode *inode = orphan_list_entry(l); 551 struct inode *inode = orphan_list_entry(l);
552 printk(KERN_ERR " " 552 printk(KERN_ERR " "
553 "inode %s:%lu at %p: mode %o, nlink %d, next %d\n", 553 "inode %s:%lu at %p: mode %o, nlink %d, next %d\n",
554 inode->i_sb->s_id, inode->i_ino, inode, 554 inode->i_sb->s_id, inode->i_ino, inode,
555 inode->i_mode, inode->i_nlink, 555 inode->i_mode, inode->i_nlink,
556 NEXT_ORPHAN(inode)); 556 NEXT_ORPHAN(inode));
557 } 557 }
558 } 558 }
559 559
560 static void ext4_put_super(struct super_block *sb) 560 static void ext4_put_super(struct super_block *sb)
561 { 561 {
562 struct ext4_sb_info *sbi = EXT4_SB(sb); 562 struct ext4_sb_info *sbi = EXT4_SB(sb);
563 struct ext4_super_block *es = sbi->s_es; 563 struct ext4_super_block *es = sbi->s_es;
564 int i, err; 564 int i, err;
565 565
566 ext4_mb_release(sb); 566 ext4_mb_release(sb);
567 ext4_ext_release(sb); 567 ext4_ext_release(sb);
568 ext4_xattr_put_super(sb); 568 ext4_xattr_put_super(sb);
569 if (sbi->s_journal) { 569 if (sbi->s_journal) {
570 err = jbd2_journal_destroy(sbi->s_journal); 570 err = jbd2_journal_destroy(sbi->s_journal);
571 sbi->s_journal = NULL; 571 sbi->s_journal = NULL;
572 if (err < 0) 572 if (err < 0)
573 ext4_abort(sb, __func__, 573 ext4_abort(sb, __func__,
574 "Couldn't clean up the journal"); 574 "Couldn't clean up the journal");
575 } 575 }
576 if (!(sb->s_flags & MS_RDONLY)) { 576 if (!(sb->s_flags & MS_RDONLY)) {
577 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 577 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
578 es->s_state = cpu_to_le16(sbi->s_mount_state); 578 es->s_state = cpu_to_le16(sbi->s_mount_state);
579 ext4_commit_super(sb, es, 1); 579 ext4_commit_super(sb, es, 1);
580 } 580 }
581 if (sbi->s_proc) { 581 if (sbi->s_proc) {
582 remove_proc_entry(sb->s_id, ext4_proc_root); 582 remove_proc_entry(sb->s_id, ext4_proc_root);
583 } 583 }
584 kobject_del(&sbi->s_kobj); 584 kobject_del(&sbi->s_kobj);
585 585
586 for (i = 0; i < sbi->s_gdb_count; i++) 586 for (i = 0; i < sbi->s_gdb_count; i++)
587 brelse(sbi->s_group_desc[i]); 587 brelse(sbi->s_group_desc[i]);
588 kfree(sbi->s_group_desc); 588 kfree(sbi->s_group_desc);
589 kfree(sbi->s_flex_groups); 589 kfree(sbi->s_flex_groups);
590 percpu_counter_destroy(&sbi->s_freeblocks_counter); 590 percpu_counter_destroy(&sbi->s_freeblocks_counter);
591 percpu_counter_destroy(&sbi->s_freeinodes_counter); 591 percpu_counter_destroy(&sbi->s_freeinodes_counter);
592 percpu_counter_destroy(&sbi->s_dirs_counter); 592 percpu_counter_destroy(&sbi->s_dirs_counter);
593 percpu_counter_destroy(&sbi->s_dirtyblocks_counter); 593 percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
594 brelse(sbi->s_sbh); 594 brelse(sbi->s_sbh);
595 #ifdef CONFIG_QUOTA 595 #ifdef CONFIG_QUOTA
596 for (i = 0; i < MAXQUOTAS; i++) 596 for (i = 0; i < MAXQUOTAS; i++)
597 kfree(sbi->s_qf_names[i]); 597 kfree(sbi->s_qf_names[i]);
598 #endif 598 #endif
599 599
600 /* Debugging code just in case the in-memory inode orphan list 600 /* Debugging code just in case the in-memory inode orphan list
601 * isn't empty. The on-disk one can be non-empty if we've 601 * isn't empty. The on-disk one can be non-empty if we've
602 * detected an error and taken the fs readonly, but the 602 * detected an error and taken the fs readonly, but the
603 * in-memory list had better be clean by this point. */ 603 * in-memory list had better be clean by this point. */
604 if (!list_empty(&sbi->s_orphan)) 604 if (!list_empty(&sbi->s_orphan))
605 dump_orphan_list(sb, sbi); 605 dump_orphan_list(sb, sbi);
606 J_ASSERT(list_empty(&sbi->s_orphan)); 606 J_ASSERT(list_empty(&sbi->s_orphan));
607 607
608 invalidate_bdev(sb->s_bdev); 608 invalidate_bdev(sb->s_bdev);
609 if (sbi->journal_bdev && sbi->journal_bdev != sb->s_bdev) { 609 if (sbi->journal_bdev && sbi->journal_bdev != sb->s_bdev) {
610 /* 610 /*
611 * Invalidate the journal device's buffers. We don't want them 611 * Invalidate the journal device's buffers. We don't want them
612 * floating about in memory - the physical journal device may 612 * floating about in memory - the physical journal device may
613 * hotswapped, and it breaks the `ro-after' testing code. 613 * hotswapped, and it breaks the `ro-after' testing code.
614 */ 614 */
615 sync_blockdev(sbi->journal_bdev); 615 sync_blockdev(sbi->journal_bdev);
616 invalidate_bdev(sbi->journal_bdev); 616 invalidate_bdev(sbi->journal_bdev);
617 ext4_blkdev_remove(sbi); 617 ext4_blkdev_remove(sbi);
618 } 618 }
619 sb->s_fs_info = NULL; 619 sb->s_fs_info = NULL;
620 /* 620 /*
621 * Now that we are completely done shutting down the 621 * Now that we are completely done shutting down the
622 * superblock, we need to actually destroy the kobject. 622 * superblock, we need to actually destroy the kobject.
623 */ 623 */
624 unlock_kernel(); 624 unlock_kernel();
625 unlock_super(sb); 625 unlock_super(sb);
626 kobject_put(&sbi->s_kobj); 626 kobject_put(&sbi->s_kobj);
627 wait_for_completion(&sbi->s_kobj_unregister); 627 wait_for_completion(&sbi->s_kobj_unregister);
628 lock_super(sb); 628 lock_super(sb);
629 lock_kernel(); 629 lock_kernel();
630 kfree(sbi->s_blockgroup_lock); 630 kfree(sbi->s_blockgroup_lock);
631 kfree(sbi); 631 kfree(sbi);
632 return; 632 return;
633 } 633 }
634 634
635 static struct kmem_cache *ext4_inode_cachep; 635 static struct kmem_cache *ext4_inode_cachep;
636 636
637 /* 637 /*
638 * Called inside transaction, so use GFP_NOFS 638 * Called inside transaction, so use GFP_NOFS
639 */ 639 */
640 static struct inode *ext4_alloc_inode(struct super_block *sb) 640 static struct inode *ext4_alloc_inode(struct super_block *sb)
641 { 641 {
642 struct ext4_inode_info *ei; 642 struct ext4_inode_info *ei;
643 643
644 ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS); 644 ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS);
645 if (!ei) 645 if (!ei)
646 return NULL; 646 return NULL;
647 #ifdef CONFIG_EXT4_FS_POSIX_ACL 647 #ifdef CONFIG_EXT4_FS_POSIX_ACL
648 ei->i_acl = EXT4_ACL_NOT_CACHED; 648 ei->i_acl = EXT4_ACL_NOT_CACHED;
649 ei->i_default_acl = EXT4_ACL_NOT_CACHED; 649 ei->i_default_acl = EXT4_ACL_NOT_CACHED;
650 #endif 650 #endif
651 ei->vfs_inode.i_version = 1; 651 ei->vfs_inode.i_version = 1;
652 ei->vfs_inode.i_data.writeback_index = 0; 652 ei->vfs_inode.i_data.writeback_index = 0;
653 memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache)); 653 memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache));
654 INIT_LIST_HEAD(&ei->i_prealloc_list); 654 INIT_LIST_HEAD(&ei->i_prealloc_list);
655 spin_lock_init(&ei->i_prealloc_lock); 655 spin_lock_init(&ei->i_prealloc_lock);
656 /* 656 /*
657 * Note: We can be called before EXT4_SB(sb)->s_journal is set, 657 * Note: We can be called before EXT4_SB(sb)->s_journal is set,
658 * therefore it can be null here. Don't check it, just initialize 658 * therefore it can be null here. Don't check it, just initialize
659 * jinode. 659 * jinode.
660 */ 660 */
661 jbd2_journal_init_jbd_inode(&ei->jinode, &ei->vfs_inode); 661 jbd2_journal_init_jbd_inode(&ei->jinode, &ei->vfs_inode);
662 ei->i_reserved_data_blocks = 0; 662 ei->i_reserved_data_blocks = 0;
663 ei->i_reserved_meta_blocks = 0; 663 ei->i_reserved_meta_blocks = 0;
664 ei->i_allocated_meta_blocks = 0; 664 ei->i_allocated_meta_blocks = 0;
665 ei->i_delalloc_reserved_flag = 0; 665 ei->i_delalloc_reserved_flag = 0;
666 spin_lock_init(&(ei->i_block_reservation_lock)); 666 spin_lock_init(&(ei->i_block_reservation_lock));
667 return &ei->vfs_inode; 667 return &ei->vfs_inode;
668 } 668 }
669 669
670 static void ext4_destroy_inode(struct inode *inode) 670 static void ext4_destroy_inode(struct inode *inode)
671 { 671 {
672 if (!list_empty(&(EXT4_I(inode)->i_orphan))) { 672 if (!list_empty(&(EXT4_I(inode)->i_orphan))) {
673 printk("EXT4 Inode %p: orphan list check failed!\n", 673 printk("EXT4 Inode %p: orphan list check failed!\n",
674 EXT4_I(inode)); 674 EXT4_I(inode));
675 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4, 675 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4,
676 EXT4_I(inode), sizeof(struct ext4_inode_info), 676 EXT4_I(inode), sizeof(struct ext4_inode_info),
677 true); 677 true);
678 dump_stack(); 678 dump_stack();
679 } 679 }
680 kmem_cache_free(ext4_inode_cachep, EXT4_I(inode)); 680 kmem_cache_free(ext4_inode_cachep, EXT4_I(inode));
681 } 681 }
682 682
683 static void init_once(void *foo) 683 static void init_once(void *foo)
684 { 684 {
685 struct ext4_inode_info *ei = (struct ext4_inode_info *) foo; 685 struct ext4_inode_info *ei = (struct ext4_inode_info *) foo;
686 686
687 INIT_LIST_HEAD(&ei->i_orphan); 687 INIT_LIST_HEAD(&ei->i_orphan);
688 #ifdef CONFIG_EXT4_FS_XATTR 688 #ifdef CONFIG_EXT4_FS_XATTR
689 init_rwsem(&ei->xattr_sem); 689 init_rwsem(&ei->xattr_sem);
690 #endif 690 #endif
691 init_rwsem(&ei->i_data_sem); 691 init_rwsem(&ei->i_data_sem);
692 inode_init_once(&ei->vfs_inode); 692 inode_init_once(&ei->vfs_inode);
693 } 693 }
694 694
695 static int init_inodecache(void) 695 static int init_inodecache(void)
696 { 696 {
697 ext4_inode_cachep = kmem_cache_create("ext4_inode_cache", 697 ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
698 sizeof(struct ext4_inode_info), 698 sizeof(struct ext4_inode_info),
699 0, (SLAB_RECLAIM_ACCOUNT| 699 0, (SLAB_RECLAIM_ACCOUNT|
700 SLAB_MEM_SPREAD), 700 SLAB_MEM_SPREAD),
701 init_once); 701 init_once);
702 if (ext4_inode_cachep == NULL) 702 if (ext4_inode_cachep == NULL)
703 return -ENOMEM; 703 return -ENOMEM;
704 return 0; 704 return 0;
705 } 705 }
706 706
707 static void destroy_inodecache(void) 707 static void destroy_inodecache(void)
708 { 708 {
709 kmem_cache_destroy(ext4_inode_cachep); 709 kmem_cache_destroy(ext4_inode_cachep);
710 } 710 }
711 711
712 static void ext4_clear_inode(struct inode *inode) 712 static void ext4_clear_inode(struct inode *inode)
713 { 713 {
714 #ifdef CONFIG_EXT4_FS_POSIX_ACL 714 #ifdef CONFIG_EXT4_FS_POSIX_ACL
715 if (EXT4_I(inode)->i_acl && 715 if (EXT4_I(inode)->i_acl &&
716 EXT4_I(inode)->i_acl != EXT4_ACL_NOT_CACHED) { 716 EXT4_I(inode)->i_acl != EXT4_ACL_NOT_CACHED) {
717 posix_acl_release(EXT4_I(inode)->i_acl); 717 posix_acl_release(EXT4_I(inode)->i_acl);
718 EXT4_I(inode)->i_acl = EXT4_ACL_NOT_CACHED; 718 EXT4_I(inode)->i_acl = EXT4_ACL_NOT_CACHED;
719 } 719 }
720 if (EXT4_I(inode)->i_default_acl && 720 if (EXT4_I(inode)->i_default_acl &&
721 EXT4_I(inode)->i_default_acl != EXT4_ACL_NOT_CACHED) { 721 EXT4_I(inode)->i_default_acl != EXT4_ACL_NOT_CACHED) {
722 posix_acl_release(EXT4_I(inode)->i_default_acl); 722 posix_acl_release(EXT4_I(inode)->i_default_acl);
723 EXT4_I(inode)->i_default_acl = EXT4_ACL_NOT_CACHED; 723 EXT4_I(inode)->i_default_acl = EXT4_ACL_NOT_CACHED;
724 } 724 }
725 #endif 725 #endif
726 ext4_discard_preallocations(inode); 726 ext4_discard_preallocations(inode);
727 if (EXT4_JOURNAL(inode)) 727 if (EXT4_JOURNAL(inode))
728 jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal, 728 jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal,
729 &EXT4_I(inode)->jinode); 729 &EXT4_I(inode)->jinode);
730 } 730 }
731 731
732 static inline void ext4_show_quota_options(struct seq_file *seq, 732 static inline void ext4_show_quota_options(struct seq_file *seq,
733 struct super_block *sb) 733 struct super_block *sb)
734 { 734 {
735 #if defined(CONFIG_QUOTA) 735 #if defined(CONFIG_QUOTA)
736 struct ext4_sb_info *sbi = EXT4_SB(sb); 736 struct ext4_sb_info *sbi = EXT4_SB(sb);
737 737
738 if (sbi->s_jquota_fmt) 738 if (sbi->s_jquota_fmt)
739 seq_printf(seq, ",jqfmt=%s", 739 seq_printf(seq, ",jqfmt=%s",
740 (sbi->s_jquota_fmt == QFMT_VFS_OLD) ? "vfsold" : "vfsv0"); 740 (sbi->s_jquota_fmt == QFMT_VFS_OLD) ? "vfsold" : "vfsv0");
741 741
742 if (sbi->s_qf_names[USRQUOTA]) 742 if (sbi->s_qf_names[USRQUOTA])
743 seq_printf(seq, ",usrjquota=%s", sbi->s_qf_names[USRQUOTA]); 743 seq_printf(seq, ",usrjquota=%s", sbi->s_qf_names[USRQUOTA]);
744 744
745 if (sbi->s_qf_names[GRPQUOTA]) 745 if (sbi->s_qf_names[GRPQUOTA])
746 seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]); 746 seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]);
747 747
748 if (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA) 748 if (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA)
749 seq_puts(seq, ",usrquota"); 749 seq_puts(seq, ",usrquota");
750 750
751 if (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA) 751 if (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)
752 seq_puts(seq, ",grpquota"); 752 seq_puts(seq, ",grpquota");
753 #endif 753 #endif
754 } 754 }
755 755
756 /* 756 /*
757 * Show an option if 757 * Show an option if
758 * - it's set to a non-default value OR 758 * - it's set to a non-default value OR
759 * - if the per-sb default is different from the global default 759 * - if the per-sb default is different from the global default
760 */ 760 */
761 static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs) 761 static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
762 { 762 {
763 int def_errors; 763 int def_errors;
764 unsigned long def_mount_opts; 764 unsigned long def_mount_opts;
765 struct super_block *sb = vfs->mnt_sb; 765 struct super_block *sb = vfs->mnt_sb;
766 struct ext4_sb_info *sbi = EXT4_SB(sb); 766 struct ext4_sb_info *sbi = EXT4_SB(sb);
767 struct ext4_super_block *es = sbi->s_es; 767 struct ext4_super_block *es = sbi->s_es;
768 768
769 def_mount_opts = le32_to_cpu(es->s_default_mount_opts); 769 def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
770 def_errors = le16_to_cpu(es->s_errors); 770 def_errors = le16_to_cpu(es->s_errors);
771 771
772 if (sbi->s_sb_block != 1) 772 if (sbi->s_sb_block != 1)
773 seq_printf(seq, ",sb=%llu", sbi->s_sb_block); 773 seq_printf(seq, ",sb=%llu", sbi->s_sb_block);
774 if (test_opt(sb, MINIX_DF)) 774 if (test_opt(sb, MINIX_DF))
775 seq_puts(seq, ",minixdf"); 775 seq_puts(seq, ",minixdf");
776 if (test_opt(sb, GRPID) && !(def_mount_opts & EXT4_DEFM_BSDGROUPS)) 776 if (test_opt(sb, GRPID) && !(def_mount_opts & EXT4_DEFM_BSDGROUPS))
777 seq_puts(seq, ",grpid"); 777 seq_puts(seq, ",grpid");
778 if (!test_opt(sb, GRPID) && (def_mount_opts & EXT4_DEFM_BSDGROUPS)) 778 if (!test_opt(sb, GRPID) && (def_mount_opts & EXT4_DEFM_BSDGROUPS))
779 seq_puts(seq, ",nogrpid"); 779 seq_puts(seq, ",nogrpid");
780 if (sbi->s_resuid != EXT4_DEF_RESUID || 780 if (sbi->s_resuid != EXT4_DEF_RESUID ||
781 le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID) { 781 le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID) {
782 seq_printf(seq, ",resuid=%u", sbi->s_resuid); 782 seq_printf(seq, ",resuid=%u", sbi->s_resuid);
783 } 783 }
784 if (sbi->s_resgid != EXT4_DEF_RESGID || 784 if (sbi->s_resgid != EXT4_DEF_RESGID ||
785 le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) { 785 le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) {
786 seq_printf(seq, ",resgid=%u", sbi->s_resgid); 786 seq_printf(seq, ",resgid=%u", sbi->s_resgid);
787 } 787 }
788 if (test_opt(sb, ERRORS_RO)) { 788 if (test_opt(sb, ERRORS_RO)) {
789 if (def_errors == EXT4_ERRORS_PANIC || 789 if (def_errors == EXT4_ERRORS_PANIC ||
790 def_errors == EXT4_ERRORS_CONTINUE) { 790 def_errors == EXT4_ERRORS_CONTINUE) {
791 seq_puts(seq, ",errors=remount-ro"); 791 seq_puts(seq, ",errors=remount-ro");
792 } 792 }
793 } 793 }
794 if (test_opt(sb, ERRORS_CONT) && def_errors != EXT4_ERRORS_CONTINUE) 794 if (test_opt(sb, ERRORS_CONT) && def_errors != EXT4_ERRORS_CONTINUE)
795 seq_puts(seq, ",errors=continue"); 795 seq_puts(seq, ",errors=continue");
796 if (test_opt(sb, ERRORS_PANIC) && def_errors != EXT4_ERRORS_PANIC) 796 if (test_opt(sb, ERRORS_PANIC) && def_errors != EXT4_ERRORS_PANIC)
797 seq_puts(seq, ",errors=panic"); 797 seq_puts(seq, ",errors=panic");
798 if (test_opt(sb, NO_UID32) && !(def_mount_opts & EXT4_DEFM_UID16)) 798 if (test_opt(sb, NO_UID32) && !(def_mount_opts & EXT4_DEFM_UID16))
799 seq_puts(seq, ",nouid32"); 799 seq_puts(seq, ",nouid32");
800 if (test_opt(sb, DEBUG) && !(def_mount_opts & EXT4_DEFM_DEBUG)) 800 if (test_opt(sb, DEBUG) && !(def_mount_opts & EXT4_DEFM_DEBUG))
801 seq_puts(seq, ",debug"); 801 seq_puts(seq, ",debug");
802 if (test_opt(sb, OLDALLOC)) 802 if (test_opt(sb, OLDALLOC))
803 seq_puts(seq, ",oldalloc"); 803 seq_puts(seq, ",oldalloc");
804 #ifdef CONFIG_EXT4_FS_XATTR 804 #ifdef CONFIG_EXT4_FS_XATTR
805 if (test_opt(sb, XATTR_USER) && 805 if (test_opt(sb, XATTR_USER) &&
806 !(def_mount_opts & EXT4_DEFM_XATTR_USER)) 806 !(def_mount_opts & EXT4_DEFM_XATTR_USER))
807 seq_puts(seq, ",user_xattr"); 807 seq_puts(seq, ",user_xattr");
808 if (!test_opt(sb, XATTR_USER) && 808 if (!test_opt(sb, XATTR_USER) &&
809 (def_mount_opts & EXT4_DEFM_XATTR_USER)) { 809 (def_mount_opts & EXT4_DEFM_XATTR_USER)) {
810 seq_puts(seq, ",nouser_xattr"); 810 seq_puts(seq, ",nouser_xattr");
811 } 811 }
812 #endif 812 #endif
813 #ifdef CONFIG_EXT4_FS_POSIX_ACL 813 #ifdef CONFIG_EXT4_FS_POSIX_ACL
814 if (test_opt(sb, POSIX_ACL) && !(def_mount_opts & EXT4_DEFM_ACL)) 814 if (test_opt(sb, POSIX_ACL) && !(def_mount_opts & EXT4_DEFM_ACL))
815 seq_puts(seq, ",acl"); 815 seq_puts(seq, ",acl");
816 if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL)) 816 if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL))
817 seq_puts(seq, ",noacl"); 817 seq_puts(seq, ",noacl");
818 #endif 818 #endif
819 if (!test_opt(sb, RESERVATION)) 819 if (!test_opt(sb, RESERVATION))
820 seq_puts(seq, ",noreservation"); 820 seq_puts(seq, ",noreservation");
821 if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) { 821 if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) {
822 seq_printf(seq, ",commit=%u", 822 seq_printf(seq, ",commit=%u",
823 (unsigned) (sbi->s_commit_interval / HZ)); 823 (unsigned) (sbi->s_commit_interval / HZ));
824 } 824 }
825 if (sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME) { 825 if (sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME) {
826 seq_printf(seq, ",min_batch_time=%u", 826 seq_printf(seq, ",min_batch_time=%u",
827 (unsigned) sbi->s_min_batch_time); 827 (unsigned) sbi->s_min_batch_time);
828 } 828 }
829 if (sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME) { 829 if (sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME) {
830 seq_printf(seq, ",max_batch_time=%u", 830 seq_printf(seq, ",max_batch_time=%u",
831 (unsigned) sbi->s_min_batch_time); 831 (unsigned) sbi->s_min_batch_time);
832 } 832 }
833 833
834 /* 834 /*
835 * We're changing the default of barrier mount option, so 835 * We're changing the default of barrier mount option, so
836 * let's always display its mount state so it's clear what its 836 * let's always display its mount state so it's clear what its
837 * status is. 837 * status is.
838 */ 838 */
839 seq_puts(seq, ",barrier="); 839 seq_puts(seq, ",barrier=");
840 seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0"); 840 seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0");
841 if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) 841 if (test_opt(sb, JOURNAL_ASYNC_COMMIT))
842 seq_puts(seq, ",journal_async_commit"); 842 seq_puts(seq, ",journal_async_commit");
843 if (test_opt(sb, NOBH)) 843 if (test_opt(sb, NOBH))
844 seq_puts(seq, ",nobh"); 844 seq_puts(seq, ",nobh");
845 if (test_opt(sb, I_VERSION)) 845 if (test_opt(sb, I_VERSION))
846 seq_puts(seq, ",i_version"); 846 seq_puts(seq, ",i_version");
847 if (!test_opt(sb, DELALLOC)) 847 if (!test_opt(sb, DELALLOC))
848 seq_puts(seq, ",nodelalloc"); 848 seq_puts(seq, ",nodelalloc");
849 849
850 850
851 if (sbi->s_stripe) 851 if (sbi->s_stripe)
852 seq_printf(seq, ",stripe=%lu", sbi->s_stripe); 852 seq_printf(seq, ",stripe=%lu", sbi->s_stripe);
853 /* 853 /*
854 * journal mode get enabled in different ways 854 * journal mode get enabled in different ways
855 * So just print the value even if we didn't specify it 855 * So just print the value even if we didn't specify it
856 */ 856 */
857 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) 857 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
858 seq_puts(seq, ",data=journal"); 858 seq_puts(seq, ",data=journal");
859 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) 859 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
860 seq_puts(seq, ",data=ordered"); 860 seq_puts(seq, ",data=ordered");
861 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA) 861 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
862 seq_puts(seq, ",data=writeback"); 862 seq_puts(seq, ",data=writeback");
863 863
864 if (sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS) 864 if (sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS)
865 seq_printf(seq, ",inode_readahead_blks=%u", 865 seq_printf(seq, ",inode_readahead_blks=%u",
866 sbi->s_inode_readahead_blks); 866 sbi->s_inode_readahead_blks);
867 867
868 if (test_opt(sb, DATA_ERR_ABORT)) 868 if (test_opt(sb, DATA_ERR_ABORT))
869 seq_puts(seq, ",data_err=abort"); 869 seq_puts(seq, ",data_err=abort");
870 870
871 ext4_show_quota_options(seq, sb); 871 ext4_show_quota_options(seq, sb);
872 return 0; 872 return 0;
873 } 873 }
874 874
875 875
876 static struct inode *ext4_nfs_get_inode(struct super_block *sb, 876 static struct inode *ext4_nfs_get_inode(struct super_block *sb,
877 u64 ino, u32 generation) 877 u64 ino, u32 generation)
878 { 878 {
879 struct inode *inode; 879 struct inode *inode;
880 880
881 if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO) 881 if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO)
882 return ERR_PTR(-ESTALE); 882 return ERR_PTR(-ESTALE);
883 if (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)) 883 if (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count))
884 return ERR_PTR(-ESTALE); 884 return ERR_PTR(-ESTALE);
885 885
886 /* iget isn't really right if the inode is currently unallocated!! 886 /* iget isn't really right if the inode is currently unallocated!!
887 * 887 *
888 * ext4_read_inode will return a bad_inode if the inode had been 888 * ext4_read_inode will return a bad_inode if the inode had been
889 * deleted, so we should be safe. 889 * deleted, so we should be safe.
890 * 890 *
891 * Currently we don't know the generation for parent directory, so 891 * Currently we don't know the generation for parent directory, so
892 * a generation of 0 means "accept any" 892 * a generation of 0 means "accept any"
893 */ 893 */
894 inode = ext4_iget(sb, ino); 894 inode = ext4_iget(sb, ino);
895 if (IS_ERR(inode)) 895 if (IS_ERR(inode))
896 return ERR_CAST(inode); 896 return ERR_CAST(inode);
897 if (generation && inode->i_generation != generation) { 897 if (generation && inode->i_generation != generation) {
898 iput(inode); 898 iput(inode);
899 return ERR_PTR(-ESTALE); 899 return ERR_PTR(-ESTALE);
900 } 900 }
901 901
902 return inode; 902 return inode;
903 } 903 }
904 904
905 static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid, 905 static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid,
906 int fh_len, int fh_type) 906 int fh_len, int fh_type)
907 { 907 {
908 return generic_fh_to_dentry(sb, fid, fh_len, fh_type, 908 return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
909 ext4_nfs_get_inode); 909 ext4_nfs_get_inode);
910 } 910 }
911 911
912 static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid, 912 static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid,
913 int fh_len, int fh_type) 913 int fh_len, int fh_type)
914 { 914 {
915 return generic_fh_to_parent(sb, fid, fh_len, fh_type, 915 return generic_fh_to_parent(sb, fid, fh_len, fh_type,
916 ext4_nfs_get_inode); 916 ext4_nfs_get_inode);
917 } 917 }
918 918
919 /* 919 /*
920 * Try to release metadata pages (indirect blocks, directories) which are 920 * Try to release metadata pages (indirect blocks, directories) which are
921 * mapped via the block device. Since these pages could have journal heads 921 * mapped via the block device. Since these pages could have journal heads
922 * which would prevent try_to_free_buffers() from freeing them, we must use 922 * which would prevent try_to_free_buffers() from freeing them, we must use
923 * jbd2 layer's try_to_free_buffers() function to release them. 923 * jbd2 layer's try_to_free_buffers() function to release them.
924 */ 924 */
925 static int bdev_try_to_free_page(struct super_block *sb, struct page *page, gfp_t wait) 925 static int bdev_try_to_free_page(struct super_block *sb, struct page *page, gfp_t wait)
926 { 926 {
927 journal_t *journal = EXT4_SB(sb)->s_journal; 927 journal_t *journal = EXT4_SB(sb)->s_journal;
928 928
929 WARN_ON(PageChecked(page)); 929 WARN_ON(PageChecked(page));
930 if (!page_has_buffers(page)) 930 if (!page_has_buffers(page))
931 return 0; 931 return 0;
932 if (journal) 932 if (journal)
933 return jbd2_journal_try_to_free_buffers(journal, page, 933 return jbd2_journal_try_to_free_buffers(journal, page,
934 wait & ~__GFP_WAIT); 934 wait & ~__GFP_WAIT);
935 return try_to_free_buffers(page); 935 return try_to_free_buffers(page);
936 } 936 }
937 937
938 #ifdef CONFIG_QUOTA 938 #ifdef CONFIG_QUOTA
939 #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group") 939 #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group")
940 #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA)) 940 #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
941 941
942 static int ext4_write_dquot(struct dquot *dquot); 942 static int ext4_write_dquot(struct dquot *dquot);
943 static int ext4_acquire_dquot(struct dquot *dquot); 943 static int ext4_acquire_dquot(struct dquot *dquot);
944 static int ext4_release_dquot(struct dquot *dquot); 944 static int ext4_release_dquot(struct dquot *dquot);
945 static int ext4_mark_dquot_dirty(struct dquot *dquot); 945 static int ext4_mark_dquot_dirty(struct dquot *dquot);
946 static int ext4_write_info(struct super_block *sb, int type); 946 static int ext4_write_info(struct super_block *sb, int type);
947 static int ext4_quota_on(struct super_block *sb, int type, int format_id, 947 static int ext4_quota_on(struct super_block *sb, int type, int format_id,
948 char *path, int remount); 948 char *path, int remount);
949 static int ext4_quota_on_mount(struct super_block *sb, int type); 949 static int ext4_quota_on_mount(struct super_block *sb, int type);
950 static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, 950 static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
951 size_t len, loff_t off); 951 size_t len, loff_t off);
952 static ssize_t ext4_quota_write(struct super_block *sb, int type, 952 static ssize_t ext4_quota_write(struct super_block *sb, int type,
953 const char *data, size_t len, loff_t off); 953 const char *data, size_t len, loff_t off);
954 954
955 static struct dquot_operations ext4_quota_operations = { 955 static struct dquot_operations ext4_quota_operations = {
956 .initialize = dquot_initialize, 956 .initialize = dquot_initialize,
957 .drop = dquot_drop, 957 .drop = dquot_drop,
958 .alloc_space = dquot_alloc_space, 958 .alloc_space = dquot_alloc_space,
959 .reserve_space = dquot_reserve_space, 959 .reserve_space = dquot_reserve_space,
960 .claim_space = dquot_claim_space, 960 .claim_space = dquot_claim_space,
961 .release_rsv = dquot_release_reserved_space, 961 .release_rsv = dquot_release_reserved_space,
962 .get_reserved_space = ext4_get_reserved_space, 962 .get_reserved_space = ext4_get_reserved_space,
963 .alloc_inode = dquot_alloc_inode, 963 .alloc_inode = dquot_alloc_inode,
964 .free_space = dquot_free_space, 964 .free_space = dquot_free_space,
965 .free_inode = dquot_free_inode, 965 .free_inode = dquot_free_inode,
966 .transfer = dquot_transfer, 966 .transfer = dquot_transfer,
967 .write_dquot = ext4_write_dquot, 967 .write_dquot = ext4_write_dquot,
968 .acquire_dquot = ext4_acquire_dquot, 968 .acquire_dquot = ext4_acquire_dquot,
969 .release_dquot = ext4_release_dquot, 969 .release_dquot = ext4_release_dquot,
970 .mark_dirty = ext4_mark_dquot_dirty, 970 .mark_dirty = ext4_mark_dquot_dirty,
971 .write_info = ext4_write_info, 971 .write_info = ext4_write_info,
972 .alloc_dquot = dquot_alloc, 972 .alloc_dquot = dquot_alloc,
973 .destroy_dquot = dquot_destroy, 973 .destroy_dquot = dquot_destroy,
974 }; 974 };
975 975
976 static struct quotactl_ops ext4_qctl_operations = { 976 static struct quotactl_ops ext4_qctl_operations = {
977 .quota_on = ext4_quota_on, 977 .quota_on = ext4_quota_on,
978 .quota_off = vfs_quota_off, 978 .quota_off = vfs_quota_off,
979 .quota_sync = vfs_quota_sync, 979 .quota_sync = vfs_quota_sync,
980 .get_info = vfs_get_dqinfo, 980 .get_info = vfs_get_dqinfo,
981 .set_info = vfs_set_dqinfo, 981 .set_info = vfs_set_dqinfo,
982 .get_dqblk = vfs_get_dqblk, 982 .get_dqblk = vfs_get_dqblk,
983 .set_dqblk = vfs_set_dqblk 983 .set_dqblk = vfs_set_dqblk
984 }; 984 };
985 #endif 985 #endif
986 986
987 static const struct super_operations ext4_sops = { 987 static const struct super_operations ext4_sops = {
988 .alloc_inode = ext4_alloc_inode, 988 .alloc_inode = ext4_alloc_inode,
989 .destroy_inode = ext4_destroy_inode, 989 .destroy_inode = ext4_destroy_inode,
990 .write_inode = ext4_write_inode, 990 .write_inode = ext4_write_inode,
991 .dirty_inode = ext4_dirty_inode, 991 .dirty_inode = ext4_dirty_inode,
992 .delete_inode = ext4_delete_inode, 992 .delete_inode = ext4_delete_inode,
993 .put_super = ext4_put_super, 993 .put_super = ext4_put_super,
994 .write_super = ext4_write_super, 994 .write_super = ext4_write_super,
995 .sync_fs = ext4_sync_fs, 995 .sync_fs = ext4_sync_fs,
996 .freeze_fs = ext4_freeze, 996 .freeze_fs = ext4_freeze,
997 .unfreeze_fs = ext4_unfreeze, 997 .unfreeze_fs = ext4_unfreeze,
998 .statfs = ext4_statfs, 998 .statfs = ext4_statfs,
999 .remount_fs = ext4_remount, 999 .remount_fs = ext4_remount,
1000 .clear_inode = ext4_clear_inode, 1000 .clear_inode = ext4_clear_inode,
1001 .show_options = ext4_show_options, 1001 .show_options = ext4_show_options,
1002 #ifdef CONFIG_QUOTA 1002 #ifdef CONFIG_QUOTA
1003 .quota_read = ext4_quota_read, 1003 .quota_read = ext4_quota_read,
1004 .quota_write = ext4_quota_write, 1004 .quota_write = ext4_quota_write,
1005 #endif 1005 #endif
1006 .bdev_try_to_free_page = bdev_try_to_free_page, 1006 .bdev_try_to_free_page = bdev_try_to_free_page,
1007 }; 1007 };
1008 1008
1009 static const struct export_operations ext4_export_ops = { 1009 static const struct export_operations ext4_export_ops = {
1010 .fh_to_dentry = ext4_fh_to_dentry, 1010 .fh_to_dentry = ext4_fh_to_dentry,
1011 .fh_to_parent = ext4_fh_to_parent, 1011 .fh_to_parent = ext4_fh_to_parent,
1012 .get_parent = ext4_get_parent, 1012 .get_parent = ext4_get_parent,
1013 }; 1013 };
1014 1014
1015 enum { 1015 enum {
1016 Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid, 1016 Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid,
1017 Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro, 1017 Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro,
1018 Opt_nouid32, Opt_debug, Opt_oldalloc, Opt_orlov, 1018 Opt_nouid32, Opt_debug, Opt_oldalloc, Opt_orlov,
1019 Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, 1019 Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
1020 Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, Opt_bh, 1020 Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, Opt_bh,
1021 Opt_commit, Opt_min_batch_time, Opt_max_batch_time, 1021 Opt_commit, Opt_min_batch_time, Opt_max_batch_time,
1022 Opt_journal_update, Opt_journal_dev, 1022 Opt_journal_update, Opt_journal_dev,
1023 Opt_journal_checksum, Opt_journal_async_commit, 1023 Opt_journal_checksum, Opt_journal_async_commit,
1024 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, 1024 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
1025 Opt_data_err_abort, Opt_data_err_ignore, 1025 Opt_data_err_abort, Opt_data_err_ignore,
1026 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, 1026 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
1027 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, 1027 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
1028 Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota, 1028 Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
1029 Opt_grpquota, Opt_i_version, 1029 Opt_grpquota, Opt_i_version,
1030 Opt_stripe, Opt_delalloc, Opt_nodelalloc, 1030 Opt_stripe, Opt_delalloc, Opt_nodelalloc,
1031 Opt_inode_readahead_blks, Opt_journal_ioprio 1031 Opt_inode_readahead_blks, Opt_journal_ioprio
1032 }; 1032 };
1033 1033
1034 static const match_table_t tokens = { 1034 static const match_table_t tokens = {
1035 {Opt_bsd_df, "bsddf"}, 1035 {Opt_bsd_df, "bsddf"},
1036 {Opt_minix_df, "minixdf"}, 1036 {Opt_minix_df, "minixdf"},
1037 {Opt_grpid, "grpid"}, 1037 {Opt_grpid, "grpid"},
1038 {Opt_grpid, "bsdgroups"}, 1038 {Opt_grpid, "bsdgroups"},
1039 {Opt_nogrpid, "nogrpid"}, 1039 {Opt_nogrpid, "nogrpid"},
1040 {Opt_nogrpid, "sysvgroups"}, 1040 {Opt_nogrpid, "sysvgroups"},
1041 {Opt_resgid, "resgid=%u"}, 1041 {Opt_resgid, "resgid=%u"},
1042 {Opt_resuid, "resuid=%u"}, 1042 {Opt_resuid, "resuid=%u"},
1043 {Opt_sb, "sb=%u"}, 1043 {Opt_sb, "sb=%u"},
1044 {Opt_err_cont, "errors=continue"}, 1044 {Opt_err_cont, "errors=continue"},
1045 {Opt_err_panic, "errors=panic"}, 1045 {Opt_err_panic, "errors=panic"},
1046 {Opt_err_ro, "errors=remount-ro"}, 1046 {Opt_err_ro, "errors=remount-ro"},
1047 {Opt_nouid32, "nouid32"}, 1047 {Opt_nouid32, "nouid32"},
1048 {Opt_debug, "debug"}, 1048 {Opt_debug, "debug"},
1049 {Opt_oldalloc, "oldalloc"}, 1049 {Opt_oldalloc, "oldalloc"},
1050 {Opt_orlov, "orlov"}, 1050 {Opt_orlov, "orlov"},
1051 {Opt_user_xattr, "user_xattr"}, 1051 {Opt_user_xattr, "user_xattr"},
1052 {Opt_nouser_xattr, "nouser_xattr"}, 1052 {Opt_nouser_xattr, "nouser_xattr"},
1053 {Opt_acl, "acl"}, 1053 {Opt_acl, "acl"},
1054 {Opt_noacl, "noacl"}, 1054 {Opt_noacl, "noacl"},
1055 {Opt_reservation, "reservation"}, 1055 {Opt_reservation, "reservation"},
1056 {Opt_noreservation, "noreservation"}, 1056 {Opt_noreservation, "noreservation"},
1057 {Opt_noload, "noload"}, 1057 {Opt_noload, "noload"},
1058 {Opt_nobh, "nobh"}, 1058 {Opt_nobh, "nobh"},
1059 {Opt_bh, "bh"}, 1059 {Opt_bh, "bh"},
1060 {Opt_commit, "commit=%u"}, 1060 {Opt_commit, "commit=%u"},
1061 {Opt_min_batch_time, "min_batch_time=%u"}, 1061 {Opt_min_batch_time, "min_batch_time=%u"},
1062 {Opt_max_batch_time, "max_batch_time=%u"}, 1062 {Opt_max_batch_time, "max_batch_time=%u"},
1063 {Opt_journal_update, "journal=update"}, 1063 {Opt_journal_update, "journal=update"},
1064 {Opt_journal_dev, "journal_dev=%u"}, 1064 {Opt_journal_dev, "journal_dev=%u"},
1065 {Opt_journal_checksum, "journal_checksum"}, 1065 {Opt_journal_checksum, "journal_checksum"},
1066 {Opt_journal_async_commit, "journal_async_commit"}, 1066 {Opt_journal_async_commit, "journal_async_commit"},
1067 {Opt_abort, "abort"}, 1067 {Opt_abort, "abort"},
1068 {Opt_data_journal, "data=journal"}, 1068 {Opt_data_journal, "data=journal"},
1069 {Opt_data_ordered, "data=ordered"}, 1069 {Opt_data_ordered, "data=ordered"},
1070 {Opt_data_writeback, "data=writeback"}, 1070 {Opt_data_writeback, "data=writeback"},
1071 {Opt_data_err_abort, "data_err=abort"}, 1071 {Opt_data_err_abort, "data_err=abort"},
1072 {Opt_data_err_ignore, "data_err=ignore"}, 1072 {Opt_data_err_ignore, "data_err=ignore"},
1073 {Opt_offusrjquota, "usrjquota="}, 1073 {Opt_offusrjquota, "usrjquota="},
1074 {Opt_usrjquota, "usrjquota=%s"}, 1074 {Opt_usrjquota, "usrjquota=%s"},
1075 {Opt_offgrpjquota, "grpjquota="}, 1075 {Opt_offgrpjquota, "grpjquota="},
1076 {Opt_grpjquota, "grpjquota=%s"}, 1076 {Opt_grpjquota, "grpjquota=%s"},
1077 {Opt_jqfmt_vfsold, "jqfmt=vfsold"}, 1077 {Opt_jqfmt_vfsold, "jqfmt=vfsold"},
1078 {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, 1078 {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
1079 {Opt_grpquota, "grpquota"}, 1079 {Opt_grpquota, "grpquota"},
1080 {Opt_noquota, "noquota"}, 1080 {Opt_noquota, "noquota"},
1081 {Opt_quota, "quota"}, 1081 {Opt_quota, "quota"},
1082 {Opt_usrquota, "usrquota"}, 1082 {Opt_usrquota, "usrquota"},
1083 {Opt_barrier, "barrier=%u"}, 1083 {Opt_barrier, "barrier=%u"},
1084 {Opt_i_version, "i_version"}, 1084 {Opt_i_version, "i_version"},
1085 {Opt_stripe, "stripe=%u"}, 1085 {Opt_stripe, "stripe=%u"},
1086 {Opt_resize, "resize"}, 1086 {Opt_resize, "resize"},
1087 {Opt_delalloc, "delalloc"}, 1087 {Opt_delalloc, "delalloc"},
1088 {Opt_nodelalloc, "nodelalloc"}, 1088 {Opt_nodelalloc, "nodelalloc"},
1089 {Opt_inode_readahead_blks, "inode_readahead_blks=%u"}, 1089 {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
1090 {Opt_journal_ioprio, "journal_ioprio=%u"}, 1090 {Opt_journal_ioprio, "journal_ioprio=%u"},
1091 {Opt_err, NULL}, 1091 {Opt_err, NULL},
1092 }; 1092 };
1093 1093
1094 static ext4_fsblk_t get_sb_block(void **data) 1094 static ext4_fsblk_t get_sb_block(void **data)
1095 { 1095 {
1096 ext4_fsblk_t sb_block; 1096 ext4_fsblk_t sb_block;
1097 char *options = (char *) *data; 1097 char *options = (char *) *data;
1098 1098
1099 if (!options || strncmp(options, "sb=", 3) != 0) 1099 if (!options || strncmp(options, "sb=", 3) != 0)
1100 return 1; /* Default location */ 1100 return 1; /* Default location */
1101 options += 3; 1101 options += 3;
1102 /*todo: use simple_strtoll with >32bit ext4 */ 1102 /*todo: use simple_strtoll with >32bit ext4 */
1103 sb_block = simple_strtoul(options, &options, 0); 1103 sb_block = simple_strtoul(options, &options, 0);
1104 if (*options && *options != ',') { 1104 if (*options && *options != ',') {
1105 printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n", 1105 printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n",
1106 (char *) *data); 1106 (char *) *data);
1107 return 1; 1107 return 1;
1108 } 1108 }
1109 if (*options == ',') 1109 if (*options == ',')
1110 options++; 1110 options++;
1111 *data = (void *) options; 1111 *data = (void *) options;
1112 return sb_block; 1112 return sb_block;
1113 } 1113 }
1114 1114
1115 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3)) 1115 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
1116 1116
1117 static int parse_options(char *options, struct super_block *sb, 1117 static int parse_options(char *options, struct super_block *sb,
1118 unsigned long *journal_devnum, 1118 unsigned long *journal_devnum,
1119 unsigned int *journal_ioprio, 1119 unsigned int *journal_ioprio,
1120 ext4_fsblk_t *n_blocks_count, int is_remount) 1120 ext4_fsblk_t *n_blocks_count, int is_remount)
1121 { 1121 {
1122 struct ext4_sb_info *sbi = EXT4_SB(sb); 1122 struct ext4_sb_info *sbi = EXT4_SB(sb);
1123 char *p; 1123 char *p;
1124 substring_t args[MAX_OPT_ARGS]; 1124 substring_t args[MAX_OPT_ARGS];
1125 int data_opt = 0; 1125 int data_opt = 0;
1126 int option; 1126 int option;
1127 #ifdef CONFIG_QUOTA 1127 #ifdef CONFIG_QUOTA
1128 int qtype, qfmt; 1128 int qtype, qfmt;
1129 char *qname; 1129 char *qname;
1130 #endif 1130 #endif
1131 1131
1132 if (!options) 1132 if (!options)
1133 return 1; 1133 return 1;
1134 1134
1135 while ((p = strsep(&options, ",")) != NULL) { 1135 while ((p = strsep(&options, ",")) != NULL) {
1136 int token; 1136 int token;
1137 if (!*p) 1137 if (!*p)
1138 continue; 1138 continue;
1139 1139
1140 token = match_token(p, tokens, args); 1140 token = match_token(p, tokens, args);
1141 switch (token) { 1141 switch (token) {
1142 case Opt_bsd_df: 1142 case Opt_bsd_df:
1143 clear_opt(sbi->s_mount_opt, MINIX_DF); 1143 clear_opt(sbi->s_mount_opt, MINIX_DF);
1144 break; 1144 break;
1145 case Opt_minix_df: 1145 case Opt_minix_df:
1146 set_opt(sbi->s_mount_opt, MINIX_DF); 1146 set_opt(sbi->s_mount_opt, MINIX_DF);
1147 break; 1147 break;
1148 case Opt_grpid: 1148 case Opt_grpid:
1149 set_opt(sbi->s_mount_opt, GRPID); 1149 set_opt(sbi->s_mount_opt, GRPID);
1150 break; 1150 break;
1151 case Opt_nogrpid: 1151 case Opt_nogrpid:
1152 clear_opt(sbi->s_mount_opt, GRPID); 1152 clear_opt(sbi->s_mount_opt, GRPID);
1153 break; 1153 break;
1154 case Opt_resuid: 1154 case Opt_resuid:
1155 if (match_int(&args[0], &option)) 1155 if (match_int(&args[0], &option))
1156 return 0; 1156 return 0;
1157 sbi->s_resuid = option; 1157 sbi->s_resuid = option;
1158 break; 1158 break;
1159 case Opt_resgid: 1159 case Opt_resgid:
1160 if (match_int(&args[0], &option)) 1160 if (match_int(&args[0], &option))
1161 return 0; 1161 return 0;
1162 sbi->s_resgid = option; 1162 sbi->s_resgid = option;
1163 break; 1163 break;
1164 case Opt_sb: 1164 case Opt_sb:
1165 /* handled by get_sb_block() instead of here */ 1165 /* handled by get_sb_block() instead of here */
1166 /* *sb_block = match_int(&args[0]); */ 1166 /* *sb_block = match_int(&args[0]); */
1167 break; 1167 break;
1168 case Opt_err_panic: 1168 case Opt_err_panic:
1169 clear_opt(sbi->s_mount_opt, ERRORS_CONT); 1169 clear_opt(sbi->s_mount_opt, ERRORS_CONT);
1170 clear_opt(sbi->s_mount_opt, ERRORS_RO); 1170 clear_opt(sbi->s_mount_opt, ERRORS_RO);
1171 set_opt(sbi->s_mount_opt, ERRORS_PANIC); 1171 set_opt(sbi->s_mount_opt, ERRORS_PANIC);
1172 break; 1172 break;
1173 case Opt_err_ro: 1173 case Opt_err_ro:
1174 clear_opt(sbi->s_mount_opt, ERRORS_CONT); 1174 clear_opt(sbi->s_mount_opt, ERRORS_CONT);
1175 clear_opt(sbi->s_mount_opt, ERRORS_PANIC); 1175 clear_opt(sbi->s_mount_opt, ERRORS_PANIC);
1176 set_opt(sbi->s_mount_opt, ERRORS_RO); 1176 set_opt(sbi->s_mount_opt, ERRORS_RO);
1177 break; 1177 break;
1178 case Opt_err_cont: 1178 case Opt_err_cont:
1179 clear_opt(sbi->s_mount_opt, ERRORS_RO); 1179 clear_opt(sbi->s_mount_opt, ERRORS_RO);
1180 clear_opt(sbi->s_mount_opt, ERRORS_PANIC); 1180 clear_opt(sbi->s_mount_opt, ERRORS_PANIC);
1181 set_opt(sbi->s_mount_opt, ERRORS_CONT); 1181 set_opt(sbi->s_mount_opt, ERRORS_CONT);
1182 break; 1182 break;
1183 case Opt_nouid32: 1183 case Opt_nouid32:
1184 set_opt(sbi->s_mount_opt, NO_UID32); 1184 set_opt(sbi->s_mount_opt, NO_UID32);
1185 break; 1185 break;
1186 case Opt_debug: 1186 case Opt_debug:
1187 set_opt(sbi->s_mount_opt, DEBUG); 1187 set_opt(sbi->s_mount_opt, DEBUG);
1188 break; 1188 break;
1189 case Opt_oldalloc: 1189 case Opt_oldalloc:
1190 set_opt(sbi->s_mount_opt, OLDALLOC); 1190 set_opt(sbi->s_mount_opt, OLDALLOC);
1191 break; 1191 break;
1192 case Opt_orlov: 1192 case Opt_orlov:
1193 clear_opt(sbi->s_mount_opt, OLDALLOC); 1193 clear_opt(sbi->s_mount_opt, OLDALLOC);
1194 break; 1194 break;
1195 #ifdef CONFIG_EXT4_FS_XATTR 1195 #ifdef CONFIG_EXT4_FS_XATTR
1196 case Opt_user_xattr: 1196 case Opt_user_xattr:
1197 set_opt(sbi->s_mount_opt, XATTR_USER); 1197 set_opt(sbi->s_mount_opt, XATTR_USER);
1198 break; 1198 break;
1199 case Opt_nouser_xattr: 1199 case Opt_nouser_xattr:
1200 clear_opt(sbi->s_mount_opt, XATTR_USER); 1200 clear_opt(sbi->s_mount_opt, XATTR_USER);
1201 break; 1201 break;
1202 #else 1202 #else
1203 case Opt_user_xattr: 1203 case Opt_user_xattr:
1204 case Opt_nouser_xattr: 1204 case Opt_nouser_xattr:
1205 printk(KERN_ERR "EXT4 (no)user_xattr options " 1205 printk(KERN_ERR "EXT4 (no)user_xattr options "
1206 "not supported\n"); 1206 "not supported\n");
1207 break; 1207 break;
1208 #endif 1208 #endif
1209 #ifdef CONFIG_EXT4_FS_POSIX_ACL 1209 #ifdef CONFIG_EXT4_FS_POSIX_ACL
1210 case Opt_acl: 1210 case Opt_acl:
1211 set_opt(sbi->s_mount_opt, POSIX_ACL); 1211 set_opt(sbi->s_mount_opt, POSIX_ACL);
1212 break; 1212 break;
1213 case Opt_noacl: 1213 case Opt_noacl:
1214 clear_opt(sbi->s_mount_opt, POSIX_ACL); 1214 clear_opt(sbi->s_mount_opt, POSIX_ACL);
1215 break; 1215 break;
1216 #else 1216 #else
1217 case Opt_acl: 1217 case Opt_acl:
1218 case Opt_noacl: 1218 case Opt_noacl:
1219 printk(KERN_ERR "EXT4 (no)acl options " 1219 printk(KERN_ERR "EXT4 (no)acl options "
1220 "not supported\n"); 1220 "not supported\n");
1221 break; 1221 break;
1222 #endif 1222 #endif
1223 case Opt_reservation: 1223 case Opt_reservation:
1224 set_opt(sbi->s_mount_opt, RESERVATION); 1224 set_opt(sbi->s_mount_opt, RESERVATION);
1225 break; 1225 break;
1226 case Opt_noreservation: 1226 case Opt_noreservation:
1227 clear_opt(sbi->s_mount_opt, RESERVATION); 1227 clear_opt(sbi->s_mount_opt, RESERVATION);
1228 break; 1228 break;
1229 case Opt_journal_update: 1229 case Opt_journal_update:
1230 /* @@@ FIXME */ 1230 /* @@@ FIXME */
1231 /* Eventually we will want to be able to create 1231 /* Eventually we will want to be able to create
1232 a journal file here. For now, only allow the 1232 a journal file here. For now, only allow the
1233 user to specify an existing inode to be the 1233 user to specify an existing inode to be the
1234 journal file. */ 1234 journal file. */
1235 if (is_remount) { 1235 if (is_remount) {
1236 printk(KERN_ERR "EXT4-fs: cannot specify " 1236 printk(KERN_ERR "EXT4-fs: cannot specify "
1237 "journal on remount\n"); 1237 "journal on remount\n");
1238 return 0; 1238 return 0;
1239 } 1239 }
1240 set_opt(sbi->s_mount_opt, UPDATE_JOURNAL); 1240 set_opt(sbi->s_mount_opt, UPDATE_JOURNAL);
1241 break; 1241 break;
1242 case Opt_journal_dev: 1242 case Opt_journal_dev:
1243 if (is_remount) { 1243 if (is_remount) {
1244 printk(KERN_ERR "EXT4-fs: cannot specify " 1244 printk(KERN_ERR "EXT4-fs: cannot specify "
1245 "journal on remount\n"); 1245 "journal on remount\n");
1246 return 0; 1246 return 0;
1247 } 1247 }
1248 if (match_int(&args[0], &option)) 1248 if (match_int(&args[0], &option))
1249 return 0; 1249 return 0;
1250 *journal_devnum = option; 1250 *journal_devnum = option;
1251 break; 1251 break;
1252 case Opt_journal_checksum: 1252 case Opt_journal_checksum:
1253 set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM); 1253 set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM);
1254 break; 1254 break;
1255 case Opt_journal_async_commit: 1255 case Opt_journal_async_commit:
1256 set_opt(sbi->s_mount_opt, JOURNAL_ASYNC_COMMIT); 1256 set_opt(sbi->s_mount_opt, JOURNAL_ASYNC_COMMIT);
1257 set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM); 1257 set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM);
1258 break; 1258 break;
1259 case Opt_noload: 1259 case Opt_noload:
1260 set_opt(sbi->s_mount_opt, NOLOAD); 1260 set_opt(sbi->s_mount_opt, NOLOAD);
1261 break; 1261 break;
1262 case Opt_commit: 1262 case Opt_commit:
1263 if (match_int(&args[0], &option)) 1263 if (match_int(&args[0], &option))
1264 return 0; 1264 return 0;
1265 if (option < 0) 1265 if (option < 0)
1266 return 0; 1266 return 0;
1267 if (option == 0) 1267 if (option == 0)
1268 option = JBD2_DEFAULT_MAX_COMMIT_AGE; 1268 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
1269 sbi->s_commit_interval = HZ * option; 1269 sbi->s_commit_interval = HZ * option;
1270 break; 1270 break;
1271 case Opt_max_batch_time: 1271 case Opt_max_batch_time:
1272 if (match_int(&args[0], &option)) 1272 if (match_int(&args[0], &option))
1273 return 0; 1273 return 0;
1274 if (option < 0) 1274 if (option < 0)
1275 return 0; 1275 return 0;
1276 if (option == 0) 1276 if (option == 0)
1277 option = EXT4_DEF_MAX_BATCH_TIME; 1277 option = EXT4_DEF_MAX_BATCH_TIME;
1278 sbi->s_max_batch_time = option; 1278 sbi->s_max_batch_time = option;
1279 break; 1279 break;
1280 case Opt_min_batch_time: 1280 case Opt_min_batch_time:
1281 if (match_int(&args[0], &option)) 1281 if (match_int(&args[0], &option))
1282 return 0; 1282 return 0;
1283 if (option < 0) 1283 if (option < 0)
1284 return 0; 1284 return 0;
1285 sbi->s_min_batch_time = option; 1285 sbi->s_min_batch_time = option;
1286 break; 1286 break;
1287 case Opt_data_journal: 1287 case Opt_data_journal:
1288 data_opt = EXT4_MOUNT_JOURNAL_DATA; 1288 data_opt = EXT4_MOUNT_JOURNAL_DATA;
1289 goto datacheck; 1289 goto datacheck;
1290 case Opt_data_ordered: 1290 case Opt_data_ordered:
1291 data_opt = EXT4_MOUNT_ORDERED_DATA; 1291 data_opt = EXT4_MOUNT_ORDERED_DATA;
1292 goto datacheck; 1292 goto datacheck;
1293 case Opt_data_writeback: 1293 case Opt_data_writeback:
1294 data_opt = EXT4_MOUNT_WRITEBACK_DATA; 1294 data_opt = EXT4_MOUNT_WRITEBACK_DATA;
1295 datacheck: 1295 datacheck:
1296 if (is_remount) { 1296 if (is_remount) {
1297 if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS) 1297 if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS)
1298 != data_opt) { 1298 != data_opt) {
1299 printk(KERN_ERR 1299 printk(KERN_ERR
1300 "EXT4-fs: cannot change data " 1300 "EXT4-fs: cannot change data "
1301 "mode on remount\n"); 1301 "mode on remount\n");
1302 return 0; 1302 return 0;
1303 } 1303 }
1304 } else { 1304 } else {
1305 sbi->s_mount_opt &= ~EXT4_MOUNT_DATA_FLAGS; 1305 sbi->s_mount_opt &= ~EXT4_MOUNT_DATA_FLAGS;
1306 sbi->s_mount_opt |= data_opt; 1306 sbi->s_mount_opt |= data_opt;
1307 } 1307 }
1308 break; 1308 break;
1309 case Opt_data_err_abort: 1309 case Opt_data_err_abort:
1310 set_opt(sbi->s_mount_opt, DATA_ERR_ABORT); 1310 set_opt(sbi->s_mount_opt, DATA_ERR_ABORT);
1311 break; 1311 break;
1312 case Opt_data_err_ignore: 1312 case Opt_data_err_ignore:
1313 clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT); 1313 clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT);
1314 break; 1314 break;
1315 #ifdef CONFIG_QUOTA 1315 #ifdef CONFIG_QUOTA
1316 case Opt_usrjquota: 1316 case Opt_usrjquota:
1317 qtype = USRQUOTA; 1317 qtype = USRQUOTA;
1318 goto set_qf_name; 1318 goto set_qf_name;
1319 case Opt_grpjquota: 1319 case Opt_grpjquota:
1320 qtype = GRPQUOTA; 1320 qtype = GRPQUOTA;
1321 set_qf_name: 1321 set_qf_name:
1322 if (sb_any_quota_loaded(sb) && 1322 if (sb_any_quota_loaded(sb) &&
1323 !sbi->s_qf_names[qtype]) { 1323 !sbi->s_qf_names[qtype]) {
1324 printk(KERN_ERR 1324 printk(KERN_ERR
1325 "EXT4-fs: Cannot change journaled " 1325 "EXT4-fs: Cannot change journaled "
1326 "quota options when quota turned on.\n"); 1326 "quota options when quota turned on.\n");
1327 return 0; 1327 return 0;
1328 } 1328 }
1329 qname = match_strdup(&args[0]); 1329 qname = match_strdup(&args[0]);
1330 if (!qname) { 1330 if (!qname) {
1331 printk(KERN_ERR 1331 printk(KERN_ERR
1332 "EXT4-fs: not enough memory for " 1332 "EXT4-fs: not enough memory for "
1333 "storing quotafile name.\n"); 1333 "storing quotafile name.\n");
1334 return 0; 1334 return 0;
1335 } 1335 }
1336 if (sbi->s_qf_names[qtype] && 1336 if (sbi->s_qf_names[qtype] &&
1337 strcmp(sbi->s_qf_names[qtype], qname)) { 1337 strcmp(sbi->s_qf_names[qtype], qname)) {
1338 printk(KERN_ERR 1338 printk(KERN_ERR
1339 "EXT4-fs: %s quota file already " 1339 "EXT4-fs: %s quota file already "
1340 "specified.\n", QTYPE2NAME(qtype)); 1340 "specified.\n", QTYPE2NAME(qtype));
1341 kfree(qname); 1341 kfree(qname);
1342 return 0; 1342 return 0;
1343 } 1343 }
1344 sbi->s_qf_names[qtype] = qname; 1344 sbi->s_qf_names[qtype] = qname;
1345 if (strchr(sbi->s_qf_names[qtype], '/')) { 1345 if (strchr(sbi->s_qf_names[qtype], '/')) {
1346 printk(KERN_ERR 1346 printk(KERN_ERR
1347 "EXT4-fs: quotafile must be on " 1347 "EXT4-fs: quotafile must be on "
1348 "filesystem root.\n"); 1348 "filesystem root.\n");
1349 kfree(sbi->s_qf_names[qtype]); 1349 kfree(sbi->s_qf_names[qtype]);
1350 sbi->s_qf_names[qtype] = NULL; 1350 sbi->s_qf_names[qtype] = NULL;
1351 return 0; 1351 return 0;
1352 } 1352 }
1353 set_opt(sbi->s_mount_opt, QUOTA); 1353 set_opt(sbi->s_mount_opt, QUOTA);
1354 break; 1354 break;
1355 case Opt_offusrjquota: 1355 case Opt_offusrjquota:
1356 qtype = USRQUOTA; 1356 qtype = USRQUOTA;
1357 goto clear_qf_name; 1357 goto clear_qf_name;
1358 case Opt_offgrpjquota: 1358 case Opt_offgrpjquota:
1359 qtype = GRPQUOTA; 1359 qtype = GRPQUOTA;
1360 clear_qf_name: 1360 clear_qf_name:
1361 if (sb_any_quota_loaded(sb) && 1361 if (sb_any_quota_loaded(sb) &&
1362 sbi->s_qf_names[qtype]) { 1362 sbi->s_qf_names[qtype]) {
1363 printk(KERN_ERR "EXT4-fs: Cannot change " 1363 printk(KERN_ERR "EXT4-fs: Cannot change "
1364 "journaled quota options when " 1364 "journaled quota options when "
1365 "quota turned on.\n"); 1365 "quota turned on.\n");
1366 return 0; 1366 return 0;
1367 } 1367 }
1368 /* 1368 /*
1369 * The space will be released later when all options 1369 * The space will be released later when all options
1370 * are confirmed to be correct 1370 * are confirmed to be correct
1371 */ 1371 */
1372 sbi->s_qf_names[qtype] = NULL; 1372 sbi->s_qf_names[qtype] = NULL;
1373 break; 1373 break;
1374 case Opt_jqfmt_vfsold: 1374 case Opt_jqfmt_vfsold:
1375 qfmt = QFMT_VFS_OLD; 1375 qfmt = QFMT_VFS_OLD;
1376 goto set_qf_format; 1376 goto set_qf_format;
1377 case Opt_jqfmt_vfsv0: 1377 case Opt_jqfmt_vfsv0:
1378 qfmt = QFMT_VFS_V0; 1378 qfmt = QFMT_VFS_V0;
1379 set_qf_format: 1379 set_qf_format:
1380 if (sb_any_quota_loaded(sb) && 1380 if (sb_any_quota_loaded(sb) &&
1381 sbi->s_jquota_fmt != qfmt) { 1381 sbi->s_jquota_fmt != qfmt) {
1382 printk(KERN_ERR "EXT4-fs: Cannot change " 1382 printk(KERN_ERR "EXT4-fs: Cannot change "
1383 "journaled quota options when " 1383 "journaled quota options when "
1384 "quota turned on.\n"); 1384 "quota turned on.\n");
1385 return 0; 1385 return 0;
1386 } 1386 }
1387 sbi->s_jquota_fmt = qfmt; 1387 sbi->s_jquota_fmt = qfmt;
1388 break; 1388 break;
1389 case Opt_quota: 1389 case Opt_quota:
1390 case Opt_usrquota: 1390 case Opt_usrquota:
1391 set_opt(sbi->s_mount_opt, QUOTA); 1391 set_opt(sbi->s_mount_opt, QUOTA);
1392 set_opt(sbi->s_mount_opt, USRQUOTA); 1392 set_opt(sbi->s_mount_opt, USRQUOTA);
1393 break; 1393 break;
1394 case Opt_grpquota: 1394 case Opt_grpquota:
1395 set_opt(sbi->s_mount_opt, QUOTA); 1395 set_opt(sbi->s_mount_opt, QUOTA);
1396 set_opt(sbi->s_mount_opt, GRPQUOTA); 1396 set_opt(sbi->s_mount_opt, GRPQUOTA);
1397 break; 1397 break;
1398 case Opt_noquota: 1398 case Opt_noquota:
1399 if (sb_any_quota_loaded(sb)) { 1399 if (sb_any_quota_loaded(sb)) {
1400 printk(KERN_ERR "EXT4-fs: Cannot change quota " 1400 printk(KERN_ERR "EXT4-fs: Cannot change quota "
1401 "options when quota turned on.\n"); 1401 "options when quota turned on.\n");
1402 return 0; 1402 return 0;
1403 } 1403 }
1404 clear_opt(sbi->s_mount_opt, QUOTA); 1404 clear_opt(sbi->s_mount_opt, QUOTA);
1405 clear_opt(sbi->s_mount_opt, USRQUOTA); 1405 clear_opt(sbi->s_mount_opt, USRQUOTA);
1406 clear_opt(sbi->s_mount_opt, GRPQUOTA); 1406 clear_opt(sbi->s_mount_opt, GRPQUOTA);
1407 break; 1407 break;
1408 #else 1408 #else
1409 case Opt_quota: 1409 case Opt_quota:
1410 case Opt_usrquota: 1410 case Opt_usrquota:
1411 case Opt_grpquota: 1411 case Opt_grpquota:
1412 printk(KERN_ERR 1412 printk(KERN_ERR
1413 "EXT4-fs: quota options not supported.\n"); 1413 "EXT4-fs: quota options not supported.\n");
1414 break; 1414 break;
1415 case Opt_usrjquota: 1415 case Opt_usrjquota:
1416 case Opt_grpjquota: 1416 case Opt_grpjquota:
1417 case Opt_offusrjquota: 1417 case Opt_offusrjquota:
1418 case Opt_offgrpjquota: 1418 case Opt_offgrpjquota:
1419 case Opt_jqfmt_vfsold: 1419 case Opt_jqfmt_vfsold:
1420 case Opt_jqfmt_vfsv0: 1420 case Opt_jqfmt_vfsv0:
1421 printk(KERN_ERR 1421 printk(KERN_ERR
1422 "EXT4-fs: journaled quota options not " 1422 "EXT4-fs: journaled quota options not "
1423 "supported.\n"); 1423 "supported.\n");
1424 break; 1424 break;
1425 case Opt_noquota: 1425 case Opt_noquota:
1426 break; 1426 break;
1427 #endif 1427 #endif
1428 case Opt_abort: 1428 case Opt_abort:
1429 set_opt(sbi->s_mount_opt, ABORT); 1429 set_opt(sbi->s_mount_opt, ABORT);
1430 break; 1430 break;
1431 case Opt_barrier: 1431 case Opt_barrier:
1432 if (match_int(&args[0], &option)) 1432 if (match_int(&args[0], &option))
1433 return 0; 1433 return 0;
1434 if (option) 1434 if (option)
1435 set_opt(sbi->s_mount_opt, BARRIER); 1435 set_opt(sbi->s_mount_opt, BARRIER);
1436 else 1436 else
1437 clear_opt(sbi->s_mount_opt, BARRIER); 1437 clear_opt(sbi->s_mount_opt, BARRIER);
1438 break; 1438 break;
1439 case Opt_ignore: 1439 case Opt_ignore:
1440 break; 1440 break;
1441 case Opt_resize: 1441 case Opt_resize:
1442 if (!is_remount) { 1442 if (!is_remount) {
1443 printk("EXT4-fs: resize option only available " 1443 printk("EXT4-fs: resize option only available "
1444 "for remount\n"); 1444 "for remount\n");
1445 return 0; 1445 return 0;
1446 } 1446 }
1447 if (match_int(&args[0], &option) != 0) 1447 if (match_int(&args[0], &option) != 0)
1448 return 0; 1448 return 0;
1449 *n_blocks_count = option; 1449 *n_blocks_count = option;
1450 break; 1450 break;
1451 case Opt_nobh: 1451 case Opt_nobh:
1452 set_opt(sbi->s_mount_opt, NOBH); 1452 set_opt(sbi->s_mount_opt, NOBH);
1453 break; 1453 break;
1454 case Opt_bh: 1454 case Opt_bh:
1455 clear_opt(sbi->s_mount_opt, NOBH); 1455 clear_opt(sbi->s_mount_opt, NOBH);
1456 break; 1456 break;
1457 case Opt_i_version: 1457 case Opt_i_version:
1458 set_opt(sbi->s_mount_opt, I_VERSION); 1458 set_opt(sbi->s_mount_opt, I_VERSION);
1459 sb->s_flags |= MS_I_VERSION; 1459 sb->s_flags |= MS_I_VERSION;
1460 break; 1460 break;
1461 case Opt_nodelalloc: 1461 case Opt_nodelalloc:
1462 clear_opt(sbi->s_mount_opt, DELALLOC); 1462 clear_opt(sbi->s_mount_opt, DELALLOC);
1463 break; 1463 break;
1464 case Opt_stripe: 1464 case Opt_stripe:
1465 if (match_int(&args[0], &option)) 1465 if (match_int(&args[0], &option))
1466 return 0; 1466 return 0;
1467 if (option < 0) 1467 if (option < 0)
1468 return 0; 1468 return 0;
1469 sbi->s_stripe = option; 1469 sbi->s_stripe = option;
1470 break; 1470 break;
1471 case Opt_delalloc: 1471 case Opt_delalloc:
1472 set_opt(sbi->s_mount_opt, DELALLOC); 1472 set_opt(sbi->s_mount_opt, DELALLOC);
1473 break; 1473 break;
1474 case Opt_inode_readahead_blks: 1474 case Opt_inode_readahead_blks:
1475 if (match_int(&args[0], &option)) 1475 if (match_int(&args[0], &option))
1476 return 0; 1476 return 0;
1477 if (option < 0 || option > (1 << 30)) 1477 if (option < 0 || option > (1 << 30))
1478 return 0; 1478 return 0;
1479 if (option & (option - 1)) { 1479 if (option & (option - 1)) {
1480 printk(KERN_ERR "EXT4-fs: inode_readahead_blks" 1480 printk(KERN_ERR "EXT4-fs: inode_readahead_blks"
1481 " must be a power of 2\n"); 1481 " must be a power of 2\n");
1482 return 0; 1482 return 0;
1483 } 1483 }
1484 sbi->s_inode_readahead_blks = option; 1484 sbi->s_inode_readahead_blks = option;
1485 break; 1485 break;
1486 case Opt_journal_ioprio: 1486 case Opt_journal_ioprio:
1487 if (match_int(&args[0], &option)) 1487 if (match_int(&args[0], &option))
1488 return 0; 1488 return 0;
1489 if (option < 0 || option > 7) 1489 if (option < 0 || option > 7)
1490 break; 1490 break;
1491 *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 1491 *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE,
1492 option); 1492 option);
1493 break; 1493 break;
1494 default: 1494 default:
1495 printk(KERN_ERR 1495 printk(KERN_ERR
1496 "EXT4-fs: Unrecognized mount option \"%s\" " 1496 "EXT4-fs: Unrecognized mount option \"%s\" "
1497 "or missing value\n", p); 1497 "or missing value\n", p);
1498 return 0; 1498 return 0;
1499 } 1499 }
1500 } 1500 }
1501 #ifdef CONFIG_QUOTA 1501 #ifdef CONFIG_QUOTA
1502 if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { 1502 if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
1503 if ((sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA) && 1503 if ((sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA) &&
1504 sbi->s_qf_names[USRQUOTA]) 1504 sbi->s_qf_names[USRQUOTA])
1505 clear_opt(sbi->s_mount_opt, USRQUOTA); 1505 clear_opt(sbi->s_mount_opt, USRQUOTA);
1506 1506
1507 if ((sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA) && 1507 if ((sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA) &&
1508 sbi->s_qf_names[GRPQUOTA]) 1508 sbi->s_qf_names[GRPQUOTA])
1509 clear_opt(sbi->s_mount_opt, GRPQUOTA); 1509 clear_opt(sbi->s_mount_opt, GRPQUOTA);
1510 1510
1511 if ((sbi->s_qf_names[USRQUOTA] && 1511 if ((sbi->s_qf_names[USRQUOTA] &&
1512 (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) || 1512 (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) ||
1513 (sbi->s_qf_names[GRPQUOTA] && 1513 (sbi->s_qf_names[GRPQUOTA] &&
1514 (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) { 1514 (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) {
1515 printk(KERN_ERR "EXT4-fs: old and new quota " 1515 printk(KERN_ERR "EXT4-fs: old and new quota "
1516 "format mixing.\n"); 1516 "format mixing.\n");
1517 return 0; 1517 return 0;
1518 } 1518 }
1519 1519
1520 if (!sbi->s_jquota_fmt) { 1520 if (!sbi->s_jquota_fmt) {
1521 printk(KERN_ERR "EXT4-fs: journaled quota format " 1521 printk(KERN_ERR "EXT4-fs: journaled quota format "
1522 "not specified.\n"); 1522 "not specified.\n");
1523 return 0; 1523 return 0;
1524 } 1524 }
1525 } else { 1525 } else {
1526 if (sbi->s_jquota_fmt) { 1526 if (sbi->s_jquota_fmt) {
1527 printk(KERN_ERR "EXT4-fs: journaled quota format " 1527 printk(KERN_ERR "EXT4-fs: journaled quota format "
1528 "specified with no journaling " 1528 "specified with no journaling "
1529 "enabled.\n"); 1529 "enabled.\n");
1530 return 0; 1530 return 0;
1531 } 1531 }
1532 } 1532 }
1533 #endif 1533 #endif
1534 return 1; 1534 return 1;
1535 } 1535 }
1536 1536
1537 static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, 1537 static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
1538 int read_only) 1538 int read_only)
1539 { 1539 {
1540 struct ext4_sb_info *sbi = EXT4_SB(sb); 1540 struct ext4_sb_info *sbi = EXT4_SB(sb);
1541 int res = 0; 1541 int res = 0;
1542 1542
1543 if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) { 1543 if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
1544 printk(KERN_ERR "EXT4-fs warning: revision level too high, " 1544 printk(KERN_ERR "EXT4-fs warning: revision level too high, "
1545 "forcing read-only mode\n"); 1545 "forcing read-only mode\n");
1546 res = MS_RDONLY; 1546 res = MS_RDONLY;
1547 } 1547 }
1548 if (read_only) 1548 if (read_only)
1549 return res; 1549 return res;
1550 if (!(sbi->s_mount_state & EXT4_VALID_FS)) 1550 if (!(sbi->s_mount_state & EXT4_VALID_FS))
1551 printk(KERN_WARNING "EXT4-fs warning: mounting unchecked fs, " 1551 printk(KERN_WARNING "EXT4-fs warning: mounting unchecked fs, "
1552 "running e2fsck is recommended\n"); 1552 "running e2fsck is recommended\n");
1553 else if ((sbi->s_mount_state & EXT4_ERROR_FS)) 1553 else if ((sbi->s_mount_state & EXT4_ERROR_FS))
1554 printk(KERN_WARNING 1554 printk(KERN_WARNING
1555 "EXT4-fs warning: mounting fs with errors, " 1555 "EXT4-fs warning: mounting fs with errors, "
1556 "running e2fsck is recommended\n"); 1556 "running e2fsck is recommended\n");
1557 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 && 1557 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
1558 le16_to_cpu(es->s_mnt_count) >= 1558 le16_to_cpu(es->s_mnt_count) >=
1559 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count)) 1559 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
1560 printk(KERN_WARNING 1560 printk(KERN_WARNING
1561 "EXT4-fs warning: maximal mount count reached, " 1561 "EXT4-fs warning: maximal mount count reached, "
1562 "running e2fsck is recommended\n"); 1562 "running e2fsck is recommended\n");
1563 else if (le32_to_cpu(es->s_checkinterval) && 1563 else if (le32_to_cpu(es->s_checkinterval) &&
1564 (le32_to_cpu(es->s_lastcheck) + 1564 (le32_to_cpu(es->s_lastcheck) +
1565 le32_to_cpu(es->s_checkinterval) <= get_seconds())) 1565 le32_to_cpu(es->s_checkinterval) <= get_seconds()))
1566 printk(KERN_WARNING 1566 printk(KERN_WARNING
1567 "EXT4-fs warning: checktime reached, " 1567 "EXT4-fs warning: checktime reached, "
1568 "running e2fsck is recommended\n"); 1568 "running e2fsck is recommended\n");
1569 if (!sbi->s_journal) 1569 if (!sbi->s_journal)
1570 es->s_state &= cpu_to_le16(~EXT4_VALID_FS); 1570 es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
1571 if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) 1571 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
1572 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); 1572 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
1573 le16_add_cpu(&es->s_mnt_count, 1); 1573 le16_add_cpu(&es->s_mnt_count, 1);
1574 es->s_mtime = cpu_to_le32(get_seconds()); 1574 es->s_mtime = cpu_to_le32(get_seconds());
1575 ext4_update_dynamic_rev(sb); 1575 ext4_update_dynamic_rev(sb);
1576 if (sbi->s_journal) 1576 if (sbi->s_journal)
1577 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 1577 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
1578 1578
1579 ext4_commit_super(sb, es, 1); 1579 ext4_commit_super(sb, es, 1);
1580 if (test_opt(sb, DEBUG)) 1580 if (test_opt(sb, DEBUG))
1581 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, " 1581 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
1582 "bpg=%lu, ipg=%lu, mo=%04lx]\n", 1582 "bpg=%lu, ipg=%lu, mo=%04lx]\n",
1583 sb->s_blocksize, 1583 sb->s_blocksize,
1584 sbi->s_groups_count, 1584 sbi->s_groups_count,
1585 EXT4_BLOCKS_PER_GROUP(sb), 1585 EXT4_BLOCKS_PER_GROUP(sb),
1586 EXT4_INODES_PER_GROUP(sb), 1586 EXT4_INODES_PER_GROUP(sb),
1587 sbi->s_mount_opt); 1587 sbi->s_mount_opt);
1588 1588
1589 if (EXT4_SB(sb)->s_journal) { 1589 if (EXT4_SB(sb)->s_journal) {
1590 printk(KERN_INFO "EXT4 FS on %s, %s journal on %s\n", 1590 printk(KERN_INFO "EXT4 FS on %s, %s journal on %s\n",
1591 sb->s_id, EXT4_SB(sb)->s_journal->j_inode ? "internal" : 1591 sb->s_id, EXT4_SB(sb)->s_journal->j_inode ? "internal" :
1592 "external", EXT4_SB(sb)->s_journal->j_devname); 1592 "external", EXT4_SB(sb)->s_journal->j_devname);
1593 } else { 1593 } else {
1594 printk(KERN_INFO "EXT4 FS on %s, no journal\n", sb->s_id); 1594 printk(KERN_INFO "EXT4 FS on %s, no journal\n", sb->s_id);
1595 } 1595 }
1596 return res; 1596 return res;
1597 } 1597 }
1598 1598
1599 static int ext4_fill_flex_info(struct super_block *sb) 1599 static int ext4_fill_flex_info(struct super_block *sb)
1600 { 1600 {
1601 struct ext4_sb_info *sbi = EXT4_SB(sb); 1601 struct ext4_sb_info *sbi = EXT4_SB(sb);
1602 struct ext4_group_desc *gdp = NULL; 1602 struct ext4_group_desc *gdp = NULL;
1603 struct buffer_head *bh; 1603 struct buffer_head *bh;
1604 ext4_group_t flex_group_count; 1604 ext4_group_t flex_group_count;
1605 ext4_group_t flex_group; 1605 ext4_group_t flex_group;
1606 int groups_per_flex = 0; 1606 int groups_per_flex = 0;
1607 int i; 1607 int i;
1608 1608
1609 if (!sbi->s_es->s_log_groups_per_flex) { 1609 if (!sbi->s_es->s_log_groups_per_flex) {
1610 sbi->s_log_groups_per_flex = 0; 1610 sbi->s_log_groups_per_flex = 0;
1611 return 1; 1611 return 1;
1612 } 1612 }
1613 1613
1614 sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex; 1614 sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
1615 groups_per_flex = 1 << sbi->s_log_groups_per_flex; 1615 groups_per_flex = 1 << sbi->s_log_groups_per_flex;
1616 1616
1617 /* We allocate both existing and potentially added groups */ 1617 /* We allocate both existing and potentially added groups */
1618 flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) + 1618 flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +
1619 ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) << 1619 ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<
1620 EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex; 1620 EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex;
1621 sbi->s_flex_groups = kzalloc(flex_group_count * 1621 sbi->s_flex_groups = kzalloc(flex_group_count *
1622 sizeof(struct flex_groups), GFP_KERNEL); 1622 sizeof(struct flex_groups), GFP_KERNEL);
1623 if (sbi->s_flex_groups == NULL) { 1623 if (sbi->s_flex_groups == NULL) {
1624 printk(KERN_ERR "EXT4-fs: not enough memory for " 1624 printk(KERN_ERR "EXT4-fs: not enough memory for "
1625 "%u flex groups\n", flex_group_count); 1625 "%u flex groups\n", flex_group_count);
1626 goto failed; 1626 goto failed;
1627 } 1627 }
1628 1628
1629 for (i = 0; i < sbi->s_groups_count; i++) { 1629 for (i = 0; i < sbi->s_groups_count; i++) {
1630 gdp = ext4_get_group_desc(sb, i, &bh); 1630 gdp = ext4_get_group_desc(sb, i, &bh);
1631 1631
1632 flex_group = ext4_flex_group(sbi, i); 1632 flex_group = ext4_flex_group(sbi, i);
1633 atomic_set(&sbi->s_flex_groups[flex_group].free_inodes, 1633 atomic_set(&sbi->s_flex_groups[flex_group].free_inodes,
1634 ext4_free_inodes_count(sb, gdp)); 1634 ext4_free_inodes_count(sb, gdp));
1635 atomic_set(&sbi->s_flex_groups[flex_group].free_blocks, 1635 atomic_set(&sbi->s_flex_groups[flex_group].free_blocks,
1636 ext4_free_blks_count(sb, gdp)); 1636 ext4_free_blks_count(sb, gdp));
1637 atomic_set(&sbi->s_flex_groups[flex_group].used_dirs,
1638 ext4_used_dirs_count(sb, gdp));
1637 } 1639 }
1638 1640
1639 return 1; 1641 return 1;
1640 failed: 1642 failed:
1641 return 0; 1643 return 0;
1642 } 1644 }
1643 1645
1644 __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group, 1646 __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group,
1645 struct ext4_group_desc *gdp) 1647 struct ext4_group_desc *gdp)
1646 { 1648 {
1647 __u16 crc = 0; 1649 __u16 crc = 0;
1648 1650
1649 if (sbi->s_es->s_feature_ro_compat & 1651 if (sbi->s_es->s_feature_ro_compat &
1650 cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { 1652 cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
1651 int offset = offsetof(struct ext4_group_desc, bg_checksum); 1653 int offset = offsetof(struct ext4_group_desc, bg_checksum);
1652 __le32 le_group = cpu_to_le32(block_group); 1654 __le32 le_group = cpu_to_le32(block_group);
1653 1655
1654 crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid)); 1656 crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));
1655 crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group)); 1657 crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group));
1656 crc = crc16(crc, (__u8 *)gdp, offset); 1658 crc = crc16(crc, (__u8 *)gdp, offset);
1657 offset += sizeof(gdp->bg_checksum); /* skip checksum */ 1659 offset += sizeof(gdp->bg_checksum); /* skip checksum */
1658 /* for checksum of struct ext4_group_desc do the rest...*/ 1660 /* for checksum of struct ext4_group_desc do the rest...*/
1659 if ((sbi->s_es->s_feature_incompat & 1661 if ((sbi->s_es->s_feature_incompat &
1660 cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) && 1662 cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) &&
1661 offset < le16_to_cpu(sbi->s_es->s_desc_size)) 1663 offset < le16_to_cpu(sbi->s_es->s_desc_size))
1662 crc = crc16(crc, (__u8 *)gdp + offset, 1664 crc = crc16(crc, (__u8 *)gdp + offset,
1663 le16_to_cpu(sbi->s_es->s_desc_size) - 1665 le16_to_cpu(sbi->s_es->s_desc_size) -
1664 offset); 1666 offset);
1665 } 1667 }
1666 1668
1667 return cpu_to_le16(crc); 1669 return cpu_to_le16(crc);
1668 } 1670 }
1669 1671
1670 int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group, 1672 int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group,
1671 struct ext4_group_desc *gdp) 1673 struct ext4_group_desc *gdp)
1672 { 1674 {
1673 if ((sbi->s_es->s_feature_ro_compat & 1675 if ((sbi->s_es->s_feature_ro_compat &
1674 cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) && 1676 cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) &&
1675 (gdp->bg_checksum != ext4_group_desc_csum(sbi, block_group, gdp))) 1677 (gdp->bg_checksum != ext4_group_desc_csum(sbi, block_group, gdp)))
1676 return 0; 1678 return 0;
1677 1679
1678 return 1; 1680 return 1;
1679 } 1681 }
1680 1682
1681 /* Called at mount-time, super-block is locked */ 1683 /* Called at mount-time, super-block is locked */
1682 static int ext4_check_descriptors(struct super_block *sb) 1684 static int ext4_check_descriptors(struct super_block *sb)
1683 { 1685 {
1684 struct ext4_sb_info *sbi = EXT4_SB(sb); 1686 struct ext4_sb_info *sbi = EXT4_SB(sb);
1685 ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); 1687 ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
1686 ext4_fsblk_t last_block; 1688 ext4_fsblk_t last_block;
1687 ext4_fsblk_t block_bitmap; 1689 ext4_fsblk_t block_bitmap;
1688 ext4_fsblk_t inode_bitmap; 1690 ext4_fsblk_t inode_bitmap;
1689 ext4_fsblk_t inode_table; 1691 ext4_fsblk_t inode_table;
1690 int flexbg_flag = 0; 1692 int flexbg_flag = 0;
1691 ext4_group_t i; 1693 ext4_group_t i;
1692 1694
1693 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) 1695 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
1694 flexbg_flag = 1; 1696 flexbg_flag = 1;
1695 1697
1696 ext4_debug("Checking group descriptors"); 1698 ext4_debug("Checking group descriptors");
1697 1699
1698 for (i = 0; i < sbi->s_groups_count; i++) { 1700 for (i = 0; i < sbi->s_groups_count; i++) {
1699 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL); 1701 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
1700 1702
1701 if (i == sbi->s_groups_count - 1 || flexbg_flag) 1703 if (i == sbi->s_groups_count - 1 || flexbg_flag)
1702 last_block = ext4_blocks_count(sbi->s_es) - 1; 1704 last_block = ext4_blocks_count(sbi->s_es) - 1;
1703 else 1705 else
1704 last_block = first_block + 1706 last_block = first_block +
1705 (EXT4_BLOCKS_PER_GROUP(sb) - 1); 1707 (EXT4_BLOCKS_PER_GROUP(sb) - 1);
1706 1708
1707 block_bitmap = ext4_block_bitmap(sb, gdp); 1709 block_bitmap = ext4_block_bitmap(sb, gdp);
1708 if (block_bitmap < first_block || block_bitmap > last_block) { 1710 if (block_bitmap < first_block || block_bitmap > last_block) {
1709 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1711 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1710 "Block bitmap for group %u not in group " 1712 "Block bitmap for group %u not in group "
1711 "(block %llu)!\n", i, block_bitmap); 1713 "(block %llu)!\n", i, block_bitmap);
1712 return 0; 1714 return 0;
1713 } 1715 }
1714 inode_bitmap = ext4_inode_bitmap(sb, gdp); 1716 inode_bitmap = ext4_inode_bitmap(sb, gdp);
1715 if (inode_bitmap < first_block || inode_bitmap > last_block) { 1717 if (inode_bitmap < first_block || inode_bitmap > last_block) {
1716 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1718 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1717 "Inode bitmap for group %u not in group " 1719 "Inode bitmap for group %u not in group "
1718 "(block %llu)!\n", i, inode_bitmap); 1720 "(block %llu)!\n", i, inode_bitmap);
1719 return 0; 1721 return 0;
1720 } 1722 }
1721 inode_table = ext4_inode_table(sb, gdp); 1723 inode_table = ext4_inode_table(sb, gdp);
1722 if (inode_table < first_block || 1724 if (inode_table < first_block ||
1723 inode_table + sbi->s_itb_per_group - 1 > last_block) { 1725 inode_table + sbi->s_itb_per_group - 1 > last_block) {
1724 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1726 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1725 "Inode table for group %u not in group " 1727 "Inode table for group %u not in group "
1726 "(block %llu)!\n", i, inode_table); 1728 "(block %llu)!\n", i, inode_table);
1727 return 0; 1729 return 0;
1728 } 1730 }
1729 spin_lock(sb_bgl_lock(sbi, i)); 1731 spin_lock(sb_bgl_lock(sbi, i));
1730 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { 1732 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) {
1731 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1733 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1732 "Checksum for group %u failed (%u!=%u)\n", 1734 "Checksum for group %u failed (%u!=%u)\n",
1733 i, le16_to_cpu(ext4_group_desc_csum(sbi, i, 1735 i, le16_to_cpu(ext4_group_desc_csum(sbi, i,
1734 gdp)), le16_to_cpu(gdp->bg_checksum)); 1736 gdp)), le16_to_cpu(gdp->bg_checksum));
1735 if (!(sb->s_flags & MS_RDONLY)) { 1737 if (!(sb->s_flags & MS_RDONLY)) {
1736 spin_unlock(sb_bgl_lock(sbi, i)); 1738 spin_unlock(sb_bgl_lock(sbi, i));
1737 return 0; 1739 return 0;
1738 } 1740 }
1739 } 1741 }
1740 spin_unlock(sb_bgl_lock(sbi, i)); 1742 spin_unlock(sb_bgl_lock(sbi, i));
1741 if (!flexbg_flag) 1743 if (!flexbg_flag)
1742 first_block += EXT4_BLOCKS_PER_GROUP(sb); 1744 first_block += EXT4_BLOCKS_PER_GROUP(sb);
1743 } 1745 }
1744 1746
1745 ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb)); 1747 ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb));
1746 sbi->s_es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb)); 1748 sbi->s_es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb));
1747 return 1; 1749 return 1;
1748 } 1750 }
1749 1751
1750 /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at 1752 /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at
1751 * the superblock) which were deleted from all directories, but held open by 1753 * the superblock) which were deleted from all directories, but held open by
1752 * a process at the time of a crash. We walk the list and try to delete these 1754 * a process at the time of a crash. We walk the list and try to delete these
1753 * inodes at recovery time (only with a read-write filesystem). 1755 * inodes at recovery time (only with a read-write filesystem).
1754 * 1756 *
1755 * In order to keep the orphan inode chain consistent during traversal (in 1757 * In order to keep the orphan inode chain consistent during traversal (in
1756 * case of crash during recovery), we link each inode into the superblock 1758 * case of crash during recovery), we link each inode into the superblock
1757 * orphan list_head and handle it the same way as an inode deletion during 1759 * orphan list_head and handle it the same way as an inode deletion during
1758 * normal operation (which journals the operations for us). 1760 * normal operation (which journals the operations for us).
1759 * 1761 *
1760 * We only do an iget() and an iput() on each inode, which is very safe if we 1762 * We only do an iget() and an iput() on each inode, which is very safe if we
1761 * accidentally point at an in-use or already deleted inode. The worst that 1763 * accidentally point at an in-use or already deleted inode. The worst that
1762 * can happen in this case is that we get a "bit already cleared" message from 1764 * can happen in this case is that we get a "bit already cleared" message from
1763 * ext4_free_inode(). The only reason we would point at a wrong inode is if 1765 * ext4_free_inode(). The only reason we would point at a wrong inode is if
1764 * e2fsck was run on this filesystem, and it must have already done the orphan 1766 * e2fsck was run on this filesystem, and it must have already done the orphan
1765 * inode cleanup for us, so we can safely abort without any further action. 1767 * inode cleanup for us, so we can safely abort without any further action.
1766 */ 1768 */
1767 static void ext4_orphan_cleanup(struct super_block *sb, 1769 static void ext4_orphan_cleanup(struct super_block *sb,
1768 struct ext4_super_block *es) 1770 struct ext4_super_block *es)
1769 { 1771 {
1770 unsigned int s_flags = sb->s_flags; 1772 unsigned int s_flags = sb->s_flags;
1771 int nr_orphans = 0, nr_truncates = 0; 1773 int nr_orphans = 0, nr_truncates = 0;
1772 #ifdef CONFIG_QUOTA 1774 #ifdef CONFIG_QUOTA
1773 int i; 1775 int i;
1774 #endif 1776 #endif
1775 if (!es->s_last_orphan) { 1777 if (!es->s_last_orphan) {
1776 jbd_debug(4, "no orphan inodes to clean up\n"); 1778 jbd_debug(4, "no orphan inodes to clean up\n");
1777 return; 1779 return;
1778 } 1780 }
1779 1781
1780 if (bdev_read_only(sb->s_bdev)) { 1782 if (bdev_read_only(sb->s_bdev)) {
1781 printk(KERN_ERR "EXT4-fs: write access " 1783 printk(KERN_ERR "EXT4-fs: write access "
1782 "unavailable, skipping orphan cleanup.\n"); 1784 "unavailable, skipping orphan cleanup.\n");
1783 return; 1785 return;
1784 } 1786 }
1785 1787
1786 if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) { 1788 if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
1787 if (es->s_last_orphan) 1789 if (es->s_last_orphan)
1788 jbd_debug(1, "Errors on filesystem, " 1790 jbd_debug(1, "Errors on filesystem, "
1789 "clearing orphan list.\n"); 1791 "clearing orphan list.\n");
1790 es->s_last_orphan = 0; 1792 es->s_last_orphan = 0;
1791 jbd_debug(1, "Skipping orphan recovery on fs with errors.\n"); 1793 jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
1792 return; 1794 return;
1793 } 1795 }
1794 1796
1795 if (s_flags & MS_RDONLY) { 1797 if (s_flags & MS_RDONLY) {
1796 printk(KERN_INFO "EXT4-fs: %s: orphan cleanup on readonly fs\n", 1798 printk(KERN_INFO "EXT4-fs: %s: orphan cleanup on readonly fs\n",
1797 sb->s_id); 1799 sb->s_id);
1798 sb->s_flags &= ~MS_RDONLY; 1800 sb->s_flags &= ~MS_RDONLY;
1799 } 1801 }
1800 #ifdef CONFIG_QUOTA 1802 #ifdef CONFIG_QUOTA
1801 /* Needed for iput() to work correctly and not trash data */ 1803 /* Needed for iput() to work correctly and not trash data */
1802 sb->s_flags |= MS_ACTIVE; 1804 sb->s_flags |= MS_ACTIVE;
1803 /* Turn on quotas so that they are updated correctly */ 1805 /* Turn on quotas so that they are updated correctly */
1804 for (i = 0; i < MAXQUOTAS; i++) { 1806 for (i = 0; i < MAXQUOTAS; i++) {
1805 if (EXT4_SB(sb)->s_qf_names[i]) { 1807 if (EXT4_SB(sb)->s_qf_names[i]) {
1806 int ret = ext4_quota_on_mount(sb, i); 1808 int ret = ext4_quota_on_mount(sb, i);
1807 if (ret < 0) 1809 if (ret < 0)
1808 printk(KERN_ERR 1810 printk(KERN_ERR
1809 "EXT4-fs: Cannot turn on journaled " 1811 "EXT4-fs: Cannot turn on journaled "
1810 "quota: error %d\n", ret); 1812 "quota: error %d\n", ret);
1811 } 1813 }
1812 } 1814 }
1813 #endif 1815 #endif
1814 1816
1815 while (es->s_last_orphan) { 1817 while (es->s_last_orphan) {
1816 struct inode *inode; 1818 struct inode *inode;
1817 1819
1818 inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan)); 1820 inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan));
1819 if (IS_ERR(inode)) { 1821 if (IS_ERR(inode)) {
1820 es->s_last_orphan = 0; 1822 es->s_last_orphan = 0;
1821 break; 1823 break;
1822 } 1824 }
1823 1825
1824 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan); 1826 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
1825 vfs_dq_init(inode); 1827 vfs_dq_init(inode);
1826 if (inode->i_nlink) { 1828 if (inode->i_nlink) {
1827 printk(KERN_DEBUG 1829 printk(KERN_DEBUG
1828 "%s: truncating inode %lu to %lld bytes\n", 1830 "%s: truncating inode %lu to %lld bytes\n",
1829 __func__, inode->i_ino, inode->i_size); 1831 __func__, inode->i_ino, inode->i_size);
1830 jbd_debug(2, "truncating inode %lu to %lld bytes\n", 1832 jbd_debug(2, "truncating inode %lu to %lld bytes\n",
1831 inode->i_ino, inode->i_size); 1833 inode->i_ino, inode->i_size);
1832 ext4_truncate(inode); 1834 ext4_truncate(inode);
1833 nr_truncates++; 1835 nr_truncates++;
1834 } else { 1836 } else {
1835 printk(KERN_DEBUG 1837 printk(KERN_DEBUG
1836 "%s: deleting unreferenced inode %lu\n", 1838 "%s: deleting unreferenced inode %lu\n",
1837 __func__, inode->i_ino); 1839 __func__, inode->i_ino);
1838 jbd_debug(2, "deleting unreferenced inode %lu\n", 1840 jbd_debug(2, "deleting unreferenced inode %lu\n",
1839 inode->i_ino); 1841 inode->i_ino);
1840 nr_orphans++; 1842 nr_orphans++;
1841 } 1843 }
1842 iput(inode); /* The delete magic happens here! */ 1844 iput(inode); /* The delete magic happens here! */
1843 } 1845 }
1844 1846
1845 #define PLURAL(x) (x), ((x) == 1) ? "" : "s" 1847 #define PLURAL(x) (x), ((x) == 1) ? "" : "s"
1846 1848
1847 if (nr_orphans) 1849 if (nr_orphans)
1848 printk(KERN_INFO "EXT4-fs: %s: %d orphan inode%s deleted\n", 1850 printk(KERN_INFO "EXT4-fs: %s: %d orphan inode%s deleted\n",
1849 sb->s_id, PLURAL(nr_orphans)); 1851 sb->s_id, PLURAL(nr_orphans));
1850 if (nr_truncates) 1852 if (nr_truncates)
1851 printk(KERN_INFO "EXT4-fs: %s: %d truncate%s cleaned up\n", 1853 printk(KERN_INFO "EXT4-fs: %s: %d truncate%s cleaned up\n",
1852 sb->s_id, PLURAL(nr_truncates)); 1854 sb->s_id, PLURAL(nr_truncates));
1853 #ifdef CONFIG_QUOTA 1855 #ifdef CONFIG_QUOTA
1854 /* Turn quotas off */ 1856 /* Turn quotas off */
1855 for (i = 0; i < MAXQUOTAS; i++) { 1857 for (i = 0; i < MAXQUOTAS; i++) {
1856 if (sb_dqopt(sb)->files[i]) 1858 if (sb_dqopt(sb)->files[i])
1857 vfs_quota_off(sb, i, 0); 1859 vfs_quota_off(sb, i, 0);
1858 } 1860 }
1859 #endif 1861 #endif
1860 sb->s_flags = s_flags; /* Restore MS_RDONLY status */ 1862 sb->s_flags = s_flags; /* Restore MS_RDONLY status */
1861 } 1863 }
1862 /* 1864 /*
1863 * Maximal extent format file size. 1865 * Maximal extent format file size.
1864 * Resulting logical blkno at s_maxbytes must fit in our on-disk 1866 * Resulting logical blkno at s_maxbytes must fit in our on-disk
1865 * extent format containers, within a sector_t, and within i_blocks 1867 * extent format containers, within a sector_t, and within i_blocks
1866 * in the vfs. ext4 inode has 48 bits of i_block in fsblock units, 1868 * in the vfs. ext4 inode has 48 bits of i_block in fsblock units,
1867 * so that won't be a limiting factor. 1869 * so that won't be a limiting factor.
1868 * 1870 *
1869 * Note, this does *not* consider any metadata overhead for vfs i_blocks. 1871 * Note, this does *not* consider any metadata overhead for vfs i_blocks.
1870 */ 1872 */
1871 static loff_t ext4_max_size(int blkbits, int has_huge_files) 1873 static loff_t ext4_max_size(int blkbits, int has_huge_files)
1872 { 1874 {
1873 loff_t res; 1875 loff_t res;
1874 loff_t upper_limit = MAX_LFS_FILESIZE; 1876 loff_t upper_limit = MAX_LFS_FILESIZE;
1875 1877
1876 /* small i_blocks in vfs inode? */ 1878 /* small i_blocks in vfs inode? */
1877 if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) { 1879 if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
1878 /* 1880 /*
1879 * CONFIG_LBD is not enabled implies the inode 1881 * CONFIG_LBD is not enabled implies the inode
1880 * i_block represent total blocks in 512 bytes 1882 * i_block represent total blocks in 512 bytes
1881 * 32 == size of vfs inode i_blocks * 8 1883 * 32 == size of vfs inode i_blocks * 8
1882 */ 1884 */
1883 upper_limit = (1LL << 32) - 1; 1885 upper_limit = (1LL << 32) - 1;
1884 1886
1885 /* total blocks in file system block size */ 1887 /* total blocks in file system block size */
1886 upper_limit >>= (blkbits - 9); 1888 upper_limit >>= (blkbits - 9);
1887 upper_limit <<= blkbits; 1889 upper_limit <<= blkbits;
1888 } 1890 }
1889 1891
1890 /* 32-bit extent-start container, ee_block */ 1892 /* 32-bit extent-start container, ee_block */
1891 res = 1LL << 32; 1893 res = 1LL << 32;
1892 res <<= blkbits; 1894 res <<= blkbits;
1893 res -= 1; 1895 res -= 1;
1894 1896
1895 /* Sanity check against vm- & vfs- imposed limits */ 1897 /* Sanity check against vm- & vfs- imposed limits */
1896 if (res > upper_limit) 1898 if (res > upper_limit)
1897 res = upper_limit; 1899 res = upper_limit;
1898 1900
1899 return res; 1901 return res;
1900 } 1902 }
1901 1903
1902 /* 1904 /*
1903 * Maximal bitmap file size. There is a direct, and {,double-,triple-}indirect 1905 * Maximal bitmap file size. There is a direct, and {,double-,triple-}indirect
1904 * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks. 1906 * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks.
1905 * We need to be 1 filesystem block less than the 2^48 sector limit. 1907 * We need to be 1 filesystem block less than the 2^48 sector limit.
1906 */ 1908 */
1907 static loff_t ext4_max_bitmap_size(int bits, int has_huge_files) 1909 static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
1908 { 1910 {
1909 loff_t res = EXT4_NDIR_BLOCKS; 1911 loff_t res = EXT4_NDIR_BLOCKS;
1910 int meta_blocks; 1912 int meta_blocks;
1911 loff_t upper_limit; 1913 loff_t upper_limit;
1912 /* This is calculated to be the largest file size for a 1914 /* This is calculated to be the largest file size for a
1913 * dense, bitmapped file such that the total number of 1915 * dense, bitmapped file such that the total number of
1914 * sectors in the file, including data and all indirect blocks, 1916 * sectors in the file, including data and all indirect blocks,
1915 * does not exceed 2^48 -1 1917 * does not exceed 2^48 -1
1916 * __u32 i_blocks_lo and _u16 i_blocks_high representing the 1918 * __u32 i_blocks_lo and _u16 i_blocks_high representing the
1917 * total number of 512 bytes blocks of the file 1919 * total number of 512 bytes blocks of the file
1918 */ 1920 */
1919 1921
1920 if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) { 1922 if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
1921 /* 1923 /*
1922 * !has_huge_files or CONFIG_LBD is not enabled 1924 * !has_huge_files or CONFIG_LBD is not enabled
1923 * implies the inode i_block represent total blocks in 1925 * implies the inode i_block represent total blocks in
1924 * 512 bytes 32 == size of vfs inode i_blocks * 8 1926 * 512 bytes 32 == size of vfs inode i_blocks * 8
1925 */ 1927 */
1926 upper_limit = (1LL << 32) - 1; 1928 upper_limit = (1LL << 32) - 1;
1927 1929
1928 /* total blocks in file system block size */ 1930 /* total blocks in file system block size */
1929 upper_limit >>= (bits - 9); 1931 upper_limit >>= (bits - 9);
1930 1932
1931 } else { 1933 } else {
1932 /* 1934 /*
1933 * We use 48 bit ext4_inode i_blocks 1935 * We use 48 bit ext4_inode i_blocks
1934 * With EXT4_HUGE_FILE_FL set the i_blocks 1936 * With EXT4_HUGE_FILE_FL set the i_blocks
1935 * represent total number of blocks in 1937 * represent total number of blocks in
1936 * file system block size 1938 * file system block size
1937 */ 1939 */
1938 upper_limit = (1LL << 48) - 1; 1940 upper_limit = (1LL << 48) - 1;
1939 1941
1940 } 1942 }
1941 1943
1942 /* indirect blocks */ 1944 /* indirect blocks */
1943 meta_blocks = 1; 1945 meta_blocks = 1;
1944 /* double indirect blocks */ 1946 /* double indirect blocks */
1945 meta_blocks += 1 + (1LL << (bits-2)); 1947 meta_blocks += 1 + (1LL << (bits-2));
1946 /* tripple indirect blocks */ 1948 /* tripple indirect blocks */
1947 meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2))); 1949 meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2)));
1948 1950
1949 upper_limit -= meta_blocks; 1951 upper_limit -= meta_blocks;
1950 upper_limit <<= bits; 1952 upper_limit <<= bits;
1951 1953
1952 res += 1LL << (bits-2); 1954 res += 1LL << (bits-2);
1953 res += 1LL << (2*(bits-2)); 1955 res += 1LL << (2*(bits-2));
1954 res += 1LL << (3*(bits-2)); 1956 res += 1LL << (3*(bits-2));
1955 res <<= bits; 1957 res <<= bits;
1956 if (res > upper_limit) 1958 if (res > upper_limit)
1957 res = upper_limit; 1959 res = upper_limit;
1958 1960
1959 if (res > MAX_LFS_FILESIZE) 1961 if (res > MAX_LFS_FILESIZE)
1960 res = MAX_LFS_FILESIZE; 1962 res = MAX_LFS_FILESIZE;
1961 1963
1962 return res; 1964 return res;
1963 } 1965 }
1964 1966
1965 static ext4_fsblk_t descriptor_loc(struct super_block *sb, 1967 static ext4_fsblk_t descriptor_loc(struct super_block *sb,
1966 ext4_fsblk_t logical_sb_block, int nr) 1968 ext4_fsblk_t logical_sb_block, int nr)
1967 { 1969 {
1968 struct ext4_sb_info *sbi = EXT4_SB(sb); 1970 struct ext4_sb_info *sbi = EXT4_SB(sb);
1969 ext4_group_t bg, first_meta_bg; 1971 ext4_group_t bg, first_meta_bg;
1970 int has_super = 0; 1972 int has_super = 0;
1971 1973
1972 first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg); 1974 first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
1973 1975
1974 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) || 1976 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) ||
1975 nr < first_meta_bg) 1977 nr < first_meta_bg)
1976 return logical_sb_block + nr + 1; 1978 return logical_sb_block + nr + 1;
1977 bg = sbi->s_desc_per_block * nr; 1979 bg = sbi->s_desc_per_block * nr;
1978 if (ext4_bg_has_super(sb, bg)) 1980 if (ext4_bg_has_super(sb, bg))
1979 has_super = 1; 1981 has_super = 1;
1980 return (has_super + ext4_group_first_block_no(sb, bg)); 1982 return (has_super + ext4_group_first_block_no(sb, bg));
1981 } 1983 }
1982 1984
1983 /** 1985 /**
1984 * ext4_get_stripe_size: Get the stripe size. 1986 * ext4_get_stripe_size: Get the stripe size.
1985 * @sbi: In memory super block info 1987 * @sbi: In memory super block info
1986 * 1988 *
1987 * If we have specified it via mount option, then 1989 * If we have specified it via mount option, then
1988 * use the mount option value. If the value specified at mount time is 1990 * use the mount option value. If the value specified at mount time is
1989 * greater than the blocks per group use the super block value. 1991 * greater than the blocks per group use the super block value.
1990 * If the super block value is greater than blocks per group return 0. 1992 * If the super block value is greater than blocks per group return 0.
1991 * Allocator needs it be less than blocks per group. 1993 * Allocator needs it be less than blocks per group.
1992 * 1994 *
1993 */ 1995 */
1994 static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi) 1996 static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi)
1995 { 1997 {
1996 unsigned long stride = le16_to_cpu(sbi->s_es->s_raid_stride); 1998 unsigned long stride = le16_to_cpu(sbi->s_es->s_raid_stride);
1997 unsigned long stripe_width = 1999 unsigned long stripe_width =
1998 le32_to_cpu(sbi->s_es->s_raid_stripe_width); 2000 le32_to_cpu(sbi->s_es->s_raid_stripe_width);
1999 2001
2000 if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group) 2002 if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group)
2001 return sbi->s_stripe; 2003 return sbi->s_stripe;
2002 2004
2003 if (stripe_width <= sbi->s_blocks_per_group) 2005 if (stripe_width <= sbi->s_blocks_per_group)
2004 return stripe_width; 2006 return stripe_width;
2005 2007
2006 if (stride <= sbi->s_blocks_per_group) 2008 if (stride <= sbi->s_blocks_per_group)
2007 return stride; 2009 return stride;
2008 2010
2009 return 0; 2011 return 0;
2010 } 2012 }
2011 2013
2012 /* sysfs supprt */ 2014 /* sysfs supprt */
2013 2015
2014 struct ext4_attr { 2016 struct ext4_attr {
2015 struct attribute attr; 2017 struct attribute attr;
2016 ssize_t (*show)(struct ext4_attr *, struct ext4_sb_info *, char *); 2018 ssize_t (*show)(struct ext4_attr *, struct ext4_sb_info *, char *);
2017 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *, 2019 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
2018 const char *, size_t); 2020 const char *, size_t);
2019 int offset; 2021 int offset;
2020 }; 2022 };
2021 2023
2022 static int parse_strtoul(const char *buf, 2024 static int parse_strtoul(const char *buf,
2023 unsigned long max, unsigned long *value) 2025 unsigned long max, unsigned long *value)
2024 { 2026 {
2025 char *endp; 2027 char *endp;
2026 2028
2027 while (*buf && isspace(*buf)) 2029 while (*buf && isspace(*buf))
2028 buf++; 2030 buf++;
2029 *value = simple_strtoul(buf, &endp, 0); 2031 *value = simple_strtoul(buf, &endp, 0);
2030 while (*endp && isspace(*endp)) 2032 while (*endp && isspace(*endp))
2031 endp++; 2033 endp++;
2032 if (*endp || *value > max) 2034 if (*endp || *value > max)
2033 return -EINVAL; 2035 return -EINVAL;
2034 2036
2035 return 0; 2037 return 0;
2036 } 2038 }
2037 2039
2038 static ssize_t delayed_allocation_blocks_show(struct ext4_attr *a, 2040 static ssize_t delayed_allocation_blocks_show(struct ext4_attr *a,
2039 struct ext4_sb_info *sbi, 2041 struct ext4_sb_info *sbi,
2040 char *buf) 2042 char *buf)
2041 { 2043 {
2042 return snprintf(buf, PAGE_SIZE, "%llu\n", 2044 return snprintf(buf, PAGE_SIZE, "%llu\n",
2043 (s64) percpu_counter_sum(&sbi->s_dirtyblocks_counter)); 2045 (s64) percpu_counter_sum(&sbi->s_dirtyblocks_counter));
2044 } 2046 }
2045 2047
2046 static ssize_t session_write_kbytes_show(struct ext4_attr *a, 2048 static ssize_t session_write_kbytes_show(struct ext4_attr *a,
2047 struct ext4_sb_info *sbi, char *buf) 2049 struct ext4_sb_info *sbi, char *buf)
2048 { 2050 {
2049 struct super_block *sb = sbi->s_buddy_cache->i_sb; 2051 struct super_block *sb = sbi->s_buddy_cache->i_sb;
2050 2052
2051 return snprintf(buf, PAGE_SIZE, "%lu\n", 2053 return snprintf(buf, PAGE_SIZE, "%lu\n",
2052 (part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 2054 (part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
2053 sbi->s_sectors_written_start) >> 1); 2055 sbi->s_sectors_written_start) >> 1);
2054 } 2056 }
2055 2057
2056 static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a, 2058 static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a,
2057 struct ext4_sb_info *sbi, char *buf) 2059 struct ext4_sb_info *sbi, char *buf)
2058 { 2060 {
2059 struct super_block *sb = sbi->s_buddy_cache->i_sb; 2061 struct super_block *sb = sbi->s_buddy_cache->i_sb;
2060 2062
2061 return snprintf(buf, PAGE_SIZE, "%llu\n", 2063 return snprintf(buf, PAGE_SIZE, "%llu\n",
2062 sbi->s_kbytes_written + 2064 sbi->s_kbytes_written +
2063 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 2065 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
2064 EXT4_SB(sb)->s_sectors_written_start) >> 1)); 2066 EXT4_SB(sb)->s_sectors_written_start) >> 1));
2065 } 2067 }
2066 2068
2067 static ssize_t inode_readahead_blks_store(struct ext4_attr *a, 2069 static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
2068 struct ext4_sb_info *sbi, 2070 struct ext4_sb_info *sbi,
2069 const char *buf, size_t count) 2071 const char *buf, size_t count)
2070 { 2072 {
2071 unsigned long t; 2073 unsigned long t;
2072 2074
2073 if (parse_strtoul(buf, 0x40000000, &t)) 2075 if (parse_strtoul(buf, 0x40000000, &t))
2074 return -EINVAL; 2076 return -EINVAL;
2075 2077
2076 /* inode_readahead_blks must be a power of 2 */ 2078 /* inode_readahead_blks must be a power of 2 */
2077 if (t & (t-1)) 2079 if (t & (t-1))
2078 return -EINVAL; 2080 return -EINVAL;
2079 2081
2080 sbi->s_inode_readahead_blks = t; 2082 sbi->s_inode_readahead_blks = t;
2081 return count; 2083 return count;
2082 } 2084 }
2083 2085
2084 static ssize_t sbi_ui_show(struct ext4_attr *a, 2086 static ssize_t sbi_ui_show(struct ext4_attr *a,
2085 struct ext4_sb_info *sbi, char *buf) 2087 struct ext4_sb_info *sbi, char *buf)
2086 { 2088 {
2087 unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset); 2089 unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset);
2088 2090
2089 return snprintf(buf, PAGE_SIZE, "%u\n", *ui); 2091 return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
2090 } 2092 }
2091 2093
2092 static ssize_t sbi_ui_store(struct ext4_attr *a, 2094 static ssize_t sbi_ui_store(struct ext4_attr *a,
2093 struct ext4_sb_info *sbi, 2095 struct ext4_sb_info *sbi,
2094 const char *buf, size_t count) 2096 const char *buf, size_t count)
2095 { 2097 {
2096 unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset); 2098 unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset);
2097 unsigned long t; 2099 unsigned long t;
2098 2100
2099 if (parse_strtoul(buf, 0xffffffff, &t)) 2101 if (parse_strtoul(buf, 0xffffffff, &t))
2100 return -EINVAL; 2102 return -EINVAL;
2101 *ui = t; 2103 *ui = t;
2102 return count; 2104 return count;
2103 } 2105 }
2104 2106
2105 #define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \ 2107 #define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \
2106 static struct ext4_attr ext4_attr_##_name = { \ 2108 static struct ext4_attr ext4_attr_##_name = { \
2107 .attr = {.name = __stringify(_name), .mode = _mode }, \ 2109 .attr = {.name = __stringify(_name), .mode = _mode }, \
2108 .show = _show, \ 2110 .show = _show, \
2109 .store = _store, \ 2111 .store = _store, \
2110 .offset = offsetof(struct ext4_sb_info, _elname), \ 2112 .offset = offsetof(struct ext4_sb_info, _elname), \
2111 } 2113 }
2112 #define EXT4_ATTR(name, mode, show, store) \ 2114 #define EXT4_ATTR(name, mode, show, store) \
2113 static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store) 2115 static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
2114 2116
2115 #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL) 2117 #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL)
2116 #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store) 2118 #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store)
2117 #define EXT4_RW_ATTR_SBI_UI(name, elname) \ 2119 #define EXT4_RW_ATTR_SBI_UI(name, elname) \
2118 EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname) 2120 EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname)
2119 #define ATTR_LIST(name) &ext4_attr_##name.attr 2121 #define ATTR_LIST(name) &ext4_attr_##name.attr
2120 2122
2121 EXT4_RO_ATTR(delayed_allocation_blocks); 2123 EXT4_RO_ATTR(delayed_allocation_blocks);
2122 EXT4_RO_ATTR(session_write_kbytes); 2124 EXT4_RO_ATTR(session_write_kbytes);
2123 EXT4_RO_ATTR(lifetime_write_kbytes); 2125 EXT4_RO_ATTR(lifetime_write_kbytes);
2124 EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show, 2126 EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
2125 inode_readahead_blks_store, s_inode_readahead_blks); 2127 inode_readahead_blks_store, s_inode_readahead_blks);
2126 EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats); 2128 EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);
2127 EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan); 2129 EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
2128 EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan); 2130 EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);
2129 EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs); 2131 EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
2130 EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request); 2132 EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
2131 EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc); 2133 EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
2132 2134
2133 static struct attribute *ext4_attrs[] = { 2135 static struct attribute *ext4_attrs[] = {
2134 ATTR_LIST(delayed_allocation_blocks), 2136 ATTR_LIST(delayed_allocation_blocks),
2135 ATTR_LIST(session_write_kbytes), 2137 ATTR_LIST(session_write_kbytes),
2136 ATTR_LIST(lifetime_write_kbytes), 2138 ATTR_LIST(lifetime_write_kbytes),
2137 ATTR_LIST(inode_readahead_blks), 2139 ATTR_LIST(inode_readahead_blks),
2138 ATTR_LIST(mb_stats), 2140 ATTR_LIST(mb_stats),
2139 ATTR_LIST(mb_max_to_scan), 2141 ATTR_LIST(mb_max_to_scan),
2140 ATTR_LIST(mb_min_to_scan), 2142 ATTR_LIST(mb_min_to_scan),
2141 ATTR_LIST(mb_order2_req), 2143 ATTR_LIST(mb_order2_req),
2142 ATTR_LIST(mb_stream_req), 2144 ATTR_LIST(mb_stream_req),
2143 ATTR_LIST(mb_group_prealloc), 2145 ATTR_LIST(mb_group_prealloc),
2144 NULL, 2146 NULL,
2145 }; 2147 };
2146 2148
2147 static ssize_t ext4_attr_show(struct kobject *kobj, 2149 static ssize_t ext4_attr_show(struct kobject *kobj,
2148 struct attribute *attr, char *buf) 2150 struct attribute *attr, char *buf)
2149 { 2151 {
2150 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 2152 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
2151 s_kobj); 2153 s_kobj);
2152 struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); 2154 struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
2153 2155
2154 return a->show ? a->show(a, sbi, buf) : 0; 2156 return a->show ? a->show(a, sbi, buf) : 0;
2155 } 2157 }
2156 2158
2157 static ssize_t ext4_attr_store(struct kobject *kobj, 2159 static ssize_t ext4_attr_store(struct kobject *kobj,
2158 struct attribute *attr, 2160 struct attribute *attr,
2159 const char *buf, size_t len) 2161 const char *buf, size_t len)
2160 { 2162 {
2161 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 2163 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
2162 s_kobj); 2164 s_kobj);
2163 struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); 2165 struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
2164 2166
2165 return a->store ? a->store(a, sbi, buf, len) : 0; 2167 return a->store ? a->store(a, sbi, buf, len) : 0;
2166 } 2168 }
2167 2169
2168 static void ext4_sb_release(struct kobject *kobj) 2170 static void ext4_sb_release(struct kobject *kobj)
2169 { 2171 {
2170 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 2172 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
2171 s_kobj); 2173 s_kobj);
2172 complete(&sbi->s_kobj_unregister); 2174 complete(&sbi->s_kobj_unregister);
2173 } 2175 }
2174 2176
2175 2177
2176 static struct sysfs_ops ext4_attr_ops = { 2178 static struct sysfs_ops ext4_attr_ops = {
2177 .show = ext4_attr_show, 2179 .show = ext4_attr_show,
2178 .store = ext4_attr_store, 2180 .store = ext4_attr_store,
2179 }; 2181 };
2180 2182
2181 static struct kobj_type ext4_ktype = { 2183 static struct kobj_type ext4_ktype = {
2182 .default_attrs = ext4_attrs, 2184 .default_attrs = ext4_attrs,
2183 .sysfs_ops = &ext4_attr_ops, 2185 .sysfs_ops = &ext4_attr_ops,
2184 .release = ext4_sb_release, 2186 .release = ext4_sb_release,
2185 }; 2187 };
2186 2188
2187 static int ext4_fill_super(struct super_block *sb, void *data, int silent) 2189 static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2188 __releases(kernel_lock) 2190 __releases(kernel_lock)
2189 __acquires(kernel_lock) 2191 __acquires(kernel_lock)
2190 2192
2191 { 2193 {
2192 struct buffer_head *bh; 2194 struct buffer_head *bh;
2193 struct ext4_super_block *es = NULL; 2195 struct ext4_super_block *es = NULL;
2194 struct ext4_sb_info *sbi; 2196 struct ext4_sb_info *sbi;
2195 ext4_fsblk_t block; 2197 ext4_fsblk_t block;
2196 ext4_fsblk_t sb_block = get_sb_block(&data); 2198 ext4_fsblk_t sb_block = get_sb_block(&data);
2197 ext4_fsblk_t logical_sb_block; 2199 ext4_fsblk_t logical_sb_block;
2198 unsigned long offset = 0; 2200 unsigned long offset = 0;
2199 unsigned long journal_devnum = 0; 2201 unsigned long journal_devnum = 0;
2200 unsigned long def_mount_opts; 2202 unsigned long def_mount_opts;
2201 struct inode *root; 2203 struct inode *root;
2202 char *cp; 2204 char *cp;
2203 const char *descr; 2205 const char *descr;
2204 int ret = -EINVAL; 2206 int ret = -EINVAL;
2205 int blocksize; 2207 int blocksize;
2206 unsigned int db_count; 2208 unsigned int db_count;
2207 unsigned int i; 2209 unsigned int i;
2208 int needs_recovery, has_huge_files; 2210 int needs_recovery, has_huge_files;
2209 int features; 2211 int features;
2210 __u64 blocks_count; 2212 __u64 blocks_count;
2211 int err; 2213 int err;
2212 unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; 2214 unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
2213 2215
2214 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); 2216 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
2215 if (!sbi) 2217 if (!sbi)
2216 return -ENOMEM; 2218 return -ENOMEM;
2217 2219
2218 sbi->s_blockgroup_lock = 2220 sbi->s_blockgroup_lock =
2219 kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); 2221 kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
2220 if (!sbi->s_blockgroup_lock) { 2222 if (!sbi->s_blockgroup_lock) {
2221 kfree(sbi); 2223 kfree(sbi);
2222 return -ENOMEM; 2224 return -ENOMEM;
2223 } 2225 }
2224 sb->s_fs_info = sbi; 2226 sb->s_fs_info = sbi;
2225 sbi->s_mount_opt = 0; 2227 sbi->s_mount_opt = 0;
2226 sbi->s_resuid = EXT4_DEF_RESUID; 2228 sbi->s_resuid = EXT4_DEF_RESUID;
2227 sbi->s_resgid = EXT4_DEF_RESGID; 2229 sbi->s_resgid = EXT4_DEF_RESGID;
2228 sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; 2230 sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;
2229 sbi->s_sb_block = sb_block; 2231 sbi->s_sb_block = sb_block;
2230 sbi->s_sectors_written_start = part_stat_read(sb->s_bdev->bd_part, 2232 sbi->s_sectors_written_start = part_stat_read(sb->s_bdev->bd_part,
2231 sectors[1]); 2233 sectors[1]);
2232 2234
2233 unlock_kernel(); 2235 unlock_kernel();
2234 2236
2235 /* Cleanup superblock name */ 2237 /* Cleanup superblock name */
2236 for (cp = sb->s_id; (cp = strchr(cp, '/'));) 2238 for (cp = sb->s_id; (cp = strchr(cp, '/'));)
2237 *cp = '!'; 2239 *cp = '!';
2238 2240
2239 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE); 2241 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
2240 if (!blocksize) { 2242 if (!blocksize) {
2241 printk(KERN_ERR "EXT4-fs: unable to set blocksize\n"); 2243 printk(KERN_ERR "EXT4-fs: unable to set blocksize\n");
2242 goto out_fail; 2244 goto out_fail;
2243 } 2245 }
2244 2246
2245 /* 2247 /*
2246 * The ext4 superblock will not be buffer aligned for other than 1kB 2248 * The ext4 superblock will not be buffer aligned for other than 1kB
2247 * block sizes. We need to calculate the offset from buffer start. 2249 * block sizes. We need to calculate the offset from buffer start.
2248 */ 2250 */
2249 if (blocksize != EXT4_MIN_BLOCK_SIZE) { 2251 if (blocksize != EXT4_MIN_BLOCK_SIZE) {
2250 logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; 2252 logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
2251 offset = do_div(logical_sb_block, blocksize); 2253 offset = do_div(logical_sb_block, blocksize);
2252 } else { 2254 } else {
2253 logical_sb_block = sb_block; 2255 logical_sb_block = sb_block;
2254 } 2256 }
2255 2257
2256 if (!(bh = sb_bread(sb, logical_sb_block))) { 2258 if (!(bh = sb_bread(sb, logical_sb_block))) {
2257 printk(KERN_ERR "EXT4-fs: unable to read superblock\n"); 2259 printk(KERN_ERR "EXT4-fs: unable to read superblock\n");
2258 goto out_fail; 2260 goto out_fail;
2259 } 2261 }
2260 /* 2262 /*
2261 * Note: s_es must be initialized as soon as possible because 2263 * Note: s_es must be initialized as soon as possible because
2262 * some ext4 macro-instructions depend on its value 2264 * some ext4 macro-instructions depend on its value
2263 */ 2265 */
2264 es = (struct ext4_super_block *) (((char *)bh->b_data) + offset); 2266 es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
2265 sbi->s_es = es; 2267 sbi->s_es = es;
2266 sb->s_magic = le16_to_cpu(es->s_magic); 2268 sb->s_magic = le16_to_cpu(es->s_magic);
2267 if (sb->s_magic != EXT4_SUPER_MAGIC) 2269 if (sb->s_magic != EXT4_SUPER_MAGIC)
2268 goto cantfind_ext4; 2270 goto cantfind_ext4;
2269 sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written); 2271 sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written);
2270 2272
2271 /* Set defaults before we parse the mount options */ 2273 /* Set defaults before we parse the mount options */
2272 def_mount_opts = le32_to_cpu(es->s_default_mount_opts); 2274 def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
2273 if (def_mount_opts & EXT4_DEFM_DEBUG) 2275 if (def_mount_opts & EXT4_DEFM_DEBUG)
2274 set_opt(sbi->s_mount_opt, DEBUG); 2276 set_opt(sbi->s_mount_opt, DEBUG);
2275 if (def_mount_opts & EXT4_DEFM_BSDGROUPS) 2277 if (def_mount_opts & EXT4_DEFM_BSDGROUPS)
2276 set_opt(sbi->s_mount_opt, GRPID); 2278 set_opt(sbi->s_mount_opt, GRPID);
2277 if (def_mount_opts & EXT4_DEFM_UID16) 2279 if (def_mount_opts & EXT4_DEFM_UID16)
2278 set_opt(sbi->s_mount_opt, NO_UID32); 2280 set_opt(sbi->s_mount_opt, NO_UID32);
2279 #ifdef CONFIG_EXT4_FS_XATTR 2281 #ifdef CONFIG_EXT4_FS_XATTR
2280 if (def_mount_opts & EXT4_DEFM_XATTR_USER) 2282 if (def_mount_opts & EXT4_DEFM_XATTR_USER)
2281 set_opt(sbi->s_mount_opt, XATTR_USER); 2283 set_opt(sbi->s_mount_opt, XATTR_USER);
2282 #endif 2284 #endif
2283 #ifdef CONFIG_EXT4_FS_POSIX_ACL 2285 #ifdef CONFIG_EXT4_FS_POSIX_ACL
2284 if (def_mount_opts & EXT4_DEFM_ACL) 2286 if (def_mount_opts & EXT4_DEFM_ACL)
2285 set_opt(sbi->s_mount_opt, POSIX_ACL); 2287 set_opt(sbi->s_mount_opt, POSIX_ACL);
2286 #endif 2288 #endif
2287 if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA) 2289 if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA)
2288 sbi->s_mount_opt |= EXT4_MOUNT_JOURNAL_DATA; 2290 sbi->s_mount_opt |= EXT4_MOUNT_JOURNAL_DATA;
2289 else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED) 2291 else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED)
2290 sbi->s_mount_opt |= EXT4_MOUNT_ORDERED_DATA; 2292 sbi->s_mount_opt |= EXT4_MOUNT_ORDERED_DATA;
2291 else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK) 2293 else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK)
2292 sbi->s_mount_opt |= EXT4_MOUNT_WRITEBACK_DATA; 2294 sbi->s_mount_opt |= EXT4_MOUNT_WRITEBACK_DATA;
2293 2295
2294 if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC) 2296 if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC)
2295 set_opt(sbi->s_mount_opt, ERRORS_PANIC); 2297 set_opt(sbi->s_mount_opt, ERRORS_PANIC);
2296 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE) 2298 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE)
2297 set_opt(sbi->s_mount_opt, ERRORS_CONT); 2299 set_opt(sbi->s_mount_opt, ERRORS_CONT);
2298 else 2300 else
2299 set_opt(sbi->s_mount_opt, ERRORS_RO); 2301 set_opt(sbi->s_mount_opt, ERRORS_RO);
2300 2302
2301 sbi->s_resuid = le16_to_cpu(es->s_def_resuid); 2303 sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
2302 sbi->s_resgid = le16_to_cpu(es->s_def_resgid); 2304 sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
2303 sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ; 2305 sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;
2304 sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME; 2306 sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
2305 sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME; 2307 sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
2306 2308
2307 set_opt(sbi->s_mount_opt, RESERVATION); 2309 set_opt(sbi->s_mount_opt, RESERVATION);
2308 set_opt(sbi->s_mount_opt, BARRIER); 2310 set_opt(sbi->s_mount_opt, BARRIER);
2309 2311
2310 /* 2312 /*
2311 * enable delayed allocation by default 2313 * enable delayed allocation by default
2312 * Use -o nodelalloc to turn it off 2314 * Use -o nodelalloc to turn it off
2313 */ 2315 */
2314 set_opt(sbi->s_mount_opt, DELALLOC); 2316 set_opt(sbi->s_mount_opt, DELALLOC);
2315 2317
2316 2318
2317 if (!parse_options((char *) data, sb, &journal_devnum, 2319 if (!parse_options((char *) data, sb, &journal_devnum,
2318 &journal_ioprio, NULL, 0)) 2320 &journal_ioprio, NULL, 0))
2319 goto failed_mount; 2321 goto failed_mount;
2320 2322
2321 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 2323 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2322 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); 2324 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2323 2325
2324 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV && 2326 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&
2325 (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) || 2327 (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) ||
2326 EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) || 2328 EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
2327 EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U))) 2329 EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U)))
2328 printk(KERN_WARNING 2330 printk(KERN_WARNING
2329 "EXT4-fs warning: feature flags set on rev 0 fs, " 2331 "EXT4-fs warning: feature flags set on rev 0 fs, "
2330 "running e2fsck is recommended\n"); 2332 "running e2fsck is recommended\n");
2331 2333
2332 /* 2334 /*
2333 * Check feature flags regardless of the revision level, since we 2335 * Check feature flags regardless of the revision level, since we
2334 * previously didn't change the revision level when setting the flags, 2336 * previously didn't change the revision level when setting the flags,
2335 * so there is a chance incompat flags are set on a rev 0 filesystem. 2337 * so there is a chance incompat flags are set on a rev 0 filesystem.
2336 */ 2338 */
2337 features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP); 2339 features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP);
2338 if (features) { 2340 if (features) {
2339 printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of " 2341 printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of "
2340 "unsupported optional features (%x).\n", sb->s_id, 2342 "unsupported optional features (%x).\n", sb->s_id,
2341 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) & 2343 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) &
2342 ~EXT4_FEATURE_INCOMPAT_SUPP)); 2344 ~EXT4_FEATURE_INCOMPAT_SUPP));
2343 goto failed_mount; 2345 goto failed_mount;
2344 } 2346 }
2345 features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP); 2347 features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP);
2346 if (!(sb->s_flags & MS_RDONLY) && features) { 2348 if (!(sb->s_flags & MS_RDONLY) && features) {
2347 printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of " 2349 printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of "
2348 "unsupported optional features (%x).\n", sb->s_id, 2350 "unsupported optional features (%x).\n", sb->s_id,
2349 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) & 2351 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) &
2350 ~EXT4_FEATURE_RO_COMPAT_SUPP)); 2352 ~EXT4_FEATURE_RO_COMPAT_SUPP));
2351 goto failed_mount; 2353 goto failed_mount;
2352 } 2354 }
2353 has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb, 2355 has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb,
2354 EXT4_FEATURE_RO_COMPAT_HUGE_FILE); 2356 EXT4_FEATURE_RO_COMPAT_HUGE_FILE);
2355 if (has_huge_files) { 2357 if (has_huge_files) {
2356 /* 2358 /*
2357 * Large file size enabled file system can only be 2359 * Large file size enabled file system can only be
2358 * mount if kernel is build with CONFIG_LBD 2360 * mount if kernel is build with CONFIG_LBD
2359 */ 2361 */
2360 if (sizeof(root->i_blocks) < sizeof(u64) && 2362 if (sizeof(root->i_blocks) < sizeof(u64) &&
2361 !(sb->s_flags & MS_RDONLY)) { 2363 !(sb->s_flags & MS_RDONLY)) {
2362 printk(KERN_ERR "EXT4-fs: %s: Filesystem with huge " 2364 printk(KERN_ERR "EXT4-fs: %s: Filesystem with huge "
2363 "files cannot be mounted read-write " 2365 "files cannot be mounted read-write "
2364 "without CONFIG_LBD.\n", sb->s_id); 2366 "without CONFIG_LBD.\n", sb->s_id);
2365 goto failed_mount; 2367 goto failed_mount;
2366 } 2368 }
2367 } 2369 }
2368 blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size); 2370 blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
2369 2371
2370 if (blocksize < EXT4_MIN_BLOCK_SIZE || 2372 if (blocksize < EXT4_MIN_BLOCK_SIZE ||
2371 blocksize > EXT4_MAX_BLOCK_SIZE) { 2373 blocksize > EXT4_MAX_BLOCK_SIZE) {
2372 printk(KERN_ERR 2374 printk(KERN_ERR
2373 "EXT4-fs: Unsupported filesystem blocksize %d on %s.\n", 2375 "EXT4-fs: Unsupported filesystem blocksize %d on %s.\n",
2374 blocksize, sb->s_id); 2376 blocksize, sb->s_id);
2375 goto failed_mount; 2377 goto failed_mount;
2376 } 2378 }
2377 2379
2378 if (sb->s_blocksize != blocksize) { 2380 if (sb->s_blocksize != blocksize) {
2379 2381
2380 /* Validate the filesystem blocksize */ 2382 /* Validate the filesystem blocksize */
2381 if (!sb_set_blocksize(sb, blocksize)) { 2383 if (!sb_set_blocksize(sb, blocksize)) {
2382 printk(KERN_ERR "EXT4-fs: bad block size %d.\n", 2384 printk(KERN_ERR "EXT4-fs: bad block size %d.\n",
2383 blocksize); 2385 blocksize);
2384 goto failed_mount; 2386 goto failed_mount;
2385 } 2387 }
2386 2388
2387 brelse(bh); 2389 brelse(bh);
2388 logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; 2390 logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
2389 offset = do_div(logical_sb_block, blocksize); 2391 offset = do_div(logical_sb_block, blocksize);
2390 bh = sb_bread(sb, logical_sb_block); 2392 bh = sb_bread(sb, logical_sb_block);
2391 if (!bh) { 2393 if (!bh) {
2392 printk(KERN_ERR 2394 printk(KERN_ERR
2393 "EXT4-fs: Can't read superblock on 2nd try.\n"); 2395 "EXT4-fs: Can't read superblock on 2nd try.\n");
2394 goto failed_mount; 2396 goto failed_mount;
2395 } 2397 }
2396 es = (struct ext4_super_block *)(((char *)bh->b_data) + offset); 2398 es = (struct ext4_super_block *)(((char *)bh->b_data) + offset);
2397 sbi->s_es = es; 2399 sbi->s_es = es;
2398 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) { 2400 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
2399 printk(KERN_ERR 2401 printk(KERN_ERR
2400 "EXT4-fs: Magic mismatch, very weird !\n"); 2402 "EXT4-fs: Magic mismatch, very weird !\n");
2401 goto failed_mount; 2403 goto failed_mount;
2402 } 2404 }
2403 } 2405 }
2404 2406
2405 sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits, 2407 sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits,
2406 has_huge_files); 2408 has_huge_files);
2407 sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files); 2409 sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files);
2408 2410
2409 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) { 2411 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
2410 sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE; 2412 sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
2411 sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO; 2413 sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;
2412 } else { 2414 } else {
2413 sbi->s_inode_size = le16_to_cpu(es->s_inode_size); 2415 sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
2414 sbi->s_first_ino = le32_to_cpu(es->s_first_ino); 2416 sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
2415 if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) || 2417 if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||
2416 (!is_power_of_2(sbi->s_inode_size)) || 2418 (!is_power_of_2(sbi->s_inode_size)) ||
2417 (sbi->s_inode_size > blocksize)) { 2419 (sbi->s_inode_size > blocksize)) {
2418 printk(KERN_ERR 2420 printk(KERN_ERR
2419 "EXT4-fs: unsupported inode size: %d\n", 2421 "EXT4-fs: unsupported inode size: %d\n",
2420 sbi->s_inode_size); 2422 sbi->s_inode_size);
2421 goto failed_mount; 2423 goto failed_mount;
2422 } 2424 }
2423 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) 2425 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
2424 sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2); 2426 sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
2425 } 2427 }
2426 sbi->s_desc_size = le16_to_cpu(es->s_desc_size); 2428 sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
2427 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) { 2429 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) {
2428 if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT || 2430 if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||
2429 sbi->s_desc_size > EXT4_MAX_DESC_SIZE || 2431 sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||
2430 !is_power_of_2(sbi->s_desc_size)) { 2432 !is_power_of_2(sbi->s_desc_size)) {
2431 printk(KERN_ERR 2433 printk(KERN_ERR
2432 "EXT4-fs: unsupported descriptor size %lu\n", 2434 "EXT4-fs: unsupported descriptor size %lu\n",
2433 sbi->s_desc_size); 2435 sbi->s_desc_size);
2434 goto failed_mount; 2436 goto failed_mount;
2435 } 2437 }
2436 } else 2438 } else
2437 sbi->s_desc_size = EXT4_MIN_DESC_SIZE; 2439 sbi->s_desc_size = EXT4_MIN_DESC_SIZE;
2438 sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); 2440 sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
2439 sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); 2441 sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
2440 if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0) 2442 if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0)
2441 goto cantfind_ext4; 2443 goto cantfind_ext4;
2442 sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb); 2444 sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
2443 if (sbi->s_inodes_per_block == 0) 2445 if (sbi->s_inodes_per_block == 0)
2444 goto cantfind_ext4; 2446 goto cantfind_ext4;
2445 sbi->s_itb_per_group = sbi->s_inodes_per_group / 2447 sbi->s_itb_per_group = sbi->s_inodes_per_group /
2446 sbi->s_inodes_per_block; 2448 sbi->s_inodes_per_block;
2447 sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb); 2449 sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);
2448 sbi->s_sbh = bh; 2450 sbi->s_sbh = bh;
2449 sbi->s_mount_state = le16_to_cpu(es->s_state); 2451 sbi->s_mount_state = le16_to_cpu(es->s_state);
2450 sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb)); 2452 sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
2451 sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb)); 2453 sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
2452 for (i = 0; i < 4; i++) 2454 for (i = 0; i < 4; i++)
2453 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); 2455 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
2454 sbi->s_def_hash_version = es->s_def_hash_version; 2456 sbi->s_def_hash_version = es->s_def_hash_version;
2455 i = le32_to_cpu(es->s_flags); 2457 i = le32_to_cpu(es->s_flags);
2456 if (i & EXT2_FLAGS_UNSIGNED_HASH) 2458 if (i & EXT2_FLAGS_UNSIGNED_HASH)
2457 sbi->s_hash_unsigned = 3; 2459 sbi->s_hash_unsigned = 3;
2458 else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) { 2460 else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) {
2459 #ifdef __CHAR_UNSIGNED__ 2461 #ifdef __CHAR_UNSIGNED__
2460 es->s_flags |= cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH); 2462 es->s_flags |= cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH);
2461 sbi->s_hash_unsigned = 3; 2463 sbi->s_hash_unsigned = 3;
2462 #else 2464 #else
2463 es->s_flags |= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH); 2465 es->s_flags |= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH);
2464 #endif 2466 #endif
2465 sb->s_dirt = 1; 2467 sb->s_dirt = 1;
2466 } 2468 }
2467 2469
2468 if (sbi->s_blocks_per_group > blocksize * 8) { 2470 if (sbi->s_blocks_per_group > blocksize * 8) {
2469 printk(KERN_ERR 2471 printk(KERN_ERR
2470 "EXT4-fs: #blocks per group too big: %lu\n", 2472 "EXT4-fs: #blocks per group too big: %lu\n",
2471 sbi->s_blocks_per_group); 2473 sbi->s_blocks_per_group);
2472 goto failed_mount; 2474 goto failed_mount;
2473 } 2475 }
2474 if (sbi->s_inodes_per_group > blocksize * 8) { 2476 if (sbi->s_inodes_per_group > blocksize * 8) {
2475 printk(KERN_ERR 2477 printk(KERN_ERR
2476 "EXT4-fs: #inodes per group too big: %lu\n", 2478 "EXT4-fs: #inodes per group too big: %lu\n",
2477 sbi->s_inodes_per_group); 2479 sbi->s_inodes_per_group);
2478 goto failed_mount; 2480 goto failed_mount;
2479 } 2481 }
2480 2482
2481 if (ext4_blocks_count(es) > 2483 if (ext4_blocks_count(es) >
2482 (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { 2484 (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
2483 printk(KERN_ERR "EXT4-fs: filesystem on %s:" 2485 printk(KERN_ERR "EXT4-fs: filesystem on %s:"
2484 " too large to mount safely\n", sb->s_id); 2486 " too large to mount safely\n", sb->s_id);
2485 if (sizeof(sector_t) < 8) 2487 if (sizeof(sector_t) < 8)
2486 printk(KERN_WARNING "EXT4-fs: CONFIG_LBD not " 2488 printk(KERN_WARNING "EXT4-fs: CONFIG_LBD not "
2487 "enabled\n"); 2489 "enabled\n");
2488 goto failed_mount; 2490 goto failed_mount;
2489 } 2491 }
2490 2492
2491 if (EXT4_BLOCKS_PER_GROUP(sb) == 0) 2493 if (EXT4_BLOCKS_PER_GROUP(sb) == 0)
2492 goto cantfind_ext4; 2494 goto cantfind_ext4;
2493 2495
2494 /* 2496 /*
2495 * It makes no sense for the first data block to be beyond the end 2497 * It makes no sense for the first data block to be beyond the end
2496 * of the filesystem. 2498 * of the filesystem.
2497 */ 2499 */
2498 if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) { 2500 if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) {
2499 printk(KERN_WARNING "EXT4-fs: bad geometry: first data" 2501 printk(KERN_WARNING "EXT4-fs: bad geometry: first data"
2500 "block %u is beyond end of filesystem (%llu)\n", 2502 "block %u is beyond end of filesystem (%llu)\n",
2501 le32_to_cpu(es->s_first_data_block), 2503 le32_to_cpu(es->s_first_data_block),
2502 ext4_blocks_count(es)); 2504 ext4_blocks_count(es));
2503 goto failed_mount; 2505 goto failed_mount;
2504 } 2506 }
2505 blocks_count = (ext4_blocks_count(es) - 2507 blocks_count = (ext4_blocks_count(es) -
2506 le32_to_cpu(es->s_first_data_block) + 2508 le32_to_cpu(es->s_first_data_block) +
2507 EXT4_BLOCKS_PER_GROUP(sb) - 1); 2509 EXT4_BLOCKS_PER_GROUP(sb) - 1);
2508 do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb)); 2510 do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));
2509 if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) { 2511 if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) {
2510 printk(KERN_WARNING "EXT4-fs: groups count too large: %u " 2512 printk(KERN_WARNING "EXT4-fs: groups count too large: %u "
2511 "(block count %llu, first data block %u, " 2513 "(block count %llu, first data block %u, "
2512 "blocks per group %lu)\n", sbi->s_groups_count, 2514 "blocks per group %lu)\n", sbi->s_groups_count,
2513 ext4_blocks_count(es), 2515 ext4_blocks_count(es),
2514 le32_to_cpu(es->s_first_data_block), 2516 le32_to_cpu(es->s_first_data_block),
2515 EXT4_BLOCKS_PER_GROUP(sb)); 2517 EXT4_BLOCKS_PER_GROUP(sb));
2516 goto failed_mount; 2518 goto failed_mount;
2517 } 2519 }
2518 sbi->s_groups_count = blocks_count; 2520 sbi->s_groups_count = blocks_count;
2519 db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) / 2521 db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
2520 EXT4_DESC_PER_BLOCK(sb); 2522 EXT4_DESC_PER_BLOCK(sb);
2521 sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *), 2523 sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *),
2522 GFP_KERNEL); 2524 GFP_KERNEL);
2523 if (sbi->s_group_desc == NULL) { 2525 if (sbi->s_group_desc == NULL) {
2524 printk(KERN_ERR "EXT4-fs: not enough memory\n"); 2526 printk(KERN_ERR "EXT4-fs: not enough memory\n");
2525 goto failed_mount; 2527 goto failed_mount;
2526 } 2528 }
2527 2529
2528 #ifdef CONFIG_PROC_FS 2530 #ifdef CONFIG_PROC_FS
2529 if (ext4_proc_root) 2531 if (ext4_proc_root)
2530 sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); 2532 sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
2531 #endif 2533 #endif
2532 2534
2533 bgl_lock_init(sbi->s_blockgroup_lock); 2535 bgl_lock_init(sbi->s_blockgroup_lock);
2534 2536
2535 for (i = 0; i < db_count; i++) { 2537 for (i = 0; i < db_count; i++) {
2536 block = descriptor_loc(sb, logical_sb_block, i); 2538 block = descriptor_loc(sb, logical_sb_block, i);
2537 sbi->s_group_desc[i] = sb_bread(sb, block); 2539 sbi->s_group_desc[i] = sb_bread(sb, block);
2538 if (!sbi->s_group_desc[i]) { 2540 if (!sbi->s_group_desc[i]) {
2539 printk(KERN_ERR "EXT4-fs: " 2541 printk(KERN_ERR "EXT4-fs: "
2540 "can't read group descriptor %d\n", i); 2542 "can't read group descriptor %d\n", i);
2541 db_count = i; 2543 db_count = i;
2542 goto failed_mount2; 2544 goto failed_mount2;
2543 } 2545 }
2544 } 2546 }
2545 if (!ext4_check_descriptors(sb)) { 2547 if (!ext4_check_descriptors(sb)) {
2546 printk(KERN_ERR "EXT4-fs: group descriptors corrupted!\n"); 2548 printk(KERN_ERR "EXT4-fs: group descriptors corrupted!\n");
2547 goto failed_mount2; 2549 goto failed_mount2;
2548 } 2550 }
2549 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) 2551 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
2550 if (!ext4_fill_flex_info(sb)) { 2552 if (!ext4_fill_flex_info(sb)) {
2551 printk(KERN_ERR 2553 printk(KERN_ERR
2552 "EXT4-fs: unable to initialize " 2554 "EXT4-fs: unable to initialize "
2553 "flex_bg meta info!\n"); 2555 "flex_bg meta info!\n");
2554 goto failed_mount2; 2556 goto failed_mount2;
2555 } 2557 }
2556 2558
2557 sbi->s_gdb_count = db_count; 2559 sbi->s_gdb_count = db_count;
2558 get_random_bytes(&sbi->s_next_generation, sizeof(u32)); 2560 get_random_bytes(&sbi->s_next_generation, sizeof(u32));
2559 spin_lock_init(&sbi->s_next_gen_lock); 2561 spin_lock_init(&sbi->s_next_gen_lock);
2560 2562
2561 err = percpu_counter_init(&sbi->s_freeblocks_counter, 2563 err = percpu_counter_init(&sbi->s_freeblocks_counter,
2562 ext4_count_free_blocks(sb)); 2564 ext4_count_free_blocks(sb));
2563 if (!err) { 2565 if (!err) {
2564 err = percpu_counter_init(&sbi->s_freeinodes_counter, 2566 err = percpu_counter_init(&sbi->s_freeinodes_counter,
2565 ext4_count_free_inodes(sb)); 2567 ext4_count_free_inodes(sb));
2566 } 2568 }
2567 if (!err) { 2569 if (!err) {
2568 err = percpu_counter_init(&sbi->s_dirs_counter, 2570 err = percpu_counter_init(&sbi->s_dirs_counter,
2569 ext4_count_dirs(sb)); 2571 ext4_count_dirs(sb));
2570 } 2572 }
2571 if (!err) { 2573 if (!err) {
2572 err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0); 2574 err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0);
2573 } 2575 }
2574 if (err) { 2576 if (err) {
2575 printk(KERN_ERR "EXT4-fs: insufficient memory\n"); 2577 printk(KERN_ERR "EXT4-fs: insufficient memory\n");
2576 goto failed_mount3; 2578 goto failed_mount3;
2577 } 2579 }
2578 2580
2579 sbi->s_stripe = ext4_get_stripe_size(sbi); 2581 sbi->s_stripe = ext4_get_stripe_size(sbi);
2580 2582
2581 /* 2583 /*
2582 * set up enough so that it can read an inode 2584 * set up enough so that it can read an inode
2583 */ 2585 */
2584 sb->s_op = &ext4_sops; 2586 sb->s_op = &ext4_sops;
2585 sb->s_export_op = &ext4_export_ops; 2587 sb->s_export_op = &ext4_export_ops;
2586 sb->s_xattr = ext4_xattr_handlers; 2588 sb->s_xattr = ext4_xattr_handlers;
2587 #ifdef CONFIG_QUOTA 2589 #ifdef CONFIG_QUOTA
2588 sb->s_qcop = &ext4_qctl_operations; 2590 sb->s_qcop = &ext4_qctl_operations;
2589 sb->dq_op = &ext4_quota_operations; 2591 sb->dq_op = &ext4_quota_operations;
2590 #endif 2592 #endif
2591 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ 2593 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
2592 2594
2593 sb->s_root = NULL; 2595 sb->s_root = NULL;
2594 2596
2595 needs_recovery = (es->s_last_orphan != 0 || 2597 needs_recovery = (es->s_last_orphan != 0 ||
2596 EXT4_HAS_INCOMPAT_FEATURE(sb, 2598 EXT4_HAS_INCOMPAT_FEATURE(sb,
2597 EXT4_FEATURE_INCOMPAT_RECOVER)); 2599 EXT4_FEATURE_INCOMPAT_RECOVER));
2598 2600
2599 /* 2601 /*
2600 * The first inode we look at is the journal inode. Don't try 2602 * The first inode we look at is the journal inode. Don't try
2601 * root first: it may be modified in the journal! 2603 * root first: it may be modified in the journal!
2602 */ 2604 */
2603 if (!test_opt(sb, NOLOAD) && 2605 if (!test_opt(sb, NOLOAD) &&
2604 EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) { 2606 EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
2605 if (ext4_load_journal(sb, es, journal_devnum)) 2607 if (ext4_load_journal(sb, es, journal_devnum))
2606 goto failed_mount3; 2608 goto failed_mount3;
2607 if (!(sb->s_flags & MS_RDONLY) && 2609 if (!(sb->s_flags & MS_RDONLY) &&
2608 EXT4_SB(sb)->s_journal->j_failed_commit) { 2610 EXT4_SB(sb)->s_journal->j_failed_commit) {
2609 printk(KERN_CRIT "EXT4-fs error (device %s): " 2611 printk(KERN_CRIT "EXT4-fs error (device %s): "
2610 "ext4_fill_super: Journal transaction " 2612 "ext4_fill_super: Journal transaction "
2611 "%u is corrupt\n", sb->s_id, 2613 "%u is corrupt\n", sb->s_id,
2612 EXT4_SB(sb)->s_journal->j_failed_commit); 2614 EXT4_SB(sb)->s_journal->j_failed_commit);
2613 if (test_opt(sb, ERRORS_RO)) { 2615 if (test_opt(sb, ERRORS_RO)) {
2614 printk(KERN_CRIT 2616 printk(KERN_CRIT
2615 "Mounting filesystem read-only\n"); 2617 "Mounting filesystem read-only\n");
2616 sb->s_flags |= MS_RDONLY; 2618 sb->s_flags |= MS_RDONLY;
2617 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 2619 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
2618 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 2620 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
2619 } 2621 }
2620 if (test_opt(sb, ERRORS_PANIC)) { 2622 if (test_opt(sb, ERRORS_PANIC)) {
2621 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 2623 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
2622 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 2624 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
2623 ext4_commit_super(sb, es, 1); 2625 ext4_commit_super(sb, es, 1);
2624 goto failed_mount4; 2626 goto failed_mount4;
2625 } 2627 }
2626 } 2628 }
2627 } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) && 2629 } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) &&
2628 EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { 2630 EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
2629 printk(KERN_ERR "EXT4-fs: required journal recovery " 2631 printk(KERN_ERR "EXT4-fs: required journal recovery "
2630 "suppressed and not mounted read-only\n"); 2632 "suppressed and not mounted read-only\n");
2631 goto failed_mount4; 2633 goto failed_mount4;
2632 } else { 2634 } else {
2633 clear_opt(sbi->s_mount_opt, DATA_FLAGS); 2635 clear_opt(sbi->s_mount_opt, DATA_FLAGS);
2634 set_opt(sbi->s_mount_opt, WRITEBACK_DATA); 2636 set_opt(sbi->s_mount_opt, WRITEBACK_DATA);
2635 sbi->s_journal = NULL; 2637 sbi->s_journal = NULL;
2636 needs_recovery = 0; 2638 needs_recovery = 0;
2637 goto no_journal; 2639 goto no_journal;
2638 } 2640 }
2639 2641
2640 if (ext4_blocks_count(es) > 0xffffffffULL && 2642 if (ext4_blocks_count(es) > 0xffffffffULL &&
2641 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0, 2643 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
2642 JBD2_FEATURE_INCOMPAT_64BIT)) { 2644 JBD2_FEATURE_INCOMPAT_64BIT)) {
2643 printk(KERN_ERR "EXT4-fs: Failed to set 64-bit journal feature\n"); 2645 printk(KERN_ERR "EXT4-fs: Failed to set 64-bit journal feature\n");
2644 goto failed_mount4; 2646 goto failed_mount4;
2645 } 2647 }
2646 2648
2647 if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) { 2649 if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
2648 jbd2_journal_set_features(sbi->s_journal, 2650 jbd2_journal_set_features(sbi->s_journal,
2649 JBD2_FEATURE_COMPAT_CHECKSUM, 0, 2651 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2650 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); 2652 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2651 } else if (test_opt(sb, JOURNAL_CHECKSUM)) { 2653 } else if (test_opt(sb, JOURNAL_CHECKSUM)) {
2652 jbd2_journal_set_features(sbi->s_journal, 2654 jbd2_journal_set_features(sbi->s_journal,
2653 JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0); 2655 JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0);
2654 jbd2_journal_clear_features(sbi->s_journal, 0, 0, 2656 jbd2_journal_clear_features(sbi->s_journal, 0, 0,
2655 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); 2657 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2656 } else { 2658 } else {
2657 jbd2_journal_clear_features(sbi->s_journal, 2659 jbd2_journal_clear_features(sbi->s_journal,
2658 JBD2_FEATURE_COMPAT_CHECKSUM, 0, 2660 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2659 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); 2661 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2660 } 2662 }
2661 2663
2662 /* We have now updated the journal if required, so we can 2664 /* We have now updated the journal if required, so we can
2663 * validate the data journaling mode. */ 2665 * validate the data journaling mode. */
2664 switch (test_opt(sb, DATA_FLAGS)) { 2666 switch (test_opt(sb, DATA_FLAGS)) {
2665 case 0: 2667 case 0:
2666 /* No mode set, assume a default based on the journal 2668 /* No mode set, assume a default based on the journal
2667 * capabilities: ORDERED_DATA if the journal can 2669 * capabilities: ORDERED_DATA if the journal can
2668 * cope, else JOURNAL_DATA 2670 * cope, else JOURNAL_DATA
2669 */ 2671 */
2670 if (jbd2_journal_check_available_features 2672 if (jbd2_journal_check_available_features
2671 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) 2673 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE))
2672 set_opt(sbi->s_mount_opt, ORDERED_DATA); 2674 set_opt(sbi->s_mount_opt, ORDERED_DATA);
2673 else 2675 else
2674 set_opt(sbi->s_mount_opt, JOURNAL_DATA); 2676 set_opt(sbi->s_mount_opt, JOURNAL_DATA);
2675 break; 2677 break;
2676 2678
2677 case EXT4_MOUNT_ORDERED_DATA: 2679 case EXT4_MOUNT_ORDERED_DATA:
2678 case EXT4_MOUNT_WRITEBACK_DATA: 2680 case EXT4_MOUNT_WRITEBACK_DATA:
2679 if (!jbd2_journal_check_available_features 2681 if (!jbd2_journal_check_available_features
2680 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) { 2682 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) {
2681 printk(KERN_ERR "EXT4-fs: Journal does not support " 2683 printk(KERN_ERR "EXT4-fs: Journal does not support "
2682 "requested data journaling mode\n"); 2684 "requested data journaling mode\n");
2683 goto failed_mount4; 2685 goto failed_mount4;
2684 } 2686 }
2685 default: 2687 default:
2686 break; 2688 break;
2687 } 2689 }
2688 set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); 2690 set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
2689 2691
2690 no_journal: 2692 no_journal:
2691 2693
2692 if (test_opt(sb, NOBH)) { 2694 if (test_opt(sb, NOBH)) {
2693 if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) { 2695 if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) {
2694 printk(KERN_WARNING "EXT4-fs: Ignoring nobh option - " 2696 printk(KERN_WARNING "EXT4-fs: Ignoring nobh option - "
2695 "its supported only with writeback mode\n"); 2697 "its supported only with writeback mode\n");
2696 clear_opt(sbi->s_mount_opt, NOBH); 2698 clear_opt(sbi->s_mount_opt, NOBH);
2697 } 2699 }
2698 } 2700 }
2699 /* 2701 /*
2700 * The jbd2_journal_load will have done any necessary log recovery, 2702 * The jbd2_journal_load will have done any necessary log recovery,
2701 * so we can safely mount the rest of the filesystem now. 2703 * so we can safely mount the rest of the filesystem now.
2702 */ 2704 */
2703 2705
2704 root = ext4_iget(sb, EXT4_ROOT_INO); 2706 root = ext4_iget(sb, EXT4_ROOT_INO);
2705 if (IS_ERR(root)) { 2707 if (IS_ERR(root)) {
2706 printk(KERN_ERR "EXT4-fs: get root inode failed\n"); 2708 printk(KERN_ERR "EXT4-fs: get root inode failed\n");
2707 ret = PTR_ERR(root); 2709 ret = PTR_ERR(root);
2708 goto failed_mount4; 2710 goto failed_mount4;
2709 } 2711 }
2710 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { 2712 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
2711 iput(root); 2713 iput(root);
2712 printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n"); 2714 printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n");
2713 goto failed_mount4; 2715 goto failed_mount4;
2714 } 2716 }
2715 sb->s_root = d_alloc_root(root); 2717 sb->s_root = d_alloc_root(root);
2716 if (!sb->s_root) { 2718 if (!sb->s_root) {
2717 printk(KERN_ERR "EXT4-fs: get root dentry failed\n"); 2719 printk(KERN_ERR "EXT4-fs: get root dentry failed\n");
2718 iput(root); 2720 iput(root);
2719 ret = -ENOMEM; 2721 ret = -ENOMEM;
2720 goto failed_mount4; 2722 goto failed_mount4;
2721 } 2723 }
2722 2724
2723 ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY); 2725 ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY);
2724 2726
2725 /* determine the minimum size of new large inodes, if present */ 2727 /* determine the minimum size of new large inodes, if present */
2726 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) { 2728 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
2727 sbi->s_want_extra_isize = sizeof(struct ext4_inode) - 2729 sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
2728 EXT4_GOOD_OLD_INODE_SIZE; 2730 EXT4_GOOD_OLD_INODE_SIZE;
2729 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 2731 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
2730 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) { 2732 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) {
2731 if (sbi->s_want_extra_isize < 2733 if (sbi->s_want_extra_isize <
2732 le16_to_cpu(es->s_want_extra_isize)) 2734 le16_to_cpu(es->s_want_extra_isize))
2733 sbi->s_want_extra_isize = 2735 sbi->s_want_extra_isize =
2734 le16_to_cpu(es->s_want_extra_isize); 2736 le16_to_cpu(es->s_want_extra_isize);
2735 if (sbi->s_want_extra_isize < 2737 if (sbi->s_want_extra_isize <
2736 le16_to_cpu(es->s_min_extra_isize)) 2738 le16_to_cpu(es->s_min_extra_isize))
2737 sbi->s_want_extra_isize = 2739 sbi->s_want_extra_isize =
2738 le16_to_cpu(es->s_min_extra_isize); 2740 le16_to_cpu(es->s_min_extra_isize);
2739 } 2741 }
2740 } 2742 }
2741 /* Check if enough inode space is available */ 2743 /* Check if enough inode space is available */
2742 if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize > 2744 if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize >
2743 sbi->s_inode_size) { 2745 sbi->s_inode_size) {
2744 sbi->s_want_extra_isize = sizeof(struct ext4_inode) - 2746 sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
2745 EXT4_GOOD_OLD_INODE_SIZE; 2747 EXT4_GOOD_OLD_INODE_SIZE;
2746 printk(KERN_INFO "EXT4-fs: required extra inode space not" 2748 printk(KERN_INFO "EXT4-fs: required extra inode space not"
2747 "available.\n"); 2749 "available.\n");
2748 } 2750 }
2749 2751
2750 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) { 2752 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
2751 printk(KERN_WARNING "EXT4-fs: Ignoring delalloc option - " 2753 printk(KERN_WARNING "EXT4-fs: Ignoring delalloc option - "
2752 "requested data journaling mode\n"); 2754 "requested data journaling mode\n");
2753 clear_opt(sbi->s_mount_opt, DELALLOC); 2755 clear_opt(sbi->s_mount_opt, DELALLOC);
2754 } else if (test_opt(sb, DELALLOC)) 2756 } else if (test_opt(sb, DELALLOC))
2755 printk(KERN_INFO "EXT4-fs: delayed allocation enabled\n"); 2757 printk(KERN_INFO "EXT4-fs: delayed allocation enabled\n");
2756 2758
2757 ext4_ext_init(sb); 2759 ext4_ext_init(sb);
2758 err = ext4_mb_init(sb, needs_recovery); 2760 err = ext4_mb_init(sb, needs_recovery);
2759 if (err) { 2761 if (err) {
2760 printk(KERN_ERR "EXT4-fs: failed to initalize mballoc (%d)\n", 2762 printk(KERN_ERR "EXT4-fs: failed to initalize mballoc (%d)\n",
2761 err); 2763 err);
2762 goto failed_mount4; 2764 goto failed_mount4;
2763 } 2765 }
2764 2766
2765 sbi->s_kobj.kset = ext4_kset; 2767 sbi->s_kobj.kset = ext4_kset;
2766 init_completion(&sbi->s_kobj_unregister); 2768 init_completion(&sbi->s_kobj_unregister);
2767 err = kobject_init_and_add(&sbi->s_kobj, &ext4_ktype, NULL, 2769 err = kobject_init_and_add(&sbi->s_kobj, &ext4_ktype, NULL,
2768 "%s", sb->s_id); 2770 "%s", sb->s_id);
2769 if (err) { 2771 if (err) {
2770 ext4_mb_release(sb); 2772 ext4_mb_release(sb);
2771 ext4_ext_release(sb); 2773 ext4_ext_release(sb);
2772 goto failed_mount4; 2774 goto failed_mount4;
2773 }; 2775 };
2774 2776
2775 /* 2777 /*
2776 * akpm: core read_super() calls in here with the superblock locked. 2778 * akpm: core read_super() calls in here with the superblock locked.
2777 * That deadlocks, because orphan cleanup needs to lock the superblock 2779 * That deadlocks, because orphan cleanup needs to lock the superblock
2778 * in numerous places. Here we just pop the lock - it's relatively 2780 * in numerous places. Here we just pop the lock - it's relatively
2779 * harmless, because we are now ready to accept write_super() requests, 2781 * harmless, because we are now ready to accept write_super() requests,
2780 * and aviro says that's the only reason for hanging onto the 2782 * and aviro says that's the only reason for hanging onto the
2781 * superblock lock. 2783 * superblock lock.
2782 */ 2784 */
2783 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; 2785 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
2784 ext4_orphan_cleanup(sb, es); 2786 ext4_orphan_cleanup(sb, es);
2785 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS; 2787 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
2786 if (needs_recovery) { 2788 if (needs_recovery) {
2787 printk(KERN_INFO "EXT4-fs: recovery complete.\n"); 2789 printk(KERN_INFO "EXT4-fs: recovery complete.\n");
2788 ext4_mark_recovery_complete(sb, es); 2790 ext4_mark_recovery_complete(sb, es);
2789 } 2791 }
2790 if (EXT4_SB(sb)->s_journal) { 2792 if (EXT4_SB(sb)->s_journal) {
2791 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) 2793 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
2792 descr = " journalled data mode"; 2794 descr = " journalled data mode";
2793 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) 2795 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
2794 descr = " ordered data mode"; 2796 descr = " ordered data mode";
2795 else 2797 else
2796 descr = " writeback data mode"; 2798 descr = " writeback data mode";
2797 } else 2799 } else
2798 descr = "out journal"; 2800 descr = "out journal";
2799 2801
2800 printk(KERN_INFO "EXT4-fs: mounted filesystem %s with%s\n", 2802 printk(KERN_INFO "EXT4-fs: mounted filesystem %s with%s\n",
2801 sb->s_id, descr); 2803 sb->s_id, descr);
2802 2804
2803 lock_kernel(); 2805 lock_kernel();
2804 return 0; 2806 return 0;
2805 2807
2806 cantfind_ext4: 2808 cantfind_ext4:
2807 if (!silent) 2809 if (!silent)
2808 printk(KERN_ERR "VFS: Can't find ext4 filesystem on dev %s.\n", 2810 printk(KERN_ERR "VFS: Can't find ext4 filesystem on dev %s.\n",
2809 sb->s_id); 2811 sb->s_id);
2810 goto failed_mount; 2812 goto failed_mount;
2811 2813
2812 failed_mount4: 2814 failed_mount4:
2813 printk(KERN_ERR "EXT4-fs (device %s): mount failed\n", sb->s_id); 2815 printk(KERN_ERR "EXT4-fs (device %s): mount failed\n", sb->s_id);
2814 if (sbi->s_journal) { 2816 if (sbi->s_journal) {
2815 jbd2_journal_destroy(sbi->s_journal); 2817 jbd2_journal_destroy(sbi->s_journal);
2816 sbi->s_journal = NULL; 2818 sbi->s_journal = NULL;
2817 } 2819 }
2818 failed_mount3: 2820 failed_mount3:
2819 percpu_counter_destroy(&sbi->s_freeblocks_counter); 2821 percpu_counter_destroy(&sbi->s_freeblocks_counter);
2820 percpu_counter_destroy(&sbi->s_freeinodes_counter); 2822 percpu_counter_destroy(&sbi->s_freeinodes_counter);
2821 percpu_counter_destroy(&sbi->s_dirs_counter); 2823 percpu_counter_destroy(&sbi->s_dirs_counter);
2822 percpu_counter_destroy(&sbi->s_dirtyblocks_counter); 2824 percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
2823 failed_mount2: 2825 failed_mount2:
2824 for (i = 0; i < db_count; i++) 2826 for (i = 0; i < db_count; i++)
2825 brelse(sbi->s_group_desc[i]); 2827 brelse(sbi->s_group_desc[i]);
2826 kfree(sbi->s_group_desc); 2828 kfree(sbi->s_group_desc);
2827 failed_mount: 2829 failed_mount:
2828 if (sbi->s_proc) { 2830 if (sbi->s_proc) {
2829 remove_proc_entry(sb->s_id, ext4_proc_root); 2831 remove_proc_entry(sb->s_id, ext4_proc_root);
2830 } 2832 }
2831 #ifdef CONFIG_QUOTA 2833 #ifdef CONFIG_QUOTA
2832 for (i = 0; i < MAXQUOTAS; i++) 2834 for (i = 0; i < MAXQUOTAS; i++)
2833 kfree(sbi->s_qf_names[i]); 2835 kfree(sbi->s_qf_names[i]);
2834 #endif 2836 #endif
2835 ext4_blkdev_remove(sbi); 2837 ext4_blkdev_remove(sbi);
2836 brelse(bh); 2838 brelse(bh);
2837 out_fail: 2839 out_fail:
2838 sb->s_fs_info = NULL; 2840 sb->s_fs_info = NULL;
2839 kfree(sbi); 2841 kfree(sbi);
2840 lock_kernel(); 2842 lock_kernel();
2841 return ret; 2843 return ret;
2842 } 2844 }
2843 2845
2844 /* 2846 /*
2845 * Setup any per-fs journal parameters now. We'll do this both on 2847 * Setup any per-fs journal parameters now. We'll do this both on
2846 * initial mount, once the journal has been initialised but before we've 2848 * initial mount, once the journal has been initialised but before we've
2847 * done any recovery; and again on any subsequent remount. 2849 * done any recovery; and again on any subsequent remount.
2848 */ 2850 */
2849 static void ext4_init_journal_params(struct super_block *sb, journal_t *journal) 2851 static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
2850 { 2852 {
2851 struct ext4_sb_info *sbi = EXT4_SB(sb); 2853 struct ext4_sb_info *sbi = EXT4_SB(sb);
2852 2854
2853 journal->j_commit_interval = sbi->s_commit_interval; 2855 journal->j_commit_interval = sbi->s_commit_interval;
2854 journal->j_min_batch_time = sbi->s_min_batch_time; 2856 journal->j_min_batch_time = sbi->s_min_batch_time;
2855 journal->j_max_batch_time = sbi->s_max_batch_time; 2857 journal->j_max_batch_time = sbi->s_max_batch_time;
2856 2858
2857 spin_lock(&journal->j_state_lock); 2859 spin_lock(&journal->j_state_lock);
2858 if (test_opt(sb, BARRIER)) 2860 if (test_opt(sb, BARRIER))
2859 journal->j_flags |= JBD2_BARRIER; 2861 journal->j_flags |= JBD2_BARRIER;
2860 else 2862 else
2861 journal->j_flags &= ~JBD2_BARRIER; 2863 journal->j_flags &= ~JBD2_BARRIER;
2862 if (test_opt(sb, DATA_ERR_ABORT)) 2864 if (test_opt(sb, DATA_ERR_ABORT))
2863 journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR; 2865 journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR;
2864 else 2866 else
2865 journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR; 2867 journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR;
2866 spin_unlock(&journal->j_state_lock); 2868 spin_unlock(&journal->j_state_lock);
2867 } 2869 }
2868 2870
2869 static journal_t *ext4_get_journal(struct super_block *sb, 2871 static journal_t *ext4_get_journal(struct super_block *sb,
2870 unsigned int journal_inum) 2872 unsigned int journal_inum)
2871 { 2873 {
2872 struct inode *journal_inode; 2874 struct inode *journal_inode;
2873 journal_t *journal; 2875 journal_t *journal;
2874 2876
2875 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 2877 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
2876 2878
2877 /* First, test for the existence of a valid inode on disk. Bad 2879 /* First, test for the existence of a valid inode on disk. Bad
2878 * things happen if we iget() an unused inode, as the subsequent 2880 * things happen if we iget() an unused inode, as the subsequent
2879 * iput() will try to delete it. */ 2881 * iput() will try to delete it. */
2880 2882
2881 journal_inode = ext4_iget(sb, journal_inum); 2883 journal_inode = ext4_iget(sb, journal_inum);
2882 if (IS_ERR(journal_inode)) { 2884 if (IS_ERR(journal_inode)) {
2883 printk(KERN_ERR "EXT4-fs: no journal found.\n"); 2885 printk(KERN_ERR "EXT4-fs: no journal found.\n");
2884 return NULL; 2886 return NULL;
2885 } 2887 }
2886 if (!journal_inode->i_nlink) { 2888 if (!journal_inode->i_nlink) {
2887 make_bad_inode(journal_inode); 2889 make_bad_inode(journal_inode);
2888 iput(journal_inode); 2890 iput(journal_inode);
2889 printk(KERN_ERR "EXT4-fs: journal inode is deleted.\n"); 2891 printk(KERN_ERR "EXT4-fs: journal inode is deleted.\n");
2890 return NULL; 2892 return NULL;
2891 } 2893 }
2892 2894
2893 jbd_debug(2, "Journal inode found at %p: %lld bytes\n", 2895 jbd_debug(2, "Journal inode found at %p: %lld bytes\n",
2894 journal_inode, journal_inode->i_size); 2896 journal_inode, journal_inode->i_size);
2895 if (!S_ISREG(journal_inode->i_mode)) { 2897 if (!S_ISREG(journal_inode->i_mode)) {
2896 printk(KERN_ERR "EXT4-fs: invalid journal inode.\n"); 2898 printk(KERN_ERR "EXT4-fs: invalid journal inode.\n");
2897 iput(journal_inode); 2899 iput(journal_inode);
2898 return NULL; 2900 return NULL;
2899 } 2901 }
2900 2902
2901 journal = jbd2_journal_init_inode(journal_inode); 2903 journal = jbd2_journal_init_inode(journal_inode);
2902 if (!journal) { 2904 if (!journal) {
2903 printk(KERN_ERR "EXT4-fs: Could not load journal inode\n"); 2905 printk(KERN_ERR "EXT4-fs: Could not load journal inode\n");
2904 iput(journal_inode); 2906 iput(journal_inode);
2905 return NULL; 2907 return NULL;
2906 } 2908 }
2907 journal->j_private = sb; 2909 journal->j_private = sb;
2908 ext4_init_journal_params(sb, journal); 2910 ext4_init_journal_params(sb, journal);
2909 return journal; 2911 return journal;
2910 } 2912 }
2911 2913
2912 static journal_t *ext4_get_dev_journal(struct super_block *sb, 2914 static journal_t *ext4_get_dev_journal(struct super_block *sb,
2913 dev_t j_dev) 2915 dev_t j_dev)
2914 { 2916 {
2915 struct buffer_head *bh; 2917 struct buffer_head *bh;
2916 journal_t *journal; 2918 journal_t *journal;
2917 ext4_fsblk_t start; 2919 ext4_fsblk_t start;
2918 ext4_fsblk_t len; 2920 ext4_fsblk_t len;
2919 int hblock, blocksize; 2921 int hblock, blocksize;
2920 ext4_fsblk_t sb_block; 2922 ext4_fsblk_t sb_block;
2921 unsigned long offset; 2923 unsigned long offset;
2922 struct ext4_super_block *es; 2924 struct ext4_super_block *es;
2923 struct block_device *bdev; 2925 struct block_device *bdev;
2924 2926
2925 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 2927 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
2926 2928
2927 bdev = ext4_blkdev_get(j_dev); 2929 bdev = ext4_blkdev_get(j_dev);
2928 if (bdev == NULL) 2930 if (bdev == NULL)
2929 return NULL; 2931 return NULL;
2930 2932
2931 if (bd_claim(bdev, sb)) { 2933 if (bd_claim(bdev, sb)) {
2932 printk(KERN_ERR 2934 printk(KERN_ERR
2933 "EXT4-fs: failed to claim external journal device.\n"); 2935 "EXT4-fs: failed to claim external journal device.\n");
2934 blkdev_put(bdev, FMODE_READ|FMODE_WRITE); 2936 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
2935 return NULL; 2937 return NULL;
2936 } 2938 }
2937 2939
2938 blocksize = sb->s_blocksize; 2940 blocksize = sb->s_blocksize;
2939 hblock = bdev_hardsect_size(bdev); 2941 hblock = bdev_hardsect_size(bdev);
2940 if (blocksize < hblock) { 2942 if (blocksize < hblock) {
2941 printk(KERN_ERR 2943 printk(KERN_ERR
2942 "EXT4-fs: blocksize too small for journal device.\n"); 2944 "EXT4-fs: blocksize too small for journal device.\n");
2943 goto out_bdev; 2945 goto out_bdev;
2944 } 2946 }
2945 2947
2946 sb_block = EXT4_MIN_BLOCK_SIZE / blocksize; 2948 sb_block = EXT4_MIN_BLOCK_SIZE / blocksize;
2947 offset = EXT4_MIN_BLOCK_SIZE % blocksize; 2949 offset = EXT4_MIN_BLOCK_SIZE % blocksize;
2948 set_blocksize(bdev, blocksize); 2950 set_blocksize(bdev, blocksize);
2949 if (!(bh = __bread(bdev, sb_block, blocksize))) { 2951 if (!(bh = __bread(bdev, sb_block, blocksize))) {
2950 printk(KERN_ERR "EXT4-fs: couldn't read superblock of " 2952 printk(KERN_ERR "EXT4-fs: couldn't read superblock of "
2951 "external journal\n"); 2953 "external journal\n");
2952 goto out_bdev; 2954 goto out_bdev;
2953 } 2955 }
2954 2956
2955 es = (struct ext4_super_block *) (((char *)bh->b_data) + offset); 2957 es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
2956 if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) || 2958 if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) ||
2957 !(le32_to_cpu(es->s_feature_incompat) & 2959 !(le32_to_cpu(es->s_feature_incompat) &
2958 EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) { 2960 EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
2959 printk(KERN_ERR "EXT4-fs: external journal has " 2961 printk(KERN_ERR "EXT4-fs: external journal has "
2960 "bad superblock\n"); 2962 "bad superblock\n");
2961 brelse(bh); 2963 brelse(bh);
2962 goto out_bdev; 2964 goto out_bdev;
2963 } 2965 }
2964 2966
2965 if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { 2967 if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
2966 printk(KERN_ERR "EXT4-fs: journal UUID does not match\n"); 2968 printk(KERN_ERR "EXT4-fs: journal UUID does not match\n");
2967 brelse(bh); 2969 brelse(bh);
2968 goto out_bdev; 2970 goto out_bdev;
2969 } 2971 }
2970 2972
2971 len = ext4_blocks_count(es); 2973 len = ext4_blocks_count(es);
2972 start = sb_block + 1; 2974 start = sb_block + 1;
2973 brelse(bh); /* we're done with the superblock */ 2975 brelse(bh); /* we're done with the superblock */
2974 2976
2975 journal = jbd2_journal_init_dev(bdev, sb->s_bdev, 2977 journal = jbd2_journal_init_dev(bdev, sb->s_bdev,
2976 start, len, blocksize); 2978 start, len, blocksize);
2977 if (!journal) { 2979 if (!journal) {
2978 printk(KERN_ERR "EXT4-fs: failed to create device journal\n"); 2980 printk(KERN_ERR "EXT4-fs: failed to create device journal\n");
2979 goto out_bdev; 2981 goto out_bdev;
2980 } 2982 }
2981 journal->j_private = sb; 2983 journal->j_private = sb;
2982 ll_rw_block(READ, 1, &journal->j_sb_buffer); 2984 ll_rw_block(READ, 1, &journal->j_sb_buffer);
2983 wait_on_buffer(journal->j_sb_buffer); 2985 wait_on_buffer(journal->j_sb_buffer);
2984 if (!buffer_uptodate(journal->j_sb_buffer)) { 2986 if (!buffer_uptodate(journal->j_sb_buffer)) {
2985 printk(KERN_ERR "EXT4-fs: I/O error on journal device\n"); 2987 printk(KERN_ERR "EXT4-fs: I/O error on journal device\n");
2986 goto out_journal; 2988 goto out_journal;
2987 } 2989 }
2988 if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) { 2990 if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
2989 printk(KERN_ERR "EXT4-fs: External journal has more than one " 2991 printk(KERN_ERR "EXT4-fs: External journal has more than one "
2990 "user (unsupported) - %d\n", 2992 "user (unsupported) - %d\n",
2991 be32_to_cpu(journal->j_superblock->s_nr_users)); 2993 be32_to_cpu(journal->j_superblock->s_nr_users));
2992 goto out_journal; 2994 goto out_journal;
2993 } 2995 }
2994 EXT4_SB(sb)->journal_bdev = bdev; 2996 EXT4_SB(sb)->journal_bdev = bdev;
2995 ext4_init_journal_params(sb, journal); 2997 ext4_init_journal_params(sb, journal);
2996 return journal; 2998 return journal;
2997 out_journal: 2999 out_journal:
2998 jbd2_journal_destroy(journal); 3000 jbd2_journal_destroy(journal);
2999 out_bdev: 3001 out_bdev:
3000 ext4_blkdev_put(bdev); 3002 ext4_blkdev_put(bdev);
3001 return NULL; 3003 return NULL;
3002 } 3004 }
3003 3005
3004 static int ext4_load_journal(struct super_block *sb, 3006 static int ext4_load_journal(struct super_block *sb,
3005 struct ext4_super_block *es, 3007 struct ext4_super_block *es,
3006 unsigned long journal_devnum) 3008 unsigned long journal_devnum)
3007 { 3009 {
3008 journal_t *journal; 3010 journal_t *journal;
3009 unsigned int journal_inum = le32_to_cpu(es->s_journal_inum); 3011 unsigned int journal_inum = le32_to_cpu(es->s_journal_inum);
3010 dev_t journal_dev; 3012 dev_t journal_dev;
3011 int err = 0; 3013 int err = 0;
3012 int really_read_only; 3014 int really_read_only;
3013 3015
3014 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 3016 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
3015 3017
3016 if (journal_devnum && 3018 if (journal_devnum &&
3017 journal_devnum != le32_to_cpu(es->s_journal_dev)) { 3019 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
3018 printk(KERN_INFO "EXT4-fs: external journal device major/minor " 3020 printk(KERN_INFO "EXT4-fs: external journal device major/minor "
3019 "numbers have changed\n"); 3021 "numbers have changed\n");
3020 journal_dev = new_decode_dev(journal_devnum); 3022 journal_dev = new_decode_dev(journal_devnum);
3021 } else 3023 } else
3022 journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev)); 3024 journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
3023 3025
3024 really_read_only = bdev_read_only(sb->s_bdev); 3026 really_read_only = bdev_read_only(sb->s_bdev);
3025 3027
3026 /* 3028 /*
3027 * Are we loading a blank journal or performing recovery after a 3029 * Are we loading a blank journal or performing recovery after a
3028 * crash? For recovery, we need to check in advance whether we 3030 * crash? For recovery, we need to check in advance whether we
3029 * can get read-write access to the device. 3031 * can get read-write access to the device.
3030 */ 3032 */
3031 3033
3032 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { 3034 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
3033 if (sb->s_flags & MS_RDONLY) { 3035 if (sb->s_flags & MS_RDONLY) {
3034 printk(KERN_INFO "EXT4-fs: INFO: recovery " 3036 printk(KERN_INFO "EXT4-fs: INFO: recovery "
3035 "required on readonly filesystem.\n"); 3037 "required on readonly filesystem.\n");
3036 if (really_read_only) { 3038 if (really_read_only) {
3037 printk(KERN_ERR "EXT4-fs: write access " 3039 printk(KERN_ERR "EXT4-fs: write access "
3038 "unavailable, cannot proceed.\n"); 3040 "unavailable, cannot proceed.\n");
3039 return -EROFS; 3041 return -EROFS;
3040 } 3042 }
3041 printk(KERN_INFO "EXT4-fs: write access will " 3043 printk(KERN_INFO "EXT4-fs: write access will "
3042 "be enabled during recovery.\n"); 3044 "be enabled during recovery.\n");
3043 } 3045 }
3044 } 3046 }
3045 3047
3046 if (journal_inum && journal_dev) { 3048 if (journal_inum && journal_dev) {
3047 printk(KERN_ERR "EXT4-fs: filesystem has both journal " 3049 printk(KERN_ERR "EXT4-fs: filesystem has both journal "
3048 "and inode journals!\n"); 3050 "and inode journals!\n");
3049 return -EINVAL; 3051 return -EINVAL;
3050 } 3052 }
3051 3053
3052 if (journal_inum) { 3054 if (journal_inum) {
3053 if (!(journal = ext4_get_journal(sb, journal_inum))) 3055 if (!(journal = ext4_get_journal(sb, journal_inum)))
3054 return -EINVAL; 3056 return -EINVAL;
3055 } else { 3057 } else {
3056 if (!(journal = ext4_get_dev_journal(sb, journal_dev))) 3058 if (!(journal = ext4_get_dev_journal(sb, journal_dev)))
3057 return -EINVAL; 3059 return -EINVAL;
3058 } 3060 }
3059 3061
3060 if (journal->j_flags & JBD2_BARRIER) 3062 if (journal->j_flags & JBD2_BARRIER)
3061 printk(KERN_INFO "EXT4-fs: barriers enabled\n"); 3063 printk(KERN_INFO "EXT4-fs: barriers enabled\n");
3062 else 3064 else
3063 printk(KERN_INFO "EXT4-fs: barriers disabled\n"); 3065 printk(KERN_INFO "EXT4-fs: barriers disabled\n");
3064 3066
3065 if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) { 3067 if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) {
3066 err = jbd2_journal_update_format(journal); 3068 err = jbd2_journal_update_format(journal);
3067 if (err) { 3069 if (err) {
3068 printk(KERN_ERR "EXT4-fs: error updating journal.\n"); 3070 printk(KERN_ERR "EXT4-fs: error updating journal.\n");
3069 jbd2_journal_destroy(journal); 3071 jbd2_journal_destroy(journal);
3070 return err; 3072 return err;
3071 } 3073 }
3072 } 3074 }
3073 3075
3074 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) 3076 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER))
3075 err = jbd2_journal_wipe(journal, !really_read_only); 3077 err = jbd2_journal_wipe(journal, !really_read_only);
3076 if (!err) 3078 if (!err)
3077 err = jbd2_journal_load(journal); 3079 err = jbd2_journal_load(journal);
3078 3080
3079 if (err) { 3081 if (err) {
3080 printk(KERN_ERR "EXT4-fs: error loading journal.\n"); 3082 printk(KERN_ERR "EXT4-fs: error loading journal.\n");
3081 jbd2_journal_destroy(journal); 3083 jbd2_journal_destroy(journal);
3082 return err; 3084 return err;
3083 } 3085 }
3084 3086
3085 EXT4_SB(sb)->s_journal = journal; 3087 EXT4_SB(sb)->s_journal = journal;
3086 ext4_clear_journal_err(sb, es); 3088 ext4_clear_journal_err(sb, es);
3087 3089
3088 if (journal_devnum && 3090 if (journal_devnum &&
3089 journal_devnum != le32_to_cpu(es->s_journal_dev)) { 3091 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
3090 es->s_journal_dev = cpu_to_le32(journal_devnum); 3092 es->s_journal_dev = cpu_to_le32(journal_devnum);
3091 sb->s_dirt = 1; 3093 sb->s_dirt = 1;
3092 3094
3093 /* Make sure we flush the recovery flag to disk. */ 3095 /* Make sure we flush the recovery flag to disk. */
3094 ext4_commit_super(sb, es, 1); 3096 ext4_commit_super(sb, es, 1);
3095 } 3097 }
3096 3098
3097 return 0; 3099 return 0;
3098 } 3100 }
3099 3101
3100 static int ext4_commit_super(struct super_block *sb, 3102 static int ext4_commit_super(struct super_block *sb,
3101 struct ext4_super_block *es, int sync) 3103 struct ext4_super_block *es, int sync)
3102 { 3104 {
3103 struct buffer_head *sbh = EXT4_SB(sb)->s_sbh; 3105 struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
3104 int error = 0; 3106 int error = 0;
3105 3107
3106 if (!sbh) 3108 if (!sbh)
3107 return error; 3109 return error;
3108 if (buffer_write_io_error(sbh)) { 3110 if (buffer_write_io_error(sbh)) {
3109 /* 3111 /*
3110 * Oh, dear. A previous attempt to write the 3112 * Oh, dear. A previous attempt to write the
3111 * superblock failed. This could happen because the 3113 * superblock failed. This could happen because the
3112 * USB device was yanked out. Or it could happen to 3114 * USB device was yanked out. Or it could happen to
3113 * be a transient write error and maybe the block will 3115 * be a transient write error and maybe the block will
3114 * be remapped. Nothing we can do but to retry the 3116 * be remapped. Nothing we can do but to retry the
3115 * write and hope for the best. 3117 * write and hope for the best.
3116 */ 3118 */
3117 printk(KERN_ERR "EXT4-fs: previous I/O error to " 3119 printk(KERN_ERR "EXT4-fs: previous I/O error to "
3118 "superblock detected for %s.\n", sb->s_id); 3120 "superblock detected for %s.\n", sb->s_id);
3119 clear_buffer_write_io_error(sbh); 3121 clear_buffer_write_io_error(sbh);
3120 set_buffer_uptodate(sbh); 3122 set_buffer_uptodate(sbh);
3121 } 3123 }
3122 es->s_wtime = cpu_to_le32(get_seconds()); 3124 es->s_wtime = cpu_to_le32(get_seconds());
3123 es->s_kbytes_written = 3125 es->s_kbytes_written =
3124 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + 3126 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written +
3125 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 3127 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
3126 EXT4_SB(sb)->s_sectors_written_start) >> 1)); 3128 EXT4_SB(sb)->s_sectors_written_start) >> 1));
3127 ext4_free_blocks_count_set(es, percpu_counter_sum_positive( 3129 ext4_free_blocks_count_set(es, percpu_counter_sum_positive(
3128 &EXT4_SB(sb)->s_freeblocks_counter)); 3130 &EXT4_SB(sb)->s_freeblocks_counter));
3129 es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive( 3131 es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive(
3130 &EXT4_SB(sb)->s_freeinodes_counter)); 3132 &EXT4_SB(sb)->s_freeinodes_counter));
3131 3133
3132 BUFFER_TRACE(sbh, "marking dirty"); 3134 BUFFER_TRACE(sbh, "marking dirty");
3133 mark_buffer_dirty(sbh); 3135 mark_buffer_dirty(sbh);
3134 if (sync) { 3136 if (sync) {
3135 error = sync_dirty_buffer(sbh); 3137 error = sync_dirty_buffer(sbh);
3136 if (error) 3138 if (error)
3137 return error; 3139 return error;
3138 3140
3139 error = buffer_write_io_error(sbh); 3141 error = buffer_write_io_error(sbh);
3140 if (error) { 3142 if (error) {
3141 printk(KERN_ERR "EXT4-fs: I/O error while writing " 3143 printk(KERN_ERR "EXT4-fs: I/O error while writing "
3142 "superblock for %s.\n", sb->s_id); 3144 "superblock for %s.\n", sb->s_id);
3143 clear_buffer_write_io_error(sbh); 3145 clear_buffer_write_io_error(sbh);
3144 set_buffer_uptodate(sbh); 3146 set_buffer_uptodate(sbh);
3145 } 3147 }
3146 } 3148 }
3147 return error; 3149 return error;
3148 } 3150 }
3149 3151
3150 3152
3151 /* 3153 /*
3152 * Have we just finished recovery? If so, and if we are mounting (or 3154 * Have we just finished recovery? If so, and if we are mounting (or
3153 * remounting) the filesystem readonly, then we will end up with a 3155 * remounting) the filesystem readonly, then we will end up with a
3154 * consistent fs on disk. Record that fact. 3156 * consistent fs on disk. Record that fact.
3155 */ 3157 */
3156 static void ext4_mark_recovery_complete(struct super_block *sb, 3158 static void ext4_mark_recovery_complete(struct super_block *sb,
3157 struct ext4_super_block *es) 3159 struct ext4_super_block *es)
3158 { 3160 {
3159 journal_t *journal = EXT4_SB(sb)->s_journal; 3161 journal_t *journal = EXT4_SB(sb)->s_journal;
3160 3162
3161 if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) { 3163 if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
3162 BUG_ON(journal != NULL); 3164 BUG_ON(journal != NULL);
3163 return; 3165 return;
3164 } 3166 }
3165 jbd2_journal_lock_updates(journal); 3167 jbd2_journal_lock_updates(journal);
3166 if (jbd2_journal_flush(journal) < 0) 3168 if (jbd2_journal_flush(journal) < 0)
3167 goto out; 3169 goto out;
3168 3170
3169 lock_super(sb); 3171 lock_super(sb);
3170 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) && 3172 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) &&
3171 sb->s_flags & MS_RDONLY) { 3173 sb->s_flags & MS_RDONLY) {
3172 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3174 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
3173 sb->s_dirt = 0; 3175 sb->s_dirt = 0;
3174 ext4_commit_super(sb, es, 1); 3176 ext4_commit_super(sb, es, 1);
3175 } 3177 }
3176 unlock_super(sb); 3178 unlock_super(sb);
3177 3179
3178 out: 3180 out:
3179 jbd2_journal_unlock_updates(journal); 3181 jbd2_journal_unlock_updates(journal);
3180 } 3182 }
3181 3183
3182 /* 3184 /*
3183 * If we are mounting (or read-write remounting) a filesystem whose journal 3185 * If we are mounting (or read-write remounting) a filesystem whose journal
3184 * has recorded an error from a previous lifetime, move that error to the 3186 * has recorded an error from a previous lifetime, move that error to the
3185 * main filesystem now. 3187 * main filesystem now.
3186 */ 3188 */
3187 static void ext4_clear_journal_err(struct super_block *sb, 3189 static void ext4_clear_journal_err(struct super_block *sb,
3188 struct ext4_super_block *es) 3190 struct ext4_super_block *es)
3189 { 3191 {
3190 journal_t *journal; 3192 journal_t *journal;
3191 int j_errno; 3193 int j_errno;
3192 const char *errstr; 3194 const char *errstr;
3193 3195
3194 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 3196 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
3195 3197
3196 journal = EXT4_SB(sb)->s_journal; 3198 journal = EXT4_SB(sb)->s_journal;
3197 3199
3198 /* 3200 /*
3199 * Now check for any error status which may have been recorded in the 3201 * Now check for any error status which may have been recorded in the
3200 * journal by a prior ext4_error() or ext4_abort() 3202 * journal by a prior ext4_error() or ext4_abort()
3201 */ 3203 */
3202 3204
3203 j_errno = jbd2_journal_errno(journal); 3205 j_errno = jbd2_journal_errno(journal);
3204 if (j_errno) { 3206 if (j_errno) {
3205 char nbuf[16]; 3207 char nbuf[16];
3206 3208
3207 errstr = ext4_decode_error(sb, j_errno, nbuf); 3209 errstr = ext4_decode_error(sb, j_errno, nbuf);
3208 ext4_warning(sb, __func__, "Filesystem error recorded " 3210 ext4_warning(sb, __func__, "Filesystem error recorded "
3209 "from previous mount: %s", errstr); 3211 "from previous mount: %s", errstr);
3210 ext4_warning(sb, __func__, "Marking fs in need of " 3212 ext4_warning(sb, __func__, "Marking fs in need of "
3211 "filesystem check."); 3213 "filesystem check.");
3212 3214
3213 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 3215 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
3214 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 3216 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
3215 ext4_commit_super(sb, es, 1); 3217 ext4_commit_super(sb, es, 1);
3216 3218
3217 jbd2_journal_clear_err(journal); 3219 jbd2_journal_clear_err(journal);
3218 } 3220 }
3219 } 3221 }
3220 3222
3221 /* 3223 /*
3222 * Force the running and committing transactions to commit, 3224 * Force the running and committing transactions to commit,
3223 * and wait on the commit. 3225 * and wait on the commit.
3224 */ 3226 */
3225 int ext4_force_commit(struct super_block *sb) 3227 int ext4_force_commit(struct super_block *sb)
3226 { 3228 {
3227 journal_t *journal; 3229 journal_t *journal;
3228 int ret = 0; 3230 int ret = 0;
3229 3231
3230 if (sb->s_flags & MS_RDONLY) 3232 if (sb->s_flags & MS_RDONLY)
3231 return 0; 3233 return 0;
3232 3234
3233 journal = EXT4_SB(sb)->s_journal; 3235 journal = EXT4_SB(sb)->s_journal;
3234 if (journal) { 3236 if (journal) {
3235 sb->s_dirt = 0; 3237 sb->s_dirt = 0;
3236 ret = ext4_journal_force_commit(journal); 3238 ret = ext4_journal_force_commit(journal);
3237 } 3239 }
3238 3240
3239 return ret; 3241 return ret;
3240 } 3242 }
3241 3243
3242 /* 3244 /*
3243 * Ext4 always journals updates to the superblock itself, so we don't 3245 * Ext4 always journals updates to the superblock itself, so we don't
3244 * have to propagate any other updates to the superblock on disk at this 3246 * have to propagate any other updates to the superblock on disk at this
3245 * point. (We can probably nuke this function altogether, and remove 3247 * point. (We can probably nuke this function altogether, and remove
3246 * any mention to sb->s_dirt in all of fs/ext4; eventual cleanup...) 3248 * any mention to sb->s_dirt in all of fs/ext4; eventual cleanup...)
3247 */ 3249 */
3248 static void ext4_write_super(struct super_block *sb) 3250 static void ext4_write_super(struct super_block *sb)
3249 { 3251 {
3250 if (EXT4_SB(sb)->s_journal) { 3252 if (EXT4_SB(sb)->s_journal) {
3251 if (mutex_trylock(&sb->s_lock) != 0) 3253 if (mutex_trylock(&sb->s_lock) != 0)
3252 BUG(); 3254 BUG();
3253 sb->s_dirt = 0; 3255 sb->s_dirt = 0;
3254 } else { 3256 } else {
3255 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1); 3257 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
3256 } 3258 }
3257 } 3259 }
3258 3260
3259 static int ext4_sync_fs(struct super_block *sb, int wait) 3261 static int ext4_sync_fs(struct super_block *sb, int wait)
3260 { 3262 {
3261 int ret = 0; 3263 int ret = 0;
3262 tid_t target; 3264 tid_t target;
3263 3265
3264 trace_mark(ext4_sync_fs, "dev %s wait %d", sb->s_id, wait); 3266 trace_mark(ext4_sync_fs, "dev %s wait %d", sb->s_id, wait);
3265 sb->s_dirt = 0; 3267 sb->s_dirt = 0;
3266 if (EXT4_SB(sb)->s_journal) { 3268 if (EXT4_SB(sb)->s_journal) {
3267 if (jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, 3269 if (jbd2_journal_start_commit(EXT4_SB(sb)->s_journal,
3268 &target)) { 3270 &target)) {
3269 if (wait) 3271 if (wait)
3270 jbd2_log_wait_commit(EXT4_SB(sb)->s_journal, 3272 jbd2_log_wait_commit(EXT4_SB(sb)->s_journal,
3271 target); 3273 target);
3272 } 3274 }
3273 } else { 3275 } else {
3274 ext4_commit_super(sb, EXT4_SB(sb)->s_es, wait); 3276 ext4_commit_super(sb, EXT4_SB(sb)->s_es, wait);
3275 } 3277 }
3276 return ret; 3278 return ret;
3277 } 3279 }
3278 3280
3279 /* 3281 /*
3280 * LVM calls this function before a (read-only) snapshot is created. This 3282 * LVM calls this function before a (read-only) snapshot is created. This
3281 * gives us a chance to flush the journal completely and mark the fs clean. 3283 * gives us a chance to flush the journal completely and mark the fs clean.
3282 */ 3284 */
3283 static int ext4_freeze(struct super_block *sb) 3285 static int ext4_freeze(struct super_block *sb)
3284 { 3286 {
3285 int error = 0; 3287 int error = 0;
3286 journal_t *journal; 3288 journal_t *journal;
3287 sb->s_dirt = 0; 3289 sb->s_dirt = 0;
3288 3290
3289 if (!(sb->s_flags & MS_RDONLY)) { 3291 if (!(sb->s_flags & MS_RDONLY)) {
3290 journal = EXT4_SB(sb)->s_journal; 3292 journal = EXT4_SB(sb)->s_journal;
3291 3293
3292 if (journal) { 3294 if (journal) {
3293 /* Now we set up the journal barrier. */ 3295 /* Now we set up the journal barrier. */
3294 jbd2_journal_lock_updates(journal); 3296 jbd2_journal_lock_updates(journal);
3295 3297
3296 /* 3298 /*
3297 * We don't want to clear needs_recovery flag when we 3299 * We don't want to clear needs_recovery flag when we
3298 * failed to flush the journal. 3300 * failed to flush the journal.
3299 */ 3301 */
3300 error = jbd2_journal_flush(journal); 3302 error = jbd2_journal_flush(journal);
3301 if (error < 0) 3303 if (error < 0)
3302 goto out; 3304 goto out;
3303 } 3305 }
3304 3306
3305 /* Journal blocked and flushed, clear needs_recovery flag. */ 3307 /* Journal blocked and flushed, clear needs_recovery flag. */
3306 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3308 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
3307 error = ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1); 3309 error = ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
3308 if (error) 3310 if (error)
3309 goto out; 3311 goto out;
3310 } 3312 }
3311 return 0; 3313 return 0;
3312 out: 3314 out:
3313 jbd2_journal_unlock_updates(journal); 3315 jbd2_journal_unlock_updates(journal);
3314 return error; 3316 return error;
3315 } 3317 }
3316 3318
3317 /* 3319 /*
3318 * Called by LVM after the snapshot is done. We need to reset the RECOVER 3320 * Called by LVM after the snapshot is done. We need to reset the RECOVER
3319 * flag here, even though the filesystem is not technically dirty yet. 3321 * flag here, even though the filesystem is not technically dirty yet.
3320 */ 3322 */
3321 static int ext4_unfreeze(struct super_block *sb) 3323 static int ext4_unfreeze(struct super_block *sb)
3322 { 3324 {
3323 if (EXT4_SB(sb)->s_journal && !(sb->s_flags & MS_RDONLY)) { 3325 if (EXT4_SB(sb)->s_journal && !(sb->s_flags & MS_RDONLY)) {
3324 lock_super(sb); 3326 lock_super(sb);
3325 /* Reser the needs_recovery flag before the fs is unlocked. */ 3327 /* Reser the needs_recovery flag before the fs is unlocked. */
3326 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3328 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
3327 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1); 3329 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
3328 unlock_super(sb); 3330 unlock_super(sb);
3329 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 3331 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
3330 } 3332 }
3331 return 0; 3333 return 0;
3332 } 3334 }
3333 3335
3334 static int ext4_remount(struct super_block *sb, int *flags, char *data) 3336 static int ext4_remount(struct super_block *sb, int *flags, char *data)
3335 { 3337 {
3336 struct ext4_super_block *es; 3338 struct ext4_super_block *es;
3337 struct ext4_sb_info *sbi = EXT4_SB(sb); 3339 struct ext4_sb_info *sbi = EXT4_SB(sb);
3338 ext4_fsblk_t n_blocks_count = 0; 3340 ext4_fsblk_t n_blocks_count = 0;
3339 unsigned long old_sb_flags; 3341 unsigned long old_sb_flags;
3340 struct ext4_mount_options old_opts; 3342 struct ext4_mount_options old_opts;
3341 ext4_group_t g; 3343 ext4_group_t g;
3342 unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; 3344 unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
3343 int err; 3345 int err;
3344 #ifdef CONFIG_QUOTA 3346 #ifdef CONFIG_QUOTA
3345 int i; 3347 int i;
3346 #endif 3348 #endif
3347 3349
3348 /* Store the original options */ 3350 /* Store the original options */
3349 old_sb_flags = sb->s_flags; 3351 old_sb_flags = sb->s_flags;
3350 old_opts.s_mount_opt = sbi->s_mount_opt; 3352 old_opts.s_mount_opt = sbi->s_mount_opt;
3351 old_opts.s_resuid = sbi->s_resuid; 3353 old_opts.s_resuid = sbi->s_resuid;
3352 old_opts.s_resgid = sbi->s_resgid; 3354 old_opts.s_resgid = sbi->s_resgid;
3353 old_opts.s_commit_interval = sbi->s_commit_interval; 3355 old_opts.s_commit_interval = sbi->s_commit_interval;
3354 old_opts.s_min_batch_time = sbi->s_min_batch_time; 3356 old_opts.s_min_batch_time = sbi->s_min_batch_time;
3355 old_opts.s_max_batch_time = sbi->s_max_batch_time; 3357 old_opts.s_max_batch_time = sbi->s_max_batch_time;
3356 #ifdef CONFIG_QUOTA 3358 #ifdef CONFIG_QUOTA
3357 old_opts.s_jquota_fmt = sbi->s_jquota_fmt; 3359 old_opts.s_jquota_fmt = sbi->s_jquota_fmt;
3358 for (i = 0; i < MAXQUOTAS; i++) 3360 for (i = 0; i < MAXQUOTAS; i++)
3359 old_opts.s_qf_names[i] = sbi->s_qf_names[i]; 3361 old_opts.s_qf_names[i] = sbi->s_qf_names[i];
3360 #endif 3362 #endif
3361 if (sbi->s_journal && sbi->s_journal->j_task->io_context) 3363 if (sbi->s_journal && sbi->s_journal->j_task->io_context)
3362 journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; 3364 journal_ioprio = sbi->s_journal->j_task->io_context->ioprio;
3363 3365
3364 /* 3366 /*
3365 * Allow the "check" option to be passed as a remount option. 3367 * Allow the "check" option to be passed as a remount option.
3366 */ 3368 */
3367 if (!parse_options(data, sb, NULL, &journal_ioprio, 3369 if (!parse_options(data, sb, NULL, &journal_ioprio,
3368 &n_blocks_count, 1)) { 3370 &n_blocks_count, 1)) {
3369 err = -EINVAL; 3371 err = -EINVAL;
3370 goto restore_opts; 3372 goto restore_opts;
3371 } 3373 }
3372 3374
3373 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) 3375 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
3374 ext4_abort(sb, __func__, "Abort forced by user"); 3376 ext4_abort(sb, __func__, "Abort forced by user");
3375 3377
3376 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 3378 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3377 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); 3379 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3378 3380
3379 es = sbi->s_es; 3381 es = sbi->s_es;
3380 3382
3381 if (sbi->s_journal) { 3383 if (sbi->s_journal) {
3382 ext4_init_journal_params(sb, sbi->s_journal); 3384 ext4_init_journal_params(sb, sbi->s_journal);
3383 set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); 3385 set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
3384 } 3386 }
3385 3387
3386 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || 3388 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) ||
3387 n_blocks_count > ext4_blocks_count(es)) { 3389 n_blocks_count > ext4_blocks_count(es)) {
3388 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) { 3390 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) {
3389 err = -EROFS; 3391 err = -EROFS;
3390 goto restore_opts; 3392 goto restore_opts;
3391 } 3393 }
3392 3394
3393 if (*flags & MS_RDONLY) { 3395 if (*flags & MS_RDONLY) {
3394 /* 3396 /*
3395 * First of all, the unconditional stuff we have to do 3397 * First of all, the unconditional stuff we have to do
3396 * to disable replay of the journal when we next remount 3398 * to disable replay of the journal when we next remount
3397 */ 3399 */
3398 sb->s_flags |= MS_RDONLY; 3400 sb->s_flags |= MS_RDONLY;
3399 3401
3400 /* 3402 /*
3401 * OK, test if we are remounting a valid rw partition 3403 * OK, test if we are remounting a valid rw partition
3402 * readonly, and if so set the rdonly flag and then 3404 * readonly, and if so set the rdonly flag and then
3403 * mark the partition as valid again. 3405 * mark the partition as valid again.
3404 */ 3406 */
3405 if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) && 3407 if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) &&
3406 (sbi->s_mount_state & EXT4_VALID_FS)) 3408 (sbi->s_mount_state & EXT4_VALID_FS))
3407 es->s_state = cpu_to_le16(sbi->s_mount_state); 3409 es->s_state = cpu_to_le16(sbi->s_mount_state);
3408 3410
3409 /* 3411 /*
3410 * We have to unlock super so that we can wait for 3412 * We have to unlock super so that we can wait for
3411 * transactions. 3413 * transactions.
3412 */ 3414 */
3413 if (sbi->s_journal) { 3415 if (sbi->s_journal) {
3414 unlock_super(sb); 3416 unlock_super(sb);
3415 ext4_mark_recovery_complete(sb, es); 3417 ext4_mark_recovery_complete(sb, es);
3416 lock_super(sb); 3418 lock_super(sb);
3417 } 3419 }
3418 } else { 3420 } else {
3419 int ret; 3421 int ret;
3420 if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb, 3422 if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb,
3421 ~EXT4_FEATURE_RO_COMPAT_SUPP))) { 3423 ~EXT4_FEATURE_RO_COMPAT_SUPP))) {
3422 printk(KERN_WARNING "EXT4-fs: %s: couldn't " 3424 printk(KERN_WARNING "EXT4-fs: %s: couldn't "
3423 "remount RDWR because of unsupported " 3425 "remount RDWR because of unsupported "
3424 "optional features (%x).\n", sb->s_id, 3426 "optional features (%x).\n", sb->s_id,
3425 (le32_to_cpu(sbi->s_es->s_feature_ro_compat) & 3427 (le32_to_cpu(sbi->s_es->s_feature_ro_compat) &
3426 ~EXT4_FEATURE_RO_COMPAT_SUPP)); 3428 ~EXT4_FEATURE_RO_COMPAT_SUPP));
3427 err = -EROFS; 3429 err = -EROFS;
3428 goto restore_opts; 3430 goto restore_opts;
3429 } 3431 }
3430 3432
3431 /* 3433 /*
3432 * Make sure the group descriptor checksums 3434 * Make sure the group descriptor checksums
3433 * are sane. If they aren't, refuse to 3435 * are sane. If they aren't, refuse to
3434 * remount r/w. 3436 * remount r/w.
3435 */ 3437 */
3436 for (g = 0; g < sbi->s_groups_count; g++) { 3438 for (g = 0; g < sbi->s_groups_count; g++) {
3437 struct ext4_group_desc *gdp = 3439 struct ext4_group_desc *gdp =
3438 ext4_get_group_desc(sb, g, NULL); 3440 ext4_get_group_desc(sb, g, NULL);
3439 3441
3440 if (!ext4_group_desc_csum_verify(sbi, g, gdp)) { 3442 if (!ext4_group_desc_csum_verify(sbi, g, gdp)) {
3441 printk(KERN_ERR 3443 printk(KERN_ERR
3442 "EXT4-fs: ext4_remount: " 3444 "EXT4-fs: ext4_remount: "
3443 "Checksum for group %u failed (%u!=%u)\n", 3445 "Checksum for group %u failed (%u!=%u)\n",
3444 g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)), 3446 g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)),
3445 le16_to_cpu(gdp->bg_checksum)); 3447 le16_to_cpu(gdp->bg_checksum));
3446 err = -EINVAL; 3448 err = -EINVAL;
3447 goto restore_opts; 3449 goto restore_opts;
3448 } 3450 }
3449 } 3451 }
3450 3452
3451 /* 3453 /*
3452 * If we have an unprocessed orphan list hanging 3454 * If we have an unprocessed orphan list hanging
3453 * around from a previously readonly bdev mount, 3455 * around from a previously readonly bdev mount,
3454 * require a full umount/remount for now. 3456 * require a full umount/remount for now.
3455 */ 3457 */
3456 if (es->s_last_orphan) { 3458 if (es->s_last_orphan) {
3457 printk(KERN_WARNING "EXT4-fs: %s: couldn't " 3459 printk(KERN_WARNING "EXT4-fs: %s: couldn't "
3458 "remount RDWR because of unprocessed " 3460 "remount RDWR because of unprocessed "
3459 "orphan inode list. Please " 3461 "orphan inode list. Please "
3460 "umount/remount instead.\n", 3462 "umount/remount instead.\n",
3461 sb->s_id); 3463 sb->s_id);
3462 err = -EINVAL; 3464 err = -EINVAL;
3463 goto restore_opts; 3465 goto restore_opts;
3464 } 3466 }
3465 3467
3466 /* 3468 /*
3467 * Mounting a RDONLY partition read-write, so reread 3469 * Mounting a RDONLY partition read-write, so reread
3468 * and store the current valid flag. (It may have 3470 * and store the current valid flag. (It may have
3469 * been changed by e2fsck since we originally mounted 3471 * been changed by e2fsck since we originally mounted
3470 * the partition.) 3472 * the partition.)
3471 */ 3473 */
3472 if (sbi->s_journal) 3474 if (sbi->s_journal)
3473 ext4_clear_journal_err(sb, es); 3475 ext4_clear_journal_err(sb, es);
3474 sbi->s_mount_state = le16_to_cpu(es->s_state); 3476 sbi->s_mount_state = le16_to_cpu(es->s_state);
3475 if ((err = ext4_group_extend(sb, es, n_blocks_count))) 3477 if ((err = ext4_group_extend(sb, es, n_blocks_count)))
3476 goto restore_opts; 3478 goto restore_opts;
3477 if (!ext4_setup_super(sb, es, 0)) 3479 if (!ext4_setup_super(sb, es, 0))
3478 sb->s_flags &= ~MS_RDONLY; 3480 sb->s_flags &= ~MS_RDONLY;
3479 } 3481 }
3480 } 3482 }
3481 if (sbi->s_journal == NULL) 3483 if (sbi->s_journal == NULL)
3482 ext4_commit_super(sb, es, 1); 3484 ext4_commit_super(sb, es, 1);
3483 3485
3484 #ifdef CONFIG_QUOTA 3486 #ifdef CONFIG_QUOTA
3485 /* Release old quota file names */ 3487 /* Release old quota file names */
3486 for (i = 0; i < MAXQUOTAS; i++) 3488 for (i = 0; i < MAXQUOTAS; i++)
3487 if (old_opts.s_qf_names[i] && 3489 if (old_opts.s_qf_names[i] &&
3488 old_opts.s_qf_names[i] != sbi->s_qf_names[i]) 3490 old_opts.s_qf_names[i] != sbi->s_qf_names[i])
3489 kfree(old_opts.s_qf_names[i]); 3491 kfree(old_opts.s_qf_names[i]);
3490 #endif 3492 #endif
3491 return 0; 3493 return 0;
3492 restore_opts: 3494 restore_opts:
3493 sb->s_flags = old_sb_flags; 3495 sb->s_flags = old_sb_flags;
3494 sbi->s_mount_opt = old_opts.s_mount_opt; 3496 sbi->s_mount_opt = old_opts.s_mount_opt;
3495 sbi->s_resuid = old_opts.s_resuid; 3497 sbi->s_resuid = old_opts.s_resuid;
3496 sbi->s_resgid = old_opts.s_resgid; 3498 sbi->s_resgid = old_opts.s_resgid;
3497 sbi->s_commit_interval = old_opts.s_commit_interval; 3499 sbi->s_commit_interval = old_opts.s_commit_interval;
3498 sbi->s_min_batch_time = old_opts.s_min_batch_time; 3500 sbi->s_min_batch_time = old_opts.s_min_batch_time;
3499 sbi->s_max_batch_time = old_opts.s_max_batch_time; 3501 sbi->s_max_batch_time = old_opts.s_max_batch_time;
3500 #ifdef CONFIG_QUOTA 3502 #ifdef CONFIG_QUOTA
3501 sbi->s_jquota_fmt = old_opts.s_jquota_fmt; 3503 sbi->s_jquota_fmt = old_opts.s_jquota_fmt;
3502 for (i = 0; i < MAXQUOTAS; i++) { 3504 for (i = 0; i < MAXQUOTAS; i++) {
3503 if (sbi->s_qf_names[i] && 3505 if (sbi->s_qf_names[i] &&
3504 old_opts.s_qf_names[i] != sbi->s_qf_names[i]) 3506 old_opts.s_qf_names[i] != sbi->s_qf_names[i])
3505 kfree(sbi->s_qf_names[i]); 3507 kfree(sbi->s_qf_names[i]);
3506 sbi->s_qf_names[i] = old_opts.s_qf_names[i]; 3508 sbi->s_qf_names[i] = old_opts.s_qf_names[i];
3507 } 3509 }
3508 #endif 3510 #endif
3509 return err; 3511 return err;
3510 } 3512 }
3511 3513
3512 static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf) 3514 static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
3513 { 3515 {
3514 struct super_block *sb = dentry->d_sb; 3516 struct super_block *sb = dentry->d_sb;
3515 struct ext4_sb_info *sbi = EXT4_SB(sb); 3517 struct ext4_sb_info *sbi = EXT4_SB(sb);
3516 struct ext4_super_block *es = sbi->s_es; 3518 struct ext4_super_block *es = sbi->s_es;
3517 u64 fsid; 3519 u64 fsid;
3518 3520
3519 if (test_opt(sb, MINIX_DF)) { 3521 if (test_opt(sb, MINIX_DF)) {
3520 sbi->s_overhead_last = 0; 3522 sbi->s_overhead_last = 0;
3521 } else if (sbi->s_blocks_last != ext4_blocks_count(es)) { 3523 } else if (sbi->s_blocks_last != ext4_blocks_count(es)) {
3522 ext4_group_t ngroups = sbi->s_groups_count, i; 3524 ext4_group_t ngroups = sbi->s_groups_count, i;
3523 ext4_fsblk_t overhead = 0; 3525 ext4_fsblk_t overhead = 0;
3524 smp_rmb(); 3526 smp_rmb();
3525 3527
3526 /* 3528 /*
3527 * Compute the overhead (FS structures). This is constant 3529 * Compute the overhead (FS structures). This is constant
3528 * for a given filesystem unless the number of block groups 3530 * for a given filesystem unless the number of block groups
3529 * changes so we cache the previous value until it does. 3531 * changes so we cache the previous value until it does.
3530 */ 3532 */
3531 3533
3532 /* 3534 /*
3533 * All of the blocks before first_data_block are 3535 * All of the blocks before first_data_block are
3534 * overhead 3536 * overhead
3535 */ 3537 */
3536 overhead = le32_to_cpu(es->s_first_data_block); 3538 overhead = le32_to_cpu(es->s_first_data_block);
3537 3539
3538 /* 3540 /*
3539 * Add the overhead attributed to the superblock and 3541 * Add the overhead attributed to the superblock and
3540 * block group descriptors. If the sparse superblocks 3542 * block group descriptors. If the sparse superblocks
3541 * feature is turned on, then not all groups have this. 3543 * feature is turned on, then not all groups have this.
3542 */ 3544 */
3543 for (i = 0; i < ngroups; i++) { 3545 for (i = 0; i < ngroups; i++) {
3544 overhead += ext4_bg_has_super(sb, i) + 3546 overhead += ext4_bg_has_super(sb, i) +
3545 ext4_bg_num_gdb(sb, i); 3547 ext4_bg_num_gdb(sb, i);
3546 cond_resched(); 3548 cond_resched();
3547 } 3549 }
3548 3550
3549 /* 3551 /*
3550 * Every block group has an inode bitmap, a block 3552 * Every block group has an inode bitmap, a block
3551 * bitmap, and an inode table. 3553 * bitmap, and an inode table.
3552 */ 3554 */
3553 overhead += ngroups * (2 + sbi->s_itb_per_group); 3555 overhead += ngroups * (2 + sbi->s_itb_per_group);
3554 sbi->s_overhead_last = overhead; 3556 sbi->s_overhead_last = overhead;
3555 smp_wmb(); 3557 smp_wmb();
3556 sbi->s_blocks_last = ext4_blocks_count(es); 3558 sbi->s_blocks_last = ext4_blocks_count(es);
3557 } 3559 }
3558 3560
3559 buf->f_type = EXT4_SUPER_MAGIC; 3561 buf->f_type = EXT4_SUPER_MAGIC;
3560 buf->f_bsize = sb->s_blocksize; 3562 buf->f_bsize = sb->s_blocksize;
3561 buf->f_blocks = ext4_blocks_count(es) - sbi->s_overhead_last; 3563 buf->f_blocks = ext4_blocks_count(es) - sbi->s_overhead_last;
3562 buf->f_bfree = percpu_counter_sum_positive(&sbi->s_freeblocks_counter) - 3564 buf->f_bfree = percpu_counter_sum_positive(&sbi->s_freeblocks_counter) -
3563 percpu_counter_sum_positive(&sbi->s_dirtyblocks_counter); 3565 percpu_counter_sum_positive(&sbi->s_dirtyblocks_counter);
3564 ext4_free_blocks_count_set(es, buf->f_bfree); 3566 ext4_free_blocks_count_set(es, buf->f_bfree);
3565 buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es); 3567 buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es);
3566 if (buf->f_bfree < ext4_r_blocks_count(es)) 3568 if (buf->f_bfree < ext4_r_blocks_count(es))
3567 buf->f_bavail = 0; 3569 buf->f_bavail = 0;
3568 buf->f_files = le32_to_cpu(es->s_inodes_count); 3570 buf->f_files = le32_to_cpu(es->s_inodes_count);
3569 buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter); 3571 buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter);
3570 es->s_free_inodes_count = cpu_to_le32(buf->f_ffree); 3572 es->s_free_inodes_count = cpu_to_le32(buf->f_ffree);
3571 buf->f_namelen = EXT4_NAME_LEN; 3573 buf->f_namelen = EXT4_NAME_LEN;
3572 fsid = le64_to_cpup((void *)es->s_uuid) ^ 3574 fsid = le64_to_cpup((void *)es->s_uuid) ^
3573 le64_to_cpup((void *)es->s_uuid + sizeof(u64)); 3575 le64_to_cpup((void *)es->s_uuid + sizeof(u64));
3574 buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL; 3576 buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
3575 buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL; 3577 buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
3576 return 0; 3578 return 0;
3577 } 3579 }
3578 3580
3579 /* Helper function for writing quotas on sync - we need to start transaction before quota file 3581 /* Helper function for writing quotas on sync - we need to start transaction before quota file
3580 * is locked for write. Otherwise the are possible deadlocks: 3582 * is locked for write. Otherwise the are possible deadlocks:
3581 * Process 1 Process 2 3583 * Process 1 Process 2
3582 * ext4_create() quota_sync() 3584 * ext4_create() quota_sync()
3583 * jbd2_journal_start() write_dquot() 3585 * jbd2_journal_start() write_dquot()
3584 * vfs_dq_init() down(dqio_mutex) 3586 * vfs_dq_init() down(dqio_mutex)
3585 * down(dqio_mutex) jbd2_journal_start() 3587 * down(dqio_mutex) jbd2_journal_start()
3586 * 3588 *
3587 */ 3589 */
3588 3590
3589 #ifdef CONFIG_QUOTA 3591 #ifdef CONFIG_QUOTA
3590 3592
3591 static inline struct inode *dquot_to_inode(struct dquot *dquot) 3593 static inline struct inode *dquot_to_inode(struct dquot *dquot)
3592 { 3594 {
3593 return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type]; 3595 return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
3594 } 3596 }
3595 3597
3596 static int ext4_write_dquot(struct dquot *dquot) 3598 static int ext4_write_dquot(struct dquot *dquot)
3597 { 3599 {
3598 int ret, err; 3600 int ret, err;
3599 handle_t *handle; 3601 handle_t *handle;
3600 struct inode *inode; 3602 struct inode *inode;
3601 3603
3602 inode = dquot_to_inode(dquot); 3604 inode = dquot_to_inode(dquot);
3603 handle = ext4_journal_start(inode, 3605 handle = ext4_journal_start(inode,
3604 EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); 3606 EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
3605 if (IS_ERR(handle)) 3607 if (IS_ERR(handle))
3606 return PTR_ERR(handle); 3608 return PTR_ERR(handle);
3607 ret = dquot_commit(dquot); 3609 ret = dquot_commit(dquot);
3608 err = ext4_journal_stop(handle); 3610 err = ext4_journal_stop(handle);
3609 if (!ret) 3611 if (!ret)
3610 ret = err; 3612 ret = err;
3611 return ret; 3613 return ret;
3612 } 3614 }
3613 3615
3614 static int ext4_acquire_dquot(struct dquot *dquot) 3616 static int ext4_acquire_dquot(struct dquot *dquot)
3615 { 3617 {
3616 int ret, err; 3618 int ret, err;
3617 handle_t *handle; 3619 handle_t *handle;
3618 3620
3619 handle = ext4_journal_start(dquot_to_inode(dquot), 3621 handle = ext4_journal_start(dquot_to_inode(dquot),
3620 EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb)); 3622 EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
3621 if (IS_ERR(handle)) 3623 if (IS_ERR(handle))
3622 return PTR_ERR(handle); 3624 return PTR_ERR(handle);
3623 ret = dquot_acquire(dquot); 3625 ret = dquot_acquire(dquot);
3624 err = ext4_journal_stop(handle); 3626 err = ext4_journal_stop(handle);
3625 if (!ret) 3627 if (!ret)
3626 ret = err; 3628 ret = err;
3627 return ret; 3629 return ret;
3628 } 3630 }
3629 3631
3630 static int ext4_release_dquot(struct dquot *dquot) 3632 static int ext4_release_dquot(struct dquot *dquot)
3631 { 3633 {
3632 int ret, err; 3634 int ret, err;
3633 handle_t *handle; 3635 handle_t *handle;
3634 3636
3635 handle = ext4_journal_start(dquot_to_inode(dquot), 3637 handle = ext4_journal_start(dquot_to_inode(dquot),
3636 EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb)); 3638 EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb));
3637 if (IS_ERR(handle)) { 3639 if (IS_ERR(handle)) {
3638 /* Release dquot anyway to avoid endless cycle in dqput() */ 3640 /* Release dquot anyway to avoid endless cycle in dqput() */
3639 dquot_release(dquot); 3641 dquot_release(dquot);
3640 return PTR_ERR(handle); 3642 return PTR_ERR(handle);
3641 } 3643 }
3642 ret = dquot_release(dquot); 3644 ret = dquot_release(dquot);
3643 err = ext4_journal_stop(handle); 3645 err = ext4_journal_stop(handle);
3644 if (!ret) 3646 if (!ret)
3645 ret = err; 3647 ret = err;
3646 return ret; 3648 return ret;
3647 } 3649 }
3648 3650
3649 static int ext4_mark_dquot_dirty(struct dquot *dquot) 3651 static int ext4_mark_dquot_dirty(struct dquot *dquot)
3650 { 3652 {
3651 /* Are we journaling quotas? */ 3653 /* Are we journaling quotas? */
3652 if (EXT4_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] || 3654 if (EXT4_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
3653 EXT4_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) { 3655 EXT4_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
3654 dquot_mark_dquot_dirty(dquot); 3656 dquot_mark_dquot_dirty(dquot);
3655 return ext4_write_dquot(dquot); 3657 return ext4_write_dquot(dquot);
3656 } else { 3658 } else {
3657 return dquot_mark_dquot_dirty(dquot); 3659 return dquot_mark_dquot_dirty(dquot);
3658 } 3660 }
3659 } 3661 }
3660 3662
3661 static int ext4_write_info(struct super_block *sb, int type) 3663 static int ext4_write_info(struct super_block *sb, int type)
3662 { 3664 {
3663 int ret, err; 3665 int ret, err;
3664 handle_t *handle; 3666 handle_t *handle;
3665 3667
3666 /* Data block + inode block */ 3668 /* Data block + inode block */
3667 handle = ext4_journal_start(sb->s_root->d_inode, 2); 3669 handle = ext4_journal_start(sb->s_root->d_inode, 2);
3668 if (IS_ERR(handle)) 3670 if (IS_ERR(handle))
3669 return PTR_ERR(handle); 3671 return PTR_ERR(handle);
3670 ret = dquot_commit_info(sb, type); 3672 ret = dquot_commit_info(sb, type);
3671 err = ext4_journal_stop(handle); 3673 err = ext4_journal_stop(handle);
3672 if (!ret) 3674 if (!ret)
3673 ret = err; 3675 ret = err;
3674 return ret; 3676 return ret;
3675 } 3677 }
3676 3678
3677 /* 3679 /*
3678 * Turn on quotas during mount time - we need to find 3680 * Turn on quotas during mount time - we need to find
3679 * the quota file and such... 3681 * the quota file and such...
3680 */ 3682 */
3681 static int ext4_quota_on_mount(struct super_block *sb, int type) 3683 static int ext4_quota_on_mount(struct super_block *sb, int type)
3682 { 3684 {
3683 return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type], 3685 return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type],
3684 EXT4_SB(sb)->s_jquota_fmt, type); 3686 EXT4_SB(sb)->s_jquota_fmt, type);
3685 } 3687 }
3686 3688
3687 /* 3689 /*
3688 * Standard function to be called on quota_on 3690 * Standard function to be called on quota_on
3689 */ 3691 */
3690 static int ext4_quota_on(struct super_block *sb, int type, int format_id, 3692 static int ext4_quota_on(struct super_block *sb, int type, int format_id,
3691 char *name, int remount) 3693 char *name, int remount)
3692 { 3694 {
3693 int err; 3695 int err;
3694 struct path path; 3696 struct path path;
3695 3697
3696 if (!test_opt(sb, QUOTA)) 3698 if (!test_opt(sb, QUOTA))
3697 return -EINVAL; 3699 return -EINVAL;
3698 /* When remounting, no checks are needed and in fact, name is NULL */ 3700 /* When remounting, no checks are needed and in fact, name is NULL */
3699 if (remount) 3701 if (remount)
3700 return vfs_quota_on(sb, type, format_id, name, remount); 3702 return vfs_quota_on(sb, type, format_id, name, remount);
3701 3703
3702 err = kern_path(name, LOOKUP_FOLLOW, &path); 3704 err = kern_path(name, LOOKUP_FOLLOW, &path);
3703 if (err) 3705 if (err)
3704 return err; 3706 return err;
3705 3707
3706 /* Quotafile not on the same filesystem? */ 3708 /* Quotafile not on the same filesystem? */
3707 if (path.mnt->mnt_sb != sb) { 3709 if (path.mnt->mnt_sb != sb) {
3708 path_put(&path); 3710 path_put(&path);
3709 return -EXDEV; 3711 return -EXDEV;
3710 } 3712 }
3711 /* Journaling quota? */ 3713 /* Journaling quota? */
3712 if (EXT4_SB(sb)->s_qf_names[type]) { 3714 if (EXT4_SB(sb)->s_qf_names[type]) {
3713 /* Quotafile not in fs root? */ 3715 /* Quotafile not in fs root? */
3714 if (path.dentry->d_parent != sb->s_root) 3716 if (path.dentry->d_parent != sb->s_root)
3715 printk(KERN_WARNING 3717 printk(KERN_WARNING
3716 "EXT4-fs: Quota file not on filesystem root. " 3718 "EXT4-fs: Quota file not on filesystem root. "
3717 "Journaled quota will not work.\n"); 3719 "Journaled quota will not work.\n");
3718 } 3720 }
3719 3721
3720 /* 3722 /*
3721 * When we journal data on quota file, we have to flush journal to see 3723 * When we journal data on quota file, we have to flush journal to see
3722 * all updates to the file when we bypass pagecache... 3724 * all updates to the file when we bypass pagecache...
3723 */ 3725 */
3724 if (EXT4_SB(sb)->s_journal && 3726 if (EXT4_SB(sb)->s_journal &&
3725 ext4_should_journal_data(path.dentry->d_inode)) { 3727 ext4_should_journal_data(path.dentry->d_inode)) {
3726 /* 3728 /*
3727 * We don't need to lock updates but journal_flush() could 3729 * We don't need to lock updates but journal_flush() could
3728 * otherwise be livelocked... 3730 * otherwise be livelocked...
3729 */ 3731 */
3730 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); 3732 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
3731 err = jbd2_journal_flush(EXT4_SB(sb)->s_journal); 3733 err = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
3732 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 3734 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
3733 if (err) { 3735 if (err) {
3734 path_put(&path); 3736 path_put(&path);
3735 return err; 3737 return err;
3736 } 3738 }
3737 } 3739 }
3738 3740
3739 err = vfs_quota_on_path(sb, type, format_id, &path); 3741 err = vfs_quota_on_path(sb, type, format_id, &path);
3740 path_put(&path); 3742 path_put(&path);
3741 return err; 3743 return err;
3742 } 3744 }
3743 3745
3744 /* Read data from quotafile - avoid pagecache and such because we cannot afford 3746 /* Read data from quotafile - avoid pagecache and such because we cannot afford
3745 * acquiring the locks... As quota files are never truncated and quota code 3747 * acquiring the locks... As quota files are never truncated and quota code
3746 * itself serializes the operations (and noone else should touch the files) 3748 * itself serializes the operations (and noone else should touch the files)
3747 * we don't have to be afraid of races */ 3749 * we don't have to be afraid of races */
3748 static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, 3750 static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
3749 size_t len, loff_t off) 3751 size_t len, loff_t off)
3750 { 3752 {
3751 struct inode *inode = sb_dqopt(sb)->files[type]; 3753 struct inode *inode = sb_dqopt(sb)->files[type];
3752 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); 3754 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
3753 int err = 0; 3755 int err = 0;
3754 int offset = off & (sb->s_blocksize - 1); 3756 int offset = off & (sb->s_blocksize - 1);
3755 int tocopy; 3757 int tocopy;
3756 size_t toread; 3758 size_t toread;
3757 struct buffer_head *bh; 3759 struct buffer_head *bh;
3758 loff_t i_size = i_size_read(inode); 3760 loff_t i_size = i_size_read(inode);
3759 3761
3760 if (off > i_size) 3762 if (off > i_size)
3761 return 0; 3763 return 0;
3762 if (off+len > i_size) 3764 if (off+len > i_size)
3763 len = i_size-off; 3765 len = i_size-off;
3764 toread = len; 3766 toread = len;
3765 while (toread > 0) { 3767 while (toread > 0) {
3766 tocopy = sb->s_blocksize - offset < toread ? 3768 tocopy = sb->s_blocksize - offset < toread ?
3767 sb->s_blocksize - offset : toread; 3769 sb->s_blocksize - offset : toread;
3768 bh = ext4_bread(NULL, inode, blk, 0, &err); 3770 bh = ext4_bread(NULL, inode, blk, 0, &err);
3769 if (err) 3771 if (err)
3770 return err; 3772 return err;
3771 if (!bh) /* A hole? */ 3773 if (!bh) /* A hole? */
3772 memset(data, 0, tocopy); 3774 memset(data, 0, tocopy);
3773 else 3775 else
3774 memcpy(data, bh->b_data+offset, tocopy); 3776 memcpy(data, bh->b_data+offset, tocopy);
3775 brelse(bh); 3777 brelse(bh);
3776 offset = 0; 3778 offset = 0;
3777 toread -= tocopy; 3779 toread -= tocopy;
3778 data += tocopy; 3780 data += tocopy;
3779 blk++; 3781 blk++;
3780 } 3782 }
3781 return len; 3783 return len;
3782 } 3784 }
3783 3785
3784 /* Write to quotafile (we know the transaction is already started and has 3786 /* Write to quotafile (we know the transaction is already started and has
3785 * enough credits) */ 3787 * enough credits) */
3786 static ssize_t ext4_quota_write(struct super_block *sb, int type, 3788 static ssize_t ext4_quota_write(struct super_block *sb, int type,
3787 const char *data, size_t len, loff_t off) 3789 const char *data, size_t len, loff_t off)
3788 { 3790 {
3789 struct inode *inode = sb_dqopt(sb)->files[type]; 3791 struct inode *inode = sb_dqopt(sb)->files[type];
3790 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); 3792 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
3791 int err = 0; 3793 int err = 0;
3792 int offset = off & (sb->s_blocksize - 1); 3794 int offset = off & (sb->s_blocksize - 1);
3793 int tocopy; 3795 int tocopy;
3794 int journal_quota = EXT4_SB(sb)->s_qf_names[type] != NULL; 3796 int journal_quota = EXT4_SB(sb)->s_qf_names[type] != NULL;
3795 size_t towrite = len; 3797 size_t towrite = len;
3796 struct buffer_head *bh; 3798 struct buffer_head *bh;
3797 handle_t *handle = journal_current_handle(); 3799 handle_t *handle = journal_current_handle();
3798 3800
3799 if (EXT4_SB(sb)->s_journal && !handle) { 3801 if (EXT4_SB(sb)->s_journal && !handle) {
3800 printk(KERN_WARNING "EXT4-fs: Quota write (off=%llu, len=%llu)" 3802 printk(KERN_WARNING "EXT4-fs: Quota write (off=%llu, len=%llu)"
3801 " cancelled because transaction is not started.\n", 3803 " cancelled because transaction is not started.\n",
3802 (unsigned long long)off, (unsigned long long)len); 3804 (unsigned long long)off, (unsigned long long)len);
3803 return -EIO; 3805 return -EIO;
3804 } 3806 }
3805 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); 3807 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
3806 while (towrite > 0) { 3808 while (towrite > 0) {
3807 tocopy = sb->s_blocksize - offset < towrite ? 3809 tocopy = sb->s_blocksize - offset < towrite ?
3808 sb->s_blocksize - offset : towrite; 3810 sb->s_blocksize - offset : towrite;
3809 bh = ext4_bread(handle, inode, blk, 1, &err); 3811 bh = ext4_bread(handle, inode, blk, 1, &err);
3810 if (!bh) 3812 if (!bh)
3811 goto out; 3813 goto out;
3812 if (journal_quota) { 3814 if (journal_quota) {
3813 err = ext4_journal_get_write_access(handle, bh); 3815 err = ext4_journal_get_write_access(handle, bh);
3814 if (err) { 3816 if (err) {
3815 brelse(bh); 3817 brelse(bh);
3816 goto out; 3818 goto out;
3817 } 3819 }
3818 } 3820 }
3819 lock_buffer(bh); 3821 lock_buffer(bh);
3820 memcpy(bh->b_data+offset, data, tocopy); 3822 memcpy(bh->b_data+offset, data, tocopy);
3821 flush_dcache_page(bh->b_page); 3823 flush_dcache_page(bh->b_page);
3822 unlock_buffer(bh); 3824 unlock_buffer(bh);
3823 if (journal_quota) 3825 if (journal_quota)
3824 err = ext4_handle_dirty_metadata(handle, NULL, bh); 3826 err = ext4_handle_dirty_metadata(handle, NULL, bh);
3825 else { 3827 else {
3826 /* Always do at least ordered writes for quotas */ 3828 /* Always do at least ordered writes for quotas */
3827 err = ext4_jbd2_file_inode(handle, inode); 3829 err = ext4_jbd2_file_inode(handle, inode);
3828 mark_buffer_dirty(bh); 3830 mark_buffer_dirty(bh);
3829 } 3831 }
3830 brelse(bh); 3832 brelse(bh);
3831 if (err) 3833 if (err)
3832 goto out; 3834 goto out;
3833 offset = 0; 3835 offset = 0;
3834 towrite -= tocopy; 3836 towrite -= tocopy;
3835 data += tocopy; 3837 data += tocopy;
3836 blk++; 3838 blk++;
3837 } 3839 }
3838 out: 3840 out:
3839 if (len == towrite) { 3841 if (len == towrite) {
3840 mutex_unlock(&inode->i_mutex); 3842 mutex_unlock(&inode->i_mutex);
3841 return err; 3843 return err;
3842 } 3844 }
3843 if (inode->i_size < off+len-towrite) { 3845 if (inode->i_size < off+len-towrite) {
3844 i_size_write(inode, off+len-towrite); 3846 i_size_write(inode, off+len-towrite);
3845 EXT4_I(inode)->i_disksize = inode->i_size; 3847 EXT4_I(inode)->i_disksize = inode->i_size;
3846 } 3848 }
3847 inode->i_mtime = inode->i_ctime = CURRENT_TIME; 3849 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
3848 ext4_mark_inode_dirty(handle, inode); 3850 ext4_mark_inode_dirty(handle, inode);
3849 mutex_unlock(&inode->i_mutex); 3851 mutex_unlock(&inode->i_mutex);
3850 return len - towrite; 3852 return len - towrite;
3851 } 3853 }
3852 3854
3853 #endif 3855 #endif
3854 3856
3855 static int ext4_get_sb(struct file_system_type *fs_type, 3857 static int ext4_get_sb(struct file_system_type *fs_type,
3856 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 3858 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
3857 { 3859 {
3858 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); 3860 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt);
3859 } 3861 }
3860 3862
3861 static struct file_system_type ext4_fs_type = { 3863 static struct file_system_type ext4_fs_type = {
3862 .owner = THIS_MODULE, 3864 .owner = THIS_MODULE,
3863 .name = "ext4", 3865 .name = "ext4",
3864 .get_sb = ext4_get_sb, 3866 .get_sb = ext4_get_sb,
3865 .kill_sb = kill_block_super, 3867 .kill_sb = kill_block_super,
3866 .fs_flags = FS_REQUIRES_DEV, 3868 .fs_flags = FS_REQUIRES_DEV,
3867 }; 3869 };
3868 3870
3869 #ifdef CONFIG_EXT4DEV_COMPAT 3871 #ifdef CONFIG_EXT4DEV_COMPAT
3870 static int ext4dev_get_sb(struct file_system_type *fs_type, 3872 static int ext4dev_get_sb(struct file_system_type *fs_type,
3871 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 3873 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
3872 { 3874 {
3873 printk(KERN_WARNING "EXT4-fs: Update your userspace programs " 3875 printk(KERN_WARNING "EXT4-fs: Update your userspace programs "
3874 "to mount using ext4\n"); 3876 "to mount using ext4\n");
3875 printk(KERN_WARNING "EXT4-fs: ext4dev backwards compatibility " 3877 printk(KERN_WARNING "EXT4-fs: ext4dev backwards compatibility "
3876 "will go away by 2.6.31\n"); 3878 "will go away by 2.6.31\n");
3877 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); 3879 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt);
3878 } 3880 }
3879 3881
3880 static struct file_system_type ext4dev_fs_type = { 3882 static struct file_system_type ext4dev_fs_type = {
3881 .owner = THIS_MODULE, 3883 .owner = THIS_MODULE,
3882 .name = "ext4dev", 3884 .name = "ext4dev",
3883 .get_sb = ext4dev_get_sb, 3885 .get_sb = ext4dev_get_sb,
3884 .kill_sb = kill_block_super, 3886 .kill_sb = kill_block_super,
3885 .fs_flags = FS_REQUIRES_DEV, 3887 .fs_flags = FS_REQUIRES_DEV,
3886 }; 3888 };
3887 MODULE_ALIAS("ext4dev"); 3889 MODULE_ALIAS("ext4dev");
3888 #endif 3890 #endif
3889 3891
3890 static int __init init_ext4_fs(void) 3892 static int __init init_ext4_fs(void)
3891 { 3893 {
3892 int err; 3894 int err;
3893 3895
3894 ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj); 3896 ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj);
3895 if (!ext4_kset) 3897 if (!ext4_kset)
3896 return -ENOMEM; 3898 return -ENOMEM;
3897 ext4_proc_root = proc_mkdir("fs/ext4", NULL); 3899 ext4_proc_root = proc_mkdir("fs/ext4", NULL);
3898 err = init_ext4_mballoc(); 3900 err = init_ext4_mballoc();
3899 if (err) 3901 if (err)
3900 return err; 3902 return err;
3901 3903
3902 err = init_ext4_xattr(); 3904 err = init_ext4_xattr();
3903 if (err) 3905 if (err)
3904 goto out2; 3906 goto out2;
3905 err = init_inodecache(); 3907 err = init_inodecache();
3906 if (err) 3908 if (err)
3907 goto out1; 3909 goto out1;
3908 err = register_filesystem(&ext4_fs_type); 3910 err = register_filesystem(&ext4_fs_type);
3909 if (err) 3911 if (err)
3910 goto out; 3912 goto out;
3911 #ifdef CONFIG_EXT4DEV_COMPAT 3913 #ifdef CONFIG_EXT4DEV_COMPAT
3912 err = register_filesystem(&ext4dev_fs_type); 3914 err = register_filesystem(&ext4dev_fs_type);
3913 if (err) { 3915 if (err) {
3914 unregister_filesystem(&ext4_fs_type); 3916 unregister_filesystem(&ext4_fs_type);
3915 goto out; 3917 goto out;
3916 } 3918 }
3917 #endif 3919 #endif
3918 return 0; 3920 return 0;
3919 out: 3921 out:
3920 destroy_inodecache(); 3922 destroy_inodecache();
3921 out1: 3923 out1:
3922 exit_ext4_xattr(); 3924 exit_ext4_xattr();
3923 out2: 3925 out2:
3924 exit_ext4_mballoc(); 3926 exit_ext4_mballoc();
3925 return err; 3927 return err;
3926 } 3928 }
3927 3929
3928 static void __exit exit_ext4_fs(void) 3930 static void __exit exit_ext4_fs(void)
3929 { 3931 {
3930 unregister_filesystem(&ext4_fs_type); 3932 unregister_filesystem(&ext4_fs_type);
3931 #ifdef CONFIG_EXT4DEV_COMPAT 3933 #ifdef CONFIG_EXT4DEV_COMPAT
3932 unregister_filesystem(&ext4dev_fs_type); 3934 unregister_filesystem(&ext4dev_fs_type);
3933 #endif 3935 #endif
3934 destroy_inodecache(); 3936 destroy_inodecache();
3935 exit_ext4_xattr(); 3937 exit_ext4_xattr();
3936 exit_ext4_mballoc(); 3938 exit_ext4_mballoc();
3937 remove_proc_entry("fs/ext4", NULL); 3939 remove_proc_entry("fs/ext4", NULL);
3938 kset_unregister(ext4_kset); 3940 kset_unregister(ext4_kset);
3939 } 3941 }
3940 3942
3941 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); 3943 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
3942 MODULE_DESCRIPTION("Fourth Extended Filesystem"); 3944 MODULE_DESCRIPTION("Fourth Extended Filesystem");
3943 MODULE_LICENSE("GPL"); 3945 MODULE_LICENSE("GPL");
3944 module_init(init_ext4_fs) 3946 module_init(init_ext4_fs)
3945 module_exit(exit_ext4_fs) 3947 module_exit(exit_ext4_fs)
3946 3948