Whamcloud - gitweb
file jbd-stats-2.6.9.patch was initially added on branch b1_4.
[fs/lustre-release.git] / lnet / libcfs / user-prim.c
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 APIs for user-level.
23  *
24  */
25
26 /* Implementations of portable APIs for liblustre */
27
28 /*
29  * liblustre is single-threaded, so most "synchronization" APIs are trivial.
30  */
31
32 #ifndef __KERNEL__
33
34 #include <sys/mman.h>
35 #ifndef  __CYGWIN__
36 #include <stdint.h>
37 #include <asm/page.h>
38 #else
39 #include <sys/types.h>
40 #endif
41 #include <stdlib.h>
42 #include <string.h>
43 #include <errno.h>
44 #include <sys/stat.h>
45 #include <sys/vfs.h>
46
47 #include <libcfs/libcfs.h>
48
49 /*
50  * Sleep channel. No-op implementation.
51  */
52
53 void cfs_waitq_init(struct cfs_waitq *waitq)
54 {
55         LASSERT(waitq != NULL);
56         (void)waitq;
57 }
58
59 void cfs_waitlink_init(struct cfs_waitlink *link)
60 {
61         LASSERT(link != NULL);
62         (void)link;
63 }
64
65 void cfs_waitq_add(struct cfs_waitq *waitq, struct cfs_waitlink *link)
66 {
67         LASSERT(waitq != NULL);
68         LASSERT(link != NULL);
69         (void)waitq;
70         (void)link;
71 }
72
73 void cfs_waitq_add_exclusive(struct cfs_waitq *waitq, struct cfs_waitlink *link)
74 {
75         LASSERT(waitq != NULL);
76         LASSERT(link != NULL);
77         (void)waitq;
78         (void)link;
79 }
80
81 void cfs_waitq_forward(struct cfs_waitlink *link, struct cfs_waitq *waitq)
82 {
83         LASSERT(waitq != NULL);
84         LASSERT(link != NULL);
85         (void)waitq;
86         (void)link;
87 }
88
89 void cfs_waitq_del(struct cfs_waitq *waitq, struct cfs_waitlink *link)
90 {
91         LASSERT(waitq != NULL);
92         LASSERT(link != NULL);
93         (void)waitq;
94         (void)link;
95 }
96
97 int cfs_waitq_active(struct cfs_waitq *waitq)
98 {
99         LASSERT(waitq != NULL);
100         (void)waitq;
101 }
102
103 void cfs_waitq_signal(struct cfs_waitq *waitq)
104 {
105         LASSERT(waitq != NULL);
106         (void)waitq;
107 }
108
109 void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr)
110 {
111         LASSERT(waitq != NULL);
112         (void)waitq;
113 }
114
115 void cfs_waitq_broadcast(struct cfs_waitq *waitq)
116 {
117         LASSERT(waitq != NULL);
118         (void)waitq;
119 }
120
121 void cfs_waitq_wait(struct cfs_waitlink *link)
122 {
123         LASSERT(link != NULL);
124         (void)link;
125 }
126
127 int64_t cfs_waitq_timedwait(struct cfs_waitlink *link, int64_t timeout)
128 {
129         LASSERT(link != NULL);
130         (void)link;
131 }
132
133 /*
134  * Allocator
135  */
136
137 cfs_page_t *cfs_alloc_pages(unsigned int flags, unsigned int order)
138 {
139         cfs_page_t *pg = malloc(sizeof(*pg));
140
141         if (!pg)
142                 return NULL;
143 #if 0 //#ifdef MAP_ANONYMOUS
144         pg->addr = mmap(0, PAGE_SIZE << order, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
145 #else
146         pg->addr = malloc(PAGE_SIZE << order);
147 #endif
148
149         if (!pg->addr) {
150                 free(pg);
151                 return NULL;
152         }
153         return pg;
154 }
155
156 void cfs_free_pages(struct page *pg, int what)
157 {
158 #if 0 //#ifdef MAP_ANONYMOUS
159         munmap(pg->addr, PAGE_SIZE);
160 #else
161         free(pg->addr);
162 #endif
163         free(pg);
164 }
165
166 cfs_page_t *cfs_alloc_page(unsigned int flags)
167 {
168         return cfs_alloc_pages(flags, 0);
169 }
170
171 void cfs_free_page(cfs_page_t *pg, int what)
172 {
173         cfs_free_page(pg, what);
174 }
175
176 void *cfs_page_address(cfs_page_t *pg)
177 {
178         return pg->addr;
179 }
180
181 void *cfs_kmap(cfs_page_t *pg)
182 {
183         return pg->addr;
184 }
185
186 void cfs_kunmap(cfs_page_t *pg)
187 {
188 }
189
190 /*
191  * Memory allocator
192  */
193 void *cfs_alloc(size_t nr_bytes, u_int32_t flags)
194 {
195         void *result;
196
197         result = malloc(nr_bytes);
198         if (result != NULL && (flags & CFS_ALLOC_ZERO))
199                 memset(result, 0, nr_bytes);
200 }
201
202 void cfs_free(void *addr)
203 {
204         free(addr);
205 }
206
207 void *cfs_alloc_large(size_t nr_bytes)
208 {
209         return cfs_alloc(nr_bytes, 0);
210 }
211
212 void  cfs_free_large(void *addr)
213 {
214         return cfs_free(addr);
215 }
216
217 /*
218  * SLAB allocator
219  */
220
221 cfs_mem_cache_t *
222 cfs_mem_cache_create(const char *, size_t, size_t, unsigned long,
223                      void (*)(void *, cfs_mem_cache_t *, unsigned long),
224                      void (*)(void *, cfs_mem_cache_t *, unsigned long))
225 {
226         cfs_mem_cache_t *c;
227
228         c = malloc(sizeof(*c));
229         if (!c)
230                 return NULL;
231         c->size = objsize;
232         CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n",
233                name, c, (int)objsize);
234         return c;
235 }
236
237 int cfs_mem_cache_destroy(cfs_mem_cache_t *c)
238 {
239         CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", c, c->size);
240         free(c);
241         return 0;
242 }
243
244 void *cfs_mem_cache_alloc(cfs_mem_cache_t *c, int gfp)
245 {
246         return cfs_alloc(c, gfp);
247 }
248
249 void cfs_mem_cache_free(cfs_mem_cache_t *c, void *addr)
250 {
251         cfs_free(addr);
252 }
253
254
255 /* !__KERNEL__ */
256 #endif
257
258 /*
259  * Local variables:
260  * c-indentation-style: "K&R"
261  * c-basic-offset: 8
262  * tab-width: 8
263  * fill-column: 80
264  * scroll-step: 1
265  * End:
266  */