staging: lustre: discard linux-time.h
[linux-2.6-microblaze.git] / drivers / staging / lustre / include / linux / libcfs / libcfs.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * GPL HEADER START
4  *
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
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.
10  *
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).
16  *
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
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25  * Use is subject to license terms.
26  *
27  * Copyright (c) 2011, 2015, Intel Corporation.
28  */
29 /*
30  * This file is part of Lustre, http://www.lustre.org/
31  * Lustre is a trademark of Sun Microsystems, Inc.
32  */
33
34 #ifndef __LIBCFS_LIBCFS_H__
35 #define __LIBCFS_LIBCFS_H__
36
37 #include <linux/gfp.h>
38 #include <linux/list.h>
39
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>
50
51 #define LIBCFS_VERSION "0.7.0"
52
53 #define LOWEST_BIT_SET(x)       ((x) & ~((x) - 1))
54
55 /*
56  * One jiffy
57  */
58 #define CFS_TICK                (1UL)
59
60 /*
61  * Lustre Error Checksum: calculates checksum
62  * of Hex number by XORing each bit.
63  */
64 #define LERRCHKSUM(hexnum) (((hexnum) & 0xf) ^ ((hexnum) >> 4 & 0xf) ^ \
65                            ((hexnum) >> 8 & 0xf))
66
67 /* need both kernel and user-land acceptor */
68 #define LNET_ACCEPTOR_MIN_RESERVED_PORT    512
69 #define LNET_ACCEPTOR_MAX_RESERVED_PORT    1023
70
71 /* Block all signals except for the @sigs */
72 static inline void cfs_block_sigsinv(unsigned long sigs, sigset_t *old)
73 {
74         sigset_t new;
75
76         siginitsetinv(&new, sigs);
77         sigorsets(&new, &current->blocked, &new);
78         sigprocmask(SIG_BLOCK, &new, old);
79 }
80
81 static inline void
82 cfs_restore_sigs(sigset_t *old)
83 {
84         sigprocmask(SIG_SETMASK, old, NULL);
85 }
86
87 struct libcfs_ioctl_handler {
88         struct list_head item;
89         int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
90 };
91
92 #define DECLARE_IOCTL_HANDLER(ident, func)                      \
93         struct libcfs_ioctl_handler ident = {                   \
94                 .item           = LIST_HEAD_INIT(ident.item),   \
95                 .handle_ioctl   = func                          \
96         }
97
98 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
99 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
100
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);
105
106 /* container_of depends on "likely" which is defined in libcfs_private.h */
107 static inline void *__container_of(void *ptr, unsigned long shift)
108 {
109         if (IS_ERR_OR_NULL(ptr))
110                 return ptr;
111         return (char *)ptr - shift;
112 }
113
114 #define container_of0(ptr, type, member) \
115         ((type *)__container_of((void *)(ptr), offsetof(type, member)))
116
117 #define _LIBCFS_H
118
119 extern struct miscdevice libcfs_dev;
120 /**
121  * The path of debug log dump upcall script.
122  */
123 extern char lnet_debug_log_upcall[1024];
124
125 extern struct workqueue_struct *cfs_rehash_wq;
126
127 struct lnet_debugfs_symlink_def {
128         char *name;
129         char *target;
130 };
131
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));
138
139 #endif /* _LIBCFS_H */