18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * (C) 2001 Clemson University and The University of Chicago
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Changes by Acxiom Corporation to add proc file handler for pvfs2 client
68c2ecf20Sopenharmony_ci * parameters, Copyright Acxiom Corporation, 2005.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * See COPYING in top-level directory.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include "protocol.h"
128c2ecf20Sopenharmony_ci#include "orangefs-kernel.h"
138c2ecf20Sopenharmony_ci#include "orangefs-debugfs.h"
148c2ecf20Sopenharmony_ci#include "orangefs-sysfs.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/* ORANGEFS_VERSION is a ./configure define */
178c2ecf20Sopenharmony_ci#ifndef ORANGEFS_VERSION
188c2ecf20Sopenharmony_ci#define ORANGEFS_VERSION "upstream"
198c2ecf20Sopenharmony_ci#endif
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*
228c2ecf20Sopenharmony_ci * global variables declared here
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistruct orangefs_stats orangefs_stats;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* the size of the hash tables for ops in progress */
288c2ecf20Sopenharmony_ciint hash_table_size = 509;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic ulong module_parm_debug_mask;
318c2ecf20Sopenharmony_ci__u64 orangefs_gossip_debug_mask;
328c2ecf20Sopenharmony_ciint op_timeout_secs = ORANGEFS_DEFAULT_OP_TIMEOUT_SECS;
338c2ecf20Sopenharmony_ciint slot_timeout_secs = ORANGEFS_DEFAULT_SLOT_TIMEOUT_SECS;
348c2ecf20Sopenharmony_ciint orangefs_cache_timeout_msecs = 50;
358c2ecf20Sopenharmony_ciint orangefs_dcache_timeout_msecs = 50;
368c2ecf20Sopenharmony_ciint orangefs_getattr_timeout_msecs = 50;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
398c2ecf20Sopenharmony_ciMODULE_AUTHOR("ORANGEFS Development Team");
408c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("The Linux Kernel VFS interface to ORANGEFS");
418c2ecf20Sopenharmony_ciMODULE_PARM_DESC(module_parm_debug_mask, "debugging level (see orangefs-debug.h for values)");
428c2ecf20Sopenharmony_ciMODULE_PARM_DESC(op_timeout_secs, "Operation timeout in seconds");
438c2ecf20Sopenharmony_ciMODULE_PARM_DESC(slot_timeout_secs, "Slot timeout in seconds");
448c2ecf20Sopenharmony_ciMODULE_PARM_DESC(hash_table_size,
458c2ecf20Sopenharmony_ci		 "size of hash table for operations in progress");
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistatic struct file_system_type orangefs_fs_type = {
488c2ecf20Sopenharmony_ci	.name = "pvfs2",
498c2ecf20Sopenharmony_ci	.mount = orangefs_mount,
508c2ecf20Sopenharmony_ci	.kill_sb = orangefs_kill_sb,
518c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cimodule_param(hash_table_size, int, 0);
558c2ecf20Sopenharmony_cimodule_param(module_parm_debug_mask, ulong, 0644);
568c2ecf20Sopenharmony_cimodule_param(op_timeout_secs, int, 0);
578c2ecf20Sopenharmony_cimodule_param(slot_timeout_secs, int, 0);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/*
608c2ecf20Sopenharmony_ci * Blocks non-priority requests from being queued for servicing.  This
618c2ecf20Sopenharmony_ci * could be used for protecting the request list data structure, but
628c2ecf20Sopenharmony_ci * for now it's only being used to stall the op addition to the request
638c2ecf20Sopenharmony_ci * list
648c2ecf20Sopenharmony_ci */
658c2ecf20Sopenharmony_ciDEFINE_MUTEX(orangefs_request_mutex);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/* hash table for storing operations waiting for matching downcall */
688c2ecf20Sopenharmony_cistruct list_head *orangefs_htable_ops_in_progress;
698c2ecf20Sopenharmony_ciDEFINE_SPINLOCK(orangefs_htable_ops_in_progress_lock);
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/* list for queueing upcall operations */
728c2ecf20Sopenharmony_ciLIST_HEAD(orangefs_request_list);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* used to protect the above orangefs_request_list */
758c2ecf20Sopenharmony_ciDEFINE_SPINLOCK(orangefs_request_list_lock);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/* used for incoming request notification */
788c2ecf20Sopenharmony_ciDECLARE_WAIT_QUEUE_HEAD(orangefs_request_list_waitq);
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic int __init orangefs_init(void)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	int ret;
838c2ecf20Sopenharmony_ci	__u32 i = 0;
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	if (op_timeout_secs < 0)
868c2ecf20Sopenharmony_ci		op_timeout_secs = 0;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	if (slot_timeout_secs < 0)
898c2ecf20Sopenharmony_ci		slot_timeout_secs = 0;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	/* initialize global book keeping data structures */
928c2ecf20Sopenharmony_ci	ret = op_cache_initialize();
938c2ecf20Sopenharmony_ci	if (ret < 0)
948c2ecf20Sopenharmony_ci		goto out;
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci	ret = orangefs_inode_cache_initialize();
978c2ecf20Sopenharmony_ci	if (ret < 0)
988c2ecf20Sopenharmony_ci		goto cleanup_op;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	orangefs_htable_ops_in_progress =
1018c2ecf20Sopenharmony_ci	    kcalloc(hash_table_size, sizeof(struct list_head), GFP_KERNEL);
1028c2ecf20Sopenharmony_ci	if (!orangefs_htable_ops_in_progress) {
1038c2ecf20Sopenharmony_ci		ret = -ENOMEM;
1048c2ecf20Sopenharmony_ci		goto cleanup_inode;
1058c2ecf20Sopenharmony_ci	}
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	/* initialize a doubly linked at each hash table index */
1088c2ecf20Sopenharmony_ci	for (i = 0; i < hash_table_size; i++)
1098c2ecf20Sopenharmony_ci		INIT_LIST_HEAD(&orangefs_htable_ops_in_progress[i]);
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	ret = fsid_key_table_initialize();
1128c2ecf20Sopenharmony_ci	if (ret < 0)
1138c2ecf20Sopenharmony_ci		goto cleanup_progress_table;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	/*
1168c2ecf20Sopenharmony_ci	 * Build the contents of /sys/kernel/debug/orangefs/debug-help
1178c2ecf20Sopenharmony_ci	 * from the keywords in the kernel keyword/mask array.
1188c2ecf20Sopenharmony_ci	 *
1198c2ecf20Sopenharmony_ci	 * The keywords in the client keyword/mask array are
1208c2ecf20Sopenharmony_ci	 * unknown at boot time.
1218c2ecf20Sopenharmony_ci	 *
1228c2ecf20Sopenharmony_ci	 * orangefs_prepare_debugfs_help_string will be used again
1238c2ecf20Sopenharmony_ci	 * later to rebuild the debug-help-string after the client starts
1248c2ecf20Sopenharmony_ci	 * and passes along the needed info. The argument signifies
1258c2ecf20Sopenharmony_ci	 * which time orangefs_prepare_debugfs_help_string is being
1268c2ecf20Sopenharmony_ci	 * called.
1278c2ecf20Sopenharmony_ci	 */
1288c2ecf20Sopenharmony_ci	ret = orangefs_prepare_debugfs_help_string(1);
1298c2ecf20Sopenharmony_ci	if (ret)
1308c2ecf20Sopenharmony_ci		goto cleanup_key_table;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	orangefs_debugfs_init(module_parm_debug_mask);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	ret = orangefs_sysfs_init();
1358c2ecf20Sopenharmony_ci	if (ret)
1368c2ecf20Sopenharmony_ci		goto sysfs_init_failed;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	/* Initialize the orangefsdev subsystem. */
1398c2ecf20Sopenharmony_ci	ret = orangefs_dev_init();
1408c2ecf20Sopenharmony_ci	if (ret < 0) {
1418c2ecf20Sopenharmony_ci		gossip_err("%s: could not initialize device subsystem %d!\n",
1428c2ecf20Sopenharmony_ci			   __func__,
1438c2ecf20Sopenharmony_ci			   ret);
1448c2ecf20Sopenharmony_ci		goto cleanup_sysfs;
1458c2ecf20Sopenharmony_ci	}
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	ret = register_filesystem(&orangefs_fs_type);
1488c2ecf20Sopenharmony_ci	if (ret == 0) {
1498c2ecf20Sopenharmony_ci		pr_info("%s: module version %s loaded\n",
1508c2ecf20Sopenharmony_ci			__func__,
1518c2ecf20Sopenharmony_ci			ORANGEFS_VERSION);
1528c2ecf20Sopenharmony_ci		goto out;
1538c2ecf20Sopenharmony_ci	}
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	orangefs_dev_cleanup();
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cicleanup_sysfs:
1588c2ecf20Sopenharmony_ci	orangefs_sysfs_exit();
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cisysfs_init_failed:
1618c2ecf20Sopenharmony_ci	orangefs_debugfs_cleanup();
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cicleanup_key_table:
1648c2ecf20Sopenharmony_ci	fsid_key_table_finalize();
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_cicleanup_progress_table:
1678c2ecf20Sopenharmony_ci	kfree(orangefs_htable_ops_in_progress);
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_cicleanup_inode:
1708c2ecf20Sopenharmony_ci	orangefs_inode_cache_finalize();
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_cicleanup_op:
1738c2ecf20Sopenharmony_ci	op_cache_finalize();
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ciout:
1768c2ecf20Sopenharmony_ci	return ret;
1778c2ecf20Sopenharmony_ci}
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_cistatic void __exit orangefs_exit(void)
1808c2ecf20Sopenharmony_ci{
1818c2ecf20Sopenharmony_ci	int i = 0;
1828c2ecf20Sopenharmony_ci	gossip_debug(GOSSIP_INIT_DEBUG, "orangefs: orangefs_exit called\n");
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	unregister_filesystem(&orangefs_fs_type);
1858c2ecf20Sopenharmony_ci	orangefs_debugfs_cleanup();
1868c2ecf20Sopenharmony_ci	orangefs_sysfs_exit();
1878c2ecf20Sopenharmony_ci	fsid_key_table_finalize();
1888c2ecf20Sopenharmony_ci	orangefs_dev_cleanup();
1898c2ecf20Sopenharmony_ci	BUG_ON(!list_empty(&orangefs_request_list));
1908c2ecf20Sopenharmony_ci	for (i = 0; i < hash_table_size; i++)
1918c2ecf20Sopenharmony_ci		BUG_ON(!list_empty(&orangefs_htable_ops_in_progress[i]));
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci	orangefs_inode_cache_finalize();
1948c2ecf20Sopenharmony_ci	op_cache_finalize();
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	kfree(orangefs_htable_ops_in_progress);
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci	pr_info("orangefs: module version %s unloaded\n", ORANGEFS_VERSION);
1998c2ecf20Sopenharmony_ci}
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/*
2028c2ecf20Sopenharmony_ci * What we do in this function is to walk the list of operations
2038c2ecf20Sopenharmony_ci * that are in progress in the hash table and mark them as purged as well.
2048c2ecf20Sopenharmony_ci */
2058c2ecf20Sopenharmony_civoid purge_inprogress_ops(void)
2068c2ecf20Sopenharmony_ci{
2078c2ecf20Sopenharmony_ci	int i;
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci	for (i = 0; i < hash_table_size; i++) {
2108c2ecf20Sopenharmony_ci		struct orangefs_kernel_op_s *op;
2118c2ecf20Sopenharmony_ci		struct orangefs_kernel_op_s *next;
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci		spin_lock(&orangefs_htable_ops_in_progress_lock);
2148c2ecf20Sopenharmony_ci		list_for_each_entry_safe(op,
2158c2ecf20Sopenharmony_ci					 next,
2168c2ecf20Sopenharmony_ci					 &orangefs_htable_ops_in_progress[i],
2178c2ecf20Sopenharmony_ci					 list) {
2188c2ecf20Sopenharmony_ci			set_op_state_purged(op);
2198c2ecf20Sopenharmony_ci			gossip_debug(GOSSIP_DEV_DEBUG,
2208c2ecf20Sopenharmony_ci				     "%s: op:%s: op_state:%d: process:%s:\n",
2218c2ecf20Sopenharmony_ci				     __func__,
2228c2ecf20Sopenharmony_ci				     get_opname_string(op),
2238c2ecf20Sopenharmony_ci				     op->op_state,
2248c2ecf20Sopenharmony_ci				     current->comm);
2258c2ecf20Sopenharmony_ci		}
2268c2ecf20Sopenharmony_ci		spin_unlock(&orangefs_htable_ops_in_progress_lock);
2278c2ecf20Sopenharmony_ci	}
2288c2ecf20Sopenharmony_ci}
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_cimodule_init(orangefs_init);
2318c2ecf20Sopenharmony_cimodule_exit(orangefs_exit);
232