file.c (6da6abae027e2dbc59bca5f4168b0760f25068c7) file.c (1832a6d5ee3b1af61001cadba9e10da9e91af4a4)
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 293 unchanged lines hidden (view full) ---

302 * either allocate an extent for the new bytes or setup the key
303 * to show we are doing inline data in the extent
304 */
305 inline_size = end_pos;
306 if (isize >= BTRFS_MAX_INLINE_DATA_SIZE(root) ||
307 inline_size > 32768 ||
308 inline_size >= BTRFS_MAX_INLINE_DATA_SIZE(root)) {
309 u64 last_end;
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 293 unchanged lines hidden (view full) ---

302 * either allocate an extent for the new bytes or setup the key
303 * to show we are doing inline data in the extent
304 */
305 inline_size = end_pos;
306 if (isize >= BTRFS_MAX_INLINE_DATA_SIZE(root) ||
307 inline_size > 32768 ||
308 inline_size >= BTRFS_MAX_INLINE_DATA_SIZE(root)) {
309 u64 last_end;
310 u64 existing_delalloc = 0;
310
311 for (i = 0; i < num_pages; i++) {
312 struct page *p = pages[i];
313 SetPageUptodate(p);
314 set_page_dirty(p);
315 }
316 last_end = (u64)(pages[num_pages -1]->index) <<
317 PAGE_CACHE_SHIFT;
318 last_end += PAGE_CACHE_SIZE - 1;
311
312 for (i = 0; i < num_pages; i++) {
313 struct page *p = pages[i];
314 SetPageUptodate(p);
315 set_page_dirty(p);
316 }
317 last_end = (u64)(pages[num_pages -1]->index) <<
318 PAGE_CACHE_SHIFT;
319 last_end += PAGE_CACHE_SIZE - 1;
320 if (start_pos < isize) {
321 u64 delalloc_start = start_pos;
322 existing_delalloc = count_range_bits(em_tree,
323 &delalloc_start,
324 end_of_last_block, (u64)-1,
325 EXTENT_DELALLOC);
326 }
319 set_extent_delalloc(em_tree, start_pos, end_of_last_block,
320 GFP_NOFS);
327 set_extent_delalloc(em_tree, start_pos, end_of_last_block,
328 GFP_NOFS);
329 spin_lock(&root->fs_info->delalloc_lock);
330 root->fs_info->delalloc_bytes += (end_of_last_block + 1 -
331 start_pos) - existing_delalloc;
332 spin_unlock(&root->fs_info->delalloc_lock);
321 } else {
322 u64 aligned_end;
323 /* step one, delete the existing extents in this range */
324 aligned_end = (pos + write_bytes + root->sectorsize - 1) &
325 ~((u64)root->sectorsize - 1);
326 err = btrfs_drop_extents(trans, root, inode, start_pos,
327 aligned_end, aligned_end, &hint_byte);
328 if (err)

--- 374 unchanged lines hidden (view full) ---

703
704 pos = *ppos;
705 start_pos = pos;
706
707 vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE);
708 current->backing_dev_info = inode->i_mapping->backing_dev_info;
709 err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode));
710 if (err)
333 } else {
334 u64 aligned_end;
335 /* step one, delete the existing extents in this range */
336 aligned_end = (pos + write_bytes + root->sectorsize - 1) &
337 ~((u64)root->sectorsize - 1);
338 err = btrfs_drop_extents(trans, root, inode, start_pos,
339 aligned_end, aligned_end, &hint_byte);
340 if (err)

--- 374 unchanged lines hidden (view full) ---

715
716 pos = *ppos;
717 start_pos = pos;
718
719 vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE);
720 current->backing_dev_info = inode->i_mapping->backing_dev_info;
721 err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode));
722 if (err)
711 goto out;
723 goto out_nolock;
712 if (count == 0)
724 if (count == 0)
713 goto out;
725 goto out_nolock;
714 err = remove_suid(fdentry(file));
715 if (err)
726 err = remove_suid(fdentry(file));
727 if (err)
716 goto out;
728 goto out_nolock;
717 file_update_time(file);
718
719 pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL);
720
721 mutex_lock(&inode->i_mutex);
722 first_index = pos >> PAGE_CACHE_SHIFT;
723 last_index = (pos + count) >> PAGE_CACHE_SHIFT;
724

--- 28 unchanged lines hidden (view full) ---

753 size_t write_bytes = min(count, nrptrs *
754 (size_t)PAGE_CACHE_SIZE -
755 offset);
756 size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >>
757 PAGE_CACHE_SHIFT;
758
759 WARN_ON(num_pages > nrptrs);
760 memset(pages, 0, sizeof(pages));
729 file_update_time(file);
730
731 pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL);
732
733 mutex_lock(&inode->i_mutex);
734 first_index = pos >> PAGE_CACHE_SHIFT;
735 last_index = (pos + count) >> PAGE_CACHE_SHIFT;
736

--- 28 unchanged lines hidden (view full) ---

765 size_t write_bytes = min(count, nrptrs *
766 (size_t)PAGE_CACHE_SIZE -
767 offset);
768 size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >>
769 PAGE_CACHE_SHIFT;
770
771 WARN_ON(num_pages > nrptrs);
772 memset(pages, 0, sizeof(pages));
773
774 mutex_lock(&root->fs_info->fs_mutex);
775 ret = btrfs_check_free_space(root, write_bytes, 0);
776 mutex_unlock(&root->fs_info->fs_mutex);
777 if (ret)
778 goto out;
779
761 ret = prepare_pages(root, file, pages, num_pages,
762 pos, first_index, last_index,
763 write_bytes);
764 if (ret)
765 goto out;
766
767 ret = btrfs_copy_from_user(pos, num_pages,
768 write_bytes, pages, buf);

--- 13 unchanged lines hidden (view full) ---

782 pos += write_bytes;
783 num_written += write_bytes;
784
785 balance_dirty_pages_ratelimited_nr(inode->i_mapping, num_pages);
786 if (num_pages < (root->leafsize >> PAGE_CACHE_SHIFT) + 1)
787 btrfs_btree_balance_dirty(root, 1);
788 cond_resched();
789 }
780 ret = prepare_pages(root, file, pages, num_pages,
781 pos, first_index, last_index,
782 write_bytes);
783 if (ret)
784 goto out;
785
786 ret = btrfs_copy_from_user(pos, num_pages,
787 write_bytes, pages, buf);

--- 13 unchanged lines hidden (view full) ---

801 pos += write_bytes;
802 num_written += write_bytes;
803
804 balance_dirty_pages_ratelimited_nr(inode->i_mapping, num_pages);
805 if (num_pages < (root->leafsize >> PAGE_CACHE_SHIFT) + 1)
806 btrfs_btree_balance_dirty(root, 1);
807 cond_resched();
808 }
790 mutex_unlock(&inode->i_mutex);
791out:
809out:
810 mutex_unlock(&inode->i_mutex);
811out_nolock:
792 kfree(pages);
793 if (pinned[0])
794 page_cache_release(pinned[0]);
795 if (pinned[1])
796 page_cache_release(pinned[1]);
797 *ppos = pos;
798
799 if (num_written > 0 && ((file->f_flags & O_SYNC) || IS_SYNC(inode))) {

--- 82 unchanged lines hidden ---
812 kfree(pages);
813 if (pinned[0])
814 page_cache_release(pinned[0]);
815 if (pinned[1])
816 page_cache_release(pinned[1]);
817 *ppos = pos;
818
819 if (num_written > 0 && ((file->f_flags & O_SYNC) || IS_SYNC(inode))) {

--- 82 unchanged lines hidden ---