4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef __LIBCFS_USER_MEM_H__
24 #define __LIBCFS_USER_MEM_H__
26 #ifndef __LIBCFS_LIBCFS_H__
27 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
31 #error "This is only for user space."
36 * for this moment, liblusre will not rely OST for non-page-aligned write
38 #define LIBLUSTRE_HANDLE_UNALIGNED_PAGE
43 struct list_head list;
44 unsigned long private;
46 /* internally used by liblustre file i/o */
49 #ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
52 struct list_head _node;
57 #define PAGE_CACHE_SHIFT 12
58 #define PAGE_CACHE_SIZE (1UL << PAGE_CACHE_SHIFT)
59 #define CFS_PAGE_MASK (~((__u64)PAGE_CACHE_SIZE-1))
61 struct page *alloc_page(unsigned int flags);
62 void __free_page(struct page *pg);
63 void *page_address(struct page *pg);
64 void *kmap(struct page *pg);
65 void kunmap(struct page *pg);
67 #define get_page(p) __I_should_not_be_called__(at_all)
68 #define page_count(p) __I_should_not_be_called__(at_all)
69 #define page_index(p) ((p)->index)
70 #define page_cache_get(page) do { } while (0)
71 #define page_cache_release(page) do { } while (0)
73 #define inc_zone_page_state(page, state) do {} while (0)
74 #define dec_zone_page_state(page, state) do {} while (0)
78 * Inline function, so utils can use them without linking of libcfs
82 * Universal memory allocator API
84 enum cfs_alloc_flags {
85 /* allocation is not allowed to block */
87 /* allocation is allowed to block */
89 /* allocation should return zeroed memory */
91 /* allocation is allowed to call file-system code to free/clean
94 /* allocation is allowed to do io to free/clean memory */
96 /* don't report allocation failure to the console */
98 /* standard allocator flag combination */
99 GFP_IOFS = __GFP_FS | __GFP_IO,
100 GFP_USER = __GFP_WAIT | __GFP_FS | __GFP_IO,
101 GFP_NOFS = __GFP_WAIT | __GFP_IO,
102 GFP_KERNEL = __GFP_WAIT | __GFP_IO | __GFP_FS,
105 /* flags for cfs_page_alloc() in addition to enum cfs_alloc_flags */
106 enum cfs_alloc_page_flags {
107 /* allow to return page beyond KVM. It has to be mapped into KVM by
108 * kmap() and unmapped with kunmap(). */
109 __GFP_HIGHMEM = 0x40,
110 GFP_HIGHUSER = __GFP_WAIT | __GFP_FS | __GFP_IO |
114 static inline void *kmalloc(size_t nr_bytes, u_int32_t flags)
118 result = malloc(nr_bytes);
119 if (result != NULL && (flags & __GFP_ZERO))
120 memset(result, 0, nr_bytes);
124 #define kfree(addr) free(addr)
125 #define vmalloc(nr_bytes) kmalloc(nr_bytes, 0)
126 #define vfree(addr) free(addr)
128 #define ALLOC_ATOMIC_TRY (0)
136 #define SLAB_HWCACHE_ALIGN 0
137 #define SLAB_DESTROY_BY_RCU 0
138 #define SLAB_KERNEL 0
141 #define memory_pressure_get() (0)
142 #define memory_pressure_set() do {} while (0)
143 #define memory_pressure_clr() do {} while (0)
145 struct kmem_cache *kmem_cache_create(const char *, size_t, size_t,
146 unsigned long, void *);
147 void kmem_cache_destroy(struct kmem_cache *c);
148 void *kmem_cache_alloc(struct kmem_cache *c, int gfp);
149 void kmem_cache_free(struct kmem_cache *c, void *addr);
150 int kmem_is_in_cache(const void *addr, const struct kmem_cache *kmem);
155 #define cfs_cpt_malloc(cptab, cpt, bytes, flags) \
156 kmalloc(bytes, flags)
157 #define cfs_cpt_vmalloc(cptab, cpt, bytes) \
159 #define cfs_page_cpt_alloc(cptab, cpt, mask) \
161 #define cfs_mem_cache_cpt_alloc(cache, cptab, cpt, gfp) \
162 kmem_cache_alloc(cache, gfp)
164 #define smp_rmb() do {} while (0)
169 static inline int copy_from_user(void *a, void *b, int c)
175 static inline int copy_to_user(void *a, void *b, int c)