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) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef __LIBCFS_LIBCFS_H__
38 #define __LIBCFS_LIBCFS_H__
41 #define __attribute__(x)
44 #include <linux/libcfs/linux/libcfs.h>
49 # define offsetof(typ,memb) ((long)(long_ptr_t)((char *)&(((typ *)0)->memb)))
53 #define ARRAY_SIZE(a) ((sizeof (a)) / (sizeof ((a)[0])))
57 #define swap(x,y) do { typeof(x) z = x; x = y; y = z; } while (0)
60 #if !defined(container_of)
61 /* given a pointer @ptr to the field @member embedded into type (usually
62 * struct) @type, return pointer to the embedding instance of @type. */
63 #define container_of(ptr, type, member) \
64 ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
67 static inline int __is_po2(unsigned long long val
)
69 return !(val
& (val
- 1));
72 #define IS_PO2(val) __is_po2((unsigned long long)(val))
74 #define LOWEST_BIT_SET(x) ((x) & ~((x) - 1))
77 * Lustre Error Checksum: calculates checksum
78 * of Hex number by XORing each bit.
80 #define LERRCHKSUM(hexnum) (((hexnum) & 0xf) ^ ((hexnum) >> 4 & 0xf) ^ \
81 ((hexnum) >> 8 & 0xf))
85 * Some (nomina odiosa sunt) platforms define NULL as naked 0. This confuses
86 * Lustre RETURN(NULL) macro.
92 #define NULL ((void *)0)
94 #define LUSTRE_SRV_LNET_PID LUSTRE_LNET_PID
97 #include <linux/list.h>
99 #ifndef cfs_for_each_possible_cpu
100 # error cfs_for_each_possible_cpu is not supported by kernel!
104 int libcfs_ipif_query(char *name
, int *up
, __u32
*ip
, __u32
*mask
);
105 int libcfs_ipif_enumerate(char ***names
);
106 void libcfs_ipif_free_enumeration(char **names
, int n
);
107 int libcfs_sock_listen(socket_t
**sockp
, __u32 ip
, int port
, int backlog
);
108 int libcfs_sock_accept(socket_t
**newsockp
, socket_t
*sock
);
109 void libcfs_sock_abort_accept(socket_t
*sock
);
110 int libcfs_sock_connect(socket_t
**sockp
, int *fatal
,
111 __u32 local_ip
, int local_port
,
112 __u32 peer_ip
, int peer_port
);
113 int libcfs_sock_setbuf(socket_t
*socket
, int txbufsize
, int rxbufsize
);
114 int libcfs_sock_getbuf(socket_t
*socket
, int *txbufsize
, int *rxbufsize
);
115 int libcfs_sock_getaddr(socket_t
*socket
, int remote
, __u32
*ip
, int *port
);
116 int libcfs_sock_write(socket_t
*sock
, void *buffer
, int nob
, int timeout
);
117 int libcfs_sock_read(socket_t
*sock
, void *buffer
, int nob
, int timeout
);
118 void libcfs_sock_release(socket_t
*sock
);
120 /* need both kernel and user-land acceptor */
121 #define LNET_ACCEPTOR_MIN_RESERVED_PORT 512
122 #define LNET_ACCEPTOR_MAX_RESERVED_PORT 1023
125 * libcfs pseudo device operations
127 * It's just draft now.
130 struct cfs_psdev_file
{
133 unsigned long reserved1
;
134 unsigned long reserved2
;
137 struct cfs_psdev_ops
{
138 int (*p_open
)(unsigned long, void *);
139 int (*p_close
)(unsigned long, void *);
140 int (*p_read
)(struct cfs_psdev_file
*, char *, unsigned long);
141 int (*p_write
)(struct cfs_psdev_file
*, char *, unsigned long);
142 int (*p_ioctl
)(struct cfs_psdev_file
*, unsigned long, void *);
146 * Drop into debugger, if possible. Implementation is provided by platform.
149 void cfs_enter_debugger(void);
152 * Defined by platform
154 int unshare_fs_struct(void);
155 sigset_t
cfs_get_blocked_sigs(void);
156 sigset_t
cfs_block_allsigs(void);
157 sigset_t
cfs_block_sigs(unsigned long sigs
);
158 sigset_t
cfs_block_sigsinv(unsigned long sigs
);
159 void cfs_restore_sigs(sigset_t
);
160 int cfs_signal_pending(void);
161 void cfs_clear_sigpending(void);
164 * Random number handling
167 /* returns a random 32-bit integer */
168 unsigned int cfs_rand(void);
169 /* seed the generator */
170 void cfs_srand(unsigned int, unsigned int);
171 void cfs_get_random_bytes(void *buf
, int size
);
173 #include <linux/libcfs/libcfs_debug.h>
174 #include <linux/libcfs/libcfs_cpu.h>
175 #include <linux/libcfs/libcfs_private.h>
176 #include <linux/libcfs/libcfs_ioctl.h>
177 #include <linux/libcfs/libcfs_prim.h>
178 #include <linux/libcfs/libcfs_time.h>
179 #include <linux/libcfs/libcfs_string.h>
180 #include <linux/libcfs/libcfs_kernelcomm.h>
181 #include <linux/libcfs/libcfs_workitem.h>
182 #include <linux/libcfs/libcfs_hash.h>
183 #include <linux/libcfs/libcfs_heap.h>
184 #include <linux/libcfs/libcfs_fail.h>
185 #include <linux/libcfs/params_tree.h>
186 #include <linux/libcfs/libcfs_crypto.h>
188 /* container_of depends on "likely" which is defined in libcfs_private.h */
189 static inline void *__container_of(void *ptr
, unsigned long shift
)
191 if (unlikely(IS_ERR(ptr
) || ptr
== NULL
))
194 return (char *)ptr
- shift
;
197 #define container_of0(ptr, type, member) \
198 ((type *)__container_of((void *)(ptr), offsetof(type, member)))
200 #define SET_BUT_UNUSED(a) do { } while(sizeof(a) - sizeof(a))
204 #endif /* _LIBCFS_H */
This page took 0.044207 seconds and 6 git commands to generate.