1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
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 #define DEBUG_SUBSYSTEM S_PORTALS
24 #include <linux/vmalloc.h>
25 #include <linux/slab.h>
26 #include <linux/highmem.h>
27 #include <libcfs/libcfs.h>
30 cfs_alloc(size_t nr_bytes, u_int32_t flags)
33 unsigned int mflags = 0;
35 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
36 if (flags & CFS_ALLOC_ATOMIC)
38 else if (flags & CFS_ALLOC_WAIT)
41 mflags |= (__GFP_HIGH | __GFP_WAIT);
43 if (flags & CFS_ALLOC_FS)
45 if (flags & CFS_ALLOC_IO)
46 mflags |= __GFP_IO | __GFP_HIGHIO;
48 if (flags & CFS_ALLOC_ATOMIC)
52 if (flags & CFS_ALLOC_FS)
54 if (flags & CFS_ALLOC_IO)
58 ptr = kmalloc(nr_bytes, mflags);
59 if (ptr != NULL && (flags & CFS_ALLOC_ZERO))
60 memset(ptr, 0, nr_bytes);
71 cfs_alloc_large(size_t nr_bytes)
73 return vmalloc(nr_bytes);
77 cfs_free_large(void *addr)
83 cfs_alloc_pages(unsigned int flags, unsigned int order)
85 unsigned int mflags = 0;
87 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
88 if (flags & CFS_ALLOC_ATOMIC)
90 else if (flags & CFS_ALLOC_WAIT)
93 mflags |= (__GFP_HIGH | __GFP_WAIT);
95 if (flags & CFS_ALLOC_FS)
97 if (flags & CFS_ALLOC_IO)
98 mflags |= __GFP_IO | __GFP_HIGHIO;
99 if (flags & CFS_ALLOC_HIGH)
100 mflags |= __GFP_HIGHMEM;
102 if (flags & CFS_ALLOC_ATOMIC)
103 mflags |= __GFP_HIGH;
105 mflags |= __GFP_WAIT;
106 if (flags & CFS_ALLOC_FS)
108 if (flags & CFS_ALLOC_IO)
110 if (flags & CFS_ALLOC_HIGH)
111 mflags |= __GFP_HIGHMEM;
114 return alloc_pages(mflags, order);
118 cfs_mem_cache_create (const char *name, size_t size, size_t offset,
119 unsigned long flags, void (*ctor)(void*, kmem_cache_t *, unsigned long),
120 void (*dtor)(void*, cfs_mem_cache_t *, unsigned long))
122 return kmem_cache_create(name, size, offset, flags, ctor, dtor);
126 cfs_mem_cache_destroy (cfs_mem_cache_t * cachep)
128 return kmem_cache_destroy(cachep);
132 cfs_mem_cache_alloc(cfs_mem_cache_t *cachep, int flags)
134 unsigned int mflags = 0;
135 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
136 if (flags & CFS_SLAB_ATOMIC)
137 mflags |= __GFP_HIGH;
138 else if (flags & CFS_ALLOC_WAIT)
139 mflags |= __GFP_WAIT;
141 mflags |= (__GFP_HIGH | __GFP_WAIT);
143 if (flags & CFS_SLAB_FS)
145 if (flags & CFS_SLAB_IO)
146 mflags |= __GFP_IO | __GFP_HIGHIO;
148 if (flags & CFS_SLAB_ATOMIC)
149 mflags |= __GFP_HIGH;
151 mflags |= __GFP_WAIT;
152 if (flags & CFS_SLAB_FS)
154 if (flags & CFS_SLAB_IO)
158 return kmem_cache_alloc(cachep, mflags);
162 cfs_mem_cache_free(cfs_mem_cache_t *cachep, void *objp)
164 return kmem_cache_free(cachep, objp);
167 EXPORT_SYMBOL(cfs_alloc);
168 EXPORT_SYMBOL(cfs_free);
169 EXPORT_SYMBOL(cfs_alloc_large);
170 EXPORT_SYMBOL(cfs_free_large);
171 EXPORT_SYMBOL(cfs_alloc_pages);
172 EXPORT_SYMBOL(cfs_mem_cache_create);
173 EXPORT_SYMBOL(cfs_mem_cache_destroy);
174 EXPORT_SYMBOL(cfs_mem_cache_alloc);
175 EXPORT_SYMBOL(cfs_mem_cache_free);