Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs: move kiocb_start_write() into vfs_iocb_iter_write()

In vfs code, sb_start_write() is usually called after the permission hook
in rw_verify_area(). vfs_iocb_iter_write() is an exception to this rule,
where kiocb_start_write() is called by its callers.

Move kiocb_start_write() from the callers into vfs_iocb_iter_write()
after the rw_verify_area() checks, to make them "start-write-safe".

The semantics of vfs_iocb_iter_write() is changed, so that the caller is
responsible for calling kiocb_end_write() on completion only if async
iocb was queued. The completion handlers of both callers were adapted
to this semantic change.

This is needed for fanotify "pre content" events.

Suggested-by: Jan Kara <jack@suse.cz>
Suggested-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Link: https://lore.kernel.org/r/20231122122715.2561213-14-amir73il@gmail.com
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Amir Goldstein and committed by
Christian Brauner
6ae65439 b8e1425b

+13 -7
+2 -3
fs/cachefiles/io.c
··· 259 259 260 260 _enter("%ld", ret); 261 261 262 - kiocb_end_write(iocb); 262 + if (ki->was_async) 263 + kiocb_end_write(iocb); 263 264 264 265 if (ret < 0) 265 266 trace_cachefiles_io_error(object, inode, ret, ··· 319 318 if (ki->term_func) 320 319 ki->iocb.ki_complete = cachefiles_write_complete; 321 320 atomic_long_add(ki->b_writing, &cache->b_writing); 322 - 323 - kiocb_start_write(&ki->iocb); 324 321 325 322 get_file(ki->iocb.ki_filp); 326 323 cachefiles_grab_object(object, cachefiles_obj_get_ioreq);
+4 -4
fs/overlayfs/file.c
··· 295 295 struct kiocb *iocb = &aio_req->iocb; 296 296 struct kiocb *orig_iocb = aio_req->orig_iocb; 297 297 298 - if (iocb->ki_flags & IOCB_WRITE) { 299 - kiocb_end_write(iocb); 298 + if (iocb->ki_flags & IOCB_WRITE) 300 299 ovl_file_modified(orig_iocb->ki_filp); 301 - } 302 300 303 301 orig_iocb->ki_pos = iocb->ki_pos; 304 302 ovl_aio_put(aio_req); ··· 307 309 struct ovl_aio_req *aio_req = container_of(iocb, 308 310 struct ovl_aio_req, iocb); 309 311 struct kiocb *orig_iocb = aio_req->orig_iocb; 312 + 313 + if (iocb->ki_flags & IOCB_WRITE) 314 + kiocb_end_write(iocb); 310 315 311 316 ovl_aio_cleanup_handler(aio_req); 312 317 orig_iocb->ki_complete(orig_iocb, res); ··· 457 456 aio_req->iocb.ki_flags = ifl; 458 457 aio_req->iocb.ki_complete = ovl_aio_queue_completion; 459 458 refcount_set(&aio_req->ref, 2); 460 - kiocb_start_write(&aio_req->iocb); 461 459 ret = vfs_iocb_iter_write(real.file, &aio_req->iocb, iter); 462 460 ovl_aio_put(aio_req); 463 461 if (ret != -EIOCBQUEUED)
+7
fs/read_write.c
··· 829 829 } 830 830 EXPORT_SYMBOL(vfs_iter_read); 831 831 832 + /* 833 + * Caller is responsible for calling kiocb_end_write() on completion 834 + * if async iocb was queued. 835 + */ 832 836 ssize_t vfs_iocb_iter_write(struct file *file, struct kiocb *iocb, 833 837 struct iov_iter *iter) 834 838 { ··· 853 849 if (ret < 0) 854 850 return ret; 855 851 852 + kiocb_start_write(iocb); 856 853 ret = call_write_iter(file, iocb, iter); 854 + if (ret != -EIOCBQUEUED) 855 + kiocb_end_write(iocb); 857 856 if (ret > 0) 858 857 fsnotify_modify(file); 859 858