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, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/include/libcfs/user-prim.h
38 * Author: Nikita Danilov <nikita@clusterfs.com>
41 #ifndef __LIBCFS_USER_PRIM_H__
42 #define __LIBCFS_USER_PRIM_H__
44 #ifndef __LIBCFS_LIBCFS_H__
45 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
48 /* Implementations of portable APIs for liblustre */
51 * liblustre is single-threaded, so most "synchronization" APIs are trivial.
56 typedef struct proc_dir_entry cfs_proc_dir_entry_t;
59 * Just present a single processor until will add thread support.
61 #ifndef smp_processor_id
62 # define smp_processor_id() 0
64 #ifndef num_online_cpus
65 # define num_online_cpus() 1
67 #ifndef num_possible_cpus
68 # define num_possible_cpus() 1
74 typedef struct cfs_waitlink {
79 typedef struct cfs_waitq {
83 #define CFS_DECL_WAITQ(wq) cfs_waitq_t wq
88 typedef long cfs_task_state_t;
90 #define CFS_TASK_INTERRUPTIBLE (0)
91 #define CFS_TASK_UNINT (1)
92 #define CFS_TASK_RUNNING (2)
94 static inline void cfs_schedule(void) {}
95 static inline void cfs_schedule_timeout(int64_t t) {}
100 typedef int (cfs_read_proc_t)(char *page, char **start, off_t off,
101 int count, int *eof, void *data);
103 struct file; /* forward ref */
104 typedef int (cfs_write_proc_t)(struct file *file, const char *buffer,
105 unsigned long count, void *data);
110 typedef sigset_t cfs_sigset_t;
118 void (*function)(ulong_ptr_t unused);
124 #define cfs_in_interrupt() (0)
126 typedef void cfs_psdev_t;
128 static inline int cfs_psdev_register(cfs_psdev_t *foo)
133 static inline int cfs_psdev_deregister(cfs_psdev_t *foo)
138 #define cfs_sigfillset(l) do {} while (0)
139 #define cfs_recalc_sigpending(l) do {} while (0)
140 /* Fine, crash, but stop giving me compile warnings */
141 #define cfs_kthread_run(fn,d,fmt,...) LBUG()
143 #define CFS_DAEMON_FLAGS 0
145 #define CFS_L1_CACHE_ALIGN(x) (x)
147 #ifdef HAVE_LIBPTHREAD
148 typedef int (*cfs_thread_t)(void *);
149 void *kthread_run(cfs_thread_t func, void *arg, const char namefmt[], ...);
151 /* Fine, crash, but stop giving me compile warnings */
152 #define kthread_run(f, a, n, ...) LBUG()
155 uid_t cfs_curproc_uid(void);
156 gid_t cfs_curproc_gid(void);
157 uid_t cfs_curproc_fsuid(void);
158 gid_t cfs_curproc_fsgid(void);
160 #ifndef HAVE_STRLCPY /* not in glibc for RHEL 5.x, remove when obsolete */
161 size_t strlcpy(char *tgt, const char *src, size_t tgt_len);
164 #ifndef HAVE_STRLCAT /* not in glibc for RHEL 5.x, remove when obsolete */
165 size_t strlcat(char *tgt, const char *src, size_t tgt_len);
168 #define LIBCFS_REALLOC(ptr, size) realloc(ptr, size)
170 #define cfs_online_cpus() sysconf(_SC_NPROCESSORS_ONLN)
172 // static inline void local_irq_save(unsigned long flag) {return;}
173 // static inline void local_irq_restore(unsigned long flag) {return;}
176 CFS_STACK_TRACE_DEPTH = 16
179 struct cfs_stack_trace {
180 void *frame[CFS_STACK_TRACE_DEPTH];
186 #ifndef do_div /* gcc only, platform-specific will override */
187 #define do_div(a,b) \
189 unsigned long remainder;\
190 remainder = (a) % (b); \
199 typedef struct cfs_group_info {
204 # define min(x,y) ((x)<(y) ? (x) : (y))
208 # define max(x,y) ((x)>(y) ? (x) : (y))
211 #define cfs_get_random_bytes_prim(val, size) (*val) = 0
213 /* utility libcfs init/fini entries */
215 extern int libcfs_arch_init(void);
216 extern void libcfs_arch_cleanup(void);
217 #else /* !__WINNT__ */
218 static inline int libcfs_arch_init(void) {
221 static inline void libcfs_arch_cleanup(void) {
226 /* proc interface wrappers for non-win OS */
228 #define cfs_proc_open open
229 #define cfs_proc_mknod mknod
230 #define cfs_proc_ioctl ioctl
231 #define cfs_proc_close close
232 #define cfs_proc_read read
233 #define cfs_proc_write write
234 #define cfs_proc_fopen fopen
235 #define cfs_proc_fclose fclose
236 #define cfs_proc_fgets fgets
243 /* __LIBCFS_USER_PRIM_H__ */
247 * c-indentation-style: "K&R"