1 // SPDX-License-Identifier: GPL-2.0
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 only,
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License version 2 for more details (a copy is included
15 * in the LICENSE file that accompanied this code).
17 * You should have received a copy of the GNU General Public License
18 * version 2 along with this program; If not, see
19 * http://www.gnu.org/licenses/gpl-2.0.html
24 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25 * Use is subject to license terms.
27 * Copyright (c) 2011, 2015, Intel Corporation.
30 * This file is part of Lustre, http://www.lustre.org/
31 * Lustre is a trademark of Sun Microsystems, Inc.
34 #ifndef __LIBCFS_LIBCFS_H__
35 #define __LIBCFS_LIBCFS_H__
37 #include <linux/gfp.h>
38 #include <linux/list.h>
40 #include <uapi/linux/lnet/libcfs_ioctl.h>
41 #include <linux/libcfs/linux/libcfs.h>
42 #include <linux/libcfs/libcfs_debug.h>
43 #include <linux/libcfs/libcfs_private.h>
44 #include <linux/libcfs/libcfs_cpu.h>
45 #include <linux/libcfs/libcfs_prim.h>
46 #include <linux/libcfs/libcfs_string.h>
47 #include <linux/libcfs/libcfs_hash.h>
48 #include <linux/libcfs/libcfs_fail.h>
49 #include <linux/libcfs/curproc.h>
51 #define LIBCFS_VERSION "0.7.0"
53 #define LOWEST_BIT_SET(x) ((x) & ~((x) - 1))
58 #define CFS_TICK (1UL)
61 * Lustre Error Checksum: calculates checksum
62 * of Hex number by XORing each bit.
64 #define LERRCHKSUM(hexnum) (((hexnum) & 0xf) ^ ((hexnum) >> 4 & 0xf) ^ \
65 ((hexnum) >> 8 & 0xf))
67 /* need both kernel and user-land acceptor */
68 #define LNET_ACCEPTOR_MIN_RESERVED_PORT 512
69 #define LNET_ACCEPTOR_MAX_RESERVED_PORT 1023
71 /* Block all signals except for the @sigs */
72 static inline void cfs_block_sigsinv(unsigned long sigs, sigset_t *old)
76 siginitsetinv(&new, sigs);
77 sigorsets(&new, ¤t->blocked, &new);
78 sigprocmask(SIG_BLOCK, &new, old);
82 cfs_restore_sigs(sigset_t *old)
84 sigprocmask(SIG_SETMASK, old, NULL);
87 struct libcfs_ioctl_handler {
88 struct list_head item;
89 int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
92 #define DECLARE_IOCTL_HANDLER(ident, func) \
93 struct libcfs_ioctl_handler ident = { \
94 .item = LIST_HEAD_INIT(ident.item), \
95 .handle_ioctl = func \
98 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
99 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
101 int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
102 const struct libcfs_ioctl_hdr __user *uparam);
103 int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data);
104 int libcfs_ioctl(unsigned long cmd, void __user *arg);
106 /* container_of depends on "likely" which is defined in libcfs_private.h */
107 static inline void *__container_of(void *ptr, unsigned long shift)
109 if (IS_ERR_OR_NULL(ptr))
111 return (char *)ptr - shift;
114 #define container_of0(ptr, type, member) \
115 ((type *)__container_of((void *)(ptr), offsetof(type, member)))
119 extern struct miscdevice libcfs_dev;
121 * The path of debug log dump upcall script.
123 extern char lnet_debug_log_upcall[1024];
125 extern struct workqueue_struct *cfs_rehash_wq;
127 struct lnet_debugfs_symlink_def {
132 void lustre_insert_debugfs(struct ctl_table *table,
133 const struct lnet_debugfs_symlink_def *symlinks);
134 int lprocfs_call_handler(void *data, int write, loff_t *ppos,
135 void __user *buffer, size_t *lenp,
136 int (*handler)(void *data, int write, loff_t pos,
137 void __user *buffer, int len));
139 #endif /* _LIBCFS_H */