diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
commit | ada47b5fe13d89735805b566185f4885f5a3f750 (patch) | |
tree | 644b88f8a71896307d71438e9b3af49126ffb22b /fs/reiserfs/inode.c | |
parent | 43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff) | |
parent | 3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff) |
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'fs/reiserfs/inode.c')
-rw-r--r-- | fs/reiserfs/inode.c | 164 |
1 files changed, 102 insertions, 62 deletions
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c index a14d6cd9eeda..dc2c65e04853 100644 --- a/fs/reiserfs/inode.c +++ b/fs/reiserfs/inode.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/smp_lock.h> | 11 | #include <linux/smp_lock.h> |
12 | #include <linux/pagemap.h> | 12 | #include <linux/pagemap.h> |
13 | #include <linux/highmem.h> | 13 | #include <linux/highmem.h> |
14 | #include <linux/slab.h> | ||
14 | #include <asm/uaccess.h> | 15 | #include <asm/uaccess.h> |
15 | #include <asm/unaligned.h> | 16 | #include <asm/unaligned.h> |
16 | #include <linux/buffer_head.h> | 17 | #include <linux/buffer_head.h> |
@@ -31,11 +32,15 @@ void reiserfs_delete_inode(struct inode *inode) | |||
31 | JOURNAL_PER_BALANCE_CNT * 2 + | 32 | JOURNAL_PER_BALANCE_CNT * 2 + |
32 | 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb); | 33 | 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb); |
33 | struct reiserfs_transaction_handle th; | 34 | struct reiserfs_transaction_handle th; |
35 | int depth; | ||
34 | int err; | 36 | int err; |
35 | 37 | ||
38 | if (!is_bad_inode(inode)) | ||
39 | dquot_initialize(inode); | ||
40 | |||
36 | truncate_inode_pages(&inode->i_data, 0); | 41 | truncate_inode_pages(&inode->i_data, 0); |
37 | 42 | ||
38 | reiserfs_write_lock(inode->i_sb); | 43 | depth = reiserfs_write_lock_once(inode->i_sb); |
39 | 44 | ||
40 | /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */ | 45 | /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */ |
41 | if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */ | 46 | if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */ |
@@ -53,7 +58,7 @@ void reiserfs_delete_inode(struct inode *inode) | |||
53 | * after delete_object so that quota updates go into the same transaction as | 58 | * after delete_object so that quota updates go into the same transaction as |
54 | * stat data deletion */ | 59 | * stat data deletion */ |
55 | if (!err) | 60 | if (!err) |
56 | vfs_dq_free_inode(inode); | 61 | dquot_free_inode(inode); |
57 | 62 | ||
58 | if (journal_end(&th, inode->i_sb, jbegin_count)) | 63 | if (journal_end(&th, inode->i_sb, jbegin_count)) |
59 | goto out; | 64 | goto out; |
@@ -74,7 +79,7 @@ void reiserfs_delete_inode(struct inode *inode) | |||
74 | out: | 79 | out: |
75 | clear_inode(inode); /* note this must go after the journal_end to prevent deadlock */ | 80 | clear_inode(inode); /* note this must go after the journal_end to prevent deadlock */ |
76 | inode->i_blocks = 0; | 81 | inode->i_blocks = 0; |
77 | reiserfs_write_unlock(inode->i_sb); | 82 | reiserfs_write_unlock_once(inode->i_sb, depth); |
78 | } | 83 | } |
79 | 84 | ||
80 | static void _make_cpu_key(struct cpu_key *key, int version, __u32 dirid, | 85 | static void _make_cpu_key(struct cpu_key *key, int version, __u32 dirid, |
@@ -251,7 +256,6 @@ static int _get_block_create_0(struct inode *inode, sector_t block, | |||
251 | struct cpu_key key; | 256 | struct cpu_key key; |
252 | struct buffer_head *bh; | 257 | struct buffer_head *bh; |
253 | struct item_head *ih, tmp_ih; | 258 | struct item_head *ih, tmp_ih; |
254 | int fs_gen; | ||
255 | b_blocknr_t blocknr; | 259 | b_blocknr_t blocknr; |
256 | char *p = NULL; | 260 | char *p = NULL; |
257 | int chars; | 261 | int chars; |
@@ -265,7 +269,6 @@ static int _get_block_create_0(struct inode *inode, sector_t block, | |||
265 | (loff_t) block * inode->i_sb->s_blocksize + 1, TYPE_ANY, | 269 | (loff_t) block * inode->i_sb->s_blocksize + 1, TYPE_ANY, |
266 | 3); | 270 | 3); |
267 | 271 | ||
268 | research: | ||
269 | result = search_for_position_by_key(inode->i_sb, &key, &path); | 272 | result = search_for_position_by_key(inode->i_sb, &key, &path); |
270 | if (result != POSITION_FOUND) { | 273 | if (result != POSITION_FOUND) { |
271 | pathrelse(&path); | 274 | pathrelse(&path); |
@@ -340,7 +343,6 @@ static int _get_block_create_0(struct inode *inode, sector_t block, | |||
340 | } | 343 | } |
341 | // read file tail into part of page | 344 | // read file tail into part of page |
342 | offset = (cpu_key_k_offset(&key) - 1) & (PAGE_CACHE_SIZE - 1); | 345 | offset = (cpu_key_k_offset(&key) - 1) & (PAGE_CACHE_SIZE - 1); |
343 | fs_gen = get_generation(inode->i_sb); | ||
344 | copy_item_head(&tmp_ih, ih); | 346 | copy_item_head(&tmp_ih, ih); |
345 | 347 | ||
346 | /* we only want to kmap if we are reading the tail into the page. | 348 | /* we only want to kmap if we are reading the tail into the page. |
@@ -348,13 +350,9 @@ static int _get_block_create_0(struct inode *inode, sector_t block, | |||
348 | ** sure we need to. But, this means the item might move if | 350 | ** sure we need to. But, this means the item might move if |
349 | ** kmap schedules | 351 | ** kmap schedules |
350 | */ | 352 | */ |
351 | if (!p) { | 353 | if (!p) |
352 | p = (char *)kmap(bh_result->b_page); | 354 | p = (char *)kmap(bh_result->b_page); |
353 | if (fs_changed(fs_gen, inode->i_sb) | 355 | |
354 | && item_moved(&tmp_ih, &path)) { | ||
355 | goto research; | ||
356 | } | ||
357 | } | ||
358 | p += offset; | 356 | p += offset; |
359 | memset(p, 0, inode->i_sb->s_blocksize); | 357 | memset(p, 0, inode->i_sb->s_blocksize); |
360 | do { | 358 | do { |
@@ -489,10 +487,14 @@ static int reiserfs_get_blocks_direct_io(struct inode *inode, | |||
489 | disappeared */ | 487 | disappeared */ |
490 | if (REISERFS_I(inode)->i_flags & i_pack_on_close_mask) { | 488 | if (REISERFS_I(inode)->i_flags & i_pack_on_close_mask) { |
491 | int err; | 489 | int err; |
492 | lock_kernel(); | 490 | |
491 | reiserfs_write_lock(inode->i_sb); | ||
492 | |||
493 | err = reiserfs_commit_for_inode(inode); | 493 | err = reiserfs_commit_for_inode(inode); |
494 | REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask; | 494 | REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask; |
495 | unlock_kernel(); | 495 | |
496 | reiserfs_write_unlock(inode->i_sb); | ||
497 | |||
496 | if (err < 0) | 498 | if (err < 0) |
497 | ret = err; | 499 | ret = err; |
498 | } | 500 | } |
@@ -601,6 +603,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block, | |||
601 | __le32 *item; | 603 | __le32 *item; |
602 | int done; | 604 | int done; |
603 | int fs_gen; | 605 | int fs_gen; |
606 | int lock_depth; | ||
604 | struct reiserfs_transaction_handle *th = NULL; | 607 | struct reiserfs_transaction_handle *th = NULL; |
605 | /* space reserved in transaction batch: | 608 | /* space reserved in transaction batch: |
606 | . 3 balancings in direct->indirect conversion | 609 | . 3 balancings in direct->indirect conversion |
@@ -616,12 +619,11 @@ int reiserfs_get_block(struct inode *inode, sector_t block, | |||
616 | loff_t new_offset = | 619 | loff_t new_offset = |
617 | (((loff_t) block) << inode->i_sb->s_blocksize_bits) + 1; | 620 | (((loff_t) block) << inode->i_sb->s_blocksize_bits) + 1; |
618 | 621 | ||
619 | /* bad.... */ | 622 | lock_depth = reiserfs_write_lock_once(inode->i_sb); |
620 | reiserfs_write_lock(inode->i_sb); | ||
621 | version = get_inode_item_key_version(inode); | 623 | version = get_inode_item_key_version(inode); |
622 | 624 | ||
623 | if (!file_capable(inode, block)) { | 625 | if (!file_capable(inode, block)) { |
624 | reiserfs_write_unlock(inode->i_sb); | 626 | reiserfs_write_unlock_once(inode->i_sb, lock_depth); |
625 | return -EFBIG; | 627 | return -EFBIG; |
626 | } | 628 | } |
627 | 629 | ||
@@ -633,7 +635,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block, | |||
633 | /* find number of block-th logical block of the file */ | 635 | /* find number of block-th logical block of the file */ |
634 | ret = _get_block_create_0(inode, block, bh_result, | 636 | ret = _get_block_create_0(inode, block, bh_result, |
635 | create | GET_BLOCK_READ_DIRECT); | 637 | create | GET_BLOCK_READ_DIRECT); |
636 | reiserfs_write_unlock(inode->i_sb); | 638 | reiserfs_write_unlock_once(inode->i_sb, lock_depth); |
637 | return ret; | 639 | return ret; |
638 | } | 640 | } |
639 | /* | 641 | /* |
@@ -751,7 +753,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block, | |||
751 | if (!dangle && th) | 753 | if (!dangle && th) |
752 | retval = reiserfs_end_persistent_transaction(th); | 754 | retval = reiserfs_end_persistent_transaction(th); |
753 | 755 | ||
754 | reiserfs_write_unlock(inode->i_sb); | 756 | reiserfs_write_unlock_once(inode->i_sb, lock_depth); |
755 | 757 | ||
756 | /* the item was found, so new blocks were not added to the file | 758 | /* the item was found, so new blocks were not added to the file |
757 | ** there is no need to make sure the inode is updated with this | 759 | ** there is no need to make sure the inode is updated with this |
@@ -935,7 +937,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block, | |||
935 | if (blocks_needed == 1) { | 937 | if (blocks_needed == 1) { |
936 | un = &unf_single; | 938 | un = &unf_single; |
937 | } else { | 939 | } else { |
938 | un = kzalloc(min(blocks_needed, max_to_insert) * UNFM_P_SIZE, GFP_ATOMIC); // We need to avoid scheduling. | 940 | un = kzalloc(min(blocks_needed, max_to_insert) * UNFM_P_SIZE, GFP_NOFS); |
939 | if (!un) { | 941 | if (!un) { |
940 | un = &unf_single; | 942 | un = &unf_single; |
941 | blocks_needed = 1; | 943 | blocks_needed = 1; |
@@ -997,10 +999,16 @@ int reiserfs_get_block(struct inode *inode, sector_t block, | |||
997 | if (retval) | 999 | if (retval) |
998 | goto failure; | 1000 | goto failure; |
999 | } | 1001 | } |
1000 | /* inserting indirect pointers for a hole can take a | 1002 | /* |
1001 | ** long time. reschedule if needed | 1003 | * inserting indirect pointers for a hole can take a |
1004 | * long time. reschedule if needed and also release the write | ||
1005 | * lock for others. | ||
1002 | */ | 1006 | */ |
1003 | cond_resched(); | 1007 | if (need_resched()) { |
1008 | reiserfs_write_unlock_once(inode->i_sb, lock_depth); | ||
1009 | schedule(); | ||
1010 | lock_depth = reiserfs_write_lock_once(inode->i_sb); | ||
1011 | } | ||
1004 | 1012 | ||
1005 | retval = search_for_position_by_key(inode->i_sb, &key, &path); | 1013 | retval = search_for_position_by_key(inode->i_sb, &key, &path); |
1006 | if (retval == IO_ERROR) { | 1014 | if (retval == IO_ERROR) { |
@@ -1035,7 +1043,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block, | |||
1035 | retval = err; | 1043 | retval = err; |
1036 | } | 1044 | } |
1037 | 1045 | ||
1038 | reiserfs_write_unlock(inode->i_sb); | 1046 | reiserfs_write_unlock_once(inode->i_sb, lock_depth); |
1039 | reiserfs_check_path(&path); | 1047 | reiserfs_check_path(&path); |
1040 | return retval; | 1048 | return retval; |
1041 | } | 1049 | } |
@@ -1493,9 +1501,11 @@ struct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key) | |||
1493 | 1501 | ||
1494 | args.objectid = key->on_disk_key.k_objectid; | 1502 | args.objectid = key->on_disk_key.k_objectid; |
1495 | args.dirid = key->on_disk_key.k_dir_id; | 1503 | args.dirid = key->on_disk_key.k_dir_id; |
1504 | reiserfs_write_unlock(s); | ||
1496 | inode = iget5_locked(s, key->on_disk_key.k_objectid, | 1505 | inode = iget5_locked(s, key->on_disk_key.k_objectid, |
1497 | reiserfs_find_actor, reiserfs_init_locked_inode, | 1506 | reiserfs_find_actor, reiserfs_init_locked_inode, |
1498 | (void *)(&args)); | 1507 | (void *)(&args)); |
1508 | reiserfs_write_lock(s); | ||
1499 | if (!inode) | 1509 | if (!inode) |
1500 | return ERR_PTR(-ENOMEM); | 1510 | return ERR_PTR(-ENOMEM); |
1501 | 1511 | ||
@@ -1609,7 +1619,7 @@ int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp, | |||
1609 | ** to properly mark inodes for datasync and such, but only actually | 1619 | ** to properly mark inodes for datasync and such, but only actually |
1610 | ** does something when called for a synchronous update. | 1620 | ** does something when called for a synchronous update. |
1611 | */ | 1621 | */ |
1612 | int reiserfs_write_inode(struct inode *inode, int do_sync) | 1622 | int reiserfs_write_inode(struct inode *inode, struct writeback_control *wbc) |
1613 | { | 1623 | { |
1614 | struct reiserfs_transaction_handle th; | 1624 | struct reiserfs_transaction_handle th; |
1615 | int jbegin_count = 1; | 1625 | int jbegin_count = 1; |
@@ -1621,7 +1631,7 @@ int reiserfs_write_inode(struct inode *inode, int do_sync) | |||
1621 | ** inode needs to reach disk for safety, and they can safely be | 1631 | ** inode needs to reach disk for safety, and they can safely be |
1622 | ** ignored because the altered inode has already been logged. | 1632 | ** ignored because the altered inode has already been logged. |
1623 | */ | 1633 | */ |
1624 | if (do_sync && !(current->flags & PF_MEMALLOC)) { | 1634 | if (wbc->sync_mode == WB_SYNC_ALL && !(current->flags & PF_MEMALLOC)) { |
1625 | reiserfs_write_lock(inode->i_sb); | 1635 | reiserfs_write_lock(inode->i_sb); |
1626 | if (!journal_begin(&th, inode->i_sb, jbegin_count)) { | 1636 | if (!journal_begin(&th, inode->i_sb, jbegin_count)) { |
1627 | reiserfs_update_sd(&th, inode); | 1637 | reiserfs_update_sd(&th, inode); |
@@ -1759,10 +1769,10 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th, | |||
1759 | 1769 | ||
1760 | BUG_ON(!th->t_trans_id); | 1770 | BUG_ON(!th->t_trans_id); |
1761 | 1771 | ||
1762 | if (vfs_dq_alloc_inode(inode)) { | 1772 | dquot_initialize(inode); |
1763 | err = -EDQUOT; | 1773 | err = dquot_alloc_inode(inode); |
1774 | if (err) | ||
1764 | goto out_end_trans; | 1775 | goto out_end_trans; |
1765 | } | ||
1766 | if (!dir->i_nlink) { | 1776 | if (!dir->i_nlink) { |
1767 | err = -EPERM; | 1777 | err = -EPERM; |
1768 | goto out_bad_inode; | 1778 | goto out_bad_inode; |
@@ -1953,12 +1963,12 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th, | |||
1953 | INODE_PKEY(inode)->k_objectid = 0; | 1963 | INODE_PKEY(inode)->k_objectid = 0; |
1954 | 1964 | ||
1955 | /* Quota change must be inside a transaction for journaling */ | 1965 | /* Quota change must be inside a transaction for journaling */ |
1956 | vfs_dq_free_inode(inode); | 1966 | dquot_free_inode(inode); |
1957 | 1967 | ||
1958 | out_end_trans: | 1968 | out_end_trans: |
1959 | journal_end(th, th->t_super, th->t_blocks_allocated); | 1969 | journal_end(th, th->t_super, th->t_blocks_allocated); |
1960 | /* Drop can be outside and it needs more credits so it's better to have it outside */ | 1970 | /* Drop can be outside and it needs more credits so it's better to have it outside */ |
1961 | vfs_dq_drop(inode); | 1971 | dquot_drop(inode); |
1962 | inode->i_flags |= S_NOQUOTA; | 1972 | inode->i_flags |= S_NOQUOTA; |
1963 | make_bad_inode(inode); | 1973 | make_bad_inode(inode); |
1964 | 1974 | ||
@@ -2072,8 +2082,9 @@ int reiserfs_truncate_file(struct inode *inode, int update_timestamps) | |||
2072 | int error; | 2082 | int error; |
2073 | struct buffer_head *bh = NULL; | 2083 | struct buffer_head *bh = NULL; |
2074 | int err2; | 2084 | int err2; |
2085 | int lock_depth; | ||
2075 | 2086 | ||
2076 | reiserfs_write_lock(inode->i_sb); | 2087 | lock_depth = reiserfs_write_lock_once(inode->i_sb); |
2077 | 2088 | ||
2078 | if (inode->i_size > 0) { | 2089 | if (inode->i_size > 0) { |
2079 | error = grab_tail_page(inode, &page, &bh); | 2090 | error = grab_tail_page(inode, &page, &bh); |
@@ -2142,14 +2153,17 @@ int reiserfs_truncate_file(struct inode *inode, int update_timestamps) | |||
2142 | page_cache_release(page); | 2153 | page_cache_release(page); |
2143 | } | 2154 | } |
2144 | 2155 | ||
2145 | reiserfs_write_unlock(inode->i_sb); | 2156 | reiserfs_write_unlock_once(inode->i_sb, lock_depth); |
2157 | |||
2146 | return 0; | 2158 | return 0; |
2147 | out: | 2159 | out: |
2148 | if (page) { | 2160 | if (page) { |
2149 | unlock_page(page); | 2161 | unlock_page(page); |
2150 | page_cache_release(page); | 2162 | page_cache_release(page); |
2151 | } | 2163 | } |
2152 | reiserfs_write_unlock(inode->i_sb); | 2164 | |
2165 | reiserfs_write_unlock_once(inode->i_sb, lock_depth); | ||
2166 | |||
2153 | return error; | 2167 | return error; |
2154 | } | 2168 | } |
2155 | 2169 | ||
@@ -2531,6 +2545,12 @@ static int reiserfs_writepage(struct page *page, struct writeback_control *wbc) | |||
2531 | return reiserfs_write_full_page(page, wbc); | 2545 | return reiserfs_write_full_page(page, wbc); |
2532 | } | 2546 | } |
2533 | 2547 | ||
2548 | static void reiserfs_truncate_failed_write(struct inode *inode) | ||
2549 | { | ||
2550 | truncate_inode_pages(inode->i_mapping, inode->i_size); | ||
2551 | reiserfs_truncate_file(inode, 0); | ||
2552 | } | ||
2553 | |||
2534 | static int reiserfs_write_begin(struct file *file, | 2554 | static int reiserfs_write_begin(struct file *file, |
2535 | struct address_space *mapping, | 2555 | struct address_space *mapping, |
2536 | loff_t pos, unsigned len, unsigned flags, | 2556 | loff_t pos, unsigned len, unsigned flags, |
@@ -2597,6 +2617,8 @@ static int reiserfs_write_begin(struct file *file, | |||
2597 | if (ret) { | 2617 | if (ret) { |
2598 | unlock_page(page); | 2618 | unlock_page(page); |
2599 | page_cache_release(page); | 2619 | page_cache_release(page); |
2620 | /* Truncate allocated blocks */ | ||
2621 | reiserfs_truncate_failed_write(inode); | ||
2600 | } | 2622 | } |
2601 | return ret; | 2623 | return ret; |
2602 | } | 2624 | } |
@@ -2608,7 +2630,10 @@ int reiserfs_prepare_write(struct file *f, struct page *page, | |||
2608 | int ret; | 2630 | int ret; |
2609 | int old_ref = 0; | 2631 | int old_ref = 0; |
2610 | 2632 | ||
2633 | reiserfs_write_unlock(inode->i_sb); | ||
2611 | reiserfs_wait_on_write_block(inode->i_sb); | 2634 | reiserfs_wait_on_write_block(inode->i_sb); |
2635 | reiserfs_write_lock(inode->i_sb); | ||
2636 | |||
2612 | fix_tail_page_for_writing(page); | 2637 | fix_tail_page_for_writing(page); |
2613 | if (reiserfs_transaction_running(inode->i_sb)) { | 2638 | if (reiserfs_transaction_running(inode->i_sb)) { |
2614 | struct reiserfs_transaction_handle *th; | 2639 | struct reiserfs_transaction_handle *th; |
@@ -2664,6 +2689,8 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping, | |||
2664 | int update_sd = 0; | 2689 | int update_sd = 0; |
2665 | struct reiserfs_transaction_handle *th; | 2690 | struct reiserfs_transaction_handle *th; |
2666 | unsigned start; | 2691 | unsigned start; |
2692 | int lock_depth = 0; | ||
2693 | bool locked = false; | ||
2667 | 2694 | ||
2668 | if ((unsigned long)fsdata & AOP_FLAG_CONT_EXPAND) | 2695 | if ((unsigned long)fsdata & AOP_FLAG_CONT_EXPAND) |
2669 | pos ++; | 2696 | pos ++; |
@@ -2689,10 +2716,10 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping, | |||
2689 | ** transaction tracking stuff when the size changes. So, we have | 2716 | ** transaction tracking stuff when the size changes. So, we have |
2690 | ** to do the i_size updates here. | 2717 | ** to do the i_size updates here. |
2691 | */ | 2718 | */ |
2692 | pos += copied; | 2719 | if (pos + copied > inode->i_size) { |
2693 | if (pos > inode->i_size) { | ||
2694 | struct reiserfs_transaction_handle myth; | 2720 | struct reiserfs_transaction_handle myth; |
2695 | reiserfs_write_lock(inode->i_sb); | 2721 | lock_depth = reiserfs_write_lock_once(inode->i_sb); |
2722 | locked = true; | ||
2696 | /* If the file have grown beyond the border where it | 2723 | /* If the file have grown beyond the border where it |
2697 | can have a tail, unmark it as needing a tail | 2724 | can have a tail, unmark it as needing a tail |
2698 | packing */ | 2725 | packing */ |
@@ -2703,12 +2730,11 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping, | |||
2703 | REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask; | 2730 | REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask; |
2704 | 2731 | ||
2705 | ret = journal_begin(&myth, inode->i_sb, 1); | 2732 | ret = journal_begin(&myth, inode->i_sb, 1); |
2706 | if (ret) { | 2733 | if (ret) |
2707 | reiserfs_write_unlock(inode->i_sb); | ||
2708 | goto journal_error; | 2734 | goto journal_error; |
2709 | } | 2735 | |
2710 | reiserfs_update_inode_transaction(inode); | 2736 | reiserfs_update_inode_transaction(inode); |
2711 | inode->i_size = pos; | 2737 | inode->i_size = pos + copied; |
2712 | /* | 2738 | /* |
2713 | * this will just nest into our transaction. It's important | 2739 | * this will just nest into our transaction. It's important |
2714 | * to use mark_inode_dirty so the inode gets pushed around on the | 2740 | * to use mark_inode_dirty so the inode gets pushed around on the |
@@ -2718,34 +2744,40 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping, | |||
2718 | reiserfs_update_sd(&myth, inode); | 2744 | reiserfs_update_sd(&myth, inode); |
2719 | update_sd = 1; | 2745 | update_sd = 1; |
2720 | ret = journal_end(&myth, inode->i_sb, 1); | 2746 | ret = journal_end(&myth, inode->i_sb, 1); |
2721 | reiserfs_write_unlock(inode->i_sb); | ||
2722 | if (ret) | 2747 | if (ret) |
2723 | goto journal_error; | 2748 | goto journal_error; |
2724 | } | 2749 | } |
2725 | if (th) { | 2750 | if (th) { |
2726 | reiserfs_write_lock(inode->i_sb); | 2751 | if (!locked) { |
2752 | lock_depth = reiserfs_write_lock_once(inode->i_sb); | ||
2753 | locked = true; | ||
2754 | } | ||
2727 | if (!update_sd) | 2755 | if (!update_sd) |
2728 | mark_inode_dirty(inode); | 2756 | mark_inode_dirty(inode); |
2729 | ret = reiserfs_end_persistent_transaction(th); | 2757 | ret = reiserfs_end_persistent_transaction(th); |
2730 | reiserfs_write_unlock(inode->i_sb); | ||
2731 | if (ret) | 2758 | if (ret) |
2732 | goto out; | 2759 | goto out; |
2733 | } | 2760 | } |
2734 | 2761 | ||
2735 | out: | 2762 | out: |
2763 | if (locked) | ||
2764 | reiserfs_write_unlock_once(inode->i_sb, lock_depth); | ||
2736 | unlock_page(page); | 2765 | unlock_page(page); |
2737 | page_cache_release(page); | 2766 | page_cache_release(page); |
2767 | |||
2768 | if (pos + len > inode->i_size) | ||
2769 | reiserfs_truncate_failed_write(inode); | ||
2770 | |||
2738 | return ret == 0 ? copied : ret; | 2771 | return ret == 0 ? copied : ret; |
2739 | 2772 | ||
2740 | journal_error: | 2773 | journal_error: |
2774 | reiserfs_write_unlock_once(inode->i_sb, lock_depth); | ||
2775 | locked = false; | ||
2741 | if (th) { | 2776 | if (th) { |
2742 | reiserfs_write_lock(inode->i_sb); | ||
2743 | if (!update_sd) | 2777 | if (!update_sd) |
2744 | reiserfs_update_sd(th, inode); | 2778 | reiserfs_update_sd(th, inode); |
2745 | ret = reiserfs_end_persistent_transaction(th); | 2779 | ret = reiserfs_end_persistent_transaction(th); |
2746 | reiserfs_write_unlock(inode->i_sb); | ||
2747 | } | 2780 | } |
2748 | |||
2749 | goto out; | 2781 | goto out; |
2750 | } | 2782 | } |
2751 | 2783 | ||
@@ -2758,7 +2790,10 @@ int reiserfs_commit_write(struct file *f, struct page *page, | |||
2758 | int update_sd = 0; | 2790 | int update_sd = 0; |
2759 | struct reiserfs_transaction_handle *th = NULL; | 2791 | struct reiserfs_transaction_handle *th = NULL; |
2760 | 2792 | ||
2793 | reiserfs_write_unlock(inode->i_sb); | ||
2761 | reiserfs_wait_on_write_block(inode->i_sb); | 2794 | reiserfs_wait_on_write_block(inode->i_sb); |
2795 | reiserfs_write_lock(inode->i_sb); | ||
2796 | |||
2762 | if (reiserfs_transaction_running(inode->i_sb)) { | 2797 | if (reiserfs_transaction_running(inode->i_sb)) { |
2763 | th = current->journal_info; | 2798 | th = current->journal_info; |
2764 | } | 2799 | } |
@@ -2770,7 +2805,6 @@ int reiserfs_commit_write(struct file *f, struct page *page, | |||
2770 | */ | 2805 | */ |
2771 | if (pos > inode->i_size) { | 2806 | if (pos > inode->i_size) { |
2772 | struct reiserfs_transaction_handle myth; | 2807 | struct reiserfs_transaction_handle myth; |
2773 | reiserfs_write_lock(inode->i_sb); | ||
2774 | /* If the file have grown beyond the border where it | 2808 | /* If the file have grown beyond the border where it |
2775 | can have a tail, unmark it as needing a tail | 2809 | can have a tail, unmark it as needing a tail |
2776 | packing */ | 2810 | packing */ |
@@ -2781,10 +2815,9 @@ int reiserfs_commit_write(struct file *f, struct page *page, | |||
2781 | REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask; | 2815 | REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask; |
2782 | 2816 | ||
2783 | ret = journal_begin(&myth, inode->i_sb, 1); | 2817 | ret = journal_begin(&myth, inode->i_sb, 1); |
2784 | if (ret) { | 2818 | if (ret) |
2785 | reiserfs_write_unlock(inode->i_sb); | ||
2786 | goto journal_error; | 2819 | goto journal_error; |
2787 | } | 2820 | |
2788 | reiserfs_update_inode_transaction(inode); | 2821 | reiserfs_update_inode_transaction(inode); |
2789 | inode->i_size = pos; | 2822 | inode->i_size = pos; |
2790 | /* | 2823 | /* |
@@ -2796,16 +2829,13 @@ int reiserfs_commit_write(struct file *f, struct page *page, | |||
2796 | reiserfs_update_sd(&myth, inode); | 2829 | reiserfs_update_sd(&myth, inode); |
2797 | update_sd = 1; | 2830 | update_sd = 1; |
2798 | ret = journal_end(&myth, inode->i_sb, 1); | 2831 | ret = journal_end(&myth, inode->i_sb, 1); |
2799 | reiserfs_write_unlock(inode->i_sb); | ||
2800 | if (ret) | 2832 | if (ret) |
2801 | goto journal_error; | 2833 | goto journal_error; |
2802 | } | 2834 | } |
2803 | if (th) { | 2835 | if (th) { |
2804 | reiserfs_write_lock(inode->i_sb); | ||
2805 | if (!update_sd) | 2836 | if (!update_sd) |
2806 | mark_inode_dirty(inode); | 2837 | mark_inode_dirty(inode); |
2807 | ret = reiserfs_end_persistent_transaction(th); | 2838 | ret = reiserfs_end_persistent_transaction(th); |
2808 | reiserfs_write_unlock(inode->i_sb); | ||
2809 | if (ret) | 2839 | if (ret) |
2810 | goto out; | 2840 | goto out; |
2811 | } | 2841 | } |
@@ -2815,11 +2845,9 @@ int reiserfs_commit_write(struct file *f, struct page *page, | |||
2815 | 2845 | ||
2816 | journal_error: | 2846 | journal_error: |
2817 | if (th) { | 2847 | if (th) { |
2818 | reiserfs_write_lock(inode->i_sb); | ||
2819 | if (!update_sd) | 2848 | if (!update_sd) |
2820 | reiserfs_update_sd(th, inode); | 2849 | reiserfs_update_sd(th, inode); |
2821 | ret = reiserfs_end_persistent_transaction(th); | 2850 | ret = reiserfs_end_persistent_transaction(th); |
2822 | reiserfs_write_unlock(inode->i_sb); | ||
2823 | } | 2851 | } |
2824 | 2852 | ||
2825 | return ret; | 2853 | return ret; |
@@ -3040,14 +3068,17 @@ static ssize_t reiserfs_direct_IO(int rw, struct kiocb *iocb, | |||
3040 | int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) | 3068 | int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) |
3041 | { | 3069 | { |
3042 | struct inode *inode = dentry->d_inode; | 3070 | struct inode *inode = dentry->d_inode; |
3043 | int error; | ||
3044 | unsigned int ia_valid; | 3071 | unsigned int ia_valid; |
3072 | int depth; | ||
3073 | int error; | ||
3045 | 3074 | ||
3046 | /* must be turned off for recursive notify_change calls */ | 3075 | /* must be turned off for recursive notify_change calls */ |
3047 | ia_valid = attr->ia_valid &= ~(ATTR_KILL_SUID|ATTR_KILL_SGID); | 3076 | ia_valid = attr->ia_valid &= ~(ATTR_KILL_SUID|ATTR_KILL_SGID); |
3048 | 3077 | ||
3049 | reiserfs_write_lock(inode->i_sb); | 3078 | depth = reiserfs_write_lock_once(inode->i_sb); |
3050 | if (attr->ia_valid & ATTR_SIZE) { | 3079 | if (attr->ia_valid & ATTR_SIZE) { |
3080 | dquot_initialize(inode); | ||
3081 | |||
3051 | /* version 2 items will be caught by the s_maxbytes check | 3082 | /* version 2 items will be caught by the s_maxbytes check |
3052 | ** done for us in vmtruncate | 3083 | ** done for us in vmtruncate |
3053 | */ | 3084 | */ |
@@ -3109,8 +3140,7 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
3109 | jbegin_count); | 3140 | jbegin_count); |
3110 | if (error) | 3141 | if (error) |
3111 | goto out; | 3142 | goto out; |
3112 | error = | 3143 | error = dquot_transfer(inode, attr); |
3113 | vfs_dq_transfer(inode, attr) ? -EDQUOT : 0; | ||
3114 | if (error) { | 3144 | if (error) { |
3115 | journal_end(&th, inode->i_sb, | 3145 | journal_end(&th, inode->i_sb, |
3116 | jbegin_count); | 3146 | jbegin_count); |
@@ -3127,8 +3157,17 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
3127 | journal_end(&th, inode->i_sb, jbegin_count); | 3157 | journal_end(&th, inode->i_sb, jbegin_count); |
3128 | } | 3158 | } |
3129 | } | 3159 | } |
3130 | if (!error) | 3160 | if (!error) { |
3161 | /* | ||
3162 | * Relax the lock here, as it might truncate the | ||
3163 | * inode pages and wait for inode pages locks. | ||
3164 | * To release such page lock, the owner needs the | ||
3165 | * reiserfs lock | ||
3166 | */ | ||
3167 | reiserfs_write_unlock_once(inode->i_sb, depth); | ||
3131 | error = inode_setattr(inode, attr); | 3168 | error = inode_setattr(inode, attr); |
3169 | depth = reiserfs_write_lock_once(inode->i_sb); | ||
3170 | } | ||
3132 | } | 3171 | } |
3133 | 3172 | ||
3134 | if (!error && reiserfs_posixacl(inode->i_sb)) { | 3173 | if (!error && reiserfs_posixacl(inode->i_sb)) { |
@@ -3137,7 +3176,8 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
3137 | } | 3176 | } |
3138 | 3177 | ||
3139 | out: | 3178 | out: |
3140 | reiserfs_write_unlock(inode->i_sb); | 3179 | reiserfs_write_unlock_once(inode->i_sb, depth); |
3180 | |||
3141 | return error; | 3181 | return error; |
3142 | } | 3182 | } |
3143 | 3183 | ||