1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/include/libcfs/posix/libcfs.h
38 * Defines for posix userspace.
40 * Author: Robert Read <rread@sun.com>
43 #ifndef __LIBCFS_POSIX_LIBCFS_H__
44 #define __LIBCFS_POSIX_LIBCFS_H__
47 #include <sys/errno.h>
58 #include <sys/ioctl.h>
59 #include <sys/signal.h>
66 #include <sys/socket.h>
67 #include <sys/utsname.h>
78 #ifdef HAVE_LIBPTHREAD
82 #if defined(HAVE_SYS_TYPES_H)
83 #include <sys/types.h>
86 #ifdef HAVE_SYS_USER_H
87 # include <sys/user.h>
98 #include <libcfs/list.h>
99 #include <libcfs/posix/posix-types.h>
100 #include <libcfs/user-time.h>
101 #include <libcfs/user-prim.h>
102 #include <libcfs/user-mem.h>
103 #include <libcfs/user-lock.h>
104 #include <libcfs/user-tcpip.h>
105 #include <libcfs/posix/posix-wordsize.h>
106 #include <libcfs/user-bitops.h>
108 # define cfs_gettimeofday(tv) gettimeofday(tv, NULL);
109 typedef unsigned long long cfs_cycles_t;
111 #define IS_ERR(a) ((unsigned long)(a) > (unsigned long)-1000L)
112 #define PTR_ERR(a) ((long)(a))
113 #define ERR_PTR(a) ((void*)((long)(a)))
115 /* this goes in posix-fs.h */
116 #include <sys/mount.h>
122 typedef struct file cfs_file_t;
123 typedef struct dentry cfs_dentry_t;
125 typedef struct dirent64 cfs_dirent_t;
128 #define cfs_get_fd(x) NULL
129 #define cfs_put_file(f) do {} while (0)
132 /* Userpace byte flipping */
134 # include <byteswap.h>
135 # define __swab16(x) bswap_16(x)
136 # define __swab32(x) bswap_32(x)
137 # define __swab64(x) bswap_64(x)
138 # define __swab16s(x) do {*(x) = bswap_16(*(x));} while (0)
139 # define __swab32s(x) do {*(x) = bswap_32(*(x));} while (0)
140 # define __swab64s(x) do {*(x) = bswap_64(*(x));} while (0)
141 # if __BYTE_ORDER == __LITTLE_ENDIAN
142 # define le16_to_cpu(x) (x)
143 # define cpu_to_le16(x) (x)
144 # define le32_to_cpu(x) (x)
145 # define cpu_to_le32(x) (x)
146 # define le64_to_cpu(x) (x)
147 # define cpu_to_le64(x) (x)
149 # define be16_to_cpu(x) bswap_16(x)
150 # define cpu_to_be16(x) bswap_16(x)
151 # define be32_to_cpu(x) bswap_32(x)
152 # define cpu_to_be32(x) bswap_32(x)
153 # define be64_to_cpu(x) (__u64)bswap_64(x)
154 # define cpu_to_be64(x) (__u64)bswap_64(x)
156 # if __BYTE_ORDER == __BIG_ENDIAN
157 # define le16_to_cpu(x) bswap_16(x)
158 # define cpu_to_le16(x) bswap_16(x)
159 # define le32_to_cpu(x) bswap_32(x)
160 # define cpu_to_le32(x) bswap_32(x)
161 # define le64_to_cpu(x) (__u64)bswap_64(x)
162 # define cpu_to_le64(x) (__u64)bswap_64(x)
164 # define be16_to_cpu(x) (x)
165 # define cpu_to_be16(x) (x)
166 # define be32_to_cpu(x) (x)
167 # define cpu_to_be32(x) (x)
168 # define be64_to_cpu(x) (x)
169 # define cpu_to_be64(x) (x)
172 # error "Unknown byte order"
173 # endif /* __BIG_ENDIAN */
174 # endif /* __LITTLE_ENDIAN */
176 #define __cpu_to_le64(x) OSSwapHostToLittleInt64(x)
177 #define __cpu_to_le32(x) OSSwapHostToLittleInt32(x)
178 #define __cpu_to_le16(x) OSSwapHostToLittleInt16(x)
180 #define __le16_to_cpu(x) OSSwapLittleToHostInt16(x)
181 #define __le32_to_cpu(x) OSSwapLittleToHostInt32(x)
182 #define __le64_to_cpu(x) OSSwapLittleToHostInt64(x)
184 #define cpu_to_le64(x) __cpu_to_le64(x)
185 #define cpu_to_le32(x) __cpu_to_le32(x)
186 #define cpu_to_le16(x) __cpu_to_le16(x)
188 #define le64_to_cpu(x) __le64_to_cpu(x)
189 #define le32_to_cpu(x) __le32_to_cpu(x)
190 #define le16_to_cpu(x) __le16_to_cpu(x)
192 #define __swab16(x) OSSwapInt16(x)
193 #define __swab32(x) OSSwapInt32(x)
194 #define __swab64(x) OSSwapInt64(x)
195 #define __swab16s(x) do { *(x) = __swab16(*(x)); } while (0)
196 #define __swab32s(x) do { *(x) = __swab32(*(x)); } while (0)
197 #define __swab64s(x) do { *(x) = __swab64(*(x)); } while (0)
201 # ifndef THREAD_SIZE /* x86_64 linux has THREAD_SIZE in userspace */
202 # define CFS_THREAD_SIZE 8192
204 # define CFS_THREAD_SIZE THREAD_SIZE
207 #define LUSTRE_TRACE_SIZE (CFS_THREAD_SIZE >> 5)
209 #define CFS_CHECK_STACK() do { } while(0)
210 #define CDEBUG_STACK() (0L)
213 #define LUSTRE_LNET_PID 12345
215 #define ENTRY_NESTING_SUPPORT (1)
216 #define ENTRY_NESTING do {;} while (0)
217 #define EXIT_NESTING do {;} while (0)
218 #define __current_nesting_level() (0)
221 * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
223 * Implementation is in linux-curproc.c
225 #define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
227 typedef __u32 cfs_kernel_cap_t;
230 * Module support (probably shouldn't be used in generic code?)
232 typedef struct cfs_module {
237 static inline void MODULE_AUTHOR(char *name)
239 printf("%s\n", name);
241 #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name)
242 #define MODULE_LICENSE(name) MODULE_AUTHOR(name)
244 #define THIS_MODULE (void *)0x11111
248 static inline int cfs_request_module(const char *name, ...)
253 static inline void __cfs_module_get(cfs_module_t *module)
257 static inline int cfs_try_module_get(cfs_module_t *module)
262 static inline void cfs_module_put(cfs_module_t *module)
267 static inline int cfs_module_refcount(cfs_module_t *m)
272 /***************************************************************************
274 * Linux kernel slab shrinker emulation. Currently used only in lu_object.c
276 ***************************************************************************/
278 struct cfs_shrinker {
282 #define CFS_DEFAULT_SEEKS (0)
284 typedef int (*cfs_shrinker_t)(int, unsigned int);
287 struct cfs_shrinker *cfs_set_shrinker(int seeks, cfs_shrinker_t shrink)
289 return (struct cfs_shrinker *)0xdeadbea1; // Cannot return NULL here
292 static inline void cfs_remove_shrinker(struct cfs_shrinker *shrinker)
296 /***************************************************************************
298 * Linux kernel radix tree emulation.
300 * XXX this stub-implementation assumes that elements stored in a radix tree
301 * are struct page's and nothing else. Proper implementation will be
304 ***************************************************************************/
306 struct radix_tree_root {
311 struct radix_tree_node {
317 #define RADIX_TREE_INIT(mask) { \
321 #define RADIX_TREE(name, mask) \
322 struct radix_tree_root name = RADIX_TREE_INIT(mask)
325 #define INIT_RADIX_TREE(root, mask) \
327 CFS_INIT_LIST_HEAD(&((struct radix_tree_root *)root)->list); \
328 ((struct radix_tree_root *)root)->rnode = NULL; \
331 static inline int radix_tree_insert(struct radix_tree_root *root,
332 unsigned long idx, void *item)
334 struct radix_tree_node *node;
335 node = malloc(sizeof(*node));
339 CFS_INIT_LIST_HEAD(&node->_node);
342 cfs_list_add_tail(&node->_node, &root->list);
343 root->rnode = (void *)1001;
347 static inline struct radix_tree_node *radix_tree_lookup0(struct radix_tree_root *root,
350 struct radix_tree_node *node;
352 if (cfs_list_empty(&root->list))
355 cfs_list_for_each_entry_typed(node, &root->list,
356 struct radix_tree_node, _node)
357 if (node->index == idx)
363 static inline void *radix_tree_lookup(struct radix_tree_root *root,
366 struct radix_tree_node *node = radix_tree_lookup0(root, idx);
373 static inline void *radix_tree_delete(struct radix_tree_root *root,
376 struct radix_tree_node *p = radix_tree_lookup0(root, idx);
382 cfs_list_del_init(&p->_node);
385 if (cfs_list_empty(&root->list))
391 static inline unsigned int
392 radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
393 unsigned long first_index, unsigned int max_items)
398 for (i = 0; i < max_items; i++, first_index++) {
399 results[j++] = radix_tree_lookup(root, first_index);
400 if (results[j - 1] == NULL)
407 static inline int radix_tree_preload(int gfp_mask)
412 void radix_tree_init(void);
414 static inline void radix_tree_preload_end(void)
418 typedef ssize_t (*read_actor_t)();
420 #define CFS_IFSHIFT 12
422 #define CFS_IFTODT(type) (((type) & S_IFMT) >> CFS_IFSHIFT)
423 #define CFS_DTTOIF(dirtype) ((dirtype) << CFS_IFSHIFT)