Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * (C) 2001 Clemson University and The University of Chicago
0004  *
0005  * Changes by Acxiom Corporation to add proc file handler for pvfs2 client
0006  * parameters, Copyright Acxiom Corporation, 2005.
0007  *
0008  * See COPYING in top-level directory.
0009  */
0010 
0011 #include "protocol.h"
0012 #include "orangefs-kernel.h"
0013 #include "orangefs-debugfs.h"
0014 #include "orangefs-sysfs.h"
0015 
0016 /* ORANGEFS_VERSION is a ./configure define */
0017 #ifndef ORANGEFS_VERSION
0018 #define ORANGEFS_VERSION "upstream"
0019 #endif
0020 
0021 /*
0022  * global variables declared here
0023  */
0024 
0025 struct orangefs_stats orangefs_stats;
0026 
0027 /* the size of the hash tables for ops in progress */
0028 int hash_table_size = 509;
0029 
0030 static ulong module_parm_debug_mask;
0031 __u64 orangefs_gossip_debug_mask;
0032 int op_timeout_secs = ORANGEFS_DEFAULT_OP_TIMEOUT_SECS;
0033 int slot_timeout_secs = ORANGEFS_DEFAULT_SLOT_TIMEOUT_SECS;
0034 int orangefs_cache_timeout_msecs = 500;
0035 int orangefs_dcache_timeout_msecs = 50;
0036 int orangefs_getattr_timeout_msecs = 50;
0037 
0038 MODULE_LICENSE("GPL");
0039 MODULE_AUTHOR("ORANGEFS Development Team");
0040 MODULE_DESCRIPTION("The Linux Kernel VFS interface to ORANGEFS");
0041 MODULE_PARM_DESC(module_parm_debug_mask, "debugging level (see orangefs-debug.h for values)");
0042 MODULE_PARM_DESC(op_timeout_secs, "Operation timeout in seconds");
0043 MODULE_PARM_DESC(slot_timeout_secs, "Slot timeout in seconds");
0044 MODULE_PARM_DESC(hash_table_size,
0045          "size of hash table for operations in progress");
0046 
0047 static struct file_system_type orangefs_fs_type = {
0048     .name = "pvfs2",
0049     .mount = orangefs_mount,
0050     .kill_sb = orangefs_kill_sb,
0051     .owner = THIS_MODULE,
0052 };
0053 
0054 module_param(hash_table_size, int, 0);
0055 module_param(module_parm_debug_mask, ulong, 0644);
0056 module_param(op_timeout_secs, int, 0);
0057 module_param(slot_timeout_secs, int, 0);
0058 
0059 /*
0060  * Blocks non-priority requests from being queued for servicing.  This
0061  * could be used for protecting the request list data structure, but
0062  * for now it's only being used to stall the op addition to the request
0063  * list
0064  */
0065 DEFINE_MUTEX(orangefs_request_mutex);
0066 
0067 /* hash table for storing operations waiting for matching downcall */
0068 struct list_head *orangefs_htable_ops_in_progress;
0069 DEFINE_SPINLOCK(orangefs_htable_ops_in_progress_lock);
0070 
0071 /* list for queueing upcall operations */
0072 LIST_HEAD(orangefs_request_list);
0073 
0074 /* used to protect the above orangefs_request_list */
0075 DEFINE_SPINLOCK(orangefs_request_list_lock);
0076 
0077 /* used for incoming request notification */
0078 DECLARE_WAIT_QUEUE_HEAD(orangefs_request_list_waitq);
0079 
0080 static int __init orangefs_init(void)
0081 {
0082     int ret;
0083     __u32 i = 0;
0084 
0085     if (op_timeout_secs < 0)
0086         op_timeout_secs = 0;
0087 
0088     if (slot_timeout_secs < 0)
0089         slot_timeout_secs = 0;
0090 
0091     /* initialize global book keeping data structures */
0092     ret = op_cache_initialize();
0093     if (ret < 0)
0094         goto out;
0095 
0096     ret = orangefs_inode_cache_initialize();
0097     if (ret < 0)
0098         goto cleanup_op;
0099 
0100     orangefs_htable_ops_in_progress =
0101         kcalloc(hash_table_size, sizeof(struct list_head), GFP_KERNEL);
0102     if (!orangefs_htable_ops_in_progress) {
0103         ret = -ENOMEM;
0104         goto cleanup_inode;
0105     }
0106 
0107     /* initialize a doubly linked at each hash table index */
0108     for (i = 0; i < hash_table_size; i++)
0109         INIT_LIST_HEAD(&orangefs_htable_ops_in_progress[i]);
0110 
0111     ret = fsid_key_table_initialize();
0112     if (ret < 0)
0113         goto cleanup_progress_table;
0114 
0115     /*
0116      * Build the contents of /sys/kernel/debug/orangefs/debug-help
0117      * from the keywords in the kernel keyword/mask array.
0118      *
0119      * The keywords in the client keyword/mask array are
0120      * unknown at boot time.
0121      *
0122      * orangefs_prepare_debugfs_help_string will be used again
0123      * later to rebuild the debug-help-string after the client starts
0124      * and passes along the needed info. The argument signifies
0125      * which time orangefs_prepare_debugfs_help_string is being
0126      * called.
0127      */
0128     ret = orangefs_prepare_debugfs_help_string(1);
0129     if (ret)
0130         goto cleanup_key_table;
0131 
0132     orangefs_debugfs_init(module_parm_debug_mask);
0133 
0134     ret = orangefs_sysfs_init();
0135     if (ret)
0136         goto sysfs_init_failed;
0137 
0138     /* Initialize the orangefsdev subsystem. */
0139     ret = orangefs_dev_init();
0140     if (ret < 0) {
0141         gossip_err("%s: could not initialize device subsystem %d!\n",
0142                __func__,
0143                ret);
0144         goto cleanup_device;
0145     }
0146 
0147     ret = register_filesystem(&orangefs_fs_type);
0148     if (ret == 0) {
0149         pr_info("%s: module version %s loaded\n",
0150             __func__,
0151             ORANGEFS_VERSION);
0152         goto out;
0153     }
0154 
0155     orangefs_sysfs_exit();
0156 
0157 cleanup_device:
0158     orangefs_dev_cleanup();
0159 
0160 sysfs_init_failed:
0161     orangefs_debugfs_cleanup();
0162 
0163 cleanup_key_table:
0164     fsid_key_table_finalize();
0165 
0166 cleanup_progress_table:
0167     kfree(orangefs_htable_ops_in_progress);
0168 
0169 cleanup_inode:
0170     orangefs_inode_cache_finalize();
0171 
0172 cleanup_op:
0173     op_cache_finalize();
0174 
0175 out:
0176     return ret;
0177 }
0178 
0179 static void __exit orangefs_exit(void)
0180 {
0181     int i = 0;
0182     gossip_debug(GOSSIP_INIT_DEBUG, "orangefs: orangefs_exit called\n");
0183 
0184     unregister_filesystem(&orangefs_fs_type);
0185     orangefs_debugfs_cleanup();
0186     orangefs_sysfs_exit();
0187     fsid_key_table_finalize();
0188     orangefs_dev_cleanup();
0189     BUG_ON(!list_empty(&orangefs_request_list));
0190     for (i = 0; i < hash_table_size; i++)
0191         BUG_ON(!list_empty(&orangefs_htable_ops_in_progress[i]));
0192 
0193     orangefs_inode_cache_finalize();
0194     op_cache_finalize();
0195 
0196     kfree(orangefs_htable_ops_in_progress);
0197 
0198     pr_info("orangefs: module version %s unloaded\n", ORANGEFS_VERSION);
0199 }
0200 
0201 /*
0202  * What we do in this function is to walk the list of operations
0203  * that are in progress in the hash table and mark them as purged as well.
0204  */
0205 void purge_inprogress_ops(void)
0206 {
0207     int i;
0208 
0209     for (i = 0; i < hash_table_size; i++) {
0210         struct orangefs_kernel_op_s *op;
0211         struct orangefs_kernel_op_s *next;
0212 
0213         spin_lock(&orangefs_htable_ops_in_progress_lock);
0214         list_for_each_entry_safe(op,
0215                      next,
0216                      &orangefs_htable_ops_in_progress[i],
0217                      list) {
0218             set_op_state_purged(op);
0219             gossip_debug(GOSSIP_DEV_DEBUG,
0220                      "%s: op:%s: op_state:%d: process:%s:\n",
0221                      __func__,
0222                      get_opname_string(op),
0223                      op->op_state,
0224                      current->comm);
0225         }
0226         spin_unlock(&orangefs_htable_ops_in_progress_lock);
0227     }
0228 }
0229 
0230 module_init(orangefs_init);
0231 module_exit(orangefs_exit);