diff options
Diffstat (limited to 'fs/ext3/inode.c')
-rw-r--r-- | fs/ext3/inode.c | 73 |
1 files changed, 48 insertions, 25 deletions
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index 354ed3b47b30..7f920b7263a4 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c | |||
@@ -196,6 +196,9 @@ void ext3_delete_inode (struct inode * inode) | |||
196 | { | 196 | { |
197 | handle_t *handle; | 197 | handle_t *handle; |
198 | 198 | ||
199 | if (!is_bad_inode(inode)) | ||
200 | dquot_initialize(inode); | ||
201 | |||
199 | truncate_inode_pages(&inode->i_data, 0); | 202 | truncate_inode_pages(&inode->i_data, 0); |
200 | 203 | ||
201 | if (is_bad_inode(inode)) | 204 | if (is_bad_inode(inode)) |
@@ -970,7 +973,7 @@ static int ext3_get_block(struct inode *inode, sector_t iblock, | |||
970 | if (max_blocks > DIO_MAX_BLOCKS) | 973 | if (max_blocks > DIO_MAX_BLOCKS) |
971 | max_blocks = DIO_MAX_BLOCKS; | 974 | max_blocks = DIO_MAX_BLOCKS; |
972 | handle = ext3_journal_start(inode, DIO_CREDITS + | 975 | handle = ext3_journal_start(inode, DIO_CREDITS + |
973 | 2 * EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb)); | 976 | EXT3_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb)); |
974 | if (IS_ERR(handle)) { | 977 | if (IS_ERR(handle)) { |
975 | ret = PTR_ERR(handle); | 978 | ret = PTR_ERR(handle); |
976 | goto out; | 979 | goto out; |
@@ -1151,6 +1154,16 @@ static int do_journal_get_write_access(handle_t *handle, | |||
1151 | return ext3_journal_get_write_access(handle, bh); | 1154 | return ext3_journal_get_write_access(handle, bh); |
1152 | } | 1155 | } |
1153 | 1156 | ||
1157 | /* | ||
1158 | * Truncate blocks that were not used by write. We have to truncate the | ||
1159 | * pagecache as well so that corresponding buffers get properly unmapped. | ||
1160 | */ | ||
1161 | static void ext3_truncate_failed_write(struct inode *inode) | ||
1162 | { | ||
1163 | truncate_inode_pages(inode->i_mapping, inode->i_size); | ||
1164 | ext3_truncate(inode); | ||
1165 | } | ||
1166 | |||
1154 | static int ext3_write_begin(struct file *file, struct address_space *mapping, | 1167 | static int ext3_write_begin(struct file *file, struct address_space *mapping, |
1155 | loff_t pos, unsigned len, unsigned flags, | 1168 | loff_t pos, unsigned len, unsigned flags, |
1156 | struct page **pagep, void **fsdata) | 1169 | struct page **pagep, void **fsdata) |
@@ -1209,7 +1222,7 @@ write_begin_failed: | |||
1209 | unlock_page(page); | 1222 | unlock_page(page); |
1210 | page_cache_release(page); | 1223 | page_cache_release(page); |
1211 | if (pos + len > inode->i_size) | 1224 | if (pos + len > inode->i_size) |
1212 | ext3_truncate(inode); | 1225 | ext3_truncate_failed_write(inode); |
1213 | } | 1226 | } |
1214 | if (ret == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries)) | 1227 | if (ret == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries)) |
1215 | goto retry; | 1228 | goto retry; |
@@ -1304,7 +1317,7 @@ static int ext3_ordered_write_end(struct file *file, | |||
1304 | page_cache_release(page); | 1317 | page_cache_release(page); |
1305 | 1318 | ||
1306 | if (pos + len > inode->i_size) | 1319 | if (pos + len > inode->i_size) |
1307 | ext3_truncate(inode); | 1320 | ext3_truncate_failed_write(inode); |
1308 | return ret ? ret : copied; | 1321 | return ret ? ret : copied; |
1309 | } | 1322 | } |
1310 | 1323 | ||
@@ -1330,7 +1343,7 @@ static int ext3_writeback_write_end(struct file *file, | |||
1330 | page_cache_release(page); | 1343 | page_cache_release(page); |
1331 | 1344 | ||
1332 | if (pos + len > inode->i_size) | 1345 | if (pos + len > inode->i_size) |
1333 | ext3_truncate(inode); | 1346 | ext3_truncate_failed_write(inode); |
1334 | return ret ? ret : copied; | 1347 | return ret ? ret : copied; |
1335 | } | 1348 | } |
1336 | 1349 | ||
@@ -1368,7 +1381,7 @@ static int ext3_journalled_write_end(struct file *file, | |||
1368 | */ | 1381 | */ |
1369 | if (pos + len > inode->i_size && ext3_can_truncate(inode)) | 1382 | if (pos + len > inode->i_size && ext3_can_truncate(inode)) |
1370 | ext3_orphan_add(handle, inode); | 1383 | ext3_orphan_add(handle, inode); |
1371 | EXT3_I(inode)->i_state |= EXT3_STATE_JDATA; | 1384 | ext3_set_inode_state(inode, EXT3_STATE_JDATA); |
1372 | if (inode->i_size > EXT3_I(inode)->i_disksize) { | 1385 | if (inode->i_size > EXT3_I(inode)->i_disksize) { |
1373 | EXT3_I(inode)->i_disksize = inode->i_size; | 1386 | EXT3_I(inode)->i_disksize = inode->i_size; |
1374 | ret2 = ext3_mark_inode_dirty(handle, inode); | 1387 | ret2 = ext3_mark_inode_dirty(handle, inode); |
@@ -1383,7 +1396,7 @@ static int ext3_journalled_write_end(struct file *file, | |||
1383 | page_cache_release(page); | 1396 | page_cache_release(page); |
1384 | 1397 | ||
1385 | if (pos + len > inode->i_size) | 1398 | if (pos + len > inode->i_size) |
1386 | ext3_truncate(inode); | 1399 | ext3_truncate_failed_write(inode); |
1387 | return ret ? ret : copied; | 1400 | return ret ? ret : copied; |
1388 | } | 1401 | } |
1389 | 1402 | ||
@@ -1407,7 +1420,7 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block) | |||
1407 | journal_t *journal; | 1420 | journal_t *journal; |
1408 | int err; | 1421 | int err; |
1409 | 1422 | ||
1410 | if (EXT3_I(inode)->i_state & EXT3_STATE_JDATA) { | 1423 | if (ext3_test_inode_state(inode, EXT3_STATE_JDATA)) { |
1411 | /* | 1424 | /* |
1412 | * This is a REALLY heavyweight approach, but the use of | 1425 | * This is a REALLY heavyweight approach, but the use of |
1413 | * bmap on dirty files is expected to be extremely rare: | 1426 | * bmap on dirty files is expected to be extremely rare: |
@@ -1426,7 +1439,7 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block) | |||
1426 | * everything they get. | 1439 | * everything they get. |
1427 | */ | 1440 | */ |
1428 | 1441 | ||
1429 | EXT3_I(inode)->i_state &= ~EXT3_STATE_JDATA; | 1442 | ext3_clear_inode_state(inode, EXT3_STATE_JDATA); |
1430 | journal = EXT3_JOURNAL(inode); | 1443 | journal = EXT3_JOURNAL(inode); |
1431 | journal_lock_updates(journal); | 1444 | journal_lock_updates(journal); |
1432 | err = journal_flush(journal); | 1445 | err = journal_flush(journal); |
@@ -1518,6 +1531,7 @@ static int ext3_ordered_writepage(struct page *page, | |||
1518 | int err; | 1531 | int err; |
1519 | 1532 | ||
1520 | J_ASSERT(PageLocked(page)); | 1533 | J_ASSERT(PageLocked(page)); |
1534 | WARN_ON_ONCE(IS_RDONLY(inode)); | ||
1521 | 1535 | ||
1522 | /* | 1536 | /* |
1523 | * We give up here if we're reentered, because it might be for a | 1537 | * We give up here if we're reentered, because it might be for a |
@@ -1590,6 +1604,9 @@ static int ext3_writeback_writepage(struct page *page, | |||
1590 | int ret = 0; | 1604 | int ret = 0; |
1591 | int err; | 1605 | int err; |
1592 | 1606 | ||
1607 | J_ASSERT(PageLocked(page)); | ||
1608 | WARN_ON_ONCE(IS_RDONLY(inode)); | ||
1609 | |||
1593 | if (ext3_journal_current_handle()) | 1610 | if (ext3_journal_current_handle()) |
1594 | goto out_fail; | 1611 | goto out_fail; |
1595 | 1612 | ||
@@ -1632,6 +1649,9 @@ static int ext3_journalled_writepage(struct page *page, | |||
1632 | int ret = 0; | 1649 | int ret = 0; |
1633 | int err; | 1650 | int err; |
1634 | 1651 | ||
1652 | J_ASSERT(PageLocked(page)); | ||
1653 | WARN_ON_ONCE(IS_RDONLY(inode)); | ||
1654 | |||
1635 | if (ext3_journal_current_handle()) | 1655 | if (ext3_journal_current_handle()) |
1636 | goto no_write; | 1656 | goto no_write; |
1637 | 1657 | ||
@@ -1660,7 +1680,7 @@ static int ext3_journalled_writepage(struct page *page, | |||
1660 | PAGE_CACHE_SIZE, NULL, write_end_fn); | 1680 | PAGE_CACHE_SIZE, NULL, write_end_fn); |
1661 | if (ret == 0) | 1681 | if (ret == 0) |
1662 | ret = err; | 1682 | ret = err; |
1663 | EXT3_I(inode)->i_state |= EXT3_STATE_JDATA; | 1683 | ext3_set_inode_state(inode, EXT3_STATE_JDATA); |
1664 | unlock_page(page); | 1684 | unlock_page(page); |
1665 | } else { | 1685 | } else { |
1666 | /* | 1686 | /* |
@@ -1775,8 +1795,9 @@ retry: | |||
1775 | handle = ext3_journal_start(inode, 2); | 1795 | handle = ext3_journal_start(inode, 2); |
1776 | if (IS_ERR(handle)) { | 1796 | if (IS_ERR(handle)) { |
1777 | /* This is really bad luck. We've written the data | 1797 | /* This is really bad luck. We've written the data |
1778 | * but cannot extend i_size. Bail out and pretend | 1798 | * but cannot extend i_size. Truncate allocated blocks |
1779 | * the write failed... */ | 1799 | * and pretend the write failed... */ |
1800 | ext3_truncate(inode); | ||
1780 | ret = PTR_ERR(handle); | 1801 | ret = PTR_ERR(handle); |
1781 | goto out; | 1802 | goto out; |
1782 | } | 1803 | } |
@@ -2033,7 +2054,7 @@ static Indirect *ext3_find_shared(struct inode *inode, int depth, | |||
2033 | int k, err; | 2054 | int k, err; |
2034 | 2055 | ||
2035 | *top = 0; | 2056 | *top = 0; |
2036 | /* Make k index the deepest non-null offest + 1 */ | 2057 | /* Make k index the deepest non-null offset + 1 */ |
2037 | for (k = depth; k > 1 && !offsets[k-1]; k--) | 2058 | for (k = depth; k > 1 && !offsets[k-1]; k--) |
2038 | ; | 2059 | ; |
2039 | partial = ext3_get_branch(inode, k, offsets, chain, &err); | 2060 | partial = ext3_get_branch(inode, k, offsets, chain, &err); |
@@ -2392,7 +2413,7 @@ void ext3_truncate(struct inode *inode) | |||
2392 | goto out_notrans; | 2413 | goto out_notrans; |
2393 | 2414 | ||
2394 | if (inode->i_size == 0 && ext3_should_writeback_data(inode)) | 2415 | if (inode->i_size == 0 && ext3_should_writeback_data(inode)) |
2395 | ei->i_state |= EXT3_STATE_FLUSH_ON_CLOSE; | 2416 | ext3_set_inode_state(inode, EXT3_STATE_FLUSH_ON_CLOSE); |
2396 | 2417 | ||
2397 | /* | 2418 | /* |
2398 | * We have to lock the EOF page here, because lock_page() nests | 2419 | * We have to lock the EOF page here, because lock_page() nests |
@@ -2711,7 +2732,7 @@ int ext3_get_inode_loc(struct inode *inode, struct ext3_iloc *iloc) | |||
2711 | { | 2732 | { |
2712 | /* We have all inode data except xattrs in memory here. */ | 2733 | /* We have all inode data except xattrs in memory here. */ |
2713 | return __ext3_get_inode_loc(inode, iloc, | 2734 | return __ext3_get_inode_loc(inode, iloc, |
2714 | !(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)); | 2735 | !ext3_test_inode_state(inode, EXT3_STATE_XATTR)); |
2715 | } | 2736 | } |
2716 | 2737 | ||
2717 | void ext3_set_inode_flags(struct inode *inode) | 2738 | void ext3_set_inode_flags(struct inode *inode) |
@@ -2883,7 +2904,7 @@ struct inode *ext3_iget(struct super_block *sb, unsigned long ino) | |||
2883 | EXT3_GOOD_OLD_INODE_SIZE + | 2904 | EXT3_GOOD_OLD_INODE_SIZE + |
2884 | ei->i_extra_isize; | 2905 | ei->i_extra_isize; |
2885 | if (*magic == cpu_to_le32(EXT3_XATTR_MAGIC)) | 2906 | if (*magic == cpu_to_le32(EXT3_XATTR_MAGIC)) |
2886 | ei->i_state |= EXT3_STATE_XATTR; | 2907 | ext3_set_inode_state(inode, EXT3_STATE_XATTR); |
2887 | } | 2908 | } |
2888 | } else | 2909 | } else |
2889 | ei->i_extra_isize = 0; | 2910 | ei->i_extra_isize = 0; |
@@ -2945,7 +2966,7 @@ again: | |||
2945 | 2966 | ||
2946 | /* For fields not not tracking in the in-memory inode, | 2967 | /* For fields not not tracking in the in-memory inode, |
2947 | * initialise them to zero for new inodes. */ | 2968 | * initialise them to zero for new inodes. */ |
2948 | if (ei->i_state & EXT3_STATE_NEW) | 2969 | if (ext3_test_inode_state(inode, EXT3_STATE_NEW)) |
2949 | memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); | 2970 | memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); |
2950 | 2971 | ||
2951 | ext3_get_inode_flags(ei); | 2972 | ext3_get_inode_flags(ei); |
@@ -3042,7 +3063,7 @@ again: | |||
3042 | rc = ext3_journal_dirty_metadata(handle, bh); | 3063 | rc = ext3_journal_dirty_metadata(handle, bh); |
3043 | if (!err) | 3064 | if (!err) |
3044 | err = rc; | 3065 | err = rc; |
3045 | ei->i_state &= ~EXT3_STATE_NEW; | 3066 | ext3_clear_inode_state(inode, EXT3_STATE_NEW); |
3046 | 3067 | ||
3047 | atomic_set(&ei->i_sync_tid, handle->h_transaction->t_tid); | 3068 | atomic_set(&ei->i_sync_tid, handle->h_transaction->t_tid); |
3048 | out_brelse: | 3069 | out_brelse: |
@@ -3086,7 +3107,7 @@ out_brelse: | |||
3086 | * `stuff()' is running, and the new i_size will be lost. Plus the inode | 3107 | * `stuff()' is running, and the new i_size will be lost. Plus the inode |
3087 | * will no longer be on the superblock's dirty inode list. | 3108 | * will no longer be on the superblock's dirty inode list. |
3088 | */ | 3109 | */ |
3089 | int ext3_write_inode(struct inode *inode, int wait) | 3110 | int ext3_write_inode(struct inode *inode, struct writeback_control *wbc) |
3090 | { | 3111 | { |
3091 | if (current->flags & PF_MEMALLOC) | 3112 | if (current->flags & PF_MEMALLOC) |
3092 | return 0; | 3113 | return 0; |
@@ -3097,7 +3118,7 @@ int ext3_write_inode(struct inode *inode, int wait) | |||
3097 | return -EIO; | 3118 | return -EIO; |
3098 | } | 3119 | } |
3099 | 3120 | ||
3100 | if (!wait) | 3121 | if (wbc->sync_mode != WB_SYNC_ALL) |
3101 | return 0; | 3122 | return 0; |
3102 | 3123 | ||
3103 | return ext3_force_commit(inode->i_sb); | 3124 | return ext3_force_commit(inode->i_sb); |
@@ -3130,19 +3151,21 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr) | |||
3130 | if (error) | 3151 | if (error) |
3131 | return error; | 3152 | return error; |
3132 | 3153 | ||
3154 | if (ia_valid & ATTR_SIZE) | ||
3155 | dquot_initialize(inode); | ||
3133 | if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) || | 3156 | if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) || |
3134 | (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) { | 3157 | (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) { |
3135 | handle_t *handle; | 3158 | handle_t *handle; |
3136 | 3159 | ||
3137 | /* (user+group)*(old+new) structure, inode write (sb, | 3160 | /* (user+group)*(old+new) structure, inode write (sb, |
3138 | * inode block, ? - but truncate inode update has it) */ | 3161 | * inode block, ? - but truncate inode update has it) */ |
3139 | handle = ext3_journal_start(inode, 2*(EXT3_QUOTA_INIT_BLOCKS(inode->i_sb)+ | 3162 | handle = ext3_journal_start(inode, EXT3_MAXQUOTAS_INIT_BLOCKS(inode->i_sb)+ |
3140 | EXT3_QUOTA_DEL_BLOCKS(inode->i_sb))+3); | 3163 | EXT3_MAXQUOTAS_DEL_BLOCKS(inode->i_sb)+3); |
3141 | if (IS_ERR(handle)) { | 3164 | if (IS_ERR(handle)) { |
3142 | error = PTR_ERR(handle); | 3165 | error = PTR_ERR(handle); |
3143 | goto err_out; | 3166 | goto err_out; |
3144 | } | 3167 | } |
3145 | error = vfs_dq_transfer(inode, attr) ? -EDQUOT : 0; | 3168 | error = dquot_transfer(inode, attr); |
3146 | if (error) { | 3169 | if (error) { |
3147 | ext3_journal_stop(handle); | 3170 | ext3_journal_stop(handle); |
3148 | return error; | 3171 | return error; |
@@ -3227,9 +3250,9 @@ static int ext3_writepage_trans_blocks(struct inode *inode) | |||
3227 | ret = 2 * (bpp + indirects) + 2; | 3250 | ret = 2 * (bpp + indirects) + 2; |
3228 | 3251 | ||
3229 | #ifdef CONFIG_QUOTA | 3252 | #ifdef CONFIG_QUOTA |
3230 | /* We know that structure was already allocated during vfs_dq_init so | 3253 | /* We know that structure was already allocated during dquot_initialize so |
3231 | * we will be updating only the data blocks + inodes */ | 3254 | * we will be updating only the data blocks + inodes */ |
3232 | ret += 2*EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb); | 3255 | ret += EXT3_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb); |
3233 | #endif | 3256 | #endif |
3234 | 3257 | ||
3235 | return ret; | 3258 | return ret; |
@@ -3318,7 +3341,7 @@ int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode) | |||
3318 | * i_size has been changed by generic_commit_write() and we thus need | 3341 | * i_size has been changed by generic_commit_write() and we thus need |
3319 | * to include the updated inode in the current transaction. | 3342 | * to include the updated inode in the current transaction. |
3320 | * | 3343 | * |
3321 | * Also, vfs_dq_alloc_space() will always dirty the inode when blocks | 3344 | * Also, dquot_alloc_space() will always dirty the inode when blocks |
3322 | * are allocated to the file. | 3345 | * are allocated to the file. |
3323 | * | 3346 | * |
3324 | * If the inode is marked synchronous, we don't honour that here - doing | 3347 | * If the inode is marked synchronous, we don't honour that here - doing |