Back to home page

LXR

 
 

    


0001 #include <linux/fault-inject.h>
0002 #include <linux/slab.h>
0003 #include <linux/mm.h>
0004 #include "slab.h"
0005 
0006 static struct {
0007     struct fault_attr attr;
0008     bool ignore_gfp_reclaim;
0009     bool cache_filter;
0010 } failslab = {
0011     .attr = FAULT_ATTR_INITIALIZER,
0012     .ignore_gfp_reclaim = true,
0013     .cache_filter = false,
0014 };
0015 
0016 bool should_failslab(struct kmem_cache *s, gfp_t gfpflags)
0017 {
0018     /* No fault-injection for bootstrap cache */
0019     if (unlikely(s == kmem_cache))
0020         return false;
0021 
0022     if (gfpflags & __GFP_NOFAIL)
0023         return false;
0024 
0025     if (failslab.ignore_gfp_reclaim && (gfpflags & __GFP_RECLAIM))
0026         return false;
0027 
0028     if (failslab.cache_filter && !(s->flags & SLAB_FAILSLAB))
0029         return false;
0030 
0031     return should_fail(&failslab.attr, s->object_size);
0032 }
0033 
0034 static int __init setup_failslab(char *str)
0035 {
0036     return setup_fault_attr(&failslab.attr, str);
0037 }
0038 __setup("failslab=", setup_failslab);
0039 
0040 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
0041 static int __init failslab_debugfs_init(void)
0042 {
0043     struct dentry *dir;
0044     umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
0045 
0046     dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr);
0047     if (IS_ERR(dir))
0048         return PTR_ERR(dir);
0049 
0050     if (!debugfs_create_bool("ignore-gfp-wait", mode, dir,
0051                 &failslab.ignore_gfp_reclaim))
0052         goto fail;
0053     if (!debugfs_create_bool("cache-filter", mode, dir,
0054                 &failslab.cache_filter))
0055         goto fail;
0056 
0057     return 0;
0058 fail:
0059     debugfs_remove_recursive(dir);
0060 
0061     return -ENOMEM;
0062 }
0063 
0064 late_initcall(failslab_debugfs_init);
0065 
0066 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */