diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-29 23:34:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-29 23:34:49 -0400 |
commit | c4755d16fce9a4cdbb316c17657444856821bd4b (patch) | |
tree | 56060ddcdb8e1e3ddcc7970a2324cadb3e8e4e27 | |
parent | c15a2434ed4868cad99278ac4d4ae4de9de62e02 (diff) | |
parent | f1fa3342e271029f93d323ca664809b94594fe04 (diff) |
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (48 commits)
ext4: fix hot spins in mballoc after err_freebuddy and err_freemeta
ext4: fix test ext_generic_write_end() copied return value
ext3: fix test ext_generic_write_end() copied return value
ext4: Move mballoc headers/structures to a seperate header file mballoc.h
ext4: cleanup for compiling mballoc with verification and debugging #defines
ext4: don't use ext4_error in ext4_check_descriptors
ext4: mark inode dirty after initializing the extent tree
ext4: update ctime and mtime for truncate with extents.
ext4: Don't do GFP_NOFS allocations after taking ext4_lock_group
ext4: move headers out of include/linux
ext4: fix wrong gfp type under transaction
ext4: Fix hang on umount with quotas when journal is aborted
ext4: Fix update of mtime and ctime on rename
jdb2: replace remaining __FUNCTION__ occurrences
ext4: replace remaining __FUNCTION__ occurrences
jbd2: only create debugfs and stats entries if init is successful
jbd2: fix kernel-doc notation
jbd2: replace potentially false assertion with if block
jbd2: eliminate duplicated code in revocation table init/destroy functions
jbd2: tidy up revoke cache initialisation and destruction
...
-rw-r--r-- | arch/arm/mm/mmu.c | 1 | ||||
-rw-r--r-- | arch/m68k/mm/init.c | 1 | ||||
-rw-r--r-- | arch/sparc/kernel/sparc_ksyms.c | 2 | ||||
-rw-r--r-- | arch/sparc64/mm/init.c | 1 | ||||
-rw-r--r-- | fs/ext3/inode.c | 14 | ||||
-rw-r--r-- | fs/ext4/acl.c | 12 | ||||
-rw-r--r-- | fs/ext4/balloc.c | 33 | ||||
-rw-r--r-- | fs/ext4/bitmap.c | 2 | ||||
-rw-r--r-- | fs/ext4/dir.c | 4 | ||||
-rw-r--r-- | fs/ext4/ext4.h (renamed from include/linux/ext4_fs.h) | 18 | ||||
-rw-r--r-- | fs/ext4/ext4_extents.h (renamed from include/linux/ext4_fs_extents.h) | 8 | ||||
-rw-r--r-- | fs/ext4/ext4_i.h (renamed from include/linux/ext4_fs_i.h) | 8 | ||||
-rw-r--r-- | fs/ext4/ext4_jbd2.c | 14 | ||||
-rw-r--r-- | fs/ext4/ext4_jbd2.h (renamed from include/linux/ext4_jbd2.h) | 10 | ||||
-rw-r--r-- | fs/ext4/ext4_sb.h (renamed from include/linux/ext4_fs_sb.h) | 8 | ||||
-rw-r--r-- | fs/ext4/extents.c | 354 | ||||
-rw-r--r-- | fs/ext4/file.c | 6 | ||||
-rw-r--r-- | fs/ext4/fsync.c | 7 | ||||
-rw-r--r-- | fs/ext4/hash.c | 2 | ||||
-rw-r--r-- | fs/ext4/ialloc.c | 44 | ||||
-rw-r--r-- | fs/ext4/inode.c | 57 | ||||
-rw-r--r-- | fs/ext4/ioctl.c | 16 | ||||
-rw-r--r-- | fs/ext4/mballoc.c | 437 | ||||
-rw-r--r-- | fs/ext4/mballoc.h | 304 | ||||
-rw-r--r-- | fs/ext4/migrate.c | 43 | ||||
-rw-r--r-- | fs/ext4/namei.c | 44 | ||||
-rw-r--r-- | fs/ext4/resize.c | 83 | ||||
-rw-r--r-- | fs/ext4/super.c | 66 | ||||
-rw-r--r-- | fs/ext4/symlink.c | 2 | ||||
-rw-r--r-- | fs/ext4/xattr.c | 40 | ||||
-rw-r--r-- | fs/ext4/xattr.h | 7 | ||||
-rw-r--r-- | fs/ext4/xattr_security.c | 4 | ||||
-rw-r--r-- | fs/ext4/xattr_trusted.c | 4 | ||||
-rw-r--r-- | fs/ext4/xattr_user.c | 4 | ||||
-rw-r--r-- | fs/jbd2/commit.c | 19 | ||||
-rw-r--r-- | fs/jbd2/journal.c | 38 | ||||
-rw-r--r-- | fs/jbd2/revoke.c | 165 | ||||
-rw-r--r-- | fs/jbd2/transaction.c | 41 |
38 files changed, 1086 insertions, 837 deletions
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index d41a75ed3dce..2d6d682c206a 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c | |||
@@ -35,6 +35,7 @@ extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; | |||
35 | * zero-initialized data and COW. | 35 | * zero-initialized data and COW. |
36 | */ | 36 | */ |
37 | struct page *empty_zero_page; | 37 | struct page *empty_zero_page; |
38 | EXPORT_SYMBOL(empty_zero_page); | ||
38 | 39 | ||
39 | /* | 40 | /* |
40 | * The pmd table for the upper-most set of pages. | 41 | * The pmd table for the upper-most set of pages. |
diff --git a/arch/m68k/mm/init.c b/arch/m68k/mm/init.c index a2bb01f59642..d8fb9c5303cc 100644 --- a/arch/m68k/mm/init.c +++ b/arch/m68k/mm/init.c | |||
@@ -69,6 +69,7 @@ void __init m68k_setup_node(int node) | |||
69 | */ | 69 | */ |
70 | 70 | ||
71 | void *empty_zero_page; | 71 | void *empty_zero_page; |
72 | EXPORT_SYMBOL(empty_zero_page); | ||
72 | 73 | ||
73 | void show_mem(void) | 74 | void show_mem(void) |
74 | { | 75 | { |
diff --git a/arch/sparc/kernel/sparc_ksyms.c b/arch/sparc/kernel/sparc_ksyms.c index 0bcf98a7ef38..aa8ee06cf488 100644 --- a/arch/sparc/kernel/sparc_ksyms.c +++ b/arch/sparc/kernel/sparc_ksyms.c | |||
@@ -282,3 +282,5 @@ EXPORT_SYMBOL(do_BUG); | |||
282 | 282 | ||
283 | /* Sun Power Management Idle Handler */ | 283 | /* Sun Power Management Idle Handler */ |
284 | EXPORT_SYMBOL(pm_idle); | 284 | EXPORT_SYMBOL(pm_idle); |
285 | |||
286 | EXPORT_SYMBOL(empty_zero_page); | ||
diff --git a/arch/sparc64/mm/init.c b/arch/sparc64/mm/init.c index 8c2b50e8abc6..4cad0b32b0af 100644 --- a/arch/sparc64/mm/init.c +++ b/arch/sparc64/mm/init.c | |||
@@ -160,6 +160,7 @@ extern unsigned int sparc_ramdisk_image; | |||
160 | extern unsigned int sparc_ramdisk_size; | 160 | extern unsigned int sparc_ramdisk_size; |
161 | 161 | ||
162 | struct page *mem_map_zero __read_mostly; | 162 | struct page *mem_map_zero __read_mostly; |
163 | EXPORT_SYMBOL(mem_map_zero); | ||
163 | 164 | ||
164 | unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly; | 165 | unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly; |
165 | 166 | ||
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index cc47b76091bf..6ae4ecf3ce40 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c | |||
@@ -1261,10 +1261,11 @@ static int ext3_ordered_write_end(struct file *file, | |||
1261 | new_i_size = pos + copied; | 1261 | new_i_size = pos + copied; |
1262 | if (new_i_size > EXT3_I(inode)->i_disksize) | 1262 | if (new_i_size > EXT3_I(inode)->i_disksize) |
1263 | EXT3_I(inode)->i_disksize = new_i_size; | 1263 | EXT3_I(inode)->i_disksize = new_i_size; |
1264 | copied = ext3_generic_write_end(file, mapping, pos, len, copied, | 1264 | ret2 = ext3_generic_write_end(file, mapping, pos, len, copied, |
1265 | page, fsdata); | 1265 | page, fsdata); |
1266 | if (copied < 0) | 1266 | copied = ret2; |
1267 | ret = copied; | 1267 | if (ret2 < 0) |
1268 | ret = ret2; | ||
1268 | } | 1269 | } |
1269 | ret2 = ext3_journal_stop(handle); | 1270 | ret2 = ext3_journal_stop(handle); |
1270 | if (!ret) | 1271 | if (!ret) |
@@ -1289,10 +1290,11 @@ static int ext3_writeback_write_end(struct file *file, | |||
1289 | if (new_i_size > EXT3_I(inode)->i_disksize) | 1290 | if (new_i_size > EXT3_I(inode)->i_disksize) |
1290 | EXT3_I(inode)->i_disksize = new_i_size; | 1291 | EXT3_I(inode)->i_disksize = new_i_size; |
1291 | 1292 | ||
1292 | copied = ext3_generic_write_end(file, mapping, pos, len, copied, | 1293 | ret2 = ext3_generic_write_end(file, mapping, pos, len, copied, |
1293 | page, fsdata); | 1294 | page, fsdata); |
1294 | if (copied < 0) | 1295 | copied = ret2; |
1295 | ret = copied; | 1296 | if (ret2 < 0) |
1297 | ret = ret2; | ||
1296 | 1298 | ||
1297 | ret2 = ext3_journal_stop(handle); | 1299 | ret2 = ext3_journal_stop(handle); |
1298 | if (!ret) | 1300 | if (!ret) |
diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c index a8bae8cd1d5d..3c8dab880d91 100644 --- a/fs/ext4/acl.c +++ b/fs/ext4/acl.c | |||
@@ -9,8 +9,8 @@ | |||
9 | #include <linux/slab.h> | 9 | #include <linux/slab.h> |
10 | #include <linux/capability.h> | 10 | #include <linux/capability.h> |
11 | #include <linux/fs.h> | 11 | #include <linux/fs.h> |
12 | #include <linux/ext4_jbd2.h> | 12 | #include "ext4_jbd2.h" |
13 | #include <linux/ext4_fs.h> | 13 | #include "ext4.h" |
14 | #include "xattr.h" | 14 | #include "xattr.h" |
15 | #include "acl.h" | 15 | #include "acl.h" |
16 | 16 | ||
@@ -37,7 +37,7 @@ ext4_acl_from_disk(const void *value, size_t size) | |||
37 | return ERR_PTR(-EINVAL); | 37 | return ERR_PTR(-EINVAL); |
38 | if (count == 0) | 38 | if (count == 0) |
39 | return NULL; | 39 | return NULL; |
40 | acl = posix_acl_alloc(count, GFP_KERNEL); | 40 | acl = posix_acl_alloc(count, GFP_NOFS); |
41 | if (!acl) | 41 | if (!acl) |
42 | return ERR_PTR(-ENOMEM); | 42 | return ERR_PTR(-ENOMEM); |
43 | for (n=0; n < count; n++) { | 43 | for (n=0; n < count; n++) { |
@@ -91,7 +91,7 @@ ext4_acl_to_disk(const struct posix_acl *acl, size_t *size) | |||
91 | 91 | ||
92 | *size = ext4_acl_size(acl->a_count); | 92 | *size = ext4_acl_size(acl->a_count); |
93 | ext_acl = kmalloc(sizeof(ext4_acl_header) + acl->a_count * | 93 | ext_acl = kmalloc(sizeof(ext4_acl_header) + acl->a_count * |
94 | sizeof(ext4_acl_entry), GFP_KERNEL); | 94 | sizeof(ext4_acl_entry), GFP_NOFS); |
95 | if (!ext_acl) | 95 | if (!ext_acl) |
96 | return ERR_PTR(-ENOMEM); | 96 | return ERR_PTR(-ENOMEM); |
97 | ext_acl->a_version = cpu_to_le32(EXT4_ACL_VERSION); | 97 | ext_acl->a_version = cpu_to_le32(EXT4_ACL_VERSION); |
@@ -187,7 +187,7 @@ ext4_get_acl(struct inode *inode, int type) | |||
187 | } | 187 | } |
188 | retval = ext4_xattr_get(inode, name_index, "", NULL, 0); | 188 | retval = ext4_xattr_get(inode, name_index, "", NULL, 0); |
189 | if (retval > 0) { | 189 | if (retval > 0) { |
190 | value = kmalloc(retval, GFP_KERNEL); | 190 | value = kmalloc(retval, GFP_NOFS); |
191 | if (!value) | 191 | if (!value) |
192 | return ERR_PTR(-ENOMEM); | 192 | return ERR_PTR(-ENOMEM); |
193 | retval = ext4_xattr_get(inode, name_index, "", value, retval); | 193 | retval = ext4_xattr_get(inode, name_index, "", value, retval); |
@@ -335,7 +335,7 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir) | |||
335 | if (error) | 335 | if (error) |
336 | goto cleanup; | 336 | goto cleanup; |
337 | } | 337 | } |
338 | clone = posix_acl_clone(acl, GFP_KERNEL); | 338 | clone = posix_acl_clone(acl, GFP_NOFS); |
339 | error = -ENOMEM; | 339 | error = -ENOMEM; |
340 | if (!clone) | 340 | if (!clone) |
341 | goto cleanup; | 341 | goto cleanup; |
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c index 0737e05ba3dd..da994374ec3b 100644 --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c | |||
@@ -15,12 +15,12 @@ | |||
15 | #include <linux/capability.h> | 15 | #include <linux/capability.h> |
16 | #include <linux/fs.h> | 16 | #include <linux/fs.h> |
17 | #include <linux/jbd2.h> | 17 | #include <linux/jbd2.h> |
18 | #include <linux/ext4_fs.h> | ||
19 | #include <linux/ext4_jbd2.h> | ||
20 | #include <linux/quotaops.h> | 18 | #include <linux/quotaops.h> |
21 | #include <linux/buffer_head.h> | 19 | #include <linux/buffer_head.h> |
22 | 20 | #include "ext4.h" | |
21 | #include "ext4_jbd2.h" | ||
23 | #include "group.h" | 22 | #include "group.h" |
23 | |||
24 | /* | 24 | /* |
25 | * balloc.c contains the blocks allocation and deallocation routines | 25 | * balloc.c contains the blocks allocation and deallocation routines |
26 | */ | 26 | */ |
@@ -48,7 +48,6 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr, | |||
48 | unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, | 48 | unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, |
49 | ext4_group_t block_group, struct ext4_group_desc *gdp) | 49 | ext4_group_t block_group, struct ext4_group_desc *gdp) |
50 | { | 50 | { |
51 | unsigned long start; | ||
52 | int bit, bit_max; | 51 | int bit, bit_max; |
53 | unsigned free_blocks, group_blocks; | 52 | unsigned free_blocks, group_blocks; |
54 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 53 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
@@ -59,7 +58,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, | |||
59 | /* If checksum is bad mark all blocks used to prevent allocation | 58 | /* If checksum is bad mark all blocks used to prevent allocation |
60 | * essentially implementing a per-group read-only flag. */ | 59 | * essentially implementing a per-group read-only flag. */ |
61 | if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { | 60 | if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { |
62 | ext4_error(sb, __FUNCTION__, | 61 | ext4_error(sb, __func__, |
63 | "Checksum bad for group %lu\n", block_group); | 62 | "Checksum bad for group %lu\n", block_group); |
64 | gdp->bg_free_blocks_count = 0; | 63 | gdp->bg_free_blocks_count = 0; |
65 | gdp->bg_free_inodes_count = 0; | 64 | gdp->bg_free_inodes_count = 0; |
@@ -106,11 +105,12 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, | |||
106 | free_blocks = group_blocks - bit_max; | 105 | free_blocks = group_blocks - bit_max; |
107 | 106 | ||
108 | if (bh) { | 107 | if (bh) { |
108 | ext4_fsblk_t start; | ||
109 | |||
109 | for (bit = 0; bit < bit_max; bit++) | 110 | for (bit = 0; bit < bit_max; bit++) |
110 | ext4_set_bit(bit, bh->b_data); | 111 | ext4_set_bit(bit, bh->b_data); |
111 | 112 | ||
112 | start = block_group * EXT4_BLOCKS_PER_GROUP(sb) + | 113 | start = ext4_group_first_block_no(sb, block_group); |
113 | le32_to_cpu(sbi->s_es->s_first_data_block); | ||
114 | 114 | ||
115 | /* Set bits for block and inode bitmaps, and inode table */ | 115 | /* Set bits for block and inode bitmaps, and inode table */ |
116 | ext4_set_bit(ext4_block_bitmap(sb, gdp) - start, bh->b_data); | 116 | ext4_set_bit(ext4_block_bitmap(sb, gdp) - start, bh->b_data); |
@@ -235,7 +235,7 @@ static int ext4_valid_block_bitmap(struct super_block *sb, | |||
235 | return 1; | 235 | return 1; |
236 | 236 | ||
237 | err_out: | 237 | err_out: |
238 | ext4_error(sb, __FUNCTION__, | 238 | ext4_error(sb, __func__, |
239 | "Invalid block bitmap - " | 239 | "Invalid block bitmap - " |
240 | "block_group = %d, block = %llu", | 240 | "block_group = %d, block = %llu", |
241 | block_group, bitmap_blk); | 241 | block_group, bitmap_blk); |
@@ -264,7 +264,7 @@ read_block_bitmap(struct super_block *sb, ext4_group_t block_group) | |||
264 | bitmap_blk = ext4_block_bitmap(sb, desc); | 264 | bitmap_blk = ext4_block_bitmap(sb, desc); |
265 | bh = sb_getblk(sb, bitmap_blk); | 265 | bh = sb_getblk(sb, bitmap_blk); |
266 | if (unlikely(!bh)) { | 266 | if (unlikely(!bh)) { |
267 | ext4_error(sb, __FUNCTION__, | 267 | ext4_error(sb, __func__, |
268 | "Cannot read block bitmap - " | 268 | "Cannot read block bitmap - " |
269 | "block_group = %d, block_bitmap = %llu", | 269 | "block_group = %d, block_bitmap = %llu", |
270 | (int)block_group, (unsigned long long)bitmap_blk); | 270 | (int)block_group, (unsigned long long)bitmap_blk); |
@@ -281,7 +281,7 @@ read_block_bitmap(struct super_block *sb, ext4_group_t block_group) | |||
281 | } | 281 | } |
282 | if (bh_submit_read(bh) < 0) { | 282 | if (bh_submit_read(bh) < 0) { |
283 | put_bh(bh); | 283 | put_bh(bh); |
284 | ext4_error(sb, __FUNCTION__, | 284 | ext4_error(sb, __func__, |
285 | "Cannot read block bitmap - " | 285 | "Cannot read block bitmap - " |
286 | "block_group = %d, block_bitmap = %llu", | 286 | "block_group = %d, block_bitmap = %llu", |
287 | (int)block_group, (unsigned long long)bitmap_blk); | 287 | (int)block_group, (unsigned long long)bitmap_blk); |
@@ -360,7 +360,7 @@ restart: | |||
360 | BUG(); | 360 | BUG(); |
361 | } | 361 | } |
362 | #define rsv_window_dump(root, verbose) \ | 362 | #define rsv_window_dump(root, verbose) \ |
363 | __rsv_window_dump((root), (verbose), __FUNCTION__) | 363 | __rsv_window_dump((root), (verbose), __func__) |
364 | #else | 364 | #else |
365 | #define rsv_window_dump(root, verbose) do {} while (0) | 365 | #define rsv_window_dump(root, verbose) do {} while (0) |
366 | #endif | 366 | #endif |
@@ -740,7 +740,7 @@ do_more: | |||
740 | if (!ext4_clear_bit_atomic(sb_bgl_lock(sbi, block_group), | 740 | if (!ext4_clear_bit_atomic(sb_bgl_lock(sbi, block_group), |
741 | bit + i, bitmap_bh->b_data)) { | 741 | bit + i, bitmap_bh->b_data)) { |
742 | jbd_unlock_bh_state(bitmap_bh); | 742 | jbd_unlock_bh_state(bitmap_bh); |
743 | ext4_error(sb, __FUNCTION__, | 743 | ext4_error(sb, __func__, |
744 | "bit already cleared for block %llu", | 744 | "bit already cleared for block %llu", |
745 | (ext4_fsblk_t)(block + i)); | 745 | (ext4_fsblk_t)(block + i)); |
746 | jbd_lock_bh_state(bitmap_bh); | 746 | jbd_lock_bh_state(bitmap_bh); |
@@ -752,9 +752,7 @@ do_more: | |||
752 | jbd_unlock_bh_state(bitmap_bh); | 752 | jbd_unlock_bh_state(bitmap_bh); |
753 | 753 | ||
754 | spin_lock(sb_bgl_lock(sbi, block_group)); | 754 | spin_lock(sb_bgl_lock(sbi, block_group)); |
755 | desc->bg_free_blocks_count = | 755 | le16_add_cpu(&desc->bg_free_blocks_count, group_freed); |
756 | cpu_to_le16(le16_to_cpu(desc->bg_free_blocks_count) + | ||
757 | group_freed); | ||
758 | desc->bg_checksum = ext4_group_desc_csum(sbi, block_group, desc); | 756 | desc->bg_checksum = ext4_group_desc_csum(sbi, block_group, desc); |
759 | spin_unlock(sb_bgl_lock(sbi, block_group)); | 757 | spin_unlock(sb_bgl_lock(sbi, block_group)); |
760 | percpu_counter_add(&sbi->s_freeblocks_counter, count); | 758 | percpu_counter_add(&sbi->s_freeblocks_counter, count); |
@@ -1798,7 +1796,7 @@ allocated: | |||
1798 | if (ext4_test_bit(grp_alloc_blk+i, | 1796 | if (ext4_test_bit(grp_alloc_blk+i, |
1799 | bh2jh(bitmap_bh)->b_committed_data)) { | 1797 | bh2jh(bitmap_bh)->b_committed_data)) { |
1800 | printk("%s: block was unexpectedly set in " | 1798 | printk("%s: block was unexpectedly set in " |
1801 | "b_committed_data\n", __FUNCTION__); | 1799 | "b_committed_data\n", __func__); |
1802 | } | 1800 | } |
1803 | } | 1801 | } |
1804 | } | 1802 | } |
@@ -1823,8 +1821,7 @@ allocated: | |||
1823 | spin_lock(sb_bgl_lock(sbi, group_no)); | 1821 | spin_lock(sb_bgl_lock(sbi, group_no)); |
1824 | if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) | 1822 | if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) |
1825 | gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); | 1823 | gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); |
1826 | gdp->bg_free_blocks_count = | 1824 | le16_add_cpu(&gdp->bg_free_blocks_count, -num); |
1827 | cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count)-num); | ||
1828 | gdp->bg_checksum = ext4_group_desc_csum(sbi, group_no, gdp); | 1825 | gdp->bg_checksum = ext4_group_desc_csum(sbi, group_no, gdp); |
1829 | spin_unlock(sb_bgl_lock(sbi, group_no)); | 1826 | spin_unlock(sb_bgl_lock(sbi, group_no)); |
1830 | percpu_counter_sub(&sbi->s_freeblocks_counter, num); | 1827 | percpu_counter_sub(&sbi->s_freeblocks_counter, num); |
diff --git a/fs/ext4/bitmap.c b/fs/ext4/bitmap.c index 420554f8f79d..d37ea6750454 100644 --- a/fs/ext4/bitmap.c +++ b/fs/ext4/bitmap.c | |||
@@ -9,7 +9,7 @@ | |||
9 | 9 | ||
10 | #include <linux/buffer_head.h> | 10 | #include <linux/buffer_head.h> |
11 | #include <linux/jbd2.h> | 11 | #include <linux/jbd2.h> |
12 | #include <linux/ext4_fs.h> | 12 | #include "ext4.h" |
13 | 13 | ||
14 | #ifdef EXT4FS_DEBUG | 14 | #ifdef EXT4FS_DEBUG |
15 | 15 | ||
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index 2c23bade9aa6..2bf0331ea194 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c | |||
@@ -23,10 +23,10 @@ | |||
23 | 23 | ||
24 | #include <linux/fs.h> | 24 | #include <linux/fs.h> |
25 | #include <linux/jbd2.h> | 25 | #include <linux/jbd2.h> |
26 | #include <linux/ext4_fs.h> | ||
27 | #include <linux/buffer_head.h> | 26 | #include <linux/buffer_head.h> |
28 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
29 | #include <linux/rbtree.h> | 28 | #include <linux/rbtree.h> |
29 | #include "ext4.h" | ||
30 | 30 | ||
31 | static unsigned char ext4_filetype_table[] = { | 31 | static unsigned char ext4_filetype_table[] = { |
32 | DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK | 32 | DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK |
@@ -42,7 +42,7 @@ const struct file_operations ext4_dir_operations = { | |||
42 | .llseek = generic_file_llseek, | 42 | .llseek = generic_file_llseek, |
43 | .read = generic_read_dir, | 43 | .read = generic_read_dir, |
44 | .readdir = ext4_readdir, /* we take BKL. needed?*/ | 44 | .readdir = ext4_readdir, /* we take BKL. needed?*/ |
45 | .ioctl = ext4_ioctl, /* BKL held */ | 45 | .unlocked_ioctl = ext4_ioctl, |
46 | #ifdef CONFIG_COMPAT | 46 | #ifdef CONFIG_COMPAT |
47 | .compat_ioctl = ext4_compat_ioctl, | 47 | .compat_ioctl = ext4_compat_ioctl, |
48 | #endif | 48 | #endif |
diff --git a/include/linux/ext4_fs.h b/fs/ext4/ext4.h index 250032548597..8158083f7ac0 100644 --- a/include/linux/ext4_fs.h +++ b/fs/ext4/ext4.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * linux/include/linux/ext4_fs.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) |
@@ -13,14 +13,13 @@ | |||
13 | * Copyright (C) 1991, 1992 Linus Torvalds | 13 | * Copyright (C) 1991, 1992 Linus Torvalds |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #ifndef _LINUX_EXT4_FS_H | 16 | #ifndef _EXT4_H |
17 | #define _LINUX_EXT4_FS_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 | 22 | #include "ext4_i.h" | |
23 | #include <linux/ext4_fs_i.h> | ||
24 | 23 | ||
25 | /* | 24 | /* |
26 | * The second extended filesystem constants/structures | 25 | * The second extended filesystem constants/structures |
@@ -176,8 +175,7 @@ struct ext4_group_desc | |||
176 | #define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ | 175 | #define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ |
177 | 176 | ||
178 | #ifdef __KERNEL__ | 177 | #ifdef __KERNEL__ |
179 | #include <linux/ext4_fs_i.h> | 178 | #include "ext4_sb.h" |
180 | #include <linux/ext4_fs_sb.h> | ||
181 | #endif | 179 | #endif |
182 | /* | 180 | /* |
183 | * Macro-instructions used to manage group descriptors | 181 | * Macro-instructions used to manage group descriptors |
@@ -231,6 +229,7 @@ struct ext4_group_desc | |||
231 | #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ | 229 | #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ |
232 | #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ | 230 | #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ |
233 | #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ | 231 | #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ |
232 | #define EXT4_EXT_MIGRATE 0x00100000 /* Inode is migrating */ | ||
234 | #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */ | 233 | #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */ |
235 | 234 | ||
236 | #define EXT4_FL_USER_VISIBLE 0x000BDFFF /* User visible flags */ | 235 | #define EXT4_FL_USER_VISIBLE 0x000BDFFF /* User visible flags */ |
@@ -1049,8 +1048,7 @@ extern int ext4_block_truncate_page(handle_t *handle, struct page *page, | |||
1049 | struct address_space *mapping, loff_t from); | 1048 | struct address_space *mapping, loff_t from); |
1050 | 1049 | ||
1051 | /* ioctl.c */ | 1050 | /* ioctl.c */ |
1052 | extern int ext4_ioctl (struct inode *, struct file *, unsigned int, | 1051 | extern long ext4_ioctl(struct file *, unsigned int, unsigned long); |
1053 | unsigned long); | ||
1054 | extern long ext4_compat_ioctl (struct file *, unsigned int, unsigned long); | 1052 | extern long ext4_compat_ioctl (struct file *, unsigned int, unsigned long); |
1055 | 1053 | ||
1056 | /* migrate.c */ | 1054 | /* migrate.c */ |
@@ -1204,4 +1202,4 @@ extern int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, | |||
1204 | int extend_disksize); | 1202 | int extend_disksize); |
1205 | #endif /* __KERNEL__ */ | 1203 | #endif /* __KERNEL__ */ |
1206 | 1204 | ||
1207 | #endif /* _LINUX_EXT4_FS_H */ | 1205 | #endif /* _EXT4_H */ |
diff --git a/include/linux/ext4_fs_extents.h b/fs/ext4/ext4_extents.h index 1285c583b2d8..75333b595fab 100644 --- a/include/linux/ext4_fs_extents.h +++ b/fs/ext4/ext4_extents.h | |||
@@ -16,10 +16,10 @@ | |||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111- | 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111- |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #ifndef _LINUX_EXT4_EXTENTS | 19 | #ifndef _EXT4_EXTENTS |
20 | #define _LINUX_EXT4_EXTENTS | 20 | #define _EXT4_EXTENTS |
21 | 21 | ||
22 | #include <linux/ext4_fs.h> | 22 | #include "ext4.h" |
23 | 23 | ||
24 | /* | 24 | /* |
25 | * With AGGRESSIVE_TEST defined, the capacity of index/leaf blocks | 25 | * With AGGRESSIVE_TEST defined, the capacity of index/leaf blocks |
@@ -228,5 +228,5 @@ extern int ext4_ext_search_left(struct inode *, struct ext4_ext_path *, | |||
228 | extern int ext4_ext_search_right(struct inode *, struct ext4_ext_path *, | 228 | extern int ext4_ext_search_right(struct inode *, struct ext4_ext_path *, |
229 | ext4_lblk_t *, ext4_fsblk_t *); | 229 | ext4_lblk_t *, ext4_fsblk_t *); |
230 | extern void ext4_ext_drop_refs(struct ext4_ext_path *); | 230 | extern void ext4_ext_drop_refs(struct ext4_ext_path *); |
231 | #endif /* _LINUX_EXT4_EXTENTS */ | 231 | #endif /* _EXT4_EXTENTS */ |
232 | 232 | ||
diff --git a/include/linux/ext4_fs_i.h b/fs/ext4/ext4_i.h index d5508d3cf290..26a4ae255d79 100644 --- a/include/linux/ext4_fs_i.h +++ b/fs/ext4/ext4_i.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * linux/include/linux/ext4_fs_i.h | 2 | * ext4_i.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) |
@@ -13,8 +13,8 @@ | |||
13 | * Copyright (C) 1991, 1992 Linus Torvalds | 13 | * Copyright (C) 1991, 1992 Linus Torvalds |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #ifndef _LINUX_EXT4_FS_I | 16 | #ifndef _EXT4_I |
17 | #define _LINUX_EXT4_FS_I | 17 | #define _EXT4_I |
18 | 18 | ||
19 | #include <linux/rwsem.h> | 19 | #include <linux/rwsem.h> |
20 | #include <linux/rbtree.h> | 20 | #include <linux/rbtree.h> |
@@ -164,4 +164,4 @@ struct ext4_inode_info { | |||
164 | spinlock_t i_prealloc_lock; | 164 | spinlock_t i_prealloc_lock; |
165 | }; | 165 | }; |
166 | 166 | ||
167 | #endif /* _LINUX_EXT4_FS_I */ | 167 | #endif /* _EXT4_I */ |
diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index d6afe4e27340..c75384b34f2c 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c | |||
@@ -2,14 +2,14 @@ | |||
2 | * Interface between ext4 and JBD | 2 | * Interface between ext4 and JBD |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #include <linux/ext4_jbd2.h> | 5 | #include "ext4_jbd2.h" |
6 | 6 | ||
7 | int __ext4_journal_get_undo_access(const char *where, handle_t *handle, | 7 | int __ext4_journal_get_undo_access(const char *where, handle_t *handle, |
8 | struct buffer_head *bh) | 8 | struct buffer_head *bh) |
9 | { | 9 | { |
10 | int err = jbd2_journal_get_undo_access(handle, bh); | 10 | int err = jbd2_journal_get_undo_access(handle, bh); |
11 | if (err) | 11 | if (err) |
12 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); | 12 | ext4_journal_abort_handle(where, __func__, bh, handle, err); |
13 | return err; | 13 | return err; |
14 | } | 14 | } |
15 | 15 | ||
@@ -18,7 +18,7 @@ int __ext4_journal_get_write_access(const char *where, handle_t *handle, | |||
18 | { | 18 | { |
19 | int err = jbd2_journal_get_write_access(handle, bh); | 19 | int err = jbd2_journal_get_write_access(handle, bh); |
20 | if (err) | 20 | if (err) |
21 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); | 21 | ext4_journal_abort_handle(where, __func__, bh, handle, err); |
22 | return err; | 22 | return err; |
23 | } | 23 | } |
24 | 24 | ||
@@ -27,7 +27,7 @@ int __ext4_journal_forget(const char *where, handle_t *handle, | |||
27 | { | 27 | { |
28 | int err = jbd2_journal_forget(handle, bh); | 28 | int err = jbd2_journal_forget(handle, bh); |
29 | if (err) | 29 | if (err) |
30 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); | 30 | ext4_journal_abort_handle(where, __func__, bh, handle, err); |
31 | return err; | 31 | return err; |
32 | } | 32 | } |
33 | 33 | ||
@@ -36,7 +36,7 @@ int __ext4_journal_revoke(const char *where, handle_t *handle, | |||
36 | { | 36 | { |
37 | int err = jbd2_journal_revoke(handle, blocknr, bh); | 37 | int err = jbd2_journal_revoke(handle, blocknr, bh); |
38 | if (err) | 38 | if (err) |
39 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); | 39 | ext4_journal_abort_handle(where, __func__, bh, handle, err); |
40 | return err; | 40 | return err; |
41 | } | 41 | } |
42 | 42 | ||
@@ -45,7 +45,7 @@ int __ext4_journal_get_create_access(const char *where, | |||
45 | { | 45 | { |
46 | int err = jbd2_journal_get_create_access(handle, bh); | 46 | int err = jbd2_journal_get_create_access(handle, bh); |
47 | if (err) | 47 | if (err) |
48 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); | 48 | ext4_journal_abort_handle(where, __func__, bh, handle, err); |
49 | return err; | 49 | return err; |
50 | } | 50 | } |
51 | 51 | ||
@@ -54,6 +54,6 @@ int __ext4_journal_dirty_metadata(const char *where, | |||
54 | { | 54 | { |
55 | int err = jbd2_journal_dirty_metadata(handle, bh); | 55 | int err = jbd2_journal_dirty_metadata(handle, bh); |
56 | if (err) | 56 | if (err) |
57 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); | 57 | ext4_journal_abort_handle(where, __func__, bh, handle, err); |
58 | return err; | 58 | return err; |
59 | } | 59 | } |
diff --git a/include/linux/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index 38c71d3c8dbf..9255a7d28b24 100644 --- a/include/linux/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * linux/include/linux/ext4_jbd2.h | 2 | * ext4_jbd2.h |
3 | * | 3 | * |
4 | * Written by Stephen C. Tweedie <sct@redhat.com>, 1999 | 4 | * Written by Stephen C. Tweedie <sct@redhat.com>, 1999 |
5 | * | 5 | * |
@@ -12,12 +12,12 @@ | |||
12 | * Ext4-specific journaling extensions. | 12 | * Ext4-specific journaling extensions. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #ifndef _LINUX_EXT4_JBD2_H | 15 | #ifndef _EXT4_JBD2_H |
16 | #define _LINUX_EXT4_JBD2_H | 16 | #define _EXT4_JBD2_H |
17 | 17 | ||
18 | #include <linux/fs.h> | 18 | #include <linux/fs.h> |
19 | #include <linux/jbd2.h> | 19 | #include <linux/jbd2.h> |
20 | #include <linux/ext4_fs.h> | 20 | #include "ext4.h" |
21 | 21 | ||
22 | #define EXT4_JOURNAL(inode) (EXT4_SB((inode)->i_sb)->s_journal) | 22 | #define EXT4_JOURNAL(inode) (EXT4_SB((inode)->i_sb)->s_journal) |
23 | 23 | ||
@@ -228,4 +228,4 @@ static inline int ext4_should_writeback_data(struct inode *inode) | |||
228 | return 0; | 228 | return 0; |
229 | } | 229 | } |
230 | 230 | ||
231 | #endif /* _LINUX_EXT4_JBD2_H */ | 231 | #endif /* _EXT4_JBD2_H */ |
diff --git a/include/linux/ext4_fs_sb.h b/fs/ext4/ext4_sb.h index abaae2c8cccf..5802e69f2191 100644 --- a/include/linux/ext4_fs_sb.h +++ b/fs/ext4/ext4_sb.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * linux/include/linux/ext4_fs_sb.h | 2 | * ext4_sb.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) |
@@ -13,8 +13,8 @@ | |||
13 | * Copyright (C) 1991, 1992 Linus Torvalds | 13 | * Copyright (C) 1991, 1992 Linus Torvalds |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #ifndef _LINUX_EXT4_FS_SB | 16 | #ifndef _EXT4_SB |
17 | #define _LINUX_EXT4_FS_SB | 17 | #define _EXT4_SB |
18 | 18 | ||
19 | #ifdef __KERNEL__ | 19 | #ifdef __KERNEL__ |
20 | #include <linux/timer.h> | 20 | #include <linux/timer.h> |
@@ -145,4 +145,4 @@ struct ext4_sb_info { | |||
145 | struct ext4_locality_group *s_locality_groups; | 145 | struct ext4_locality_group *s_locality_groups; |
146 | }; | 146 | }; |
147 | 147 | ||
148 | #endif /* _LINUX_EXT4_FS_SB */ | 148 | #endif /* _EXT4_SB */ |
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 9ae6e67090cd..47929c4e3dae 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -32,7 +32,6 @@ | |||
32 | #include <linux/module.h> | 32 | #include <linux/module.h> |
33 | #include <linux/fs.h> | 33 | #include <linux/fs.h> |
34 | #include <linux/time.h> | 34 | #include <linux/time.h> |
35 | #include <linux/ext4_jbd2.h> | ||
36 | #include <linux/jbd2.h> | 35 | #include <linux/jbd2.h> |
37 | #include <linux/highuid.h> | 36 | #include <linux/highuid.h> |
38 | #include <linux/pagemap.h> | 37 | #include <linux/pagemap.h> |
@@ -40,8 +39,9 @@ | |||
40 | #include <linux/string.h> | 39 | #include <linux/string.h> |
41 | #include <linux/slab.h> | 40 | #include <linux/slab.h> |
42 | #include <linux/falloc.h> | 41 | #include <linux/falloc.h> |
43 | #include <linux/ext4_fs_extents.h> | ||
44 | #include <asm/uaccess.h> | 42 | #include <asm/uaccess.h> |
43 | #include "ext4_jbd2.h" | ||
44 | #include "ext4_extents.h" | ||
45 | 45 | ||
46 | 46 | ||
47 | /* | 47 | /* |
@@ -308,7 +308,7 @@ corrupted: | |||
308 | } | 308 | } |
309 | 309 | ||
310 | #define ext4_ext_check_header(inode, eh, depth) \ | 310 | #define ext4_ext_check_header(inode, eh, depth) \ |
311 | __ext4_ext_check_header(__FUNCTION__, inode, eh, depth) | 311 | __ext4_ext_check_header(__func__, inode, eh, depth) |
312 | 312 | ||
313 | #ifdef EXT_DEBUG | 313 | #ifdef EXT_DEBUG |
314 | static void ext4_ext_show_path(struct inode *inode, struct ext4_ext_path *path) | 314 | static void ext4_ext_show_path(struct inode *inode, struct ext4_ext_path *path) |
@@ -614,7 +614,7 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode, | |||
614 | 614 | ||
615 | ix->ei_block = cpu_to_le32(logical); | 615 | ix->ei_block = cpu_to_le32(logical); |
616 | ext4_idx_store_pblock(ix, ptr); | 616 | ext4_idx_store_pblock(ix, ptr); |
617 | curp->p_hdr->eh_entries = cpu_to_le16(le16_to_cpu(curp->p_hdr->eh_entries)+1); | 617 | le16_add_cpu(&curp->p_hdr->eh_entries, 1); |
618 | 618 | ||
619 | BUG_ON(le16_to_cpu(curp->p_hdr->eh_entries) | 619 | BUG_ON(le16_to_cpu(curp->p_hdr->eh_entries) |
620 | > le16_to_cpu(curp->p_hdr->eh_max)); | 620 | > le16_to_cpu(curp->p_hdr->eh_max)); |
@@ -736,7 +736,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode, | |||
736 | } | 736 | } |
737 | if (m) { | 737 | if (m) { |
738 | memmove(ex, path[depth].p_ext-m, sizeof(struct ext4_extent)*m); | 738 | memmove(ex, path[depth].p_ext-m, sizeof(struct ext4_extent)*m); |
739 | neh->eh_entries = cpu_to_le16(le16_to_cpu(neh->eh_entries)+m); | 739 | le16_add_cpu(&neh->eh_entries, m); |
740 | } | 740 | } |
741 | 741 | ||
742 | set_buffer_uptodate(bh); | 742 | set_buffer_uptodate(bh); |
@@ -753,8 +753,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode, | |||
753 | err = ext4_ext_get_access(handle, inode, path + depth); | 753 | err = ext4_ext_get_access(handle, inode, path + depth); |
754 | if (err) | 754 | if (err) |
755 | goto cleanup; | 755 | goto cleanup; |
756 | path[depth].p_hdr->eh_entries = | 756 | le16_add_cpu(&path[depth].p_hdr->eh_entries, -m); |
757 | cpu_to_le16(le16_to_cpu(path[depth].p_hdr->eh_entries)-m); | ||
758 | err = ext4_ext_dirty(handle, inode, path + depth); | 757 | err = ext4_ext_dirty(handle, inode, path + depth); |
759 | if (err) | 758 | if (err) |
760 | goto cleanup; | 759 | goto cleanup; |
@@ -817,8 +816,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode, | |||
817 | if (m) { | 816 | if (m) { |
818 | memmove(++fidx, path[i].p_idx - m, | 817 | memmove(++fidx, path[i].p_idx - m, |
819 | sizeof(struct ext4_extent_idx) * m); | 818 | sizeof(struct ext4_extent_idx) * m); |
820 | neh->eh_entries = | 819 | le16_add_cpu(&neh->eh_entries, m); |
821 | cpu_to_le16(le16_to_cpu(neh->eh_entries) + m); | ||
822 | } | 820 | } |
823 | set_buffer_uptodate(bh); | 821 | set_buffer_uptodate(bh); |
824 | unlock_buffer(bh); | 822 | unlock_buffer(bh); |
@@ -834,7 +832,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode, | |||
834 | err = ext4_ext_get_access(handle, inode, path + i); | 832 | err = ext4_ext_get_access(handle, inode, path + i); |
835 | if (err) | 833 | if (err) |
836 | goto cleanup; | 834 | goto cleanup; |
837 | path[i].p_hdr->eh_entries = cpu_to_le16(le16_to_cpu(path[i].p_hdr->eh_entries)-m); | 835 | le16_add_cpu(&path[i].p_hdr->eh_entries, -m); |
838 | err = ext4_ext_dirty(handle, inode, path + i); | 836 | err = ext4_ext_dirty(handle, inode, path + i); |
839 | if (err) | 837 | if (err) |
840 | goto cleanup; | 838 | goto cleanup; |
@@ -1369,7 +1367,7 @@ int ext4_ext_try_to_merge(struct inode *inode, | |||
1369 | * sizeof(struct ext4_extent); | 1367 | * sizeof(struct ext4_extent); |
1370 | memmove(ex + 1, ex + 2, len); | 1368 | memmove(ex + 1, ex + 2, len); |
1371 | } | 1369 | } |
1372 | eh->eh_entries = cpu_to_le16(le16_to_cpu(eh->eh_entries) - 1); | 1370 | le16_add_cpu(&eh->eh_entries, -1); |
1373 | merge_done = 1; | 1371 | merge_done = 1; |
1374 | WARN_ON(eh->eh_entries == 0); | 1372 | WARN_ON(eh->eh_entries == 0); |
1375 | if (!eh->eh_entries) | 1373 | if (!eh->eh_entries) |
@@ -1560,7 +1558,7 @@ has_space: | |||
1560 | path[depth].p_ext = nearex; | 1558 | path[depth].p_ext = nearex; |
1561 | } | 1559 | } |
1562 | 1560 | ||
1563 | eh->eh_entries = cpu_to_le16(le16_to_cpu(eh->eh_entries)+1); | 1561 | le16_add_cpu(&eh->eh_entries, 1); |
1564 | nearex = path[depth].p_ext; | 1562 | nearex = path[depth].p_ext; |
1565 | nearex->ee_block = newext->ee_block; | 1563 | nearex->ee_block = newext->ee_block; |
1566 | ext4_ext_store_pblock(nearex, ext_pblock(newext)); | 1564 | ext4_ext_store_pblock(nearex, ext_pblock(newext)); |
@@ -1699,7 +1697,7 @@ static int ext4_ext_rm_idx(handle_t *handle, struct inode *inode, | |||
1699 | err = ext4_ext_get_access(handle, inode, path); | 1697 | err = ext4_ext_get_access(handle, inode, path); |
1700 | if (err) | 1698 | if (err) |
1701 | return err; | 1699 | return err; |
1702 | path->p_hdr->eh_entries = cpu_to_le16(le16_to_cpu(path->p_hdr->eh_entries)-1); | 1700 | le16_add_cpu(&path->p_hdr->eh_entries, -1); |
1703 | err = ext4_ext_dirty(handle, inode, path); | 1701 | err = ext4_ext_dirty(handle, inode, path); |
1704 | if (err) | 1702 | if (err) |
1705 | return err; | 1703 | return err; |
@@ -1902,7 +1900,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, | |||
1902 | if (num == 0) { | 1900 | if (num == 0) { |
1903 | /* this extent is removed; mark slot entirely unused */ | 1901 | /* this extent is removed; mark slot entirely unused */ |
1904 | ext4_ext_store_pblock(ex, 0); | 1902 | ext4_ext_store_pblock(ex, 0); |
1905 | eh->eh_entries = cpu_to_le16(le16_to_cpu(eh->eh_entries)-1); | 1903 | le16_add_cpu(&eh->eh_entries, -1); |
1906 | } | 1904 | } |
1907 | 1905 | ||
1908 | ex->ee_block = cpu_to_le32(block); | 1906 | ex->ee_block = cpu_to_le32(block); |
@@ -1979,7 +1977,7 @@ static int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start) | |||
1979 | * We start scanning from right side, freeing all the blocks | 1977 | * We start scanning from right side, freeing all the blocks |
1980 | * after i_size and walking into the tree depth-wise. | 1978 | * after i_size and walking into the tree depth-wise. |
1981 | */ | 1979 | */ |
1982 | path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 1), GFP_KERNEL); | 1980 | path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 1), GFP_NOFS); |
1983 | if (path == NULL) { | 1981 | if (path == NULL) { |
1984 | ext4_journal_stop(handle); | 1982 | ext4_journal_stop(handle); |
1985 | return -ENOMEM; | 1983 | return -ENOMEM; |
@@ -2138,6 +2136,82 @@ void ext4_ext_release(struct super_block *sb) | |||
2138 | #endif | 2136 | #endif |
2139 | } | 2137 | } |
2140 | 2138 | ||
2139 | static void bi_complete(struct bio *bio, int error) | ||
2140 | { | ||
2141 | complete((struct completion *)bio->bi_private); | ||
2142 | } | ||
2143 | |||
2144 | /* FIXME!! we need to try to merge to left or right after zero-out */ | ||
2145 | static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex) | ||
2146 | { | ||
2147 | int ret = -EIO; | ||
2148 | struct bio *bio; | ||
2149 | int blkbits, blocksize; | ||
2150 | sector_t ee_pblock; | ||
2151 | struct completion event; | ||
2152 | unsigned int ee_len, len, done, offset; | ||
2153 | |||
2154 | |||
2155 | blkbits = inode->i_blkbits; | ||
2156 | blocksize = inode->i_sb->s_blocksize; | ||
2157 | ee_len = ext4_ext_get_actual_len(ex); | ||
2158 | ee_pblock = ext_pblock(ex); | ||
2159 | |||
2160 | /* convert ee_pblock to 512 byte sectors */ | ||
2161 | ee_pblock = ee_pblock << (blkbits - 9); | ||
2162 | |||
2163 | while (ee_len > 0) { | ||
2164 | |||
2165 | if (ee_len > BIO_MAX_PAGES) | ||
2166 | len = BIO_MAX_PAGES; | ||
2167 | else | ||
2168 | len = ee_len; | ||
2169 | |||
2170 | bio = bio_alloc(GFP_NOIO, len); | ||
2171 | if (!bio) | ||
2172 | return -ENOMEM; | ||
2173 | bio->bi_sector = ee_pblock; | ||
2174 | bio->bi_bdev = inode->i_sb->s_bdev; | ||
2175 | |||
2176 | done = 0; | ||
2177 | offset = 0; | ||
2178 | while (done < len) { | ||
2179 | ret = bio_add_page(bio, ZERO_PAGE(0), | ||
2180 | blocksize, offset); | ||
2181 | if (ret != blocksize) { | ||
2182 | /* | ||
2183 | * We can't add any more pages because of | ||
2184 | * hardware limitations. Start a new bio. | ||
2185 | */ | ||
2186 | break; | ||
2187 | } | ||
2188 | done++; | ||
2189 | offset += blocksize; | ||
2190 | if (offset >= PAGE_CACHE_SIZE) | ||
2191 | offset = 0; | ||
2192 | } | ||
2193 | |||
2194 | init_completion(&event); | ||
2195 | bio->bi_private = &event; | ||
2196 | bio->bi_end_io = bi_complete; | ||
2197 | submit_bio(WRITE, bio); | ||
2198 | wait_for_completion(&event); | ||
2199 | |||
2200 | if (test_bit(BIO_UPTODATE, &bio->bi_flags)) | ||
2201 | ret = 0; | ||
2202 | else { | ||
2203 | ret = -EIO; | ||
2204 | break; | ||
2205 | } | ||
2206 | bio_put(bio); | ||
2207 | ee_len -= done; | ||
2208 | ee_pblock += done << (blkbits - 9); | ||
2209 | } | ||
2210 | return ret; | ||
2211 | } | ||
2212 | |||
2213 | #define EXT4_EXT_ZERO_LEN 7 | ||
2214 | |||
2141 | /* | 2215 | /* |
2142 | * This function is called by ext4_ext_get_blocks() if someone tries to write | 2216 | * This function is called by ext4_ext_get_blocks() if someone tries to write |
2143 | * to an uninitialized extent. It may result in splitting the uninitialized | 2217 | * to an uninitialized extent. It may result in splitting the uninitialized |
@@ -2154,7 +2228,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, | |||
2154 | ext4_lblk_t iblock, | 2228 | ext4_lblk_t iblock, |
2155 | unsigned long max_blocks) | 2229 | unsigned long max_blocks) |
2156 | { | 2230 | { |
2157 | struct ext4_extent *ex, newex; | 2231 | struct ext4_extent *ex, newex, orig_ex; |
2158 | struct ext4_extent *ex1 = NULL; | 2232 | struct ext4_extent *ex1 = NULL; |
2159 | struct ext4_extent *ex2 = NULL; | 2233 | struct ext4_extent *ex2 = NULL; |
2160 | struct ext4_extent *ex3 = NULL; | 2234 | struct ext4_extent *ex3 = NULL; |
@@ -2173,10 +2247,26 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, | |||
2173 | allocated = ee_len - (iblock - ee_block); | 2247 | allocated = ee_len - (iblock - ee_block); |
2174 | newblock = iblock - ee_block + ext_pblock(ex); | 2248 | newblock = iblock - ee_block + ext_pblock(ex); |
2175 | ex2 = ex; | 2249 | ex2 = ex; |
2250 | orig_ex.ee_block = ex->ee_block; | ||
2251 | orig_ex.ee_len = cpu_to_le16(ee_len); | ||
2252 | ext4_ext_store_pblock(&orig_ex, ext_pblock(ex)); | ||
2176 | 2253 | ||
2177 | err = ext4_ext_get_access(handle, inode, path + depth); | 2254 | err = ext4_ext_get_access(handle, inode, path + depth); |
2178 | if (err) | 2255 | if (err) |
2179 | goto out; | 2256 | goto out; |
2257 | /* If extent has less than 2*EXT4_EXT_ZERO_LEN zerout directly */ | ||
2258 | if (ee_len <= 2*EXT4_EXT_ZERO_LEN) { | ||
2259 | err = ext4_ext_zeroout(inode, &orig_ex); | ||
2260 | if (err) | ||
2261 | goto fix_extent_len; | ||
2262 | /* update the extent length and mark as initialized */ | ||
2263 | ex->ee_block = orig_ex.ee_block; | ||
2264 | ex->ee_len = orig_ex.ee_len; | ||
2265 | ext4_ext_store_pblock(ex, ext_pblock(&orig_ex)); | ||
2266 | ext4_ext_dirty(handle, inode, path + depth); | ||
2267 | /* zeroed the full extent */ | ||
2268 | return allocated; | ||
2269 | } | ||
2180 | 2270 | ||
2181 | /* ex1: ee_block to iblock - 1 : uninitialized */ | 2271 | /* ex1: ee_block to iblock - 1 : uninitialized */ |
2182 | if (iblock > ee_block) { | 2272 | if (iblock > ee_block) { |
@@ -2195,19 +2285,103 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, | |||
2195 | /* ex3: to ee_block + ee_len : uninitialised */ | 2285 | /* ex3: to ee_block + ee_len : uninitialised */ |
2196 | if (allocated > max_blocks) { | 2286 | if (allocated > max_blocks) { |
2197 | unsigned int newdepth; | 2287 | unsigned int newdepth; |
2288 | /* If extent has less than EXT4_EXT_ZERO_LEN zerout directly */ | ||
2289 | if (allocated <= EXT4_EXT_ZERO_LEN) { | ||
2290 | /* Mark first half uninitialized. | ||
2291 | * Mark second half initialized and zero out the | ||
2292 | * initialized extent | ||
2293 | */ | ||
2294 | ex->ee_block = orig_ex.ee_block; | ||
2295 | ex->ee_len = cpu_to_le16(ee_len - allocated); | ||
2296 | ext4_ext_mark_uninitialized(ex); | ||
2297 | ext4_ext_store_pblock(ex, ext_pblock(&orig_ex)); | ||
2298 | ext4_ext_dirty(handle, inode, path + depth); | ||
2299 | |||
2300 | ex3 = &newex; | ||
2301 | ex3->ee_block = cpu_to_le32(iblock); | ||
2302 | ext4_ext_store_pblock(ex3, newblock); | ||
2303 | ex3->ee_len = cpu_to_le16(allocated); | ||
2304 | err = ext4_ext_insert_extent(handle, inode, path, ex3); | ||
2305 | if (err == -ENOSPC) { | ||
2306 | err = ext4_ext_zeroout(inode, &orig_ex); | ||
2307 | if (err) | ||
2308 | goto fix_extent_len; | ||
2309 | ex->ee_block = orig_ex.ee_block; | ||
2310 | ex->ee_len = orig_ex.ee_len; | ||
2311 | ext4_ext_store_pblock(ex, ext_pblock(&orig_ex)); | ||
2312 | ext4_ext_dirty(handle, inode, path + depth); | ||
2313 | /* zeroed the full extent */ | ||
2314 | return allocated; | ||
2315 | |||
2316 | } else if (err) | ||
2317 | goto fix_extent_len; | ||
2318 | |||
2319 | /* | ||
2320 | * We need to zero out the second half because | ||
2321 | * an fallocate request can update file size and | ||
2322 | * converting the second half to initialized extent | ||
2323 | * implies that we can leak some junk data to user | ||
2324 | * space. | ||
2325 | */ | ||
2326 | err = ext4_ext_zeroout(inode, ex3); | ||
2327 | if (err) { | ||
2328 | /* | ||
2329 | * We should actually mark the | ||
2330 | * second half as uninit and return error | ||
2331 | * Insert would have changed the extent | ||
2332 | */ | ||
2333 | depth = ext_depth(inode); | ||
2334 | ext4_ext_drop_refs(path); | ||
2335 | path = ext4_ext_find_extent(inode, | ||
2336 | iblock, path); | ||
2337 | if (IS_ERR(path)) { | ||
2338 | err = PTR_ERR(path); | ||
2339 | return err; | ||
2340 | } | ||
2341 | ex = path[depth].p_ext; | ||
2342 | err = ext4_ext_get_access(handle, inode, | ||
2343 | path + depth); | ||
2344 | if (err) | ||
2345 | return err; | ||
2346 | ext4_ext_mark_uninitialized(ex); | ||
2347 | ext4_ext_dirty(handle, inode, path + depth); | ||
2348 | return err; | ||
2349 | } | ||
2350 | |||
2351 | /* zeroed the second half */ | ||
2352 | return allocated; | ||
2353 | } | ||
2198 | ex3 = &newex; | 2354 | ex3 = &newex; |
2199 | ex3->ee_block = cpu_to_le32(iblock + max_blocks); | 2355 | ex3->ee_block = cpu_to_le32(iblock + max_blocks); |
2200 | ext4_ext_store_pblock(ex3, newblock + max_blocks); | 2356 | ext4_ext_store_pblock(ex3, newblock + max_blocks); |
2201 | ex3->ee_len = cpu_to_le16(allocated - max_blocks); | 2357 | ex3->ee_len = cpu_to_le16(allocated - max_blocks); |
2202 | ext4_ext_mark_uninitialized(ex3); | 2358 | ext4_ext_mark_uninitialized(ex3); |
2203 | err = ext4_ext_insert_extent(handle, inode, path, ex3); | 2359 | err = ext4_ext_insert_extent(handle, inode, path, ex3); |
2204 | if (err) | 2360 | if (err == -ENOSPC) { |
2205 | goto out; | 2361 | err = ext4_ext_zeroout(inode, &orig_ex); |
2362 | if (err) | ||
2363 | goto fix_extent_len; | ||
2364 | /* update the extent length and mark as initialized */ | ||
2365 | ex->ee_block = orig_ex.ee_block; | ||
2366 | ex->ee_len = orig_ex.ee_len; | ||
2367 | ext4_ext_store_pblock(ex, ext_pblock(&orig_ex)); | ||
2368 | ext4_ext_dirty(handle, inode, path + depth); | ||
2369 | /* zeroed the full extent */ | ||
2370 | return allocated; | ||
2371 | |||
2372 | } else if (err) | ||
2373 | goto fix_extent_len; | ||
2206 | /* | 2374 | /* |
2207 | * The depth, and hence eh & ex might change | 2375 | * The depth, and hence eh & ex might change |
2208 | * as part of the insert above. | 2376 | * as part of the insert above. |
2209 | */ | 2377 | */ |
2210 | newdepth = ext_depth(inode); | 2378 | newdepth = ext_depth(inode); |
2379 | /* | ||
2380 | * update the extent length after successfull insert of the | ||
2381 | * split extent | ||
2382 | */ | ||
2383 | orig_ex.ee_len = cpu_to_le16(ee_len - | ||
2384 | ext4_ext_get_actual_len(ex3)); | ||
2211 | if (newdepth != depth) { | 2385 | if (newdepth != depth) { |
2212 | depth = newdepth; | 2386 | depth = newdepth; |
2213 | ext4_ext_drop_refs(path); | 2387 | ext4_ext_drop_refs(path); |
@@ -2226,6 +2400,24 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, | |||
2226 | goto out; | 2400 | goto out; |
2227 | } | 2401 | } |
2228 | allocated = max_blocks; | 2402 | allocated = max_blocks; |
2403 | |||
2404 | /* If extent has less than EXT4_EXT_ZERO_LEN and we are trying | ||
2405 | * to insert a extent in the middle zerout directly | ||
2406 | * otherwise give the extent a chance to merge to left | ||
2407 | */ | ||
2408 | if (le16_to_cpu(orig_ex.ee_len) <= EXT4_EXT_ZERO_LEN && | ||
2409 | iblock != ee_block) { | ||
2410 | err = ext4_ext_zeroout(inode, &orig_ex); | ||
2411 | if (err) | ||
2412 | goto fix_extent_len; | ||
2413 | /* update the extent length and mark as initialized */ | ||
2414 | ex->ee_block = orig_ex.ee_block; | ||
2415 | ex->ee_len = orig_ex.ee_len; | ||
2416 | ext4_ext_store_pblock(ex, ext_pblock(&orig_ex)); | ||
2417 | ext4_ext_dirty(handle, inode, path + depth); | ||
2418 | /* zero out the first half */ | ||
2419 | return allocated; | ||
2420 | } | ||
2229 | } | 2421 | } |
2230 | /* | 2422 | /* |
2231 | * If there was a change of depth as part of the | 2423 | * If there was a change of depth as part of the |
@@ -2282,8 +2474,29 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, | |||
2282 | goto out; | 2474 | goto out; |
2283 | insert: | 2475 | insert: |
2284 | err = ext4_ext_insert_extent(handle, inode, path, &newex); | 2476 | err = ext4_ext_insert_extent(handle, inode, path, &newex); |
2477 | if (err == -ENOSPC) { | ||
2478 | err = ext4_ext_zeroout(inode, &orig_ex); | ||
2479 | if (err) | ||
2480 | goto fix_extent_len; | ||
2481 | /* update the extent length and mark as initialized */ | ||
2482 | ex->ee_block = orig_ex.ee_block; | ||
2483 | ex->ee_len = orig_ex.ee_len; | ||
2484 | ext4_ext_store_pblock(ex, ext_pblock(&orig_ex)); | ||
2485 | ext4_ext_dirty(handle, inode, path + depth); | ||
2486 | /* zero out the first half */ | ||
2487 | return allocated; | ||
2488 | } else if (err) | ||
2489 | goto fix_extent_len; | ||
2285 | out: | 2490 | out: |
2286 | return err ? err : allocated; | 2491 | return err ? err : allocated; |
2492 | |||
2493 | fix_extent_len: | ||
2494 | ex->ee_block = orig_ex.ee_block; | ||
2495 | ex->ee_len = orig_ex.ee_len; | ||
2496 | ext4_ext_store_pblock(ex, ext_pblock(&orig_ex)); | ||
2497 | ext4_ext_mark_uninitialized(ex); | ||
2498 | ext4_ext_dirty(handle, inode, path + depth); | ||
2499 | return err; | ||
2287 | } | 2500 | } |
2288 | 2501 | ||
2289 | /* | 2502 | /* |
@@ -2393,8 +2606,20 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, | |||
2393 | } | 2606 | } |
2394 | if (create == EXT4_CREATE_UNINITIALIZED_EXT) | 2607 | if (create == EXT4_CREATE_UNINITIALIZED_EXT) |
2395 | goto out; | 2608 | goto out; |
2396 | if (!create) | 2609 | if (!create) { |
2610 | /* | ||
2611 | * We have blocks reserved already. We | ||
2612 | * return allocated blocks so that delalloc | ||
2613 | * won't do block reservation for us. But | ||
2614 | * the buffer head will be unmapped so that | ||
2615 | * a read from the block returns 0s. | ||
2616 | */ | ||
2617 | if (allocated > max_blocks) | ||
2618 | allocated = max_blocks; | ||
2619 | /* mark the buffer unwritten */ | ||
2620 | __set_bit(BH_Unwritten, &bh_result->b_state); | ||
2397 | goto out2; | 2621 | goto out2; |
2622 | } | ||
2398 | 2623 | ||
2399 | ret = ext4_ext_convert_to_initialized(handle, inode, | 2624 | ret = ext4_ext_convert_to_initialized(handle, inode, |
2400 | path, iblock, | 2625 | path, iblock, |
@@ -2584,6 +2809,8 @@ out_stop: | |||
2584 | ext4_orphan_del(handle, inode); | 2809 | ext4_orphan_del(handle, inode); |
2585 | 2810 | ||
2586 | up_write(&EXT4_I(inode)->i_data_sem); | 2811 | up_write(&EXT4_I(inode)->i_data_sem); |
2812 | inode->i_mtime = inode->i_ctime = ext4_current_time(inode); | ||
2813 | ext4_mark_inode_dirty(handle, inode); | ||
2587 | ext4_journal_stop(handle); | 2814 | ext4_journal_stop(handle); |
2588 | } | 2815 | } |
2589 | 2816 | ||
@@ -2608,6 +2835,28 @@ int ext4_ext_writepage_trans_blocks(struct inode *inode, int num) | |||
2608 | return needed; | 2835 | return needed; |
2609 | } | 2836 | } |
2610 | 2837 | ||
2838 | static void ext4_falloc_update_inode(struct inode *inode, | ||
2839 | int mode, loff_t new_size, int update_ctime) | ||
2840 | { | ||
2841 | struct timespec now; | ||
2842 | |||
2843 | if (update_ctime) { | ||
2844 | now = current_fs_time(inode->i_sb); | ||
2845 | if (!timespec_equal(&inode->i_ctime, &now)) | ||
2846 | inode->i_ctime = now; | ||
2847 | } | ||
2848 | /* | ||
2849 | * Update only when preallocation was requested beyond | ||
2850 | * the file size. | ||
2851 | */ | ||
2852 | if (!(mode & FALLOC_FL_KEEP_SIZE) && | ||
2853 | new_size > i_size_read(inode)) { | ||
2854 | i_size_write(inode, new_size); | ||
2855 | EXT4_I(inode)->i_disksize = new_size; | ||
2856 | } | ||
2857 | |||
2858 | } | ||
2859 | |||
2611 | /* | 2860 | /* |
2612 | * preallocate space for a file. This implements ext4's fallocate inode | 2861 | * preallocate space for a file. This implements ext4's fallocate inode |
2613 | * operation, which gets called from sys_fallocate system call. | 2862 | * operation, which gets called from sys_fallocate system call. |
@@ -2619,8 +2868,8 @@ long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len) | |||
2619 | { | 2868 | { |
2620 | handle_t *handle; | 2869 | handle_t *handle; |
2621 | ext4_lblk_t block; | 2870 | ext4_lblk_t block; |
2871 | loff_t new_size; | ||
2622 | unsigned long max_blocks; | 2872 | unsigned long max_blocks; |
2623 | ext4_fsblk_t nblocks = 0; | ||
2624 | int ret = 0; | 2873 | int ret = 0; |
2625 | int ret2 = 0; | 2874 | int ret2 = 0; |
2626 | int retries = 0; | 2875 | int retries = 0; |
@@ -2639,9 +2888,12 @@ long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len) | |||
2639 | return -ENODEV; | 2888 | return -ENODEV; |
2640 | 2889 | ||
2641 | block = offset >> blkbits; | 2890 | block = offset >> blkbits; |
2891 | /* | ||
2892 | * We can't just convert len to max_blocks because | ||
2893 | * If blocksize = 4096 offset = 3072 and len = 2048 | ||
2894 | */ | ||
2642 | max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) | 2895 | max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) |
2643 | - block; | 2896 | - block; |
2644 | |||
2645 | /* | 2897 | /* |
2646 | * credits to insert 1 extent into extent tree + buffers to be able to | 2898 | * credits to insert 1 extent into extent tree + buffers to be able to |
2647 | * modify 1 super block, 1 block bitmap and 1 group descriptor. | 2899 | * modify 1 super block, 1 block bitmap and 1 group descriptor. |
@@ -2657,7 +2909,6 @@ retry: | |||
2657 | ret = PTR_ERR(handle); | 2909 | ret = PTR_ERR(handle); |
2658 | break; | 2910 | break; |
2659 | } | 2911 | } |
2660 | |||
2661 | ret = ext4_get_blocks_wrap(handle, inode, block, | 2912 | ret = ext4_get_blocks_wrap(handle, inode, block, |
2662 | max_blocks, &map_bh, | 2913 | max_blocks, &map_bh, |
2663 | EXT4_CREATE_UNINITIALIZED_EXT, 0); | 2914 | EXT4_CREATE_UNINITIALIZED_EXT, 0); |
@@ -2673,61 +2924,24 @@ retry: | |||
2673 | ret2 = ext4_journal_stop(handle); | 2924 | ret2 = ext4_journal_stop(handle); |
2674 | break; | 2925 | break; |
2675 | } | 2926 | } |
2676 | if (ret > 0) { | 2927 | if ((block + ret) >= (EXT4_BLOCK_ALIGN(offset + len, |
2677 | /* check wrap through sign-bit/zero here */ | 2928 | blkbits) >> blkbits)) |
2678 | if ((block + ret) < 0 || (block + ret) < block) { | 2929 | new_size = offset + len; |
2679 | ret = -EIO; | 2930 | else |
2680 | ext4_mark_inode_dirty(handle, inode); | 2931 | new_size = (block + ret) << blkbits; |
2681 | ret2 = ext4_journal_stop(handle); | ||
2682 | break; | ||
2683 | } | ||
2684 | if (buffer_new(&map_bh) && ((block + ret) > | ||
2685 | (EXT4_BLOCK_ALIGN(i_size_read(inode), blkbits) | ||
2686 | >> blkbits))) | ||
2687 | nblocks = nblocks + ret; | ||
2688 | } | ||
2689 | |||
2690 | /* Update ctime if new blocks get allocated */ | ||
2691 | if (nblocks) { | ||
2692 | struct timespec now; | ||
2693 | |||
2694 | now = current_fs_time(inode->i_sb); | ||
2695 | if (!timespec_equal(&inode->i_ctime, &now)) | ||
2696 | inode->i_ctime = now; | ||
2697 | } | ||
2698 | 2932 | ||
2933 | ext4_falloc_update_inode(inode, mode, new_size, | ||
2934 | buffer_new(&map_bh)); | ||
2699 | ext4_mark_inode_dirty(handle, inode); | 2935 | ext4_mark_inode_dirty(handle, inode); |
2700 | ret2 = ext4_journal_stop(handle); | 2936 | ret2 = ext4_journal_stop(handle); |
2701 | if (ret2) | 2937 | if (ret2) |
2702 | break; | 2938 | break; |
2703 | } | 2939 | } |
2704 | 2940 | if (ret == -ENOSPC && | |
2705 | if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) | 2941 | ext4_should_retry_alloc(inode->i_sb, &retries)) { |
2942 | ret = 0; | ||
2706 | goto retry; | 2943 | goto retry; |
2707 | |||
2708 | /* | ||
2709 | * Time to update the file size. | ||
2710 | * Update only when preallocation was requested beyond the file size. | ||
2711 | */ | ||
2712 | if (!(mode & FALLOC_FL_KEEP_SIZE) && | ||
2713 | (offset + len) > i_size_read(inode)) { | ||
2714 | if (ret > 0) { | ||
2715 | /* | ||
2716 | * if no error, we assume preallocation succeeded | ||
2717 | * completely | ||
2718 | */ | ||
2719 | i_size_write(inode, offset + len); | ||
2720 | EXT4_I(inode)->i_disksize = i_size_read(inode); | ||
2721 | } else if (ret < 0 && nblocks) { | ||
2722 | /* Handle partial allocation scenario */ | ||
2723 | loff_t newsize; | ||
2724 | |||
2725 | newsize = (nblocks << blkbits) + i_size_read(inode); | ||
2726 | i_size_write(inode, EXT4_BLOCK_ALIGN(newsize, blkbits)); | ||
2727 | EXT4_I(inode)->i_disksize = i_size_read(inode); | ||
2728 | } | ||
2729 | } | 2944 | } |
2730 | |||
2731 | mutex_unlock(&inode->i_mutex); | 2945 | mutex_unlock(&inode->i_mutex); |
2732 | return ret > 0 ? ret2 : ret; | 2946 | return ret > 0 ? ret2 : ret; |
2733 | } | 2947 | } |
diff --git a/fs/ext4/file.c b/fs/ext4/file.c index ac35ec58db55..4159be6366ab 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c | |||
@@ -21,8 +21,8 @@ | |||
21 | #include <linux/time.h> | 21 | #include <linux/time.h> |
22 | #include <linux/fs.h> | 22 | #include <linux/fs.h> |
23 | #include <linux/jbd2.h> | 23 | #include <linux/jbd2.h> |
24 | #include <linux/ext4_fs.h> | 24 | #include "ext4.h" |
25 | #include <linux/ext4_jbd2.h> | 25 | #include "ext4_jbd2.h" |
26 | #include "xattr.h" | 26 | #include "xattr.h" |
27 | #include "acl.h" | 27 | #include "acl.h" |
28 | 28 | ||
@@ -129,7 +129,7 @@ const struct file_operations ext4_file_operations = { | |||
129 | .write = do_sync_write, | 129 | .write = do_sync_write, |
130 | .aio_read = generic_file_aio_read, | 130 | .aio_read = generic_file_aio_read, |
131 | .aio_write = ext4_file_write, | 131 | .aio_write = ext4_file_write, |
132 | .ioctl = ext4_ioctl, | 132 | .unlocked_ioctl = ext4_ioctl, |
133 | #ifdef CONFIG_COMPAT | 133 | #ifdef CONFIG_COMPAT |
134 | .compat_ioctl = ext4_compat_ioctl, | 134 | .compat_ioctl = ext4_compat_ioctl, |
135 | #endif | 135 | #endif |
diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c index 8d50879d1c2c..1c8ba48d4f8d 100644 --- a/fs/ext4/fsync.c +++ b/fs/ext4/fsync.c | |||
@@ -27,8 +27,8 @@ | |||
27 | #include <linux/sched.h> | 27 | #include <linux/sched.h> |
28 | #include <linux/writeback.h> | 28 | #include <linux/writeback.h> |
29 | #include <linux/jbd2.h> | 29 | #include <linux/jbd2.h> |
30 | #include <linux/ext4_fs.h> | 30 | #include "ext4.h" |
31 | #include <linux/ext4_jbd2.h> | 31 | #include "ext4_jbd2.h" |
32 | 32 | ||
33 | /* | 33 | /* |
34 | * akpm: A new design for ext4_sync_file(). | 34 | * akpm: A new design for ext4_sync_file(). |
@@ -72,6 +72,9 @@ int ext4_sync_file(struct file * file, struct dentry *dentry, int datasync) | |||
72 | goto out; | 72 | goto out; |
73 | } | 73 | } |
74 | 74 | ||
75 | if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) | ||
76 | goto out; | ||
77 | |||
75 | /* | 78 | /* |
76 | * The VFS has written the file data. If the inode is unaltered | 79 | * The VFS has written the file data. If the inode is unaltered |
77 | * then we need not start a commit. | 80 | * then we need not start a commit. |
diff --git a/fs/ext4/hash.c b/fs/ext4/hash.c index 1555024e3b36..1d6329dbe390 100644 --- a/fs/ext4/hash.c +++ b/fs/ext4/hash.c | |||
@@ -11,8 +11,8 @@ | |||
11 | 11 | ||
12 | #include <linux/fs.h> | 12 | #include <linux/fs.h> |
13 | #include <linux/jbd2.h> | 13 | #include <linux/jbd2.h> |
14 | #include <linux/ext4_fs.h> | ||
15 | #include <linux/cryptohash.h> | 14 | #include <linux/cryptohash.h> |
15 | #include "ext4.h" | ||
16 | 16 | ||
17 | #define DELTA 0x9E3779B9 | 17 | #define DELTA 0x9E3779B9 |
18 | 18 | ||
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 486e46a3918d..c6efbab0c801 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c | |||
@@ -15,8 +15,6 @@ | |||
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/ext4_fs.h> | ||
19 | #include <linux/ext4_jbd2.h> | ||
20 | #include <linux/stat.h> | 18 | #include <linux/stat.h> |
21 | #include <linux/string.h> | 19 | #include <linux/string.h> |
22 | #include <linux/quotaops.h> | 20 | #include <linux/quotaops.h> |
@@ -25,7 +23,8 @@ | |||
25 | #include <linux/bitops.h> | 23 | #include <linux/bitops.h> |
26 | #include <linux/blkdev.h> | 24 | #include <linux/blkdev.h> |
27 | #include <asm/byteorder.h> | 25 | #include <asm/byteorder.h> |
28 | 26 | #include "ext4.h" | |
27 | #include "ext4_jbd2.h" | ||
29 | #include "xattr.h" | 28 | #include "xattr.h" |
30 | #include "acl.h" | 29 | #include "acl.h" |
31 | #include "group.h" | 30 | #include "group.h" |
@@ -75,7 +74,7 @@ unsigned ext4_init_inode_bitmap(struct super_block *sb, struct buffer_head *bh, | |||
75 | /* 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 |
76 | * allocation, essentially implementing a per-group read-only flag. */ | 75 | * allocation, essentially implementing a per-group read-only flag. */ |
77 | if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { | 76 | if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { |
78 | ext4_error(sb, __FUNCTION__, "Checksum bad for group %lu\n", | 77 | ext4_error(sb, __func__, "Checksum bad for group %lu\n", |
79 | block_group); | 78 | block_group); |
80 | gdp->bg_free_blocks_count = 0; | 79 | gdp->bg_free_blocks_count = 0; |
81 | gdp->bg_free_inodes_count = 0; | 80 | gdp->bg_free_inodes_count = 0; |
@@ -223,11 +222,9 @@ void ext4_free_inode (handle_t *handle, struct inode * inode) | |||
223 | 222 | ||
224 | if (gdp) { | 223 | if (gdp) { |
225 | spin_lock(sb_bgl_lock(sbi, block_group)); | 224 | spin_lock(sb_bgl_lock(sbi, block_group)); |
226 | gdp->bg_free_inodes_count = cpu_to_le16( | 225 | le16_add_cpu(&gdp->bg_free_inodes_count, 1); |
227 | le16_to_cpu(gdp->bg_free_inodes_count) + 1); | ||
228 | if (is_directory) | 226 | if (is_directory) |
229 | gdp->bg_used_dirs_count = cpu_to_le16( | 227 | le16_add_cpu(&gdp->bg_used_dirs_count, -1); |
230 | le16_to_cpu(gdp->bg_used_dirs_count) - 1); | ||
231 | gdp->bg_checksum = ext4_group_desc_csum(sbi, | 228 | gdp->bg_checksum = ext4_group_desc_csum(sbi, |
232 | block_group, gdp); | 229 | block_group, gdp); |
233 | spin_unlock(sb_bgl_lock(sbi, block_group)); | 230 | spin_unlock(sb_bgl_lock(sbi, block_group)); |
@@ -588,7 +585,7 @@ got: | |||
588 | ino++; | 585 | ino++; |
589 | if ((group == 0 && ino < EXT4_FIRST_INO(sb)) || | 586 | if ((group == 0 && ino < EXT4_FIRST_INO(sb)) || |
590 | ino > EXT4_INODES_PER_GROUP(sb)) { | 587 | ino > EXT4_INODES_PER_GROUP(sb)) { |
591 | ext4_error(sb, __FUNCTION__, | 588 | ext4_error(sb, __func__, |
592 | "reserved inode or inode > inodes count - " | 589 | "reserved inode or inode > inodes count - " |
593 | "block_group = %lu, inode=%lu", group, | 590 | "block_group = %lu, inode=%lu", group, |
594 | ino + group * EXT4_INODES_PER_GROUP(sb)); | 591 | ino + group * EXT4_INODES_PER_GROUP(sb)); |
@@ -664,11 +661,9 @@ got: | |||
664 | cpu_to_le16(EXT4_INODES_PER_GROUP(sb) - ino); | 661 | cpu_to_le16(EXT4_INODES_PER_GROUP(sb) - ino); |
665 | } | 662 | } |
666 | 663 | ||
667 | gdp->bg_free_inodes_count = | 664 | le16_add_cpu(&gdp->bg_free_inodes_count, -1); |
668 | cpu_to_le16(le16_to_cpu(gdp->bg_free_inodes_count) - 1); | ||
669 | if (S_ISDIR(mode)) { | 665 | if (S_ISDIR(mode)) { |
670 | gdp->bg_used_dirs_count = | 666 | le16_add_cpu(&gdp->bg_used_dirs_count, 1); |
671 | cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1); | ||
672 | } | 667 | } |
673 | gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp); | 668 | gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp); |
674 | spin_unlock(sb_bgl_lock(sbi, group)); | 669 | spin_unlock(sb_bgl_lock(sbi, group)); |
@@ -744,23 +739,24 @@ got: | |||
744 | if (err) | 739 | if (err) |
745 | goto fail_free_drop; | 740 | goto fail_free_drop; |
746 | 741 | ||
747 | err = ext4_mark_inode_dirty(handle, inode); | ||
748 | if (err) { | ||
749 | ext4_std_error(sb, err); | ||
750 | goto fail_free_drop; | ||
751 | } | ||
752 | if (test_opt(sb, EXTENTS)) { | 742 | if (test_opt(sb, EXTENTS)) { |
753 | /* set extent flag only for directory and file */ | 743 | /* set extent flag only for diretory, file and normal symlink*/ |
754 | if (S_ISDIR(mode) || S_ISREG(mode)) { | 744 | if (S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode)) { |
755 | EXT4_I(inode)->i_flags |= EXT4_EXTENTS_FL; | 745 | EXT4_I(inode)->i_flags |= EXT4_EXTENTS_FL; |
756 | ext4_ext_tree_init(handle, inode); | 746 | ext4_ext_tree_init(handle, inode); |
757 | err = ext4_update_incompat_feature(handle, sb, | 747 | err = ext4_update_incompat_feature(handle, sb, |
758 | EXT4_FEATURE_INCOMPAT_EXTENTS); | 748 | EXT4_FEATURE_INCOMPAT_EXTENTS); |
759 | if (err) | 749 | if (err) |
760 | goto fail; | 750 | goto fail_free_drop; |
761 | } | 751 | } |
762 | } | 752 | } |
763 | 753 | ||
754 | err = ext4_mark_inode_dirty(handle, inode); | ||
755 | if (err) { | ||
756 | ext4_std_error(sb, err); | ||
757 | goto fail_free_drop; | ||
758 | } | ||
759 | |||
764 | ext4_debug("allocating inode %lu\n", inode->i_ino); | 760 | ext4_debug("allocating inode %lu\n", inode->i_ino); |
765 | goto really_out; | 761 | goto really_out; |
766 | fail: | 762 | fail: |
@@ -796,7 +792,7 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino) | |||
796 | 792 | ||
797 | /* Error cases - e2fsck has already cleaned up for us */ | 793 | /* Error cases - e2fsck has already cleaned up for us */ |
798 | if (ino > max_ino) { | 794 | if (ino > max_ino) { |
799 | ext4_warning(sb, __FUNCTION__, | 795 | ext4_warning(sb, __func__, |
800 | "bad orphan ino %lu! e2fsck was run?", ino); | 796 | "bad orphan ino %lu! e2fsck was run?", ino); |
801 | goto error; | 797 | goto error; |
802 | } | 798 | } |
@@ -805,7 +801,7 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino) | |||
805 | bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); | 801 | bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); |
806 | bitmap_bh = read_inode_bitmap(sb, block_group); | 802 | bitmap_bh = read_inode_bitmap(sb, block_group); |
807 | if (!bitmap_bh) { | 803 | if (!bitmap_bh) { |
808 | ext4_warning(sb, __FUNCTION__, | 804 | ext4_warning(sb, __func__, |
809 | "inode bitmap error for orphan %lu", ino); | 805 | "inode bitmap error for orphan %lu", ino); |
810 | goto error; | 806 | goto error; |
811 | } | 807 | } |
@@ -830,7 +826,7 @@ iget_failed: | |||
830 | err = PTR_ERR(inode); | 826 | err = PTR_ERR(inode); |
831 | inode = NULL; | 827 | inode = NULL; |
832 | bad_orphan: | 828 | bad_orphan: |
833 | ext4_warning(sb, __FUNCTION__, | 829 | ext4_warning(sb, __func__, |
834 | "bad orphan inode %lu! e2fsck was run?", ino); | 830 | "bad orphan inode %lu! e2fsck was run?", ino); |
835 | printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n", | 831 | printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n", |
836 | bit, (unsigned long long)bitmap_bh->b_blocknr, | 832 | bit, (unsigned long long)bitmap_bh->b_blocknr, |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 8fab233cb05f..8d9707746413 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -25,7 +25,6 @@ | |||
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/fs.h> | 26 | #include <linux/fs.h> |
27 | #include <linux/time.h> | 27 | #include <linux/time.h> |
28 | #include <linux/ext4_jbd2.h> | ||
29 | #include <linux/jbd2.h> | 28 | #include <linux/jbd2.h> |
30 | #include <linux/highuid.h> | 29 | #include <linux/highuid.h> |
31 | #include <linux/pagemap.h> | 30 | #include <linux/pagemap.h> |
@@ -36,6 +35,7 @@ | |||
36 | #include <linux/mpage.h> | 35 | #include <linux/mpage.h> |
37 | #include <linux/uio.h> | 36 | #include <linux/uio.h> |
38 | #include <linux/bio.h> | 37 | #include <linux/bio.h> |
38 | #include "ext4_jbd2.h" | ||
39 | #include "xattr.h" | 39 | #include "xattr.h" |
40 | #include "acl.h" | 40 | #include "acl.h" |
41 | 41 | ||
@@ -93,7 +93,7 @@ int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode, | |||
93 | BUFFER_TRACE(bh, "call ext4_journal_revoke"); | 93 | BUFFER_TRACE(bh, "call ext4_journal_revoke"); |
94 | err = ext4_journal_revoke(handle, blocknr, bh); | 94 | err = ext4_journal_revoke(handle, blocknr, bh); |
95 | if (err) | 95 | if (err) |
96 | ext4_abort(inode->i_sb, __FUNCTION__, | 96 | ext4_abort(inode->i_sb, __func__, |
97 | "error %d when attempting revoke", err); | 97 | "error %d when attempting revoke", err); |
98 | BUFFER_TRACE(bh, "exit"); | 98 | BUFFER_TRACE(bh, "exit"); |
99 | return err; | 99 | return err; |
@@ -985,6 +985,16 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, | |||
985 | } else { | 985 | } else { |
986 | retval = ext4_get_blocks_handle(handle, inode, block, | 986 | retval = ext4_get_blocks_handle(handle, inode, block, |
987 | max_blocks, bh, create, extend_disksize); | 987 | max_blocks, bh, create, extend_disksize); |
988 | |||
989 | if (retval > 0 && buffer_new(bh)) { | ||
990 | /* | ||
991 | * We allocated new blocks which will result in | ||
992 | * i_data's format changing. Force the migrate | ||
993 | * to fail by clearing migrate flags | ||
994 | */ | ||
995 | EXT4_I(inode)->i_flags = EXT4_I(inode)->i_flags & | ||
996 | ~EXT4_EXT_MIGRATE; | ||
997 | } | ||
988 | } | 998 | } |
989 | up_write((&EXT4_I(inode)->i_data_sem)); | 999 | up_write((&EXT4_I(inode)->i_data_sem)); |
990 | return retval; | 1000 | return retval; |
@@ -1230,7 +1240,7 @@ int ext4_journal_dirty_data(handle_t *handle, struct buffer_head *bh) | |||
1230 | { | 1240 | { |
1231 | int err = jbd2_journal_dirty_data(handle, bh); | 1241 | int err = jbd2_journal_dirty_data(handle, bh); |
1232 | if (err) | 1242 | if (err) |
1233 | ext4_journal_abort_handle(__FUNCTION__, __FUNCTION__, | 1243 | ext4_journal_abort_handle(__func__, __func__, |
1234 | bh, handle, err); | 1244 | bh, handle, err); |
1235 | return err; | 1245 | return err; |
1236 | } | 1246 | } |
@@ -1301,10 +1311,11 @@ static int ext4_ordered_write_end(struct file *file, | |||
1301 | new_i_size = pos + copied; | 1311 | new_i_size = pos + copied; |
1302 | if (new_i_size > EXT4_I(inode)->i_disksize) | 1312 | if (new_i_size > EXT4_I(inode)->i_disksize) |
1303 | EXT4_I(inode)->i_disksize = new_i_size; | 1313 | EXT4_I(inode)->i_disksize = new_i_size; |
1304 | copied = ext4_generic_write_end(file, mapping, pos, len, copied, | 1314 | ret2 = ext4_generic_write_end(file, mapping, pos, len, copied, |
1305 | page, fsdata); | 1315 | page, fsdata); |
1306 | if (copied < 0) | 1316 | copied = ret2; |
1307 | ret = copied; | 1317 | if (ret2 < 0) |
1318 | ret = ret2; | ||
1308 | } | 1319 | } |
1309 | ret2 = ext4_journal_stop(handle); | 1320 | ret2 = ext4_journal_stop(handle); |
1310 | if (!ret) | 1321 | if (!ret) |
@@ -1329,10 +1340,11 @@ static int ext4_writeback_write_end(struct file *file, | |||
1329 | if (new_i_size > EXT4_I(inode)->i_disksize) | 1340 | if (new_i_size > EXT4_I(inode)->i_disksize) |
1330 | EXT4_I(inode)->i_disksize = new_i_size; | 1341 | EXT4_I(inode)->i_disksize = new_i_size; |
1331 | 1342 | ||
1332 | copied = ext4_generic_write_end(file, mapping, pos, len, copied, | 1343 | ret2 = ext4_generic_write_end(file, mapping, pos, len, copied, |
1333 | page, fsdata); | 1344 | page, fsdata); |
1334 | if (copied < 0) | 1345 | copied = ret2; |
1335 | ret = copied; | 1346 | if (ret2 < 0) |
1347 | ret = ret2; | ||
1336 | 1348 | ||
1337 | ret2 = ext4_journal_stop(handle); | 1349 | ret2 = ext4_journal_stop(handle); |
1338 | if (!ret) | 1350 | if (!ret) |
@@ -2501,12 +2513,10 @@ out_stop: | |||
2501 | static ext4_fsblk_t ext4_get_inode_block(struct super_block *sb, | 2513 | static ext4_fsblk_t ext4_get_inode_block(struct super_block *sb, |
2502 | unsigned long ino, struct ext4_iloc *iloc) | 2514 | unsigned long ino, struct ext4_iloc *iloc) |
2503 | { | 2515 | { |
2504 | unsigned long desc, group_desc; | ||
2505 | ext4_group_t block_group; | 2516 | ext4_group_t block_group; |
2506 | unsigned long offset; | 2517 | unsigned long offset; |
2507 | ext4_fsblk_t block; | 2518 | ext4_fsblk_t block; |
2508 | struct buffer_head *bh; | 2519 | struct ext4_group_desc *gdp; |
2509 | struct ext4_group_desc * gdp; | ||
2510 | 2520 | ||
2511 | if (!ext4_valid_inum(sb, ino)) { | 2521 | if (!ext4_valid_inum(sb, ino)) { |
2512 | /* | 2522 | /* |
@@ -2518,22 +2528,10 @@ static ext4_fsblk_t ext4_get_inode_block(struct super_block *sb, | |||
2518 | } | 2528 | } |
2519 | 2529 | ||
2520 | block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); | 2530 | block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); |
2521 | if (block_group >= EXT4_SB(sb)->s_groups_count) { | 2531 | gdp = ext4_get_group_desc(sb, block_group, NULL); |
2522 | ext4_error(sb,"ext4_get_inode_block","group >= groups count"); | 2532 | if (!gdp) |
2523 | return 0; | 2533 | return 0; |
2524 | } | ||
2525 | smp_rmb(); | ||
2526 | group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb); | ||
2527 | desc = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1); | ||
2528 | bh = EXT4_SB(sb)->s_group_desc[group_desc]; | ||
2529 | if (!bh) { | ||
2530 | ext4_error (sb, "ext4_get_inode_block", | ||
2531 | "Descriptor not loaded"); | ||
2532 | return 0; | ||
2533 | } | ||
2534 | 2534 | ||
2535 | gdp = (struct ext4_group_desc *)((__u8 *)bh->b_data + | ||
2536 | desc * EXT4_DESC_SIZE(sb)); | ||
2537 | /* | 2535 | /* |
2538 | * Figure out the offset within the block group inode table | 2536 | * Figure out the offset within the block group inode table |
2539 | */ | 2537 | */ |
@@ -2976,7 +2974,8 @@ static int ext4_do_update_inode(handle_t *handle, | |||
2976 | if (ext4_inode_blocks_set(handle, raw_inode, ei)) | 2974 | if (ext4_inode_blocks_set(handle, raw_inode, ei)) |
2977 | goto out_brelse; | 2975 | goto out_brelse; |
2978 | raw_inode->i_dtime = cpu_to_le32(ei->i_dtime); | 2976 | raw_inode->i_dtime = cpu_to_le32(ei->i_dtime); |
2979 | raw_inode->i_flags = cpu_to_le32(ei->i_flags); | 2977 | /* clear the migrate flag in the raw_inode */ |
2978 | raw_inode->i_flags = cpu_to_le32(ei->i_flags & ~EXT4_EXT_MIGRATE); | ||
2980 | if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != | 2979 | if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != |
2981 | cpu_to_le32(EXT4_OS_HURD)) | 2980 | cpu_to_le32(EXT4_OS_HURD)) |
2982 | raw_inode->i_file_acl_high = | 2981 | raw_inode->i_file_acl_high = |
@@ -3374,7 +3373,7 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode) | |||
3374 | EXT4_I(inode)->i_state |= EXT4_STATE_NO_EXPAND; | 3373 | EXT4_I(inode)->i_state |= EXT4_STATE_NO_EXPAND; |
3375 | if (mnt_count != | 3374 | if (mnt_count != |
3376 | le16_to_cpu(sbi->s_es->s_mnt_count)) { | 3375 | le16_to_cpu(sbi->s_es->s_mnt_count)) { |
3377 | ext4_warning(inode->i_sb, __FUNCTION__, | 3376 | ext4_warning(inode->i_sb, __func__, |
3378 | "Unable to expand inode %lu. Delete" | 3377 | "Unable to expand inode %lu. Delete" |
3379 | " some EAs or run e2fsck.", | 3378 | " some EAs or run e2fsck.", |
3380 | inode->i_ino); | 3379 | inode->i_ino); |
@@ -3415,7 +3414,7 @@ void ext4_dirty_inode(struct inode *inode) | |||
3415 | current_handle->h_transaction != handle->h_transaction) { | 3414 | current_handle->h_transaction != handle->h_transaction) { |
3416 | /* This task has a transaction open against a different fs */ | 3415 | /* This task has a transaction open against a different fs */ |
3417 | printk(KERN_EMERG "%s: transactions do not match!\n", | 3416 | printk(KERN_EMERG "%s: transactions do not match!\n", |
3418 | __FUNCTION__); | 3417 | __func__); |
3419 | } else { | 3418 | } else { |
3420 | jbd_debug(5, "marking dirty. outer handle=%p\n", | 3419 | jbd_debug(5, "marking dirty. outer handle=%p\n", |
3421 | current_handle); | 3420 | current_handle); |
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index 25b13ede8086..7a6c2f1faba6 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c | |||
@@ -10,17 +10,17 @@ | |||
10 | #include <linux/fs.h> | 10 | #include <linux/fs.h> |
11 | #include <linux/jbd2.h> | 11 | #include <linux/jbd2.h> |
12 | #include <linux/capability.h> | 12 | #include <linux/capability.h> |
13 | #include <linux/ext4_fs.h> | ||
14 | #include <linux/ext4_jbd2.h> | ||
15 | #include <linux/time.h> | 13 | #include <linux/time.h> |
16 | #include <linux/compat.h> | 14 | #include <linux/compat.h> |
17 | #include <linux/smp_lock.h> | 15 | #include <linux/smp_lock.h> |
18 | #include <linux/mount.h> | 16 | #include <linux/mount.h> |
19 | #include <asm/uaccess.h> | 17 | #include <asm/uaccess.h> |
18 | #include "ext4_jbd2.h" | ||
19 | #include "ext4.h" | ||
20 | 20 | ||
21 | int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, | 21 | long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
22 | unsigned long arg) | ||
23 | { | 22 | { |
23 | struct inode *inode = filp->f_dentry->d_inode; | ||
24 | struct ext4_inode_info *ei = EXT4_I(inode); | 24 | struct ext4_inode_info *ei = EXT4_I(inode); |
25 | unsigned int flags; | 25 | unsigned int flags; |
26 | unsigned short rsv_window_size; | 26 | unsigned short rsv_window_size; |
@@ -277,9 +277,6 @@ setversion_out: | |||
277 | #ifdef CONFIG_COMPAT | 277 | #ifdef CONFIG_COMPAT |
278 | long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | 278 | long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
279 | { | 279 | { |
280 | struct inode *inode = file->f_path.dentry->d_inode; | ||
281 | int ret; | ||
282 | |||
283 | /* These are just misnamed, they actually get/put from/to user an int */ | 280 | /* These are just misnamed, they actually get/put from/to user an int */ |
284 | switch (cmd) { | 281 | switch (cmd) { |
285 | case EXT4_IOC32_GETFLAGS: | 282 | case EXT4_IOC32_GETFLAGS: |
@@ -319,9 +316,6 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
319 | default: | 316 | default: |
320 | return -ENOIOCTLCMD; | 317 | return -ENOIOCTLCMD; |
321 | } | 318 | } |
322 | lock_kernel(); | 319 | return ext4_ioctl(file, cmd, (unsigned long) compat_ptr(arg)); |
323 | ret = ext4_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg)); | ||
324 | unlock_kernel(); | ||
325 | return ret; | ||
326 | } | 320 | } |
327 | #endif | 321 | #endif |
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 9d57695de746..fbec2ef93797 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
@@ -21,21 +21,7 @@ | |||
21 | * mballoc.c contains the multiblocks allocation routines | 21 | * mballoc.c contains the multiblocks allocation routines |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/time.h> | 24 | #include "mballoc.h" |
25 | #include <linux/fs.h> | ||
26 | #include <linux/namei.h> | ||
27 | #include <linux/ext4_jbd2.h> | ||
28 | #include <linux/ext4_fs.h> | ||
29 | #include <linux/quotaops.h> | ||
30 | #include <linux/buffer_head.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/swap.h> | ||
33 | #include <linux/proc_fs.h> | ||
34 | #include <linux/pagemap.h> | ||
35 | #include <linux/seq_file.h> | ||
36 | #include <linux/version.h> | ||
37 | #include "group.h" | ||
38 | |||
39 | /* | 25 | /* |
40 | * MUSTDO: | 26 | * MUSTDO: |
41 | * - test ext4_ext_search_left() and ext4_ext_search_right() | 27 | * - test ext4_ext_search_left() and ext4_ext_search_right() |
@@ -345,288 +331,6 @@ | |||
345 | * | 331 | * |
346 | */ | 332 | */ |
347 | 333 | ||
348 | /* | ||
349 | * with AGGRESSIVE_CHECK allocator runs consistency checks over | ||
350 | * structures. these checks slow things down a lot | ||
351 | */ | ||
352 | #define AGGRESSIVE_CHECK__ | ||
353 | |||
354 | /* | ||
355 | * with DOUBLE_CHECK defined mballoc creates persistent in-core | ||
356 | * bitmaps, maintains and uses them to check for double allocations | ||
357 | */ | ||
358 | #define DOUBLE_CHECK__ | ||
359 | |||
360 | /* | ||
361 | */ | ||
362 | #define MB_DEBUG__ | ||
363 | #ifdef MB_DEBUG | ||
364 | #define mb_debug(fmt, a...) printk(fmt, ##a) | ||
365 | #else | ||
366 | #define mb_debug(fmt, a...) | ||
367 | #endif | ||
368 | |||
369 | /* | ||
370 | * with EXT4_MB_HISTORY mballoc stores last N allocations in memory | ||
371 | * and you can monitor it in /proc/fs/ext4/<dev>/mb_history | ||
372 | */ | ||
373 | #define EXT4_MB_HISTORY | ||
374 | #define EXT4_MB_HISTORY_ALLOC 1 /* allocation */ | ||
375 | #define EXT4_MB_HISTORY_PREALLOC 2 /* preallocated blocks used */ | ||
376 | #define EXT4_MB_HISTORY_DISCARD 4 /* preallocation discarded */ | ||
377 | #define EXT4_MB_HISTORY_FREE 8 /* free */ | ||
378 | |||
379 | #define EXT4_MB_HISTORY_DEFAULT (EXT4_MB_HISTORY_ALLOC | \ | ||
380 | EXT4_MB_HISTORY_PREALLOC) | ||
381 | |||
382 | /* | ||
383 | * How long mballoc can look for a best extent (in found extents) | ||
384 | */ | ||
385 | #define MB_DEFAULT_MAX_TO_SCAN 200 | ||
386 | |||
387 | /* | ||
388 | * How long mballoc must look for a best extent | ||
389 | */ | ||
390 | #define MB_DEFAULT_MIN_TO_SCAN 10 | ||
391 | |||
392 | /* | ||
393 | * How many groups mballoc will scan looking for the best chunk | ||
394 | */ | ||
395 | #define MB_DEFAULT_MAX_GROUPS_TO_SCAN 5 | ||
396 | |||
397 | /* | ||
398 | * with 'ext4_mb_stats' allocator will collect stats that will be | ||
399 | * shown at umount. The collecting costs though! | ||
400 | */ | ||
401 | #define MB_DEFAULT_STATS 1 | ||
402 | |||
403 | /* | ||
404 | * files smaller than MB_DEFAULT_STREAM_THRESHOLD are served | ||
405 | * by the stream allocator, which purpose is to pack requests | ||
406 | * as close each to other as possible to produce smooth I/O traffic | ||
407 | * We use locality group prealloc space for stream request. | ||
408 | * We can tune the same via /proc/fs/ext4/<parition>/stream_req | ||
409 | */ | ||
410 | #define MB_DEFAULT_STREAM_THRESHOLD 16 /* 64K */ | ||
411 | |||
412 | /* | ||
413 | * for which requests use 2^N search using buddies | ||
414 | */ | ||
415 | #define MB_DEFAULT_ORDER2_REQS 2 | ||
416 | |||
417 | /* | ||
418 | * default group prealloc size 512 blocks | ||
419 | */ | ||
420 | #define MB_DEFAULT_GROUP_PREALLOC 512 | ||
421 | |||
422 | static struct kmem_cache *ext4_pspace_cachep; | ||
423 | static struct kmem_cache *ext4_ac_cachep; | ||
424 | |||
425 | #ifdef EXT4_BB_MAX_BLOCKS | ||
426 | #undef EXT4_BB_MAX_BLOCKS | ||
427 | #endif | ||
428 | #define EXT4_BB_MAX_BLOCKS 30 | ||
429 | |||
430 | struct ext4_free_metadata { | ||
431 | ext4_group_t group; | ||
432 | unsigned short num; | ||
433 | ext4_grpblk_t blocks[EXT4_BB_MAX_BLOCKS]; | ||
434 | struct list_head list; | ||
435 | }; | ||
436 | |||
437 | struct ext4_group_info { | ||
438 | unsigned long bb_state; | ||
439 | unsigned long bb_tid; | ||
440 | struct ext4_free_metadata *bb_md_cur; | ||
441 | unsigned short bb_first_free; | ||
442 | unsigned short bb_free; | ||
443 | unsigned short bb_fragments; | ||
444 | struct list_head bb_prealloc_list; | ||
445 | #ifdef DOUBLE_CHECK | ||
446 | void *bb_bitmap; | ||
447 | #endif | ||
448 | unsigned short bb_counters[]; | ||
449 | }; | ||
450 | |||
451 | #define EXT4_GROUP_INFO_NEED_INIT_BIT 0 | ||
452 | #define EXT4_GROUP_INFO_LOCKED_BIT 1 | ||
453 | |||
454 | #define EXT4_MB_GRP_NEED_INIT(grp) \ | ||
455 | (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) | ||
456 | |||
457 | |||
458 | struct ext4_prealloc_space { | ||
459 | struct list_head pa_inode_list; | ||
460 | struct list_head pa_group_list; | ||
461 | union { | ||
462 | struct list_head pa_tmp_list; | ||
463 | struct rcu_head pa_rcu; | ||
464 | } u; | ||
465 | spinlock_t pa_lock; | ||
466 | atomic_t pa_count; | ||
467 | unsigned pa_deleted; | ||
468 | ext4_fsblk_t pa_pstart; /* phys. block */ | ||
469 | ext4_lblk_t pa_lstart; /* log. block */ | ||
470 | unsigned short pa_len; /* len of preallocated chunk */ | ||
471 | unsigned short pa_free; /* how many blocks are free */ | ||
472 | unsigned short pa_linear; /* consumed in one direction | ||
473 | * strictly, for grp prealloc */ | ||
474 | spinlock_t *pa_obj_lock; | ||
475 | struct inode *pa_inode; /* hack, for history only */ | ||
476 | }; | ||
477 | |||
478 | |||
479 | struct ext4_free_extent { | ||
480 | ext4_lblk_t fe_logical; | ||
481 | ext4_grpblk_t fe_start; | ||
482 | ext4_group_t fe_group; | ||
483 | int fe_len; | ||
484 | }; | ||
485 | |||
486 | /* | ||
487 | * Locality group: | ||
488 | * we try to group all related changes together | ||
489 | * so that writeback can flush/allocate them together as well | ||
490 | */ | ||
491 | struct ext4_locality_group { | ||
492 | /* for allocator */ | ||
493 | struct mutex lg_mutex; /* to serialize allocates */ | ||
494 | struct list_head lg_prealloc_list;/* list of preallocations */ | ||
495 | spinlock_t lg_prealloc_lock; | ||
496 | }; | ||
497 | |||
498 | struct ext4_allocation_context { | ||
499 | struct inode *ac_inode; | ||
500 | struct super_block *ac_sb; | ||
501 | |||
502 | /* original request */ | ||
503 | struct ext4_free_extent ac_o_ex; | ||
504 | |||
505 | /* goal request (after normalization) */ | ||
506 | struct ext4_free_extent ac_g_ex; | ||
507 | |||
508 | /* the best found extent */ | ||
509 | struct ext4_free_extent ac_b_ex; | ||
510 | |||
511 | /* copy of the bext found extent taken before preallocation efforts */ | ||
512 | struct ext4_free_extent ac_f_ex; | ||
513 | |||
514 | /* number of iterations done. we have to track to limit searching */ | ||
515 | unsigned long ac_ex_scanned; | ||
516 | __u16 ac_groups_scanned; | ||
517 | __u16 ac_found; | ||
518 | __u16 ac_tail; | ||
519 | __u16 ac_buddy; | ||
520 | __u16 ac_flags; /* allocation hints */ | ||
521 | __u8 ac_status; | ||
522 | __u8 ac_criteria; | ||
523 | __u8 ac_repeats; | ||
524 | __u8 ac_2order; /* if request is to allocate 2^N blocks and | ||
525 | * N > 0, the field stores N, otherwise 0 */ | ||
526 | __u8 ac_op; /* operation, for history only */ | ||
527 | struct page *ac_bitmap_page; | ||
528 | struct page *ac_buddy_page; | ||
529 | struct ext4_prealloc_space *ac_pa; | ||
530 | struct ext4_locality_group *ac_lg; | ||
531 | }; | ||
532 | |||
533 | #define AC_STATUS_CONTINUE 1 | ||
534 | #define AC_STATUS_FOUND 2 | ||
535 | #define AC_STATUS_BREAK 3 | ||
536 | |||
537 | struct ext4_mb_history { | ||
538 | struct ext4_free_extent orig; /* orig allocation */ | ||
539 | struct ext4_free_extent goal; /* goal allocation */ | ||
540 | struct ext4_free_extent result; /* result allocation */ | ||
541 | unsigned pid; | ||
542 | unsigned ino; | ||
543 | __u16 found; /* how many extents have been found */ | ||
544 | __u16 groups; /* how many groups have been scanned */ | ||
545 | __u16 tail; /* what tail broke some buddy */ | ||
546 | __u16 buddy; /* buddy the tail ^^^ broke */ | ||
547 | __u16 flags; | ||
548 | __u8 cr:3; /* which phase the result extent was found at */ | ||
549 | __u8 op:4; | ||
550 | __u8 merged:1; | ||
551 | }; | ||
552 | |||
553 | struct ext4_buddy { | ||
554 | struct page *bd_buddy_page; | ||
555 | void *bd_buddy; | ||
556 | struct page *bd_bitmap_page; | ||
557 | void *bd_bitmap; | ||
558 | struct ext4_group_info *bd_info; | ||
559 | struct super_block *bd_sb; | ||
560 | __u16 bd_blkbits; | ||
561 | ext4_group_t bd_group; | ||
562 | }; | ||
563 | #define EXT4_MB_BITMAP(e4b) ((e4b)->bd_bitmap) | ||
564 | #define EXT4_MB_BUDDY(e4b) ((e4b)->bd_buddy) | ||
565 | |||
566 | #ifndef EXT4_MB_HISTORY | ||
567 | static inline void ext4_mb_store_history(struct ext4_allocation_context *ac) | ||
568 | { | ||
569 | return; | ||
570 | } | ||
571 | #else | ||
572 | static void ext4_mb_store_history(struct ext4_allocation_context *ac); | ||
573 | #endif | ||
574 | |||
575 | #define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1) | ||
576 | |||
577 | static struct proc_dir_entry *proc_root_ext4; | ||
578 | struct buffer_head *read_block_bitmap(struct super_block *, ext4_group_t); | ||
579 | ext4_fsblk_t ext4_new_blocks_old(handle_t *handle, struct inode *inode, | ||
580 | ext4_fsblk_t goal, unsigned long *count, int *errp); | ||
581 | |||
582 | static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap, | ||
583 | ext4_group_t group); | ||
584 | static void ext4_mb_poll_new_transaction(struct super_block *, handle_t *); | ||
585 | static void ext4_mb_free_committed_blocks(struct super_block *); | ||
586 | static void ext4_mb_return_to_preallocation(struct inode *inode, | ||
587 | struct ext4_buddy *e4b, sector_t block, | ||
588 | int count); | ||
589 | static void ext4_mb_put_pa(struct ext4_allocation_context *, | ||
590 | struct super_block *, struct ext4_prealloc_space *pa); | ||
591 | static int ext4_mb_init_per_dev_proc(struct super_block *sb); | ||
592 | static int ext4_mb_destroy_per_dev_proc(struct super_block *sb); | ||
593 | |||
594 | |||
595 | static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group) | ||
596 | { | ||
597 | struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); | ||
598 | |||
599 | bit_spin_lock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state)); | ||
600 | } | ||
601 | |||
602 | static inline void ext4_unlock_group(struct super_block *sb, | ||
603 | ext4_group_t group) | ||
604 | { | ||
605 | struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); | ||
606 | |||
607 | bit_spin_unlock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state)); | ||
608 | } | ||
609 | |||
610 | static inline int ext4_is_group_locked(struct super_block *sb, | ||
611 | ext4_group_t group) | ||
612 | { | ||
613 | struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); | ||
614 | |||
615 | return bit_spin_is_locked(EXT4_GROUP_INFO_LOCKED_BIT, | ||
616 | &(grinfo->bb_state)); | ||
617 | } | ||
618 | |||
619 | static ext4_fsblk_t ext4_grp_offs_to_block(struct super_block *sb, | ||
620 | struct ext4_free_extent *fex) | ||
621 | { | ||
622 | ext4_fsblk_t block; | ||
623 | |||
624 | block = (ext4_fsblk_t) fex->fe_group * EXT4_BLOCKS_PER_GROUP(sb) | ||
625 | + fex->fe_start | ||
626 | + le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); | ||
627 | return block; | ||
628 | } | ||
629 | |||
630 | static inline void *mb_correct_addr_and_bit(int *bit, void *addr) | 334 | static inline void *mb_correct_addr_and_bit(int *bit, void *addr) |
631 | { | 335 | { |
632 | #if BITS_PER_LONG == 64 | 336 | #if BITS_PER_LONG == 64 |
@@ -736,7 +440,7 @@ static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b, | |||
736 | blocknr += | 440 | blocknr += |
737 | le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); | 441 | le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); |
738 | 442 | ||
739 | ext4_error(sb, __FUNCTION__, "double-free of inode" | 443 | ext4_error(sb, __func__, "double-free of inode" |
740 | " %lu's block %llu(bit %u in group %lu)\n", | 444 | " %lu's block %llu(bit %u in group %lu)\n", |
741 | inode ? inode->i_ino : 0, blocknr, | 445 | inode ? inode->i_ino : 0, blocknr, |
742 | first + i, e4b->bd_group); | 446 | first + i, e4b->bd_group); |
@@ -898,17 +602,17 @@ static int __mb_check_buddy(struct ext4_buddy *e4b, char *file, | |||
898 | list_for_each(cur, &grp->bb_prealloc_list) { | 602 | list_for_each(cur, &grp->bb_prealloc_list) { |
899 | ext4_group_t groupnr; | 603 | ext4_group_t groupnr; |
900 | struct ext4_prealloc_space *pa; | 604 | struct ext4_prealloc_space *pa; |
901 | pa = list_entry(cur, struct ext4_prealloc_space, group_list); | 605 | pa = list_entry(cur, struct ext4_prealloc_space, pa_group_list); |
902 | ext4_get_group_no_and_offset(sb, pa->pstart, &groupnr, &k); | 606 | ext4_get_group_no_and_offset(sb, pa->pa_pstart, &groupnr, &k); |
903 | MB_CHECK_ASSERT(groupnr == e4b->bd_group); | 607 | MB_CHECK_ASSERT(groupnr == e4b->bd_group); |
904 | for (i = 0; i < pa->len; i++) | 608 | for (i = 0; i < pa->pa_len; i++) |
905 | MB_CHECK_ASSERT(mb_test_bit(k + i, buddy)); | 609 | MB_CHECK_ASSERT(mb_test_bit(k + i, buddy)); |
906 | } | 610 | } |
907 | return 0; | 611 | return 0; |
908 | } | 612 | } |
909 | #undef MB_CHECK_ASSERT | 613 | #undef MB_CHECK_ASSERT |
910 | #define mb_check_buddy(e4b) __mb_check_buddy(e4b, \ | 614 | #define mb_check_buddy(e4b) __mb_check_buddy(e4b, \ |
911 | __FILE__, __FUNCTION__, __LINE__) | 615 | __FILE__, __func__, __LINE__) |
912 | #else | 616 | #else |
913 | #define mb_check_buddy(e4b) | 617 | #define mb_check_buddy(e4b) |
914 | #endif | 618 | #endif |
@@ -982,7 +686,7 @@ static void ext4_mb_generate_buddy(struct super_block *sb, | |||
982 | grp->bb_fragments = fragments; | 686 | grp->bb_fragments = fragments; |
983 | 687 | ||
984 | if (free != grp->bb_free) { | 688 | if (free != grp->bb_free) { |
985 | ext4_error(sb, __FUNCTION__, | 689 | ext4_error(sb, __func__, |
986 | "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd\n", | 690 | "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd\n", |
987 | group, free, grp->bb_free); | 691 | group, free, grp->bb_free); |
988 | /* | 692 | /* |
@@ -1168,8 +872,9 @@ out: | |||
1168 | return err; | 872 | return err; |
1169 | } | 873 | } |
1170 | 874 | ||
1171 | static int ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group, | 875 | static noinline_for_stack int |
1172 | struct ext4_buddy *e4b) | 876 | ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group, |
877 | struct ext4_buddy *e4b) | ||
1173 | { | 878 | { |
1174 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 879 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
1175 | struct inode *inode = sbi->s_buddy_cache; | 880 | struct inode *inode = sbi->s_buddy_cache; |
@@ -1367,7 +1072,7 @@ static int mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b, | |||
1367 | blocknr += | 1072 | blocknr += |
1368 | le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); | 1073 | le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); |
1369 | 1074 | ||
1370 | ext4_error(sb, __FUNCTION__, "double-free of inode" | 1075 | ext4_error(sb, __func__, "double-free of inode" |
1371 | " %lu's block %llu(bit %u in group %lu)\n", | 1076 | " %lu's block %llu(bit %u in group %lu)\n", |
1372 | inode ? inode->i_ino : 0, blocknr, block, | 1077 | inode ? inode->i_ino : 0, blocknr, block, |
1373 | e4b->bd_group); | 1078 | e4b->bd_group); |
@@ -1848,7 +1553,7 @@ static void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac, | |||
1848 | * free blocks even though group info says we | 1553 | * free blocks even though group info says we |
1849 | * we have free blocks | 1554 | * we have free blocks |
1850 | */ | 1555 | */ |
1851 | ext4_error(sb, __FUNCTION__, "%d free blocks as per " | 1556 | ext4_error(sb, __func__, "%d free blocks as per " |
1852 | "group info. But bitmap says 0\n", | 1557 | "group info. But bitmap says 0\n", |
1853 | free); | 1558 | free); |
1854 | break; | 1559 | break; |
@@ -1857,7 +1562,7 @@ static void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac, | |||
1857 | mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex); | 1562 | mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex); |
1858 | BUG_ON(ex.fe_len <= 0); | 1563 | BUG_ON(ex.fe_len <= 0); |
1859 | if (free < ex.fe_len) { | 1564 | if (free < ex.fe_len) { |
1860 | ext4_error(sb, __FUNCTION__, "%d free blocks as per " | 1565 | ext4_error(sb, __func__, "%d free blocks as per " |
1861 | "group info. But got %d blocks\n", | 1566 | "group info. But got %d blocks\n", |
1862 | free, ex.fe_len); | 1567 | free, ex.fe_len); |
1863 | /* | 1568 | /* |
@@ -1965,7 +1670,8 @@ static int ext4_mb_good_group(struct ext4_allocation_context *ac, | |||
1965 | return 0; | 1670 | return 0; |
1966 | } | 1671 | } |
1967 | 1672 | ||
1968 | static int ext4_mb_regular_allocator(struct ext4_allocation_context *ac) | 1673 | static noinline_for_stack int |
1674 | ext4_mb_regular_allocator(struct ext4_allocation_context *ac) | ||
1969 | { | 1675 | { |
1970 | ext4_group_t group; | 1676 | ext4_group_t group; |
1971 | ext4_group_t i; | 1677 | ext4_group_t i; |
@@ -2465,7 +2171,8 @@ static void ext4_mb_history_init(struct super_block *sb) | |||
2465 | /* if we can't allocate history, then we simple won't use it */ | 2171 | /* if we can't allocate history, then we simple won't use it */ |
2466 | } | 2172 | } |
2467 | 2173 | ||
2468 | static void ext4_mb_store_history(struct ext4_allocation_context *ac) | 2174 | static noinline_for_stack void |
2175 | ext4_mb_store_history(struct ext4_allocation_context *ac) | ||
2469 | { | 2176 | { |
2470 | struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); | 2177 | struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); |
2471 | struct ext4_mb_history h; | 2178 | struct ext4_mb_history h; |
@@ -2565,13 +2272,13 @@ static int ext4_mb_init_backend(struct super_block *sb) | |||
2565 | meta_group_info[j] = kzalloc(len, GFP_KERNEL); | 2272 | meta_group_info[j] = kzalloc(len, GFP_KERNEL); |
2566 | if (meta_group_info[j] == NULL) { | 2273 | if (meta_group_info[j] == NULL) { |
2567 | printk(KERN_ERR "EXT4-fs: can't allocate buddy mem\n"); | 2274 | printk(KERN_ERR "EXT4-fs: can't allocate buddy mem\n"); |
2568 | i--; | ||
2569 | goto err_freebuddy; | 2275 | goto err_freebuddy; |
2570 | } | 2276 | } |
2571 | desc = ext4_get_group_desc(sb, i, NULL); | 2277 | desc = ext4_get_group_desc(sb, i, NULL); |
2572 | if (desc == NULL) { | 2278 | if (desc == NULL) { |
2573 | printk(KERN_ERR | 2279 | printk(KERN_ERR |
2574 | "EXT4-fs: can't read descriptor %lu\n", i); | 2280 | "EXT4-fs: can't read descriptor %lu\n", i); |
2281 | i++; | ||
2575 | goto err_freebuddy; | 2282 | goto err_freebuddy; |
2576 | } | 2283 | } |
2577 | memset(meta_group_info[j], 0, len); | 2284 | memset(meta_group_info[j], 0, len); |
@@ -2611,13 +2318,11 @@ static int ext4_mb_init_backend(struct super_block *sb) | |||
2611 | return 0; | 2318 | return 0; |
2612 | 2319 | ||
2613 | err_freebuddy: | 2320 | err_freebuddy: |
2614 | while (i >= 0) { | 2321 | while (i-- > 0) |
2615 | kfree(ext4_get_group_info(sb, i)); | 2322 | kfree(ext4_get_group_info(sb, i)); |
2616 | i--; | ||
2617 | } | ||
2618 | i = num_meta_group_infos; | 2323 | i = num_meta_group_infos; |
2619 | err_freemeta: | 2324 | err_freemeta: |
2620 | while (--i >= 0) | 2325 | while (i-- > 0) |
2621 | kfree(sbi->s_group_info[i]); | 2326 | kfree(sbi->s_group_info[i]); |
2622 | iput(sbi->s_buddy_cache); | 2327 | iput(sbi->s_buddy_cache); |
2623 | err_freesgi: | 2328 | err_freesgi: |
@@ -2801,7 +2506,8 @@ int ext4_mb_release(struct super_block *sb) | |||
2801 | return 0; | 2506 | return 0; |
2802 | } | 2507 | } |
2803 | 2508 | ||
2804 | static void ext4_mb_free_committed_blocks(struct super_block *sb) | 2509 | static noinline_for_stack void |
2510 | ext4_mb_free_committed_blocks(struct super_block *sb) | ||
2805 | { | 2511 | { |
2806 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 2512 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
2807 | int err; | 2513 | int err; |
@@ -3021,7 +2727,8 @@ void exit_ext4_mballoc(void) | |||
3021 | * Check quota and mark choosed space (ac->ac_b_ex) non-free in bitmaps | 2727 | * Check quota and mark choosed space (ac->ac_b_ex) non-free in bitmaps |
3022 | * Returns 0 if success or error code | 2728 | * Returns 0 if success or error code |
3023 | */ | 2729 | */ |
3024 | static int ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, | 2730 | static noinline_for_stack int |
2731 | ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, | ||
3025 | handle_t *handle) | 2732 | handle_t *handle) |
3026 | { | 2733 | { |
3027 | struct buffer_head *bitmap_bh = NULL; | 2734 | struct buffer_head *bitmap_bh = NULL; |
@@ -3070,7 +2777,7 @@ static int ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, | |||
3070 | in_range(block, ext4_inode_table(sb, gdp), | 2777 | in_range(block, ext4_inode_table(sb, gdp), |
3071 | EXT4_SB(sb)->s_itb_per_group)) { | 2778 | EXT4_SB(sb)->s_itb_per_group)) { |
3072 | 2779 | ||
3073 | ext4_error(sb, __FUNCTION__, | 2780 | ext4_error(sb, __func__, |
3074 | "Allocating block in system zone - block = %llu", | 2781 | "Allocating block in system zone - block = %llu", |
3075 | block); | 2782 | block); |
3076 | } | 2783 | } |
@@ -3094,9 +2801,7 @@ static int ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, | |||
3094 | ac->ac_b_ex.fe_group, | 2801 | ac->ac_b_ex.fe_group, |
3095 | gdp)); | 2802 | gdp)); |
3096 | } | 2803 | } |
3097 | gdp->bg_free_blocks_count = | 2804 | le16_add_cpu(&gdp->bg_free_blocks_count, -ac->ac_b_ex.fe_len); |
3098 | cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count) | ||
3099 | - ac->ac_b_ex.fe_len); | ||
3100 | gdp->bg_checksum = ext4_group_desc_csum(sbi, ac->ac_b_ex.fe_group, gdp); | 2805 | gdp->bg_checksum = ext4_group_desc_csum(sbi, ac->ac_b_ex.fe_group, gdp); |
3101 | spin_unlock(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group)); | 2806 | spin_unlock(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group)); |
3102 | percpu_counter_sub(&sbi->s_freeblocks_counter, ac->ac_b_ex.fe_len); | 2807 | percpu_counter_sub(&sbi->s_freeblocks_counter, ac->ac_b_ex.fe_len); |
@@ -3130,7 +2835,7 @@ static void ext4_mb_normalize_group_request(struct ext4_allocation_context *ac) | |||
3130 | ac->ac_g_ex.fe_len = EXT4_SB(sb)->s_stripe; | 2835 | ac->ac_g_ex.fe_len = EXT4_SB(sb)->s_stripe; |
3131 | else | 2836 | else |
3132 | ac->ac_g_ex.fe_len = EXT4_SB(sb)->s_mb_group_prealloc; | 2837 | ac->ac_g_ex.fe_len = EXT4_SB(sb)->s_mb_group_prealloc; |
3133 | mb_debug("#%u: goal %lu blocks for locality group\n", | 2838 | mb_debug("#%u: goal %u blocks for locality group\n", |
3134 | current->pid, ac->ac_g_ex.fe_len); | 2839 | current->pid, ac->ac_g_ex.fe_len); |
3135 | } | 2840 | } |
3136 | 2841 | ||
@@ -3138,15 +2843,16 @@ static void ext4_mb_normalize_group_request(struct ext4_allocation_context *ac) | |||
3138 | * Normalization means making request better in terms of | 2843 | * Normalization means making request better in terms of |
3139 | * size and alignment | 2844 | * size and alignment |
3140 | */ | 2845 | */ |
3141 | static void ext4_mb_normalize_request(struct ext4_allocation_context *ac, | 2846 | static noinline_for_stack void |
2847 | ext4_mb_normalize_request(struct ext4_allocation_context *ac, | ||
3142 | struct ext4_allocation_request *ar) | 2848 | struct ext4_allocation_request *ar) |
3143 | { | 2849 | { |
3144 | int bsbits, max; | 2850 | int bsbits, max; |
3145 | ext4_lblk_t end; | 2851 | ext4_lblk_t end; |
3146 | struct list_head *cur; | ||
3147 | loff_t size, orig_size, start_off; | 2852 | loff_t size, orig_size, start_off; |
3148 | ext4_lblk_t start, orig_start; | 2853 | ext4_lblk_t start, orig_start; |
3149 | struct ext4_inode_info *ei = EXT4_I(ac->ac_inode); | 2854 | struct ext4_inode_info *ei = EXT4_I(ac->ac_inode); |
2855 | struct ext4_prealloc_space *pa; | ||
3150 | 2856 | ||
3151 | /* do normalize only data requests, metadata requests | 2857 | /* do normalize only data requests, metadata requests |
3152 | do not need preallocation */ | 2858 | do not need preallocation */ |
@@ -3232,12 +2938,9 @@ static void ext4_mb_normalize_request(struct ext4_allocation_context *ac, | |||
3232 | 2938 | ||
3233 | /* check we don't cross already preallocated blocks */ | 2939 | /* check we don't cross already preallocated blocks */ |
3234 | rcu_read_lock(); | 2940 | rcu_read_lock(); |
3235 | list_for_each_rcu(cur, &ei->i_prealloc_list) { | 2941 | list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) { |
3236 | struct ext4_prealloc_space *pa; | ||
3237 | unsigned long pa_end; | 2942 | unsigned long pa_end; |
3238 | 2943 | ||
3239 | pa = list_entry(cur, struct ext4_prealloc_space, pa_inode_list); | ||
3240 | |||
3241 | if (pa->pa_deleted) | 2944 | if (pa->pa_deleted) |
3242 | continue; | 2945 | continue; |
3243 | spin_lock(&pa->pa_lock); | 2946 | spin_lock(&pa->pa_lock); |
@@ -3279,10 +2982,8 @@ static void ext4_mb_normalize_request(struct ext4_allocation_context *ac, | |||
3279 | 2982 | ||
3280 | /* XXX: extra loop to check we really don't overlap preallocations */ | 2983 | /* XXX: extra loop to check we really don't overlap preallocations */ |
3281 | rcu_read_lock(); | 2984 | rcu_read_lock(); |
3282 | list_for_each_rcu(cur, &ei->i_prealloc_list) { | 2985 | list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) { |
3283 | struct ext4_prealloc_space *pa; | ||
3284 | unsigned long pa_end; | 2986 | unsigned long pa_end; |
3285 | pa = list_entry(cur, struct ext4_prealloc_space, pa_inode_list); | ||
3286 | spin_lock(&pa->pa_lock); | 2987 | spin_lock(&pa->pa_lock); |
3287 | if (pa->pa_deleted == 0) { | 2988 | if (pa->pa_deleted == 0) { |
3288 | pa_end = pa->pa_lstart + pa->pa_len; | 2989 | pa_end = pa->pa_lstart + pa->pa_len; |
@@ -3374,7 +3075,7 @@ static void ext4_mb_use_inode_pa(struct ext4_allocation_context *ac, | |||
3374 | BUG_ON(pa->pa_free < len); | 3075 | BUG_ON(pa->pa_free < len); |
3375 | pa->pa_free -= len; | 3076 | pa->pa_free -= len; |
3376 | 3077 | ||
3377 | mb_debug("use %llu/%lu from inode pa %p\n", start, len, pa); | 3078 | mb_debug("use %llu/%u from inode pa %p\n", start, len, pa); |
3378 | } | 3079 | } |
3379 | 3080 | ||
3380 | /* | 3081 | /* |
@@ -3404,12 +3105,12 @@ static void ext4_mb_use_group_pa(struct ext4_allocation_context *ac, | |||
3404 | /* | 3105 | /* |
3405 | * search goal blocks in preallocated space | 3106 | * search goal blocks in preallocated space |
3406 | */ | 3107 | */ |
3407 | static int ext4_mb_use_preallocated(struct ext4_allocation_context *ac) | 3108 | static noinline_for_stack int |
3109 | ext4_mb_use_preallocated(struct ext4_allocation_context *ac) | ||
3408 | { | 3110 | { |
3409 | struct ext4_inode_info *ei = EXT4_I(ac->ac_inode); | 3111 | struct ext4_inode_info *ei = EXT4_I(ac->ac_inode); |
3410 | struct ext4_locality_group *lg; | 3112 | struct ext4_locality_group *lg; |
3411 | struct ext4_prealloc_space *pa; | 3113 | struct ext4_prealloc_space *pa; |
3412 | struct list_head *cur; | ||
3413 | 3114 | ||
3414 | /* only data can be preallocated */ | 3115 | /* only data can be preallocated */ |
3415 | if (!(ac->ac_flags & EXT4_MB_HINT_DATA)) | 3116 | if (!(ac->ac_flags & EXT4_MB_HINT_DATA)) |
@@ -3417,8 +3118,7 @@ static int ext4_mb_use_preallocated(struct ext4_allocation_context *ac) | |||
3417 | 3118 | ||
3418 | /* first, try per-file preallocation */ | 3119 | /* first, try per-file preallocation */ |
3419 | rcu_read_lock(); | 3120 | rcu_read_lock(); |
3420 | list_for_each_rcu(cur, &ei->i_prealloc_list) { | 3121 | list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) { |
3421 | pa = list_entry(cur, struct ext4_prealloc_space, pa_inode_list); | ||
3422 | 3122 | ||
3423 | /* all fields in this condition don't change, | 3123 | /* all fields in this condition don't change, |
3424 | * so we can skip locking for them */ | 3124 | * so we can skip locking for them */ |
@@ -3450,8 +3150,7 @@ static int ext4_mb_use_preallocated(struct ext4_allocation_context *ac) | |||
3450 | return 0; | 3150 | return 0; |
3451 | 3151 | ||
3452 | rcu_read_lock(); | 3152 | rcu_read_lock(); |
3453 | list_for_each_rcu(cur, &lg->lg_prealloc_list) { | 3153 | list_for_each_entry_rcu(pa, &lg->lg_prealloc_list, pa_inode_list) { |
3454 | pa = list_entry(cur, struct ext4_prealloc_space, pa_inode_list); | ||
3455 | spin_lock(&pa->pa_lock); | 3154 | spin_lock(&pa->pa_lock); |
3456 | if (pa->pa_deleted == 0 && pa->pa_free >= ac->ac_o_ex.fe_len) { | 3155 | if (pa->pa_deleted == 0 && pa->pa_free >= ac->ac_o_ex.fe_len) { |
3457 | atomic_inc(&pa->pa_count); | 3156 | atomic_inc(&pa->pa_count); |
@@ -3571,7 +3270,8 @@ static void ext4_mb_put_pa(struct ext4_allocation_context *ac, | |||
3571 | /* | 3270 | /* |
3572 | * creates new preallocated space for given inode | 3271 | * creates new preallocated space for given inode |
3573 | */ | 3272 | */ |
3574 | static int ext4_mb_new_inode_pa(struct ext4_allocation_context *ac) | 3273 | static noinline_for_stack int |
3274 | ext4_mb_new_inode_pa(struct ext4_allocation_context *ac) | ||
3575 | { | 3275 | { |
3576 | struct super_block *sb = ac->ac_sb; | 3276 | struct super_block *sb = ac->ac_sb; |
3577 | struct ext4_prealloc_space *pa; | 3277 | struct ext4_prealloc_space *pa; |
@@ -3658,7 +3358,8 @@ static int ext4_mb_new_inode_pa(struct ext4_allocation_context *ac) | |||
3658 | /* | 3358 | /* |
3659 | * creates new preallocated space for locality group inodes belongs to | 3359 | * creates new preallocated space for locality group inodes belongs to |
3660 | */ | 3360 | */ |
3661 | static int ext4_mb_new_group_pa(struct ext4_allocation_context *ac) | 3361 | static noinline_for_stack int |
3362 | ext4_mb_new_group_pa(struct ext4_allocation_context *ac) | ||
3662 | { | 3363 | { |
3663 | struct super_block *sb = ac->ac_sb; | 3364 | struct super_block *sb = ac->ac_sb; |
3664 | struct ext4_locality_group *lg; | 3365 | struct ext4_locality_group *lg; |
@@ -3731,11 +3432,11 @@ static int ext4_mb_new_preallocation(struct ext4_allocation_context *ac) | |||
3731 | * the caller MUST hold group/inode locks. | 3432 | * the caller MUST hold group/inode locks. |
3732 | * TODO: optimize the case when there are no in-core structures yet | 3433 | * TODO: optimize the case when there are no in-core structures yet |
3733 | */ | 3434 | */ |
3734 | static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b, | 3435 | static noinline_for_stack int |
3735 | struct buffer_head *bitmap_bh, | 3436 | ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh, |
3736 | struct ext4_prealloc_space *pa) | 3437 | struct ext4_prealloc_space *pa, |
3438 | struct ext4_allocation_context *ac) | ||
3737 | { | 3439 | { |
3738 | struct ext4_allocation_context *ac; | ||
3739 | struct super_block *sb = e4b->bd_sb; | 3440 | struct super_block *sb = e4b->bd_sb; |
3740 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 3441 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
3741 | unsigned long end; | 3442 | unsigned long end; |
@@ -3751,8 +3452,6 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b, | |||
3751 | BUG_ON(group != e4b->bd_group && pa->pa_len != 0); | 3452 | BUG_ON(group != e4b->bd_group && pa->pa_len != 0); |
3752 | end = bit + pa->pa_len; | 3453 | end = bit + pa->pa_len; |
3753 | 3454 | ||
3754 | ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); | ||
3755 | |||
3756 | if (ac) { | 3455 | if (ac) { |
3757 | ac->ac_sb = sb; | 3456 | ac->ac_sb = sb; |
3758 | ac->ac_inode = pa->pa_inode; | 3457 | ac->ac_inode = pa->pa_inode; |
@@ -3789,7 +3488,7 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b, | |||
3789 | pa, (unsigned long) pa->pa_lstart, | 3488 | pa, (unsigned long) pa->pa_lstart, |
3790 | (unsigned long) pa->pa_pstart, | 3489 | (unsigned long) pa->pa_pstart, |
3791 | (unsigned long) pa->pa_len); | 3490 | (unsigned long) pa->pa_len); |
3792 | ext4_error(sb, __FUNCTION__, "free %u, pa_free %u\n", | 3491 | ext4_error(sb, __func__, "free %u, pa_free %u\n", |
3793 | free, pa->pa_free); | 3492 | free, pa->pa_free); |
3794 | /* | 3493 | /* |
3795 | * pa is already deleted so we use the value obtained | 3494 | * pa is already deleted so we use the value obtained |
@@ -3797,22 +3496,19 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b, | |||
3797 | */ | 3496 | */ |
3798 | } | 3497 | } |
3799 | atomic_add(free, &sbi->s_mb_discarded); | 3498 | atomic_add(free, &sbi->s_mb_discarded); |
3800 | if (ac) | ||
3801 | kmem_cache_free(ext4_ac_cachep, ac); | ||
3802 | 3499 | ||
3803 | return err; | 3500 | return err; |
3804 | } | 3501 | } |
3805 | 3502 | ||
3806 | static int ext4_mb_release_group_pa(struct ext4_buddy *e4b, | 3503 | static noinline_for_stack int |
3807 | struct ext4_prealloc_space *pa) | 3504 | ext4_mb_release_group_pa(struct ext4_buddy *e4b, |
3505 | struct ext4_prealloc_space *pa, | ||
3506 | struct ext4_allocation_context *ac) | ||
3808 | { | 3507 | { |
3809 | struct ext4_allocation_context *ac; | ||
3810 | struct super_block *sb = e4b->bd_sb; | 3508 | struct super_block *sb = e4b->bd_sb; |
3811 | ext4_group_t group; | 3509 | ext4_group_t group; |
3812 | ext4_grpblk_t bit; | 3510 | ext4_grpblk_t bit; |
3813 | 3511 | ||
3814 | ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); | ||
3815 | |||
3816 | if (ac) | 3512 | if (ac) |
3817 | ac->ac_op = EXT4_MB_HISTORY_DISCARD; | 3513 | ac->ac_op = EXT4_MB_HISTORY_DISCARD; |
3818 | 3514 | ||
@@ -3830,7 +3526,6 @@ static int ext4_mb_release_group_pa(struct ext4_buddy *e4b, | |||
3830 | ac->ac_b_ex.fe_len = pa->pa_len; | 3526 | ac->ac_b_ex.fe_len = pa->pa_len; |
3831 | ac->ac_b_ex.fe_logical = 0; | 3527 | ac->ac_b_ex.fe_logical = 0; |
3832 | ext4_mb_store_history(ac); | 3528 | ext4_mb_store_history(ac); |
3833 | kmem_cache_free(ext4_ac_cachep, ac); | ||
3834 | } | 3529 | } |
3835 | 3530 | ||
3836 | return 0; | 3531 | return 0; |
@@ -3845,12 +3540,14 @@ static int ext4_mb_release_group_pa(struct ext4_buddy *e4b, | |||
3845 | * - how many do we discard | 3540 | * - how many do we discard |
3846 | * 1) how many requested | 3541 | * 1) how many requested |
3847 | */ | 3542 | */ |
3848 | static int ext4_mb_discard_group_preallocations(struct super_block *sb, | 3543 | static noinline_for_stack int |
3544 | ext4_mb_discard_group_preallocations(struct super_block *sb, | ||
3849 | ext4_group_t group, int needed) | 3545 | ext4_group_t group, int needed) |
3850 | { | 3546 | { |
3851 | struct ext4_group_info *grp = ext4_get_group_info(sb, group); | 3547 | struct ext4_group_info *grp = ext4_get_group_info(sb, group); |
3852 | struct buffer_head *bitmap_bh = NULL; | 3548 | struct buffer_head *bitmap_bh = NULL; |
3853 | struct ext4_prealloc_space *pa, *tmp; | 3549 | struct ext4_prealloc_space *pa, *tmp; |
3550 | struct ext4_allocation_context *ac; | ||
3854 | struct list_head list; | 3551 | struct list_head list; |
3855 | struct ext4_buddy e4b; | 3552 | struct ext4_buddy e4b; |
3856 | int err; | 3553 | int err; |
@@ -3878,6 +3575,7 @@ static int ext4_mb_discard_group_preallocations(struct super_block *sb, | |||
3878 | grp = ext4_get_group_info(sb, group); | 3575 | grp = ext4_get_group_info(sb, group); |
3879 | INIT_LIST_HEAD(&list); | 3576 | INIT_LIST_HEAD(&list); |
3880 | 3577 | ||
3578 | ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); | ||
3881 | repeat: | 3579 | repeat: |
3882 | ext4_lock_group(sb, group); | 3580 | ext4_lock_group(sb, group); |
3883 | list_for_each_entry_safe(pa, tmp, | 3581 | list_for_each_entry_safe(pa, tmp, |
@@ -3932,9 +3630,9 @@ repeat: | |||
3932 | spin_unlock(pa->pa_obj_lock); | 3630 | spin_unlock(pa->pa_obj_lock); |
3933 | 3631 | ||
3934 | if (pa->pa_linear) | 3632 | if (pa->pa_linear) |
3935 | ext4_mb_release_group_pa(&e4b, pa); | 3633 | ext4_mb_release_group_pa(&e4b, pa, ac); |
3936 | else | 3634 | else |
3937 | ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa); | 3635 | ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa, ac); |
3938 | 3636 | ||
3939 | list_del(&pa->u.pa_tmp_list); | 3637 | list_del(&pa->u.pa_tmp_list); |
3940 | call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback); | 3638 | call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback); |
@@ -3942,6 +3640,8 @@ repeat: | |||
3942 | 3640 | ||
3943 | out: | 3641 | out: |
3944 | ext4_unlock_group(sb, group); | 3642 | ext4_unlock_group(sb, group); |
3643 | if (ac) | ||
3644 | kmem_cache_free(ext4_ac_cachep, ac); | ||
3945 | ext4_mb_release_desc(&e4b); | 3645 | ext4_mb_release_desc(&e4b); |
3946 | put_bh(bitmap_bh); | 3646 | put_bh(bitmap_bh); |
3947 | return free; | 3647 | return free; |
@@ -3962,6 +3662,7 @@ void ext4_mb_discard_inode_preallocations(struct inode *inode) | |||
3962 | struct super_block *sb = inode->i_sb; | 3662 | struct super_block *sb = inode->i_sb; |
3963 | struct buffer_head *bitmap_bh = NULL; | 3663 | struct buffer_head *bitmap_bh = NULL; |
3964 | struct ext4_prealloc_space *pa, *tmp; | 3664 | struct ext4_prealloc_space *pa, *tmp; |
3665 | struct ext4_allocation_context *ac; | ||
3965 | ext4_group_t group = 0; | 3666 | ext4_group_t group = 0; |
3966 | struct list_head list; | 3667 | struct list_head list; |
3967 | struct ext4_buddy e4b; | 3668 | struct ext4_buddy e4b; |
@@ -3976,6 +3677,7 @@ void ext4_mb_discard_inode_preallocations(struct inode *inode) | |||
3976 | 3677 | ||
3977 | INIT_LIST_HEAD(&list); | 3678 | INIT_LIST_HEAD(&list); |
3978 | 3679 | ||
3680 | ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); | ||
3979 | repeat: | 3681 | repeat: |
3980 | /* first, collect all pa's in the inode */ | 3682 | /* first, collect all pa's in the inode */ |
3981 | spin_lock(&ei->i_prealloc_lock); | 3683 | spin_lock(&ei->i_prealloc_lock); |
@@ -4040,7 +3742,7 @@ repeat: | |||
4040 | 3742 | ||
4041 | ext4_lock_group(sb, group); | 3743 | ext4_lock_group(sb, group); |
4042 | list_del(&pa->pa_group_list); | 3744 | list_del(&pa->pa_group_list); |
4043 | ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa); | 3745 | ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa, ac); |
4044 | ext4_unlock_group(sb, group); | 3746 | ext4_unlock_group(sb, group); |
4045 | 3747 | ||
4046 | ext4_mb_release_desc(&e4b); | 3748 | ext4_mb_release_desc(&e4b); |
@@ -4049,6 +3751,8 @@ repeat: | |||
4049 | list_del(&pa->u.pa_tmp_list); | 3751 | list_del(&pa->u.pa_tmp_list); |
4050 | call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback); | 3752 | call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback); |
4051 | } | 3753 | } |
3754 | if (ac) | ||
3755 | kmem_cache_free(ext4_ac_cachep, ac); | ||
4052 | } | 3756 | } |
4053 | 3757 | ||
4054 | /* | 3758 | /* |
@@ -4108,7 +3812,7 @@ static void ext4_mb_show_ac(struct ext4_allocation_context *ac) | |||
4108 | printk(KERN_ERR "PA:%lu:%d:%u \n", i, | 3812 | printk(KERN_ERR "PA:%lu:%d:%u \n", i, |
4109 | start, pa->pa_len); | 3813 | start, pa->pa_len); |
4110 | } | 3814 | } |
4111 | ext4_lock_group(sb, i); | 3815 | ext4_unlock_group(sb, i); |
4112 | 3816 | ||
4113 | if (grp->bb_free == 0) | 3817 | if (grp->bb_free == 0) |
4114 | continue; | 3818 | continue; |
@@ -4167,7 +3871,8 @@ static void ext4_mb_group_or_file(struct ext4_allocation_context *ac) | |||
4167 | mutex_lock(&ac->ac_lg->lg_mutex); | 3871 | mutex_lock(&ac->ac_lg->lg_mutex); |
4168 | } | 3872 | } |
4169 | 3873 | ||
4170 | static int ext4_mb_initialize_context(struct ext4_allocation_context *ac, | 3874 | static noinline_for_stack int |
3875 | ext4_mb_initialize_context(struct ext4_allocation_context *ac, | ||
4171 | struct ext4_allocation_request *ar) | 3876 | struct ext4_allocation_request *ar) |
4172 | { | 3877 | { |
4173 | struct super_block *sb = ar->inode->i_sb; | 3878 | struct super_block *sb = ar->inode->i_sb; |
@@ -4398,7 +4103,8 @@ static void ext4_mb_poll_new_transaction(struct super_block *sb, | |||
4398 | ext4_mb_free_committed_blocks(sb); | 4103 | ext4_mb_free_committed_blocks(sb); |
4399 | } | 4104 | } |
4400 | 4105 | ||
4401 | static int ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b, | 4106 | static noinline_for_stack int |
4107 | ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b, | ||
4402 | ext4_group_t group, ext4_grpblk_t block, int count) | 4108 | ext4_group_t group, ext4_grpblk_t block, int count) |
4403 | { | 4109 | { |
4404 | struct ext4_group_info *db = e4b->bd_info; | 4110 | struct ext4_group_info *db = e4b->bd_info; |
@@ -4489,7 +4195,7 @@ void ext4_mb_free_blocks(handle_t *handle, struct inode *inode, | |||
4489 | if (block < le32_to_cpu(es->s_first_data_block) || | 4195 | if (block < le32_to_cpu(es->s_first_data_block) || |
4490 | block + count < block || | 4196 | block + count < block || |
4491 | block + count > ext4_blocks_count(es)) { | 4197 | block + count > ext4_blocks_count(es)) { |
4492 | ext4_error(sb, __FUNCTION__, | 4198 | ext4_error(sb, __func__, |
4493 | "Freeing blocks not in datazone - " | 4199 | "Freeing blocks not in datazone - " |
4494 | "block = %lu, count = %lu", block, count); | 4200 | "block = %lu, count = %lu", block, count); |
4495 | goto error_return; | 4201 | goto error_return; |
@@ -4530,7 +4236,7 @@ do_more: | |||
4530 | in_range(block + count - 1, ext4_inode_table(sb, gdp), | 4236 | in_range(block + count - 1, ext4_inode_table(sb, gdp), |
4531 | EXT4_SB(sb)->s_itb_per_group)) { | 4237 | EXT4_SB(sb)->s_itb_per_group)) { |
4532 | 4238 | ||
4533 | ext4_error(sb, __FUNCTION__, | 4239 | ext4_error(sb, __func__, |
4534 | "Freeing blocks in system zone - " | 4240 | "Freeing blocks in system zone - " |
4535 | "Block = %lu, count = %lu", block, count); | 4241 | "Block = %lu, count = %lu", block, count); |
4536 | } | 4242 | } |
@@ -4588,8 +4294,7 @@ do_more: | |||
4588 | } | 4294 | } |
4589 | 4295 | ||
4590 | spin_lock(sb_bgl_lock(sbi, block_group)); | 4296 | spin_lock(sb_bgl_lock(sbi, block_group)); |
4591 | gdp->bg_free_blocks_count = | 4297 | le16_add_cpu(&gdp->bg_free_blocks_count, count); |
4592 | cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count) + count); | ||
4593 | gdp->bg_checksum = ext4_group_desc_csum(sbi, block_group, gdp); | 4298 | gdp->bg_checksum = ext4_group_desc_csum(sbi, block_group, gdp); |
4594 | spin_unlock(sb_bgl_lock(sbi, block_group)); | 4299 | spin_unlock(sb_bgl_lock(sbi, block_group)); |
4595 | percpu_counter_add(&sbi->s_freeblocks_counter, count); | 4300 | percpu_counter_add(&sbi->s_freeblocks_counter, count); |
diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h new file mode 100644 index 000000000000..bfe6add46bcf --- /dev/null +++ b/fs/ext4/mballoc.h | |||
@@ -0,0 +1,304 @@ | |||
1 | /* | ||
2 | * fs/ext4/mballoc.h | ||
3 | * | ||
4 | * Written by: Alex Tomas <alex@clusterfs.com> | ||
5 | * | ||
6 | */ | ||
7 | #ifndef _EXT4_MBALLOC_H | ||
8 | #define _EXT4_MBALLOC_H | ||
9 | |||
10 | #include <linux/time.h> | ||
11 | #include <linux/fs.h> | ||
12 | #include <linux/namei.h> | ||
13 | #include <linux/quotaops.h> | ||
14 | #include <linux/buffer_head.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/swap.h> | ||
17 | #include <linux/proc_fs.h> | ||
18 | #include <linux/pagemap.h> | ||
19 | #include <linux/seq_file.h> | ||
20 | #include <linux/version.h> | ||
21 | #include "ext4_jbd2.h" | ||
22 | #include "ext4.h" | ||
23 | #include "group.h" | ||
24 | |||
25 | /* | ||
26 | * with AGGRESSIVE_CHECK allocator runs consistency checks over | ||
27 | * structures. these checks slow things down a lot | ||
28 | */ | ||
29 | #define AGGRESSIVE_CHECK__ | ||
30 | |||
31 | /* | ||
32 | * with DOUBLE_CHECK defined mballoc creates persistent in-core | ||
33 | * bitmaps, maintains and uses them to check for double allocations | ||
34 | */ | ||
35 | #define DOUBLE_CHECK__ | ||
36 | |||
37 | /* | ||
38 | */ | ||
39 | #define MB_DEBUG__ | ||
40 | #ifdef MB_DEBUG | ||
41 | #define mb_debug(fmt, a...) printk(fmt, ##a) | ||
42 | #else | ||
43 | #define mb_debug(fmt, a...) | ||
44 | #endif | ||
45 | |||
46 | /* | ||
47 | * with EXT4_MB_HISTORY mballoc stores last N allocations in memory | ||
48 | * and you can monitor it in /proc/fs/ext4/<dev>/mb_history | ||
49 | */ | ||
50 | #define EXT4_MB_HISTORY | ||
51 | #define EXT4_MB_HISTORY_ALLOC 1 /* allocation */ | ||
52 | #define EXT4_MB_HISTORY_PREALLOC 2 /* preallocated blocks used */ | ||
53 | #define EXT4_MB_HISTORY_DISCARD 4 /* preallocation discarded */ | ||
54 | #define EXT4_MB_HISTORY_FREE 8 /* free */ | ||
55 | |||
56 | #define EXT4_MB_HISTORY_DEFAULT (EXT4_MB_HISTORY_ALLOC | \ | ||
57 | EXT4_MB_HISTORY_PREALLOC) | ||
58 | |||
59 | /* | ||
60 | * How long mballoc can look for a best extent (in found extents) | ||
61 | */ | ||
62 | #define MB_DEFAULT_MAX_TO_SCAN 200 | ||
63 | |||
64 | /* | ||
65 | * How long mballoc must look for a best extent | ||
66 | */ | ||
67 | #define MB_DEFAULT_MIN_TO_SCAN 10 | ||
68 | |||
69 | /* | ||
70 | * How many groups mballoc will scan looking for the best chunk | ||
71 | */ | ||
72 | #define MB_DEFAULT_MAX_GROUPS_TO_SCAN 5 | ||
73 | |||
74 | /* | ||
75 | * with 'ext4_mb_stats' allocator will collect stats that will be | ||
76 | * shown at umount. The collecting costs though! | ||
77 | */ | ||
78 | #define MB_DEFAULT_STATS 1 | ||
79 | |||
80 | /* | ||
81 | * files smaller than MB_DEFAULT_STREAM_THRESHOLD are served | ||
82 | * by the stream allocator, which purpose is to pack requests | ||
83 | * as close each to other as possible to produce smooth I/O traffic | ||
84 | * We use locality group prealloc space for stream request. | ||
85 | * We can tune the same via /proc/fs/ext4/<parition>/stream_req | ||
86 | */ | ||
87 | #define MB_DEFAULT_STREAM_THRESHOLD 16 /* 64K */ | ||
88 | |||
89 | /* | ||
90 | * for which requests use 2^N search using buddies | ||
91 | */ | ||
92 | #define MB_DEFAULT_ORDER2_REQS 2 | ||
93 | |||
94 | /* | ||
95 | * default group prealloc size 512 blocks | ||
96 | */ | ||
97 | #define MB_DEFAULT_GROUP_PREALLOC 512 | ||
98 | |||
99 | static struct kmem_cache *ext4_pspace_cachep; | ||
100 | static struct kmem_cache *ext4_ac_cachep; | ||
101 | |||
102 | #ifdef EXT4_BB_MAX_BLOCKS | ||
103 | #undef EXT4_BB_MAX_BLOCKS | ||
104 | #endif | ||
105 | #define EXT4_BB_MAX_BLOCKS 30 | ||
106 | |||
107 | struct ext4_free_metadata { | ||
108 | ext4_group_t group; | ||
109 | unsigned short num; | ||
110 | ext4_grpblk_t blocks[EXT4_BB_MAX_BLOCKS]; | ||
111 | struct list_head list; | ||
112 | }; | ||
113 | |||
114 | struct ext4_group_info { | ||
115 | unsigned long bb_state; | ||
116 | unsigned long bb_tid; | ||
117 | struct ext4_free_metadata *bb_md_cur; | ||
118 | unsigned short bb_first_free; | ||
119 | unsigned short bb_free; | ||
120 | unsigned short bb_fragments; | ||
121 | struct list_head bb_prealloc_list; | ||
122 | #ifdef DOUBLE_CHECK | ||
123 | void *bb_bitmap; | ||
124 | #endif | ||
125 | unsigned short bb_counters[]; | ||
126 | }; | ||
127 | |||
128 | #define EXT4_GROUP_INFO_NEED_INIT_BIT 0 | ||
129 | #define EXT4_GROUP_INFO_LOCKED_BIT 1 | ||
130 | |||
131 | #define EXT4_MB_GRP_NEED_INIT(grp) \ | ||
132 | (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) | ||
133 | |||
134 | |||
135 | struct ext4_prealloc_space { | ||
136 | struct list_head pa_inode_list; | ||
137 | struct list_head pa_group_list; | ||
138 | union { | ||
139 | struct list_head pa_tmp_list; | ||
140 | struct rcu_head pa_rcu; | ||
141 | } u; | ||
142 | spinlock_t pa_lock; | ||
143 | atomic_t pa_count; | ||
144 | unsigned pa_deleted; | ||
145 | ext4_fsblk_t pa_pstart; /* phys. block */ | ||
146 | ext4_lblk_t pa_lstart; /* log. block */ | ||
147 | unsigned short pa_len; /* len of preallocated chunk */ | ||
148 | unsigned short pa_free; /* how many blocks are free */ | ||
149 | unsigned short pa_linear; /* consumed in one direction | ||
150 | * strictly, for grp prealloc */ | ||
151 | spinlock_t *pa_obj_lock; | ||
152 | struct inode *pa_inode; /* hack, for history only */ | ||
153 | }; | ||
154 | |||
155 | |||
156 | struct ext4_free_extent { | ||
157 | ext4_lblk_t fe_logical; | ||
158 | ext4_grpblk_t fe_start; | ||
159 | ext4_group_t fe_group; | ||
160 | int fe_len; | ||
161 | }; | ||
162 | |||
163 | /* | ||
164 | * Locality group: | ||
165 | * we try to group all related changes together | ||
166 | * so that writeback can flush/allocate them together as well | ||
167 | */ | ||
168 | struct ext4_locality_group { | ||
169 | /* for allocator */ | ||
170 | struct mutex lg_mutex; /* to serialize allocates */ | ||
171 | struct list_head lg_prealloc_list;/* list of preallocations */ | ||
172 | spinlock_t lg_prealloc_lock; | ||
173 | }; | ||
174 | |||
175 | struct ext4_allocation_context { | ||
176 | struct inode *ac_inode; | ||
177 | struct super_block *ac_sb; | ||
178 | |||
179 | /* original request */ | ||
180 | struct ext4_free_extent ac_o_ex; | ||
181 | |||
182 | /* goal request (after normalization) */ | ||
183 | struct ext4_free_extent ac_g_ex; | ||
184 | |||
185 | /* the best found extent */ | ||
186 | struct ext4_free_extent ac_b_ex; | ||
187 | |||
188 | /* copy of the bext found extent taken before preallocation efforts */ | ||
189 | struct ext4_free_extent ac_f_ex; | ||
190 | |||
191 | /* number of iterations done. we have to track to limit searching */ | ||
192 | unsigned long ac_ex_scanned; | ||
193 | __u16 ac_groups_scanned; | ||
194 | __u16 ac_found; | ||
195 | __u16 ac_tail; | ||
196 | __u16 ac_buddy; | ||
197 | __u16 ac_flags; /* allocation hints */ | ||
198 | __u8 ac_status; | ||
199 | __u8 ac_criteria; | ||
200 | __u8 ac_repeats; | ||
201 | __u8 ac_2order; /* if request is to allocate 2^N blocks and | ||
202 | * N > 0, the field stores N, otherwise 0 */ | ||
203 | __u8 ac_op; /* operation, for history only */ | ||
204 | struct page *ac_bitmap_page; | ||
205 | struct page *ac_buddy_page; | ||
206 | struct ext4_prealloc_space *ac_pa; | ||
207 | struct ext4_locality_group *ac_lg; | ||
208 | }; | ||
209 | |||
210 | #define AC_STATUS_CONTINUE 1 | ||
211 | #define AC_STATUS_FOUND 2 | ||
212 | #define AC_STATUS_BREAK 3 | ||
213 | |||
214 | struct ext4_mb_history { | ||
215 | struct ext4_free_extent orig; /* orig allocation */ | ||
216 | struct ext4_free_extent goal; /* goal allocation */ | ||
217 | struct ext4_free_extent result; /* result allocation */ | ||
218 | unsigned pid; | ||
219 | unsigned ino; | ||
220 | __u16 found; /* how many extents have been found */ | ||
221 | __u16 groups; /* how many groups have been scanned */ | ||
222 | __u16 tail; /* what tail broke some buddy */ | ||
223 | __u16 buddy; /* buddy the tail ^^^ broke */ | ||
224 | __u16 flags; | ||
225 | __u8 cr:3; /* which phase the result extent was found at */ | ||
226 | __u8 op:4; | ||
227 | __u8 merged:1; | ||
228 | }; | ||
229 | |||
230 | struct ext4_buddy { | ||
231 | struct page *bd_buddy_page; | ||
232 | void *bd_buddy; | ||
233 | struct page *bd_bitmap_page; | ||
234 | void *bd_bitmap; | ||
235 | struct ext4_group_info *bd_info; | ||
236 | struct super_block *bd_sb; | ||
237 | __u16 bd_blkbits; | ||
238 | ext4_group_t bd_group; | ||
239 | }; | ||
240 | #define EXT4_MB_BITMAP(e4b) ((e4b)->bd_bitmap) | ||
241 | #define EXT4_MB_BUDDY(e4b) ((e4b)->bd_buddy) | ||
242 | |||
243 | #ifndef EXT4_MB_HISTORY | ||
244 | static inline void ext4_mb_store_history(struct ext4_allocation_context *ac) | ||
245 | { | ||
246 | return; | ||
247 | } | ||
248 | #else | ||
249 | static void ext4_mb_store_history(struct ext4_allocation_context *ac); | ||
250 | #endif | ||
251 | |||
252 | #define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1) | ||
253 | |||
254 | static struct proc_dir_entry *proc_root_ext4; | ||
255 | struct buffer_head *read_block_bitmap(struct super_block *, ext4_group_t); | ||
256 | |||
257 | static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap, | ||
258 | ext4_group_t group); | ||
259 | static void ext4_mb_poll_new_transaction(struct super_block *, handle_t *); | ||
260 | static void ext4_mb_free_committed_blocks(struct super_block *); | ||
261 | static void ext4_mb_return_to_preallocation(struct inode *inode, | ||
262 | struct ext4_buddy *e4b, sector_t block, | ||
263 | int count); | ||
264 | static void ext4_mb_put_pa(struct ext4_allocation_context *, | ||
265 | struct super_block *, struct ext4_prealloc_space *pa); | ||
266 | static int ext4_mb_init_per_dev_proc(struct super_block *sb); | ||
267 | static int ext4_mb_destroy_per_dev_proc(struct super_block *sb); | ||
268 | |||
269 | |||
270 | static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group) | ||
271 | { | ||
272 | struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); | ||
273 | |||
274 | bit_spin_lock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state)); | ||
275 | } | ||
276 | |||
277 | static inline void ext4_unlock_group(struct super_block *sb, | ||
278 | ext4_group_t group) | ||
279 | { | ||
280 | struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); | ||
281 | |||
282 | bit_spin_unlock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state)); | ||
283 | } | ||
284 | |||
285 | static inline int ext4_is_group_locked(struct super_block *sb, | ||
286 | ext4_group_t group) | ||
287 | { | ||
288 | struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); | ||
289 | |||
290 | return bit_spin_is_locked(EXT4_GROUP_INFO_LOCKED_BIT, | ||
291 | &(grinfo->bb_state)); | ||
292 | } | ||
293 | |||
294 | static ext4_fsblk_t ext4_grp_offs_to_block(struct super_block *sb, | ||
295 | struct ext4_free_extent *fex) | ||
296 | { | ||
297 | ext4_fsblk_t block; | ||
298 | |||
299 | block = (ext4_fsblk_t) fex->fe_group * EXT4_BLOCKS_PER_GROUP(sb) | ||
300 | + fex->fe_start | ||
301 | + le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); | ||
302 | return block; | ||
303 | } | ||
304 | #endif | ||
diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c index 5c1e27de7755..b9e077ba07e9 100644 --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c | |||
@@ -13,8 +13,8 @@ | |||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/ext4_jbd2.h> | 16 | #include "ext4_jbd2.h" |
17 | #include <linux/ext4_fs_extents.h> | 17 | #include "ext4_extents.h" |
18 | 18 | ||
19 | /* | 19 | /* |
20 | * The contiguous blocks details which can be | 20 | * The contiguous blocks details which can be |
@@ -327,7 +327,7 @@ static int free_ind_block(handle_t *handle, struct inode *inode, __le32 *i_data) | |||
327 | } | 327 | } |
328 | 328 | ||
329 | static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, | 329 | static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, |
330 | struct inode *tmp_inode) | 330 | struct inode *tmp_inode) |
331 | { | 331 | { |
332 | int retval; | 332 | int retval; |
333 | __le32 i_data[3]; | 333 | __le32 i_data[3]; |
@@ -339,7 +339,7 @@ static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, | |||
339 | * i_data field of the original inode | 339 | * i_data field of the original inode |
340 | */ | 340 | */ |
341 | retval = ext4_journal_extend(handle, 1); | 341 | retval = ext4_journal_extend(handle, 1); |
342 | if (retval != 0) { | 342 | if (retval) { |
343 | retval = ext4_journal_restart(handle, 1); | 343 | retval = ext4_journal_restart(handle, 1); |
344 | if (retval) | 344 | if (retval) |
345 | goto err_out; | 345 | goto err_out; |
@@ -351,6 +351,18 @@ static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, | |||
351 | 351 | ||
352 | down_write(&EXT4_I(inode)->i_data_sem); | 352 | down_write(&EXT4_I(inode)->i_data_sem); |
353 | /* | 353 | /* |
354 | * if EXT4_EXT_MIGRATE is cleared a block allocation | ||
355 | * happened after we started the migrate. We need to | ||
356 | * fail the migrate | ||
357 | */ | ||
358 | if (!(EXT4_I(inode)->i_flags & EXT4_EXT_MIGRATE)) { | ||
359 | retval = -EAGAIN; | ||
360 | up_write(&EXT4_I(inode)->i_data_sem); | ||
361 | goto err_out; | ||
362 | } else | ||
363 | EXT4_I(inode)->i_flags = EXT4_I(inode)->i_flags & | ||
364 | ~EXT4_EXT_MIGRATE; | ||
365 | /* | ||
354 | * We have the extent map build with the tmp inode. | 366 | * We have the extent map build with the tmp inode. |
355 | * Now copy the i_data across | 367 | * Now copy the i_data across |
356 | */ | 368 | */ |
@@ -508,6 +520,17 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp, | |||
508 | * switch the inode format to prevent read. | 520 | * switch the inode format to prevent read. |
509 | */ | 521 | */ |
510 | mutex_lock(&(inode->i_mutex)); | 522 | mutex_lock(&(inode->i_mutex)); |
523 | /* | ||
524 | * Even though we take i_mutex we can still cause block allocation | ||
525 | * via mmap write to holes. If we have allocated new blocks we fail | ||
526 | * migrate. New block allocation will clear EXT4_EXT_MIGRATE flag. | ||
527 | * The flag is updated with i_data_sem held to prevent racing with | ||
528 | * block allocation. | ||
529 | */ | ||
530 | down_read((&EXT4_I(inode)->i_data_sem)); | ||
531 | EXT4_I(inode)->i_flags = EXT4_I(inode)->i_flags | EXT4_EXT_MIGRATE; | ||
532 | up_read((&EXT4_I(inode)->i_data_sem)); | ||
533 | |||
511 | handle = ext4_journal_start(inode, 1); | 534 | handle = ext4_journal_start(inode, 1); |
512 | 535 | ||
513 | ei = EXT4_I(inode); | 536 | ei = EXT4_I(inode); |
@@ -559,9 +582,15 @@ err_out: | |||
559 | * tmp_inode | 582 | * tmp_inode |
560 | */ | 583 | */ |
561 | free_ext_block(handle, tmp_inode); | 584 | free_ext_block(handle, tmp_inode); |
562 | else | 585 | else { |
563 | retval = ext4_ext_swap_inode_data(handle, inode, | 586 | retval = ext4_ext_swap_inode_data(handle, inode, tmp_inode); |
564 | tmp_inode); | 587 | if (retval) |
588 | /* | ||
589 | * if we fail to swap inode data free the extent | ||
590 | * details of the tmp inode | ||
591 | */ | ||
592 | free_ext_block(handle, tmp_inode); | ||
593 | } | ||
565 | 594 | ||
566 | /* We mark the tmp_inode dirty via ext4_ext_tree_init. */ | 595 | /* We mark the tmp_inode dirty via ext4_ext_tree_init. */ |
567 | if (ext4_journal_extend(handle, 1) != 0) | 596 | if (ext4_journal_extend(handle, 1) != 0) |
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 28aa2ed4297e..ab16beaa830d 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
@@ -28,14 +28,14 @@ | |||
28 | #include <linux/pagemap.h> | 28 | #include <linux/pagemap.h> |
29 | #include <linux/jbd2.h> | 29 | #include <linux/jbd2.h> |
30 | #include <linux/time.h> | 30 | #include <linux/time.h> |
31 | #include <linux/ext4_fs.h> | ||
32 | #include <linux/ext4_jbd2.h> | ||
33 | #include <linux/fcntl.h> | 31 | #include <linux/fcntl.h> |
34 | #include <linux/stat.h> | 32 | #include <linux/stat.h> |
35 | #include <linux/string.h> | 33 | #include <linux/string.h> |
36 | #include <linux/quotaops.h> | 34 | #include <linux/quotaops.h> |
37 | #include <linux/buffer_head.h> | 35 | #include <linux/buffer_head.h> |
38 | #include <linux/bio.h> | 36 | #include <linux/bio.h> |
37 | #include "ext4.h" | ||
38 | #include "ext4_jbd2.h" | ||
39 | 39 | ||
40 | #include "namei.h" | 40 | #include "namei.h" |
41 | #include "xattr.h" | 41 | #include "xattr.h" |
@@ -57,10 +57,15 @@ static struct buffer_head *ext4_append(handle_t *handle, | |||
57 | 57 | ||
58 | *block = inode->i_size >> inode->i_sb->s_blocksize_bits; | 58 | *block = inode->i_size >> inode->i_sb->s_blocksize_bits; |
59 | 59 | ||
60 | if ((bh = ext4_bread(handle, inode, *block, 1, err))) { | 60 | bh = ext4_bread(handle, inode, *block, 1, err); |
61 | if (bh) { | ||
61 | inode->i_size += inode->i_sb->s_blocksize; | 62 | inode->i_size += inode->i_sb->s_blocksize; |
62 | EXT4_I(inode)->i_disksize = inode->i_size; | 63 | EXT4_I(inode)->i_disksize = inode->i_size; |
63 | ext4_journal_get_write_access(handle,bh); | 64 | *err = ext4_journal_get_write_access(handle, bh); |
65 | if (*err) { | ||
66 | brelse(bh); | ||
67 | bh = NULL; | ||
68 | } | ||
64 | } | 69 | } |
65 | return bh; | 70 | return bh; |
66 | } | 71 | } |
@@ -348,7 +353,7 @@ dx_probe(struct dentry *dentry, struct inode *dir, | |||
348 | if (root->info.hash_version != DX_HASH_TEA && | 353 | if (root->info.hash_version != DX_HASH_TEA && |
349 | root->info.hash_version != DX_HASH_HALF_MD4 && | 354 | root->info.hash_version != DX_HASH_HALF_MD4 && |
350 | root->info.hash_version != DX_HASH_LEGACY) { | 355 | root->info.hash_version != DX_HASH_LEGACY) { |
351 | ext4_warning(dir->i_sb, __FUNCTION__, | 356 | ext4_warning(dir->i_sb, __func__, |
352 | "Unrecognised inode hash code %d", | 357 | "Unrecognised inode hash code %d", |
353 | root->info.hash_version); | 358 | root->info.hash_version); |
354 | brelse(bh); | 359 | brelse(bh); |
@@ -362,7 +367,7 @@ dx_probe(struct dentry *dentry, struct inode *dir, | |||
362 | hash = hinfo->hash; | 367 | hash = hinfo->hash; |
363 | 368 | ||
364 | if (root->info.unused_flags & 1) { | 369 | if (root->info.unused_flags & 1) { |
365 | ext4_warning(dir->i_sb, __FUNCTION__, | 370 | ext4_warning(dir->i_sb, __func__, |
366 | "Unimplemented inode hash flags: %#06x", | 371 | "Unimplemented inode hash flags: %#06x", |
367 | root->info.unused_flags); | 372 | root->info.unused_flags); |
368 | brelse(bh); | 373 | brelse(bh); |
@@ -371,7 +376,7 @@ dx_probe(struct dentry *dentry, struct inode *dir, | |||
371 | } | 376 | } |
372 | 377 | ||
373 | if ((indirect = root->info.indirect_levels) > 1) { | 378 | if ((indirect = root->info.indirect_levels) > 1) { |
374 | ext4_warning(dir->i_sb, __FUNCTION__, | 379 | ext4_warning(dir->i_sb, __func__, |
375 | "Unimplemented inode hash depth: %#06x", | 380 | "Unimplemented inode hash depth: %#06x", |
376 | root->info.indirect_levels); | 381 | root->info.indirect_levels); |
377 | brelse(bh); | 382 | brelse(bh); |
@@ -384,7 +389,7 @@ dx_probe(struct dentry *dentry, struct inode *dir, | |||
384 | 389 | ||
385 | if (dx_get_limit(entries) != dx_root_limit(dir, | 390 | if (dx_get_limit(entries) != dx_root_limit(dir, |
386 | root->info.info_length)) { | 391 | root->info.info_length)) { |
387 | ext4_warning(dir->i_sb, __FUNCTION__, | 392 | ext4_warning(dir->i_sb, __func__, |
388 | "dx entry: limit != root limit"); | 393 | "dx entry: limit != root limit"); |
389 | brelse(bh); | 394 | brelse(bh); |
390 | *err = ERR_BAD_DX_DIR; | 395 | *err = ERR_BAD_DX_DIR; |
@@ -396,7 +401,7 @@ dx_probe(struct dentry *dentry, struct inode *dir, | |||
396 | { | 401 | { |
397 | count = dx_get_count(entries); | 402 | count = dx_get_count(entries); |
398 | if (!count || count > dx_get_limit(entries)) { | 403 | if (!count || count > dx_get_limit(entries)) { |
399 | ext4_warning(dir->i_sb, __FUNCTION__, | 404 | ext4_warning(dir->i_sb, __func__, |
400 | "dx entry: no count or count > limit"); | 405 | "dx entry: no count or count > limit"); |
401 | brelse(bh); | 406 | brelse(bh); |
402 | *err = ERR_BAD_DX_DIR; | 407 | *err = ERR_BAD_DX_DIR; |
@@ -441,7 +446,7 @@ dx_probe(struct dentry *dentry, struct inode *dir, | |||
441 | goto fail2; | 446 | goto fail2; |
442 | at = entries = ((struct dx_node *) bh->b_data)->entries; | 447 | at = entries = ((struct dx_node *) bh->b_data)->entries; |
443 | if (dx_get_limit(entries) != dx_node_limit (dir)) { | 448 | if (dx_get_limit(entries) != dx_node_limit (dir)) { |
444 | ext4_warning(dir->i_sb, __FUNCTION__, | 449 | ext4_warning(dir->i_sb, __func__, |
445 | "dx entry: limit != node limit"); | 450 | "dx entry: limit != node limit"); |
446 | brelse(bh); | 451 | brelse(bh); |
447 | *err = ERR_BAD_DX_DIR; | 452 | *err = ERR_BAD_DX_DIR; |
@@ -457,7 +462,7 @@ fail2: | |||
457 | } | 462 | } |
458 | fail: | 463 | fail: |
459 | if (*err == ERR_BAD_DX_DIR) | 464 | if (*err == ERR_BAD_DX_DIR) |
460 | ext4_warning(dir->i_sb, __FUNCTION__, | 465 | ext4_warning(dir->i_sb, __func__, |
461 | "Corrupt dir inode %ld, running e2fsck is " | 466 | "Corrupt dir inode %ld, running e2fsck is " |
462 | "recommended.", dir->i_ino); | 467 | "recommended.", dir->i_ino); |
463 | return NULL; | 468 | return NULL; |
@@ -914,7 +919,7 @@ restart: | |||
914 | wait_on_buffer(bh); | 919 | wait_on_buffer(bh); |
915 | if (!buffer_uptodate(bh)) { | 920 | if (!buffer_uptodate(bh)) { |
916 | /* read error, skip block & hope for the best */ | 921 | /* read error, skip block & hope for the best */ |
917 | ext4_error(sb, __FUNCTION__, "reading directory #%lu " | 922 | ext4_error(sb, __func__, "reading directory #%lu " |
918 | "offset %lu", dir->i_ino, | 923 | "offset %lu", dir->i_ino, |
919 | (unsigned long)block); | 924 | (unsigned long)block); |
920 | brelse(bh); | 925 | brelse(bh); |
@@ -1007,7 +1012,7 @@ static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry, | |||
1007 | retval = ext4_htree_next_block(dir, hash, frame, | 1012 | retval = ext4_htree_next_block(dir, hash, frame, |
1008 | frames, NULL); | 1013 | frames, NULL); |
1009 | if (retval < 0) { | 1014 | if (retval < 0) { |
1010 | ext4_warning(sb, __FUNCTION__, | 1015 | ext4_warning(sb, __func__, |
1011 | "error reading index page in directory #%lu", | 1016 | "error reading index page in directory #%lu", |
1012 | dir->i_ino); | 1017 | dir->i_ino); |
1013 | *err = retval; | 1018 | *err = retval; |
@@ -1532,7 +1537,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry, | |||
1532 | 1537 | ||
1533 | if (levels && (dx_get_count(frames->entries) == | 1538 | if (levels && (dx_get_count(frames->entries) == |
1534 | dx_get_limit(frames->entries))) { | 1539 | dx_get_limit(frames->entries))) { |
1535 | ext4_warning(sb, __FUNCTION__, | 1540 | ext4_warning(sb, __func__, |
1536 | "Directory index full!"); | 1541 | "Directory index full!"); |
1537 | err = -ENOSPC; | 1542 | err = -ENOSPC; |
1538 | goto cleanup; | 1543 | goto cleanup; |
@@ -1860,11 +1865,11 @@ static int empty_dir (struct inode * inode) | |||
1860 | if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) || | 1865 | if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) || |
1861 | !(bh = ext4_bread (NULL, inode, 0, 0, &err))) { | 1866 | !(bh = ext4_bread (NULL, inode, 0, 0, &err))) { |
1862 | if (err) | 1867 | if (err) |
1863 | ext4_error(inode->i_sb, __FUNCTION__, | 1868 | ext4_error(inode->i_sb, __func__, |
1864 | "error %d reading directory #%lu offset 0", | 1869 | "error %d reading directory #%lu offset 0", |
1865 | err, inode->i_ino); | 1870 | err, inode->i_ino); |
1866 | else | 1871 | else |
1867 | ext4_warning(inode->i_sb, __FUNCTION__, | 1872 | ext4_warning(inode->i_sb, __func__, |
1868 | "bad directory (dir #%lu) - no data block", | 1873 | "bad directory (dir #%lu) - no data block", |
1869 | inode->i_ino); | 1874 | inode->i_ino); |
1870 | return 1; | 1875 | return 1; |
@@ -1893,7 +1898,7 @@ static int empty_dir (struct inode * inode) | |||
1893 | offset >> EXT4_BLOCK_SIZE_BITS(sb), 0, &err); | 1898 | offset >> EXT4_BLOCK_SIZE_BITS(sb), 0, &err); |
1894 | if (!bh) { | 1899 | if (!bh) { |
1895 | if (err) | 1900 | if (err) |
1896 | ext4_error(sb, __FUNCTION__, | 1901 | ext4_error(sb, __func__, |
1897 | "error %d reading directory" | 1902 | "error %d reading directory" |
1898 | " #%lu offset %lu", | 1903 | " #%lu offset %lu", |
1899 | err, inode->i_ino, offset); | 1904 | err, inode->i_ino, offset); |
@@ -2217,6 +2222,8 @@ retry: | |||
2217 | goto out_stop; | 2222 | goto out_stop; |
2218 | } | 2223 | } |
2219 | } else { | 2224 | } else { |
2225 | /* clear the extent format for fast symlink */ | ||
2226 | EXT4_I(inode)->i_flags &= ~EXT4_EXTENTS_FL; | ||
2220 | inode->i_op = &ext4_fast_symlink_inode_operations; | 2227 | inode->i_op = &ext4_fast_symlink_inode_operations; |
2221 | memcpy((char*)&EXT4_I(inode)->i_data,symname,l); | 2228 | memcpy((char*)&EXT4_I(inode)->i_data,symname,l); |
2222 | inode->i_size = l-1; | 2229 | inode->i_size = l-1; |
@@ -2347,6 +2354,9 @@ static int ext4_rename (struct inode * old_dir, struct dentry *old_dentry, | |||
2347 | EXT4_FEATURE_INCOMPAT_FILETYPE)) | 2354 | EXT4_FEATURE_INCOMPAT_FILETYPE)) |
2348 | new_de->file_type = old_de->file_type; | 2355 | new_de->file_type = old_de->file_type; |
2349 | new_dir->i_version++; | 2356 | new_dir->i_version++; |
2357 | new_dir->i_ctime = new_dir->i_mtime = | ||
2358 | ext4_current_time(new_dir); | ||
2359 | ext4_mark_inode_dirty(handle, new_dir); | ||
2350 | BUFFER_TRACE(new_bh, "call ext4_journal_dirty_metadata"); | 2360 | BUFFER_TRACE(new_bh, "call ext4_journal_dirty_metadata"); |
2351 | ext4_journal_dirty_metadata(handle, new_bh); | 2361 | ext4_journal_dirty_metadata(handle, new_bh); |
2352 | brelse(new_bh); | 2362 | brelse(new_bh); |
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index e29efa0f9d62..9f086a6a472b 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c | |||
@@ -11,11 +11,10 @@ | |||
11 | 11 | ||
12 | #define EXT4FS_DEBUG | 12 | #define EXT4FS_DEBUG |
13 | 13 | ||
14 | #include <linux/ext4_jbd2.h> | ||
15 | |||
16 | #include <linux/errno.h> | 14 | #include <linux/errno.h> |
17 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
18 | 16 | ||
17 | #include "ext4_jbd2.h" | ||
19 | #include "group.h" | 18 | #include "group.h" |
20 | 19 | ||
21 | #define outside(b, first, last) ((b) < (first) || (b) >= (last)) | 20 | #define outside(b, first, last) ((b) < (first) || (b) >= (last)) |
@@ -50,63 +49,63 @@ static int verify_group_input(struct super_block *sb, | |||
50 | 49 | ||
51 | ext4_get_group_no_and_offset(sb, start, NULL, &offset); | 50 | ext4_get_group_no_and_offset(sb, start, NULL, &offset); |
52 | if (group != sbi->s_groups_count) | 51 | if (group != sbi->s_groups_count) |
53 | ext4_warning(sb, __FUNCTION__, | 52 | ext4_warning(sb, __func__, |
54 | "Cannot add at group %u (only %lu groups)", | 53 | "Cannot add at group %u (only %lu groups)", |
55 | input->group, sbi->s_groups_count); | 54 | input->group, sbi->s_groups_count); |
56 | else if (offset != 0) | 55 | else if (offset != 0) |
57 | ext4_warning(sb, __FUNCTION__, "Last group not full"); | 56 | ext4_warning(sb, __func__, "Last group not full"); |
58 | else if (input->reserved_blocks > input->blocks_count / 5) | 57 | else if (input->reserved_blocks > input->blocks_count / 5) |
59 | ext4_warning(sb, __FUNCTION__, "Reserved blocks too high (%u)", | 58 | ext4_warning(sb, __func__, "Reserved blocks too high (%u)", |
60 | input->reserved_blocks); | 59 | input->reserved_blocks); |
61 | else if (free_blocks_count < 0) | 60 | else if (free_blocks_count < 0) |
62 | ext4_warning(sb, __FUNCTION__, "Bad blocks count %u", | 61 | ext4_warning(sb, __func__, "Bad blocks count %u", |
63 | input->blocks_count); | 62 | input->blocks_count); |
64 | else if (!(bh = sb_bread(sb, end - 1))) | 63 | else if (!(bh = sb_bread(sb, end - 1))) |
65 | ext4_warning(sb, __FUNCTION__, | 64 | ext4_warning(sb, __func__, |
66 | "Cannot read last block (%llu)", | 65 | "Cannot read last block (%llu)", |
67 | end - 1); | 66 | end - 1); |
68 | else if (outside(input->block_bitmap, start, end)) | 67 | else if (outside(input->block_bitmap, start, end)) |
69 | ext4_warning(sb, __FUNCTION__, | 68 | ext4_warning(sb, __func__, |
70 | "Block bitmap not in group (block %llu)", | 69 | "Block bitmap not in group (block %llu)", |
71 | (unsigned long long)input->block_bitmap); | 70 | (unsigned long long)input->block_bitmap); |
72 | else if (outside(input->inode_bitmap, start, end)) | 71 | else if (outside(input->inode_bitmap, start, end)) |
73 | ext4_warning(sb, __FUNCTION__, | 72 | ext4_warning(sb, __func__, |
74 | "Inode bitmap not in group (block %llu)", | 73 | "Inode bitmap not in group (block %llu)", |
75 | (unsigned long long)input->inode_bitmap); | 74 | (unsigned long long)input->inode_bitmap); |
76 | else if (outside(input->inode_table, start, end) || | 75 | else if (outside(input->inode_table, start, end) || |
77 | outside(itend - 1, start, end)) | 76 | outside(itend - 1, start, end)) |
78 | ext4_warning(sb, __FUNCTION__, | 77 | ext4_warning(sb, __func__, |
79 | "Inode table not in group (blocks %llu-%llu)", | 78 | "Inode table not in group (blocks %llu-%llu)", |
80 | (unsigned long long)input->inode_table, itend - 1); | 79 | (unsigned long long)input->inode_table, itend - 1); |
81 | else if (input->inode_bitmap == input->block_bitmap) | 80 | else if (input->inode_bitmap == input->block_bitmap) |
82 | ext4_warning(sb, __FUNCTION__, | 81 | ext4_warning(sb, __func__, |
83 | "Block bitmap same as inode bitmap (%llu)", | 82 | "Block bitmap same as inode bitmap (%llu)", |
84 | (unsigned long long)input->block_bitmap); | 83 | (unsigned long long)input->block_bitmap); |
85 | else if (inside(input->block_bitmap, input->inode_table, itend)) | 84 | else if (inside(input->block_bitmap, input->inode_table, itend)) |
86 | ext4_warning(sb, __FUNCTION__, | 85 | ext4_warning(sb, __func__, |
87 | "Block bitmap (%llu) in inode table (%llu-%llu)", | 86 | "Block bitmap (%llu) in inode table (%llu-%llu)", |
88 | (unsigned long long)input->block_bitmap, | 87 | (unsigned long long)input->block_bitmap, |
89 | (unsigned long long)input->inode_table, itend - 1); | 88 | (unsigned long long)input->inode_table, itend - 1); |
90 | else if (inside(input->inode_bitmap, input->inode_table, itend)) | 89 | else if (inside(input->inode_bitmap, input->inode_table, itend)) |
91 | ext4_warning(sb, __FUNCTION__, | 90 | ext4_warning(sb, __func__, |
92 | "Inode bitmap (%llu) in inode table (%llu-%llu)", | 91 | "Inode bitmap (%llu) in inode table (%llu-%llu)", |
93 | (unsigned long long)input->inode_bitmap, | 92 | (unsigned long long)input->inode_bitmap, |
94 | (unsigned long long)input->inode_table, itend - 1); | 93 | (unsigned long long)input->inode_table, itend - 1); |
95 | else if (inside(input->block_bitmap, start, metaend)) | 94 | else if (inside(input->block_bitmap, start, metaend)) |
96 | ext4_warning(sb, __FUNCTION__, | 95 | ext4_warning(sb, __func__, |
97 | "Block bitmap (%llu) in GDT table" | 96 | "Block bitmap (%llu) in GDT table" |
98 | " (%llu-%llu)", | 97 | " (%llu-%llu)", |
99 | (unsigned long long)input->block_bitmap, | 98 | (unsigned long long)input->block_bitmap, |
100 | start, metaend - 1); | 99 | start, metaend - 1); |
101 | else if (inside(input->inode_bitmap, start, metaend)) | 100 | else if (inside(input->inode_bitmap, start, metaend)) |
102 | ext4_warning(sb, __FUNCTION__, | 101 | ext4_warning(sb, __func__, |
103 | "Inode bitmap (%llu) in GDT table" | 102 | "Inode bitmap (%llu) in GDT table" |
104 | " (%llu-%llu)", | 103 | " (%llu-%llu)", |
105 | (unsigned long long)input->inode_bitmap, | 104 | (unsigned long long)input->inode_bitmap, |
106 | start, metaend - 1); | 105 | start, metaend - 1); |
107 | else if (inside(input->inode_table, start, metaend) || | 106 | else if (inside(input->inode_table, start, metaend) || |
108 | inside(itend - 1, start, metaend)) | 107 | inside(itend - 1, start, metaend)) |
109 | ext4_warning(sb, __FUNCTION__, | 108 | ext4_warning(sb, __func__, |
110 | "Inode table (%llu-%llu) overlaps" | 109 | "Inode table (%llu-%llu) overlaps" |
111 | "GDT table (%llu-%llu)", | 110 | "GDT table (%llu-%llu)", |
112 | (unsigned long long)input->inode_table, | 111 | (unsigned long long)input->inode_table, |
@@ -368,7 +367,7 @@ static int verify_reserved_gdb(struct super_block *sb, | |||
368 | while ((grp = ext4_list_backups(sb, &three, &five, &seven)) < end) { | 367 | while ((grp = ext4_list_backups(sb, &three, &five, &seven)) < end) { |
369 | if (le32_to_cpu(*p++) != | 368 | if (le32_to_cpu(*p++) != |
370 | grp * EXT4_BLOCKS_PER_GROUP(sb) + blk){ | 369 | grp * EXT4_BLOCKS_PER_GROUP(sb) + blk){ |
371 | ext4_warning(sb, __FUNCTION__, | 370 | ext4_warning(sb, __func__, |
372 | "reserved GDT %llu" | 371 | "reserved GDT %llu" |
373 | " missing grp %d (%llu)", | 372 | " missing grp %d (%llu)", |
374 | blk, grp, | 373 | blk, grp, |
@@ -424,7 +423,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, | |||
424 | */ | 423 | */ |
425 | if (EXT4_SB(sb)->s_sbh->b_blocknr != | 424 | if (EXT4_SB(sb)->s_sbh->b_blocknr != |
426 | le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) { | 425 | le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) { |
427 | ext4_warning(sb, __FUNCTION__, | 426 | ext4_warning(sb, __func__, |
428 | "won't resize using backup superblock at %llu", | 427 | "won't resize using backup superblock at %llu", |
429 | (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr); | 428 | (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr); |
430 | return -EPERM; | 429 | return -EPERM; |
@@ -448,7 +447,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, | |||
448 | 447 | ||
449 | data = (__le32 *)dind->b_data; | 448 | data = (__le32 *)dind->b_data; |
450 | if (le32_to_cpu(data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)]) != gdblock) { | 449 | if (le32_to_cpu(data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)]) != gdblock) { |
451 | ext4_warning(sb, __FUNCTION__, | 450 | ext4_warning(sb, __func__, |
452 | "new group %u GDT block %llu not reserved", | 451 | "new group %u GDT block %llu not reserved", |
453 | input->group, gdblock); | 452 | input->group, gdblock); |
454 | err = -EINVAL; | 453 | err = -EINVAL; |
@@ -469,10 +468,10 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, | |||
469 | goto exit_dindj; | 468 | goto exit_dindj; |
470 | 469 | ||
471 | n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *), | 470 | n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *), |
472 | GFP_KERNEL); | 471 | GFP_NOFS); |
473 | if (!n_group_desc) { | 472 | if (!n_group_desc) { |
474 | err = -ENOMEM; | 473 | err = -ENOMEM; |
475 | ext4_warning (sb, __FUNCTION__, | 474 | ext4_warning(sb, __func__, |
476 | "not enough memory for %lu groups", gdb_num + 1); | 475 | "not enough memory for %lu groups", gdb_num + 1); |
477 | goto exit_inode; | 476 | goto exit_inode; |
478 | } | 477 | } |
@@ -502,8 +501,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, | |||
502 | EXT4_SB(sb)->s_gdb_count++; | 501 | EXT4_SB(sb)->s_gdb_count++; |
503 | kfree(o_group_desc); | 502 | kfree(o_group_desc); |
504 | 503 | ||
505 | es->s_reserved_gdt_blocks = | 504 | le16_add_cpu(&es->s_reserved_gdt_blocks, -1); |
506 | cpu_to_le16(le16_to_cpu(es->s_reserved_gdt_blocks) - 1); | ||
507 | ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh); | 505 | ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh); |
508 | 506 | ||
509 | return 0; | 507 | return 0; |
@@ -553,7 +551,7 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode, | |||
553 | int res, i; | 551 | int res, i; |
554 | int err; | 552 | int err; |
555 | 553 | ||
556 | primary = kmalloc(reserved_gdb * sizeof(*primary), GFP_KERNEL); | 554 | primary = kmalloc(reserved_gdb * sizeof(*primary), GFP_NOFS); |
557 | if (!primary) | 555 | if (!primary) |
558 | return -ENOMEM; | 556 | return -ENOMEM; |
559 | 557 | ||
@@ -571,7 +569,7 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode, | |||
571 | /* Get each reserved primary GDT block and verify it holds backups */ | 569 | /* Get each reserved primary GDT block and verify it holds backups */ |
572 | for (res = 0; res < reserved_gdb; res++, blk++) { | 570 | for (res = 0; res < reserved_gdb; res++, blk++) { |
573 | if (le32_to_cpu(*data) != blk) { | 571 | if (le32_to_cpu(*data) != blk) { |
574 | ext4_warning(sb, __FUNCTION__, | 572 | ext4_warning(sb, __func__, |
575 | "reserved block %llu" | 573 | "reserved block %llu" |
576 | " not at offset %ld", | 574 | " not at offset %ld", |
577 | blk, | 575 | blk, |
@@ -715,7 +713,7 @@ static void update_backups(struct super_block *sb, | |||
715 | */ | 713 | */ |
716 | exit_err: | 714 | exit_err: |
717 | if (err) { | 715 | if (err) { |
718 | ext4_warning(sb, __FUNCTION__, | 716 | ext4_warning(sb, __func__, |
719 | "can't update backup for group %lu (err %d), " | 717 | "can't update backup for group %lu (err %d), " |
720 | "forcing fsck on next reboot", group, err); | 718 | "forcing fsck on next reboot", group, err); |
721 | sbi->s_mount_state &= ~EXT4_VALID_FS; | 719 | sbi->s_mount_state &= ~EXT4_VALID_FS; |
@@ -755,33 +753,33 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input) | |||
755 | 753 | ||
756 | if (gdb_off == 0 && !EXT4_HAS_RO_COMPAT_FEATURE(sb, | 754 | if (gdb_off == 0 && !EXT4_HAS_RO_COMPAT_FEATURE(sb, |
757 | EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) { | 755 | EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) { |
758 | ext4_warning(sb, __FUNCTION__, | 756 | ext4_warning(sb, __func__, |
759 | "Can't resize non-sparse filesystem further"); | 757 | "Can't resize non-sparse filesystem further"); |
760 | return -EPERM; | 758 | return -EPERM; |
761 | } | 759 | } |
762 | 760 | ||
763 | if (ext4_blocks_count(es) + input->blocks_count < | 761 | if (ext4_blocks_count(es) + input->blocks_count < |
764 | ext4_blocks_count(es)) { | 762 | ext4_blocks_count(es)) { |
765 | ext4_warning(sb, __FUNCTION__, "blocks_count overflow\n"); | 763 | ext4_warning(sb, __func__, "blocks_count overflow\n"); |
766 | return -EINVAL; | 764 | return -EINVAL; |
767 | } | 765 | } |
768 | 766 | ||
769 | if (le32_to_cpu(es->s_inodes_count) + EXT4_INODES_PER_GROUP(sb) < | 767 | if (le32_to_cpu(es->s_inodes_count) + EXT4_INODES_PER_GROUP(sb) < |
770 | le32_to_cpu(es->s_inodes_count)) { | 768 | le32_to_cpu(es->s_inodes_count)) { |
771 | ext4_warning(sb, __FUNCTION__, "inodes_count overflow\n"); | 769 | ext4_warning(sb, __func__, "inodes_count overflow\n"); |
772 | return -EINVAL; | 770 | return -EINVAL; |
773 | } | 771 | } |
774 | 772 | ||
775 | if (reserved_gdb || gdb_off == 0) { | 773 | if (reserved_gdb || gdb_off == 0) { |
776 | if (!EXT4_HAS_COMPAT_FEATURE(sb, | 774 | if (!EXT4_HAS_COMPAT_FEATURE(sb, |
777 | EXT4_FEATURE_COMPAT_RESIZE_INODE)){ | 775 | EXT4_FEATURE_COMPAT_RESIZE_INODE)){ |
778 | ext4_warning(sb, __FUNCTION__, | 776 | ext4_warning(sb, __func__, |
779 | "No reserved GDT blocks, can't resize"); | 777 | "No reserved GDT blocks, can't resize"); |
780 | return -EPERM; | 778 | return -EPERM; |
781 | } | 779 | } |
782 | inode = ext4_iget(sb, EXT4_RESIZE_INO); | 780 | inode = ext4_iget(sb, EXT4_RESIZE_INO); |
783 | if (IS_ERR(inode)) { | 781 | if (IS_ERR(inode)) { |
784 | ext4_warning(sb, __FUNCTION__, | 782 | ext4_warning(sb, __func__, |
785 | "Error opening resize inode"); | 783 | "Error opening resize inode"); |
786 | return PTR_ERR(inode); | 784 | return PTR_ERR(inode); |
787 | } | 785 | } |
@@ -810,7 +808,7 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input) | |||
810 | 808 | ||
811 | lock_super(sb); | 809 | lock_super(sb); |
812 | if (input->group != sbi->s_groups_count) { | 810 | if (input->group != sbi->s_groups_count) { |
813 | ext4_warning(sb, __FUNCTION__, | 811 | ext4_warning(sb, __func__, |
814 | "multiple resizers run on filesystem!"); | 812 | "multiple resizers run on filesystem!"); |
815 | err = -EBUSY; | 813 | err = -EBUSY; |
816 | goto exit_journal; | 814 | goto exit_journal; |
@@ -877,8 +875,7 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input) | |||
877 | */ | 875 | */ |
878 | ext4_blocks_count_set(es, ext4_blocks_count(es) + | 876 | ext4_blocks_count_set(es, ext4_blocks_count(es) + |
879 | input->blocks_count); | 877 | input->blocks_count); |
880 | es->s_inodes_count = cpu_to_le32(le32_to_cpu(es->s_inodes_count) + | 878 | le32_add_cpu(&es->s_inodes_count, EXT4_INODES_PER_GROUP(sb)); |
881 | EXT4_INODES_PER_GROUP(sb)); | ||
882 | 879 | ||
883 | /* | 880 | /* |
884 | * We need to protect s_groups_count against other CPUs seeing | 881 | * We need to protect s_groups_count against other CPUs seeing |
@@ -977,13 +974,13 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, | |||
977 | " too large to resize to %llu blocks safely\n", | 974 | " too large to resize to %llu blocks safely\n", |
978 | sb->s_id, n_blocks_count); | 975 | sb->s_id, n_blocks_count); |
979 | if (sizeof(sector_t) < 8) | 976 | if (sizeof(sector_t) < 8) |
980 | ext4_warning(sb, __FUNCTION__, | 977 | ext4_warning(sb, __func__, |
981 | "CONFIG_LBD not enabled\n"); | 978 | "CONFIG_LBD not enabled\n"); |
982 | return -EINVAL; | 979 | return -EINVAL; |
983 | } | 980 | } |
984 | 981 | ||
985 | if (n_blocks_count < o_blocks_count) { | 982 | if (n_blocks_count < o_blocks_count) { |
986 | ext4_warning(sb, __FUNCTION__, | 983 | ext4_warning(sb, __func__, |
987 | "can't shrink FS - resize aborted"); | 984 | "can't shrink FS - resize aborted"); |
988 | return -EBUSY; | 985 | return -EBUSY; |
989 | } | 986 | } |
@@ -992,7 +989,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, | |||
992 | ext4_get_group_no_and_offset(sb, o_blocks_count, NULL, &last); | 989 | ext4_get_group_no_and_offset(sb, o_blocks_count, NULL, &last); |
993 | 990 | ||
994 | if (last == 0) { | 991 | if (last == 0) { |
995 | ext4_warning(sb, __FUNCTION__, | 992 | ext4_warning(sb, __func__, |
996 | "need to use ext2online to resize further"); | 993 | "need to use ext2online to resize further"); |
997 | return -EPERM; | 994 | return -EPERM; |
998 | } | 995 | } |
@@ -1000,7 +997,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, | |||
1000 | add = EXT4_BLOCKS_PER_GROUP(sb) - last; | 997 | add = EXT4_BLOCKS_PER_GROUP(sb) - last; |
1001 | 998 | ||
1002 | if (o_blocks_count + add < o_blocks_count) { | 999 | if (o_blocks_count + add < o_blocks_count) { |
1003 | ext4_warning(sb, __FUNCTION__, "blocks_count overflow"); | 1000 | ext4_warning(sb, __func__, "blocks_count overflow"); |
1004 | return -EINVAL; | 1001 | return -EINVAL; |
1005 | } | 1002 | } |
1006 | 1003 | ||
@@ -1008,7 +1005,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, | |||
1008 | add = n_blocks_count - o_blocks_count; | 1005 | add = n_blocks_count - o_blocks_count; |
1009 | 1006 | ||
1010 | if (o_blocks_count + add < n_blocks_count) | 1007 | if (o_blocks_count + add < n_blocks_count) |
1011 | ext4_warning(sb, __FUNCTION__, | 1008 | ext4_warning(sb, __func__, |
1012 | "will only finish group (%llu" | 1009 | "will only finish group (%llu" |
1013 | " blocks, %u new)", | 1010 | " blocks, %u new)", |
1014 | o_blocks_count + add, add); | 1011 | o_blocks_count + add, add); |
@@ -1016,7 +1013,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, | |||
1016 | /* See if the device is actually as big as what was requested */ | 1013 | /* See if the device is actually as big as what was requested */ |
1017 | bh = sb_bread(sb, o_blocks_count + add -1); | 1014 | bh = sb_bread(sb, o_blocks_count + add -1); |
1018 | if (!bh) { | 1015 | if (!bh) { |
1019 | ext4_warning(sb, __FUNCTION__, | 1016 | ext4_warning(sb, __func__, |
1020 | "can't read last block, resize aborted"); | 1017 | "can't read last block, resize aborted"); |
1021 | return -ENOSPC; | 1018 | return -ENOSPC; |
1022 | } | 1019 | } |
@@ -1028,13 +1025,13 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, | |||
1028 | handle = ext4_journal_start_sb(sb, 3); | 1025 | handle = ext4_journal_start_sb(sb, 3); |
1029 | if (IS_ERR(handle)) { | 1026 | if (IS_ERR(handle)) { |
1030 | err = PTR_ERR(handle); | 1027 | err = PTR_ERR(handle); |
1031 | ext4_warning(sb, __FUNCTION__, "error %d on journal start",err); | 1028 | ext4_warning(sb, __func__, "error %d on journal start", err); |
1032 | goto exit_put; | 1029 | goto exit_put; |
1033 | } | 1030 | } |
1034 | 1031 | ||
1035 | lock_super(sb); | 1032 | lock_super(sb); |
1036 | if (o_blocks_count != ext4_blocks_count(es)) { | 1033 | if (o_blocks_count != ext4_blocks_count(es)) { |
1037 | ext4_warning(sb, __FUNCTION__, | 1034 | ext4_warning(sb, __func__, |
1038 | "multiple resizers run on filesystem!"); | 1035 | "multiple resizers run on filesystem!"); |
1039 | unlock_super(sb); | 1036 | unlock_super(sb); |
1040 | ext4_journal_stop(handle); | 1037 | ext4_journal_stop(handle); |
@@ -1044,7 +1041,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, | |||
1044 | 1041 | ||
1045 | if ((err = ext4_journal_get_write_access(handle, | 1042 | if ((err = ext4_journal_get_write_access(handle, |
1046 | EXT4_SB(sb)->s_sbh))) { | 1043 | EXT4_SB(sb)->s_sbh))) { |
1047 | ext4_warning(sb, __FUNCTION__, | 1044 | ext4_warning(sb, __func__, |
1048 | "error %d on journal write access", err); | 1045 | "error %d on journal write access", err); |
1049 | unlock_super(sb); | 1046 | unlock_super(sb); |
1050 | ext4_journal_stop(handle); | 1047 | ext4_journal_stop(handle); |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index c81a8e759bad..52dd0679a4e2 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -21,8 +21,6 @@ | |||
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/ext4_fs.h> | ||
25 | #include <linux/ext4_jbd2.h> | ||
26 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
27 | #include <linux/init.h> | 25 | #include <linux/init.h> |
28 | #include <linux/blkdev.h> | 26 | #include <linux/blkdev.h> |
@@ -38,9 +36,10 @@ | |||
38 | #include <linux/seq_file.h> | 36 | #include <linux/seq_file.h> |
39 | #include <linux/log2.h> | 37 | #include <linux/log2.h> |
40 | #include <linux/crc16.h> | 38 | #include <linux/crc16.h> |
41 | |||
42 | #include <asm/uaccess.h> | 39 | #include <asm/uaccess.h> |
43 | 40 | ||
41 | #include "ext4.h" | ||
42 | #include "ext4_jbd2.h" | ||
44 | #include "xattr.h" | 43 | #include "xattr.h" |
45 | #include "acl.h" | 44 | #include "acl.h" |
46 | #include "namei.h" | 45 | #include "namei.h" |
@@ -135,7 +134,7 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks) | |||
135 | * take the FS itself readonly cleanly. */ | 134 | * take the FS itself readonly cleanly. */ |
136 | journal = EXT4_SB(sb)->s_journal; | 135 | journal = EXT4_SB(sb)->s_journal; |
137 | if (is_journal_aborted(journal)) { | 136 | if (is_journal_aborted(journal)) { |
138 | ext4_abort(sb, __FUNCTION__, | 137 | ext4_abort(sb, __func__, |
139 | "Detected aborted journal"); | 138 | "Detected aborted journal"); |
140 | return ERR_PTR(-EROFS); | 139 | return ERR_PTR(-EROFS); |
141 | } | 140 | } |
@@ -355,7 +354,7 @@ void ext4_update_dynamic_rev(struct super_block *sb) | |||
355 | if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV) | 354 | if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV) |
356 | return; | 355 | return; |
357 | 356 | ||
358 | ext4_warning(sb, __FUNCTION__, | 357 | ext4_warning(sb, __func__, |
359 | "updating to rev %d because of new feature flag, " | 358 | "updating to rev %d because of new feature flag, " |
360 | "running e2fsck is recommended", | 359 | "running e2fsck is recommended", |
361 | EXT4_DYNAMIC_REV); | 360 | EXT4_DYNAMIC_REV); |
@@ -945,8 +944,8 @@ static match_table_t tokens = { | |||
945 | {Opt_mballoc, "mballoc"}, | 944 | {Opt_mballoc, "mballoc"}, |
946 | {Opt_nomballoc, "nomballoc"}, | 945 | {Opt_nomballoc, "nomballoc"}, |
947 | {Opt_stripe, "stripe=%u"}, | 946 | {Opt_stripe, "stripe=%u"}, |
948 | {Opt_err, NULL}, | ||
949 | {Opt_resize, "resize"}, | 947 | {Opt_resize, "resize"}, |
948 | {Opt_err, NULL}, | ||
950 | }; | 949 | }; |
951 | 950 | ||
952 | static ext4_fsblk_t get_sb_block(void **data) | 951 | static ext4_fsblk_t get_sb_block(void **data) |
@@ -1388,11 +1387,11 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, | |||
1388 | * a plain journaled filesystem we can keep it set as | 1387 | * a plain journaled filesystem we can keep it set as |
1389 | * valid forever! :) | 1388 | * valid forever! :) |
1390 | */ | 1389 | */ |
1391 | es->s_state = cpu_to_le16(le16_to_cpu(es->s_state) & ~EXT4_VALID_FS); | 1390 | es->s_state &= cpu_to_le16(~EXT4_VALID_FS); |
1392 | #endif | 1391 | #endif |
1393 | if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) | 1392 | if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) |
1394 | es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); | 1393 | es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); |
1395 | es->s_mnt_count=cpu_to_le16(le16_to_cpu(es->s_mnt_count) + 1); | 1394 | le16_add_cpu(&es->s_mnt_count, 1); |
1396 | es->s_mtime = cpu_to_le32(get_seconds()); | 1395 | es->s_mtime = cpu_to_le32(get_seconds()); |
1397 | ext4_update_dynamic_rev(sb); | 1396 | ext4_update_dynamic_rev(sb); |
1398 | EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); | 1397 | EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); |
@@ -1485,36 +1484,33 @@ static int ext4_check_descriptors(struct super_block *sb) | |||
1485 | block_bitmap = ext4_block_bitmap(sb, gdp); | 1484 | block_bitmap = ext4_block_bitmap(sb, gdp); |
1486 | if (block_bitmap < first_block || block_bitmap > last_block) | 1485 | if (block_bitmap < first_block || block_bitmap > last_block) |
1487 | { | 1486 | { |
1488 | ext4_error (sb, "ext4_check_descriptors", | 1487 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
1489 | "Block bitmap for group %lu" | 1488 | "Block bitmap for group %lu not in group " |
1490 | " not in group (block %llu)!", | 1489 | "(block %llu)!", i, block_bitmap); |
1491 | i, block_bitmap); | ||
1492 | return 0; | 1490 | return 0; |
1493 | } | 1491 | } |
1494 | inode_bitmap = ext4_inode_bitmap(sb, gdp); | 1492 | inode_bitmap = ext4_inode_bitmap(sb, gdp); |
1495 | if (inode_bitmap < first_block || inode_bitmap > last_block) | 1493 | if (inode_bitmap < first_block || inode_bitmap > last_block) |
1496 | { | 1494 | { |
1497 | ext4_error (sb, "ext4_check_descriptors", | 1495 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
1498 | "Inode bitmap for group %lu" | 1496 | "Inode bitmap for group %lu not in group " |
1499 | " not in group (block %llu)!", | 1497 | "(block %llu)!", i, inode_bitmap); |
1500 | i, inode_bitmap); | ||
1501 | return 0; | 1498 | return 0; |
1502 | } | 1499 | } |
1503 | inode_table = ext4_inode_table(sb, gdp); | 1500 | inode_table = ext4_inode_table(sb, gdp); |
1504 | if (inode_table < first_block || | 1501 | if (inode_table < first_block || |
1505 | inode_table + sbi->s_itb_per_group - 1 > last_block) | 1502 | inode_table + sbi->s_itb_per_group - 1 > last_block) |
1506 | { | 1503 | { |
1507 | ext4_error (sb, "ext4_check_descriptors", | 1504 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
1508 | "Inode table for group %lu" | 1505 | "Inode table for group %lu not in group " |
1509 | " not in group (block %llu)!", | 1506 | "(block %llu)!", i, inode_table); |
1510 | i, inode_table); | ||
1511 | return 0; | 1507 | return 0; |
1512 | } | 1508 | } |
1513 | if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { | 1509 | if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { |
1514 | ext4_error(sb, __FUNCTION__, | 1510 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
1515 | "Checksum for group %lu failed (%u!=%u)\n", | 1511 | "Checksum for group %lu failed (%u!=%u)\n", |
1516 | i, le16_to_cpu(ext4_group_desc_csum(sbi, i, | 1512 | i, le16_to_cpu(ext4_group_desc_csum(sbi, i, |
1517 | gdp)), le16_to_cpu(gdp->bg_checksum)); | 1513 | gdp)), le16_to_cpu(gdp->bg_checksum)); |
1518 | return 0; | 1514 | return 0; |
1519 | } | 1515 | } |
1520 | if (!flexbg_flag) | 1516 | if (!flexbg_flag) |
@@ -1594,8 +1590,8 @@ static void ext4_orphan_cleanup (struct super_block * sb, | |||
1594 | while (es->s_last_orphan) { | 1590 | while (es->s_last_orphan) { |
1595 | struct inode *inode; | 1591 | struct inode *inode; |
1596 | 1592 | ||
1597 | if (!(inode = | 1593 | inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan)); |
1598 | ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan)))) { | 1594 | if (IS_ERR(inode)) { |
1599 | es->s_last_orphan = 0; | 1595 | es->s_last_orphan = 0; |
1600 | break; | 1596 | break; |
1601 | } | 1597 | } |
@@ -1605,7 +1601,7 @@ static void ext4_orphan_cleanup (struct super_block * sb, | |||
1605 | if (inode->i_nlink) { | 1601 | if (inode->i_nlink) { |
1606 | printk(KERN_DEBUG | 1602 | printk(KERN_DEBUG |
1607 | "%s: truncating inode %lu to %Ld bytes\n", | 1603 | "%s: truncating inode %lu to %Ld bytes\n", |
1608 | __FUNCTION__, inode->i_ino, inode->i_size); | 1604 | __func__, inode->i_ino, inode->i_size); |
1609 | jbd_debug(2, "truncating inode %lu to %Ld bytes\n", | 1605 | jbd_debug(2, "truncating inode %lu to %Ld bytes\n", |
1610 | inode->i_ino, inode->i_size); | 1606 | inode->i_ino, inode->i_size); |
1611 | ext4_truncate(inode); | 1607 | ext4_truncate(inode); |
@@ -1613,7 +1609,7 @@ static void ext4_orphan_cleanup (struct super_block * sb, | |||
1613 | } else { | 1609 | } else { |
1614 | printk(KERN_DEBUG | 1610 | printk(KERN_DEBUG |
1615 | "%s: deleting unreferenced inode %lu\n", | 1611 | "%s: deleting unreferenced inode %lu\n", |
1616 | __FUNCTION__, inode->i_ino); | 1612 | __func__, inode->i_ino); |
1617 | jbd_debug(2, "deleting unreferenced inode %lu\n", | 1613 | jbd_debug(2, "deleting unreferenced inode %lu\n", |
1618 | inode->i_ino); | 1614 | inode->i_ino); |
1619 | nr_orphans++; | 1615 | nr_orphans++; |
@@ -2699,9 +2695,9 @@ static void ext4_clear_journal_err(struct super_block * sb, | |||
2699 | char nbuf[16]; | 2695 | char nbuf[16]; |
2700 | 2696 | ||
2701 | errstr = ext4_decode_error(sb, j_errno, nbuf); | 2697 | errstr = ext4_decode_error(sb, j_errno, nbuf); |
2702 | ext4_warning(sb, __FUNCTION__, "Filesystem error recorded " | 2698 | ext4_warning(sb, __func__, "Filesystem error recorded " |
2703 | "from previous mount: %s", errstr); | 2699 | "from previous mount: %s", errstr); |
2704 | ext4_warning(sb, __FUNCTION__, "Marking fs in need of " | 2700 | ext4_warning(sb, __func__, "Marking fs in need of " |
2705 | "filesystem check."); | 2701 | "filesystem check."); |
2706 | 2702 | ||
2707 | EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; | 2703 | EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; |
@@ -2828,7 +2824,7 @@ static int ext4_remount (struct super_block * sb, int * flags, char * data) | |||
2828 | } | 2824 | } |
2829 | 2825 | ||
2830 | if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) | 2826 | if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) |
2831 | ext4_abort(sb, __FUNCTION__, "Abort forced by user"); | 2827 | ext4_abort(sb, __func__, "Abort forced by user"); |
2832 | 2828 | ||
2833 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | | 2829 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | |
2834 | ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); | 2830 | ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); |
@@ -3040,8 +3036,14 @@ static int ext4_dquot_drop(struct inode *inode) | |||
3040 | 3036 | ||
3041 | /* We may delete quota structure so we need to reserve enough blocks */ | 3037 | /* We may delete quota structure so we need to reserve enough blocks */ |
3042 | handle = ext4_journal_start(inode, 2*EXT4_QUOTA_DEL_BLOCKS(inode->i_sb)); | 3038 | handle = ext4_journal_start(inode, 2*EXT4_QUOTA_DEL_BLOCKS(inode->i_sb)); |
3043 | if (IS_ERR(handle)) | 3039 | if (IS_ERR(handle)) { |
3040 | /* | ||
3041 | * We call dquot_drop() anyway to at least release references | ||
3042 | * to quota structures so that umount does not hang. | ||
3043 | */ | ||
3044 | dquot_drop(inode); | ||
3044 | return PTR_ERR(handle); | 3045 | return PTR_ERR(handle); |
3046 | } | ||
3045 | ret = dquot_drop(inode); | 3047 | ret = dquot_drop(inode); |
3046 | err = ext4_journal_stop(handle); | 3048 | err = ext4_journal_stop(handle); |
3047 | if (!ret) | 3049 | if (!ret) |
diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c index e6f9da4287c4..e9178643dc01 100644 --- a/fs/ext4/symlink.c +++ b/fs/ext4/symlink.c | |||
@@ -19,8 +19,8 @@ | |||
19 | 19 | ||
20 | #include <linux/fs.h> | 20 | #include <linux/fs.h> |
21 | #include <linux/jbd2.h> | 21 | #include <linux/jbd2.h> |
22 | #include <linux/ext4_fs.h> | ||
23 | #include <linux/namei.h> | 22 | #include <linux/namei.h> |
23 | #include "ext4.h" | ||
24 | #include "xattr.h" | 24 | #include "xattr.h" |
25 | 25 | ||
26 | static void * ext4_follow_link(struct dentry *dentry, struct nameidata *nd) | 26 | static void * ext4_follow_link(struct dentry *dentry, struct nameidata *nd) |
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index e9054c1c7d93..3fbc2c6c3d0e 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c | |||
@@ -53,11 +53,11 @@ | |||
53 | #include <linux/init.h> | 53 | #include <linux/init.h> |
54 | #include <linux/fs.h> | 54 | #include <linux/fs.h> |
55 | #include <linux/slab.h> | 55 | #include <linux/slab.h> |
56 | #include <linux/ext4_jbd2.h> | ||
57 | #include <linux/ext4_fs.h> | ||
58 | #include <linux/mbcache.h> | 56 | #include <linux/mbcache.h> |
59 | #include <linux/quotaops.h> | 57 | #include <linux/quotaops.h> |
60 | #include <linux/rwsem.h> | 58 | #include <linux/rwsem.h> |
59 | #include "ext4_jbd2.h" | ||
60 | #include "ext4.h" | ||
61 | #include "xattr.h" | 61 | #include "xattr.h" |
62 | #include "acl.h" | 62 | #include "acl.h" |
63 | 63 | ||
@@ -92,6 +92,8 @@ static struct buffer_head *ext4_xattr_cache_find(struct inode *, | |||
92 | struct mb_cache_entry **); | 92 | struct mb_cache_entry **); |
93 | static void ext4_xattr_rehash(struct ext4_xattr_header *, | 93 | static void ext4_xattr_rehash(struct ext4_xattr_header *, |
94 | struct ext4_xattr_entry *); | 94 | struct ext4_xattr_entry *); |
95 | static int ext4_xattr_list(struct inode *inode, char *buffer, | ||
96 | size_t buffer_size); | ||
95 | 97 | ||
96 | static struct mb_cache *ext4_xattr_cache; | 98 | static struct mb_cache *ext4_xattr_cache; |
97 | 99 | ||
@@ -225,7 +227,7 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name, | |||
225 | ea_bdebug(bh, "b_count=%d, refcount=%d", | 227 | ea_bdebug(bh, "b_count=%d, refcount=%d", |
226 | atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); | 228 | atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); |
227 | if (ext4_xattr_check_block(bh)) { | 229 | if (ext4_xattr_check_block(bh)) { |
228 | bad_block: ext4_error(inode->i_sb, __FUNCTION__, | 230 | bad_block: ext4_error(inode->i_sb, __func__, |
229 | "inode %lu: bad block %llu", inode->i_ino, | 231 | "inode %lu: bad block %llu", inode->i_ino, |
230 | EXT4_I(inode)->i_file_acl); | 232 | EXT4_I(inode)->i_file_acl); |
231 | error = -EIO; | 233 | error = -EIO; |
@@ -367,7 +369,7 @@ ext4_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size) | |||
367 | ea_bdebug(bh, "b_count=%d, refcount=%d", | 369 | ea_bdebug(bh, "b_count=%d, refcount=%d", |
368 | atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); | 370 | atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); |
369 | if (ext4_xattr_check_block(bh)) { | 371 | if (ext4_xattr_check_block(bh)) { |
370 | ext4_error(inode->i_sb, __FUNCTION__, | 372 | ext4_error(inode->i_sb, __func__, |
371 | "inode %lu: bad block %llu", inode->i_ino, | 373 | "inode %lu: bad block %llu", inode->i_ino, |
372 | EXT4_I(inode)->i_file_acl); | 374 | EXT4_I(inode)->i_file_acl); |
373 | error = -EIO; | 375 | error = -EIO; |
@@ -420,7 +422,7 @@ cleanup: | |||
420 | * Returns a negative error number on failure, or the number of bytes | 422 | * Returns a negative error number on failure, or the number of bytes |
421 | * used / required on success. | 423 | * used / required on success. |
422 | */ | 424 | */ |
423 | int | 425 | static int |
424 | ext4_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) | 426 | ext4_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) |
425 | { | 427 | { |
426 | int i_error, b_error; | 428 | int i_error, b_error; |
@@ -484,8 +486,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode, | |||
484 | get_bh(bh); | 486 | get_bh(bh); |
485 | ext4_forget(handle, 1, inode, bh, bh->b_blocknr); | 487 | ext4_forget(handle, 1, inode, bh, bh->b_blocknr); |
486 | } else { | 488 | } else { |
487 | BHDR(bh)->h_refcount = cpu_to_le32( | 489 | le32_add_cpu(&BHDR(bh)->h_refcount, -1); |
488 | le32_to_cpu(BHDR(bh)->h_refcount) - 1); | ||
489 | error = ext4_journal_dirty_metadata(handle, bh); | 490 | error = ext4_journal_dirty_metadata(handle, bh); |
490 | if (IS_SYNC(inode)) | 491 | if (IS_SYNC(inode)) |
491 | handle->h_sync = 1; | 492 | handle->h_sync = 1; |
@@ -660,7 +661,7 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i, | |||
660 | atomic_read(&(bs->bh->b_count)), | 661 | atomic_read(&(bs->bh->b_count)), |
661 | le32_to_cpu(BHDR(bs->bh)->h_refcount)); | 662 | le32_to_cpu(BHDR(bs->bh)->h_refcount)); |
662 | if (ext4_xattr_check_block(bs->bh)) { | 663 | if (ext4_xattr_check_block(bs->bh)) { |
663 | ext4_error(sb, __FUNCTION__, | 664 | ext4_error(sb, __func__, |
664 | "inode %lu: bad block %llu", inode->i_ino, | 665 | "inode %lu: bad block %llu", inode->i_ino, |
665 | EXT4_I(inode)->i_file_acl); | 666 | EXT4_I(inode)->i_file_acl); |
666 | error = -EIO; | 667 | error = -EIO; |
@@ -738,7 +739,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, | |||
738 | ce = NULL; | 739 | ce = NULL; |
739 | } | 740 | } |
740 | ea_bdebug(bs->bh, "cloning"); | 741 | ea_bdebug(bs->bh, "cloning"); |
741 | s->base = kmalloc(bs->bh->b_size, GFP_KERNEL); | 742 | s->base = kmalloc(bs->bh->b_size, GFP_NOFS); |
742 | error = -ENOMEM; | 743 | error = -ENOMEM; |
743 | if (s->base == NULL) | 744 | if (s->base == NULL) |
744 | goto cleanup; | 745 | goto cleanup; |
@@ -750,7 +751,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, | |||
750 | } | 751 | } |
751 | } else { | 752 | } else { |
752 | /* Allocate a buffer where we construct the new block. */ | 753 | /* Allocate a buffer where we construct the new block. */ |
753 | s->base = kzalloc(sb->s_blocksize, GFP_KERNEL); | 754 | s->base = kzalloc(sb->s_blocksize, GFP_NOFS); |
754 | /* assert(header == s->base) */ | 755 | /* assert(header == s->base) */ |
755 | error = -ENOMEM; | 756 | error = -ENOMEM; |
756 | if (s->base == NULL) | 757 | if (s->base == NULL) |
@@ -789,8 +790,7 @@ inserted: | |||
789 | if (error) | 790 | if (error) |
790 | goto cleanup_dquot; | 791 | goto cleanup_dquot; |
791 | lock_buffer(new_bh); | 792 | lock_buffer(new_bh); |
792 | BHDR(new_bh)->h_refcount = cpu_to_le32(1 + | 793 | le32_add_cpu(&BHDR(new_bh)->h_refcount, 1); |
793 | le32_to_cpu(BHDR(new_bh)->h_refcount)); | ||
794 | ea_bdebug(new_bh, "reusing; refcount now=%d", | 794 | ea_bdebug(new_bh, "reusing; refcount now=%d", |
795 | le32_to_cpu(BHDR(new_bh)->h_refcount)); | 795 | le32_to_cpu(BHDR(new_bh)->h_refcount)); |
796 | unlock_buffer(new_bh); | 796 | unlock_buffer(new_bh); |
@@ -808,10 +808,8 @@ inserted: | |||
808 | get_bh(new_bh); | 808 | get_bh(new_bh); |
809 | } else { | 809 | } else { |
810 | /* We need to allocate a new block */ | 810 | /* We need to allocate a new block */ |
811 | ext4_fsblk_t goal = le32_to_cpu( | 811 | ext4_fsblk_t goal = ext4_group_first_block_no(sb, |
812 | EXT4_SB(sb)->s_es->s_first_data_block) + | 812 | EXT4_I(inode)->i_block_group); |
813 | (ext4_fsblk_t)EXT4_I(inode)->i_block_group * | ||
814 | EXT4_BLOCKS_PER_GROUP(sb); | ||
815 | ext4_fsblk_t block = ext4_new_block(handle, inode, | 813 | ext4_fsblk_t block = ext4_new_block(handle, inode, |
816 | goal, &error); | 814 | goal, &error); |
817 | if (error) | 815 | if (error) |
@@ -863,7 +861,7 @@ cleanup_dquot: | |||
863 | goto cleanup; | 861 | goto cleanup; |
864 | 862 | ||
865 | bad_block: | 863 | bad_block: |
866 | ext4_error(inode->i_sb, __FUNCTION__, | 864 | ext4_error(inode->i_sb, __func__, |
867 | "inode %lu: bad block %llu", inode->i_ino, | 865 | "inode %lu: bad block %llu", inode->i_ino, |
868 | EXT4_I(inode)->i_file_acl); | 866 | EXT4_I(inode)->i_file_acl); |
869 | goto cleanup; | 867 | goto cleanup; |
@@ -1166,7 +1164,7 @@ retry: | |||
1166 | if (!bh) | 1164 | if (!bh) |
1167 | goto cleanup; | 1165 | goto cleanup; |
1168 | if (ext4_xattr_check_block(bh)) { | 1166 | if (ext4_xattr_check_block(bh)) { |
1169 | ext4_error(inode->i_sb, __FUNCTION__, | 1167 | ext4_error(inode->i_sb, __func__, |
1170 | "inode %lu: bad block %llu", inode->i_ino, | 1168 | "inode %lu: bad block %llu", inode->i_ino, |
1171 | EXT4_I(inode)->i_file_acl); | 1169 | EXT4_I(inode)->i_file_acl); |
1172 | error = -EIO; | 1170 | error = -EIO; |
@@ -1341,14 +1339,14 @@ ext4_xattr_delete_inode(handle_t *handle, struct inode *inode) | |||
1341 | goto cleanup; | 1339 | goto cleanup; |
1342 | bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl); | 1340 | bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl); |
1343 | if (!bh) { | 1341 | if (!bh) { |
1344 | ext4_error(inode->i_sb, __FUNCTION__, | 1342 | ext4_error(inode->i_sb, __func__, |
1345 | "inode %lu: block %llu read error", inode->i_ino, | 1343 | "inode %lu: block %llu read error", inode->i_ino, |
1346 | EXT4_I(inode)->i_file_acl); | 1344 | EXT4_I(inode)->i_file_acl); |
1347 | goto cleanup; | 1345 | goto cleanup; |
1348 | } | 1346 | } |
1349 | if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) || | 1347 | if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) || |
1350 | BHDR(bh)->h_blocks != cpu_to_le32(1)) { | 1348 | BHDR(bh)->h_blocks != cpu_to_le32(1)) { |
1351 | ext4_error(inode->i_sb, __FUNCTION__, | 1349 | ext4_error(inode->i_sb, __func__, |
1352 | "inode %lu: bad block %llu", inode->i_ino, | 1350 | "inode %lu: bad block %llu", inode->i_ino, |
1353 | EXT4_I(inode)->i_file_acl); | 1351 | EXT4_I(inode)->i_file_acl); |
1354 | goto cleanup; | 1352 | goto cleanup; |
@@ -1475,7 +1473,7 @@ again: | |||
1475 | } | 1473 | } |
1476 | bh = sb_bread(inode->i_sb, ce->e_block); | 1474 | bh = sb_bread(inode->i_sb, ce->e_block); |
1477 | if (!bh) { | 1475 | if (!bh) { |
1478 | ext4_error(inode->i_sb, __FUNCTION__, | 1476 | ext4_error(inode->i_sb, __func__, |
1479 | "inode %lu: block %lu read error", | 1477 | "inode %lu: block %lu read error", |
1480 | inode->i_ino, (unsigned long) ce->e_block); | 1478 | inode->i_ino, (unsigned long) ce->e_block); |
1481 | } else if (le32_to_cpu(BHDR(bh)->h_refcount) >= | 1479 | } else if (le32_to_cpu(BHDR(bh)->h_refcount) >= |
diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h index d7f5d6a12651..5992fe979bb9 100644 --- a/fs/ext4/xattr.h +++ b/fs/ext4/xattr.h | |||
@@ -74,7 +74,6 @@ extern struct xattr_handler ext4_xattr_security_handler; | |||
74 | extern ssize_t ext4_listxattr(struct dentry *, char *, size_t); | 74 | extern ssize_t ext4_listxattr(struct dentry *, char *, size_t); |
75 | 75 | ||
76 | extern int ext4_xattr_get(struct inode *, int, const char *, void *, size_t); | 76 | extern int ext4_xattr_get(struct inode *, int, const char *, void *, size_t); |
77 | extern int ext4_xattr_list(struct inode *, char *, size_t); | ||
78 | extern int ext4_xattr_set(struct inode *, int, const char *, const void *, size_t, int); | 77 | extern int ext4_xattr_set(struct inode *, int, const char *, const void *, size_t, int); |
79 | extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int); | 78 | extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int); |
80 | 79 | ||
@@ -99,12 +98,6 @@ ext4_xattr_get(struct inode *inode, int name_index, const char *name, | |||
99 | } | 98 | } |
100 | 99 | ||
101 | static inline int | 100 | static inline int |
102 | ext4_xattr_list(struct inode *inode, void *buffer, size_t size) | ||
103 | { | ||
104 | return -EOPNOTSUPP; | ||
105 | } | ||
106 | |||
107 | static inline int | ||
108 | ext4_xattr_set(struct inode *inode, int name_index, const char *name, | 101 | ext4_xattr_set(struct inode *inode, int name_index, const char *name, |
109 | const void *value, size_t size, int flags) | 102 | const void *value, size_t size, int flags) |
110 | { | 103 | { |
diff --git a/fs/ext4/xattr_security.c b/fs/ext4/xattr_security.c index f17eaf2321b9..ca5f89fc6cae 100644 --- a/fs/ext4/xattr_security.c +++ b/fs/ext4/xattr_security.c | |||
@@ -6,9 +6,9 @@ | |||
6 | #include <linux/module.h> | 6 | #include <linux/module.h> |
7 | #include <linux/string.h> | 7 | #include <linux/string.h> |
8 | #include <linux/fs.h> | 8 | #include <linux/fs.h> |
9 | #include <linux/ext4_jbd2.h> | ||
10 | #include <linux/ext4_fs.h> | ||
11 | #include <linux/security.h> | 9 | #include <linux/security.h> |
10 | #include "ext4_jbd2.h" | ||
11 | #include "ext4.h" | ||
12 | #include "xattr.h" | 12 | #include "xattr.h" |
13 | 13 | ||
14 | static size_t | 14 | static size_t |
diff --git a/fs/ext4/xattr_trusted.c b/fs/ext4/xattr_trusted.c index e0f05acdafec..fff33382cadc 100644 --- a/fs/ext4/xattr_trusted.c +++ b/fs/ext4/xattr_trusted.c | |||
@@ -9,8 +9,8 @@ | |||
9 | #include <linux/string.h> | 9 | #include <linux/string.h> |
10 | #include <linux/capability.h> | 10 | #include <linux/capability.h> |
11 | #include <linux/fs.h> | 11 | #include <linux/fs.h> |
12 | #include <linux/ext4_jbd2.h> | 12 | #include "ext4_jbd2.h" |
13 | #include <linux/ext4_fs.h> | 13 | #include "ext4.h" |
14 | #include "xattr.h" | 14 | #include "xattr.h" |
15 | 15 | ||
16 | #define XATTR_TRUSTED_PREFIX "trusted." | 16 | #define XATTR_TRUSTED_PREFIX "trusted." |
diff --git a/fs/ext4/xattr_user.c b/fs/ext4/xattr_user.c index 7ed3d8ebf096..67be723fcc4e 100644 --- a/fs/ext4/xattr_user.c +++ b/fs/ext4/xattr_user.c | |||
@@ -8,8 +8,8 @@ | |||
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | #include <linux/string.h> | 9 | #include <linux/string.h> |
10 | #include <linux/fs.h> | 10 | #include <linux/fs.h> |
11 | #include <linux/ext4_jbd2.h> | 11 | #include "ext4_jbd2.h" |
12 | #include <linux/ext4_fs.h> | 12 | #include "ext4.h" |
13 | #include "xattr.h" | 13 | #include "xattr.h" |
14 | 14 | ||
15 | #define XATTR_USER_PREFIX "user." | 15 | #define XATTR_USER_PREFIX "user." |
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index a8173081f831..e0139786f717 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c | |||
@@ -520,22 +520,6 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
520 | jbd_debug (3, "JBD: commit phase 2\n"); | 520 | jbd_debug (3, "JBD: commit phase 2\n"); |
521 | 521 | ||
522 | /* | 522 | /* |
523 | * First, drop modified flag: all accesses to the buffers | ||
524 | * will be tracked for a new trasaction only -bzzz | ||
525 | */ | ||
526 | spin_lock(&journal->j_list_lock); | ||
527 | if (commit_transaction->t_buffers) { | ||
528 | new_jh = jh = commit_transaction->t_buffers->b_tnext; | ||
529 | do { | ||
530 | J_ASSERT_JH(new_jh, new_jh->b_modified == 1 || | ||
531 | new_jh->b_modified == 0); | ||
532 | new_jh->b_modified = 0; | ||
533 | new_jh = new_jh->b_tnext; | ||
534 | } while (new_jh != jh); | ||
535 | } | ||
536 | spin_unlock(&journal->j_list_lock); | ||
537 | |||
538 | /* | ||
539 | * Now start flushing things to disk, in the order they appear | 523 | * Now start flushing things to disk, in the order they appear |
540 | * on the transaction lists. Data blocks go first. | 524 | * on the transaction lists. Data blocks go first. |
541 | */ | 525 | */ |
@@ -584,6 +568,9 @@ void jbd2_journal_commit_transaction(journal_t *journal) | |||
584 | stats.u.run.rs_blocks = commit_transaction->t_outstanding_credits; | 568 | stats.u.run.rs_blocks = commit_transaction->t_outstanding_credits; |
585 | stats.u.run.rs_blocks_logged = 0; | 569 | stats.u.run.rs_blocks_logged = 0; |
586 | 570 | ||
571 | J_ASSERT(commit_transaction->t_nr_buffers <= | ||
572 | commit_transaction->t_outstanding_credits); | ||
573 | |||
587 | descriptor = NULL; | 574 | descriptor = NULL; |
588 | bufs = 0; | 575 | bufs = 0; |
589 | while (commit_transaction->t_buffers) { | 576 | while (commit_transaction->t_buffers) { |
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index eb7eb6c27bcb..53632e3e8457 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c | |||
@@ -534,7 +534,7 @@ int jbd2_log_wait_commit(journal_t *journal, tid_t tid) | |||
534 | if (!tid_geq(journal->j_commit_request, tid)) { | 534 | if (!tid_geq(journal->j_commit_request, tid)) { |
535 | printk(KERN_EMERG | 535 | printk(KERN_EMERG |
536 | "%s: error: j_commit_request=%d, tid=%d\n", | 536 | "%s: error: j_commit_request=%d, tid=%d\n", |
537 | __FUNCTION__, journal->j_commit_request, tid); | 537 | __func__, journal->j_commit_request, tid); |
538 | } | 538 | } |
539 | spin_unlock(&journal->j_state_lock); | 539 | spin_unlock(&journal->j_state_lock); |
540 | #endif | 540 | #endif |
@@ -599,7 +599,7 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr, | |||
599 | 599 | ||
600 | printk(KERN_ALERT "%s: journal block not found " | 600 | printk(KERN_ALERT "%s: journal block not found " |
601 | "at offset %lu on %s\n", | 601 | "at offset %lu on %s\n", |
602 | __FUNCTION__, | 602 | __func__, |
603 | blocknr, | 603 | blocknr, |
604 | bdevname(journal->j_dev, b)); | 604 | bdevname(journal->j_dev, b)); |
605 | err = -EIO; | 605 | err = -EIO; |
@@ -997,13 +997,14 @@ fail: | |||
997 | */ | 997 | */ |
998 | 998 | ||
999 | /** | 999 | /** |
1000 | * journal_t * jbd2_journal_init_dev() - creates an initialises a journal structure | 1000 | * journal_t * jbd2_journal_init_dev() - creates and initialises a journal structure |
1001 | * @bdev: Block device on which to create the journal | 1001 | * @bdev: Block device on which to create the journal |
1002 | * @fs_dev: Device which hold journalled filesystem for this journal. | 1002 | * @fs_dev: Device which hold journalled filesystem for this journal. |
1003 | * @start: Block nr Start of journal. | 1003 | * @start: Block nr Start of journal. |
1004 | * @len: Length of the journal in blocks. | 1004 | * @len: Length of the journal in blocks. |
1005 | * @blocksize: blocksize of journalling device | 1005 | * @blocksize: blocksize of journalling device |
1006 | * @returns: a newly created journal_t * | 1006 | * |
1007 | * Returns: a newly created journal_t * | ||
1007 | * | 1008 | * |
1008 | * jbd2_journal_init_dev creates a journal which maps a fixed contiguous | 1009 | * jbd2_journal_init_dev creates a journal which maps a fixed contiguous |
1009 | * range of blocks on an arbitrary block device. | 1010 | * range of blocks on an arbitrary block device. |
@@ -1027,7 +1028,7 @@ journal_t * jbd2_journal_init_dev(struct block_device *bdev, | |||
1027 | journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL); | 1028 | journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL); |
1028 | if (!journal->j_wbuf) { | 1029 | if (!journal->j_wbuf) { |
1029 | printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n", | 1030 | printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n", |
1030 | __FUNCTION__); | 1031 | __func__); |
1031 | kfree(journal); | 1032 | kfree(journal); |
1032 | journal = NULL; | 1033 | journal = NULL; |
1033 | goto out; | 1034 | goto out; |
@@ -1083,7 +1084,7 @@ journal_t * jbd2_journal_init_inode (struct inode *inode) | |||
1083 | journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL); | 1084 | journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL); |
1084 | if (!journal->j_wbuf) { | 1085 | if (!journal->j_wbuf) { |
1085 | printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n", | 1086 | printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n", |
1086 | __FUNCTION__); | 1087 | __func__); |
1087 | kfree(journal); | 1088 | kfree(journal); |
1088 | return NULL; | 1089 | return NULL; |
1089 | } | 1090 | } |
@@ -1092,7 +1093,7 @@ journal_t * jbd2_journal_init_inode (struct inode *inode) | |||
1092 | /* If that failed, give up */ | 1093 | /* If that failed, give up */ |
1093 | if (err) { | 1094 | if (err) { |
1094 | printk(KERN_ERR "%s: Cannnot locate journal superblock\n", | 1095 | printk(KERN_ERR "%s: Cannnot locate journal superblock\n", |
1095 | __FUNCTION__); | 1096 | __func__); |
1096 | kfree(journal); | 1097 | kfree(journal); |
1097 | return NULL; | 1098 | return NULL; |
1098 | } | 1099 | } |
@@ -1178,7 +1179,7 @@ int jbd2_journal_create(journal_t *journal) | |||
1178 | */ | 1179 | */ |
1179 | printk(KERN_EMERG | 1180 | printk(KERN_EMERG |
1180 | "%s: creation of journal on external device!\n", | 1181 | "%s: creation of journal on external device!\n", |
1181 | __FUNCTION__); | 1182 | __func__); |
1182 | BUG(); | 1183 | BUG(); |
1183 | } | 1184 | } |
1184 | 1185 | ||
@@ -1976,9 +1977,10 @@ static int journal_init_jbd2_journal_head_cache(void) | |||
1976 | 1977 | ||
1977 | static void jbd2_journal_destroy_jbd2_journal_head_cache(void) | 1978 | static void jbd2_journal_destroy_jbd2_journal_head_cache(void) |
1978 | { | 1979 | { |
1979 | J_ASSERT(jbd2_journal_head_cache != NULL); | 1980 | if (jbd2_journal_head_cache) { |
1980 | kmem_cache_destroy(jbd2_journal_head_cache); | 1981 | kmem_cache_destroy(jbd2_journal_head_cache); |
1981 | jbd2_journal_head_cache = NULL; | 1982 | jbd2_journal_head_cache = NULL; |
1983 | } | ||
1982 | } | 1984 | } |
1983 | 1985 | ||
1984 | /* | 1986 | /* |
@@ -1997,7 +1999,7 @@ static struct journal_head *journal_alloc_journal_head(void) | |||
1997 | jbd_debug(1, "out of memory for journal_head\n"); | 1999 | jbd_debug(1, "out of memory for journal_head\n"); |
1998 | if (time_after(jiffies, last_warning + 5*HZ)) { | 2000 | if (time_after(jiffies, last_warning + 5*HZ)) { |
1999 | printk(KERN_NOTICE "ENOMEM in %s, retrying.\n", | 2001 | printk(KERN_NOTICE "ENOMEM in %s, retrying.\n", |
2000 | __FUNCTION__); | 2002 | __func__); |
2001 | last_warning = jiffies; | 2003 | last_warning = jiffies; |
2002 | } | 2004 | } |
2003 | while (!ret) { | 2005 | while (!ret) { |
@@ -2134,13 +2136,13 @@ static void __journal_remove_journal_head(struct buffer_head *bh) | |||
2134 | if (jh->b_frozen_data) { | 2136 | if (jh->b_frozen_data) { |
2135 | printk(KERN_WARNING "%s: freeing " | 2137 | printk(KERN_WARNING "%s: freeing " |
2136 | "b_frozen_data\n", | 2138 | "b_frozen_data\n", |
2137 | __FUNCTION__); | 2139 | __func__); |
2138 | jbd2_free(jh->b_frozen_data, bh->b_size); | 2140 | jbd2_free(jh->b_frozen_data, bh->b_size); |
2139 | } | 2141 | } |
2140 | if (jh->b_committed_data) { | 2142 | if (jh->b_committed_data) { |
2141 | printk(KERN_WARNING "%s: freeing " | 2143 | printk(KERN_WARNING "%s: freeing " |
2142 | "b_committed_data\n", | 2144 | "b_committed_data\n", |
2143 | __FUNCTION__); | 2145 | __func__); |
2144 | jbd2_free(jh->b_committed_data, bh->b_size); | 2146 | jbd2_free(jh->b_committed_data, bh->b_size); |
2145 | } | 2147 | } |
2146 | bh->b_private = NULL; | 2148 | bh->b_private = NULL; |
@@ -2305,10 +2307,12 @@ static int __init journal_init(void) | |||
2305 | BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024); | 2307 | BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024); |
2306 | 2308 | ||
2307 | ret = journal_init_caches(); | 2309 | ret = journal_init_caches(); |
2308 | if (ret != 0) | 2310 | if (ret == 0) { |
2311 | jbd2_create_debugfs_entry(); | ||
2312 | jbd2_create_jbd_stats_proc_entry(); | ||
2313 | } else { | ||
2309 | jbd2_journal_destroy_caches(); | 2314 | jbd2_journal_destroy_caches(); |
2310 | jbd2_create_debugfs_entry(); | 2315 | } |
2311 | jbd2_create_jbd_stats_proc_entry(); | ||
2312 | return ret; | 2316 | return ret; |
2313 | } | 2317 | } |
2314 | 2318 | ||
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c index 2e1453a5e998..257ff2625765 100644 --- a/fs/jbd2/revoke.c +++ b/fs/jbd2/revoke.c | |||
@@ -139,7 +139,7 @@ repeat: | |||
139 | oom: | 139 | oom: |
140 | if (!journal_oom_retry) | 140 | if (!journal_oom_retry) |
141 | return -ENOMEM; | 141 | return -ENOMEM; |
142 | jbd_debug(1, "ENOMEM in %s, retrying\n", __FUNCTION__); | 142 | jbd_debug(1, "ENOMEM in %s, retrying\n", __func__); |
143 | yield(); | 143 | yield(); |
144 | goto repeat; | 144 | goto repeat; |
145 | } | 145 | } |
@@ -167,138 +167,121 @@ static struct jbd2_revoke_record_s *find_revoke_record(journal_t *journal, | |||
167 | return NULL; | 167 | return NULL; |
168 | } | 168 | } |
169 | 169 | ||
170 | void jbd2_journal_destroy_revoke_caches(void) | ||
171 | { | ||
172 | if (jbd2_revoke_record_cache) { | ||
173 | kmem_cache_destroy(jbd2_revoke_record_cache); | ||
174 | jbd2_revoke_record_cache = NULL; | ||
175 | } | ||
176 | if (jbd2_revoke_table_cache) { | ||
177 | kmem_cache_destroy(jbd2_revoke_table_cache); | ||
178 | jbd2_revoke_table_cache = NULL; | ||
179 | } | ||
180 | } | ||
181 | |||
170 | int __init jbd2_journal_init_revoke_caches(void) | 182 | int __init jbd2_journal_init_revoke_caches(void) |
171 | { | 183 | { |
184 | J_ASSERT(!jbd2_revoke_record_cache); | ||
185 | J_ASSERT(!jbd2_revoke_table_cache); | ||
186 | |||
172 | jbd2_revoke_record_cache = kmem_cache_create("jbd2_revoke_record", | 187 | jbd2_revoke_record_cache = kmem_cache_create("jbd2_revoke_record", |
173 | sizeof(struct jbd2_revoke_record_s), | 188 | sizeof(struct jbd2_revoke_record_s), |
174 | 0, | 189 | 0, |
175 | SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY, | 190 | SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY, |
176 | NULL); | 191 | NULL); |
177 | if (!jbd2_revoke_record_cache) | 192 | if (!jbd2_revoke_record_cache) |
178 | return -ENOMEM; | 193 | goto record_cache_failure; |
179 | 194 | ||
180 | jbd2_revoke_table_cache = kmem_cache_create("jbd2_revoke_table", | 195 | jbd2_revoke_table_cache = kmem_cache_create("jbd2_revoke_table", |
181 | sizeof(struct jbd2_revoke_table_s), | 196 | sizeof(struct jbd2_revoke_table_s), |
182 | 0, SLAB_TEMPORARY, NULL); | 197 | 0, SLAB_TEMPORARY, NULL); |
183 | if (!jbd2_revoke_table_cache) { | 198 | if (!jbd2_revoke_table_cache) |
184 | kmem_cache_destroy(jbd2_revoke_record_cache); | 199 | goto table_cache_failure; |
185 | jbd2_revoke_record_cache = NULL; | ||
186 | return -ENOMEM; | ||
187 | } | ||
188 | return 0; | 200 | return 0; |
201 | table_cache_failure: | ||
202 | jbd2_journal_destroy_revoke_caches(); | ||
203 | record_cache_failure: | ||
204 | return -ENOMEM; | ||
189 | } | 205 | } |
190 | 206 | ||
191 | void jbd2_journal_destroy_revoke_caches(void) | 207 | static struct jbd2_revoke_table_s *jbd2_journal_init_revoke_table(int hash_size) |
192 | { | 208 | { |
193 | kmem_cache_destroy(jbd2_revoke_record_cache); | 209 | int shift = 0; |
194 | jbd2_revoke_record_cache = NULL; | 210 | int tmp = hash_size; |
195 | kmem_cache_destroy(jbd2_revoke_table_cache); | 211 | struct jbd2_revoke_table_s *table; |
196 | jbd2_revoke_table_cache = NULL; | ||
197 | } | ||
198 | |||
199 | /* Initialise the revoke table for a given journal to a given size. */ | ||
200 | |||
201 | int jbd2_journal_init_revoke(journal_t *journal, int hash_size) | ||
202 | { | ||
203 | int shift, tmp; | ||
204 | 212 | ||
205 | J_ASSERT (journal->j_revoke_table[0] == NULL); | 213 | table = kmem_cache_alloc(jbd2_revoke_table_cache, GFP_KERNEL); |
214 | if (!table) | ||
215 | goto out; | ||
206 | 216 | ||
207 | shift = 0; | ||
208 | tmp = hash_size; | ||
209 | while((tmp >>= 1UL) != 0UL) | 217 | while((tmp >>= 1UL) != 0UL) |
210 | shift++; | 218 | shift++; |
211 | 219 | ||
212 | journal->j_revoke_table[0] = kmem_cache_alloc(jbd2_revoke_table_cache, GFP_KERNEL); | 220 | table->hash_size = hash_size; |
213 | if (!journal->j_revoke_table[0]) | 221 | table->hash_shift = shift; |
214 | return -ENOMEM; | 222 | table->hash_table = |
215 | journal->j_revoke = journal->j_revoke_table[0]; | ||
216 | |||
217 | /* Check that the hash_size is a power of two */ | ||
218 | J_ASSERT(is_power_of_2(hash_size)); | ||
219 | |||
220 | journal->j_revoke->hash_size = hash_size; | ||
221 | |||
222 | journal->j_revoke->hash_shift = shift; | ||
223 | |||
224 | journal->j_revoke->hash_table = | ||
225 | kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL); | 223 | kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL); |
226 | if (!journal->j_revoke->hash_table) { | 224 | if (!table->hash_table) { |
227 | kmem_cache_free(jbd2_revoke_table_cache, journal->j_revoke_table[0]); | 225 | kmem_cache_free(jbd2_revoke_table_cache, table); |
228 | journal->j_revoke = NULL; | 226 | table = NULL; |
229 | return -ENOMEM; | 227 | goto out; |
230 | } | 228 | } |
231 | 229 | ||
232 | for (tmp = 0; tmp < hash_size; tmp++) | 230 | for (tmp = 0; tmp < hash_size; tmp++) |
233 | INIT_LIST_HEAD(&journal->j_revoke->hash_table[tmp]); | 231 | INIT_LIST_HEAD(&table->hash_table[tmp]); |
234 | 232 | ||
235 | journal->j_revoke_table[1] = kmem_cache_alloc(jbd2_revoke_table_cache, GFP_KERNEL); | 233 | out: |
236 | if (!journal->j_revoke_table[1]) { | 234 | return table; |
237 | kfree(journal->j_revoke_table[0]->hash_table); | 235 | } |
238 | kmem_cache_free(jbd2_revoke_table_cache, journal->j_revoke_table[0]); | 236 | |
239 | return -ENOMEM; | 237 | static void jbd2_journal_destroy_revoke_table(struct jbd2_revoke_table_s *table) |
238 | { | ||
239 | int i; | ||
240 | struct list_head *hash_list; | ||
241 | |||
242 | for (i = 0; i < table->hash_size; i++) { | ||
243 | hash_list = &table->hash_table[i]; | ||
244 | J_ASSERT(list_empty(hash_list)); | ||
240 | } | 245 | } |
241 | 246 | ||
242 | journal->j_revoke = journal->j_revoke_table[1]; | 247 | kfree(table->hash_table); |
248 | kmem_cache_free(jbd2_revoke_table_cache, table); | ||
249 | } | ||
243 | 250 | ||
244 | /* Check that the hash_size is a power of two */ | 251 | /* Initialise the revoke table for a given journal to a given size. */ |
252 | int jbd2_journal_init_revoke(journal_t *journal, int hash_size) | ||
253 | { | ||
254 | J_ASSERT(journal->j_revoke_table[0] == NULL); | ||
245 | J_ASSERT(is_power_of_2(hash_size)); | 255 | J_ASSERT(is_power_of_2(hash_size)); |
246 | 256 | ||
247 | journal->j_revoke->hash_size = hash_size; | 257 | journal->j_revoke_table[0] = jbd2_journal_init_revoke_table(hash_size); |
248 | 258 | if (!journal->j_revoke_table[0]) | |
249 | journal->j_revoke->hash_shift = shift; | 259 | goto fail0; |
250 | 260 | ||
251 | journal->j_revoke->hash_table = | 261 | journal->j_revoke_table[1] = jbd2_journal_init_revoke_table(hash_size); |
252 | kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL); | 262 | if (!journal->j_revoke_table[1]) |
253 | if (!journal->j_revoke->hash_table) { | 263 | goto fail1; |
254 | kfree(journal->j_revoke_table[0]->hash_table); | ||
255 | kmem_cache_free(jbd2_revoke_table_cache, journal->j_revoke_table[0]); | ||
256 | kmem_cache_free(jbd2_revoke_table_cache, journal->j_revoke_table[1]); | ||
257 | journal->j_revoke = NULL; | ||
258 | return -ENOMEM; | ||
259 | } | ||
260 | 264 | ||
261 | for (tmp = 0; tmp < hash_size; tmp++) | 265 | journal->j_revoke = journal->j_revoke_table[1]; |
262 | INIT_LIST_HEAD(&journal->j_revoke->hash_table[tmp]); | ||
263 | 266 | ||
264 | spin_lock_init(&journal->j_revoke_lock); | 267 | spin_lock_init(&journal->j_revoke_lock); |
265 | 268 | ||
266 | return 0; | 269 | return 0; |
267 | } | ||
268 | 270 | ||
269 | /* Destoy a journal's revoke table. The table must already be empty! */ | 271 | fail1: |
272 | jbd2_journal_destroy_revoke_table(journal->j_revoke_table[0]); | ||
273 | fail0: | ||
274 | return -ENOMEM; | ||
275 | } | ||
270 | 276 | ||
277 | /* Destroy a journal's revoke table. The table must already be empty! */ | ||
271 | void jbd2_journal_destroy_revoke(journal_t *journal) | 278 | void jbd2_journal_destroy_revoke(journal_t *journal) |
272 | { | 279 | { |
273 | struct jbd2_revoke_table_s *table; | ||
274 | struct list_head *hash_list; | ||
275 | int i; | ||
276 | |||
277 | table = journal->j_revoke_table[0]; | ||
278 | if (!table) | ||
279 | return; | ||
280 | |||
281 | for (i=0; i<table->hash_size; i++) { | ||
282 | hash_list = &table->hash_table[i]; | ||
283 | J_ASSERT (list_empty(hash_list)); | ||
284 | } | ||
285 | |||
286 | kfree(table->hash_table); | ||
287 | kmem_cache_free(jbd2_revoke_table_cache, table); | ||
288 | journal->j_revoke = NULL; | ||
289 | |||
290 | table = journal->j_revoke_table[1]; | ||
291 | if (!table) | ||
292 | return; | ||
293 | |||
294 | for (i=0; i<table->hash_size; i++) { | ||
295 | hash_list = &table->hash_table[i]; | ||
296 | J_ASSERT (list_empty(hash_list)); | ||
297 | } | ||
298 | |||
299 | kfree(table->hash_table); | ||
300 | kmem_cache_free(jbd2_revoke_table_cache, table); | ||
301 | journal->j_revoke = NULL; | 280 | journal->j_revoke = NULL; |
281 | if (journal->j_revoke_table[0]) | ||
282 | jbd2_journal_destroy_revoke_table(journal->j_revoke_table[0]); | ||
283 | if (journal->j_revoke_table[1]) | ||
284 | jbd2_journal_destroy_revoke_table(journal->j_revoke_table[1]); | ||
302 | } | 285 | } |
303 | 286 | ||
304 | 287 | ||
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index b9b0b6f899b9..d6e006e67804 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c | |||
@@ -618,6 +618,12 @@ repeat: | |||
618 | goto done; | 618 | goto done; |
619 | 619 | ||
620 | /* | 620 | /* |
621 | * this is the first time this transaction is touching this buffer, | ||
622 | * reset the modified flag | ||
623 | */ | ||
624 | jh->b_modified = 0; | ||
625 | |||
626 | /* | ||
621 | * If there is already a copy-out version of this buffer, then we don't | 627 | * If there is already a copy-out version of this buffer, then we don't |
622 | * need to make another one | 628 | * need to make another one |
623 | */ | 629 | */ |
@@ -690,7 +696,7 @@ repeat: | |||
690 | if (!frozen_buffer) { | 696 | if (!frozen_buffer) { |
691 | printk(KERN_EMERG | 697 | printk(KERN_EMERG |
692 | "%s: OOM for frozen_buffer\n", | 698 | "%s: OOM for frozen_buffer\n", |
693 | __FUNCTION__); | 699 | __func__); |
694 | JBUFFER_TRACE(jh, "oom!"); | 700 | JBUFFER_TRACE(jh, "oom!"); |
695 | error = -ENOMEM; | 701 | error = -ENOMEM; |
696 | jbd_lock_bh_state(bh); | 702 | jbd_lock_bh_state(bh); |
@@ -829,9 +835,16 @@ int jbd2_journal_get_create_access(handle_t *handle, struct buffer_head *bh) | |||
829 | 835 | ||
830 | if (jh->b_transaction == NULL) { | 836 | if (jh->b_transaction == NULL) { |
831 | jh->b_transaction = transaction; | 837 | jh->b_transaction = transaction; |
838 | |||
839 | /* first access by this transaction */ | ||
840 | jh->b_modified = 0; | ||
841 | |||
832 | JBUFFER_TRACE(jh, "file as BJ_Reserved"); | 842 | JBUFFER_TRACE(jh, "file as BJ_Reserved"); |
833 | __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved); | 843 | __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved); |
834 | } else if (jh->b_transaction == journal->j_committing_transaction) { | 844 | } else if (jh->b_transaction == journal->j_committing_transaction) { |
845 | /* first access by this transaction */ | ||
846 | jh->b_modified = 0; | ||
847 | |||
835 | JBUFFER_TRACE(jh, "set next transaction"); | 848 | JBUFFER_TRACE(jh, "set next transaction"); |
836 | jh->b_next_transaction = transaction; | 849 | jh->b_next_transaction = transaction; |
837 | } | 850 | } |
@@ -901,7 +914,7 @@ repeat: | |||
901 | committed_data = jbd2_alloc(jh2bh(jh)->b_size, GFP_NOFS); | 914 | committed_data = jbd2_alloc(jh2bh(jh)->b_size, GFP_NOFS); |
902 | if (!committed_data) { | 915 | if (!committed_data) { |
903 | printk(KERN_EMERG "%s: No memory for committed data\n", | 916 | printk(KERN_EMERG "%s: No memory for committed data\n", |
904 | __FUNCTION__); | 917 | __func__); |
905 | err = -ENOMEM; | 918 | err = -ENOMEM; |
906 | goto out; | 919 | goto out; |
907 | } | 920 | } |
@@ -1230,6 +1243,7 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh) | |||
1230 | struct journal_head *jh; | 1243 | struct journal_head *jh; |
1231 | int drop_reserve = 0; | 1244 | int drop_reserve = 0; |
1232 | int err = 0; | 1245 | int err = 0; |
1246 | int was_modified = 0; | ||
1233 | 1247 | ||
1234 | BUFFER_TRACE(bh, "entry"); | 1248 | BUFFER_TRACE(bh, "entry"); |
1235 | 1249 | ||
@@ -1248,6 +1262,9 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh) | |||
1248 | goto not_jbd; | 1262 | goto not_jbd; |
1249 | } | 1263 | } |
1250 | 1264 | ||
1265 | /* keep track of wether or not this transaction modified us */ | ||
1266 | was_modified = jh->b_modified; | ||
1267 | |||
1251 | /* | 1268 | /* |
1252 | * The buffer's going from the transaction, we must drop | 1269 | * The buffer's going from the transaction, we must drop |
1253 | * all references -bzzz | 1270 | * all references -bzzz |
@@ -1265,7 +1282,12 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh) | |||
1265 | 1282 | ||
1266 | JBUFFER_TRACE(jh, "belongs to current transaction: unfile"); | 1283 | JBUFFER_TRACE(jh, "belongs to current transaction: unfile"); |
1267 | 1284 | ||
1268 | drop_reserve = 1; | 1285 | /* |
1286 | * we only want to drop a reference if this transaction | ||
1287 | * modified the buffer | ||
1288 | */ | ||
1289 | if (was_modified) | ||
1290 | drop_reserve = 1; | ||
1269 | 1291 | ||
1270 | /* | 1292 | /* |
1271 | * We are no longer going to journal this buffer. | 1293 | * We are no longer going to journal this buffer. |
@@ -1305,7 +1327,13 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh) | |||
1305 | if (jh->b_next_transaction) { | 1327 | if (jh->b_next_transaction) { |
1306 | J_ASSERT(jh->b_next_transaction == transaction); | 1328 | J_ASSERT(jh->b_next_transaction == transaction); |
1307 | jh->b_next_transaction = NULL; | 1329 | jh->b_next_transaction = NULL; |
1308 | drop_reserve = 1; | 1330 | |
1331 | /* | ||
1332 | * only drop a reference if this transaction modified | ||
1333 | * the buffer | ||
1334 | */ | ||
1335 | if (was_modified) | ||
1336 | drop_reserve = 1; | ||
1309 | } | 1337 | } |
1310 | } | 1338 | } |
1311 | 1339 | ||
@@ -1434,7 +1462,8 @@ int jbd2_journal_stop(handle_t *handle) | |||
1434 | return err; | 1462 | return err; |
1435 | } | 1463 | } |
1436 | 1464 | ||
1437 | /**int jbd2_journal_force_commit() - force any uncommitted transactions | 1465 | /** |
1466 | * int jbd2_journal_force_commit() - force any uncommitted transactions | ||
1438 | * @journal: journal to force | 1467 | * @journal: journal to force |
1439 | * | 1468 | * |
1440 | * For synchronous operations: force any uncommitted transactions | 1469 | * For synchronous operations: force any uncommitted transactions |
@@ -2077,7 +2106,7 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh) | |||
2077 | jh->b_transaction = jh->b_next_transaction; | 2106 | jh->b_transaction = jh->b_next_transaction; |
2078 | jh->b_next_transaction = NULL; | 2107 | jh->b_next_transaction = NULL; |
2079 | __jbd2_journal_file_buffer(jh, jh->b_transaction, | 2108 | __jbd2_journal_file_buffer(jh, jh->b_transaction, |
2080 | was_dirty ? BJ_Metadata : BJ_Reserved); | 2109 | jh->b_modified ? BJ_Metadata : BJ_Reserved); |
2081 | J_ASSERT_JH(jh, jh->b_transaction->t_state == T_RUNNING); | 2110 | J_ASSERT_JH(jh, jh->b_transaction->t_state == T_RUNNING); |
2082 | 2111 | ||
2083 | if (was_dirty) | 2112 | if (was_dirty) |