orangefs-mod.c 5.9 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
M
Mike Marshall 已提交
2 3 4 5 6 7 8 9 10 11
/*
 * (C) 2001 Clemson University and The University of Chicago
 *
 * Changes by Acxiom Corporation to add proc file handler for pvfs2 client
 * parameters, Copyright Acxiom Corporation, 2005.
 *
 * See COPYING in top-level directory.
 */

#include "protocol.h"
12 13 14
#include "orangefs-kernel.h"
#include "orangefs-debugfs.h"
#include "orangefs-sysfs.h"
M
Mike Marshall 已提交
15

16 17
/* ORANGEFS_VERSION is a ./configure define */
#ifndef ORANGEFS_VERSION
18
#define ORANGEFS_VERSION "upstream"
M
Mike Marshall 已提交
19 20 21 22 23 24
#endif

/*
 * global variables declared here
 */

25
struct orangefs_stats orangefs_stats;
M
Mike Marshall 已提交
26 27 28 29 30

/* the size of the hash tables for ops in progress */
int hash_table_size = 509;

static ulong module_parm_debug_mask;
31
__u64 orangefs_gossip_debug_mask;
32 33
int op_timeout_secs = ORANGEFS_DEFAULT_OP_TIMEOUT_SECS;
int slot_timeout_secs = ORANGEFS_DEFAULT_SLOT_TIMEOUT_SECS;
34
int orangefs_cache_timeout_msecs = 500;
35 36
int orangefs_dcache_timeout_msecs = 50;
int orangefs_getattr_timeout_msecs = 50;
M
Mike Marshall 已提交
37 38

MODULE_LICENSE("GPL");
39 40 41
MODULE_AUTHOR("ORANGEFS Development Team");
MODULE_DESCRIPTION("The Linux Kernel VFS interface to ORANGEFS");
MODULE_PARM_DESC(module_parm_debug_mask, "debugging level (see orangefs-debug.h for values)");
M
Mike Marshall 已提交
42 43 44 45 46
MODULE_PARM_DESC(op_timeout_secs, "Operation timeout in seconds");
MODULE_PARM_DESC(slot_timeout_secs, "Slot timeout in seconds");
MODULE_PARM_DESC(hash_table_size,
		 "size of hash table for operations in progress");

47
static struct file_system_type orangefs_fs_type = {
M
Mike Marshall 已提交
48
	.name = "pvfs2",
49 50
	.mount = orangefs_mount,
	.kill_sb = orangefs_kill_sb,
M
Mike Marshall 已提交
51 52 53 54
	.owner = THIS_MODULE,
};

module_param(hash_table_size, int, 0);
55
module_param(module_parm_debug_mask, ulong, 0644);
M
Mike Marshall 已提交
56 57 58 59
module_param(op_timeout_secs, int, 0);
module_param(slot_timeout_secs, int, 0);

/*
60 61 62 63 64
 * Blocks non-priority requests from being queued for servicing.  This
 * could be used for protecting the request list data structure, but
 * for now it's only being used to stall the op addition to the request
 * list
 */
65
DEFINE_MUTEX(orangefs_request_mutex);
M
Mike Marshall 已提交
66 67

/* hash table for storing operations waiting for matching downcall */
68 69
struct list_head *orangefs_htable_ops_in_progress;
DEFINE_SPINLOCK(orangefs_htable_ops_in_progress_lock);
M
Mike Marshall 已提交
70 71

/* list for queueing upcall operations */
72
LIST_HEAD(orangefs_request_list);
M
Mike Marshall 已提交
73

74 75
/* used to protect the above orangefs_request_list */
DEFINE_SPINLOCK(orangefs_request_list_lock);
M
Mike Marshall 已提交
76 77

/* used for incoming request notification */
78
DECLARE_WAIT_QUEUE_HEAD(orangefs_request_list_waitq);
M
Mike Marshall 已提交
79

