903-debloat_direct_io.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. --- a/fs/Kconfig
  2. +++ b/fs/Kconfig
  3. @@ -62,6 +62,11 @@ config FILE_LOCKING
  4. for filesystems like NFS and for the flock() system
  5. call. Disabling this option saves about 11k.
  6. +config DIRECT_IO
  7. + bool "Enable O_DIRECT support" if EXPERT
  8. + depends on BLOCK
  9. + default y
  10. +
  11. source "fs/notify/Kconfig"
  12. source "fs/quota/Kconfig"
  13. --- a/fs/Makefile
  14. +++ b/fs/Makefile
  15. @@ -14,7 +14,8 @@ obj-y := open.o read_write.o file_table.
  16. stack.o fs_struct.o statfs.o fs_pin.o
  17. ifeq ($(CONFIG_BLOCK),y)
  18. -obj-y += buffer.o block_dev.o direct-io.o mpage.o
  19. +obj-y += buffer.o block_dev.o mpage.o
  20. +obj-$(CONFIG_DIRECT_IO) += direct-io.o
  21. else
  22. obj-y += no-block.o
  23. endif
  24. --- a/include/linux/fs.h
  25. +++ b/include/linux/fs.h
  26. @@ -2529,12 +2529,25 @@ enum {
  27. DIO_ASYNC_EXTEND = 0x04,
  28. };
  29. +#ifdef CONFIG_DIRECT_IO
  30. void dio_end_io(struct bio *bio, int error);
  31. ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
  32. struct block_device *bdev, struct iov_iter *iter, loff_t offset,
  33. get_block_t get_block, dio_iodone_t end_io,
  34. dio_submit_t submit_io, int flags);
  35. +#else
  36. +static inline void dio_end_io(struct bio *bio, int error)
  37. +{
  38. +}
  39. +static inline ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
  40. + struct block_device *bdev, struct iov_iter *iter, loff_t offset,
  41. + get_block_t get_block, dio_iodone_t end_io,
  42. + dio_submit_t submit_io, int flags)
  43. +{
  44. + return -EOPNOTSUPP;
  45. +}
  46. +#endif
  47. static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb,
  48. struct inode *inode, struct iov_iter *iter, loff_t offset,
  49. --- a/fs/fcntl.c
  50. +++ b/fs/fcntl.c
  51. @@ -52,8 +52,10 @@ static int setfl(int fd, struct file * f
  52. arg |= O_NONBLOCK;
  53. if (arg & O_DIRECT) {
  54. +#ifdef CONFIG_DIRECT_IO
  55. if (!filp->f_mapping || !filp->f_mapping->a_ops ||
  56. !filp->f_mapping->a_ops->direct_IO)
  57. +#endif
  58. return -EINVAL;
  59. }
  60. --- a/fs/open.c
  61. +++ b/fs/open.c
  62. @@ -655,9 +655,12 @@ int open_check_o_direct(struct file *f)
  63. {
  64. /* NB: we're sure to have correct a_ops only after f_op->open */
  65. if (f->f_flags & O_DIRECT) {
  66. +#ifdef CONFIG_DIRECT_IO
  67. if (!f->f_mapping->a_ops ||
  68. ((!f->f_mapping->a_ops->direct_IO) &&
  69. - (!f->f_mapping->a_ops->get_xip_mem))) {
  70. + (!f->f_mapping->a_ops->get_xip_mem)))
  71. +#endif
  72. + {
  73. return -EINVAL;
  74. }
  75. }