add patch add-fallocate-mode-blocking-for-debugging
[ext4-patch-queue.git] / add-fallocate-mode-blocking-for-debugging
blob08cf97ef00f00811873e263465c62257dfe36e95
1 ext4: add fallocate mode blocking for debugging purposes
3 If a particular fallocate mode is causing test failures, give the
4 tester the ability to block a particular fallocate mode so that the
5 use of a particular fallocate mode will be reported as not supported.
7 For example, if the COLLAPSE_RANGE fallocate mode is causing test
8 failures, this allows us to suppress it so we can more easily test the
9 rest of the file system code.
11 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
12 ---
13  fs/ext4/extents.c | 14 ++++++++++++++
14  1 file changed, 14 insertions(+)
16 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
17 index 64b4003..1bb3e4b 100644
18 --- a/fs/ext4/extents.c
19 +++ b/fs/ext4/extents.c
20 @@ -29,6 +29,7 @@
21   *   - smart tree reduction
22   */
24 +#include <linux/module.h>
25  #include <linux/fs.h>
26  #include <linux/time.h>
27  #include <linux/jbd2.h>
28 @@ -4862,6 +4863,12 @@ out_mutex:
29         return ret;
30  }
32 +int ext4_fallocate_mode_block __read_mostly;
34 +module_param_named(fallocate_mode_block, ext4_fallocate_mode_block, int, 0644);
35 +MODULE_PARM_DESC(fallocate_mode_block,
36 +                "Fallocate modes which are blocked for debugging purposes");
38  /*
39   * preallocate space for a file. This implements ext4's fallocate file
40   * operation, which gets called from sys_fallocate system call.
41 @@ -4881,6 +4888,13 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
42         struct timespec tv;
43         unsigned int blkbits = inode->i_blkbits;
45 +       /*
46 +        * for debugging purposes, allow certain fallocate operations
47 +        * to be disabled
48 +        */
49 +       if (unlikely(mode & ext4_fallocate_mode_block))
50 +               return -EOPNOTSUPP;
52         /* Return error if mode is not supported */
53         if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
54                      FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE))