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

replace checking for ->read/->aio_read presence with check in ->f_mode

Since we are about to introduce new methods (read_iter/write_iter), the
tests in a bunch of places would have to grow inconveniently. Check
once (at open() time) and store results in ->f_mode as FMODE_CAN_READ
and FMODE_CAN_WRITE resp. It might end up being a temporary measure -
once everything switches from ->aio_{read,write} to ->{read,write}_iter
it might make sense to return to open-coded checks. We'll see...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 7f7f25e8 b3188919

+23 -11
+2 -2
drivers/mtd/nand/nandsim.c
··· 575 575 cfile = filp_open(cache_file, O_CREAT | O_RDWR | O_LARGEFILE, 0600); 576 576 if (IS_ERR(cfile)) 577 577 return PTR_ERR(cfile); 578 - if (!cfile->f_op->read && !cfile->f_op->aio_read) { 578 + if (!(cfile->f_mode & FMODE_CAN_READ)) { 579 579 NS_ERR("alloc_device: cache file not readable\n"); 580 580 err = -EINVAL; 581 581 goto err_close; 582 582 } 583 - if (!cfile->f_op->write && !cfile->f_op->aio_write) { 583 + if (!(cfile->f_mode & FMODE_CAN_WRITE)) { 584 584 NS_ERR("alloc_device: cache file not writeable\n"); 585 585 err = -EINVAL; 586 586 goto err_close;
+2 -2
drivers/usb/gadget/storage_common.c
··· 220 220 * If we can't read the file, it's no good. 221 221 * If we can't write the file, use it read-only. 222 222 */ 223 - if (!(filp->f_op->read || filp->f_op->aio_read)) { 223 + if (!(filp->f_mode & FMODE_CAN_READ)) { 224 224 LINFO(curlun, "file not readable: %s\n", filename); 225 225 goto out; 226 226 } 227 - if (!(filp->f_op->write || filp->f_op->aio_write)) 227 + if (!(filp->f_mode & FMODE_CAN_WRITE)) 228 228 ro = 1; 229 229 230 230 size = i_size_read(inode->i_mapping->host);
+4
fs/file_table.c
··· 175 175 file->f_path = *path; 176 176 file->f_inode = path->dentry->d_inode; 177 177 file->f_mapping = path->dentry->d_inode->i_mapping; 178 + if ((mode & FMODE_READ) && likely(fop->read || fop->aio_read)) 179 + mode |= FMODE_CAN_READ; 180 + if ((mode & FMODE_WRITE) && likely(fop->write || fop->aio_write)) 181 + mode |= FMODE_CAN_WRITE; 178 182 file->f_mode = mode; 179 183 file->f_op = fop; 180 184 if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
+4
fs/open.c
··· 725 725 } 726 726 if ((f->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) 727 727 i_readcount_inc(inode); 728 + if ((f->f_mode & FMODE_READ) && likely(f->f_op->read || f->f_op->aio_read)) 729 + f->f_mode |= FMODE_CAN_READ; 730 + if ((f->f_mode & FMODE_WRITE) && likely(f->f_op->write || f->f_op->aio_write)) 731 + f->f_mode |= FMODE_CAN_WRITE; 728 732 729 733 f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); 730 734
+7 -7
fs/read_write.c
··· 396 396 397 397 if (!(file->f_mode & FMODE_READ)) 398 398 return -EBADF; 399 - if (!file->f_op->read && !file->f_op->aio_read) 399 + if (!(file->f_mode & FMODE_CAN_READ)) 400 400 return -EINVAL; 401 401 if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) 402 402 return -EFAULT; ··· 445 445 const char __user *p; 446 446 ssize_t ret; 447 447 448 - if (!file->f_op->write && !file->f_op->aio_write) 448 + if (!(file->f_mode & FMODE_CAN_WRITE)) 449 449 return -EINVAL; 450 450 451 451 old_fs = get_fs(); ··· 472 472 473 473 if (!(file->f_mode & FMODE_WRITE)) 474 474 return -EBADF; 475 - if (!file->f_op->write && !file->f_op->aio_write) 475 + if (!(file->f_mode & FMODE_CAN_WRITE)) 476 476 return -EINVAL; 477 477 if (unlikely(!access_ok(VERIFY_READ, buf, count))) 478 478 return -EFAULT; ··· 785 785 { 786 786 if (!(file->f_mode & FMODE_READ)) 787 787 return -EBADF; 788 - if (!file->f_op->aio_read && !file->f_op->read) 788 + if (!(file->f_mode & FMODE_CAN_READ)) 789 789 return -EINVAL; 790 790 791 791 return do_readv_writev(READ, file, vec, vlen, pos); ··· 798 798 { 799 799 if (!(file->f_mode & FMODE_WRITE)) 800 800 return -EBADF; 801 - if (!file->f_op->aio_write && !file->f_op->write) 801 + if (!(file->f_mode & FMODE_CAN_WRITE)) 802 802 return -EINVAL; 803 803 804 804 return do_readv_writev(WRITE, file, vec, vlen, pos); ··· 964 964 goto out; 965 965 966 966 ret = -EINVAL; 967 - if (!file->f_op->aio_read && !file->f_op->read) 967 + if (!(file->f_mode & FMODE_CAN_READ)) 968 968 goto out; 969 969 970 970 ret = compat_do_readv_writev(READ, file, vec, vlen, pos); ··· 1041 1041 goto out; 1042 1042 1043 1043 ret = -EINVAL; 1044 - if (!file->f_op->aio_write && !file->f_op->write) 1044 + if (!(file->f_mode & FMODE_CAN_WRITE)) 1045 1045 goto out; 1046 1046 1047 1047 ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos);
+4
include/linux/fs.h
··· 128 128 #define FMODE_ATOMIC_POS ((__force fmode_t)0x8000) 129 129 /* Write access to underlying fs */ 130 130 #define FMODE_WRITER ((__force fmode_t)0x10000) 131 + /* Has read method(s) */ 132 + #define FMODE_CAN_READ ((__force fmode_t)0x20000) 133 + /* Has write method(s) */ 134 + #define FMODE_CAN_WRITE ((__force fmode_t)0x40000) 131 135 132 136 /* File was opened by fanotify and shouldn't generate fanotify events */ 133 137 #define FMODE_NONOTIFY ((__force fmode_t)0x1000000)