file.c (811f933df1e55615fd0bb4818f31e3868a8e6e23) | file.c (e7d4cb6bc19658646357eeff134645cd9bc3479f) |
---|---|
1/* -*- mode: c; c-basic-offset: 8; -*- 2 * vim: noexpandtab sw=8 ts=8 sts=0: 3 * 4 * file.c 5 * 6 * File open, close, extend, truncate 7 * 8 * Copyright (C) 2002, 2004 Oracle. All rights reserved. --- 507 unchanged lines hidden (view full) --- 516 u64 block; 517 u8 flags = 0; 518 519 BUG_ON(!clusters_to_add); 520 521 if (mark_unwritten) 522 flags = OCFS2_EXT_UNWRITTEN; 523 | 1/* -*- mode: c; c-basic-offset: 8; -*- 2 * vim: noexpandtab sw=8 ts=8 sts=0: 3 * 4 * file.c 5 * 6 * File open, close, extend, truncate 7 * 8 * Copyright (C) 2002, 2004 Oracle. All rights reserved. --- 507 unchanged lines hidden (view full) --- 516 u64 block; 517 u8 flags = 0; 518 519 BUG_ON(!clusters_to_add); 520 521 if (mark_unwritten) 522 flags = OCFS2_EXT_UNWRITTEN; 523 |
524 free_extents = ocfs2_num_free_extents(osb, inode, fe_bh); | 524 free_extents = ocfs2_num_free_extents(osb, inode, fe_bh, 525 OCFS2_DINODE_EXTENT); |
525 if (free_extents < 0) { 526 status = free_extents; 527 mlog_errno(status); 528 goto leave; 529 } 530 531 /* there are two cases which could cause us to EAGAIN in the 532 * we-need-more-metadata case: --- 32 unchanged lines hidden (view full) --- 565 goto leave; 566 } 567 568 block = ocfs2_clusters_to_blocks(osb->sb, bit_off); 569 mlog(0, "Allocating %u clusters at block %u for inode %llu\n", 570 num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno); 571 status = ocfs2_insert_extent(osb, handle, inode, fe_bh, 572 *logical_offset, block, num_bits, | 526 if (free_extents < 0) { 527 status = free_extents; 528 mlog_errno(status); 529 goto leave; 530 } 531 532 /* there are two cases which could cause us to EAGAIN in the 533 * we-need-more-metadata case: --- 32 unchanged lines hidden (view full) --- 566 goto leave; 567 } 568 569 block = ocfs2_clusters_to_blocks(osb->sb, bit_off); 570 mlog(0, "Allocating %u clusters at block %u for inode %llu\n", 571 num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno); 572 status = ocfs2_insert_extent(osb, handle, inode, fe_bh, 573 *logical_offset, block, num_bits, |
573 flags, meta_ac); | 574 flags, meta_ac, OCFS2_DINODE_EXTENT); |
574 if (status < 0) { 575 mlog_errno(status); 576 goto leave; 577 } 578 579 status = ocfs2_journal_dirty(handle, fe_bh); 580 if (status < 0) { 581 mlog_errno(status); --- 12 unchanged lines hidden (view full) --- 594 595leave: 596 mlog_exit(status); 597 if (reason_ret) 598 *reason_ret = reason; 599 return status; 600} 601 | 575 if (status < 0) { 576 mlog_errno(status); 577 goto leave; 578 } 579 580 status = ocfs2_journal_dirty(handle, fe_bh); 581 if (status < 0) { 582 mlog_errno(status); --- 12 unchanged lines hidden (view full) --- 595 596leave: 597 mlog_exit(status); 598 if (reason_ret) 599 *reason_ret = reason; 600 return status; 601} 602 |
602/* 603 * For a given allocation, determine which allocators will need to be 604 * accessed, and lock them, reserving the appropriate number of bits. 605 * 606 * Sparse file systems call this from ocfs2_write_begin_nolock() 607 * and ocfs2_allocate_unwritten_extents(). 608 * 609 * File systems which don't support holes call this from 610 * ocfs2_extend_allocation(). 611 */ 612int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *di_bh, 613 u32 clusters_to_add, u32 extents_to_split, 614 struct ocfs2_alloc_context **data_ac, 615 struct ocfs2_alloc_context **meta_ac) 616{ 617 int ret = 0, num_free_extents; 618 unsigned int max_recs_needed = clusters_to_add + 2 * extents_to_split; 619 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 620 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; 621 622 *meta_ac = NULL; 623 if (data_ac) 624 *data_ac = NULL; 625 626 BUG_ON(clusters_to_add != 0 && data_ac == NULL); 627 628 mlog(0, "extend inode %llu, i_size = %lld, di->i_clusters = %u, " 629 "clusters_to_add = %u, extents_to_split = %u\n", 630 (unsigned long long)OCFS2_I(inode)->ip_blkno, (long long)i_size_read(inode), 631 le32_to_cpu(di->i_clusters), clusters_to_add, extents_to_split); 632 633 num_free_extents = ocfs2_num_free_extents(osb, inode, di_bh); 634 if (num_free_extents < 0) { 635 ret = num_free_extents; 636 mlog_errno(ret); 637 goto out; 638 } 639 640 /* 641 * Sparse allocation file systems need to be more conservative 642 * with reserving room for expansion - the actual allocation 643 * happens while we've got a journal handle open so re-taking 644 * a cluster lock (because we ran out of room for another 645 * extent) will violate ordering rules. 646 * 647 * Most of the time we'll only be seeing this 1 cluster at a time 648 * anyway. 649 * 650 * Always lock for any unwritten extents - we might want to 651 * add blocks during a split. 652 */ 653 if (!num_free_extents || 654 (ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed)) { 655 ret = ocfs2_reserve_new_metadata(osb, &di->id2.i_list, meta_ac); 656 if (ret < 0) { 657 if (ret != -ENOSPC) 658 mlog_errno(ret); 659 goto out; 660 } 661 } 662 663 if (clusters_to_add == 0) 664 goto out; 665 666 ret = ocfs2_reserve_clusters(osb, clusters_to_add, data_ac); 667 if (ret < 0) { 668 if (ret != -ENOSPC) 669 mlog_errno(ret); 670 goto out; 671 } 672 673out: 674 if (ret) { 675 if (*meta_ac) { 676 ocfs2_free_alloc_context(*meta_ac); 677 *meta_ac = NULL; 678 } 679 680 /* 681 * We cannot have an error and a non null *data_ac. 682 */ 683 } 684 685 return ret; 686} 687 | |
688static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start, 689 u32 clusters_to_add, int mark_unwritten) 690{ 691 int status = 0; 692 int restart_func = 0; 693 int credits; 694 u32 prev_clusters; 695 struct buffer_head *bh = NULL; --- 24 unchanged lines hidden (view full) --- 720 OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe); 721 status = -EIO; 722 goto leave; 723 } 724 725restart_all: 726 BUG_ON(le32_to_cpu(fe->i_clusters) != OCFS2_I(inode)->ip_clusters); 727 | 603static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start, 604 u32 clusters_to_add, int mark_unwritten) 605{ 606 int status = 0; 607 int restart_func = 0; 608 int credits; 609 u32 prev_clusters; 610 struct buffer_head *bh = NULL; --- 24 unchanged lines hidden (view full) --- 635 OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe); 636 status = -EIO; 637 goto leave; 638 } 639 640restart_all: 641 BUG_ON(le32_to_cpu(fe->i_clusters) != OCFS2_I(inode)->ip_clusters); 642 |
728 status = ocfs2_lock_allocators(inode, bh, clusters_to_add, 0, &data_ac, | 643 mlog(0, "extend inode %llu, i_size = %lld, di->i_clusters = %u, " 644 "clusters_to_add = %u\n", 645 (unsigned long long)OCFS2_I(inode)->ip_blkno, 646 (long long)i_size_read(inode), le32_to_cpu(fe->i_clusters), 647 clusters_to_add); 648 status = ocfs2_lock_allocators(inode, bh, &fe->id2.i_list, 649 clusters_to_add, 0, &data_ac, |
729 &meta_ac); 730 if (status) { 731 mlog_errno(status); 732 goto leave; 733 } 734 735 credits = ocfs2_calc_extend_credits(osb->sb, &fe->id2.i_list, 736 clusters_to_add); --- 655 unchanged lines hidden (view full) --- 1392 int ret; 1393 u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos); 1394 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 1395 struct inode *tl_inode = osb->osb_tl_inode; 1396 handle_t *handle; 1397 struct ocfs2_alloc_context *meta_ac = NULL; 1398 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; 1399 | 650 &meta_ac); 651 if (status) { 652 mlog_errno(status); 653 goto leave; 654 } 655 656 credits = ocfs2_calc_extend_credits(osb->sb, &fe->id2.i_list, 657 clusters_to_add); --- 655 unchanged lines hidden (view full) --- 1313 int ret; 1314 u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos); 1315 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 1316 struct inode *tl_inode = osb->osb_tl_inode; 1317 handle_t *handle; 1318 struct ocfs2_alloc_context *meta_ac = NULL; 1319 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; 1320 |
1400 ret = ocfs2_lock_allocators(inode, di_bh, 0, 1, NULL, &meta_ac); | 1321 ret = ocfs2_lock_allocators(inode, di_bh, &di->id2.i_list, 1322 0, 1, NULL, &meta_ac); |
1401 if (ret) { 1402 mlog_errno(ret); 1403 return ret; 1404 } 1405 1406 mutex_lock(&tl_inode->i_mutex); 1407 1408 if (ocfs2_truncate_log_needs_flush(osb)) { --- 14 unchanged lines hidden (view full) --- 1423 ret = ocfs2_journal_access(handle, inode, di_bh, 1424 OCFS2_JOURNAL_ACCESS_WRITE); 1425 if (ret) { 1426 mlog_errno(ret); 1427 goto out; 1428 } 1429 1430 ret = ocfs2_remove_extent(inode, di_bh, cpos, len, handle, meta_ac, | 1323 if (ret) { 1324 mlog_errno(ret); 1325 return ret; 1326 } 1327 1328 mutex_lock(&tl_inode->i_mutex); 1329 1330 if (ocfs2_truncate_log_needs_flush(osb)) { --- 14 unchanged lines hidden (view full) --- 1345 ret = ocfs2_journal_access(handle, inode, di_bh, 1346 OCFS2_JOURNAL_ACCESS_WRITE); 1347 if (ret) { 1348 mlog_errno(ret); 1349 goto out; 1350 } 1351 1352 ret = ocfs2_remove_extent(inode, di_bh, cpos, len, handle, meta_ac, |
1431 dealloc); | 1353 dealloc, OCFS2_DINODE_EXTENT); |
1432 if (ret) { 1433 mlog_errno(ret); 1434 goto out_commit; 1435 } 1436 1437 OCFS2_I(inode)->ip_clusters -= len; 1438 di->i_clusters = cpu_to_le32(OCFS2_I(inode)->ip_clusters); 1439 --- 885 unchanged lines hidden --- | 1354 if (ret) { 1355 mlog_errno(ret); 1356 goto out_commit; 1357 } 1358 1359 OCFS2_I(inode)->ip_clusters -= len; 1360 di->i_clusters = cpu_to_le32(OCFS2_I(inode)->ip_clusters); 1361 --- 885 unchanged lines hidden --- |