4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LNET
39 #include <libcfs/libcfs.h>
40 #include <libcfs/libcfs_crypto.h>
41 #include <lnet/lib-lnet.h>
43 static DECLARE_RWSEM(ioctl_list_sem);
44 static LIST_HEAD(ioctl_list);
46 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand)
50 down_write(&ioctl_list_sem);
51 if (!list_empty(&hand->item))
54 list_add_tail(&hand->item, &ioctl_list);
55 up_write(&ioctl_list_sem);
59 EXPORT_SYMBOL(libcfs_register_ioctl);
61 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand)
65 down_write(&ioctl_list_sem);
66 if (list_empty(&hand->item))
69 list_del_init(&hand->item);
70 up_write(&ioctl_list_sem);
74 EXPORT_SYMBOL(libcfs_deregister_ioctl);
76 int libcfs_ioctl(unsigned long cmd, void __user *uparam)
78 struct libcfs_ioctl_data *data = NULL;
79 struct libcfs_ioctl_hdr *hdr;
83 /* 'cmd' and permissions get checked in our arch-specific caller */
84 err = libcfs_ioctl_getdata(&hdr, uparam);
87 "libcfs ioctl: data header error %d\n", err);
91 if (hdr->ioc_version == LIBCFS_IOCTL_VERSION) {
92 /* The libcfs_ioctl_data_adjust() function performs adjustment
93 * operations on the libcfs_ioctl_data structure to make
94 * it usable by the code. This doesn't need to be called
95 * for new data structures added. */
96 data = container_of(hdr, struct libcfs_ioctl_data, ioc_hdr);
97 err = libcfs_ioctl_data_adjust(data);
102 CDEBUG(D_IOCTL, "libcfs ioctl cmd %lu\n", cmd);
104 case IOC_LIBCFS_CLEAR_DEBUG:
105 libcfs_debug_clear_buffer();
107 case IOC_LIBCFS_MARK_DEBUG:
109 data->ioc_inlbuf1 == NULL ||
110 data->ioc_inlbuf1[data->ioc_inllen1 - 1] != '\0')
111 GOTO(out, err = -EINVAL);
113 libcfs_debug_mark_buffer(data->ioc_inlbuf1);
117 struct libcfs_ioctl_handler *hand;
120 down_read(&ioctl_list_sem);
121 list_for_each_entry(hand, &ioctl_list, item) {
122 err = hand->handle_ioctl(cmd, hdr);
127 if (copy_to_user(uparam, hdr, hdr->ioc_len))
132 up_read(&ioctl_list_sem);
136 LIBCFS_FREE(hdr, hdr->ioc_len);
140 static int __init libcfs_init(void)
144 rc = libcfs_debug_init(5 * 1024 * 1024);
146 printk(KERN_ERR "LustreError: libcfs_debug_init: %d\n", rc);
154 rc = misc_register(&libcfs_dev);
156 CERROR("misc_register: error %d\n", rc);
160 rc = cfs_wi_startup();
162 CERROR("initialize workitem: error %d\n", rc);
163 goto cleanup_deregister;
166 /* max to 4 threads, should be enough for rehash */
167 rc = min(cfs_cpt_weight(cfs_cpt_table, CFS_CPT_ANY), 4);
168 rc = cfs_wi_sched_create("cfs_rh", cfs_cpt_table, CFS_CPT_ANY,
169 rc, &cfs_sched_rehash);
171 CERROR("Startup workitem scheduler: error: %d\n", rc);
172 goto cleanup_deregister;
175 rc = cfs_crypto_register();
177 CERROR("cfs_crypto_regster: error %d\n", rc);
184 CERROR("insert_proc: error %d\n", rc);
188 CDEBUG (D_OTHER, "portals setup OK\n");
191 cfs_crypto_unregister();
195 misc_deregister(&libcfs_dev);
199 libcfs_debug_cleanup();
203 static void __exit libcfs_exit(void)
209 CDEBUG(D_MALLOC, "before Portals cleanup: kmem %d\n",
210 atomic_read(&libcfs_kmemory));
212 if (cfs_sched_rehash != NULL) {
213 cfs_wi_sched_destroy(cfs_sched_rehash);
214 cfs_sched_rehash = NULL;
217 cfs_crypto_unregister();
220 misc_deregister(&libcfs_dev);
224 if (atomic_read(&libcfs_kmemory) != 0)
225 CERROR("Portals memory leaked: %d bytes\n",
226 atomic_read(&libcfs_kmemory));
228 rc = libcfs_debug_cleanup();
230 printk(KERN_ERR "LustreError: libcfs_debug_cleanup: %d\n",
234 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
235 MODULE_DESCRIPTION("Lustre helper library");
236 MODULE_VERSION(LIBCFS_VERSION);
237 MODULE_LICENSE("GPL");
239 module_init(libcfs_init);
240 module_exit(libcfs_exit);