80
static int __init orangefs_init(void)
M
Mike Marshall 已提交
81
{
82
	int ret;
M
Mike Marshall 已提交
83 84 85 86 87 88 89 90 91 92 93
	__u32 i = 0;

	if (op_timeout_secs < 0)
		op_timeout_secs = 0;

	if (slot_timeout_secs < 0)
		slot_timeout_secs = 0;

	/* initialize global book keeping data structures */
	ret = op_cache_initialize();
	if (ret < 0)
94
		goto out;
M
Mike Marshall 已提交
95

96
	ret = orangefs_inode_cache_initialize();
M
Mike Marshall 已提交
97
	if (ret < 0)
98
		goto cleanup_op;
M
Mike Marshall 已提交
99

100
	orangefs_htable_ops_in_progress =
M
Mike Marshall 已提交
101
	    kcalloc(hash_table_size, sizeof(struct list_head), GFP_KERNEL);
102
	if (!orangefs_htable_ops_in_progress) {
M
Mike Marshall 已提交
103
		ret = -ENOMEM;
104
		goto cleanup_inode;
M
Mike Marshall 已提交
105 106 107 108
	}

	/* initialize a doubly linked at each hash table index */
	for (i = 0; i < hash_table_size; i++)
109
		INIT_LIST_HEAD(&orangefs_htable_ops_in_progress[i]);
M
Mike Marshall 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122

	ret = fsid_key_table_initialize();
	if (ret < 0)
		goto cleanup_progress_table;

	/*
	 * Build the contents of /sys/kernel/debug/orangefs/debug-help
	 * from the keywords in the kernel keyword/mask array.
	 *
	 * The keywords in the client keyword/mask array are
	 * unknown at boot time.
	 *
	 * orangefs_prepare_debugfs_help_string will be used again
M
Mike Marshall 已提交
123
	 * later to rebuild the debug-help-string after the client starts
M
Mike Marshall 已提交
124 125 126 127 128 129
	 * and passes along the needed info. The argument signifies
	 * which time orangefs_prepare_debugfs_help_string is being
	 * called.
	 */
	ret = orangefs_prepare_debugfs_help_string(1);
	if (ret)
130
		goto cleanup_key_table;
131

132
	orangefs_debugfs_init(module_parm_debug_mask);
M
Mike Marshall 已提交
133

134 135 136
	ret = orangefs_sysfs_init();
	if (ret)
		goto sysfs_init_failed;
M
Mike Marshall 已提交
137

138 139 140 141 142 143 144 145 146
	/* Initialize the orangefsdev subsystem. */
	ret = orangefs_dev_init();
	if (ret < 0) {
		gossip_err("%s: could not initialize device subsystem %d!\n",
			   __func__,
			   ret);
		goto cleanup_device;
	}

147
	ret = register_filesystem(&orangefs_fs_type);
M
Mike Marshall 已提交
148
	if (ret == 0) {
M
Mike Marshall 已提交
149 150 151
		pr_info("%s: module version %s loaded\n",
			__func__,
			ORANGEFS_VERSION);
152
		goto out;
M
Mike Marshall 已提交
153 154 155 156
	}

	orangefs_sysfs_exit();

157 158 159
cleanup_device:
	orangefs_dev_cleanup();

160 161 162
sysfs_init_failed:
	orangefs_debugfs_cleanup();

163 164
cleanup_key_table:
	fsid_key_table_finalize();
165

M
Mike Marshall 已提交
166
cleanup_progress_table:
167
	kfree(orangefs_htable_ops_in_progress);
M
Mike Marshall 已提交
168 169

cleanup_inode:
170
	orangefs_inode_cache_finalize();
M
Mike Marshall 已提交
171 172 173 174 175 176 177 178

cleanup_op:
	op_cache_finalize();

out:
	return ret;
}

179
static void __exit orangefs_exit(void)
M
Mike Marshall 已提交
180 181
{
	int i = 0;
182
	gossip_debug(GOSSIP_INIT_DEBUG, "orangefs: orangefs_exit called\n");
M
Mike Marshall 已提交
183

184 185
	unregister_filesystem(&orangefs_fs_type);
	orangefs_debugfs_cleanup();
M
Mike Marshall 已提交
186 187
	orangefs_sysfs_exit();
	fsid_key_table_finalize();
188
	orangefs_dev_cleanup();
189
	BUG_ON(!list_empty(&orangefs_request_list));
M
Mike Marshall 已提交
190
	for (i = 0; i < hash_table_size; i++)
191
		BUG_ON(!list_empty(&orangefs_htable_ops_in_progress[i]));
M
Mike Marshall 已提交
192

193
	orangefs_inode_cache_finalize();
M
Mike Marshall 已提交
194 195
	op_cache_finalize();

196
	kfree(orangefs_htable_ops_in_progress);
M
Mike Marshall 已提交
197

198
	pr_info("orangefs: module version %s unloaded\n", ORANGEFS_VERSION);
M
Mike Marshall 已提交
199 200 201 202 203 204 205 206 207 208 209
}

/*
 * What we do in this function is to walk the list of operations
 * that are in progress in the hash table and mark them as purged as well.
 */
void purge_inprogress_ops(void)
{
	int i;

	for (i = 0; i < hash_table_size; i++) {
210 211
		struct orangefs_kernel_op_s *op;
		struct orangefs_kernel_op_s *next;
M
Mike Marshall 已提交
212

213
		spin_lock(&orangefs_htable_ops_in_progress_lock);
M
Mike Marshall 已提交
214 215
		list_for_each_entry_safe(op,
					 next,
216
					 &orangefs_htable_ops_in_progress[i],
M
Mike Marshall 已提交
217 218
					 list) {
			set_op_state_purged(op);
219 220 221 222 223 224
			gossip_debug(GOSSIP_DEV_DEBUG,
				     "%s: op:%s: op_state:%d: process:%s:\n",
				     __func__,
				     get_opname_string(op),
				     op->op_state,
				     current->comm);
M
Mike Marshall 已提交
225
		}
226
		spin_unlock(&orangefs_htable_ops_in_progress_lock);
M
Mike Marshall 已提交
227 228 229
	}
}

230 231
module_init(orangefs_init);
module_exit(orangefs_exit);