diff options
Diffstat (limited to 'fs/ext3/inode.c')
| -rw-r--r-- | fs/ext3/inode.c | 143 |
1 files changed, 92 insertions, 51 deletions
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index 735f0190ec2a..5e0faf4cda79 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c | |||
| @@ -190,18 +190,28 @@ static int truncate_restart_transaction(handle_t *handle, struct inode *inode) | |||
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | /* | 192 | /* |
| 193 | * Called at the last iput() if i_nlink is zero. | 193 | * Called at inode eviction from icache |
| 194 | */ | 194 | */ |
| 195 | void ext3_delete_inode (struct inode * inode) | 195 | void ext3_evict_inode (struct inode *inode) |
| 196 | { | 196 | { |
| 197 | struct ext3_block_alloc_info *rsv; | ||
| 197 | handle_t *handle; | 198 | handle_t *handle; |
| 199 | int want_delete = 0; | ||
| 198 | 200 | ||
| 199 | if (!is_bad_inode(inode)) | 201 | if (!inode->i_nlink && !is_bad_inode(inode)) { |
| 200 | dquot_initialize(inode); | 202 | dquot_initialize(inode); |
| 203 | want_delete = 1; | ||
| 204 | } | ||
| 201 | 205 | ||
| 202 | truncate_inode_pages(&inode->i_data, 0); | 206 | truncate_inode_pages(&inode->i_data, 0); |
| 203 | 207 | ||
| 204 | if (is_bad_inode(inode)) | 208 | ext3_discard_reservation(inode); |
| 209 | rsv = EXT3_I(inode)->i_block_alloc_info; | ||
| 210 | EXT3_I(inode)->i_block_alloc_info = NULL; | ||
| 211 | if (unlikely(rsv)) | ||
| 212 | kfree(rsv); | ||
| 213 | |||
| 214 | if (!want_delete) | ||
| 205 | goto no_delete; | 215 | goto no_delete; |
| 206 | 216 | ||
| 207 | handle = start_transaction(inode); | 217 | handle = start_transaction(inode); |
| @@ -238,15 +248,22 @@ void ext3_delete_inode (struct inode * inode) | |||
| 238 | * having errors), but we can't free the inode if the mark_dirty | 248 | * having errors), but we can't free the inode if the mark_dirty |
| 239 | * fails. | 249 | * fails. |
| 240 | */ | 250 | */ |
| 241 | if (ext3_mark_inode_dirty(handle, inode)) | 251 | if (ext3_mark_inode_dirty(handle, inode)) { |
| 242 | /* If that failed, just do the required in-core inode clear. */ | 252 | /* If that failed, just dquot_drop() and be done with that */ |
| 243 | clear_inode(inode); | 253 | dquot_drop(inode); |
| 244 | else | 254 | end_writeback(inode); |
| 255 | } else { | ||
| 256 | ext3_xattr_delete_inode(handle, inode); | ||
| 257 | dquot_free_inode(inode); | ||
| 258 | dquot_drop(inode); | ||
| 259 | end_writeback(inode); | ||
| 245 | ext3_free_inode(handle, inode); | 260 | ext3_free_inode(handle, inode); |
| 261 | } | ||
| 246 | ext3_journal_stop(handle); | 262 | ext3_journal_stop(handle); |
| 247 | return; | 263 | return; |
| 248 | no_delete: | 264 | no_delete: |
| 249 | clear_inode(inode); /* We must guarantee clearing of inode... */ | 265 | end_writeback(inode); |
| 266 | dquot_drop(inode); | ||
| 250 | } | 267 | } |
| 251 | 268 | ||
| 252 | typedef struct { | 269 | typedef struct { |
| @@ -1149,9 +1166,25 @@ static int walk_page_buffers( handle_t *handle, | |||
| 1149 | static int do_journal_get_write_access(handle_t *handle, | 1166 | static int do_journal_get_write_access(handle_t *handle, |
| 1150 | struct buffer_head *bh) | 1167 | struct buffer_head *bh) |
| 1151 | { | 1168 | { |
| 1169 | int dirty = buffer_dirty(bh); | ||
| 1170 | int ret; | ||
| 1171 | |||
| 1152 | if (!buffer_mapped(bh) || buffer_freed(bh)) | 1172 | if (!buffer_mapped(bh) || buffer_freed(bh)) |
| 1153 | return 0; | 1173 | return 0; |
| 1154 | return ext3_journal_get_write_access(handle, bh); | 1174 | /* |
| 1175 | * __block_prepare_write() could have dirtied some buffers. Clean | ||
| 1176 | * the dirty bit as jbd2_journal_get_write_access() could complain | ||
| 1177 | * otherwise about fs integrity issues. Setting of the dirty bit | ||
| 1178 | * by __block_prepare_write() isn't a real problem here as we clear | ||
| 1179 | * the bit before releasing a page lock and thus writeback cannot | ||
| 1180 | * ever write the buffer. | ||
| 1181 | */ | ||
| 1182 | if (dirty) | ||
| 1183 | clear_buffer_dirty(bh); | ||
| 1184 | ret = ext3_journal_get_write_access(handle, bh); | ||
| 1185 | if (!ret && dirty) | ||
| 1186 | ret = ext3_journal_dirty_metadata(handle, bh); | ||
| 1187 | return ret; | ||
| 1155 | } | 1188 | } |
| 1156 | 1189 | ||
| 1157 | /* | 1190 | /* |
| @@ -1196,8 +1229,7 @@ retry: | |||
| 1196 | ret = PTR_ERR(handle); | 1229 | ret = PTR_ERR(handle); |
| 1197 | goto out; | 1230 | goto out; |
| 1198 | } | 1231 | } |
| 1199 | ret = block_write_begin(file, mapping, pos, len, flags, pagep, fsdata, | 1232 | ret = __block_write_begin(page, pos, len, ext3_get_block); |
| 1200 | ext3_get_block); | ||
| 1201 | if (ret) | 1233 | if (ret) |
| 1202 | goto write_begin_failed; | 1234 | goto write_begin_failed; |
| 1203 | 1235 | ||
| @@ -1625,10 +1657,7 @@ static int ext3_writeback_writepage(struct page *page, | |||
| 1625 | goto out_fail; | 1657 | goto out_fail; |
| 1626 | } | 1658 | } |
| 1627 | 1659 | ||
| 1628 | if (test_opt(inode->i_sb, NOBH) && ext3_should_writeback_data(inode)) | 1660 | ret = block_write_full_page(page, ext3_get_block, wbc); |
| 1629 | ret = nobh_writepage(page, ext3_get_block, wbc); | ||
| 1630 | else | ||
| 1631 | ret = block_write_full_page(page, ext3_get_block, wbc); | ||
| 1632 | 1661 | ||
| 1633 | err = ext3_journal_stop(handle); | 1662 | err = ext3_journal_stop(handle); |
| 1634 | if (!ret) | 1663 | if (!ret) |
| @@ -1785,6 +1814,17 @@ retry: | |||
| 1785 | ret = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, | 1814 | ret = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, |
| 1786 | offset, nr_segs, | 1815 | offset, nr_segs, |
| 1787 | ext3_get_block, NULL); | 1816 | ext3_get_block, NULL); |
| 1817 | /* | ||
| 1818 | * In case of error extending write may have instantiated a few | ||
| 1819 | * blocks outside i_size. Trim these off again. | ||
| 1820 | */ | ||
| 1821 | if (unlikely((rw & WRITE) && ret < 0)) { | ||
| 1822 | loff_t isize = i_size_read(inode); | ||
| 1823 | loff_t end = offset + iov_length(iov, nr_segs); | ||
| 1824 | |||
| 1825 | if (end > isize) | ||
| 1826 | vmtruncate(inode, isize); | ||
| 1827 | } | ||
| 1788 | if (ret == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries)) | 1828 | if (ret == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries)) |
| 1789 | goto retry; | 1829 | goto retry; |
| 1790 | 1830 | ||
| @@ -1922,17 +1962,6 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page, | |||
| 1922 | length = blocksize - (offset & (blocksize - 1)); | 1962 | length = blocksize - (offset & (blocksize - 1)); |
| 1923 | iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits); | 1963 | iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits); |
| 1924 | 1964 | ||
| 1925 | /* | ||
| 1926 | * For "nobh" option, we can only work if we don't need to | ||
| 1927 | * read-in the page - otherwise we create buffers to do the IO. | ||
| 1928 | */ | ||
| 1929 | if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) && | ||
| 1930 | ext3_should_writeback_data(inode) && PageUptodate(page)) { | ||
| 1931 | zero_user(page, offset, length); | ||
| 1932 | set_page_dirty(page); | ||
| 1933 | goto unlock; | ||
| 1934 | } | ||
| 1935 | |||
| 1936 | if (!page_has_buffers(page)) | 1965 | if (!page_has_buffers(page)) |
| 1937 | create_empty_buffers(page, blocksize, 0); | 1966 | create_empty_buffers(page, blocksize, 0); |
| 1938 | 1967 | ||
| @@ -2284,27 +2313,6 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, | |||
| 2284 | depth); | 2313 | depth); |
| 2285 | 2314 | ||
| 2286 | /* | 2315 | /* |
| 2287 | * We've probably journalled the indirect block several | ||
| 2288 | * times during the truncate. But it's no longer | ||
| 2289 | * needed and we now drop it from the transaction via | ||
| 2290 | * journal_revoke(). | ||
| 2291 | * | ||
| 2292 | * That's easy if it's exclusively part of this | ||
| 2293 | * transaction. But if it's part of the committing | ||
| 2294 | * transaction then journal_forget() will simply | ||
| 2295 | * brelse() it. That means that if the underlying | ||
| 2296 | * block is reallocated in ext3_get_block(), | ||
| 2297 | * unmap_underlying_metadata() will find this block | ||
| 2298 | * and will try to get rid of it. damn, damn. | ||
| 2299 | * | ||
| 2300 | * If this block has already been committed to the | ||
| 2301 | * journal, a revoke record will be written. And | ||
| 2302 | * revoke records must be emitted *before* clearing | ||
| 2303 | * this block's bit in the bitmaps. | ||
| 2304 | */ | ||
| 2305 | ext3_forget(handle, 1, inode, bh, bh->b_blocknr); | ||
| 2306 | |||
| 2307 | /* | ||
| 2308 | * Everything below this this pointer has been | 2316 | * Everything below this this pointer has been |
| 2309 | * released. Now let this top-of-subtree go. | 2317 | * released. Now let this top-of-subtree go. |
| 2310 | * | 2318 | * |
| @@ -2327,6 +2335,31 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, | |||
| 2327 | truncate_restart_transaction(handle, inode); | 2335 | truncate_restart_transaction(handle, inode); |
| 2328 | } | 2336 | } |
| 2329 | 2337 | ||
| 2338 | /* | ||
| 2339 | * We've probably journalled the indirect block several | ||
| 2340 | * times during the truncate. But it's no longer | ||
| 2341 | * needed and we now drop it from the transaction via | ||
| 2342 | * journal_revoke(). | ||
| 2343 | * | ||
| 2344 | * That's easy if it's exclusively part of this | ||
| 2345 | * transaction. But if it's part of the committing | ||
| 2346 | * transaction then journal_forget() will simply | ||
| 2347 | * brelse() it. That means that if the underlying | ||
| 2348 | * block is reallocated in ext3_get_block(), | ||
| 2349 | * unmap_underlying_metadata() will find this block | ||
| 2350 | * and will try to get rid of it. damn, damn. Thus | ||
| 2351 | * we don't allow a block to be reallocated until | ||
| 2352 | * a transaction freeing it has fully committed. | ||
| 2353 | * | ||
| 2354 | * We also have to make sure journal replay after a | ||
| 2355 | * crash does not overwrite non-journaled data blocks | ||
| 2356 | * with old metadata when the block got reallocated for | ||
| 2357 | * data. Thus we have to store a revoke record for a | ||
| 2358 | * block in the same transaction in which we free the | ||
| 2359 | * block. | ||
| 2360 | */ | ||
| 2361 | ext3_forget(handle, 1, inode, bh, bh->b_blocknr); | ||
| 2362 | |||
| 2330 | ext3_free_blocks(handle, inode, nr, 1); | 2363 | ext3_free_blocks(handle, inode, nr, 1); |
| 2331 | 2364 | ||
| 2332 | if (parent_bh) { | 2365 | if (parent_bh) { |
| @@ -2554,7 +2587,7 @@ out_stop: | |||
| 2554 | * If this was a simple ftruncate(), and the file will remain alive | 2587 | * If this was a simple ftruncate(), and the file will remain alive |
| 2555 | * then we need to clear up the orphan record which we created above. | 2588 | * then we need to clear up the orphan record which we created above. |
| 2556 | * However, if this was a real unlink then we were called by | 2589 | * However, if this was a real unlink then we were called by |
| 2557 | * ext3_delete_inode(), and we allow that function to clean up the | 2590 | * ext3_evict_inode(), and we allow that function to clean up the |
| 2558 | * orphan info for us. | 2591 | * orphan info for us. |
| 2559 | */ | 2592 | */ |
| 2560 | if (inode->i_nlink) | 2593 | if (inode->i_nlink) |
| @@ -3198,9 +3231,17 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr) | |||
| 3198 | ext3_journal_stop(handle); | 3231 | ext3_journal_stop(handle); |
| 3199 | } | 3232 | } |
| 3200 | 3233 | ||
| 3201 | rc = inode_setattr(inode, attr); | 3234 | if ((attr->ia_valid & ATTR_SIZE) && |
| 3235 | attr->ia_size != i_size_read(inode)) { | ||
| 3236 | rc = vmtruncate(inode, attr->ia_size); | ||
| 3237 | if (rc) | ||
| 3238 | goto err_out; | ||
| 3239 | } | ||
| 3240 | |||
| 3241 | setattr_copy(inode, attr); | ||
| 3242 | mark_inode_dirty(inode); | ||
| 3202 | 3243 | ||
| 3203 | if (!rc && (ia_valid & ATTR_MODE)) | 3244 | if (ia_valid & ATTR_MODE) |
| 3204 | rc = ext3_acl_chmod(inode); | 3245 | rc = ext3_acl_chmod(inode); |
| 3205 | 3246 | ||
| 3206 | err_out: | 3247 | err_out: |
