1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2004 Cluster File Systems, Inc.
5 * Author: Nikita Danilov <nikita@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
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.
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
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.
22 * Implementation of portable APIs for user-level.
26 /* Implementations of portable APIs for liblustre */
29 * liblustre is single-threaded, so most "synchronization" APIs are trivial.
39 #include <sys/types.h>
47 #include <libcfs/libcfs.h>
50 * Sleep channel. No-op implementation.
53 void cfs_waitq_init(struct cfs_waitq *waitq)
55 LASSERT(waitq != NULL);
59 void cfs_waitlink_init(struct cfs_waitlink *link)
61 LASSERT(link != NULL);
65 void cfs_waitq_add(struct cfs_waitq *waitq, struct cfs_waitlink *link)
67 LASSERT(waitq != NULL);
68 LASSERT(link != NULL);
73 void cfs_waitq_add_exclusive(struct cfs_waitq *waitq, struct cfs_waitlink *link)
75 LASSERT(waitq != NULL);
76 LASSERT(link != NULL);
81 void cfs_waitq_forward(struct cfs_waitlink *link, struct cfs_waitq *waitq)
83 LASSERT(waitq != NULL);
84 LASSERT(link != NULL);
89 void cfs_waitq_del(struct cfs_waitq *waitq, struct cfs_waitlink *link)
91 LASSERT(waitq != NULL);
92 LASSERT(link != NULL);
97 int cfs_waitq_active(struct cfs_waitq *waitq)
99 LASSERT(waitq != NULL);
103 void cfs_waitq_signal(struct cfs_waitq *waitq)
105 LASSERT(waitq != NULL);
109 void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr)
111 LASSERT(waitq != NULL);
115 void cfs_waitq_broadcast(struct cfs_waitq *waitq)
117 LASSERT(waitq != NULL);
121 void cfs_waitq_wait(struct cfs_waitlink *link)
123 LASSERT(link != NULL);
127 int64_t cfs_waitq_timedwait(struct cfs_waitlink *link, int64_t timeout)
129 LASSERT(link != NULL);
137 cfs_page_t *cfs_alloc_pages(unsigned int flags, unsigned int order)
139 cfs_page_t *pg = malloc(sizeof(*pg));
143 #if 0 //#ifdef MAP_ANONYMOUS
144 pg->addr = mmap(0, PAGE_SIZE << order, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
146 pg->addr = malloc(PAGE_SIZE << order);
156 void cfs_free_pages(struct page *pg, int what)
158 #if 0 //#ifdef MAP_ANONYMOUS
159 munmap(pg->addr, PAGE_SIZE);
166 cfs_page_t *cfs_alloc_page(unsigned int flags)
168 return cfs_alloc_pages(flags, 0);
171 void cfs_free_page(cfs_page_t *pg, int what)
173 cfs_free_page(pg, what);
176 void *cfs_page_address(cfs_page_t *pg)
181 void *cfs_kmap(cfs_page_t *pg)
186 void cfs_kunmap(cfs_page_t *pg)
193 void *cfs_alloc(size_t nr_bytes, u_int32_t flags)
197 result = malloc(nr_bytes);
198 if (result != NULL && (flags & CFS_ALLOC_ZERO))
199 memset(result, 0, nr_bytes);
202 void cfs_free(void *addr)
207 void *cfs_alloc_large(size_t nr_bytes)
209 return cfs_alloc(nr_bytes, 0);
212 void cfs_free_large(void *addr)
214 return cfs_free(addr);
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))
228 c = malloc(sizeof(*c));
232 CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n",
233 name, c, (int)objsize);
237 int cfs_mem_cache_destroy(cfs_mem_cache_t *c)
239 CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", c, c->size);
244 void *cfs_mem_cache_alloc(cfs_mem_cache_t *c, int gfp)
246 return cfs_alloc(c, gfp);
249 void cfs_mem_cache_free(cfs_mem_cache_t *c, void *addr)
260 * c-indentation-style: "K&R"