make use of anon_inode_getfile_fmode()
Subsystems (6)
Al Viro
maintainerRFC PATCH 1/1 make use of anon_inode_getfile_fmode()
["fallen through the cracks" misc stuff]
A bunch of anon_inode_getfile() callers follow it with adjusting ->f_mode; we have a helper doing that now, so let's make use of it.
---
arch/powerpc/platforms/pseries/papr-vpd.c +3 -4
@@ -482,14 +482,13 @@ static long papr_vpd_create_handle(struct papr_location_code __user *ulc) goto free_blob; } - file =anon_inode_getfile ("[papr-vpd]" , &papr_vpd_handle_ops, - (void *)blob,O_RDONLY ); + file =anon_inode_getfile_fmode ("[papr-vpd]" , &papr_vpd_handle_ops, + (void *)blob,O_RDONLY , +FMODE_LSEEK |FMODE_PREAD );if (IS_ERR (file)) { err =PTR_ERR (file); goto put_fd; } - - file->f_mode |=FMODE_LSEEK |FMODE_PREAD ;fd_install (fd, file);return fd; put_fd:
drivers/vfio/group.c +2 -14
@@ -266,24 +266,12 @@ static struct file *vfio_device_open_file(struct vfio_device *device)if (ret) goto err_free; -/* -* We can't use anon_inode_getfd() because we need to modify -* the f_mode flags directly to allow more than just ioctls -*/ - filep =anon_inode_getfile ("[vfio-device]" , &vfio_device_fops, - df,O_RDWR ); + filep =anon_inode_getfile_fmode ("[vfio-device]" , &vfio_device_fops, + df,O_RDWR ,FMODE_PREAD |FMODE_PWRITE );if (IS_ERR (filep)) { ret =PTR_ERR (filep); goto err_close_device; } - -/* -* TODO: add an anon_inode interface to do this. -* Appears to be missing by lack of need rather than -* explicitly prevented. Now there's need. -*/ - filep->f_mode |= (FMODE_PREAD |FMODE_PWRITE ); -/* * Use the pseudo fs inode on the device to link all mmaps * to the same address space, allowing us to unmap all vmas
fs/cachefiles/ondemand.c +3 -4
@@ -317,8 +317,9 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req, goto err_free_id; } - anon_file->file =anon_inode_getfile ("[cachefiles]" , - &cachefiles_ondemand_fd_fops, object,O_WRONLY ); + anon_file->file =anon_inode_getfile_fmode ("[cachefiles]" , + &cachefiles_ondemand_fd_fops, object, +O_WRONLY ,FMODE_PWRITE |FMODE_LSEEK );if (IS_ERR (anon_file->file)) { ret =PTR_ERR (anon_file->file); goto err_put_fd;
@@ -333,8 +334,6 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req, goto err_put_file; } - anon_file->file->f_mode |=FMODE_PWRITE |FMODE_LSEEK ; - load = (void *)req->msg.data; load->fd = anon_file->fd; object->ondemand->ondemand_id = object_id;
fs/eventfd.c +2 -3
@@ -406,14 +406,13 @@ static int do_eventfd(unsigned int count, int flags)if (fd <0 ) goto err; - file =anon_inode_getfile ("[eventfd]" , &eventfd_fops, ctx, flags); + file =anon_inode_getfile_fmode ("[eventfd]" , &eventfd_fops, + ctx, flags,FMODE_NOWAIT );if (IS_ERR (file)) {put_unused_fd (fd); fd =PTR_ERR (file); goto err; } - - file->f_mode |=FMODE_NOWAIT ;fd_install (fd, file);return fd; err:
fs/signalfd.c +3 -4
@@ -277,15 +277,14 @@ static int do_signalfd4(int ufd, sigset_t *mask, int flags)return ufd; } - file =anon_inode_getfile ("[signalfd]" , &signalfd_fops, ctx, -O_RDWR | (flags &O_NONBLOCK )); + file =anon_inode_getfile_fmode ("[signalfd]" , &signalfd_fops, + ctx,O_RDWR | (flags &O_NONBLOCK ), +FMODE_NOWAIT );if (IS_ERR (file)) {put_unused_fd (ufd);kfree (ctx);return PTR_ERR (file); } - file->f_mode |=FMODE_NOWAIT ; -fd_install (ufd, file); }else {CLASS (fd, f)(ufd);
fs/timerfd.c +3 -3
@@ -439,15 +439,15 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)return ufd; } - file =anon_inode_getfile ("[timerfd]" , &timerfd_fops, ctx, -O_RDWR | (flags &TFD_SHARED_FCNTL_FLAGS )); + file =anon_inode_getfile_fmode ("[timerfd]" , &timerfd_fops, ctx, +O_RDWR | (flags &TFD_SHARED_FCNTL_FLAGS ), +FMODE_NOWAIT );if (IS_ERR (file)) {put_unused_fd (ufd);kfree (ctx);return PTR_ERR (file); } - file->f_mode |=FMODE_NOWAIT ;fd_install (ufd, file);return ufd; }
virt/kvm/kvm_main.c +4 -7
@@ -4222,15 +4222,14 @@ static int kvm_vcpu_ioctl_get_stats_fd(struct kvm_vcpu *vcpu)if (fd <0 )return fd; - file =anon_inode_getfile (name, &kvm_vcpu_stats_fops, vcpu,O_RDONLY ); + file =anon_inode_getfile_fmode (name, &kvm_vcpu_stats_fops, vcpu, +O_RDONLY ,FMODE_PREAD );if (IS_ERR (file)) {put_unused_fd (fd);return PTR_ERR (file); }kvm_get_kvm (vcpu->kvm); - - file->f_mode |=FMODE_PREAD ;fd_install (fd, file);return fd;
@@ -4982,16 +4981,14 @@ static int kvm_vm_ioctl_get_stats_fd(struct kvm *kvm)if (fd <0 )return fd; - file =anon_inode_getfile ("kvm-vm-stats" , - &kvm_vm_stats_fops, kvm,O_RDONLY ); + file =anon_inode_getfile_fmode ("kvm-vm-stats" , + &kvm_vm_stats_fops, kvm,O_RDONLY ,FMODE_PREAD );if (IS_ERR (file)) {put_unused_fd (fd);return PTR_ERR (file); }kvm_get_kvm (kvm); - - file->f_mode |=FMODE_PREAD ;fd_install (fd, file);return fd;
Quoted 8 lines · Al Viro
["fallen through the cracks" misc stuff]
A bunch of
anon_inode_getfile()callers follow it with adjusting ->f_mode; we have a helper doing that now, so let's make use of it.[...]
Applied to the vfs-6.15.misc branch of the vfs/vfs.git tree. Patches in the vfs-6.15.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.15.misc
[1/1] make use of anon_inode_getfile_fmode()
https://git.kernel.org/vfs/vfs/c/2f4cccd32a0d
Quoted 7 lines · Al Viro
["fallen through the cracks" misc stuff]
A bunch of
anon_inode_getfile()callers follow it with adjusting ->f_mode; we have a helper doing that now, so let's make use of it.Signed-off-by Al Viro <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 187 lines
---
arch/powerpc/platforms/pseries/papr-vpd.c +3
-4@@ -482,14 +482,13 @@ static long papr_vpd_create_handle(struct papr_location_code __user *ulc) goto free_blob; } - file =anon_inode_getfile ("[papr-vpd]" , &papr_vpd_handle_ops, - (void *)blob,O_RDONLY ); + file =anon_inode_getfile_fmode ("[papr-vpd]" , &papr_vpd_handle_ops, + (void *)blob,O_RDONLY , +FMODE_LSEEK |FMODE_PREAD );if (IS_ERR (file)) { err =PTR_ERR (file); goto put_fd; } - - file->f_mode |=FMODE_LSEEK |FMODE_PREAD ;fd_install (fd, file);return fd; put_fd:drivers/vfio/group.c +2
-14@@ -266,24 +266,12 @@ static struct file *vfio_device_open_file(struct vfio_device *device)if (ret) goto err_free; -/* -* We can't use anon_inode_getfd() because we need to modify -* the f_mode flags directly to allow more than just ioctls -*/ - filep =anon_inode_getfile ("[vfio-device]" , &vfio_device_fops, - df,O_RDWR ); + filep =anon_inode_getfile_fmode ("[vfio-device]" , &vfio_device_fops, + df,O_RDWR ,FMODE_PREAD |FMODE_PWRITE );if (IS_ERR (filep)) { ret =PTR_ERR (filep); goto err_close_device; } - -/* -* TODO: add an anon_inode interface to do this. -* Appears to be missing by lack of need rather than -* explicitly prevented. Now there's need. -*/ - filep->f_mode |= (FMODE_PREAD |FMODE_PWRITE ); -/* * Use the pseudo fs inode on the device to link all mmaps * to the same address space, allowing us to unmap all vmas fs/cachefiles/ondemand.c +3
-4@@ -317,8 +317,9 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req, goto err_free_id; } - anon_file->file =anon_inode_getfile ("[cachefiles]" , - &cachefiles_ondemand_fd_fops, object,O_WRONLY ); + anon_file->file =anon_inode_getfile_fmode ("[cachefiles]" , + &cachefiles_ondemand_fd_fops, object, +O_WRONLY ,FMODE_PWRITE |FMODE_LSEEK );if (IS_ERR (anon_file->file)) { ret =PTR_ERR (anon_file->file); goto err_put_fd;@@ -333,8 +334,6 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req, goto err_put_file; } - anon_file->file->f_mode |=FMODE_PWRITE |FMODE_LSEEK ; - load = (void *)req->msg.data; load->fd = anon_file->fd; object->ondemand->ondemand_id = object_id;fs/eventfd.c +2
-3@@ -406,14 +406,13 @@ static int do_eventfd(unsigned int count, int flags)if (fd <0 ) goto err; - file =anon_inode_getfile ("[eventfd]" , &eventfd_fops, ctx, flags); + file =anon_inode_getfile_fmode ("[eventfd]" , &eventfd_fops, + ctx, flags,FMODE_NOWAIT );if (IS_ERR (file)) {put_unused_fd (fd); fd =PTR_ERR (file); goto err; } - - file->f_mode |=FMODE_NOWAIT ;fd_install (fd, file);return fd; err:fs/signalfd.c +3
-4@@ -277,15 +277,14 @@ static int do_signalfd4(int ufd, sigset_t *mask, int flags)return ufd; } - file =anon_inode_getfile ("[signalfd]" , &signalfd_fops, ctx, -O_RDWR | (flags &O_NONBLOCK )); + file =anon_inode_getfile_fmode ("[signalfd]" , &signalfd_fops, + ctx,O_RDWR | (flags &O_NONBLOCK ), +FMODE_NOWAIT );if (IS_ERR (file)) {put_unused_fd (ufd);kfree (ctx);return PTR_ERR (file); } - file->f_mode |=FMODE_NOWAIT ; -fd_install (ufd, file); }else {CLASS (fd, f)(ufd);fs/timerfd.c +3
-3@@ -439,15 +439,15 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)return ufd; } - file =anon_inode_getfile ("[timerfd]" , &timerfd_fops, ctx, -O_RDWR | (flags &TFD_SHARED_FCNTL_FLAGS )); + file =anon_inode_getfile_fmode ("[timerfd]" , &timerfd_fops, ctx, +O_RDWR | (flags &TFD_SHARED_FCNTL_FLAGS ), +FMODE_NOWAIT );if (IS_ERR (file)) {put_unused_fd (ufd);kfree (ctx);return PTR_ERR (file); } - file->f_mode |=FMODE_NOWAIT ;fd_install (ufd, file);return ufd; }virt/kvm/kvm_main.c +4
-7@@ -4222,15 +4222,14 @@ static int kvm_vcpu_ioctl_get_stats_fd(struct kvm_vcpu *vcpu)if (fd <0 )return fd; - file =anon_inode_getfile (name, &kvm_vcpu_stats_fops, vcpu,O_RDONLY ); + file =anon_inode_getfile_fmode (name, &kvm_vcpu_stats_fops, vcpu, +O_RDONLY ,FMODE_PREAD );if (IS_ERR (file)) {put_unused_fd (fd);return PTR_ERR (file); }kvm_get_kvm (vcpu->kvm); - - file->f_mode |=FMODE_PREAD ;fd_install (fd, file);return fd;@@ -4982,16 +4981,14 @@ static int kvm_vm_ioctl_get_stats_fd(struct kvm *kvm)if (fd <0 )return fd; - file =anon_inode_getfile ("kvm-vm-stats" , - &kvm_vm_stats_fops, kvm,O_RDONLY ); + file =anon_inode_getfile_fmode ("kvm-vm-stats" , + &kvm_vm_stats_fops, kvm,O_RDONLY ,FMODE_PREAD );if (IS_ERR (file)) {put_unused_fd (fd);return PTR_ERR (file); }kvm_get_kvm (kvm); - - file->f_mode |=FMODE_PREAD ;fd_install (fd, file);return fd;
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR