Whamcloud - gitweb
* removed spurious 'inline' from extern portal_ioctl_getdata() decl
[fs/lustre-release.git] / lnet / include / libcfs / user-prim.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2004 Cluster File Systems, Inc.
5  * Author: Nikita Danilov <nikita@clusterfs.com>
6  *
7  * This file is part of Lustre, http://www.lustre.org.
8  *
9  * Lustre is free software; you can redistribute it and/or modify it under the
10  * terms of version 2 of the GNU General Public License as published by the
11  * Free Software Foundation.
12  *
13  * Lustre is distributed in the hope that it will be useful, but WITHOUT ANY
14  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with Lustre; if not, write to the Free Software Foundation, Inc., 675 Mass
20  * Ave, Cambridge, MA 02139, USA.
21  *
22  * Implementation of portable time API for user-level.
23  *
24  */
25
26 #ifndef __LIBCFS_USER_PRIM_H__
27 #define __LIBCFS_USER_PRIM_H__
28
29 #ifndef __LIBCFS_LIBCFS_H__
30 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
31 #endif
32
33 /* Implementations of portable APIs for liblustre */
34
35 /*
36  * liblustre is single-threaded, so most "synchronization" APIs are trivial.
37  */
38
39 #ifndef __KERNEL__
40
41 #include <libcfs/list.h>
42
43 /*
44  * Wait Queue. No-op implementation.
45  */
46
47 typedef struct cfs_waitlink {} cfs_waitlink_t;
48 typedef struct cfs_waitq {} cfs_waitq_t;
49
50 void cfs_waitq_init(struct cfs_waitq *waitq);
51 void cfs_waitlink_init(struct cfs_waitlink *link);
52 void cfs_waitq_add(struct cfs_waitq *waitq, struct cfs_waitlink *link);
53 void cfs_waitq_add_exclusive(struct cfs_waitq *waitq, 
54                              struct cfs_waitlink *link);
55 void cfs_waitq_forward(struct cfs_waitlink *link, struct cfs_waitq *waitq);
56 void cfs_waitq_del(struct cfs_waitq *waitq, struct cfs_waitlink *link);
57 int  cfs_waitq_active(struct cfs_waitq *waitq);
58 void cfs_waitq_signal(struct cfs_waitq *waitq);
59 void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr);
60 void cfs_waitq_broadcast(struct cfs_waitq *waitq);
61 void cfs_waitq_wait(struct cfs_waitlink *link);
62 int64_t cfs_waitq_timedwait(struct cfs_waitlink *link, int64_t timeout);
63
64 /*
65  * Allocator
66  */
67
68 /* 2.4 defines */
69
70 /* XXX
71  * for this moment, liblusre will not rely OST for non-page-aligned write
72  */
73 #define LIBLUSTRE_HANDLE_UNALIGNED_PAGE
74
75 struct page {
76         void   *addr;
77         unsigned long index;
78         struct list_head list;
79         unsigned long private;
80
81         /* internally used by liblustre file i/o */
82         int     _offset;
83         int     _count;
84 #ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
85         int     _managed;
86 #endif
87 };
88
89 typedef struct page cfs_page_t;
90
91 #define CFS_PAGE_SIZE                   PAGE_CACHE_SIZE
92 #define CFS_PAGE_SHIFT                  PAGE_CACHE_SHIFT
93 #define CFS_PAGE_MASK                   PAGE_CACHE_MASK
94
95 cfs_page_t *cfs_alloc_pages(unsigned int flags, unsigned int order);
96 void cfs_free_pages(struct page *pg, int what);
97
98 cfs_page_t *cfs_alloc_page(unsigned int flags);
99 void cfs_free_page(cfs_page_t *pg, int what);
100 void *cfs_page_address(cfs_page_t *pg);
101 void *cfs_kmap(cfs_page_t *pg);
102 void cfs_kunmap(cfs_page_t *pg);
103
104 #define cfs_get_page(p)                 __I_should_not_be_called__(at_all)
105 #define cfs_page_count(p)               __I_should_not_be_called__(at_all)
106 #define cfs_set_page_count(p, v)        __I_should_not_be_called__(at_all)
107
108 /*
109  * Memory allocator
110  */
111 void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
112 void cfs_free(void *addr);
113 void *cfs_alloc_large(size_t nr_bytes);
114 void  cfs_free_large(void *addr);
115
116 /*
117  * SLAB allocator
118  */
119 typedef struct {
120          int size;
121 } cfs_mem_cache_t;
122
123 #define SLAB_HWCACHE_ALIGN 0
124
125 cfs_mem_cache_t *
126 cfs_mem_cache_create(const char *, size_t, size_t, unsigned long,
127                      void (*)(void *, cfs_mem_cache_t *, unsigned long),
128                      void (*)(void *, cfs_mem_cache_t *, unsigned long));
129 int cfs_mem_cache_destroy(cfs_mem_cache_t *c);
130 void *cfs_mem_cache_alloc(cfs_mem_cache_t *c, int gfp);
131 void cfs_mem_cache_free(cfs_mem_cache_t *c, void *addr);
132
133 typedef int (cfs_read_proc_t)(char *page, char **start, off_t off,
134                           int count, int *eof, void *data);
135
136 struct file; /* forward ref */
137 typedef int (cfs_write_proc_t)(struct file *file, const char *buffer,
138                                unsigned long count, void *data);
139
140 /*
141  * Timer
142  */
143
144 typedef struct cfs_timer {} cfs_timer_t;
145
146 #if 0
147 #define cfs_init_timer(t)       do {} while(0)
148 void cfs_timer_init(struct cfs_timer *t, void (*func)(unsigned long), void *arg);
149 void cfs_timer_done(struct cfs_timer *t);
150 void cfs_timer_arm(struct cfs_timer *t, cfs_time_t deadline);
151 void cfs_timer_disarm(struct cfs_timer *t);
152 int  cfs_timer_is_armed(struct cfs_timer *t);
153
154 cfs_time_t cfs_timer_deadline(struct cfs_timer *t);
155 #endif
156
157 typedef void cfs_psdev_t;
158
159 static inline int cfs_psdev_register(cfs_psdev_t *foo)
160 {
161         return 0;
162 }
163
164 static inline int cfs_psdev_deregister(cfs_psdev_t *foo)
165 {
166         return 0;
167 }
168
169 /* !__KERNEL__ */
170 #endif
171
172 /* __LIBCFS_USER_PRIM_H__ */
173 #endif
174 /*
175  * Local variables:
176  * c-indentation-style: "K&R"
177  * c-basic-offset: 8
178  * tab-width: 8
179  * fill-column: 80
180  * scroll-step: 1
181  * End:
182  */