file.c (cc6cf827dd6858966cb5086703447cb68186650e) | file.c (f0b65f39ac505e8f1dcdaa165aa7b8c0bd6fd454) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2007 Oracle. All rights reserved. 4 */ 5 6#include <linux/fs.h> 7#include <linux/pagemap.h> 8#include <linux/time.h> --- 384 unchanged lines hidden (view full) --- 393 394 while (write_bytes > 0) { 395 size_t count = min_t(size_t, 396 PAGE_SIZE - offset, write_bytes); 397 struct page *page = prepared_pages[pg]; 398 /* 399 * Copy data from userspace to the current page 400 */ | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2007 Oracle. All rights reserved. 4 */ 5 6#include <linux/fs.h> 7#include <linux/pagemap.h> 8#include <linux/time.h> --- 384 unchanged lines hidden (view full) --- 393 394 while (write_bytes > 0) { 395 size_t count = min_t(size_t, 396 PAGE_SIZE - offset, write_bytes); 397 struct page *page = prepared_pages[pg]; 398 /* 399 * Copy data from userspace to the current page 400 */ |
401 copied = iov_iter_copy_from_user_atomic(page, i, offset, count); | 401 copied = copy_page_from_iter_atomic(page, offset, count, i); |
402 403 /* Flush processor's dcache for this page */ 404 flush_dcache_page(page); 405 406 /* 407 * if we get a partial write, we can end up with 408 * partially up to date pages. These add 409 * a lot of complexity, so make sure they don't 410 * happen by forcing this copy to be retried. 411 * 412 * The rest of the btrfs_file_write code will fall 413 * back to page at a time copies after we return 0. 414 */ | 402 403 /* Flush processor's dcache for this page */ 404 flush_dcache_page(page); 405 406 /* 407 * if we get a partial write, we can end up with 408 * partially up to date pages. These add 409 * a lot of complexity, so make sure they don't 410 * happen by forcing this copy to be retried. 411 * 412 * The rest of the btrfs_file_write code will fall 413 * back to page at a time copies after we return 0. 414 */ |
415 if (!PageUptodate(page) && copied < count) 416 copied = 0; | 415 if (unlikely(copied < count)) { 416 if (!PageUptodate(page)) { 417 iov_iter_revert(i, copied); 418 copied = 0; 419 } 420 if (!copied) 421 break; 422 } |
417 | 423 |
418 iov_iter_advance(i, copied); | |
419 write_bytes -= copied; 420 total_copied += copied; | 424 write_bytes -= copied; 425 total_copied += copied; |
421 422 /* Return to btrfs_file_write_iter to fault page */ 423 if (unlikely(copied == 0)) 424 break; 425 426 if (copied < PAGE_SIZE - offset) { 427 offset += copied; 428 } else { | 426 offset += copied; 427 if (offset == PAGE_SIZE) { |
429 pg++; 430 offset = 0; 431 } 432 } 433 return total_copied; 434} 435 436/* --- 652 unchanged lines hidden (view full) --- 1089 u64 extent_end; 1090 u64 orig_offset; 1091 u64 other_start; 1092 u64 other_end; 1093 u64 split; 1094 int del_nr = 0; 1095 int del_slot = 0; 1096 int recow; | 428 pg++; 429 offset = 0; 430 } 431 } 432 return total_copied; 433} 434 435/* --- 652 unchanged lines hidden (view full) --- 1088 u64 extent_end; 1089 u64 orig_offset; 1090 u64 other_start; 1091 u64 other_end; 1092 u64 split; 1093 int del_nr = 0; 1094 int del_slot = 0; 1095 int recow; |
1097 int ret = 0; | 1096 int ret; |
1098 u64 ino = btrfs_ino(inode); 1099 1100 path = btrfs_alloc_path(); 1101 if (!path) 1102 return -ENOMEM; 1103again: 1104 recow = 0; 1105 split = start; --- 204 unchanged lines hidden (view full) --- 1310 ret = btrfs_del_items(trans, root, path, del_slot, del_nr); 1311 if (ret < 0) { 1312 btrfs_abort_transaction(trans, ret); 1313 goto out; 1314 } 1315 } 1316out: 1317 btrfs_free_path(path); | 1097 u64 ino = btrfs_ino(inode); 1098 1099 path = btrfs_alloc_path(); 1100 if (!path) 1101 return -ENOMEM; 1102again: 1103 recow = 0; 1104 split = start; --- 204 unchanged lines hidden (view full) --- 1309 ret = btrfs_del_items(trans, root, path, del_slot, del_nr); 1310 if (ret < 0) { 1311 btrfs_abort_transaction(trans, ret); 1312 goto out; 1313 } 1314 } 1315out: 1316 btrfs_free_path(path); |
1318 return ret; | 1317 return 0; |
1319} 1320 1321/* 1322 * on error we return an unlocked page and the error value 1323 * on success we return a locked page and 0 1324 */ 1325static int prepare_uptodate_page(struct inode *inode, 1326 struct page *page, u64 pos, --- 735 unchanged lines hidden (view full) --- 2062 atomic_inc(&BTRFS_I(inode)->sync_writers); 2063 ret = btrfs_fdatawrite_range(inode, start, end); 2064 atomic_dec(&BTRFS_I(inode)->sync_writers); 2065 blk_finish_plug(&plug); 2066 2067 return ret; 2068} 2069 | 1318} 1319 1320/* 1321 * on error we return an unlocked page and the error value 1322 * on success we return a locked page and 0 1323 */ 1324static int prepare_uptodate_page(struct inode *inode, 1325 struct page *page, u64 pos, --- 735 unchanged lines hidden (view full) --- 2061 atomic_inc(&BTRFS_I(inode)->sync_writers); 2062 ret = btrfs_fdatawrite_range(inode, start, end); 2063 atomic_dec(&BTRFS_I(inode)->sync_writers); 2064 blk_finish_plug(&plug); 2065 2066 return ret; 2067} 2068 |
2070static inline bool skip_inode_logging(const struct btrfs_log_ctx *ctx) 2071{ 2072 struct btrfs_inode *inode = BTRFS_I(ctx->inode); 2073 struct btrfs_fs_info *fs_info = inode->root->fs_info; 2074 2075 if (btrfs_inode_in_log(inode, fs_info->generation) && 2076 list_empty(&ctx->ordered_extents)) 2077 return true; 2078 2079 /* 2080 * If we are doing a fast fsync we can not bail out if the inode's 2081 * last_trans is <= then the last committed transaction, because we only 2082 * update the last_trans of the inode during ordered extent completion, 2083 * and for a fast fsync we don't wait for that, we only wait for the 2084 * writeback to complete. 2085 */ 2086 if (inode->last_trans <= fs_info->last_trans_committed && 2087 (test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags) || 2088 list_empty(&ctx->ordered_extents))) 2089 return true; 2090 2091 return false; 2092} 2093 | |
2094/* 2095 * fsync call for both files and directories. This logs the inode into 2096 * the tree log instead of forcing full commits whenever possible. 2097 * 2098 * It needs to call filemap_fdatawait so that all ordered extent updates are 2099 * in the metadata btree are up to date for copying to the log. 2100 * 2101 * It drops the inode mutex before doing the tree log commit. This is an --- 102 unchanged lines hidden (view full) --- 2204 ret = filemap_fdatawait_range(inode->i_mapping, start, end); 2205 } 2206 2207 if (ret) 2208 goto out_release_extents; 2209 2210 atomic_inc(&root->log_batch); 2211 | 2069/* 2070 * fsync call for both files and directories. This logs the inode into 2071 * the tree log instead of forcing full commits whenever possible. 2072 * 2073 * It needs to call filemap_fdatawait so that all ordered extent updates are 2074 * in the metadata btree are up to date for copying to the log. 2075 * 2076 * It drops the inode mutex before doing the tree log commit. This is an --- 102 unchanged lines hidden (view full) --- 2179 ret = filemap_fdatawait_range(inode->i_mapping, start, end); 2180 } 2181 2182 if (ret) 2183 goto out_release_extents; 2184 2185 atomic_inc(&root->log_batch); 2186 |
2187 /* 2188 * If we are doing a fast fsync we can not bail out if the inode's 2189 * last_trans is <= then the last committed transaction, because we only 2190 * update the last_trans of the inode during ordered extent completion, 2191 * and for a fast fsync we don't wait for that, we only wait for the 2192 * writeback to complete. 2193 */ |
|
2212 smp_mb(); | 2194 smp_mb(); |
2213 if (skip_inode_logging(&ctx)) { | 2195 if (btrfs_inode_in_log(BTRFS_I(inode), fs_info->generation) || 2196 (BTRFS_I(inode)->last_trans <= fs_info->last_trans_committed && 2197 (full_sync || list_empty(&ctx.ordered_extents)))) { |
2214 /* 2215 * We've had everything committed since the last time we were 2216 * modified so clear this flag in case it was set for whatever 2217 * reason, it's no longer relevant. 2218 */ 2219 clear_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 2220 &BTRFS_I(inode)->runtime_flags); 2221 /* --- 1486 unchanged lines hidden --- | 2198 /* 2199 * We've had everything committed since the last time we were 2200 * modified so clear this flag in case it was set for whatever 2201 * reason, it's no longer relevant. 2202 */ 2203 clear_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 2204 &BTRFS_I(inode)->runtime_flags); 2205 /* --- 1486 unchanged lines hidden --- |