hpfs: handle allocation failures in hpfs_add_pos()
[deliverable/linux.git] / mm / failslab.c
CommitLineData
773ff60e 1#include <linux/fault-inject.h>
4c13dd3b 2#include <linux/slab.h>
fab9963a
JDB
3#include <linux/mm.h>
4#include "slab.h"
773ff60e
AM
5
6static struct {
7 struct fault_attr attr;
71baba4b 8 bool ignore_gfp_reclaim;
621a5f7a 9 bool cache_filter;
773ff60e
AM
10} failslab = {
11 .attr = FAULT_ATTR_INITIALIZER,
71baba4b 12 .ignore_gfp_reclaim = true,
621a5f7a 13 .cache_filter = false,
773ff60e
AM
14};
15
fab9963a 16bool should_failslab(struct kmem_cache *s, gfp_t gfpflags)
773ff60e 17{
fab9963a
JDB
18 /* No fault-injection for bootstrap cache */
19 if (unlikely(s == kmem_cache))
20 return false;
21
773ff60e
AM
22 if (gfpflags & __GFP_NOFAIL)
23 return false;
24
71baba4b 25 if (failslab.ignore_gfp_reclaim && (gfpflags & __GFP_RECLAIM))
773ff60e
AM
26 return false;
27
fab9963a 28 if (failslab.cache_filter && !(s->flags & SLAB_FAILSLAB))
4c13dd3b
DM
29 return false;
30
fab9963a 31 return should_fail(&failslab.attr, s->object_size);
773ff60e
AM
32}
33
34static int __init setup_failslab(char *str)
35{
36 return setup_fault_attr(&failslab.attr, str);
37}
38__setup("failslab=", setup_failslab);
39
40#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
773ff60e
AM
41static int __init failslab_debugfs_init(void)
42{
dd48c085 43 struct dentry *dir;
f4ae40a6 44 umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
773ff60e 45
dd48c085
AM
46 dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr);
47 if (IS_ERR(dir))
48 return PTR_ERR(dir);
773ff60e 49
dd48c085 50 if (!debugfs_create_bool("ignore-gfp-wait", mode, dir,
71baba4b 51 &failslab.ignore_gfp_reclaim))
810f09b8 52 goto fail;
dd48c085 53 if (!debugfs_create_bool("cache-filter", mode, dir,
810f09b8
AM
54 &failslab.cache_filter))
55 goto fail;
4c13dd3b 56
810f09b8
AM
57 return 0;
58fail:
dd48c085 59 debugfs_remove_recursive(dir);
773ff60e 60
810f09b8 61 return -ENOMEM;
773ff60e
AM
62}
63
64late_initcall(failslab_debugfs_init);
65
66#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
This page took 0.439876 seconds and 5 git commands to generate.