aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r--fs/ext4/inode.c747
1 files changed, 442 insertions, 305 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 7e91913e325b..8dbf6953845b 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -190,7 +190,7 @@ static int ext4_journal_test_restart(handle_t *handle, struct inode *inode)
190/* 190/*
191 * Called at the last iput() if i_nlink is zero. 191 * Called at the last iput() if i_nlink is zero.
192 */ 192 */
193void ext4_delete_inode (struct inode * inode) 193void ext4_delete_inode(struct inode *inode)
194{ 194{
195 handle_t *handle; 195 handle_t *handle;
196 int err; 196 int err;
@@ -330,11 +330,11 @@ static int ext4_block_to_path(struct inode *inode,
330 int final = 0; 330 int final = 0;
331 331
332 if (i_block < 0) { 332 if (i_block < 0) {
333 ext4_warning (inode->i_sb, "ext4_block_to_path", "block < 0"); 333 ext4_warning(inode->i_sb, "ext4_block_to_path", "block < 0");
334 } else if (i_block < direct_blocks) { 334 } else if (i_block < direct_blocks) {
335 offsets[n++] = i_block; 335 offsets[n++] = i_block;
336 final = direct_blocks; 336 final = direct_blocks;
337 } else if ( (i_block -= direct_blocks) < indirect_blocks) { 337 } else if ((i_block -= direct_blocks) < indirect_blocks) {
338 offsets[n++] = EXT4_IND_BLOCK; 338 offsets[n++] = EXT4_IND_BLOCK;
339 offsets[n++] = i_block; 339 offsets[n++] = i_block;
340 final = ptrs; 340 final = ptrs;
@@ -400,14 +400,14 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth,
400 400
401 *err = 0; 401 *err = 0;
402 /* i_data is not going away, no lock needed */ 402 /* i_data is not going away, no lock needed */
403 add_chain (chain, NULL, EXT4_I(inode)->i_data + *offsets); 403 add_chain(chain, NULL, EXT4_I(inode)->i_data + *offsets);
404 if (!p->key) 404 if (!p->key)
405 goto no_block; 405 goto no_block;
406 while (--depth) { 406 while (--depth) {
407 bh = sb_bread(sb, le32_to_cpu(p->key)); 407 bh = sb_bread(sb, le32_to_cpu(p->key));
408 if (!bh) 408 if (!bh)
409 goto failure; 409 goto failure;
410 add_chain(++p, bh, (__le32*)bh->b_data + *++offsets); 410 add_chain(++p, bh, (__le32 *)bh->b_data + *++offsets);
411 /* Reader: end */ 411 /* Reader: end */
412 if (!p->key) 412 if (!p->key)
413 goto no_block; 413 goto no_block;
@@ -443,7 +443,7 @@ no_block:
443static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind) 443static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
444{ 444{
445 struct ext4_inode_info *ei = EXT4_I(inode); 445 struct ext4_inode_info *ei = EXT4_I(inode);
446 __le32 *start = ind->bh ? (__le32*) ind->bh->b_data : ei->i_data; 446 __le32 *start = ind->bh ? (__le32 *) ind->bh->b_data : ei->i_data;
447 __le32 *p; 447 __le32 *p;
448 ext4_fsblk_t bg_start; 448 ext4_fsblk_t bg_start;
449 ext4_fsblk_t last_block; 449 ext4_fsblk_t last_block;
@@ -486,18 +486,9 @@ static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
486static ext4_fsblk_t ext4_find_goal(struct inode *inode, ext4_lblk_t block, 486static ext4_fsblk_t ext4_find_goal(struct inode *inode, ext4_lblk_t block,
487 Indirect *partial) 487 Indirect *partial)
488{ 488{
489 struct ext4_block_alloc_info *block_i;
490
491 block_i = EXT4_I(inode)->i_block_alloc_info;
492
493 /* 489 /*
494 * try the heuristic for sequential allocation, 490 * XXX need to get goal block from mballoc's data structures
495 * failing that at least try to get decent locality.
496 */ 491 */
497 if (block_i && (block == block_i->last_alloc_logical_block + 1)
498 && (block_i->last_alloc_physical_block != 0)) {
499 return block_i->last_alloc_physical_block + 1;
500 }
501 492
502 return ext4_find_near(inode, partial); 493 return ext4_find_near(inode, partial);
503} 494}
@@ -630,7 +621,7 @@ allocated:
630 *err = 0; 621 *err = 0;
631 return ret; 622 return ret;
632failed_out: 623failed_out:
633 for (i = 0; i <index; i++) 624 for (i = 0; i < index; i++)
634 ext4_free_blocks(handle, inode, new_blocks[i], 1, 0); 625 ext4_free_blocks(handle, inode, new_blocks[i], 1, 0);
635 return ret; 626 return ret;
636} 627}
@@ -703,7 +694,7 @@ static int ext4_alloc_branch(handle_t *handle, struct inode *inode,
703 branch[n].p = (__le32 *) bh->b_data + offsets[n]; 694 branch[n].p = (__le32 *) bh->b_data + offsets[n];
704 branch[n].key = cpu_to_le32(new_blocks[n]); 695 branch[n].key = cpu_to_le32(new_blocks[n]);
705 *branch[n].p = branch[n].key; 696 *branch[n].p = branch[n].key;
706 if ( n == indirect_blks) { 697 if (n == indirect_blks) {
707 current_block = new_blocks[n]; 698 current_block = new_blocks[n];
708 /* 699 /*
709 * End of chain, update the last new metablock of 700 * End of chain, update the last new metablock of
@@ -730,7 +721,7 @@ failed:
730 BUFFER_TRACE(branch[i].bh, "call jbd2_journal_forget"); 721 BUFFER_TRACE(branch[i].bh, "call jbd2_journal_forget");
731 ext4_journal_forget(handle, branch[i].bh); 722 ext4_journal_forget(handle, branch[i].bh);
732 } 723 }
733 for (i = 0; i <indirect_blks; i++) 724 for (i = 0; i < indirect_blks; i++)
734 ext4_free_blocks(handle, inode, new_blocks[i], 1, 0); 725 ext4_free_blocks(handle, inode, new_blocks[i], 1, 0);
735 726
736 ext4_free_blocks(handle, inode, new_blocks[i], num, 0); 727 ext4_free_blocks(handle, inode, new_blocks[i], num, 0);
@@ -757,10 +748,8 @@ static int ext4_splice_branch(handle_t *handle, struct inode *inode,
757{ 748{
758 int i; 749 int i;
759 int err = 0; 750 int err = 0;
760 struct ext4_block_alloc_info *block_i;
761 ext4_fsblk_t current_block; 751 ext4_fsblk_t current_block;
762 752
763 block_i = EXT4_I(inode)->i_block_alloc_info;
764 /* 753 /*
765 * If we're splicing into a [td]indirect block (as opposed to the 754 * If we're splicing into a [td]indirect block (as opposed to the
766 * inode) then we need to get write access to the [td]indirect block 755 * inode) then we need to get write access to the [td]indirect block
@@ -783,18 +772,7 @@ static int ext4_splice_branch(handle_t *handle, struct inode *inode,
783 if (num == 0 && blks > 1) { 772 if (num == 0 && blks > 1) {
784 current_block = le32_to_cpu(where->key) + 1; 773 current_block = le32_to_cpu(where->key) + 1;
785 for (i = 1; i < blks; i++) 774 for (i = 1; i < blks; i++)
786 *(where->p + i ) = cpu_to_le32(current_block++); 775 *(where->p + i) = cpu_to_le32(current_block++);
787 }
788
789 /*
790 * update the most recently allocated logical & physical block
791 * in i_block_alloc_info, to assist find the proper goal block for next
792 * allocation
793 */
794 if (block_i) {
795 block_i->last_alloc_logical_block = block + blks - 1;
796 block_i->last_alloc_physical_block =
797 le32_to_cpu(where[num].key) + blks - 1;
798 } 776 }
799 777
800 /* We are done with atomic stuff, now do the rest of housekeeping */ 778 /* We are done with atomic stuff, now do the rest of housekeeping */
@@ -914,12 +892,8 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
914 goto cleanup; 892 goto cleanup;
915 893
916 /* 894 /*
917 * Okay, we need to do block allocation. Lazily initialize the block 895 * Okay, we need to do block allocation.
918 * allocation info here if necessary
919 */ 896 */
920 if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info))
921 ext4_init_block_alloc_info(inode);
922
923 goal = ext4_find_goal(inode, iblock, partial); 897 goal = ext4_find_goal(inode, iblock, partial);
924 898
925 /* the number of blocks need to allocate for [d,t]indirect blocks */ 899 /* the number of blocks need to allocate for [d,t]indirect blocks */
@@ -1030,19 +1004,20 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used)
1030 BUG_ON(mdb > EXT4_I(inode)->i_reserved_meta_blocks); 1004 BUG_ON(mdb > EXT4_I(inode)->i_reserved_meta_blocks);
1031 mdb_free = EXT4_I(inode)->i_reserved_meta_blocks - mdb; 1005 mdb_free = EXT4_I(inode)->i_reserved_meta_blocks - mdb;
1032 1006
1033 /* Account for allocated meta_blocks */ 1007 if (mdb_free) {
1034 mdb_free -= EXT4_I(inode)->i_allocated_meta_blocks; 1008 /* Account for allocated meta_blocks */
1009 mdb_free -= EXT4_I(inode)->i_allocated_meta_blocks;
1035 1010
1036 /* update fs free blocks counter for truncate case */ 1011 /* update fs dirty blocks counter */
1037 percpu_counter_add(&sbi->s_freeblocks_counter, mdb_free); 1012 percpu_counter_sub(&sbi->s_dirtyblocks_counter, mdb_free);
1013 EXT4_I(inode)->i_allocated_meta_blocks = 0;
1014 EXT4_I(inode)->i_reserved_meta_blocks = mdb;
1015 }
1038 1016
1039 /* update per-inode reservations */ 1017 /* update per-inode reservations */
1040 BUG_ON(used > EXT4_I(inode)->i_reserved_data_blocks); 1018 BUG_ON(used > EXT4_I(inode)->i_reserved_data_blocks);
1041 EXT4_I(inode)->i_reserved_data_blocks -= used; 1019 EXT4_I(inode)->i_reserved_data_blocks -= used;
1042 1020
1043 BUG_ON(mdb > EXT4_I(inode)->i_reserved_meta_blocks);
1044 EXT4_I(inode)->i_reserved_meta_blocks = mdb;
1045 EXT4_I(inode)->i_allocated_meta_blocks = 0;
1046 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1021 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
1047} 1022}
1048 1023
@@ -1160,8 +1135,8 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block,
1160/* Maximum number of blocks we map for direct IO at once. */ 1135/* Maximum number of blocks we map for direct IO at once. */
1161#define DIO_MAX_BLOCKS 4096 1136#define DIO_MAX_BLOCKS 4096
1162 1137
1163static int ext4_get_block(struct inode *inode, sector_t iblock, 1138int ext4_get_block(struct inode *inode, sector_t iblock,
1164 struct buffer_head *bh_result, int create) 1139 struct buffer_head *bh_result, int create)
1165{ 1140{
1166 handle_t *handle = ext4_journal_current_handle(); 1141 handle_t *handle = ext4_journal_current_handle();
1167 int ret = 0, started = 0; 1142 int ret = 0, started = 0;
@@ -1241,7 +1216,7 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
1241 BUFFER_TRACE(bh, "call get_create_access"); 1216 BUFFER_TRACE(bh, "call get_create_access");
1242 fatal = ext4_journal_get_create_access(handle, bh); 1217 fatal = ext4_journal_get_create_access(handle, bh);
1243 if (!fatal && !buffer_uptodate(bh)) { 1218 if (!fatal && !buffer_uptodate(bh)) {
1244 memset(bh->b_data,0,inode->i_sb->s_blocksize); 1219 memset(bh->b_data, 0, inode->i_sb->s_blocksize);
1245 set_buffer_uptodate(bh); 1220 set_buffer_uptodate(bh);
1246 } 1221 }
1247 unlock_buffer(bh); 1222 unlock_buffer(bh);
@@ -1266,7 +1241,7 @@ err:
1266struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode, 1241struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode,
1267 ext4_lblk_t block, int create, int *err) 1242 ext4_lblk_t block, int create, int *err)
1268{ 1243{
1269 struct buffer_head * bh; 1244 struct buffer_head *bh;
1270 1245
1271 bh = ext4_getblk(handle, inode, block, create, err); 1246 bh = ext4_getblk(handle, inode, block, create, err);
1272 if (!bh) 1247 if (!bh)
@@ -1282,13 +1257,13 @@ struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode,
1282 return NULL; 1257 return NULL;
1283} 1258}
1284 1259
1285static int walk_page_buffers( handle_t *handle, 1260static int walk_page_buffers(handle_t *handle,
1286 struct buffer_head *head, 1261 struct buffer_head *head,
1287 unsigned from, 1262 unsigned from,
1288 unsigned to, 1263 unsigned to,
1289 int *partial, 1264 int *partial,
1290 int (*fn)( handle_t *handle, 1265 int (*fn)(handle_t *handle,
1291 struct buffer_head *bh)) 1266 struct buffer_head *bh))
1292{ 1267{
1293 struct buffer_head *bh; 1268 struct buffer_head *bh;
1294 unsigned block_start, block_end; 1269 unsigned block_start, block_end;
@@ -1296,9 +1271,9 @@ static int walk_page_buffers( handle_t *handle,
1296 int err, ret = 0; 1271 int err, ret = 0;
1297 struct buffer_head *next; 1272 struct buffer_head *next;
1298 1273
1299 for ( bh = head, block_start = 0; 1274 for (bh = head, block_start = 0;
1300 ret == 0 && (bh != head || !block_start); 1275 ret == 0 && (bh != head || !block_start);
1301 block_start = block_end, bh = next) 1276 block_start = block_end, bh = next)
1302 { 1277 {
1303 next = bh->b_this_page; 1278 next = bh->b_this_page;
1304 block_end = block_start + blocksize; 1279 block_end = block_start + blocksize;
@@ -1351,23 +1326,23 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
1351 loff_t pos, unsigned len, unsigned flags, 1326 loff_t pos, unsigned len, unsigned flags,
1352 struct page **pagep, void **fsdata) 1327 struct page **pagep, void **fsdata)
1353{ 1328{
1354 struct inode *inode = mapping->host; 1329 struct inode *inode = mapping->host;
1355 int ret, needed_blocks = ext4_writepage_trans_blocks(inode); 1330 int ret, needed_blocks = ext4_writepage_trans_blocks(inode);
1356 handle_t *handle; 1331 handle_t *handle;
1357 int retries = 0; 1332 int retries = 0;
1358 struct page *page; 1333 struct page *page;
1359 pgoff_t index; 1334 pgoff_t index;
1360 unsigned from, to; 1335 unsigned from, to;
1361 1336
1362 index = pos >> PAGE_CACHE_SHIFT; 1337 index = pos >> PAGE_CACHE_SHIFT;
1363 from = pos & (PAGE_CACHE_SIZE - 1); 1338 from = pos & (PAGE_CACHE_SIZE - 1);
1364 to = from + len; 1339 to = from + len;
1365 1340
1366retry: 1341retry:
1367 handle = ext4_journal_start(inode, needed_blocks); 1342 handle = ext4_journal_start(inode, needed_blocks);
1368 if (IS_ERR(handle)) { 1343 if (IS_ERR(handle)) {
1369 ret = PTR_ERR(handle); 1344 ret = PTR_ERR(handle);
1370 goto out; 1345 goto out;
1371 } 1346 }
1372 1347
1373 page = __grab_cache_page(mapping, index); 1348 page = __grab_cache_page(mapping, index);
@@ -1387,9 +1362,16 @@ retry:
1387 } 1362 }
1388 1363
1389 if (ret) { 1364 if (ret) {
1390 unlock_page(page); 1365 unlock_page(page);
1391 ext4_journal_stop(handle); 1366 ext4_journal_stop(handle);
1392 page_cache_release(page); 1367 page_cache_release(page);
1368 /*
1369 * block_write_begin may have instantiated a few blocks
1370 * outside i_size. Trim these off again. Don't need
1371 * i_size_read because we hold i_mutex.
1372 */
1373 if (pos + len > inode->i_size)
1374 vmtruncate(inode, inode->i_size);
1393 } 1375 }
1394 1376
1395 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) 1377 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
@@ -1426,16 +1408,18 @@ static int ext4_ordered_write_end(struct file *file,
1426 ret = ext4_jbd2_file_inode(handle, inode); 1408 ret = ext4_jbd2_file_inode(handle, inode);
1427 1409
1428 if (ret == 0) { 1410 if (ret == 0) {
1429 /*
1430 * generic_write_end() will run mark_inode_dirty() if i_size
1431 * changes. So let's piggyback the i_disksize mark_inode_dirty
1432 * into that.
1433 */
1434 loff_t new_i_size; 1411 loff_t new_i_size;
1435 1412
1436 new_i_size = pos + copied; 1413 new_i_size = pos + copied;
1437 if (new_i_size > EXT4_I(inode)->i_disksize) 1414 if (new_i_size > EXT4_I(inode)->i_disksize) {
1438 EXT4_I(inode)->i_disksize = new_i_size; 1415 ext4_update_i_disksize(inode, new_i_size);
1416 /* We need to mark inode dirty even if
1417 * new_i_size is less that inode->i_size
1418 * bu greater than i_disksize.(hint delalloc)
1419 */
1420 ext4_mark_inode_dirty(handle, inode);
1421 }
1422
1439 ret2 = generic_write_end(file, mapping, pos, len, copied, 1423 ret2 = generic_write_end(file, mapping, pos, len, copied,
1440 page, fsdata); 1424 page, fsdata);
1441 copied = ret2; 1425 copied = ret2;
@@ -1460,8 +1444,14 @@ static int ext4_writeback_write_end(struct file *file,
1460 loff_t new_i_size; 1444 loff_t new_i_size;
1461 1445
1462 new_i_size = pos + copied; 1446 new_i_size = pos + copied;
1463 if (new_i_size > EXT4_I(inode)->i_disksize) 1447 if (new_i_size > EXT4_I(inode)->i_disksize) {
1464 EXT4_I(inode)->i_disksize = new_i_size; 1448 ext4_update_i_disksize(inode, new_i_size);
1449 /* We need to mark inode dirty even if
1450 * new_i_size is less that inode->i_size
1451 * bu greater than i_disksize.(hint delalloc)
1452 */
1453 ext4_mark_inode_dirty(handle, inode);
1454 }
1465 1455
1466 ret2 = generic_write_end(file, mapping, pos, len, copied, 1456 ret2 = generic_write_end(file, mapping, pos, len, copied,
1467 page, fsdata); 1457 page, fsdata);
@@ -1486,6 +1476,7 @@ static int ext4_journalled_write_end(struct file *file,
1486 int ret = 0, ret2; 1476 int ret = 0, ret2;
1487 int partial = 0; 1477 int partial = 0;
1488 unsigned from, to; 1478 unsigned from, to;
1479 loff_t new_i_size;
1489 1480
1490 from = pos & (PAGE_CACHE_SIZE - 1); 1481 from = pos & (PAGE_CACHE_SIZE - 1);
1491 to = from + len; 1482 to = from + len;
@@ -1500,11 +1491,12 @@ static int ext4_journalled_write_end(struct file *file,
1500 to, &partial, write_end_fn); 1491 to, &partial, write_end_fn);
1501 if (!partial) 1492 if (!partial)
1502 SetPageUptodate(page); 1493 SetPageUptodate(page);
1503 if (pos+copied > inode->i_size) 1494 new_i_size = pos + copied;
1495 if (new_i_size > inode->i_size)
1504 i_size_write(inode, pos+copied); 1496 i_size_write(inode, pos+copied);
1505 EXT4_I(inode)->i_state |= EXT4_STATE_JDATA; 1497 EXT4_I(inode)->i_state |= EXT4_STATE_JDATA;
1506 if (inode->i_size > EXT4_I(inode)->i_disksize) { 1498 if (new_i_size > EXT4_I(inode)->i_disksize) {
1507 EXT4_I(inode)->i_disksize = inode->i_size; 1499 ext4_update_i_disksize(inode, new_i_size);
1508 ret2 = ext4_mark_inode_dirty(handle, inode); 1500 ret2 = ext4_mark_inode_dirty(handle, inode);
1509 if (!ret) 1501 if (!ret)
1510 ret = ret2; 1502 ret = ret2;
@@ -1521,6 +1513,7 @@ static int ext4_journalled_write_end(struct file *file,
1521 1513
1522static int ext4_da_reserve_space(struct inode *inode, int nrblocks) 1514static int ext4_da_reserve_space(struct inode *inode, int nrblocks)
1523{ 1515{
1516 int retries = 0;
1524 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 1517 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
1525 unsigned long md_needed, mdblocks, total = 0; 1518 unsigned long md_needed, mdblocks, total = 0;
1526 1519
@@ -1529,6 +1522,7 @@ static int ext4_da_reserve_space(struct inode *inode, int nrblocks)
1529 * in order to allocate nrblocks 1522 * in order to allocate nrblocks
1530 * worse case is one extent per block 1523 * worse case is one extent per block
1531 */ 1524 */
1525repeat:
1532 spin_lock(&EXT4_I(inode)->i_block_reservation_lock); 1526 spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
1533 total = EXT4_I(inode)->i_reserved_data_blocks + nrblocks; 1527 total = EXT4_I(inode)->i_reserved_data_blocks + nrblocks;
1534 mdblocks = ext4_calc_metadata_amount(inode, total); 1528 mdblocks = ext4_calc_metadata_amount(inode, total);
@@ -1537,13 +1531,14 @@ static int ext4_da_reserve_space(struct inode *inode, int nrblocks)
1537 md_needed = mdblocks - EXT4_I(inode)->i_reserved_meta_blocks; 1531 md_needed = mdblocks - EXT4_I(inode)->i_reserved_meta_blocks;
1538 total = md_needed + nrblocks; 1532 total = md_needed + nrblocks;
1539 1533
1540 if (ext4_has_free_blocks(sbi, total) < total) { 1534 if (ext4_claim_free_blocks(sbi, total)) {
1541 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1535 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
1536 if (ext4_should_retry_alloc(inode->i_sb, &retries)) {
1537 yield();
1538 goto repeat;
1539 }
1542 return -ENOSPC; 1540 return -ENOSPC;
1543 } 1541 }
1544 /* reduce fs free blocks counter */
1545 percpu_counter_sub(&sbi->s_freeblocks_counter, total);
1546
1547 EXT4_I(inode)->i_reserved_data_blocks += nrblocks; 1542 EXT4_I(inode)->i_reserved_data_blocks += nrblocks;
1548 EXT4_I(inode)->i_reserved_meta_blocks = mdblocks; 1543 EXT4_I(inode)->i_reserved_meta_blocks = mdblocks;
1549 1544
@@ -1585,8 +1580,8 @@ static void ext4_da_release_space(struct inode *inode, int to_free)
1585 1580
1586 release = to_free + mdb_free; 1581 release = to_free + mdb_free;
1587 1582
1588 /* update fs free blocks counter for truncate case */ 1583 /* update fs dirty blocks counter for truncate case */
1589 percpu_counter_add(&sbi->s_freeblocks_counter, release); 1584 percpu_counter_sub(&sbi->s_dirtyblocks_counter, release);
1590 1585
1591 /* update per-inode reservations */ 1586 /* update per-inode reservations */
1592 BUG_ON(to_free > EXT4_I(inode)->i_reserved_data_blocks); 1587 BUG_ON(to_free > EXT4_I(inode)->i_reserved_data_blocks);
@@ -1630,6 +1625,7 @@ struct mpage_da_data {
1630 struct writeback_control *wbc; 1625 struct writeback_control *wbc;
1631 int io_done; 1626 int io_done;
1632 long pages_written; 1627 long pages_written;
1628 int retval;
1633}; 1629};
1634 1630
1635/* 1631/*
@@ -1652,6 +1648,7 @@ static int mpage_da_submit_io(struct mpage_da_data *mpd)
1652 int ret = 0, err, nr_pages, i; 1648 int ret = 0, err, nr_pages, i;
1653 unsigned long index, end; 1649 unsigned long index, end;
1654 struct pagevec pvec; 1650 struct pagevec pvec;
1651 long pages_skipped;
1655 1652
1656 BUG_ON(mpd->next_page <= mpd->first_page); 1653 BUG_ON(mpd->next_page <= mpd->first_page);
1657 pagevec_init(&pvec, 0); 1654 pagevec_init(&pvec, 0);
@@ -1659,20 +1656,30 @@ static int mpage_da_submit_io(struct mpage_da_data *mpd)
1659 end = mpd->next_page - 1; 1656 end = mpd->next_page - 1;
1660 1657
1661 while (index <= end) { 1658 while (index <= end) {
1662 /* XXX: optimize tail */ 1659 /*
1663 nr_pages = pagevec_lookup(&pvec, mapping, index, PAGEVEC_SIZE); 1660 * We can use PAGECACHE_TAG_DIRTY lookup here because
1661 * even though we have cleared the dirty flag on the page
1662 * We still keep the page in the radix tree with tag
1663 * PAGECACHE_TAG_DIRTY. See clear_page_dirty_for_io.
1664 * The PAGECACHE_TAG_DIRTY is cleared in set_page_writeback
1665 * which is called via the below writepage callback.
1666 */
1667 nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
1668 PAGECACHE_TAG_DIRTY,
1669 min(end - index,
1670 (pgoff_t)PAGEVEC_SIZE-1) + 1);
1664 if (nr_pages == 0) 1671 if (nr_pages == 0)
1665 break; 1672 break;
1666 for (i = 0; i < nr_pages; i++) { 1673 for (i = 0; i < nr_pages; i++) {
1667 struct page *page = pvec.pages[i]; 1674 struct page *page = pvec.pages[i];
1668 1675
1669 index = page->index; 1676 pages_skipped = mpd->wbc->pages_skipped;
1670 if (index > end)
1671 break;
1672 index++;
1673
1674 err = mapping->a_ops->writepage(page, mpd->wbc); 1677 err = mapping->a_ops->writepage(page, mpd->wbc);
1675 if (!err) 1678 if (!err && (pages_skipped == mpd->wbc->pages_skipped))
1679 /*
1680 * have successfully written the page
1681 * without skipping the same
1682 */
1676 mpd->pages_written++; 1683 mpd->pages_written++;
1677 /* 1684 /*
1678 * In error case, we have to continue because 1685 * In error case, we have to continue because
@@ -1783,6 +1790,57 @@ static inline void __unmap_underlying_blocks(struct inode *inode,
1783 unmap_underlying_metadata(bdev, bh->b_blocknr + i); 1790 unmap_underlying_metadata(bdev, bh->b_blocknr + i);
1784} 1791}
1785 1792
1793static void ext4_da_block_invalidatepages(struct mpage_da_data *mpd,
1794 sector_t logical, long blk_cnt)
1795{
1796 int nr_pages, i;
1797 pgoff_t index, end;
1798 struct pagevec pvec;
1799 struct inode *inode = mpd->inode;
1800 struct address_space *mapping = inode->i_mapping;
1801
1802 index = logical >> (PAGE_CACHE_SHIFT - inode->i_blkbits);
1803 end = (logical + blk_cnt - 1) >>
1804 (PAGE_CACHE_SHIFT - inode->i_blkbits);
1805 while (index <= end) {
1806 nr_pages = pagevec_lookup(&pvec, mapping, index, PAGEVEC_SIZE);
1807 if (nr_pages == 0)
1808 break;
1809 for (i = 0; i < nr_pages; i++) {
1810 struct page *page = pvec.pages[i];
1811 index = page->index;
1812 if (index > end)
1813 break;
1814 index++;
1815
1816 BUG_ON(!PageLocked(page));
1817 BUG_ON(PageWriteback(page));
1818 block_invalidatepage(page, 0);
1819 ClearPageUptodate(page);
1820 unlock_page(page);
1821 }
1822 }
1823 return;
1824}
1825
1826static void ext4_print_free_blocks(struct inode *inode)
1827{
1828 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
1829 printk(KERN_EMERG "Total free blocks count %lld\n",
1830 ext4_count_free_blocks(inode->i_sb));
1831 printk(KERN_EMERG "Free/Dirty block details\n");
1832 printk(KERN_EMERG "free_blocks=%lld\n",
1833 percpu_counter_sum(&sbi->s_freeblocks_counter));
1834 printk(KERN_EMERG "dirty_blocks=%lld\n",
1835 percpu_counter_sum(&sbi->s_dirtyblocks_counter));
1836 printk(KERN_EMERG "Block reservation details\n");
1837 printk(KERN_EMERG "i_reserved_data_blocks=%lu\n",
1838 EXT4_I(inode)->i_reserved_data_blocks);
1839 printk(KERN_EMERG "i_reserved_meta_blocks=%lu\n",
1840 EXT4_I(inode)->i_reserved_meta_blocks);
1841 return;
1842}
1843
1786/* 1844/*
1787 * mpage_da_map_blocks - go through given space 1845 * mpage_da_map_blocks - go through given space
1788 * 1846 *
@@ -1792,32 +1850,69 @@ static inline void __unmap_underlying_blocks(struct inode *inode,
1792 * The function skips space we know is already mapped to disk blocks. 1850 * The function skips space we know is already mapped to disk blocks.
1793 * 1851 *
1794 */ 1852 */
1795static void mpage_da_map_blocks(struct mpage_da_data *mpd) 1853static int mpage_da_map_blocks(struct mpage_da_data *mpd)
1796{ 1854{
1797 int err = 0; 1855 int err = 0;
1798 struct buffer_head *lbh = &mpd->lbh;
1799 sector_t next = lbh->b_blocknr;
1800 struct buffer_head new; 1856 struct buffer_head new;
1857 struct buffer_head *lbh = &mpd->lbh;
1858 sector_t next;
1801 1859
1802 /* 1860 /*
1803 * We consider only non-mapped and non-allocated blocks 1861 * We consider only non-mapped and non-allocated blocks
1804 */ 1862 */
1805 if (buffer_mapped(lbh) && !buffer_delay(lbh)) 1863 if (buffer_mapped(lbh) && !buffer_delay(lbh))
1806 return; 1864 return 0;
1807
1808 new.b_state = lbh->b_state; 1865 new.b_state = lbh->b_state;
1809 new.b_blocknr = 0; 1866 new.b_blocknr = 0;
1810 new.b_size = lbh->b_size; 1867 new.b_size = lbh->b_size;
1811 1868 next = lbh->b_blocknr;
1812 /* 1869 /*
1813 * If we didn't accumulate anything 1870 * If we didn't accumulate anything
1814 * to write simply return 1871 * to write simply return
1815 */ 1872 */
1816 if (!new.b_size) 1873 if (!new.b_size)
1817 return; 1874 return 0;
1818 err = mpd->get_block(mpd->inode, next, &new, 1); 1875 err = mpd->get_block(mpd->inode, next, &new, 1);
1819 if (err) 1876 if (err) {
1820 return; 1877
1878 /* If get block returns with error
1879 * we simply return. Later writepage
1880 * will redirty the page and writepages
1881 * will find the dirty page again
1882 */
1883 if (err == -EAGAIN)
1884 return 0;
1885
1886 if (err == -ENOSPC &&
1887 ext4_count_free_blocks(mpd->inode->i_sb)) {
1888 mpd->retval = err;
1889 return 0;
1890 }
1891
1892 /*
1893 * get block failure will cause us
1894 * to loop in writepages. Because
1895 * a_ops->writepage won't be able to
1896 * make progress. The page will be redirtied
1897 * by writepage and writepages will again
1898 * try to write the same.
1899 */
1900 printk(KERN_EMERG "%s block allocation failed for inode %lu "
1901 "at logical offset %llu with max blocks "
1902 "%zd with error %d\n",
1903 __func__, mpd->inode->i_ino,
1904 (unsigned long long)next,
1905 lbh->b_size >> mpd->inode->i_blkbits, err);
1906 printk(KERN_EMERG "This should not happen.!! "
1907 "Data will be lost\n");
1908 if (err == -ENOSPC) {
1909 ext4_print_free_blocks(mpd->inode);
1910 }
1911 /* invlaidate all the pages */
1912 ext4_da_block_invalidatepages(mpd, next,
1913 lbh->b_size >> mpd->inode->i_blkbits);
1914 return err;
1915 }
1821 BUG_ON(new.b_size == 0); 1916 BUG_ON(new.b_size == 0);
1822 1917
1823 if (buffer_new(&new)) 1918 if (buffer_new(&new))
@@ -1830,7 +1925,7 @@ static void mpage_da_map_blocks(struct mpage_da_data *mpd)
1830 if (buffer_delay(lbh) || buffer_unwritten(lbh)) 1925 if (buffer_delay(lbh) || buffer_unwritten(lbh))
1831 mpage_put_bnr_to_bhs(mpd, next, &new); 1926 mpage_put_bnr_to_bhs(mpd, next, &new);
1832 1927
1833 return; 1928 return 0;
1834} 1929}
1835 1930
1836#define BH_FLAGS ((1 << BH_Uptodate) | (1 << BH_Mapped) | \ 1931#define BH_FLAGS ((1 << BH_Uptodate) | (1 << BH_Mapped) | \
@@ -1899,8 +1994,8 @@ flush_it:
1899 * We couldn't merge the block to our extent, so we 1994 * We couldn't merge the block to our extent, so we
1900 * need to flush current extent and start new one 1995 * need to flush current extent and start new one
1901 */ 1996 */
1902 mpage_da_map_blocks(mpd); 1997 if (mpage_da_map_blocks(mpd) == 0)
1903 mpage_da_submit_io(mpd); 1998 mpage_da_submit_io(mpd);
1904 mpd->io_done = 1; 1999 mpd->io_done = 1;
1905 return; 2000 return;
1906} 2001}
@@ -1942,8 +2037,8 @@ static int __mpage_da_writepage(struct page *page,
1942 * and start IO on them using writepage() 2037 * and start IO on them using writepage()
1943 */ 2038 */
1944 if (mpd->next_page != mpd->first_page) { 2039 if (mpd->next_page != mpd->first_page) {
1945 mpage_da_map_blocks(mpd); 2040 if (mpage_da_map_blocks(mpd) == 0)
1946 mpage_da_submit_io(mpd); 2041 mpage_da_submit_io(mpd);
1947 /* 2042 /*
1948 * skip rest of the page in the page_vec 2043 * skip rest of the page in the page_vec
1949 */ 2044 */
@@ -2018,39 +2113,34 @@ static int __mpage_da_writepage(struct page *page,
2018 */ 2113 */
2019static int mpage_da_writepages(struct address_space *mapping, 2114static int mpage_da_writepages(struct address_space *mapping,
2020 struct writeback_control *wbc, 2115 struct writeback_control *wbc,
2021 get_block_t get_block) 2116 struct mpage_da_data *mpd)
2022{ 2117{
2023 struct mpage_da_data mpd;
2024 long to_write;
2025 int ret; 2118 int ret;
2026 2119
2027 if (!get_block) 2120 if (!mpd->get_block)
2028 return generic_writepages(mapping, wbc); 2121 return generic_writepages(mapping, wbc);
2029 2122
2030 mpd.wbc = wbc; 2123 mpd->lbh.b_size = 0;
2031 mpd.inode = mapping->host; 2124 mpd->lbh.b_state = 0;
2032 mpd.lbh.b_size = 0; 2125 mpd->lbh.b_blocknr = 0;
2033 mpd.lbh.b_state = 0; 2126 mpd->first_page = 0;
2034 mpd.lbh.b_blocknr = 0; 2127 mpd->next_page = 0;
2035 mpd.first_page = 0; 2128 mpd->io_done = 0;
2036 mpd.next_page = 0; 2129 mpd->pages_written = 0;
2037 mpd.get_block = get_block; 2130 mpd->retval = 0;
2038 mpd.io_done = 0;
2039 mpd.pages_written = 0;
2040
2041 to_write = wbc->nr_to_write;
2042
2043 ret = write_cache_pages(mapping, wbc, __mpage_da_writepage, &mpd);
2044 2131
2132 ret = write_cache_pages(mapping, wbc, __mpage_da_writepage, mpd);
2045 /* 2133 /*
2046 * Handle last extent of pages 2134 * Handle last extent of pages
2047 */ 2135 */
2048 if (!mpd.io_done && mpd.next_page != mpd.first_page) { 2136 if (!mpd->io_done && mpd->next_page != mpd->first_page) {
2049 mpage_da_map_blocks(&mpd); 2137 if (mpage_da_map_blocks(mpd) == 0)
2050 mpage_da_submit_io(&mpd); 2138 mpage_da_submit_io(mpd);
2051 }
2052 2139
2053 wbc->nr_to_write = to_write - mpd.pages_written; 2140 mpd->io_done = 1;
2141 ret = MPAGE_DA_EXTENT_TAIL;
2142 }
2143 wbc->nr_to_write -= mpd->pages_written;
2054 return ret; 2144 return ret;
2055} 2145}
2056 2146
@@ -2103,18 +2193,24 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock,
2103 handle_t *handle = NULL; 2193 handle_t *handle = NULL;
2104 2194
2105 handle = ext4_journal_current_handle(); 2195 handle = ext4_journal_current_handle();
2106 if (!handle) { 2196 BUG_ON(!handle);
2107 ret = ext4_get_blocks_wrap(handle, inode, iblock, max_blocks, 2197 ret = ext4_get_blocks_wrap(handle, inode, iblock, max_blocks,
2108 bh_result, 0, 0, 0); 2198 bh_result, create, 0, EXT4_DELALLOC_RSVED);
2109 BUG_ON(!ret);
2110 } else {
2111 ret = ext4_get_blocks_wrap(handle, inode, iblock, max_blocks,
2112 bh_result, create, 0, EXT4_DELALLOC_RSVED);
2113 }
2114
2115 if (ret > 0) { 2199 if (ret > 0) {
2200
2116 bh_result->b_size = (ret << inode->i_blkbits); 2201 bh_result->b_size = (ret << inode->i_blkbits);
2117 2202
2203 if (ext4_should_order_data(inode)) {
2204 int retval;
2205 retval = ext4_jbd2_file_inode(handle, inode);
2206 if (retval)
2207 /*
2208 * Failed to add inode for ordered
2209 * mode. Don't update file size
2210 */
2211 return retval;
2212 }
2213
2118 /* 2214 /*
2119 * Update on-disk size along with block allocation 2215 * Update on-disk size along with block allocation
2120 * we don't use 'extend_disksize' as size may change 2216 * we don't use 'extend_disksize' as size may change
@@ -2124,18 +2220,9 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock,
2124 if (disksize > i_size_read(inode)) 2220 if (disksize > i_size_read(inode))
2125 disksize = i_size_read(inode); 2221 disksize = i_size_read(inode);
2126 if (disksize > EXT4_I(inode)->i_disksize) { 2222 if (disksize > EXT4_I(inode)->i_disksize) {
2127 /* 2223 ext4_update_i_disksize(inode, disksize);
2128 * XXX: replace with spinlock if seen contended -bzzz 2224 ret = ext4_mark_inode_dirty(handle, inode);
2129 */ 2225 return ret;
2130 down_write(&EXT4_I(inode)->i_data_sem);
2131 if (disksize > EXT4_I(inode)->i_disksize)
2132 EXT4_I(inode)->i_disksize = disksize;
2133 up_write(&EXT4_I(inode)->i_data_sem);
2134
2135 if (EXT4_I(inode)->i_disksize == disksize) {
2136 ret = ext4_mark_inode_dirty(handle, inode);
2137 return ret;
2138 }
2139 } 2226 }
2140 ret = 0; 2227 ret = 0;
2141 } 2228 }
@@ -2282,11 +2369,14 @@ static int ext4_da_writepages_trans_blocks(struct inode *inode)
2282static int ext4_da_writepages(struct address_space *mapping, 2369static int ext4_da_writepages(struct address_space *mapping,
2283 struct writeback_control *wbc) 2370 struct writeback_control *wbc)
2284{ 2371{
2372 pgoff_t index;
2373 int range_whole = 0;
2285 handle_t *handle = NULL; 2374 handle_t *handle = NULL;
2286 loff_t range_start = 0; 2375 struct mpage_da_data mpd;
2287 struct inode *inode = mapping->host; 2376 struct inode *inode = mapping->host;
2377 int no_nrwrite_index_update;
2378 long pages_written = 0, pages_skipped;
2288 int needed_blocks, ret = 0, nr_to_writebump = 0; 2379 int needed_blocks, ret = 0, nr_to_writebump = 0;
2289 long to_write, pages_skipped = 0;
2290 struct ext4_sb_info *sbi = EXT4_SB(mapping->host->i_sb); 2380 struct ext4_sb_info *sbi = EXT4_SB(mapping->host->i_sb);
2291 2381
2292 /* 2382 /*
@@ -2306,20 +2396,26 @@ static int ext4_da_writepages(struct address_space *mapping,
2306 nr_to_writebump = sbi->s_mb_stream_request - wbc->nr_to_write; 2396 nr_to_writebump = sbi->s_mb_stream_request - wbc->nr_to_write;
2307 wbc->nr_to_write = sbi->s_mb_stream_request; 2397 wbc->nr_to_write = sbi->s_mb_stream_request;
2308 } 2398 }
2399 if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
2400 range_whole = 1;
2309 2401
2310 if (!wbc->range_cyclic) 2402 if (wbc->range_cyclic)
2311 /* 2403 index = mapping->writeback_index;
2312 * If range_cyclic is not set force range_cont 2404 else
2313 * and save the old writeback_index 2405 index = wbc->range_start >> PAGE_CACHE_SHIFT;
2314 */ 2406
2315 wbc->range_cont = 1; 2407 mpd.wbc = wbc;
2408 mpd.inode = mapping->host;
2316 2409
2317 range_start = wbc->range_start; 2410 /*
2411 * we don't want write_cache_pages to update
2412 * nr_to_write and writeback_index
2413 */
2414 no_nrwrite_index_update = wbc->no_nrwrite_index_update;
2415 wbc->no_nrwrite_index_update = 1;
2318 pages_skipped = wbc->pages_skipped; 2416 pages_skipped = wbc->pages_skipped;
2319 2417
2320restart_loop: 2418 while (!ret && wbc->nr_to_write > 0) {
2321 to_write = wbc->nr_to_write;
2322 while (!ret && to_write > 0) {
2323 2419
2324 /* 2420 /*
2325 * we insert one extent at a time. So we need 2421 * we insert one extent at a time. So we need
@@ -2340,57 +2436,83 @@ restart_loop:
2340 dump_stack(); 2436 dump_stack();
2341 goto out_writepages; 2437 goto out_writepages;
2342 } 2438 }
2343 if (ext4_should_order_data(inode)) { 2439 mpd.get_block = ext4_da_get_block_write;
2344 /* 2440 ret = mpage_da_writepages(mapping, wbc, &mpd);
2345 * With ordered mode we need to add
2346 * the inode to the journal handl
2347 * when we do block allocation.
2348 */
2349 ret = ext4_jbd2_file_inode(handle, inode);
2350 if (ret) {
2351 ext4_journal_stop(handle);
2352 goto out_writepages;
2353 }
2354 }
2355 2441
2356 to_write -= wbc->nr_to_write;
2357 ret = mpage_da_writepages(mapping, wbc,
2358 ext4_da_get_block_write);
2359 ext4_journal_stop(handle); 2442 ext4_journal_stop(handle);
2360 if (ret == MPAGE_DA_EXTENT_TAIL) { 2443
2444 if (mpd.retval == -ENOSPC) {
2445 /* commit the transaction which would
2446 * free blocks released in the transaction
2447 * and try again
2448 */
2449 jbd2_journal_force_commit_nested(sbi->s_journal);
2450 wbc->pages_skipped = pages_skipped;
2451 ret = 0;
2452 } else if (ret == MPAGE_DA_EXTENT_TAIL) {
2361 /* 2453 /*
2362 * got one extent now try with 2454 * got one extent now try with
2363 * rest of the pages 2455 * rest of the pages
2364 */ 2456 */
2365 to_write += wbc->nr_to_write; 2457 pages_written += mpd.pages_written;
2458 wbc->pages_skipped = pages_skipped;
2366 ret = 0; 2459 ret = 0;
2367 } else if (wbc->nr_to_write) { 2460 } else if (wbc->nr_to_write)
2368 /* 2461 /*
2369 * There is no more writeout needed 2462 * There is no more writeout needed
2370 * or we requested for a noblocking writeout 2463 * or we requested for a noblocking writeout
2371 * and we found the device congested 2464 * and we found the device congested
2372 */ 2465 */
2373 to_write += wbc->nr_to_write;
2374 break; 2466 break;
2375 }
2376 wbc->nr_to_write = to_write;
2377 }
2378
2379 if (wbc->range_cont && (pages_skipped != wbc->pages_skipped)) {
2380 /* We skipped pages in this loop */
2381 wbc->range_start = range_start;
2382 wbc->nr_to_write = to_write +
2383 wbc->pages_skipped - pages_skipped;
2384 wbc->pages_skipped = pages_skipped;
2385 goto restart_loop;
2386 } 2467 }
2468 if (pages_skipped != wbc->pages_skipped)
2469 printk(KERN_EMERG "This should not happen leaving %s "
2470 "with nr_to_write = %ld ret = %d\n",
2471 __func__, wbc->nr_to_write, ret);
2472
2473 /* Update index */
2474 index += pages_written;
2475 if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
2476 /*
2477 * set the writeback_index so that range_cyclic
2478 * mode will write it back later
2479 */
2480 mapping->writeback_index = index;
2387 2481
2388out_writepages: 2482out_writepages:
2389 wbc->nr_to_write = to_write - nr_to_writebump; 2483 if (!no_nrwrite_index_update)
2390 wbc->range_start = range_start; 2484 wbc->no_nrwrite_index_update = 0;
2485 wbc->nr_to_write -= nr_to_writebump;
2391 return ret; 2486 return ret;
2392} 2487}
2393 2488
2489#define FALL_BACK_TO_NONDELALLOC 1
2490static int ext4_nonda_switch(struct super_block *sb)
2491{
2492 s64 free_blocks, dirty_blocks;
2493 struct ext4_sb_info *sbi = EXT4_SB(sb);
2494
2495 /*
2496 * switch to non delalloc mode if we are running low
2497 * on free block. The free block accounting via percpu
2498 * counters can get slightly wrong with FBC_BATCH getting
2499 * accumulated on each CPU without updating global counters
2500 * Delalloc need an accurate free block accounting. So switch
2501 * to non delalloc when we are near to error range.
2502 */
2503 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
2504 dirty_blocks = percpu_counter_read_positive(&sbi->s_dirtyblocks_counter);
2505 if (2 * free_blocks < 3 * dirty_blocks ||
2506 free_blocks < (dirty_blocks + EXT4_FREEBLOCKS_WATERMARK)) {
2507 /*
2508 * free block count is less that 150% of dirty blocks
2509 * or free blocks is less that watermark
2510 */
2511 return 1;
2512 }
2513 return 0;
2514}
2515
2394static int ext4_da_write_begin(struct file *file, struct address_space *mapping, 2516static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
2395 loff_t pos, unsigned len, unsigned flags, 2517 loff_t pos, unsigned len, unsigned flags,
2396 struct page **pagep, void **fsdata) 2518 struct page **pagep, void **fsdata)
@@ -2406,6 +2528,12 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
2406 from = pos & (PAGE_CACHE_SIZE - 1); 2528 from = pos & (PAGE_CACHE_SIZE - 1);
2407 to = from + len; 2529 to = from + len;
2408 2530
2531 if (ext4_nonda_switch(inode->i_sb)) {
2532 *fsdata = (void *)FALL_BACK_TO_NONDELALLOC;
2533 return ext4_write_begin(file, mapping, pos,
2534 len, flags, pagep, fsdata);
2535 }
2536 *fsdata = (void *)0;
2409retry: 2537retry:
2410 /* 2538 /*
2411 * With delayed allocation, we don't log the i_disksize update 2539 * With delayed allocation, we don't log the i_disksize update
@@ -2433,6 +2561,13 @@ retry:
2433 unlock_page(page); 2561 unlock_page(page);
2434 ext4_journal_stop(handle); 2562 ext4_journal_stop(handle);
2435 page_cache_release(page); 2563 page_cache_release(page);
2564 /*
2565 * block_write_begin may have instantiated a few blocks
2566 * outside i_size. Trim these off again. Don't need
2567 * i_size_read because we hold i_mutex.
2568 */
2569 if (pos + len > inode->i_size)
2570 vmtruncate(inode, inode->i_size);
2436 } 2571 }
2437 2572
2438 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) 2573 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
@@ -2456,7 +2591,7 @@ static int ext4_da_should_update_i_disksize(struct page *page,
2456 bh = page_buffers(page); 2591 bh = page_buffers(page);
2457 idx = offset >> inode->i_blkbits; 2592 idx = offset >> inode->i_blkbits;
2458 2593
2459 for (i=0; i < idx; i++) 2594 for (i = 0; i < idx; i++)
2460 bh = bh->b_this_page; 2595 bh = bh->b_this_page;
2461 2596
2462 if (!buffer_mapped(bh) || (buffer_delay(bh))) 2597 if (!buffer_mapped(bh) || (buffer_delay(bh)))
@@ -2474,9 +2609,22 @@ static int ext4_da_write_end(struct file *file,
2474 handle_t *handle = ext4_journal_current_handle(); 2609 handle_t *handle = ext4_journal_current_handle();
2475 loff_t new_i_size; 2610 loff_t new_i_size;
2476 unsigned long start, end; 2611 unsigned long start, end;
2612 int write_mode = (int)(unsigned long)fsdata;
2613
2614 if (write_mode == FALL_BACK_TO_NONDELALLOC) {
2615 if (ext4_should_order_data(inode)) {
2616 return ext4_ordered_write_end(file, mapping, pos,
2617 len, copied, page, fsdata);
2618 } else if (ext4_should_writeback_data(inode)) {
2619 return ext4_writeback_write_end(file, mapping, pos,
2620 len, copied, page, fsdata);
2621 } else {
2622 BUG();
2623 }
2624 }
2477 2625
2478 start = pos & (PAGE_CACHE_SIZE - 1); 2626 start = pos & (PAGE_CACHE_SIZE - 1);
2479 end = start + copied -1; 2627 end = start + copied - 1;
2480 2628
2481 /* 2629 /*
2482 * generic_write_end() will run mark_inode_dirty() if i_size 2630 * generic_write_end() will run mark_inode_dirty() if i_size
@@ -2500,6 +2648,11 @@ static int ext4_da_write_end(struct file *file,
2500 EXT4_I(inode)->i_disksize = new_i_size; 2648 EXT4_I(inode)->i_disksize = new_i_size;
2501 } 2649 }
2502 up_write(&EXT4_I(inode)->i_data_sem); 2650 up_write(&EXT4_I(inode)->i_data_sem);
2651 /* We need to mark inode dirty even if
2652 * new_i_size is less that inode->i_size
2653 * bu greater than i_disksize.(hint delalloc)
2654 */
2655 ext4_mark_inode_dirty(handle, inode);
2503 } 2656 }
2504 } 2657 }
2505 ret2 = generic_write_end(file, mapping, pos, len, copied, 2658 ret2 = generic_write_end(file, mapping, pos, len, copied,
@@ -2591,7 +2744,7 @@ static sector_t ext4_bmap(struct address_space *mapping, sector_t block)
2591 return 0; 2744 return 0;
2592 } 2745 }
2593 2746
2594 return generic_block_bmap(mapping,block,ext4_get_block); 2747 return generic_block_bmap(mapping, block, ext4_get_block);
2595} 2748}
2596 2749
2597static int bget_one(handle_t *handle, struct buffer_head *bh) 2750static int bget_one(handle_t *handle, struct buffer_head *bh)
@@ -3197,7 +3350,7 @@ static Indirect *ext4_find_shared(struct inode *inode, int depth,
3197 if (!partial->key && *partial->p) 3350 if (!partial->key && *partial->p)
3198 /* Writer: end */ 3351 /* Writer: end */
3199 goto no_top; 3352 goto no_top;
3200 for (p=partial; p>chain && all_zeroes((__le32*)p->bh->b_data,p->p); p--) 3353 for (p = partial; (p > chain) && all_zeroes((__le32 *) p->bh->b_data, p->p); p--)
3201 ; 3354 ;
3202 /* 3355 /*
3203 * OK, we've found the last block that must survive. The rest of our 3356 * OK, we've found the last block that must survive. The rest of our
@@ -3216,7 +3369,7 @@ static Indirect *ext4_find_shared(struct inode *inode, int depth,
3216 } 3369 }
3217 /* Writer: end */ 3370 /* Writer: end */
3218 3371
3219 while(partial > p) { 3372 while (partial > p) {
3220 brelse(partial->bh); 3373 brelse(partial->bh);
3221 partial--; 3374 partial--;
3222 } 3375 }
@@ -3408,9 +3561,9 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,
3408 /* This zaps the entire block. Bottom up. */ 3561 /* This zaps the entire block. Bottom up. */
3409 BUFFER_TRACE(bh, "free child branches"); 3562 BUFFER_TRACE(bh, "free child branches");
3410 ext4_free_branches(handle, inode, bh, 3563 ext4_free_branches(handle, inode, bh,
3411 (__le32*)bh->b_data, 3564 (__le32 *) bh->b_data,
3412 (__le32*)bh->b_data + addr_per_block, 3565 (__le32 *) bh->b_data + addr_per_block,
3413 depth); 3566 depth);
3414 3567
3415 /* 3568 /*
3416 * We've probably journalled the indirect block several 3569 * We've probably journalled the indirect block several
@@ -3578,7 +3731,7 @@ void ext4_truncate(struct inode *inode)
3578 */ 3731 */
3579 down_write(&ei->i_data_sem); 3732 down_write(&ei->i_data_sem);
3580 3733
3581 ext4_discard_reservation(inode); 3734 ext4_discard_preallocations(inode);
3582 3735
3583 /* 3736 /*
3584 * The orphan list entry will now protect us from any crash which 3737 * The orphan list entry will now protect us from any crash which
@@ -3673,41 +3826,6 @@ out_stop:
3673 ext4_journal_stop(handle); 3826 ext4_journal_stop(handle);
3674} 3827}
3675 3828
3676static ext4_fsblk_t ext4_get_inode_block(struct super_block *sb,
3677 unsigned long ino, struct ext4_iloc *iloc)
3678{
3679 ext4_group_t block_group;
3680 unsigned long offset;
3681 ext4_fsblk_t block;
3682 struct ext4_group_desc *gdp;
3683
3684 if (!ext4_valid_inum(sb, ino)) {
3685 /*
3686 * This error is already checked for in namei.c unless we are
3687 * looking at an NFS filehandle, in which case no error
3688 * report is needed
3689 */
3690 return 0;
3691 }
3692
3693 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
3694 gdp = ext4_get_group_desc(sb, block_group, NULL);
3695 if (!gdp)
3696 return 0;
3697
3698 /*
3699 * Figure out the offset within the block group inode table
3700 */
3701 offset = ((ino - 1) % EXT4_INODES_PER_GROUP(sb)) *
3702 EXT4_INODE_SIZE(sb);
3703 block = ext4_inode_table(sb, gdp) +
3704 (offset >> EXT4_BLOCK_SIZE_BITS(sb));
3705
3706 iloc->block_group = block_group;
3707 iloc->offset = offset & (EXT4_BLOCK_SIZE(sb) - 1);
3708 return block;
3709}
3710
3711/* 3829/*
3712 * ext4_get_inode_loc returns with an extra refcount against the inode's 3830 * ext4_get_inode_loc returns with an extra refcount against the inode's
3713 * underlying buffer_head on success. If 'in_mem' is true, we have all 3831 * underlying buffer_head on success. If 'in_mem' is true, we have all
@@ -3717,19 +3835,35 @@ static ext4_fsblk_t ext4_get_inode_block(struct super_block *sb,
3717static int __ext4_get_inode_loc(struct inode *inode, 3835static int __ext4_get_inode_loc(struct inode *inode,
3718 struct ext4_iloc *iloc, int in_mem) 3836 struct ext4_iloc *iloc, int in_mem)
3719{ 3837{
3720 ext4_fsblk_t block; 3838 struct ext4_group_desc *gdp;
3721 struct buffer_head *bh; 3839 struct buffer_head *bh;
3840 struct super_block *sb = inode->i_sb;
3841 ext4_fsblk_t block;
3842 int inodes_per_block, inode_offset;
3843
3844 iloc->bh = 0;
3845 if (!ext4_valid_inum(sb, inode->i_ino))
3846 return -EIO;
3722 3847
3723 block = ext4_get_inode_block(inode->i_sb, inode->i_ino, iloc); 3848 iloc->block_group = (inode->i_ino - 1) / EXT4_INODES_PER_GROUP(sb);
3724 if (!block) 3849 gdp = ext4_get_group_desc(sb, iloc->block_group, NULL);
3850 if (!gdp)
3725 return -EIO; 3851 return -EIO;
3726 3852
3727 bh = sb_getblk(inode->i_sb, block); 3853 /*
3854 * Figure out the offset within the block group inode table
3855 */
3856 inodes_per_block = (EXT4_BLOCK_SIZE(sb) / EXT4_INODE_SIZE(sb));
3857 inode_offset = ((inode->i_ino - 1) %
3858 EXT4_INODES_PER_GROUP(sb));
3859 block = ext4_inode_table(sb, gdp) + (inode_offset / inodes_per_block);
3860 iloc->offset = (inode_offset % inodes_per_block) * EXT4_INODE_SIZE(sb);
3861
3862 bh = sb_getblk(sb, block);
3728 if (!bh) { 3863 if (!bh) {
3729 ext4_error (inode->i_sb, "ext4_get_inode_loc", 3864 ext4_error(sb, "ext4_get_inode_loc", "unable to read "
3730 "unable to read inode block - " 3865 "inode block - inode=%lu, block=%llu",
3731 "inode=%lu, block=%llu", 3866 inode->i_ino, block);
3732 inode->i_ino, block);
3733 return -EIO; 3867 return -EIO;
3734 } 3868 }
3735 if (!buffer_uptodate(bh)) { 3869 if (!buffer_uptodate(bh)) {
@@ -3757,28 +3891,12 @@ static int __ext4_get_inode_loc(struct inode *inode,
3757 */ 3891 */
3758 if (in_mem) { 3892 if (in_mem) {
3759 struct buffer_head *bitmap_bh; 3893 struct buffer_head *bitmap_bh;
3760 struct ext4_group_desc *desc; 3894 int i, start;
3761 int inodes_per_buffer;
3762 int inode_offset, i;
3763 ext4_group_t block_group;
3764 int start;
3765
3766 block_group = (inode->i_ino - 1) /
3767 EXT4_INODES_PER_GROUP(inode->i_sb);
3768 inodes_per_buffer = bh->b_size /
3769 EXT4_INODE_SIZE(inode->i_sb);
3770 inode_offset = ((inode->i_ino - 1) %
3771 EXT4_INODES_PER_GROUP(inode->i_sb));
3772 start = inode_offset & ~(inodes_per_buffer - 1);
3773 3895
3774 /* Is the inode bitmap in cache? */ 3896 start = inode_offset & ~(inodes_per_block - 1);
3775 desc = ext4_get_group_desc(inode->i_sb,
3776 block_group, NULL);
3777 if (!desc)
3778 goto make_io;
3779 3897
3780 bitmap_bh = sb_getblk(inode->i_sb, 3898 /* Is the inode bitmap in cache? */
3781 ext4_inode_bitmap(inode->i_sb, desc)); 3899 bitmap_bh = sb_getblk(sb, ext4_inode_bitmap(sb, gdp));
3782 if (!bitmap_bh) 3900 if (!bitmap_bh)
3783 goto make_io; 3901 goto make_io;
3784 3902
@@ -3791,14 +3909,14 @@ static int __ext4_get_inode_loc(struct inode *inode,
3791 brelse(bitmap_bh); 3909 brelse(bitmap_bh);
3792 goto make_io; 3910 goto make_io;
3793 } 3911 }
3794 for (i = start; i < start + inodes_per_buffer; i++) { 3912 for (i = start; i < start + inodes_per_block; i++) {
3795 if (i == inode_offset) 3913 if (i == inode_offset)
3796 continue; 3914 continue;
3797 if (ext4_test_bit(i, bitmap_bh->b_data)) 3915 if (ext4_test_bit(i, bitmap_bh->b_data))
3798 break; 3916 break;
3799 } 3917 }
3800 brelse(bitmap_bh); 3918 brelse(bitmap_bh);
3801 if (i == start + inodes_per_buffer) { 3919 if (i == start + inodes_per_block) {
3802 /* all other inodes are free, so skip I/O */ 3920 /* all other inodes are free, so skip I/O */
3803 memset(bh->b_data, 0, bh->b_size); 3921 memset(bh->b_data, 0, bh->b_size);
3804 set_buffer_uptodate(bh); 3922 set_buffer_uptodate(bh);
@@ -3809,6 +3927,36 @@ static int __ext4_get_inode_loc(struct inode *inode,
3809 3927
3810make_io: 3928make_io:
3811 /* 3929 /*
3930 * If we need to do any I/O, try to pre-readahead extra
3931 * blocks from the inode table.
3932 */
3933 if (EXT4_SB(sb)->s_inode_readahead_blks) {
3934 ext4_fsblk_t b, end, table;
3935 unsigned num;
3936
3937 table = ext4_inode_table(sb, gdp);
3938 /* Make sure s_inode_readahead_blks is a power of 2 */
3939 while (EXT4_SB(sb)->s_inode_readahead_blks &
3940 (EXT4_SB(sb)->s_inode_readahead_blks-1))
3941 EXT4_SB(sb)->s_inode_readahead_blks =
3942 (EXT4_SB(sb)->s_inode_readahead_blks &
3943 (EXT4_SB(sb)->s_inode_readahead_blks-1));
3944 b = block & ~(EXT4_SB(sb)->s_inode_readahead_blks-1);
3945 if (table > b)
3946 b = table;
3947 end = b + EXT4_SB(sb)->s_inode_readahead_blks;
3948 num = EXT4_INODES_PER_GROUP(sb);
3949 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
3950 EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
3951 num -= le16_to_cpu(gdp->bg_itable_unused);
3952 table += num / inodes_per_block;
3953 if (end > table)
3954 end = table;
3955 while (b <= end)
3956 sb_breadahead(sb, b++);
3957 }
3958
3959 /*
3812 * There are other valid inodes in the buffer, this inode 3960 * There are other valid inodes in the buffer, this inode
3813 * has in-inode xattrs, or we don't have this inode in memory. 3961 * has in-inode xattrs, or we don't have this inode in memory.
3814 * Read the block from disk. 3962 * Read the block from disk.
@@ -3818,10 +3966,9 @@ make_io:
3818 submit_bh(READ_META, bh); 3966 submit_bh(READ_META, bh);
3819 wait_on_buffer(bh); 3967 wait_on_buffer(bh);
3820 if (!buffer_uptodate(bh)) { 3968 if (!buffer_uptodate(bh)) {
3821 ext4_error(inode->i_sb, "ext4_get_inode_loc", 3969 ext4_error(sb, __func__,
3822 "unable to read inode block - " 3970 "unable to read inode block - inode=%lu, "
3823 "inode=%lu, block=%llu", 3971 "block=%llu", inode->i_ino, block);
3824 inode->i_ino, block);
3825 brelse(bh); 3972 brelse(bh);
3826 return -EIO; 3973 return -EIO;
3827 } 3974 }
@@ -3913,11 +4060,10 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
3913 return inode; 4060 return inode;
3914 4061
3915 ei = EXT4_I(inode); 4062 ei = EXT4_I(inode);
3916#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL 4063#ifdef CONFIG_EXT4_FS_POSIX_ACL
3917 ei->i_acl = EXT4_ACL_NOT_CACHED; 4064 ei->i_acl = EXT4_ACL_NOT_CACHED;
3918 ei->i_default_acl = EXT4_ACL_NOT_CACHED; 4065 ei->i_default_acl = EXT4_ACL_NOT_CACHED;
3919#endif 4066#endif
3920 ei->i_block_alloc_info = NULL;
3921 4067
3922 ret = __ext4_get_inode_loc(inode, &iloc, 0); 4068 ret = __ext4_get_inode_loc(inode, &iloc, 0);
3923 if (ret < 0) 4069 if (ret < 0)
@@ -3927,7 +4073,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
3927 inode->i_mode = le16_to_cpu(raw_inode->i_mode); 4073 inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3928 inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low); 4074 inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3929 inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low); 4075 inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3930 if(!(test_opt (inode->i_sb, NO_UID32))) { 4076 if (!(test_opt(inode->i_sb, NO_UID32))) {
3931 inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16; 4077 inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3932 inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16; 4078 inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3933 } 4079 }
@@ -3945,7 +4091,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
3945 if (inode->i_mode == 0 || 4091 if (inode->i_mode == 0 ||
3946 !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) { 4092 !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) {
3947 /* this inode is deleted */ 4093 /* this inode is deleted */
3948 brelse (bh); 4094 brelse(bh);
3949 ret = -ESTALE; 4095 ret = -ESTALE;
3950 goto bad_inode; 4096 goto bad_inode;
3951 } 4097 }
@@ -3978,7 +4124,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
3978 ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize); 4124 ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize);
3979 if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize > 4125 if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
3980 EXT4_INODE_SIZE(inode->i_sb)) { 4126 EXT4_INODE_SIZE(inode->i_sb)) {
3981 brelse (bh); 4127 brelse(bh);
3982 ret = -EIO; 4128 ret = -EIO;
3983 goto bad_inode; 4129 goto bad_inode;
3984 } 4130 }
@@ -4031,7 +4177,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
4031 init_special_inode(inode, inode->i_mode, 4177 init_special_inode(inode, inode->i_mode,
4032 new_decode_dev(le32_to_cpu(raw_inode->i_block[1]))); 4178 new_decode_dev(le32_to_cpu(raw_inode->i_block[1])));
4033 } 4179 }
4034 brelse (iloc.bh); 4180 brelse(iloc.bh);
4035 ext4_set_inode_flags(inode); 4181 ext4_set_inode_flags(inode);
4036 unlock_new_inode(inode); 4182 unlock_new_inode(inode);
4037 return inode; 4183 return inode;
@@ -4048,7 +4194,6 @@ static int ext4_inode_blocks_set(handle_t *handle,
4048 struct inode *inode = &(ei->vfs_inode); 4194 struct inode *inode = &(ei->vfs_inode);
4049 u64 i_blocks = inode->i_blocks; 4195 u64 i_blocks = inode->i_blocks;
4050 struct super_block *sb = inode->i_sb; 4196 struct super_block *sb = inode->i_sb;
4051 int err = 0;
4052 4197
4053 if (i_blocks <= ~0U) { 4198 if (i_blocks <= ~0U) {
4054 /* 4199 /*
@@ -4058,36 +4203,27 @@ static int ext4_inode_blocks_set(handle_t *handle,
4058 raw_inode->i_blocks_lo = cpu_to_le32(i_blocks); 4203 raw_inode->i_blocks_lo = cpu_to_le32(i_blocks);
4059 raw_inode->i_blocks_high = 0; 4204 raw_inode->i_blocks_high = 0;
4060 ei->i_flags &= ~EXT4_HUGE_FILE_FL; 4205 ei->i_flags &= ~EXT4_HUGE_FILE_FL;
4061 } else if (i_blocks <= 0xffffffffffffULL) { 4206 return 0;
4207 }
4208 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE))
4209 return -EFBIG;
4210
4211 if (i_blocks <= 0xffffffffffffULL) {
4062 /* 4212 /*
4063 * i_blocks can be represented in a 48 bit variable 4213 * i_blocks can be represented in a 48 bit variable
4064 * as multiple of 512 bytes 4214 * as multiple of 512 bytes
4065 */ 4215 */
4066 err = ext4_update_rocompat_feature(handle, sb,
4067 EXT4_FEATURE_RO_COMPAT_HUGE_FILE);
4068 if (err)
4069 goto err_out;
4070 /* i_block is stored in the split 48 bit fields */
4071 raw_inode->i_blocks_lo = cpu_to_le32(i_blocks); 4216 raw_inode->i_blocks_lo = cpu_to_le32(i_blocks);
4072 raw_inode->i_blocks_high = cpu_to_le16(i_blocks >> 32); 4217 raw_inode->i_blocks_high = cpu_to_le16(i_blocks >> 32);
4073 ei->i_flags &= ~EXT4_HUGE_FILE_FL; 4218 ei->i_flags &= ~EXT4_HUGE_FILE_FL;
4074 } else { 4219 } else {
4075 /*
4076 * i_blocks should be represented in a 48 bit variable
4077 * as multiple of file system block size
4078 */
4079 err = ext4_update_rocompat_feature(handle, sb,
4080 EXT4_FEATURE_RO_COMPAT_HUGE_FILE);
4081 if (err)
4082 goto err_out;
4083 ei->i_flags |= EXT4_HUGE_FILE_FL; 4220 ei->i_flags |= EXT4_HUGE_FILE_FL;
4084 /* i_block is stored in file system block size */ 4221 /* i_block is stored in file system block size */
4085 i_blocks = i_blocks >> (inode->i_blkbits - 9); 4222 i_blocks = i_blocks >> (inode->i_blkbits - 9);
4086 raw_inode->i_blocks_lo = cpu_to_le32(i_blocks); 4223 raw_inode->i_blocks_lo = cpu_to_le32(i_blocks);
4087 raw_inode->i_blocks_high = cpu_to_le16(i_blocks >> 32); 4224 raw_inode->i_blocks_high = cpu_to_le16(i_blocks >> 32);
4088 } 4225 }
4089err_out: 4226 return 0;
4090 return err;
4091} 4227}
4092 4228
4093/* 4229/*
@@ -4113,14 +4249,14 @@ static int ext4_do_update_inode(handle_t *handle,
4113 4249
4114 ext4_get_inode_flags(ei); 4250 ext4_get_inode_flags(ei);
4115 raw_inode->i_mode = cpu_to_le16(inode->i_mode); 4251 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
4116 if(!(test_opt(inode->i_sb, NO_UID32))) { 4252 if (!(test_opt(inode->i_sb, NO_UID32))) {
4117 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid)); 4253 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
4118 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid)); 4254 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
4119/* 4255/*
4120 * Fix up interoperability with old kernels. Otherwise, old inodes get 4256 * Fix up interoperability with old kernels. Otherwise, old inodes get
4121 * re-used with the upper 16 bits of the uid/gid intact 4257 * re-used with the upper 16 bits of the uid/gid intact
4122 */ 4258 */
4123 if(!ei->i_dtime) { 4259 if (!ei->i_dtime) {
4124 raw_inode->i_uid_high = 4260 raw_inode->i_uid_high =
4125 cpu_to_le16(high_16_bits(inode->i_uid)); 4261 cpu_to_le16(high_16_bits(inode->i_uid));
4126 raw_inode->i_gid_high = 4262 raw_inode->i_gid_high =
@@ -4208,7 +4344,7 @@ static int ext4_do_update_inode(handle_t *handle,
4208 ei->i_state &= ~EXT4_STATE_NEW; 4344 ei->i_state &= ~EXT4_STATE_NEW;
4209 4345
4210out_brelse: 4346out_brelse:
4211 brelse (bh); 4347 brelse(bh);
4212 ext4_std_error(inode->i_sb, err); 4348 ext4_std_error(inode->i_sb, err);
4213 return err; 4349 return err;
4214} 4350}
@@ -4811,6 +4947,7 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct page *page)
4811 loff_t size; 4947 loff_t size;
4812 unsigned long len; 4948 unsigned long len;
4813 int ret = -EINVAL; 4949 int ret = -EINVAL;
4950 void *fsdata;
4814 struct file *file = vma->vm_file; 4951 struct file *file = vma->vm_file;
4815 struct inode *inode = file->f_path.dentry->d_inode; 4952 struct inode *inode = file->f_path.dentry->d_inode;
4816 struct address_space *mapping = inode->i_mapping; 4953 struct address_space *mapping = inode->i_mapping;
@@ -4849,11 +4986,11 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct page *page)
4849 * on the same page though 4986 * on the same page though
4850 */ 4987 */
4851 ret = mapping->a_ops->write_begin(file, mapping, page_offset(page), 4988 ret = mapping->a_ops->write_begin(file, mapping, page_offset(page),
4852 len, AOP_FLAG_UNINTERRUPTIBLE, &page, NULL); 4989 len, AOP_FLAG_UNINTERRUPTIBLE, &page, &fsdata);
4853 if (ret < 0) 4990 if (ret < 0)
4854 goto out_unlock; 4991 goto out_unlock;
4855 ret = mapping->a_ops->write_end(file, mapping, page_offset(page), 4992 ret = mapping->a_ops->write_end(file, mapping, page_offset(page),
4856 len, len, page, NULL); 4993 len, len, page, fsdata);
4857 if (ret < 0) 4994 if (ret < 0)
4858 goto out_unlock; 4995 goto out_unlock;
4859 ret = 0; 4996 ret = 0;