LCOV - code coverage report
Current view: top level - fs/fscache - main.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 22 46 47.8 %
Date: 2020-09-30 20:25:40 Functions: 1 3 33.3 %
Branches: 8 16 50.0 %

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0-or-later
       2                 :            : /* General filesystem local caching manager
       3                 :            :  *
       4                 :            :  * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
       5                 :            :  * Written by David Howells (dhowells@redhat.com)
       6                 :            :  */
       7                 :            : 
       8                 :            : #define FSCACHE_DEBUG_LEVEL CACHE
       9                 :            : #include <linux/module.h>
      10                 :            : #include <linux/init.h>
      11                 :            : #include <linux/sched.h>
      12                 :            : #include <linux/completion.h>
      13                 :            : #include <linux/slab.h>
      14                 :            : #include <linux/seq_file.h>
      15                 :            : #define CREATE_TRACE_POINTS
      16                 :            : #include "internal.h"
      17                 :            : 
      18                 :            : MODULE_DESCRIPTION("FS Cache Manager");
      19                 :            : MODULE_AUTHOR("Red Hat, Inc.");
      20                 :            : MODULE_LICENSE("GPL");
      21                 :            : 
      22                 :            : unsigned fscache_defer_lookup = 1;
      23                 :            : module_param_named(defer_lookup, fscache_defer_lookup, uint,
      24                 :            :                    S_IWUSR | S_IRUGO);
      25                 :            : MODULE_PARM_DESC(fscache_defer_lookup,
      26                 :            :                  "Defer cookie lookup to background thread");
      27                 :            : 
      28                 :            : unsigned fscache_defer_create = 1;
      29                 :            : module_param_named(defer_create, fscache_defer_create, uint,
      30                 :            :                    S_IWUSR | S_IRUGO);
      31                 :            : MODULE_PARM_DESC(fscache_defer_create,
      32                 :            :                  "Defer cookie creation to background thread");
      33                 :            : 
      34                 :            : unsigned fscache_debug;
      35                 :            : module_param_named(debug, fscache_debug, uint,
      36                 :            :                    S_IWUSR | S_IRUGO);
      37                 :            : MODULE_PARM_DESC(fscache_debug,
      38                 :            :                  "FS-Cache debugging mask");
      39                 :            : 
      40                 :            : struct kobject *fscache_root;
      41                 :            : struct workqueue_struct *fscache_object_wq;
      42                 :            : struct workqueue_struct *fscache_op_wq;
      43                 :            : 
      44                 :            : DEFINE_PER_CPU(wait_queue_head_t, fscache_object_cong_wait);
      45                 :            : 
      46                 :            : /* these values serve as lower bounds, will be adjusted in fscache_init() */
      47                 :            : static unsigned fscache_object_max_active = 4;
      48                 :            : static unsigned fscache_op_max_active = 2;
      49                 :            : 
      50                 :            : #ifdef CONFIG_SYSCTL
      51                 :            : static struct ctl_table_header *fscache_sysctl_header;
      52                 :            : 
      53                 :          0 : static int fscache_max_active_sysctl(struct ctl_table *table, int write,
      54                 :            :                                      void __user *buffer,
      55                 :            :                                      size_t *lenp, loff_t *ppos)
      56                 :            : {
      57                 :          0 :         struct workqueue_struct **wqp = table->extra1;
      58                 :          0 :         unsigned int *datap = table->data;
      59                 :            :         int ret;
      60                 :            : 
      61                 :          0 :         ret = proc_dointvec(table, write, buffer, lenp, ppos);
      62         [ #  # ]:          0 :         if (ret == 0)
      63                 :          0 :                 workqueue_set_max_active(*wqp, *datap);
      64                 :          0 :         return ret;
      65                 :            : }
      66                 :            : 
      67                 :            : static struct ctl_table fscache_sysctls[] = {
      68                 :            :         {
      69                 :            :                 .procname       = "object_max_active",
      70                 :            :                 .data           = &fscache_object_max_active,
      71                 :            :                 .maxlen         = sizeof(unsigned),
      72                 :            :                 .mode           = 0644,
      73                 :            :                 .proc_handler   = fscache_max_active_sysctl,
      74                 :            :                 .extra1         = &fscache_object_wq,
      75                 :            :         },
      76                 :            :         {
      77                 :            :                 .procname       = "operation_max_active",
      78                 :            :                 .data           = &fscache_op_max_active,
      79                 :            :                 .maxlen         = sizeof(unsigned),
      80                 :            :                 .mode           = 0644,
      81                 :            :                 .proc_handler   = fscache_max_active_sysctl,
      82                 :            :                 .extra1         = &fscache_op_wq,
      83                 :            :         },
      84                 :            :         {}
      85                 :            : };
      86                 :            : 
      87                 :            : static struct ctl_table fscache_sysctls_root[] = {
      88                 :            :         {
      89                 :            :                 .procname       = "fscache",
      90                 :            :                 .mode           = 0555,
      91                 :            :                 .child          = fscache_sysctls,
      92                 :            :         },
      93                 :            :         {}
      94                 :            : };
      95                 :            : #endif
      96                 :            : 
      97                 :            : /*
      98                 :            :  * initialise the fs caching module
      99                 :            :  */
     100                 :        207 : static int __init fscache_init(void)
     101                 :            : {
     102                 :        207 :         unsigned int nr_cpus = num_possible_cpus();
     103                 :            :         unsigned int cpu;
     104                 :            :         int ret;
     105                 :            : 
     106                 :        207 :         fscache_object_max_active =
     107                 :        207 :                 clamp_val(nr_cpus,
     108                 :            :                           fscache_object_max_active, WQ_UNBOUND_MAX_ACTIVE);
     109                 :            : 
     110                 :            :         ret = -ENOMEM;
     111                 :        207 :         fscache_object_wq = alloc_workqueue("fscache_object", WQ_UNBOUND,
     112                 :            :                                             fscache_object_max_active);
     113         [ +  - ]:        207 :         if (!fscache_object_wq)
     114                 :            :                 goto error_object_wq;
     115                 :            : 
     116                 :        207 :         fscache_op_max_active =
     117                 :        207 :                 clamp_val(fscache_object_max_active / 2,
     118                 :            :                           fscache_op_max_active, WQ_UNBOUND_MAX_ACTIVE);
     119                 :            : 
     120                 :            :         ret = -ENOMEM;
     121                 :        207 :         fscache_op_wq = alloc_workqueue("fscache_operation", WQ_UNBOUND,
     122                 :            :                                         fscache_op_max_active);
     123         [ +  - ]:        207 :         if (!fscache_op_wq)
     124                 :            :                 goto error_op_wq;
     125                 :            : 
     126         [ +  + ]:       1035 :         for_each_possible_cpu(cpu)
     127                 :        828 :                 init_waitqueue_head(&per_cpu(fscache_object_cong_wait, cpu));
     128                 :            : 
     129                 :        207 :         ret = fscache_proc_init();
     130         [ +  - ]:        207 :         if (ret < 0)
     131                 :            :                 goto error_proc;
     132                 :            : 
     133                 :            : #ifdef CONFIG_SYSCTL
     134                 :            :         ret = -ENOMEM;
     135                 :        207 :         fscache_sysctl_header = register_sysctl_table(fscache_sysctls_root);
     136         [ +  - ]:        207 :         if (!fscache_sysctl_header)
     137                 :            :                 goto error_sysctl;
     138                 :            : #endif
     139                 :            : 
     140                 :        207 :         fscache_cookie_jar = kmem_cache_create("fscache_cookie_jar",
     141                 :            :                                                sizeof(struct fscache_cookie),
     142                 :            :                                                0, 0, NULL);
     143         [ -  + ]:        207 :         if (!fscache_cookie_jar) {
     144                 :          0 :                 pr_notice("Failed to allocate a cookie jar\n");
     145                 :            :                 ret = -ENOMEM;
     146                 :          0 :                 goto error_cookie_jar;
     147                 :            :         }
     148                 :            : 
     149                 :        207 :         fscache_root = kobject_create_and_add("fscache", kernel_kobj);
     150         [ +  - ]:        207 :         if (!fscache_root)
     151                 :            :                 goto error_kobj;
     152                 :            : 
     153                 :        207 :         pr_notice("Loaded\n");
     154                 :        207 :         return 0;
     155                 :            : 
     156                 :            : error_kobj:
     157                 :          0 :         kmem_cache_destroy(fscache_cookie_jar);
     158                 :            : error_cookie_jar:
     159                 :            : #ifdef CONFIG_SYSCTL
     160                 :          0 :         unregister_sysctl_table(fscache_sysctl_header);
     161                 :            : error_sysctl:
     162                 :            : #endif
     163                 :          0 :         fscache_proc_cleanup();
     164                 :            : error_proc:
     165                 :          0 :         destroy_workqueue(fscache_op_wq);
     166                 :            : error_op_wq:
     167                 :          0 :         destroy_workqueue(fscache_object_wq);
     168                 :            : error_object_wq:
     169                 :          0 :         return ret;
     170                 :            : }
     171                 :            : 
     172                 :            : fs_initcall(fscache_init);
     173                 :            : 
     174                 :            : /*
     175                 :            :  * clean up on module removal
     176                 :            :  */
     177                 :          0 : static void __exit fscache_exit(void)
     178                 :            : {
     179                 :            :         _enter("");
     180                 :            : 
     181                 :          0 :         kobject_put(fscache_root);
     182                 :          0 :         kmem_cache_destroy(fscache_cookie_jar);
     183                 :            : #ifdef CONFIG_SYSCTL
     184                 :          0 :         unregister_sysctl_table(fscache_sysctl_header);
     185                 :            : #endif
     186                 :          0 :         fscache_proc_cleanup();
     187                 :          0 :         destroy_workqueue(fscache_op_wq);
     188                 :          0 :         destroy_workqueue(fscache_object_wq);
     189                 :          0 :         pr_notice("Unloaded\n");
     190                 :          0 : }
     191                 :            : 
     192                 :            : module_exit(fscache_exit);

Generated by: LCOV version 1.14