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 [sun.com URL with a
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 2008 Sun Microsystems, Inc. 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/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.
58 #include <sys/signal.h>
60 #include <libcfs/list.h>
61 #include <libcfs/user-time.h>
66 #ifdef HAVE_LIBPTHREAD
72 * Wait Queue. No-op implementation.
75 typedef struct cfs_waitlink {
76 struct list_head sleeping;
80 typedef struct cfs_waitq {
81 struct list_head sleepers;
84 void cfs_waitq_init(struct cfs_waitq *waitq);
85 void cfs_waitlink_init(struct cfs_waitlink *link);
86 void cfs_waitq_add(struct cfs_waitq *waitq, struct cfs_waitlink *link);
87 void cfs_waitq_add_exclusive(struct cfs_waitq *waitq,
88 struct cfs_waitlink *link);
89 void cfs_waitq_forward(struct cfs_waitlink *link, struct cfs_waitq *waitq);
90 void cfs_waitq_del(struct cfs_waitq *waitq, struct cfs_waitlink *link);
91 int cfs_waitq_active(struct cfs_waitq *waitq);
92 void cfs_waitq_signal(struct cfs_waitq *waitq);
93 void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr);
94 void cfs_waitq_broadcast(struct cfs_waitq *waitq);
95 void cfs_waitq_wait(struct cfs_waitlink *link, int state);
96 int64_t cfs_waitq_timedwait(struct cfs_waitlink *link, int state, int64_t timeout);
97 #define cfs_schedule_timeout(s, t) \
100 cfs_waitq_timedwait(&l, s, t); \
103 #define CFS_TASK_INTERRUPTIBLE (0)
104 #define CFS_TASK_UNINT (0)
109 * for this moment, liblusre will not rely OST for non-page-aligned write
111 #define LIBLUSTRE_HANDLE_UNALIGNED_PAGE
116 struct list_head list;
117 unsigned long private;
119 /* internally used by liblustre file i/o */
122 #ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
125 struct list_head _node;
128 typedef struct page cfs_page_t;
133 #define CFS_PAGE_SHIFT 12
134 #define CFS_PAGE_SIZE (1UL << CFS_PAGE_SHIFT)
135 #define CFS_PAGE_MASK (~((__u64)CFS_PAGE_SIZE-1))
139 #define CFS_PAGE_SIZE PAGE_SIZE
140 #define CFS_PAGE_SHIFT PAGE_SHIFT
141 #define CFS_PAGE_MASK (~((__u64)CFS_PAGE_SIZE-1))
145 cfs_page_t *cfs_alloc_page(unsigned int flags);
146 void cfs_free_page(cfs_page_t *pg);
147 void *cfs_page_address(cfs_page_t *pg);
148 void *cfs_kmap(cfs_page_t *pg);
149 void cfs_kunmap(cfs_page_t *pg);
151 #define cfs_get_page(p) __I_should_not_be_called__(at_all)
152 #define cfs_page_count(p) __I_should_not_be_called__(at_all)
153 #define cfs_page_index(p) ((p)->index)
157 * Inline function, so utils can use them without linking of libcfs
159 #define __ALLOC_ZERO (1 << 2)
160 static inline void *cfs_alloc(size_t nr_bytes, u_int32_t flags)
164 result = malloc(nr_bytes);
165 if (result != NULL && (flags & __ALLOC_ZERO))
166 memset(result, 0, nr_bytes);
170 #define cfs_free(addr) free(addr)
171 #define cfs_alloc_large(nr_bytes) cfs_alloc(nr_bytes, 0)
172 #define cfs_free_large(addr) cfs_free(addr)
174 #define CFS_ALLOC_ATOMIC_TRY (0)
182 #define SLAB_HWCACHE_ALIGN 0
183 #define SLAB_KERNEL 0
187 cfs_mem_cache_create(const char *, size_t, size_t, unsigned long);
188 int cfs_mem_cache_destroy(cfs_mem_cache_t *c);
189 void *cfs_mem_cache_alloc(cfs_mem_cache_t *c, int gfp);
190 void cfs_mem_cache_free(cfs_mem_cache_t *c, void *addr);
192 typedef int (cfs_read_proc_t)(char *page, char **start, off_t off,
193 int count, int *eof, void *data);
195 struct file; /* forward ref */
196 typedef int (cfs_write_proc_t)(struct file *file, const char *buffer,
197 unsigned long count, void *data);
202 typedef sigset_t cfs_sigset_t;
207 #include <sys/time.h>
210 struct list_head tl_list;
211 void (*function)(unsigned long unused);
216 #define cfs_init_timer(t) do {} while(0)
217 #define cfs_jiffies \
219 unsigned long _ret = 0; \
221 if (gettimeofday(&tv, NULL) == 0) \
226 static inline int cfs_timer_init(cfs_timer_t *l, void (* func)(unsigned long), void *arg)
228 CFS_INIT_LIST_HEAD(&l->tl_list);
230 l->data = (unsigned long)arg;
234 static inline int cfs_timer_is_armed(cfs_timer_t *l)
236 if (cfs_time_before(cfs_jiffies, l->expires))
242 static inline void cfs_timer_arm(cfs_timer_t *l, int thetime)
244 l->expires = thetime;
247 static inline void cfs_timer_disarm(cfs_timer_t *l)
251 static inline long cfs_timer_deadline(cfs_timer_t *l)
257 #define cfs_init_timer(t) do {} while(0)
258 void cfs_timer_init(struct cfs_timer *t, void (*func)(unsigned long), void *arg);
259 void cfs_timer_done(struct cfs_timer *t);
260 void cfs_timer_arm(struct cfs_timer *t, cfs_time_t deadline);
261 void cfs_timer_disarm(struct cfs_timer *t);
262 int cfs_timer_is_armed(struct cfs_timer *t);
264 cfs_time_t cfs_timer_deadline(struct cfs_timer *t);
267 #define in_interrupt() (0)
269 static inline void cfs_pause(cfs_duration_t d)
273 cfs_duration_nsec(d, &s);
277 typedef void cfs_psdev_t;
279 static inline int cfs_psdev_register(cfs_psdev_t *foo)
284 static inline int cfs_psdev_deregister(cfs_psdev_t *foo)
289 #define cfs_lock_kernel() do {} while (0)
290 #define cfs_sigfillset(l) do {} while (0)
291 #define cfs_recalc_sigpending(l) do {} while (0)
292 #define cfs_kernel_thread(l,m,n) LBUG()
294 #ifdef HAVE_LIBPTHREAD
295 typedef int (*cfs_thread_t)(void *);
296 int cfs_create_thread(cfs_thread_t func, void *arg);
298 #define cfs_create_thread(l,m) LBUG()
301 int cfs_parse_int_tunable(int *value, char *name);
302 uid_t cfs_curproc_uid(void);
304 #define LIBCFS_REALLOC(ptr, size) realloc(ptr, size)
306 #define cfs_online_cpus() sysconf(_SC_NPROCESSORS_ONLN)
308 // static inline void local_irq_save(unsigned long flag) {return;}
309 // static inline void local_irq_restore(unsigned long flag) {return;}
312 CFS_STACK_TRACE_DEPTH = 16
315 struct cfs_stack_trace {
316 void *frame[CFS_STACK_TRACE_DEPTH];
322 #define do_div(a,b) \
324 unsigned long remainder;\
325 remainder = (a) % (b); \
333 /* __LIBCFS_USER_PRIM_H__ */
337 * c-indentation-style: "K&R"