diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-16 23:27:56 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-16 23:27:56 -0400 |
commit | 4fc8adcfec3da639da76e8314c9ccefe5bf9a045 (patch) | |
tree | e07a2dea8acf04d8bbbecd4fd3a571653ecdd953 /fs/ocfs2 | |
parent | 84588e7a5d8220446d677d7b909a20ee7a4496b9 (diff) | |
parent | aa4d86163e4e91a1ac560954a554bab417e338f4 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull third hunk of vfs changes from Al Viro:
"This contains the ->direct_IO() changes from Omar + saner
generic_write_checks() + dealing with fcntl()/{read,write}() races
(mirroring O_APPEND/O_DIRECT into iocb->ki_flags and instead of
repeatedly looking at ->f_flags, which can be changed by fcntl(2),
check ->ki_flags - which cannot) + infrastructure bits for dhowells'
d_inode annotations + Christophs switch of /dev/loop to
vfs_iter_write()"
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (30 commits)
block: loop: switch to VFS ITER_BVEC
configfs: Fix inconsistent use of file_inode() vs file->f_path.dentry->d_inode
VFS: Make pathwalk use d_is_reg() rather than S_ISREG()
VFS: Fix up debugfs to use d_is_dir() in place of S_ISDIR()
VFS: Combine inode checks with d_is_negative() and d_is_positive() in pathwalk
NFS: Don't use d_inode as a variable name
VFS: Impose ordering on accesses of d_inode and d_flags
VFS: Add owner-filesystem positive/negative dentry checks
nfs: generic_write_checks() shouldn't be done on swapout...
ocfs2: use __generic_file_write_iter()
mirror O_APPEND and O_DIRECT into iocb->ki_flags
switch generic_write_checks() to iocb and iter
ocfs2: move generic_write_checks() before the alignment checks
ocfs2_file_write_iter: stop messing with ppos
udf_file_write_iter: reorder and simplify
fuse: ->direct_IO() doesn't need generic_write_checks()
ext4_file_write_iter: move generic_write_checks() up
xfs_file_aio_write_checks: switch to iocb/iov_iter
generic_write_checks(): drop isblk argument
blkdev_write_iter: expand generic_file_checks() call in there
...
Diffstat (limited to 'fs/ocfs2')
-rw-r--r-- | fs/ocfs2/aops.c | 22 | ||||
-rw-r--r-- | fs/ocfs2/file.c | 124 |
2 files changed, 43 insertions, 103 deletions
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 8d2bc840c288..f906a250da6a 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c | |||
@@ -855,10 +855,9 @@ static ssize_t ocfs2_direct_IO_write(struct kiocb *iocb, | |||
855 | ocfs2_inode_unlock(inode, 1); | 855 | ocfs2_inode_unlock(inode, 1); |
856 | } | 856 | } |
857 | 857 | ||
858 | written = __blockdev_direct_IO(WRITE, iocb, inode, inode->i_sb->s_bdev, | 858 | written = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter, |
859 | iter, offset, | 859 | offset, ocfs2_direct_IO_get_blocks, |
860 | ocfs2_direct_IO_get_blocks, | 860 | ocfs2_dio_end_io, NULL, 0); |
861 | ocfs2_dio_end_io, NULL, 0); | ||
862 | if (unlikely(written < 0)) { | 861 | if (unlikely(written < 0)) { |
863 | loff_t i_size = i_size_read(inode); | 862 | loff_t i_size = i_size_read(inode); |
864 | 863 | ||
@@ -946,9 +945,7 @@ out: | |||
946 | return ret; | 945 | return ret; |
947 | } | 946 | } |
948 | 947 | ||
949 | static ssize_t ocfs2_direct_IO(int rw, | 948 | static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter, |
950 | struct kiocb *iocb, | ||
951 | struct iov_iter *iter, | ||
952 | loff_t offset) | 949 | loff_t offset) |
953 | { | 950 | { |
954 | struct file *file = iocb->ki_filp; | 951 | struct file *file = iocb->ki_filp; |
@@ -970,12 +967,11 @@ static ssize_t ocfs2_direct_IO(int rw, | |||
970 | if (i_size_read(inode) <= offset && !full_coherency) | 967 | if (i_size_read(inode) <= offset && !full_coherency) |
971 | return 0; | 968 | return 0; |
972 | 969 | ||
973 | if (rw == READ) | 970 | if (iov_iter_rw(iter) == READ) |
974 | return __blockdev_direct_IO(rw, iocb, inode, | 971 | return __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, |
975 | inode->i_sb->s_bdev, | 972 | iter, offset, |
976 | iter, offset, | 973 | ocfs2_direct_IO_get_blocks, |
977 | ocfs2_direct_IO_get_blocks, | 974 | ocfs2_dio_end_io, NULL, 0); |
978 | ocfs2_dio_end_io, NULL, 0); | ||
979 | else | 975 | else |
980 | return ocfs2_direct_IO_write(iocb, iter, offset); | 976 | return ocfs2_direct_IO_write(iocb, iter, offset); |
981 | } | 977 | } |
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 8c48e989beba..913fc250d85a 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c | |||
@@ -2106,7 +2106,7 @@ out: | |||
2106 | } | 2106 | } |
2107 | 2107 | ||
2108 | static int ocfs2_prepare_inode_for_write(struct file *file, | 2108 | static int ocfs2_prepare_inode_for_write(struct file *file, |
2109 | loff_t *ppos, | 2109 | loff_t pos, |
2110 | size_t count, | 2110 | size_t count, |
2111 | int appending, | 2111 | int appending, |
2112 | int *direct_io, | 2112 | int *direct_io, |
@@ -2115,7 +2115,7 @@ static int ocfs2_prepare_inode_for_write(struct file *file, | |||
2115 | int ret = 0, meta_level = 0; | 2115 | int ret = 0, meta_level = 0; |
2116 | struct dentry *dentry = file->f_path.dentry; | 2116 | struct dentry *dentry = file->f_path.dentry; |
2117 | struct inode *inode = dentry->d_inode; | 2117 | struct inode *inode = dentry->d_inode; |
2118 | loff_t saved_pos = 0, end; | 2118 | loff_t end; |
2119 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 2119 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
2120 | int full_coherency = !(osb->s_mount_opt & | 2120 | int full_coherency = !(osb->s_mount_opt & |
2121 | OCFS2_MOUNT_COHERENCY_BUFFERED); | 2121 | OCFS2_MOUNT_COHERENCY_BUFFERED); |
@@ -2155,23 +2155,16 @@ static int ocfs2_prepare_inode_for_write(struct file *file, | |||
2155 | } | 2155 | } |
2156 | } | 2156 | } |
2157 | 2157 | ||
2158 | /* work on a copy of ppos until we're sure that we won't have | 2158 | end = pos + count; |
2159 | * to recalculate it due to relocking. */ | ||
2160 | if (appending) | ||
2161 | saved_pos = i_size_read(inode); | ||
2162 | else | ||
2163 | saved_pos = *ppos; | ||
2164 | |||
2165 | end = saved_pos + count; | ||
2166 | 2159 | ||
2167 | ret = ocfs2_check_range_for_refcount(inode, saved_pos, count); | 2160 | ret = ocfs2_check_range_for_refcount(inode, pos, count); |
2168 | if (ret == 1) { | 2161 | if (ret == 1) { |
2169 | ocfs2_inode_unlock(inode, meta_level); | 2162 | ocfs2_inode_unlock(inode, meta_level); |
2170 | meta_level = -1; | 2163 | meta_level = -1; |
2171 | 2164 | ||
2172 | ret = ocfs2_prepare_inode_for_refcount(inode, | 2165 | ret = ocfs2_prepare_inode_for_refcount(inode, |
2173 | file, | 2166 | file, |
2174 | saved_pos, | 2167 | pos, |
2175 | count, | 2168 | count, |
2176 | &meta_level); | 2169 | &meta_level); |
2177 | if (has_refcount) | 2170 | if (has_refcount) |
@@ -2227,7 +2220,7 @@ static int ocfs2_prepare_inode_for_write(struct file *file, | |||
2227 | * caller will have to retake some cluster | 2220 | * caller will have to retake some cluster |
2228 | * locks and initiate the io as buffered. | 2221 | * locks and initiate the io as buffered. |
2229 | */ | 2222 | */ |
2230 | ret = ocfs2_check_range_for_holes(inode, saved_pos, count); | 2223 | ret = ocfs2_check_range_for_holes(inode, pos, count); |
2231 | if (ret == 1) { | 2224 | if (ret == 1) { |
2232 | /* | 2225 | /* |
2233 | * Fallback to old way if the feature bit is not set. | 2226 | * Fallback to old way if the feature bit is not set. |
@@ -2242,12 +2235,9 @@ static int ocfs2_prepare_inode_for_write(struct file *file, | |||
2242 | break; | 2235 | break; |
2243 | } | 2236 | } |
2244 | 2237 | ||
2245 | if (appending) | ||
2246 | *ppos = saved_pos; | ||
2247 | |||
2248 | out_unlock: | 2238 | out_unlock: |
2249 | trace_ocfs2_prepare_inode_for_write(OCFS2_I(inode)->ip_blkno, | 2239 | trace_ocfs2_prepare_inode_for_write(OCFS2_I(inode)->ip_blkno, |
2250 | saved_pos, appending, count, | 2240 | pos, appending, count, |
2251 | direct_io, has_refcount); | 2241 | direct_io, has_refcount); |
2252 | 2242 | ||
2253 | if (meta_level >= 0) | 2243 | if (meta_level >= 0) |
@@ -2260,19 +2250,20 @@ out: | |||
2260 | static ssize_t ocfs2_file_write_iter(struct kiocb *iocb, | 2250 | static ssize_t ocfs2_file_write_iter(struct kiocb *iocb, |
2261 | struct iov_iter *from) | 2251 | struct iov_iter *from) |
2262 | { | 2252 | { |
2263 | int ret, direct_io, appending, rw_level, have_alloc_sem = 0; | 2253 | int direct_io, appending, rw_level, have_alloc_sem = 0; |
2264 | int can_do_direct, has_refcount = 0; | 2254 | int can_do_direct, has_refcount = 0; |
2265 | ssize_t written = 0; | 2255 | ssize_t written = 0; |
2266 | size_t count = iov_iter_count(from); | 2256 | ssize_t ret; |
2267 | loff_t old_size, *ppos = &iocb->ki_pos; | 2257 | size_t count = iov_iter_count(from), orig_count; |
2258 | loff_t old_size; | ||
2268 | u32 old_clusters; | 2259 | u32 old_clusters; |
2269 | struct file *file = iocb->ki_filp; | 2260 | struct file *file = iocb->ki_filp; |
2270 | struct inode *inode = file_inode(file); | 2261 | struct inode *inode = file_inode(file); |
2271 | struct address_space *mapping = file->f_mapping; | ||
2272 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 2262 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
2273 | int full_coherency = !(osb->s_mount_opt & | 2263 | int full_coherency = !(osb->s_mount_opt & |
2274 | OCFS2_MOUNT_COHERENCY_BUFFERED); | 2264 | OCFS2_MOUNT_COHERENCY_BUFFERED); |
2275 | int unaligned_dio = 0; | 2265 | int unaligned_dio = 0; |
2266 | int dropped_dio = 0; | ||
2276 | 2267 | ||
2277 | trace_ocfs2_file_aio_write(inode, file, file->f_path.dentry, | 2268 | trace_ocfs2_file_aio_write(inode, file, file->f_path.dentry, |
2278 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | 2269 | (unsigned long long)OCFS2_I(inode)->ip_blkno, |
@@ -2283,8 +2274,8 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb, | |||
2283 | if (count == 0) | 2274 | if (count == 0) |
2284 | return 0; | 2275 | return 0; |
2285 | 2276 | ||
2286 | appending = file->f_flags & O_APPEND ? 1 : 0; | 2277 | appending = iocb->ki_flags & IOCB_APPEND ? 1 : 0; |
2287 | direct_io = file->f_flags & O_DIRECT ? 1 : 0; | 2278 | direct_io = iocb->ki_flags & IOCB_DIRECT ? 1 : 0; |
2288 | 2279 | ||
2289 | mutex_lock(&inode->i_mutex); | 2280 | mutex_lock(&inode->i_mutex); |
2290 | 2281 | ||
@@ -2329,8 +2320,17 @@ relock: | |||
2329 | ocfs2_inode_unlock(inode, 1); | 2320 | ocfs2_inode_unlock(inode, 1); |
2330 | } | 2321 | } |
2331 | 2322 | ||
2323 | orig_count = iov_iter_count(from); | ||
2324 | ret = generic_write_checks(iocb, from); | ||
2325 | if (ret <= 0) { | ||
2326 | if (ret) | ||
2327 | mlog_errno(ret); | ||
2328 | goto out; | ||
2329 | } | ||
2330 | count = ret; | ||
2331 | |||
2332 | can_do_direct = direct_io; | 2332 | can_do_direct = direct_io; |
2333 | ret = ocfs2_prepare_inode_for_write(file, ppos, count, appending, | 2333 | ret = ocfs2_prepare_inode_for_write(file, iocb->ki_pos, count, appending, |
2334 | &can_do_direct, &has_refcount); | 2334 | &can_do_direct, &has_refcount); |
2335 | if (ret < 0) { | 2335 | if (ret < 0) { |
2336 | mlog_errno(ret); | 2336 | mlog_errno(ret); |
@@ -2338,7 +2338,7 @@ relock: | |||
2338 | } | 2338 | } |
2339 | 2339 | ||
2340 | if (direct_io && !is_sync_kiocb(iocb)) | 2340 | if (direct_io && !is_sync_kiocb(iocb)) |
2341 | unaligned_dio = ocfs2_is_io_unaligned(inode, count, *ppos); | 2341 | unaligned_dio = ocfs2_is_io_unaligned(inode, count, iocb->ki_pos); |
2342 | 2342 | ||
2343 | /* | 2343 | /* |
2344 | * We can't complete the direct I/O as requested, fall back to | 2344 | * We can't complete the direct I/O as requested, fall back to |
@@ -2351,6 +2351,9 @@ relock: | |||
2351 | rw_level = -1; | 2351 | rw_level = -1; |
2352 | 2352 | ||
2353 | direct_io = 0; | 2353 | direct_io = 0; |
2354 | iocb->ki_flags &= ~IOCB_DIRECT; | ||
2355 | iov_iter_reexpand(from, orig_count); | ||
2356 | dropped_dio = 1; | ||
2354 | goto relock; | 2357 | goto relock; |
2355 | } | 2358 | } |
2356 | 2359 | ||
@@ -2374,74 +2377,15 @@ relock: | |||
2374 | /* communicate with ocfs2_dio_end_io */ | 2377 | /* communicate with ocfs2_dio_end_io */ |
2375 | ocfs2_iocb_set_rw_locked(iocb, rw_level); | 2378 | ocfs2_iocb_set_rw_locked(iocb, rw_level); |
2376 | 2379 | ||
2377 | ret = generic_write_checks(file, ppos, &count, | 2380 | written = __generic_file_write_iter(iocb, from); |
2378 | S_ISBLK(inode->i_mode)); | ||
2379 | if (ret) | ||
2380 | goto out_dio; | ||
2381 | |||
2382 | iov_iter_truncate(from, count); | ||
2383 | if (direct_io) { | ||
2384 | loff_t endbyte; | ||
2385 | ssize_t written_buffered; | ||
2386 | written = generic_file_direct_write(iocb, from, *ppos); | ||
2387 | if (written < 0 || written == count) { | ||
2388 | ret = written; | ||
2389 | goto out_dio; | ||
2390 | } | ||
2391 | |||
2392 | /* | ||
2393 | * for completing the rest of the request. | ||
2394 | */ | ||
2395 | count -= written; | ||
2396 | written_buffered = generic_perform_write(file, from, *ppos); | ||
2397 | /* | ||
2398 | * If generic_file_buffered_write() returned a synchronous error | ||
2399 | * then we want to return the number of bytes which were | ||
2400 | * direct-written, or the error code if that was zero. Note | ||
2401 | * that this differs from normal direct-io semantics, which | ||
2402 | * will return -EFOO even if some bytes were written. | ||
2403 | */ | ||
2404 | if (written_buffered < 0) { | ||
2405 | ret = written_buffered; | ||
2406 | goto out_dio; | ||
2407 | } | ||
2408 | |||
2409 | /* We need to ensure that the page cache pages are written to | ||
2410 | * disk and invalidated to preserve the expected O_DIRECT | ||
2411 | * semantics. | ||
2412 | */ | ||
2413 | endbyte = *ppos + written_buffered - 1; | ||
2414 | ret = filemap_write_and_wait_range(file->f_mapping, *ppos, | ||
2415 | endbyte); | ||
2416 | if (ret == 0) { | ||
2417 | iocb->ki_pos = *ppos + written_buffered; | ||
2418 | written += written_buffered; | ||
2419 | invalidate_mapping_pages(mapping, | ||
2420 | *ppos >> PAGE_CACHE_SHIFT, | ||
2421 | endbyte >> PAGE_CACHE_SHIFT); | ||
2422 | } else { | ||
2423 | /* | ||
2424 | * We don't know how much we wrote, so just return | ||
2425 | * the number of bytes which were direct-written | ||
2426 | */ | ||
2427 | } | ||
2428 | } else { | ||
2429 | current->backing_dev_info = inode_to_bdi(inode); | ||
2430 | written = generic_perform_write(file, from, *ppos); | ||
2431 | if (likely(written >= 0)) | ||
2432 | iocb->ki_pos = *ppos + written; | ||
2433 | current->backing_dev_info = NULL; | ||
2434 | } | ||
2435 | |||
2436 | out_dio: | ||
2437 | /* buffered aio wouldn't have proper lock coverage today */ | 2381 | /* buffered aio wouldn't have proper lock coverage today */ |
2438 | BUG_ON(ret == -EIOCBQUEUED && !(file->f_flags & O_DIRECT)); | 2382 | BUG_ON(written == -EIOCBQUEUED && !(iocb->ki_flags & IOCB_DIRECT)); |
2439 | 2383 | ||
2440 | if (unlikely(written <= 0)) | 2384 | if (unlikely(written <= 0)) |
2441 | goto no_sync; | 2385 | goto no_sync; |
2442 | 2386 | ||
2443 | if (((file->f_flags & O_DSYNC) && !direct_io) || IS_SYNC(inode) || | 2387 | if (((file->f_flags & O_DSYNC) && !direct_io) || |
2444 | ((file->f_flags & O_DIRECT) && !direct_io)) { | 2388 | IS_SYNC(inode) || dropped_dio) { |
2445 | ret = filemap_fdatawrite_range(file->f_mapping, | 2389 | ret = filemap_fdatawrite_range(file->f_mapping, |
2446 | iocb->ki_pos - written, | 2390 | iocb->ki_pos - written, |
2447 | iocb->ki_pos - 1); | 2391 | iocb->ki_pos - 1); |
@@ -2552,7 +2496,7 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb, | |||
2552 | * buffered reads protect themselves in ->readpage(). O_DIRECT reads | 2496 | * buffered reads protect themselves in ->readpage(). O_DIRECT reads |
2553 | * need locks to protect pending reads from racing with truncate. | 2497 | * need locks to protect pending reads from racing with truncate. |
2554 | */ | 2498 | */ |
2555 | if (filp->f_flags & O_DIRECT) { | 2499 | if (iocb->ki_flags & IOCB_DIRECT) { |
2556 | have_alloc_sem = 1; | 2500 | have_alloc_sem = 1; |
2557 | ocfs2_iocb_set_sem_locked(iocb); | 2501 | ocfs2_iocb_set_sem_locked(iocb); |
2558 | 2502 | ||
@@ -2586,7 +2530,7 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb, | |||
2586 | trace_generic_file_aio_read_ret(ret); | 2530 | trace_generic_file_aio_read_ret(ret); |
2587 | 2531 | ||
2588 | /* buffered aio wouldn't have proper lock coverage today */ | 2532 | /* buffered aio wouldn't have proper lock coverage today */ |
2589 | BUG_ON(ret == -EIOCBQUEUED && !(filp->f_flags & O_DIRECT)); | 2533 | BUG_ON(ret == -EIOCBQUEUED && !(iocb->ki_flags & IOCB_DIRECT)); |
2590 | 2534 | ||
2591 | /* see ocfs2_file_write_iter */ | 2535 | /* see ocfs2_file_write_iter */ |
2592 | if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) { | 2536 | if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) { |