1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Basic library routines.
25 #ifndef __LIBCFS_LINUX_CFS_PRIM_H__
26 #define __LIBCFS_LINUX_CFS_PRIM_H__
28 #ifndef __LIBCFS_LIBCFS_H__
29 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
33 #ifndef AUTOCONF_INCLUDED
34 #include <linux/config.h>
36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/version.h>
39 #include <linux/proc_fs.h>
41 #include <linux/timer.h>
43 #include <linux/miscdevice.h>
44 #include <libcfs/linux/portals_compat25.h>
45 #include <asm/div64.h>
47 #include <libcfs/linux/linux-time.h>
50 * Pseudo device register
52 typedef struct miscdevice cfs_psdev_t;
53 #define cfs_psdev_register(dev) misc_register(dev)
54 #define cfs_psdev_deregister(dev) misc_deregister(dev)
59 typedef struct ctl_table cfs_sysctl_table_t;
60 typedef struct ctl_table_header cfs_sysctl_table_header_t;
62 #ifdef HAVE_2ARGS_REGISTER_SYSCTL
63 #define cfs_register_sysctl_table(t, a) register_sysctl_table(t, a)
65 #define cfs_register_sysctl_table(t, a) register_sysctl_table(t)
67 #define cfs_unregister_sysctl_table(t) unregister_sysctl_table(t)
72 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
73 #define cfs_symbol_register(s, p) inter_module_register(s, THIS_MODULE, p)
74 #define cfs_symbol_unregister(s) inter_module_unregister(s)
75 #define cfs_symbol_get(s) inter_module_get(s)
76 #define cfs_symbol_put(s) inter_module_put(s)
77 #define cfs_module_get() MOD_INC_USE_COUNT
78 #define cfs_module_put() MOD_DEC_USE_COUNT
80 #define cfs_symbol_register(s, p) do {} while(0)
81 #define cfs_symbol_unregister(s) do {} while(0)
82 #define cfs_symbol_get(s) symbol_get(s)
83 #define cfs_symbol_put(s) symbol_put(s)
84 #define cfs_module_get() try_module_get(THIS_MODULE)
85 #define cfs_module_put() module_put(THIS_MODULE)
89 * Proc file system APIs
91 typedef read_proc_t cfs_read_proc_t;
92 typedef write_proc_t cfs_write_proc_t;
93 typedef struct proc_dir_entry cfs_proc_dir_entry_t;
94 #define cfs_create_proc_entry(n, m, p) create_proc_entry(n, m, p)
95 #define cfs_free_proc_entry(e) free_proc_entry(e)
96 #define cfs_remove_proc_entry(n, e) remove_proc_entry(n, e)
101 #define CFS_TASK_INTERRUPTIBLE TASK_INTERRUPTIBLE
102 #define CFS_TASK_UNINT TASK_UNINTERRUPTIBLE
104 typedef wait_queue_t cfs_waitlink_t;
105 typedef wait_queue_head_t cfs_waitq_t;
107 typedef long cfs_task_state_t;
109 #define cfs_waitq_init(w) init_waitqueue_head(w)
110 #define cfs_waitlink_init(l) init_waitqueue_entry(l, current)
111 #define cfs_waitq_add(w, l) add_wait_queue(w, l)
112 #define cfs_waitq_add_exclusive(w, l) add_wait_queue_exclusive(w, l)
113 #define cfs_waitq_forward(l, w) do {} while(0)
114 #define cfs_waitq_del(w, l) remove_wait_queue(w, l)
115 #define cfs_waitq_active(w) waitqueue_active(w)
116 #define cfs_waitq_signal(w) wake_up(w)
117 #define cfs_waitq_signal_nr(w,n) wake_up_nr(w, n)
118 #define cfs_waitq_broadcast(w) wake_up_all(w)
119 #define cfs_waitq_wait(l, s) schedule()
120 #define cfs_waitq_timedwait(l, s, t) schedule_timeout(t)
121 #define cfs_schedule_timeout(s, t) schedule_timeout(t)
122 #define cfs_schedule() schedule()
125 typedef int (*cfs_thread_t)(void *);
126 #define cfs_kernel_thread(func, a, f) kernel_thread(func, a, f)
131 typedef struct task_struct cfs_task_t;
132 #define cfs_current() current
133 #define cfs_task_lock(t) task_lock(t)
134 #define cfs_task_unlock(t) task_unlock(t)
135 #define CFS_DECL_JOURNAL_DATA void *journal_info
136 #define CFS_PUSH_JOURNAL do { \
137 journal_info = current->journal_info; \
138 current->journal_info = NULL; \
140 #define CFS_POP_JOURNAL do { \
141 current->journal_info = journal_info; \
144 /* Module interfaces */
145 #define cfs_module(name, version, init, fini) \
152 typedef sigset_t cfs_sigset_t;
157 typedef struct timer_list cfs_timer_t;
158 typedef void (*timer_func_t)(unsigned long);
160 #define cfs_init_timer(t) init_timer(t)
162 static inline void cfs_timer_init(cfs_timer_t *t, void (*func)(unsigned long), void *arg)
165 t->function = (timer_func_t)func;
166 t->data = (unsigned long)arg;
169 static inline void cfs_timer_done(cfs_timer_t *t)
174 static inline void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline)
176 mod_timer(t, deadline);
179 static inline void cfs_timer_disarm(cfs_timer_t *t)
184 static inline int cfs_timer_is_armed(cfs_timer_t *t)
186 return timer_pending(t);
189 static inline cfs_time_t cfs_timer_deadline(cfs_timer_t *t)
195 /* deschedule for a bit... */
196 static inline void cfs_pause(cfs_duration_t ticks)
198 set_current_state(TASK_UNINTERRUPTIBLE);
199 schedule_timeout(ticks);
202 #else /* !__KERNEL__ */
204 typedef struct proc_dir_entry cfs_proc_dir_entry_t;
205 #include "../user-prim.h"
207 #endif /* __KERNEL__ */