162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * (C) 2001 Clemson University and The University of Chicago 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Changes by Acxiom Corporation to add proc file handler for pvfs2 client 662306a36Sopenharmony_ci * parameters, Copyright Acxiom Corporation, 2005. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * See COPYING in top-level directory. 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include "protocol.h" 1262306a36Sopenharmony_ci#include "orangefs-kernel.h" 1362306a36Sopenharmony_ci#include "orangefs-debugfs.h" 1462306a36Sopenharmony_ci#include "orangefs-sysfs.h" 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/* ORANGEFS_VERSION is a ./configure define */ 1762306a36Sopenharmony_ci#ifndef ORANGEFS_VERSION 1862306a36Sopenharmony_ci#define ORANGEFS_VERSION "upstream" 1962306a36Sopenharmony_ci#endif 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci/* 2262306a36Sopenharmony_ci * global variables declared here 2362306a36Sopenharmony_ci */ 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cistruct orangefs_stats orangefs_stats; 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* the size of the hash tables for ops in progress */ 2862306a36Sopenharmony_ciint hash_table_size = 509; 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_cistatic ulong module_parm_debug_mask; 3162306a36Sopenharmony_ci__u64 orangefs_gossip_debug_mask; 3262306a36Sopenharmony_ciint op_timeout_secs = ORANGEFS_DEFAULT_OP_TIMEOUT_SECS; 3362306a36Sopenharmony_ciint slot_timeout_secs = ORANGEFS_DEFAULT_SLOT_TIMEOUT_SECS; 3462306a36Sopenharmony_ciint orangefs_cache_timeout_msecs = 500; 3562306a36Sopenharmony_ciint orangefs_dcache_timeout_msecs = 50; 3662306a36Sopenharmony_ciint orangefs_getattr_timeout_msecs = 50; 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 3962306a36Sopenharmony_ciMODULE_AUTHOR("ORANGEFS Development Team"); 4062306a36Sopenharmony_ciMODULE_DESCRIPTION("The Linux Kernel VFS interface to ORANGEFS"); 4162306a36Sopenharmony_ciMODULE_PARM_DESC(module_parm_debug_mask, "debugging level (see orangefs-debug.h for values)"); 4262306a36Sopenharmony_ciMODULE_PARM_DESC(op_timeout_secs, "Operation timeout in seconds"); 4362306a36Sopenharmony_ciMODULE_PARM_DESC(slot_timeout_secs, "Slot timeout in seconds"); 4462306a36Sopenharmony_ciMODULE_PARM_DESC(hash_table_size, 4562306a36Sopenharmony_ci "size of hash table for operations in progress"); 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_cistatic struct file_system_type orangefs_fs_type = { 4862306a36Sopenharmony_ci .name = "pvfs2", 4962306a36Sopenharmony_ci .mount = orangefs_mount, 5062306a36Sopenharmony_ci .kill_sb = orangefs_kill_sb, 5162306a36Sopenharmony_ci .owner = THIS_MODULE, 5262306a36Sopenharmony_ci}; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_cimodule_param(hash_table_size, int, 0); 5562306a36Sopenharmony_cimodule_param(module_parm_debug_mask, ulong, 0644); 5662306a36Sopenharmony_cimodule_param(op_timeout_secs, int, 0); 5762306a36Sopenharmony_cimodule_param(slot_timeout_secs, int, 0); 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/* 6062306a36Sopenharmony_ci * Blocks non-priority requests from being queued for servicing. This 6162306a36Sopenharmony_ci * could be used for protecting the request list data structure, but 6262306a36Sopenharmony_ci * for now it's only being used to stall the op addition to the request 6362306a36Sopenharmony_ci * list 6462306a36Sopenharmony_ci */ 6562306a36Sopenharmony_ciDEFINE_MUTEX(orangefs_request_mutex); 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci/* hash table for storing operations waiting for matching downcall */ 6862306a36Sopenharmony_cistruct list_head *orangefs_htable_ops_in_progress; 6962306a36Sopenharmony_ciDEFINE_SPINLOCK(orangefs_htable_ops_in_progress_lock); 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci/* list for queueing upcall operations */ 7262306a36Sopenharmony_ciLIST_HEAD(orangefs_request_list); 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci/* used to protect the above orangefs_request_list */ 7562306a36Sopenharmony_ciDEFINE_SPINLOCK(orangefs_request_list_lock); 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* used for incoming request notification */ 7862306a36Sopenharmony_ciDECLARE_WAIT_QUEUE_HEAD(orangefs_request_list_waitq); 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_cistatic int __init orangefs_init(void) 8162306a36Sopenharmony_ci{ 8262306a36Sopenharmony_ci int ret; 8362306a36Sopenharmony_ci __u32 i = 0; 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci if (op_timeout_secs < 0) 8662306a36Sopenharmony_ci op_timeout_secs = 0; 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci if (slot_timeout_secs < 0) 8962306a36Sopenharmony_ci slot_timeout_secs = 0; 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci /* initialize global book keeping data structures */ 9262306a36Sopenharmony_ci ret = op_cache_initialize(); 9362306a36Sopenharmony_ci if (ret < 0) 9462306a36Sopenharmony_ci goto out; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci ret = orangefs_inode_cache_initialize(); 9762306a36Sopenharmony_ci if (ret < 0) 9862306a36Sopenharmony_ci goto cleanup_op; 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci orangefs_htable_ops_in_progress = 10162306a36Sopenharmony_ci kcalloc(hash_table_size, sizeof(struct list_head), GFP_KERNEL); 10262306a36Sopenharmony_ci if (!orangefs_htable_ops_in_progress) { 10362306a36Sopenharmony_ci ret = -ENOMEM; 10462306a36Sopenharmony_ci goto cleanup_inode; 10562306a36Sopenharmony_ci } 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci /* initialize a doubly linked at each hash table index */ 10862306a36Sopenharmony_ci for (i = 0; i < hash_table_size; i++) 10962306a36Sopenharmony_ci INIT_LIST_HEAD(&orangefs_htable_ops_in_progress[i]); 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci ret = fsid_key_table_initialize(); 11262306a36Sopenharmony_ci if (ret < 0) 11362306a36Sopenharmony_ci goto cleanup_progress_table; 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci /* 11662306a36Sopenharmony_ci * Build the contents of /sys/kernel/debug/orangefs/debug-help 11762306a36Sopenharmony_ci * from the keywords in the kernel keyword/mask array. 11862306a36Sopenharmony_ci * 11962306a36Sopenharmony_ci * The keywords in the client keyword/mask array are 12062306a36Sopenharmony_ci * unknown at boot time. 12162306a36Sopenharmony_ci * 12262306a36Sopenharmony_ci * orangefs_prepare_debugfs_help_string will be used again 12362306a36Sopenharmony_ci * later to rebuild the debug-help-string after the client starts 12462306a36Sopenharmony_ci * and passes along the needed info. The argument signifies 12562306a36Sopenharmony_ci * which time orangefs_prepare_debugfs_help_string is being 12662306a36Sopenharmony_ci * called. 12762306a36Sopenharmony_ci */ 12862306a36Sopenharmony_ci ret = orangefs_prepare_debugfs_help_string(1); 12962306a36Sopenharmony_ci if (ret) 13062306a36Sopenharmony_ci goto cleanup_key_table; 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci orangefs_debugfs_init(module_parm_debug_mask); 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci ret = orangefs_sysfs_init(); 13562306a36Sopenharmony_ci if (ret) 13662306a36Sopenharmony_ci goto sysfs_init_failed; 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci /* Initialize the orangefsdev subsystem. */ 13962306a36Sopenharmony_ci ret = orangefs_dev_init(); 14062306a36Sopenharmony_ci if (ret < 0) { 14162306a36Sopenharmony_ci gossip_err("%s: could not initialize device subsystem %d!\n", 14262306a36Sopenharmony_ci __func__, 14362306a36Sopenharmony_ci ret); 14462306a36Sopenharmony_ci goto cleanup_sysfs; 14562306a36Sopenharmony_ci } 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci ret = register_filesystem(&orangefs_fs_type); 14862306a36Sopenharmony_ci if (ret == 0) { 14962306a36Sopenharmony_ci pr_info("%s: module version %s loaded\n", 15062306a36Sopenharmony_ci __func__, 15162306a36Sopenharmony_ci ORANGEFS_VERSION); 15262306a36Sopenharmony_ci goto out; 15362306a36Sopenharmony_ci } 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci orangefs_dev_cleanup(); 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_cicleanup_sysfs: 15862306a36Sopenharmony_ci orangefs_sysfs_exit(); 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_cisysfs_init_failed: 16162306a36Sopenharmony_ci orangefs_debugfs_cleanup(); 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_cicleanup_key_table: 16462306a36Sopenharmony_ci fsid_key_table_finalize(); 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_cicleanup_progress_table: 16762306a36Sopenharmony_ci kfree(orangefs_htable_ops_in_progress); 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_cicleanup_inode: 17062306a36Sopenharmony_ci orangefs_inode_cache_finalize(); 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_cicleanup_op: 17362306a36Sopenharmony_ci op_cache_finalize(); 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ciout: 17662306a36Sopenharmony_ci return ret; 17762306a36Sopenharmony_ci} 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_cistatic void __exit orangefs_exit(void) 18062306a36Sopenharmony_ci{ 18162306a36Sopenharmony_ci int i = 0; 18262306a36Sopenharmony_ci gossip_debug(GOSSIP_INIT_DEBUG, "orangefs: orangefs_exit called\n"); 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci unregister_filesystem(&orangefs_fs_type); 18562306a36Sopenharmony_ci orangefs_debugfs_cleanup(); 18662306a36Sopenharmony_ci orangefs_sysfs_exit(); 18762306a36Sopenharmony_ci fsid_key_table_finalize(); 18862306a36Sopenharmony_ci orangefs_dev_cleanup(); 18962306a36Sopenharmony_ci BUG_ON(!list_empty(&orangefs_request_list)); 19062306a36Sopenharmony_ci for (i = 0; i < hash_table_size; i++) 19162306a36Sopenharmony_ci BUG_ON(!list_empty(&orangefs_htable_ops_in_progress[i])); 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci orangefs_inode_cache_finalize(); 19462306a36Sopenharmony_ci op_cache_finalize(); 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci kfree(orangefs_htable_ops_in_progress); 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci pr_info("orangefs: module version %s unloaded\n", ORANGEFS_VERSION); 19962306a36Sopenharmony_ci} 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci/* 20262306a36Sopenharmony_ci * What we do in this function is to walk the list of operations 20362306a36Sopenharmony_ci * that are in progress in the hash table and mark them as purged as well. 20462306a36Sopenharmony_ci */ 20562306a36Sopenharmony_civoid purge_inprogress_ops(void) 20662306a36Sopenharmony_ci{ 20762306a36Sopenharmony_ci int i; 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci for (i = 0; i < hash_table_size; i++) { 21062306a36Sopenharmony_ci struct orangefs_kernel_op_s *op; 21162306a36Sopenharmony_ci struct orangefs_kernel_op_s *next; 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ci spin_lock(&orangefs_htable_ops_in_progress_lock); 21462306a36Sopenharmony_ci list_for_each_entry_safe(op, 21562306a36Sopenharmony_ci next, 21662306a36Sopenharmony_ci &orangefs_htable_ops_in_progress[i], 21762306a36Sopenharmony_ci list) { 21862306a36Sopenharmony_ci set_op_state_purged(op); 21962306a36Sopenharmony_ci gossip_debug(GOSSIP_DEV_DEBUG, 22062306a36Sopenharmony_ci "%s: op:%s: op_state:%d: process:%s:\n", 22162306a36Sopenharmony_ci __func__, 22262306a36Sopenharmony_ci get_opname_string(op), 22362306a36Sopenharmony_ci op->op_state, 22462306a36Sopenharmony_ci current->comm); 22562306a36Sopenharmony_ci } 22662306a36Sopenharmony_ci spin_unlock(&orangefs_htable_ops_in_progress_lock); 22762306a36Sopenharmony_ci } 22862306a36Sopenharmony_ci} 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_cimodule_init(orangefs_init); 23162306a36Sopenharmony_cimodule_exit(orangefs_exit); 232