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 * Copyright (c) 2012, 2013, Intel Corporation.
26 #ifndef __LIBCFS_USER_MEM_H__
27 #define __LIBCFS_USER_MEM_H__
29 #ifndef __LIBCFS_LIBCFS_H__
30 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
34 #error "This is only for user space."
39 * for this moment, liblusre will not rely OST for non-page-aligned write
41 #define LIBLUSTRE_HANDLE_UNALIGNED_PAGE
46 struct list_head list;
47 unsigned long private;
49 /* internally used by liblustre file i/o */
52 #ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
55 struct list_head _node;
60 #define PAGE_CACHE_SHIFT 12
61 #define PAGE_CACHE_SIZE (1UL << PAGE_CACHE_SHIFT)
62 #define CFS_PAGE_MASK (~((__u64)PAGE_CACHE_SIZE-1))
64 struct page *alloc_page(unsigned int flags);
65 void __free_page(struct page *pg);
66 void *page_address(struct page *pg);
67 void *kmap(struct page *pg);
68 void kunmap(struct page *pg);
70 #define get_page(p) __I_should_not_be_called__(at_all)
71 #define page_count(p) __I_should_not_be_called__(at_all)
72 #define page_index(p) ((p)->index)
73 #define page_cache_get(page) do { } while (0)
74 #define page_cache_release(page) do { } while (0)
76 #define inc_zone_page_state(page, state) do {} while (0)
77 #define dec_zone_page_state(page, state) do {} while (0)
81 * Inline function, so utils can use them without linking of libcfs
85 * Universal memory allocator API
87 enum cfs_alloc_flags {
88 /* allocation is not allowed to block */
90 /* allocation is allowed to block */
92 /* allocation should return zeroed memory */
94 /* allocation is allowed to call file-system code to free/clean
97 /* allocation is allowed to do io to free/clean memory */
99 /* don't report allocation failure to the console */
101 /* standard allocator flag combination */
102 GFP_IOFS = __GFP_FS | __GFP_IO,
103 GFP_USER = __GFP_WAIT | __GFP_FS | __GFP_IO,
104 GFP_NOFS = __GFP_WAIT | __GFP_IO,
105 GFP_KERNEL = __GFP_WAIT | __GFP_IO | __GFP_FS,
108 /* flags for cfs_page_alloc() in addition to enum cfs_alloc_flags */
109 enum cfs_alloc_page_flags {
110 /* allow to return page beyond KVM. It has to be mapped into KVM by
111 * kmap() and unmapped with kunmap(). */
112 __GFP_HIGHMEM = 0x40,
113 GFP_HIGHUSER = __GFP_WAIT | __GFP_FS | __GFP_IO |
117 static inline void *kmalloc(size_t nr_bytes, u_int32_t flags)
121 result = malloc(nr_bytes);
122 if (result != NULL && (flags & __GFP_ZERO))
123 memset(result, 0, nr_bytes);
127 #define kfree(addr) free(addr)
128 #define vmalloc(nr_bytes) kmalloc(nr_bytes, 0)
129 #define vfree(addr) free(addr)
131 #define ALLOC_ATOMIC_TRY (0)
139 #define SLAB_HWCACHE_ALIGN 0
140 #define SLAB_DESTROY_BY_RCU 0
141 #define SLAB_KERNEL 0
144 #define memory_pressure_get() (0)
145 #define memory_pressure_set() do {} while (0)
146 #define memory_pressure_clr() do {} while (0)
148 struct kmem_cache *kmem_cache_create(const char *, size_t, size_t,
149 unsigned long, void *);
150 void kmem_cache_destroy(struct kmem_cache *c);
151 void *kmem_cache_alloc(struct kmem_cache *c, int gfp);
152 void kmem_cache_free(struct kmem_cache *c, void *addr);
153 int kmem_is_in_cache(const void *addr, const struct kmem_cache *kmem);
158 #define cfs_cpt_malloc(cptab, cpt, bytes, flags) \
159 kmalloc(bytes, flags)
160 #define cfs_cpt_vmalloc(cptab, cpt, bytes) \
162 #define cfs_page_cpt_alloc(cptab, cpt, mask) \
164 #define cfs_mem_cache_cpt_alloc(cache, cptab, cpt, gfp) \
165 kmem_cache_alloc(cache, gfp)
167 #define smp_rmb() do {} while (0)
172 static inline int copy_from_user(void *a, void *b, int c)
178 static inline int copy_to_user(void *a, void *b, int c)