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 #ifdef HAVE_KERNEL_CONFIG_H
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 #define cfs_register_sysctl_table(t, a) register_sysctl_table(t, a)
63 #define cfs_unregister_sysctl_table(t) unregister_sysctl_table(t, a)
68 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
69 #define cfs_symbol_register(s, p) inter_module_register(s, THIS_MODULE, p)
70 #define cfs_symbol_unregister(s) inter_module_unregister(s)
71 #define cfs_symbol_get(s) inter_module_get(s)
72 #define cfs_symbol_put(s) inter_module_put(s)
73 #define cfs_module_get() MOD_INC_USE_COUNT
74 #define cfs_module_put() MOD_DEC_USE_COUNT
76 #define cfs_symbol_register(s, p) do {} while(0)
77 #define cfs_symbol_unregister(s) do {} while(0)
78 #define cfs_symbol_get(s) symbol_get(s)
79 #define cfs_symbol_put(s) symbol_put(s)
80 #define cfs_module_get() try_module_get(THIS_MODULE)
81 #define cfs_module_put() module_put(THIS_MODULE)
85 * Proc file system APIs
87 typedef read_proc_t cfs_read_proc_t;
88 typedef write_proc_t cfs_write_proc_t;
89 typedef struct proc_dir_entry cfs_proc_dir_entry_t;
90 #define cfs_create_proc_entry(n, m, p) create_proc_entry(n, m, p)
91 #define cfs_free_proc_entry(e) free_proc_entry(e)
92 #define cfs_remove_proc_entry(n, e) remove_proc_entry(n, e)
97 #define CFS_TASK_INTERRUPTIBLE TASK_INTERRUPTIBLE
98 #define CFS_TASK_UNINT TASK_UNINTERRUPTIBLE
100 typedef wait_queue_t cfs_waitlink_t;
101 typedef wait_queue_head_t cfs_waitq_t;
103 typedef long cfs_task_state_t;
105 #define cfs_waitq_init(w) init_waitqueue_head(w)
106 #define cfs_waitlink_init(l) init_waitqueue_entry(l, current)
107 #define cfs_waitq_add(w, l) add_wait_queue(w, l)
108 #define cfs_waitq_add_exclusive(w, l) add_wait_queue_exclusive(w, l)
109 #define cfs_waitq_forward(l, w) do {} while(0)
110 #define cfs_waitq_del(w, l) remove_wait_queue(w, l)
111 #define cfs_waitq_active(w) waitqueue_active(w)
112 #define cfs_waitq_signal(w) wake_up(w)
113 #define cfs_waitq_signal_nr(w,n) wake_up_nr(w, n)
114 #define cfs_waitq_broadcast(w) wake_up_all(w)
115 #define cfs_waitq_wait(l, s) schedule()
116 #define cfs_waitq_timedwait(l, s, t) schedule_timeout(t)
117 #define cfs_schedule_timeout(s, t) schedule_timeout(t)
118 #define cfs_schedule() schedule()
121 typedef int (*cfs_thread_t)(void *);
122 #define cfs_kernel_thread(func, a, f) kernel_thread(func, a, f)
127 typedef struct task_struct cfs_task_t;
128 #define cfs_current() current
129 #define cfs_task_lock(t) task_lock(t)
130 #define cfs_task_unlock(t) task_unlock(t)
131 #define CFS_DECL_JOURNAL_DATA void *journal_info
132 #define CFS_PUSH_JOURNAL do { \
133 journal_info = current->journal_info; \
134 current->journal_info = NULL; \
136 #define CFS_POP_JOURNAL do { \
137 current->journal_info = journal_info; \
140 /* Module interfaces */
141 #define cfs_module(name, version, init, fini) \
148 typedef sigset_t cfs_sigset_t;
153 typedef struct timer_list cfs_timer_t;
154 typedef void (*timer_func_t)(unsigned long);
156 #define cfs_init_timer(t) init_timer(t)
158 static inline void cfs_timer_init(cfs_timer_t *t, void (*func)(unsigned long), void *arg)
161 t->function = (timer_func_t)func;
162 t->data = (unsigned long)arg;
165 static inline void cfs_timer_done(cfs_timer_t *t)
170 static inline void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline)
172 mod_timer(t, deadline);
175 static inline void cfs_timer_disarm(cfs_timer_t *t)
180 static inline int cfs_timer_is_armed(cfs_timer_t *t)
182 return timer_pending(t);
185 static inline cfs_time_t cfs_timer_deadline(cfs_timer_t *t)
191 /* deschedule for a bit... */
192 static inline void cfs_pause(cfs_duration_t ticks)
194 set_current_state(TASK_UNINTERRUPTIBLE);
195 schedule_timeout(ticks);
198 #else /* !__KERNEL__ */
200 typedef struct proc_dir_entry cfs_proc_dir_entry_t;
201 #include "../user-prim.h"
203 #endif /* __KERNEL__ */